void Harlond::ProcessResponse(const QString &str) { // LogLine(RDConfig::LogNotice,str); QStringList cmds=cmds.split(" ",str); if(cmds[0]=="PW") { if(cmds.size()==2) { if(cmds[1]=="+") { LogLine(RDConfig::LogInfo,tr("connection to harlond device at ")+ bt_ip_address.toString()+QString().sprintf(":%d ",bt_tcp_port)+ tr("established")); bt_socket->writeBlock("SS!",3); return; } } LogLine(RDConfig::LogInfo,tr("connection to harlond device at ")+ bt_ip_address.toString()+QString().sprintf(":%d ",bt_tcp_port)+ tr("refused, invalid password")); } if(cmds[0]=="ON") { if(cmds.size()==2) { emit gpiChanged(bt_matrix,cmds[1].toInt()-1,true); } } if(cmds[0]=="OF") { if(cmds.size()==2) { emit gpiChanged(bt_matrix,cmds[1].toInt()-1,false); } } }
void ModemLines::gpiOneshotData(int value) { int lines=0; gpio_gpi_mask[value]=false; if(ioctl(gpio_fd,TIOCMGET,&lines)==0) { emit gpiChanged(gpio_matrix,value,(lines&gpio_gpi_table[value])!=0); } }
void BtSs82::ProcessPipStatus(const QString &buf) { QStringList f1=buf.split(","); if(f1.size()==18) { for(int i=0;i<BTSS82_GPIS;i++) { if((f1[i+2]=="1")!=bt_gpi_states[i]) { bt_gpi_states[i]=f1[i+2]=="1"; emit gpiChanged(id(),i,bt_gpi_states[i]); } } } }
void ModemLines::pollTtyData() { int lines=0; if(ioctl(gpio_fd,TIOCMGET,&lines)==0) { if(lines==gpio_poll_state) { return; } for(int i=0;i<gpio_gpis;i++) { if((lines&gpio_gpi_table[i])!=(gpio_poll_state&gpio_gpi_table[i])) { emit gpiChanged(gpio_matrix,i,(lines&gpio_gpi_table[i])!=0); } } gpio_poll_state=lines; } }
void Gpio::pollData() { #ifdef HAVE_MC_GPIO struct gpio_mask mask; unsigned gpi=0; if(ioctl(gpio_fd,GPIO_GET_INPUTS,&mask)<0) { return; } for(unsigned i=0;i<4;i++) { for(unsigned j=0;(j<8*sizeof(unsigned));j++) { if((gpi=i*8*sizeof(unsigned)+j)>=gpio_gpi_states.size()) { return; } bool state=((mask.mask[i]>>j)&0x01)==0x01; if(state!=gpio_gpi_states[gpi]) { gpio_gpi_states[gpi]=state; emit gpiChanged(id(),gpi,state); } } } #endif // HAVE_MC_GPIO }
void BtSs42::processStatus() { char buffer[256]; int n; int gpi; while((n=bt_device->readBlock(buffer,255))>0) { for(int i=0;i<n;i++) { switch(bt_istate) { case 0: if(buffer[i]=='S') { bt_istate=1; } break; case 1: if(buffer[i]==(BTSS42_UNIT_ID+'0')) { bt_istate=2; } else { bt_istate=0; } break; case 2: if(buffer[i]=='P') { bt_istate=3; } else { bt_istate=0; } break; case 3: if(buffer[i]==',') { bt_istate=4; } else { bt_istate=0; } break; case 4: if(buffer[i]=='A') { bt_istate=5; } else { bt_istate=0; } break; case 5: case 7: case 9: case 11: case 13: case 15: case 17: case 19: case 21: case 23: case 25: case 27: case 29: case 31: case 33: case 35: if(buffer[i]==',') { bt_istate++; } else { bt_istate=0; } break; case 6: case 8: case 10: case 12: case 14: case 16: case 18: case 20: case 22: case 24: case 26: case 28: case 30: case 32: case 34: case 36: if(buffer[i]=='0') { gpi=(bt_istate-6)/2; if(bt_gpi_state[gpi]&&(!bt_gpi_mask[gpi])) { emit gpiChanged(bt_matrix,gpi,false); bt_gpi_state[gpi]=false; } bt_istate++; } if(buffer[i]=='1') { gpi=(bt_istate-6)/2; if((!bt_gpi_state[gpi])&&(!bt_gpi_mask[gpi])) { emit gpiChanged(bt_matrix,gpi,true); bt_gpi_state[gpi]=true; } bt_istate++; } break; default: bt_istate=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; } }
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]; } } }
void ModemLines::processCommand(RDMacro *cmd) { switch(cmd->command()) { case RDMacro::GO: if((gpio_fd<0)||(cmd->argQuantity()!=5)|| ((cmd->arg(1).toString().lower()!="i")&& (cmd->arg(1).toString().lower()!="o"))|| (cmd->arg(2).toInt()<1)||(cmd->arg(2).toInt()>gpio_gpos)|| ((cmd->arg(3).toInt()!=1)&&(cmd->arg(3).toInt()!=0)&& (cmd->arg(3).toInt()!=-1))||(cmd->arg(4).toInt()<0)) { cmd->acknowledge(false); emit rmlEcho(cmd); return; } if(cmd->arg(1).toString().lower()=="i") { if(cmd->arg(3).toInt()==0) { emit gpiChanged(gpio_matrix,cmd->arg(2).toInt()-1,false); gpio_gpi_mask[cmd->arg(2).toInt()-1]=true; if(cmd->arg(4).toInt()>0) { gpio_gpi_oneshot-> start(cmd->arg(2).toInt()-1,cmd->arg(4).toInt()); } } else { if(cmd->arg(3).toInt()==1) { emit gpiChanged(gpio_matrix,cmd->arg(2).toInt()-1,true); gpio_gpi_mask[cmd->arg(2).toInt()-1]=true; if(cmd->arg(4).toInt()>0) { gpio_gpi_oneshot-> start(cmd->arg(2).toInt()-1,cmd->arg(4).toInt()); } } else { gpiOneshotData(cmd->arg(2).toInt()-1); } } cmd->acknowledge(true); emit rmlEcho(cmd); return; } if(cmd->arg(1).toString().lower()=="o") { if(cmd->arg(3).toInt()==0) { ioctl(gpio_fd,TIOCMBIC,&gpio_gpo_table[cmd->arg(2).toInt()-1]); if(cmd->arg(4).toInt()>0) { gpio_gpo_timers[cmd->arg(2).toInt()-1]-> start(cmd->arg(4).toInt(),true); gpio_gpo_pending_states[cmd->arg(2).toInt()-1]=true; } } else { if(cmd->arg(3).toInt()==1) { ioctl(gpio_fd,TIOCMBIS,&gpio_gpo_table[cmd->arg(2).toInt()-1]); if(cmd->arg(4).toInt()>0) { gpio_gpo_timers[cmd->arg(2).toInt()-1]-> start(cmd->arg(4).toInt(),true); gpio_gpo_pending_states[cmd->arg(2).toInt()-1]=false; } } else { cmd->acknowledge(false); emit rmlEcho(cmd); return; } } cmd->acknowledge(true); emit rmlEcho(cmd); return; } break; default: cmd->acknowledge(false); emit rmlEcho(cmd); break; } }
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; } }