// rdcatchevent.cpp // // A container class for a Rivendell Catch Event message. // // (C) Copyright 2022-2023 Fred Gleason // // 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 #include "rdcatchevent.h" #include "rdapplication.h" RDCatchMeterLevel::RDCatchMeterLevel(int deck,int16_t *lvls) { d_deck_channel=deck; for(int i=0;i RDCatchEvent::meterLevels() const { return d_meter_levels; } void RDCatchEvent::setMeterLevels(const QList &lvls) { d_meter_levels=lvls; } bool RDCatchEvent::read(const QString &str) { // printf("RDCatchEvent::read(\"%s\")\n",str.toUtf8().constData()); RDCatchEvent::Operation op=RDCatchEvent::NullOp; QStringList f0=str.split(" "); unsigned chan=0; unsigned num=0; RDDeck::Status status=RDDeck::Offline; int state=0; bool ok=false; clear(); // // Common Fields // if((f0.size()<3)||(f0.at(0)!="CATCH")) { return false; } op=(RDCatchEvent::Operation)f0.at(2).toUInt(&ok); if(!ok) { return false; } // // Operation-specific Fields // switch(op) { case RDCatchEvent::DeckEventProcessedOp: if(f0.size()!=5) { return false; } chan=f0.at(3).toUInt(&ok); if(!ok) { return false; } num=f0.at(4).toUInt(&ok); if(ok) { d_operation=op; d_host_name=f0.at(1); d_deck_channel=chan; d_event_number=num; return true; } break; case RDCatchEvent::SendMeterLevelsOp: for(int i=2;i=255) { d_meter_levels.clear(); return false; } int16_t lvls[RDCatchMeterLevel::LastChannel]; for(int j=0;j0xFFFF)) { d_meter_levels.clear(); return false; } lvls[j]=-(int16_t)lvl; } d_meter_levels.push_back(RDCatchMeterLevel(chan,lvls)); } } d_operation=op; d_host_name=f0.at(1); return true; break; case RDCatchEvent::DeckStatusQueryOp: if(f0.size()!=3) { return false; } d_operation=op; d_host_name=f0.at(1); return true; break; case RDCatchEvent::DeckStatusResponseOp: if(f0.size()!=8) { return false; } chan=f0.at(3).toUInt(&ok); if(ok&&(chan<255)) { status=(RDDeck::Status)f0.at(4).toUInt(&ok); if(ok&&(status=0)&&(cutnum<=RD_MAX_CUT_NUMBER)) { d_operation=op; d_host_name=f0.at(1); d_deck_channel=chan; d_deck_status=status; d_event_id=id; d_cart_number=cartnum; d_cut_number=cutnum; return true; } } } } } break; case RDCatchEvent::StopDeckOp: if(f0.size()!=5) { return false; } chan=f0.at(4).toInt(&ok); if(ok&&(chan<255)) { d_operation=op; d_host_name=f0.at(1); d_target_host_name=f0.at(3); d_deck_channel=chan; return true; } break; case RDCatchEvent::SetInputMonitorOp: if(f0.size()!=6) { return false; } chan=f0.at(4).toInt(&ok); if(ok&&(chan<255)) { state=f0.at(5).toUInt(&ok); if((state==0)||(state==1)) { d_operation=op; d_host_name=f0.at(1); d_target_host_name=f0.at(3); d_deck_channel=chan; d_input_monitor_active=(state==1); return true; } } break; case RDCatchEvent::SetInputMonitorResponseOp: if(f0.size()!=5) { return false; } chan=f0.at(3).toInt(&ok); if(ok&&(chan<255)) { state=f0.at(4).toUInt(&ok); if((state==0)||(state==1)) { d_operation=op; d_host_name=f0.at(1); d_deck_channel=chan; d_input_monitor_active=(state==1); return true; } } break; case RDCatchEvent::ReloadDecksOp: if(f0.size()!=4) { return false; } d_operation=op; d_host_name=f0.at(1); d_target_host_name=f0.at(3); return true; case RDCatchEvent::NullOp: case RDCatchEvent::LastOp: break; } return false; } QString RDCatchEvent::write() const { QString ret; // // Common Fields // ret+="CATCH "; ret+=d_host_name+" "; ret+=QString::asprintf("%u",d_operation); // // Operation-specific Fields // switch(d_operation) { case RDCatchEvent::DeckEventProcessedOp: ret+=QString::asprintf(" %u",d_deck_channel); ret+=QString::asprintf(" %u",d_event_number); break; case RDCatchEvent::DeckStatusResponseOp: ret+=QString::asprintf(" %u",d_deck_channel); ret+=QString::asprintf(" %u",d_deck_status); ret+=QString::asprintf(" %u",d_event_id); ret+=QString::asprintf(" %u",d_cart_number); ret+=QString::asprintf(" %d",d_cut_number); break; case RDCatchEvent::DeckStatusQueryOp: case RDCatchEvent::NullOp: case RDCatchEvent::LastOp: break; case RDCatchEvent::SendMeterLevelsOp: for(int i=0;istation()->name(); d_target_host_name=""; d_event_id=0; d_cart_number=0; d_cut_number=0; d_deck_channel=0; d_event_number=0; d_input_monitor_active=false; d_deck_status=RDDeck::Offline; d_meter_levels.clear(); }