Skip to content

FT8 HEX message fix #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 28 additions & 37 deletions src/JTEncode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void JTEncode::jt65_encode(const char * msg, uint8_t * symbols)
{
char message[14];
memset(message, 0, 14);
strcpy(message, msg);
strncpy(message, msg, 13);

// Ensure that the message text conforms to standards
// --------------------------------------------------
Expand Down Expand Up @@ -111,7 +111,7 @@ void JTEncode::jt9_encode(const char * msg, uint8_t * symbols)
{
char message[14];
memset(message, 0, 14);
strcpy(message, msg);
strncpy(message, msg, 13);

// Ensure that the message text conforms to standards
// --------------------------------------------------
Expand Down Expand Up @@ -160,7 +160,7 @@ void JTEncode::jt4_encode(const char * msg, uint8_t * symbols)
{
char message[14];
memset(message, 0, 14);
strcpy(message, msg);
strncpy(message, msg, 13);

// Ensure that the message text conforms to standards
// --------------------------------------------------
Expand Down Expand Up @@ -205,11 +205,13 @@ void JTEncode::wspr_encode(const char * call, const char * loc, const int8_t dbm
char call_[13];
char loc_[7];
uint8_t dbm_ = dbm;
strcpy(call_, call);
strcpy(loc_, loc);
snprintf(call_, 13, "%.12s", call);
snprintf(loc_, 7, "%.6s", loc);

// Ensure that the message text conforms to standards
// --------------------------------------------------
//:w

wspr_message_prep(call_, loc_, dbm_);

// Bit packing
Expand Down Expand Up @@ -427,7 +429,7 @@ void JTEncode::ft8_encode(const char * msg, uint8_t * symbols)

char message[19];
memset(message, 0, 19);
strcpy(message, msg);
strncpy(message, msg, 18);

// Bit packing
// -----------
Expand Down Expand Up @@ -496,7 +498,7 @@ void JTEncode::latlon_to_grid(float lat, float lon, char* ret_grid)
grid[4] = (char)((uint8_t)(lon * 12) + 'a');
grid[5] = (char)((uint8_t)(lat * 24) + 'a');

strncpy(ret_grid, grid, 6);
strncpy(ret_grid, grid, 7);
}

/* Private Class Members */
Expand Down Expand Up @@ -687,7 +689,7 @@ void JTEncode::wspr_message_prep(char * call, char * loc, int8_t dbm)
}
call[12] = 0;

strncpy(callsign, call, 12);
strncpy(callsign, call, 13);

// Grid locator validation
if(strlen(loc) == 4 || strlen(loc) == 6)
Expand Down Expand Up @@ -1075,9 +1077,7 @@ void JTEncode::ft8_bit_packing(char* message, uint8_t* codeword)
uint8_t n3 = 0;
uint8_t qa[10];
uint8_t qb[10];
char c18[19];
bool telem = false;
char temp_msg[19];
memset(qa, 0, 10);
memset(qb, 0, 10);

Expand All @@ -1088,51 +1088,42 @@ void JTEncode::ft8_bit_packing(char* message, uint8_t* codeword)
// Has to be hex digits, can be no more than 18
for(i = 0; i < 19; ++i)
{
if(message[i] == 0 || message[i] == ' ')
if(message[i] == 0)
{
break;
}
// bugfix: "73 DL9SAU" was interpreted as hex message. Check further for non-hex-character
else if (message[i] == ' ')
continue;
else if(hex2int(message[i]) == -1)
{
telem = false;
break;
}
else
{
c18[i] = message[i];
telem = true;
}
}

// If telemetry
if(telem)
{
// Get the first 18 hex digits
for(i = 0; i < strlen(message); ++i)
{
i0 = i;
if(message[i] == ' ')
{
--i0;
break;
}
char *p;

// skip leading blanks
for (p = message; *p == ' '; p++) ;
{ char buf[19];
char *q = buf;
// Copy until end or first ' ' ("AA BB" is invalid),
// and convert all chars to uppercase.
while (*p && *p != ' ')
*q++ = toupper(*p++);
*q = 0;
// right-align
sprintf(message, "%18.18s", buf);
}

memset(c18, 0, 19);
memmove(c18, message, i0 + 1);
snprintf(temp_msg, 19, "%*s", 18, c18);

// Convert all chars to uppercase
for(i = 0; i < strlen(temp_msg); i++)
{
if(islower(temp_msg[i]))
{
temp_msg[i] = toupper(temp_msg[i]);
}
}
strcpy(message, temp_msg);


uint8_t temp_int;
temp_int = message[0] == ' ' ? 0 : hex2int(message[0]);
for(i = 1; i < 4; ++i)
Expand Down Expand Up @@ -1645,4 +1636,4 @@ void JTEncode::pad_callsign(char * call)
// {
// // return 1;
// }
}
}
2 changes: 1 addition & 1 deletion src/JTEncode.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class JTEncode
uint8_t crc8(const char *);
void pad_callsign(char *);
void * rs_inst;
char callsign[12];
char callsign[13];
char locator[7];
int8_t power;
};
Expand Down