Skip to content

Commit

Permalink
Changed String back to char *, too many memory problems
Browse files Browse the repository at this point in the history
  • Loading branch information
NT7S committed Jul 11, 2016
1 parent cb87ffa commit 01fc48d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 71 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
*
Expand All @@ -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.
*
Expand All @@ -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
Expand All @@ -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

Expand Down
11 changes: 4 additions & 7 deletions examples/Si5351JTDemo/Si5351JTDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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

Expand Down
72 changes: 22 additions & 50 deletions src/JTEncode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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
// ---------------------
Expand All @@ -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.
Expand All @@ -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
// ---------------------
Expand All @@ -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.
Expand All @@ -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
// ---------------------
Expand All @@ -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
*
Expand All @@ -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
// -----------
Expand All @@ -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.
*
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
Expand All @@ -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
// -----------------------------
Expand All @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/JTEncode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 01fc48d

Please sign in to comment.