repair wifichancycle

This commit is contained in:
Klaus K Wilting 2018-04-28 14:09:27 +02:00
parent 37005a2087
commit 589058d7c5
7 changed files with 49 additions and 46 deletions

View File

@ -21,7 +21,7 @@ void antenna_init(void) {
gpio_config(&gpioconf); gpio_config(&gpioconf);
} }
void antenna_select (const int8_t _ant) { void antenna_select (const uint8_t _ant) {
if (HAS_ANTENNA_SWITCH < 32) { if (HAS_ANTENNA_SWITCH < 32) {
if (_ant == ANTENNA_EXT) { if (_ant == ANTENNA_EXT) {
GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, 1 << HAS_ANTENNA_SWITCH); GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, 1 << HAS_ANTENNA_SWITCH);

View File

@ -13,7 +13,7 @@ esp_err_t err;
// defined in antenna.cpp // defined in antenna.cpp
#ifdef HAS_ANTENNA_SWITCH #ifdef HAS_ANTENNA_SWITCH
void antenna_select(const int8_t _ant); void antenna_select(const uint8_t _ant);
#endif #endif
// populate cfg vars with factory settings // populate cfg vars with factory settings

View File

@ -26,20 +26,20 @@
// Struct holding devices's runtime configuration // Struct holding devices's runtime configuration
typedef struct { typedef struct {
int8_t lorasf; // 7-12, lora spreadfactor uint8_t lorasf; // 7-12, lora spreadfactor
int8_t txpower; // 2-15, lora tx power uint8_t txpower; // 2-15, lora tx power
int8_t adrmode; // 0=disabled, 1=enabled uint8_t adrmode; // 0=disabled, 1=enabled
int8_t screensaver; // 0=disabled, 1=enabled uint8_t screensaver; // 0=disabled, 1=enabled
int8_t screenon; // 0=disabled, 1=enabled uint8_t screenon; // 0=disabled, 1=enabled
int8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed uint8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed
int16_t rssilimit; // threshold for rssilimiter, negative value! int16_t rssilimit; // threshold for rssilimiter, negative value!
int8_t sendcycle; // payload send cycle [seconds/2] uint8_t sendcycle; // payload send cycle [seconds/2]
int8_t wifichancycle; // wifi channel switch cycle [seconds/100] uint8_t wifichancycle; // wifi channel switch cycle [seconds/100]
int8_t blescantime; // BLE scan cycle duration [seconds] uint8_t blescantime; // BLE scan cycle duration [seconds]
int8_t blescan; // 0=disabled, 1=enabled uint8_t blescan; // 0=disabled, 1=enabled
int8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4) uint8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4)
int8_t vendorfilter; // 0=disabled, 1=enabled uint8_t vendorfilter; // 0=disabled, 1=enabled
int8_t rgblum; // RGB Led luminosity (0..100%) uint8_t rgblum; // RGB Led luminosity (0..100%)
char version[10]; // Firmware version char version[10]; // Firmware version
} configData_t; } configData_t;
@ -51,7 +51,8 @@ extern char display_lora[], display_lmic[];
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim; extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
extern uint16_t macs_total, macs_wifi, macs_ble; // MAC counters extern uint16_t macs_total, macs_wifi, macs_ble; // MAC counters
extern bool joinstate; extern bool joinstate;
extern std::set<uint16_t> macs; extern std::set<uint16_t> macs;
extern hw_timer_t * channelSwitch; // hardware timer used for wifi channel switching
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
extern HAS_DISPLAY u8x8; extern HAS_DISPLAY u8x8;

View File

@ -14,8 +14,8 @@
static const char *TAG = "lorawan"; static const char *TAG = "lorawan";
// functions defined in rcommand.cpp // functions defined in rcommand.cpp
void rcommand(int cmd, int arg); void rcommand(uint8_t cmd, uint8_t arg);
void switch_lora(int sf, int tx); void switch_lora(uint8_t sf, uint8_t tx);
// DevEUI generator using devices's MAC address // DevEUI generator using devices's MAC address
void gen_lora_deveui(uint8_t *pdeveui) { void gen_lora_deveui(uint8_t *pdeveui) {

View File

@ -192,7 +192,7 @@ void lorawan_loop(void * pvParameters) {
#ifdef HAS_ANTENNA_SWITCH #ifdef HAS_ANTENNA_SWITCH
// defined in antenna.cpp // defined in antenna.cpp
void antenna_init(); void antenna_init();
void antenna_select(const int8_t _ant); void antenna_select(const uint8_t _ant);
#endif #endif
#ifndef BLECOUNTER #ifndef BLECOUNTER
@ -562,7 +562,7 @@ void setup() {
// setup channel rotation IRQ, thanks to https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/ // setup channel rotation IRQ, thanks to https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
channelSwitch = timerBegin(1, 80, true); // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 1, count up channelSwitch = timerBegin(1, 80, true); // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 1, count up
timerAttachInterrupt(channelSwitch, &ChannelSwitchIRQ, true); // interrupt handler, triggered by edge timerAttachInterrupt(channelSwitch, &ChannelSwitchIRQ, true); // interrupt handler, triggered by edge
timerAlarmWrite(channelSwitch, WIFI_CHANNEL_SWITCH_INTERVAL * 10000, true); // reload interrupt after each trigger of channel switch cycle timerAlarmWrite(channelSwitch, cfg.wifichancycle * 10000, true); // reload interrupt after each trigger of channel switch cycle
timerAlarmEnable(channelSwitch); // enable channel switching interrupt timerAlarmEnable(channelSwitch); // enable channel switching interrupt
// show compiled features // show compiled features

View File

@ -1,6 +1,6 @@
// program version - note: increment version after modifications to configData_t struct!! // program version - note: increment version after modifications to configData_t struct!!
#define PROGVERSION "1.3.34" // use max 10 chars here! #define PROGVERSION "1.3.35" // use max 10 chars here!
#define PROGNAME "PAXCNT" #define PROGNAME "PAXCNT"
//--- Declarations --- //--- Declarations ---

View File

@ -14,18 +14,18 @@ static const char *TAG = "rcommand";
// table of remote commands and assigned functions // table of remote commands and assigned functions
typedef struct { typedef struct {
const int nam; const uint8_t nam;
void (*func)(int); void (*func)(uint8_t);
const bool store; const bool store;
} cmd_t; } cmd_t;
// function defined in antenna.cpp // function defined in antenna.cpp
#ifdef HAS_ANTENNA_SWITCH #ifdef HAS_ANTENNA_SWITCH
void antenna_select(const int8_t _ant); void antenna_select(const uint8_t _ant);
#endif #endif
// help function to assign LoRa datarates to numeric spreadfactor values // help function to assign LoRa datarates to numeric spreadfactor values
void switch_lora (int sf, int tx) { void switch_lora (uint8_t sf, uint8_t tx) {
if ( tx > 20 ) return; if ( tx > 20 ) return;
cfg.txpower = tx; cfg.txpower = tx;
switch (sf) { switch (sf) {
@ -50,7 +50,7 @@ void switch_lora (int sf, int tx) {
} }
// set of functions that can be triggered by remote commands // set of functions that can be triggered by remote commands
void set_reset(int val) { void set_reset(uint8_t val) {
switch (val) { switch (val) {
case 0: // restart device case 0: // restart device
ESP_LOGI(TAG, "Remote command: restart device"); ESP_LOGI(TAG, "Remote command: restart device");
@ -72,27 +72,29 @@ void set_reset(int val) {
} }
}; };
void set_rssi(int val) { void set_rssi(uint8_t val) {
cfg.rssilimit = val * -1; cfg.rssilimit = val * -1;
ESP_LOGI(TAG, "Remote command: set RSSI limit to %d", cfg.rssilimit); ESP_LOGI(TAG, "Remote command: set RSSI limit to %d", cfg.rssilimit);
}; };
void set_sendcycle(int val) { void set_sendcycle(uint8_t val) {
cfg.sendcycle = val; cfg.sendcycle = val;
ESP_LOGI(TAG, "Remote command: set payload send cycle to %d seconds", cfg.sendcycle*2); ESP_LOGI(TAG, "Remote command: set payload send cycle to %d seconds", cfg.sendcycle*2);
}; };
void set_wifichancycle(int val) { void set_wifichancycle(uint8_t val) {
cfg.wifichancycle = val; cfg.wifichancycle = val;
ESP_LOGI(TAG, "Remote command: set Wifi channel switch interval to %d seconds", cfg.wifichancycle/100); // modify wifi channel rotation IRQ
timerAlarmWrite(channelSwitch, cfg.wifichancycle * 10000, true); // reload interrupt after each trigger of channel switch cycle
ESP_LOGI(TAG, "Remote command: set Wifi channel switch interval to %.1f seconds", cfg.wifichancycle/float(100));
}; };
void set_blescantime(int val) { void set_blescantime(uint8_t val) {
cfg.blescantime = val; cfg.blescantime = val;
ESP_LOGI(TAG, "Remote command: set BLE scan time to %d seconds", cfg.blescantime); ESP_LOGI(TAG, "Remote command: set BLE scan time to %d seconds", cfg.blescantime);
}; };
void set_countmode(int val) { void set_countmode(uint8_t val) {
switch (val) { switch (val) {
case 0: // cyclic unconfirmed case 0: // cyclic unconfirmed
cfg.countermode = 0; cfg.countermode = 0;
@ -109,7 +111,7 @@ void set_countmode(int val) {
} }
}; };
void set_screensaver(int val) { void set_screensaver(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set screen saver to %s ", val ? "on" : "off"); ESP_LOGI(TAG, "Remote command: set screen saver to %s ", val ? "on" : "off");
switch (val) { switch (val) {
case 1: cfg.screensaver = val; break; case 1: cfg.screensaver = val; break;
@ -117,7 +119,7 @@ void set_screensaver(int val) {
} }
}; };
void set_display(int val) { void set_display(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set screen to %s", val ? "on" : "off"); ESP_LOGI(TAG, "Remote command: set screen to %s", val ? "on" : "off");
switch (val) { switch (val) {
case 1: cfg.screenon = val; break; case 1: cfg.screenon = val; break;
@ -125,12 +127,12 @@ void set_display(int val) {
} }
}; };
void set_lorasf(int val) { void set_lorasf(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set LoRa SF to %d", val); ESP_LOGI(TAG, "Remote command: set LoRa SF to %d", val);
switch_lora(val, cfg.txpower); switch_lora(val, cfg.txpower);
}; };
void set_loraadr(int val) { void set_loraadr(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set LoRa ADR mode to %s", val ? "on" : "off"); ESP_LOGI(TAG, "Remote command: set LoRa ADR mode to %s", val ? "on" : "off");
switch (val) { switch (val) {
case 1: cfg.adrmode = val; break; case 1: cfg.adrmode = val; break;
@ -139,7 +141,7 @@ void set_loraadr(int val) {
LMIC_setAdrMode(cfg.adrmode); LMIC_setAdrMode(cfg.adrmode);
}; };
void set_blescan(int val) { void set_blescan(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set BLE scan mode to %s", val ? "on" : "off"); ESP_LOGI(TAG, "Remote command: set BLE scan mode to %s", val ? "on" : "off");
switch (val) { switch (val) {
case 0: case 0:
@ -152,7 +154,7 @@ void set_blescan(int val) {
} }
}; };
void set_wifiant(int val) { void set_wifiant(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set Wifi antenna to %s", val ? "external" : "internal"); ESP_LOGI(TAG, "Remote command: set Wifi antenna to %s", val ? "external" : "internal");
switch (val) { switch (val) {
case 1: cfg.wifiant = val; break; case 1: cfg.wifiant = val; break;
@ -163,7 +165,7 @@ void set_wifiant(int val) {
#endif #endif
}; };
void set_vendorfilter(int val) { void set_vendorfilter(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set vendorfilter mode to %s", val ? "on" : "off"); ESP_LOGI(TAG, "Remote command: set vendorfilter mode to %s", val ? "on" : "off");
switch (val) { switch (val) {
case 1: cfg.vendorfilter = val; break; case 1: cfg.vendorfilter = val; break;
@ -171,22 +173,22 @@ void set_vendorfilter(int val) {
} }
}; };
void set_rgblum(int val) { void set_rgblum(uint8_t val) {
// Avoid wrong parameters // Avoid wrong parameters
cfg.rgblum = (val>=0 && val<=100) ? (uint8_t) val : RGBLUMINOSITY; cfg.rgblum = (val>=0 && val<=100) ? (uint8_t) val : RGBLUMINOSITY;
ESP_LOGI(TAG, "Remote command: set RGB Led luminosity %d", cfg.rgblum); ESP_LOGI(TAG, "Remote command: set RGB Led luminosity %d", cfg.rgblum);
}; };
void set_lorapower(int val) { void set_lorapower(uint8_t val) {
ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %d", val); ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %d", val);
switch_lora(cfg.lorasf, val); switch_lora(cfg.lorasf, val);
}; };
void set_noop (int val) { void set_noop (uint8_t val) {
ESP_LOGI(TAG, "Remote command: noop - doing nothing"); ESP_LOGI(TAG, "Remote command: noop - doing nothing");
}; };
void get_config (int val) { void get_config (uint8_t val) {
ESP_LOGI(TAG, "Remote command: get configuration"); ESP_LOGI(TAG, "Remote command: get configuration");
int size = sizeof(configData_t); int size = sizeof(configData_t);
// declare send buffer (char byte array) // declare send buffer (char byte array)
@ -198,7 +200,7 @@ void get_config (int val) {
ESP_LOGI(TAG, "%d bytes queued in send queue", size-1); ESP_LOGI(TAG, "%d bytes queued in send queue", size-1);
}; };
void get_uptime (int val) { void get_uptime (uint8_t val) {
ESP_LOGI(TAG, "Remote command: get uptime"); ESP_LOGI(TAG, "Remote command: get uptime");
int size = sizeof(uptimecounter); int size = sizeof(uptimecounter);
unsigned char *sendData = new unsigned char[size]; unsigned char *sendData = new unsigned char[size];
@ -208,7 +210,7 @@ void get_uptime (int val) {
ESP_LOGI(TAG, "%d bytes queued in send queue", size-1); ESP_LOGI(TAG, "%d bytes queued in send queue", size-1);
}; };
void get_cputemp (int val) { void get_cputemp (uint8_t val) {
ESP_LOGI(TAG, "Remote command: get cpu temperature"); ESP_LOGI(TAG, "Remote command: get cpu temperature");
float temp = temperatureRead(); float temp = temperatureRead();
int size = sizeof(temp); int size = sizeof(temp);
@ -245,7 +247,7 @@ cmd_t table[] = {
}; };
// check and execute remote command // check and execute remote command
void rcommand(int cmd, int arg) { void rcommand(uint8_t cmd, uint8_t arg) {
int i = sizeof(table) / sizeof(table[0]); // number of commands in command table int i = sizeof(table) / sizeof(table[0]); // number of commands in command table
bool store_flag = false; bool store_flag = false;
while(i--) { while(i--) {