@@ -408,10 +408,11 @@ void TheThingsNetwork::reset(bool adr)
408
408
409
409
size_t length = readResponse (SYS_TABLE, SYS_RESET, buffer, sizeof (buffer));
410
410
411
- // buffer contains "RN2xx3 1.x.x ...", splitting model from version
412
- buffer[6 ] = ' \0 ' ;
413
- debugPrintIndex (SHOW_MODEL, buffer);
414
- debugPrintIndex (SHOW_VERSION, buffer + 7 );
411
+ // buffer contains "RN2xx3[xx] x.x.x ...", splitting model from version
412
+ char *model = strtok (buffer, " " );
413
+ debugPrintIndex (SHOW_MODEL, model);
414
+ char *version = strtok (NULL , " " );
415
+ debugPrintIndex (SHOW_VERSION, version);
415
416
416
417
readResponse (SYS_TABLE, SYS_TABLE, SYS_GET_HWEUI, buffer, sizeof (buffer));
417
418
sendMacSet (MAC_DEVEUI, buffer);
@@ -482,7 +483,15 @@ bool TheThingsNetwork::provision(const char *appEui, const char *appKey)
482
483
sendMacSet (MAC_DEVEUI, buffer);
483
484
sendMacSet (MAC_APPEUI, appEui);
484
485
sendMacSet (MAC_APPKEY, appKey);
485
- saveState ();
486
+ switch (fp)
487
+ {
488
+ case TTN_FP_AS920_923:
489
+ // TODO: temporarily removed 'mac save' because RN2903AS crashes on this command!
490
+ break ;
491
+ default :
492
+ saveState ();
493
+ break ;
494
+ }
486
495
return true ;
487
496
}
488
497
@@ -591,77 +600,40 @@ void TheThingsNetwork::showStatus()
591
600
592
601
void TheThingsNetwork::configureEU868 (uint8_t sf)
593
602
{
594
- uint8_t ch;
595
- char dr[2 ];
596
- uint32_t freq = 867100000 ;
597
-
598
- uint32_t tmp;
599
- size_t length = 8 ;
600
- char buf[length + 1 ];
601
- buf[length + 1 ] = ' \0 ' ;
602
-
603
603
sendMacSet (MAC_RX2, " 3 869525000" );
604
604
sendChSet (MAC_CHANNEL_DRRANGE, 1 , " 0 6" );
605
+
606
+ char buf[10 ];
607
+ uint32_t freq = 867100000 ;
608
+ uint8_t ch;
605
609
for (ch = 0 ; ch < 8 ; ch++)
606
610
{
607
611
sendChSet (MAC_CHANNEL_DCYCLE, ch, " 799" );
608
612
if (ch > 2 )
609
613
{
610
- size_t length = 8 ;
611
- tmp = freq;
612
- while (tmp > 0 )
613
- {
614
- buf[length] = (tmp % 10 ) + 48 ;
615
- tmp = tmp / 10 ;
616
- length -= 1 ;
617
- }
614
+ sprintf (buf, " %lu" , freq);
618
615
sendChSet (MAC_CHANNEL_FREQ, ch, buf);
619
616
sendChSet (MAC_CHANNEL_DRRANGE, ch, " 0 5" );
620
617
sendChSet (MAC_CHANNEL_STATUS, ch, " on" );
621
618
freq = freq + 200000 ;
622
619
}
623
620
}
624
- sendMacSet (MAC_PWRIDX, TTN_PWRIDX_868);
625
- switch (sf)
626
- {
627
- case 7 :
628
- dr[0 ] = ' 5' ;
629
- break ;
630
- case 8 :
631
- dr[0 ] = ' 4' ;
632
- break ;
633
- case 9 :
634
- dr[0 ] = ' 3' ;
635
- break ;
636
- case 10 :
637
- dr[0 ] = ' 2' ;
638
- break ;
639
- case 11 :
640
- dr[0 ] = ' 1' ;
641
- break ;
642
- case 12 :
643
- dr[0 ] = ' 0' ;
644
- break ;
645
- default :
646
- debugPrintMessage (ERR_MESSAGE, ERR_INVALID_SF);
647
- break ;
648
- }
649
- dr[1 ] = ' \0 ' ;
650
- if (dr[0 ] >= ' 0' && dr[0 ] <= ' 5' )
621
+ sendMacSet (MAC_PWRIDX, TTN_PWRIDX_EU868);
622
+ if (sf >= 7 && sf <= 12 )
651
623
{
624
+ char dr[2 ];
625
+ dr[0 ] = ' 0' + (12 - sf);
626
+ dr[1 ] = ' \0 ' ;
652
627
sendMacSet (MAC_DR, dr);
653
628
}
654
629
}
655
630
656
631
void TheThingsNetwork::configureUS915 (uint8_t sf, uint8_t fsb)
657
632
{
658
633
uint8_t ch;
659
- char dr[2 ];
660
634
uint8_t chLow = fsb > 0 ? (fsb - 1 ) * 8 : 0 ;
661
635
uint8_t chHigh = fsb > 0 ? chLow + 7 : 71 ;
662
636
uint8_t ch500 = fsb + 63 ;
663
-
664
- sendMacSet (MAC_PWRIDX, TTN_PWRIDX_915);
665
637
for (ch = 0 ; ch < 72 ; ch++)
666
638
{
667
639
if (ch == ch500 || (ch <= chHigh && ch >= chLow))
@@ -677,27 +649,48 @@ void TheThingsNetwork::configureUS915(uint8_t sf, uint8_t fsb)
677
649
sendChSet (MAC_CHANNEL_STATUS, ch, " off" );
678
650
}
679
651
}
680
- switch (sf)
652
+ sendMacSet (MAC_PWRIDX, TTN_PWRIDX_US915);
653
+ if (sf >= 7 && sf <= 10 )
681
654
{
682
- case 7 :
683
- dr[0 ] = ' 3' ;
684
- break ;
685
- case 8 :
686
- dr[0 ] = ' 2' ;
687
- break ;
688
- case 9 :
689
- dr[0 ] = ' 1' ;
690
- break ;
691
- case 10 :
692
- dr[0 ] = ' 0' ;
693
- break ;
694
- default :
695
- debugPrintMessage (ERR_MESSAGE, ERR_INVALID_SF);
696
- break ;
655
+ char dr[2 ];
656
+ dr[0 ] = ' 0' + (10 - sf);
657
+ dr[1 ] = ' \0 ' ;
658
+ sendMacSet (MAC_DR, dr);
697
659
}
698
- dr[1 ] = ' \0 ' ;
699
- if (dr[0 ] >= ' 0' && dr[0 ] < ' 4' )
660
+ }
661
+
662
+ void TheThingsNetwork::configureAS920_923 (uint8_t sf)
663
+ {
664
+ sendMacSet (MAC_ADR, " off" ); // TODO: remove when ADR is implemented for this plan
665
+ sendMacSet (MAC_RX2, " 2 923200000" );
666
+
667
+ char buf[10 ];
668
+ uint32_t freq = 922000000 ;
669
+ uint8_t ch;
670
+ for (ch = 0 ; ch < 8 ; ch++)
700
671
{
672
+ sendChSet (MAC_CHANNEL_DCYCLE, ch, " 799" );
673
+ if (ch > 1 )
674
+ {
675
+ sprintf (buf, " %lu" , freq);
676
+ sendChSet (MAC_CHANNEL_FREQ, ch, buf);
677
+ sendChSet (MAC_CHANNEL_DRRANGE, ch, " 0 5" );
678
+ sendChSet (MAC_CHANNEL_STATUS, ch, " on" );
679
+ freq = freq + 200000 ;
680
+ }
681
+ }
682
+ // TODO: SF7BW250/DR6 channel, not properly supported by RN2903AS yet
683
+ // sendChSet(MAC_CHANNEL_DCYCLE, 8, "799");
684
+ // sendChSet(MAC_CHANNEL_FREQ, 8, "922100000");
685
+ // sendChSet(MAC_CHANNEL_DRRANGE, 8, "6 6");
686
+ // sendChSet(MAC_CHANNEL_STATUS, 8, "on");
687
+ // TODO: Add FSK channel
688
+ sendMacSet (MAC_PWRIDX, TTN_PWRIDX_AS920_923);
689
+ if (sf >= 7 && sf <= 12 )
690
+ {
691
+ char dr[2 ];
692
+ dr[0 ] = ' 0' + (12 - sf);
693
+ dr[1 ] = ' \0 ' ;
701
694
sendMacSet (MAC_DR, dr);
702
695
}
703
696
}
@@ -712,6 +705,9 @@ void TheThingsNetwork::configureChannels(uint8_t sf, uint8_t fsb)
712
705
case TTN_FP_US915:
713
706
configureUS915 (sf, fsb);
714
707
break ;
708
+ case TTN_FP_AS920_923:
709
+ configureAS920_923 (sf);
710
+ break ;
715
711
default :
716
712
debugPrintMessage (ERR_MESSAGE, ERR_INVALID_FP);
717
713
break ;
0 commit comments