rcommand.cpp: code sanitizations

This commit is contained in:
cyberman54 2023-03-12 14:09:31 +01:00
parent e37dae601d
commit eed618cfaa

View File

@ -58,7 +58,7 @@ void set_rssi(uint8_t val[]) {
current_config.ble_rssi_threshold = cfg.rssilimit; current_config.ble_rssi_threshold = cfg.rssilimit;
libpax_update_config(&current_config); libpax_update_config(&current_config);
init_libpax(); init_libpax();
ESP_LOGI(TAG, "Remote command: set RSSI limit to %d", cfg.rssilimit); ESP_LOGI(TAG, "Remote command: set RSSI limit to %hd", cfg.rssilimit);
} }
void set_sendcycle(uint8_t val[]) { void set_sendcycle(uint8_t val[]) {
@ -66,7 +66,7 @@ void set_sendcycle(uint8_t val[]) {
return; return;
// update send cycle interrupt [seconds / 2] // update send cycle interrupt [seconds / 2]
cfg.sendcycle = val[0]; cfg.sendcycle = val[0];
ESP_LOGI(TAG, "Remote command: set send cycle to %d seconds", ESP_LOGI(TAG, "Remote command: set send cycle to %u seconds",
cfg.sendcycle * 2); cfg.sendcycle * 2);
libpax_counter_stop(); libpax_counter_stop();
init_libpax(); init_libpax();
@ -75,7 +75,7 @@ void set_sendcycle(uint8_t val[]) {
void set_sleepcycle(uint8_t val[]) { void set_sleepcycle(uint8_t val[]) {
// swap byte order from msb to lsb, note: this is a platform dependent hack // swap byte order from msb to lsb, note: this is a platform dependent hack
cfg.sleepcycle = __builtin_bswap16(*(uint16_t *)(val)); cfg.sleepcycle = __builtin_bswap16(*(uint16_t *)(val));
ESP_LOGI(TAG, "Remote command: set sleep cycle to %d seconds", ESP_LOGI(TAG, "Remote command: set sleep cycle to %hu seconds",
cfg.sleepcycle * 10); cfg.sleepcycle * 10);
} }
@ -198,7 +198,7 @@ void set_sensor(uint8_t val[]) {
return; // invalid sensor number -> exit return; // invalid sensor number -> exit
} }
ESP_LOGI(TAG, "Remote command: set sensor #%d mode to %s", val[0], ESP_LOGI(TAG, "Remote command: set sensor #%u mode to %s", val[0],
val[1] ? "on" : "off"); val[1] ? "on" : "off");
if (val[1]) if (val[1])
@ -218,7 +218,7 @@ void set_loradr(uint8_t val[]) {
#if (HAS_LORA) #if (HAS_LORA)
if (validDR(val[0])) { if (validDR(val[0])) {
cfg.loradr = val[0]; cfg.loradr = val[0];
ESP_LOGI(TAG, "Remote command: set LoRa Datarate to %d", cfg.loradr); ESP_LOGI(TAG, "Remote command: set LoRa Datarate to %u", cfg.loradr);
LMIC_setDrTxpow(assertDR(cfg.loradr), KEEP_TXPOW); LMIC_setDrTxpow(assertDR(cfg.loradr), KEEP_TXPOW);
ESP_LOGI(TAG, "Radio parameters now %s / %s / %s", ESP_LOGI(TAG, "Radio parameters now %s / %s / %s",
getSfName(updr2rps(LMIC.datarate)), getSfName(updr2rps(LMIC.datarate)),
@ -227,7 +227,7 @@ void set_loradr(uint8_t val[]) {
} else } else
ESP_LOGI( ESP_LOGI(
TAG, TAG,
"Remote command: set LoRa Datarate called with illegal datarate %d", "Remote command: set LoRa Datarate called with illegal datarate %u",
val[0]); val[0]);
#else #else
ESP_LOGW(TAG, "Remote command: LoRa not implemented"); ESP_LOGW(TAG, "Remote command: LoRa not implemented");
@ -280,15 +280,15 @@ void set_wifiant(uint8_t val[]) {
void set_rgblum(uint8_t val[]) { void set_rgblum(uint8_t val[]) {
// Avoid wrong parameters // Avoid wrong parameters
cfg.rgblum = (val[0] <= 100) ? (uint8_t)val[0] : RGBLUMINOSITY; cfg.rgblum = (val[0] <= 100) ? (uint8_t)val[0] : RGBLUMINOSITY;
ESP_LOGI(TAG, "Remote command: set RGB Led luminosity %d", cfg.rgblum); ESP_LOGI(TAG, "Remote command: set RGB Led luminosity %u", cfg.rgblum);
}; }
void set_lorapower(uint8_t val[]) { void set_lorapower(uint8_t val[]) {
#if (HAS_LORA) #if (HAS_LORA)
// set data rate and transmit power only if we have no ADR // set data rate and transmit power only if we have no ADR
if (!cfg.adrmode) { if (!cfg.adrmode) {
cfg.txpower = val[0]; cfg.txpower = val[0];
ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %d", cfg.txpower); ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %u", cfg.txpower);
LMIC_setDrTxpow(assertDR(cfg.loradr), cfg.txpower); LMIC_setDrTxpow(assertDR(cfg.loradr), cfg.txpower);
} else } else
ESP_LOGI( ESP_LOGI(
@ -298,14 +298,14 @@ void set_lorapower(uint8_t val[]) {
#else #else
ESP_LOGW(TAG, "Remote command: LoRa not implemented"); ESP_LOGW(TAG, "Remote command: LoRa not implemented");
#endif // HAS_LORA #endif // HAS_LORA
}; }
void get_config(uint8_t val[]) { void get_config(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get device configuration"); ESP_LOGI(TAG, "Remote command: get device configuration");
payload.reset(); payload.reset();
payload.addConfig(cfg); payload.addConfig(cfg);
SendPayload(CONFIGPORT); SendPayload(CONFIGPORT);
}; }
void get_status(uint8_t val[]) { void get_status(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get device status"); ESP_LOGI(TAG, "Remote command: get device status");
@ -320,7 +320,7 @@ void get_status(uint8_t val[]) {
RTC_restarts); RTC_restarts);
#endif #endif
SendPayload(STATUSPORT); SendPayload(STATUSPORT);
}; }
void get_gps(uint8_t val[]) { void get_gps(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get gps status"); ESP_LOGI(TAG, "Remote command: get gps status");
@ -333,7 +333,7 @@ void get_gps(uint8_t val[]) {
#else #else
ESP_LOGW(TAG, "GPS function not supported"); ESP_LOGW(TAG, "GPS function not supported");
#endif #endif
}; }
void get_bme(uint8_t val[]) { void get_bme(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get bme680 sensor data"); ESP_LOGI(TAG, "Remote command: get bme680 sensor data");
@ -344,7 +344,7 @@ void get_bme(uint8_t val[]) {
#else #else
ESP_LOGW(TAG, "BME sensor not supported"); ESP_LOGW(TAG, "BME sensor not supported");
#endif #endif
}; }
void get_batt(uint8_t val[]) { void get_batt(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get battery voltage"); ESP_LOGI(TAG, "Remote command: get battery voltage");
@ -355,7 +355,7 @@ void get_batt(uint8_t val[]) {
#else #else
ESP_LOGW(TAG, "Battery voltage not supported"); ESP_LOGW(TAG, "Battery voltage not supported");
#endif #endif
}; }
void get_time(uint8_t val[]) { void get_time(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get time"); ESP_LOGI(TAG, "Remote command: get time");
@ -364,35 +364,35 @@ void get_time(uint8_t val[]) {
payload.addTime(t); payload.addTime(t);
payload.addByte(sntp_get_sync_status() << 4 | timeSource); payload.addByte(sntp_get_sync_status() << 4 | timeSource);
SendPayload(TIMEPORT); SendPayload(TIMEPORT);
}; }
void set_timesync(uint8_t val[]) { void set_timesync(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: timesync requested"); ESP_LOGI(TAG, "Remote command: timesync requested");
setTimeSyncIRQ(); setTimeSyncIRQ();
}; }
void set_time(uint8_t val[]) { void set_time(uint8_t val[]) {
// swap byte order from msb to lsb, note: this is a platform dependent hack // swap byte order from msb to lsb, note: this is a platform dependent hack
uint32_t t = __builtin_bswap32(*(uint32_t *)(val)); uint32_t t = __builtin_bswap32(*(uint32_t *)(val));
ESP_LOGI(TAG, "Remote command: set time to %lu", t); ESP_LOGI(TAG, "Remote command: set time to %lu", t);
setMyTime(t, 0, _set); setMyTime(t, 0, _set);
}; }
void set_flush(uint8_t val[]) { void set_flush(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: flush"); ESP_LOGI(TAG, "Remote command: flush");
// does nothing // does nothing
// used to open receive window on LoRaWAN class a nodes // used to open receive window on LoRaWAN class a nodes
}; }
void set_loadconfig(uint8_t val[]) { void set_loadconfig(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: load config from NVRAM"); ESP_LOGI(TAG, "Remote command: load config from NVRAM");
loadConfig(); loadConfig();
}; }
void set_saveconfig(uint8_t val[]) { void set_saveconfig(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: save config to NVRAM"); ESP_LOGI(TAG, "Remote command: save config to NVRAM");
saveConfig(false); saveConfig(false);
}; }
// assign previously defined functions to set of numeric remote commands // assign previously defined functions to set of numeric remote commands
// format: {opcode, function, number of function arguments} // format: {opcode, function, number of function arguments}
@ -497,7 +497,7 @@ esp_err_t rcmd_init(void) {
ESP_LOGE(TAG, "Could not create rcommand send queue. Aborting."); ESP_LOGE(TAG, "Could not create rcommand send queue. Aborting.");
return ESP_FAIL; return ESP_FAIL;
} }
ESP_LOGI(TAG, "Rcommand send queue created, size %d Bytes", ESP_LOGI(TAG, "Rcommand send queue created, size %u Bytes",
RCMD_QUEUE_SIZE * sizeof(RcmdBuffer_t)); RCMD_QUEUE_SIZE * sizeof(RcmdBuffer_t));
xTaskCreatePinnedToCore(rcmd_process, // task function xTaskCreatePinnedToCore(rcmd_process, // task function