Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

NetworkStatusControl.h

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

Tekkotsu v4.0
Generated Thu Nov 22 00:54:54 2007 by Doxygen 1.5.4