2018-02-01 Fred Gleason <fredg@paravelsystems.com>

* Converted rdgpimon(1) to use RDApplication.
This commit is contained in:
Fred Gleason
2018-01-31 18:39:38 -05:00
parent a8b2ac6cd6
commit a5309b2448
10 changed files with 123 additions and 139 deletions

View File

@@ -2,7 +2,7 @@
//
// A Qt-based application for testing General Purpose Input (GPI) devices.
//
// (C) Copyright 2002-2014,2016 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2014,2016-2018 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@@ -33,14 +33,14 @@
#include <qtextcodec.h>
#include <qtranslator.h>
#include <rdapplication.h>
#include <rddb.h>
#include <rdgpimon.h>
#include <rdcmd_switch.h>
#include <rddbheartbeat.h>
#include <rdescape_string.h>
#include <rdlistviewitem.h>
#include <rdtextfile.h>
#include "rdgpimon.h"
//
// Icons
//
@@ -49,13 +49,30 @@
MainWidget::MainWidget(QWidget *parent)
:QWidget(parent)
{
QString err_msg;
gpi_scroll_mode=false;
//
// Open the Database
//
rda=new RDApplication("RDGpiMon","rdgpimon",RDGPIMON_USAGE,this);
if(!rda->open(&err_msg)) {
QMessageBox::critical(this,"RDGpiMon - "+tr("Error"),err_msg);
exit(1);
}
//
// Read Command Options
//
RDCmdSwitch *cmd=new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdgpimon","\n");
delete cmd;
for(unsigned i=0;i<rda->cmdSwitch()->keys();i++) {
if(!rda->cmdSwitch()->processed(i)) {
QMessageBox::critical(this,"RDGpiMon - "+tr("Error"),
tr("Unknown command option")+": "+
rda->cmdSwitch()->key(i));
exit(2);
}
}
//
// Set Window Size
@@ -84,58 +101,24 @@ MainWidget::MainWidget(QWidget *parent)
gpi_rivendell_map=new QPixmap(rivendell_22x22_xpm);
setIcon(*gpi_rivendell_map);
//
// Load Local Configs
//
gpi_config=new RDConfig();
gpi_config->load();
gpi_config->setModuleName("RDGpiMon");
//
// Open Database
//
gpi_db=QSqlDatabase::addDatabase(gpi_config->mysqlDriver());
if(!gpi_db) {
QMessageBox::warning(this,tr("Database Error"),
tr("Can't Connect","Unable to connect to mySQL Server!"));
exit(0);
}
gpi_db->setDatabaseName(gpi_config->mysqlDbname());
gpi_db->setUserName(gpi_config->mysqlUsername());
gpi_db->setPassword(gpi_config->mysqlPassword());
gpi_db->setHostName(gpi_config->mysqlHostname());
if(!gpi_db->open()) {
QMessageBox::warning(this,tr("Can't Connect"),
tr("Unable to connect to mySQL Server!"));
gpi_db->removeDatabase(gpi_config->mysqlDbname());
exit(0);
}
new RDDbHeartbeat(gpi_config->mysqlHeartbeatInterval(),this);
//
// RDStation
//
gpi_station=new RDStation(gpi_config->stationName());
//
// RIPC Connection
//
gpi_ripc=new RDRipc(gpi_station,gpi_config,this);
gpi_ripc->setIgnoreMask(true);
connect(gpi_ripc,SIGNAL(userChanged()),this,SLOT(userData()));
connect(gpi_ripc,SIGNAL(gpiStateChanged(int,int,bool)),
rda->ripc()->setIgnoreMask(true);
connect(rda,SIGNAL(userChanged()),this,SLOT(userData()));
connect(rda->ripc(),SIGNAL(gpiStateChanged(int,int,bool)),
this,SLOT(gpiStateChangedData(int,int,bool)));
connect(gpi_ripc,SIGNAL(gpoStateChanged(int,int,bool)),
connect(rda->ripc(),SIGNAL(gpoStateChanged(int,int,bool)),
this,SLOT(gpoStateChangedData(int,int,bool)));
connect(gpi_ripc,SIGNAL(gpiMaskChanged(int,int,bool)),
connect(rda->ripc(),SIGNAL(gpiMaskChanged(int,int,bool)),
this,SLOT(gpiMaskChangedData(int,int,bool)));
connect(gpi_ripc,SIGNAL(gpoMaskChanged(int,int,bool)),
connect(rda->ripc(),SIGNAL(gpoMaskChanged(int,int,bool)),
this,SLOT(gpoMaskChangedData(int,int,bool)));
connect(gpi_ripc,SIGNAL(gpiCartChanged(int,int,int,int)),
connect(rda->ripc(),SIGNAL(gpiCartChanged(int,int,int,int)),
this,SLOT(gpiCartChangedData(int,int,int,int)));
connect(gpi_ripc,SIGNAL(gpoCartChanged(int,int,int,int)),
connect(rda->ripc(),SIGNAL(gpoCartChanged(int,int,int,int)),
this,SLOT(gpoCartChangedData(int,int,int,int)));
gpi_ripc->connectHost("localhost",RIPCD_TCP_PORT,gpi_config->password());
rda->ripc()->connectHost("localhost",RIPCD_TCP_PORT,rda->config()->password());
//
// RDMatrix;
@@ -326,7 +309,7 @@ void MainWidget::userData()
QString str;
str=QString("RDGpiMon")+" v"+VERSION+" - "+tr("User")+":";
setCaption(str+" "+gpi_ripc->user());
setCaption(str+" "+rda->ripc()->user());
}
@@ -341,20 +324,20 @@ void MainWidget::matrixActivatedData(int index)
delete gpi_matrix;
}
gpi_matrix=
new RDMatrix(gpi_config->stationName(),gpi_matrix_box->currentItem());
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:
gpi_ripc->sendGpiStatus(gpi_matrix_box->currentItem());
gpi_ripc->sendGpiMask(gpi_matrix_box->currentItem());
gpi_ripc->sendGpiCart(gpi_matrix_box->currentItem());
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:
gpi_ripc->sendGpoStatus(gpi_matrix_box->currentItem());
gpi_ripc->sendGpoMask(gpi_matrix_box->currentItem());
gpi_ripc->sendGpoCart(gpi_matrix_box->currentItem());
rda->ripc()->sendGpoStatus(gpi_matrix_box->currentItem());
rda->ripc()->sendGpoMask(gpi_matrix_box->currentItem());
rda->ripc()->sendGpoCart(gpi_matrix_box->currentItem());
break;
}
RefreshEventsList();
@@ -404,13 +387,13 @@ void MainWidget::eventsReportData()
report=" Rivendell GPIO Event Report\n";
report+=" Date: "+gpi_events_date_edit->date().toString("MM/dd/yyyy")+
" Station/Matrix: "+gpi_station->name()+":"+
" Station/Matrix: "+rda->station()->name()+":"+
QString().sprintf("%d ",gpi_matrix_box->currentItem())+
" State Filter: "+gpi_events_state_box->currentText()+"\n";
report+="\n";
sql=QString("select EVENT_DATETIME,NUMBER,EDGE from GPIO_EVENTS where ")+
"(STATION_NAME=\""+RDEscapeString(gpi_station->name())+"\")&&"+
"(STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
QString().sprintf("(MATRIX=%d)&&",gpi_matrix_box->currentItem())+
QString().sprintf("(TYPE=%d)&&",gpi_type_box->currentItem())+
"(EVENT_DATETIME>=\""+gpi_events_date_edit->date().toString("yyyy-MM-dd")+
@@ -614,7 +597,7 @@ void MainWidget::UpdateLabelsUp(int last_line)
(MATRIX=%d)&&\
(NUMBER<=%d) order by NUMBER desc",
(const char *)tablename,
(const char *)gpi_station->name(),
(const char *)rda->station()->name(),
gpi_matrix->matrix(),last_line);
q=new RDSqlQuery(sql);
if(q->size()<count_limit) {
@@ -662,7 +645,7 @@ void MainWidget::UpdateLabelsDown(int first_line)
(MATRIX=%d)&&\
(NUMBER>=%d) order by NUMBER",
(const char *)tablename,
(const char *)gpi_station->name(),
(const char *)rda->station()->name(),
gpi_matrix->matrix(),first_line);
q=new RDSqlQuery(sql);
while(q->next()&&(count<(GPIMON_ROWS*GPIMON_COLS))) {
@@ -687,7 +670,7 @@ void MainWidget::RefreshEventsList()
RDSqlQuery *q;
sql=QString("select EVENT_DATETIME,NUMBER,EDGE from GPIO_EVENTS where ")+
"(STATION_NAME=\""+RDEscapeString(gpi_station->name())+"\")&&"+
"(STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
QString().sprintf("(MATRIX=%d)&&",gpi_matrix_box->currentItem())+
QString().sprintf("(TYPE=%d)&&",gpi_type_box->currentItem())+
"(EVENT_DATETIME>=\""+gpi_events_date_edit->date().toString("yyyy-MM-dd")+

View File

@@ -2,7 +2,7 @@
//
// A Qt-based application for testing general purpose input (GPI) devices.
//
// (C) Copyright 2002-2005,2016 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2005,2016-2018 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@@ -37,16 +37,14 @@
#include <rdlistview.h>
#include <rdmatrix.h>
#include <rdconfig.h>
#include <rdripc.h>
#include <rdstation.h>
#include <rdtransportbutton.h>
#include <gpi_label.h>
#include "gpi_label.h"
#define GPIMON_START_UP_DELAY 100
#define GPIMON_ROWS 4
#define GPIMON_COLS 8
#define RDGPIMON_USAGE "\n"
class MainWidget : public QWidget
{
@@ -81,10 +79,6 @@ class MainWidget : public QWidget
void UpdateLabelsDown(int first_line);
void RefreshEventsList();
void AddEventsItem(int line,bool state);
RDConfig *gpi_config;
QSqlDatabase *gpi_db;
RDRipc *gpi_ripc;
RDStation *gpi_station;
RDMatrix *gpi_matrix;
QComboBox *gpi_type_box;
QComboBox *gpi_matrix_box;
@@ -107,4 +101,4 @@ class MainWidget : public QWidget
};
#endif // MAIN_WIDGET_H
#endif // RDGPIMON_H

View File

@@ -1,23 +1,6 @@
<!DOCTYPE TS><TS>
<context>
<name>MainWidget</name>
<message>
<source>Database Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<comment>Unable to connect to mySQL Server!</comment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to connect to mySQL Server!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>GPI (Inputs)</source>
<translation type="unfinished"></translation>
@@ -90,5 +73,13 @@
<source>OFF</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@@ -3,20 +3,20 @@
<name>MainWidget</name>
<message>
<source>Database Error</source>
<translation>Datenbankfehler</translation>
<translation type="obsolete">Datenbankfehler</translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<comment>Unable to connect to mySQL Server!</comment>
<translation>Kann keine Verbindung zum mySQL-Server herstellen</translation>
<translation type="obsolete">Kann keine Verbindung zum mySQL-Server herstellen</translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<translation>Kann keine Verbindung herstellen</translation>
<translation type="obsolete">Kann keine Verbindung herstellen</translation>
</message>
<message>
<source>Unable to connect to mySQL Server!</source>
<translation>Kann keine Verbindung zum mySQL-Server herstellen!</translation>
<translation type="obsolete">Kann keine Verbindung zum mySQL-Server herstellen!</translation>
</message>
<message>
<source>Matrix:</source>
@@ -98,5 +98,13 @@
<source>OFF</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@@ -3,20 +3,20 @@
<name>MainWidget</name>
<message>
<source>Database Error</source>
<translation>Error de base de datos</translation>
<translation type="obsolete">Error de base de datos</translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<comment>Unable to connect to mySQL Server!</comment>
<translation>No puedo conectarme</translation>
<translation type="obsolete">No puedo conectarme</translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<translation>No puedo conectarme</translation>
<translation type="obsolete">No puedo conectarme</translation>
</message>
<message>
<source>Unable to connect to mySQL Server!</source>
<translation>¡No puedo conectarme al servidor MySQL!</translation>
<translation type="obsolete">¡No puedo conectarme al servidor MySQL!</translation>
</message>
<message>
<source>Matrix:</source>
@@ -98,5 +98,13 @@
<source>OFF</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@@ -1,23 +1,6 @@
<!DOCTYPE TS><TS>
<context>
<name>MainWidget</name>
<message>
<source>Database Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<comment>Unable to connect to mySQL Server!</comment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to connect to mySQL Server!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Matrix:</source>
<translation type="unfinished"></translation>
@@ -90,5 +73,13 @@
<source>OFF</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@@ -3,20 +3,20 @@
<name>MainWidget</name>
<message>
<source>Database Error</source>
<translation>Databasefeil</translation>
<translation type="obsolete">Databasefeil</translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<comment>Unable to connect to mySQL Server!</comment>
<translation>Kan ikkje kopla til</translation>
<translation type="obsolete">Kan ikkje kopla til</translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<translation>Kan ikkje kopla til</translation>
<translation type="obsolete">Kan ikkje kopla til</translation>
</message>
<message>
<source>Unable to connect to mySQL Server!</source>
<translation>Greier ikkje kopla til mySQL-tenaren!</translation>
<translation type="obsolete">Greier ikkje kopla til mySQL-tenaren!</translation>
</message>
<message>
<source>Matrix:</source>
@@ -98,5 +98,13 @@
<source>OFF</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@@ -3,20 +3,20 @@
<name>MainWidget</name>
<message>
<source>Database Error</source>
<translation>Databasefeil</translation>
<translation type="obsolete">Databasefeil</translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<comment>Unable to connect to mySQL Server!</comment>
<translation>Kan ikkje kopla til</translation>
<translation type="obsolete">Kan ikkje kopla til</translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<translation>Kan ikkje kopla til</translation>
<translation type="obsolete">Kan ikkje kopla til</translation>
</message>
<message>
<source>Unable to connect to mySQL Server!</source>
<translation>Greier ikkje kopla til mySQL-tenaren!</translation>
<translation type="obsolete">Greier ikkje kopla til mySQL-tenaren!</translation>
</message>
<message>
<source>Matrix:</source>
@@ -98,5 +98,13 @@
<source>OFF</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@@ -1,23 +1,6 @@
<!DOCTYPE TS><TS>
<context>
<name>MainWidget</name>
<message>
<source>Database Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<comment>Unable to connect to mySQL Server!</comment>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t Connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to connect to mySQL Server!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>GPI (Inputs)</source>
<translation type="unfinished"></translation>
@@ -90,5 +73,13 @@
<source>OFF</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>