From 0b271f95b3d11ff70a82992cdc50ff8045355190 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Thu, 1 Apr 2021 12:17:46 +0200 Subject: [PATCH] libpax integration 6 (trigger sendcycle) --- README.md | 2 +- include/libpax_helpers.h | 6 ++++-- include/senddata.h | 1 - src/libpax_helpers.cpp | 5 +++-- src/main.cpp | 13 ++++++------- src/rcommand.cpp | 3 ++- src/reset.cpp | 2 +- src/senddata.cpp | 2 -- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 85e67dca..57601bd0 100644 --- a/README.md +++ b/README.md @@ -443,7 +443,7 @@ Send for example `83` `86` as Downlink on Port 2 to get battery status and time/ 8 = reboot device to maintenance mode (local web server) 9 = reboot device to OTA update via Wifi mode -0x0A set LoRaWAN payload send cycle +0x0A set payload send cycle 0 ... 255 payload send cycle in seconds/2 e.g. 120 -> payload is transmitted each 240 seconds [default] diff --git a/include/libpax_helpers.h b/include/libpax_helpers.h index 59749226..e11958ec 100644 --- a/include/libpax_helpers.h +++ b/include/libpax_helpers.h @@ -1,11 +1,13 @@ #ifndef _LIBPAX_HELPERS_H #define _LIBPAX_HELPERS_H -#include "globals.h" #include #include +#include "globals.h" +#include "senddata.h" +#include "configmanager.h" -void init_libpax(); +void init_libpax(void); extern uint16_t volatile libpax_macs_ble, libpax_macs_wifi; // libpax values diff --git a/include/senddata.h b/include/senddata.h index cc00c796..41cad9a3 100644 --- a/include/senddata.h +++ b/include/senddata.h @@ -16,7 +16,6 @@ #endif extern struct count_payload_t count_from_libpax; -extern Ticker sendTimer; void SendPayload(uint8_t port); void sendData(void); diff --git a/src/libpax_helpers.cpp b/src/libpax_helpers.cpp index 4cecebbd..3c25856e 100644 --- a/src/libpax_helpers.cpp +++ b/src/libpax_helpers.cpp @@ -12,10 +12,11 @@ void process_count(void) { count_from_libpax.wifi_count, count_from_libpax.ble_count); libpax_macs_ble = count_from_libpax.ble_count; libpax_macs_wifi = count_from_libpax.wifi_count; + setSendIRQ(); } -void init_libpax() { - libpax_counter_init(process_count, &count_from_libpax, SENDCYCLE * 2 * 1000, +void init_libpax(void) { + libpax_counter_init(process_count, &count_from_libpax, cfg.sendcycle * 2 * 1000, 1); libpax_counter_start(); } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 9337375c..00d768ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,11 +65,11 @@ MatrixDisplayIRQ-> esp32 timer 3 ButtonIRQ -> external GPIO PMUIRQ -> PMU chip GPIO -fired by software (Ticker.h) -TIMESYNC_IRQ -> setTimeSyncIRQ() -CYCLIC_IRQ -> setCyclicIRQ() -SENDCYCLE_IRQ -> setSendIRQ() -BME_IRQ -> setBMEIRQ() +fired by software +TIMESYNC_IRQ -> setTimeSyncIRQ() -> Ticker.h +CYCLIC_IRQ -> setCyclicIRQ() -> Ticker.h +SENDCYCLE_IRQ -> setSendIRQ() -> xTimer +BME_IRQ -> setBMEIRQ() -> Ticker.h ClockTask (Core 1), see timekeeper.cpp @@ -89,7 +89,7 @@ triggers pps 1 sec impulse // local Tag for logging static const char TAG[] = __FILE__; -char clientId[20] = {0}; // unique ClientID +char clientId[20] = {0}; // unique ClientID void setup() { @@ -484,7 +484,6 @@ void setup() { #endif // HAS_BUTTON // cyclic function interrupts - sendTimer.attach(cfg.sendcycle * 2, setSendIRQ); cyclicTimer.attach(HOMECYCLE, setCyclicIRQ); // only if we have a timesource we do timesync diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 32df1207..346be53c 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -67,9 +67,10 @@ void set_rssi(uint8_t val[]) { void set_sendcycle(uint8_t val[]) { cfg.sendcycle = val[0]; // update send cycle interrupt [seconds / 2] - sendTimer.attach(cfg.sendcycle * 2, setSendIRQ); ESP_LOGI(TAG, "Remote command: set send cycle to %d seconds", cfg.sendcycle * 2); + libpax_counter_stop(); + init_libpax(); } void set_sleepcycle(uint8_t val[]) { diff --git a/src/reset.cpp b/src/reset.cpp index e7525ac3..d8dcf153 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -102,7 +102,7 @@ void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) { wakeup_gpio = GPIO_NUM_MAX; // stop further enqueuing of senddata and MAC processing - sendTimer.detach(); + libpax_counter_stop(); // switch off radio and other power consuming hardware #if (HAS_SDS011) diff --git a/src/senddata.cpp b/src/senddata.cpp index d7665526..a21ab7ae 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -1,8 +1,6 @@ // Basic Config #include "senddata.h" -Ticker sendTimer; - void setSendIRQ() { xTaskNotify(irqHandlerTask, SENDCYCLE_IRQ, eSetBits); } // put data to send in RTos Queues used for transmit over channels Lora and SPI