Skip to content
Merged
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
16 changes: 15 additions & 1 deletion coco/src/fn_network/network_json_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ int16_t network_json_query(const char *devicespec, const char *query, char *s)
uint16_t bw=0;
uint8_t c=0, err=0;
uint8_t unit = network_unit(devicespec);
char ch;
unsigned short offset = 0;

jq.opcode = OP_NET;
jq.unit = unit;
Expand All @@ -35,5 +37,17 @@ int16_t network_json_query(const char *devicespec, const char *query, char *s)
if (!bw)
return 0;

return network_read(devicespec, (uint8_t *)s, bw);
if (network_read(devicespec, (uint8_t *)s, bw) > 0)
{
// if last char is 0x9b, 0x0A or 0x0D, then set that char to nul, else just null terminate
ch = s[bw - 1];
if (ch == 0x9B || ch == 0x0A || ch == 0x0D)
{
offset = 1;
}
s[bw - offset] = '\0';
}

// return the string length (minus any trailing EOL char)
return bw - offset;
}
16 changes: 15 additions & 1 deletion msdos/src/fn_network/network_json_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ int16_t network_json_query(const char *devicespec, const char *query, char *s)
uint8_t ret = 0;
uint8_t c=0, err=0;
uint16_t bw=0;
char ch;
unsigned short offset = 0;

// Perform query
ret = int_f5_write(device,'Q',0x00,0x00,(void *)query,256);
Expand All @@ -20,6 +22,18 @@ int16_t network_json_query(const char *devicespec, const char *query, char *s)

if (!bw)
return 0;

if (network_read(devicespec, (uint8_t *)s, bw) > 0)
{
// if last char is 0x9b, 0x0A or 0x0D, then set that char to nul, else just null terminate
ch = s[bw - 1];
if (ch == 0x9B || ch == 0x0A || ch == 0x0D)
{
offset = 1;
}
s[bw - offset] = '\0';
}

return network_read(devicespec,(uint8_t *)s, bw);
// return the string length (minus any trailing EOL char)
return bw - offset;
}