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

@ -19782,3 +19782,7 @@
* Fixed a bug in the 'List GPIs' dialog in rdadmin(1) that
prevented changes in GPI assignments from being propagated
to the underlying device.
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).

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;
}
}

View File

@ -79,6 +79,7 @@ class SoftwareAuthority : public Switcher
unsigned swa_start_cart;
unsigned swa_stop_cart;
int swa_istate;
bool swa_is_gpio;
RDMatrix::PortType swa_porttype;
std::map<int,QString> swa_gpi_states;
std::map<int,QString> swa_gpo_states;

View File

@ -298,19 +298,6 @@ void MainWidget::matrixActivatedData(int index)
new RDMatrix(rda->config()->stationName(),gpi_matrix_box->currentItem());
UpdateLabelsDown(0);
gpi_up_button->setDisabled(true);
switch((RDMatrix::GpioType)gpi_type_box->currentItem()) {
case RDMatrix::GpioInput:
rda->ripc()->sendGpiStatus(gpi_matrix_box->currentItem());
rda->ripc()->sendGpiMask(gpi_matrix_box->currentItem());
rda->ripc()->sendGpiCart(gpi_matrix_box->currentItem());
break;
case RDMatrix::GpioOutput:
rda->ripc()->sendGpoStatus(gpi_matrix_box->currentItem());
rda->ripc()->sendGpoMask(gpi_matrix_box->currentItem());
rda->ripc()->sendGpoCart(gpi_matrix_box->currentItem());
break;
}
RefreshEventsList();
gpi_events_startup_timer->start(1000,true);
}
@ -459,6 +446,7 @@ void MainWidget::gpiMaskChangedData(int matrix,int line,bool state)
void MainWidget::gpoMaskChangedData(int matrix,int line,bool state)
{
// printf("gpoMaskChangedData(%d,%d,%d)\n",matrix,line,state);
if(gpi_type_box->currentItem()!=RDMatrix::GpioOutput) {
return;
}
@ -502,6 +490,8 @@ void MainWidget::gpiCartChangedData(int matrix,int line,int off_cartnum,
void MainWidget::gpoCartChangedData(int matrix,int line,int off_cartnum,
int on_cartnum)
{
// printf("gpoCartChangedData(%d,%d,%d,%d)\n",matrix,line,off_cartnum,
// on_cartnum);
if(gpi_type_box->currentItem()!=RDMatrix::GpioOutput) {
return;
}
@ -633,9 +623,7 @@ void MainWidget::UpdateLabelsDown(int first_line)
"order by NUMBER";
q=new RDSqlQuery(sql);
while(q->next()&&(count<(GPIMON_ROWS*GPIMON_COLS))) {
gpi_labels[count]->setLine(q->value(0).toInt()-1);
gpi_labels[count]->setCart(q->value(1).toUInt(),q->value(2).toUInt());
gpi_labels[count]->show();
if(!first_updated) {
gpi_first_line=q->value(0).toInt();
first_updated=true;
@ -646,6 +634,22 @@ void MainWidget::UpdateLabelsDown(int first_line)
gpi_down_button->setEnabled(q->next());
delete q;
sql=QString("select ")+
tablename+" "+ // 00
"from MATRICES where "+
"(STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\") && "+
QString().sprintf("(MATRIX=%d)",gpi_matrix->matrix());
q=new RDSqlQuery(sql);
if(q->first()) {
for(int i=0;i<(GPIMON_ROWS*GPIMON_COLS);i++) {
if((i+first_line)<q->value(0).toInt()) {
gpi_labels[i]->setLine(i+first_line);
gpi_labels[i]->show();
}
}
}
delete q;
RefreshGpioStates();
}