From 01fc48d8183e6a9d3b3a11fd3edd0195b4c5940f Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sun, 10 Jul 2016 17:30:04 -0700 Subject: [PATCH] Changed String back to char *, too many memory problems --- README.md | 16 +++--- examples/Si5351JTDemo/Si5351JTDemo.ino | 11 ++-- src/JTEncode.cpp | 72 ++++++++------------------ src/JTEncode.h | 12 ++--- 4 files changed, 40 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 968756c..c3ab8e0 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ Public Methods ### jt65_encode() ``` /* - * jt65_encode(String message, uint8_t * symbols) + * jt65_encode(char * message, uint8_t * symbols) * * Takes an arbitrary message of up to 13 allowable characters and returns * a channel symbol table. @@ -136,7 +136,7 @@ Public Methods ### jt9_encode() ``` /* - * jt9_encode(String message, uint8_t * symbols) + * jt9_encode(char * message, uint8_t * symbols) * * Takes an arbitrary message of up to 13 allowable characters and returns * a channel symbol table. @@ -151,7 +151,7 @@ Public Methods ### jt4_encode() ``` /* - * jt4_encode(String message, uint8_t * symbols) + * jt4_encode(char * message, uint8_t * symbols) * * Takes an arbitrary message of up to 13 allowable characters and returns * a channel symbol table. @@ -166,7 +166,7 @@ Public Methods ### wspr_encode() ``` /* - * wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbols) + * wspr_encode(char * call, char * loc, uint8_t dbm, uint8_t * symbols) * * Takes an arbitrary message of up to 13 allowable characters and returns * @@ -182,7 +182,7 @@ Public Methods ### fsq_encode() ``` /* - * fsq_encode(String from_call, String message, uint8_t * symbols) + * fsq_encode(char * from_call, char * message, uint8_t * symbols) * * Takes an arbitrary message and returns a FSQ channel symbol table. * @@ -198,13 +198,13 @@ Public Methods ### fsq_dir_encode() ``` /* -* fsq_dir_encode(String from_call, String to_call, String cmd, String message, uint8_t * symbols) +* fsq_dir_encode(char * from_call, char * to_call, char cmd, char * message, uint8_t * symbols) * * Takes an arbitrary message and returns a FSQ channel symbol table. * * from_call - Callsign from which message is directed (maximum size: 20) * to_call - Callsign to which message is directed (maximum size: 20) -* cmd - Directed command (maximum size: 10) +* cmd - Directed command * message - Null-terminated message string, no greater than 100 chars in length * symbols - Array of channel symbols to transmit retunred by the method. * Ensure that you pass a uint8_t array of at least the size of the message @@ -231,7 +231,7 @@ Changelog --------- * v1.1.0 - Added FSQ, changed all public methods to take String instead of char * + Added FSQ * v1.0.1 diff --git a/examples/Si5351JTDemo/Si5351JTDemo.ino b/examples/Si5351JTDemo/Si5351JTDemo.ino index 0a10688..a636195 100644 --- a/examples/Si5351JTDemo/Si5351JTDemo.ino +++ b/examples/Si5351JTDemo/Si5351JTDemo.ino @@ -80,9 +80,9 @@ JTEncode jtencode; // Global variables unsigned long freq; -String message = "N0CALL AA00"; -String call = "N0CALL"; -String loc = "AA00"; +char message[] = "N0CALL AA00"; +char call[] = "N0CALL"; +char loc[] = "AA00"; uint8_t dbm = 27; uint8_t tx_buffer[255]; enum mode cur_mode = DEFAULT_MODE; @@ -121,15 +121,13 @@ void encode() jtencode.jt4_encode(message, tx_buffer); break; case MODE_WSPR: - call.toUpperCase(); jtencode.wspr_encode(call, loc, dbm, tx_buffer); break; case MODE_FSQ_2: case MODE_FSQ_3: case MODE_FSQ_4_5: case MODE_FSQ_6: - call.toLowerCase(); - jtencode.fsq_dir_encode(call, "n0call", " ", "hello world", tx_buffer); + jtencode.fsq_dir_encode(call, "n0call", ' ', "hello world", tx_buffer); break; } @@ -231,7 +229,6 @@ void setup() // Set CLK0 output si5351.set_correction(0); - si5351.set_freq(freq * 100, 0, SI5351_CLK0); si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); // Set for max power if desired si5351.output_enable(SI5351_CLK0, 0); // Disable the clock initially diff --git a/src/JTEncode.cpp b/src/JTEncode.cpp index b08d471..3b93a16 100644 --- a/src/JTEncode.cpp +++ b/src/JTEncode.cpp @@ -36,8 +36,6 @@ // upper bound. #define NGLYPHS (sizeof(fsq_code_table)/sizeof(fsq_code_table[0])) -//uint8_t JTEncode::crc8_table[256]; - /* Public Class Members */ JTEncode::JTEncode(void) @@ -47,7 +45,7 @@ JTEncode::JTEncode(void) } /* - * jt65_encode(String message, uint8_t * symbols) + * jt65_encode(char * message, uint8_t * symbols) * * Takes an arbitrary message of up to 13 allowable characters and returns * a channel symbol table. @@ -57,22 +55,16 @@ JTEncode::JTEncode(void) * Ensure that you pass a uint8_t array of size JT65_SYMBOL_COUNT to the method. * */ -void JTEncode::jt65_encode(String message, uint8_t * symbols) +void JTEncode::jt65_encode(char * message, uint8_t * symbols) { - char message_array[14]; - - // Convert the String to C-style char array - // ---------------------------------------- - message.toCharArray(message_array, 14); - // Ensure that the message text conforms to standards // -------------------------------------------------- - jt_message_prep(message_array); + jt_message_prep(message); // Bit packing // ----------- uint8_t c[12]; - jt65_bit_packing(message_array, c); + jt65_bit_packing(message, c); // Reed-Solomon encoding // --------------------- @@ -93,7 +85,7 @@ void JTEncode::jt65_encode(String message, uint8_t * symbols) } /* - * jt9_encode(String message, uint8_t * symbols) + * jt9_encode(char * message, uint8_t * symbols) * * Takes an arbitrary message of up to 13 allowable characters and returns * a channel symbol table. @@ -103,22 +95,16 @@ void JTEncode::jt65_encode(String message, uint8_t * symbols) * Ensure that you pass a uint8_t array of size JT9_SYMBOL_COUNT to the method. * */ -void JTEncode::jt9_encode(String message, uint8_t * symbols) +void JTEncode::jt9_encode(char * message, uint8_t * symbols) { - char message_array[14]; - - // Convert the String to C-style char array - // ---------------------------------------- - message.toCharArray(message_array, 14); - // Ensure that the message text conforms to standards // -------------------------------------------------- - jt_message_prep(message_array); + jt_message_prep(message); // Bit packing // ----------- uint8_t c[13]; - jt9_bit_packing(message_array, c); + jt9_bit_packing(message, c); // Convolutional Encoding // --------------------- @@ -144,7 +130,7 @@ void JTEncode::jt9_encode(String message, uint8_t * symbols) } /* - * jt4_encode(String message, uint8_t * symbols) + * jt4_encode(char * message, uint8_t * symbols) * * Takes an arbitrary message of up to 13 allowable characters and returns * a channel symbol table. @@ -154,22 +140,16 @@ void JTEncode::jt9_encode(String message, uint8_t * symbols) * Ensure that you pass a uint8_t array of size JT9_SYMBOL_COUNT to the method. * */ -void JTEncode::jt4_encode(String message, uint8_t * symbols) +void JTEncode::jt4_encode(char * message, uint8_t * symbols) { - char message_array[14]; - - // Convert the String to C-style char array - // ---------------------------------------- - message.toCharArray(message_array, 14); - // Ensure that the message text conforms to standards // -------------------------------------------------- - jt_message_prep(message_array); + jt_message_prep(message); // Bit packing // ----------- uint8_t c[13]; - jt9_bit_packing(message_array, c); + jt9_bit_packing(message, c); // Convolutional Encoding // --------------------- @@ -188,7 +168,7 @@ void JTEncode::jt4_encode(String message, uint8_t * symbols) } /* - * wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbols) + * wspr_encode(char * call, char * loc, uint8_t dbm, uint8_t * symbols) * * Takes an arbitrary message of up to 13 allowable characters and returns * @@ -199,19 +179,11 @@ void JTEncode::jt4_encode(String message, uint8_t * symbols) * Ensure that you pass a uint8_t array of size WSPR_SYMBOL_COUNT to the method. * */ -void JTEncode::wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbols) +void JTEncode::wspr_encode(char * call, char * loc, uint8_t dbm, uint8_t * symbols) { - char call_array[8]; - char loc_array[8]; - - // Convert the String to C-style char array - // ---------------------------------------- - call.toCharArray(call_array, 8); - loc.toCharArray(loc_array, 8); - // Ensure that the message text conforms to standards // -------------------------------------------------- - wspr_message_prep(call_array, loc_array, dbm); + wspr_message_prep(call, loc, dbm); // Bit packing // ----------- @@ -233,7 +205,7 @@ void JTEncode::wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbo } /* - * fsq_encode(String from_call, String message, uint8_t * symbols) + * fsq_encode(cahr * from_call, char * message, uint8_t * symbols) * * Takes an arbitrary message and returns a FSQ channel symbol table. * @@ -244,7 +216,7 @@ void JTEncode::wspr_encode(String call, String loc, uint8_t dbm, uint8_t * symbo * plus 5 characters to the method. Terminated in 0xFF. * */ -void JTEncode::fsq_encode(String from_call, String message, uint8_t * symbols) +void JTEncode::fsq_encode(char * from_call, char * message, uint8_t * symbols) { char tx_buffer[155]; char * tx_message; @@ -258,7 +230,7 @@ void JTEncode::fsq_encode(String from_call, String message, uint8_t * symbols) // Create the message to be transmitted // ------------------------------------ - sprintf(tx_buffer, " \n%s: %s", from_call.c_str(), message.c_str()); + sprintf(tx_buffer, " \n%s: %s", from_call, message); tx_message = tx_buffer; @@ -318,7 +290,7 @@ void JTEncode::fsq_encode(String from_call, String message, uint8_t * symbols) } /* - * fsq_dir_encode(String from_call, String to_call, char cmd, String message, uint8_t * symbols) + * fsq_dir_encode(char * from_call, char * to_call, char cmd, char * message, uint8_t * symbols) * * Takes an arbitrary message and returns a FSQ channel symbol table. * @@ -331,7 +303,7 @@ void JTEncode::fsq_encode(String from_call, String message, uint8_t * symbols) * plus 5 characters to the method. Terminated in 0xFF. * */ -void JTEncode::fsq_dir_encode(String from_call, String to_call, char cmd, String message, uint8_t * symbols) +void JTEncode::fsq_dir_encode(char * from_call, char * to_call, char cmd, char * message, uint8_t * symbols) { char tx_buffer[155]; char * tx_message; @@ -341,7 +313,7 @@ void JTEncode::fsq_dir_encode(String from_call, String to_call, char cmd, String // Generate a CRC on from_call // --------------------------- - from_call_crc = crc8(from_call.c_str()); + from_call_crc = crc8(from_call); // Clear out the transmit buffer // ----------------------------- @@ -351,7 +323,7 @@ void JTEncode::fsq_dir_encode(String from_call, String to_call, char cmd, String // We are building a directed message here. // FSQ very specifically needs " \b " in // directed mode to indicate EOT. A single backspace won't do it. - 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 "); + sprintf(tx_buffer, " \n%s:%02x%s%c%s%s", from_call, from_call_crc, to_call, cmd, message, " \b "); tx_message = tx_buffer; diff --git a/src/JTEncode.h b/src/JTEncode.h index d3892f9..446caa3 100644 --- a/src/JTEncode.h +++ b/src/JTEncode.h @@ -189,12 +189,12 @@ class JTEncode { public: JTEncode(void); - void jt65_encode(String, uint8_t *); - void jt9_encode(String, uint8_t *); - void jt4_encode(String, uint8_t *); - void wspr_encode(String, String, uint8_t, uint8_t *); - void fsq_encode(String, String, uint8_t *); - void fsq_dir_encode(String, String, char, String, uint8_t *); + void jt65_encode(char *, uint8_t *); + void jt9_encode(char *, uint8_t *); + void jt4_encode(char *, uint8_t *); + void wspr_encode(char *, char *, uint8_t, uint8_t *); + void fsq_encode(char *, char *, uint8_t *); + void fsq_dir_encode(char *, char *, char, char *, uint8_t *); private: uint8_t jt_code(char); uint8_t wspr_code(char);