2020-04-13 Fred Gleason <fredg@paravelsystems.com>

* Fixed a bug in the 'Software Authority' driver that caused
	autodetection of the number of GPIOs in a router to be unreliable.
	* Removed superfluous code from rdgpimon(1).
This commit is contained in:
Fred Gleason
2020-04-13 17:36:17 -04:00
parent f92e8771ce
commit e737fcbc27
4 changed files with 42 additions and 33 deletions

View File

@@ -51,6 +51,7 @@ SoftwareAuthority::SoftwareAuthority(RDMatrix *matrix,QObject *parent)
swa_gpos=0;
swa_start_cart=matrix->startCart(RDMatrix::Primary);
swa_stop_cart=matrix->stopCart(RDMatrix::Primary);
swa_is_gpio=false;
//
// Reconnection Timer
@@ -260,6 +261,11 @@ void SoftwareAuthority::DispatchCommand()
// Startup Sequence. Get initial GPIO states and the input and output lists.
//
if(section=="login successful") {
swa_inputs=0;
swa_outputs=0;
swa_gpis=0;
swa_gpos=0;
swa_is_gpio=false;
sprintf(buffer,"gpistat %d\x0D\x0A",swa_card); // Request GPI States
SendCommand(buffer);
sprintf(buffer,"gpostat %d\x0D\x0A",swa_card); // Request GPO States
@@ -299,8 +305,12 @@ void SoftwareAuthority::DispatchCommand()
// Write Sources Data
//
swa_istate=0;
if(swa_is_gpio) {
swa_gpis=swa_inputs*RD_LIVEWIRE_GPIO_BUNDLE_SIZE;
}
sql=QString("update MATRICES set ")+
QString().sprintf("INPUTS=%d ",swa_inputs)+
QString().sprintf("INPUTS=%d,",swa_inputs)+
QString().sprintf("GPIS=%d ",swa_gpis)+
"where (STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
QString().sprintf("(MATRIX=%d)",swa_matrix);
q=new RDSqlQuery(sql);
@@ -345,8 +355,12 @@ void SoftwareAuthority::DispatchCommand()
// Write Destinations Data
//
swa_istate=0;
if(swa_is_gpio) {
swa_gpos=swa_outputs*RD_LIVEWIRE_GPIO_BUNDLE_SIZE;
}
sql=QString("update MATRICES set ")+
QString().sprintf("OUTPUTS=%d ",swa_outputs)+
QString().sprintf("OUTPUTS=%d,",swa_outputs)+
QString().sprintf("GPOS=%d ",swa_gpos)+
"where (STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
QString().sprintf("(MATRIX=%d)",swa_matrix);
q=new RDSqlQuery(sql);
@@ -391,16 +405,6 @@ void SoftwareAuthority::DispatchCommand()
delete q;
q=new RDSqlQuery(sql);
delete q;
//
// Write GPIO Data
//
sql=QString("update MATRICES set ")+
QString().sprintf("GPIS=%d,GPOS=%d where ",swa_gpis,swa_gpos)+
"(STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
QString().sprintf("(MATRIX=%d)",swa_matrix);
q=new RDSqlQuery(sql);
delete q;
break;
}
@@ -411,9 +415,6 @@ void SoftwareAuthority::DispatchCommand()
if((f0.size()==4)&&(f0[0].lower()=="gpistat")&&(f0[1].toInt()==swa_card)) {
if(swa_gpi_states[f0[2].toInt()].isEmpty()) {
swa_gpi_states[f0[2].toInt()]=f0[3];
if((RD_LIVEWIRE_GPIO_BUNDLE_SIZE*f0[2].toInt())>swa_gpis) {
swa_gpis=RD_LIVEWIRE_GPIO_BUNDLE_SIZE*f0[2].toInt();
}
}
else {
for(unsigned i=0;i<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;i++) {
@@ -424,13 +425,11 @@ void SoftwareAuthority::DispatchCommand()
}
swa_gpi_states[f0[2].toInt()]=f0[3];
}
swa_is_gpio=true;
}
if((f0.size()==4)&&(f0[0].lower()=="gpostat")&&(f0[1].toInt()==swa_card)) {
if(swa_gpo_states[f0[2].toInt()].isEmpty()) {
swa_gpo_states[f0[2].toInt()]=f0[3];
if((RD_LIVEWIRE_GPIO_BUNDLE_SIZE*f0[2].toInt())>swa_gpos) {
swa_gpos=RD_LIVEWIRE_GPIO_BUNDLE_SIZE*f0[2].toInt();
}
}
else {
for(unsigned i=0;i<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;i++) {
@@ -441,6 +440,7 @@ void SoftwareAuthority::DispatchCommand()
}
swa_gpo_states[f0[2].toInt()]=f0[3];
}
swa_is_gpio=true;
}
}