Skip to content

Commit

Permalink
AS920-923 channel plan, affects #191
Browse files Browse the repository at this point in the history
  • Loading branch information
johanstokking committed Mar 18, 2017
1 parent 67258be commit fd3d1ee
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 68 deletions.
111 changes: 46 additions & 65 deletions src/TheThingsNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,77 +591,40 @@ void TheThingsNetwork::showStatus()

void TheThingsNetwork::configureEU868(uint8_t sf)
{
uint8_t ch;
char dr[2];
uint32_t freq = 867100000;

uint32_t tmp;
size_t length = 8;
char buf[length + 1];
buf[length + 1] = '\0';

sendMacSet(MAC_RX2, "3 869525000");
sendChSet(MAC_CHANNEL_DRRANGE, 1, "0 6");

char buf[10];
uint32_t freq = 867100000;
uint8_t ch;
for (ch = 0; ch < 8; ch++)
{
sendChSet(MAC_CHANNEL_DCYCLE, ch, "799");
if (ch > 2)
{
size_t length = 8;
tmp = freq;
while (tmp > 0)
{
buf[length] = (tmp % 10) + 48;
tmp = tmp / 10;
length -= 1;
}
sprintf(buf, "%d", freq);
sendChSet(MAC_CHANNEL_FREQ, ch, buf);
sendChSet(MAC_CHANNEL_DRRANGE, ch, "0 5");
sendChSet(MAC_CHANNEL_STATUS, ch, "on");
freq = freq + 200000;
}
}
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_868);
switch (sf)
{
case 7:
dr[0] = '5';
break;
case 8:
dr[0] = '4';
break;
case 9:
dr[0] = '3';
break;
case 10:
dr[0] = '2';
break;
case 11:
dr[0] = '1';
break;
case 12:
dr[0] = '0';
break;
default:
debugPrintMessage(ERR_MESSAGE, ERR_INVALID_SF);
break;
}
dr[1] = '\0';
if (dr[0] >= '0' && dr[0] <= '5')
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_EU868);
if (sf >= 7 && sf <= 12)
{
char dr[2];
dr[0] = '0' + (12 - sf);
dr[1] = '\0';
sendMacSet(MAC_DR, dr);
}
}

void TheThingsNetwork::configureUS915(uint8_t sf, uint8_t fsb)
{
uint8_t ch;
char dr[2];
uint8_t chLow = fsb > 0 ? (fsb - 1) * 8 : 0;
uint8_t chHigh = fsb > 0 ? chLow + 7 : 71;
uint8_t ch500 = fsb + 63;

sendMacSet(MAC_PWRIDX, TTN_PWRIDX_915);
for (ch = 0; ch < 72; ch++)
{
if (ch == ch500 || (ch <= chHigh && ch >= chLow))
Expand All @@ -677,27 +640,42 @@ void TheThingsNetwork::configureUS915(uint8_t sf, uint8_t fsb)
sendChSet(MAC_CHANNEL_STATUS, ch, "off");
}
}
switch (sf)
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_US915);
if (sf >= 7 && sf <= 10)
{
case 7:
dr[0] = '3';
break;
case 8:
dr[0] = '2';
break;
case 9:
dr[0] = '1';
break;
case 10:
dr[0] = '0';
break;
default:
debugPrintMessage(ERR_MESSAGE, ERR_INVALID_SF);
break;
char dr[2];
dr[0] = '0' + (10 - sf);
dr[1] = '\0';
sendMacSet(MAC_DR, dr);
}
}

void TheThingsNetwork::configureAS920_923(uint8_t sf)
{
sendMacSet(MAC_RX2, "2 923200000");
sendChSet(MAC_CHANNEL_DRRANGE, 1, "0 6");

char buf[10];
uint32_t freq = 922000000;
uint8_t ch;
for (ch = 0; ch < 8; ch++)
{
sendChSet(MAC_CHANNEL_DCYCLE, ch, "799");
if (ch > 1)
{
sprintf(buf, "%d", freq);
sendChSet(MAC_CHANNEL_FREQ, ch, buf);
sendChSet(MAC_CHANNEL_DRRANGE, ch, "0 5");
sendChSet(MAC_CHANNEL_STATUS, ch, "on");
freq = freq + 200000;
}
}
dr[1] = '\0';
if (dr[0] >= '0' && dr[0] < '4')
sendMacSet(MAC_PWRIDX, TTN_PWRIDX_AS920_923);
if (sf >= 7 && sf <= 12)
{
char dr[2];
dr[0] = '0' + (12 - sf);
dr[1] = '\0';
sendMacSet(MAC_DR, dr);
}
}
Expand All @@ -712,6 +690,9 @@ void TheThingsNetwork::configureChannels(uint8_t sf, uint8_t fsb)
case TTN_FP_US915:
configureUS915(sf, fsb);
break;
case TTN_FP_AS920_923:
configureAS920_923(sf);
break;
default:
debugPrintMessage(ERR_MESSAGE, ERR_INVALID_FP);
break;
Expand Down
9 changes: 6 additions & 3 deletions src/TheThingsNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#define TTN_DEFAULT_FSB 2
#define TTN_RETX "7"

#define TTN_PWRIDX_868 "1"
#define TTN_PWRIDX_915 "5"
#define TTN_PWRIDX_EU868 "1"
#define TTN_PWRIDX_US915 "5"
#define TTN_PWRIDX_AS920_923 "0"

#define TTN_BUFFER_SIZE 300

Expand All @@ -30,7 +31,8 @@ enum ttn_response_t
enum ttn_fp_t
{
TTN_FP_EU868,
TTN_FP_US915
TTN_FP_US915,
TTN_FP_AS920_923
};

class TheThingsNetwork
Expand All @@ -56,6 +58,7 @@ class TheThingsNetwork
void autoBaud();
void configureEU868(uint8_t sf);
void configureUS915(uint8_t sf, uint8_t fsb);
void configureAS920_923(uint8_t sf);
void configureChannels(uint8_t sf, uint8_t fsb);
bool waitForOk();

Expand Down

0 comments on commit fd3d1ee

Please sign in to comment.