Skip to content

Commit 01fc48d

Browse files
committed
Changed String back to char *, too many memory problems
1 parent cb87ffa commit 01fc48d

File tree

4 files changed

+40
-71
lines changed

4 files changed

+40
-71
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Public Methods
122122
### jt65_encode()
123123
```
124124
/*
125-
* jt65_encode(String message, uint8_t * symbols)
125+
* jt65_encode(char * message, uint8_t * symbols)
126126
*
127127
* Takes an arbitrary message of up to 13 allowable characters and returns
128128
* a channel symbol table.
@@ -136,7 +136,7 @@ Public Methods
136136
### jt9_encode()
137137
```
138138
/*
139-
* jt9_encode(String message, uint8_t * symbols)
139+
* jt9_encode(char * message, uint8_t * symbols)
140140
*
141141
* Takes an arbitrary message of up to 13 allowable characters and returns
142142
* a channel symbol table.
@@ -151,7 +151,7 @@ Public Methods
151151
### jt4_encode()
152152
```
153153
/*
154-
* jt4_encode(String message, uint8_t * symbols)
154+
* jt4_encode(char * message, uint8_t * symbols)
155155
*
156156
* Takes an arbitrary message of up to 13 allowable characters and returns
157157
* a channel symbol table.
@@ -166,7 +166,7 @@ Public Methods
166166
### wspr_encode()
167167
```
168168
/*
169-
* wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbols)
169+
* wspr_encode(char * call, char * loc, uint8_t dbm, uint8_t * symbols)
170170
*
171171
* Takes an arbitrary message of up to 13 allowable characters and returns
172172
*
@@ -182,7 +182,7 @@ Public Methods
182182
### fsq_encode()
183183
```
184184
/*
185-
* fsq_encode(String from_call, String message, uint8_t * symbols)
185+
* fsq_encode(char * from_call, char * message, uint8_t * symbols)
186186
*
187187
* Takes an arbitrary message and returns a FSQ channel symbol table.
188188
*
@@ -198,13 +198,13 @@ Public Methods
198198
### fsq_dir_encode()
199199
```
200200
/*
201-
* fsq_dir_encode(String from_call, String to_call, String cmd, String message, uint8_t * symbols)
201+
* fsq_dir_encode(char * from_call, char * to_call, char cmd, char * message, uint8_t * symbols)
202202
*
203203
* Takes an arbitrary message and returns a FSQ channel symbol table.
204204
*
205205
* from_call - Callsign from which message is directed (maximum size: 20)
206206
* to_call - Callsign to which message is directed (maximum size: 20)
207-
* cmd - Directed command (maximum size: 10)
207+
* cmd - Directed command
208208
* message - Null-terminated message string, no greater than 100 chars in length
209209
* symbols - Array of channel symbols to transmit retunred by the method.
210210
* Ensure that you pass a uint8_t array of at least the size of the message
@@ -231,7 +231,7 @@ Changelog
231231
---------
232232
* v1.1.0
233233

234-
Added FSQ, changed all public methods to take String instead of char *
234+
Added FSQ
235235

236236
* v1.0.1
237237

examples/Si5351JTDemo/Si5351JTDemo.ino

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ JTEncode jtencode;
8080

8181
// Global variables
8282
unsigned long freq;
83-
String message = "N0CALL AA00";
84-
String call = "N0CALL";
85-
String loc = "AA00";
83+
char message[] = "N0CALL AA00";
84+
char call[] = "N0CALL";
85+
char loc[] = "AA00";
8686
uint8_t dbm = 27;
8787
uint8_t tx_buffer[255];
8888
enum mode cur_mode = DEFAULT_MODE;
@@ -121,15 +121,13 @@ void encode()
121121
jtencode.jt4_encode(message, tx_buffer);
122122
break;
123123
case MODE_WSPR:
124-
call.toUpperCase();
125124
jtencode.wspr_encode(call, loc, dbm, tx_buffer);
126125
break;
127126
case MODE_FSQ_2:
128127
case MODE_FSQ_3:
129128
case MODE_FSQ_4_5:
130129
case MODE_FSQ_6:
131-
call.toLowerCase();
132-
jtencode.fsq_dir_encode(call, "n0call", " ", "hello world", tx_buffer);
130+
jtencode.fsq_dir_encode(call, "n0call", ' ', "hello world", tx_buffer);
133131
break;
134132
}
135133

@@ -231,7 +229,6 @@ void setup()
231229

232230
// Set CLK0 output
233231
si5351.set_correction(0);
234-
si5351.set_freq(freq * 100, 0, SI5351_CLK0);
235232
si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); // Set for max power if desired
236233
si5351.output_enable(SI5351_CLK0, 0); // Disable the clock initially
237234

src/JTEncode.cpp

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
// upper bound.
3737
#define NGLYPHS (sizeof(fsq_code_table)/sizeof(fsq_code_table[0]))
3838

39-
//uint8_t JTEncode::crc8_table[256];
40-
4139
/* Public Class Members */
4240

