diff options
-rw-r--r-- | lora_pkt_fwd/src/lora_pkt_fwd.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/lora_pkt_fwd/src/lora_pkt_fwd.c b/lora_pkt_fwd/src/lora_pkt_fwd.c index da65907..6d87f91 100644 --- a/lora_pkt_fwd/src/lora_pkt_fwd.c +++ b/lora_pkt_fwd/src/lora_pkt_fwd.c @@ -147,8 +147,10 @@ Maintainer: Michael Coracin #define MTS_IO_SYS "mts-io-sysfs store" #define LORA_PIN_LOW "/reset 0" #define LORA_PIN_HIGH "/reset 1" -#define LORA_PATH_AP1 "/dev/spidev32766.2" -#define LORA_PATH_AP2 "/dev/spidev32765.2" +#define LORA_PATH_OLD_AP1 "/dev/spidev32766.2" +#define LORA_PATH_OLD_AP2 "/dev/spidev32765.2" +#define LORA_PATH_AP1 "/dev/spidev0.2" +#define LORA_PATH_AP2 "/dev/spidev1.2" /* -------------------------------------------------------------------------- */ /* --- PRIVATE VARIABLES (GLOBAL) ------------------------------------------- */ @@ -1790,14 +1792,25 @@ int main(int argc, char** argv) char lora_port[5] = "lora"; /* path mapping for mts-io */ /* set custom SPI device path if configured */ if (strlen(spi_device_path) > 0) { - if (strcmp(spi_device_path, LORA_PATH_AP1) == 0) { + if (strcmp(spi_device_path, LORA_PATH_AP1) == 0 || + strcmp(spi_device_path, LORA_PATH_OLD_AP1) == 0) { snprintf(lora_port, sizeof lora_port, "%s", "ap1"); - } else if (strcmp(spi_device_path, LORA_PATH_AP2) == 0) { + } else if (strcmp(spi_device_path, LORA_PATH_AP2) == 0 || + strcmp(spi_device_path, LORA_PATH_OLD_AP2) == 0) { snprintf(lora_port, sizeof lora_port, "%s", "ap2"); } lgw_spi_set_path(spi_device_path); } + MSG("INFO: [main] resetting %s **************\n", lora_port); + + char cmd_pin_low[64]; + char cmd_pin_high[64]; + snprintf(cmd_pin_low, sizeof cmd_pin_low, "%s %s%s", MTS_IO_SYS, lora_port, LORA_PIN_LOW); + snprintf(cmd_pin_high, sizeof cmd_pin_high, "%s %s%s", MTS_IO_SYS, lora_port, LORA_PIN_HIGH); + system(cmd_pin_low); + wait_ms(250); + system(cmd_pin_high); /* starting the concentrator */ i = lgw_start(); @@ -1805,10 +1818,6 @@ int main(int argc, char** argv) MSG("INFO: [main] concentrator started, packet can now be received\n"); } else { MSG("ERROR: [main] failed to start the concentrator, resetting %s and trying again\n", lora_port); - char cmd_pin_low[64]; - char cmd_pin_high[64]; - snprintf(cmd_pin_low, sizeof cmd_pin_low, "%s %s%s", MTS_IO_SYS, lora_port, LORA_PIN_LOW); - snprintf(cmd_pin_high, sizeof cmd_pin_high, "%s %s%s", MTS_IO_SYS, lora_port, LORA_PIN_HIGH); system(cmd_pin_low); wait_ms(250); system(cmd_pin_high); @@ -2023,6 +2032,7 @@ int main(int argc, char** argv) if (restart_interval_minutes > 0 && (int)(difftimespec(check_time, start_time)) > (restart_interval_minutes * 60)) { // forcing a periodic restart MSG("INFO: periodic restart, process is exiting.\n"); + lgw_stop(); exit(1); } @@ -2371,6 +2381,7 @@ void thread_up(void) { MSG("ERROR: [up] received packet with unknown status\n"); memcpy((void *)(buff_up + buff_index), (void *)",\"stat\":?", 9); buff_index += 9; + lgw_stop(); exit(EXIT_FAILURE); } @@ -2409,6 +2420,7 @@ void thread_up(void) { MSG("ERROR: [up] lora packet with unknown datarate\n"); memcpy((void *)(buff_up + buff_index), (void *)",\"datr\":\"SF?", 12); buff_index += 12; + lgw_stop(); exit(EXIT_FAILURE); } switch (p->bandwidth) { @@ -2428,6 +2440,7 @@ void thread_up(void) { MSG("ERROR: [up] lora packet with unknown bandwidth\n"); memcpy((void *)(buff_up + buff_index), (void *)"BW?\"", 4); buff_index += 4; + lgw_stop(); exit(EXIT_FAILURE); } @@ -2457,6 +2470,7 @@ void thread_up(void) { MSG("ERROR: [up] lora packet with unknown coderate\n"); memcpy((void *)(buff_up + buff_index), (void *)",\"codr\":\"?\"", 11); buff_index += 11; + lgw_stop(); exit(EXIT_FAILURE); } @@ -2482,6 +2496,7 @@ void thread_up(void) { } } else { MSG("ERROR: [up] received packet with unknown modulation\n"); + lgw_stop(); exit(EXIT_FAILURE); } |