L-Tek / Mbed OS TEST_FF1705

Dependencies:   libxDot-dev-mbed5-deprecated ISL29011

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RadioEvent.h Source File

RadioEvent.h

00001 #ifndef __RADIO_EVENT_H__
00002 #define __RADIO_EVENT_H__
00003 
00004 #include "dot_util.h"
00005 #include "mDotEvent.h"
00006 #include "C12832.h"
00007 
00008 #define TEST_board
00009 //#define REFERENCE_board
00010 
00011 #ifdef TEST_board
00012 extern C12832 lcd;
00013 extern uint8_t trx; 
00014 extern uint8_t sent_rx; 
00015 
00016 #elif defined(REFERENCE_board)
00017 extern uint8_t received;
00018 extern uint16_t *ptr_rx;
00019 
00020 #endif
00021 
00022 class RadioEvent : public mDotEvent
00023 {
00024  
00025 public:
00026     RadioEvent() {}
00027  
00028     virtual ~RadioEvent() {}
00029  
00030     /*!
00031      * MAC layer event callback prototype.
00032      *
00033      * \param [IN] flags Bit field indicating the MAC events occurred
00034      * \param [IN] info  Details about MAC events occurred
00035      */
00036     virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) {
00037  
00038         if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) {
00039             std::string msg = "OK";
00040             switch (info->Status) {
00041                 case LORAMAC_EVENT_INFO_STATUS_ERROR:
00042                     msg = "ERROR";
00043                     break;
00044                 case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT:
00045                     msg = "TX_TIMEOUT";
00046                     break;
00047                 case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT:
00048                     msg = "RX_TIMEOUT";
00049                     break;
00050                 case LORAMAC_EVENT_INFO_STATUS_RX_ERROR:
00051                     msg = "RX_ERROR";
00052                     break;
00053                 case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL:
00054                     msg = "JOIN_FAIL";
00055                     break;
00056                 case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL:
00057                     msg = "DOWNLINK_FAIL";
00058                     break;
00059                 case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL:
00060                     msg = "ADDRESS_FAIL";
00061                     break;
00062                 case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL:
00063                     msg = "MIC_FAIL";
00064                     break;
00065                 default:
00066                     break;
00067             }
00068             logTrace("Event: %s", msg.c_str());
00069  
00070             logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d",
00071                      flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept);
00072             logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d",
00073                      info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize,
00074                      info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways);
00075         }
00076  
00077         if (flags->Bits.Rx) {
00078             
00079             printf("Rx %d bytes \r\n", info->RxBufferSize);                     // Rx 2 bytes
00080             
00081             if (info->RxBufferSize > 0) {
00082 
00083 #ifdef TEST_board
00084                 
00085                 sent_rx = 1;
00086                 
00087                 uint16_t *ptr_tx = (uint16_t*)(info->RxBuffer);                 // warning! get shifted transmited data; MSByte relevant
00088                 printf("*ptr_tx: %#x\r\n", *ptr_tx);
00089                 *ptr_tx = *ptr_tx >> 8;                                         // shift MSByte to LSByte
00090                 printf("*ptr_tx shift left by 8-bit: %#x\r\n", *ptr_tx);
00091                 
00092                 printf("%#x\r\n",trx);
00093                 
00094                 // print RX data as string and hexadecimal 
00095                 std::string rx((const char*)info->RxBuffer, info->RxBufferSize);
00096                     
00097                 printf("Rx data: (String):%s (HexString):%s \r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str());
00098 
00099                 lcd.locate(0,10);
00100                 lcd.printf("Prejeto: %u (+1)", *ptr_tx);
00101                 
00102                 
00103                 if(*ptr_tx == trx+1)                                            // compare received and transmitted+1 value
00104                 {
00105                    lcd.locate(0,20);
00106                    lcd.printf("PASS!");   
00107                    printf("PASS\r\n");
00108 
00109                 }
00110                 else
00111                 {
00112                    lcd.locate(0,20);
00113                    lcd.printf("FAIL!"); 
00114                    printf("FAIL\r\n");
00115                 }
00116                             
00117                 
00118                 
00119 #elif defined(REFERENCE_board)
00120                 
00121                 // get Received value       
00122                 ptr_rx = (uint16_t*)(info->RxBuffer);                           // warning! get shifted transmited data; MSByte relevant
00123                 *ptr_rx = *ptr_rx >> 8;                                         // shift MSByte to LSByte
00124                 printf("*ptr_rx shift left by 8-bit: %#x \r\n", *ptr_rx);
00125             
00126                 // print RX data as string and hexadecimal    
00127                 std::string rx((const char*)info->RxBuffer, info->RxBufferSize);
00128                 printf("Rx data: (String):%s (HexString):%s \r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str());
00129                           
00130                 received = 1;                                                   // indicate that the RadioEvent has happened
00131                 
00132                 printf("received: %u \r\n", received);
00133  
00134 #endif
00135                 
00136             }
00137         }
00138     }
00139 };
00140 
00141 #endif
00142 
00143