Loading Noto/Servers/NotoWeatherStation/include/MeteoSocket.h +6 −4 Original line number Diff line number Diff line Loading @@ -22,10 +22,10 @@ public: virtual ~MeteoSocket(); int sendCMD(CError&,CString); int receiveData(CError&,CString&); CError connection() throw (ACSErr::ACSbaseExImpl); void connection() throw (ACSErr::ACSbaseExImpl); CError init() ; CError disconnection() throw (ACSErr::ACSbaseExImpl);; void disconnection() throw (ACSErr::ACSbaseExImpl);; inline bool isConnected(){return m_isConnected;}; void initParser(MeteoData *md); // void releaseParser(){ XML_ParserFree(p);};; Loading @@ -35,6 +35,9 @@ public: double getTemperature(); double getHumidity(); double getPressure(); double getWindspeedPeak(); int updateParam(); private: Loading @@ -59,7 +62,6 @@ static int Depth; int fs_parse(const char* buff); // weather data from the field system // MeteoData *m_sensorData; int updateParam(); Loading Noto/Servers/NotoWeatherStation/include/NotoWeatherStationImpl.h +31 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ #include "MeteoData.h" #include <ManagementErrors.h> #include <acsThread.h> /* const CString ADDRESS="192.167.8.13"; //DEBUG const int THREADSLEEPSECONDS=10000; // 1 s in unit of 100ns, from thread sleep time*/ Loading Loading @@ -65,6 +68,33 @@ Not all the paramters from the station have been implemented. @todo add all the info returned by the HW */ using ACS::ThreadBase; class MeteoSocket; class CMeteoParamUpdaterThread : public ACS::Thread { public: CMeteoParamUpdaterThread (const ACE_CString& name, MeteoSocket* socket, const ACS::TimeInterval& responseTime=ThreadBase::defaultResponseTime, const ACS::TimeInterval& sleepTime=ThreadBase::defaultSleepTime) ; ~CMeteoParamUpdaterThread() { ACS_TRACE("CMeteoParamUpdaterThread::~CMeteoParamUpdaterThread"); } virtual void onStop(); virtual void onStart(); virtual void runLoop(); private: int loopCounter_m; int m_threshold; // wind threshold in km/h MeteoSocket * m_socket; }; Loading Loading @@ -168,6 +198,7 @@ private: SmartPropertyPointer<RWdouble> m_humidity; SmartPropertyPointer<RWdouble> m_pressure; SmartPropertyPointer<RWdouble> m_windspeedPeak; CMeteoParamUpdaterThread *m_controlThread_p; SimpleParser::CParser<MeteoSocket> * m_parser; Loading Noto/Servers/NotoWeatherStation/src/CMeteoParamUpdaterThread.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line #include "NotoWeatherStationImpl.h" CMeteoParamUpdaterThread::CMeteoParamUpdaterThread (const ACE_CString& name, MeteoSocket * socketConnectionWeatherStation, const ACS::TimeInterval& responseTime, const ACS::TimeInterval& sleepTime) : ACS::Thread(name) { ACS_TRACE("CMeteoParamUpdaterThread::CMeteoParamUpdaterThread"); loopCounter_m = 0; m_socket = (MeteoSocket *) socketConnectionWeatherStation; } void CMeteoParamUpdaterThread::runLoop() { Weather::parameters wdata; double wind; TIMEVALUE now; IRA::CIRATools::getTime(now); m_socket->updateParam(); } void CMeteoParamUpdaterThread::onStop() { AUTO_TRACE("CMeteoParamUpdaterThread::onStop()"); } void CMeteoParamUpdaterThread::onStart() { AUTO_TRACE("WindCheckerThread::onStart()"); } Noto/Servers/NotoWeatherStation/src/Makefile +1 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ EXECUTABLES_L = # Linked with Medicina stubs because has the same interface as Noto # <brief description of xxxxx program> NotoWeatherStationImpl_OBJECTS = MeteoSocket NotoWeatherStationImpl NotoWeatherStationImpl_OBJECTS = MeteoSocket CMeteoParamUpdaterThread NotoWeatherStationImpl #xxxxx_LDFLAGS = NotoWeatherStationImpl_LIBS =ComponentErrors \ NotoWeatherStationStubs\ Loading Noto/Servers/NotoWeatherStation/src/MeteoSocket.cpp +92 −74 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ #define MAXSIZE 255 int MeteoSocket::Depth=0; #define SIMULATOR // #define SIMULATOR Loading Loading @@ -57,6 +57,7 @@ int MeteoSocket::sendCMD(CError& err, CString cmd) int MeteoSocket:: updateParam(){ // // cout << "update param" <<endl; #ifndef SIMULATOR try{ Loading @@ -64,34 +65,53 @@ int MeteoSocket:: updateParam(){ int n_sent=0; CError err; CString rdata=""; /* connect();*/ connection(); n_sent=Send(err,WEATHERCMD,CString(WEATHERCMD).GetLength()); if ((n_sent==FAIL) || (err.isNoError()==false) ) { _EXCPT(ComponentErrors::SocketErrorExImpl,ex,"MeteoSocket::update Param()- sending cmd to Socket"); ex.log(LM_DEBUG); throw ex; } cout <<"Manda manda:" << WEATHERCMD << endl; cout << "sent:"<<n_sent << endl; ACS_DEBUG_PARAM("MeteoSocket::updateParam(CError& err, CString cmd)","sent: %s", (const char *) WEATHERCMD); /* receiveData(err,rdata);*/ int n_received,n_received_total=0; char buff[MAXSIZE]; char receivedChar=0; int i=0; CTimer timer; while (n_received_total !=100) while (n_received_total !=100 && timer.elapsed() < 5* 10000000 ) { n_received=Receive(err,&receivedChar,1); // receivedChar=buff[0]; if (i >= MAXSIZE ) // avoid pointer overflow if ((n_received==FAIL) || (err.isNoError()==false) ) { _EXCPT(ComponentErrors::SocketErrorExImpl,ex,"MeteoSocket::update Param()- receiving param from Socket"); ex.log(LM_DEBUG); throw ex; } /* if (i >= MAXSIZE ) // avoid pointer overflow { buff[i]=0; rdata=CString(buff); return n_received_total; } }*/ buff[i++]=receivedChar; Loading @@ -100,6 +120,13 @@ int MeteoSocket:: updateParam(){ } buff[n_received_total]=0; if (n_received_total !=100) { ACS_LOG(LM_FULL_INFO,"MeteoSocket::updateParm()",(LM_WARNING,"Weather Parameters Not updated ")); return 0; } Loading @@ -110,26 +137,22 @@ int MeteoSocket:: updateParam(){ ACS_DEBUG_PARAM("MeteoSocket::updateParam(CError& err, CString cmd)","received: %s", (const char *) rdata) // sendCMD(err,CString("noresp\n")); parse(buff); IRA::CIRATools::Wait(0,50000); if (err.isNoError()) return 0; else { cout <<"err:"<< err.getFullDescription()<<endl; return -1; } /* disconnect();*/ disconnection(); }catch (ComponentErrors::SocketErrorExImpl &x) { ACS_LOG(LM_FULL_INFO,"MeteoSocket:: updateParam", (LM_ERROR,"Can not connect to WeatherStation @%s:%d ", (const char *) ADDRESS,PORT)); CError error; // CError object only for Closing the Socket) if (m_isConnected==true) { Close (error); m_isConnected=false; } _THROW_EXCPT(ComponentErrors::SocketErrorExImpl,"MeteoSocket:: updateParam"); Loading Loading @@ -208,46 +231,42 @@ CError MeteoSocket::init() CError MeteoSocket::connection() throw (ACSErr::ACSbaseExImpl) void MeteoSocket::connection() throw (ACSErr::ACSbaseExImpl) { OperationResult err ; try{ err=Create(m_error,STREAM); if (err==FAIL) { m_isConnected=false; } setSockMode(m_error,BLOCKING); _EXCPT(ComponentErrors::SocketErrorExImpl,ex,"MeteoSocket::connection()- Cannot create Socket"); ex.log(LM_DEBUG); throw ex; } else { setSockMode(m_error,BLOCKINGTIMEO,2000000,2000000); err=Connect(m_error,ADDRESS,PORT); if (err==FAIL) { CError error; // CError object only for Closing the Socket) Close (error); m_isConnected=false; _EXCPT(ComponentErrors::SocketErrorExImpl,ex,"MeteoSocket::connect()- Connect to Socket"); ex.log(LM_DEBUG); throw ex; Close (error); m_isConnected=false; return m_error; /* return m_error;*/ } m_isConnected=true; // return m_error; } catch(...) { cout <<"Connect Error" << endl; return m_error; } } CError MeteoSocket::disconnection()throw (ACSErr::ACSbaseExImpl) void MeteoSocket::disconnection()throw (ACSErr::ACSbaseExImpl) { ACS_LOG(LM_FULL_INFO,"MeteoSocket::Disconnect()",(LM_INFO," disconnecting Socket")); Loading @@ -272,14 +291,14 @@ CError MeteoSocket::disconnection()throw (ACSErr::ACSbaseExImpl) } return m_error; /* return m_error;*/ } double MeteoSocket::getWindSpeed() { // if((updateParam()==-1)) cout <<"Error Reading Param"<< endl; updateParam(); //updateParam(); // m_windspeed=-99; // windspeed disabled ACS_LOG(LM_FULL_INFO,"MeteoSocket::getWindSpeed()",(LM_TRACE,"Not yet implemented")); Loading @@ -292,7 +311,6 @@ double MeteoSocket::getWindSpeed() double MeteoSocket::getWindDir() { // if((updateParam()==-1)) cout <<"Error Reading Param"<< endl; updateParam(); ACS_LOG(LM_FULL_INFO,"MeteoSocket::getWindDir()",(LM_TRACE,"Not yet implemented")); #ifdef SIMULATOR Loading @@ -307,10 +325,10 @@ double MeteoSocket::getWindDir() } double MeteoSocket::getTemperature() { /* if((updateParam()==-1)){ ACS_LOG(LM_FULL_INFO,"MeteoSocket::getTemperature()",(LM_ERROR,"Reading Temperature")); } }*/ #ifdef SIMULATOR m_temperature=7; Loading @@ -322,9 +340,9 @@ double MeteoSocket::getTemperature() } double MeteoSocket::getHumidity() { //to be impemented if((updateParam()==-1)){ ACS_LOG(LM_FULL_INFO,"MeteoSocket::getHumidity()",(LM_ERROR,"Reading Humidity")); } // if((updateParam()==-1)){ // ACS_LOG(LM_FULL_INFO,"MeteoSocket::getHumidity()",(LM_ERROR,"Reading Humidity")); // } #ifdef SIMULATOR Loading @@ -335,9 +353,9 @@ double MeteoSocket::getHumidity() { } double MeteoSocket::getPressure() { //to be impemented if((updateParam()==-1)){ /* if((updateParam()==-1)){ ACS_LOG(LM_FULL_INFO,"MeteoSocket::getPressure()",(LM_ERROR,"Reading Pressure")); } }*/ #ifdef SIMULATOR m_pressure=1024; Loading @@ -347,12 +365,12 @@ double MeteoSocket::getPressure() { } //double MeteoSocket::getWinDir() { // // to be implemented // return -99; // // //} double MeteoSocket::getWindspeedPeak() { return m_windspeedPeak; } Loading Loading
Noto/Servers/NotoWeatherStation/include/MeteoSocket.h +6 −4 Original line number Diff line number Diff line Loading @@ -22,10 +22,10 @@ public: virtual ~MeteoSocket(); int sendCMD(CError&,CString); int receiveData(CError&,CString&); CError connection() throw (ACSErr::ACSbaseExImpl); void connection() throw (ACSErr::ACSbaseExImpl); CError init() ; CError disconnection() throw (ACSErr::ACSbaseExImpl);; void disconnection() throw (ACSErr::ACSbaseExImpl);; inline bool isConnected(){return m_isConnected;}; void initParser(MeteoData *md); // void releaseParser(){ XML_ParserFree(p);};; Loading @@ -35,6 +35,9 @@ public: double getTemperature(); double getHumidity(); double getPressure(); double getWindspeedPeak(); int updateParam(); private: Loading @@ -59,7 +62,6 @@ static int Depth; int fs_parse(const char* buff); // weather data from the field system // MeteoData *m_sensorData; int updateParam(); Loading
Noto/Servers/NotoWeatherStation/include/NotoWeatherStationImpl.h +31 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ #include "MeteoData.h" #include <ManagementErrors.h> #include <acsThread.h> /* const CString ADDRESS="192.167.8.13"; //DEBUG const int THREADSLEEPSECONDS=10000; // 1 s in unit of 100ns, from thread sleep time*/ Loading Loading @@ -65,6 +68,33 @@ Not all the paramters from the station have been implemented. @todo add all the info returned by the HW */ using ACS::ThreadBase; class MeteoSocket; class CMeteoParamUpdaterThread : public ACS::Thread { public: CMeteoParamUpdaterThread (const ACE_CString& name, MeteoSocket* socket, const ACS::TimeInterval& responseTime=ThreadBase::defaultResponseTime, const ACS::TimeInterval& sleepTime=ThreadBase::defaultSleepTime) ; ~CMeteoParamUpdaterThread() { ACS_TRACE("CMeteoParamUpdaterThread::~CMeteoParamUpdaterThread"); } virtual void onStop(); virtual void onStart(); virtual void runLoop(); private: int loopCounter_m; int m_threshold; // wind threshold in km/h MeteoSocket * m_socket; }; Loading Loading @@ -168,6 +198,7 @@ private: SmartPropertyPointer<RWdouble> m_humidity; SmartPropertyPointer<RWdouble> m_pressure; SmartPropertyPointer<RWdouble> m_windspeedPeak; CMeteoParamUpdaterThread *m_controlThread_p; SimpleParser::CParser<MeteoSocket> * m_parser; Loading
Noto/Servers/NotoWeatherStation/src/CMeteoParamUpdaterThread.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line #include "NotoWeatherStationImpl.h" CMeteoParamUpdaterThread::CMeteoParamUpdaterThread (const ACE_CString& name, MeteoSocket * socketConnectionWeatherStation, const ACS::TimeInterval& responseTime, const ACS::TimeInterval& sleepTime) : ACS::Thread(name) { ACS_TRACE("CMeteoParamUpdaterThread::CMeteoParamUpdaterThread"); loopCounter_m = 0; m_socket = (MeteoSocket *) socketConnectionWeatherStation; } void CMeteoParamUpdaterThread::runLoop() { Weather::parameters wdata; double wind; TIMEVALUE now; IRA::CIRATools::getTime(now); m_socket->updateParam(); } void CMeteoParamUpdaterThread::onStop() { AUTO_TRACE("CMeteoParamUpdaterThread::onStop()"); } void CMeteoParamUpdaterThread::onStart() { AUTO_TRACE("WindCheckerThread::onStart()"); }
Noto/Servers/NotoWeatherStation/src/Makefile +1 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ EXECUTABLES_L = # Linked with Medicina stubs because has the same interface as Noto # <brief description of xxxxx program> NotoWeatherStationImpl_OBJECTS = MeteoSocket NotoWeatherStationImpl NotoWeatherStationImpl_OBJECTS = MeteoSocket CMeteoParamUpdaterThread NotoWeatherStationImpl #xxxxx_LDFLAGS = NotoWeatherStationImpl_LIBS =ComponentErrors \ NotoWeatherStationStubs\ Loading
Noto/Servers/NotoWeatherStation/src/MeteoSocket.cpp +92 −74 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ #define MAXSIZE 255 int MeteoSocket::Depth=0; #define SIMULATOR // #define SIMULATOR Loading Loading @@ -57,6 +57,7 @@ int MeteoSocket::sendCMD(CError& err, CString cmd) int MeteoSocket:: updateParam(){ // // cout << "update param" <<endl; #ifndef SIMULATOR try{ Loading @@ -64,34 +65,53 @@ int MeteoSocket:: updateParam(){ int n_sent=0; CError err; CString rdata=""; /* connect();*/ connection(); n_sent=Send(err,WEATHERCMD,CString(WEATHERCMD).GetLength()); if ((n_sent==FAIL) || (err.isNoError()==false) ) { _EXCPT(ComponentErrors::SocketErrorExImpl,ex,"MeteoSocket::update Param()- sending cmd to Socket"); ex.log(LM_DEBUG); throw ex; } cout <<"Manda manda:" << WEATHERCMD << endl; cout << "sent:"<<n_sent << endl; ACS_DEBUG_PARAM("MeteoSocket::updateParam(CError& err, CString cmd)","sent: %s", (const char *) WEATHERCMD); /* receiveData(err,rdata);*/ int n_received,n_received_total=0; char buff[MAXSIZE]; char receivedChar=0; int i=0; CTimer timer; while (n_received_total !=100) while (n_received_total !=100 && timer.elapsed() < 5* 10000000 ) { n_received=Receive(err,&receivedChar,1); // receivedChar=buff[0]; if (i >= MAXSIZE ) // avoid pointer overflow if ((n_received==FAIL) || (err.isNoError()==false) ) { _EXCPT(ComponentErrors::SocketErrorExImpl,ex,"MeteoSocket::update Param()- receiving param from Socket"); ex.log(LM_DEBUG); throw ex; } /* if (i >= MAXSIZE ) // avoid pointer overflow { buff[i]=0; rdata=CString(buff); return n_received_total; } }*/ buff[i++]=receivedChar; Loading @@ -100,6 +120,13 @@ int MeteoSocket:: updateParam(){ } buff[n_received_total]=0; if (n_received_total !=100) { ACS_LOG(LM_FULL_INFO,"MeteoSocket::updateParm()",(LM_WARNING,"Weather Parameters Not updated ")); return 0; } Loading @@ -110,26 +137,22 @@ int MeteoSocket:: updateParam(){ ACS_DEBUG_PARAM("MeteoSocket::updateParam(CError& err, CString cmd)","received: %s", (const char *) rdata) // sendCMD(err,CString("noresp\n")); parse(buff); IRA::CIRATools::Wait(0,50000); if (err.isNoError()) return 0; else { cout <<"err:"<< err.getFullDescription()<<endl; return -1; } /* disconnect();*/ disconnection(); }catch (ComponentErrors::SocketErrorExImpl &x) { ACS_LOG(LM_FULL_INFO,"MeteoSocket:: updateParam", (LM_ERROR,"Can not connect to WeatherStation @%s:%d ", (const char *) ADDRESS,PORT)); CError error; // CError object only for Closing the Socket) if (m_isConnected==true) { Close (error); m_isConnected=false; } _THROW_EXCPT(ComponentErrors::SocketErrorExImpl,"MeteoSocket:: updateParam"); Loading Loading @@ -208,46 +231,42 @@ CError MeteoSocket::init() CError MeteoSocket::connection() throw (ACSErr::ACSbaseExImpl) void MeteoSocket::connection() throw (ACSErr::ACSbaseExImpl) { OperationResult err ; try{ err=Create(m_error,STREAM); if (err==FAIL) { m_isConnected=false; } setSockMode(m_error,BLOCKING); _EXCPT(ComponentErrors::SocketErrorExImpl,ex,"MeteoSocket::connection()- Cannot create Socket"); ex.log(LM_DEBUG); throw ex; } else { setSockMode(m_error,BLOCKINGTIMEO,2000000,2000000); err=Connect(m_error,ADDRESS,PORT); if (err==FAIL) { CError error; // CError object only for Closing the Socket) Close (error); m_isConnected=false; _EXCPT(ComponentErrors::SocketErrorExImpl,ex,"MeteoSocket::connect()- Connect to Socket"); ex.log(LM_DEBUG); throw ex; Close (error); m_isConnected=false; return m_error; /* return m_error;*/ } m_isConnected=true; // return m_error; } catch(...) { cout <<"Connect Error" << endl; return m_error; } } CError MeteoSocket::disconnection()throw (ACSErr::ACSbaseExImpl) void MeteoSocket::disconnection()throw (ACSErr::ACSbaseExImpl) { ACS_LOG(LM_FULL_INFO,"MeteoSocket::Disconnect()",(LM_INFO," disconnecting Socket")); Loading @@ -272,14 +291,14 @@ CError MeteoSocket::disconnection()throw (ACSErr::ACSbaseExImpl) } return m_error; /* return m_error;*/ } double MeteoSocket::getWindSpeed() { // if((updateParam()==-1)) cout <<"Error Reading Param"<< endl; updateParam(); //updateParam(); // m_windspeed=-99; // windspeed disabled ACS_LOG(LM_FULL_INFO,"MeteoSocket::getWindSpeed()",(LM_TRACE,"Not yet implemented")); Loading @@ -292,7 +311,6 @@ double MeteoSocket::getWindSpeed() double MeteoSocket::getWindDir() { // if((updateParam()==-1)) cout <<"Error Reading Param"<< endl; updateParam(); ACS_LOG(LM_FULL_INFO,"MeteoSocket::getWindDir()",(LM_TRACE,"Not yet implemented")); #ifdef SIMULATOR Loading @@ -307,10 +325,10 @@ double MeteoSocket::getWindDir() } double MeteoSocket::getTemperature() { /* if((updateParam()==-1)){ ACS_LOG(LM_FULL_INFO,"MeteoSocket::getTemperature()",(LM_ERROR,"Reading Temperature")); } }*/ #ifdef SIMULATOR m_temperature=7; Loading @@ -322,9 +340,9 @@ double MeteoSocket::getTemperature() } double MeteoSocket::getHumidity() { //to be impemented if((updateParam()==-1)){ ACS_LOG(LM_FULL_INFO,"MeteoSocket::getHumidity()",(LM_ERROR,"Reading Humidity")); } // if((updateParam()==-1)){ // ACS_LOG(LM_FULL_INFO,"MeteoSocket::getHumidity()",(LM_ERROR,"Reading Humidity")); // } #ifdef SIMULATOR Loading @@ -335,9 +353,9 @@ double MeteoSocket::getHumidity() { } double MeteoSocket::getPressure() { //to be impemented if((updateParam()==-1)){ /* if((updateParam()==-1)){ ACS_LOG(LM_FULL_INFO,"MeteoSocket::getPressure()",(LM_ERROR,"Reading Pressure")); } }*/ #ifdef SIMULATOR m_pressure=1024; Loading @@ -347,12 +365,12 @@ double MeteoSocket::getPressure() { } //double MeteoSocket::getWinDir() { // // to be implemented // return -99; // // //} double MeteoSocket::getWindspeedPeak() { return m_windspeedPeak; } Loading