kopia lustrzana https://github.com/PiInTheSky/lora-gateway
V1.8.21 - Remove superfluous trailing zeroes from ASCII telemetry produced by HABPack decoder
rodzic
9c05f71dd6
commit
efaadfc1a6
|
@ -227,6 +227,11 @@ Many thanks to David Brooke for coding this feature and the AFC.
|
||||||
Change History
|
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
|
04/05/2018 - V1.8.20
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#include "udpclient.h"
|
#include "udpclient.h"
|
||||||
#include "lifo_buffer.h"
|
#include "lifo_buffer.h"
|
||||||
|
|
||||||
#define VERSION "V1.8.20"
|
#define VERSION "V1.8.21"
|
||||||
bool run = TRUE;
|
bool run = TRUE;
|
||||||
|
|
||||||
// RFM98
|
// RFM98
|
||||||
|
|
38
habpack.c
38
habpack.c
|
@ -222,6 +222,41 @@ void Habpack_telem_store_field(received_t *Received, uint64_t map_id, char *fiel
|
||||||
value \
|
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)
|
void Habpack_Telem_UKHAS_String(received_t *Received, char *ukhas_string, uint32_t max_length)
|
||||||
{
|
{
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
|
@ -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)
|
else if(walk_ptr->value_type == HB_VALUE_REAL)
|
||||||
{
|
{
|
||||||
str_index += snprintf(
|
str_index += snprintf_real(
|
||||||
&ukhas_string[str_index],
|
&ukhas_string[str_index],
|
||||||
(max_length - str_index),
|
(max_length - str_index),
|
||||||
"%f,",
|
|
||||||
walk_ptr->value.real
|
walk_ptr->value.real
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue