From e37dae601de2bd1bc8fa821f96f567e608b05b8b Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 12 Mar 2023 14:01:47 +0100 Subject: [PATCH] add rcommand 0x0d set wakeupsync --- docs/remotecontrol.md | 5 +++++ include/globals.h | 3 ++- src/configmanager.cpp | 2 +- src/rcommand.cpp | 31 ++++++++++++++++++------------- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/docs/remotecontrol.md b/docs/remotecontrol.md index b1faafc3..d573ca12 100644 --- a/docs/remotecontrol.md +++ b/docs/remotecontrol.md @@ -91,6 +91,11 @@ Send for example `83` `86` as Downlink on Port 2 to get battery status and time/ 0 ... 255 duration for scanning a bluetooth advertising channel in seconds/100 e.g. 8 -> each channel is scanned for 80 milliseconds [default] +#### 0x0D set wakeup sync window + + bytes 1..2 = wakeup sync window size in seconds (MSB), 0..255 (0 = no wakuep sync) + e.g. {0x02, 0x58} -> device adjusts it's wakeup time when it is +/- 5 minutes from top-of-hour [default = 0] + #### 0x0E set Bluetooth scanner 0 = disabled diff --git a/include/globals.h b/include/globals.h index 35adfb7e..0b042d50 100644 --- a/include/globals.h +++ b/include/globals.h @@ -64,6 +64,7 @@ typedef struct __attribute__((packed)) { int16_t rssilimit; // threshold for rssilimiter, negative value! uint8_t sendcycle; // payload send cycle [seconds/2] uint16_t sleepcycle; // sleep cycle [seconds/10] + uint16_t wakesync; // time window [seconds] to sync wakeup on top-of-hour uint8_t wifichancycle; // wifi channel switch cycle [seconds/100] uint8_t blescantime; // BLE scan cycle duration [seconds] uint8_t blescan; // 0=disabled, 1=enabled @@ -109,6 +110,6 @@ typedef struct { float pm25; } sdsStatus_t; -extern char clientId[20]; // unique clientID +extern char clientId[20]; // unique clientID #endif \ No newline at end of file diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 7d6181bf..3360a4ef 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -3,7 +3,6 @@ #include "globals.h" #include "configmanager.h" - // namespace for device runtime preferences #define DEVCONFIG "paxcntcfg" @@ -38,6 +37,7 @@ static void defaultConfig(configData_t *myconfig) { myconfig->rssilimit = RSSILIMIT; // threshold for rssilimiter, negative value! myconfig->sendcycle = SENDCYCLE; // payload send cycle [seconds/2] myconfig->sleepcycle = SLEEPCYCLE; // sleep cycle [seconds/10] + myconfig->wakesync = SYNCWAKEUP; // wakeup sync window [seconds] myconfig->wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100] myconfig->blescantime = diff --git a/src/rcommand.cpp b/src/rcommand.cpp index fbdb833f..55751f98 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -2,7 +2,6 @@ #include "globals.h" #include "rcommand.h" - static QueueHandle_t RcmdQueue; TaskHandle_t rcmdTask; @@ -80,6 +79,12 @@ void set_sleepcycle(uint8_t val[]) { cfg.sleepcycle * 10); } +void set_wakesync(uint8_t val[]) { + // swap byte order from msb to lsb, note: this is a platform dependent hack + cfg.wakesync = __builtin_bswap16(*(uint16_t *)(val)); + ESP_LOGI(TAG, "Remote command: set wakesync to %hu seconds", cfg.wakesync); +} + void set_wifichancycle(uint8_t val[]) { cfg.wifichancycle = val[0]; libpax_counter_stop(); @@ -369,7 +374,7 @@ void set_timesync(uint8_t val[]) { void set_time(uint8_t val[]) { // swap byte order from msb to lsb, note: this is a platform dependent hack uint32_t t = __builtin_bswap32(*(uint32_t *)(val)); - ESP_LOGI(TAG, "Remote command: set time to %d", t); + ESP_LOGI(TAG, "Remote command: set time to %lu", t); setMyTime(t, 0, _set); }; @@ -399,17 +404,17 @@ static const cmd_t table[] = { {0x07, set_loraadr, 1}, {0x08, set_screensaver, 1}, {0x09, set_reset, 1}, {0x0a, set_sendcycle, 1}, {0x0b, set_wifichancycle, 1}, {0x0c, set_blescantime, 1}, - {0x0e, set_blescan, 1}, {0x0f, set_wifiant, 1}, - {0x10, set_rgblum, 1}, {0x13, set_sensor, 2}, - {0x14, set_payloadmask, 1}, {0x15, set_bme, 1}, - {0x16, set_batt, 1}, {0x17, set_wifiscan, 1}, - {0x18, set_flush, 0}, {0x19, set_sleepcycle, 2}, - {0x20, set_loadconfig, 0}, {0x21, set_saveconfig, 0}, - {0x80, get_config, 0}, {0x81, get_status, 0}, - {0x83, get_batt, 0}, {0x84, get_gps, 0}, - {0x85, get_bme, 0}, {0x86, get_time, 0}, - {0x87, set_timesync, 0}, {0x88, set_time, 4}, - {0x99, set_flush, 0}}; + {0x0d, set_wakesync, 2}, {0x0e, set_blescan, 1}, + {0x0f, set_wifiant, 1}, {0x10, set_rgblum, 1}, + {0x13, set_sensor, 2}, {0x14, set_payloadmask, 1}, + {0x15, set_bme, 1}, {0x16, set_batt, 1}, + {0x17, set_wifiscan, 1}, {0x18, set_flush, 0}, + {0x19, set_sleepcycle, 2}, {0x20, set_loadconfig, 0}, + {0x21, set_saveconfig, 0}, {0x80, get_config, 0}, + {0x81, get_status, 0}, {0x83, get_batt, 0}, + {0x84, get_gps, 0}, {0x85, get_bme, 0}, + {0x86, get_time, 0}, {0x87, set_timesync, 0}, + {0x88, set_time, 4}, {0x99, set_flush, 0}}; static const uint8_t cmdtablesize = sizeof(table) / sizeof(table[0]); // number of commands in command table