@@ -291,7 +291,6 @@ TheThingsNetwork::TheThingsNetwork(Stream &modemStream, Stream &debugStream, ttn
291
291
292
292
void TheThingsNetwork::debugPrintIndex (uint8_t index, const char *value)
293
293
{
294
- char buffer[100 ];
295
294
strcpy_P (buffer, (char *)pgm_read_word (&(show_table[index])));
296
295
debugPrint (buffer);
297
296
if (value)
@@ -302,7 +301,6 @@ void TheThingsNetwork::debugPrintIndex(uint8_t index, const char *value)
302
301
303
302
void TheThingsNetwork::debugPrintMessage (uint8_t type, uint8_t index, const char *output)
304
303
{
305
- char buffer[100 ];
306
304
switch (type)
307
305
{
308
306
case ERR_MESSAGE:
@@ -368,7 +366,6 @@ size_t TheThingsNetwork::readResponse(uint8_t prefixTable, uint8_t indexTable, u
368
366
369
367
void TheThingsNetwork::reset (bool adr)
370
368
{
371
- char buffer[100 ];
372
369
size_t length = readResponse (SYS_TABLE, SYS_RESET, buffer, sizeof (buffer));
373
370
debugPrintLn (buffer);
374
371
@@ -388,6 +385,15 @@ void TheThingsNetwork::reset(bool adr)
388
385
}
389
386
}
390
387
388
+ void TheThingsNetwork::saveState ()
389
+ {
390
+ debugPrint (SENDING);
391
+ sendCommand (MAC_TABLE, MAC_PREFIX, true );
392
+ sendCommand (MAC_TABLE, MAC_SAVE, false );
393
+ modemStream->write (SEND_MSG);
394
+ debugPrintLn ();
395
+ }
396
+
391
397
void TheThingsNetwork::onMessage (void (*cb)(const uint8_t *payload, size_t size, port_t port))
392
398
{
393
399
messageCallback = cb;
@@ -411,8 +417,6 @@ bool TheThingsNetwork::personalize()
411
417
{
412
418
configureChannels (sf, fsb);
413
419
sendJoinSet (MAC_JOIN_MODE_ABP);
414
-
415
- char buffer[100 ];
416
420
readLine (buffer, sizeof (buffer));
417
421
if (pgmstrcmp (buffer, CMP_ACCEPTED) != 0 )
418
422
{
@@ -433,26 +437,17 @@ bool TheThingsNetwork::provision(const char *appEui, const char *appKey)
433
437
debugPrintMessage (ERR_MESSAGE, ERR_KEY_LENGTH);
434
438
return false ;
435
439
}
436
-
437
- char buffer[17 ];
438
440
readResponse (SYS_TABLE, SYS_TABLE, SYS_GET_HWEUI, buffer, sizeof (buffer));
439
441
sendMacSet (MAC_SET_DEVEUI, buffer);
440
-
441
442
sendMacSet (MAC_SET_APPEUI, appEui);
442
443
sendMacSet (MAC_SET_APPKEY, appKey);
443
- debugPrint (SENDING);
444
- sendCommand (MAC_TABLE, MAC_PREFIX, true );
445
- sendCommand (MAC_TABLE, MAC_SAVE, false );
446
- modemStream->write (SEND_MSG);
447
- debugPrintLn ();
444
+ saveState ();
448
445
return true ;
449
446
}
450
447
451
448
bool TheThingsNetwork::join (int8_t retries, uint32_t retryDelay)
452
449
{
453
450
configureChannels (sf, fsb);
454
-
455
- char buffer[100 ];
456
451
while (--retries)
457
452
{
458
453
if (!sendJoinSet (MAC_JOIN_MODE_OTAA))
@@ -540,7 +535,6 @@ int8_t TheThingsNetwork::poll(port_t port, bool confirm)
540
535
541
536
void TheThingsNetwork::showStatus ()
542
537
{
543
- char buffer[100 ];
544
538
readResponse (SYS_TABLE, SYS_TABLE, SYS_GET_HWEUI, buffer, sizeof (buffer));
545
539
debugPrintIndex (SHOW_EUI, buffer);
546
540
readResponse (SYS_TABLE, SYS_TABLE, SYS_GET_VDD, buffer, sizeof (buffer));
@@ -687,9 +681,8 @@ void TheThingsNetwork::configureChannels(uint8_t sf, uint8_t fsb)
687
681
sendMacSet (MAC_SET_RETX, TTN_RETX);
688
682
}
689
683
690
- void TheThingsNetwork::sendCommand (uint8_t table, uint8_t index, bool with_space , bool print)
684
+ void TheThingsNetwork::sendCommand (uint8_t table, uint8_t index, bool appendSpace , bool print)
691
685
{
692
- char buffer[500 ];
693
686
switch (table)
694
687
{
695
688
case MAC_TABLE:
@@ -717,7 +710,7 @@ void TheThingsNetwork::sendCommand(uint8_t table, uint8_t index, bool with_space
717
710
return ;
718
711
}
719
712
modemStream->write (buffer);
720
- if (with_space )
713
+ if (appendSpace )
721
714
{
722
715
modemStream->write (" " );
723
716
}
@@ -743,7 +736,6 @@ bool TheThingsNetwork::sendMacSet(uint8_t index, const char *setting)
743
736
744
737
bool TheThingsNetwork::waitForOk ()
745
738
{
746
- char buffer[100 ];
747
739
readLine (buffer, sizeof (buffer));
748
740
if (pgmstrcmp (buffer, CMP_OK) != 0 )
749
741
{
@@ -857,7 +849,6 @@ void TheThingsNetwork::sleep(unsigned long msec)
857
849
sendCommand (SYS_TABLE, SYS_PREFIX, true );
858
850
sendCommand (SYS_TABLE, SYS_SLEEP, true );
859
851
860
- char buffer[11 ];
861
852
sprintf (buffer, " %ld" , msec);
862
853
modemStream->write (buffer);
863
854
modemStream->write (SEND_MSG);
0 commit comments