Basic xdot code to check how many memory is available for user APP after initializing libxdot lorawan stack
examples/inc/RadioEvent.h@42:20f6b29a9903, 2021-05-25 (annotated)
- Committer:
- Taylor Heck
- Date:
- Tue May 25 09:54:33 2021 -0500
- Revision:
- 42:20f6b29a9903
- Parent:
- 41:67feacfab49c
Target mbed-os 6 and Dot Library version 4.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
14:19fae4509473 | 1 | #ifndef __RADIO_EVENT_H__ |
Mike Fiore |
14:19fae4509473 | 2 | #define __RADIO_EVENT_H__ |
Mike Fiore |
14:19fae4509473 | 3 | |
Mike Fiore |
14:19fae4509473 | 4 | #include "dot_util.h" |
Mike Fiore |
14:19fae4509473 | 5 | #include "mDotEvent.h" |
Jason Reiss |
34:f6486829a451 | 6 | #include "Fota.h" |
Taylor Heck |
42:20f6b29a9903 | 7 | #include "example_config.h" |
Mike Fiore |
14:19fae4509473 | 8 | |
Mike Fiore |
14:19fae4509473 | 9 | class RadioEvent : public mDotEvent |
Mike Fiore |
14:19fae4509473 | 10 | { |
Jason Reiss |
34:f6486829a451 | 11 | |
Mike Fiore |
14:19fae4509473 | 12 | public: |
Mike Fiore |
14:19fae4509473 | 13 | RadioEvent() {} |
Jason Reiss |
34:f6486829a451 | 14 | |
Mike Fiore |
14:19fae4509473 | 15 | virtual ~RadioEvent() {} |
Jason Reiss |
34:f6486829a451 | 16 | |
Taylor Heck |
42:20f6b29a9903 | 17 | virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries, uint32_t address, uint32_t fcnt, bool dupRx) { |
Taylor Heck |
42:20f6b29a9903 | 18 | mDotEvent::PacketRx(port, payload, size, rssi, snr, ctrl, slot, retries, address, fcnt, dupRx); |
Jason Reiss |
34:f6486829a451 | 19 | |
Jason Reiss |
34:f6486829a451 | 20 | #if ACTIVE_EXAMPLE == FOTA_EXAMPLE |
Jason Reiss |
34:f6486829a451 | 21 | if(port == 200 || port == 201 || port == 202) { |
Jason Reiss |
34:f6486829a451 | 22 | Fota::getInstance()->processCmd(payload, port, size); |
Jason Reiss |
34:f6486829a451 | 23 | } |
Jason Reiss |
34:f6486829a451 | 24 | #endif |
Jason Reiss |
34:f6486829a451 | 25 | } |
Jason Reiss |
34:f6486829a451 | 26 | |
Mike Fiore |
14:19fae4509473 | 27 | /*! |
Mike Fiore |
14:19fae4509473 | 28 | * MAC layer event callback prototype. |
Mike Fiore |
14:19fae4509473 | 29 | * |
Mike Fiore |
14:19fae4509473 | 30 | * \param [IN] flags Bit field indicating the MAC events occurred |
Mike Fiore |
14:19fae4509473 | 31 | * \param [IN] info Details about MAC events occurred |
Mike Fiore |
14:19fae4509473 | 32 | */ |
Mike Fiore |
14:19fae4509473 | 33 | virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { |
Jason Reiss |
34:f6486829a451 | 34 | |
Mike Fiore |
14:19fae4509473 | 35 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
Mike Fiore |
14:19fae4509473 | 36 | std::string msg = "OK"; |
Mike Fiore |
14:19fae4509473 | 37 | switch (info->Status) { |
Mike Fiore |
14:19fae4509473 | 38 | case LORAMAC_EVENT_INFO_STATUS_ERROR: |
Mike Fiore |
14:19fae4509473 | 39 | msg = "ERROR"; |
Mike Fiore |
14:19fae4509473 | 40 | break; |
Mike Fiore |
14:19fae4509473 | 41 | case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: |
Mike Fiore |
14:19fae4509473 | 42 | msg = "TX_TIMEOUT"; |
Mike Fiore |
14:19fae4509473 | 43 | break; |
Mike Fiore |
14:19fae4509473 | 44 | case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: |
Mike Fiore |
14:19fae4509473 | 45 | msg = "RX_TIMEOUT"; |
Mike Fiore |
14:19fae4509473 | 46 | break; |
Mike Fiore |
14:19fae4509473 | 47 | case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: |
Mike Fiore |
14:19fae4509473 | 48 | msg = "RX_ERROR"; |
Mike Fiore |
14:19fae4509473 | 49 | break; |
Mike Fiore |
14:19fae4509473 | 50 | case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: |
Mike Fiore |
14:19fae4509473 | 51 | msg = "JOIN_FAIL"; |
Mike Fiore |
14:19fae4509473 | 52 | break; |
Mike Fiore |
14:19fae4509473 | 53 | case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: |
Mike Fiore |
14:19fae4509473 | 54 | msg = "DOWNLINK_FAIL"; |
Mike Fiore |
14:19fae4509473 | 55 | break; |
Mike Fiore |
14:19fae4509473 | 56 | case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: |
Mike Fiore |
14:19fae4509473 | 57 | msg = "ADDRESS_FAIL"; |
Mike Fiore |
14:19fae4509473 | 58 | break; |
Mike Fiore |
14:19fae4509473 | 59 | case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: |
Mike Fiore |
14:19fae4509473 | 60 | msg = "MIC_FAIL"; |
Mike Fiore |
14:19fae4509473 | 61 | break; |
Mike Fiore |
14:19fae4509473 | 62 | default: |
Mike Fiore |
14:19fae4509473 | 63 | break; |
Mike Fiore |
14:19fae4509473 | 64 | } |
Mike Fiore |
14:19fae4509473 | 65 | logTrace("Event: %s", msg.c_str()); |
Jason Reiss |
34:f6486829a451 | 66 | |
Mike Fiore |
14:19fae4509473 | 67 | logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", |
Mike Fiore |
14:19fae4509473 | 68 | flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); |
Mike Fiore |
14:19fae4509473 | 69 | logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d", |
Mike Fiore |
14:19fae4509473 | 70 | info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, |
Mike Fiore |
14:19fae4509473 | 71 | info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); |
Mike Fiore |
14:19fae4509473 | 72 | } |
Jason Reiss |
34:f6486829a451 | 73 | |
Mike Fiore |
14:19fae4509473 | 74 | if (flags->Bits.Rx) { |
Jason Reiss |
34:f6486829a451 | 75 | |
Taylor Heck |
42:20f6b29a9903 | 76 | logInfo("Rx %d bytes", info->RxBufferSize); |
Taylor Heck |
42:20f6b29a9903 | 77 | |
Mike Fiore |
14:19fae4509473 | 78 | if (info->RxBufferSize > 0) { |
jreiss | 38:2c027824e046 | 79 | #if ACTIVE_EXAMPLE != FOTA_EXAMPLE |
Jason Reiss |
34:f6486829a451 | 80 | // print RX data as string and hexadecimal |
Mike Fiore |
14:19fae4509473 | 81 | std::string rx((const char*)info->RxBuffer, info->RxBufferSize); |
Mike Fiore |
21:09d05faf0e13 | 82 | printf("Rx data: %s [%s]\r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); |
Jason Reiss |
36:f1053cb17d4f | 83 | #endif |
Mike Fiore |
14:19fae4509473 | 84 | } |
Mike Fiore |
14:19fae4509473 | 85 | } |
Mike Fiore |
14:19fae4509473 | 86 | } |
Jason Reiss |
41:67feacfab49c | 87 | |
Taylor Heck |
42:20f6b29a9903 | 88 | |
Jason Reiss |
41:67feacfab49c | 89 | #if ACTIVE_EXAMPLE == FOTA_EXAMPLE |
Jason Reiss |
41:67feacfab49c | 90 | virtual void ServerTime(uint32_t seconds, uint8_t sub_seconds) { |
Jason Reiss |
41:67feacfab49c | 91 | mDotEvent::ServerTime(seconds, sub_seconds); |
Jason Reiss |
41:67feacfab49c | 92 | |
Jason Reiss |
41:67feacfab49c | 93 | Fota::getInstance()->setClockOffset(seconds); |
Jason Reiss |
41:67feacfab49c | 94 | } |
Jason Reiss |
41:67feacfab49c | 95 | #endif |
Mike Fiore |
14:19fae4509473 | 96 | }; |
Mike Fiore |
14:19fae4509473 | 97 | |
Mike Fiore |
14:19fae4509473 | 98 | #endif |
Mike Fiore |
14:19fae4509473 | 99 |