Skip to content

Commit

Permalink
V1.8.21 - Remove superfluous trailing zeroes from ASCII telemetry pro…
Browse files Browse the repository at this point in the history
…duced by HABPack decoder
  • Loading branch information
daveake committed May 9, 2018
1 parent 9c05f71 commit efaadfc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ Many thanks to David Brooke for coding this feature and the AFC.
Change History
==============

09/05/2018 - V1.8.21
--------------------

Remove superfluous trailing zeroes from the ASCII telemetry produced from HABPack

04/05/2018 - V1.8.20
--------------------

Expand Down
2 changes: 1 addition & 1 deletion gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "udpclient.h"
#include "lifo_buffer.h"

#define VERSION "V1.8.20"
#define VERSION "V1.8.21"
bool run = TRUE;

// RFM98
Expand Down
38 changes: 36 additions & 2 deletions habpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,41 @@ void Habpack_telem_store_field(received_t *Received, uint64_t map_id, char *fiel
value \
)

// sprintfs a real number without superfluous trailing zeroes.
// sprintf doesn't have that ability, hence this horrible little function
int snprintf_real(char *str, int max_len, double value)
{
int i, len;

len = snprintf(str, max_len, "%f,", value);

if (strchr(str, '.') != NULL)
{
// Just in case there's no dp in the resulting string. There should always be one (I think) but just in case ...

// Look backwards for first non-zero character, starting at the last digit in the string
for (i=len-2; i; i--)
{
if (str[i] != '0')
{
// Found a non zero
if (str[i] == '.')
{
// It's just zeroes after the dp, so we want to keep one zero, so step past that
i++;
}

// Add comma delimeter and null terminator, return the new length
str[++i] = ',';
str[++i] = '\0';
return i;
}
}
}

return len;
}

void Habpack_Telem_UKHAS_String(received_t *Received, char *ukhas_string, uint32_t max_length)
{
uint16_t crc;
Expand Down Expand Up @@ -270,10 +305,9 @@ void Habpack_Telem_UKHAS_String(received_t *Received, char *ukhas_string, uint32
}
else if(walk_ptr->value_type == HB_VALUE_REAL)
{
str_index += snprintf(
str_index += snprintf_real(
&ukhas_string[str_index],
(max_length - str_index),
"%f,",
walk_ptr->value.real
);
}
Expand Down

0 comments on commit efaadfc

Please sign in to comment.