repair wifichancycle
This commit is contained in:
parent
37005a2087
commit
589058d7c5
@ -21,7 +21,7 @@ void antenna_init(void) {
|
||||
gpio_config(&gpioconf);
|
||||
}
|
||||
|
||||
void antenna_select (const int8_t _ant) {
|
||||
void antenna_select (const uint8_t _ant) {
|
||||
if (HAS_ANTENNA_SWITCH < 32) {
|
||||
if (_ant == ANTENNA_EXT) {
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, 1 << HAS_ANTENNA_SWITCH);
|
||||
|
@ -13,7 +13,7 @@ esp_err_t err;
|
||||
|
||||
// defined in antenna.cpp
|
||||
#ifdef HAS_ANTENNA_SWITCH
|
||||
void antenna_select(const int8_t _ant);
|
||||
void antenna_select(const uint8_t _ant);
|
||||
#endif
|
||||
|
||||
// populate cfg vars with factory settings
|
||||
|
@ -26,20 +26,20 @@
|
||||
|
||||
// Struct holding devices's runtime configuration
|
||||
typedef struct {
|
||||
int8_t lorasf; // 7-12, lora spreadfactor
|
||||
int8_t txpower; // 2-15, lora tx power
|
||||
int8_t adrmode; // 0=disabled, 1=enabled
|
||||
int8_t screensaver; // 0=disabled, 1=enabled
|
||||
int8_t screenon; // 0=disabled, 1=enabled
|
||||
int8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed
|
||||
uint8_t lorasf; // 7-12, lora spreadfactor
|
||||
uint8_t txpower; // 2-15, lora tx power
|
||||
uint8_t adrmode; // 0=disabled, 1=enabled
|
||||
uint8_t screensaver; // 0=disabled, 1=enabled
|
||||
uint8_t screenon; // 0=disabled, 1=enabled
|
||||
uint8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed
|
||||
int16_t rssilimit; // threshold for rssilimiter, negative value!
|
||||
int8_t sendcycle; // payload send cycle [seconds/2]
|
||||
int8_t wifichancycle; // wifi channel switch cycle [seconds/100]
|
||||
int8_t blescantime; // BLE scan cycle duration [seconds]
|
||||
int8_t blescan; // 0=disabled, 1=enabled
|
||||
int8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||
int8_t vendorfilter; // 0=disabled, 1=enabled
|
||||
int8_t rgblum; // RGB Led luminosity (0..100%)
|
||||
uint8_t sendcycle; // payload send cycle [seconds/2]
|
||||
uint8_t wifichancycle; // wifi channel switch cycle [seconds/100]
|
||||
uint8_t blescantime; // BLE scan cycle duration [seconds]
|
||||
uint8_t blescan; // 0=disabled, 1=enabled
|
||||
uint8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||
uint8_t vendorfilter; // 0=disabled, 1=enabled
|
||||
uint8_t rgblum; // RGB Led luminosity (0..100%)
|
||||
char version[10]; // Firmware version
|
||||
} configData_t;
|
||||
|
||||
@ -52,6 +52,7 @@ extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
||||
extern uint16_t macs_total, macs_wifi, macs_ble; // MAC counters
|
||||
extern bool joinstate;
|
||||
extern std::set<uint16_t> macs;
|
||||
extern hw_timer_t * channelSwitch; // hardware timer used for wifi channel switching
|
||||
|
||||
#ifdef HAS_DISPLAY
|
||||
extern HAS_DISPLAY u8x8;
|
||||
|
@ -14,8 +14,8 @@
|
||||
static const char *TAG = "lorawan";
|
||||
|
||||
// functions defined in rcommand.cpp
|
||||
void rcommand(int cmd, int arg);
|
||||
void switch_lora(int sf, int tx);
|
||||
void rcommand(uint8_t cmd, uint8_t arg);
|
||||
void switch_lora(uint8_t sf, uint8_t tx);
|
||||
|
||||
// DevEUI generator using devices's MAC address
|
||||
void gen_lora_deveui(uint8_t *pdeveui) {
|
||||
|
@ -192,7 +192,7 @@ void lorawan_loop(void * pvParameters) {
|
||||
#ifdef HAS_ANTENNA_SWITCH
|
||||
// defined in antenna.cpp
|
||||
void antenna_init();
|
||||
void antenna_select(const int8_t _ant);
|
||||
void antenna_select(const uint8_t _ant);
|
||||
#endif
|
||||
|
||||
#ifndef BLECOUNTER
|
||||
@ -562,7 +562,7 @@ void setup() {
|
||||
// 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
|
||||
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
|
||||
|
||||
// show compiled features
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
// 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"
|
||||
|
||||
//--- Declarations ---
|
||||
|
@ -14,18 +14,18 @@ static const char *TAG = "rcommand";
|
||||
|
||||
// table of remote commands and assigned functions
|
||||
typedef struct {
|
||||
const int nam;
|
||||
void (*func)(int);
|
||||
const uint8_t nam;
|
||||
void (*func)(uint8_t);
|
||||
const bool store;
|
||||
} cmd_t;
|
||||
|
||||
// function defined in antenna.cpp
|
||||
#ifdef HAS_ANTENNA_SWITCH
|
||||
void antenna_select(const int8_t _ant);
|
||||
void antenna_select(const uint8_t _ant);
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
cfg.txpower = tx;
|
||||
switch (sf) {
|
||||
@ -50,7 +50,7 @@ void switch_lora (int sf, int tx) {
|
||||
}
|
||||
|
||||
// set of functions that can be triggered by remote commands
|
||||
void set_reset(int val) {
|
||||
void set_reset(uint8_t val) {
|
||||
switch (val) {
|
||||
case 0: // 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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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) {
|
||||
case 0: // cyclic unconfirmed
|
||||
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");
|
||||
switch (val) {
|
||||
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");
|
||||
switch (val) {
|
||||
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);
|
||||
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");
|
||||
switch (val) {
|
||||
case 1: cfg.adrmode = val; break;
|
||||
@ -139,7 +141,7 @@ void set_loraadr(int val) {
|
||||
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");
|
||||
switch (val) {
|
||||
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");
|
||||
switch (val) {
|
||||
case 1: cfg.wifiant = val; break;
|
||||
@ -163,7 +165,7 @@ void set_wifiant(int val) {
|
||||
#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");
|
||||
switch (val) {
|
||||
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
|
||||
cfg.rgblum = (val>=0 && val<=100) ? (uint8_t) val : RGBLUMINOSITY;
|
||||
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);
|
||||
switch_lora(cfg.lorasf, val);
|
||||
};
|
||||
|
||||
void set_noop (int val) {
|
||||
void set_noop (uint8_t val) {
|
||||
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");
|
||||
int size = sizeof(configData_t);
|
||||
// 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);
|
||||
};
|
||||
|
||||
void get_uptime (int val) {
|
||||
void get_uptime (uint8_t val) {
|
||||
ESP_LOGI(TAG, "Remote command: get uptime");
|
||||
int size = sizeof(uptimecounter);
|
||||
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);
|
||||
};
|
||||
|
||||
void get_cputemp (int val) {
|
||||
void get_cputemp (uint8_t val) {
|
||||
ESP_LOGI(TAG, "Remote command: get cpu temperature");
|
||||
float temp = temperatureRead();
|
||||
int size = sizeof(temp);
|
||||
@ -245,7 +247,7 @@ cmd_t table[] = {
|
||||
};
|
||||
|
||||
// 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
|
||||
bool store_flag = false;
|
||||
while(i--) {
|
||||
|
Loading…
Reference in New Issue
Block a user