Rivendellaudio/ripcd/switcher.cpp
Fred Gleason ac4d9305bc 2019-06-25 Fred Gleason <fredg@paravelsystems.com>
* Adjusted to priority of 'operations' system events to use
	LOG_INFO priority.
2019-06-25 15:08:12 -04:00

111 lines
2.3 KiB
C++

// switcher.cpp
//
// Abstract base class for Rivendell Switcher/GPIO drivers.
//
// (C) Copyright 2002-2019 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
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <syslog.h>
#include <rdapplication.h>
#include <rddb.h>
#include <rdescape_string.h>
#include <switcher.h>
#include <globals.h>
Switcher::Switcher(RDMatrix *matrix,QObject *parent)
: QObject(parent)
{
switcher_station_name=matrix->station();
switcher_matrix_number=matrix->matrix();
}
Switcher::~Switcher()
{
}
QString Switcher::stationName() const
{
return switcher_station_name;
}
int Switcher::matrixNumber() const
{
return switcher_matrix_number;
}
void Switcher::sendGpi()
{
}
void Switcher::sendGpo()
{
}
void Switcher::executeMacroCart(unsigned cartnum)
{
RDMacro rml;
rml.setRole(RDMacro::Cmd);
rml.setCommand(RDMacro::EX);
rml.setAddress(rda->station()->address());
rml.setEchoRequested(false);
rml.addArg(cartnum);
emit rmlEcho(&rml);
}
void Switcher::logBytes(uint8_t *data,int len)
{
QString str;
for(int i=0;i<len;i++) {
str+=QString().sprintf("%02X ",0xff&data[i]);
}
rda->syslog(LOG_INFO,"bytes: %s",(const char *)str);
}
void Switcher::insertGpioEntry(bool is_gpo,int line)
{
QString sql;
RDSqlQuery *q;
QString table="GPIS";
if(is_gpo) {
table="GPOS";
}
sql="select ID from "+table+" where (STATION_NAME=\""+
RDEscapeString(stationName())+"\")&&"+
QString().sprintf("(MATRIX=%u)&&(NUMBER=%d)",matrixNumber(),line);
q=new RDSqlQuery(sql);
if(!q->first()) {
delete q;
sql="insert into "+table+" set STATION_NAME=\""+
RDEscapeString(stationName())+"\","+
QString().sprintf("MATRIX=%u,NUMBER=%d",matrixNumber(),line);
q=new RDSqlQuery(sql);
}
delete q;
}