Test program for FF1705.
Dependencies: libxDot-dev-mbed5-deprecated ISL29011
Example/inc/RadioEvent.h@2:9b44950b84af, 2017-11-09 (annotated)
- Committer:
- jernej_vrscaj
- Date:
- Thu Nov 09 07:18:24 2017 +0000
- Revision:
- 2:9b44950b84af
- Parent:
- 1:12a289bd6b82
Small correction in printf message.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jernej_vrscaj | 0:d96e7e513c16 | 1 | #ifndef __RADIO_EVENT_H__ |
jernej_vrscaj | 0:d96e7e513c16 | 2 | #define __RADIO_EVENT_H__ |
jernej_vrscaj | 0:d96e7e513c16 | 3 | |
jernej_vrscaj | 0:d96e7e513c16 | 4 | #include "dot_util.h" |
jernej_vrscaj | 0:d96e7e513c16 | 5 | #include "mDotEvent.h" |
jernej_vrscaj | 0:d96e7e513c16 | 6 | #include "C12832.h" |
jernej_vrscaj | 0:d96e7e513c16 | 7 | |
jernej_vrscaj | 1:12a289bd6b82 | 8 | #define TEST_board |
jernej_vrscaj | 1:12a289bd6b82 | 9 | //#define REFERENCE_board |
jernej_vrscaj | 0:d96e7e513c16 | 10 | |
jernej_vrscaj | 0:d96e7e513c16 | 11 | #ifdef TEST_board |
jernej_vrscaj | 0:d96e7e513c16 | 12 | extern C12832 lcd; |
jernej_vrscaj | 0:d96e7e513c16 | 13 | extern uint8_t trx; |
jernej_vrscaj | 0:d96e7e513c16 | 14 | extern uint8_t sent_rx; |
jernej_vrscaj | 0:d96e7e513c16 | 15 | |
jernej_vrscaj | 0:d96e7e513c16 | 16 | #elif defined(REFERENCE_board) |
jernej_vrscaj | 0:d96e7e513c16 | 17 | extern uint8_t received; |
jernej_vrscaj | 0:d96e7e513c16 | 18 | extern uint16_t *ptr_rx; |
jernej_vrscaj | 0:d96e7e513c16 | 19 | |
jernej_vrscaj | 0:d96e7e513c16 | 20 | #endif |
jernej_vrscaj | 0:d96e7e513c16 | 21 | |
jernej_vrscaj | 0:d96e7e513c16 | 22 | class RadioEvent : public mDotEvent |
jernej_vrscaj | 0:d96e7e513c16 | 23 | { |
jernej_vrscaj | 0:d96e7e513c16 | 24 | |
jernej_vrscaj | 0:d96e7e513c16 | 25 | public: |
jernej_vrscaj | 0:d96e7e513c16 | 26 | RadioEvent() {} |
jernej_vrscaj | 0:d96e7e513c16 | 27 | |
jernej_vrscaj | 0:d96e7e513c16 | 28 | virtual ~RadioEvent() {} |
jernej_vrscaj | 0:d96e7e513c16 | 29 | |
jernej_vrscaj | 0:d96e7e513c16 | 30 | /*! |
jernej_vrscaj | 0:d96e7e513c16 | 31 | * MAC layer event callback prototype. |
jernej_vrscaj | 0:d96e7e513c16 | 32 | * |
jernej_vrscaj | 0:d96e7e513c16 | 33 | * \param [IN] flags Bit field indicating the MAC events occurred |
jernej_vrscaj | 0:d96e7e513c16 | 34 | * \param [IN] info Details about MAC events occurred |
jernej_vrscaj | 0:d96e7e513c16 | 35 | */ |
jernej_vrscaj | 0:d96e7e513c16 | 36 | virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { |
jernej_vrscaj | 0:d96e7e513c16 | 37 | |
jernej_vrscaj | 0:d96e7e513c16 | 38 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
jernej_vrscaj | 0:d96e7e513c16 | 39 | std::string msg = "OK"; |
jernej_vrscaj | 0:d96e7e513c16 | 40 | switch (info->Status) { |
jernej_vrscaj | 0:d96e7e513c16 | 41 | case LORAMAC_EVENT_INFO_STATUS_ERROR: |
jernej_vrscaj | 0:d96e7e513c16 | 42 | msg = "ERROR"; |
jernej_vrscaj | 0:d96e7e513c16 | 43 | break; |
jernej_vrscaj | 0:d96e7e513c16 | 44 | case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: |
jernej_vrscaj | 0:d96e7e513c16 | 45 | msg = "TX_TIMEOUT"; |
jernej_vrscaj | 0:d96e7e513c16 | 46 | break; |
jernej_vrscaj | 0:d96e7e513c16 | 47 | case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: |
jernej_vrscaj | 0:d96e7e513c16 | 48 | msg = "RX_TIMEOUT"; |
jernej_vrscaj | 0:d96e7e513c16 | 49 | break; |
jernej_vrscaj | 0:d96e7e513c16 | 50 | case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: |
jernej_vrscaj | 0:d96e7e513c16 | 51 | msg = "RX_ERROR"; |
jernej_vrscaj | 0:d96e7e513c16 | 52 | break; |
jernej_vrscaj | 0:d96e7e513c16 | 53 | case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: |
jernej_vrscaj | 0:d96e7e513c16 | 54 | msg = "JOIN_FAIL"; |
jernej_vrscaj | 0:d96e7e513c16 | 55 | break; |
jernej_vrscaj | 0:d96e7e513c16 | 56 | case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: |
jernej_vrscaj | 0:d96e7e513c16 | 57 | msg = "DOWNLINK_FAIL"; |
jernej_vrscaj | 0:d96e7e513c16 | 58 | break; |
jernej_vrscaj | 0:d96e7e513c16 | 59 | case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: |
jernej_vrscaj | 0:d96e7e513c16 | 60 | msg = "ADDRESS_FAIL"; |
jernej_vrscaj | 0:d96e7e513c16 | 61 | break; |
jernej_vrscaj | 0:d96e7e513c16 | 62 | case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: |
jernej_vrscaj | 0:d96e7e513c16 | 63 | msg = "MIC_FAIL"; |
jernej_vrscaj | 0:d96e7e513c16 | 64 | break; |
jernej_vrscaj | 0:d96e7e513c16 | 65 | default: |
jernej_vrscaj | 0:d96e7e513c16 | 66 | break; |
jernej_vrscaj | 0:d96e7e513c16 | 67 | } |
jernej_vrscaj | 0:d96e7e513c16 | 68 | logTrace("Event: %s", msg.c_str()); |
jernej_vrscaj | 0:d96e7e513c16 | 69 | |
jernej_vrscaj | 0:d96e7e513c16 | 70 | logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", |
jernej_vrscaj | 0:d96e7e513c16 | 71 | flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); |
jernej_vrscaj | 0:d96e7e513c16 | 72 | logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d", |
jernej_vrscaj | 0:d96e7e513c16 | 73 | info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, |
jernej_vrscaj | 0:d96e7e513c16 | 74 | info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); |
jernej_vrscaj | 0:d96e7e513c16 | 75 | } |
jernej_vrscaj | 0:d96e7e513c16 | 76 | |
jernej_vrscaj | 0:d96e7e513c16 | 77 | if (flags->Bits.Rx) { |
jernej_vrscaj | 0:d96e7e513c16 | 78 | |
jernej_vrscaj | 0:d96e7e513c16 | 79 | printf("Rx %d bytes \r\n", info->RxBufferSize); // Rx 2 bytes |
jernej_vrscaj | 0:d96e7e513c16 | 80 | |
jernej_vrscaj | 0:d96e7e513c16 | 81 | if (info->RxBufferSize > 0) { |
jernej_vrscaj | 0:d96e7e513c16 | 82 | |
jernej_vrscaj | 0:d96e7e513c16 | 83 | #ifdef TEST_board |
jernej_vrscaj | 0:d96e7e513c16 | 84 | |
jernej_vrscaj | 0:d96e7e513c16 | 85 | sent_rx = 1; |
jernej_vrscaj | 0:d96e7e513c16 | 86 | |
jernej_vrscaj | 0:d96e7e513c16 | 87 | uint16_t *ptr_tx = (uint16_t*)(info->RxBuffer); // warning! get shifted transmited data; MSByte relevant |
jernej_vrscaj | 0:d96e7e513c16 | 88 | printf("*ptr_tx: %#x\r\n", *ptr_tx); |
jernej_vrscaj | 0:d96e7e513c16 | 89 | *ptr_tx = *ptr_tx >> 8; // shift MSByte to LSByte |
jernej_vrscaj | 0:d96e7e513c16 | 90 | printf("*ptr_tx shift left by 8-bit: %#x\r\n", *ptr_tx); |
jernej_vrscaj | 0:d96e7e513c16 | 91 | |
jernej_vrscaj | 0:d96e7e513c16 | 92 | printf("%#x\r\n",trx); |
jernej_vrscaj | 0:d96e7e513c16 | 93 | |
jernej_vrscaj | 0:d96e7e513c16 | 94 | // print RX data as string and hexadecimal |
jernej_vrscaj | 0:d96e7e513c16 | 95 | std::string rx((const char*)info->RxBuffer, info->RxBufferSize); |
jernej_vrscaj | 0:d96e7e513c16 | 96 | |
jernej_vrscaj | 0:d96e7e513c16 | 97 | printf("Rx data: (String):%s (HexString):%s \r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); |
jernej_vrscaj | 0:d96e7e513c16 | 98 | |
jernej_vrscaj | 0:d96e7e513c16 | 99 | lcd.locate(0,10); |
jernej_vrscaj | 0:d96e7e513c16 | 100 | lcd.printf("Prejeto: %u (+1)", *ptr_tx); |
jernej_vrscaj | 0:d96e7e513c16 | 101 | |
jernej_vrscaj | 0:d96e7e513c16 | 102 | |
jernej_vrscaj | 0:d96e7e513c16 | 103 | if(*ptr_tx == trx+1) // compare received and transmitted+1 value |
jernej_vrscaj | 0:d96e7e513c16 | 104 | { |
jernej_vrscaj | 0:d96e7e513c16 | 105 | lcd.locate(0,20); |
jernej_vrscaj | 0:d96e7e513c16 | 106 | lcd.printf("PASS!"); |
jernej_vrscaj | 0:d96e7e513c16 | 107 | printf("PASS\r\n"); |
jernej_vrscaj | 0:d96e7e513c16 | 108 | |
jernej_vrscaj | 0:d96e7e513c16 | 109 | } |
jernej_vrscaj | 0:d96e7e513c16 | 110 | else |
jernej_vrscaj | 0:d96e7e513c16 | 111 | { |
jernej_vrscaj | 0:d96e7e513c16 | 112 | lcd.locate(0,20); |
jernej_vrscaj | 0:d96e7e513c16 | 113 | lcd.printf("FAIL!"); |
jernej_vrscaj | 0:d96e7e513c16 | 114 | printf("FAIL\r\n"); |
jernej_vrscaj | 0:d96e7e513c16 | 115 | } |
jernej_vrscaj | 0:d96e7e513c16 | 116 | |
jernej_vrscaj | 0:d96e7e513c16 | 117 | |
jernej_vrscaj | 0:d96e7e513c16 | 118 | |
jernej_vrscaj | 0:d96e7e513c16 | 119 | #elif defined(REFERENCE_board) |
jernej_vrscaj | 0:d96e7e513c16 | 120 | |
jernej_vrscaj | 0:d96e7e513c16 | 121 | // get Received value |
jernej_vrscaj | 0:d96e7e513c16 | 122 | ptr_rx = (uint16_t*)(info->RxBuffer); // warning! get shifted transmited data; MSByte relevant |
jernej_vrscaj | 0:d96e7e513c16 | 123 | *ptr_rx = *ptr_rx >> 8; // shift MSByte to LSByte |
jernej_vrscaj | 0:d96e7e513c16 | 124 | printf("*ptr_rx shift left by 8-bit: %#x \r\n", *ptr_rx); |
jernej_vrscaj | 0:d96e7e513c16 | 125 | |
jernej_vrscaj | 0:d96e7e513c16 | 126 | // print RX data as string and hexadecimal |
jernej_vrscaj | 0:d96e7e513c16 | 127 | std::string rx((const char*)info->RxBuffer, info->RxBufferSize); |
jernej_vrscaj | 0:d96e7e513c16 | 128 | printf("Rx data: (String):%s (HexString):%s \r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); |
jernej_vrscaj | 0:d96e7e513c16 | 129 | |
jernej_vrscaj | 0:d96e7e513c16 | 130 | received = 1; // indicate that the RadioEvent has happened |
jernej_vrscaj | 0:d96e7e513c16 | 131 | |
jernej_vrscaj | 0:d96e7e513c16 | 132 | printf("received: %u \r\n", received); |
jernej_vrscaj | 0:d96e7e513c16 | 133 | |
jernej_vrscaj | 0:d96e7e513c16 | 134 | #endif |
jernej_vrscaj | 0:d96e7e513c16 | 135 | |
jernej_vrscaj | 0:d96e7e513c16 | 136 | } |
jernej_vrscaj | 0:d96e7e513c16 | 137 | } |
jernej_vrscaj | 0:d96e7e513c16 | 138 | } |
jernej_vrscaj | 0:d96e7e513c16 | 139 | }; |
jernej_vrscaj | 0:d96e7e513c16 | 140 | |
jernej_vrscaj | 0:d96e7e513c16 | 141 | #endif |
jernej_vrscaj | 0:d96e7e513c16 | 142 | |
jernej_vrscaj | 0:d96e7e513c16 | 143 |