rcommand.cpp: code sanitization
This commit is contained in:
parent
2352d7d743
commit
59e3876296
@ -379,9 +379,13 @@ void set_saveconfig(uint8_t val[]) {
|
||||
saveConfig(false);
|
||||
};
|
||||
|
||||
// assign previously defined functions to set of numeric remote commands
|
||||
// format: {opcode, function, number of function arguments}
|
||||
static const cmd_t table[] = {
|
||||
// check and execute remote command
|
||||
void rcmd_execute(const uint8_t cmd[], const uint8_t cmdlength) {
|
||||
|
||||
// assign previously defined functions to set of numeric remote commands
|
||||
// format: {opcode, function, number of function arguments}
|
||||
|
||||
const cmd_t table[] = {
|
||||
{0x01, set_rssi, 1}, {0x02, set_countmode, 1},
|
||||
{0x03, set_gps, 1}, {0x04, set_display, 1},
|
||||
{0x05, set_loradr, 1}, {0x06, set_lorapower, 1},
|
||||
@ -401,20 +405,15 @@ static const cmd_t table[] = {
|
||||
{0x86, get_time, 0}, {0x87, set_time, 0},
|
||||
{0x99, set_flush, 0}};
|
||||
|
||||
static const uint8_t cmdtablesize =
|
||||
sizeof(table) / sizeof(table[0]); // number of commands in command table
|
||||
|
||||
// check and execute remote command
|
||||
void rcmd_execute(const uint8_t cmd[], const uint8_t cmdlength) {
|
||||
|
||||
if (cmdlength == 0)
|
||||
return;
|
||||
|
||||
uint8_t foundcmd[cmdlength], cursor = 0;
|
||||
int i =
|
||||
sizeof(table) / sizeof(table[0]); // number of commands in command table
|
||||
|
||||
while (cursor < cmdlength) {
|
||||
|
||||
int i = cmdtablesize;
|
||||
while (i--) {
|
||||
if (cmd[cursor] == table[i].opcode) { // lookup command in opcode table
|
||||
cursor++; // strip 1 byte opcode
|
||||
@ -432,6 +431,7 @@ void rcmd_execute(const uint8_t cmd[], const uint8_t cmdlength) {
|
||||
break; // command found -> exit table lookup loop
|
||||
} // end of command validation
|
||||
} // end of command table lookup loop
|
||||
|
||||
if (i < 0) { // command not found -> exit parser
|
||||
ESP_LOGI(TAG, "Unknown remote command x%02X, ignored", cmd[cursor]);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user