Communication::Communication(QObject *parent) : QObject(parent) { serial = new QSerialPort(this); dataReceived = new QByteArray(); //controlParams = new ControlPC(); pidController = new Controller(parent); connectionTimer = new QTimer(parent); setStateCounter(0); openPort(); connect(serial, SIGNAL(readyRead()), this, SLOT(readData())); connect(this, SIGNAL(newDataArived(QByteArray, ControlCommands::CH_COMMAND)), this, SLOT(on_newDataArived(QByteArray, ControlCommands::CH_COMMAND))); connect(this, SIGNAL(replyReady(ControlCommands::CH_COMMAND)), this, SLOT(reply(ControlCommands::CH_COMMAND))); connect(this, SIGNAL(requestControl()), pidController, SLOT(on_controlRequested())); connect(pidController, SIGNAL(controlready(ControlCommands::CH_COMMAND)), this, SLOT(reply(ControlCommands::CH_COMMAND))); connect(this, SIGNAL(stateCounterChanged(int)), this, SLOT(on_stateCounterChanged(int))); //! conntrol comands signals connection to this // connect(pidController->controlCommands, SIGNAL(idleStateChanged()), // this, SLOT(on_idelStateChanged())); //! connection timer signal connection to this connect(connectionTimer, SIGNAL(timeout()), this, SLOT(on_connectionTimerOut())); //! set the state of connection to false !// // setChamberConnected(false); pidController->controlCommands->setIdle(true); connectionTimer->start(1000); }
void Communication::on_newDataArived(QByteArray newDataArived, ControlCommands::CH_COMMAND chCommand) { if(chCommand == ControlCommands::A){ QStringList list; double temp, humid; QString str(newDataArived); list = str.split(" "); temp = list[0].mid(4,9).toDouble(); humid = list[2].left(4).toDouble(); pidController->chamberParams->setDryTemprature(temp); pidController->chamberParams->setHumidity(humid); if(pidController->controlCommands->isIdle()) { emit replyReady(chCommand); }else{ emit requestControl(); } }else if(chCommand == ControlCommands::B){ if(!isChamberConnected() && getStateCounter() > 2){ setStateCounter(0); } setStateCounter(1); setChamberConnected(true); emit replyReady(chCommand); }else if(chCommand == ControlCommands::A){ emit replyReady(chCommand); }else if(chCommand == ControlCommands::I){ setChamberConnected(false); emit replyReady(chCommand); return; }else if (chCommand == ControlCommands::ACK) { // emit replyReady(chCommand); } }
void JAUSClient::requestControl(openjaus::transport::Address accessControlAddress) { //openjaus::core::ReleaseControl *cmd = new openjaus::core::ReleaseControl(); //JAUSComponent->sendMessage(cmd); //requestControl(accessControlAddress, processControlResponse); requestControl(accessControlAddress); }