clang-format: configmanager.cpp, globals.h, gpsread.cpp
This commit is contained in:
parent
0cbfb1c354
commit
4466889a18
@ -13,130 +13,151 @@ esp_err_t err;
|
||||
|
||||
// defined in antenna.cpp
|
||||
#ifdef HAS_ANTENNA_SWITCH
|
||||
void antenna_select(const uint8_t _ant);
|
||||
void antenna_select(const uint8_t _ant);
|
||||
#endif
|
||||
|
||||
// populate cfg vars with factory settings
|
||||
void defaultConfig() {
|
||||
cfg.lorasf = LORASFDEFAULT; // 7-12, initial lora spreadfactor defined in paxcounter.conf
|
||||
cfg.txpower = 15; // 2-15, lora tx power
|
||||
cfg.adrmode = 1; // 0=disabled, 1=enabled
|
||||
cfg.screensaver = 0; // 0=disabled, 1=enabled
|
||||
cfg.screenon = 1; // 0=disabled, 1=enabled
|
||||
cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed
|
||||
cfg.rssilimit = 0; // threshold for rssilimiter, negative value!
|
||||
cfg.sendcycle = SEND_SECS; // payload send cycle [seconds/2]
|
||||
cfg.wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
|
||||
cfg.blescantime = BLESCANINTERVAL / 10; // BT channel scan cycle duration [seconds/100], default 1 (= 10ms)
|
||||
cfg.blescan = 1; // 0=disabled, 1=enabled
|
||||
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||
cfg.vendorfilter = 1; // 0=disabled, 1=enabled
|
||||
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
|
||||
cfg.gpsmode = 1; // 0=disabled, 1=enabled
|
||||
cfg.lorasf = LORASFDEFAULT; // 7-12, initial lora sf, see pacounter.conf
|
||||
cfg.txpower = 15; // 2-15, lora tx power
|
||||
cfg.adrmode = 1; // 0=disabled, 1=enabled
|
||||
cfg.screensaver = 0; // 0=disabled, 1=enabled
|
||||
cfg.screenon = 1; // 0=disabled, 1=enabled
|
||||
cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed
|
||||
cfg.rssilimit = 0; // threshold for rssilimiter, negative value!
|
||||
cfg.sendcycle = SEND_SECS; // payload send cycle [seconds/2]
|
||||
cfg.wifichancycle =
|
||||
WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
|
||||
cfg.blescantime =
|
||||
BLESCANINTERVAL /
|
||||
10; // BT channel scan cycle [seconds/100], default 1 (= 10ms)
|
||||
cfg.blescan = 1; // 0=disabled, 1=enabled
|
||||
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||
cfg.vendorfilter = 1; // 0=disabled, 1=enabled
|
||||
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
|
||||
cfg.gpsmode = 1; // 0=disabled, 1=enabled
|
||||
|
||||
strncpy( cfg.version, PROGVERSION, sizeof(cfg.version)-1 );
|
||||
strncpy(cfg.version, PROGVERSION, sizeof(cfg.version) - 1);
|
||||
}
|
||||
|
||||
void open_storage() {
|
||||
err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
// NVS partition was truncated and needs to be erased
|
||||
// Retry nvs_flash_init
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
// NVS partition was truncated and needs to be erased
|
||||
// Retry nvs_flash_init
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK( err );
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
// Open
|
||||
ESP_LOGI(TAG, "Opening NVS");
|
||||
err = nvs_open("config", NVS_READWRITE, &my_handle);
|
||||
if (err != ESP_OK)
|
||||
ESP_LOGI(TAG, "Error (%d) opening NVS handle", err);
|
||||
else
|
||||
ESP_LOGI(TAG, "Done");
|
||||
// Open
|
||||
ESP_LOGI(TAG, "Opening NVS");
|
||||
err = nvs_open("config", NVS_READWRITE, &my_handle);
|
||||
if (err != ESP_OK)
|
||||
ESP_LOGI(TAG, "Error (%d) opening NVS handle", err);
|
||||
else
|
||||
ESP_LOGI(TAG, "Done");
|
||||
}
|
||||
|
||||
// erase all keys and values in NVRAM
|
||||
void eraseConfig() {
|
||||
ESP_LOGI(TAG, "Clearing settings in NVS");
|
||||
open_storage();
|
||||
if (err == ESP_OK) {
|
||||
nvs_erase_all(my_handle);
|
||||
nvs_commit(my_handle);
|
||||
nvs_close(my_handle);
|
||||
ESP_LOGI(TAG, "Done");}
|
||||
else {
|
||||
ESP_LOGW(TAG, "NVS erase failed"); }
|
||||
ESP_LOGI(TAG, "Clearing settings in NVS");
|
||||
open_storage();
|
||||
if (err == ESP_OK) {
|
||||
nvs_erase_all(my_handle);
|
||||
nvs_commit(my_handle);
|
||||
nvs_close(my_handle);
|
||||
ESP_LOGI(TAG, "Done");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "NVS erase failed");
|
||||
}
|
||||
}
|
||||
|
||||
// save current configuration from RAM to NVRAM
|
||||
void saveConfig() {
|
||||
ESP_LOGI(TAG, "Storing settings in NVS");
|
||||
open_storage();
|
||||
if (err == ESP_OK) {
|
||||
int8_t flash8 = 0;
|
||||
int16_t flash16 = 0;
|
||||
size_t required_size;
|
||||
char storedversion[10];
|
||||
ESP_LOGI(TAG, "Storing settings in NVS");
|
||||
open_storage();
|
||||
if (err == ESP_OK) {
|
||||
int8_t flash8 = 0;
|
||||
int16_t flash16 = 0;
|
||||
size_t required_size;
|
||||
char storedversion[10];
|
||||
|
||||
if( nvs_get_str(my_handle, "version", storedversion, &required_size) != ESP_OK || strcmp(storedversion, cfg.version) != 0 )
|
||||
nvs_set_str(my_handle, "version", cfg.version);
|
||||
if (nvs_get_str(my_handle, "version", storedversion, &required_size) !=
|
||||
ESP_OK ||
|
||||
strcmp(storedversion, cfg.version) != 0)
|
||||
nvs_set_str(my_handle, "version", cfg.version);
|
||||
|
||||
if( nvs_get_i8(my_handle, "lorasf", &flash8) != ESP_OK || flash8 != cfg.lorasf )
|
||||
nvs_set_i8(my_handle, "lorasf", cfg.lorasf);
|
||||
if (nvs_get_i8(my_handle, "lorasf", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.lorasf)
|
||||
nvs_set_i8(my_handle, "lorasf", cfg.lorasf);
|
||||
|
||||
if( nvs_get_i8(my_handle, "txpower", &flash8) != ESP_OK || flash8 != cfg.txpower )
|
||||
nvs_set_i8(my_handle, "txpower", cfg.txpower);
|
||||
if (nvs_get_i8(my_handle, "txpower", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.txpower)
|
||||
nvs_set_i8(my_handle, "txpower", cfg.txpower);
|
||||
|
||||
if( nvs_get_i8(my_handle, "adrmode", &flash8) != ESP_OK || flash8 != cfg.adrmode )
|
||||
nvs_set_i8(my_handle, "adrmode", cfg.adrmode);
|
||||
if (nvs_get_i8(my_handle, "adrmode", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.adrmode)
|
||||
nvs_set_i8(my_handle, "adrmode", cfg.adrmode);
|
||||
|
||||
if( nvs_get_i8(my_handle, "screensaver", &flash8) != ESP_OK || flash8 != cfg.screensaver )
|
||||
nvs_set_i8(my_handle, "screensaver", cfg.screensaver);
|
||||
if (nvs_get_i8(my_handle, "screensaver", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.screensaver)
|
||||
nvs_set_i8(my_handle, "screensaver", cfg.screensaver);
|
||||
|
||||
if( nvs_get_i8(my_handle, "screenon", &flash8) != ESP_OK || flash8 != cfg.screenon )
|
||||
nvs_set_i8(my_handle, "screenon", cfg.screenon);
|
||||
if (nvs_get_i8(my_handle, "screenon", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.screenon)
|
||||
nvs_set_i8(my_handle, "screenon", cfg.screenon);
|
||||
|
||||
if( nvs_get_i8(my_handle, "countermode", &flash8) != ESP_OK || flash8 != cfg.countermode )
|
||||
nvs_set_i8(my_handle, "countermode", cfg.countermode);
|
||||
if (nvs_get_i8(my_handle, "countermode", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.countermode)
|
||||
nvs_set_i8(my_handle, "countermode", cfg.countermode);
|
||||
|
||||
if( nvs_get_i8(my_handle, "sendcycle", &flash8) != ESP_OK || flash8 != cfg.sendcycle )
|
||||
nvs_set_i8(my_handle, "sendcycle", cfg.sendcycle);
|
||||
if (nvs_get_i8(my_handle, "sendcycle", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.sendcycle)
|
||||
nvs_set_i8(my_handle, "sendcycle", cfg.sendcycle);
|
||||
|
||||
if( nvs_get_i8(my_handle, "wifichancycle", &flash8) != ESP_OK || flash8 != cfg.wifichancycle )
|
||||
nvs_set_i8(my_handle, "wifichancycle", cfg.wifichancycle);
|
||||
if (nvs_get_i8(my_handle, "wifichancycle", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.wifichancycle)
|
||||
nvs_set_i8(my_handle, "wifichancycle", cfg.wifichancycle);
|
||||
|
||||
if( nvs_get_i8(my_handle, "blescantime", &flash8) != ESP_OK || flash8 != cfg.blescantime )
|
||||
nvs_set_i8(my_handle, "blescantime", cfg.blescantime);
|
||||
if (nvs_get_i8(my_handle, "blescantime", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.blescantime)
|
||||
nvs_set_i8(my_handle, "blescantime", cfg.blescantime);
|
||||
|
||||
if( nvs_get_i8(my_handle, "blescanmode", &flash8) != ESP_OK || flash8 != cfg.blescan )
|
||||
nvs_set_i8(my_handle, "blescanmode", cfg.blescan);
|
||||
if (nvs_get_i8(my_handle, "blescanmode", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.blescan)
|
||||
nvs_set_i8(my_handle, "blescanmode", cfg.blescan);
|
||||
|
||||
if( nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK || flash8 != cfg.wifiant )
|
||||
nvs_set_i8(my_handle, "wifiant", cfg.wifiant);
|
||||
if (nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.wifiant)
|
||||
nvs_set_i8(my_handle, "wifiant", cfg.wifiant);
|
||||
|
||||
if( nvs_get_i8(my_handle, "vendorfilter", &flash8) != ESP_OK || flash8 != cfg.vendorfilter )
|
||||
nvs_set_i8(my_handle, "vendorfilter", cfg.vendorfilter);
|
||||
if (nvs_get_i8(my_handle, "vendorfilter", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.vendorfilter)
|
||||
nvs_set_i8(my_handle, "vendorfilter", cfg.vendorfilter);
|
||||
|
||||
if( nvs_get_i8(my_handle, "rgblum", &flash8) != ESP_OK || flash8 != cfg.rgblum )
|
||||
nvs_set_i8(my_handle, "rgblum", cfg.rgblum);
|
||||
if (nvs_get_i8(my_handle, "rgblum", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.rgblum)
|
||||
nvs_set_i8(my_handle, "rgblum", cfg.rgblum);
|
||||
|
||||
if( nvs_get_i8(my_handle, "gpsmode", &flash8) != ESP_OK || flash8 != cfg.gpsmode )
|
||||
if (nvs_get_i8(my_handle, "gpsmode", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.gpsmode)
|
||||
nvs_set_i8(my_handle, "gpsmode", cfg.gpsmode);
|
||||
|
||||
if( nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK || flash16 != cfg.rssilimit )
|
||||
nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit);
|
||||
if (nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK ||
|
||||
flash16 != cfg.rssilimit)
|
||||
nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit);
|
||||
|
||||
err = nvs_commit(my_handle);
|
||||
nvs_close(my_handle);
|
||||
if ( err == ESP_OK ) {
|
||||
ESP_LOGI(TAG, "Done");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "NVS config write failed");
|
||||
}
|
||||
err = nvs_commit(my_handle);
|
||||
nvs_close(my_handle);
|
||||
if (err == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Done");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Error (%d) opening NVS handle", err);
|
||||
ESP_LOGW(TAG, "NVS config write failed");
|
||||
}
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Error (%d) opening NVS handle", err);
|
||||
}
|
||||
}
|
||||
|
||||
// set and save cfg.version
|
||||
@ -152,31 +173,33 @@ void loadConfig() {
|
||||
ESP_LOGI(TAG, "Reading settings from NVS");
|
||||
open_storage();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG,"Error (%d) opening NVS handle, storing defaults", err);
|
||||
saveConfig(); } // saves factory settings to NVRAM
|
||||
ESP_LOGW(TAG, "Error (%d) opening NVS handle, storing defaults", err);
|
||||
saveConfig();
|
||||
} // saves factory settings to NVRAM
|
||||
else {
|
||||
int8_t flash8 = 0;
|
||||
int8_t flash8 = 0;
|
||||
int16_t flash16 = 0;
|
||||
size_t required_size;
|
||||
|
||||
// check if configuration stored in NVRAM matches PROGVERSION
|
||||
if( nvs_get_str(my_handle, "version", NULL, &required_size) == ESP_OK ) {
|
||||
if (nvs_get_str(my_handle, "version", NULL, &required_size) == ESP_OK) {
|
||||
nvs_get_str(my_handle, "version", cfg.version, &required_size);
|
||||
ESP_LOGI(TAG, "NVRAM settings version = %s", cfg.version);
|
||||
if (strcmp(cfg.version, PROGVERSION)) {
|
||||
ESP_LOGI(TAG, "migrating NVRAM settings to new version %s", PROGVERSION);
|
||||
ESP_LOGI(TAG, "migrating NVRAM settings to new version %s",
|
||||
PROGVERSION);
|
||||
nvs_close(my_handle);
|
||||
migrateVersion();
|
||||
}
|
||||
} else {
|
||||
ESP_LOGI(TAG, "new version %s, deleting NVRAM settings", PROGVERSION);
|
||||
nvs_close(my_handle);
|
||||
eraseConfig();
|
||||
migrateVersion();
|
||||
ESP_LOGI(TAG, "new version %s, deleting NVRAM settings", PROGVERSION);
|
||||
nvs_close(my_handle);
|
||||
eraseConfig();
|
||||
migrateVersion();
|
||||
}
|
||||
|
||||
// overwrite defaults with valid values from NVRAM
|
||||
if( nvs_get_i8(my_handle, "lorasf", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "lorasf", &flash8) == ESP_OK) {
|
||||
cfg.lorasf = flash8;
|
||||
ESP_LOGI(TAG, "lorasf = %d", flash8);
|
||||
} else {
|
||||
@ -184,7 +207,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "txpower", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "txpower", &flash8) == ESP_OK) {
|
||||
cfg.txpower = flash8;
|
||||
ESP_LOGI(TAG, "txpower = %d", flash8);
|
||||
} else {
|
||||
@ -192,7 +215,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "adrmode", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "adrmode", &flash8) == ESP_OK) {
|
||||
cfg.adrmode = flash8;
|
||||
ESP_LOGI(TAG, "adrmode = %d", flash8);
|
||||
} else {
|
||||
@ -200,7 +223,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "screensaver", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "screensaver", &flash8) == ESP_OK) {
|
||||
cfg.screensaver = flash8;
|
||||
ESP_LOGI(TAG, "screensaver = %d", flash8);
|
||||
} else {
|
||||
@ -208,7 +231,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "screenon", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "screenon", &flash8) == ESP_OK) {
|
||||
cfg.screenon = flash8;
|
||||
ESP_LOGI(TAG, "screenon = %d", flash8);
|
||||
} else {
|
||||
@ -216,7 +239,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "countermode", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "countermode", &flash8) == ESP_OK) {
|
||||
cfg.countermode = flash8;
|
||||
ESP_LOGI(TAG, "countermode = %d", flash8);
|
||||
} else {
|
||||
@ -224,7 +247,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "sendcycle", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "sendcycle", &flash8) == ESP_OK) {
|
||||
cfg.sendcycle = flash8;
|
||||
ESP_LOGI(TAG, "sendcycle = %d", flash8);
|
||||
} else {
|
||||
@ -232,7 +255,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "wifichancycle", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "wifichancycle", &flash8) == ESP_OK) {
|
||||
cfg.wifichancycle = flash8;
|
||||
ESP_LOGI(TAG, "wifichancycle = %d", flash8);
|
||||
} else {
|
||||
@ -240,7 +263,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "wifiant", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "wifiant", &flash8) == ESP_OK) {
|
||||
cfg.wifiant = flash8;
|
||||
ESP_LOGI(TAG, "wifiantenna = %d", flash8);
|
||||
} else {
|
||||
@ -248,7 +271,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "vendorfilter", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "vendorfilter", &flash8) == ESP_OK) {
|
||||
cfg.vendorfilter = flash8;
|
||||
ESP_LOGI(TAG, "vendorfilter = %d", flash8);
|
||||
} else {
|
||||
@ -256,7 +279,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "rgblum", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "rgblum", &flash8) == ESP_OK) {
|
||||
cfg.rgblum = flash8;
|
||||
ESP_LOGI(TAG, "rgbluminosity = %d", flash8);
|
||||
} else {
|
||||
@ -264,7 +287,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "blescantime", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "blescantime", &flash8) == ESP_OK) {
|
||||
cfg.blescantime = flash8;
|
||||
ESP_LOGI(TAG, "blescantime = %d", flash8);
|
||||
} else {
|
||||
@ -272,7 +295,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "blescanmode", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "blescanmode", &flash8) == ESP_OK) {
|
||||
cfg.blescan = flash8;
|
||||
ESP_LOGI(TAG, "BLEscanmode = %d", flash8);
|
||||
} else {
|
||||
@ -280,7 +303,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK ) {
|
||||
if (nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK) {
|
||||
cfg.rssilimit = flash16;
|
||||
ESP_LOGI(TAG, "rssilimit = %d", flash16);
|
||||
} else {
|
||||
@ -288,7 +311,7 @@ void loadConfig() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if( nvs_get_i8(my_handle, "gpsmode", &flash8) == ESP_OK ) {
|
||||
if (nvs_get_i8(my_handle, "gpsmode", &flash8) == ESP_OK) {
|
||||
cfg.gpsmode = flash8;
|
||||
ESP_LOGI(TAG, "GPSmode = %d", flash8);
|
||||
} else {
|
||||
@ -300,9 +323,9 @@ void loadConfig() {
|
||||
ESP_LOGI(TAG, "Done");
|
||||
|
||||
// put actions to be triggered after config loaded here
|
||||
|
||||
#ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one
|
||||
antenna_select(cfg.wifiant);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one
|
||||
antenna_select(cfg.wifiant);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -8,12 +8,12 @@
|
||||
|
||||
// OLED Display
|
||||
#ifdef HAS_DISPLAY
|
||||
#include <U8x8lib.h>
|
||||
#include <U8x8lib.h>
|
||||
#endif
|
||||
|
||||
//GPS
|
||||
// GPS
|
||||
#ifdef HAS_GPS
|
||||
#include <TinyGPS++.h>
|
||||
#include <TinyGPS++.h>
|
||||
#endif
|
||||
|
||||
// LMIC-Arduino LoRaWAN Stack
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
// LED controls
|
||||
#ifdef HAS_RGB_LED
|
||||
#include <SmartLeds.h>
|
||||
#include <SmartLeds.h>
|
||||
#endif
|
||||
|
||||
#include "rgb_led.h"
|
||||
@ -31,34 +31,34 @@
|
||||
|
||||
// Struct holding devices's runtime configuration
|
||||
typedef struct {
|
||||
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!
|
||||
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%)
|
||||
uint8_t gpsmode; // 0=disabled, 1=enabled
|
||||
char version[10]; // Firmware version
|
||||
} configData_t;
|
||||
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!
|
||||
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%)
|
||||
uint8_t gpsmode; // 0=disabled, 1=enabled
|
||||
char version[10]; // Firmware version
|
||||
} configData_t;
|
||||
|
||||
#ifdef HAS_GPS
|
||||
typedef struct {
|
||||
uint32_t latitude;
|
||||
uint32_t longitude;
|
||||
uint8_t satellites;
|
||||
uint16_t hdop;
|
||||
uint16_t altitude;
|
||||
} gpsStatus_t;
|
||||
extern gpsStatus_t gps_status; // struct for storing gps data
|
||||
extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe
|
||||
typedef struct {
|
||||
uint32_t latitude;
|
||||
uint32_t longitude;
|
||||
uint8_t satellites;
|
||||
uint16_t hdop;
|
||||
uint16_t altitude;
|
||||
} gpsStatus_t;
|
||||
extern gpsStatus_t gps_status; // struct for storing gps data
|
||||
extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe
|
||||
#endif
|
||||
|
||||
extern configData_t cfg;
|
||||
@ -68,6 +68,7 @@ extern char display_lora[], display_lmic[];
|
||||
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
||||
extern uint16_t macs_total, macs_wifi, macs_ble; // MAC counters
|
||||
extern std::set<uint16_t> macs;
|
||||
extern hw_timer_t * channelSwitch; // hardware timer used for wifi channel switching
|
||||
extern xref2u1_t rcmd_data; // buffer for rcommand results size
|
||||
extern u1_t rcmd_data_size; // buffer for rcommand results size
|
||||
extern hw_timer_t
|
||||
*channelSwitch; // hardware timer used for wifi channel switching
|
||||
extern xref2u1_t rcmd_data; // buffer for rcommand results size
|
||||
extern u1_t rcmd_data_size; // buffer for rcommand results size
|
||||
|
113
src/gpsread.cpp
113
src/gpsread.cpp
@ -7,74 +7,73 @@ static const char TAG[] = "main";
|
||||
|
||||
// read GPS data and cast to global struct
|
||||
void gps_read() {
|
||||
gps_status.latitude = (uint32_t) (gps.location.lat() * 1000000);
|
||||
gps_status.longitude = (uint32_t) (gps.location.lng() * 1000000);
|
||||
gps_status.satellites = (uint8_t) gps.satellites.value();
|
||||
gps_status.hdop = (uint16_t) gps.hdop.value();
|
||||
gps_status.altitude = (uint16_t) gps.altitude.meters();
|
||||
gps_status.latitude = (uint32_t)(gps.location.lat() * 1000000);
|
||||
gps_status.longitude = (uint32_t)(gps.location.lng() * 1000000);
|
||||
gps_status.satellites = (uint8_t)gps.satellites.value();
|
||||
gps_status.hdop = (uint16_t)gps.hdop.value();
|
||||
gps_status.altitude = (uint16_t)gps.altitude.meters();
|
||||
}
|
||||
|
||||
// GPS serial feed FreeRTos Task
|
||||
void gps_loop(void * pvParameters) {
|
||||
void gps_loop(void *pvParameters) {
|
||||
|
||||
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
|
||||
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
||||
|
||||
// initialize and, if needed, configure, GPS
|
||||
#if defined GPS_SERIAL
|
||||
HardwareSerial GPS_Serial(1);
|
||||
#elif defined GPS_I2C
|
||||
// to be done
|
||||
#endif
|
||||
// initialize and, if needed, configure, GPS
|
||||
#if defined GPS_SERIAL
|
||||
HardwareSerial GPS_Serial(1);
|
||||
#elif defined GPS_I2C
|
||||
// to be done
|
||||
#endif
|
||||
|
||||
while(1) {
|
||||
while (1) {
|
||||
|
||||
if (cfg.gpsmode)
|
||||
{
|
||||
#if defined GPS_SERIAL
|
||||
|
||||
// serial connect to GPS device
|
||||
GPS_Serial.begin(GPS_SERIAL);
|
||||
|
||||
while(cfg.gpsmode) {
|
||||
// feed GPS decoder with serial NMEA data from GPS device
|
||||
while (GPS_Serial.available()) {
|
||||
gps.encode(GPS_Serial.read());
|
||||
}
|
||||
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
|
||||
}
|
||||
// after GPS function was disabled, close connect to GPS device
|
||||
GPS_Serial.end();
|
||||
if (cfg.gpsmode) {
|
||||
#if defined GPS_SERIAL
|
||||
|
||||
#elif defined GPS_I2C
|
||||
|
||||
// I2C connect to GPS device with 100 kHz
|
||||
Wire.begin(GPS_I2C_PINS, 100000);
|
||||
Wire.beginTransmission(GPS_I2C_ADDRESS_WRITE);
|
||||
Wire.write(0x00);
|
||||
// serial connect to GPS device
|
||||
GPS_Serial.begin(GPS_SERIAL);
|
||||
|
||||
i2c_ret == Wire.beginTransmission(GPS_I2C_ADDRESS_READ);
|
||||
if (i2c_ret == 0) { // check if device seen on i2c bus
|
||||
while(cfg.gpsmode) {
|
||||
// feed GPS decoder with serial NMEA data from GPS device
|
||||
while (Wire.available()) {
|
||||
Wire.requestFrom(GPS_I2C_ADDRESS_READ, 255);
|
||||
gps.encode(Wire.read());
|
||||
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
|
||||
}
|
||||
}
|
||||
// after GPS function was disabled, close connect to GPS device
|
||||
|
||||
Wire.endTransmission();
|
||||
Wire.setClock(400000); // Set back to 400KHz to speed up OLED
|
||||
}
|
||||
|
||||
#endif
|
||||
while (cfg.gpsmode) {
|
||||
// feed GPS decoder with serial NMEA data from GPS device
|
||||
while (GPS_Serial.available()) {
|
||||
gps.encode(GPS_Serial.read());
|
||||
}
|
||||
|
||||
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
|
||||
vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
|
||||
}
|
||||
// after GPS function was disabled, close connect to GPS device
|
||||
GPS_Serial.end();
|
||||
|
||||
} // end of infinite loop
|
||||
#elif defined GPS_I2C
|
||||
|
||||
// I2C connect to GPS device with 100 kHz
|
||||
Wire.begin(GPS_I2C_PINS, 100000);
|
||||
Wire.beginTransmission(GPS_I2C_ADDRESS_WRITE);
|
||||
Wire.write(0x00);
|
||||
|
||||
i2c_ret == Wire.beginTransmission(GPS_I2C_ADDRESS_READ);
|
||||
if (i2c_ret == 0) { // check if device seen on i2c bus
|
||||
while (cfg.gpsmode) {
|
||||
// feed GPS decoder with serial NMEA data from GPS device
|
||||
while (Wire.available()) {
|
||||
Wire.requestFrom(GPS_I2C_ADDRESS_READ, 255);
|
||||
gps.encode(Wire.read());
|
||||
vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
|
||||
}
|
||||
}
|
||||
// after GPS function was disabled, close connect to GPS device
|
||||
|
||||
Wire.endTransmission();
|
||||
Wire.setClock(400000); // Set back to 400KHz to speed up OLED
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
|
||||
|
||||
} // end of infinite loop
|
||||
|
||||
} // gps_loop()
|
||||
|
||||
|
||||
#endif // HAS_GPS
|
Loading…
Reference in New Issue
Block a user