2015-02-22 Fred Gleason <fredg@paravelsystems.com>

* Fixed a bug in 'lib/rdlivewire.cpp' that caused long LWRP
	messages to be truncated.
	* Refactored parser code in 'lib/rdlivewire.cpp' for greater
	robustness.
	* Fixed a bug in 'rdadmin/view_node_info.cpp' that caused
	slots to be sorted in incorrect order.
	* Renamed the 'STREAMING' column to 'ACTIVE' in
	'rdadmin/view_node_info.cpp'.
This commit is contained in:
Fred Gleason 2015-02-22 21:20:32 -05:00
parent 741dc183da
commit 482aebf204
5 changed files with 235 additions and 215 deletions

View File

@ -14780,3 +14780,12 @@
* Fixed a regression in 'rdairplay/log_play.cpp' that caused
the 'Play Tail' button to start from an incorrect position when
non-zero Start Marker position was set for the cut.
2015-02-22 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in 'lib/rdlivewire.cpp' that caused long LWRP
messages to be truncated.
* Refactored parser code in 'lib/rdlivewire.cpp' for greater
robustness.
* Fixed a bug in 'rdadmin/view_node_info.cpp' that caused
slots to be sorted in incorrect order.
* Renamed the 'STREAMING' column to 'ACTIVE' in
'rdadmin/view_node_info.cpp'.

View File

