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.

93 lines
2.6 KiB

2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years 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. #include "mainwindow.h"
  2. #include <QDateTime>
  3. #include <QtConcurrent>
  4. #include <QtSerialPort/QSerialPort>
  5. #include <QtSerialPort/QSerialPortInfo>
  6. #include "./ui_mainwindow.h"
  7. #include "logger.hpp"
  8. #include "xsync_regs.hpp"
  9. using namespace iflytop;
  10. using namespace xsync;
  11. using namespace std;
  12. static MainWindow *m_mainWindow;
  13. #define TAG "MainWindow"
  14. static const char *fmt(const char *fmt, ...) {
  15. va_list args;
  16. va_start(args, fmt);
  17. static char buf[1024] = {0};
  18. vsnprintf(buf, sizeof(buf), fmt, args);
  19. va_end(args);
  20. return buf;
  21. }
  22. static const uint32_t str2int(QString str) {
  23. // 如果0x开头,按16进制转换
  24. // 如果0b开头,按2进制转换
  25. // 否则按10进制转换
  26. // 去除掉str中_
  27. str.remove("_");
  28. if (str.startsWith("0x")) {
  29. return str.toUInt(nullptr, 16);
  30. } else if (str.startsWith("0b")) {
  31. // remove 0b
  32. str.remove(0, 2);
  33. return str.toUInt(nullptr, 2);
  34. } else {
  35. return str.toUInt(nullptr, 10);
  36. }
  37. }
  38. void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
  39. // QString text;
  40. // text.append(msg);
  41. }
  42. // void MainWindow::append_log_slot(QString text) { ui->logbrowser->append(text); }
  43. void MainWindow::doinui_slot(QFunction func) {
  44. if (func.get()) func.get()();
  45. }
  46. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
  47. ui->setupUi(this);
  48. m_mainWindow = this;
  49. qRegisterMetaType<int32_t>("int32_t");
  50. qRegisterMetaType<uint32_t>("uint32_t");
  51. qRegisterMetaType<function<void()>>("function<void()>");
  52. qRegisterMetaType<QFunction>("QFunction");
  53. // qInstallMessageHandler(log_output);
  54. connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction)));
  55. /**
  56. * @brief UI
  57. */
  58. // ZLOG
  59. // ZLOGI(TAG, "Hello");
  60. // QSerialPort *serialPort;
  61. // const auto infos = QSerialPortInfo::availablePorts();
  62. // for(const QSerialPortInfo &info : infos)
  63. // {
  64. // ZLOGI(TAG,"PortName:%s",info.portName().toStdString().c_str());
  65. // QSerialPort serial;
  66. // serial.setPort(info);
  67. // if(serial.open(QIODevice::ReadWrite))
  68. // {
  69. // // ui->PortBox->addItem(info.portName());
  70. // serial.close();
  71. // }
  72. // }
  73. /*******************************************************************************
  74. * *
  75. *******************************************************************************/
  76. // XSyncUdpFactoryImpl::Ins()->initialize();
  77. }
  78. MainWindow::~MainWindow() { delete ui; }