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.

499 lines
24 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "mainwindow.h"
  2. #include <QDateTime>
  3. #include <QtConcurrent>
  4. #include "./ui_mainwindow.h"
  5. using namespace iflytop;
  6. using namespace xsync;
  7. using namespace std;
  8. static MainWindow *m_mainWindow;
  9. #define TAG "MainWindow"
  10. static const char *fmt(const char *fmt, ...) {
  11. va_list args;
  12. va_start(args, fmt);
  13. static char buf[1024] = {0};
  14. vsnprintf(buf, sizeof(buf), fmt, args);
  15. va_end(args);
  16. return buf;
  17. }
  18. static const uint32_t str2int(QString str) {
  19. // 如果0x开头,按16进制转换
  20. // 如果0b开头,按2进制转换
  21. // 否则按10进制转换
  22. // 去除掉str中_
  23. str.remove("_");
  24. if (str.startsWith("0x")) {
  25. return str.toUInt(nullptr, 16);
  26. } else if (str.startsWith("0b")) {
  27. // remove 0b
  28. str.remove(0, 2);
  29. return str.toUInt(nullptr, 2);
  30. } else {
  31. return str.toUInt(nullptr, 10);
  32. }
  33. }
  34. void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
  35. QString text;
  36. text.append(msg);
  37. m_mainWindow->append_log_signal(text);
  38. }
  39. void MainWindow::append_log_slot(QString text) { ui->logbrowser->append(text); }
  40. void MainWindow::updateUI_timeCodeInfo_slot(QString text) { ui->TimecodeDisplayer->setText(text); }
  41. void MainWindow::updateUI_cameraSyncInfo_slot(QString text) { ui->CameraSyncIndex->setText(text); }
  42. void MainWindow::updateUI_reg_slot(int32_t regadd, uint32_t regval) {
  43. auto it = m_regdisplayer.find(regadd);
  44. if (it != m_regdisplayer.end()) {
  45. ZLOGI(TAG, "updateUI_reg_slot %x %d", regadd, regval);
  46. it->second->regBrowser->setText(QString::number(regval, 16));
  47. }
  48. }
  49. void MainWindow::doinui_slot(QFunction func) {
  50. if (func.get()) func.get()();
  51. }
  52. void MainWindow::push_reg(QWidget *parent, int off, const char *regname, int32_t regadd, int32_t rwflag, reg_val_type_t regvaltype) {
  53. DispalyRegIterm *regitem = new DispalyRegIterm();
  54. regitem->regvaltype = regvaltype;
  55. {
  56. auto *label = new QLabel(parent);
  57. label->setObjectName(QString::fromUtf8("label"));
  58. label->setText(QString(fmt("%s(0x%04x)", regname, regadd)));
  59. QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Expanding);
  60. sizePolicy1.setHorizontalStretch(0);
  61. sizePolicy1.setVerticalStretch(0);
  62. sizePolicy1.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
  63. label->setSizePolicy(sizePolicy1);
  64. label->setMinimumSize(QSize(250, 0));
  65. label->setMaximumSize(QSize(16777215, 16777215));
  66. ui->reg_table->addWidget(label, off, 0, 1, 1);
  67. regitem->label = label;
  68. }
  69. {
  70. auto *textbrowser = new QTextBrowser(parent);
  71. textbrowser->setObjectName(QString::fromUtf8("textbrowser"));
  72. textbrowser->setEnabled(true);
  73. textbrowser->setText(QString("unset"));
  74. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  75. sizePolicy.setHorizontalStretch(0);
  76. sizePolicy.setVerticalStretch(0);
  77. sizePolicy.setHeightForWidth(textbrowser->sizePolicy().hasHeightForWidth());
  78. textbrowser->setSizePolicy(sizePolicy);
  79. textbrowser->setMaximumSize(QSize(16777215, 16777215));
  80. ui->reg_table->addWidget(textbrowser, off, 1, 1, 1);
  81. regitem->regBrowser = textbrowser;
  82. }
  83. {
  84. auto *textEdit = new QTextEdit(parent);
  85. textEdit->setObjectName(QString::fromUtf8("textEdit"));
  86. textEdit->setEnabled(true);
  87. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  88. sizePolicy.setHorizontalStretch(0);
  89. sizePolicy.setVerticalStretch(0);
  90. sizePolicy.setHeightForWidth(textEdit->sizePolicy().hasHeightForWidth());
  91. textEdit->setSizePolicy(sizePolicy);
  92. textEdit->setMaximumSize(QSize(16777215, 16777215));
  93. ui->reg_table->addWidget(textEdit, off, 2, 1, 1);
  94. regitem->regEditer = textEdit;
  95. }
  96. {
  97. // new button
  98. auto *button = new QPushButton(parent);
  99. button->setObjectName(QString::fromUtf8("button"));
  100. button->setText(QString("Write"));
  101. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  102. sizePolicy.setHorizontalStretch(0);
  103. sizePolicy.setVerticalStretch(0);
  104. sizePolicy.setHeightForWidth(button->sizePolicy().hasHeightForWidth());
  105. button->setSizePolicy(sizePolicy);
  106. // connect(this,
  107. connect(button, &QPushButton::clicked, [this, regadd](bool) { //
  108. QString regval_str = m_regdisplayer[regadd]->regEditer->toPlainText();
  109. uint32_t regval = str2int(regval_str);
  110. ZLOGI(TAG, "write reg 0x%04x %d", regadd, regval);
  111. uint32_t readbackval = 0;
  112. auto ecode = Xsync::Ins().reg_write(regadd, regval, readbackval);
  113. if (ecode == kxs_ec_success) {
  114. ZLOGI(TAG, "write reg 0x%04x %d success", regadd, regval);
  115. m_regdisplayer[regadd]->regvalcache = readbackval;
  116. updateUI_timeCodeInfo(regadd);
  117. } else {
  118. ZLOGE(TAG, "write reg 0x%04x %d fail,ecode:%s", regadd, regval, xs_error_code_2_str(ecode));
  119. }
  120. });
  121. regitem->writerButton = button;
  122. ui->reg_table->addWidget(button, off, 3, 1, 1);
  123. }
  124. m_regdisplayer[regadd] = regitem;
  125. }
  126. void MainWindow::updateUI_timeCodeInfo(uint32_t regoff) {
  127. // m_regdisplayer[regoff]->regBrowser->setText("0x" + QString::number(regValue, 16));
  128. uint32_t regval = m_regdisplayer[regoff]->regvalcache;
  129. auto *regBrowser = m_regdisplayer[regoff]->regBrowser;
  130. reg_val_type_t regvaltype = m_regdisplayer[regoff]->regvaltype;
  131. if (regvaltype == kreg_val_type_dotted_hex) {
  132. regBrowser->setText(QString(fmt("%02x.%02x.%02x.%02x", (regval >> 0) & 0xff, (regval >> 8) & 0xff, (regval >> 16) & 0xff, (regval >> 24) & 0xff)));
  133. } else if (regvaltype == kreg_val_type_dotted_decimal) {
  134. regBrowser->setText(QString(fmt("%d.%d.%d.%d", (regval >> 0) & 0xff, (regval >> 8) & 0xff, (regval >> 16) & 0xff, (regval >> 24) & 0xff)));
  135. } else if (regvaltype == kreg_val_type_str) {
  136. char text[5] = {0};
  137. memcpy(text, &regval, 4);
  138. regBrowser->setText(QString(text));
  139. } else if (regvaltype == kreg_val_type_hex) {
  140. regBrowser->setText(QString(fmt("0x%08x", regval)));
  141. } else if (regvaltype == kreg_val_type_decimal) {
  142. regBrowser->setText(QString::number(regval, 10));
  143. } else if (regvaltype == kreg_val_type_binary) {
  144. regBrowser->setText(QString::number(regval, 2));
  145. }
  146. }
  147. void MainWindow::construct_reg_table() { //
  148. int regoff = 1;
  149. push_reg(ui->gridLayoutWidget, regoff++, "software_version", reg::ksoftware_version, 0, kreg_val_type_dotted_decimal);
  150. push_reg(ui->gridLayoutWidget, regoff++, "manufacturer0", reg::kmanufacturer0, 0, kreg_val_type_str);
  151. push_reg(ui->gridLayoutWidget, regoff++, "manufacturer1", reg::kmanufacturer1, 0, kreg_val_type_str);
  152. push_reg(ui->gridLayoutWidget, regoff++, "product_type_id", reg::kproduct_type_id, 0, kreg_val_type_decimal);
  153. push_reg(ui->gridLayoutWidget, regoff++, "sn_id0", reg::ksn_id0, 0, kreg_val_type_dotted_hex);
  154. push_reg(ui->gridLayoutWidget, regoff++, "sn_id1", reg::ksn_id1, 0, kreg_val_type_dotted_hex);
  155. push_reg(ui->gridLayoutWidget, regoff++, "sn_id2", reg::ksn_id2, 0, kreg_val_type_dotted_hex);
  156. push_reg(ui->gridLayoutWidget, regoff++, "mac0", reg::kmac0, 0, kreg_val_type_dotted_hex);
  157. push_reg(ui->gridLayoutWidget, regoff++, "mac1", reg::kmac1, 0, kreg_val_type_dotted_hex);
  158. // reg::kstm32_ip
  159. // reg::kstm32_gw
  160. // reg::kstm32_netmask
  161. // reg::kstm32_camera_sync_signal_count
  162. push_reg(ui->gridLayoutWidget, regoff++, "stm32_ip", reg::kstm32_ip, 0, kreg_val_type_dotted_decimal);
  163. push_reg(ui->gridLayoutWidget, regoff++, "stm32_gw", reg::kstm32_gw, 0, kreg_val_type_dotted_decimal);
  164. push_reg(ui->gridLayoutWidget, regoff++, "stm32_netmask", reg::kstm32_netmask, 0, kreg_val_type_dotted_decimal);
  165. push_reg(ui->gridLayoutWidget, regoff++, "stm32_camera_sync_signal_count", reg::kstm32_camera_sync_signal_count, 0, kreg_val_type_decimal);
  166. push_reg(ui->gridLayoutWidget, regoff++, "fpga_reg_test_reg0", reg::kfpga_test_reg0, 0, kreg_val_type_hex);
  167. push_reg(ui->gridLayoutWidget, regoff++, "fpga_reg_test_reg1", reg::kfpga_test_reg1, 0, kreg_val_type_hex);
  168. push_reg(ui->gridLayoutWidget, regoff++, "fpga_reg_test_reg2", reg::kfpga_test_reg2, 0, kreg_val_type_hex);
  169. push_reg(ui->gridLayoutWidget, regoff++, "fpga_reg_test_reg3", reg::kfpga_test_reg3, 0, kreg_val_type_hex);
  170. push_reg(ui->gridLayoutWidget, regoff++, "fpga_reg_test_reg4", reg::kfpga_test_reg4, 0, kreg_val_type_hex);
  171. push_reg(ui->gridLayoutWidget, regoff++, "ttlout1_input_sig_slt", reg::kttlout1_input_sig_slt, 0, kreg_val_type_decimal);
  172. push_reg(ui->gridLayoutWidget, regoff++, "ttlout1_output_sig_slt", reg::kttlout1_output_sig_slt, 0, kreg_val_type_decimal);
  173. push_reg(ui->gridLayoutWidget, regoff++, "ttlout1_config", reg::kttlout1_config, 0, kreg_val_type_hex);
  174. push_reg(ui->gridLayoutWidget, regoff++, "ttlout1_pulse_mode_duration", reg::kttlout1_pulse_mode_duration, 0, kreg_val_type_decimal);
  175. push_reg(ui->gridLayoutWidget, regoff++, "ttlout1_pulse_mode_delay", reg::kttlout1_pulse_mode_delay, 0, kreg_val_type_decimal);
  176. push_reg(ui->gridLayoutWidget, regoff++, "ttlout2_input_sig_slt", reg::kttlout2_input_sig_slt, 0, kreg_val_type_decimal);
  177. push_reg(ui->gridLayoutWidget, regoff++, "ttlout2_output_sig_slt", reg::kttlout2_output_sig_slt, 0, kreg_val_type_decimal);
  178. push_reg(ui->gridLayoutWidget, regoff++, "ttlout2_config", reg::kttlout2_config, 0, kreg_val_type_hex);
  179. push_reg(ui->gridLayoutWidget, regoff++, "ttlout2_pulse_mode_duration", reg::kttlout2_pulse_mode_duration, 0, kreg_val_type_decimal);
  180. push_reg(ui->gridLayoutWidget, regoff++, "ttlout2_pulse_mode_delay", reg::kttlout2_pulse_mode_delay, 0, kreg_val_type_decimal);
  181. push_reg(ui->gridLayoutWidget, regoff++, "ttlout3_input_sig_slt", reg::kttlout3_input_sig_slt, 0, kreg_val_type_decimal);
  182. push_reg(ui->gridLayoutWidget, regoff++, "ttlout3_output_sig_slt", reg::kttlout3_output_sig_slt, 0, kreg_val_type_decimal);
  183. push_reg(ui->gridLayoutWidget, regoff++, "ttlout3_config", reg::kttlout3_config, 0, kreg_val_type_hex);
  184. push_reg(ui->gridLayoutWidget, regoff++, "ttlout3_pulse_mode_duration", reg::kttlout3_pulse_mode_duration, 0, kreg_val_type_decimal);
  185. push_reg(ui->gridLayoutWidget, regoff++, "ttlout3_pulse_mode_delay", reg::kttlout3_pulse_mode_delay, 0, kreg_val_type_decimal);
  186. push_reg(ui->gridLayoutWidget, regoff++, "ttlout4_input_sig_slt", reg::kttlout4_input_sig_slt, 0, kreg_val_type_decimal);
  187. push_reg(ui->gridLayoutWidget, regoff++, "ttlout4_output_sig_slt", reg::kttlout4_output_sig_slt, 0, kreg_val_type_decimal);
  188. push_reg(ui->gridLayoutWidget, regoff++, "ttlout4_config", reg::kttlout4_config, 0, kreg_val_type_hex);
  189. push_reg(ui->gridLayoutWidget, regoff++, "ttlout4_pulse_mode_duration", reg::kttlout4_pulse_mode_duration, 0, kreg_val_type_decimal);
  190. // kSigGenerator_ctl
  191. // kSigGenerator_genlock_format
  192. // kSigGenerator_timecode_format
  193. // kSigGenerator_control_trigger_reg
  194. // kSigGenerator_timecode0
  195. // kSigGenerator_timecode1
  196. // kSigGenerator_timecode_start0
  197. // kSigGenerator_timecode_start1
  198. // kSigGenerator_work_state
  199. push_reg(ui->gridLayoutWidget, regoff++, "SigGenerator_ctl", reg::kSigGenerator_ctl, 0, kreg_val_type_decimal);
  200. push_reg(ui->gridLayoutWidget, regoff++, "SigGenerator_genlock_format", reg::kSigGenerator_genlock_format, 0, kreg_val_type_decimal);
  201. push_reg(ui->gridLayoutWidget, regoff++, "SigGenerator_timecode_format", reg::kSigGenerator_timecode_format, 0, kreg_val_type_decimal);
  202. push_reg(ui->gridLayoutWidget, regoff++, "SigGenerator_control_trigger_reg", reg::kSigGenerator_control_trigger_reg, 0, kreg_val_type_decimal);
  203. push_reg(ui->gridLayoutWidget, regoff++, "SigGenerator_timecode0", reg::kSigGenerator_timecode0, 0, kreg_val_type_dotted_hex);
  204. push_reg(ui->gridLayoutWidget, regoff++, "SigGenerator_timecode1", reg::kSigGenerator_timecode1, 0, kreg_val_type_dotted_hex);
  205. push_reg(ui->gridLayoutWidget, regoff++, "SigGenerator_timecode_start0", reg::kSigGenerator_timecode_start0, 0, kreg_val_type_dotted_hex);
  206. push_reg(ui->gridLayoutWidget, regoff++, "SigGenerator_timecode_start1", reg::kSigGenerator_timecode_start1, 0, kreg_val_type_dotted_hex);
  207. push_reg(ui->gridLayoutWidget, regoff++, "SigGenerator_work_state", reg::kSigGenerator_work_state, 0, kreg_val_type_decimal);
  208. // 设置table的高度
  209. auto qrect = ui->gridLayoutWidget->geometry();
  210. qrect.setHeight(31 * regoff - 1);
  211. ui->gridLayoutWidget->setGeometry(qrect);
  212. }
  213. //
  214. void MainWindow::UI_TTLOutputMoudleConstruct() {
  215. ui->TTLOutputMoudle_ID->clear();
  216. for (int i = 1; i <= 4; i++) {
  217. ui->TTLOutputMoudle_ID->addItem(QString::number(i));
  218. }
  219. ui->TTLOutputMoudle_InputSigType->clear();
  220. for (auto &str : ttlout_module::TriggerSigTypeStrSet()) {
  221. ui->TTLOutputMoudle_InputSigType->addItem(QString::fromStdString(str));
  222. }
  223. ui->TTLOutputMoudle_OutputSigType->clear();
  224. for (auto &str : ttlout_module::OutputSigTypeStrSet()) {
  225. ui->TTLOutputMoudle_OutputSigType->addItem(QString::fromStdString(str));
  226. }
  227. }
  228. void MainWindow::UI_SigGeneratorConstruct() {
  229. ui->SigGenerator_ControlMode->clear();
  230. for (auto &str : sig_generator_module::ControlModeStrSet()) {
  231. ui->SigGenerator_ControlMode->addItem(QString::fromStdString(str));
  232. }
  233. ui->SigGenerator_GenlockFormat->clear();
  234. for (auto &str : GenlockFormatStrSet()) {
  235. ui->SigGenerator_GenlockFormat->addItem(QString::fromStdString(str));
  236. }
  237. ui->SigGenerator_TimecodeFormat->clear();
  238. for (auto &str : TimecodeFormatStrSet()) {
  239. ui->SigGenerator_TimecodeFormat->addItem(QString::fromStdString(str));
  240. }
  241. }
  242. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
  243. ui->setupUi(this);
  244. m_mainWindow = this;
  245. /**
  246. * @brief UI
  247. */
  248. construct_reg_table();
  249. qInstallMessageHandler(log_output);
  250. UI_TTLOutputMoudleConstruct();
  251. UI_SigGeneratorConstruct();
  252. /*******************************************************************************
  253. * *
  254. *******************************************************************************/
  255. qRegisterMetaType<int32_t>("int32_t");
  256. qRegisterMetaType<uint32_t>("uint32_t");
  257. qRegisterMetaType<function<void()>>("function<void()>");
  258. qRegisterMetaType<QFunction>("QFunction");
  259. XSyncUdpFactoryImpl::Ins()->initialize();
  260. connect(this, SIGNAL(append_log_signal(QString)), this, SLOT(append_log_slot(QString)));
  261. connect(this, SIGNAL(updateUI_timeCodeInfo_signal(QString)), this, SLOT(updateUI_timeCodeInfo_slot(QString)));
  262. connect(this, SIGNAL(updateUI_cameraSyncInfo_signal(QString)), this, SLOT(updateUI_cameraSyncInfo_slot(QString)));
  263. connect(this, SIGNAL(updateUI_reg_signal(int32_t, uint32_t)), this, SLOT(updateUI_reg_slot(int32_t, uint32_t)));
  264. connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction)));
  265. m_thread.reset(new ZQThread("test", [this]() { mainWindowsRun(); }));
  266. m_thread->start();
  267. // m_xsync.reset(new Xsync());
  268. Xsync::Ins().initialize(XSyncUdpFactoryImpl::Ins());
  269. Xsync::Ins().Basic_registerOnTimecodeMsgCallback([this](XsyncTimecode_t *timecode_msg) { //
  270. XsyncTimecode_t timecode = *timecode_msg;
  271. QString text = QString(fmt("%02d:%02d:%02d:%02d", timecode.hour, timecode.minute, timecode.second, timecode.frame));
  272. updateUI_timeCodeInfo_signal(text);
  273. });
  274. Xsync::Ins().Basic_registerOnCameraSyncMsgCallback([this](xysnc_camera_sync_data_t *camera_sync_msg) { //
  275. xysnc_camera_sync_data_t camera_sync_data = *camera_sync_msg;
  276. updateUI_cameraSyncInfo_signal(QString(fmt("%d", camera_sync_data.frameIndex)));
  277. });
  278. }
  279. MainWindow::~MainWindow() { delete ui; }
  280. #define XS_ASSERT(exptr) \
  281. { \
  282. auto ecode = exptr; \
  283. while (!(ecode == kxs_ec_success)) { \
  284. ZLOGE(TAG, "do: %s fail,ecode:%d", #exptr, ecode); \
  285. ZQThread::sleep(1); \
  286. } \
  287. }
  288. void MainWindow::on_RefreshRegsButton_clicked() { //
  289. ZLOGI(TAG, "on_refreshRegsButton_clicked");
  290. // int32_t _t1, uint32_t _t2
  291. QtConcurrent::run([this]() {
  292. bool suc = true;
  293. for (auto &reg : m_regdisplayer) {
  294. uint32_t regValue = 0;
  295. auto ecode = Xsync::Ins().reg_read(reg.first, regValue);
  296. int regoff = reg.first;
  297. if (ecode == kxs_ec_success) {
  298. ZLOGI(TAG, "reg_read %x success", reg.first);
  299. m_regdisplayer[regoff]->regvalcache = regValue;
  300. emit doinui_signal(QFunction([this, regoff, regValue]() { updateUI_timeCodeInfo(regoff); }));
  301. } else {
  302. emit doinui_signal(QFunction([this, regoff, regValue]() {
  303. m_regdisplayer[regoff]->regvalcache = 0;
  304. m_regdisplayer[regoff]->regBrowser->setText("error");
  305. }));
  306. }
  307. }
  308. });
  309. }
  310. void MainWindow::on_ClearLogButton_clicked() { //
  311. ui->logbrowser->clear();
  312. }
  313. void MainWindow::on_Connect2XsyncButton_clicked() { //
  314. ZLOGI(TAG, "connect %s", ui->IpInput->text().toStdString().c_str());
  315. xs_error_code_t ecode = Xsync::Ins().connect(ui->IpInput->text().toStdString());
  316. ZLOGI(TAG, "connect %s ecode:%s", ui->IpInput->text().toStdString().c_str(), xs_error_code_2_str(ecode));
  317. }
  318. void MainWindow::mainWindowsRun() { //
  319. // auto xsudp = XSyncUdpFactoryImpl::Ins()->createXSUDP();
  320. // XS_ASSERT(xsudp->initialize("0.0.0.0", 9999));
  321. // xsudp->startReceive([this, xsudp](XsyncNetAdd &from, uint8_t *data, size_t length) {
  322. // // ZLOGI(TAG, "receive from <%s:%d> (%d) :%s", from.ip.c_str(), from.port, data, length);
  323. // xsudp->sendto(from, "hello\n", 5, NULL);
  324. // });
  325. }
  326. #define DO_XSYNC_FUNC(exptr) \
  327. { \
  328. auto ecode = exptr; \
  329. if (!(ecode == kxs_ec_success)) { \
  330. ZLOGE(TAG, "do: %s fail,ecode:[%d](%s)", #exptr, ecode, xs_error_code_2_str(ecode)); \
  331. return; \
  332. } else { \
  333. ZLOGI(TAG, "do: %s success", #exptr); \
  334. } \
  335. }
  336. void MainWindow::on_GenNewMac_clicked() { DO_XSYNC_FUNC(Xsync::Ins().Basic_generatorNewMac()); }
  337. void MainWindow::on_FactoryReset_clicked() { DO_XSYNC_FUNC(Xsync::Ins().Basic_factoryReset()); }
  338. void MainWindow::on_Reboot_clicked() { DO_XSYNC_FUNC(Xsync::Ins().Basic_reboot()); }
  339. void MainWindow::on_ChangeNetCfg_clicked() { //
  340. DO_XSYNC_FUNC(Xsync::Ins().Basic_changeNetworkConfig(ui->ChangeNetCfg_ip->text().toStdString(), ui->ChangeNetCfg_mask->text().toStdString(), ui->ChangeNetCfg_gateway->text().toStdString()));
  341. }
  342. void MainWindow::on_WriteReg_clicked() {
  343. uint32_t regadd = str2int(ui->RegAdd->text());
  344. uint32_t regval = str2int(ui->RegVal->text());
  345. ZLOGI(TAG, "write reg 0x%08x %d", regadd, regval);
  346. uint32_t readbakval = 0;
  347. DO_XSYNC_FUNC(Xsync::Ins().reg_write(regadd, regval, readbakval));
  348. ZLOGI(TAG, "write reg 0x%08x 0x%08x ,readback:0x%08x success", regadd, regval, readbakval);
  349. ui->RegVal->setText(QString(fmt("0x%08x", readbakval)));
  350. }
  351. void MainWindow::on_ReadReg_clicked() {
  352. uint32_t regadd = str2int(ui->RegAdd->text());
  353. uint32_t regval = 0;
  354. DO_XSYNC_FUNC(Xsync::Ins().reg_read(regadd, regval));
  355. ZLOGI(TAG, "read reg 0x%08x 0x%08x success", regadd, regval);
  356. ui->RegVal->setText(QString(fmt("0x%08x", regval)));
  357. }
  358. void MainWindow::on_TTLOutputMoudle_Update_clicked() {
  359. int32_t ID = //
  360. ui->TTLOutputMoudle_ID->currentText().toInt();
  361. auto InputSigType = //
  362. ttlout_module::Str2TriggerSigType(ui->TTLOutputMoudle_InputSigType->currentText().toStdString());
  363. auto OutputSigType = //
  364. ttlout_module::Str2OutputSigType(ui->TTLOutputMoudle_OutputSigType->currentText().toStdString());
  365. uint32_t TriggerModePulseWidth = //
  366. ui->TTLOutputMoudle_TriggerModePulseWidth->text().toUInt();
  367. uint32_t TriggerModePulseDelay = //
  368. ui->TTLOutputMoudle_TriggerModePulseDelay->text().toUInt();
  369. ZLOGI(TAG, "on_TTLOutputMoudle_Update_clicked ID:%d InputSigType:%d OutputSigType:%d TriggerModePulseWidth:%d TriggerModePulseDelay:%d", //
  370. ID, InputSigType, OutputSigType, TriggerModePulseWidth, TriggerModePulseDelay);
  371. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_setInputSigType(ID, InputSigType));
  372. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_setOutputSigType(ID, OutputSigType));
  373. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_setTriggerModePulseWidth(ID, TriggerModePulseWidth));
  374. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_setTriggerModePulseDelay(ID, TriggerModePulseDelay));
  375. }
  376. void MainWindow::on_TTLOutputMoudle_Read_clicked() {
  377. ttlout_module::TriggerSigType_t InputSigType;
  378. ttlout_module::OutputSigType_t OutputSigType;
  379. uint32_t TriggerModePulseWidth;
  380. uint32_t TriggerModePulseDelay;
  381. int32_t ID = //
  382. ui->TTLOutputMoudle_ID->currentText().toInt();
  383. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_getInputSigType(ID, InputSigType));
  384. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_getOutputSigType(ID, OutputSigType));
  385. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_getTriggerModePulseWidth(ID, TriggerModePulseWidth));
  386. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_getTriggerModePulseDelay(ID, TriggerModePulseDelay));
  387. ui->TTLOutputMoudle_InputSigType->setCurrentText(QString::fromStdString(ttlout_module::TriggerSigType2Str(InputSigType)));
  388. ui->TTLOutputMoudle_OutputSigType->setCurrentText(QString::fromStdString(ttlout_module::OutputSigType2Str(OutputSigType)));
  389. ui->TTLOutputMoudle_TriggerModePulseWidth->setText(QString::number(TriggerModePulseWidth));
  390. ui->TTLOutputMoudle_TriggerModePulseDelay->setText(QString::number(TriggerModePulseDelay));
  391. }
  392. void MainWindow::on_SigGenerator_Read_clicked() {
  393. sig_generator_module::ControlMode_t ControlMode;
  394. GenlockFormat_t GenlockFormat;
  395. TimecodeFormat_t TimecodeFormat;
  396. XsyncTimecode_t Timecode;
  397. XsyncTimecode_t AutoStartTimecode;
  398. uint32_t WorkState;
  399. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getControlMode(ControlMode));
  400. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getGenlockFormat(GenlockFormat));
  401. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getTimecodeFormat(TimecodeFormat));
  402. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getTimecode(Timecode));
  403. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getAutoStartTimecode(AutoStartTimecode));
  404. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getWorkState(WorkState));
  405. ui->SigGenerator_ControlMode->setCurrentText(QString::fromStdString(sig_generator_module::ControlMode2Str(ControlMode)));
  406. ui->SigGenerator_GenlockFormat->setCurrentText(QString::fromStdString(GenlockFormatToStr(GenlockFormat)));
  407. ui->SigGenerator_TimecodeFormat->setCurrentText(QString::fromStdString(TimecodeFormatToStr(TimecodeFormat)));
  408. ui->SigGenerator_Timecode->setText(QString(XsyncTimecodeToStr(Timecode).c_str()));
  409. ui->SigGenerator_AutoStartTimecode->setText(QString(XsyncTimecodeToStr(AutoStartTimecode).c_str()));
  410. ui->SigGenerator_WorkState->setText(QString::number(WorkState));
  411. }
  412. void MainWindow::on_SigGenerator_Update_clicked() {
  413. auto ControlMode = sig_generator_module::Str2ControlMode(ui->SigGenerator_ControlMode->currentText().toStdString());
  414. auto GenlockFormat = Str2GenlockFormat(ui->SigGenerator_GenlockFormat->currentText().toStdString());
  415. auto TimecodeFormat = Str2TimecodeFormat(ui->SigGenerator_TimecodeFormat->currentText().toStdString());
  416. XsyncTimecode_t timecode = Str2XsyncTimecode(ui->SigGenerator_Timecode->text().toStdString());
  417. XsyncTimecode_t autoStartTimecode = Str2XsyncTimecode(ui->SigGenerator_AutoStartTimecode->text().toStdString());
  418. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setControlMode(ControlMode));
  419. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setGenlockFormat(GenlockFormat));
  420. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setTimecodeFormat(TimecodeFormat));
  421. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setTimecode(timecode));
  422. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setAutoStartTimecode(autoStartTimecode));
  423. }
  424. void MainWindow::on_SigGenerator_Start_clicked() {
  425. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_manualStart());
  426. }
  427. void MainWindow::on_SigGenerator_Stop_clicked() {
  428. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_manualStop());
  429. }