@ -30,6 +30,49 @@
#include <rd.h>
#include <rdlivewire.h>
AString::AString()
: QString()
{
}
AString::AString(const AString &lhs)
: QString(lhs)
{
}
AString::AString(const QString &lhs)
: QString(lhs)
{
}
QStringList AString::split(const QString &sep,const QString &esc) const
{
if(esc.isEmpty()) {
return QStringList::split(sep,*this);
}
QStringList list;
bool escape=false;
QChar e=esc.at(0);
list.push_back(QString());
for(unsigned i=0;i<length();i++) {
if(at(i)==e) {
escape=!escape;
}
else {
if((!escape)&&(mid(i,1)==sep)) {
list.push_back(QString());
}
else {
list.back()+=at(i);
}
}
}
return list;
}
RDLiveWire::RDLiveWire(unsigned id,QObject *parent,const char *name)
: QObject(parent,name)
@ -344,22 +387,25 @@ void RDLiveWire::readyReadData()
{
char buf[RD_LIVEWIRE_MAX_CMD_LENGTH];
int n=live_socket->readBlock(buf,RD_LIVEWIRE_MAX_CMD_LENGTH);
buf[n]=0;
for(int i=0;i<n;i++) {
if(buf[i]=='\n') {
live_buf[live_ptr]=0;
DespatchCommand(live_buf);
live_ptr=0;
}
else {
if(buf[i]!='\r') {
live_buf[live_ptr++]=buf[i];
int n;
while((n=live_socket->readBlock(buf,RD_LIVEWIRE_MAX_CMD_LENGTH))>0) {
buf[n]=0;
for(int i=0;i<n;i++) {
if(buf[i]=='\n') {
live_buf[live_ptr]=0;
DespatchCommand(live_buf);
live_ptr=0;
}
else {
if(buf[i]!='\r') {
live_buf[live_ptr++]=buf[i];
}
}
if(live_ptr>=RD_LIVEWIRE_MAX_CMD_LENGTH) {
fprintf(stderr,"LiveWire: status string truncated");
live_ptr=0;
}
}
if(live_ptr>=RD_LIVEWIRE_MAX_CMD_LENGTH) {
fprintf(stderr,"LiveWire: status string truncated");
live_ptr=0;
}
}
}
@ -532,83 +578,87 @@ void RDLiveWire::DespatchCommand(const QString &cmd)
void RDLiveWire::ReadVersion(const QString &cmd)
{
int ptr=0;
QString tag;
QString value;
QStringList f0;
QStringList f1;
if(!live_connected) {
while((ptr=ParseString(cmd,ptr,&tag,&value))>=0) {
if(tag=="LWRP") {
live_protocol_version=value;
}
if(tag=="DEVN") {
live_device_name=value;
}
if(tag=="SYSV") {
live_system_version=value;
}
if(tag=="NSRC") {
int delimiter=value.find("/");
if(delimiter<0) {
live_sources=value.toInt();
f0=AString(cmd).split(" ","\"");
for(unsigned i=0;i<f0.size();i++) {
f1=f1.split(":",f0[i]);
if(f1.size()==2) {
if(f1[0]=="LWRP") {
live_protocol_version=f1[1];
}
else {
live_sources=value.left(delimiter).toInt();
live_channels=value.right(value.length()-delimiter-1).toInt();
if(f1[0]=="DEVN") {
live_device_name=f1[1];
}
if(live_sources>0) {
live_socket->writeBlock("SRC\r\n",5);
if(f1[0]=="SYSV") {
live_system_version=f1[1];
}
}
if(tag=="NDST") {
int delimiter=value.find("/");
if(delimiter<0) {
live_destinations=value.toInt();
if(f1[0]=="NSRC") {
int delimiter=f1[1].find("/");
if(delimiter<0) {
live_sources=f1[1].toInt();
}
else {
live_sources=f1[1].left(delimiter).toInt();
live_channels=f1[1].right(f1[1].length()-delimiter-1).toInt();
}
if(live_sources>0) {
live_socket->writeBlock("SRC\r\n",5);
}
}
else {
live_destinations=value.left(delimiter).toInt();
live_channels=value.right(value.length()-delimiter-1).toInt();
if(f1[0]=="NDST") {
int delimiter=f1[1].find("/");
if(delimiter<0) {
live_destinations=f1[1].toInt();
}
else {
live_destinations=f1[1].left(delimiter).toInt();
live_channels=f1[1].right(f1[1].length()-delimiter-1).toInt();
}
if(live_destinations>0) {
live_socket->writeBlock("DST\r\n",5);
}
}
if(live_destinations>0) {
live_socket->writeBlock("DST\r\n",5);
if(f1[0]=="NGPI") {
live_gpis=f1[1].toInt();
QSignalMapper *mapper=new QSignalMapper(this,"gpi_mapper");
connect(mapper,SIGNAL(mapped(int)),this,SLOT(gpiTimeoutData(int)));
for(int i=0;i<live_gpis;i++) {
live_gpi_states.push_back(new bool[RD_LIVEWIRE_GPIO_BUNDLE_SIZE]);
live_gpi_channels.
push_back(new unsigned[RD_LIVEWIRE_GPIO_BUNDLE_SIZE]);
for(int j=0;j<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;j++) {
live_gpi_states.back()[j]=false;
live_gpi_channels.back()[j]=i*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+j;
live_gpi_timers.push_back(new QTimer(this));
mapper->setMapping(live_gpi_timers.back(),
i*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+j);
connect(live_gpi_timers.back(),SIGNAL(timeout()),mapper,SLOT(map()));
}
}
if(!live_gpi_initialized) {
live_socket->writeBlock("ADD GPI\r\n",9);
live_gpi_initialized=true;
}
}
}
if(tag=="NGPI") {
live_gpis=value.toInt();
QSignalMapper *mapper=new QSignalMapper(this,"gpi_mapper");
connect(mapper,SIGNAL(mapped(int)),this,SLOT(gpiTimeoutData(int)));
for(int i=0;i<live_gpis;i++) {
live_gpi_states.push_back(new bool[RD_LIVEWIRE_GPIO_BUNDLE_SIZE]);
live_gpi_channels.
push_back(new unsigned[RD_LIVEWIRE_GPIO_BUNDLE_SIZE]);
for(int j=0;j<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;j++) {
live_gpi_states.back()[j]=false;
live_gpi_channels.back()[j]=i*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+j;
live_gpi_timers.push_back(new QTimer(this));
mapper->setMapping(live_gpi_timers.back(),
i*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+j);
connect(live_gpi_timers.back(),SIGNAL(timeout()),mapper,SLOT(map()));
}
}
if(!live_gpi_initialized) {
live_socket->writeBlock("ADD GPI\r\n",9);
live_gpi_initialized=true;
}
}
if(tag=="NGPO") {
live_gpos=value.toInt();
QSignalMapper *mapper=new QSignalMapper(this,"gpo_mapper");
connect(mapper,SIGNAL(mapped(int)),this,SLOT(gpoTimeoutData(int)));
for(int i=0;i<live_gpos;i++) {
live_gpo_states.push_back(new bool[RD_LIVEWIRE_GPIO_BUNDLE_SIZE]);
live_gpo_channels.
push_back(new unsigned[RD_LIVEWIRE_GPIO_BUNDLE_SIZE]);
for(int j=0;j<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;j++) {
live_gpo_states.back()[j]=false;
live_gpo_channels.back()[j]=i*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+j;
live_gpo_timers.push_back(new QTimer(this));
mapper->setMapping(live_gpo_timers.back(),
i*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+j);
connect(live_gpo_timers.back(),SIGNAL(timeout()),mapper,SLOT(map()));
if(f1[0]=="NGPO") {
live_gpos=f1[1].toInt();
QSignalMapper *mapper=new QSignalMapper(this,"gpo_mapper");
connect(mapper,SIGNAL(mapped(int)),this,SLOT(gpoTimeoutData(int)));
for(int i=0;i<live_gpos;i++) {
live_gpo_states.push_back(new bool[RD_LIVEWIRE_GPIO_BUNDLE_SIZE]);
live_gpo_channels.
push_back(new unsigned[RD_LIVEWIRE_GPIO_BUNDLE_SIZE]);
for(int j=0;j<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;j++) {
live_gpo_states.back()[j]=false;
live_gpo_channels.back()[j]=i*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+j;
live_gpo_timers.push_back(new QTimer(this));
mapper->setMapping(live_gpo_timers.back(),
i*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+j);
connect(live_gpo_timers.back(),SIGNAL(timeout()),mapper,SLOT(map()));
}
}
}
if(!live_gpo_initialized) {
@ -638,44 +688,42 @@ void RDLiveWire::ReadVersion(const QString &cmd)
void RDLiveWire::ReadSources(const QString &cmd)
{
// printf("SOURCES: %s\n",(const char *)cmd);
int ptr=0;
QString tag;
QString value;
RDLiveWireSource *src=new RDLiveWireSource();
QHostAddress addr;
int offset=cmd.find(" ");
src->setSlotNumber(cmd.left(offset).toInt());
ptr=offset+1;
while((ptr=ParseString(cmd,ptr,&tag,&value))>=0) {
if(tag=="PSNM") {
src->setPrimaryName(value);
}
if(tag=="LABL") {
src->setLabelName(value);
}
if(tag=="FASM") {
// ????
}
if(tag=="RTPE") {
src->setRtpEnabled(value.toInt());
}
if(tag=="RTPA") {
addr.setAddress(value);
src->setStreamAddress(addr);
}
if(tag=="INGN") {
src->setInputGain(value.toInt());
}
if(tag=="SHAB") {
src->setShareable(value.toInt());
}
if(tag=="NCHN") {
src->setChannels(value.toInt());
}
if(tag=="RTPP") {
// ????
QStringList f1;
RDLiveWireSource *src=new RDLiveWireSource();
QStringList f0=AString(cmd).split(" ","\"");
src->setSlotNumber(f0[0].toInt());
for(unsigned i=1;i<f0.size();i++) {
f1=f1.split(":",f0[i]);
if(f1.size()==2) {
if(f1[0]=="PSNM") {
src->setPrimaryName(f1[1]);
}
if(f1[0]=="LABL") {
src->setLabelName(f1[1]);
}
if(f1[0]=="FASM") {
// ????
}
if(f1[0]=="RTPE") {
src->setRtpEnabled(f1[1].toInt());
}
if(f1[0]=="RTPA") {
addr.setAddress(f1[1]);
src->setStreamAddress(addr);
}
if(f1[0]=="INGN") {
src->setInputGain(f1[1].toInt());
}
if(f1[0]=="SHAB") {
src->setShareable(f1[1].toInt());
}
if(f1[0]=="NCHN") {
src->setChannels(f1[1].toInt());
}
if(f1[0]=="RTPP") {
// ????
}
}
}
emit sourceChanged(live_id,src);
@ -685,31 +733,30 @@ void RDLiveWire::ReadSources(const QString &cmd)
void RDLiveWire::ReadDestinations(const QString &cmd)
{
int ptr=0;
QString tag;
QString value;
RDLiveWireDestination *dst=new RDLiveWireDestination();
QHostAddress addr;
int offset=cmd.find(" ");
dst->setSlotNumber(cmd.left(offset).toInt());
ptr=offset+1;
while((ptr=ParseString(cmd,ptr,&tag,&value))>=0) {
if(tag=="NAME") {
dst->setPrimaryName(value);
}
if(tag=="ADDR") {
addr.setAddress(value);
dst->setStreamAddress(addr);
}
if(tag=="NCHN") {
dst->setChannels(value.toInt());
}
if(tag=="LOAD") {
dst->setLoad((RDLiveWireDestination::Load)value.toInt());
}
if(tag=="OUGN") {
dst->setOutputGain(value.toInt());
QStringList f1;
RDLiveWireDestination *dst=new RDLiveWireDestination();
QStringList f0=AString(cmd).split(" ","\"");
dst->setSlotNumber(f0[0].toInt());
for(unsigned i=1;i<f0.size();i++) {
f1=f1.split(":",f0[i]);
if(f1.size()==2) {
if(f1[0]=="NAME") {
dst->setPrimaryName(f1[1]);
}
if(f1[0]=="ADDR") {
addr.setAddress(f1[1]);
dst->setStreamAddress(addr);
}
if(f1[0]=="NCHN") {
dst->setChannels(f1[1].toInt());
}
if(f1[0]=="LOAD") {
dst->setOutputGain((RDLiveWireDestination::Load)f1[1].toInt());
}
if(f1[0]=="OUGN") {
dst->setOutputGain(f1[1].toInt());
}
}
}
emit destinationChanged(live_id,dst);
@ -769,77 +816,27 @@ void RDLiveWire::ReadGpos(const QString &cmd)
void RDLiveWire::ReadGpioConfig(const QString &cmd)
{
// printf("GpioConfig: %s\n",(const char *)cmd);
int ptr=0;
QString tag;
QString value;
int offset=cmd.find(" ");
int slot=cmd.left(offset).toInt()-1;
QString str=cmd.right(cmd.length()-offset-1).lower();
ptr=offset+1;
while((ptr=ParseString(cmd,ptr,&tag,&value))>=0) {
if(tag=="SRCA") {
int chan=PruneUrl(value).toInt();
for(unsigned i=0;i<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;i++) {
live_gpi_channels[slot][i]=chan*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+i;
live_gpo_channels[slot][i]=chan*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+i;
emit gpoConfigChanged(live_id,slot,live_gpo_channels[slot][i]);
QStringList f0;
QStringList f1;
f0=AString(cmd).split(" ","\"");
int slot=f0[0].toInt()-1;
for(unsigned i=1;i<f0.size();i++) {
f1=f1.split(":",f0[i]);
if(f1.size()==2) {
if(f1[0]=="SRCA") {
int chan=PruneUrl(f1[1]).toInt();
for(unsigned i=0;i<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;i++) {
live_gpi_channels[slot][i]=chan*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+i;
live_gpo_channels[slot][i]=chan*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+i;
emit gpoConfigChanged(live_id,slot,live_gpo_channels[slot][i]);
}
}
}
}
}
int RDLiveWire::ParseString(const QString &str,int ptr,
QString *tag,QString *value) const
{
int len=(int)str.length();
bool quote_mode=false;
if(ptr>=len) {
return -1;
}
*tag="";
*value="";
//
// Get Tag
//
for(int i=ptr;i<len;i++) {
if(str[i]==':') {
ptr=i+1;
i=len;
}
else {
(*tag)+=str[i];
}
}
//
// Get Value
//
for(int i=ptr;i<len;i++) {
if(str[i]=='\"') {
quote_mode=!quote_mode;
}
else {
if((str[i]==' ')&&(!quote_mode)) {
ptr=i+1;
return ptr;
}
else {
(*value)+=str[i];
}
}
if(i==(len-1)) {
ptr=i+1;
return ptr;
}
}
return ptr;
}
QString RDLiveWire::PruneUrl(const QString &str)
{
QString ret=str;

View File

@ -25,8 +25,10 @@
#include <vector>
#include <qstring.h>
#include <qobject.h>
#include <qsocket.h>
#include <qstringlist.h>
#include <qtimer.h>
#include <rd.h>
@ -38,6 +40,16 @@
#define RDLIVEWIRE_RECONNECT_MIN_INTERVAL 5000
#define RDLIVEWIRE_RECONNECT_MAX_INTERVAL 30000
class AString : public QString
{
public:
AString();
AString(const AString &lhs);
AString(const QString &lhs);
QStringList split(const QString &sep,const QString &esc="") const;
};
class RDLiveWire : public QObject
{
Q_OBJECT
@ -98,8 +110,6 @@ class RDLiveWire : public QObject
void ReadGpis(const QString &cmd);
void ReadGpos(const QString &cmd);
void ReadGpioConfig(const QString &cmd);
int ParseString(const QString &str,int ptr,QString *tag,
QString *value) const;
QString PruneUrl(const QString &str);
void ResetConnection();
int GetHoldoff();

View File

@ -20,6 +20,8 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <stdio.h>
#include <rd.h>
#include <rdlivewiresource.h>

View File

@ -193,7 +193,7 @@ ViewNodeInfo::ViewNodeInfo(QWidget *parent,const char *name)
view_sources_view->setColumnAlignment(1,Qt::AlignCenter);
view_sources_view->addColumn(tr("NAME"));
view_sources_view->setColumnAlignment(2,Qt::AlignLeft);
view_sources_view->addColumn(tr("STREAMING"));
view_sources_view->addColumn(tr("ACTIVE"));
view_sources_view->setColumnAlignment(3,Qt::AlignCenter);
view_sources_view->addColumn(tr("SHAREABLE"));
view_sources_view->setColumnAlignment(4,Qt::AlignCenter);
@ -217,6 +217,7 @@ ViewNodeInfo::ViewNodeInfo(QWidget *parent,const char *name)
view_destinations_view->setItemMargin(5);
view_destinations_view->addColumn(tr("#"));
view_destinations_view->setColumnAlignment(0,Qt::AlignCenter);
view_destinations_view->setColumnSortType(0,RDListView::LineSort);
view_destinations_view->addColumn(tr("CHAN"));
view_destinations_view->setColumnAlignment(1,Qt::AlignCenter);
view_destinations_view->addColumn(tr("NAME"));
@ -326,7 +327,7 @@ void ViewNodeInfo::closeData()
void ViewNodeInfo::WriteSourceItem(RDLiveWireSource *src,RDListViewItem *item)
{
item->setLine(src->slotNumber());
item->setText(1,QString().sprintf("%05d",src->channelNumber()));
item->setText(2,src->primaryName());
if(src->rtpEnabled()) {
@ -349,6 +350,7 @@ void ViewNodeInfo::WriteSourceItem(RDLiveWireSource *src,RDListViewItem *item)
void ViewNodeInfo::WriteDestinationItem(RDLiveWireDestination *dst,
RDListViewItem *item)
{
item->setLine(dst->slotNumber());
item->
setText(1,QString().sprintf("%05u",view_base_output+dst->slotNumber()-1));
item->setText(2,dst->primaryName());