From e737fcbc27c35c456c995fdf15a717b5046fc882 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Mon, 13 Apr 2020 17:36:17 -0400 Subject: [PATCH] 2020-04-13 Fred Gleason * 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). --- ChangeLog | 4 ++++ ripcd/swauthority.cpp | 36 ++++++++++++++++++------------------ ripcd/swauthority.h | 1 + utils/rdgpimon/rdgpimon.cpp | 34 +++++++++++++++++++--------------- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index fbd050b0..d05150aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 + * 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). diff --git a/ripcd/swauthority.cpp b/ripcd/swauthority.cpp index 8c1b0bf4..e1d99139 100644 --- a/ripcd/swauthority.cpp +++ b/ripcd/swauthority.cpp @@ -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;iswa_gpos) { - swa_gpos=RD_LIVEWIRE_GPIO_BUNDLE_SIZE*f0[2].toInt(); - } } else { for(unsigned i=0;i swa_gpi_states; std::map swa_gpo_states; diff --git a/utils/rdgpimon/rdgpimon.cpp b/utils/rdgpimon/rdgpimon.cpp index 0258cc01..7364a075 100644 --- a/utils/rdgpimon/rdgpimon.cpp +++ b/utils/rdgpimon/rdgpimon.cpp @@ -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)value(0).toInt()) { + gpi_labels[i]->setLine(i+first_line); + gpi_labels[i]->show(); + } + } + } + delete q; + RefreshGpioStates(); }