4341
JTEncode::JTEncode(void)
@@ -47,7 +45,7 @@ JTEncode::JTEncode(void)
4745
}
4846

4947
/*
50-
* jt65_encode(String message, uint8_t * symbols)
48+
* jt65_encode(char * message, uint8_t * symbols)
5149
*
5250
* Takes an arbitrary message of up to 13 allowable characters and returns
5351
* a channel symbol table.
@@ -57,22 +55,16 @@ JTEncode::JTEncode(void)
5755
* Ensure that you pass a uint8_t array of size JT65_SYMBOL_COUNT to the method.
5856
*
5957
*/
60-
void JTEncode::jt65_encode(String message, uint8_t * symbols)
58+
void JTEncode::jt65_encode(char * message, uint8_t * symbols)
6159
{
62-
char message_array[14];
63-
64-
// Convert the String to C-style char array
65-
// ----------------------------------------
66-
message.toCharArray(message_array, 14);
67-
6860
// Ensure that the message text conforms to standards
6961
// --------------------------------------------------
70-
jt_message_prep(message_array);
62+
jt_message_prep(message);
7163

7264
// Bit packing
7365
// -----------
7466
uint8_t c[12];
75-
jt65_bit_packing(message_array, c);
67+
jt65_bit_packing(message, c);
7668

7769
// Reed-Solomon encoding
7870
// ---------------------
@@ -93,7 +85,7 @@ void JTEncode::jt65_encode(String message, uint8_t * symbols)
9385
}
9486

9587
/*
96-
* jt9_encode(String message, uint8_t * symbols)
88+
* jt9_encode(char * message, uint8_t * symbols)
9789
*
9890
* Takes an arbitrary message of up to 13 allowable characters and returns
9991
* a channel symbol table.
@@ -103,22 +95,16 @@ void JTEncode::jt65_encode(String message, uint8_t * symbols)
10395
* Ensure that you pass a uint8_t array of size JT9_SYMBOL_COUNT to the method.
10496
*
10597
*/
106-
void JTEncode::jt9_encode(String message, uint8_t * symbols)
98+
void JTEncode::jt9_encode(char * message, uint8_t * symbols)
10799
{
108-
char message_array[14];
109-
110-
// Convert the String to C-style char array
111-
// ----------------------------------------
112-
message.toCharArray(message_array, 14);
113-
114100
// Ensure that the message text conforms to standards
115101
// --------------------------------------------------
116-
jt_message_prep(message_array);
102+
jt_message_prep(message);
117103

118104
// Bit packing
119105
// -----------
120106
uint8_t c[13];
121-
jt9_bit_packing(message_array, c);
107+
jt9_bit_packing(message, c);
122108

123109
// Convolutional Encoding
124110
// ---------------------
@@ -144,7 +130,7 @@ void JTEncode::jt9_encode(String message, uint8_t * symbols)
144130
}
145131

146132
/*
147-
* jt4_encode(String message, uint8_t * symbols)
133+
* jt4_encode(char * message, uint8_t * symbols)
148134
*
149135
* Takes an arbitrary message of up to 13 allowable characters and returns
150136
* a channel symbol table.
@@ -154,22 +140,16 @@ void JTEncode::jt9_encode(String message, uint8_t * symbols)
154140
* Ensure that you pass a uint8_t array of size JT9_SYMBOL_COUNT to the method.
155141
*
156142
*/
157-
void JTEncode::jt4_encode(String message, uint8_t * symbols)
143+
void JTEncode::jt4_encode(char * message, uint8_t * symbols)
158144
{
159-
char message_array[14];
160-
161-
// Convert the String to C-style char array
162-
// ----------------------------------------
163-
message.toCharArray(message_array, 14);
164-
165145
// Ensure that the message text conforms to standards
166146
// --------------------------------------------------
167-
jt_message_prep(message_array);
147+
jt_message_prep(message);
168148

169149
// Bit packing
170150
// -----------
171151
uint8_t c[13];
172-
jt9_bit_packing(message_array, c);
152+
jt9_bit_packing(message, c);
173153

174154
// Convolutional Encoding
175155
// ---------------------
@@ -188,7 +168,7 @@ void JTEncode::jt4_encode(String message, uint8_t * symbols)
188168
}
189169

