@@ -268,14 +268,15 @@ uint8_t digits(uint8_t port)
268
268
return 1 ;
269
269
}
270
270
271
- uint8_t receivedPort (const char *s, size_t length )
271
+ uint8_t receivedPort (const char *s)
272
272
{
273
273
uint8_t port = 0 ;
274
- while (s[length] != ' ' && s[length] != ' \0 ' )
274
+ uint8_t i = 0 ;
275
+ while (s[i] != ' ' && s[i] != ' \0 ' )
275
276
{
276
277
port *= 10 ;
277
- port += s[length ] - 48 ;
278
- length ++;
278
+ port += s[i ] - 48 ;
279
+ i ++;
279
280
}
280
281
return port;
281
282
}
@@ -291,34 +292,31 @@ TheThingsNetwork::TheThingsNetwork(Stream &modemStream, Stream &debugStream, ttn
291
292
292
293
void TheThingsNetwork::debugPrintIndex (uint8_t index, const char *value)
293
294
{
294
- strcpy_P (buffer, (char *)pgm_read_word (&(show_table[index])));
295
- debugPrint (buffer);
295
+ char message[100 ];
296
+ strcpy_P (message, (char *)pgm_read_word (&(show_table[index])));
297
+ debugPrint (message);
296
298
if (value)
297
299
{
298
300
debugPrintLn (value);
299
301
}
300
302
}
301
303
302
- void TheThingsNetwork::debugPrintMessage (uint8_t type, uint8_t index, const char *output )
304
+ void TheThingsNetwork::debugPrintMessage (uint8_t type, uint8_t index, const char *value )
303
305
{
306
+ char message[100 ];
304
307
switch (type)
305
308
{
306
309
case ERR_MESSAGE:
307
- strcpy_P (buffer , (char *)pgm_read_word (&(error_msg[index])));
310
+ strcpy_P (message , (char *)pgm_read_word (&(error_msg[index])));
308
311
break ;
309
312
case SUCCESS_MESSAGE:
310
- strcpy_P (buffer , (char *)pgm_read_word (&(success_msg[index])));
313
+ strcpy_P (message , (char *)pgm_read_word (&(success_msg[index])));
311
314
break ;
312
315
}
313
- debugPrint (buffer);
314
- if (type == SUCCESS_MESSAGE && index == SCS_SUCCESSFUL_TRANSMISSION_RECEIVED)
315
- {
316
- debugPrint (output);
317
- debugPrintLn (" bytes" );
318
- }
319
- else if (output)
316
+ debugPrint (message);
317
+ if (value)
320
318
{
321
- debugPrintLn (output );
319
+ debugPrintLn (value );
322
320
}
323
321
else
324
322
{
@@ -367,8 +365,8 @@ size_t TheThingsNetwork::readResponse(uint8_t prefixTable, uint8_t indexTable, u
367
365
void TheThingsNetwork::reset (bool adr)
368
366
{
369
367
size_t length = readResponse (SYS_TABLE, SYS_RESET, buffer, sizeof (buffer));
370
- debugPrintLn (buffer);
371
368
369
+ // buffer contains "RN2xx3 1.x.x ...", splitting model from version
372
370
buffer[6 ] = ' \0 ' ;
373
371
debugPrintIndex (SHOW_MODEL, buffer);
374
372
debugPrintIndex (SHOW_VERSION, buffer + 7 );
@@ -496,19 +494,16 @@ ttn_response_t TheThingsNetwork::sendBytes(const uint8_t *payload, size_t length
496
494
return TTN_ERROR_SEND_COMMAND_FAILED;
497
495
}
498
496
499
- char response[500 ];
500
- readLine (response, sizeof (response));
501
-
502
- if (pgmstrcmp (response, CMP_MAC_TX_OK) == 0 )
497
+ readLine (buffer, sizeof (buffer));
498
+ if (pgmstrcmp (buffer, CMP_MAC_TX_OK) == 0 )
503
499
{
504
500
debugPrintMessage (SUCCESS_MESSAGE, SCS_SUCCESSFUL_TRANSMISSION);
505
501
return TTN_SUCCESSFUL_TRANSMISSION;
506
502
}
507
-
508
- if (pgmstrcmp (response, CMP_MAC_RX) == 0 )
503
+ if (pgmstrcmp (buffer, CMP_MAC_RX) == 0 )
509
504
{
510
- port_t downlinkPort = receivedPort (response, 7 );
511
- char *data = response + 7 + digits (downlinkPort) + 1 ;
505
+ port_t downlinkPort = receivedPort (buffer + 7 );
506
+ char *data = buffer + 7 + digits (downlinkPort) + 1 ;
512
507
size_t downlinkLength = strlen (data) / 2 ;
513
508
uint8_t downlink[downlinkLength];
514
509
for (size_t i = 0 , d = 0 ; i < downlinkLength; i++, d += 2 )
@@ -523,11 +518,11 @@ ttn_response_t TheThingsNetwork::sendBytes(const uint8_t *payload, size_t length
523
518
return TTN_SUCCESSFUL_RECEIVE;
524
519
}
525
520
526
- debugPrintMessage (ERR_MESSAGE, ERR_UNEXPECTED_RESPONSE, response );
521
+ debugPrintMessage (ERR_MESSAGE, ERR_UNEXPECTED_RESPONSE, buffer );
527
522
return TTN_ERROR_UNEXPECTED_RESPONSE;
528
523
}
529
524
530
- int8_t TheThingsNetwork::poll (port_t port, bool confirm)
525
+ ttn_response_t TheThingsNetwork::poll (port_t port, bool confirm)
531
526
{
532
527
uint8_t payload[] = {0x00 };
533
528
return sendBytes (payload, 1 , port, confirm);
@@ -683,54 +678,55 @@ void TheThingsNetwork::configureChannels(uint8_t sf, uint8_t fsb)
683
678
684
679
void TheThingsNetwork::sendCommand (uint8_t table, uint8_t index, bool appendSpace, bool print)
685
680
{
681
+ char command[100 ];
686
682
switch (table)
687
683
{
688
684
case MAC_TABLE:
689
- strcpy_P (buffer , (char *)pgm_read_word (&(mac_table[index])));
685
+ strcpy_P (command , (char *)pgm_read_word (&(mac_table[index])));
690
686
break ;
691
687
case MAC_GET_SET_TABLE:
692
- strcpy_P (buffer , (char *)pgm_read_word (&(mac_set_options[index])));
688
+ strcpy_P (command , (char *)pgm_read_word (&(mac_set_options[index])));
693
689
break ;
694
690
case MAC_JOIN_TABLE:
695
- strcpy_P (buffer , (char *)pgm_read_word (&(mac_join_mode[index])));
691
+ strcpy_P (command , (char *)pgm_read_word (&(mac_join_mode[index])));
696
692
break ;
697
693
case MAC_CH_TABLE:
698
- strcpy_P (buffer , (char *)pgm_read_word (&(mac_ch_options[index])));
694
+ strcpy_P (command , (char *)pgm_read_word (&(mac_ch_options[index])));
699
695
break ;
700
696
case MAC_TX_TABLE:
701
- strcpy_P (buffer , (char *)pgm_read_word (&(mac_tx_table[index])));
697
+ strcpy_P (command , (char *)pgm_read_word (&(mac_tx_table[index])));
702
698
break ;
703
699
case SYS_TABLE:
704
- strcpy_P (buffer , (char *)pgm_read_word (&(sys_table[index])));
700
+ strcpy_P (command , (char *)pgm_read_word (&(sys_table[index])));
705
701
break ;
706
702
case RADIO_TABLE:
707
- strcpy_P (buffer , (char *)pgm_read_word (&(radio_table[index])));
703
+ strcpy_P (command , (char *)pgm_read_word (&(radio_table[index])));
708
704
break ;
709
705
default :
710
706
return ;
711
707
}
712
- modemStream->write (buffer );
708
+ modemStream->write (command );
713
709
if (appendSpace)
714
710
{
715
711
modemStream->write (" " );
716
712
}
717
713
if (print)
718
714
{
719
- debugPrint (buffer );
715
+ debugPrint (command );
720
716
debugPrint (F (" " ));
721
717
}
722
718
}
723
719
724
- bool TheThingsNetwork::sendMacSet (uint8_t index, const char *setting )
720
+ bool TheThingsNetwork::sendMacSet (uint8_t index, const char *value )
725
721
{
726
722
clearReadBuffer ();
727
723
debugPrint (SENDING);
728
724
sendCommand (MAC_TABLE, MAC_PREFIX, true );
729
725
sendCommand (MAC_TABLE, MAC_SET, true );
730
726
sendCommand (MAC_GET_SET_TABLE, index, true );
731
- modemStream->write (setting );
727
+ modemStream->write (value );
732
728
modemStream->write (SEND_MSG);
733
- debugPrintLn (setting );
729
+ debugPrintLn (value );
734
730
return waitForOk ();
735
731
}
736
732
@@ -745,7 +741,7 @@ bool TheThingsNetwork::waitForOk()
745
741
return true ;
746
742
}
747
743
748
- bool TheThingsNetwork::sendChSet (uint8_t index, uint8_t channel, const char *setting )
744
+ bool TheThingsNetwork::sendChSet (uint8_t index, uint8_t channel, const char *value )
749
745
{
750
746
clearReadBuffer ();
751
747
char ch[5 ];
@@ -767,11 +763,11 @@ bool TheThingsNetwork::sendChSet(uint8_t index, uint8_t channel, const char *set
767
763
sendCommand (MAC_CH_TABLE, index, true );
768
764
modemStream->write (ch);
769
765
modemStream->write (" " );
770
- modemStream->write (setting );
766
+ modemStream->write (value );
771
767
modemStream->write (SEND_MSG);
772
768
debugPrint (channel);
773
769
debugPrint (F (" " ));
774
- debugPrintLn (setting );
770
+ debugPrintLn (value );
775
771
return waitForOk ();
776
772
}
777
773
@@ -838,9 +834,9 @@ bool TheThingsNetwork::sendPayload(uint8_t mode, uint8_t port, uint8_t *payload,
838
834
return waitForOk ();
839
835
}
840
836
841
- void TheThingsNetwork::sleep (unsigned long msec )
837
+ void TheThingsNetwork::sleep (uint32_t mseconds )
842
838
{
843
- if (msec < 100 || msec >= 4294967296 )
839
+ if (mseconds < 100 || mseconds >= 4294967296 )
844
840
{
845
841
return ;
846
842
}
@@ -849,7 +845,7 @@ void TheThingsNetwork::sleep(unsigned long msec)
849
845
sendCommand (SYS_TABLE, SYS_PREFIX, true );
850
846
sendCommand (SYS_TABLE, SYS_SLEEP, true );
851
847
852
- sprintf (buffer, " %ld" , msec );
848
+ sprintf (buffer, " %ld" , mseconds );
853
849
modemStream->write (buffer);
854
850
modemStream->write (SEND_MSG);
855
851
debugPrintLn (buffer);
0 commit comments