rfid_tag_phy.cpp

00001 
00002 #include "rfid_tag_phy.hpp"
00003 #include "node.hpp"
00004 
00005 RfidTagPhy::RfidTagPhy(
00006    NodePtr node, WirelessChannelManagerPtr wirelessChannelManager)
00007    : PhysicalLayer(node), m_sendingChannelIsValid(false), 
00008    m_allListenersChannelIsValid(false)
00009 {
00010    m_wirelessChannelManagerPtr = wirelessChannelManager;
00011 }
00012 
00013 RfidTagPhy::~RfidTagPhy()
00014 {
00015    // Detatch from any channels to which it is still attached.
00016    if(m_sendingChannelIsValid) {
00017       m_wirelessChannelManagerPtr->detachAsSender(thisPhysicalLayer(), 
00018          m_sendingChannel);
00019    }
00020 
00021    if(m_allListenersChannelIsValid) {
00022       m_wirelessChannelManagerPtr->detachAsListener(thisPhysicalLayer(),
00023          m_allListenersChannel);
00024    }
00025 }
00026 
00027 void RfidTagPhy::simulationEndHandler()
00028 {
00029 
00030 }
00031 
00032 void RfidTagPhy::resetSendingChannel()
00033 {
00034    assert(m_wirelessChannelManagerPtr.get() != 0);
00035 
00036    if(m_sendingChannelIsValid) {
00037       m_wirelessChannelManagerPtr->detachAsSender(thisPhysicalLayer(), 
00038          m_sendingChannel);
00039    }
00040 
00041 }
00042 
00043 bool RfidTagPhy::setSendingChannel(t_uint channelId)
00044 {
00045    assert(m_wirelessChannelManagerPtr.get() != 0);
00046 
00047    // First, we need to see if we can detach from our current
00048    // channel if it's valid.
00049    resetSendingChannel();
00050 
00051    bool wasSuccessful = true;
00052    wasSuccessful &= m_wirelessChannelManagerPtr->attachAsSender(
00053       thisPhysicalLayer(), channelId);
00054 
00055    m_sendingChannelIsValid = wasSuccessful;
00056    m_sendingChannel = channelId;
00057 
00058    return wasSuccessful;
00059 }
00060 
00061 bool RfidTagPhy::setAllListenersChannel(t_uint channelId)
00062 {
00063    assert(m_wirelessChannelManagerPtr.get() != 0);
00064 
00065    resetAllListenersChannel();
00066 
00067    bool wasSuccessful = true;
00068    wasSuccessful &= m_wirelessChannelManagerPtr->attachAsListener(
00069       thisPhysicalLayer(), channelId);
00070 
00071    m_allListenersChannelIsValid = wasSuccessful;
00072    m_allListenersChannel = channelId;
00073 
00074    return wasSuccessful;
00075 
00076 }
00077 
00078 void RfidTagPhy::resetAllListenersChannel()
00079 {
00080 
00081    assert(m_wirelessChannelManagerPtr.get() != 0);
00082    if(m_allListenersChannelIsValid) {
00083       m_wirelessChannelManagerPtr->detachAsListener(thisPhysicalLayer(),
00084          m_allListenersChannel);
00085    }
00086 
00087    m_allListenersChannelIsValid = false;
00088 }
00089 
00090 void RfidTagPhy::recvdErrorFreeSignal(WirelessCommSignalPtr signal,
00091    double recvdSignalStrength)
00092 {
00093    // The tag should lock onto the channel on which the
00094    // packet was received.
00095    setSendingChannel(signal->getChannelId());
00096    setCurrentTxPower(recvdSignalStrength);
00097 }
00098 
00099 

Generated on Tue Dec 12 17:04:38 2006 for rfidsim by  doxygen 1.4.7