mainwindow.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include <QMainWindow>
  4. #include <softkeyboard.h>
  5. #include <QScreen>
  6. #include <QGraphicsScene>
  7. #include <QGraphicsView>
  8. #include <QGraphicsProxyWidget>
  9. #include <QRect>
  10. #include <QStackedWidget>
  11. #include <QSerialPort>
  12. #include <QSerialPortInfo>
  13. #include <channelinfo.h>
  14. #include <landscape.h>
  15. #include <QTimer>
  16. #include <QThread>
  17. #include <QModbusDataUnit>
  18. #include <QModbusTcpClient>
  19. #include <QModbusRtuSerialMaster>
  20. #include <QTimeZone>
  21. #include <QMutex>
  22. #include <QMutexLocker>
  23. #include "portraitmode.h"
  24. #include "modbus/modbus.h"
  25. #include "readmodbus.h"
  26. #include "softkeyboard.h"
  27. #include "gpiobutten.h"
  28. QT_BEGIN_NAMESPACE
  29. namespace Ui { class MainWindow; }
  30. QT_END_NAMESPACE
  31. class ReadModbus;
  32. class Portraitmode;
  33. #define MAX_CHANNELS 14
  34. #define _SWITCH_T_AC_TYPE_CHN_INFO 0x1770 //获取三项类型通道
  35. #define _SWITCH_T_AC_IN_L1_INFO 0x1771 //三项交流输入L1
  36. #define _SWITCH_T_AC_IN_L2_INFO 0x1779 //三项交流输入L2
  37. #define _SWITCH_T_AC_IN_L3_INFO 0x1781 //三项交流输入L3
  38. #define _SWITCH_T_AC_CH_INFO 0x1789 //每个通道信息
  39. #define _SWITCH_T_AC_CH_PHASE_INFO 0x1A09 //每个通道相信息
  40. #define _SWITCH_T_AC_TH_INFO 0x2189 //温湿度信息
  41. #define _SWITCH_T_AC_CH_STATUS 0x218B //通道开关信息
  42. #define _SWITCH_T_AC_SENSOR_INFO 0x224B //MODBUS传感器信息
  43. #define _SWITCH_T_AC_SENSOR_INFO1 0x225B //干节点传感器信息
  44. typedef struct{
  45. uint16_t AllChs;
  46. uint8_t Type;
  47. float AllVoltage_L1 =0;
  48. float AllCurrent_L1=0;
  49. float AllPower_L1=0;
  50. float AllConsumption_L1=0;
  51. float AllVoltage_L2=0;
  52. float AllCurrent_L2=0;
  53. float AllPower_L2=0;
  54. float AllConsumption_L2=0;
  55. float AllVoltage_L3=0;
  56. float AllCurrent_L3=0;
  57. float AllPower_L3=0;
  58. float AllConsumption_L3=0;
  59. float Sensor_Temperature=0;
  60. float Sensor_Humidity=0;
  61. float Sensor_CO2=0;
  62. float Sensor_INTemperature=0;
  63. float Sensor_IN_Pressure = 0;
  64. float Sensor_OUTTemperature=0;
  65. float Sensor_OUT_Pressure = 0;
  66. bool Sensor_WaterImmersion=false;
  67. bool Sensor_LeakFlag=false;
  68. }PDUAllInfo_t;
  69. typedef struct
  70. {
  71. int CHNum=0;
  72. QString CHName=0;
  73. int CHPhase=0;
  74. float CHVoltage=0;
  75. float CHCurrent=0;
  76. float CHPower=0;
  77. float CHFactor=0;
  78. float CHConsumption=0;
  79. bool CHStatus=false;
  80. }PDUCHInfo_t;
  81. typedef struct
  82. {
  83. QString edit;
  84. QString line_send;
  85. QString line_recived;
  86. QString year;
  87. QString mon;
  88. QString day;
  89. QString hour;
  90. QString min;
  91. QString sec;
  92. QString port;
  93. QString addr;
  94. QString band;
  95. QString data;
  96. QString stop;
  97. QString parity;
  98. QString zone;
  99. int britnight;
  100. }chache_t;
  101. typedef struct
  102. {
  103. uint16_t slave_addr;
  104. char serial_name[32];
  105. uint32_t serial_banud;
  106. char serial_parity;
  107. uint8_t serial_data_bit;
  108. uint8_t serial_stop;
  109. }modbus_info_t;
  110. class MainWindow : public QMainWindow
  111. {
  112. Q_OBJECT
  113. public:
  114. MainWindow(QWidget *parent = nullptr);
  115. ~MainWindow();
  116. void test_modbus();
  117. void read_pdu_data();
  118. modbus_info_t get_modbus_info();
  119. int modbus_set(modbus_info_t &md_info);
  120. const modbus_t * get_mb() const;
  121. const SoftKeyBoard* get_keyboard()const;
  122. uint8_t get_suspend_flag();
  123. QTimeZone get_zone();
  124. void route();
  125. signals:
  126. void update_ui();
  127. void Notice(QString &send,QString &recived,uint8_t send_flag,uint8_t recive_flag);
  128. public slots:
  129. void opt_stop_or_start_signal(bool val);
  130. private:
  131. void modbus_init();
  132. public:
  133. ChannelInfo* get_channel_info();
  134. public:
  135. PDUAllInfo_t pdu_all_info;
  136. PDUCHInfo_t pdu_ch_info[15];
  137. uint8_t page;
  138. // chache_t m_che;
  139. int britnight;
  140. private:
  141. Ui::MainWindow *ui;
  142. QGraphicsScene *m_sence;
  143. QGraphicsView *m_view;
  144. QGraphicsProxyWidget *m_proxy;
  145. QScreen *m_screen;
  146. QRect screen_info;
  147. uint32_t m_width;
  148. uint32_t m_height;
  149. uint32_t rotation;
  150. modbus_info_t modbus;
  151. ChannelInfo *m_channel;
  152. SoftKeyBoard *keyboard;
  153. Portraitmode *port;
  154. Landscape *land;
  155. QTimer *m_timer;
  156. QTimeZone sysTime_zone;
  157. modbus_t *m_mb;
  158. QThread *m_thread;
  159. ReadModbus *m_read;
  160. uint8_t suspend_flag;
  161. GpioButten *m_key;
  162. };
  163. #endif // MAINWINDOW_H