DeciderUWBIREDSync.cc

00001 #include "DeciderUWBIREDSync.h"
00002 
00003 
00004 DeciderUWBIREDSync::DeciderUWBIREDSync(DeciderToPhyInterface* iface,
00005         PhyLayerUWBIR* _uwbiface,
00006         double _syncThreshold, bool _syncAlwaysSucceeds, bool _stats,
00007         bool _trace, double _tmin, bool alwaysFailOnDataInterference) :
00008           DeciderUWBIRED(iface, _uwbiface,
00009             _syncThreshold, _syncAlwaysSucceeds, _stats, _trace,
00010             alwaysFailOnDataInterference),
00011             tmin(_tmin){
00012 
00013 };
00014 
00015 bool DeciderUWBIREDSync::attemptSync(Signal* s) {
00016   syncVector.clear();
00017   // Retrieve all potentially colliding airFrames
00018   phy->getChannelInfo(s->getSignalStart(), s->getSignalStart()+IEEE802154A::mandatory_preambleLength,
00019       syncVector);
00020   assert(syncVector.size() != 0);
00021 
00022   if (syncVector.size() == 1) {
00023     return evaluateEnergy(s);
00024   }
00025 
00026   bool synchronized = false;
00027   AirFrameVector::iterator it = syncVector.begin();
00028   bool search = true;
00029   simtime_t latestSyncStart = s->getSignalStart() + IEEE802154A::mandatory_preambleLength - tmin;
00030   AirFrame* af = syncVector.front();
00031   Signal & aSignal = af->getSignal();
00032 
00033   while(search &&
00034       !(aSignal.getSignalStart() == s->getSignalStart() &&
00035           aSignal.getSignalLength() == s->getSignalLength())) {
00036     if(aSignal.getSignalStart()+aSignal.getSignalLength() > latestSyncStart) {
00037       // CASE: the end of one of the previous signals goes too far
00038       // and prevents synchronizing on the current frame.
00039       search = false;
00040       break;
00041     }
00042     it++;
00043     af = *it;
00044     aSignal = af->getSignal();
00045   }
00046 
00047   if(search && it != syncVector.end()) {
00048     // sync is possible but there is a frame beginning after our sync start
00049     Signal & nextSignal = (*it)->getSignal();
00050     if(nextSignal.getSignalStart() <
00051         aSignal.getSignalStart()+aSignal.getSignalLength() + tmin) {
00052       // CASE: sync is not possible because next frame starts too early
00053       search = false;
00054     }
00055   }
00056 
00057   if(search) {
00058     // the signal is long enough. Now evaluate its energy
00059     synchronized = evaluateEnergy(s);
00060   }
00061 
00062   return synchronized;
00063 };
00064 
00065 bool DeciderUWBIREDSync::evaluateEnergy(Signal* s) {
00066   // Assumption: channel coherence time > signal duration
00067   // Thus we can simply sample the first pulse of the received signal
00068   ConstMapping* rxPower = s->getReceivingPower();
00069   argSync.setTime(s->getSignalStart() + IEEE802154A::tFirstSyncPulseMax);
00070   // We could retrieve the pathloss through s->getAttenuation() but we must be careful:
00071   // maybe the pathloss is not the only analogue model (e.g. RSAMAnalogueModel)
00072   // If we get the pathloss, we can compute Eb/N0: Eb=1E-3*pathloss if we are at peak power
00073   double signalPower = sqrt(pow(rxPower->getValue(argSync), 2)*0.5*peakPulsePower / 10); // de-normalize, take half, and 10 dB losses
00074   double noisePower = pow(getNoiseValue(), 2)/ 50;
00075   if(signalPower / noisePower > syncThreshold) {
00076     return true;
00077   }
00078   return false;
00079 };
00080 
00081 DeciderUWBIREDSync::~DeciderUWBIREDSync() {
00082   syncVector.clear();
00083 };
00084 
00085 
00086