Peer to peer xDot
Dependencies: ISL29011 libxDot-dev-mbed5-deprecated
src/RadioEvent.h@0:33f2abdc6bf9, 2018-03-05 (annotated)
- Committer:
- javierp
- Date:
- Mon Mar 05 23:51:58 2018 +0000
- Revision:
- 0:33f2abdc6bf9
Conexi?n peer to peer para que con una misma clave se entiendan dos xDot.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
javierp | 0:33f2abdc6bf9 | 1 | #ifndef __RADIO_EVENT_H__ |
javierp | 0:33f2abdc6bf9 | 2 | #define __RADIO_EVENT_H__ |
javierp | 0:33f2abdc6bf9 | 3 | |
javierp | 0:33f2abdc6bf9 | 4 | #include "dot_util.h" |
javierp | 0:33f2abdc6bf9 | 5 | #include "mDotEvent.h" |
javierp | 0:33f2abdc6bf9 | 6 | |
javierp | 0:33f2abdc6bf9 | 7 | class RadioEvent : public mDotEvent |
javierp | 0:33f2abdc6bf9 | 8 | { |
javierp | 0:33f2abdc6bf9 | 9 | |
javierp | 0:33f2abdc6bf9 | 10 | public: |
javierp | 0:33f2abdc6bf9 | 11 | RadioEvent() {} |
javierp | 0:33f2abdc6bf9 | 12 | |
javierp | 0:33f2abdc6bf9 | 13 | virtual ~RadioEvent() {} |
javierp | 0:33f2abdc6bf9 | 14 | |
javierp | 0:33f2abdc6bf9 | 15 | /*! |
javierp | 0:33f2abdc6bf9 | 16 | * MAC layer event callback prototype. |
javierp | 0:33f2abdc6bf9 | 17 | * |
javierp | 0:33f2abdc6bf9 | 18 | * \param [IN] flags Bit field indicating the MAC events occurred |
javierp | 0:33f2abdc6bf9 | 19 | * \param [IN] info Details about MAC events occurred |
javierp | 0:33f2abdc6bf9 | 20 | */ |
javierp | 0:33f2abdc6bf9 | 21 | virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { |
javierp | 0:33f2abdc6bf9 | 22 | |
javierp | 0:33f2abdc6bf9 | 23 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
javierp | 0:33f2abdc6bf9 | 24 | std::string msg = "OK"; |
javierp | 0:33f2abdc6bf9 | 25 | switch (info->Status) { |
javierp | 0:33f2abdc6bf9 | 26 | case LORAMAC_EVENT_INFO_STATUS_ERROR: |
javierp | 0:33f2abdc6bf9 | 27 | msg = "ERROR"; |
javierp | 0:33f2abdc6bf9 | 28 | break; |
javierp | 0:33f2abdc6bf9 | 29 | case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: |
javierp | 0:33f2abdc6bf9 | 30 | msg = "TX_TIMEOUT"; |
javierp | 0:33f2abdc6bf9 | 31 | break; |
javierp | 0:33f2abdc6bf9 | 32 | case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: |
javierp | 0:33f2abdc6bf9 | 33 | msg = "RX_TIMEOUT"; |
javierp | 0:33f2abdc6bf9 | 34 | break; |
javierp | 0:33f2abdc6bf9 | 35 | case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: |
javierp | 0:33f2abdc6bf9 | 36 | msg = "RX_ERROR"; |
javierp | 0:33f2abdc6bf9 | 37 | break; |
javierp | 0:33f2abdc6bf9 | 38 | case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: |
javierp | 0:33f2abdc6bf9 | 39 | msg = "JOIN_FAIL"; |
javierp | 0:33f2abdc6bf9 | 40 | break; |
javierp | 0:33f2abdc6bf9 | 41 | case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: |
javierp | 0:33f2abdc6bf9 | 42 | msg = "DOWNLINK_FAIL"; |
javierp | 0:33f2abdc6bf9 | 43 | break; |
javierp | 0:33f2abdc6bf9 | 44 | case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: |
javierp | 0:33f2abdc6bf9 | 45 | msg = "ADDRESS_FAIL"; |
javierp | 0:33f2abdc6bf9 | 46 | break; |
javierp | 0:33f2abdc6bf9 | 47 | case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: |
javierp | 0:33f2abdc6bf9 | 48 | msg = "MIC_FAIL"; |
javierp | 0:33f2abdc6bf9 | 49 | break; |
javierp | 0:33f2abdc6bf9 | 50 | default: |
javierp | 0:33f2abdc6bf9 | 51 | break; |
javierp | 0:33f2abdc6bf9 | 52 | } |
javierp | 0:33f2abdc6bf9 | 53 | logTrace("Event: %s", msg.c_str()); |
javierp | 0:33f2abdc6bf9 | 54 | |
javierp | 0:33f2abdc6bf9 | 55 | logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", |
javierp | 0:33f2abdc6bf9 | 56 | flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); |
javierp | 0:33f2abdc6bf9 | 57 | logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d", |
javierp | 0:33f2abdc6bf9 | 58 | info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, |
javierp | 0:33f2abdc6bf9 | 59 | info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); |
javierp | 0:33f2abdc6bf9 | 60 | } |
javierp | 0:33f2abdc6bf9 | 61 | |
javierp | 0:33f2abdc6bf9 | 62 | if (flags->Bits.Rx) { |
javierp | 0:33f2abdc6bf9 | 63 | |
javierp | 0:33f2abdc6bf9 | 64 | logDebug("Rx %d bytes", info->RxBufferSize); |
javierp | 0:33f2abdc6bf9 | 65 | if (info->RxBufferSize > 0) { |
javierp | 0:33f2abdc6bf9 | 66 | // print RX data as string and hexadecimal |
javierp | 0:33f2abdc6bf9 | 67 | std::string rx((const char*)info->RxBuffer, info->RxBufferSize); |
javierp | 0:33f2abdc6bf9 | 68 | printf("Rx data: %s [%s]\r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); |
javierp | 0:33f2abdc6bf9 | 69 | } |
javierp | 0:33f2abdc6bf9 | 70 | } |
javierp | 0:33f2abdc6bf9 | 71 | } |
javierp | 0:33f2abdc6bf9 | 72 | }; |
javierp | 0:33f2abdc6bf9 | 73 | |
javierp | 0:33f2abdc6bf9 | 74 | #endif |
javierp | 0:33f2abdc6bf9 | 75 |