RadioUWBIR.h

00001 /*
00002  * RadioUWBIR.h
00003  * Author: Jerome Rousselot <jerome.rousselot@csem.ch>
00004  * Copyright: (C) 2008-2010 Centre Suisse d'Electronique et Microtechnique (CSEM) SA
00005  *              Wireless Embedded Systems
00006  *              Jaquet-Droz 1, CH-2002 Neuchatel, Switzerland.
00007  */
00008 
00009 
00010 #ifndef UWBIRRADIO_H_
00011 #define UWBIRRADIO_H_
00012 
00013 #include "PhyUtils.h"
00014 #include "BasePhyLayer.h"
00015 #include "UWBIRIEEE802154APathlossModel.h"
00016 
00030 class RadioUWBIR: public Radio {
00031   friend class PhyLayerUWBIR;
00032 
00033 public:
00034 
00035   enum UWBIRRadioStates {
00036     /* receiving state*/
00037      SYNC = Radio::NUM_RADIO_STATES,
00038      UWBIR_NUM_RADIO_STATES
00039   };
00040 
00041   /* Static factory method (see Radio class in PhyUtils.h) */
00042   static RadioUWBIR* createNewUWBIRRadio(int initialState,
00043                  bool recordStats,
00044                  double minAtt = 1.0,
00045                  double maxAtt = 0.0)
00046   {
00047     return new RadioUWBIR(RadioUWBIR::UWBIR_NUM_RADIO_STATES,
00048              recordStats,
00049              initialState,
00050              minAtt, maxAtt);
00051   }
00052 
00053 
00059   virtual simtime_t switchTo(int newState, simtime_t now) {
00060     // state must be one of sleep, receive or transmit (not sync)
00061     //assert(newState != Radio::SYNC);
00062     if(newState == state || (newState == RadioUWBIR::RX && state == RadioUWBIR::SYNC)) {
00063       return -1; // nothing to do
00064     } else {
00065       if(newState == RadioUWBIR::RX) {
00066         // prevent entering "frame reception" immediately
00067         newState = RadioUWBIR::SYNC;
00068       }
00069       return reallySwitchTo(newState, now);
00070     }
00071   }
00072 
00073   virtual simtime_t reallySwitchTo(int newState, simtime_t now) {
00074     // set the nextState to the newState and the current state to SWITCHING
00075     nextState = newState;
00076     int lastState = state;
00077     state = RadioUWBIR::SWITCHING;
00078         radioStates.record(state);
00079     // make entry to RSAM
00080     makeRSAMEntry(now, state);
00081 
00082     // return matching entry from the switch times matrix
00083     return swTimes[lastState][nextState];
00084   }
00085 
00086 protected:
00087 
00088   RadioUWBIR(int numRadioStates,bool recordStats, int initialState, double minAtt = 1.0, double maxAtt = 0.0)
00089   :Radio(numRadioStates, recordStats, initialState, minAtt, maxAtt) { }
00090 
00091   virtual double mapStateToAtt(int state)
00092   {
00093     if (state == RadioUWBIR::RX || state == RadioUWBIR::SYNC)
00094     {
00095       return minAtt;
00096     } else
00097     {
00098       return maxAtt;
00099     }
00100   }
00101 
00102 private:
00107   virtual void startReceivingFrame(simtime_t now) {
00108     assert(state == RadioUWBIR::SYNC);
00109     state = RadioUWBIR::SWITCHING;
00110     nextState = RadioUWBIR::RX;
00111     endSwitch(now);
00112   }
00118   virtual void finishReceivingFrame(simtime_t now) {
00119     assert(state == RadioUWBIR::RX);
00120     state = RadioUWBIR::SWITCHING;
00121     nextState = RadioUWBIR::SYNC;
00122     endSwitch(now);
00123   }
00124 
00125 };
00126 
00127 #endif /* UWBIRRADIO_H_ */