phyPER.cc

00001 //
00002 // (c) 2009 CSEM SA, Neuchâtel, Switzerland.
00003 //
00004 // This program is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program.  If not, see http://www.gnu.org/licenses/.
00016 //
00017 
00018 #include "phyPER.h"
00019 
00020 Define_Module(phyPER);
00021 
00022 void phyPER::initialize(int stage)
00023 {
00024   BaseModule::initialize(stage);
00025   if(stage == 0) {
00026     catPacket = utility->subscribe(this, &packet, -1);
00027     catUWBIRPacket = utility->subscribe(this, &uwbirpacket, -1);
00028     maiPER.setName("maiPER");
00029     maiPERnoRS.setName("maiPERnoRS");
00030     nbSyncAttempts = 0;
00031     nbSyncSuccesses = 0;
00032     nbRx = 0;
00033     nbRxnoRS = 0;
00034   }
00035 }
00036 
00037 
00038 void phyPER::receiveBBItem(int category, const BBItem * details, int scopeModuleId) {
00039     if(category == catPacket) {
00040       packet = *(static_cast<const Packet*>(details));
00041       nbRx = static_cast<long>(packet.getNbPacketsReceived());
00042       nbRxnoRS = static_cast<long>(packet.getNbPacketsReceivedNoRS());
00043     } else if(category == catUWBIRPacket) {
00044       uwbirpacket = *(static_cast<const UWBIRPacket*>(details));
00045       nbSyncAttempts = static_cast<long>(uwbirpacket.getNbSyncAttempts());
00046       nbSyncSuccesses = uwbirpacket.getNbSyncSuccesses();
00047     }
00048     if(nbSyncAttempts > 0) {
00049       maiPER.record( static_cast<double>(nbRx) / nbSyncAttempts );
00050       maiPERnoRS.record( static_cast<double>(nbRxnoRS) / nbSyncAttempts );
00051     }
00052 
00053 }