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.

553 lines
28 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
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. void MainWindow::UI_TimecodeOutputModuleConstruct() {
  243. ui->TimecodeOutputModule_TimecodeSrcSelect->clear();
  244. for (auto &str : timecode_output_module::TriggerSigTypeStrSet()) {
  245. ui->TimecodeOutputModule_TimecodeSrcSelect->addItem(QString::fromStdString(str));
  246. }
  247. ui->TimecodeOutputModule_BncOutputLevel->clear();
  248. for (auto &str : timecode_output_module::OutputSigLevelTypeStrSet()) {
  249. ui->TimecodeOutputModule_BncOutputLevel->addItem(QString::fromStdString(str));
  250. }
  251. ui->TimecodeOutputModule_HeadphoneOutputLevel->clear();
  252. for (auto &str : timecode_output_module::OutputSigLevelTypeStrSet()) {
  253. ui->TimecodeOutputModule_HeadphoneOutputLevel->addItem(QString::fromStdString(str));
  254. }
  255. ui->TimecodeOutputModule_TimecodeFormat->clear();
  256. for (auto &str : TimecodeFormatStrSet()) {
  257. ui->TimecodeOutputModule_TimecodeFormat->addItem(QString::fromStdString(str));
  258. }
  259. }
  260. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
  261. ui->setupUi(this);
  262. m_mainWindow = this;
  263. /**
  264. * @brief UI
  265. */
  266. construct_reg_table();
  267. qInstallMessageHandler(log_output);
  268. UI_TTLOutputMoudleConstruct();
  269. UI_SigGeneratorConstruct();
  270. UI_TimecodeOutputModuleConstruct();
  271. /*******************************************************************************
  272. * *
  273. *******************************************************************************/
  274. qRegisterMetaType<int32_t>("int32_t");
  275. qRegisterMetaType<uint32_t>("uint32_t");
  276. qRegisterMetaType<function<void()>>("function<void()>");
  277. qRegisterMetaType<QFunction>("QFunction");
  278. XSyncUdpFactoryImpl::Ins()->initialize();
  279. connect(this, SIGNAL(append_log_signal(QString)), this, SLOT(append_log_slot(QString)));
  280. connect(this, SIGNAL(updateUI_timeCodeInfo_signal(QString)), this, SLOT(updateUI_timeCodeInfo_slot(QString)));
  281. connect(this, SIGNAL(updateUI_cameraSyncInfo_signal(QString)), this, SLOT(updateUI_cameraSyncInfo_slot(QString)));
  282. connect(this, SIGNAL(updateUI_reg_signal(int32_t, uint32_t)), this, SLOT(updateUI_reg_slot(int32_t, uint32_t)));
  283. connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction)));
  284. m_thread.reset(new ZQThread("test", [this]() { mainWindowsRun(); }));
  285. m_thread->start();
  286. // m_xsync.reset(new Xsync());
  287. Xsync::Ins().initialize(XSyncUdpFactoryImpl::Ins());
  288. Xsync::Ins().Basic_registerOnTimecodeMsgCallback([this](XsyncTimecode_t *timecode_msg) { //
  289. XsyncTimecode_t timecode = *timecode_msg;
  290. QString text = QString(fmt("%02d:%02d:%02d:%02d", timecode.hour, timecode.minute, timecode.second, timecode.frame));
  291. updateUI_timeCodeInfo_signal(text);
  292. });
  293. Xsync::Ins().Basic_registerOnCameraSyncMsgCallback([this](xysnc_camera_sync_data_t *camera_sync_msg) { //
  294. xysnc_camera_sync_data_t camera_sync_data = *camera_sync_msg;
  295. updateUI_cameraSyncInfo_signal(QString(fmt("%d", camera_sync_data.frameIndex)));
  296. });
  297. }
  298. MainWindow::~MainWindow() { delete ui; }
  299. #define XS_ASSERT(exptr) \
  300. { \
  301. auto ecode = exptr; \
  302. while (!(ecode == kxs_ec_success)) { \
  303. ZLOGE(TAG, "do: %s fail,ecode:%d", #exptr, ecode); \
  304. ZQThread::sleep(1); \
  305. } \
  306. }
  307. void MainWindow::on_RefreshRegsButton_clicked() { //
  308. ZLOGI(TAG, "on_refreshRegsButton_clicked");
  309. // int32_t _t1, uint32_t _t2
  310. QtConcurrent::run([this]() {
  311. bool suc = true;
  312. for (auto &reg : m_regdisplayer) {
  313. uint32_t regValue = 0;
  314. auto ecode = Xsync::Ins().reg_read(reg.first, regValue);
  315. int regoff = reg.first;
  316. if (ecode == kxs_ec_success) {
  317. ZLOGI(TAG, "reg_read %x success", reg.first);
  318. m_regdisplayer[regoff]->regvalcache = regValue;
  319. emit doinui_signal(QFunction([this, regoff, regValue]() { updateUI_timeCodeInfo(regoff); }));
  320. } else {
  321. emit doinui_signal(QFunction([this, regoff, regValue]() {
  322. m_regdisplayer[regoff]->regvalcache = 0;
  323. m_regdisplayer[regoff]->regBrowser->setText("error");
  324. }));
  325. }
  326. }
  327. });
  328. }
  329. void MainWindow::on_ClearLogButton_clicked() { //
  330. ui->logbrowser->clear();
  331. }
  332. void MainWindow::on_Connect2XsyncButton_clicked() { //
  333. ZLOGI(TAG, "connect %s", ui->IpInput->text().toStdString().c_str());
  334. xs_error_code_t ecode = Xsync::Ins().connect(ui->IpInput->text().toStdString());
  335. ZLOGI(TAG, "connect %s ecode:%s", ui->IpInput->text().toStdString().c_str(), xs_error_code_2_str(ecode));
  336. }
  337. void MainWindow::mainWindowsRun() { //
  338. // auto xsudp = XSyncUdpFactoryImpl::Ins()->createXSUDP();
  339. // XS_ASSERT(xsudp->initialize("0.0.0.0", 9999));
  340. // xsudp->startReceive([this, xsudp](XsyncNetAdd &from, uint8_t *data, size_t length) {
  341. // // ZLOGI(TAG, "receive from <%s:%d> (%d) :%s", from.ip.c_str(), from.port, data, length);
  342. // xsudp->sendto(from, "hello\n", 5, NULL);
  343. // });
  344. }
  345. #define DO_XSYNC_FUNC(exptr) \
  346. { \
  347. auto ecode = exptr; \
  348. if (!(ecode == kxs_ec_success)) { \
  349. ZLOGE(TAG, "do: %s fail,ecode:[%d](%s)", #exptr, ecode, xs_error_code_2_str(ecode)); \
  350. return; \
  351. } else { \
  352. ZLOGI(TAG, "do: %s success", #exptr); \
  353. } \
  354. }
  355. void MainWindow::on_GenNewMac_clicked() { DO_XSYNC_FUNC(Xsync::Ins().Basic_generatorNewMac()); }
  356. void MainWindow::on_FactoryReset_clicked() { DO_XSYNC_FUNC(Xsync::Ins().Basic_factoryReset()); }
  357. void MainWindow::on_Reboot_clicked() { DO_XSYNC_FUNC(Xsync::Ins().Basic_reboot()); }
  358. void MainWindow::on_ChangeNetCfg_clicked() { //
  359. DO_XSYNC_FUNC(Xsync::Ins().Basic_changeNetworkConfig(ui->ChangeNetCfg_ip->text().toStdString(), ui->ChangeNetCfg_mask->text().toStdString(), ui->ChangeNetCfg_gateway->text().toStdString()));
  360. }
  361. void MainWindow::on_WriteReg_clicked() {
  362. uint32_t regadd = str2int(ui->RegAdd->text());
  363. uint32_t regval = str2int(ui->RegVal->text());
  364. ZLOGI(TAG, "write reg 0x%08x %d", regadd, regval);
  365. uint32_t readbakval = 0;
  366. DO_XSYNC_FUNC(Xsync::Ins().reg_write(regadd, regval, readbakval));
  367. ZLOGI(TAG, "write reg 0x%08x 0x%08x ,readback:0x%08x success", regadd, regval, readbakval);
  368. ui->RegVal->setText(QString(fmt("0x%08x", readbakval)));
  369. }
  370. void MainWindow::on_ReadReg_clicked() {
  371. uint32_t regadd = str2int(ui->RegAdd->text());
  372. uint32_t regval = 0;
  373. DO_XSYNC_FUNC(Xsync::Ins().reg_read(regadd, regval));
  374. ZLOGI(TAG, "read reg 0x%08x 0x%08x success", regadd, regval);
  375. ui->RegVal->setText(QString(fmt("0x%08x", regval)));
  376. }
  377. void MainWindow::on_TTLOutputMoudle_Update_clicked() {
  378. int32_t ID = //
  379. ui->TTLOutputMoudle_ID->currentText().toInt();
  380. auto InputSigType = //
  381. ttlout_module::Str2TriggerSigType(ui->TTLOutputMoudle_InputSigType->currentText().toStdString());
  382. auto OutputSigType = //
  383. ttlout_module::Str2OutputSigType(ui->TTLOutputMoudle_OutputSigType->currentText().toStdString());
  384. uint32_t TriggerModePulseWidth = //
  385. ui->TTLOutputMoudle_TriggerModePulseWidth->text().toUInt();
  386. uint32_t TriggerModePulseDelay = //
  387. ui->TTLOutputMoudle_TriggerModePulseDelay->text().toUInt();
  388. ZLOGI(TAG, "on_TTLOutputMoudle_Update_clicked ID:%d InputSigType:%d OutputSigType:%d TriggerModePulseWidth:%d TriggerModePulseDelay:%d", //
  389. ID, InputSigType, OutputSigType, TriggerModePulseWidth, TriggerModePulseDelay);
  390. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_setInputSigType(ID, InputSigType));
  391. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_setOutputSigType(ID, OutputSigType));
  392. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_setTriggerModePulseWidth(ID, TriggerModePulseWidth));
  393. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_setTriggerModePulseDelay(ID, TriggerModePulseDelay));
  394. }
  395. void MainWindow::on_TTLOutputMoudle_Read_clicked() {
  396. ttlout_module::TriggerSigType_t InputSigType;
  397. ttlout_module::OutputSigType_t OutputSigType;
  398. uint32_t TriggerModePulseWidth;
  399. uint32_t TriggerModePulseDelay;
  400. int32_t ID = //
  401. ui->TTLOutputMoudle_ID->currentText().toInt();
  402. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_getInputSigType(ID, InputSigType));
  403. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_getOutputSigType(ID, OutputSigType));
  404. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_getTriggerModePulseWidth(ID, TriggerModePulseWidth));
  405. DO_XSYNC_FUNC(Xsync::Ins().TTLOutputModule_getTriggerModePulseDelay(ID, TriggerModePulseDelay));
  406. ui->TTLOutputMoudle_InputSigType->setCurrentText(QString::fromStdString(ttlout_module::TriggerSigType2Str(InputSigType)));
  407. ui->TTLOutputMoudle_OutputSigType->setCurrentText(QString::fromStdString(ttlout_module::OutputSigType2Str(OutputSigType)));
  408. ui->TTLOutputMoudle_TriggerModePulseWidth->setText(QString::number(TriggerModePulseWidth));
  409. ui->TTLOutputMoudle_TriggerModePulseDelay->setText(QString::number(TriggerModePulseDelay));
  410. }
  411. void MainWindow::on_SigGenerator_Read_clicked() {
  412. sig_generator_module::ControlMode_t ControlMode;
  413. GenlockFormat_t GenlockFormat;
  414. TimecodeFormat_t TimecodeFormat;
  415. XsyncTimecode_t Timecode;
  416. XsyncTimecode_t AutoStartTimecode;
  417. uint32_t WorkState;
  418. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getControlMode(ControlMode));
  419. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getGenlockFormat(GenlockFormat));
  420. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getTimecodeFormat(TimecodeFormat));
  421. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getTimecode(Timecode));
  422. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getAutoStartTimecode(AutoStartTimecode));
  423. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_getWorkState(WorkState));
  424. ui->SigGenerator_ControlMode->setCurrentText(QString::fromStdString(sig_generator_module::ControlMode2Str(ControlMode)));
  425. ui->SigGenerator_GenlockFormat->setCurrentText(QString::fromStdString(GenlockFormatToStr(GenlockFormat)));
  426. ui->SigGenerator_TimecodeFormat->setCurrentText(QString::fromStdString(TimecodeFormatToStr(TimecodeFormat)));
  427. ui->SigGenerator_Timecode->setText(QString(XsyncTimecodeToStr(Timecode).c_str()));
  428. ui->SigGenerator_AutoStartTimecode->setText(QString(XsyncTimecodeToStr(AutoStartTimecode).c_str()));
  429. ui->SigGenerator_WorkState->setText(QString::number(WorkState));
  430. }
  431. void MainWindow::on_SigGenerator_Update_clicked() {
  432. auto ControlMode = sig_generator_module::Str2ControlMode(ui->SigGenerator_ControlMode->currentText().toStdString());
  433. auto GenlockFormat = Str2GenlockFormat(ui->SigGenerator_GenlockFormat->currentText().toStdString());
  434. auto TimecodeFormat = Str2TimecodeFormat(ui->SigGenerator_TimecodeFormat->currentText().toStdString());
  435. XsyncTimecode_t timecode = Str2XsyncTimecode(ui->SigGenerator_Timecode->text().toStdString());
  436. XsyncTimecode_t autoStartTimecode = Str2XsyncTimecode(ui->SigGenerator_AutoStartTimecode->text().toStdString());
  437. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setControlMode(ControlMode));
  438. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setGenlockFormat(GenlockFormat));
  439. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setTimecodeFormat(TimecodeFormat));
  440. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setTimecode(timecode));
  441. DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_setAutoStartTimecode(autoStartTimecode));
  442. }
  443. void MainWindow::on_SigGenerator_Start_clicked() { DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_manualStart()); }
  444. void MainWindow::on_SigGenerator_Stop_clicked() { DO_XSYNC_FUNC(Xsync::Ins().SigGenerator_manualStop()); }
  445. void MainWindow::on_TimecodeOutputModule_Read_clicked() {
  446. // TimecodeOutputModule_TimecodeSrcSelect
  447. // TimecodeOutputModule_BncOutputLevel
  448. // TimecodeOutputModule_HeadphoneOutputLevel
  449. // TimecodeOutputModule_TimecodeFormat
  450. // TimecodeOutputModule_TimecodeNow
  451. timecode_output_module::TriggerSigType_t TimecodeSrcSelect;
  452. timecode_output_module::OutputSigLevelType_t BncOutputLevel;
  453. timecode_output_module::OutputSigLevelType_t HeadphoneOutputLevel;
  454. TimecodeFormat_t TimecodeFormat;
  455. XsyncTimecode_t TimecodeNow;
  456. DO_XSYNC_FUNC(Xsync::Ins().TimecodeOutputModule_getTimecodeSrcSelect(TimecodeSrcSelect));
  457. DO_XSYNC_FUNC(Xsync::Ins().TimecodeOutputModule_getBncOutputLevel(BncOutputLevel));
  458. DO_XSYNC_FUNC(Xsync::Ins().TimecodeOutputModule_getHeadphoneOutputLevel(HeadphoneOutputLevel));
  459. DO_XSYNC_FUNC(Xsync::Ins().TimecodeOutputModule_getTimecodeFormat(TimecodeFormat));
  460. DO_XSYNC_FUNC(Xsync::Ins().TimecodeOutputModule_getTimecodeNow(TimecodeNow));
  461. ui->TimecodeOutputModule_TimecodeSrcSelect->setCurrentText(QString::fromStdString(timecode_output_module::TriggerSigType2Str(TimecodeSrcSelect)));
  462. ui->TimecodeOutputModule_BncOutputLevel->setCurrentText(QString::fromStdString(timecode_output_module::OutputSigLevelType2Str(BncOutputLevel)));
  463. ui->TimecodeOutputModule_HeadphoneOutputLevel->setCurrentText(QString::fromStdString(timecode_output_module::OutputSigLevelType2Str(HeadphoneOutputLevel)));
  464. ui->TimecodeOutputModule_TimecodeFormat->setCurrentText(QString::fromStdString(TimecodeFormatToStr(TimecodeFormat)));
  465. ui->TimecodeOutputModule_TimecodeNow->setText(QString(XsyncTimecodeToStr(TimecodeNow).c_str()));
  466. }
  467. void MainWindow::on_TimecodeOutputModule_Update_clicked() {
  468. auto TimecodeSrcSelect = timecode_output_module::Str2TriggerSigType(ui->TimecodeOutputModule_TimecodeSrcSelect->currentText().toStdString());
  469. auto BncOutputLevel = timecode_output_module::Str2OutputSigLevelType(ui->TimecodeOutputModule_BncOutputLevel->currentText().toStdString());
  470. auto HeadphoneOutputLevel = timecode_output_module::Str2OutputSigLevelType(ui->TimecodeOutputModule_HeadphoneOutputLevel->currentText().toStdString());
  471. DO_XSYNC_FUNC(Xsync::Ins().TimecodeOutputModule_setTimecodeSrcSelect(TimecodeSrcSelect));
  472. DO_XSYNC_FUNC(Xsync::Ins().TimecodeOutputModule_setBncOutputLevel(BncOutputLevel));
  473. DO_XSYNC_FUNC(Xsync::Ins().TimecodeOutputModule_setHeadphoneOutputLevel(HeadphoneOutputLevel));
  474. }