Skip to content

Commit

Permalink
Merge pull request #226 from alexbn71/patch-4
Browse files Browse the repository at this point in the history
Link check command feature
  • Loading branch information
johanstokking authored Jul 26, 2017
2 parents 4f20df9 + e035522 commit 24fe75f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
34 changes: 34 additions & 0 deletions docs/TheThingsNetwork.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,37 @@ void sleep(unsigned long mseconds);
```
- `unsigned long mseconds`: number of milliseconds to sleep.
## Method: `wake`
Wake up the LoRa module from sleep before the expiration of the defined time.
```c
void wake();
```

## Method: `linkCheck`

Sets the time interval for the link check process to be triggered.

```c
void linkCheck(uint16_t seconds);
```
- `uint16_t seconds`: the time interval in seconds. A value of 0 will disable the link check process.
## Method: `getLinkCheckGateways`
Gets the number of gateways that successfully received the last Link Check Request frame.
```c
uint8_t getLinkCheckGateways();
```

## Method: `getLinkCheckMargin`

Gets the demodulation margin as received in the last Link Check Answer frame.

```c
uint8_t getLinkCheckMargin();
```
33 changes: 32 additions & 1 deletion src/TheThingsNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ const char mac_band[] PROGMEM = "band";
const char mac_ar[] PROGMEM = "ar";
const char mac_rx2[] PROGMEM = "rx2";
const char mac_ch[] PROGMEM = "ch";
const char mac_gwnb[] PROGMEM = "gwnb";
const char mac_mrgn[] PROGMEM = "mrgn";

const char *const mac_options[] PROGMEM = {mac_devaddr, mac_deveui, mac_appeui, mac_nwkskey, mac_appskey, mac_appkey, mac_pwridx, mac_dr, mac_adr, mac_bat, mac_retx, mac_linkchk, mac_rxdelay1, mac_rxdelay2, mac_band, mac_ar, mac_rx2, mac_ch};
const char *const mac_options[] PROGMEM = {mac_devaddr, mac_deveui, mac_appeui, mac_nwkskey, mac_appskey, mac_appkey, mac_pwridx, mac_dr, mac_adr, mac_bat, mac_retx, mac_linkchk, mac_rxdelay1, mac_rxdelay2, mac_band, mac_ar, mac_rx2, mac_ch, mac_gwnb, mac_mrgn};

#define MAC_DEVADDR 0
#define MAC_DEVEUI 1
Expand All @@ -211,6 +213,8 @@ const char *const mac_options[] PROGMEM = {mac_devaddr, mac_deveui, mac_appeui,
#define MAC_AR 15
#define MAC_RX2 16
#define MAC_CH 17
#define MAC_GWNB 18
#define MAC_MRGN 19

const char mac_join_mode_otaa[] PROGMEM = "otaa";
const char mac_join_mode_abp[] PROGMEM = "abp";
Expand Down Expand Up @@ -963,3 +967,30 @@ void TheThingsNetwork::wake()
{
autoBaud();
}

void TheThingsNetwork::linkCheck(uint16_t seconds)
{
clearReadBuffer();
debugPrint(SENDING);
sendCommand(MAC_TABLE, MAC_PREFIX, true);
sendCommand(MAC_TABLE, MAC_SET, true);
sendCommand(MAC_GET_SET_TABLE, MAC_LINKCHK, true);

sprintf(buffer, "%u", seconds);
modemStream->write(buffer);
modemStream->write(SEND_MSG);
debugPrintLn(buffer);
waitForOk();
}

uint8_t TheThingsNetwork::getLinkCheckGateways()
{
readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_GWNB, buffer, sizeof(buffer));
return strtol(buffer, NULL, 10);
}

uint8_t TheThingsNetwork::getLinkCheckMargin()
{
readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_MRGN, buffer, sizeof(buffer));
return strtol(buffer, NULL, 10);
}
3 changes: 3 additions & 0 deletions src/TheThingsNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class TheThingsNetwork
void sleep(uint32_t mseconds);
void wake();
void saveState();
void linkCheck(uint16_t seconds);
uint8_t getLinkCheckGateways();
uint8_t getLinkCheckMargin();
};

#endif

0 comments on commit 24fe75f

Please sign in to comment.