|
@@ -0,0 +1,300 @@
|
|
|
|
+#include "mainwindow.h"
|
|
|
|
+#include "ui_mainwindow.h"
|
|
|
|
+
|
|
|
|
+MainWindow::MainWindow(QWidget *parent)
|
|
|
|
+ : QMainWindow(parent)
|
|
|
|
+ , ui(new Ui::MainWindow)
|
|
|
|
+{
|
|
|
|
+ ui->setupUi(this);
|
|
|
|
+
|
|
|
|
+ std::string strmsgname;
|
|
|
|
+
|
|
|
|
+ strmsgname = "brainstate";
|
|
|
|
+ strncpy(shmBrainState.mstrmsgname,strmsgname.data(),255);
|
|
|
|
+ shmBrainState.mnBufferSize = 10000;
|
|
|
|
+ shmBrainState.mnBufferCount = 10;
|
|
|
|
+
|
|
|
|
+ strmsgname = "FSMSkipCommand";
|
|
|
|
+ strncpy(shmFSMSkipCMD.mstrmsgname,strmsgname.data(),255);
|
|
|
|
+ shmFSMSkipCMD.mnBufferSize = 10000;
|
|
|
|
+ shmFSMSkipCMD.mnBufferCount = 1;
|
|
|
|
+
|
|
|
|
+ shmFSMSkipCMD.mpa = iv::modulecomm::RegisterSend(shmFSMSkipCMD.mstrmsgname,shmFSMSkipCMD.mnBufferSize,shmFSMSkipCMD.mnBufferCount);
|
|
|
|
+ ModuleFun funupdate = std::bind(&MainWindow::ListenBrainStateMsg,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5);
|
|
|
|
+ shmBrainState.mpa = iv::modulecomm::RegisterRecvPlus(shmBrainState.mstrmsgname,funupdate);
|
|
|
|
+
|
|
|
|
+ QObject::connect(&signalSendTimer,&QTimer::timeout,this,&MainWindow::signalSend_Timeout);
|
|
|
|
+ if(signalSendTimer.isActive() == false)signalSendTimer.start(50);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+MainWindow::~MainWindow()
|
|
|
|
+{
|
|
|
|
+ signalSendTimer.stop();
|
|
|
|
+ if(shmFSMSkipCMD.mpa != nullptr)iv::modulecomm::Unregister(shmFSMSkipCMD.mpa);
|
|
|
|
+ if(shmBrainState.mpa != nullptr)iv::modulecomm::Unregister(shmBrainState.mpa);
|
|
|
|
+ delete ui;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::ListenBrainStateMsg(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
|
+{
|
|
|
|
+ iv::brain::brainstate xdata;
|
|
|
|
+ if(!xdata.ParseFromArray(strdata,nSize))
|
|
|
|
+ {
|
|
|
|
+ std::cout<<" ListenBrainStateMsg parese error."<<std::endl;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FSMState = xdata.mbfsm_state(); //0:待命停车 1:任务中 2:人工接管 3:停工停车 4:返程 5:返库
|
|
|
|
+
|
|
|
|
+ switch (FSMState) {
|
|
|
|
+ case 0:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("0待命停车");
|
|
|
|
+ if(missionCMD == iv::brain::MissionCMD::MISSIOH_FINISH \
|
|
|
|
+ || missionCMD == iv::brain::MissionCMD::MISSION_CANCEL)
|
|
|
|
+ {
|
|
|
|
+ missionCMD = iv::brain::MissionCMD::MISSION_RESERVED;
|
|
|
|
+ ui->missionResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(workCMD == iv::brain::WorkCMD::WORK_START)
|
|
|
|
+ {
|
|
|
|
+ workCMD = iv::brain::WorkCMD::WORK_RESERVED;
|
|
|
|
+ ui->workResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(waitingStationArrived == true)
|
|
|
|
+ {
|
|
|
|
+ waitingStationArrived = false;
|
|
|
|
+ ui->waitSta_checkBox->setChecked(false);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("1任务中");
|
|
|
|
+ if(missionCMD == iv::brain::MissionCMD::MISSION_START)
|
|
|
|
+ {
|
|
|
|
+ missionCMD = iv::brain::MissionCMD::MISSION_RESERVED;
|
|
|
|
+ ui->missionResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("2人工接管");
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_ENTER)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("3停工停车");
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(maintainStationArrived == true)
|
|
|
|
+ {
|
|
|
|
+ maintainStationArrived = false;
|
|
|
|
+ ui->maintainSta_checkBox->setChecked(false);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 4:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("4返程");
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 5:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("5返库");
|
|
|
|
+ if(workCMD == iv::brain::WorkCMD::WORK_STOP)
|
|
|
|
+ {
|
|
|
|
+ workCMD = iv::brain::WorkCMD::WORK_RESERVED;
|
|
|
|
+ ui->workResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::signalSend_Timeout(void)
|
|
|
|
+{
|
|
|
|
+ iv::brain::fsm_skip_cmd xmsg;
|
|
|
|
+ xmsg.set_timestamp(QDateTime::currentMSecsSinceEpoch());
|
|
|
|
+ xmsg.set_missioncmd(missionCMD);
|
|
|
|
+ xmsg.set_workcmd(workCMD);
|
|
|
|
+ xmsg.set_remotectrlcmd(remoteCtrlCMD);
|
|
|
|
+ xmsg.set_waitingstationarrived(waitingStationArrived);
|
|
|
|
+ xmsg.set_maintainstationarrived(maintainStationArrived);
|
|
|
|
+
|
|
|
|
+ int ndatasize = xmsg.ByteSize();
|
|
|
|
+ char * str = new char[ndatasize];
|
|
|
|
+ std::shared_ptr<char> pstr;pstr.reset(str);
|
|
|
|
+ if(!xmsg.SerializeToArray(str,ndatasize))
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"FSMSkipCommand serialize error."<<std::endl;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ iv::modulecomm::ModuleSendMsg(shmFSMSkipCMD.mpa,str,ndatasize);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_missionStaButton_clicked(bool checked)
|
|
|
|
+{
|
|
|
|
+ if(checked)
|
|
|
|
+ missionCMD = iv::brain::MissionCMD::MISSION_START;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_missionFinButton_clicked(bool checked)
|
|
|
|
+{
|
|
|
|
+ if(checked)
|
|
|
|
+ missionCMD = iv::brain::MissionCMD::MISSIOH_FINISH;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_missionCanButton_clicked(bool checked)
|
|
|
|
+{
|
|
|
|
+ if(checked)
|
|
|
|
+ missionCMD = iv::brain::MissionCMD::MISSION_CANCEL;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_workStaButton_clicked(bool checked)
|
|
|
|
+{
|
|
|
|
+ if(checked)
|
|
|
|
+ workCMD = iv::brain::WorkCMD::WORK_START;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_workStoButton_clicked(bool checked)
|
|
|
|
+{
|
|
|
|
+ if(checked)
|
|
|
|
+ workCMD = iv::brain::WorkCMD::WORK_STOP;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_remoteExiButton_clicked(bool checked)
|
|
|
|
+{
|
|
|
|
+ if(checked)
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_remoteEntButton_clicked(bool checked)
|
|
|
|
+{
|
|
|
|
+ if(checked)
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_ENTER;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_waitSta_checkBox_clicked(bool checked)
|
|
|
|
+{
|
|
|
|
+ if(checked)
|
|
|
|
+ waitingStationArrived = true;
|
|
|
|
+ else
|
|
|
|
+ waitingStationArrived = false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_maintainSta_checkBox_clicked(bool checked)
|
|
|
|
+{
|
|
|
|
+ if(checked)
|
|
|
|
+ maintainStationArrived = true;
|
|
|
|
+ else
|
|
|
|
+ maintainStationArrived = false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MainWindow::on_comboBox_activated(int index)
|
|
|
|
+{
|
|
|
|
+ FSMState = index; //0:待命停车 1:任务中 2:人工接管 3:停工停车 4:返程 5:返库
|
|
|
|
+
|
|
|
|
+ switch (FSMState) {
|
|
|
|
+ case 0:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("0待命停车");
|
|
|
|
+ if(missionCMD == iv::brain::MissionCMD::MISSIOH_FINISH \
|
|
|
|
+ || missionCMD == iv::brain::MissionCMD::MISSION_CANCEL)
|
|
|
|
+ {
|
|
|
|
+ missionCMD = iv::brain::MissionCMD::MISSION_RESERVED;
|
|
|
|
+ ui->missionResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(workCMD == iv::brain::WorkCMD::WORK_START)
|
|
|
|
+ {
|
|
|
|
+ workCMD = iv::brain::WorkCMD::WORK_RESERVED;
|
|
|
|
+ ui->workResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(waitingStationArrived == true)
|
|
|
|
+ {
|
|
|
|
+ waitingStationArrived = false;
|
|
|
|
+ ui->waitSta_checkBox->setChecked(false);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("1任务中");
|
|
|
|
+ if(missionCMD == iv::brain::MissionCMD::MISSION_START)
|
|
|
|
+ {
|
|
|
|
+ missionCMD = iv::brain::MissionCMD::MISSION_RESERVED;
|
|
|
|
+ ui->missionResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("2人工接管");
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_ENTER)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("3停工停车");
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(maintainStationArrived == true)
|
|
|
|
+ {
|
|
|
|
+ maintainStationArrived = false;
|
|
|
|
+ ui->maintainSta_checkBox->setChecked(false);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 4:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("4返程");
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 5:
|
|
|
|
+ ui->FSMStateTextBrowser->setText("5返库");
|
|
|
|
+ if(workCMD == iv::brain::WorkCMD::WORK_STOP)
|
|
|
|
+ {
|
|
|
|
+ workCMD = iv::brain::WorkCMD::WORK_RESERVED;
|
|
|
|
+ ui->workResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ if(remoteCtrlCMD == iv::brain::RemoteCtrlCMD::REMOTE_CTRL_EXIT)
|
|
|
|
+ {
|
|
|
|
+ remoteCtrlCMD = iv::brain::RemoteCtrlCMD::REMOTE_CTRL_RESERVED;
|
|
|
|
+ ui->remoteResButton->setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+}
|