Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

NetworkStatusControl.cc

Go to the documentation of this file.
00001 #ifdef PLATFORM_APERIOS
00002 
00003 #include "ControlBase.h"
00004 #include "Motion/MMAccessor.h"
00005 #include "NullControl.h"
00006 #include "Events/EventRouter.h"
00007 #include "Wireless/Wireless.h"
00008 
00009 #include "Shared/RobotInfo.h"
00010 #ifdef TGT_HAS_LEDS
00011 #  include "Motion/LedMC.h"
00012 #endif
00013 
00014 #ifdef PLATFORM_APERIOS
00015 #  include <ERA201D1.h>
00016 #endif
00017 
00018 //! will display current network status such as wireless signal strength
00019 class NetworkStatusControl : public ControlBase, public EventListener {
00020 public:
00021   //! constructor
00022   NetworkStatusControl() : ControlBase("Network Status","Displays current network status such as wireless signal strength"), EventListener() {}
00023   
00024   //! constructor, pass custom name
00025   NetworkStatusControl(const std::string& nm) : ControlBase(nm,"Displays current network status such as wireless signal strength"), EventListener() {}
00026   
00027   //! stops listening for power events and sets display to invalid
00028   virtual void pause() {
00029     erouter->remove(this);
00030     ControlBase::pause();
00031   }
00032   //! calls report()
00033   virtual void refresh() {
00034     erouter->addTimer(this,0,1000,true);
00035 #ifdef PLATFORM_APERIOS
00036     EtherDriverGetWLANStatisticsMsg msg;
00037     EtherStatus status = ERA201D1_GetWLANStatistics(&msg);
00038     clearSlots();
00039     const unsigned int TMP_SIZE=255;
00040     char tmp[TMP_SIZE];
00041     if (status == ETHER_OK) {
00042       snprintf(tmp,TMP_SIZE,"link: %d",msg.statistics.link);
00043       pushSlot(new NullControl(tmp));
00044       snprintf(tmp,TMP_SIZE,"signal: %d",msg.statistics.signal);
00045       pushSlot(new NullControl(tmp));
00046       snprintf(tmp,TMP_SIZE,"noise: %d",msg.statistics.noise);
00047       pushSlot(new NullControl(tmp));
00048       snprintf(tmp,TMP_SIZE,"invalidIDCount: %u",(unsigned int)msg.statistics.invalidIDCount);
00049       pushSlot(new NullControl(tmp));
00050       snprintf(tmp,TMP_SIZE,"invalidEncCount: %u",(unsigned int)msg.statistics.invalidEncCount);
00051       pushSlot(new NullControl(tmp));
00052       snprintf(tmp,TMP_SIZE,"invalidMiscCount: %u",(unsigned int)msg.statistics.invalidMiscCount);
00053       pushSlot(new NullControl(tmp));
00054       MMAccessor<LedMC> leds_acc(display_id);
00055       leds_acc->displayPercent(msg.statistics.signal/100.0,LedEngine::major,LedEngine::major);
00056     } else {
00057       snprintf(tmp,TMP_SIZE,"ERA201D1_GetWLANSettings() FAILED %d", status);
00058       pushSlot(new NullControl("Error Accessing wireless statistics",tmp));
00059       serr->printf("%s",tmp);
00060     }
00061 #else
00062     // Other platforms here?
00063 #endif
00064     ControlBase::refresh();
00065   }
00066   virtual void deactivate() {
00067     erouter->remove(this);
00068     ControlBase::deactivate();
00069   }
00070   //! refresh the control whenever an event is received
00071   virtual void processEvent(const EventBase& /*event*/) {
00072     refresh();
00073   }
00074   
00075 };
00076 
00077 REGISTER_CONTROL(NetworkStatusControl,"Status Reports");
00078 
00079 #endif
00080 
00081 /*! @file
00082  * @brief Defines NetworkStatusControl, which will display current network status such as wireless signal strength
00083  * @author Sony OPEN-R Sample Code
00084  * @author klibby and lkirtane (original port)
00085  * @author ejt (UI repackaging)
00086  */

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:45 2016 by Doxygen 1.6.3