From 2e3a2d5d1b6bcbe611fd94dd5e2d9bfc64881275 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Sun, 13 Aug 2017 08:48:16 -0400 Subject: [PATCH] 2017-08-13 Fred Gleason * Refactored the WheatNet LIO driver to use event subscription. --- ChangeLog | 2 ++ ripcd/wheatnet_lio.cpp | 43 ++++++++++++++++++++++++------------------ ripcd/wheatnet_lio.h | 10 +++++----- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea859f0f..09f6f0a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15933,3 +15933,5 @@ * Implemented a driver for WheatNet SLIO devices. 2017-08-12 Fred Gleason * Implemented a driver for WheatNet LIO devices. +2017-08-13 Fred Gleason + * Refactored the WheatNet LIO driver to use event subscription. diff --git a/ripcd/wheatnet_lio.cpp b/ripcd/wheatnet_lio.cpp index 3f297a61..75415061 100644 --- a/ripcd/wheatnet_lio.cpp +++ b/ripcd/wheatnet_lio.cpp @@ -42,7 +42,7 @@ WheatnetLio::WheatnetLio(RDMatrix *matrix,QObject *parent) lio_socket->connectToHost(lio_ip_address.toString(),lio_ip_port); lio_poll_timer=new QTimer(this); - connect(lio_poll_timer,SIGNAL(timeout()),this,SLOT(pollInputs())); + connect(lio_poll_timer,SIGNAL(timeout()),this,SLOT(pollData())); lio_reset_mapper=new QSignalMapper(this); connect(lio_reset_mapper,SIGNAL(mapped(int)), @@ -211,14 +211,6 @@ void WheatnetLio::errorData(int err) } -void WheatnetLio::pollInputs() -{ - for(int i=0;i",i)); - } -} - - void WheatnetLio::resetStateData(int line) { SendCommand(QString().sprintf("",line, @@ -227,6 +219,12 @@ void WheatnetLio::resetStateData(int line) } +void WheatnetLio::pollData() +{ + SendCommand(""); +} + + void WheatnetLio::watchdogData() { if(!lio_watchdog_active) { @@ -303,6 +301,7 @@ void WheatnetLio::ProcessSys(const QString &cmd) lio_reset_states.push_back(false); lio_gpi_states.push_back(false); CheckLineEntry(i+1); + SendCommand(QString().sprintf("",i)); } sql=QString("update MATRICES set ")+ QString().sprintf("GPIS=%d,GPOS=%d where ",lio_gpios,lio_gpios)+ @@ -310,15 +309,21 @@ void WheatnetLio::ProcessSys(const QString &cmd) QString().sprintf("(MATRIX=%d)",matrixNumber()); q=new RDSqlQuery(sql); delete q; - pollInputs(); + lio_watchdog_timer->start(WHEATNET_LIO_WATCHDOG_INTERVAL,true); + lio_poll_timer->start(WHEATNET_LIO_POLL_INTERVAL,true); } } + if((f0[0]=="BLID")&&(f0.size()==2)) { + lio_watchdog_timer->stop(); + lio_watchdog_timer->start(WHEATNET_LIO_WATCHDOG_INTERVAL,true); + lio_poll_timer->start(WHEATNET_LIO_POLL_INTERVAL,true); + } } -void WheatnetLio::ProcessLio(int chan,QString &cmd) +void WheatnetLio::ProcessLioevent(int chan,QString &cmd) { - // printf("ProcessSlip(%d,%s)\n",chan,(const char *)cmd); + // printf("ProcessLioevent(%d,%s)\n",chan,(const char *)cmd); QStringList f0=f0.split(":",cmd); if((f0[0]=="LVL")&&(f0.size()==2)) { if(chan<(int)lio_gpi_states.size()) { @@ -330,12 +335,11 @@ void WheatnetLio::ProcessLio(int chan,QString &cmd) } else { syslog(LOG_WARNING, - "WheatNet device at %s:%d sent invalid LIO LVL update [%s]", + "WheatNet device at %s:%d sent invalid LIOEVENT LVL update [%s]", (const char *)lio_ip_address.toString(), lio_ip_port,(const char *)cmd); } if((chan+1)==lio_gpios) { - lio_poll_timer->start(50,true); lio_watchdog_timer->stop(); lio_watchdog_timer->start(1000,true); } @@ -355,10 +359,13 @@ void WheatnetLio::ProcessCommand(const QString &cmd) if(f1[0]=="SYS") { ProcessSys(f0[1]); } - if((f1[0]=="LIO")&&(f1.size()==2)) { - int chan=f1[1].toUInt(&ok); - if(ok) { - ProcessLio(chan,f0[1]); + if((f1[0]=="LIOEVENT")&&(f1.size()==2)) { + QStringList f2=f2.split(".",f1[1]); + if((f2[0]=="0")&&(f2.size()==2)) { + int chan=f2[1].toUInt(&ok); + if(ok) { + ProcessLioevent(chan,f0[1]); + } } } } diff --git a/ripcd/wheatnet_lio.h b/ripcd/wheatnet_lio.h index e1fd5a04..91cd6e4b 100644 --- a/ripcd/wheatnet_lio.h +++ b/ripcd/wheatnet_lio.h @@ -33,8 +33,8 @@ #include -#define WHEATNET_LIO_POLL_INTERVAL 100 -#define WHEATNET_LIO_WATCHDOG_INTERVAL 1000 +#define WHEATNET_LIO_POLL_INTERVAL 1000 +#define WHEATNET_LIO_WATCHDOG_INTERVAL 5000 class WheatnetLio : public Switcher { @@ -53,18 +53,17 @@ class WheatnetLio : public Switcher void connectedData(); void readyReadData(); void errorData(int err); - void pollInputs(); void resetStateData(int line); + void pollData(); void watchdogData(); private: void CheckLineEntry(int line); void ProcessSys(const QString &cmd); - void ProcessLio(int chan,QString &cmd); + void ProcessLioevent(int chan,QString &cmd); void ProcessCommand(const QString &cmd); void SendCommand(const QString &cmd); QSocket *lio_socket; - QTimer *lio_poll_timer; QTimer *lio_watchdog_timer; bool lio_watchdog_active; QHostAddress lio_ip_address; @@ -76,6 +75,7 @@ class WheatnetLio : public Switcher QSignalMapper *lio_reset_mapper; std::vector lio_reset_timers; std::vector lio_reset_states; + QTimer *lio_poll_timer; };