#include <urbi/uobject.h>
#include <ERA201D1.h>

using namespace urbi;

class Wifi: public UObject //must inherit from UObject
{
	public:
		UVar link,signal,noise;
		EtherDriverGetWLANStatisticsMsg wlanStatMsg;
		EtherStatus status;

	//the constructor registers init only
	Wifi(std::string s): UObject(s) { //required
		UBindFunction( Wifi, init); //register init
	}

	int init(std::string cameraval) { //URBI constructor
		UBindVar( Wifi,link);
		UBindVar( Wifi,signal);
		UBindVar( Wifi,noise);
		
		UNotifyAccess(link, &Wifi::getStatistics);
		UNotifyAccess(signal, &Wifi::getStatistics);
		UNotifyAccess(noise, &Wifi::getStatistics);
		
		return 0;
	}
	
	
	int getStatistics(UVar &) {
		// GetWLANStatistics
		status = ERA201D1_GetWLANStatistics(&wlanStatMsg);
		if (status != ETHER_OK) {
			return 1;
		}
		
		// Save informations
		link = wlanStatMsg.statistics.link;// link
		signal = wlanStatMsg.statistics.signal;// signal
		noise = wlanStatMsg.statistics.noise;// noise
		
		return 0;
	}

};
UStart(Wifi);
