Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
inc/RadioEvent.h
- Committer:
- alan1974
- Date:
- 2018-06-18
- Revision:
- 0:a91cd1b08360
- Child:
- 11:77fe4f18a81b
File content as of revision 0:a91cd1b08360:
#ifndef __RADIO_EVENT_H__
#define __RADIO_EVENT_H__
#include "dot_util.h"
#include "mDotEvent.h"
//extern bool downstream_packet_received;
class RadioEvent : public mDotEvent
{
private:
bool downstream_packet_received;
std::vector<uint8_t> received_packet;
public:
RadioEvent() {
downstream_packet_received = false;
}
virtual ~RadioEvent() {}
std::vector<uint8_t> get_downstream_packet() {
downstream_packet_received = false;
return received_packet; //0x4567;
}
bool is_packet_received() {
return downstream_packet_received;
}
/*!
* MAC layer event callback prototype.
*
* \param [IN] flags Bit field indicating the MAC events occurred
* \param [IN] info Details about MAC events occurred
*/
virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) {
//printf("--------------------- DRT. this is a test. Bits.Rx = %d\r\n", flags->Bits.Rx);
if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) {
std::string msg = "OK";
switch (info->Status) {
case LORAMAC_EVENT_INFO_STATUS_ERROR:
msg = "ERROR";
break;
case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT:
msg = "TX_TIMEOUT";
break;
case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT:
msg = "RX_TIMEOUT";
break;
case LORAMAC_EVENT_INFO_STATUS_RX_ERROR:
msg = "RX_ERROR";
break;
case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL:
msg = "JOIN_FAIL";
break;
case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL:
msg = "DOWNLINK_FAIL";
break;
case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL:
msg = "ADDRESS_FAIL";
break;
case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL:
msg = "MIC_FAIL";
break;
default:
break;
}
logTrace("Event: %s", msg.c_str());
logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d",
flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept);
logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d",
info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize,
info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways);
}
if (flags->Bits.Rx) {
logDebug("Rx %d bytes", info->RxBufferSize);
if (info->RxBufferSize > 0) {
// print RX data as hexadecimal
//printf("******* DRT ****** Rx data: %s\r\n", mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str());
//downstream_packet_received = true;
int i;
received_packet.clear();
for (i=0; i<(info->RxBufferSize); i++)
{
printf("Rx Data %d = %x\r\n", i, info->RxBuffer[i]);
received_packet.push_back(info->RxBuffer[i]);
}
downstream_packet_received = true;
// print RX data as string
//std::string rx((const char*)info->RxBuffer, info->RxBufferSize);
//printf("Rx data: %s\r\n", rx.c_str());
}
}
}
};
#endif