You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

758 lines
36 KiB

2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include "mainwindow.h"
  2. #include <QDateTime>
  3. #include <QMessageBox>
  4. #include <QtConcurrent>
  5. #include <QtSerialPort/QSerialPort>
  6. #include <QtSerialPort/QSerialPortInfo>
  7. #include "./ui_mainwindow.h"
  8. #include "camera_light_src_timing_controller/qt_serial_datachannel.hpp"
  9. #include "logger.hpp"
  10. using namespace iflytop;
  11. using namespace clst;
  12. using namespace std;
  13. static MainWindow *m_mainWindow;
  14. static CLSTControler *m_clstc;
  15. QTimer *timer0;
  16. QTimer *timer1;
  17. QTimer *timer2;
  18. QTimer *timer3;
  19. QTimer *checkConnectTimer0;
  20. #define TAG "MainWindow"
  21. static const char *fmt(const char *fmt, ...) {
  22. va_list args;
  23. va_start(args, fmt);
  24. static char buf[1024] = {0};
  25. vsnprintf(buf, sizeof(buf), fmt, args);
  26. va_end(args);
  27. return buf;
  28. }
  29. static const uint32_t str2int(QString str) {
  30. // 如果0x开头,??16进制转换
  31. // 如果0b开头,??2进制转换
  32. // 否则??10进制转换
  33. // 去除掉str中_
  34. str.remove("_");
  35. if (str.startsWith("0x")) {
  36. return str.toUInt(nullptr, 16);
  37. } else if (str.startsWith("0b")) {
  38. // remove 0b
  39. str.remove(0, 2);
  40. return str.toUInt(nullptr, 2);
  41. } else {
  42. return str.toUInt(nullptr, 10);
  43. }
  44. }
  45. // static QSerialPort G_SerialPort;
  46. // static QThread G_SerialPortThread;
  47. static QTDataChannel G_QTDataChannel;
  48. static const QString zaferror_to_str(zaf_error_code_t value) {
  49. if (value == kaf_ec_overtime) {
  50. return "操作超时";
  51. } else if (value == kaf_ec_device_notopen) {
  52. return "设备未打开";
  53. } else {
  54. return "未知错误";
  55. }
  56. }
  57. #define DO(action) \
  58. { \
  59. zaf_error_code_t ecode = action; \
  60. if (ecode != kaf_ec_success) { \
  61. dumpLog("do %s fail,%s", #action, zaferror_to_str(ecode).toStdString().c_str()); \
  62. return; \
  63. } \
  64. }
  65. void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
  66. // QString text;
  67. // text.append(msg);
  68. }
  69. // void MainWindow::append_log_slot(QString text) { ui->logbrowser->append(text); }
  70. void MainWindow::doinui_slot(QFunction func) {
  71. if (func.get()) func.get()();
  72. }
  73. void MainWindow::updatePage() {
  74. {
  75. float Freq;
  76. uint32_t PluseCnt;
  77. uint32_t SeqCtrlPluseCntMax;
  78. Freq = ui->InterClk_Freq_Text->text().toFloat();
  79. PluseCnt = ui->InterClk_PluseCnt_Text->text().toUInt();
  80. SeqCtrlPluseCntMax = ui->InterClk_SeqCtrlPluseCntMax_Text->text().toUInt();
  81. DO(m_clstc->InterClk_setFreq(Freq));
  82. DO(m_clstc->InterClk_setPluseCnt(PluseCnt));
  83. DO(m_clstc->InterClk_setSeqCtrlPluseCntMax(SeqCtrlPluseCntMax));
  84. }
  85. {
  86. ExtTriggerSrcType src;
  87. SigProcessMode mode;
  88. TriggerEdge edge;
  89. uint32_t coefficient;
  90. uint32_t bias;
  91. uint32_t division;
  92. uint32_t multiplication;
  93. #define UPDATE(index) \
  94. src = ExtTriggerSrcType(ui->TriInX_SrcSelect_Val_##index->currentText().toStdString()); \
  95. coefficient = ui->TriInX_FileterCoefficient_Val_##index->text().toUInt(); \
  96. bias = ui->TriInX_FreqDetectBias_Val_##index->text().toUInt(); \
  97. mode = SigProcessMode(ui->TriInX_Mode_Val_##index->currentText().toStdString()); \
  98. edge = TriggerEdge(ui->TriInX_TriggerModeTriggerEdge_Val_##index->currentText().toStdString()); \
  99. division = ui->TriInX_TriggerModeFreqDivision_Val_##index->text().toUInt(); \
  100. multiplication = ui->TriInX_TriggerModeFreqMultiplication_Val_##index->text().toUInt(); \
  101. DO(m_clstc->TriInX_setSrcSelect(index, src)); \
  102. DO(m_clstc->TriInX_setFileterCoefficient(index, coefficient)); \
  103. DO(m_clstc->TriInX_setFreqDetectBias(index, bias)); \
  104. DO(m_clstc->TriInX_setMode(index, mode)); \
  105. DO(m_clstc->TriInX_setTriggerModeTriggerEdge(index, edge)); \
  106. DO(m_clstc->TriInX_setTriggerModeFreqDivision(index, division)); \
  107. DO(m_clstc->TriInX_setTriggerModeFreqMultiplication(index, multiplication));
  108. UPDATE(1);
  109. UPDATE(2);
  110. UPDATE(3);
  111. UPDATE(4);
  112. #undef UPDATE
  113. }
  114. {
  115. InternalSig src;
  116. uint32_t width;
  117. uint32_t offset;
  118. float duty;
  119. float freq;
  120. #define UPDATE(index) \
  121. src = InternalSig(ui->LightSrcX_TriSrc_##index->currentText().toStdString()); \
  122. width = ui->LightSrcX_TriggerModePluseWidth_##index->text().toUInt(); \
  123. offset = ui->LightSrcX_TriggerModeFirstPluseOffset_##index->text().toUInt(); \
  124. duty = ui->LightSrcX_LightIntensityDuty_##index->text().toFloat(); \
  125. freq = ui->LightSrcX_LightDriverFreq_##index->text().toFloat(); \
  126. DO(m_clstc->LightSrcX_setTriSrc(index, src)); \
  127. DO(m_clstc->LightSrcX_setTriggerModePluseWidth(index, width)); \
  128. DO(m_clstc->LightSrcX_setTriggerModeFirstPluseOffset(index, offset)); \
  129. DO(m_clstc->LightSrcX_setLightIntensityDuty(index, duty)); \
  130. DO(m_clstc->LightSrcX_setLightDriverFreq(index, freq));
  131. UPDATE(1);
  132. UPDATE(2);
  133. UPDATE(3);
  134. UPDATE(4);
  135. }
  136. {
  137. SigProcessMode mode;
  138. uint32_t offset;
  139. uint32_t bindstate1;
  140. uint32_t bindstate2;
  141. uint32_t bindstate3;
  142. uint32_t bindstate4;
  143. InternalSig sig;
  144. #define UPDATE(index) \
  145. mode = SigProcessMode(ui->ShutterX_OutputCtrlMode_##index->currentText().toStdString()); \
  146. offset = ui->ShutterX_LtEnOffset_##index->text().toUInt(); \
  147. bindstate1 = ui->ShutterX_LtEnBind_val1_##index->checkState() == Qt::CheckState::Checked; \
  148. bindstate2 = ui->ShutterX_LtEnBind_val2_##index->checkState() == Qt::CheckState::Checked; \
  149. bindstate3 = ui->ShutterX_LtEnBind_val3_##index->checkState() == Qt::CheckState::Checked; \
  150. bindstate4 = ui->ShutterX_LtEnBind_val4_##index->checkState() == Qt::CheckState::Checked; \
  151. sig = InternalSig(ui->ShutterX_InSigSelect_##index->currentText().toStdString()); \
  152. DO(m_clstc->ShutterX_setOutputCtrlMode(index, mode)); \
  153. DO(m_clstc->ShutterX_setLtEnOffset(index, offset)); \
  154. DO(m_clstc->ShutterX_setLtEnBind(index, 1, bindstate1)); \
  155. DO(m_clstc->ShutterX_setLtEnBind(index, 2, bindstate2)); \
  156. DO(m_clstc->ShutterX_setLtEnBind(index, 3, bindstate3)); \
  157. DO(m_clstc->ShutterX_setLtEnBind(index, 4, bindstate4)); \
  158. DO(m_clstc->ShutterX_setInSigSelect(index, sig));
  159. UPDATE(1);
  160. UPDATE(2);
  161. UPDATE(3);
  162. UPDATE(4);
  163. }
  164. }
  165. void MainWindow::refreshReadonlyPage0() {
  166. zaf_error_code_t ecode;
  167. if (!G_QTDataChannel.isOpen()) {
  168. return;
  169. }
  170. {
  171. float TriOutSignalFreq;
  172. DO(m_clstc->InterClk_readTriOutSignalFreq(TriOutSignalFreq));
  173. ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2));
  174. }
  175. }
  176. void MainWindow::refreshReadonlyPage1() {
  177. if (!G_QTDataChannel.isOpen()) {
  178. return;
  179. }
  180. {
  181. float infreq;
  182. float outfreq;
  183. #define UPDATE(index) \
  184. DO(m_clstc->TriInX_readInSignalFreq(index, infreq)); \
  185. DO(m_clstc->TriInX_readOutSignalFreq(index, outfreq)); \
  186. ui->TriInX_OutSignalFreq_Val_##index->setText(QString::number(outfreq, 'f', 2)); \
  187. ui->TriInX_InSignalFreq_Val_##index->setText(QString::number(infreq, 'f', 2));
  188. UPDATE(1);
  189. UPDATE(2);
  190. UPDATE(3);
  191. UPDATE(4);
  192. #undef UPDATE
  193. }
  194. }
  195. void MainWindow::refreshReadonlyPage2() {
  196. if (!G_QTDataChannel.isOpen()) {
  197. return;
  198. }
  199. // 刷新光源时序控制页面
  200. {
  201. float infreq;
  202. float outfreq;
  203. uint32_t state;
  204. #define UPDATE(index) \
  205. DO(m_clstc->LightSrcX_readInSigFreqDetect(index, infreq)); \
  206. DO(m_clstc->LightSrcX_readOutSigFreqDetect(index, outfreq)); \
  207. DO(m_clstc->LightSrcX_readLightSrcErrorState(index, state)); \
  208. ui->LightSrcX_InSigFreqDetect_##index->setText(QString::number(infreq, 'f', 2)); \
  209. ui->LightSrcX_OutSigFreqDetect_##index->setText(QString::number(outfreq, 'f', 2)); \
  210. ui->LightSrcX_LightSrcErrorState_##index->setText(QString::number(state));
  211. UPDATE(1);
  212. UPDATE(2);
  213. UPDATE(3);
  214. UPDATE(4);
  215. }
  216. }
  217. bool MainWindow::checkConnected() {
  218. if (!G_QTDataChannel.isOpen()) {
  219. return false;
  220. }
  221. uint32_t val;
  222. zaf_error_code_t ecode = m_clstc->reg_read(kreg_software_version, val);
  223. if (ecode != kaf_ec_success) {
  224. return false;
  225. }
  226. return true;
  227. }
  228. void MainWindow::refreshReadonlyPage3() {
  229. if (!G_QTDataChannel.isOpen()) {
  230. return;
  231. }
  232. }
  233. void MainWindow::refreshPage() {
  234. /*******************************************************************************
  235. * *
  236. *******************************************************************************/
  237. {
  238. float Freq;
  239. uint32_t PluseCnt;
  240. uint32_t SeqCtrlPluseCntMax;
  241. float TriOutSignalFreq;
  242. DO(m_clstc->InterClk_getFreq(Freq));
  243. DO(m_clstc->InterClk_getPluseCnt(PluseCnt));
  244. DO(m_clstc->InterClk_getSeqCtrlPluseCntMax(SeqCtrlPluseCntMax));
  245. DO(m_clstc->InterClk_readTriOutSignalFreq(TriOutSignalFreq));
  246. ui->InterClk_Freq_Text->setText(QString::number(Freq, 'f', 2));
  247. ui->InterClk_PluseCnt_Text->setText(QString::number(PluseCnt));
  248. ui->InterClk_SeqCtrlPluseCntMax_Text->setText(QString::number(SeqCtrlPluseCntMax));
  249. ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2));
  250. }
  251. /*******************************************************************************
  252. * *
  253. *******************************************************************************/
  254. {
  255. ExtTriggerSrcType src;
  256. SigProcessMode mode;
  257. TriggerEdge edge;
  258. uint32_t coefficient;
  259. uint32_t bias;
  260. uint32_t division;
  261. uint32_t multiplication;
  262. float infreq;
  263. float outfreq;
  264. #define UPDATE(index) \
  265. DO(m_clstc->TriInX_getSrcSelect(index, src)); \
  266. DO(m_clstc->TriInX_getFileterCoefficient(index, coefficient)); \
  267. DO(m_clstc->TriInX_getFreqDetectBias(index, bias)); \
  268. DO(m_clstc->TriInX_getMode(index, mode)); \
  269. DO(m_clstc->TriInX_getTriggerModeTriggerEdge(index, edge)); \
  270. DO(m_clstc->TriInX_getTriggerModeFreqDivision(index, division)); \
  271. DO(m_clstc->TriInX_getTriggerModeFreqMultiplication(index, multiplication)); \
  272. DO(m_clstc->TriInX_readInSignalFreq(index, infreq)); \
  273. DO(m_clstc->TriInX_readOutSignalFreq(index, outfreq)); \
  274. ui->TriInX_SrcSelect_Val_##index->setCurrentText(QString::fromStdString(src.toString())); \
  275. ui->TriInX_FileterCoefficient_Val_##index->setText(QString::number(coefficient)); \
  276. ui->TriInX_FreqDetectBias_Val_##index->setText(QString::number(bias)); \
  277. ui->TriInX_Mode_Val_##index->setCurrentText(QString::fromStdString(mode.toString())); \
  278. ui->TriInX_OutSignalFreq_Val_##index->setText(QString::number(outfreq, 'f', 2)); \
  279. ui->TriInX_InSignalFreq_Val_##index->setText(QString::number(infreq, 'f', 2)); \
  280. ui->TriInX_TriggerModeFreqDivision_Val_##index->setText(QString::number(division)); \
  281. ui->TriInX_TriggerModeFreqMultiplication_Val_##index->setText(QString::number(multiplication)); \
  282. ui->TriInX_TriggerModeTriggerEdge_Val_##index->setCurrentText(QString::fromStdString(edge.toString()));
  283. UPDATE(1);
  284. UPDATE(2);
  285. UPDATE(3);
  286. UPDATE(4);
  287. #undef UPDATE
  288. }
  289. // 刷新光源时序控制页面
  290. {
  291. InternalSig src;
  292. uint32_t width;
  293. uint32_t offset;
  294. float duty;
  295. float freq;
  296. uint32_t state;
  297. float infreq;
  298. float outfreq;
  299. #define UPDATE(index) \
  300. DO(m_clstc->LightSrcX_getTriSrc(index, src)); \
  301. DO(m_clstc->LightSrcX_getTriggerModePluseWidth(index, width)); \
  302. DO(m_clstc->LightSrcX_getTriggerModeFirstPluseOffset(index, offset)); \
  303. DO(m_clstc->LightSrcX_getLightIntensityDuty(index, duty)); \
  304. DO(m_clstc->LightSrcX_getLightDriverFreq(index, freq)); \
  305. DO(m_clstc->LightSrcX_readLightSrcErrorState(index, state)); \
  306. DO(m_clstc->LightSrcX_readInSigFreqDetect(index, infreq)); \
  307. DO(m_clstc->LightSrcX_readOutSigFreqDetect(index, outfreq)); \
  308. ui->LightSrcX_TriSrc_##index->setCurrentText(QString::fromStdString(src.toString())); \
  309. ui->LightSrcX_TriggerModePluseWidth_##index->setText(QString::number(width)); \
  310. ui->LightSrcX_TriggerModeFirstPluseOffset_##index->setText(QString::number(offset)); \
  311. ui->LightSrcX_LightIntensityDuty_##index->setText(QString::number(duty, 'f', 2)); \
  312. ui->LightSrcX_LightDriverFreq_##index->setText(QString::number(freq, 'f', 2)); \
  313. ui->LightSrcX_LightSrcErrorState_##index->setText(QString::number(state)); \
  314. ui->LightSrcX_InSigFreqDetect_##index->setText(QString::number(infreq, 'f', 2)); \
  315. ui->LightSrcX_OutSigFreqDetect_##index->setText(QString::number(outfreq, 'f', 2));
  316. UPDATE(1);
  317. UPDATE(2);
  318. UPDATE(3);
  319. UPDATE(4);
  320. }
  321. {
  322. SigProcessMode mode;
  323. uint32_t offset;
  324. uint32_t bindstate1;
  325. uint32_t bindstate2;
  326. uint32_t bindstate3;
  327. uint32_t bindstate4;
  328. InternalSig sig;
  329. #define UPDATE(index) \
  330. DO(m_clstc->ShutterX_getOutputCtrlMode(index, mode)); \
  331. DO(m_clstc->ShutterX_getLtEnOffset(index, offset)); \
  332. DO(m_clstc->ShutterX_getLtEnBind(index, 1, bindstate1)); \
  333. DO(m_clstc->ShutterX_getLtEnBind(index, 2, bindstate2)); \
  334. DO(m_clstc->ShutterX_getLtEnBind(index, 3, bindstate3)); \
  335. DO(m_clstc->ShutterX_getLtEnBind(index, 4, bindstate4)); \
  336. DO(m_clstc->ShutterX_getInSigSelect(index, sig)); \
  337. ui->ShutterX_OutputCtrlMode_##index->setCurrentText(QString::fromStdString(mode.toString())); \
  338. ui->ShutterX_LtEnOffset_##index->setText(QString::number(offset)); \
  339. ui->ShutterX_LtEnBind_val1_##index->setChecked(bindstate1 != 0 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); \
  340. ui->ShutterX_LtEnBind_val2_##index->setChecked(bindstate2 != 0 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); \
  341. ui->ShutterX_LtEnBind_val3_##index->setChecked(bindstate3 != 0 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); \
  342. ui->ShutterX_LtEnBind_val4_##index->setChecked(bindstate4 != 0 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); \
  343. ui->ShutterX_InSigSelect_##index->setCurrentText(QString::fromStdString(sig.toString()));
  344. // ui->ShutterX_LtEnBind_val1_1->checkState()
  345. UPDATE(1);
  346. UPDATE(2);
  347. UPDATE(3);
  348. UPDATE(4);
  349. }
  350. }
  351. void MainWindow::constructUI() {
  352. /*******************************************************************************
  353. * serialPortCB *
  354. *******************************************************************************/
  355. const auto infos = QSerialPortInfo::availablePorts();
  356. for (const QSerialPortInfo &info : infos) {
  357. ui->serialPortCB->addItem(info.portName());
  358. }
  359. /*******************************************************************************
  360. * ?? *
  361. *******************************************************************************/
  362. ui->serialBaudrateCB->addItem("9600");
  363. ui->serialBaudrateCB->addItem("14400");
  364. ui->serialBaudrateCB->addItem("19200");
  365. ui->serialBaudrateCB->addItem("38400");
  366. ui->serialBaudrateCB->addItem("57600");
  367. ui->serialBaudrateCB->addItem("115200");
  368. ui->serialBaudrateCB->addItem("500000");
  369. ui->serialBaudrateCB->setCurrentIndex(6);
  370. /*******************************************************************************
  371. * *
  372. *******************************************************************************/
  373. connect(ui->serialPortRefreshKey, &QPushButton::clicked, this, [this](bool check) {
  374. ui->serialPortCB->clear();
  375. const auto infos = QSerialPortInfo::availablePorts();
  376. for (const QSerialPortInfo &info : infos) {
  377. ui->serialPortCB->addItem(info.portName());
  378. }
  379. });
  380. /*******************************************************************************
  381. * *
  382. *******************************************************************************/
  383. connect(ui->serialOpenKey, &QPushButton::clicked, this, [=](bool check) {
  384. // 打开串口
  385. if (ui->serialOpenKey->text() == "打开") {
  386. G_QTDataChannel.setPortName(ui->serialPortCB->currentText().toStdString());
  387. G_QTDataChannel.setBaudRate(ui->serialBaudrateCB->currentText().toInt());
  388. G_QTDataChannel.setDataBits(QSerialPort::Data8);
  389. G_QTDataChannel.setParity(QSerialPort::NoParity);
  390. G_QTDataChannel.setFlowControl(QSerialPort::NoFlowControl);
  391. G_QTDataChannel.setStopBits(QSerialPort::OneStop);
  392. if (!G_QTDataChannel.open()) {
  393. QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占??");
  394. return;
  395. }
  396. ui->serialOpenKey->setText("关闭");
  397. // 下拉菜单控件使能
  398. ui->serialBaudrateCB->setEnabled(false);
  399. ui->serialPortCB->setEnabled(false);
  400. ui->serialPortRefreshKey->setEnabled(false);
  401. } else {
  402. G_QTDataChannel.close();
  403. ui->serialOpenKey->setText("打开");
  404. ui->serialBaudrateCB->setEnabled(true);
  405. ui->serialPortCB->setEnabled(true);
  406. ui->serialPortRefreshKey->setEnabled(true);
  407. }
  408. });
  409. /*******************************************************************************
  410. * *
  411. *******************************************************************************/
  412. connect(ui->refreshPageKey, &QPushButton::clicked, this, [=](bool check) { //
  413. refreshPage();
  414. dumpLog("刷新成功");
  415. });
  416. connect(ui->UpdateCfg_Key, &QPushButton::clicked, this, [=](bool check) { //
  417. updatePage();
  418. refreshPage();
  419. dumpLog("提交成功");
  420. });
  421. /*******************************************************************************
  422. * *
  423. *******************************************************************************/
  424. connect(ui->storageConfigKey, &QPushButton::clicked, this, [=](bool check) { //
  425. DO(m_clstc->storageConfigs());
  426. dumpLog("保存配置成功");
  427. });
  428. /*******************************************************************************
  429. * *
  430. *******************************************************************************/
  431. connect(ui->rebootDeviceKey, &QPushButton::clicked, this, [=](bool check) { //
  432. DO(m_clstc->reboot());
  433. dumpLog("重启设备成功");
  434. });
  435. /*******************************************************************************
  436. * *
  437. *******************************************************************************/
  438. connect(ui->factoryResetKey, &QPushButton::clicked, this, [=](bool check) { //
  439. DO(m_clstc->factoryReset());
  440. dumpLog("恢复出厂设置成功");
  441. });
  442. /*******************************************************************************
  443. * ?? *
  444. *******************************************************************************/
  445. ui->RegAdd->setText("0x00000000");
  446. connect(ui->regReadKey, &QPushButton::clicked, this, [=](bool check) { //
  447. uint32_t addr = str2int(ui->RegAdd->text());
  448. uint32_t value = 0;
  449. DO(m_clstc->reg_read(addr, value, 100));
  450. ui->regReadbakVal->setText(fmt("0x%08X", value));
  451. dumpLog(fmt("读取0x%04x成功", addr));
  452. });
  453. connect(ui->regWriteKey, &QPushButton::clicked, this, [=](bool check) { //
  454. uint32_t addr = str2int(ui->RegAdd->text());
  455. uint32_t value = str2int(ui->regWriteVal->text());
  456. uint32_t readkbak = 0;
  457. DO(m_clstc->reg_write(addr, value, readkbak, 100));
  458. ui->regReadbakVal->setText(fmt("0x%04x", readkbak));
  459. dumpLog(fmt("写入0x%08x成功", addr));
  460. });
  461. connect(ui->InterClk_trigger_Key, &QPushButton::clicked, this, [=](bool check) { //
  462. DO(m_clstc->InterClk_trigger());
  463. dumpLog(fmt("触发成功"));
  464. });
  465. connect(ui->InterClk_stop_Key, &QPushButton::clicked, this, [=](bool check) { //
  466. DO(m_clstc->InterClk_stop());
  467. dumpLog(fmt("停止触发成功"));
  468. });
  469. /*******************************************************************************
  470. * *
  471. *******************************************************************************/
  472. ui->TriInX_SrcSelect_Val_1->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  473. ui->TriInX_SrcSelect_Val_1->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  474. ui->TriInX_Mode_Val_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  475. ui->TriInX_Mode_Val_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  476. ui->TriInX_TriggerModeTriggerEdge_Val_1->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  477. ui->TriInX_TriggerModeTriggerEdge_Val_1->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  478. ui->TriInX_SrcSelect_Val_2->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  479. ui->TriInX_SrcSelect_Val_2->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  480. ui->TriInX_Mode_Val_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  481. ui->TriInX_Mode_Val_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  482. ui->TriInX_TriggerModeTriggerEdge_Val_2->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  483. ui->TriInX_TriggerModeTriggerEdge_Val_2->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  484. ui->TriInX_SrcSelect_Val_3->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  485. ui->TriInX_SrcSelect_Val_3->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  486. ui->TriInX_Mode_Val_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  487. ui->TriInX_Mode_Val_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  488. ui->TriInX_TriggerModeTriggerEdge_Val_3->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  489. ui->TriInX_TriggerModeTriggerEdge_Val_3->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  490. ui->TriInX_SrcSelect_Val_4->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  491. ui->TriInX_SrcSelect_Val_4->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  492. ui->TriInX_Mode_Val_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  493. ui->TriInX_Mode_Val_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  494. ui->TriInX_TriggerModeTriggerEdge_Val_4->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  495. ui->TriInX_TriggerModeTriggerEdge_Val_4->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  496. ui->TriInX_InSignalFreq_Val_1->setDisabled(true);
  497. ui->TriInX_InSignalFreq_Val_2->setDisabled(true);
  498. ui->TriInX_InSignalFreq_Val_3->setDisabled(true);
  499. ui->TriInX_InSignalFreq_Val_4->setDisabled(true);
  500. ui->TriInX_OutSignalFreq_Val_1->setDisabled(true);
  501. ui->TriInX_OutSignalFreq_Val_2->setDisabled(true);
  502. ui->TriInX_OutSignalFreq_Val_3->setDisabled(true);
  503. ui->TriInX_OutSignalFreq_Val_4->setDisabled(true);
  504. /*******************************************************************************
  505. * *
  506. *******************************************************************************/
  507. QStringList LightSrcX_TriSrc_QStringList;
  508. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::LOGIC0).toString()));
  509. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::LOGIC1).toString()));
  510. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER).toString()));
  511. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I1).toString()));
  512. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I2).toString()));
  513. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I3).toString()));
  514. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I4).toString()));
  515. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1).toString()));
  516. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I1).toString()));
  517. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I2).toString()));
  518. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I3).toString()));
  519. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I4).toString()));
  520. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2).toString()));
  521. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I1).toString()));
  522. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I2).toString()));
  523. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I3).toString()));
  524. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I4).toString()));
  525. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3).toString()));
  526. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I1).toString()));
  527. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I2).toString()));
  528. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I3).toString()));
  529. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I4).toString()));
  530. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4).toString()));
  531. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I1).toString()));
  532. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I2).toString()));
  533. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I3).toString()));
  534. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I4).toString()));
  535. ui->LightSrcX_TriSrc_1->addItems(LightSrcX_TriSrc_QStringList);
  536. ui->LightSrcX_TriSrc_2->addItems(LightSrcX_TriSrc_QStringList);
  537. ui->LightSrcX_TriSrc_3->addItems(LightSrcX_TriSrc_QStringList);
  538. ui->LightSrcX_TriSrc_4->addItems(LightSrcX_TriSrc_QStringList);
  539. ui->LightSrcX_InSigFreqDetect_1->setDisabled(true);
  540. ui->LightSrcX_InSigFreqDetect_2->setDisabled(true);
  541. ui->LightSrcX_InSigFreqDetect_3->setDisabled(true);
  542. ui->LightSrcX_InSigFreqDetect_4->setDisabled(true);
  543. ui->LightSrcX_OutSigFreqDetect_1->setDisabled(true);
  544. ui->LightSrcX_OutSigFreqDetect_2->setDisabled(true);
  545. ui->LightSrcX_OutSigFreqDetect_3->setDisabled(true);
  546. ui->LightSrcX_OutSigFreqDetect_4->setDisabled(true);
  547. ui->LightSrcX_LightSrcErrorState_1->setDisabled(true);
  548. ui->LightSrcX_LightSrcErrorState_2->setDisabled(true);
  549. ui->LightSrcX_LightSrcErrorState_3->setDisabled(true);
  550. ui->LightSrcX_LightSrcErrorState_4->setDisabled(true);
  551. ui->LightSrcX_LightDriverFreq_1->setDisabled(true);
  552. ui->LightSrcX_LightDriverFreq_2->setDisabled(true);
  553. ui->LightSrcX_LightDriverFreq_3->setDisabled(true);
  554. ui->LightSrcX_LightDriverFreq_4->setDisabled(true);
  555. /*******************************************************************************
  556. * *
  557. *******************************************************************************/
  558. ui->ShutterX_OutputCtrlMode_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  559. ui->ShutterX_OutputCtrlMode_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  560. ui->ShutterX_OutputCtrlMode_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  561. ui->ShutterX_OutputCtrlMode_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  562. ui->ShutterX_OutputCtrlMode_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  563. ui->ShutterX_OutputCtrlMode_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  564. ui->ShutterX_OutputCtrlMode_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  565. ui->ShutterX_OutputCtrlMode_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  566. ui->ShutterX_InSigSelect_1->addItems(LightSrcX_TriSrc_QStringList);
  567. ui->ShutterX_InSigSelect_2->addItems(LightSrcX_TriSrc_QStringList);
  568. ui->ShutterX_InSigSelect_3->addItems(LightSrcX_TriSrc_QStringList);
  569. ui->ShutterX_InSigSelect_4->addItems(LightSrcX_TriSrc_QStringList);
  570. ui->InterClk_TriOutSignalFreq_Text->setDisabled(true);
  571. }
  572. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
  573. // G_SerialPort.moveToThread();
  574. // QObject::connect(&G_SerialPortThread, &QThread::started, &G_SerialPort, &QSerialPort::open);
  575. G_QTDataChannel.init();
  576. CLSTControler::ins()->initialize(&G_QTDataChannel);
  577. m_clstc = CLSTControler::ins();
  578. ui->setupUi(this);
  579. m_mainWindow = this;
  580. qRegisterMetaType<int32_t>("int32_t");
  581. qRegisterMetaType<uint32_t>("uint32_t");
  582. qRegisterMetaType<function<void()>>("function<void()>");
  583. qRegisterMetaType<QFunction>("QFunction");
  584. // qInstallMessageHandler(log_output);
  585. connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction)));
  586. constructUI();
  587. // 创建定时器
  588. timer0 = new QTimer(this);
  589. timer1 = new QTimer(this);
  590. timer2 = new QTimer(this);
  591. timer3 = new QTimer(this);
  592. checkConnectTimer0 = new QTimer(this);
  593. connect(timer0, &QTimer::timeout, this, [this]() { refreshReadonlyPage0(); });
  594. connect(timer1, &QTimer::timeout, this, [this]() { refreshReadonlyPage1(); });
  595. connect(timer2, &QTimer::timeout, this, [this]() { refreshReadonlyPage2(); });
  596. connect(timer3, &QTimer::timeout, this, [this]() { refreshReadonlyPage3(); });
  597. connect(checkConnectTimer0, &QTimer::timeout, this, [this]() { //
  598. static bool connected = false;
  599. bool connect = checkConnected();
  600. if (connect) {
  601. ui->DeviceConnectStateTB->setText("已连接");
  602. ui->DeviceConnectStateTB->setStyleSheet("color: green");
  603. } else {
  604. ui->DeviceConnectStateTB->setText("未连接");
  605. ui->DeviceConnectStateTB->setStyleSheet("color: red");
  606. }
  607. if (connected != connect) {
  608. connected = connect;
  609. if (connected) {
  610. refreshPage();
  611. }
  612. }
  613. });
  614. timer0->setInterval(1100); // 每隔一秒触发一次
  615. timer1->setInterval(1200); // 每隔一秒触发一次
  616. timer2->setInterval(900); // 每隔一秒触发一次
  617. timer3->setInterval(1000); // 每隔一秒触发一次
  618. checkConnectTimer0->setInterval(100);
  619. timer0->start();
  620. timer1->start();
  621. timer2->start();
  622. timer3->start();
  623. checkConnectTimer0->start();
  624. // m_clstc->regRawDataListener([this](uart_message_type_t type, uint8_t *data, size_t len) {
  625. // QString text;
  626. // if (type == kuart_raw_tx) {
  627. // text.append("TX: ");
  628. // for (size_t i = 0; i < len; i++) {
  629. // text.append(fmt("%02X ", data[i]));
  630. // }
  631. // } else if (type == kuart_raw_rx) {
  632. // text.append("RX: ");
  633. // for (size_t i = 0; i < len; i++) {
  634. // text.append(fmt("%02X ", data[i]));
  635. // }
  636. // }
  637. // emit doinui_signal(QFunction([this, text]() {
  638. // if (ui->instructionPreview->document()->lineCount() > 100) {
  639. // ui->instructionPreview->document()->clear();
  640. // }
  641. // ui->instructionPreview->append(text);
  642. // }));
  643. // });
  644. }
  645. void MainWindow::dumpLog(const char *fmt, ...) {
  646. va_list args;
  647. va_start(args, fmt);
  648. char buf[1024] = {0};
  649. vsnprintf(buf, sizeof(buf), fmt, args);
  650. qDebug() << buf;
  651. va_end(args);
  652. QString text(buf);
  653. QString info;
  654. // zos_get_ticket
  655. info.append(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"));
  656. info.append(" [Info]:");
  657. info.append(text);
  658. emit doinui_signal(QFunction([this, info]() {
  659. if (ui->instructionPreview->document()->lineCount() > 100) {
  660. ui->instructionPreview->document()->clear();
  661. }
  662. ui->instructionPreview->append(info);
  663. }));
  664. }
  665. MainWindow::~MainWindow() { delete ui; }