@@ -591,77 +591,40 @@ void TheThingsNetwork::showStatus()
591
591
592
592
void TheThingsNetwork::configureEU868 (uint8_t sf)
593
593
{
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
594
sendMacSet (MAC_RX2, " 3 869525000" );
604
595
sendChSet (MAC_CHANNEL_DRRANGE, 1 , " 0 6" );
596
+
597
+ char buf[10 ];
598
+ uint32_t freq = 867100000 ;
599
+ uint8_t ch;
605
600
for (ch = 0 ; ch < 8 ; ch++)
606
601
{
607
602
sendChSet (MAC_CHANNEL_DCYCLE, ch, " 799" );
608
603
if (ch > 2 )
609
604
{
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
- }
605
+ sprintf (buf, " %d" , freq);
618
606
sendChSet (MAC_CHANNEL_FREQ, ch, buf);
619
607
sendChSet (MAC_CHANNEL_DRRANGE, ch, " 0 5" );
620
608
sendChSet (MAC_CHANNEL_STATUS, ch, " on" );
621
609
freq = freq + 200000 ;
622
610
}
623
611
}
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' )
612
+ sendMacSet (MAC_PWRIDX, TTN_PWRIDX_EU868);
613
+ if (sf >= 7 && sf <= 12 )
651
614
{
615
+ char dr[2 ];
616
+ dr[0 ] = ' 0' + (12 - sf);
617
+ dr[1 ] = ' \0 ' ;
652
618
sendMacSet (MAC_DR, dr);
653
619
}
654
620
}
655
621
656
622
void TheThingsNetwork::configureUS915 (uint8_t sf, uint8_t fsb)
657
623
{
658
624
uint8_t ch;
659
- char dr[2 ];
660
625
uint8_t chLow = fsb > 0 ? (fsb - 1 ) * 8 : 0 ;
661
626
uint8_t chHigh = fsb > 0 ? chLow + 7 : 71 ;
662
627
uint8_t ch500 = fsb + 63 ;
663
-
664
- sendMacSet (MAC_PWRIDX, TTN_PWRIDX_915);
665
628
for (ch = 0 ; ch < 72 ; ch++)
666
629
{
667
630
if (ch == ch500 || (ch <= chHigh && ch >= chLow))
@@ -677,27 +640,42 @@ void TheThingsNetwork::configureUS915(uint8_t sf, uint8_t fsb)
677
640
sendChSet (MAC_CHANNEL_STATUS, ch, " off" );
678
641
}
679
642
}
680
- switch (sf)
643
+ sendMacSet (MAC_PWRIDX, TTN_PWRIDX_US915);
644
+ if (sf >= 7 && sf <= 10 )
681
645
{
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 ;
646
+ char dr[2 ];
647
+ dr[0 ] = ' 0' + (10 - sf);
648
+ dr[1 ] = ' \0 ' ;
649
+ sendMacSet (MAC_DR, dr);
650
+ }
651
+ }
652
+
653
+ void TheThingsNetwork::configureAS920_923 (uint8_t sf)
654
+ {
655
+ sendMacSet (MAC_RX2, " 2 923200000" );
656
+ sendChSet (MAC_CHANNEL_DRRANGE, 1 , " 0 6" );
657
+
658
+ char buf[10 ];
659
+ uint32_t freq = 922000000 ;
660
+ uint8_t ch;
661
+ for (ch = 0 ; ch < 8 ; ch++)
662
+ {
663
+ sendChSet (MAC_CHANNEL_DCYCLE, ch, " 799" );
664
+ if (ch > 1 )
665
+ {
666
+ sprintf (buf, " %d" , freq);
667
+ sendChSet (MAC_CHANNEL_FREQ, ch, buf);
668
+ sendChSet (MAC_CHANNEL_DRRANGE, ch, " 0 5" );
669
+ sendChSet (MAC_CHANNEL_STATUS, ch, " on" );
670
+ freq = freq + 200000 ;
671
+ }
697
672
}
698
- dr[ 1 ] = ' \0 ' ;
699
- if (dr[ 0 ] >= ' 0 ' && dr[ 0 ] < ' 4 ' )
673
+ sendMacSet (MAC_PWRIDX, TTN_PWRIDX_AS920_923) ;
674
+ if (sf >= 7 && sf <= 12 )
700
675
{
676
+ char dr[2 ];
677
+ dr[0 ] = ' 0' + (12 - sf);
678
+ dr[1 ] = ' \0 ' ;
701
679
sendMacSet (MAC_DR, dr);
702
680
}
703
681
}
@@ -712,6 +690,9 @@ void TheThingsNetwork::configureChannels(uint8_t sf, uint8_t fsb)
712
690
case TTN_FP_US915:
713
691
configureUS915 (sf, fsb);
714
692
break ;
693
+ case TTN_FP_AS920_923:
694
+ configureAS920_923 (sf);
695
+ break ;
715
696
default :
716
697
debugPrintMessage (ERR_MESSAGE, ERR_INVALID_FP);
717
698
break ;
0 commit comments