Decider for the 802.15.4 Narrow band module. More...
#include <Decider802154Narrow.h>
Inherits BaseDecider.
Public Types | |
enum | Decider802154NarrowControlKinds { RECEPTION_STARTED = LAST_BASE_DECIDER_CONTROL_KIND, LAST_DECIDER802154NARROW_CONTROL_KIND } |
Public Member Functions | |
Decider802154Narrow (DeciderToPhyInterface *phy, int myIndex, bool debug, int sfdLength, double BER_LOWER_BOUND, const std::string &modulation, int phyHeaderLength, bool recordStats) | |
Initializes the Decider with a pointer to its PhyLayer and specific values for threshold and sensitivity. | |
virtual void | channelChanged (int newChannel) |
Called by phy layer to indicate that the channel this radio currently listens to has changed. | |
virtual void | finish () |
Method to be called by an OMNeT-module during its own finish(), to enable a decider to do some things. | |
Protected Member Functions | |
virtual simtime_t | processNewSignal (AirFrame *frame) |
Process a new signal the first time. | |
virtual simtime_t | processSignalHeader (AirFrame *frame) |
Processes the end of the header of a received Signal. | |
virtual simtime_t | processSignalEnd (AirFrame *frame) |
Process the end of a signal. | |
double | getBERFromSNR (double snr) |
bool | syncOnSFD (AirFrame *frame) |
double | evalBER (AirFrame *frame) |
double | n_choose_k (int n, int k) |
Helper function to compute BER from SNR using analytical formulas. | |
Protected Attributes | |
int | sfdLength |
Start Frame Delimiter length in bits. | |
double | BER_LOWER_BOUND |
Minimum bit error rate. If SNIR is high, computed ber could be higher than maximum radio performance. This value is an upper bound to the performance. | |
std::string | modulation |
modulation type | |
int | phyHeaderLength |
PHY header length in bits. | |
cOutVector | snirDropped |
cOutVector | snirReceived |
cOutVector | snrlog |
cOutVector | berlog |
bool | recordStats |
Tracked statistic values. | |
unsigned long | nbFramesWithInterference |
unsigned long | nbFramesWithoutInterference |
unsigned long | nbFramesWithInterferenceDropped |
unsigned long | nbFramesWithoutInterferenceDropped |
Decider for the 802.15.4 Narrow band module.
Definition at line 21 of file Decider802154Narrow.h.
void Decider802154Narrow::channelChanged | ( | int | newChannel | ) | [virtual] |
Called by phy layer to indicate that the channel this radio currently listens to has changed.
Sub-classing deciders which support multiple channels should override this method to handle the effects of channel changes on ongoing receptions.
newChannel | The new channel the radio has changed to. |
Reimplemented from Decider.
Definition at line 239 of file Decider802154Narrow.cc.
{
//TODO: stop receiving
;
}
simtime_t Decider802154Narrow::processSignalEnd | ( | AirFrame * | frame | ) | [protected, virtual] |
Process the end of a signal.
Checks if signal was received correct and sends it up to the MAC layer.
Reimplemented from BaseDecider.
Definition at line 83 of file Decider802154Narrow.cc.
References BER_LOWER_BOUND, BaseDecider::calcChannelSenseRSSI(), BaseDecider::calculateSnrMapping(), ConstMapping::createConstIterator(), BaseDecider::currentSignal, Signal::getBitrate(), DeciderToPhyInterface::getChannelInfo(), ConstMappingIterator::getNextPosition(), ConstMappingIterator::getPosition(), Signal::getSignalLength(), Signal::getSignalStart(), Argument::getTime(), ConstMappingIterator::getValue(), ConstMapping::getValue(), ConstMappingIterator::hasNext(), ConstMappingIterator::next(), Decider::notAgain, BaseDecider::PACKET_DROPPED, Decider::phy, MappingUtils::post(), DeciderToPhyInterface::sendControlMsg(), DeciderToPhyInterface::sendUp(), BaseDecider::setChannelIdleStatus(), snirDropped, and snirReceived.
{ ConstMapping* snrMapping = calculateSnrMapping(frame); Signal& s = frame->getSignal(); simtime_t start = s.getSignalStart(); simtime_t end = start + s.getSignalLength(); AirFrameVector channel; phy->getChannelInfo(start, end, channel); bool hasInterference = channel.size() > 1; if(hasInterference) { nbFramesWithInterference++; } else { nbFramesWithoutInterference++; } double bitrate = s.getBitrate()->getValue(Argument(start)); double avgBER = 0; double bestBER = 0.5; double snirAvg = 0; bool noErrors = true; double ber; double errorProbability; simtime_t receivingStart = MappingUtils::post(start); Argument argStart(receivingStart); ConstMappingIterator* iter = snrMapping->createConstIterator(argStart); double snirMin = iter->getValue(); // Evaluate bit errors for each snr value // and stops as soon as we have an error. // TODO: add error correction code. simtime_t curTime = iter->getPosition().getTime(); simtime_t snrDuration; while(curTime < end) { //get SNR for this interval double snr = iter->getValue(); //determine end of this interval simtime_t nextTime = end; //either the end of the signal... if(iter->hasNext()) { //or the position of the next entry const Argument& argNext = iter->getNextPosition(); nextTime = std::min(argNext.getTime(), nextTime); iter->next(); //the iterator will already point to the next entry } if (noErrors) { snrDuration = nextTime - curTime; int nbBits = int (snrDuration.dbl() * bitrate); // non-coherent detection of m-ary orthogonal signals in an AWGN // Channel // Digital Communications, John G. Proakis, section 4.3.2 // p. 212, (4.3.32) // Pm = sum(n=1,n=M-1){(-1)^(n+1)choose(M-1,n) 1/(n+1) exp(-nkgamma/(n+1))} // Pb = 2^(k-1)/(2^k - 1) Pm ber = std::max(getBERFromSNR(snr), BER_LOWER_BOUND); avgBER = ber*nbBits; snirAvg = snirAvg + snr*snrDuration.dbl(); if(ber < bestBER) { bestBER = ber; } errorProbability = 1.0 - pow((1.0 - ber), nbBits); noErrors = errorProbability < uniform(0, 1); } if (snr < snirMin) snirMin = snr; curTime = nextTime; } delete iter; delete snrMapping; avgBER = avgBER / frame->getBitLength(); snirAvg = snirAvg / (end - start); //double rssi = 10*log10(snirAvg); double rssi = calcChannelSenseRSSI(start, end); if (noErrors) { phy->sendUp(frame, new DeciderResult802154Narrow(true, bitrate, snirMin, avgBER, rssi)); if(recordStats) { snirReceived.record(10*log10(snirMin)); // in dB } } else { MacPkt* mac = static_cast<MacPkt*> (frame->decapsulate()); mac->setName("BIT_ERRORS"); mac->setKind(PACKET_DROPPED); DeciderResult802154Narrow* result = new DeciderResult802154Narrow(false, bitrate, snirMin, avgBER, rssi); PhyToMacControlInfo* cInfo = new PhyToMacControlInfo(result); mac->setControlInfo(cInfo); phy->sendControlMsg(mac); if(recordStats) { snirDropped.record(10*log10(snirMin)); // in dB } if(hasInterference) { nbFramesWithInterferenceDropped++; } else { nbFramesWithoutInterferenceDropped++; } } //decoding is done currentSignal.first = 0; //channel is back idle setChannelIdleStatus(true); //TODO: publish rssi and channel state return notAgain; }
simtime_t Decider802154Narrow::processSignalHeader | ( | AirFrame * | frame | ) | [protected, virtual] |
Processes the end of the header of a received Signal.
Returns the time it wants to handle the signal again.
Default implementation does not handle signal headers.
Reimplemented from BaseDecider.
Definition at line 60 of file Decider802154Narrow.cc.
References BaseDecider::currentSignal, Signal::getSignalLength(), Signal::getSignalStart(), Decider::notAgain, Decider::phy, DeciderToPhyInterface::sendControlMsg(), and BaseDecider::setChannelIdleStatus().
{ if (!syncOnSFD(frame)) { currentSignal.first = 0; //channel is back idle setChannelIdleStatus(true); return notAgain; } // store this frame as signal to receive and set state // currentSignal.first = frame; currentSignal.second = EXPECT_END; //channel is busy now setChannelIdleStatus(false); //TODO: publish rssi and channel state // Inform the MAC that we started receiving a frame phy->sendControlMsg(new cMessage("start_rx",RECEPTION_STARTED)); Signal& s = frame->getSignal(); return s.getSignalStart() + s.getSignalLength(); }
cOutVector Decider802154Narrow::berlog [protected] |
log ber value each time we enter getBERFromSNR
Definition at line 61 of file Decider802154Narrow.h.
Referenced by Decider802154Narrow().
cOutVector Decider802154Narrow::snirDropped [protected] |
log minimum snir values of dropped packets
Definition at line 51 of file Decider802154Narrow.h.
Referenced by Decider802154Narrow(), and processSignalEnd().
cOutVector Decider802154Narrow::snirReceived [protected] |
log minimum snir values of received packets
Definition at line 54 of file Decider802154Narrow.h.
Referenced by Decider802154Narrow(), and processSignalEnd().
cOutVector Decider802154Narrow::snrlog [protected] |
log snr value each time we enter getBERFromSNR
Definition at line 58 of file Decider802154Narrow.h.
Referenced by Decider802154Narrow().