Example #1
0
void BtSs42::processCommand(RDMacro *cmd)
{
  char str[9];

  switch(cmd->command()) {
      case RDMacro::GO:
	if((cmd->argQuantity()!=5)||
	   ((cmd->arg(1).toString().lower()!="i")&&
	    (cmd->arg(1).toString().lower()!="o"))||
	   (cmd->arg(2).toInt()<1)||(cmd->arg(3).toInt()>bt_gpos)||
	   (cmd->arg(2).toInt()>bt_gpos)||
	   ((cmd->arg(3).toInt()!=1)&&(cmd->arg(3).toInt()!=0)&&
	    (cmd->arg(1).toString().lower()!="i"))||
	   ((cmd->arg(3).toInt()!=1)&&(cmd->arg(3).toInt()!=0)&&
	    (cmd->arg(3).toInt()!=-1)&&(cmd->arg(1).toString().lower()=="i"))||
	   (cmd->arg(4).toInt()<0)) {
	  cmd->acknowledge(false);
	  emit rmlEcho(cmd);
	  return;
	}
	if(cmd->arg(3).toInt()==0) {  // Turn OFF
	  if(cmd->arg(4).toInt()==0) {
	    if(cmd->arg(1).toString().lower()=="i") {
	      if(bt_gpi_state[cmd->arg(2).toInt()-1]) {
		emit gpiChanged(bt_matrix,cmd->arg(2).toInt()-1,false);
		bt_gpi_state[cmd->arg(2).toInt()-1]=false;
	      }
	      bt_gpi_mask[cmd->arg(2).toInt()-1]=true;
	    }
	    if(cmd->arg(1).toString().lower()=="o") {
	      if(cmd->arg(2).toInt()<=4) {
		sprintf(str,"*%dOO%dF",BTSS42_UNIT_ID,cmd->arg(2).toInt());
	      }
	      else {
		sprintf(str,"*%dOR%dF",BTSS42_UNIT_ID,cmd->arg(2).toInt()-4);
	      }
	      bt_device->writeBlock(str,6);
	      emit gpoChanged(bt_matrix,cmd->arg(2).toInt()-1,false);
	    }
	  }
	  else {
	    if(cmd->echoRequested()) {
	      cmd->acknowledge(false);
	      emit rmlEcho(cmd);
	    }
	    return;
	  }
	}
	else {
	  if(cmd->arg(3).toInt()==-1) {  // Clear input
	    bt_gpi_mask[cmd->arg(2).toInt()-1]=false;
	    bt_device->writeBlock("*0SPA",5);
	  }
	  else { 
	    if(cmd->arg(4).toInt()==0) {  // Turn ON
	      if(cmd->arg(1).toString().lower()=="i") {
		if(!bt_gpi_state[cmd->arg(2).toInt()-1]) {
		  emit gpiChanged(bt_matrix,cmd->arg(2).toInt()-1,true);
		  bt_gpi_state[cmd->arg(2).toInt()-1]=true;
		}
		bt_gpi_mask[cmd->arg(2).toInt()-1]=true;
	      }
	      if(cmd->arg(1).toString().lower()=="o") {
		if(cmd->arg(2).toInt()<=4) {
		  sprintf(str,"*%dOO%dL",BTSS42_UNIT_ID,cmd->arg(2).toInt());
		}
		else {
		  sprintf(str,"*%dOR%dL",BTSS42_UNIT_ID,cmd->arg(2).toInt()-4);
		}
		bt_device->writeBlock(str,6);
		emit gpoChanged(bt_matrix,cmd->arg(2).toInt()-1,true);
	      }
	    }
	    else {  // Pulse
	      if(cmd->arg(1).toString().lower()=="i") {
		if(!bt_gpi_state[cmd->arg(2).toInt()-1]) {
		  emit gpiChanged(bt_matrix,cmd->arg(2).toInt()-1,true);
		  bt_gpi_state[cmd->arg(2).toInt()-1]=true;
		}
		bt_gpi_mask[cmd->arg(2).toInt()-1]=true;
		bt_gpi_oneshot->start(cmd->arg(2).toInt()-1,500);
	      }
	      if(cmd->arg(1).toString().lower()=="o") {
		if(cmd->arg(2).toInt()<=4) {
		  sprintf(str,"*%dOO%dP",BTSS42_UNIT_ID,cmd->arg(2).toInt());
		}
		else {
		  sprintf(str,"*%dOR%dP",BTSS42_UNIT_ID,cmd->arg(2).toInt()-4);
		}
		bt_device->writeBlock(str,6);
		emit gpoChanged(bt_matrix,cmd->arg(2).toInt()-1,true);
		bt_gpo_oneshot->start(cmd->arg(2).toInt()-1,500);
	      }
	    }
	  }
	}
	if(cmd->echoRequested()) {
	  cmd->acknowledge(true);
	  emit rmlEcho(cmd);
	}
	break;

      case RDMacro::SA:
	if((cmd->arg(1).toInt()<1)||(cmd->arg(1).toInt()>bt_inputs)||
	   (cmd->arg(2).toInt()<1)||(cmd->arg(2).toInt()>2)) {
	  cmd->acknowledge(false);
	  emit rmlEcho(cmd);
	  return;
	}
	sprintf(str,"*%d%02d%d",BTSS42_UNIT_ID,
		cmd->arg(1).toInt(),cmd->arg(2).toInt());
	bt_device->writeBlock(str,5);
	cmd->acknowledge(true);
	emit rmlEcho(cmd);
	break;

      case RDMacro::SR:
	if((cmd->arg(1).toInt()<1)||(cmd->arg(1).toInt()>bt_inputs)||
	   (cmd->arg(2).toInt()<1)||(cmd->arg(2).toInt()>2)) {
	  cmd->acknowledge(false);
	  emit rmlEcho(cmd);
	  return;
	}
	sprintf(str,"*%d%02dM%d",BTSS42_UNIT_ID,
		cmd->arg(1).toInt(),cmd->arg(2).toInt());
	bt_device->writeBlock(str,6);
	cmd->acknowledge(true);
	emit rmlEcho(cmd);
	break;

      case RDMacro::ST:
	if((cmd->arg(1).toInt()<0)||(cmd->arg(1).toInt()>bt_inputs)||
	   (cmd->arg(2).toInt()<1)||(cmd->arg(2).toInt()>2)) {
	  cmd->acknowledge(false);
	  emit rmlEcho(cmd);
	  return;
	}
	if(cmd->arg(1).toInt()==0) {
	  sprintf(str,"*%dM%d",BTSS42_UNIT_ID,cmd->arg(2).toInt());
	  bt_device->writeBlock(str,4);
	}
	else {
	  sprintf(str,"*%d%02d%d",BTSS42_UNIT_ID,
		  cmd->arg(1).toInt(),cmd->arg(2).toInt());
	  bt_device->writeBlock(str,5);
	  for(int i=1;i<cmd->arg(1).toInt();i++) {
	    sprintf(str,"*%d%02dM%d",BTSS42_UNIT_ID,
		    i,cmd->arg(2).toInt());
	    bt_device->writeBlock(str,6);
	  }
	  for(int i=cmd->arg(1).toInt()+1;i<5;i++) {
	    sprintf(str,"*%d%02dM%d",BTSS42_UNIT_ID,
		    i,cmd->arg(2).toInt());
	    bt_device->writeBlock(str,6);
	  }
	}
	cmd->acknowledge(true);
	emit rmlEcho(cmd);
	break;

      default:
	cmd->acknowledge(false);
	emit rmlEcho(cmd);
	break;
  }
}
Example #2
0
void BtSs42::gpoOneshotData(int value)
{
  emit gpoChanged(bt_matrix,value,false);
}
Example #3
0
void SoftwareAuthority::DispatchCommand()
{
  char buffer[SWAUTHORITY_MAX_LENGTH];
  QString cmd;
  QString label;
  QString sql;
  RDSqlQuery *q;
  QStringList f0;
  QString name;

  //  LogLine(RDConfig::LogNotice,QString().sprintf("RECEIVED: %s",(const char *)swa_buffer));

  QString line_in=swa_buffer;
  QString section=line_in.lower().replace(">>","");

  //
  // Startup Sequence.  Get the input and output lists.
  //
  if(section=="login successful") {
    sprintf(buffer,"gpistat %d\x0D\x0A",swa_card);      // Request GPI States
    SendCommand(buffer);
    sprintf(buffer,"gpostat %d\x0D\x0A",swa_card);      // Request GPO States
    SendCommand(buffer);
    sprintf(buffer,"sourcenames %d\x0D\x0A",swa_card);  // Request Input List
    SendCommand(buffer);
    sprintf(buffer,"destnames %d\x0D\x0A",swa_card);    // Request Output List
    SendCommand(buffer);
    return;
  }
  if(section=="login failure") {
    LogLine(RDConfig::LogWarning,QString().sprintf(
	    "Error on connection to SoftwareAuthority device at %s:%d: Login Failure",
	    (const char *)swa_ipaddress.toString(),
	    swa_ipport));
    swa_socket->close();
    return;
  }

  switch(swa_istate) {
  case 0:   // No section selected
    if(section==QString().sprintf("begin sourcenames - %d",swa_card)) {
      swa_istate=1;
      swa_inputs=0;
      return;
    }
    if(section==QString().sprintf("begin destnames - %d",swa_card)) {
      swa_istate=2;
      swa_outputs=0;
      return;
    }
    break;

  case 1:   // Source List
    if(section==QString().sprintf("end sourcenames - %d",swa_card)) {
      //
      // Write Sources Data
      //
      swa_istate=0;
      sql=QString("update MATRICES set ")+
	QString().sprintf("INPUTS=%d ",swa_inputs)+
	"where (STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
	QString().sprintf("(MATRIX=%d)",swa_matrix);
      q=new RDSqlQuery(sql);
      delete q;
      return;
    }
    swa_inputs++;
    f0=f0.split("\t",line_in);
    name=f0[1];
    if(f0.size()>=7) {
      name=f0[6]+": "+f0[2];
    }
    sql=QString("select NUMBER from INPUTS where ")+
      "(STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
      QString().sprintf("(MATRIX=%d)&&",swa_matrix)+
      QString().sprintf("(NUMBER=%d)",f0[0].toInt());
    q=new RDSqlQuery(sql);
    if(q->first()) {
      sql=QString("update INPUTS set ")+
	"NAME=\""+RDEscapeString(name)+"\" where "+
	"(STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
	QString().sprintf("(MATRIX=%d)&&",swa_matrix)+
	QString().sprintf("(NUMBER=%d)",f0[0].toInt());
    }
    else {
      sql=QString("insert into INPUTS set ")+
	"NAME=\""+RDEscapeString(name)+"\","+
	"STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\","+
	QString().sprintf("MATRIX=%d,",swa_matrix)+
	QString().sprintf("NUMBER=%d",f0[0].toInt());
    }
    delete q;
    q=new RDSqlQuery(sql);
    delete q;
    break;

  case 2:   // Destinations List
    if(section==QString().sprintf("end destnames - %d",swa_card)) {
      //
      // Write Destinations Data
      //
      swa_istate=0;
      sql=QString("update MATRICES set ")+
	QString().sprintf("OUTPUTS=%d ",swa_outputs)+
	"where (STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
	QString().sprintf("(MATRIX=%d)",swa_matrix);
      q=new RDSqlQuery(sql);
      delete q;

      LogLine(RDConfig::LogInfo,QString().
	      sprintf("Connection to SoftwareAuthority device at %s:%d established",
		      (const char *)swa_ipaddress.toString(),
		      swa_ipport));
      if(swa_start_cart>0) {
	ExecuteMacroCart(swa_start_cart);
      }
      return;
    }
    swa_outputs++;
    f0=f0.split("\t",line_in);
    name=f0[1];
    if(f0.size()>=6) {
      name=f0[3]+"/"+f0[5]+": "+f0[2];
    }
    sql=QString("select NUMBER from OUTPUTS where ")+
      "(STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
      QString().sprintf("(MATRIX=%d)&&",swa_matrix)+
      QString().sprintf("(NUMBER=%d)",f0[0].toInt());
    q=new RDSqlQuery(sql);
    if(q->first()) {
      sql=QString("update OUTPUTS set ")+
	"NAME=\""+RDEscapeString(name)+"\" where "+
	"(STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\")&&"+
	QString().sprintf("(MATRIX=%d)&&",swa_matrix)+
	QString().sprintf("(NUMBER=%d)",f0[0].toInt());
    }
    else {
      sql=QString("insert into OUTPUTS set ")+
	"NAME=\""+RDEscapeString(name)+"\","+
	"STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\","+
	QString().sprintf("MATRIX=%d,",swa_matrix)+
	QString().sprintf("NUMBER=%d",f0[0].toInt());
    }
    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;
  }

  //
  // GPIO State Parser
  //
  f0=f0.split(" ",section);
  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;i<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;i++) {
	int gpi=(f0[2].toInt()-1)*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+i;
	if(f0[3].at(i)!=swa_gpi_states[f0[2].toInt()].at(i)) {
	  emit gpiChanged(swa_matrix,gpi,f0[3].at(i)=='l');
	}
      }
      swa_gpi_states[f0[2].toInt()]=f0[3];
    }
  }
  if((f0.size()==4)&&(f0[0].lower()=="gpostat")&&(f0[1].toInt()==swa_card)) {
    if(swa_gpo_states[f0[2].toInt()].isEmpty()) {
      swa_gpo_states[f0[2].toInt()]=f0[3];
      if((RD_LIVEWIRE_GPIO_BUNDLE_SIZE*f0[2].toInt())>swa_gpos) {
	swa_gpos=RD_LIVEWIRE_GPIO_BUNDLE_SIZE*f0[2].toInt();
      }
    }
    else {
      for(unsigned i=0;i<RD_LIVEWIRE_GPIO_BUNDLE_SIZE;i++) {
	int gpo=(f0[2].toInt()-1)*RD_LIVEWIRE_GPIO_BUNDLE_SIZE+i;
	if(f0[3].at(i)!=swa_gpo_states[f0[2].toInt()].at(i)) {
	  emit gpoChanged(swa_matrix,gpo,f0[3].at(i)=='l');
	}
      }
      swa_gpo_states[f0[2].toInt()]=f0[3];
    }
  }
}
Example #4
0
void BtSs82::gpoOneshotData(void *data)
{
  emit gpoChanged(bt_matrix,(long)data,false);
}
Example #5
0
void BtSrc8Iii::processCommand(RDMacro *cmd)
{
  char str[9];

  switch(cmd->command()) {
      case RDMacro::GO:
	if((cmd->argQuantity()!=5)||
	   ((cmd->arg(1).toString().lower()!="i")&&
	    (cmd->arg(1).toString().lower()!="o"))||
	   (cmd->arg(2).toInt()<1)||(cmd->arg(3).toInt()>bt_gpos)||
	   (cmd->arg(2).toInt()>bt_gpos)||
	   ((cmd->arg(3).toInt()!=1)&&(cmd->arg(3).toInt()!=0)&&
	    (cmd->arg(1).toString().lower()!="i"))||
	   ((cmd->arg(3).toInt()!=1)&&(cmd->arg(3).toInt()!=0)&&
	    (cmd->arg(3).toInt()!=-1)&&(cmd->arg(1).toString().lower()=="i"))||
	   (cmd->arg(4).toInt()<0)) {
	  cmd->acknowledge(false);
	  emit rmlEcho(cmd);
	  return;
	}
	if(cmd->arg(3).toInt()==0) {  // Turn OFF
	  if(cmd->arg(4).toInt()==0) {
	    if(cmd->arg(1).toString().lower()=="i") {
	      if(bt_gpi_state[cmd->arg(2).toInt()-1]) {
		emit gpiChanged(bt_matrix,cmd->arg(2).toInt()-1,false);
		bt_gpi_state[cmd->arg(2).toInt()-1]=false;
	      }
	      bt_gpi_mask[cmd->arg(2).toInt()-1]=true;
	    }
	    if(cmd->arg(1).toString().lower()=="o") {
	      sprintf(str,"*%dOR%dF\r\n",BTSRC8III_UNIT_ID,cmd->arg(2).toInt());
	      bt_device->writeBlock(str,8);
	      emit gpoChanged(bt_matrix,cmd->arg(2).toInt()-1,false);
	    }
	  }
	  else {
	    if(cmd->echoRequested()) {
	      cmd->acknowledge(false);
	      emit rmlEcho(cmd);
	    }
	    return;
	  }
	}
	else {
	  if(cmd->arg(3).toInt()==-1) {  // Clear input
	    bt_gpi_mask[cmd->arg(2).toInt()-1]=false;
	    bt_device->writeBlock("*0SPA\r\n",7);
	  }
	  else { 
	    if(cmd->arg(4).toInt()==0) {  // Turn ON
	      if(cmd->arg(1).toString().lower()=="i") {
		if(!bt_gpi_state[cmd->arg(2).toInt()-1]) {
		  emit gpiChanged(bt_matrix,cmd->arg(2).toInt()-1,true);
		  bt_gpi_state[cmd->arg(2).toInt()-1]=true;
		}
		bt_gpi_mask[cmd->arg(2).toInt()-1]=true;
	      }
	      if(cmd->arg(1).toString().lower()=="o") {
		sprintf(str,"*%dOR%dL\r\n",
			BTSRC8III_UNIT_ID,cmd->arg(2).toInt());
		bt_device->writeBlock(str,8);
		emit gpoChanged(bt_matrix,cmd->arg(2).toInt()-1,true);
	      }
	    }
	    else {  // Pulse
	      if(cmd->arg(1).toString().lower()=="i") {
		if(!bt_gpi_state[cmd->arg(2).toInt()-1]) {
		  emit gpiChanged(bt_matrix,cmd->arg(2).toInt()-1,true);
		  bt_gpi_state[cmd->arg(2).toInt()-1]=true;
		}
		bt_gpi_mask[cmd->arg(2).toInt()-1]=true;
		bt_gpi_oneshot->start(cmd->arg(2).toInt()-1,500);
	      }
	      if(cmd->arg(1).toString().lower()=="o") {
		sprintf(str,"*%dOR%dP%02d\r\n",
			BTSRC8III_UNIT_ID,cmd->arg(2).toInt(),
			cmd->arg(4).toInt()/100+1);
		bt_device->writeBlock(str,10);
		emit gpoChanged(bt_matrix,cmd->arg(2).toInt()-1,true);
		bt_gpo_oneshot->start(cmd->arg(2).toInt()-1,500);
	      }
	    }
	  }
	}
	if(cmd->echoRequested()) {
	  cmd->acknowledge(true);
	  emit rmlEcho(cmd);
	}
	break;

      default:
	cmd->acknowledge(false);
	emit rmlEcho(cmd);
	break;
  }
}
Example #6
0
void Sas64000Gpi::processCommand(RDMacro *cmd)
{
  char str[9];
  char cmd_byte;

  switch(cmd->command()) {
      case RDMacro::ST:
	if((cmd->arg(1).toInt()<1)||(cmd->arg(1).toInt()>sas_inputs)||
	   (cmd->arg(2).toInt()<1)||(cmd->arg(2).toInt()>sas_outputs)) {
	  cmd->acknowledge(false);
	  emit rmlEcho(cmd);
	  return;
	}
	sprintf(str,"\xFE%c%c%c%c%c\xFF",
		(char)((cmd->arg(2).toInt()-1)/16)&0x0F,
		(char)((cmd->arg(2).toInt()-1)%16)&0x0F,
		(char)((cmd->arg(1).toInt()-1)%128),
		(char)((cmd->arg(1).toInt()-1)/128),
		(char)(((cmd->arg(1).toInt()-1)%128)+
		((cmd->arg(1).toInt()-1)/128))&0x7F);
	sas_device->writeBlock(str,7);
	cmd->acknowledge(true);
	emit rmlEcho(cmd);
	break;

      case RDMacro::GO:
	if((cmd->arg(1).toString().lower()!="o")||
	   (cmd->arg(2).toInt()<1)||(cmd->arg(2).toInt()>sas_gpos)) {
	  cmd->acknowledge(false);
	  emit rmlEcho(cmd);
	  return;
	}
	if(cmd->arg(4).toInt()==0) {   // Latch
	  if(cmd->arg(3).toInt()==0) {   // Off
	    cmd_byte=0xF9;
	    emit gpoChanged(sas_matrix,cmd->arg(2).toInt()-1,false);
	  }
	  else {
	    cmd_byte=0xFA;
	    emit gpoChanged(sas_matrix,cmd->arg(2).toInt()-1,true);
	  }
	}
	else {  // Pulse
	  if(cmd->arg(3).toInt()==0) {
	    cmd->acknowledge(false);
	    emit rmlEcho(cmd);
	    return;
	  }
	  cmd_byte=0xFB;
	  sas_gpo_oneshot->start((void *)(cmd->arg(2).toInt()-1),500);
	  emit gpoChanged(sas_matrix,cmd->arg(2).toInt()-1,true);
	}
	sprintf(str,"%c%c\xFF",cmd_byte,cmd->arg(2).toInt()-1);
	sas_device->writeBlock(str,3);
	cmd->acknowledge(true);
	emit rmlEcho(cmd);
	break;

      default:
	cmd->acknowledge(false);
	emit rmlEcho(cmd);
	break;
  }
}
Example #7
0
void Sas64000Gpi::gpoOneshotData(void *data)
{
  emit gpoChanged(sas_matrix,(long)data,false);
}