#include "CommandBox.h" #include "ui_CommandBox.h" CommandBox::CommandBox(QWidget *parent) : QWidget(parent), ui(new Ui::CommandBox) { ui->setupUi(this); m_parent = parent; ui->comboBox_Full->addItem("基准档",0x85); ui->comboBox_Full->addItem("1档",0x16); ui->comboBox_Full->addItem("2档",0x26); ui->comboBox_Full->addItem("3档",0x36); ui->comboBox_Full->addItem("4档",0x46); ui->comboBox_Full->addItem("5档",0x56); ui->comboBox_Full->addItem("6档",0x66); ui->comboBox_Full->addItem("7档",0x76); ui->comboBox_Full->addItem("8档",0x86); ui->comboBox_Full->addItem("9档",0x96); ui->comboBox_Full->setCurrentIndex(0); ui->comboBox_Half->addItem("基准档",0x75); ui->comboBox_Half->addItem("1档",0x1c); ui->comboBox_Half->addItem("2档",0x2c); ui->comboBox_Half->addItem("3档",0x3c); ui->comboBox_Half->addItem("4档",0x4c); ui->comboBox_Half->addItem("5档",0x5c); ui->comboBox_Half->addItem("6档",0x6c); ui->comboBox_Half->addItem("7档",0x7c); ui->comboBox_Half->addItem("8档",0x8c); ui->comboBox_Half->addItem("9档",0x9c); ui->comboBox_Half->setCurrentIndex(0); ui->comboBox_rate->addItem("10000",10000); ui->comboBox_rate->addItem("15000",15000); ui->comboBox_rate->addItem("20000",20000); ui->comboBox_rate->addItem("25000",25000); ui->comboBox_rate->addItem("30000",30000); ui->comboBox_rate->addItem("35000",35000); ui->comboBox_rate->addItem("40000",40000); ui->comboBox_rate->addItem("46000",46000); ui->comboBox_rate->setEditable(true); ui->comboBox_rate->setCurrentIndex(-1); ui->comboBox_TestPoint->addItem("核心机主燃油泵",0x19); ui->comboBox_TestPoint->addItem("加力主燃油泵",0x29); ui->comboBox_TestPoint->addItem("加力点火燃油泵",0x49); ui->comboBox_TestPoint->addItem("尾喷口舵机",0x79); ui->comboBox_TestPoint->addItem("点火器",0x89); ui->comboBox_TestPoint->addItem("起动控制1",0xb9); ui->comboBox_TestPoint->addItem("起动控制2",0xd9); ui->comboBox_TestPoint->addItem("核心机点火油阀",0x1a); ui->comboBox_TestPoint->addItem("核心机优先油阀",0x2a); ui->comboBox_TestPoint->addItem("核心机轻吹油阀",0x4a); ui->comboBox_TestPoint->addItem("核心机起动气阀",0x7a); ui->comboBox_TestPoint->addItem("核心机主油阀",0x8a); ui->comboBox_TestPoint->addItem("加力主油阀",0xba); ui->comboBox_TestPoint->addItem("加力轻吹阀",0xda); ui->comboBox_TestPoint->addItem("加力点火快速阀",0xea); ui->comboBox_TestPoint->addItem("手动转速控制",0xd5); ui->comboBox_TestPoint->setCurrentIndex(-1); ui->comboBox_TestValue->show(); ui->comboBox_TestValue->setCurrentIndex(-1); //use_ext_ins参数名称 ui->comboBox_IMU->addItem("内置惯导",0x00); ui->comboBox_IMU->addItem("SBG",0x01); ui->comboBox_IMU->setCurrentIndex(0); ui->comboBox_ServoType->addItem("左副翼",0x01); ui->comboBox_ServoType->addItem("右副翼",0x02); ui->comboBox_ServoType->addItem("左升降",0x03); ui->comboBox_ServoType->addItem("右升降",0x04); ui->comboBox_ServoType->addItem("方向舵",0x05); ui->comboBox_ServoType->setCurrentIndex(0); } CommandBox::~CommandBox() { delete ui; } void CommandBox::closeEvent(QCloseEvent *event) { setFloat(); event->ignore(); } void CommandBox::contextMenuEvent(QContextMenuEvent *event) { if(floatflag) { QMenu *menu = new QMenu(this); QAction *pAction = new QAction("float",this); connect(pAction,SIGNAL(triggered(bool)), this,SLOT(setFloat())); menu->addAction(pAction); menu->move(cursor().pos()); menu->show(); } } void CommandBox::setFloat(void) { if(floatflag) { if(this->parent()) { this->setParent(nullptr); this->show(); } else { this->setParent(m_parent); this->move(0,0); this->hide(); } } } void CommandBox::setFloatFlag(bool flag) { floatflag = flag; } void CommandBox::commandAccepted(bool flag,uint16_t command,uint8_t result) { bool isFundSender = false; QString string; //找到消息的发送者 QObjectList list = ui->frame->children(); //qDebug() << CommandBox.findChildren(); if(command == m_command) { /* foreach (QObject *obj, list) { QPushButton *btn = qobject_cast(obj); if(btn) { QString btn_name = btn->text(); qDebug() << btn_name << m_name; if(btn_name.contains(m_name))//查到正在等待回复的按键 { isFundSender = true; */ switch (result) { case MAV_RESULT_ACCEPTED: string.append(tr("%1,%2 accepted and executed").arg(command).arg(m_name)); break; case MAV_RESULT_TEMPORARILY_REJECTED: string.append(tr("%1,%2 rejected").arg(command).arg(m_name)); break; case MAV_RESULT_DENIED: string.append(tr("%1,%2 permanently denied").arg(command).arg(m_name)); break; case MAV_RESULT_UNSUPPORTED: string.append(tr("%1,%2 unsupported").arg(command).arg(m_name)); break; case MAV_RESULT_FAILED: string.append(tr("%1,%2 failed").arg(command).arg(m_name)); break; case MAV_RESULT_IN_PROGRESS: string.append(tr("%1,%2 being executed").arg(command).arg(m_name)); break; default: break; } //btn->style()->unpolish(btn); //btn->style()->polish(btn); // } //} //} } /* if(isFundSender == false) { switch (result) { case MAV_RESULT_ACCEPTED: string.append(tr("%1 accepted and executed").arg(command)); break; case MAV_RESULT_TEMPORARILY_REJECTED: string.append(tr("%1 rejected").arg(command)); break; case MAV_RESULT_DENIED: string.append(tr("%1 permanently denied").arg(command)); break; case MAV_RESULT_UNSUPPORTED: string.append(tr("%1 unsupported").arg(command)); break; case MAV_RESULT_FAILED: string.append(tr("%1 failed").arg(command)); break; case MAV_RESULT_IN_PROGRESS: string.append(tr("%1 being executed").arg(command)); break; default: break; } } */ if(string.size() > 0) { QTextToSpeech *tts = new QTextToSpeech(); tts->say(string); tts->deleteLater(); emit showMessage(string); } } void CommandBox::on_comboBox_TestPoint_currentIndexChanged(int index) { switch (index) { case 0: case 1: case 2: case 3: case 15: ui->label_TestValue->show(); ui->label_TestValue->setText("转速"); ui->comboBox_TestValue->show(); ui->comboBox_TestValue->clear(); ui->comboBox_TestValue->addItem("10000",10000); ui->comboBox_TestValue->addItem("15000",15000); ui->comboBox_TestValue->addItem("20000",20000); ui->comboBox_TestValue->addItem("25000",25000); ui->comboBox_TestValue->addItem("30000",30000); ui->comboBox_TestValue->addItem("35000",35000); ui->comboBox_TestValue->addItem("40000",40000); if(index != 3) { ui->comboBox_TestValue->addItem("45000",45000); } ui->comboBox_TestValue->setCurrentIndex(0); break; case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: ui->label_TestValue->show(); ui->label_TestValue->setText("电平"); ui->comboBox_TestValue->show(); ui->comboBox_TestValue->clear(); ui->comboBox_TestValue->addItem("低电平",0); ui->comboBox_TestValue->addItem("高电平",1); ui->comboBox_TestValue->setEditable(true); ui->comboBox_TestValue->setCurrentIndex(1); break; case 4: ui->label_TestValue->hide(); ui->comboBox_TestValue->hide(); break; } } //二次确认 void CommandBox::setSecondConfirm(QVariant value) { if(value.toBool() == true) { emit cmd_long(m_param1,m_param2,m_param3,m_param4,m_param5,m_param6,m_param7,m_command,m_confirm); } else { m_param1 = 0; m_param2 = 0; m_param3 = 0; m_param4 = 0; m_param5 = 0; m_param6 = 0; m_param7 = 0; m_command = 0; m_confirm = 0; } } void CommandBox::on_pushButton_SendCommand_clicked() { if(cmdType == 0) { emit showMessage(tr("发送指令 ") + m_name + " " + QString::number(m_command),5000); emit cmd_long(m_param1,m_param2,m_param3,m_param4,m_param5,m_param6,m_param7,m_command,m_confirm); } else if(cmdType == 1) { emit showMessage(tr("修改参数 ") + " " + ui->comboBox_IMU->itemText(m_value),5000); emit WriteCmd(m_sysid,m_compid,m_id.toLatin1().data(),m_type,m_value); qDebug() << m_type << m_value; } } void CommandBox::on_pushButton_Cancel_clicked() { m_param1 = 0; m_param2 = 0; m_param3 = 0; m_param4 = 0; m_param5 = 0; m_param6 = 0; m_param7 = 0; m_command = 0; m_confirm = 0; } void CommandBox::on_commandClicked(QString name, float param1,float param2,float param3,float param4, float param5,float param6,float param7, uint16_t command,uint8_t confirmation) { m_name = name; m_param1 = param1; m_param2 = param2; m_param3 = param3; m_param4 = param4; m_param5 = param5; m_param6 = param6; m_param7 = param7; m_command = command; m_confirm = confirmation; ui->lineEdit_CommandName->setText(name); cmdType = 0; } void CommandBox::on_paramClicked(uint8_t sysid, uint8_t compid , QString id, uint8_t type, float value) { m_sysid = sysid; m_compid = compid; m_id = id; m_type = type; m_value = value; ui->lineEdit_CommandName->setText(id + " " + QString::number(value)); cmdType = 1; } //测试指令 void CommandBox::on_pushButton_SendTest_clicked() { //判断 两个 内容是否是空, float testPoint = 0; float testValue = 0; if(!ui->comboBox_TestValue->isHidden())//如果显示 { testPoint = ui->comboBox_TestPoint->currentData(Qt::UserRole).toFloat(); testValue = ui->comboBox_TestValue->currentData(Qt::UserRole).toFloat(); if((ui->comboBox_TestPoint->currentIndex() != -1)&&(ui->comboBox_TestValue->currentIndex() != -1)) { on_commandClicked(ui->comboBox_TestPoint->currentText() + " " + ui->comboBox_TestValue->currentText() , 103,testPoint,testValue,0,0,0,0,180,0); } else { QMessageBox *box = new QMessageBox(this); box->setWindowTitle(tr("警告")); box->setText(tr("请选择测试项和测试点")); box->show(); } } else { if(ui->comboBox_TestPoint->currentIndex() != -1) { testPoint = ui->comboBox_TestPoint->currentData(Qt::UserRole).toFloat(); on_commandClicked(ui->comboBox_TestPoint->currentText(), 103,testPoint,0,0,0,0,0,180,0); } else { QMessageBox *box = new QMessageBox(this); box->setWindowTitle(tr("警告")); box->setText(tr("请选择测试项和测试点")); box->show(); } } } //伺服指令 void CommandBox::on_pushButton_AirHeatOn_clicked() { on_commandClicked(ui->pushButton_AirHeatOn->text(), 105,1,0,0,0,0,0,180,0); } void CommandBox::on_pushButton_AirHeatOff_clicked() { on_commandClicked(ui->pushButton_AirHeatOff->text(), 105,0,0,0,0,0,0,180,0); } //舵机指令 void CommandBox::on_pushButton_Servo_Check_clicked() { on_commandClicked(ui->pushButton_Servo_Check->text(), 1,0,0,0,0,0,0,20004,0); } void CommandBox::on_pushButton_Servo_Read_clicked() { on_commandClicked(ui->pushButton_Servo_Read->text(), 2,0,0,0,0,0,0,20004,0); } void CommandBox::on_pushButton_Servo_Zero_clicked() { on_commandClicked(ui->pushButton_Servo_Zero->text(), 3,0,0,0,0,0,0,20004,0); } void CommandBox::on_pushButton_Servo_Work_clicked() { on_commandClicked(ui->pushButton_Servo_Work->text(), 4,0,0,0,0,0,0,20004,0); } void CommandBox::on_pushButton_coldrun_clicked() { on_commandClicked(ui->pushButton_coldrun->text(), 103,0x13,0,0,0,0,0,180,0); } void CommandBox::on_pushButton_groundstartup_clicked() { on_commandClicked(ui->pushButton_groundstartup->text(), 103,0x15,0,0,0,0,0,180,0); } void CommandBox::on_pushButton_Afterburner_off_clicked() { on_commandClicked(ui->pushButton_Afterburner_off->text(), 103,0xb5,0,0,0,0,0,180,0); } void CommandBox::on_pushButton_stop_clicked() { on_commandClicked(ui->pushButton_stop->text(), 103,0x43,0,0,0,0,0,180,0); } void CommandBox::on_pushButton_EmergencyStop_clicked() { on_commandClicked(ui->pushButton_EmergencyStop->text(), 103,0x73,0,0,0,0,0,180,0); } void CommandBox::on_pushButton_Afterburner_on_clicked() { //根据档位选择 float Level = ui->comboBox_Full->currentData(Qt::UserRole).toFloat(); on_commandClicked(ui->pushButton_Afterburner_on->text() + " " + ui->comboBox_Full->currentText(), 103,0x85,Level,0,0,0,0,180,0); } void CommandBox::on_pushButton_Afterburner_half_clicked() { float Level = ui->comboBox_Half->currentData(Qt::UserRole).toFloat(); on_commandClicked(ui->pushButton_Afterburner_half->text() + " " + ui->comboBox_Half->currentText(), 103,0x75,Level,0,0,0,0,180,0); } void CommandBox::on_pushButton_setRPM_clicked() { if(ui->comboBox_rate->currentIndex() != -1) { float rpm = ui->comboBox_rate->currentData(Qt::UserRole).toFloat(); on_commandClicked(ui->pushButton_setRPM->text() + " " + ui->comboBox_rate->currentText(), 103,0x45,rpm,0,0,0,0,180,0); } else { QMessageBox *box = new QMessageBox(this); box->setWindowTitle(tr("警告")); box->setText(tr("请设定给定转速")); box->show(); } } void CommandBox::on_pushButton_IMU_clicked() { if((ui->comboBox_IMU->currentIndex() != -1)&&(ui->comboBox_sys->currentIndex() != -1)) { uint8_t value = ui->comboBox_IMU->currentData(Qt::UserRole).toInt(); uint8_t sysid = ui->comboBox_sys->currentData(Qt::UserRole).toInt(); uint8_t compid = 1; QString id; uint8_t type = MAV_PARAM_TYPE_UINT8; id.clear(); id.append("use_ext_ins"); on_paramClicked(sysid,compid,id,type,value); } else { QMessageBox *box = new QMessageBox(this); box->setWindowTitle(tr("警告")); box->setText(tr("请设定目标")); box->show(); } } void CommandBox::addVehicles(int sysid, int compid) { Q_UNUSED(compid) if(ui->comboBox_sys->findData(sysid) == -1) { ui->comboBox_sys->addItem(QString::number(sysid),sysid); } } void CommandBox::on_pushButton_ServoSet_clicked() { float ra = 0; float la = 0; float ru = 0; float re = 0; float le = 0; if(ui->comboBox_ServoType->currentIndex() != -1) { switch(ui->comboBox_ServoType->currentData(Qt::UserRole).toInt()) { case 1: { la = ui->spinBox_Servo->value(); }break; case 2: { ra = ui->spinBox_Servo->value(); }break; case 3: { le = ui->spinBox_Servo->value(); }break; case 4: { re = ui->spinBox_Servo->value(); }break; case 5: { ru = ui->spinBox_Servo->value(); }break; } on_commandClicked(tr("设定舵机 %1").arg(ui->spinBox_Servo->value()), 106,ra,re,ru,la,le,0,180,0); qDebug() << ra << re << ru << la << le; } else { QMessageBox *box = new QMessageBox(this); box->setWindowTitle(tr("警告")); box->setText(tr("请设定")); box->show(); } }