code sanitizations

This commit is contained in:
cyberman54 2022-08-16 13:43:04 +02:00
parent 27fd296753
commit f05acd32a8
17 changed files with 4 additions and 59 deletions

View File

@ -39,7 +39,6 @@
#endif #endif
class PayloadConvert { class PayloadConvert {
public: public:
PayloadConvert(uint8_t size); PayloadConvert(uint8_t size);
~PayloadConvert(); ~PayloadConvert();
@ -59,6 +58,7 @@ public:
void addSensor(uint8_t[]); void addSensor(uint8_t[]);
void addTime(time_t value); void addTime(time_t value);
void addSDS(sdsStatus_t value); void addSDS(sdsStatus_t value);
private: private:
void addChars( char* string, int len); void addChars( char* string, int len);

View File

@ -23,7 +23,6 @@
#include <WString.h> #include <WString.h>
class BintrayClient { class BintrayClient {
public: public:
BintrayClient(const String& user, const String& repository, const String& package); BintrayClient(const String& user, const String& repository, const String& package);
String getUser() const; String getUser() const;

View File

@ -48,7 +48,6 @@ void setBMEIRQ() { xTaskNotify(irqHandlerTask, BME_IRQ, eSetBits); }
// initialize MEMS sensor // initialize MEMS sensor
// return = 0 -> error / return = 1 -> success // return = 0 -> error / return = 1 -> success
int bme_init(void) { int bme_init(void) {
int rc = 0; int rc = 0;
#ifdef HAS_BME680 #ifdef HAS_BME680
@ -77,7 +76,6 @@ int bme_init(void) {
if (rc) if (rc)
bmecycler.attach(BMECYCLE, setBMEIRQ); // start cyclic data transmit bmecycler.attach(BMECYCLE, setBMEIRQ); // start cyclic data transmit
return rc; return rc;
} // bme_init() } // bme_init()
#ifdef HAS_BME680 #ifdef HAS_BME680
@ -108,7 +106,6 @@ int checkIaqSensorStatus(void) {
// store current BME sensor data in struct // store current BME sensor data in struct
void bme_storedata(bmeStatus_t *bme_store) { void bme_storedata(bmeStatus_t *bme_store) {
if (cfg.payloadmask & MEMS_DATA) if (cfg.payloadmask & MEMS_DATA)
#ifdef HAS_BME680 #ifdef HAS_BME680
@ -138,7 +135,6 @@ void bme_storedata(bmeStatus_t *bme_store) {
// bme.readAltitude(SEALEVELPRESSURE_HPA); // bme.readAltitude(SEALEVELPRESSURE_HPA);
bme_store->iaq = 0; // IAQ feature not present with BME280 bme_store->iaq = 0; // IAQ feature not present with BME280
#endif #endif
} // bme_storedata() } // bme_storedata()
#ifdef HAS_BME680 #ifdef HAS_BME680

View File

@ -75,7 +75,6 @@ void IRAM_ATTR watchdog() { xTaskResumeFromISR(RestartHandle); }
// used for manually uploading a firmware file via wifi // used for manually uploading a firmware file via wifi
void start_boot_menu(void) { void start_boot_menu(void) {
const char *host = clientId; const char *host = clientId;
const char *ssid = WIFI_SSID; const char *ssid = WIFI_SSID;
const char *password = WIFI_PASS; const char *password = WIFI_PASS;
@ -150,9 +149,7 @@ void start_boot_menu(void) {
// did we get a file name? // did we get a file name?
if (upload.filename != NULL) { if (upload.filename != NULL) {
switch (upload.status) { switch (upload.status) {
case UPLOAD_FILE_START: case UPLOAD_FILE_START:
// start file transfer // start file transfer
ESP_LOGI(TAG, "Uploading %s", upload.filename.c_str()); ESP_LOGI(TAG, "Uploading %s", upload.filename.c_str());
@ -177,7 +174,6 @@ void start_boot_menu(void) {
case UPLOAD_FILE_ABORTED: case UPLOAD_FILE_ABORTED:
default: default:
break; break;
} // switch } // switch
// don't boot to production if update failed // don't boot to production if update failed

View File

@ -26,7 +26,6 @@ static uint8_t buffer[cfgLen + cfgLen2];
// 3. magicByte [cfgLen2 bytes, containing a fixed identifier] // 3. magicByte [cfgLen2 bytes, containing a fixed identifier]
static void defaultConfig(configData_t *myconfig) { static void defaultConfig(configData_t *myconfig) {
strncpy(myconfig->version, PROGVERSION, strncpy(myconfig->version, PROGVERSION,
sizeof(myconfig->version) - 1); // Firmware version sizeof(myconfig->version) - 1); // Firmware version
@ -92,7 +91,6 @@ void saveConfig(bool erase) {
// load configuration from NVRAM into RAM and make it current // load configuration from NVRAM into RAM and make it current
void loadConfig(void) { void loadConfig(void) {
int readBytes = 0; int readBytes = 0;
ESP_LOGI(TAG, "Loading device configuration from NVRAM..."); ESP_LOGI(TAG, "Loading device configuration from NVRAM...");
@ -144,7 +142,6 @@ bool comp(char s1, char s2) { return (tolower(s1) < tolower(s2)); }
// helper function to lexicographically compare two versions. Returns 1 if v2 // helper function to lexicographically compare two versions. Returns 1 if v2
// is smaller, -1 if v1 is smaller, 0 if equal // is smaller, -1 if v1 is smaller, 0 if equal
int version_compare(const String v1, const String v2) { int version_compare(const String v1, const String v2) {
if (v1 == v2) if (v1 == v2)
return 0; return 0;

View File

@ -13,7 +13,6 @@ void setCyclicIRQ() { xTaskNotify(irqHandlerTask, CYCLIC_IRQ, eSetBits); }
// do all housekeeping // do all housekeeping
void doHousekeeping() { void doHousekeeping() {
// check if update or maintenance mode trigger switch was set by rcommand // check if update or maintenance mode trigger switch was set by rcommand
if ((RTC_runmode == RUNMODE_UPDATE) || (RTC_runmode == RUNMODE_MAINTENANCE)) if ((RTC_runmode == RUNMODE_UPDATE) || (RTC_runmode == RUNMODE_MAINTENANCE))
do_reset(true); // warmstart do_reset(true); // warmstart
@ -125,7 +124,6 @@ void doHousekeeping() {
#if (HAS_SDCARD) #if (HAS_SDCARD)
sdcard_flush(); sdcard_flush();
#endif #endif
} // doHousekeeping() } // doHousekeeping()
uint32_t getFreeRAM() { uint32_t getFreeRAM() {

View File

@ -18,41 +18,33 @@ static const char TAG[] = __FILE__;
// triggered by second timepulse to ticker out DCF signal // triggered by second timepulse to ticker out DCF signal
void DCF77_Pulse(uint8_t bit) { void DCF77_Pulse(uint8_t bit) {
TickType_t startTime; TickType_t startTime;
// induce a DCF Pulse // induce a DCF Pulse
for (uint8_t pulseLength = 0; pulseLength <= 2; pulseLength++) { for (uint8_t pulseLength = 0; pulseLength <= 2; pulseLength++) {
startTime = xTaskGetTickCount(); // reference time pulse start startTime = xTaskGetTickCount(); // reference time pulse start
switch (pulseLength) { switch (pulseLength) {
case 0: // 0ms = start of pulse case 0: // 0ms = start of pulse
digitalWrite(HAS_DCF77, dcf_low); digitalWrite(HAS_DCF77, dcf_low);
break; break;
case 1: // 100ms = logic 0 case 1: // 100ms = logic 0
if (bit == 0) if (bit == 0)
digitalWrite(HAS_DCF77, dcf_high); digitalWrite(HAS_DCF77, dcf_high);
break; break;
case 2: // 200ms = logic 1 case 2: // 200ms = logic 1
digitalWrite(HAS_DCF77, dcf_high); digitalWrite(HAS_DCF77, dcf_high);
break; break;
} // switch } // switch
// delay to genrate pulseLength // delay to genrate pulseLength
vTaskDelayUntil(&startTime, pdMS_TO_TICKS(100)); vTaskDelayUntil(&startTime, pdMS_TO_TICKS(100));
} // for } // for
} // DCF77_Pulse() } // DCF77_Pulse()
// helper function to convert decimal to bcd digit // helper function to convert decimal to bcd digit
uint64_t dec2bcd(uint8_t const dec, uint8_t const startpos, uint64_t dec2bcd(uint8_t const dec, uint8_t const startpos,
uint8_t const endpos, uint8_t *parity) { uint8_t const endpos, uint8_t *parity) {
uint8_t data = dec < 10 ? dec : ((dec / 10) << 4) + dec % 10; uint8_t data = dec < 10 ? dec : ((dec / 10) << 4) + dec % 10;
uint64_t bcd = 0; uint64_t bcd = 0;
@ -68,7 +60,6 @@ uint64_t dec2bcd(uint8_t const dec, uint8_t const startpos,
// generates a 1 minute dcf pulse frame for calendar time t // generates a 1 minute dcf pulse frame for calendar time t
uint64_t DCF77_Frame(const struct tm t) { uint64_t DCF77_Frame(const struct tm t) {
uint8_t parity = 0, parity_sum = 0; uint8_t parity = 0, parity_sum = 0;
uint64_t frame = 0; // start with all bits 0 uint64_t frame = 0; // start with all bits 0
@ -105,7 +96,6 @@ uint64_t DCF77_Frame(const struct tm t) {
frame += parity_sum ? set_dcfbit(58) : 0; frame += parity_sum ? set_dcfbit(58) : 0;
return frame; return frame;
} // DCF77_Frame() } // DCF77_Frame()
#endif // HAS_DCF77 #endif // HAS_DCF77

View File

@ -15,7 +15,6 @@ void i2c_init(void) {
void i2c_deinit(void) { Wire.end(); } void i2c_deinit(void) { Wire.end(); }
void i2c_scan(void) { void i2c_scan(void) {
// parts of the code in this function were taken from: // parts of the code in this function were taken from:
// //
// Copyright (c) 2019 BitBank Software, Inc. // Copyright (c) 2019 BitBank Software, Inc.
@ -78,7 +77,6 @@ void i2c_scan(void) {
// functions for i2c r/w access, mutexing is done by Wire.cpp // functions for i2c r/w access, mutexing is done by Wire.cpp
int i2c_readBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) { int i2c_readBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) {
uint8_t ret = 0; uint8_t ret = 0;
Wire.beginTransmission(addr); Wire.beginTransmission(addr);
Wire.write(reg); Wire.write(reg);
@ -100,7 +98,6 @@ finish:
} }
int i2c_writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) { int i2c_writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) {
uint8_t ret = 0; uint8_t ret = 0;
Wire.beginTransmission(addr); Wire.beginTransmission(addr);
Wire.write(reg); Wire.write(reg);
@ -110,4 +107,4 @@ int i2c_writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) {
ret = Wire.endTransmission(); ret = Wire.endTransmission();
return ret ? ret : 0xFF; return ret ? ret : 0xFF;
} }

View File

@ -85,7 +85,6 @@ not evaluated by model BU-190, use "F" instead for this model
static const char TAG[] = __FILE__; static const char TAG[] = __FILE__;
String IF482_Frame(time_t t) { String IF482_Frame(time_t t) {
char mon, out[IF482_FRAME_SIZE + 1], buf[IF482_FRAME_SIZE - 3]; char mon, out[IF482_FRAME_SIZE + 1], buf[IF482_FRAME_SIZE - 3];
if (sntp_get_sync_status() == SNTP_SYNC_STATUS_IN_PROGRESS) if (sntp_get_sync_status() == SNTP_SYNC_STATUS_IN_PROGRESS)

View File

@ -7,7 +7,6 @@ TaskHandle_t irqHandlerTask = NULL;
// irq handler task, handles all our application level interrupts // irq handler task, handles all our application level interrupts
void irqHandler(void *pvParameters) { void irqHandler(void *pvParameters) {
_ASSERT((uint32_t)pvParameters == 1); // FreeRTOS check _ASSERT((uint32_t)pvParameters == 1); // FreeRTOS check
uint32_t irqSource; uint32_t irqSource;

View File

@ -158,7 +158,6 @@ void ledLoop(void *parameter) {
} }
// No custom blink, check LoRaWAN state // No custom blink, check LoRaWAN state
} else { } else {
#if (HAS_LORA) #if (HAS_LORA)
// LED indicators for viusalizing LoRaWAN state // LED indicators for viusalizing LoRaWAN state
if (LMIC.opmode & (OP_JOINING | OP_REJOIN)) { if (LMIC.opmode & (OP_JOINING | OP_REJOIN)) {

View File

@ -14,7 +14,6 @@
*********************************************************************/ *********************************************************************/
void setABPParameters() { void setABPParameters() {
/** ************************************************************** /** **************************************************************
* ************************************************************* */ * ************************************************************* */
#if defined(CFG_eu868) #if defined(CFG_eu868)

View File

@ -19,7 +19,6 @@ void mqtt_deinit(void) {
} }
esp_err_t mqtt_init(void) { esp_err_t mqtt_init(void) {
// setup network connection and MQTT client // setup network connection and MQTT client
ETH.begin(); ETH.begin();
ETH.setHostname(clientId); ETH.setHostname(clientId);
@ -43,7 +42,6 @@ esp_err_t mqtt_init(void) {
} }
int mqtt_connect(const char *my_host, const uint16_t my_port) { int mqtt_connect(const char *my_host, const uint16_t my_port) {
IPAddress mqtt_server_ip; IPAddress mqtt_server_ip;
ESP_LOGI(TAG, "MQTT name is %s", MQTT_CLIENTNAME); ESP_LOGI(TAG, "MQTT name is %s", MQTT_CLIENTNAME);
@ -75,13 +73,10 @@ int mqtt_connect(const char *my_host, const uint16_t my_port) {
} }
void mqtt_client_task(void *param) { void mqtt_client_task(void *param) {
MessageBuffer_t msg; MessageBuffer_t msg;
while (1) { while (1) {
if (mqttClient.connected()) { if (mqttClient.connected()) {
// check for incoming messages // check for incoming messages
mqttClient.loop(); mqttClient.loop();
@ -124,11 +119,10 @@ void mqtt_client_task(void *param) {
// process incoming MQTT messages // process incoming MQTT messages
void mqtt_callback(MQTTClient *client, char *topic, char *payload, int length) { void mqtt_callback(MQTTClient *client, char *topic, char *payload, int length) {
if (strcmp(topic, MQTT_INTOPIC) == 0) { if (strcmp(topic, MQTT_INTOPIC) == 0) {
// get length of base64 encoded message // get length of base64 encoded message
size_t out_len = 0; size_t out_len = 0;
mbedtls_base64_decode(NULL, 0, &out_len, (unsigned char *)payload, length); mbedtls_base64_decode(NULL, 0, &out_len, (unsigned char *)payload, length);
// decode the base64 message // decode the base64 message
unsigned char decoded[out_len]; unsigned char decoded[out_len];
mbedtls_base64_decode(decoded, out_len, &out_len, (unsigned char *)payload, mbedtls_base64_decode(decoded, out_len, &out_len, (unsigned char *)payload,

View File

@ -9,7 +9,6 @@ RtcDS3231<TwoWire> Rtc(Wire); // RTC hardware i2c interface
// initialize RTC // initialize RTC
uint8_t rtc_init(void) { uint8_t rtc_init(void) {
Wire.begin(HAS_RTC); Wire.begin(HAS_RTC);
Rtc.Begin(MY_DISPLAY_SDA, MY_DISPLAY_SCL); Rtc.Begin(MY_DISPLAY_SDA, MY_DISPLAY_SCL);
@ -43,7 +42,6 @@ uint8_t rtc_init(void) {
} // rtc_init() } // rtc_init()
uint8_t set_rtctime(time_t t) { // t is sec epoch time uint8_t set_rtctime(time_t t) { // t is sec epoch time
#ifdef RTC_INT // sync rtc 1Hz pulse on top of second #ifdef RTC_INT // sync rtc 1Hz pulse on top of second
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone); // off Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone); // off
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock); // start Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock); // start
@ -55,7 +53,6 @@ uint8_t set_rtctime(time_t t) { // t is sec epoch time
} // set_rtctime() } // set_rtctime()
time_t get_rtctime(uint16_t *msec) { time_t get_rtctime(uint16_t *msec) {
time_t t = 0; time_t t = 0;
*msec = 0; *msec = 0;
if (Rtc.IsDateTimeValid() && Rtc.GetIsRunning()) { if (Rtc.IsDateTimeValid() && Rtc.GetIsRunning()) {

View File

@ -72,7 +72,6 @@ void SendPayload(uint8_t port) {
// timer triggered function to prepare payload to send // timer triggered function to prepare payload to send
void sendData() { void sendData() {
uint8_t bitmask = cfg.payloadmask; uint8_t bitmask = cfg.payloadmask;
uint8_t mask = 1; uint8_t mask = 1;
@ -91,7 +90,6 @@ void sendData() {
while (bitmask) { while (bitmask) {
switch (bitmask & mask) { switch (bitmask & mask) {
#if ((WIFICOUNTER) || (BLECOUNTER)) #if ((WIFICOUNTER) || (BLECOUNTER))
case COUNT_DATA: case COUNT_DATA:
payload.reset(); payload.reset();
@ -197,7 +195,6 @@ void sendData() {
SendPayload(BATTPORT); SendPayload(BATTPORT);
break; break;
#endif #endif
} // switch } // switch
bitmask &= ~mask; bitmask &= ~mask;
mask <<= 1; mask <<= 1;

View File

@ -9,7 +9,6 @@ static const char TAG[] = __FILE__;
10 // max. size of user sensor data buffer in bytes [default=20] 10 // max. size of user sensor data buffer in bytes [default=20]
void sensor_init(void) { void sensor_init(void) {
// this function is called during device startup // this function is called during device startup
// put your user sensor initialization routines here // put your user sensor initialization routines here
} }
@ -38,14 +37,11 @@ uint8_t sensor_mask(uint8_t sensor_no) {
} }
uint8_t *sensor_read(uint8_t sensor) { uint8_t *sensor_read(uint8_t sensor) {
static uint8_t buf[SENSORBUFFER] = {0}; static uint8_t buf[SENSORBUFFER] = {0};
uint8_t length = 3; uint8_t length = 3;
switch (sensor) { switch (sensor) {
case 1: case 1:
// insert user specific sensor data frames here // insert user specific sensor data frames here
buf[0] = length; buf[0] = length;
buf[1] = 0x01; buf[1] = 0x01;
@ -53,15 +49,12 @@ uint8_t *sensor_read(uint8_t sensor) {
buf[3] = 0x03; buf[3] = 0x03;
break; break;
case 2: case 2:
buf[0] = length; buf[0] = length;
buf[1] = 0x01; buf[1] = 0x01;
buf[2] = 0x02; buf[2] = 0x02;
buf[3] = 0x03; buf[3] = 0x03;
break; break;
case 3: case 3:
buf[0] = length; buf[0] = length;
buf[1] = 0x01; buf[1] = 0x01;
buf[2] = 0x02; buf[2] = 0x02;
@ -70,4 +63,4 @@ uint8_t *sensor_read(uint8_t sensor) {
} }
return buf; return buf;
} }

View File

@ -56,7 +56,6 @@ void timesync_request(void) {
// task for processing time sync request // task for processing time sync request
void timesync_processReq(void *taskparameter) { void timesync_processReq(void *taskparameter) {
uint32_t rcv_seqNo = TIME_SYNC_END_FLAG; uint32_t rcv_seqNo = TIME_SYNC_END_FLAG;
uint32_t time_offset_sec = 0, time_offset_ms = 0; uint32_t time_offset_sec = 0, time_offset_ms = 0;
@ -68,7 +67,6 @@ void timesync_processReq(void *taskparameter) {
// --- asnychronous part: generate and collect timestamps from gateway --- // --- asnychronous part: generate and collect timestamps from gateway ---
while (1) { while (1) {
// wait for kickoff // wait for kickoff
ulTaskNotifyTake(pdFALSE, portMAX_DELAY); ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
@ -85,7 +83,6 @@ void timesync_processReq(void *taskparameter) {
// collect timestamp samples in timestamp array // collect timestamp samples in timestamp array
for (int8_t i = 0; i < TIME_SYNC_SAMPLES; i++) { for (int8_t i = 0; i < TIME_SYNC_SAMPLES; i++) {
// send timesync request // send timesync request
#if (TIME_SYNC_LORASERVER) // ask user's timeserver (for LoRAWAN < 1.0.3) #if (TIME_SYNC_LORASERVER) // ask user's timeserver (for LoRAWAN < 1.0.3)
payload.reset(); payload.reset();
@ -122,7 +119,6 @@ void timesync_processReq(void *taskparameter) {
// if we are not in last cycle, pause until next cycle // if we are not in last cycle, pause until next cycle
if (i < TIME_SYNC_SAMPLES - 1) if (i < TIME_SYNC_SAMPLES - 1)
vTaskDelay(pdMS_TO_TICKS(TIME_SYNC_CYCLE * 1000)); vTaskDelay(pdMS_TO_TICKS(TIME_SYNC_CYCLE * 1000));
} // for i } // for i
// --- time critial part: evaluate timestamps and calculate time --- // --- time critial part: evaluate timestamps and calculate time ---
@ -174,7 +170,6 @@ void timesync_store(uint32_t timestamp, timesync_t timestamp_type) {
// callback function to receive time answer from network or answer // callback function to receive time answer from network or answer
void timesync_serverAnswer(void *pUserData, int flag) { void timesync_serverAnswer(void *pUserData, int flag) {
#if (HAS_LORA_TIME) #if (HAS_LORA_TIME)
// if no timesync handshake is pending then exit // if no timesync handshake is pending then exit