Skip to content

Commit fd3d1ee

Browse files
committed
AS920-923 channel plan, affects #191
1 parent 67258be commit fd3d1ee

File tree

2 files changed

+52
-68
lines changed

2 files changed

+52
-68
lines changed

src/TheThingsNetwork.cpp

Lines changed: 46 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -591,77 +591,40 @@ void TheThingsNetwork::showStatus()
591591

592592
void TheThingsNetwork::configureEU868(uint8_t sf)
593593
{
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-
603594
sendMacSet(MAC_RX2, "3 869525000");
604595
sendChSet(MAC_CHANNEL_DRRANGE, 1, "0 6");
596+
597+
char buf[10];
598+
uint32_t freq = 867100000;
599+
uint8_t ch;
605600
for (ch = 0; ch < 8; ch++)
606601
{
607602
sendChSet(MAC_CHANNEL_DCYCLE, ch, "799");
608603
if (ch > 2)
609604
{
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);
618606
sendChSet(MAC_CHANNEL_FREQ, ch, buf);
619607
sendChSet(MAC_CHANNEL_DRRANGE, ch, "0 5");
620608
sendChSet(MAC_CHANNEL_STATUS, ch, "on");
621609
freq = freq + 200000;
622610
}
623611
}
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)
651614
{
615+
char dr[2];
616+
dr[0] = '0' + (12 - sf);
617+
dr[1] = '\0';
652618
sendMacSet(MAC_DR, dr);
653619
}
654620
}
655621

656622
void TheThingsNetwork::configureUS915(uint8_t sf, uint8_t fsb)
657623
{
658624
uint8_t ch;
659-
char dr[2];
660625
uint8_t chLow = fsb > 0 ? (fsb - 1) * 8 : 0;
661626
uint8_t chHigh = fsb > 0 ? chLow + 7 : 71;
662627
uint8_t ch500 = fsb + 63;
663-
664-
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_915);
665628
for (ch = 0; ch < 72; ch++)
666629
{
667630
if (ch == ch500 || (ch <= chHigh && ch >= chLow))
@@ -677,27 +640,42 @@ void TheThingsNetwork::configureUS915(uint8_t sf, uint8_t fsb)
677640
sendChSet(MAC_CHANNEL_STATUS, ch, "off");
678641
}
679642
}
680-
switch (sf)
643+
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_US915);
644+
if (sf >= 7 && sf <= 10)
681645
{
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+
}
697672
}
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)
700675
{
676+
char dr[2];
677+
dr[0] = '0' + (12 - sf);
678+
dr[1] = '\0';
701679
sendMacSet(MAC_DR, dr);
702680
}
703681
}
@@ -712,6 +690,9 @@ void TheThingsNetwork::configureChannels(uint8_t sf, uint8_t fsb)
712690
case TTN_FP_US915:
713691
configureUS915(sf, fsb);
714692
break;
693+
case TTN_FP_AS920_923:
694+
configureAS920_923(sf);
695+
break;
715696
default:
716697
debugPrintMessage(ERR_MESSAGE, ERR_INVALID_FP);
717698
break;

src/TheThingsNetwork.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#define TTN_DEFAULT_FSB 2
1313
#define TTN_RETX "7"
1414

15-
#define TTN_PWRIDX_868 "1"
16-
#define TTN_PWRIDX_915 "5"
15+
#define TTN_PWRIDX_EU868 "1"
16+
#define TTN_PWRIDX_US915 "5"
17+
#define TTN_PWRIDX_AS920_923 "0"
1718

1819
#define TTN_BUFFER_SIZE 300
1920

@@ -30,7 +31,8 @@ enum ttn_response_t
3031
enum ttn_fp_t
3132
{
3233
TTN_FP_EU868,
33-
TTN_FP_US915
34+
TTN_FP_US915,
35+
TTN_FP_AS920_923
3436
};
3537

3638
class TheThingsNetwork
@@ -56,6 +58,7 @@ class TheThingsNetwork
5658
void autoBaud();
5759
void configureEU868(uint8_t sf);
5860
void configureUS915(uint8_t sf, uint8_t fsb);
61+
void configureAS920_923(uint8_t sf);
5962
void configureChannels(uint8_t sf, uint8_t fsb);
6063
bool waitForOk();
6164

0 commit comments

Comments
 (0)