Skip to content

Commit

Permalink
Prvent showing unavailable strings because sometimes GPS decoding has…
Browse files Browse the repository at this point in the history
… not yet succeeded.
  • Loading branch information
iPAS committed Jun 16, 2021
1 parent a03b808 commit 9d7d9d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/axp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ static AXP20X_Class axp;
static uint32_t next_axp_log_millis;
static uint32_t next_axp_report_millis;

static char str_axp_temp[10];
static char str_axp_bus[20];
static char str_axp_bat[60];
static char str_axp_temp[10] = {'\0'};
static char str_axp_bus[20] = {'\0'};
static char str_axp_bat[60] = {'\0'};

// ----------------------------------------------------------------------------
bool axp_setup() {
Expand Down Expand Up @@ -113,6 +113,8 @@ void axp_update_data() {

// ----------------------------------------------------------------------------
char *axp_update_str(const char *fmt) {
if (str_axp_temp[0] == '\0' || str_axp_bus[0] == '\0' || str_axp_bat[0] == '\0') return NULL;

static char str[sizeof(str_axp_temp) + sizeof(str_axp_bus) + sizeof(str_axp_bat) + 10];
snprintf(str, sizeof(str), fmt, str_axp_temp, str_axp_bus, str_axp_bat);
return str;
Expand Down
8 changes: 5 additions & 3 deletions src/gps.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ static TinyGPSPlus gps;
static uint32_t next_gps_stamp_millis;
static uint32_t next_gps_report_millis;

static char str_gps_datetime[20];
static char str_gps_loc[32];
static char str_gps_quality[10];
static char str_gps_datetime[20] = {'\0'};
static char str_gps_loc[32] = {'\0'};
static char str_gps_quality[10] = {'\0'};

// ----------------------------------------------------------------------------
void gps_setup(bool do_axp_exist) {
Expand Down Expand Up @@ -91,6 +91,8 @@ void gps_update_data() {

// ----------------------------------------------------------------------------
char *gps_update_str(const char *fmt) {
if (str_gps_datetime[0] == '\0' || str_gps_loc[0] == '\0' || str_gps_quality[0] == '\0') return NULL;

static char str[sizeof(str_gps_datetime) + sizeof(str_gps_loc) + sizeof(str_gps_quality) + 10];
snprintf(str, sizeof(str), fmt, str_gps_datetime, str_gps_loc, str_gps_quality);
return str;
Expand Down
8 changes: 8 additions & 0 deletions src/lora.ino
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ bool report_status_to(Address sink) {
// ----------------------------------------------------------------------------
bool report_gps_to(Address sink) {
char *str = gps_update_str("@GPS %s\n%s\n%s\n");
if (str == NULL) {
term_println("[LORA] report_gps_to(): gps_update_str() return NULL!");
return false;
}
uint8_t cnt = strlen(str);

term_printf("[LORA] Report GPS node %d to %d, %d bytes:", getAddress(), sink, cnt);
Expand All @@ -118,6 +122,10 @@ bool report_gps_to(Address sink) {
// ----------------------------------------------------------------------------
bool report_axp_to(Address sink) {
char *str = axp_update_str("@AXP %s\n%s\n%s\n");
if (str == NULL) {
term_println("[LORA] report_axp_to(): axp_update_str() return NULL!");
return false;
}
uint8_t cnt = strlen(str);

term_printf("[LORA] Report AXP node %d to %d, %d bytes:", getAddress(), sink, cnt);
Expand Down

0 comments on commit 9d7d9d1

Please sign in to comment.