Skip to content

Commit ef877ff

Browse files
committed
Modifications for ESP32
1. Change from pgm_read_word to pgm_read_dword (see TheThingsNetwork#289) 2. Add null pointer check to checkValidModuleConnected
1 parent 867ab97 commit ef877ff

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

src/TheThingsNetwork.cpp

+28-26
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,12 @@ int pgmstrcmp(const char *str1, uint8_t str2Index, uint8_t table = CMP_TABLE)
380380

381381
switch (table) {
382382
case CMP_ERR_TABLE:
383-
strcpy_P(str2, (char *)pgm_read_word(&(compareerr_table[str2Index])));
383+
strcpy_P(str2, (char *)pgm_read_dword(&(compareerr_table[str2Index])));
384384
break;
385385

386386
default:
387387
case CMP_TABLE:
388-
strcpy_P(str2, (char *)pgm_read_word(&(compare_table[str2Index])));
388+
strcpy_P(str2, (char *)pgm_read_dword(&(compare_table[str2Index])));
389389
}
390390

391391
return memcmp(str1, str2, min(strlen(str1), strlen(str2)));
@@ -603,7 +603,7 @@ ttn_response_code_t TheThingsNetwork::getLastError(){
603603
void TheThingsNetwork::debugPrintIndex(uint8_t index, const char *value)
604604
{
605605
char message[100];
606-
strcpy_P(message, (char *)pgm_read_word(&(show_table[index])));
606+
strcpy_P(message, (char *)pgm_read_dword(&(show_table[index])));
607607
debugPrint(message);
608608
if (value)
609609
{
@@ -617,10 +617,10 @@ void TheThingsNetwork::debugPrintMessage(uint8_t type, uint8_t index, const char
617617
switch (type)
618618
{
619619
case ERR_MESSAGE:
620-
strcpy_P(message, (char *)pgm_read_word(&(error_msg[index])));
620+
strcpy_P(message, (char *)pgm_read_dword(&(error_msg[index])));
621621
break;
622622
case SUCCESS_MESSAGE:
623-
strcpy_P(message, (char *)pgm_read_word(&(success_msg[index])));
623+
strcpy_P(message, (char *)pgm_read_dword(&(success_msg[index])));
624624
break;
625625
}
626626
debugPrint(message);
@@ -1088,19 +1088,21 @@ bool TheThingsNetwork::checkValidModuleConnected(bool autoBaudFirst)
10881088
}
10891089
// buffer contains "RN2xx3[xx] x.x.x ...", getting only model (RN2xx3[xx])
10901090
char *model = strtok(buffer, " ");
1091-
debugPrintIndex(SHOW_MODEL, model);
1092-
// check if module is valid (must be RN2483, RN2483A, RN2903, RN2903AS or SAMR34)
1093-
if(pgmstrcmp(model, CMP_RN2483) == 0 || pgmstrcmp(model, CMP_RN2483A) == 0 || pgmstrcmp(model, CMP_RN2903) == 0 || pgmstrcmp(model, CMP_RN2903AS) == 0)
1094-
{
1095-
setModemType(TTN_MODEM_TYPE_RN);
1096-
debugPrintMessage(SUCCESS_MESSAGE, SCS_VALID_MODULE);
1097-
return true; // module responded and is valid (recognized/supported)
1098-
}
1099-
else if(pgmstrcmp(model, CMP_SAMR34) == 0)
1100-
{
1101-
setModemType(TTN_MODEM_TYPE_SAMR34);
1102-
debugPrintMessage(SUCCESS_MESSAGE, SCS_VALID_MODULE); // module responded and is valid (recognized/supported)
1103-
return true;
1091+
if(model != NULL) {
1092+
debugPrintIndex(SHOW_MODEL, model);
1093+
// check if module is valid (must be RN2483, RN2483A, RN2903, RN2903AS or SAMR34)
1094+
if(pgmstrcmp(model, CMP_RN2483) == 0 || pgmstrcmp(model, CMP_RN2483A) == 0 || pgmstrcmp(model, CMP_RN2903) == 0 || pgmstrcmp(model, CMP_RN2903AS) == 0)
1095+
{
1096+
setModemType(TTN_MODEM_TYPE_RN);
1097+
debugPrintMessage(SUCCESS_MESSAGE, SCS_VALID_MODULE);
1098+
return true; // module responded and is valid (recognized/supported)
1099+
}
1100+
else if(pgmstrcmp(model, CMP_SAMR34) == 0)
1101+
{
1102+
setModemType(TTN_MODEM_TYPE_SAMR34);
1103+
debugPrintMessage(SUCCESS_MESSAGE, SCS_VALID_MODULE); // module responded and is valid (recognized/supported)
1104+
return true;
1105+
}
11041106
}
11051107
debugPrintMessage(ERR_MESSAGE, ERR_INVALID_MODULE);
11061108
return false; // module responded but is invalid (unrecognized/unsupported)
@@ -1457,28 +1459,28 @@ void TheThingsNetwork::sendCommand(uint8_t table, uint8_t index, bool appendSpac
14571459
switch (table)
14581460
{
14591461
case MAC_TABLE:
1460-
strcpy_P(command, (char *)pgm_read_word(&(mac_table[index])));
1462+
strcpy_P(command, (char *)pgm_read_dword(&(mac_table[index])));
14611463
break;
14621464
case MAC_GET_SET_TABLE:
1463-
strcpy_P(command, (char *)pgm_read_word(&(mac_options[index])));
1465+
strcpy_P(command, (char *)pgm_read_dword(&(mac_options[index])));
14641466
break;
14651467
case MAC_JOIN_TABLE:
1466-
strcpy_P(command, (char *)pgm_read_word(&(mac_join_mode[index])));
1468+
strcpy_P(command, (char *)pgm_read_dword(&(mac_join_mode[index])));
14671469
break;
14681470
case MAC_CH_TABLE:
1469-
strcpy_P(command, (char *)pgm_read_word(&(mac_ch_options[index])));
1471+
strcpy_P(command, (char *)pgm_read_dword(&(mac_ch_options[index])));
14701472
break;
14711473
case MAC_TX_TABLE:
1472-
strcpy_P(command, (char *)pgm_read_word(&(mac_tx_table[index])));
1474+
strcpy_P(command, (char *)pgm_read_dword(&(mac_tx_table[index])));
14731475
break;
14741476
case SYS_TABLE:
1475-
strcpy_P(command, (char *)pgm_read_word(&(sys_table[index])));
1477+
strcpy_P(command, (char *)pgm_read_dword(&(sys_table[index])));
14761478
break;
14771479
case RADIO_TABLE:
1478-
strcpy_P(command, (char *)pgm_read_word(&(radio_table[index])));
1480+
strcpy_P(command, (char *)pgm_read_dword(&(radio_table[index])));
14791481
break;
14801482
case MAC_RESET_TABLE:
1481-
strcpy_P(command, (char *)pgm_read_word(&(mac_reset_table[index])));
1483+
strcpy_P(command, (char *)pgm_read_dword(&(mac_reset_table[index])));
14821484
break;
14831485
default:
14841486
return;

0 commit comments

Comments
 (0)