00001
00002 #include "rfid_reader_phy.hpp"
00003 #include "node.hpp"
00004
00005
00006 const double RfidReaderPhy::m_DEFAULT_READER_RX_THRESHOLD = 3.652e-10;
00007 const double RfidReaderPhy::m_DEFAULT_READER_CS_THRESHOLD = 1.559e-11;
00008
00009 RfidReaderPhy::RfidReaderPhy(
00010 NodePtr node, WirelessChannelManagerPtr wirelessChannelManager)
00011 : PhysicalLayer(node), m_regularChannelIsValid(false),
00012 m_allSendersChannelIsValid(false)
00013 {
00014 m_wirelessChannelManagerPtr = wirelessChannelManager;
00015 setRxThreshold(m_DEFAULT_READER_RX_THRESHOLD);
00016 setCsThreshold(m_DEFAULT_READER_CS_THRESHOLD);
00017 }
00018
00019 RfidReaderPhy::~RfidReaderPhy()
00020 {
00021
00022 if(m_regularChannelIsValid) {
00023 m_wirelessChannelManagerPtr->detachAsListener(thisPhysicalLayer(),
00024 m_regularChannel);
00025 m_wirelessChannelManagerPtr->detachAsSender(thisPhysicalLayer(),
00026 m_regularChannel);
00027 }
00028
00029 if(m_allSendersChannelIsValid) {
00030 m_wirelessChannelManagerPtr->detachAsSender(thisPhysicalLayer(),
00031 m_allSendersChannel);
00032 }
00033 }
00034
00035 void RfidReaderPhy::simulationEndHandler()
00036 {
00037
00038 }
00039
00040 void RfidReaderPhy::resetRegularChannel()
00041 {
00042 assert(m_wirelessChannelManagerPtr.get() != 0);
00043
00044 if(m_regularChannelIsValid) {
00045 m_wirelessChannelManagerPtr->detachAsListener(thisPhysicalLayer(),
00046 m_regularChannel);
00047 m_wirelessChannelManagerPtr->detachAsSender(thisPhysicalLayer(),
00048 m_regularChannel);
00049 }
00050
00051 }
00052
00053 bool RfidReaderPhy::setRegularChannel(t_uint channelId)
00054 {
00055 assert(m_wirelessChannelManagerPtr.get() != 0);
00056
00057
00058
00059 resetRegularChannel();
00060
00061 bool wasSuccessful = true;
00062 wasSuccessful &= m_wirelessChannelManagerPtr->attachAsListener(
00063 thisPhysicalLayer(), channelId);
00064 wasSuccessful &= m_wirelessChannelManagerPtr->attachAsSender(
00065 thisPhysicalLayer(), channelId);
00066
00067 m_regularChannelIsValid = wasSuccessful;
00068 m_regularChannel = channelId;
00069
00070 return wasSuccessful;
00071 }
00072
00073 bool RfidReaderPhy::setAllSendersChannel(t_uint channelId)
00074 {
00075 assert(m_wirelessChannelManagerPtr.get() != 0);
00076
00077 resetAllSendersChannel();
00078
00079 bool wasSuccessful = true;
00080 wasSuccessful &= m_wirelessChannelManagerPtr->attachAsSender(
00081 thisPhysicalLayer(), channelId);
00082
00083 m_allSendersChannelIsValid = wasSuccessful;
00084 m_allSendersChannel = channelId;
00085
00086 return wasSuccessful;
00087
00088 }
00089
00090 void RfidReaderPhy::resetAllSendersChannel()
00091 {
00092
00093 assert(m_wirelessChannelManagerPtr.get() != 0);
00094 if(m_allSendersChannelIsValid) {
00095 m_wirelessChannelManagerPtr->detachAsSender(thisPhysicalLayer(),
00096 m_allSendersChannel);
00097 }
00098
00099 m_allSendersChannelIsValid = false;
00100 }
00101
00102