PhyLayerUWBIR.h

00001 /* -*- mode:c++ -*- ********************************************************
00002  * file:        PhyLayerUWBIR.h
00003  *
00004  * author:      Jerome Rousselot <jerome.rousselot@csem.ch>
00005  *
00006  * copyright:   (C) 2008 Centre Suisse d'Electronique et Microtechnique (CSEM) SA
00007  *        Systems Engineering
00008  *              Wireless Embedded Systems
00009  *              Jaquet-Droz 1, CH-2002 Neuchatel, Switzerland.
00010  *
00011  *
00012  *              This program is free software; you can redistribute it
00013  *              and/or modify it under the terms of the GNU General Public
00014  *              License as published by the Free Software Foundation; either
00015  *              version 2 of the License, or (at your option) any later
00016  *              version.
00017  *              For further information see file COPYING
00018  *              in the top level directory
00019  * description: this physical layer models an ultra wideband impulse radio channel.
00020  * acknowledgment: this work was supported (in part) by the National Competence
00021  *          Center in Research on Mobile Information and Communication Systems
00022  *        NCCR-MICS, a center supported by the Swiss National Science
00023  *        Foundation under grant number 5005-67322.
00024  ***************************************************************************/
00025 //
00026 // A physical layer that models an Ultra Wideband Impulse Radio wireless communication system.
00027 //
00028 // This class loads channel models and delivers frames to an UWB Decider. It is independent of the modulation technique,
00029 // as long as the frames are represented using the same approach as in IEEE802154A.h (Maximum Pulse Amplitude Estimation).
00030 //
00031 // Several channel models are possible: Ghassemzadeh-LOS, Ghassemadeh-NLOS (see UWBIRStochasticPathlossModel.h)
00032 // and the IEEE 802.15.4A UWB channel models that use the default power delay profile (see UWBIRIEEE802154APathlossModel.h).
00033 //
00034 // Currently, an energy detection receiver is modeled in UWBIRED.h.
00035 // Several synchronization logics have been implemented in derived classes:
00036 // see DeciderUWBIREDSync.h and and DeciderUWBIREDSyncOnAddress.h.
00037 //
00038 // To add a novel receiver (e.g. coherent demodulation), either derive UWBIRED or write a new one,
00039 // then add functionality in this module to load the new decider.
00040 // The same procedure applies for new channel models.
00041 //
00042 // To change the modulation, see UWBIRMac.h, IEEE802154A.h and UWBIRED.h.
00043 //
00044 // To implement optional modes of IEEE802154A, see IEEE802154A.h.
00045 //
00046 // Citation of the following publication is appreciated if you use the MiXiM UWB PHY model
00047 // for a publication of your own.
00048 // J. Rousselot, J.-D. Decotignie, An ultra-wideband impulse radio PHY
00049 // layer model for network simulation. SIMULATION January 2011 vol. 87 no. 1-2 82-112.
00050 //
00051 // For more information, see also:
00052 //
00053 // [1] J. Rousselot, J.-D. Decotignie, An ultra-wideband impulse radio PHY
00054 // layer model for network simulation. SIMULATION January 2011 vol. 87 no.
00055 // 1-2 82-112. http://dx.doi.org/10.1177/0037549710377767
00056 // [2] J. Rousselot, Ultra Low Power Communication Protocols for UWB
00057 // Impulse Radio Wireless Sensor Networks. EPFL Thesis 4720, 2010.
00058 // http://infoscience.epfl.ch/record/147987
00059 // [3]  A High-Precision Ultra Wideband Impulse Radio Physical Layer Model
00060 // for Network Simulation, Jérôme Rousselot, Jean-Dominique Decotignie,
00061 // Second International Omnet++ Workshop,Simu'TOOLS, Rome, 6 Mar 09.
00062 // http://portal.acm.org/citation.cfm?id=1537714
00063 //
00064 
00065 #ifndef UWBIR_PHY_LAYER_H
00066 #define UWBIR_PHY_LAYER_H
00067 
00068 #include "PhyLayerBattery.h"
00069 #include "RadioUWBIR.h"
00070 #include "UWBIRStochasticPathlossModel.h"
00071 #include "UWBIRIEEE802154APathlossModel.h"
00072 #include "HostState.h"
00073 #include "MacToPhyControlInfo.h"
00074 #include "BaseUtility.h"
00075 
00076 
00077 class DeciderUWBIRED;
00078 class DeciderUWBIREDSyncOnAddress;
00079 class DeciderUWBIREDSync;
00080 
00081 #include "DeciderUWBIRED.h"
00082 #include "DeciderUWBIREDSyncOnAddress.h"
00083 #include "DeciderUWBIREDSync.h"
00084 
00118 class PhyLayerUWBIR : public BasePhyLayer
00119 {
00120   friend class DeciderUWBIRED;
00121 
00122 public:
00123   void initialize(int stage);
00124         PhyLayerUWBIR() : uwbpathloss(0), ieee802154AChannel(0) {}
00125 
00126     void finish();
00127 
00128     // this function allows to include common xml documents for ned parameters as ned functions
00129     static cDynamicExpression::Value ghassemzadehNLOSFunc(cComponent *context, cDynamicExpression::Value argv[], int argc) {
00130       const char * ghassemzadehnlosxml =
00131           "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
00132           "<root>"
00133           "<AnalogueModels>"
00134           "<AnalogueModel type=\"UWBIRStochasticPathlossModel\"><parameter name=\"PL0\" type=\"double\" value=\"-51\"/>"
00135                 "<parameter name=\"mu_gamma\" type=\"double\" value=\"3.5\"/>"
00136                     "<parameter name=\"sigma_gamma\" type=\"double\" value=\"0.97\"/>"
00137                     "<parameter name=\"mu_sigma\" type=\"double\" value=\"2.7\"/>"
00138                     "<parameter name=\"sigma_sigma\" type=\"double\" value=\"0.98\"/>"
00139                     "<parameter name=\"isEnabled\" type=\"bool\" value=\"true\"/>"
00140                     "<parameter name=\"shadowing\" type=\"bool\" value=\"true\"/>"
00141                 "</AnalogueModel>"
00142           "</AnalogueModels>"
00143           "</root>";
00144       cXMLParImpl xmlParser;
00145       xmlParser.parse(ghassemzadehnlosxml);  // from char* to xml
00146       cDynamicExpression::Value parameters(xmlParser.xmlValue(NULL)); // from xml to Value
00147       return parameters;
00148     }
00149     typedef cDynamicExpression::Value (*fptr) (cComponent *context, cDynamicExpression::Value argv[], int argc);
00150     static fptr ghassemzadehNLOSFPtr;
00151     //static cDynamicExpression::Value (*ghassemzadehNLOSFPtr) (cComponent *context, cDynamicExpression::Value argv[], int argc);
00152 
00153 
00154 
00155 protected:
00156 
00157     UWBIRStochasticPathlossModel* uwbpathloss;
00158     UWBIRIEEE802154APathlossModel* ieee802154AChannel;
00159     DeciderUWBIRED* uwbdecider;
00160 
00161     virtual AirFrame *encapsMsg(cPacket *msg);
00162 
00163     virtual AnalogueModel* getAnalogueModelFromName(std::string name, ParameterMap& params);
00164 
00165     AnalogueModel* createUWBIRStochasticPathlossModel(ParameterMap & params);
00166     AnalogueModel* createUWBIRIEEE802154APathlossModel(ParameterMap & params);
00167     AnalogueModel* createIntensityModel(ParameterMap & params);
00168     virtual Decider* getDeciderFromName(std::string name, ParameterMap& params);
00169     virtual Radio* initializeRadio();
00170 
00171     RadioUWBIR* uwbradio;
00175     virtual void receiveBBItem(int category, const BBItem *details, int scopeModuleId);
00176 
00177     virtual void handleAirFrame(cMessage* msg);
00178 
00179     virtual void switchRadioToRX() {
00180       Enter_Method_Silent();
00181       uwbradio->startReceivingFrame(simTime());
00182       setRadioCurrent(uwbradio->getCurrentState());
00183     }
00184 
00185     virtual void switchRadioToSync() {
00186       Enter_Method_Silent();
00187       uwbradio->finishReceivingFrame(simTime());
00188       setRadioCurrent(radio->getCurrentState());
00189     }
00190 
00191     virtual simtime_t setRadioState(int rs);
00192 
00194   int numActivities;
00195 
00197   double sleepCurrent, rxCurrent, decodingCurrentDelta, txCurrent, syncCurrent;
00198 
00200   double setupRxCurrent, setupTxCurrent, rxTxCurrent, txRxCurrent;
00201 
00206   enum Activities {
00207     SLEEP_ACCT=0,
00208     RX_ACCT,      //1
00209     TX_ACCT,      //2
00210     SWITCHING_ACCT, //3
00211     SYNC_ACCT,    //4
00212   };
00213 
00214   enum ProtocolIds {
00215     IEEE_802154_UWB = 3200,
00216   };
00217 
00218   virtual void setRadioCurrent(int rs);
00219 
00220   virtual void setSwitchingCurrent(int from, int to);
00221 
00228   virtual void handleHostState(const HostState& state);
00229 
00233   virtual void finishRadioSwitching();
00234 
00235 };
00236 
00237 #endif