190170
/*
191-
* wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbols)
171+
* wspr_encode(char * call, char * loc, uint8_t dbm, uint8_t * symbols)
192172
*
193173
* Takes an arbitrary message of up to 13 allowable characters and returns
194174
*
@@ -199,19 +179,11 @@ void JTEncode::jt4_encode(String message, uint8_t * symbols)
199179
* Ensure that you pass a uint8_t array of size WSPR_SYMBOL_COUNT to the method.
200180
*
201181
*/
202-
void JTEncode::wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbols)
182+
void JTEncode::wspr_encode(char * call, char * loc, uint8_t dbm, uint8_t * symbols)
203183
{
204-
char call_array[8];
205-
char loc_array[8];
206-
207-
// Convert the String to C-style char array
208-
// ----------------------------------------
209-
call.toCharArray(call_array, 8);
210-
loc.toCharArray(loc_array, 8);
211-
212184
// Ensure that the message text conforms to standards
213185
// --------------------------------------------------
214-
wspr_message_prep(call_array, loc_array, dbm);
186+
wspr_message_prep(call, loc, dbm);
215187

216188
// Bit packing
217189
// -----------
@@ -233,7 +205,7 @@ void JTEncode::wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbo
233205
}
234206

235207
/*
236-
* fsq_encode(String from_call, String message, uint8_t * symbols)
208+
* fsq_encode(cahr * from_call, char * message, uint8_t * symbols)
237209
*
238210
* Takes an arbitrary message and returns a FSQ channel symbol table.
239211
*
@@ -244,7 +216,7 @@ void JTEncode::wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbo
244216
* plus 5 characters to the method. Terminated in 0xFF.
245217
*
246218
*/
247-
void JTEncode::fsq_encode(String from_call, String message, uint8_t * symbols)
219+
void JTEncode::fsq_encode(char * from_call, char * message, uint8_t * symbols)
248220
{
249221
char tx_buffer[155];
250222
char * tx_message;
@@ -258,7 +230,7 @@ void JTEncode::fsq_encode(String from_call, String message, uint8_t * symbols)
258230

259231
// Create the message to be transmitted
260232
// ------------------------------------
261-
sprintf(tx_buffer, " \n%s: %s", from_call.c_str(), message.c_str());
233+
sprintf(tx_buffer, " \n%s: %s", from_call, message);
262234

263235
tx_message = tx_buffer;
264236

@@ -318,7 +290,7 @@ void JTEncode::fsq_encode(String from_call, String message, uint8_t * symbols)
318290
}
319291

320292
/*
321-
* fsq_dir_encode(String from_call, String to_call, char cmd, String message, uint8_t * symbols)
293+
* fsq_dir_encode(char * from_call, char * to_call, char cmd, char * message, uint8_t * symbols)
322294
*
323295
* Takes an arbitrary message and returns a FSQ channel symbol table.
324296
*
@@ -331,7 +303,7 @@ void JTEncode::fsq_encode(String from_call, String message, uint8_t * symbols)
331303
* plus 5 characters to the method. Terminated in 0xFF.
332304
*
333305
*/
334-
void JTEncode::fsq_dir_encode(String from_call, String to_call, char cmd, String message, uint8_t * symbols)
306+
void JTEncode::fsq_dir_encode(char * from_call, char * to_call, char cmd, char * message, uint8_t * symbols)
335307
{
336308
char tx_buffer[155];
337309
char * tx_message;
@@ -341,7 +313,7 @@ void JTEncode::fsq_dir_encode(String from_call, String to_call, char cmd, String
341313

342314
// Generate a CRC on from_call
343315
// ---------------------------
344-
from_call_crc = crc8(from_call.c_str());
316+
from_call_crc = crc8(from_call);
345317

346318
// Clear out the transmit buffer
347319
// -----------------------------
@@ -351,7 +323,7 @@ void JTEncode::fsq_dir_encode(String from_call, String to_call, char cmd, String
351323
// We are building a directed message here.
352324
// FSQ very specifically needs " \b " in
353325
// directed mode to indicate EOT. A single backspace won't do it.
354-
sprintf(tx_buffer, " \n%s:%02x%s%c%s%s", from_call.c_str(), from_call_crc, to_call.c_str(), cmd, message.c_str(), " \b ");
326+
sprintf(tx_buffer, " \n%s:%02x%s%c%s%s", from_call, from_call_crc, to_call, cmd, message, " \b ");
355327

356328
tx_message = tx_buffer;
357329

src/JTEncode.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ class JTEncode
189189
{
190190
public:
191191
JTEncode(void);
192-
void jt65_encode(String, uint8_t *);
193-
void jt9_encode(String, uint8_t *);
194-
void jt4_encode(String, uint8_t *);
195-
void wspr_encode(String, String, uint8_t, uint8_t *);
196-
void fsq_encode(String, String, uint8_t *);
197-
void fsq_dir_encode(String, String, char, String, uint8_t *);
192+
void jt65_encode(char *, uint8_t *);
193+
void jt9_encode(char *, uint8_t *);
194+
void jt4_encode(char *, uint8_t *);
195+
void wspr_encode(char *, char *, uint8_t, uint8_t *);
196+
void fsq_encode(char *, char *, uint8_t *);
197+
void fsq_dir_encode(char *, char *, char, char *, uint8_t *);
198198
private:
199199
uint8_t jt_code(char);
200200
uint8_t wspr_code(char);

0 commit comments

Comments
 (0)