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