|
INET Framework for OMNeT++/OMNEST
|
00001 /* -*- mode:c++ -*- ******************************************************** 00002 * file: RadioState.h 00003 * 00004 * author: Andreas Koepke 00005 * modifications Andras Varga, 2006 00006 * 00007 * copyright: (C) 2004 Telecommunication Networks Group (TKN) at 00008 * Technische Universitaet Berlin, Germany. 00009 * 00010 * This program is free software; you can redistribute it 00011 * and/or modify it under the terms of the GNU General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2 of the License, or (at your option) any later 00014 * version. 00015 * For further information see file COPYING 00016 * in the top level directory 00017 *************************************************************************** 00018 * part of: framework implementation developed by tkn 00019 **************************************************************************/ 00020 00021 #ifndef RADIOSTATE_H 00022 #define RADIOSTATE_H 00023 00024 #include <omnetpp.h> 00025 #include "INETDefs.h" 00026 00039 class INET_API RadioState : public cPolymorphic 00040 { 00041 public: 00043 enum State 00044 { 00045 IDLE, 00046 RECV, 00047 TRANSMIT, 00048 SLEEP 00049 }; 00050 00051 //XXX consider adding the following: 00052 //Q: how to notify a TRANSMIT->RECV transition? as TRANSMIT_END, RECV_START, both, or some 3rd one? 00053 // enum Transition 00054 // { 00055 // TRANSMIT_START, ///< start of a transmission (non-TRANSMIT to TRANSMIT) 00056 // TRANSMIT_END, ///< TRANSMIT to non-TRANSMIT (note: new state is in "state" field) 00057 // RECV_START, ///< IDLE to RECV 00058 // RECV_END_OK, ///< reception ends, frame received OK 00059 // RECV_END_ERROR ///< reception ends, received frame has bit errors 00060 // }; 00061 00062 private: 00063 int radioId; // identifies the radio 00064 State state; // IDLE, RECV, TRANSMIT, SLEEP 00065 int channelNumber; // the radio channel 00066 double bitrate; // the current transmit bitrate 00067 00068 public: 00070 RadioState(int radioModuleId) : cPolymorphic() { 00071 radioId = radioModuleId; state = IDLE; channelNumber = -1; bitrate = -1; 00072 } 00073 00075 int getRadioId() const { return radioId; } 00076 00078 State getState() const { return state; } 00079 00081 void setState(State s) { state = s; } 00082 00084 int getChannelNumber() const { return channelNumber; } 00085 00087 void setChannelNumber(int chan) { channelNumber = chan; } 00088 00090 double getBitrate() const { return bitrate; } 00091 00093 void setBitrate(double d) { bitrate = d; } 00094 00096 static const char *stateName(State state) { 00097 switch(state) { 00098 case IDLE: return "IDLE"; 00099 case RECV: return "RECV"; 00100 case TRANSMIT: return "TRANSMIT"; 00101 case SLEEP: return "SLEEP"; 00102 default: return "???"; 00103 } 00104 } 00105 00107 std::string info() const { 00108 std::stringstream out; 00109 out << stateName(state) << ", channel #" << channelNumber << ", " << (bitrate/1e6) << "Mbps "; 00110 return out.str(); 00111 } 00112 00113 }; 00114 00115 00116 inline std::ostream& operator<<(std::ostream& os, const RadioState& r) 00117 { 00118 return os << r.info(); 00119 } 00120 00121 #endif