2017-08-13 Fred Gleason <fredg@paravelsystems.com>

* Refactored the WheatNet LIO driver to use event subscription.
This commit is contained in:
Fred Gleason
2017-08-13 08:48:16 -04:00
parent b548f6264b
commit 2e3a2d5d1b
3 changed files with 32 additions and 23 deletions

View File

@@ -15933,3 +15933,5 @@
* Implemented a driver for WheatNet SLIO devices. * Implemented a driver for WheatNet SLIO devices.
2017-08-12 Fred Gleason <fredg@paravelsystems.com> 2017-08-12 Fred Gleason <fredg@paravelsystems.com>
* Implemented a driver for WheatNet LIO devices. * Implemented a driver for WheatNet LIO devices.
2017-08-13 Fred Gleason <fredg@paravelsystems.com>
* Refactored the WheatNet LIO driver to use event subscription.

View File

@@ -42,7 +42,7 @@ WheatnetLio::WheatnetLio(RDMatrix *matrix,QObject *parent)
lio_socket->connectToHost(lio_ip_address.toString(),lio_ip_port); lio_socket->connectToHost(lio_ip_address.toString(),lio_ip_port);
lio_poll_timer=new QTimer(this); 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); lio_reset_mapper=new QSignalMapper(this);
connect(lio_reset_mapper,SIGNAL(mapped(int)), connect(lio_reset_mapper,SIGNAL(mapped(int)),
@@ -211,14 +211,6 @@ void WheatnetLio::errorData(int err)
} }
void WheatnetLio::pollInputs()
{
for(int i=0;i<lio_gpios;i++) {
SendCommand(QString().sprintf("<LIO:%d?LVL>",i));
}
}
void WheatnetLio::resetStateData(int line) void WheatnetLio::resetStateData(int line)
{ {
SendCommand(QString().sprintf("<LIO:%d|LVL:%d>",line, SendCommand(QString().sprintf("<LIO:%d|LVL:%d>",line,
@@ -227,6 +219,12 @@ void WheatnetLio::resetStateData(int line)
} }
void WheatnetLio::pollData()
{
SendCommand("<SYS?BLID>");
}
void WheatnetLio::watchdogData() void WheatnetLio::watchdogData()
{ {
if(!lio_watchdog_active) { if(!lio_watchdog_active) {
@@ -303,6 +301,7 @@ void WheatnetLio::ProcessSys(const QString &cmd)
lio_reset_states.push_back(false); lio_reset_states.push_back(false);
lio_gpi_states.push_back(false); lio_gpi_states.push_back(false);
CheckLineEntry(i+1); CheckLineEntry(i+1);
SendCommand(QString().sprintf("<LIOSUB:0.%d|LVL:1>",i));
} }
sql=QString("update MATRICES set ")+ sql=QString("update MATRICES set ")+
QString().sprintf("GPIS=%d,GPOS=%d where ",lio_gpios,lio_gpios)+ 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()); QString().sprintf("(MATRIX=%d)",matrixNumber());
q=new RDSqlQuery(sql); q=new RDSqlQuery(sql);
delete q; 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); QStringList f0=f0.split(":",cmd);
if((f0[0]=="LVL")&&(f0.size()==2)) { if((f0[0]=="LVL")&&(f0.size()==2)) {
if(chan<(int)lio_gpi_states.size()) { if(chan<(int)lio_gpi_states.size()) {
@@ -330,12 +335,11 @@ void WheatnetLio::ProcessLio(int chan,QString &cmd)
} }
else { else {
syslog(LOG_WARNING, 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(), (const char *)lio_ip_address.toString(),
lio_ip_port,(const char *)cmd); lio_ip_port,(const char *)cmd);
} }
if((chan+1)==lio_gpios) { if((chan+1)==lio_gpios) {
lio_poll_timer->start(50,true);
lio_watchdog_timer->stop(); lio_watchdog_timer->stop();
lio_watchdog_timer->start(1000,true); lio_watchdog_timer->start(1000,true);
} }
@@ -355,10 +359,13 @@ void WheatnetLio::ProcessCommand(const QString &cmd)
if(f1[0]=="SYS") { if(f1[0]=="SYS") {
ProcessSys(f0[1]); ProcessSys(f0[1]);
} }
if((f1[0]=="LIO")&&(f1.size()==2)) { if((f1[0]=="LIOEVENT")&&(f1.size()==2)) {
int chan=f1[1].toUInt(&ok); QStringList f2=f2.split(".",f1[1]);
if(ok) { if((f2[0]=="0")&&(f2.size()==2)) {
ProcessLio(chan,f0[1]); int chan=f2[1].toUInt(&ok);
if(ok) {
ProcessLioevent(chan,f0[1]);
}
} }
} }
} }

View File

@@ -33,8 +33,8 @@
#include <switcher.h> #include <switcher.h>
#define WHEATNET_LIO_POLL_INTERVAL 100 #define WHEATNET_LIO_POLL_INTERVAL 1000
#define WHEATNET_LIO_WATCHDOG_INTERVAL 1000 #define WHEATNET_LIO_WATCHDOG_INTERVAL 5000
class WheatnetLio : public Switcher class WheatnetLio : public Switcher
{ {
@@ -53,18 +53,17 @@ class WheatnetLio : public Switcher
void connectedData(); void connectedData();
void readyReadData(); void readyReadData();
void errorData(int err); void errorData(int err);
void pollInputs();
void resetStateData(int line); void resetStateData(int line);
void pollData();
void watchdogData(); void watchdogData();
private: private:
void CheckLineEntry(int line); void CheckLineEntry(int line);
void ProcessSys(const QString &cmd); void ProcessSys(const QString &cmd);
void ProcessLio(int chan,QString &cmd); void ProcessLioevent(int chan,QString &cmd);
void ProcessCommand(const QString &cmd); void ProcessCommand(const QString &cmd);
void SendCommand(const QString &cmd); void SendCommand(const QString &cmd);
QSocket *lio_socket; QSocket *lio_socket;
QTimer *lio_poll_timer;
QTimer *lio_watchdog_timer; QTimer *lio_watchdog_timer;
bool lio_watchdog_active; bool lio_watchdog_active;
QHostAddress lio_ip_address; QHostAddress lio_ip_address;
@@ -76,6 +75,7 @@ class WheatnetLio : public Switcher
QSignalMapper *lio_reset_mapper; QSignalMapper *lio_reset_mapper;
std::vector<QTimer *> lio_reset_timers; std::vector<QTimer *> lio_reset_timers;
std::vector<bool> lio_reset_states; std::vector<bool> lio_reset_states;
QTimer *lio_poll_timer;
}; };