Replace spaces in string parsing with non-printable 0x7F for correct passthrough in radio

This commit is contained in:
Ed Gonzalez 2015-03-12 14:53:51 -05:00
parent 637e3376a0
commit 5cd5b63b7e
5 changed files with 27 additions and 2 deletions

View file

@ -265,6 +265,7 @@ uint32 cmd_slice(int requester_fd, int argc, char **argv)
if(strncmp(argv[2], "string", strlen("string")) == 0) if(strncmp(argv[2], "string", strlen("string")) == 0)
{ {
char* new_string = argv[2]+strlen("string")+1; char* new_string = argv[2]+strlen("string")+1;
charReplace(new_string, (char) 0x7F, ' ');
freedv_set_string(slc, new_string); freedv_set_string(slc, new_string);
return SUCCESS; return SUCCESS;
} }

View file

@ -196,8 +196,14 @@ Circular_Float_Buffer TX4_cb = &tx4_cb;
void my_put_next_rx_char(void *callback_state, char c) void my_put_next_rx_char(void *callback_state, char c)
{ {
char new_char[2]; char new_char[2];
new_char[0] = c; if ( c == ' ' ) {
/* Encode spaces differently */
new_char[0] = (char) 0x7F;
} else {
new_char[0] = c;
}
new_char[1] = 0; new_char[1] = 0;
strncat(_rx_string, new_char, MAX_RX_STRING_LENGTH+4); strncat(_rx_string, new_char, MAX_RX_STRING_LENGTH+4);
if (strlen(_rx_string) > MAX_RX_STRING_LENGTH) if (strlen(_rx_string) > MAX_RX_STRING_LENGTH)
{ {

View file

@ -177,7 +177,7 @@ uint32 register_mode(void)
} }
/* Transfer data expecting to encounter end of input (or an error) */ /* Transfer data expecting to encounter end of input (or an error) */
inputBuffer = (char *) malloc (nbytes + 1); // Initial buffer size inputBuffer = (char *) safe_malloc (nbytes + 1); // Initial buffer size
readFlag = TRUE; readFlag = TRUE;
while(readFlag) // Look for the start of the [header] while(readFlag) // Look for the start of the [header]
@ -186,6 +186,7 @@ uint32 register_mode(void)
if (numRead == -1) if (numRead == -1)
{ {
output(ANSI_YELLOW"Error reading config file %s\n", cfg_file); output(ANSI_YELLOW"Error reading config file %s\n", cfg_file);
safe_free(inputBuffer);
return 999; return 999;
} }

View file

@ -140,3 +140,19 @@ void printIP(uint32 ip)
output("%d.%d.%d.%d\n",((ip>>24)& 0xFF),((ip>>16)& 0xFF),((ip>>8)& 0xFF),(ip & 0xFF)); output("%d.%d.%d.%d\n",((ip>>24)& 0xFF),((ip>>16)& 0xFF),((ip>>8)& 0xFF),(ip & 0xFF));
} }
void charReplace( char * string, char oldChar, char newChar )
{
if ( string == NULL ) {
output("Null string passed to charReplace\n");
return ;
}
while (*string != 0 ) {
if ( *string == oldChar )
*string = newChar;
string++;
}
}

View file

@ -45,5 +45,6 @@ void lock_malloc_init(void);
void* safe_malloc(size_t size); void* safe_malloc(size_t size);
void safe_free(void* ptr); void safe_free(void* ptr);
void printIP(uint32 ip); void printIP(uint32 ip);
void charReplace( char * string, char oldChar, char newChar );
#endif /* UTILS_H_ */ #endif /* UTILS_H_ */