Skip to content

Commit 53c9dad

Browse files
Merge pull request #192 from TheThingsNetwork/feature/as920_923
AS920-923 channel plan
2 parents 67258be + d08c506 commit 53c9dad

File tree

2 files changed

+72
-73
lines changed

2 files changed

+72
-73
lines changed

src/TheThingsNetwork.cpp

100644100755
Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,11 @@ void TheThingsNetwork::reset(bool adr)
408408

409409
size_t length = readResponse(SYS_TABLE, SYS_RESET, buffer, sizeof(buffer));
410410

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);
415416

416417
readResponse(SYS_TABLE, SYS_TABLE, SYS_GET_HWEUI, buffer, sizeof(buffer));
417418
sendMacSet(MAC_DEVEUI, buffer);
@@ -482,7 +483,15 @@ bool TheThingsNetwork::provision(const char *appEui, const char *appKey)
482483
sendMacSet(MAC_DEVEUI, buffer);
483484
sendMacSet(MAC_APPEUI, appEui);
484485
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+
}
486495
return true;
487496
}
488497

@@ -591,77 +600,40 @@ void TheThingsNetwork::showStatus()
591600

592601
void TheThingsNetwork::configureEU868(uint8_t sf)
593602
{
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-
603603
sendMacSet(MAC_RX2, "3 869525000");
604604
sendChSet(MAC_CHANNEL_DRRANGE, 1, "0 6");
605+
606+
char buf[10];
607+
uint32_t freq = 867100000;
608+
uint8_t ch;
605609
for (ch = 0; ch < 8; ch++)
606610
{
607611
sendChSet(MAC_CHANNEL_DCYCLE, ch, "799");
608612
if (ch > 2)
609613
{
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);
618615
sendChSet(MAC_CHANNEL_FREQ, ch, buf);
619616
sendChSet(MAC_CHANNEL_DRRANGE, ch, "0 5");
620617
sendChSet(MAC_CHANNEL_STATUS, ch, "on");
621618
freq = freq + 200000;
622619
}
623620
}
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)
651623
{
624+
char dr[2];
625+
dr[0] = '0' + (12 - sf);
626+
dr[1] = '\0';
652627
sendMacSet(MAC_DR, dr);
653628
}
654629
}
655630

656631
void TheThingsNetwork::configureUS915(uint8_t sf, uint8_t fsb)
657632
{
658633
uint8_t ch;
659-
char dr[2];
660634
uint8_t chLow = fsb > 0 ? (fsb - 1) * 8 : 0;
661635
uint8_t chHigh = fsb > 0 ? chLow + 7 : 71;
662636
uint8_t ch500 = fsb + 63;
663-
664-
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_915);
665637
for (ch = 0; ch < 72; ch++)
666638
{
667639
if (ch == ch500 || (ch <= chHigh && ch >= chLow))
@@ -677,27 +649,48 @@ void TheThingsNetwork::configureUS915(uint8_t sf, uint8_t fsb)
677649
sendChSet(MAC_CHANNEL_STATUS, ch, "off");
678650
}
679651
}
680-
switch (sf)
652+
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_US915);
653+
if (sf >= 7 && sf <= 10)
681654
{
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);
697659
}
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++)
700671
{
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';
701694
sendMacSet(MAC_DR, dr);
702695
}
703696
}
@@ -712,6 +705,9 @@ void TheThingsNetwork::configureChannels(uint8_t sf, uint8_t fsb)
712705
case TTN_FP_US915:
713706
configureUS915(sf, fsb);
714707
break;
708+
case TTN_FP_AS920_923:
709+
configureAS920_923(sf);
710+
break;
715711
default:
716712
debugPrintMessage(ERR_MESSAGE, ERR_INVALID_FP);
717713
break;

src/TheThingsNetwork.h

100644100755
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 "1" // TODO: should be 0, but the current RN2903AS firmware doesn't accept that value (probably still using EU868: 1=14dBm)
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)