From 0b91f20d684d2f673501d7e0b196b3f39ffb33d8 Mon Sep 17 00:00:00 2001 From: shi_jq Date: Thu, 13 Mar 2025 15:21:23 +0800 Subject: [PATCH] =?UTF-8?q?[ref]=E5=90=8C=E6=AD=A5711?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- product/src/tools/db_installer/CSqlOpt.cpp | 157 ++ product/src/tools/db_installer/CSqlOpt.h | 18 + .../src/tools/db_installer/db_installer.pro | 40 + product/src/tools/db_installer/main.cpp | 13 + .../src/tools/debug_tool_v2/CActiveWindow.cpp | 27 + .../src/tools/debug_tool_v2/CActiveWindow.h | 47 + product/src/tools/debug_tool_v2/CDataMng.cpp | 585 +++++ product/src/tools/debug_tool_v2/CDataMng.h | 185 ++ .../src/tools/debug_tool_v2/CDebugTool.cpp | 268 ++ product/src/tools/debug_tool_v2/CDebugTool.h | 83 + product/src/tools/debug_tool_v2/CDebugTool.ui | 178 ++ .../tools/debug_tool_v2/CEventDataCollect.cpp | 893 +++++++ .../tools/debug_tool_v2/CEventDataCollect.h | 150 ++ .../tools/debug_tool_v2/CEventDelegate.cpp | 210 ++ .../src/tools/debug_tool_v2/CEventDelegate.h | 46 + .../tools/debug_tool_v2/CEventFilterDialog.ui | 405 +++ .../tools/debug_tool_v2/CEventFormShow.cpp | 71 + .../src/tools/debug_tool_v2/CEventFormShow.h | 30 + .../src/tools/debug_tool_v2/CEventFormShow.ui | 31 + .../tools/debug_tool_v2/CEventItemModel.cpp | 724 ++++++ .../src/tools/debug_tool_v2/CEventItemModel.h | 145 ++ .../src/tools/debug_tool_v2/CEventMsgInfo.cpp | 448 ++++ .../src/tools/debug_tool_v2/CEventMsgInfo.h | 168 ++ .../tools/debug_tool_v2/CEventMsgManage.cpp | 115 + .../src/tools/debug_tool_v2/CEventMsgManage.h | 39 + .../src/tools/debug_tool_v2/CEventView.cpp | 36 + product/src/tools/debug_tool_v2/CEventView.h | 22 + .../src/tools/debug_tool_v2/CFesChanData.cpp | 77 + .../src/tools/debug_tool_v2/CFesChanData.h | 42 + .../src/tools/debug_tool_v2/CFesChanData.ui | 36 + .../src/tools/debug_tool_v2/CFesCtrlSim.cpp | 170 ++ product/src/tools/debug_tool_v2/CFesCtrlSim.h | 48 + .../src/tools/debug_tool_v2/CFesCtrlSim.ui | 66 + product/src/tools/debug_tool_v2/CFesData.cpp | 178 ++ product/src/tools/debug_tool_v2/CFesData.h | 48 + product/src/tools/debug_tool_v2/CFesData.ui | 64 + .../src/tools/debug_tool_v2/CFesDataSim.cpp | 193 ++ product/src/tools/debug_tool_v2/CFesDataSim.h | 54 + .../src/tools/debug_tool_v2/CFesDataSim.ui | 65 + product/src/tools/debug_tool_v2/CFesEvent.cpp | 133 + product/src/tools/debug_tool_v2/CFesEvent.h | 42 + product/src/tools/debug_tool_v2/CFesEvent.ui | 55 + .../tools/debug_tool_v2/CFesForwardData.cpp | 224 ++ .../src/tools/debug_tool_v2/CFesForwardData.h | 51 + .../tools/debug_tool_v2/CFesForwardData.ui | 65 + .../src/tools/debug_tool_v2/CFesParamShow.cpp | 108 + .../src/tools/debug_tool_v2/CFesParamShow.h | 42 + .../src/tools/debug_tool_v2/CFesParamShow.ui | 53 + product/src/tools/debug_tool_v2/CFessim.cpp | 581 +++++ product/src/tools/debug_tool_v2/CFessim.h | 110 + product/src/tools/debug_tool_v2/CFessim.ui | 609 +++++ .../src/tools/debug_tool_v2/CHistoryEvent.ui | 100 + .../src/tools/debug_tool_v2/CMyCalendar.cpp | 93 + product/src/tools/debug_tool_v2/CMyCalendar.h | 38 + .../src/tools/debug_tool_v2/CMyCalendar.ui | 119 + .../src/tools/debug_tool_v2/CMyCheckBox.cpp | 22 + product/src/tools/debug_tool_v2/CMyCheckBox.h | 16 + .../src/tools/debug_tool_v2/CMyListWidget.cpp | 12 + .../src/tools/debug_tool_v2/CMyListWidget.h | 15 + .../src/tools/debug_tool_v2/CNodeStatus.cpp | 14 + product/src/tools/debug_tool_v2/CNodeStatus.h | 22 + .../src/tools/debug_tool_v2/CNodeStatus.ui | 134 + .../src/tools/debug_tool_v2/CRdbWorker.cpp | 40 + product/src/tools/debug_tool_v2/CRdbWorker.h | 22 + product/src/tools/debug_tool_v2/CRealAlarm.ui | 249 ++ .../tools/debug_tool_v2/CRealDataControl.cpp | 1221 +++++++++ .../tools/debug_tool_v2/CRealDataControl.h | 127 + .../tools/debug_tool_v2/CRealDataControl.ui | 290 +++ .../tools/debug_tool_v2/CRealDataSelect.cpp | 905 +++++++ .../src/tools/debug_tool_v2/CRealDataSelect.h | 80 + .../tools/debug_tool_v2/CRealDataSelect.ui | 200 ++ .../tools/debug_tool_v2/CRealDataWatch.cpp | 722 ++++++ .../src/tools/debug_tool_v2/CRealDataWatch.h | 123 + .../src/tools/debug_tool_v2/CRealDataWatch.ui | 237 ++ .../debug_tool_v2/CRealDatabaseItemInfo.cpp | 63 + .../debug_tool_v2/CRealDatabaseItemInfo.h | 24 + .../debug_tool_v2/CRealDatabaseItemModel.cpp | 82 + .../debug_tool_v2/CRealDatabaseItemModel.h | 34 + .../debug_tool_v2/CRealDatabaseSelect.cpp | 966 ++++++++ .../tools/debug_tool_v2/CRealDatabaseSelect.h | 86 + .../debug_tool_v2/CRealDatabaseSelect.ui | 247 ++ .../tools/debug_tool_v2/CRealDatabaseShow.cpp | 1195 +++++++++ .../tools/debug_tool_v2/CRealDatabaseShow.h | 148 ++ .../tools/debug_tool_v2/CRealDatabaseShow.ui | 228 ++ product/src/tools/debug_tool_v2/CRealEvent.ui | 96 + .../src/tools/debug_tool_v2/CSelectAppDlg.cpp | 162 ++ .../src/tools/debug_tool_v2/CSelectAppDlg.h | 41 + .../src/tools/debug_tool_v2/CSelectAppDlg.ui | 263 ++ .../src/tools/debug_tool_v2/CStatusDialog.cpp | 154 ++ .../src/tools/debug_tool_v2/CStatusDialog.h | 45 + .../src/tools/debug_tool_v2/CStatusDialog.ui | 83 + .../tools/debug_tool_v2/CSystemResources.cpp | 209 ++ .../tools/debug_tool_v2/CSystemResources.h | 78 + .../src/tools/debug_tool_v2/CUpdateThread.cpp | 73 + .../src/tools/debug_tool_v2/CUpdateThread.h | 34 + .../tools/debug_tool_v2/ComProtocolThread.h | 180 ++ .../src/tools/debug_tool_v2/CommonSheet.cpp | 43 + product/src/tools/debug_tool_v2/CommonSheet.h | 15 + product/src/tools/debug_tool_v2/FesDef.h | 2195 +++++++++++++++++ .../src/tools/debug_tool_v2/FesRdbStruct.h | 321 +++ .../src/tools/debug_tool_v2/FesSimProtocol.h | 824 +++++++ .../tools/debug_tool_v2/MbClientMngThread.cpp | 415 ++++ .../tools/debug_tool_v2/MbClientMngThread.h | 142 ++ .../tools/debug_tool_v2/MbCommunicator.cpp | 141 ++ .../src/tools/debug_tool_v2/MbCommunicator.h | 30 + .../tools/debug_tool_v2/SingleApplication.cpp | 181 ++ .../tools/debug_tool_v2/SingleApplication.h | 135 + .../debug_tool_v2/SingleApplication_p.cpp | 405 +++ .../tools/debug_tool_v2/SingleApplication_p.h | 99 + product/src/tools/debug_tool_v2/aimondlg.cpp | 805 ++++++ product/src/tools/debug_tool_v2/aimondlg.h | 96 + product/src/tools/debug_tool_v2/aimondlg.ui | 292 +++ .../src/tools/debug_tool_v2/chaneventdlg.cpp | 238 ++ .../src/tools/debug_tool_v2/chaneventdlg.h | 61 + .../src/tools/debug_tool_v2/chaneventdlg.ui | 175 ++ .../src/tools/debug_tool_v2/chanmondlg.cpp | 615 +++++ product/src/tools/debug_tool_v2/chanmondlg.h | 94 + product/src/tools/debug_tool_v2/chanmondlg.ui | 634 +++++ .../src/tools/debug_tool_v2/chanparamdlg.cpp | 203 ++ .../src/tools/debug_tool_v2/chanparamdlg.h | 45 + .../src/tools/debug_tool_v2/chanparamdlg.ui | 225 ++ .../debug_tool_v2/commTool/CCommTool.cpp | 63 + .../tools/debug_tool_v2/commTool/CCommTool.h | 30 + .../tools/debug_tool_v2/commTool/CCommTool.ui | 154 ++ .../src/tools/debug_tool_v2/debug_tool.ico | Bin 0 -> 3198 bytes .../src/tools/debug_tool_v2/debug_tool_v2.pro | 254 ++ product/src/tools/debug_tool_v2/defcmddlg.cpp | 384 +++ product/src/tools/debug_tool_v2/defcmddlg.h | 61 + product/src/tools/debug_tool_v2/defcmddlg.ui | 694 ++++++ product/src/tools/debug_tool_v2/dimondlg.cpp | 798 ++++++ product/src/tools/debug_tool_v2/dimondlg.h | 90 + product/src/tools/debug_tool_v2/dimondlg.ui | 286 +++ .../src/tools/debug_tool_v2/fwaccmondlg.cpp | 645 +++++ product/src/tools/debug_tool_v2/fwaccmondlg.h | 87 + .../src/tools/debug_tool_v2/fwaccmondlg.ui | 236 ++ .../src/tools/debug_tool_v2/fwaimondlg.cpp | 642 +++++ product/src/tools/debug_tool_v2/fwaimondlg.h | 86 + product/src/tools/debug_tool_v2/fwaimondlg.ui | 236 ++ .../src/tools/debug_tool_v2/fwddimondlg.cpp | 648 +++++ product/src/tools/debug_tool_v2/fwddimondlg.h | 86 + .../src/tools/debug_tool_v2/fwddimondlg.ui | 236 ++ .../src/tools/debug_tool_v2/fwdimondlg.cpp | 643 +++++ product/src/tools/debug_tool_v2/fwdimondlg.h | 87 + product/src/tools/debug_tool_v2/fwdimondlg.ui | 236 ++ .../src/tools/debug_tool_v2/fwmimondlg.cpp | 641 +++++ product/src/tools/debug_tool_v2/fwmimondlg.h | 84 + product/src/tools/debug_tool_v2/fwmimondlg.ui | 236 ++ product/src/tools/debug_tool_v2/images.qrc | 6 + .../debug_tool_v2/images/EngineeringDebug.png | Bin 0 -> 6641 bytes product/src/tools/debug_tool_v2/main.cpp | 100 + .../src/tools/debug_tool_v2/mainwindow.cpp | 307 +++ product/src/tools/debug_tool_v2/mainwindow.h | 84 + product/src/tools/debug_tool_v2/mainwindow.ui | 180 ++ product/src/tools/debug_tool_v2/mimondlg.cpp | 786 ++++++ product/src/tools/debug_tool_v2/mimondlg.h | 93 + product/src/tools/debug_tool_v2/mimondlg.ui | 286 +++ product/src/tools/debug_tool_v2/pimondlg.cpp | 791 ++++++ product/src/tools/debug_tool_v2/pimondlg.h | 87 + product/src/tools/debug_tool_v2/pimondlg.ui | 286 +++ .../src/tools/debug_tool_v2/rtuparamdlg.cpp | 139 ++ product/src/tools/debug_tool_v2/rtuparamdlg.h | 45 + .../src/tools/debug_tool_v2/rtuparamdlg.ui | 134 + product/src/tools/debug_tool_v2/simaidlg.cpp | 1042 ++++++++ product/src/tools/debug_tool_v2/simaidlg.h | 106 + product/src/tools/debug_tool_v2/simaidlg.ui | 918 +++++++ product/src/tools/debug_tool_v2/simaodlg.cpp | 605 +++++ product/src/tools/debug_tool_v2/simaodlg.h | 83 + product/src/tools/debug_tool_v2/simaodlg.ui | 418 ++++ product/src/tools/debug_tool_v2/simdidlg.cpp | 1042 ++++++++ product/src/tools/debug_tool_v2/simdidlg.h | 107 + product/src/tools/debug_tool_v2/simdidlg.ui | 778 ++++++ product/src/tools/debug_tool_v2/simdodlg.cpp | 605 +++++ product/src/tools/debug_tool_v2/simdodlg.h | 80 + product/src/tools/debug_tool_v2/simdodlg.ui | 418 ++++ .../src/tools/debug_tool_v2/simeventdlg.cpp | 616 +++++ product/src/tools/debug_tool_v2/simeventdlg.h | 85 + .../src/tools/debug_tool_v2/simeventdlg.ui | 823 ++++++ product/src/tools/debug_tool_v2/simmidlg.cpp | 1044 ++++++++ product/src/tools/debug_tool_v2/simmidlg.h | 104 + product/src/tools/debug_tool_v2/simmidlg.ui | 938 +++++++ product/src/tools/debug_tool_v2/simmodlg.cpp | 602 +++++ product/src/tools/debug_tool_v2/simmodlg.h | 79 + product/src/tools/debug_tool_v2/simmodlg.ui | 418 ++++ product/src/tools/debug_tool_v2/simpidlg.cpp | 1048 ++++++++ product/src/tools/debug_tool_v2/simpidlg.h | 104 + product/src/tools/debug_tool_v2/simpidlg.ui | 913 +++++++ .../src/tools/debug_tool_v2/soeeventdlg.cpp | 228 ++ product/src/tools/debug_tool_v2/soeeventdlg.h | 61 + .../src/tools/debug_tool_v2/soeeventdlg.ui | 220 ++ .../src/tools/debug_tool_v2/soememorydlg.cpp | 130 + .../src/tools/debug_tool_v2/soememorydlg.h | 53 + .../src/tools/debug_tool_v2/soememorydlg.ui | 155 ++ product/src/tools/debug_tool_v2/toolCommon.h | 113 + .../src/tools/link_seq_tool/link_seq_tool.pro | 11 + .../linkage_server_tool/CGetDBData.cpp | 542 ++++ .../linkage_server_tool/CGetDBData.h | 49 + .../linkage_server_tool/CGetRdbData.cpp | 146 ++ .../linkage_server_tool/CGetRdbData.h | 65 + .../CLinkageDbContainer.cpp | 314 +++ .../linkage_server_tool/CLinkageDbContainer.h | 136 + .../CLinkageForHmiApiInterface.cpp | 333 +++ .../CLinkageForHmiApiInterface.h | 38 + .../CRdbLinkRunningAccess.cpp | 132 + .../CRdbLinkRunningAccess.h | 70 + .../linkage_server_tool/CRecoverNode.cpp | 425 ++++ .../linkage_server_tool/CRecoverNode.h | 125 + .../CRecoverNodeContainer.cpp | 211 ++ .../CRecoverNodeContainer.h | 44 + .../linkage_server_tool/CSetReqMsgInfo.cpp | 134 + .../linkage_server_tool/CSetReqMsgInfo.h | 55 + .../linkage_server_tool/ConfigureDialog.cpp | 375 +++ .../linkage_server_tool/ConfigureDialog.h | 74 + .../linkage_server_tool/ConfigureDialog.ui | 132 + .../linkage_server_tool/DbTableDefine.h | 197 ++ .../RefreshExeStateThread.cpp | 134 + .../RefreshExeStateThread.h | 86 + .../linkage_server_tool.pro | 92 + .../linkage_server_tool/main.cpp | 62 + .../linkage_server_tool/mainwindow.cpp | 890 +++++++ .../linkage_server_tool/mainwindow.h | 116 + .../linkage_server_tool/mainwindow.ui | 413 ++++ .../predifineforlinkageserver.h | 193 ++ .../clinkageforhmiapiimpl.cpp | 157 ++ .../clinkageforhmiapiimpl.h | 46 + .../linkage_tuihuamian_tool.pro | 63 + .../linkage_tuihuamian_tool/main.cpp | 63 + .../linkage_tuihuamian_tool/mainwindow.cpp | 54 + .../linkage_tuihuamian_tool/mainwindow.h | 33 + .../linkage_tuihuamian_tool/mainwindow.ui | 46 + .../sequence_server_tool/CConfigureDialog.cpp | 382 +++ .../sequence_server_tool/CConfigureDialog.h | 77 + .../sequence_server_tool/CConfigureDialog.ui | 128 + .../CGetRdbDataThread.cpp | 135 + .../sequence_server_tool/CGetRdbDataThread.h | 67 + .../CRdbSeqRunningAccess.cpp | 140 ++ .../CRdbSeqRunningAccess.h | 60 + .../sequence_server_tool/CRecoverNode.cpp | 411 +++ .../sequence_server_tool/CRecoverNode.h | 113 + .../CRecoverNodeContainer.cpp | 208 ++ .../CRecoverNodeContainer.h | 45 + .../CRefreshExeStatusThread.cpp | 134 + .../CRefreshExeStatusThread.h | 87 + .../sequence_server_tool/CSeqDbContainer.cpp | 304 +++ .../sequence_server_tool/CSeqDbContainer.h | 107 + .../CSequenceForHmiApiInterface.cpp | 285 +++ .../CSequenceForHmiApiInterface.h | 33 + .../sequence_server_tool/CSetSeqMsgInfo.cpp | 133 + .../sequence_server_tool/CSetSeqMsgInfo.h | 51 + .../sequence_server_tool/CSqlDbCtrl.cpp | 491 ++++ .../sequence_server_tool/CSqlDbCtrl.h | 48 + .../sequence_server_tool/DbTableDefine.h | 191 ++ .../sequence_server_tool/main.cpp | 62 + .../sequence_server_tool/mainwindow.cpp | 855 +++++++ .../sequence_server_tool/mainwindow.h | 109 + .../sequence_server_tool/mainwindow.ui | 359 +++ .../predifineforseqserver.h | 158 ++ .../sequence_server_tool.pro | 93 + .../trigger_tool/CDbContainer.cpp | 129 + .../link_seq_tool/trigger_tool/CDbContainer.h | 39 + .../trigger_tool/CEditBaseWidget.cpp | 35 + .../trigger_tool/CEditBaseWidget.h | 19 + .../trigger_tool/CEditConditionWidget.cpp | 26 + .../trigger_tool/CEditConditionWidget.h | 21 + .../trigger_tool/CEditConditionWidget.ui | 32 + .../trigger_tool/CEditDialog.cpp | 187 ++ .../link_seq_tool/trigger_tool/CEditDialog.h | 57 + .../link_seq_tool/trigger_tool/CEditDialog.ui | 119 + .../trigger_tool/CEditPeriodWidget.cpp | 22 + .../trigger_tool/CEditPeriodWidget.h | 22 + .../trigger_tool/CEditPeriodWidget.ui | 32 + .../trigger_tool/CEditTimerWidget.cpp | 149 ++ .../trigger_tool/CEditTimerWidget.h | 47 + .../trigger_tool/CEditTimerWidget.ui | 140 ++ .../link_seq_tool/trigger_tool/CIterator.cpp | 281 +++ .../link_seq_tool/trigger_tool/CIterator.h | 102 + .../link_seq_tool/trigger_tool/CSqlDbCtrl.cpp | 270 ++ .../link_seq_tool/trigger_tool/CSqlDbCtrl.h | 45 + .../trigger_tool/CTriggerInterface.cpp | 20 + .../trigger_tool/CTriggerInterface.h | 20 + .../trigger_tool/CTriggerMngr.cpp | 153 ++ .../link_seq_tool/trigger_tool/CTriggerMngr.h | 54 + .../trigger_tool/TriggerCommonDefine.h | 111 + .../tools/link_seq_tool/trigger_tool/main.cpp | 64 + .../link_seq_tool/trigger_tool/mainwindow.cpp | 506 ++++ .../link_seq_tool/trigger_tool/mainwindow.h | 92 + .../link_seq_tool/trigger_tool/mainwindow.ui | 257 ++ .../trigger_tool/trigger_tool.pro | 64 + .../StaticsWidget/statics_analysis_EN.ts | 671 +++++ product/src/tools/mqtt_tool/CommonSheet.cpp | 43 + product/src/tools/mqtt_tool/CommonSheet.h | 15 + product/src/tools/mqtt_tool/QMqttClient.cpp | 205 ++ product/src/tools/mqtt_tool/QMqttClient.h | 237 ++ product/src/tools/mqtt_tool/QMqttMessage.cpp | 73 + product/src/tools/mqtt_tool/QMqttMessage.h | 96 + product/src/tools/mqtt_tool/connform.cpp | 64 + product/src/tools/mqtt_tool/connform.h | 49 + product/src/tools/mqtt_tool/connform.ui | 276 +++ product/src/tools/mqtt_tool/main.cpp | 14 + product/src/tools/mqtt_tool/mainwindow.cpp | 160 ++ product/src/tools/mqtt_tool/mainwindow.h | 54 + product/src/tools/mqtt_tool/mainwindow.ui | 256 ++ product/src/tools/mqtt_tool/mqtt_tool.pro | 72 + product/src/tools/mqtt_tool/mqttform.h | 44 + product/src/tools/mqtt_tool/pubform.cpp | 52 + product/src/tools/mqtt_tool/pubform.h | 44 + product/src/tools/mqtt_tool/pubform.ui | 176 ++ product/src/tools/mqtt_tool/subform.cpp | 104 + product/src/tools/mqtt_tool/subform.h | 53 + product/src/tools/mqtt_tool/subform.ui | 188 ++ product/src/tools/net_msg_tool/NetThread.cpp | 145 ++ product/src/tools/net_msg_tool/NetThread.h | 47 + product/src/tools/net_msg_tool/main.cpp | 64 + product/src/tools/net_msg_tool/mainwindow.cpp | 631 +++++ product/src/tools/net_msg_tool/mainwindow.h | 64 + product/src/tools/net_msg_tool/mainwindow.ui | 341 +++ .../src/tools/net_msg_tool/net_msg_tool.pro | 60 + product/src/tools/style_tool/AboutDlg.cpp | 138 ++ product/src/tools/style_tool/AboutDlg.h | 31 + product/src/tools/style_tool/LoginDlg.cpp | 19 + product/src/tools/style_tool/LoginDlg.h | 23 + product/src/tools/style_tool/LoginDlg.ui | 145 ++ product/src/tools/style_tool/MainWindow2.cpp | 151 ++ product/src/tools/style_tool/MainWindow2.h | 34 + product/src/tools/style_tool/main.cpp | 20 + product/src/tools/style_tool/mainwindow.cpp | 269 ++ product/src/tools/style_tool/mainwindow.h | 52 + product/src/tools/style_tool/mainwindow.ui | 1591 ++++++++++++ product/src/tools/style_tool/style_tool.pro | 57 + product/src/tools/workBench/AppMngForm.cpp | 384 +++ product/src/tools/workBench/AppMngForm.h | 58 + product/src/tools/workBench/AppMngForm.ui | 60 + product/src/tools/workBench/AutoStart.cpp | 62 + product/src/tools/workBench/AutoStart.h | 34 + product/src/tools/workBench/AutoStart.ui | 146 ++ .../src/tools/workBench/BrushDataThread.cpp | 233 ++ product/src/tools/workBench/BrushDataThread.h | 103 + product/src/tools/workBench/ButtonForm.cpp | 354 +++ product/src/tools/workBench/ButtonForm.h | 51 + product/src/tools/workBench/ButtonForm.ui | 91 + product/src/tools/workBench/DbCheck.cpp | 732 ++++++ product/src/tools/workBench/DbCheck.h | 142 ++ product/src/tools/workBench/DbCheck.ui | 273 ++ product/src/tools/workBench/DbCheckSync.cpp | 81 + product/src/tools/workBench/DbCheckSync.h | 24 + product/src/tools/workBench/DogCheck.cpp | 97 + product/src/tools/workBench/DogCheck.h | 26 + product/src/tools/workBench/DogCheck.ui | 151 ++ product/src/tools/workBench/Main.cpp | 50 + product/src/tools/workBench/MainWindow.cpp | 1484 +++++++++++ product/src/tools/workBench/MainWindow.h | 228 ++ .../src/tools/workBench/ModifyButtonForm.cpp | 214 ++ .../src/tools/workBench/ModifyButtonForm.h | 49 + .../src/tools/workBench/ModifyButtonForm.ui | 141 ++ product/src/tools/workBench/MonitorCommon.h | 204 ++ product/src/tools/workBench/MyProgressBar.cpp | 134 + product/src/tools/workBench/MyProgressBar.h | 71 + .../src/tools/workBench/OnTimeCheckThread.cpp | 38 + .../src/tools/workBench/OnTimeCheckThread.h | 21 + product/src/tools/workBench/ProcMngForm.cpp | 572 +++++ product/src/tools/workBench/ProcMngForm.h | 78 + product/src/tools/workBench/ProcMngForm.ui | 83 + product/src/tools/workBench/SetupFunc.h | 56 + .../src/tools/workBench/SetupFuncLinux.cpp | 284 +++ .../src/tools/workBench/SetupFuncWindows.cpp | 272 ++ .../src/tools/workBench/SingleApplication.cpp | 181 ++ .../src/tools/workBench/SingleApplication.h | 135 + .../tools/workBench/SingleApplication_p.cpp | 406 +++ .../src/tools/workBench/SingleApplication_p.h | 99 + product/src/tools/workBench/StartUpForm.cpp | 184 ++ product/src/tools/workBench/StartUpForm.h | 62 + product/src/tools/workBench/StartUpForm.ui | 318 +++ product/src/tools/workBench/StatusForm.cpp | 81 + product/src/tools/workBench/StatusForm.h | 41 + product/src/tools/workBench/StatusForm.ui | 103 + product/src/tools/workBench/SystemSetForm.cpp | 246 ++ product/src/tools/workBench/SystemSetForm.h | 52 + product/src/tools/workBench/SystemSetForm.ui | 712 ++++++ product/src/tools/workBench/auto_start.ico | Bin 0 -> 4286 bytes product/src/tools/workBench/db_check.ico | Bin 0 -> 4286 bytes .../src/tools/workBench/dog_auth_check.ico | Bin 0 -> 4286 bytes .../src/tools/workBench/images/restart.png | Bin 0 -> 558 bytes product/src/tools/workBench/images/start.png | Bin 0 -> 23061 bytes product/src/tools/workBench/images/stop.png | Bin 0 -> 23000 bytes .../tools/workBench/img/button_background.png | Bin 0 -> 1442 bytes .../src/tools/workBench/localstateform.cpp | 311 +++ product/src/tools/workBench/localstateform.h | 43 + product/src/tools/workBench/localstateform.ui | 39 + product/src/tools/workBench/mainwindow.ui | 248 ++ product/src/tools/workBench/resource.qrc | 11 + product/src/tools/workBench/sys_startup.ico | Bin 0 -> 16958 bytes .../tools/workBench/tool/CheckBoxDialog.cpp | 75 + .../src/tools/workBench/tool/CheckBoxDialog.h | 32 + product/src/tools/workBench/tool/CommonEnum.h | 14 + product/src/tools/workBench/tool/DataMng.cpp | 828 +++++++ product/src/tools/workBench/tool/DataMng.h | 327 +++ .../src/tools/workBench/tool/InputDialog.cpp | 123 + .../src/tools/workBench/tool/InputDialog.h | 44 + product/src/tools/workBench/workBench.pro | 158 ++ 398 files changed, 84091 insertions(+) create mode 100644 product/src/tools/db_installer/CSqlOpt.cpp create mode 100644 product/src/tools/db_installer/CSqlOpt.h create mode 100644 product/src/tools/db_installer/db_installer.pro create mode 100644 product/src/tools/db_installer/main.cpp create mode 100644 product/src/tools/debug_tool_v2/CActiveWindow.cpp create mode 100644 product/src/tools/debug_tool_v2/CActiveWindow.h create mode 100644 product/src/tools/debug_tool_v2/CDataMng.cpp create mode 100644 product/src/tools/debug_tool_v2/CDataMng.h create mode 100644 product/src/tools/debug_tool_v2/CDebugTool.cpp create mode 100644 product/src/tools/debug_tool_v2/CDebugTool.h create mode 100644 product/src/tools/debug_tool_v2/CDebugTool.ui create mode 100644 product/src/tools/debug_tool_v2/CEventDataCollect.cpp create mode 100644 product/src/tools/debug_tool_v2/CEventDataCollect.h create mode 100644 product/src/tools/debug_tool_v2/CEventDelegate.cpp create mode 100644 product/src/tools/debug_tool_v2/CEventDelegate.h create mode 100644 product/src/tools/debug_tool_v2/CEventFilterDialog.ui create mode 100644 product/src/tools/debug_tool_v2/CEventFormShow.cpp create mode 100644 product/src/tools/debug_tool_v2/CEventFormShow.h create mode 100644 product/src/tools/debug_tool_v2/CEventFormShow.ui create mode 100644 product/src/tools/debug_tool_v2/CEventItemModel.cpp create mode 100644 product/src/tools/debug_tool_v2/CEventItemModel.h create mode 100644 product/src/tools/debug_tool_v2/CEventMsgInfo.cpp create mode 100644 product/src/tools/debug_tool_v2/CEventMsgInfo.h create mode 100644 product/src/tools/debug_tool_v2/CEventMsgManage.cpp create mode 100644 product/src/tools/debug_tool_v2/CEventMsgManage.h create mode 100644 product/src/tools/debug_tool_v2/CEventView.cpp create mode 100644 product/src/tools/debug_tool_v2/CEventView.h create mode 100644 product/src/tools/debug_tool_v2/CFesChanData.cpp create mode 100644 product/src/tools/debug_tool_v2/CFesChanData.h create mode 100644 product/src/tools/debug_tool_v2/CFesChanData.ui create mode 100644 product/src/tools/debug_tool_v2/CFesCtrlSim.cpp create mode 100644 product/src/tools/debug_tool_v2/CFesCtrlSim.h create mode 100644 product/src/tools/debug_tool_v2/CFesCtrlSim.ui create mode 100644 product/src/tools/debug_tool_v2/CFesData.cpp create mode 100644 product/src/tools/debug_tool_v2/CFesData.h create mode 100644 product/src/tools/debug_tool_v2/CFesData.ui create mode 100644 product/src/tools/debug_tool_v2/CFesDataSim.cpp create mode 100644 product/src/tools/debug_tool_v2/CFesDataSim.h create mode 100644 product/src/tools/debug_tool_v2/CFesDataSim.ui create mode 100644 product/src/tools/debug_tool_v2/CFesEvent.cpp create mode 100644 product/src/tools/debug_tool_v2/CFesEvent.h create mode 100644 product/src/tools/debug_tool_v2/CFesEvent.ui create mode 100644 product/src/tools/debug_tool_v2/CFesForwardData.cpp create mode 100644 product/src/tools/debug_tool_v2/CFesForwardData.h create mode 100644 product/src/tools/debug_tool_v2/CFesForwardData.ui create mode 100644 product/src/tools/debug_tool_v2/CFesParamShow.cpp create mode 100644 product/src/tools/debug_tool_v2/CFesParamShow.h create mode 100644 product/src/tools/debug_tool_v2/CFesParamShow.ui create mode 100644 product/src/tools/debug_tool_v2/CFessim.cpp create mode 100644 product/src/tools/debug_tool_v2/CFessim.h create mode 100644 product/src/tools/debug_tool_v2/CFessim.ui create mode 100644 product/src/tools/debug_tool_v2/CHistoryEvent.ui create mode 100644 product/src/tools/debug_tool_v2/CMyCalendar.cpp create mode 100644 product/src/tools/debug_tool_v2/CMyCalendar.h create mode 100644 product/src/tools/debug_tool_v2/CMyCalendar.ui create mode 100644 product/src/tools/debug_tool_v2/CMyCheckBox.cpp create mode 100644 product/src/tools/debug_tool_v2/CMyCheckBox.h create mode 100644 product/src/tools/debug_tool_v2/CMyListWidget.cpp create mode 100644 product/src/tools/debug_tool_v2/CMyListWidget.h create mode 100644 product/src/tools/debug_tool_v2/CNodeStatus.cpp create mode 100644 product/src/tools/debug_tool_v2/CNodeStatus.h create mode 100644 product/src/tools/debug_tool_v2/CNodeStatus.ui create mode 100644 product/src/tools/debug_tool_v2/CRdbWorker.cpp create mode 100644 product/src/tools/debug_tool_v2/CRdbWorker.h create mode 100644 product/src/tools/debug_tool_v2/CRealAlarm.ui create mode 100644 product/src/tools/debug_tool_v2/CRealDataControl.cpp create mode 100644 product/src/tools/debug_tool_v2/CRealDataControl.h create mode 100644 product/src/tools/debug_tool_v2/CRealDataControl.ui create mode 100644 product/src/tools/debug_tool_v2/CRealDataSelect.cpp create mode 100644 product/src/tools/debug_tool_v2/CRealDataSelect.h create mode 100644 product/src/tools/debug_tool_v2/CRealDataSelect.ui create mode 100644 product/src/tools/debug_tool_v2/CRealDataWatch.cpp create mode 100644 product/src/tools/debug_tool_v2/CRealDataWatch.h create mode 100644 product/src/tools/debug_tool_v2/CRealDataWatch.ui create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseItemInfo.cpp create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseItemInfo.h create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseItemModel.cpp create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseItemModel.h create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseSelect.cpp create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseSelect.h create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseSelect.ui create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseShow.cpp create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseShow.h create mode 100644 product/src/tools/debug_tool_v2/CRealDatabaseShow.ui create mode 100644 product/src/tools/debug_tool_v2/CRealEvent.ui create mode 100644 product/src/tools/debug_tool_v2/CSelectAppDlg.cpp create mode 100644 product/src/tools/debug_tool_v2/CSelectAppDlg.h create mode 100644 product/src/tools/debug_tool_v2/CSelectAppDlg.ui create mode 100644 product/src/tools/debug_tool_v2/CStatusDialog.cpp create mode 100644 product/src/tools/debug_tool_v2/CStatusDialog.h create mode 100644 product/src/tools/debug_tool_v2/CStatusDialog.ui create mode 100644 product/src/tools/debug_tool_v2/CSystemResources.cpp create mode 100644 product/src/tools/debug_tool_v2/CSystemResources.h create mode 100644 product/src/tools/debug_tool_v2/CUpdateThread.cpp create mode 100644 product/src/tools/debug_tool_v2/CUpdateThread.h create mode 100644 product/src/tools/debug_tool_v2/ComProtocolThread.h create mode 100644 product/src/tools/debug_tool_v2/CommonSheet.cpp create mode 100644 product/src/tools/debug_tool_v2/CommonSheet.h create mode 100644 product/src/tools/debug_tool_v2/FesDef.h create mode 100644 product/src/tools/debug_tool_v2/FesRdbStruct.h create mode 100644 product/src/tools/debug_tool_v2/FesSimProtocol.h create mode 100644 product/src/tools/debug_tool_v2/MbClientMngThread.cpp create mode 100644 product/src/tools/debug_tool_v2/MbClientMngThread.h create mode 100644 product/src/tools/debug_tool_v2/MbCommunicator.cpp create mode 100644 product/src/tools/debug_tool_v2/MbCommunicator.h create mode 100644 product/src/tools/debug_tool_v2/SingleApplication.cpp create mode 100644 product/src/tools/debug_tool_v2/SingleApplication.h create mode 100644 product/src/tools/debug_tool_v2/SingleApplication_p.cpp create mode 100644 product/src/tools/debug_tool_v2/SingleApplication_p.h create mode 100644 product/src/tools/debug_tool_v2/aimondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/aimondlg.h create mode 100644 product/src/tools/debug_tool_v2/aimondlg.ui create mode 100644 product/src/tools/debug_tool_v2/chaneventdlg.cpp create mode 100644 product/src/tools/debug_tool_v2/chaneventdlg.h create mode 100644 product/src/tools/debug_tool_v2/chaneventdlg.ui create mode 100644 product/src/tools/debug_tool_v2/chanmondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/chanmondlg.h create mode 100644 product/src/tools/debug_tool_v2/chanmondlg.ui create mode 100644 product/src/tools/debug_tool_v2/chanparamdlg.cpp create mode 100644 product/src/tools/debug_tool_v2/chanparamdlg.h create mode 100644 product/src/tools/debug_tool_v2/chanparamdlg.ui create mode 100644 product/src/tools/debug_tool_v2/commTool/CCommTool.cpp create mode 100644 product/src/tools/debug_tool_v2/commTool/CCommTool.h create mode 100644 product/src/tools/debug_tool_v2/commTool/CCommTool.ui create mode 100644 product/src/tools/debug_tool_v2/debug_tool.ico create mode 100644 product/src/tools/debug_tool_v2/debug_tool_v2.pro create mode 100644 product/src/tools/debug_tool_v2/defcmddlg.cpp create mode 100644 product/src/tools/debug_tool_v2/defcmddlg.h create mode 100644 product/src/tools/debug_tool_v2/defcmddlg.ui create mode 100644 product/src/tools/debug_tool_v2/dimondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/dimondlg.h create mode 100644 product/src/tools/debug_tool_v2/dimondlg.ui create mode 100644 product/src/tools/debug_tool_v2/fwaccmondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/fwaccmondlg.h create mode 100644 product/src/tools/debug_tool_v2/fwaccmondlg.ui create mode 100644 product/src/tools/debug_tool_v2/fwaimondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/fwaimondlg.h create mode 100644 product/src/tools/debug_tool_v2/fwaimondlg.ui create mode 100644 product/src/tools/debug_tool_v2/fwddimondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/fwddimondlg.h create mode 100644 product/src/tools/debug_tool_v2/fwddimondlg.ui create mode 100644 product/src/tools/debug_tool_v2/fwdimondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/fwdimondlg.h create mode 100644 product/src/tools/debug_tool_v2/fwdimondlg.ui create mode 100644 product/src/tools/debug_tool_v2/fwmimondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/fwmimondlg.h create mode 100644 product/src/tools/debug_tool_v2/fwmimondlg.ui create mode 100644 product/src/tools/debug_tool_v2/images.qrc create mode 100644 product/src/tools/debug_tool_v2/images/EngineeringDebug.png create mode 100644 product/src/tools/debug_tool_v2/main.cpp create mode 100644 product/src/tools/debug_tool_v2/mainwindow.cpp create mode 100644 product/src/tools/debug_tool_v2/mainwindow.h create mode 100644 product/src/tools/debug_tool_v2/mainwindow.ui create mode 100644 product/src/tools/debug_tool_v2/mimondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/mimondlg.h create mode 100644 product/src/tools/debug_tool_v2/mimondlg.ui create mode 100644 product/src/tools/debug_tool_v2/pimondlg.cpp create mode 100644 product/src/tools/debug_tool_v2/pimondlg.h create mode 100644 product/src/tools/debug_tool_v2/pimondlg.ui create mode 100644 product/src/tools/debug_tool_v2/rtuparamdlg.cpp create mode 100644 product/src/tools/debug_tool_v2/rtuparamdlg.h create mode 100644 product/src/tools/debug_tool_v2/rtuparamdlg.ui create mode 100644 product/src/tools/debug_tool_v2/simaidlg.cpp create mode 100644 product/src/tools/debug_tool_v2/simaidlg.h create mode 100644 product/src/tools/debug_tool_v2/simaidlg.ui create mode 100644 product/src/tools/debug_tool_v2/simaodlg.cpp create mode 100644 product/src/tools/debug_tool_v2/simaodlg.h create mode 100644 product/src/tools/debug_tool_v2/simaodlg.ui create mode 100644 product/src/tools/debug_tool_v2/simdidlg.cpp create mode 100644 product/src/tools/debug_tool_v2/simdidlg.h create mode 100644 product/src/tools/debug_tool_v2/simdidlg.ui create mode 100644 product/src/tools/debug_tool_v2/simdodlg.cpp create mode 100644 product/src/tools/debug_tool_v2/simdodlg.h create mode 100644 product/src/tools/debug_tool_v2/simdodlg.ui create mode 100644 product/src/tools/debug_tool_v2/simeventdlg.cpp create mode 100644 product/src/tools/debug_tool_v2/simeventdlg.h create mode 100644 product/src/tools/debug_tool_v2/simeventdlg.ui create mode 100644 product/src/tools/debug_tool_v2/simmidlg.cpp create mode 100644 product/src/tools/debug_tool_v2/simmidlg.h create mode 100644 product/src/tools/debug_tool_v2/simmidlg.ui create mode 100644 product/src/tools/debug_tool_v2/simmodlg.cpp create mode 100644 product/src/tools/debug_tool_v2/simmodlg.h create mode 100644 product/src/tools/debug_tool_v2/simmodlg.ui create mode 100644 product/src/tools/debug_tool_v2/simpidlg.cpp create mode 100644 product/src/tools/debug_tool_v2/simpidlg.h create mode 100644 product/src/tools/debug_tool_v2/simpidlg.ui create mode 100644 product/src/tools/debug_tool_v2/soeeventdlg.cpp create mode 100644 product/src/tools/debug_tool_v2/soeeventdlg.h create mode 100644 product/src/tools/debug_tool_v2/soeeventdlg.ui create mode 100644 product/src/tools/debug_tool_v2/soememorydlg.cpp create mode 100644 product/src/tools/debug_tool_v2/soememorydlg.h create mode 100644 product/src/tools/debug_tool_v2/soememorydlg.ui create mode 100644 product/src/tools/debug_tool_v2/toolCommon.h create mode 100644 product/src/tools/link_seq_tool/link_seq_tool.pro create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CGetDBData.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CGetDBData.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CGetRdbData.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CGetRdbData.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CLinkageDbContainer.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CLinkageDbContainer.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CLinkageForHmiApiInterface.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CLinkageForHmiApiInterface.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CRdbLinkRunningAccess.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CRdbLinkRunningAccess.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNode.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNode.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNodeContainer.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNodeContainer.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CSetReqMsgInfo.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/CSetReqMsgInfo.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.ui create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/DbTableDefine.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/RefreshExeStateThread.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/RefreshExeStateThread.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/linkage_server_tool.pro create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/main.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.h create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.ui create mode 100644 product/src/tools/link_seq_tool/linkage_server_tool/predifineforlinkageserver.h create mode 100644 product/src/tools/link_seq_tool/linkage_tuihuamian_tool/clinkageforhmiapiimpl.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_tuihuamian_tool/clinkageforhmiapiimpl.h create mode 100644 product/src/tools/link_seq_tool/linkage_tuihuamian_tool/linkage_tuihuamian_tool.pro create mode 100644 product/src/tools/link_seq_tool/linkage_tuihuamian_tool/main.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.cpp create mode 100644 product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.h create mode 100644 product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.ui create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.ui create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CGetRdbDataThread.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CGetRdbDataThread.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CRdbSeqRunningAccess.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CRdbSeqRunningAccess.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNode.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNode.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNodeContainer.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNodeContainer.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CRefreshExeStatusThread.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CRefreshExeStatusThread.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CSeqDbContainer.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CSeqDbContainer.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CSequenceForHmiApiInterface.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CSequenceForHmiApiInterface.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CSetSeqMsgInfo.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CSetSeqMsgInfo.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CSqlDbCtrl.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/CSqlDbCtrl.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/DbTableDefine.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/main.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.cpp create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.ui create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/predifineforseqserver.h create mode 100644 product/src/tools/link_seq_tool/sequence_server_tool/sequence_server_tool.pro create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CDbContainer.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CDbContainer.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditBaseWidget.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditBaseWidget.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.ui create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditDialog.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditDialog.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditDialog.ui create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.ui create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.ui create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CIterator.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CIterator.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CSqlDbCtrl.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CSqlDbCtrl.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CTriggerInterface.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CTriggerInterface.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CTriggerMngr.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/CTriggerMngr.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/TriggerCommonDefine.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/main.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/mainwindow.cpp create mode 100644 product/src/tools/link_seq_tool/trigger_tool/mainwindow.h create mode 100644 product/src/tools/link_seq_tool/trigger_tool/mainwindow.ui create mode 100644 product/src/tools/link_seq_tool/trigger_tool/trigger_tool.pro create mode 100644 product/src/tools/model_plugin/StaticsWidget/statics_analysis_EN.ts create mode 100644 product/src/tools/mqtt_tool/CommonSheet.cpp create mode 100644 product/src/tools/mqtt_tool/CommonSheet.h create mode 100644 product/src/tools/mqtt_tool/QMqttClient.cpp create mode 100644 product/src/tools/mqtt_tool/QMqttClient.h create mode 100644 product/src/tools/mqtt_tool/QMqttMessage.cpp create mode 100644 product/src/tools/mqtt_tool/QMqttMessage.h create mode 100644 product/src/tools/mqtt_tool/connform.cpp create mode 100644 product/src/tools/mqtt_tool/connform.h create mode 100644 product/src/tools/mqtt_tool/connform.ui create mode 100644 product/src/tools/mqtt_tool/main.cpp create mode 100644 product/src/tools/mqtt_tool/mainwindow.cpp create mode 100644 product/src/tools/mqtt_tool/mainwindow.h create mode 100644 product/src/tools/mqtt_tool/mainwindow.ui create mode 100644 product/src/tools/mqtt_tool/mqtt_tool.pro create mode 100644 product/src/tools/mqtt_tool/mqttform.h create mode 100644 product/src/tools/mqtt_tool/pubform.cpp create mode 100644 product/src/tools/mqtt_tool/pubform.h create mode 100644 product/src/tools/mqtt_tool/pubform.ui create mode 100644 product/src/tools/mqtt_tool/subform.cpp create mode 100644 product/src/tools/mqtt_tool/subform.h create mode 100644 product/src/tools/mqtt_tool/subform.ui create mode 100644 product/src/tools/net_msg_tool/NetThread.cpp create mode 100644 product/src/tools/net_msg_tool/NetThread.h create mode 100644 product/src/tools/net_msg_tool/main.cpp create mode 100644 product/src/tools/net_msg_tool/mainwindow.cpp create mode 100644 product/src/tools/net_msg_tool/mainwindow.h create mode 100644 product/src/tools/net_msg_tool/mainwindow.ui create mode 100644 product/src/tools/net_msg_tool/net_msg_tool.pro create mode 100644 product/src/tools/style_tool/AboutDlg.cpp create mode 100644 product/src/tools/style_tool/AboutDlg.h create mode 100644 product/src/tools/style_tool/LoginDlg.cpp create mode 100644 product/src/tools/style_tool/LoginDlg.h create mode 100644 product/src/tools/style_tool/LoginDlg.ui create mode 100644 product/src/tools/style_tool/MainWindow2.cpp create mode 100644 product/src/tools/style_tool/MainWindow2.h create mode 100644 product/src/tools/style_tool/main.cpp create mode 100644 product/src/tools/style_tool/mainwindow.cpp create mode 100644 product/src/tools/style_tool/mainwindow.h create mode 100644 product/src/tools/style_tool/mainwindow.ui create mode 100644 product/src/tools/style_tool/style_tool.pro create mode 100644 product/src/tools/workBench/AppMngForm.cpp create mode 100644 product/src/tools/workBench/AppMngForm.h create mode 100644 product/src/tools/workBench/AppMngForm.ui create mode 100644 product/src/tools/workBench/AutoStart.cpp create mode 100644 product/src/tools/workBench/AutoStart.h create mode 100644 product/src/tools/workBench/AutoStart.ui create mode 100644 product/src/tools/workBench/BrushDataThread.cpp create mode 100644 product/src/tools/workBench/BrushDataThread.h create mode 100644 product/src/tools/workBench/ButtonForm.cpp create mode 100644 product/src/tools/workBench/ButtonForm.h create mode 100644 product/src/tools/workBench/ButtonForm.ui create mode 100644 product/src/tools/workBench/DbCheck.cpp create mode 100644 product/src/tools/workBench/DbCheck.h create mode 100644 product/src/tools/workBench/DbCheck.ui create mode 100644 product/src/tools/workBench/DbCheckSync.cpp create mode 100644 product/src/tools/workBench/DbCheckSync.h create mode 100644 product/src/tools/workBench/DogCheck.cpp create mode 100644 product/src/tools/workBench/DogCheck.h create mode 100644 product/src/tools/workBench/DogCheck.ui create mode 100644 product/src/tools/workBench/Main.cpp create mode 100644 product/src/tools/workBench/MainWindow.cpp create mode 100644 product/src/tools/workBench/MainWindow.h create mode 100644 product/src/tools/workBench/ModifyButtonForm.cpp create mode 100644 product/src/tools/workBench/ModifyButtonForm.h create mode 100644 product/src/tools/workBench/ModifyButtonForm.ui create mode 100644 product/src/tools/workBench/MonitorCommon.h create mode 100644 product/src/tools/workBench/MyProgressBar.cpp create mode 100644 product/src/tools/workBench/MyProgressBar.h create mode 100644 product/src/tools/workBench/OnTimeCheckThread.cpp create mode 100644 product/src/tools/workBench/OnTimeCheckThread.h create mode 100644 product/src/tools/workBench/ProcMngForm.cpp create mode 100644 product/src/tools/workBench/ProcMngForm.h create mode 100644 product/src/tools/workBench/ProcMngForm.ui create mode 100644 product/src/tools/workBench/SetupFunc.h create mode 100644 product/src/tools/workBench/SetupFuncLinux.cpp create mode 100644 product/src/tools/workBench/SetupFuncWindows.cpp create mode 100644 product/src/tools/workBench/SingleApplication.cpp create mode 100644 product/src/tools/workBench/SingleApplication.h create mode 100644 product/src/tools/workBench/SingleApplication_p.cpp create mode 100644 product/src/tools/workBench/SingleApplication_p.h create mode 100644 product/src/tools/workBench/StartUpForm.cpp create mode 100644 product/src/tools/workBench/StartUpForm.h create mode 100644 product/src/tools/workBench/StartUpForm.ui create mode 100644 product/src/tools/workBench/StatusForm.cpp create mode 100644 product/src/tools/workBench/StatusForm.h create mode 100644 product/src/tools/workBench/StatusForm.ui create mode 100644 product/src/tools/workBench/SystemSetForm.cpp create mode 100644 product/src/tools/workBench/SystemSetForm.h create mode 100644 product/src/tools/workBench/SystemSetForm.ui create mode 100644 product/src/tools/workBench/auto_start.ico create mode 100644 product/src/tools/workBench/db_check.ico create mode 100644 product/src/tools/workBench/dog_auth_check.ico create mode 100644 product/src/tools/workBench/images/restart.png create mode 100644 product/src/tools/workBench/images/start.png create mode 100644 product/src/tools/workBench/images/stop.png create mode 100644 product/src/tools/workBench/img/button_background.png create mode 100644 product/src/tools/workBench/localstateform.cpp create mode 100644 product/src/tools/workBench/localstateform.h create mode 100644 product/src/tools/workBench/localstateform.ui create mode 100644 product/src/tools/workBench/mainwindow.ui create mode 100644 product/src/tools/workBench/resource.qrc create mode 100644 product/src/tools/workBench/sys_startup.ico create mode 100644 product/src/tools/workBench/tool/CheckBoxDialog.cpp create mode 100644 product/src/tools/workBench/tool/CheckBoxDialog.h create mode 100644 product/src/tools/workBench/tool/CommonEnum.h create mode 100644 product/src/tools/workBench/tool/DataMng.cpp create mode 100644 product/src/tools/workBench/tool/DataMng.h create mode 100644 product/src/tools/workBench/tool/InputDialog.cpp create mode 100644 product/src/tools/workBench/tool/InputDialog.h create mode 100644 product/src/tools/workBench/workBench.pro diff --git a/product/src/tools/db_installer/CSqlOpt.cpp b/product/src/tools/db_installer/CSqlOpt.cpp new file mode 100644 index 00000000..c6b4ee64 --- /dev/null +++ b/product/src/tools/db_installer/CSqlOpt.cpp @@ -0,0 +1,157 @@ +#include "CSqlOpt.h" + +#include "../../dbms/db_manager_api/db_manager_api_common.h" +#include "db_manager_api/db_opt_mysql.h" +#include "db_manager_api/db_opt_kingbase.h" +#include "db_manager_api/db_opt_opengauss.h" +#include "db_manager_api/db_manager_api.h" +using namespace iot_dbms; + + +CSqlOpt::CSqlOpt() +{ + +} + +int CSqlOpt::installer() +{ + mysql_opt(); + kingbase_opt(); + opengauss_opt(); + return 0; +} + +int CSqlOpt::mysql_opt() +{ + db_opt_mysql pDbOpt; + QString sDatabaseName = EMS_DEFAULT_DATABASE; + + if (pDbOpt.openDatabase("127.0.0.1",3306,"root","kbdct@0755","mysql")) + { + QString sError = ""; + QString sSql = QString("update mysql.user set password=password('%1') where user='root'; and Host ='localhost';").arg(EMS_DEFAULT_PASSWD) ; + bool result = pDbOpt.executeSql( sSql, sError ); + if(!result) + { + QString sSql = QString("UPDATE mysql.user SET authentication_string=PASSWORD('%1') WHERE User='root'; and Host ='localhost';").arg(EMS_DEFAULT_PASSWD) ; + result = pDbOpt.executeSql( sSql, sError ); + if(!result) + { + return -1; + } + } + + result = pDbOpt.executeSql( "flush privileges;", sError ); + if(!result) + { + return -1; + } + } + + if (!pDbOpt.openDatabase("127.0.0.1",3306,"root",EMS_DEFAULT_PASSWD,"")) + { + return -1; + } + + QString sSql; + sSql = "CREATE DATABASE " + sDatabaseName; + QString sError = ""; + + bool result = pDbOpt.executeSql( sSql, sError ); + if(!result) + { + return -1; + } + + db_manager_api api; + if(!api.updateDatabase(&pDbOpt, sDatabaseName,true)) + { + return -1; + } + + return 0; +} + +int CSqlOpt::kingbase_opt() +{ + db_opt_kingbase pDbOpt; + QString sDatabaseName = EMS_DEFAULT_DATABASE; + + if (pDbOpt.openDatabase("127.0.0.1",54321,"system","kbdct@0755","")) + { + //金仓数据库的处理 + QString sSql; + QString sError = ""; + sSql = QString("ALTER USER system WITH PASSWORD '%1';").arg(EMS_DEFAULT_PASSWD) ; + bool result = pDbOpt.executeSql( sSql, sError ); + if(!result) + { + return -1; + } + } + + if (!pDbOpt.openDatabase("127.0.0.1",54321,"system",EMS_DEFAULT_PASSWD,"")) + { + return -1; + } + + QString sSql; + sSql = "CREATE DATABASE " + sDatabaseName; + QString sError = ""; + + bool result = pDbOpt.executeSql( sSql, sError ); + if(!result) + { + return -1; + } + + db_manager_api api; + if(!api.updateDatabase(&pDbOpt, sDatabaseName,true)) + { + return -1; + } + + return 0; +} + +int CSqlOpt::opengauss_opt() +{ + db_opt_opengauss pDbOpt; + QString sDatabaseName = EMS_DEFAULT_DATABASE; + + if (pDbOpt.openDatabase("127.0.0.1",5432,"iscs","kbdct@0755","")) + { + //高斯数据库的处理 + QString sSql; + QString sError = ""; + sSql = QString("ALTER USER iscs identified by '%1' replace 'kbdct@0755';").arg(EMS_DEFAULT_PASSWD) ; + bool result = pDbOpt.executeSql( sSql, sError ); + if(!result) + { + return -1; + } + } + + if (!pDbOpt.openDatabase("127.0.0.1",5432,"iscs",EMS_DEFAULT_PASSWD,"")) + { + return -1; + } + + QString sSql; + sSql = "CREATE DATABASE " + sDatabaseName; + QString sError = ""; + + bool result = pDbOpt.executeSql( sSql, sError ); + if(!result) + { + return -1; + } + + db_manager_api api; + if(!api.updateDatabase(&pDbOpt, sDatabaseName,true)) + { + return -1; + } + + return 0; +} diff --git a/product/src/tools/db_installer/CSqlOpt.h b/product/src/tools/db_installer/CSqlOpt.h new file mode 100644 index 00000000..2fa86eff --- /dev/null +++ b/product/src/tools/db_installer/CSqlOpt.h @@ -0,0 +1,18 @@ +#ifndef CSQLOPT_H +#define CSQLOPT_H + +#include + +class CSqlOpt +{ +public: + CSqlOpt(); +public: + int installer(); +private: + int mysql_opt(); + int kingbase_opt(); + int opengauss_opt(); +}; + +#endif // CSQLOPT_H diff --git a/product/src/tools/db_installer/db_installer.pro b/product/src/tools/db_installer/db_installer.pro new file mode 100644 index 00000000..d2dea611 --- /dev/null +++ b/product/src/tools/db_installer/db_installer.pro @@ -0,0 +1,40 @@ +QT -= gui +QT += sql xml network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +#CONFIG += c++11 console + +TARGET = db_installer +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# QMAKE_CXXFLAGS+=/execution-charset:utf-8 + + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + CSqlOpt.cpp \ + main.cpp + +HEADERS += \ + CSqlOpt.h + +LIBS += -lpub_utility_api -ldb_manager_api -ldb_base_api + +#------------------------------------------------------------------- +COMMON_PRI=$$PWD/../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} diff --git a/product/src/tools/db_installer/main.cpp b/product/src/tools/db_installer/main.cpp new file mode 100644 index 00000000..e8aa53d5 --- /dev/null +++ b/product/src/tools/db_installer/main.cpp @@ -0,0 +1,13 @@ +// RQEH6000mysql_update.cpp : 定义控制台应用程序的入口点。 +// + +#include + +#include "CSqlOpt.h" +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + CSqlOpt opt; + return opt.installer(); +} + diff --git a/product/src/tools/debug_tool_v2/CActiveWindow.cpp b/product/src/tools/debug_tool_v2/CActiveWindow.cpp new file mode 100644 index 00000000..d04dd51f --- /dev/null +++ b/product/src/tools/debug_tool_v2/CActiveWindow.cpp @@ -0,0 +1,27 @@ +#include "CActiveWindow.h" +#include "pub_logger_api/logger.h" +CActiveWindow * CActiveWindow::m_pInstance = NULL; +CActiveWindow *CActiveWindow::instance() +{ + if(NULL == m_pInstance) + { + m_pInstance = new CActiveWindow(); + } + return m_pInstance; +} + +void CActiveWindow::setActiveWindow(int windowId) +{ + LOGINFO("setActiveWindow():设置激活窗口为%d",windowId); + m_nActive = windowId; +} + +int CActiveWindow::getActiveWindow() +{ + return m_nActive; +} + +CActiveWindow::CActiveWindow() +{ + m_nActive = (int)E_ACTIVE_WINDOW_FES; +} diff --git a/product/src/tools/debug_tool_v2/CActiveWindow.h b/product/src/tools/debug_tool_v2/CActiveWindow.h new file mode 100644 index 00000000..20ff7708 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CActiveWindow.h @@ -0,0 +1,47 @@ +#ifndef CACTIVEWINDOW_H +#define CACTIVEWINDOW_H + +#include +enum E_ACTIVE_WINDOW_ID +{ + E_ACTIVE_WINDOW_FES = 0, + E_ACTIVE_WINDOW_FES_AI_DATA = 1, + E_ACTIVE_WINDOW_FES_DI_DATA, + E_ACTIVE_WINDOW_FES_PI_DATA, + E_ACTIVE_WINDOW_FES_MI_DATA , + E_ACTIVE_WINDOW_FES_AI_CTRL, + E_ACTIVE_WINDOW_FES_DI_CTRL, + E_ACTIVE_WINDOW_FES_PI_CTRL, + E_ACTIVE_WINDOW_FES_MI_CTRL, + E_ACTIVE_WINDOW_FES_EVENT_CTRL, + E_ACTIVE_WINDOW_FES_AO_CTRL, + E_ACTIVE_WINDOW_FES_DO_CTRL, + E_ACTIVE_WINDOW_FES_MO_CTRL, + E_ACTIVE_WINDOW_FES_CUSTOM_CTRL, + E_ACTIVE_WINDOW_FES_AI_FARWARD, + E_ACTIVE_WINDOW_FES_DI_FARWARD, + E_ACTIVE_WINDOW_FES_DDI_FARWARD, + E_ACTIVE_WINDOW_FES_PI_FARWARD, + E_ACTIVE_WINDOW_FES_MI_FARWARD, + E_ACTIVE_WINDOW_FES_SOE_EVENT, + E_ACTIVE_WINDOW_FES_CHAN_EVENT, + E_ACTIVE_WINDOW_FES_SOE_MEMORY, + E_ACTIVE_WINDOW_FES_CHAN_PARAM, + E_ACTIVE_WINDOW_FES_RTU_PARAM, + E_ACTIVE_WINDOW_FES_CHAN_DATA +}; + +class CActiveWindow +{ +public: + static CActiveWindow *instance(); + + void setActiveWindow(int windowId); + int getActiveWindow(); + CActiveWindow(); +private: + int m_nActive; + static CActiveWindow * m_pInstance; +}; + +#endif // CACTIVEWINDOW_H diff --git a/product/src/tools/debug_tool_v2/CDataMng.cpp b/product/src/tools/debug_tool_v2/CDataMng.cpp new file mode 100644 index 00000000..98b18bd6 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CDataMng.cpp @@ -0,0 +1,585 @@ +#include "CDataMng.h" +#include "db_api_ex/CDbApi.h" +#include "pub_logger_api/logger.h" +#include "Common.h" + +CDataMng *CDataMng::m_pInstance = Q_NULLPTR; +CDataMng *CDataMng::instance() +{ + if(m_pInstance == Q_NULLPTR) + { + m_pInstance = new CDataMng(); + } + return m_pInstance; +} + +CDataMng::~CDataMng() +{ + if(m_pReadApi != Q_NULLPTR) + { + m_pReadApi->close(); + delete m_pReadApi; + } + m_pReadApi = Q_NULLPTR; + m_pInstance = Q_NULLPTR; +} + +ChanInfoMap CDataMng::getChanInfo() +{ + if(!m_chanHaveLoad) + { + m_chanMap.clear(); + QSqlQuery sqlQueue; + m_pReadApi->execute("SELECT TAG_NAME,CHAN_NO,DESCRIPTION,RES_PARA_INT4 FROM fes_channel_para ORDER BY CHAN_NO", sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + //采用下标方式,提高效率,注意与SELECT语句顺序对应 + QString tagName = sqlQueue.value(0).toString(); + int chanNo = sqlQueue.value(1).toInt(); + QString chanDesc = sqlQueue.value(2).toString(); + int res_para_int4 = sqlQueue.value(3).toInt(); + + SFESCHANINFO &fesChan = m_chanMap[chanNo]; + fesChan.nChanNo = chanNo; + fesChan.strTagName = tagName; + fesChan.strDesc = chanDesc; + fesChan.nLocalPort = res_para_int4; + } + m_chanHaveLoad = true; + } + } + return m_chanMap; +} + +void CDataMng::loadAllDevInfo(const bool bForceLoad/*= false*/) +{ + if(bForceLoad) + { + m_rtuDevMap.clear(); + } + + if(!m_rtuDevMap.empty()) + { + return; + } + + QSqlQuery sqlQueue; + m_pReadApi->execute("SELECT RTU_NO,TAG_NAME,DEV_NAME,DEV_DESC FROM fes_dev_info", sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + //采用下标方式,提高效率,注意与SELECT语句顺序对应 + int rtuNo = sqlQueue.value(0).toInt(); + QString tagName = sqlQueue.value(1).toString(); + QString devName = sqlQueue.value(2).toString(); + QString devDesc = sqlQueue.value(3).toString(); + + SFESDEVINFO &devInfo = m_rtuDevMap[rtuNo][tagName]; + devInfo.nRtuNo = rtuNo; + devInfo.strTagName = tagName; + devInfo.strDevName = devName; + devInfo.strDesc = devDesc; + } + } +} + +RtuDevMap CDataMng::getDevInfo() +{ + return m_rtuDevMap; +} + +const RtuDevMap &CDataMng::getDevInfoRef() +{ + return m_rtuDevMap; +} + +void CDataMng::loadAiInfo(const int nRtuNo, const bool bForceLoad) +{ + if(nRtuNo < 0) + { + return; + } + + loadAllDevInfo(); + + if(bForceLoad) + { + m_rtuAiPointMap.clear(); + } + + if(m_rtuAiPointMap.count(nRtuNo)) + { + return; + } + + MaxAndMinPointNo mapDev2MaxMinPntNo; //记录设备的最大点号和最小点号 + + QSqlQuery sqlQueue; + QString strSQL = QString("SELECT DOT_NO,RTU_NO,TAG_NAME,DESCRIPTION,APP_TAG_NAME,RES_PARA_INT1,DEV_TAG FROM fes_analog WHERE RTU_NO=%1").arg(nRtuNo); + + m_pReadApi->execute(strSQL, sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + //采用下标方式,提高效率,注意与SELECT语句顺序对应 + int pointNo = sqlQueue.value(0).toInt(); + int rtuNo = sqlQueue.value(1).toInt(); + QString tagName = sqlQueue.value(2).toString(); + QString tagDesc = sqlQueue.value(3).toString(); + QString appTagName = sqlQueue.value(4).toString(); + int resPara = sqlQueue.value(5).toInt(); + QString devTag =sqlQueue.value(6).toString(); + + SFESPOINTINFO &pointInfo = m_rtuAiPointMap[rtuNo][pointNo]; + pointInfo.nDotNo = pointNo; + pointInfo.nRtuNo = rtuNo; + pointInfo.strTagName = tagName; + pointInfo.strDesc = tagDesc; + pointInfo.strAppTagName = appTagName; + pointInfo.nRespPara = resPara; + pointInfo.strDevTag = devTag; + pointInfo.strDevDesc = m_rtuDevMap.value(rtuNo).value(devTag).strDesc; + + SFESDEVMAXANDMINPOINTNO & maxminNo = mapDev2MaxMinPntNo[devTag]; + if(pointNo > maxminNo.maxPointNo) + { + maxminNo.maxPointNo = pointNo; + } + if(pointNo < maxminNo.minPointNo) + { + maxminNo.minPointNo = pointNo; + } + } + } + + if(!mapDev2MaxMinPntNo.empty()) + { + m_rtuAiMaxMinNo[nRtuNo].swap(mapDev2MaxMinPntNo); + } +} + +const RtuPointMap &CDataMng::getAiInfoRef() +{ + return m_rtuAiPointMap; +} + +void CDataMng::loadDiInfo(const int nRtuNo, const bool bForceLoad) +{ + if(nRtuNo < 0) + { + return; + } + + loadAllDevInfo(); + + if(bForceLoad) + { + m_rtuDiPointMap.clear(); + } + + if(m_rtuDiPointMap.count(nRtuNo)) + { + return; + } + + MaxAndMinPointNo mapDev2MaxMinPntNo; //记录设备的最大点号和最小点号 + QSqlQuery sqlQueue; + QString strSQL = QString("SELECT DOT_NO,RTU_NO,TAG_NAME,DESCRIPTION,APP_TAG_NAME,RES_PARA_INT1,DEV_TAG FROM fes_digital WHERE RTU_NO=%1").arg(nRtuNo); + + m_pReadApi->execute(strSQL, sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + //采用下标方式,提高效率,注意与SELECT语句顺序对应 + int pointNo = sqlQueue.value(0).toInt(); + int rtuNo = sqlQueue.value(1).toInt(); + QString tagName = sqlQueue.value(2).toString(); + QString tagDesc = sqlQueue.value(3).toString(); + QString appTagName = sqlQueue.value(4).toString(); + int resPara = sqlQueue.value(5).toInt(); + QString devTag =sqlQueue.value(6).toString(); + + SFESPOINTINFO &pointInfo = m_rtuDiPointMap[rtuNo][pointNo]; + pointInfo.nDotNo = pointNo; + pointInfo.nRtuNo = rtuNo; + pointInfo.strTagName = tagName; + pointInfo.strDesc = tagDesc; + pointInfo.strAppTagName = appTagName; + pointInfo.nRespPara = resPara; + pointInfo.strDevTag = devTag; + pointInfo.strDevDesc = m_rtuDevMap.value(rtuNo).value(devTag).strDesc; + + SFESDEVMAXANDMINPOINTNO & maxminNo = mapDev2MaxMinPntNo[devTag]; + if(pointNo > maxminNo.maxPointNo) + { + maxminNo.maxPointNo = pointNo; + } + if(pointNo < maxminNo.minPointNo) + { + maxminNo.minPointNo = pointNo; + } + } + } + + if(!mapDev2MaxMinPntNo.empty()) + { + m_rtuDiMaxMinNo[nRtuNo].swap(mapDev2MaxMinPntNo); + } +} + +const RtuPointMap &CDataMng::getDiInfoRef() +{ + return m_rtuDiPointMap; +} + +const RtuMaxAndMinPointNo &CDataMng::getDiMaxMinNoRef() +{ + return m_rtuDiMaxMinNo; +} + +void CDataMng::loadAccInfo(const int nRtuNo, const bool bForceLoad) +{ + if(nRtuNo < 0) + { + return; + } + + loadAllDevInfo(); + + if(bForceLoad) + { + m_rtuPiPointMap.clear(); + } + + if(m_rtuPiPointMap.count(nRtuNo)) + { + return; + } + + MaxAndMinPointNo mapDev2MaxMinPntNo; //记录设备的最大点号和最小点号 + QSqlQuery sqlQueue; + QString strSQL = QString("SELECT DOT_NO,RTU_NO,TAG_NAME,DESCRIPTION,APP_TAG_NAME,RES_PARA_INT1,DEV_TAG FROM fes_accuml WHERE RTU_NO=%1").arg(nRtuNo); + + m_pReadApi->execute(strSQL, sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + //采用下标方式,提高效率,注意与SELECT语句顺序对应 + int pointNo = sqlQueue.value(0).toInt(); + int rtuNo = sqlQueue.value(1).toInt(); + QString tagName = sqlQueue.value(2).toString(); + QString tagDesc = sqlQueue.value(3).toString(); + QString appTagName = sqlQueue.value(4).toString(); + int resPara = sqlQueue.value(5).toInt(); + QString devTag =sqlQueue.value(6).toString(); + + SFESPOINTINFO &pointInfo = m_rtuPiPointMap[rtuNo][pointNo]; + pointInfo.nDotNo = pointNo; + pointInfo.nRtuNo = rtuNo; + pointInfo.strTagName = tagName; + pointInfo.strDesc = tagDesc; + pointInfo.strAppTagName = appTagName; + pointInfo.nRespPara = resPara; + pointInfo.strDevTag = devTag; + pointInfo.strDevDesc = m_rtuDevMap.value(rtuNo).value(devTag).strDesc; + + SFESDEVMAXANDMINPOINTNO & maxminNo = mapDev2MaxMinPntNo[devTag]; + if(pointNo > maxminNo.maxPointNo) + { + maxminNo.maxPointNo = pointNo; + } + if(pointNo < maxminNo.minPointNo) + { + maxminNo.minPointNo = pointNo; + } + } + } + + if(!mapDev2MaxMinPntNo.empty()) + { + m_rtuPiMaxMinNo[nRtuNo].swap(mapDev2MaxMinPntNo); + } +} + +const RtuPointMap &CDataMng::getAccInfoRef() +{ + return m_rtuPiPointMap; +} + +const RtuMaxAndMinPointNo &CDataMng::getAccMaxMinNoRef() +{ + return m_rtuPiMaxMinNo; +} + +void CDataMng::loadMiInfo(const int nRtuNo, const bool bForceLoad) +{ + if(nRtuNo < 0) + { + return; + } + + loadAllDevInfo(); + + if(bForceLoad) + { + m_rtuMiPointMap.clear(); + } + + if(m_rtuMiPointMap.count(nRtuNo)) + { + return; + } + + MaxAndMinPointNo mapDev2MaxMinPntNo; //记录设备的最大点号和最小点号 + QString strSQL = QString("SELECT DOT_NO,RTU_NO,TAG_NAME,DESCRIPTION,APP_TAG_NAME,RES_PARA_INT1,DEV_TAG FROM fes_mix WHERE RTU_NO=%1").arg(nRtuNo); + QSqlQuery sqlQueue; + + m_pReadApi->execute(strSQL, sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + //采用下标方式,提高效率,注意与SELECT语句顺序对应 + int pointNo = sqlQueue.value(0).toInt(); + int rtuNo = sqlQueue.value(1).toInt(); + QString tagName = sqlQueue.value(2).toString(); + QString tagDesc = sqlQueue.value(3).toString(); + QString appTagName = sqlQueue.value(4).toString(); + int resPara = sqlQueue.value(5).toInt(); + QString devTag =sqlQueue.value(6).toString(); + + SFESPOINTINFO &pointInfo = m_rtuMiPointMap[rtuNo][pointNo]; + pointInfo.nDotNo = pointNo; + pointInfo.nRtuNo = rtuNo; + pointInfo.strTagName = tagName; + pointInfo.strDesc = tagDesc; + pointInfo.strAppTagName = appTagName; + pointInfo.nRespPara = resPara; + pointInfo.strDevTag = devTag; + pointInfo.strDevDesc = m_rtuDevMap.value(rtuNo).value(devTag).strDesc; + + SFESDEVMAXANDMINPOINTNO & maxminNo = mapDev2MaxMinPntNo[devTag]; + if(pointNo > maxminNo.maxPointNo) + { + maxminNo.maxPointNo = pointNo; + } + if(pointNo < maxminNo.minPointNo) + { + maxminNo.minPointNo = pointNo; + } + } + } + + if(!mapDev2MaxMinPntNo.empty()) + { + m_rtuMiMaxMinNo[nRtuNo].swap(mapDev2MaxMinPntNo); + } +} + +const RtuPointMap &CDataMng::getMiInfoRef() +{ + return m_rtuMiPointMap; +} + +const RtuMaxAndMinPointNo &CDataMng::getMiMaxMinNoRef() +{ + return m_rtuMiMaxMinNo; +} + +void CDataMng::loadAoInfo(const int nRtuNo, const bool bForceLoad) +{ + if(nRtuNo < 0) + { + return; + } + + loadAllDevInfo(); + + if(bForceLoad) + { + m_rtuAoPointMap.clear(); + } + + if(m_rtuAoPointMap.count(nRtuNo)) + { + return; + } + + QString strSQL = QString("SELECT DOT_NO,RTU_NO,TAG_NAME,DESCRIPTION,RES_PARA_INT1,DEV_TAG FROM fes_analog_ctrl WHERE RTU_NO=%1").arg(nRtuNo); + QSqlQuery sqlQueue; + m_pReadApi->execute(strSQL, sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + //采用下标方式,提高效率,注意与SELECT语句顺序对应 + int pointNo = sqlQueue.value(0).toInt(); + int rtuNo = sqlQueue.value(1).toInt(); + QString tagName = sqlQueue.value(2).toString(); + QString tagDesc = sqlQueue.value(3).toString(); + int resPara = sqlQueue.value(4).toInt(); + QString devTag =sqlQueue.value(5).toString(); + + SFESPOINTINFO &pointInfo = m_rtuAoPointMap[rtuNo][pointNo]; + pointInfo.nDotNo = pointNo; + pointInfo.nRtuNo = rtuNo; + pointInfo.strTagName = tagName; + pointInfo.strDesc = tagDesc; + pointInfo.nRespPara = resPara; + pointInfo.strDevTag = devTag; + pointInfo.strDevDesc = m_rtuDevMap.value(rtuNo).value(devTag).strDesc; + } + } +} + +const RtuPointMap &CDataMng::getAoInfoRef() +{ + return m_rtuAoPointMap; +} + +void CDataMng::loadDoInfo(const int nRtuNo, const bool bForceLoad) +{ + if(nRtuNo < 0) + { + return; + } + + loadAllDevInfo(); + + if(bForceLoad) + { + m_rtuDoPointMap.clear(); + } + + if(m_rtuDoPointMap.count(nRtuNo)) + { + return; + } + + QString strSQL = QString("SELECT DOT_NO,RTU_NO,TAG_NAME,DESCRIPTION,RES_PARA_INT1,DEV_TAG FROM fes_digital_ctrl WHERE RTU_NO=%1").arg(nRtuNo); + QSqlQuery sqlQueue; + m_pReadApi->execute(strSQL, sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + //采用下标方式,提高效率,注意与SELECT语句顺序对应 + int pointNo = sqlQueue.value(0).toInt(); + int rtuNo = sqlQueue.value(1).toInt(); + QString tagName = sqlQueue.value(2).toString(); + QString tagDesc = sqlQueue.value(3).toString(); + int resPara = sqlQueue.value(4).toInt(); + QString devTag =sqlQueue.value(5).toString(); + + SFESPOINTINFO &pointInfo = m_rtuDoPointMap[rtuNo][pointNo]; + pointInfo.nDotNo = pointNo; + pointInfo.nRtuNo = rtuNo; + pointInfo.strTagName = tagName; + pointInfo.strDesc = tagDesc; + pointInfo.nRespPara = resPara; + pointInfo.strDevTag = devTag; + pointInfo.strDevDesc = m_rtuDevMap.value(rtuNo).value(devTag).strDesc; + } + } +} + +const RtuPointMap &CDataMng::getDoInfoRef() +{ + return m_rtuDoPointMap; +} + +void CDataMng::loadMoInfo(const int nRtuNo, const bool bForceLoad) +{ + if(nRtuNo < 0) + { + return; + } + + loadAllDevInfo(); + + if(bForceLoad) + { + m_rtuMoPointMap.clear(); + } + + if(m_rtuMoPointMap.count(nRtuNo)) + { + return; + } + + QString strSQL = QString("SELECT DOT_NO,RTU_NO,TAG_NAME,DESCRIPTION,RES_PARA_INT1,DEV_TAG FROM fes_mix_ctrl WHERE RTU_NO=%1").arg(nRtuNo); + QSqlQuery sqlQueue; + + m_pReadApi->execute(strSQL, sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + //采用下标方式,提高效率,注意与SELECT语句顺序对应 + int pointNo = sqlQueue.value(0).toInt(); + int rtuNo = sqlQueue.value(1).toInt(); + QString tagName = sqlQueue.value(2).toString(); + QString tagDesc = sqlQueue.value(3).toString(); + int resPara = sqlQueue.value(4).toInt(); + QString devTag =sqlQueue.value(5).toString(); + + SFESPOINTINFO &pointInfo = m_rtuMoPointMap[rtuNo][pointNo]; + pointInfo.nDotNo = pointNo; + pointInfo.nRtuNo = rtuNo; + pointInfo.strTagName = tagName; + pointInfo.strDesc = tagDesc; + pointInfo.nRespPara = resPara; + pointInfo.strDevTag = devTag; + pointInfo.strDevDesc = m_rtuDevMap.value(rtuNo).value(devTag).strDesc; + } + } +} + +const RtuPointMap &CDataMng::getMoInfoRef() +{ + return m_rtuMoPointMap; +} + +QVector CDataMng::getAppInfo() +{ + m_appVec.clear(); + QSqlQuery ret; + QString strSql = "SELECT APP_ID,TAG_NAME,DESCRIPTION FROM sys_model_app_info ORDER BY APP_ID"; + m_pReadApi->execute(strSql,ret); + if(ret.isActive()) + { + while(ret.next()) + { + FesAppName fesApp; + fesApp.appId = ret.value("APP_ID").toInt(); + fesApp.desc = ret.value("DESCRIPTION").toString(); + fesApp.appName = ret.value("TAG_NAME").toString(); + + if(fesApp.appId > CN_AppId_COMAPP) + { + m_appVec.append(fesApp); + } + } + + } + return m_appVec; +} + +const RtuMaxAndMinPointNo &CDataMng::getAiMaxMinNoRef() +{ + return m_rtuAiMaxMinNo; +} + +CDataMng::CDataMng():QObject(), + m_pReadApi(Q_NULLPTR), + m_chanHaveLoad(false) +{ + m_pReadApi = new iot_dbms::CDbApi(DB_CONN_MODEL_READ); + m_pReadApi->open(); +} diff --git a/product/src/tools/debug_tool_v2/CDataMng.h b/product/src/tools/debug_tool_v2/CDataMng.h new file mode 100644 index 00000000..92dd7181 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CDataMng.h @@ -0,0 +1,185 @@ +#ifndef CDATAMNG_H +#define CDATAMNG_H + +#include +#include "toolCommon.h" +#include "db_api_ex/CDbApi.h" + +class QMutex; + +class CDataMng : public QObject +{ + Q_OBJECT +public: + static CDataMng * instance(); + ~CDataMng(); + + ChanInfoMap getChanInfo(); + RtuDevMap getDevInfo(); + void loadAllDevInfo(const bool bForceLoad = false); + const RtuDevMap& getDevInfoRef(); + + void loadAiInfo(const int nRtuNo,const bool bForceLoad = false); + const RtuPointMap& getAiInfoRef(); + const RtuMaxAndMinPointNo& getAiMaxMinNoRef(); + + void loadDiInfo(const int nRtuNo,const bool bForceLoad = false); + const RtuPointMap& getDiInfoRef(); + const RtuMaxAndMinPointNo& getDiMaxMinNoRef(); + + void loadAccInfo(const int nRtuNo,const bool bForceLoad = false); + const RtuPointMap& getAccInfoRef(); + const RtuMaxAndMinPointNo& getAccMaxMinNoRef(); + + void loadMiInfo(const int nRtuNo,const bool bForceLoad = false); + const RtuPointMap& getMiInfoRef(); + const RtuMaxAndMinPointNo& getMiMaxMinNoRef(); + + void loadAoInfo(const int nRtuNo,const bool bForceLoad = false); + const RtuPointMap& getAoInfoRef(); + + void loadDoInfo(const int nRtuNo,const bool bForceLoad = false); + const RtuPointMap& getDoInfoRef(); + + void loadMoInfo(const int nRtuNo,const bool bForceLoad = false); + const RtuPointMap& getMoInfoRef(); + + QVector getAppInfo(); + +signals: + void signal_sendMsgToServer(const std::string &strMsg); + + //FesParam + //通道状态 - 通道参数 + void signal_chanParamResp(int nMsgType, const std::string &strBody); + //通道状态 - RTU参数 + void signal_rtuParamResp(int nMsgType, const std::string &strBody); + + //FesData + //前置数据 - 模拟量 + void signal_aiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_aiParamResp(int nMsgType,const std::string &strBody); + void signal_aiValueResp(int nMsgType,const std::string &strBody); + //前置数据 - 数字量 + void signal_diRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_diParamResp(int nMsgType,const std::string &strBody); + void signal_diValueResp(int nMsgType,const std::string &strBody); + //前置数据 - 累积量 + void signal_accRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_accParamResp(int nMsgType,const std::string &strBody); + void signal_accValueResp(int nMsgType,const std::string &strBody); + //前置数据 - 混合量 + void signal_miRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_miParamResp(int nMsgType,const std::string &strBody); + void signal_miValueResp(int nMsgType,const std::string &strBody); + + //数据仿真 - 模拟量 + void signal_simAiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simAiParamResp(int nMsgType,const std::string &strBody); + void signal_simAiValueResp(int nMsgType,const std::string &strBody); + void signal_simAiStartSimResp(int nMsgType,const std::string &strBody); + void signal_simAiStopSimResp(int nMsgType,const std::string &strBody); + + //数据仿真 - 数字量 + void signal_simDiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simDiParamResp(int nMsgType,const std::string &strBody); + void signal_simDiValueResp(int nMsgType,const std::string &strBody); + void signal_simDiStartSimResp(int nMsgType,const std::string &strBody); + void signal_simDiStopSimResp(int nMsgType,const std::string &strBody); + + //数据仿真 - 混合量 + void signal_simMiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simMiParamResp(int nMsgType,const std::string &strBody); + void signal_simMiValueResp(int nMsgType,const std::string &strBody); + void signal_simMiStartSimResp(int nMsgType,const std::string &strBody); + void signal_simMiStopSimResp(int nMsgType,const std::string &strBody); + + //数据仿真 - 累积量 + void signal_simAccRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simAccParamResp(int nMsgType,const std::string &strBody); + void signal_simAccValueResp(int nMsgType,const std::string &strBody); + void signal_simAccStartSimResp(int nMsgType,const std::string &strBody); + void signal_simAccStopSimResp(int nMsgType,const std::string &strBody); + + //数据仿真 - 事件仿真 + void signal_simEventRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simEventDiParamResp(int nMsgType,const std::string &strBody); + void signal_simEventCreateResp(int nMsgType,const std::string &strBody); + + //控制仿真 - 模拟量 + void signal_simAoRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simAoParamResp(int nMsgType,const std::string &strBody); + void signal_simAoControlResp(int nMsgType,const std::string &strBody); + + //控制仿真 - 数字量 + void signal_simDoRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simDoParamResp(int nMsgType,const std::string &strBody); + void signal_simDoControlResp(int nMsgType,const std::string &strBody); + + //控制仿真 - 混合量 + void signal_simMoRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simMoParamResp(int nMsgType,const std::string &strBody); + void signal_simMoControlResp(int nMsgType,const std::string &strBody); + + //控制仿真 - 自定义命令 + void signal_simDefCmdRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simDefCmdControlResp(int nMsgType,const std::string &strBody); + + //转发数据 - 模拟量 + void signal_fwAiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwAiParamResp(int nMsgType,const std::string &strBody); + void signal_fwAiValueResp(int nMsgType,const std::string &strBody); + //转发数据 - 数字量(单位开关) + void signal_fwDiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwDiParamResp(int nMsgType,const std::string &strBody); + void signal_fwDiValueResp(int nMsgType,const std::string &strBody); + //转发数据 - 数字量(双位开关) + void signal_fwDDiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwDDiParamResp(int nMsgType,const std::string &strBody); + void signal_fwDDiValueResp(int nMsgType,const std::string &strBody); + //转发数据 - 混合量 + void signal_fwMiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwMiParamResp(int nMsgType,const std::string &strBody); + void signal_fwMiValueResp(int nMsgType,const std::string &strBody); + //转发数据 - 累积量 + void signal_fwAccRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwAccParamResp(int nMsgType,const std::string &strBody); + void signal_fwAccValueResp(int nMsgType,const std::string &strBody); + + //事件监视 + void signal_soeEventResp(int nMsgType,const std::string &strBody); + void signal_chanEventResp(int nMsgType,const std::string &strBody); + void signal_soeMemEventResp(int nMsgType,const std::string &strBody); + +private: + CDataMng(); + +private: + static CDataMng *m_pInstance; + iot_dbms::CDbApi *m_pReadApi; + bool m_chanHaveLoad; + + RtuDevMap m_rtuDevMap; + RtuPointMap m_rtuAiPointMap; + RtuPointMap m_rtuDiPointMap; + RtuPointMap m_rtuPiPointMap; + RtuPointMap m_rtuMiPointMap; + + RtuPointMap m_rtuAoPointMap; + RtuPointMap m_rtuDoPointMap; + RtuPointMap m_rtuMoPointMap; + + ChanInfoMap m_chanMap; + + RtuMaxAndMinPointNo m_rtuAiMaxMinNo; + RtuMaxAndMinPointNo m_rtuDiMaxMinNo; + RtuMaxAndMinPointNo m_rtuPiMaxMinNo; + RtuMaxAndMinPointNo m_rtuMiMaxMinNo; + RtuMaxAndMinPointNo m_rtuAoMaxMinNo; + RtuMaxAndMinPointNo m_rtuDoMaxMinNo; + RtuMaxAndMinPointNo m_rtuMoMaxMinNo; + + QVector m_appVec; +}; + +#endif // CDATAMNG_H diff --git a/product/src/tools/debug_tool_v2/CDebugTool.cpp b/product/src/tools/debug_tool_v2/CDebugTool.cpp new file mode 100644 index 00000000..9267d5dd --- /dev/null +++ b/product/src/tools/debug_tool_v2/CDebugTool.cpp @@ -0,0 +1,268 @@ +#include "CDebugTool.h" +#include "ui_CDebugTool.h" +#include +#include "CommonSheet.h" +#include "pub_utility_api/FileUtil.h" + +CDebugTool::CDebugTool(CSystemResources *pSystemResources, QWidget *parent): + m_pSystemResources(pSystemResources), + CustomUiMainWindow(parent), + m_pFessim(NULL), + m_pUpdateThread(NULL), + m_pEventFormShow(NULL), + ui(new Ui::CDebugTool) +{ + ui->setupUi(this); + + //setMinimumSize(1200,755); + setWindowTitle(tr("工程调试工具")); + setWindowIcon(QIcon(":/debug_tool.ico")); + CommonSheet sheetStyle; + QString sheet; + if(sheetStyle.getSheet(sheet)) + { + setStyleSheet(sheet); + }else + { + LOGERROR("MainWindow::initSheet():获取样式文件失败!"); + } + initDebugTool(); + + setTitleWidget(ui->mainmenu); + connect(ui->tabWidget,&QTabWidget::currentChanged,this,&CDebugTool::changeTab); +} + +CDebugTool::~CDebugTool() +{ + //releaseResouce(); + if(m_pUpdateThread) + { + delete m_pUpdateThread; + m_pUpdateThread =NULL; + } + + delete ui; +} + +void CDebugTool::initDebugTool() +{ + initLogSystem(); + initVariable(); + initView(); + connectSignalSlot(); + + m_pUpdateThread->start(); +} + + +void CDebugTool::initVariable() +{ + m_pRealDataSelect = new CRealDataSelect; + m_pRealDataWatch = new CRealDataWatch; + m_pRealDatabaseSelect = new CRealDatabaseSelect; + m_pRealDatabaseShow = new CRealDatabaseShow; + m_pUpdateThread = new CUpdateThread; + m_pEventFormShow = new CEventFormShow; + + +} + +void CDebugTool::initView() +{ + addRealData(); + addRealAlarm(); + addRealEvent(); + addHistoryEvent(); + addRealDataBase(); + + ui->splitter_2->setSizes(QList()<<200<<900); + ui->splitter->setSizes(QList()<<200<<900); + +} + +void CDebugTool::addRealData() +{ + QGridLayout *gridLayout = new QGridLayout(ui->groupBox_1); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pRealDataSelect, 0, 0, 1, 1); + m_pRealDataSelect->setSystemResources(m_pSystemResources); + m_pRealDataSelect->initSelect(); + + + + gridLayout = new QGridLayout(ui->groupBox_2); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pRealDataWatch, 0, 0, 1, 1); + m_pRealDataWatch->setSystemResources(m_pSystemResources); + m_pRealDataWatch->initWatch(); + ui->textEdit_status->setToolTip("具体状态"); + + m_pRealDataSelect->setRealDataWatch(m_pRealDataWatch); + +} +void CDebugTool::addRealAlarm() +{ + QGridLayout *gridLayout = new QGridLayout(ui->tab); + ui->textEdit_status->setHidden(true); + ui->tab->setLayout(gridLayout); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pEventFormShow, 0, 0, 1, 1); + m_pEventFormShow->setSystemResources(m_pSystemResources); + m_pEventFormShow->initRealModel(); + //m_pEventFormShow->setSystemResources(m_pSystemResources); + // m_pAlarmFormShow->initSelect(); + +} +void CDebugTool::addRealEvent() +{ + +} +void CDebugTool::addHistoryEvent() +{ + +} +void CDebugTool::addRealDataBase() +{ + QGridLayout *gridLayout4 = new QGridLayout(ui->groupBox_4); + gridLayout4->setSpacing(6); + gridLayout4->setContentsMargins(0, 0, 0, 0); + gridLayout4->addWidget(m_pRealDatabaseSelect, 0, 0, 1, 1); + m_pRealDatabaseSelect->initRealDb(m_pSystemResources); + + QGridLayout * gridLayout5 = new QGridLayout(ui->groupBox_5); + gridLayout5->setSpacing(6); + gridLayout5->setContentsMargins(0, 0, 0, 0); + gridLayout5->addWidget(m_pRealDatabaseShow, 0, 0, 1, 1); + m_pRealDatabaseShow->initRealDatabaseShow(m_pSystemResources); +} +void CDebugTool::addNodeStatus() +{ +// QGridLayout *gridLayout = new QGridLayout(ui->tab_nodeStatus); +// gridLayout->setSpacing(6); +// gridLayout->setContentsMargins(0, 0, 0, 0); +// gridLayout->addWidget(m_pNodeStatus, 0, 0, 1, 1); +} + +void CDebugTool::addFessim() +{ + QGridLayout *gridLayout = new QGridLayout(ui->tab_fes); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pFessim, 0, 0, 1, 1); + m_pFessim->Init(); +} + +void CDebugTool::initLogSystem() +{ +// QString app = QString::fromStdString(CN_AppName_BASE); +// iot_public::StartLogSystem(app.toStdString().c_str(),CN_ProcName_debug_tool.c_str()); +// LOGINFO("initLogSystem()成功!"); +} + +void CDebugTool::initMsgBus() +{ + //< 初始化消息总线库 + if (!(iot_net::initMsgBus("debugToolAppName", "debugToolProcessName"))) + { + qDebug() << "Initialize message bus failed, exit !" << endl; + LOGERROR("Initialize message bus failed, exit !"); + return; + } + else + { + qDebug() << "Initialize message bus successed !" << endl; + LOGINFO("Initialize message bus successed !"); + + } + iot_service::CDpcdaForApp::initGlobalThread(); + return; +} + +void CDebugTool::releaseResouce() +{ + iot_service::CDpcdaForApp::releaseGlobalThread(); + + //< 释放消息总线库 + iot_net::releaseMsgBus(); + + //< 停止日志系统 + //iot_public::StopLogSystem(); + +} + +void CDebugTool::connectSignalSlot() +{ + connect(m_pRealDataSelect,SIGNAL(signal_addPoint(QString,uint,QString,uint,QString,QString,QString,QString,QString,QString,QString,int,QString)), + m_pRealDataWatch,SLOT(slot_addPoint(QString,uint,QString,uint,QString,QString,QString,QString,QString,QString,QString,int,QString))); + connect(m_pUpdateThread,SIGNAL(signal_updateAi(QString,float,uint)), + m_pRealDataWatch,SLOT(slot_updateAi(QString,float,uint))); + connect(m_pUpdateThread,SIGNAL(signal_updateDi(QString,int,uint)), + m_pRealDataWatch,SLOT(slot_updateDi(QString,int,uint))); + connect(m_pUpdateThread,SIGNAL(signal_updatePi(QString,double,uint)), + m_pRealDataWatch,SLOT(slot_updatePi(QString,double,uint))); + connect(m_pUpdateThread,SIGNAL(signal_updateMi(QString,int,uint)), + m_pRealDataWatch,SLOT(slot_updateMi(QString,int,uint))); + connect(m_pRealDatabaseSelect,SIGNAL(signal_showTable(QString,QVector*,int,int,int,int,QMap,QString,QString)), + m_pRealDatabaseShow,SLOT(slot_showTable(QString,QVector*,int,int,int,int,QMap,QString,QString))); + connect(m_pRealDatabaseSelect,SIGNAL(signal_showOrHideColumn(int,int)), + m_pRealDatabaseShow,SLOT(slot_showOrHindColumn(int,int))); + connect(m_pRealDataWatch,SIGNAL(signal_selectTextEdit(QString ,QString , int )), + this,SLOT(slot_selectTextEdit(QString,QString, int ))); + connect(m_pRealDataWatch,SIGNAL(signal_paging()),m_pRealDataSelect,SLOT(slot_paging())); + connect(m_pRealDatabaseShow,SIGNAL(signal_selectTextEdit(QString)), + this,SLOT(slot_selectTextEdit(QString))); +} + +void CDebugTool::changeTab(int index) +{ + switch (index) { + case 0: + ui->textEdit_status->setHidden(true); + break; + case 1: + ui->textEdit_status->setHidden(false); + break; + case 2:{ + ui->textEdit_status->setHidden(false); + break; + } + case 3: + { + ui->textEdit_status->setHidden(true); + if(m_pFessim == NULL) + { + m_pFessim = new CFessim; + addFessim(); + } + //此处判断是否连接 若连接 则不做处理 若断开状态 则直接调用连接 + if(!m_pFessim->isConnect()) + { + if(!m_pFessim->slot_connect()) + { + return ; + } + int index = m_pFessim->getCurrentIndex(); + m_pFessim->setActiveWindow(index); + } + break; + } + default: + break; + } +} + +void CDebugTool::slot_selectTextEdit(QString allStatus, QString m_allName, int m_value) +{ + ui->textEdit_status->setReadOnly(true); + ui->textEdit_status->setText("当前标签为"+m_allName+", 值为" + +QString::number(m_value)+", 状态为" + +allStatus); + +} +void CDebugTool::slot_selectTextEdit(QString allQString) +{ ui->textEdit_status->setReadOnly(true); + ui->textEdit_status->setText(allQString); +} diff --git a/product/src/tools/debug_tool_v2/CDebugTool.h b/product/src/tools/debug_tool_v2/CDebugTool.h new file mode 100644 index 00000000..9b4a585b --- /dev/null +++ b/product/src/tools/debug_tool_v2/CDebugTool.h @@ -0,0 +1,83 @@ +#ifndef CDEBUGTOOL_H +#define CDEBUGTOOL_H + +#include "CFessim.h" +#include "CNodeStatus.h" +#include "CRealDatabaseSelect.h" +#include "CRealDatabaseShow.h" +#include "CRealDataControl.h" +#include "CRealDataSelect.h" +#include "CRealDataWatch.h" +#include "CSystemResources.h" +#include "CUpdateThread.h" +#include "CEventFormShow.h" +#include "pub_logger_api/logger.h" +#include "net_msg_bus_api/MsgBusApi.h" +#include "pub_widget/NcFramelessHelper.h" + +#include +#include +#include "pub_widget/CustomMainWindow.h" + +namespace Ui { +class CDebugTool; +} + +class CDebugTool : public CustomUiMainWindow +{ + Q_OBJECT + +public: + explicit CDebugTool(CSystemResources *pSystemResources,QWidget *parent = 0); + ~CDebugTool(); + + +private: + + + CSystemResources * m_pSystemResources; + + CRealDataSelect * m_pRealDataSelect; + CRealDataWatch * m_pRealDataWatch; + CRealDatabaseSelect * m_pRealDatabaseSelect; + CRealDatabaseShow * m_pRealDatabaseShow; + CEventFormShow * m_pEventFormShow; + //CNodeStatus * m_pNodeStatus; + CFessim * m_pFessim; + CUpdateThread * m_pUpdateThread; + + Ui::CDebugTool *ui; + + +private: + +// void loadStyle(); + void initDebugTool(); + + void initVariable(); + void initView(); + + void addRealData(); + void addRealAlarm(); + void addRealEvent(); + void addHistoryEvent(); + void addRealDataBase(); + void addNodeStatus(); + void addFessim(); + + void initMsgBus(); + void initLogSystem(); + + void releaseResouce(); + + void connectSignalSlot(); +private slots: + void changeTab(int index); + void slot_selectTextEdit(QString allStatus,QString m_allName, int m_value); + void slot_selectTextEdit(QString allQString); + +private: + +}; + +#endif // CDEBUGTOOL_H diff --git a/product/src/tools/debug_tool_v2/CDebugTool.ui b/product/src/tools/debug_tool_v2/CDebugTool.ui new file mode 100644 index 00000000..6070a12f --- /dev/null +++ b/product/src/tools/debug_tool_v2/CDebugTool.ui @@ -0,0 +1,178 @@ + + + CDebugTool + + + + 0 + 0 + 800 + 500 + + + + CDebugTool + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + 0 + + + + + 0 + 0 + + + + 事件信息 + + + + + 实时数据 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 测点选择 + + + + + 测点监控 + + + + + + + + + 实时库表 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 表选择 + + + + + 表内容 + + + + + + + + + 前置数据 + + + + + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + + + + + + + WorkFrame + QWidget +
pub_widget/WorkFrame.h
+ 1 +
+
+ + +
diff --git a/product/src/tools/debug_tool_v2/CEventDataCollect.cpp b/product/src/tools/debug_tool_v2/CEventDataCollect.cpp new file mode 100644 index 00000000..2a66d244 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventDataCollect.cpp @@ -0,0 +1,893 @@ +#include "CEventDataCollect.h" +#include +#include "pub_widget/MessageBox.h" +#include +#include +#include "pub_logger_api/logger.h" +#include "net_msg_bus_api/MsgBusApi.h" +#include "public/pub_sysinfo_api/SysInfoApi.h" +#include "perm_mng_api/PermMngApi.h" +#include "CEventMsgManage.h" + +//< 屏蔽xml_parser编译告警 +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-copy" +#endif + +#include "boost/property_tree/xml_parser.hpp" + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + +#include "boost/typeof/typeof.hpp" +#include "boost/filesystem.hpp" +#include "Common.h" +#include "pub_utility_api/FileUtil.h" +#include "pub_utility_api/CharUtil.h" +#include "dbms/db_api_ex/CDbApi.h" + +using namespace std; +using namespace iot_public; +using namespace iot_dbms; + +CEventDataCollect * CEventDataCollect::m_pInstance = NULL; +CSystemResources *m_pSystemResources=NULL; +CEventDataCollect * CEventDataCollect::instance() +{ + if(NULL == m_pInstance) + { + m_pInstance = new CEventDataCollect(); + } + return m_pInstance; +} + +void CEventDataCollect::setSystemResources(CSystemResources *pSystemResources) +{ + if(m_pSystemResources==NULL){ + m_pSystemResources=pSystemResources; + } +} + +CEventDataCollect::CEventDataCollect() + : m_pTimer(NULL) +{ + msgMutex = new QMutex(); + //m_rtdbPriorityOrderAccess = new iot_dbms::CRdbAccess(); + //m_rtdbPriorityOrderAccess->open("base", "alarm_level_define"); + //m_rtdbAccess = new iot_dbms::CRdbAccess(); + m_pTimer = new QTimer(); + m_pTimer->setInterval(1000); + connect(m_pTimer, &QTimer::timeout, this, &CEventDataCollect::slotUpdateEvent); + + initialize(); +} + +int CEventDataCollect::queryPriorityOrder(int &id) +{ + int nRet = -1; + if ( m_priorityOrderMap.contains(id) ) + nRet = m_priorityOrderMap[id]; + return nRet; + +// iot_dbms::CTableLockGuard locker(*m_rtdbPriorityOrderAccess); +// iot_dbms::CVarType value; +// m_rtdbPriorityOrderAccess->getColumnValueByKey((void*)&id, "priority_order", value); +// return value.toInt(); +} + +CEventDataCollect::~CEventDataCollect() +{ + LOGDEBUG("CEventDataCollect::~CEventDataCollect()"); +} + +bool CEventDataCollect::initialize() +{ + m_pTimer->start(); + initVariable();; + iot_public::CSysInfoInterfacePtr spSysInfo; + if (iot_public::createSysInfoInstance(spSysInfo)) + { + iot_public::SNodeInfo stNodeInfo; + spSysInfo->getLocalNodeInfo(stNodeInfo); + iot_public::SLocationInfo stLocationInfo; + spSysInfo->getLocationInfoById(stNodeInfo.nLocationId, stLocationInfo); + m_nLocationID = stNodeInfo.nLocationId; + } + loadEventConfig(); + return resumeThread(); +} + +void CEventDataCollect::release() +{ + m_pTimer->stop(); + suspendThread(true); + m_priorityOrderMap.clear(); + m_priorityDescriptionMap.clear(); + m_locationDescriptionMap.clear(); + m_regionInfoDescriptionMap.clear(); + m_alarmTypeDescriptionMap.clear(); + m_deviceTypeDescriptionMap.clear(); + m_subSystemDescriptionMap.clear(); + m_areaInfoMap.clear(); + m_areaLocMap.clear(); + m_locationOrderList.clear(); + + CEventMsgManage::instance()->clearRTMsg(); +} + +void CEventDataCollect::loadEventConfig() +{ + loadPermInfo(); + loadPriorityOrder(); + loadPriorityDescription(); + loadLocationDescription(); + loadRegionInfoDescription(); + loadAlarmTypeDescription(); + loadDeviceTypeDescription(); + loadAlarmStatusDescription(); + loadEventShowStatusDescription(); + loadEventOtherStatusDescription(); + loadUserName(); +} + +int CEventDataCollect::priorityId(const QString &description) +{ + return m_priorityDescriptionMap.key(description, -1); +} + +int CEventDataCollect::locationId(const QString &description) +{ + return m_locationDescriptionMap.key(description, -1); +} + +int CEventDataCollect::regionId(const QString &description) +{ + return m_regionInfoDescriptionMap.key(description, -1); +} + +int CEventDataCollect::alarmTypeId(const QString &description) +{ + return m_alarmTypeDescriptionMap.key(description, -1); +} + +int CEventDataCollect::eventStatusId(const QString &description) +{ + return m_eventShowStatusMap.key(description, -1); +} + +int CEventDataCollect::deviceTypeId(const QString &description) +{ + return m_deviceTypeDescriptionMap.key(description, -1); +} + +QString CEventDataCollect::priorityDescription(const int &id) +{ + return m_priorityDescriptionMap.value(id, QString()); +} + +QString CEventDataCollect::locationDescription(const int &id) +{ + return m_locationDescriptionMap.value(id, QString()); +} + +QString CEventDataCollect::regionDescription(const int &id) +{ + return m_regionInfoDescriptionMap.value(id, QString()); +} + +QString CEventDataCollect::alarmTypeDescription(const int &id) +{ + return m_alarmTypeDescriptionMap.value(id, QString()); +} + +QString CEventDataCollect::deviceTypeDescription(const int &id) +{ + return m_deviceTypeDescriptionMap.value(id, QString()); +} + +QString CEventDataCollect::alarmStatusDescription(const int &id) +{ + return m_alarmStatusMap.value(id, QString()); +} + +QString CEventDataCollect::userNameDescription(const int &id) +{ + return m_userNameMap.value(id, QString()); +} + + +QString CEventDataCollect::eventShowStatusDescription(const int &id) +{ + return m_eventShowStatusMap.value(id, QString()); +} + +QList CEventDataCollect::priorityList() +{ + return m_priorityDescriptionMap.keys(); +} + +QList CEventDataCollect::locationList() +{ + return m_listPermLocationId; +} + +QList CEventDataCollect::regionList() +{ + return m_listPermRegionId; +} + +QList CEventDataCollect::alarmTypeList() +{ + return m_alarmTypeDescriptionMap.keys(); +} + +QList CEventDataCollect::alarmStatusList() +{ + return m_eventShowStatusMap.keys(); +} + +QList CEventDataCollect::alarmOtherList() +{ + return m_eventOtherStatusMap.keys(); +} + +QMap CEventDataCollect::areaInfoMap() +{ + return m_areaInfoMap; +} + +QMap > CEventDataCollect::areaLocMap() +{ + return m_areaLocMap; +} + +QList CEventDataCollect::locationOrderList() +{ + return m_locationOrderList; +} + +void CEventDataCollect::loadPermInfo() +{ + QSqlQuery locationTable; + m_pObjDbInterface->execute("SELECT LOCATION_ID FROM sys_model_location_info ORDER BY LOCATION_ID", locationTable); + if(locationTable.isActive()) + { + QVariant val; + val.clear(); + int locationId = -1; + while(locationTable.next()) + { + val = locationTable.value("LOCATION_ID"); + locationId = val.toInt(); + m_listPermLocationId.append(locationId); + } + } + QSqlQuery RegionTable; + m_pObjDbInterface->execute("SELECT REGION_ID FROM region_info ORDER BY REGION_ID", RegionTable); + if(RegionTable.isActive()) + { + QVariant val; + val.clear(); + int regionId = -1; + while(RegionTable.next()) + { + val = RegionTable.value("REGION_ID"); + regionId = val.toInt(); + m_listPermRegionId.append(regionId); + } + } +// iot_service::CPermMngApiPtr permMngPtr = iot_service::getPermMngInstance("base"); +// if(permMngPtr != NULL) +// { +// permMngPtr->PermDllInit(); +// std::vector vecRegionId; +// std::vector vecLocationId; +// m_listPermLocationId.clear(); +// m_listPermRegionId.clear(); +// if(PERM_NORMAL == permMngPtr->GetSpeFunc(FUNC_SPE_EVENT_VIEW, vecRegionId, vecLocationId)) +// { +// std::vector ::iterator location = vecLocationId.begin(); +// while (location != vecLocationId.end()) +// { +// m_listPermLocationId.append(*location++); +// } +// std::vector ::iterator region = vecRegionId.begin(); +// while (region != vecRegionId.end()) +// { +// m_listPermRegionId.append(*region++); +// } +// } +// } +} + +void CEventDataCollect::loadPriorityOrder() +{ + m_priorityOrderMap.clear(); + if ( !m_pObjDbInterface || !m_pObjDbInterface->isOpen() ) + { + N_MessageBox::critical(qApp->activeWindow(),tr("错误"),tr("打开数据库失败")); + return; + } + QSqlQuery objQuery; + m_pObjDbInterface->execute("select priority_id,priority_order from alarm_level_define",objQuery); + while ( objQuery.next() ) + m_priorityOrderMap[objQuery.value(0).toInt()] = objQuery.value(1).toInt(); + objQuery.clear(); +} + +void CEventDataCollect::loadPriorityDescription() +{ + m_priorityDescriptionMap.clear(); + if ( !m_pObjDbInterface || !m_pObjDbInterface->isOpen() ) + { + N_MessageBox::critical(qApp->activeWindow(),tr("错误"),tr("打开数据库失败")); + return; + } + QSqlQuery objQuery; + m_pObjDbInterface->execute("select priority_id,priority_name from alarm_level_define",objQuery); + while ( objQuery.next() ) + m_priorityDescriptionMap[objQuery.value(0).toInt()] = objQuery.value(1).toString(); + objQuery.clear(); + +// m_priorityDescriptionMap.clear(); +// if(m_rtdbAccess->open("base", "alarm_level_define")) +// { +// iot_dbms::CTableLockGuard locker(*m_rtdbAccess); +// iot_dbms::CRdbQueryResult result; +// std::vector columns; +// columns.push_back("priority_id"); +// columns.push_back("priority_name"); +// if(m_rtdbAccess->select(result, columns)) +// { +// for(int nIndex(0); nIndex < result.getRecordCount(); nIndex++) +// { +// iot_dbms::CVarType key; +// iot_dbms::CVarType value; +// result.getColumnValue(nIndex, 0, key); +// result.getColumnValue(nIndex, 1, value); +// m_priorityDescriptionMap[key.toInt()] = QString::fromStdString(value.toStdString()); +// } +// } +// } +} + +void CEventDataCollect::loadLocationDescription() +{ + m_areaInfoMap.clear(); + if ( !m_pObjDbInterface || !m_pObjDbInterface->isOpen() ) + { + N_MessageBox::critical(qApp->activeWindow(),tr("错误"),tr("打开数据库失败")); + return; + } + QSqlQuery objQuery; + m_pObjDbInterface->execute("select location_id,tag_name,description,location_type,plocation_id from sys_model_location_info order by location_no",objQuery); + while ( objQuery.next() ) + { + SAreaInfo info; + info.nId = objQuery.value(0).toInt(); + info.stTag = objQuery.value(1).toString(); + info.stDes = objQuery.value(2).toString(); + if ( objQuery.value(3).toInt() != (int)E_LOCATION_NODE ) + info.eType = E_LOCATION_AREA; + else + info.eType = E_LOCATION_NODE; + info.nPareaId = objQuery.value(4).toInt(); + m_areaInfoMap[info.nId] = info; + if(m_listPermLocationId.contains(info.nId)) + { + m_locationOrderList.push_back(info.nId); + m_locationDescriptionMap[info.nId] = info.stDes; + } + } + objQuery.clear(); + +// m_areaInfoMap.clear(); +// m_areaLocMap.clear(); +// if(m_rtdbAccess->open("base", "sys_model_location_info")) +// { +// m_locationDescriptionMap.clear(); +// m_locationOrderList.clear(); +// iot_dbms::CTableLockGuard locker(*m_rtdbAccess); +// iot_dbms::CRdbQueryResult result; +// std::vector columns; +// columns.push_back("location_id"); +// columns.push_back("tag_name"); +// columns.push_back("description"); +// columns.push_back("location_type"); +// columns.push_back("plocation_id"); +// std::string sOrderColumn = "location_no"; + +// if(m_rtdbAccess->select(result, columns, sOrderColumn)) +// { +// for(int nIndex(0); nIndex < result.getRecordCount(); nIndex++) +// { +// iot_dbms::CVarType area_id; +// iot_dbms::CVarType tag_name; +// iot_dbms::CVarType description; +// iot_dbms::CVarType area_type; +// iot_dbms::CVarType parea_id; +// result.getColumnValue(nIndex, 0, area_id); +// result.getColumnValue(nIndex, 1, tag_name); +// result.getColumnValue(nIndex, 2, description); +// result.getColumnValue(nIndex, 3, area_type); +// result.getColumnValue(nIndex, 4, parea_id); +// SAreaInfo info; +// info.nId =area_id.toInt(); +// info.stTag =QString::fromStdString(tag_name.toStdString()); +// info.stDes =QString::fromStdString(description.toStdString()); +// if(area_type.toInt() != (int)E_LOCATION_NODE) +// { +// info.eType = E_LOCATION_AREA; +// }else +// { +// info.eType = E_LOCATION_NODE; +// } +// info.nPareaId =parea_id.toInt(); +// m_areaInfoMap[info.nId] = info; +// if(m_listPermLocationId.contains(info.nId)) +// { +// m_locationOrderList.push_back(info.nId); +// m_locationDescriptionMap[info.nId] = info.stDes; +// } +// } +// } +// } + QMap::iterator it= m_areaInfoMap.begin(); + while (it != m_areaInfoMap.end()) { + if(m_listPermLocationId.contains(it.key())) + { + if(it.value().eType == (int)E_LOCATION_NODE) + { + QMap >::iterator pos = m_areaLocMap.find(it.value().nPareaId); + if(pos == m_areaLocMap.end()) + { + QVector locVec; + locVec.append(it.value().nId); + m_areaLocMap.insert(it.value().nPareaId,locVec); + }else + { + QVector &locVec = pos.value(); + locVec.append(it.value().nId); + } + }else + { + QMap >::iterator pos = m_areaLocMap.find(it.key()); + if(pos == m_areaLocMap.end()) + { + QVector locVec; + locVec.append(it.value().nId); + m_areaLocMap.insert(it.key(),locVec); + }else + { + QVector &locVec = pos.value(); + locVec.append(it.value().nId); + } + } + + } + it++; + } +} + +void CEventDataCollect::loadRegionInfoDescription() +{ + m_regionInfoDescriptionMap.clear(); + if ( !m_pObjDbInterface || !m_pObjDbInterface->isOpen() ) + { + N_MessageBox::critical(qApp->activeWindow(),tr("错误"),tr("打开数据库失败")); + return; + } + QSqlQuery objQuery; + m_pObjDbInterface->execute("select region_id,description from region_info",objQuery); + while ( objQuery.next() ) + { + if(m_listPermRegionId.contains(objQuery.value(0).toInt())) + m_regionInfoDescriptionMap[objQuery.value(0).toInt()] = objQuery.value(1).toString(); + } + objQuery.clear(); + +// m_regionInfoDescriptionMap.clear(); +// if(m_rtdbAccess->open("base", "region_info")) +// { +// iot_dbms::CTableLockGuard locker(*m_rtdbAccess); +// iot_dbms::CRdbQueryResult result; +// std::vector columns; +// columns.push_back("region_id"); +// columns.push_back("description"); +// if(m_rtdbAccess->select(result, columns)) +// { +// for(int nIndex(0); nIndex < result.getRecordCount(); nIndex++) +// { +// iot_dbms::CVarType key; +// iot_dbms::CVarType value; +// result.getColumnValue(nIndex, 0, key); +// result.getColumnValue(nIndex, 1, value); +// if(m_listPermRegionId.contains(key.toInt())) +// { +// m_regionInfoDescriptionMap[key.toInt()] = QString::fromStdString(value.toStdString()); +// } +// } +// } +// } +} + +void CEventDataCollect::loadAlarmTypeDescription() +{ + m_alarmTypeDescriptionMap.clear(); + if ( !m_pObjDbInterface || !m_pObjDbInterface->isOpen() ) + { + N_MessageBox::critical(qApp->activeWindow(),tr("错误"),tr("打开数据库失败")); + return; + } + QSqlQuery objQuery; + m_pObjDbInterface->execute("select type_id,type_name from alarm_type_define",objQuery); + while ( objQuery.next() ) + m_alarmTypeDescriptionMap[objQuery.value(0).toInt()] = objQuery.value(1).toString(); + objQuery.clear(); + +// m_alarmTypeDescriptionMap.clear(); +// if(m_rtdbAccess->open("base", "alarm_type_define")) +// { +// iot_dbms::CTableLockGuard locker(*m_rtdbAccess); +// iot_dbms::CRdbQueryResult result; +// std::vector columns; +// columns.push_back("type_id"); +// columns.push_back("type_name"); +// if(m_rtdbAccess->select(result, columns)) +// { +// for(int nIndex(0); nIndex < result.getRecordCount(); nIndex++) +// { +// iot_dbms::CVarType key; +// iot_dbms::CVarType value; +// result.getColumnValue(nIndex, 0, key); +// result.getColumnValue(nIndex, 1, value); +// m_alarmTypeDescriptionMap[key.toInt()] = QString::fromStdString(value.toStdString()); +// } +// } +// } +} + +void CEventDataCollect::loadDeviceTypeDescription() +{ + m_deviceTypeDescriptionMap.clear(); + if ( !m_pObjDbInterface || !m_pObjDbInterface->isOpen() ) + { + N_MessageBox::critical(qApp->activeWindow(),tr("错误"),tr("打开数据库失败")); + return; + } + QSqlQuery objQuery; + m_pObjDbInterface->execute("select dev_type_id,description from dev_type_def",objQuery); + while ( objQuery.next() ) + m_deviceTypeDescriptionMap[objQuery.value(0).toInt()] = objQuery.value(1).toString(); + objQuery.clear(); + +// m_deviceTypeDescriptionMap.clear(); +// if(m_rtdbAccess->open("base", "dev_type_def")) +// { +// iot_dbms::CTableLockGuard locker(*m_rtdbAccess); +// iot_dbms::CRdbQueryResult result; +// std::vector columns; +// columns.push_back("dev_type_id"); +// columns.push_back("description"); +// if(m_rtdbAccess->select(result, columns)) +// { +// for(int nIndex(0); nIndex < result.getRecordCount(); nIndex++) +// { +// iot_dbms::CVarType key; +// iot_dbms::CVarType value; +// result.getColumnValue(nIndex, 0, key); +// result.getColumnValue(nIndex, 1, value); +// m_deviceTypeDescriptionMap[key.toInt()] = QString::fromStdString(value.toStdString()); +// } +// } +// } +} + +void CEventDataCollect::loadAlarmStatusDescription() +{ + m_alarmStatusMap.clear(); + if ( !m_pObjDbInterface || !m_pObjDbInterface->isOpen() ) + { + N_MessageBox::critical(qApp->activeWindow(),tr("错误"),tr("打开数据库失败")); + return; + } + QSqlQuery objQuery; + m_pObjDbInterface->execute("select status_value,display_name from alarm_status_define",objQuery); + while ( objQuery.next() ) + m_alarmStatusMap[objQuery.value(0).toInt()] = objQuery.value(1).toString(); + objQuery.clear(); + +// m_alarmStatusMap.clear(); +// if(m_rtdbAccess->open("base", "alarm_status_define")) +// { +// iot_dbms::CTableLockGuard locker(*m_rtdbAccess); +// iot_dbms::CRdbQueryResult result; +// std::vector columns; +// columns.push_back("status_value"); +// columns.push_back("display_name"); + +// if(m_rtdbAccess->select(result, columns)) +// { +// for(int nIndex(0); nIndex < result.getRecordCount(); nIndex++) +// { +// iot_dbms::CVarType key; +// iot_dbms::CVarType value; +// result.getColumnValue(nIndex, 0, key); +// result.getColumnValue(nIndex, 1, value); +// m_alarmStatusMap[key.toInt()] = QString::fromStdString(value.toStdString()); +// } +// } +// } +} + +void CEventDataCollect::loadUserName() +{ + m_userNameMap.clear(); + if ( !m_pObjDbInterface || !m_pObjDbInterface->isOpen() ) + { + N_MessageBox::critical(qApp->activeWindow(),tr("错误"),tr("打开数据库失败")); + return; + } + QSqlQuery objQuery; + m_pObjDbInterface->execute("select perm_id,perm_name from rm_user_def",objQuery); + while ( objQuery.next() ) + m_userNameMap[objQuery.value(0).toInt()] = objQuery.value(1).toString(); + objQuery.clear(); + +// m_userNameMap.clear(); +// if(m_rtdbAccess->open("base", "rm_user_def")) +// { +// iot_dbms::CTableLockGuard locker(*m_rtdbAccess); +// iot_dbms::CRdbQueryResult result; +// std::vector columns; +// columns.push_back("perm_id"); +// columns.push_back("perm_name"); +// if(m_rtdbAccess->select(result, columns)) +// { +// for(int nIndex(0); nIndex < result.getRecordCount(); nIndex++) +// { +// iot_dbms::CVarType key; +// iot_dbms::CVarType value; +// result.getColumnValue(nIndex, 0, key); +// result.getColumnValue(nIndex, 1, value); +// m_userNameMap[key.toInt()] = QString::fromStdString(value.toStdString()); +// } +// } +// } +} + +void CEventDataCollect::loadEventShowStatusDescription() +{ + const std::string strConfFullPath = iot_public::CFileUtil::getPathOfCfgFile("alarmStatus.xml"); + boost::property_tree::ptree pt; + namespace xml = boost::property_tree::xml_parser; + try + { + xml::read_xml(strConfFullPath, pt, xml::no_comments); + BOOST_AUTO(module, pt.get_child("root")); + for (BOOST_AUTO(pModuleIter, module.begin()); pModuleIter != module.end(); ++pModuleIter) + { + boost::property_tree::ptree ptParam = pModuleIter->second; + for (BOOST_AUTO(pParamIter, ptParam.begin()); pParamIter != ptParam.end(); ++pParamIter) + { + if (pParamIter->first == "param") + { + string strKey = pParamIter->second.get(".key"); + //string strValue = pParamIter->second.get(".value"); + if(StringToInt(strKey) != OTHERSTATUS) + { + m_eventShowStatusMap[StringToInt(strKey)] = m_alarmStatusMap[StringToInt(strKey)]; + }else + { + m_eventShowStatusMap[StringToInt(strKey)] = tr("其他"); + } + } + } + } + } + catch (std::exception &ex) + { + LOGERROR("解析配置文件[%s]失败.Msg=[%s]", strConfFullPath.c_str(), ex.what()); + } +} + +void CEventDataCollect::loadEventOtherStatusDescription() +{ + m_eventOtherStatusMap.clear(); + const std::string strConfFullPath = iot_public::CFileUtil::getPathOfCfgFile("alarmOther.xml"); + boost::property_tree::ptree pt; + namespace xml = boost::property_tree::xml_parser; + try + { + xml::read_xml(strConfFullPath, pt, xml::no_comments); + BOOST_AUTO(module, pt.get_child("root")); + for (BOOST_AUTO(pModuleIter, module.begin()); pModuleIter != module.end(); ++pModuleIter) + { + boost::property_tree::ptree ptParam = pModuleIter->second; + for (BOOST_AUTO(pParamIter, ptParam.begin()); pParamIter != ptParam.end(); ++pParamIter) + { + if (pParamIter->first == "param") + { + string strKey = pParamIter->second.get(".key"); + //string strValue = pParamIter->second.get(".value"); + m_eventOtherStatusMap[StringToInt(strKey)] = m_alarmStatusMap[StringToInt(strKey)]; + } + } + } + } + catch (std::exception &ex) + { + LOGERROR("解析配置文件[%s]失败.Msg=[%s]", strConfFullPath.c_str(), ex.what()); + } +} + +QMap CEventDataCollect::priorityDescriptionMap() +{ + return m_priorityDescriptionMap; +} + +QMap CEventDataCollect::locationDescriptionMap() +{ + return m_locationDescriptionMap; +} + +QMap CEventDataCollect::regionInfoDescriptionMap() +{ + return m_regionInfoDescriptionMap; +} + +QMap CEventDataCollect::alarmTypeDescriptionMap() +{ + return m_alarmTypeDescriptionMap; +} + +QMap CEventDataCollect::deviceTypeDescriptionMap() +{ + return m_deviceTypeDescriptionMap; +} + +QMap CEventDataCollect::alarmStatusMap() +{ + return m_alarmStatusMap; +} + +QMap CEventDataCollect::userNameMap() +{ + return m_userNameMap; +} + +QMap CEventDataCollect::eventShowStatusDescriptionMap() +{ + return m_eventShowStatusMap; +} + +QMap CEventDataCollect::eventOtherStatusDescriptionMap() +{ + return m_eventOtherStatusMap; +} + +void CEventDataCollect::slotUpdateEvent() +{ + //loadEventConfig(); + + QMutexLocker locker(msgMutex); + + if(!m_listEventCache.isEmpty()) + { + emit sigMsgArrived(m_listEventCache); + m_listEventCache.clear(); + } +} + +void CEventDataCollect::handleAllEvtMsg(int nDomainID, iot_idl::SEvtCltAddEvt &objAllEvt) +{ + QMutexLocker locker(msgMutex); + LOGINFO("-------------------------handleAllEvtMsg-------------------------"); + CEventMsgManage::instance()->removeEventMsgByDomainID(nDomainID); + removeCache(nDomainID); + for(int nAddMsgIndex(0); nAddMsgIndex < objAllEvt.evt_info_size(); nAddMsgIndex++) + { + iot_idl::SEvtInfoToEvtClt msg = objAllEvt.evt_info(nAddMsgIndex); + EventMsgPtr event(new CEventMsgInfo()); + event->initialize(msg); + event->priorityOrder = queryPriorityOrder(event->priority); + if(!m_listPermLocationId.contains(event->location_id)) + { + continue; + } + if(!m_listPermRegionId.contains(event->region_id) && event->region_id != -1) + { + continue; + } + CEventMsgManage::instance()->addEventMsg(event); + } + emit sigMsgRefresh(); + emit sigEventStateChanged(); +} + +void CEventDataCollect::handleAddEvtMsg(iot_idl::SEvtCltAddEvt &objAddEvt) +{ + QMutexLocker locker(msgMutex); + LOGINFO("-------------------------handleAddEvtMsg-------------------------"); + for(int nAddMsgIndex(0); nAddMsgIndex < objAddEvt.evt_info_size(); nAddMsgIndex++) + { + iot_idl::SEvtInfoToEvtClt msg = objAddEvt.evt_info(nAddMsgIndex); + EventMsgPtr event(new CEventMsgInfo()); + event->initialize(msg); + event->priorityOrder = queryPriorityOrder(event->priority); + if(!m_listPermRegionId.contains(event->region_id) && event->region_id != -1) + { + continue; + } + CEventMsgManage::instance()->addEventMsg(event); + m_listEventCache.append(event); + } + emit sigEventStateChanged(); +} + +void CEventDataCollect::handleLinkWave2EvtMsg(iot_idl::SAlmCltLinkWave2Alm &objWave2Evt) +{ + QMutexLocker locker(msgMutex); + QList uuidList; + LOGINFO("-------------------------handleAddEvtMsg-------------------------"); + QString waveFile = QString::fromStdString(objWave2Evt.wave_file()); + for(int nAddMsgIndex(0); nAddMsgIndex < objWave2Evt.uuid_base64_size(); nAddMsgIndex++) + { + QString uuid = QString::fromStdString(objWave2Evt.uuid_base64(nAddMsgIndex)); + uuidList.append(uuid); + } + CEventMsgManage::instance()->linkWave2EvtMsg(uuidList,waveFile); +} + +void CEventDataCollect::handleClearRTEvent() +{ + QMutexLocker locker(msgMutex); + CEventMsgManage::instance()->clearRTMsg(); + emit sigMsgRefresh(); + emit sigEventStateChanged(); +} + +void CEventDataCollect::destory() +{ + if(m_pTimer != NULL) + { + m_pTimer->stop(); + delete m_pTimer; + } + m_pTimer = NULL; + + suspendThread(); + + m_priorityOrderMap.clear(); + m_priorityDescriptionMap.clear(); + m_locationDescriptionMap.clear(); + m_regionInfoDescriptionMap.clear(); + m_alarmTypeDescriptionMap.clear(); + m_deviceTypeDescriptionMap.clear(); + m_subSystemDescriptionMap.clear(); + m_locationOrderList.clear(); + + delete msgMutex; +// delete m_rtdbAccess; + m_pInstance = NULL; +} + +void CEventDataCollect::removeCache(int nDomain) +{ + QList::iterator it = m_listEventCache.begin(); + while (it != m_listEventCache.end()) + { + if(nDomain == (*it)->domain_id) + { + it = m_listEventCache.erase(it); + continue; + } + it++; + } +} +void CEventDataCollect::initVariable() +{ + m_pObjDbInterface = m_pSystemResources->getDbInterface(); +} diff --git a/product/src/tools/debug_tool_v2/CEventDataCollect.h b/product/src/tools/debug_tool_v2/CEventDataCollect.h new file mode 100644 index 00000000..cf31ff55 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventDataCollect.h @@ -0,0 +1,150 @@ +#ifndef CEventDataCollect_H +#define CEventDataCollect_H + +#include +#include +#include +#include "AlarmMessage.pb.h" +#include "CEventMsgInfo.h" +#include "net_msg_bus_api/MsgBusApi.h" +//#include "dbms/rdb_api/CRdbAccess.h" +#include "CSystemResources.h" +#include +#include + +#define FUNC_SPE_EVENT_VIEW ("FUNC_SPE_EVENT_VIEW") + +const int OTHERSTATUS = 9999; +class CEventDataCollect : public QObject, public iot_service::CAlmApiForEvtClt +{ + Q_OBJECT +public: + static CEventDataCollect * instance(); + static void setSystemResources(CSystemResources *pSystemResources); + virtual ~CEventDataCollect(); + + bool initialize(); + + void release(); + + void loadEventConfig(); + int priorityId(const QString &description); + int locationId(const QString &description); + int regionId(const QString &description); + int alarmTypeId(const QString &description); + int eventStatusId(const QString &description); + int deviceTypeId(const QString &description); + + QString priorityDescription(const int & id); + QString locationDescription(const int & id); + QString regionDescription(const int & id); + QString alarmTypeDescription(const int & id); + QString deviceTypeDescription(const int & id); + QString alarmStatusDescription(const int & id); + QString userNameDescription(const int & id); + + + QString eventShowStatusDescription(const int & id); + + QList priorityList(); + QList locationList(); + QList regionList(); + QList alarmTypeList(); + QList alarmStatusList(); + QList alarmOtherList(); + QMap areaInfoMap(); + QMap > areaLocMap(); + QList locationOrderList(); + + QMap priorityDescriptionMap(); + QMap locationDescriptionMap(); + QMap regionInfoDescriptionMap(); + QMap alarmTypeDescriptionMap(); + QMap deviceTypeDescriptionMap(); + QMap alarmStatusMap(); + QMap userNameMap(); + + QMap eventShowStatusDescriptionMap(); + QMap eventOtherStatusDescriptionMap(); + + virtual void handleAllEvtMsg(int nDomainID, iot_idl::SEvtCltAddEvt &objAllEvt); + + virtual void handleAddEvtMsg(iot_idl::SEvtCltAddEvt &objAddEvt); + + virtual void handleLinkWave2EvtMsg( iot_idl::SAlmCltLinkWave2Alm &objWave2Evt); + + void handleClearRTEvent(); + void destory(); + +signals: + /** + * @brief sigMsgRefresh 在handleAllAlmMsg时触发,通知model重新拉取报警消息 + */ + void sigMsgRefresh(); + + /** + * @brief sigMsgArrived 在handleAddAlmMsg时触发,通知model新报警消息到达 + */ + void sigMsgArrived(QList listEvents); + + /** + * @brief sigEventStateChanged 事件数量或状态改变时触发。 + */ + void sigEventStateChanged(); +public slots: + //void queryHistoryEvent(const QStringList &tables, QList typeFilter, const QString &condition); + void slotUpdateEvent(); + +private: + CEventDataCollect(); + int queryPriorityOrder(int &id); + void removeCache(int nDomain); + + void initVariable(); + + void loadPermInfo(); + void loadPriorityOrder(); + void loadPriorityDescription(); + void loadLocationDescription(); + void loadRegionInfoDescription(); + void loadAlarmTypeDescription(); + void loadDeviceTypeDescription(); + void loadAlarmStatusDescription(); + void loadUserName(); + + void loadEventShowStatusDescription(); + void loadEventOtherStatusDescription(); + +private: + QMutex * msgMutex; + QTimer * m_pTimer; + int m_nLocationID; + QList m_listEventCache; + //iot_dbms::CRdbAccess * m_rtdbAccess; + //iot_dbms::CRdbAccess * m_rtdbPriorityOrderAccess; + iot_dbms::CDbApi *m_pObjDbInterface; + + QList m_listPermLocationId; + QList m_listPermRegionId; + QMap m_priorityOrderMap; + QMap m_priorityDescriptionMap; + QMap m_locationDescriptionMap; + QMap m_regionInfoDescriptionMap; + QMap m_alarmTypeDescriptionMap; + QMap m_deviceTypeDescriptionMap; + QMap m_subSystemDescriptionMap; + QMap m_alarmStatusMap; + QMap m_userNameMap; + static CEventDataCollect * m_pInstance; + + QMap m_eventShowStatusMap; // + QMap m_eventOtherStatusMap; //其他报警状态 + + + QMap m_areaInfoMap; //区域信息 + QMap > m_areaLocMap; //区域映射 + + QList m_locationOrderList; //< location_id: 按location_no排序 +}; + +#endif // CEventDataCollect_H diff --git a/product/src/tools/debug_tool_v2/CEventDelegate.cpp b/product/src/tools/debug_tool_v2/CEventDelegate.cpp new file mode 100644 index 00000000..0c35620a --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventDelegate.cpp @@ -0,0 +1,210 @@ +#include "CEventDelegate.h" +#include +#include +#include +#include "CEventMsgInfo.h" +#include "CEventItemModel.h" +#include "pub_utility_api/FileUtil.h" +#include "pub_utility_api/FileStyle.h" +#include "pub_logger_api/logger.h" +#include +#include +#include +CEventDelegate::CEventDelegate(QObject *parent) + : QStyledItemDelegate(parent), + m_pModel(Q_NULLPTR), + m_selectIsEmpty(false), + m_enableWave(true) +{ + loadColorConfig(); +} + +void CEventDelegate::setEnableWave(bool isNeed) +{ + m_enableWave = isNeed; +} + +void CEventDelegate::setEventModel(CEventItemModel *model) +{ + m_pModel = model; +} + + +void CEventDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + if(!index.isValid()) + { + return; + } + QColor fillColor(255,255,255); + QColor penColor(0,0,0); + bool select = option.state & QStyle::State_Selected; + + //< Common + if(m_pModel != NULL) + { + EventMsgPtr info = m_pModel->getAlarmInfo(index); + + if(info != Q_NULLPTR) + { + painter->save(); + if(AS_ALARM_RTN == info->alm_style) + { + if(select) + { + fillColor = m_selectBackgroundColor; + if(m_selectIsEmpty) + { + if ( m_activeTextMap.contains(info->priorityOrder) ) + penColor = m_activeTextMap[info->priorityOrder]; + } + else + { + penColor = m_selectTextColor; + } + } + else + { + if ( m_resumeTextMap.contains(info->priorityOrder) ) + penColor = m_resumeTextMap[info->priorityOrder]; + if ( m_backgroundMap.contains(info->priorityOrder) ) + fillColor = m_backgroundMap[info->priorityOrder]; + } + }else + { + if(select) + { + fillColor = m_selectBackgroundColor; + if(m_selectIsEmpty) + { + if ( m_activeTextMap.contains(info->priorityOrder) ) + penColor = m_activeTextMap[info->priorityOrder]; + } + else + { + penColor = m_selectTextColor; + } + } + else + { + if ( m_activeTextMap.contains(info->priorityOrder) ) + penColor = m_activeTextMap[info->priorityOrder]; + if ( m_backgroundMap.contains(info->priorityOrder) ) + fillColor = m_backgroundMap[info->priorityOrder]; + } + } + + painter->setPen(penColor); + painter->fillRect(option.rect, fillColor); + if(m_enableWave && REAL_BUTTON_COLUMN == index.column() && !info->wave_file.isEmpty()) + { + painter->save(); + QStyleOptionButton button; + button.state |= QStyle::State_Enabled; + button.rect = option.rect; + + button.rect.adjust(option.rect.width() - 40-40-40, option.rect.height()/2-10, -12-40-40, -(option.rect.height()/2-10)); + std::string style = iot_public::CFileStyle::getCurStyle(); + QString file = iot_public::CFileUtil::getPathOfResFile("gui/icon/alarm/wave_"+style+".png").c_str(); + button.iconSize = QSize(button.rect.width()+2,button.rect.height()+2); + button.icon = QIcon(file); + button.features = QStyleOptionButton::Flat; + QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter); + painter->restore(); + } + painter->drawText(option.rect, m_pModel->data(index, Qt::TextAlignmentRole).toInt(), m_pModel->data(index).toString()); + painter->restore(); + } + } +} + +bool CEventDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) +{ + if(!index.isValid()) + { + return false; + } + if(m_pModel != NULL) + { + if(index.column() != REAL_BUTTON_COLUMN) + { + return false; + } + EventMsgPtr info = m_pModel->getAlarmInfo(index); + QMouseEvent *mouseEvent = static_cast(event); + if(info && m_enableWave && !info->wave_file.isEmpty()) + { + if(mouseEvent != NULL && mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QMouseEvent::MouseButtonPress) + { + QStyleOptionButton button; + button.rect = option.rect; + button.rect.adjust(option.rect.width() - 122, option.rect.height()/2-10, -90, -(option.rect.height()/2-10)); + QRect rect = button.rect; + if(rect.contains(mouseEvent->pos())) + { + QString wave = info->wave_file; + wave = QString("%1%2%3").arg("\"").arg(wave).arg("\""); + LOGINFO("录波文件为:%s",wave.toStdString().c_str()); + + const std::string strProc = std::move(iot_public::CFileUtil::getPathOfBinFile( + std::string("WaveAnalyze") + iot_public::CFileUtil::getProcSuffix())); + if(strProc.empty()) + LOGERROR("未找到可执行文件WaveAnalyze"); + else + QProcess::startDetached(QString("%1 %2").arg(strProc.c_str()).arg(wave)); + } + } + } + } + return QStyledItemDelegate::editorEvent(event, model, option, index); +} +void CEventDelegate::loadColorConfig() +{ + QString filePath = QString::fromStdString(iot_public::CFileUtil::getCurModuleDir()) + QString("../../data/model/alarm_color_define.xml"); + QDomDocument document; + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) + { + LOGINFO("loadColorConfig Failed!"); + return; + } + if (!document.setContent(&file)) + { + file.close(); + return; + } + file.close(); + + QDomElement element = document.documentElement(); + QDomNode node = element.firstChild(); + while(!node.isNull()) + { + QDomElement attr = node.toElement(); + if(!attr.isNull()) + { + if(QString("Level") == attr.tagName()) + { + int priority = attr.attribute("priority").toInt(); + m_backgroundMap[priority] = QColor(attr.attribute("background_color")); + m_alternatingMap[priority] = QColor(attr.attribute("alternating_color")); + m_confirmMap[priority] = QColor(attr.attribute("confirm_color")); + + m_activeTextMap[priority] = QColor(attr.attribute("active_text_color")); + m_confirmTextMap[priority] = QColor(attr.attribute("confirm_text_color")); + m_resumeTextMap[priority] = QColor(attr.attribute("resume_text_color")); + } + else if(QString("Select") == attr.tagName()) + { + m_selectBackgroundColor = QColor(attr.attribute("background_color")); + if(attr.attribute("text_color").isEmpty()) + { + m_selectIsEmpty = true; + }else + { + m_selectTextColor = QColor(attr.attribute("text_color")); + } + } + } + node = node.nextSibling(); + } +} diff --git a/product/src/tools/debug_tool_v2/CEventDelegate.h b/product/src/tools/debug_tool_v2/CEventDelegate.h new file mode 100644 index 00000000..4bdf0bdd --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventDelegate.h @@ -0,0 +1,46 @@ +#ifndef CEVENTDELEGATE_H +#define CEVENTDELEGATE_H + +#include +class CEventItemModel; + +class CEventDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + CEventDelegate(QObject *parent = 0); + + void setEnableWave(bool isNeed); + void setEventModel(CEventItemModel *model); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + bool editorEvent(QEvent *event, QAbstractItemModel *model, + const QStyleOptionViewItem &option, const QModelIndex &index) Q_DECL_OVERRIDE; +private: + void loadColorConfig(); +private: + CEventItemModel *m_pModel; + //< background color + QMap m_backgroundMap; + QMap m_alternatingMap; + QMap m_confirmMap; + + //< text color + QMap m_activeTextMap; + QMap m_confirmTextMap; + QMap m_resumeTextMap; + + //< select color + QColor m_selectBackgroundColor; + QColor m_selectTextColor; + + //< no item + QColor m_emptyBackgroundColor; + QColor m_emptyTipColor; + QString m_emptyTip; + + bool m_selectIsEmpty; + + bool m_enableWave; +}; + +#endif // CEVENTDELEGATE_H diff --git a/product/src/tools/debug_tool_v2/CEventFilterDialog.ui b/product/src/tools/debug_tool_v2/CEventFilterDialog.ui new file mode 100644 index 00000000..035ffa99 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventFilterDialog.ui @@ -0,0 +1,405 @@ + + + CEventFilterDialog + + + + 0 + 0 + 570 + 421 + + + + + 530 + 0 + + + + + 16777215 + 16777215 + + + + 过滤 + + + + + + 时间 + + + true + + + false + + + + + + + + 开始时间 + + + + + + + + 2018 + 1 + 1 + + + + + 0 + 0 + 0 + 2000 + 1 + 1 + + + + + 2050 + 12 + 31 + + + + QDateTimeEdit::YearSection + + + yyyy/MM/dd hh:mm + + + + + + + + + + + 结束时间 + + + + + + + false + + + + 2018 + 1 + 1 + + + + + 0 + 0 + 0 + 2000 + 1 + 1 + + + + + 2050 + 12 + 31 + + + + yyyy/MM/dd hh:mm + + + false + + + + + + + + + + + + + + Qt::Horizontal + + + + 281 + 20 + + + + + + + + 确定 + + + + + + + 取消 + + + + + + + + + + + 优先级 + + + true + + + + + + 全选 + + + true + + + true + + + + + + + + + + + + + 位置 + + + true + + + + + + 全选 + + + true + + + + + + + QAbstractItemView::NoSelection + + + false + + + + 1 + + + + + + + + + + + 责任区 + + + true + + + + + + 全选 + + + true + + + + + + + + + + + + + 事件状态 + + + true + + + + + + 全选 + + + true + + + + + + + + + + + + + + + + + 设备类型 + + + true + + + false + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + + + 事件内容关键字 + + + true + + + false + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + 0 + + + + 复归 + + + true + + + false + + + + + + + 0 + 0 + + + + 已复归 + + + + + + + + 0 + 0 + + + + 未复归 + + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CEventFormShow.cpp b/product/src/tools/debug_tool_v2/CEventFormShow.cpp new file mode 100644 index 00000000..327e0f7b --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventFormShow.cpp @@ -0,0 +1,71 @@ +#include "CEventFormShow.h" +#include "ui_CEventFormShow.h" +#include +#include "CEventDataCollect.h" +CEventFormShow::CEventFormShow(QWidget *parent) : + QWidget(parent),m_pRealDelegate(NULL),m_pRealTimeModel(NULL), + ui(new Ui::CEventFormShow) +{ + ui->setupUi(this); + +// m_pmodel=new CEventForm(this,0); +// QGridLayout *gridLayout = new QGridLayout(this); +// gridLayout->setSpacing(6); +// gridLayout->setContentsMargins(0, 0, 0, 0); +// gridLayout->addWidget(m_pmodel, 0, 0, 1, 1); +} + +CEventFormShow::~CEventFormShow() +{ + if(m_pRealTimeModel) + delete m_pRealTimeModel; + delete ui; +} +void CEventFormShow::initRealModel() +{ + CEventDataCollect::setSystemResources(m_pSystemResources); + QSettings columFlags("IOT_HMI", "eventReal config"); + if(!columFlags.contains(QString("eventReal/colum_0"))) + { + columFlags.setValue(QString("eventReal/colum_0"), false); //< 时间 + columFlags.setValue(QString("eventReal/colum_1"), false); //< 优先级 + columFlags.setValue(QString("eventReal/colum_2"), false); //< 位置 + columFlags.setValue(QString("eventReal/colum_3"), true); //< 责任区 + columFlags.setValue(QString("eventReal/colum_4"), true); //< 事件类型 + columFlags.setValue(QString("eventReal/colum_5"), false); //< 事件状态 + columFlags.setValue(QString("eventReal/colum_6"), false); //< 复归状态 + } + if(m_pRealDelegate == NULL) + { + m_pRealDelegate = new CEventDelegate(this); + ui->eventView->setItemDelegate(m_pRealDelegate); + } + ui->eventView->setSortingEnabled(true); + if(NULL == m_pRealTimeModel) + { + m_pRealTimeModel = new CEventItemModel(this); + connect(ui->eventView->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), m_pRealTimeModel, SLOT(sortColumn(int,Qt::SortOrder))); + ui->eventView->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder); + } + ui->eventView->setModel(m_pRealTimeModel); + m_pRealDelegate->setEventModel(m_pRealTimeModel); + QSettings columFlags1("IOT_HMI", "eventReal config"); + for(int nColumnIndex(0); nColumnIndex < m_pRealTimeModel->columnCount() - 1; nColumnIndex++) + { + bool visible = columFlags1.value(QString("eventReal/colum_%1").arg(nColumnIndex)).toBool(); + ui->eventView->setColumnHidden(nColumnIndex, visible); + } + ui->eventView->setColumnHidden(m_pRealTimeModel->columnCount() - 1, false); + ui->eventView->setColumnWidth(0, 250); + ui->eventView->setColumnWidth(1, 150); + ui->eventView->setColumnWidth(2, 150); + ui->eventView->setColumnWidth(3, 150); + ui->eventView->setColumnWidth(4, 150); + ui->eventView->setColumnWidth(5, 150); +} + +void CEventFormShow::setSystemResources(CSystemResources *pSystemResources) +{ + m_pSystemResources = pSystemResources; + +} diff --git a/product/src/tools/debug_tool_v2/CEventFormShow.h b/product/src/tools/debug_tool_v2/CEventFormShow.h new file mode 100644 index 00000000..1c8df5e1 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventFormShow.h @@ -0,0 +1,30 @@ +#ifndef CEVENTFORMSHOW_H +#define CEVENTFORMSHOW_H + +#include +#include "CSystemResources.h" +#include "CEventDelegate.h" +#include"CEventItemModel.h" +namespace Ui { +class CEventFormShow; +} + +class CEventFormShow : public QWidget +{ + Q_OBJECT + +public: + explicit CEventFormShow(QWidget *parent = 0); + ~CEventFormShow(); + void setSystemResources(CSystemResources *pSystemResources); + void initRealModel(); + + +private: + Ui::CEventFormShow *ui; + CEventDelegate *m_pRealDelegate; + CEventItemModel * m_pRealTimeModel; + CSystemResources *m_pSystemResources; +}; + +#endif // CEVENTFORMSHOW_H diff --git a/product/src/tools/debug_tool_v2/CEventFormShow.ui b/product/src/tools/debug_tool_v2/CEventFormShow.ui new file mode 100644 index 00000000..4ce6f401 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventFormShow.ui @@ -0,0 +1,31 @@ + + + CEventFormShow + + + + 0 + 0 + 941 + 571 + + + + Form + + + + + + + + + + CEventView + QTableView +
CEventView.h
+
+
+ + +
diff --git a/product/src/tools/debug_tool_v2/CEventItemModel.cpp b/product/src/tools/debug_tool_v2/CEventItemModel.cpp new file mode 100644 index 00000000..e122d2d4 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventItemModel.cpp @@ -0,0 +1,724 @@ +#include "CEventItemModel.h" +#include "CEventMsgInfo.h" +#include +#include +#include +#include +#include "CEventDataCollect.h" +#include "service/alarm_server_api/AlarmCommonDef.h" +#include "CEventMsgManage.h" +#include "pub_logger_api/logger.h" + +///////////////////////////////////////////////////////////////////////////// + +typedef QPair > PAIRLISTALARMINFO; + +CEventItemModel::CEventItemModel(QObject *parent) + :QAbstractTableModel(parent), + m_sortKey(E_SORT_TIME), + m_order(Qt::AscendingOrder) +{ + header << tr("时间") << tr("优先级") << tr("位置") << tr("责任区") << tr("事件类型") << tr("事件状态") << tr("复归状态") << tr("事件内容"); + initialize(); + connect(CEventDataCollect::instance(), SIGNAL(sigMsgRefresh()), + this, SLOT(slotMsgRefresh()), Qt::QueuedConnection); + connect(CEventDataCollect::instance(), SIGNAL(sigMsgArrived(QList)), + this, SLOT(slotMsgArrived(QList))); +} + +CEventItemModel::~CEventItemModel() +{ + m_listShowEventInfo.clear(); + CEventDataCollect::instance()->destory(); +} + +void CEventItemModel::initialize() +{ + beginResetModel(); + m_listShowEventInfo.clear(); + endResetModel(); + + initFilterAndReloadData(); +} + +void CEventItemModel::initFilter() +{ + m_isLevelFilterEnable = false; + m_levelFilter.clear(); + m_isLocationFilterEnable = false; + m_locationFilter.clear(); + m_isRegionFilterEnable = false; + m_regionFilter.clear(); + m_isStatusFilterEnable = false; + m_statusFilter.clear(); + m_statusFilter2.clear(); + m_isDeviceTypeFileter = false; + m_subSystem = QString(); + m_deviceType = QString(); + m_isKeywordEnable = false; + m_keyword = QString(); + m_timeFilterEnable = false; + m_isReturnFilterEnable = false; + m_isReturn = false; +} + +void CEventItemModel::initFilterAndReloadData() +{ + initFilter(); + slotMsgRefresh(); +} + +void CEventItemModel::setSystemResources(CSystemResources *pSystemResources) +{ + m_pSystemResources=pSystemResources; +} + +EventMsgPtr CEventItemModel::getAlarmInfo(const QModelIndex &index) const +{ + if(!index.isValid() || index.row() >= m_listShowEventInfo.count()) + { + return NULL; + } + + return m_listShowEventInfo.at(index.row()); +} + +const QList CEventItemModel::getListShowAlarmInfo() const +{ + return m_listShowEventInfo; +} + +void CEventItemModel::insertAlarmMsg(EventMsgPtr info) +{ + int nInsertRowIndex = -1; + if (Qt::AscendingOrder == m_order) + { + for (int nIndex(0); nIndex < m_listShowEventInfo.count(); nIndex++) + { + EventMsgPtr msg(m_listShowEventInfo.at(nIndex)); + if (!msg->lessThan(info, m_sortKey)) + { + nInsertRowIndex = nIndex; + break; + } + } + } + else + { + for (int nIndex(0); nIndex < m_listShowEventInfo.count(); nIndex++) + { + EventMsgPtr msg(m_listShowEventInfo.at(nIndex)); + if (!msg->moreThan(info, m_sortKey)) + { + nInsertRowIndex = nIndex; + break; + } + } + } + if (-1 == nInsertRowIndex) + { + nInsertRowIndex = m_listShowEventInfo.count(); + } + + + beginInsertRows(QModelIndex(), nInsertRowIndex, nInsertRowIndex); + m_listShowEventInfo.insert(nInsertRowIndex, info); + endInsertRows(); + + return; +} + +QVariant CEventItemModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(Qt::DisplayRole == role && Qt::Horizontal == orientation) + { + return QVariant(header.at(section)); + } + return QVariant(); +} + +QVariant CEventItemModel::data(const QModelIndex &index, int role) const +{ + if(!index.isValid() || index.row() >= m_listShowEventInfo.count()) + { + return QVariant(); + } + + if(Qt::TextAlignmentRole == role) + { + if(index.column() == (int)E_SORT_CONTENT) + { + return QVariant(Qt::AlignLeft | Qt::AlignVCenter); + }else + { + return QVariant(Qt::AlignHCenter | Qt::AlignVCenter); + } + } + else if(Qt::DisplayRole == role) + { + switch (index.column()) + { + case E_SORT_TIME : + { + return QDateTime::fromMSecsSinceEpoch(m_listShowEventInfo.at(index.row())->time_stamp, Qt::LocalTime).toString("yyyy-MM-dd hh:mm:ss.zzz"); + } + case E_SORT_PRIORITY : + { + return CEventDataCollect::instance()->priorityDescription(m_listShowEventInfo.at(index.row())->priority); + } + case E_SORT_LOCATION : + { + return CEventDataCollect::instance()->locationDescription(m_listShowEventInfo.at(index.row())->location_id); + } + case E_SORT_REGION : + { + return CEventDataCollect::instance()->regionDescription(m_listShowEventInfo.at(index.row())->region_id); + } + case E_SORT_TYPE : + { + return CEventDataCollect::instance()->alarmTypeDescription(m_listShowEventInfo.at(index.row())->alm_type); + } + case E_SORT_STATUS : + { + return CEventDataCollect::instance()->alarmStatusDescription(m_listShowEventInfo.at(index.row())->alm_status); + } + case E_SORT_STYLE : + { + if(AS_ALARM == m_listShowEventInfo.at(index.row())->alm_style) //未复归 + { + return tr("未复归"); + } + else if(AS_ALARM_RTN == m_listShowEventInfo.at(index.row())->alm_style ) //已复归 + { + return tr("已复归"); + }else{ + return QString("-"); + } + } + case E_SORT_CONTENT : + { + return m_listShowEventInfo.at(index.row())->content; + } + default: + return QVariant(); + } + } + return QVariant(); +} + +int CEventItemModel::columnCount(const QModelIndex &index) const +{ + if (index.isValid()) + { + return 0; + } + + return header.count(); +} + +int CEventItemModel::rowCount(const QModelIndex &index) const +{ + if (index.isValid()) + { + return 0; + } + return m_listShowEventInfo.count(); +} + +Qt::ItemFlags CEventItemModel::flags(const QModelIndex &index) const +{ + // return Qt::NoItemFlags; + if (!index.isValid()) + { + return Qt::NoItemFlags; + } + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; +} +// +void CEventItemModel::sortColumn(int column, Qt::SortOrder order) +{ + if(order == Qt::AscendingOrder) + { + m_order = Qt::DescendingOrder; + } + else + { + m_order = Qt::AscendingOrder; + } + m_sortKey = (E_ALARM_SORTKEY)column; + + beginResetModel(); + sort(); + endResetModel(); +} + +//<归并排序 +void CEventItemModel::sort() +{ + QMap mapAlarmInfo; + //<分 + for(int nIndex(0); nIndex < m_listShowEventInfo.count(); nIndex++) + { + EventMsgPtr temp = m_listShowEventInfo.at(nIndex); + mapAlarmInfo[nIndex / 1000].second.append(temp); + } + + //<快速排序 + for(int nMapIndex(0); nMapIndex < mapAlarmInfo.count(); nMapIndex++) + { + qucikSort(mapAlarmInfo[nMapIndex].second, 0, mapAlarmInfo[nMapIndex].second.count() - 1); + } + + //<治 + PAIRLISTALARMINFO tempListAlarmInfo = mapAlarmInfo[0]; + for(int nPairIndex(1); nPairIndex < mapAlarmInfo.count(); nPairIndex++) + { + //<归并 + tempListAlarmInfo.first = 0; + mapAlarmInfo[nPairIndex].first = 0; + while(mapAlarmInfo[nPairIndex].first < mapAlarmInfo[nPairIndex].second.count()) + { + if(tempListAlarmInfo.first >= tempListAlarmInfo.second.count()) + { + tempListAlarmInfo.second.append(mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first)); + mapAlarmInfo[nPairIndex].first += 1; + } + else + { + if(Qt::AscendingOrder == m_order) + { + if(!tempListAlarmInfo.second[tempListAlarmInfo.first]->lessThan(mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first), m_sortKey)) + { + tempListAlarmInfo.second.insert(tempListAlarmInfo.first, mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first)); + mapAlarmInfo[nPairIndex].first += 1; + } + } + else if(Qt::DescendingOrder == m_order) + { + if(!tempListAlarmInfo.second[tempListAlarmInfo.first]->moreThan(mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first), m_sortKey)) + { + tempListAlarmInfo.second.insert(tempListAlarmInfo.first, mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first)); + mapAlarmInfo[nPairIndex].first += 1; + } + } + } + tempListAlarmInfo.first += 1; + } + } + m_listShowEventInfo = tempListAlarmInfo.second; +} + +// +void CEventItemModel::qucikSort(QList &list, int start, int last) +{ + int index; + while(start < last) + { + if(Qt::AscendingOrder == m_order) + { + index = partitionAscendingOrder(list, start, last); + } + else if(Qt::DescendingOrder == m_order) + { + index = partitionDescendingOrder(list, start, last); + } + qucikSort(list, start, index - 1); + start=index+1; //<尾优化 + } +} +//// +int CEventItemModel::partitionAscendingOrder(QList &list, int start, int last) +{ + EventMsgPtr info = list[start]; + int left = start; + int right = last; + while(left < right) + { + while(left < right && !list[right]->lessThan(info, m_sortKey)) + { + --right; + } + list[left] = list[right]; + + while(leftlessThan(info, m_sortKey)) + { + ++left; + } + list[right] = list[left]; + } + list[left] = info; + return left; +} + +int CEventItemModel::partitionDescendingOrder(QList &list, int start, int last) +{ + EventMsgPtr info = list[start]; + int left = start; + int right = last; + while(left < right) + { + while(left < right && !list[right]->moreThan(info, m_sortKey)) + { + --right; + } + list[left] = list[right]; + + while(leftmoreThan(info, m_sortKey)) + { + ++left; + } + list[right] = list[left]; + } + list[left] = info; + return left; +} +//// + + +void CEventItemModel::getFilter(bool &isLevelFilterEnable, QList &levelFilter, + bool &isLocationFilterEnable, QList &locationFilter, + bool &isRegionFilterEnable, QList ®ionFilter, + bool &isTypeFilterEnable, QList &alarmTypeFilter, + bool &deviceTypeFilter, QString &subSystem, QString &deviceType, + bool &keywordFilterEnable, QString &keyword, + bool &timeFilterEnable, QDateTime &startTime, QDateTime &endTime, + bool &returnFilterEnable,bool &isReturn) +{ + Q_UNUSED(isLevelFilterEnable); + Q_UNUSED(levelFilter); + Q_UNUSED(isLocationFilterEnable); + Q_UNUSED(locationFilter); + Q_UNUSED(isRegionFilterEnable); + Q_UNUSED(regionFilter); + Q_UNUSED(isTypeFilterEnable); + Q_UNUSED(alarmTypeFilter); + Q_UNUSED(deviceTypeFilter); + Q_UNUSED(subSystem); + Q_UNUSED(deviceType); + Q_UNUSED(keywordFilterEnable); + Q_UNUSED(keyword); + Q_UNUSED(timeFilterEnable); + Q_UNUSED(startTime); + Q_UNUSED(endTime); + Q_UNUSED(returnFilterEnable); + Q_UNUSED(isReturn); +} +// isLevelFilterEnable = m_isLevelFilterEnable; +// levelFilter = m_levelFilter; +// isLocationFilterEnable = m_isLocationFilterEnable; +// locationFilter = m_locationFilter; +// isRegionFilterEnable = m_isRegionFilterEnable; +// regionFilter = m_regionFilter; +// isTypeFilterEnable = m_isStatusFilterEnable; +// alarmTypeFilter = m_statusFilter2; +// subSystem = m_subSystem; +// deviceTypeFilter = m_isDeviceTypeFileter; +// deviceType = m_deviceType; +// keywordFilterEnable = m_isKeywordEnable; +// keyword = m_keyword; +// timeFilterEnable = m_timeFilterEnable; +// startTime = m_startTime; +// endTime = m_endTime; +// returnFilterEnable = m_isReturnFilterEnable; +// isReturn = m_isReturn; +//} +//// +bool CEventItemModel::conditionFilter(EventMsgPtr info) +{ + //< 等级 + if(m_isLevelFilterEnable && !m_levelFilter.contains(info->priority)) + { + return false; + } + + //< 车站 + if(m_isLocationFilterEnable) + { + if(!m_locationFilter.contains(info->location_id)) + { + return false; + } + } + else + { + if(!CEventDataCollect::instance()->locationList().contains(info->location_id)) + { + return false; + } + } + + //< 责任区 + if(m_isRegionFilterEnable) + { + if(!m_regionFilter.contains(info->region_id)) + { + return false; + } + } + else + { + if(!CEventDataCollect::instance()->regionList().contains(info->region_id) && info->region_id != -1) //< 未配置责任区的报警同样显示 + { + return false; + } + } + + //< 状态 + if(m_isStatusFilterEnable && !m_statusFilter.contains(info->alm_status)) + { + return false; + } + + //< 设备类型 + if(m_isDeviceTypeFileter) + { + if(CEventDataCollect::instance()->deviceTypeId(m_deviceType) != info->dev_type) + { + return false; + } + } + //< 关键字 + if(m_isKeywordEnable) + { + if(!info->content.contains(m_keyword)) + { + return false; + } + } + + //< 时间 + if(m_timeFilterEnable) + { + if((quint64)m_startTime.toMSecsSinceEpoch() >= info->time_stamp) + { + return false; + } + if((quint64)m_endTime.toMSecsSinceEpoch() <= info->time_stamp) + { + return false; + } + } + if(m_isReturnFilterEnable) + { + if(m_isReturn) + { + if(info->alm_style != AS_ALARM_RTN) + { + return false; + } + } + else + { + if(info->alm_style != AS_ALARM ) + { + return false; + } + } + } + return true; +} +//// +void CEventItemModel::setPriorityFilter(bool &isCheck, QList &priorityFilter) +{ + Q_UNUSED(isCheck); + Q_UNUSED(priorityFilter); +} +// m_isLevelFilterEnable = isCheck; +// m_levelFilter = priorityFilter; + +// slotMsgRefresh(); +//} +//// +void CEventItemModel::setLocationFilter(bool &isCheck, QList &locationFilter) +{ + Q_UNUSED(isCheck); + Q_UNUSED(locationFilter); +} +// m_isLocationFilterEnable = isCheck; +// m_locationFilter = locationFilter; + +// slotMsgRefresh(); +//} +//// +void CEventItemModel::setEventTypeFilter(bool &isCheck, QList &eventTypeFilter, bool &other) +{ + Q_UNUSED(isCheck); + Q_UNUSED(eventTypeFilter); + Q_UNUSED(other); +} +// m_isStatusFilterEnable = isCheck; +// m_statusFilter = eventTypeFilter; +// m_statusFilter2 = eventTypeFilter; +// if(other == true) +// { +// QMap otherEventStatus = CEventDataCollect::instance()->eventOtherStatusDescriptionMap(); +// QMap::iterator it = otherEventStatus.begin(); +// for(;it != otherEventStatus.end(); ++it) +// { +// m_statusFilter.append(it.key()); +// } +// } +// slotMsgRefresh(); +//} +//// +void CEventItemModel::setEventTimeFilter(bool &isCheck, QDate &startTime, QDate &endTime) +{ + Q_UNUSED(isCheck); + Q_UNUSED(startTime); + Q_UNUSED(endTime); +} +// m_timeFilterEnable = isCheck; +// if(isCheck) +// { +// QTime time_1(0,0,0); +// QTime time_2(23,59,59); +// m_startTime.setDate(startTime); +// m_startTime.setTime(time_1); +// m_endTime.setDate(endTime); +// m_endTime.setTime(time_2); +// } +// slotMsgRefresh(); +//} +//// +void CEventItemModel::setEventTimeFilter(bool &isCheck) +{ + Q_UNUSED(isCheck); +} +// m_timeFilterEnable = isCheck; +// slotMsgRefresh(); +//} +//// +void CEventItemModel::getPriorityFilter(bool &isCheck, QList &priorityFilter) +{ + Q_UNUSED(isCheck); + Q_UNUSED(priorityFilter); +} +// isCheck = m_isLevelFilterEnable; +// priorityFilter = m_levelFilter; +//} +//// +void CEventItemModel::getLocationFilter(bool &isCheck, QList &locationFilter) +{ + Q_UNUSED(isCheck); + Q_UNUSED(locationFilter); +} +// isCheck = m_isLocationFilterEnable; +// locationFilter = m_locationFilter; +//} +//// +void CEventItemModel::getEventStatusFilter(bool &isCheck, QList &eventStatusFilter) +{ + Q_UNUSED(isCheck); + Q_UNUSED(eventStatusFilter); +} +// isCheck = m_isStatusFilterEnable; +// eventStatusFilter = m_statusFilter2; +//} +//// +void CEventItemModel::getEventTimeFilter(bool &isCheck, QDateTime &startTime, QDateTime &endTime) +{ + Q_UNUSED(isCheck); + Q_UNUSED(startTime); + Q_UNUSED(endTime); +} +// isCheck = m_timeFilterEnable; +// startTime = m_startTime; +// endTime = m_endTime; +//} +//// +QList CEventItemModel::getListEventInfo() +{return m_listShowEventInfo;} +// return m_listShowEventInfo; +//} + +void CEventItemModel::slotMsgRefresh() +{ + //需要先过滤 + m_listAllEventInfo = CEventMsgManage::instance()->getListEventInfo(); + //根据复归过滤 + QList listFilterInfo; + firstFilterByReturn(listFilterInfo); + m_listAllEventInfo.clear(); + beginResetModel(); + m_listShowEventInfo.clear(); + QList::iterator it = listFilterInfo.begin(); + while (it != listFilterInfo.end()) { + if(conditionFilter(*it)) + { + m_listShowEventInfo.append(*it); + } + it++; + } + sort(); + endResetModel(); +} + +void CEventItemModel::slotMsgArrived(QList listEvents) +{ + if(m_isReturnFilterEnable) + { + slotMsgRefresh(); + }else + { + QList::iterator itPos = listEvents.begin(); + while(itPos != listEvents.end()) + { + if(conditionFilter(*itPos)) + { + insertAlarmMsg(*itPos); + } + itPos++; + } + } + + for(int nIndex = m_listShowEventInfo.size() - 1; nIndex >= 0; --nIndex) + { + if(m_listShowEventInfo.at(nIndex)->deleted) + { + beginRemoveRows(QModelIndex(), nIndex, nIndex); + m_listShowEventInfo.removeAt(nIndex); + endRemoveRows(); + } + } +} + +void CEventItemModel::firstFilterByReturn(QList &filterList) +{ + if(!m_isReturnFilterEnable) + { + filterList = m_listAllEventInfo; + return; + } + + QHash filerHash; + + QList::iterator it = m_listAllEventInfo.begin(); + while (it != m_listAllEventInfo.end()) { + if((*it)->key_id_tag.isEmpty()) + { + it++; + continue; + } + //< 动作和复归 + if((*it)->alm_style == AS_ALARM || (*it)->alm_style == AS_ALARM_RTN) + { + EventMsgPtr ptr = filerHash.value((*it)->key_id_tag,NULL); + if(ptr != NULL) + { + if((*it)->time_stamp >ptr->time_stamp) + { + filerHash[(*it)->key_id_tag] = (*it); + } + }else + { + filerHash[(*it)->key_id_tag] = (*it); + } + } + it++; + } + QHash::iterator pos = filerHash.begin(); + while (pos != filerHash.end()) { + filterList.append(pos.value()); + pos++; + } +} diff --git a/product/src/tools/debug_tool_v2/CEventItemModel.h b/product/src/tools/debug_tool_v2/CEventItemModel.h new file mode 100644 index 00000000..2a113044 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventItemModel.h @@ -0,0 +1,145 @@ +#ifndef CEVENTITEMMODEL_H +#define CEVENTITEMMODEL_H + +#include +#include +#include "CEventMsgInfo.h" +#include "CEventDataCollect.h" +#include + +#define Row_Full (15000) + +class CEventMsgInfo; +class QTimer; + +class CEventItemModel : public QAbstractTableModel +{ + Q_OBJECT +public: + CEventItemModel(QObject *parent = Q_NULLPTR); + ~CEventItemModel(); + + void initialize(); + void initFilter(); + + void initFilterAndReloadData(); + void setSystemResources(CSystemResources *pSystemResources); + + EventMsgPtr getAlarmInfo(const QModelIndex &index) const; + + const QList getListShowAlarmInfo() const; + + /** + * @brief insertAlarmMsg 数采通知模型报警到达 + * @param info + */ + void insertAlarmMsg(EventMsgPtr info); + + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + virtual int columnCount(const QModelIndex &index = QModelIndex()) const; + virtual int rowCount(const QModelIndex &index = QModelIndex()) const; + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + void sort(); + void qucikSort(QList &listAlarmInfo, int left, int right); + int partitionAscendingOrder(QList &list, int start, int last); + int partitionDescendingOrder(QList &list, int start, int last); + + /** + * 设置模型数据过滤条件,过滤显示数据 + */ + void setFilter(const bool &isLevelFilterEnable, const QList &levelFilter, + const bool &isStationFilterEnable, const QList &stationFilter, + const bool &isRegionFilterEnable, const QList ®ionFilter, + const bool &isTypeFilterEnable, const QList &typeFilter, + const bool &isDeviceTypeFilter = false, const QString &subSystem = QString(), const QString &deviceType = QString(), + const bool &isKeywordFilterEnable = false, const QString &keyword = QString(), + const bool &timeFilterEnable = false, const QDateTime &startTime = QDateTime(), + const QDateTime &endTime = QDateTime(),const bool &isReturnFilterEnable = false,const bool &isReturn = false); + + /** + * 获取模型数据过滤条件,用于初始化过滤对话框 + */ + void getFilter(bool &isLevelFilterEnable, QList &levelFilter, + bool &isLocationFilterEnable, QList &locationFilter, + bool &isRegionFilterEnable, QList ®ionFilter, + bool &isTypeFilterEnable, QList &alarmTypeFilter, + bool &deviceTypeFilter, QString &subSystem, QString &deviceType, + bool &keywordFilterEnable, QString &keyword, + bool &timeFilterEnable, QDateTime &startTime, QDateTime &endTime, + bool &returnFilterEnable,bool &isReturn); + + bool conditionFilter(EventMsgPtr info); + + void setPriorityFilter(bool &isCheck, QList &priorityFilter); + void setLocationFilter(bool &isCheck, QList &locationFilter); + void setEventTypeFilter(bool &isCheck, QList &eventTypeFilter, bool &other); + void setEventTimeFilter(bool &isCheck,QDate &startTime,QDate &endTime); + void setEventTimeFilter(bool &isCheck); + + void getPriorityFilter(bool &isCheck,QList &priorityFilter); + + void getLocationFilter(bool &isCheck,QList &locationFilter); + + void getEventStatusFilter(bool &isCheck, QList &eventStatusFilter); + + void getEventTimeFilter(bool &isCheck,QDateTime &startTime, QDateTime &endTime); + + QList getListEventInfo(); +signals: + void sigRowChanged(); + +public slots: + void sortColumn(int column, Qt::SortOrder order = Qt::AscendingOrder); + +private slots: + /** + * @brief slotMsgRefresh 更新model,重新拉取数据 + */ + void slotMsgRefresh(); + + /** + * @brief slotMsgArrived 报警消息到达 + * @param info + */ + void slotMsgArrived(QList listEvents); +private: + void firstFilterByReturn(QList &filterSet); + +private: + QStringList header; + QList m_listShowEventInfo; + QList m_listAllEventInfo; + CSystemResources *m_pSystemResources; + + E_ALARM_SORTKEY m_sortKey; //排序规则 + Qt::SortOrder m_order; + + //Filter + bool m_isLevelFilterEnable; //是否按报警级别过滤 + QList m_levelFilter; //报警级别过滤 + bool m_isLocationFilterEnable; //是否按车站过滤 + QList m_locationFilter; //车站过滤 + bool m_isRegionFilterEnable; //是否按责任区过滤 + QList m_regionFilter; //责任区过滤 + bool m_isStatusFilterEnable; //是否按事件状态过滤 + QList m_statusFilter; //事件状态过滤(所有的要过滤事件状态--如果其他状态没有被勾选,则与下面的内容相同) + QList m_statusFilter2; //事件状态过滤(显示在过滤窗中的事件状态) + bool m_isDeviceTypeFileter; //设备类型过滤 + QString m_subSystem; //子系统 + QString m_deviceType; //设备类型 + bool m_isKeywordEnable; //关键字过滤 + QString m_keyword; //关键字 + bool m_timeFilterEnable; //是否根据时间过滤 + QDateTime m_startTime; //起始时间 + QDateTime m_endTime; //终止时间 + + bool m_isReturnFilterEnable; //是否根据复归状态过滤 + bool m_isReturn; + + QMap m_areaInfoMap; //区域信息 + + QMap > m_areaLocMap; //区域映射 +}; + +#endif // CEVENTITEMMODEL_H diff --git a/product/src/tools/debug_tool_v2/CEventMsgInfo.cpp b/product/src/tools/debug_tool_v2/CEventMsgInfo.cpp new file mode 100644 index 00000000..9be7e361 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventMsgInfo.cpp @@ -0,0 +1,448 @@ +#include "CEventMsgInfo.h" +#include +#include "CEventDataCollect.h" +#include + +CEventMsgInfo::CEventMsgInfo() +{ + alm_type = -1; + alm_style = AS_EVENT_ONLY; + time_stamp = 1000; + domain_id = -1; + location_id = -1; + app_id = -1; + content = QString(""); + priority = -1; + dev_type = -1; + region_id = -1; + key_id_tag = QString(); + uuid_base64 = QString(); + priorityOrder = -1; + deleted = false; + filterDelete = false; + wave_file = QString(); +} + +CEventMsgInfo::CEventMsgInfo(const CEventMsgInfo &other) +{ + alm_type = other.alm_type; + alm_style = other.alm_style; + time_stamp = other.time_stamp; + domain_id = other.domain_id; + location_id = other.location_id; + app_id = other.app_id; + content = other.content; + priority = other.priority; + dev_type = other.dev_type; + key_id_tag = other.key_id_tag; + uuid_base64 = other.uuid_base64; + region_id = other.region_id; + deleted = other.deleted; + filterDelete = other.filterDelete; + wave_file = other.wave_file; +} + +void CEventMsgInfo::initialize(const iot_idl::SEvtInfoToEvtClt &eventInfo) +{ + alm_type = eventInfo.alm_type(); + E_ALARM_LOGICSTATE logic = (E_ALARM_LOGICSTATE)eventInfo.logic_state(); + if(logic == E_ALS_ALARM || logic == E_ALS_ALARM_CFM || + logic == E_ALS_ALARM_DEL || logic == E_ALS_ALARM_CFM_DEL) + { + alm_style = AS_ALARM; + }else if(logic == E_ALS_RETURN || logic == E_ALS_RETURN_CFM || + logic == E_ALS_RETURN_DEL || logic == E_ALS_RETURN_CFM_DEL) + { + alm_style = AS_ALARM_RTN; + }else{ + alm_style = AS_EVENT_ONLY; + } + time_stamp = eventInfo.time_stamp(); + alm_status = eventInfo.alm_status(); + domain_id = eventInfo.domain_id(); + location_id = eventInfo.location_id(); + app_id = eventInfo.app_id(); + content = QString::fromStdString(eventInfo.content()); + priority = eventInfo.priority(); + dev_type = eventInfo.dev_type(); + key_id_tag = QString::fromStdString(eventInfo.key_id_tag()); + uuid_base64 = QString::fromStdString(eventInfo.uuid_base64()); + if(eventInfo.has_region_id() && eventInfo.region_id() > 0) + { + region_id = eventInfo.region_id(); + } + else + { + region_id = -1; + } + wave_file = QString::fromStdString(eventInfo.wave_file()); +} + +bool CEventMsgInfo::lessThan(EventMsgPtr info, E_ALARM_SORTKEY sortkey) +{ + switch (sortkey) + { + case E_SORT_PRIORITY: + { + if(priorityOrder < info->priorityOrder) + { + return true; + } + else if(priorityOrder > info->priorityOrder) + { + return false; + } + else if(priorityOrder == info->priorityOrder) + { + if(time_stamp <= info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_TIME: + { + if(time_stamp < info->time_stamp) + { + return true; + } + if(time_stamp > info->time_stamp) + { + return false; + } + else if(time_stamp == info->time_stamp) + { + if(priorityOrder <= info->priorityOrder) + { + return true; + } + return false; + } + break; + } + case E_SORT_LOCATION: + { + if(location_id < info->location_id) + { + return true; + } + else if(location_id > info->location_id) + { + return false; + } + else if(location_id == info->location_id) + { + if(time_stamp <= info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_REGION: + { + if(region_id < info->region_id) + { + return true; + } + else if(region_id > info->region_id) + { + return false; + } + else if(region_id == info->region_id) + { + if(time_stamp <= info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_TYPE: + { + if(alm_type < info->alm_type) + { + return true; + } + else if(alm_type > info->alm_type) + { + return false; + } + else if(alm_type == info->alm_type) + { + if(time_stamp <= info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_STATUS: + { + if(alm_status < info->alm_status) + { + return true; + } + else if(alm_status > info->alm_status) + { + return false; + } + else if(alm_status == info->alm_status) + { + if(time_stamp <= info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_STYLE: + { + if(alm_style alm_style) + { + return true; + } + else if(alm_style >info->alm_style) + { + return false; + } + else + { + if(time_stamp < info->time_stamp) + { + return true; + } + return false; + } + break; + } + case E_SORT_CONTENT: + { + if(content.isEmpty() && info->content.isEmpty()) + { + return false; + } + else if(content.isEmpty() && (!info->content.isEmpty())) + { + return true; + } + else if((!content.isEmpty()) && info->content.isEmpty()) + { + return false; + } + else if(content < info->content) + { + return true; + } + else if(content > info->content) + { + return false; + } + else if(content == info->content) + { + if(time_stamp < info->time_stamp) + { + return false; + } + return true; + } + break; + } + default: + break; + } + return false; +} + +bool CEventMsgInfo::moreThan(EventMsgPtr info, E_ALARM_SORTKEY sortkey) +{ + switch (sortkey) + { + case E_SORT_PRIORITY: + { + if(priorityOrder > info->priorityOrder) + { + return true; + } + else if(priorityOrder < info->priorityOrder) + { + return false; + } + else if(priorityOrder == info->priorityOrder) + { + if(time_stamp >= info->time_stamp) + { + return true; + } + return false; + } + break; + } + case E_SORT_TIME: + { + if(time_stamp > info->time_stamp) + { + return true; + } + if(time_stamp < info->time_stamp) + { + return false; + } + else if(time_stamp == info->time_stamp) + { + if(priorityOrder < info->priorityOrder) + { + return true; + } + return false; + } + break; + } + case E_SORT_LOCATION: + { + if(location_id > info->location_id) + { + return true; + } + else if(location_id < info->location_id) + { + return false; + } + else if(location_id == info->location_id) + { + if(time_stamp <= info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_REGION: + { + if(region_id > info->region_id) + { + return true; + } + else if(region_id < info->region_id) + { + return false; + } + else if(region_id == info->region_id) + { + if(time_stamp <= info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_TYPE: + { + if(alm_type > info->alm_type) + { + return true; + } + else if(alm_type < info->alm_type) + { + return false; + } + else if(alm_type == info->alm_type) + { + if(time_stamp <= info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_STATUS: + { + if(alm_status > info->alm_status) + { + return true; + } + else if(alm_status < info->alm_status) + { + return false; + } + else if(alm_status == info->alm_status) + { + if(time_stamp <= info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_STYLE: + { + if(alm_style alm_style) + { + return false; + } + else if(alm_style >info->alm_style) + { + return true; + } + else + { + if(time_stamp < info->time_stamp) + { + return false; + } + return true; + } + break; + } + case E_SORT_CONTENT: + { + if(content.isEmpty() && info->content.isEmpty()) + { + return true; + } + else if(content.isEmpty() && (!info->content.isEmpty())) + { + return false; + } + else if((!content.isEmpty()) && info->content.isEmpty()) + { + return true; + } + else if(content > info->content) + { + return true; + } + else if(content < info->content) + { + return false; + } + else if(content == info->content) + { + if(time_stamp < info->time_stamp) + { + return false; + } + return true; + } + break; + } + default: + break; + } + return false; +} + +bool CEventMsgInfo::operator==(const EventMsgPtr &target) +{ + return uuid_base64 == target->uuid_base64; +} diff --git a/product/src/tools/debug_tool_v2/CEventMsgInfo.h b/product/src/tools/debug_tool_v2/CEventMsgInfo.h new file mode 100644 index 00000000..133c6eb8 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventMsgInfo.h @@ -0,0 +1,168 @@ +#ifndef ALARMMSGINFO_H +#define ALARMMSGINFO_H + +#include +#include +#include +#include "alarm_server_api/CAlmApiForEvtClt.h" +#include "common/DataType.h" +#include + +#define LIMIT_HIS_RECORD 10000 +#define REAL_BUTTON_COLUMN 7 //按钮所在列 +#define HIS_BUTTON_COLUMN 9 //按钮所在列 +//排序 +enum E_ALARM_VIEW +{ + E_ALARM_REAL_EVENT = 0, + E_ALARM_HIS_EVENT =1 +}; +enum E_ALARM_SORTKEY +{ + E_SORT_TIME = 0, //时间戳 + E_SORT_PRIORITY, //优先级 + E_SORT_LOCATION, //车站 + E_SORT_REGION, //责任区 + E_SORT_TYPE, //事件类型 + E_SORT_STATUS, //事件状态 + E_SORT_STYLE, //复归状态 + E_SORT_CONTENT //告警内容 +}; + +enum E_ALARM_STYLE +{ + AS_ALARM = 0, // 告警动作 + AS_ALARM_RTN = 1, // 告警恢复 + AS_EVENT_ONLY = 2, // 仅产生事件 + AS_DO_NOTHING = 3, // 无 +}; +// 报警状态 +enum E_ALARM_LOGICSTATE +{ + E_ALS_ALARM = 0, // 报警状态 + E_ALS_ALARM_CFM=1, // 报警确认状态 + E_ALS_RETURN=2, // 报警返回状态 + E_ALS_RETURN_CFM=3, // 报警返回确认状态 + ALS_EVT_ONLY = 4, // 仅事件 + + //在原始告警窗删除后,可能还需要在智能告警窗展示 + E_ALS_ALARM_DEL = 20, // 告警状态,且在原始告警窗已删除,可能是达到数量上限而删除 + E_ALS_ALARM_CFM_DEL =21, // 告警确认状态,且在原始告警窗已删除 + E_ALS_RETURN_DEL=22, // 告警返回状态,且在原始告警窗已删除,可能是达到数量上限而删除 + E_ALS_RETURN_CFM_DEL=23, // 告警返回确认状态,且在原始告警窗已删除 + E_ALS_BAD = 100 +}; + +enum E_LOCATION_TYPE +{ + E_LOCATION_NODE = 0, + E_LOCATION_AREA +}; + +struct STimeKeyIdTag +{ + quint64 time_stamp; + QString key_id_tag; +}; + +struct SAreaInfo +{ + int nId; + QString stTag; + QString stDes; + E_LOCATION_TYPE eType; + int nPareaId; + SAreaInfo() { + nId = -1; + stTag = QString(); + stDes = QString(); + eType = E_LOCATION_NODE; + nPareaId = -1; + } +}; +struct ST_FILTER +{ + + bool isLevelFilterEnable; + QList levelFilter; //报警级别过滤 + bool isLocationFilterEnable; //是否按车站过滤 + QList locationFilter; //车站过滤 + bool isRegionFilterEnable; //是否按责任区过滤 + QList regionFilter; //责任区过滤 + bool isStatusFilterEnable; //是否按报警类型过滤 + QList statusFilter; //事件状态过滤(所有的要过滤事件状态--如果其他状态没有被勾选,则与下面的内容相同) + QList statusFilter2; //事件状态过滤(显示在过滤窗中的事件状态) + bool isDeviceTypeFileter; //设备类型过滤 + QString subSystem; //子系统 + QString deviceType; //设备类型 + bool isKeywordEnable; //关键字过滤 + QString keyword; //关键字 + bool timeFilterEnable; //是否根据时间过滤 + QDateTime startTime; //起始时间 + QDateTime endTime; //终止时间 + + bool isReturnFilterEnable; //是否根据复归状态过滤 + bool isReturn; + ST_FILTER() { + isLevelFilterEnable = false; + isLocationFilterEnable = false; + isRegionFilterEnable = false; + + isStatusFilterEnable = false; + + isDeviceTypeFileter = false; + subSystem = QString(); + deviceType = QString(); + isKeywordEnable = false; + keyword = QString(); + timeFilterEnable = false; + QDateTime dataTime(QDateTime::currentDateTime()); + dataTime.setTime(QTime(dataTime.time().hour(),dataTime.time().second(),0,0)); + startTime = dataTime; + dataTime.setTime(QTime(dataTime.time().hour(),dataTime.time().second(),59,999)); + endTime = dataTime; + + isReturnFilterEnable =false; + isReturn = false; + } +}; +class CEventMsgInfo; +typedef QSharedPointer EventMsgPtr; + +class CEventMsgInfo +{ +public: + CEventMsgInfo(); + CEventMsgInfo(const CEventMsgInfo &other); + void initialize(const iot_idl::SEvtInfoToEvtClt &eventInfo); + bool lessThan(EventMsgPtr info, E_ALARM_SORTKEY sortkey = E_SORT_PRIORITY); + bool moreThan(EventMsgPtr info, E_ALARM_SORTKEY sortkey = E_SORT_PRIORITY); + bool operator==(const EventMsgPtr &target); + qint32 alm_type; //报警类型 + E_ALARM_STYLE alm_style; //< 告警类型 + quint64 time_stamp; //时标(RFC1305、POSIX时标标准) + qint32 domain_id; //域ID + qint32 location_id; //位置ID + qint32 app_id; //应用号 + QString content; //报警内容 + qint32 priority; //报警优先级id + qint32 dev_type; //设备类型ID + qint32 region_id; //责任区ID + bool deleted; //实时事件删除标志 + bool filterDelete; //过滤删除 + QString uuid_base64; //< uuid 主键 + QString key_id_tag; //< 测点ID + int32 alm_status; //事件状态 + uint cfm_user; //确认人 + uint64 cfm_time; //确认时间 +//Extend + qint32 priorityOrder; + + QString wave_file; +}; + + +Q_DECLARE_METATYPE(CEventMsgInfo) +Q_DECLARE_METATYPE(EventMsgPtr) + +#endif // ALARMMSGINFO_H diff --git a/product/src/tools/debug_tool_v2/CEventMsgManage.cpp b/product/src/tools/debug_tool_v2/CEventMsgManage.cpp new file mode 100644 index 00000000..1bdf5ea0 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventMsgManage.cpp @@ -0,0 +1,115 @@ +#include "CEventMsgManage.h" +#include +#include +CEventMsgManage * CEventMsgManage::m_pInstance = Q_NULLPTR; + +CEventMsgManage *CEventMsgManage::instance() +{ + if(m_pInstance == Q_NULLPTR) + { + m_pInstance = new CEventMsgManage(); + } + return m_pInstance; +} + + +CEventMsgManage::CEventMsgManage() + : QObject() +{ + mutex = new QMutex(); +} + +CEventMsgManage::~CEventMsgManage() +{ + m_listEventInfo.clear(); + delete mutex; + m_pInstance = Q_NULLPTR; +} + +QList CEventMsgManage::getListEventInfo() +{ + QMutexLocker locker(mutex); + return m_listEventInfo; +} + +int CEventMsgManage::getListEventCount() +{ + if(m_listEventInfo.isEmpty()) + { + return 0; + } + + return m_listEventInfo.count(); +} + +void CEventMsgManage::addEventMsg(const EventMsgPtr msg) +{ + QMutexLocker locker(mutex); + if(!m_listEventInfo.isEmpty()) + { + bool inserted = false; + QList::iterator iter = m_listEventInfo.begin(); + while (iter != m_listEventInfo.end()) + { + if(msg->time_stamp >= (*iter)->time_stamp) + { + m_listEventInfo.insert(iter, msg); + inserted = true; + break; + } + iter++; + } + if (!inserted) + { + m_listEventInfo.append(msg); + } + } + else + { + m_listEventInfo.append(msg); + } + if(m_listEventInfo.size() > 10000) + { + EventMsgPtr info = m_listEventInfo.takeLast(); + info->deleted = true; + } +} + +void CEventMsgManage::linkWave2EvtMsg(const QList &uuidList, const QString &waveFile) +{ + QMutexLocker locker(mutex); + for(int index(0);index::iterator it = m_listEventInfo.begin(); + while (it != m_listEventInfo.end()) { + if((*it)->uuid_base64 == uuidList.at(index)) + { + (*it)->wave_file = waveFile; + break; + } + it++; + } + } +} + +void CEventMsgManage::removeEventMsgByDomainID(const int domainId) +{ + QMutexLocker locker(mutex); + QList::iterator it = m_listEventInfo.begin(); + while (it != m_listEventInfo.end()) + { + if(domainId == (*it)->domain_id) + { + it = m_listEventInfo.erase(it); + continue; + } + it++; + } +} + +void CEventMsgManage::clearRTMsg() +{ + QMutexLocker locker(mutex); + m_listEventInfo.clear(); +} + diff --git a/product/src/tools/debug_tool_v2/CEventMsgManage.h b/product/src/tools/debug_tool_v2/CEventMsgManage.h new file mode 100644 index 00000000..5fa38f26 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventMsgManage.h @@ -0,0 +1,39 @@ +#ifndef CEventMsgManage_H +#define CEventMsgManage_H + +#include +#include "CEventMsgInfo.h" + +class QMutex; + +class CEventMsgManage : public QObject +{ + Q_OBJECT +public: + static CEventMsgManage * instance(); + + ~CEventMsgManage(); + + QList getListEventInfo(); + + int getListEventCount(); + + void addEventMsg(const EventMsgPtr msg); + + void linkWave2EvtMsg(const QList &uuidList,const QString &waveFile); + + void removeEventMsgByDomainID(const int domainId); + + void clearRTMsg(); + +private: + CEventMsgManage(); + +private: + QMutex * mutex; + QList m_listEventInfo; + QList m_historyEventInfo; + static CEventMsgManage * m_pInstance; +}; + +#endif // CEventMsgManage_H diff --git a/product/src/tools/debug_tool_v2/CEventView.cpp b/product/src/tools/debug_tool_v2/CEventView.cpp new file mode 100644 index 00000000..9a0c521d --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventView.cpp @@ -0,0 +1,36 @@ +#include +#include "CEventView.h" + +CEventView::CEventView(QWidget *parent) + :QTableView(parent) +{ + setSortingEnabled(true); + //setAlternatingRowColors(true); + horizontalHeader()->setStretchLastSection(true); + setSelectionBehavior(QAbstractItemView::SelectRows); + //setSelectionMode(QAbstractItemView::MultiSelection); +} + +QModelIndexList CEventView::selectedItems() const +{ + QModelIndexList indexList; + foreach(QModelIndex index, selectedIndexes()) + { + if(index.column() == 0) + { + indexList.append(index); + } + } + return indexList; +} + +void CEventView::setDefaultRowHeight(int height) +{ + verticalHeader()->setDefaultSectionSize(height); +} + +void CEventView::selectionChanged(const QItemSelection &selected, const QItemSelection &deSelected) +{ + QTableView::selectionChanged(selected, deSelected); + emit sig_selectionChanged(selectedIndexes()); +} diff --git a/product/src/tools/debug_tool_v2/CEventView.h b/product/src/tools/debug_tool_v2/CEventView.h new file mode 100644 index 00000000..24779826 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CEventView.h @@ -0,0 +1,22 @@ +#ifndef CEventView_H +#define CEventView_H + +#include + +class CEventView : public QTableView +{ + Q_OBJECT +public: + CEventView(QWidget *parent = Q_NULLPTR); + + QModelIndexList selectedItems() const; + + void setDefaultRowHeight(int height); +signals: + void sig_selectionChanged(const QModelIndexList &list); + +protected slots: + virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deSelected); +}; + +#endif // ALARMVIEW_H diff --git a/product/src/tools/debug_tool_v2/CFesChanData.cpp b/product/src/tools/debug_tool_v2/CFesChanData.cpp new file mode 100644 index 00000000..3d0add6f --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesChanData.cpp @@ -0,0 +1,77 @@ +#include "CFesChanData.h" +#include "ui_CFesChanData.h" +#include "CActiveWindow.h" +CFesChanData::CFesChanData(QWidget *parent) : + QWidget(parent), + ui(new Ui::CFesChanData) +{ + ui->setupUi(this); +} + +CFesChanData::~CFesChanData() +{ + if(ptrChanMonDlg != NULL) + { + delete ptrChanMonDlg; + } + delete ui; +} + +void CFesChanData::Init(bool isConnected) +{ + if(isConnected) + { + m_ConnectFlag = CN_CommConnect; + }else + { + m_ConnectFlag = CN_CommDisconnect; + } + initVariable(); + initSignalAndSlot(); + initView(); +} + +void CFesChanData::slotActiveWindow() +{ + setActiveWindow(); +} + +void CFesChanData::initVariable() +{ + ptrChanMonDlg = new ChanMonDlg((int)E_ACTIVE_WINDOW_FES_CHAN_DATA,this); + ptrChanMonDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesChanData::initSignalAndSlot() +{ + +} + +void CFesChanData::initView() +{ + QGridLayout *gridLayout = new QGridLayout(ui->widget); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrChanMonDlg, 0, 0, 1, 1); +} + +void CFesChanData::setActiveWindow() +{ + //CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_CHAN_DATA); +} + +void CFesChanData::OnNetConnect() +{ + m_ConnectFlag =CN_CommConnect; + + if(ptrChanMonDlg!=NULL) + ptrChanMonDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesChanData::OnNetDisConnect() +{ + m_ConnectFlag =CN_CommDisconnect; + + if(ptrChanMonDlg!=NULL) + ptrChanMonDlg->SetConnectFlags(m_ConnectFlag); +} diff --git a/product/src/tools/debug_tool_v2/CFesChanData.h b/product/src/tools/debug_tool_v2/CFesChanData.h new file mode 100644 index 00000000..574ed34c --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesChanData.h @@ -0,0 +1,42 @@ +#ifndef CFESCHANDATA_H +#define CFESCHANDATA_H + +#include +#include "chanmondlg.h" + +namespace Ui { +class CFesChanData; +} + +class CFesChanData : public QWidget +{ + Q_OBJECT + +public: + explicit CFesChanData(QWidget *parent = 0); + ~CFesChanData(); + void Init(bool isConnected); + +public slots: + void slotActiveWindow(); + +private: + void initVariable(); + void initSignalAndSlot(); + void initView(); + +private slots: + void setActiveWindow(); + + void OnNetConnect(); + void OnNetDisConnect(); + +public: + ChanMonDlg *ptrChanMonDlg; + +private: + Ui::CFesChanData *ui; + int m_ConnectFlag; //连接成功标志 +}; + +#endif // CFESCHANDATA_H diff --git a/product/src/tools/debug_tool_v2/CFesChanData.ui b/product/src/tools/debug_tool_v2/CFesChanData.ui new file mode 100644 index 00000000..4aec7f5b --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesChanData.ui @@ -0,0 +1,36 @@ + + + CFesChanData + + + + 0 + 0 + 558 + 343 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CFesCtrlSim.cpp b/product/src/tools/debug_tool_v2/CFesCtrlSim.cpp new file mode 100644 index 00000000..1f7acce7 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesCtrlSim.cpp @@ -0,0 +1,170 @@ +#include "CFesCtrlSim.h" +#include "ui_CFesCtrlSim.h" +#include "CActiveWindow.h" + +CFesCtrlSim::CFesCtrlSim(QWidget *parent) : + QWidget(parent), + ui(new Ui::CFesCtrlSim), + ptrSimAoDlg(Q_NULLPTR), + ptrSimDoDlg(Q_NULLPTR), + ptrSimMoDlg(Q_NULLPTR), + ptrDefCmdDlg(Q_NULLPTR) +{ + ui->setupUi(this); +} + +CFesCtrlSim::~CFesCtrlSim() +{ + if(ptrSimAoDlg != NULL) + { + delete ptrSimAoDlg; + } + if(ptrSimDoDlg != NULL) + { + delete ptrSimDoDlg; + } + if(ptrSimMoDlg != NULL) + { + delete ptrSimMoDlg; + } + if(ptrDefCmdDlg != NULL) + { + delete ptrDefCmdDlg; + } + delete ui; +} + +void CFesCtrlSim::Init(bool isConnected) +{ + if(isConnected) + { + m_ConnectFlag = CN_CommConnect; + }else + { + m_ConnectFlag = CN_CommDisconnect; + } + initVariable(); + initSignalAndSlot(); + initView(); +} + +void CFesCtrlSim::slotActiveWindow() +{ + setActiveWindow(ui->tabWidget->currentIndex()); +} + +void CFesCtrlSim::initVariable() +{ + ptrSimAoDlg = new SimAoDlg((int)E_ACTIVE_WINDOW_FES_AO_CTRL,this); + ptrSimAoDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesCtrlSim::initSignalAndSlot() +{ + connect(ui->tabWidget,&QTabWidget::currentChanged,this,&CFesCtrlSim::setActiveWindow); +} + +void CFesCtrlSim::initView() +{ + QGridLayout *gridLayout = new QGridLayout(ui->tab); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimAoDlg, 0, 0, 1, 1); + + ui->tabWidget->removeTab(3); +} + +void CFesCtrlSim::setActiveWindow(int current) +{ + switch (current) { + case 0: + if(ptrSimAoDlg == NULL) + { + ptrSimAoDlg = new SimAoDlg((int)E_ACTIVE_WINDOW_FES_AO_CTRL,this); + ptrSimAoDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimAoDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_AO_CTRL); + ptrSimAoDlg->OnRTURefresh(); + break; + case 1: + if(ptrSimDoDlg == NULL) + { + ptrSimDoDlg = new SimDoDlg((int)E_ACTIVE_WINDOW_FES_DO_CTRL,this); + ptrSimDoDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_2); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimDoDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_DO_CTRL); + ptrSimDoDlg->OnRTURefresh(); + break; + case 2: + if(ptrSimMoDlg == NULL) + { + ptrSimMoDlg = new SimMoDlg((int)E_ACTIVE_WINDOW_FES_MO_CTRL,this); + ptrSimMoDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_3); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimMoDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_MO_CTRL); + ptrSimMoDlg->OnRTURefresh(); + break; + case 3: + if(ptrDefCmdDlg == NULL) + { + ptrDefCmdDlg = new DefCmdDlg((int)E_ACTIVE_WINDOW_FES_CUSTOM_CTRL,this); + ptrDefCmdDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_4); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrDefCmdDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_CUSTOM_CTRL); + ptrDefCmdDlg->OnRTURefresh(); + break; + default: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES); + break; + } +} + +void CFesCtrlSim::OnNetConnect() +{ + m_ConnectFlag =CN_CommConnect; + + if(ptrSimAoDlg!=NULL) + ptrSimAoDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimDoDlg!=NULL) + ptrSimDoDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimMoDlg!=NULL) + ptrSimMoDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrDefCmdDlg!=NULL) + ptrDefCmdDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesCtrlSim::OnNetDisConnect() +{ + m_ConnectFlag =CN_CommDisconnect; + + if(ptrSimAoDlg!=NULL) + ptrSimAoDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimDoDlg!=NULL) + ptrSimDoDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimMoDlg!=NULL) + ptrSimMoDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrDefCmdDlg!=NULL) + ptrDefCmdDlg->SetConnectFlags(m_ConnectFlag); +} diff --git a/product/src/tools/debug_tool_v2/CFesCtrlSim.h b/product/src/tools/debug_tool_v2/CFesCtrlSim.h new file mode 100644 index 00000000..add2100d --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesCtrlSim.h @@ -0,0 +1,48 @@ +#ifndef CFESCTRLSIM_H +#define CFESCTRLSIM_H + +#include +#include "defcmddlg.h" +#include "simaodlg.h" +#include "simdodlg.h" +#include "simmodlg.h" + +namespace Ui { +class CFesCtrlSim; +} + +class CFesCtrlSim : public QWidget +{ + Q_OBJECT + +public: + explicit CFesCtrlSim(QWidget *parent = 0); + ~CFesCtrlSim(); + void Init(bool isConnected); + +public slots: + void slotActiveWindow(); + +private: + void initVariable(); + void initSignalAndSlot(); + void initView(); + +private slots: + void setActiveWindow(int current); + + void OnNetConnect(); + void OnNetDisConnect(); + +public: + SimAoDlg *ptrSimAoDlg; + SimDoDlg *ptrSimDoDlg; + SimMoDlg *ptrSimMoDlg; + DefCmdDlg *ptrDefCmdDlg; + +private: + Ui::CFesCtrlSim *ui; + int m_ConnectFlag; //连接成功标志 +}; + +#endif // CFESCTRLSIM_H diff --git a/product/src/tools/debug_tool_v2/CFesCtrlSim.ui b/product/src/tools/debug_tool_v2/CFesCtrlSim.ui new file mode 100644 index 00000000..27b7441f --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesCtrlSim.ui @@ -0,0 +1,66 @@ + + + CFesCtrlSim + + + + 0 + 0 + 653 + 343 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + 0 + + + + 模拟量控制 + + + + + 数字量控制 + + + + + 混合量控制 + + + + + true + + + 自定义控制 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CFesData.cpp b/product/src/tools/debug_tool_v2/CFesData.cpp new file mode 100644 index 00000000..eab64547 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesData.cpp @@ -0,0 +1,178 @@ +#include "CFesData.h" +#include "ui_CFesData.h" +#include "pub_widget/MessageBox.h" +#include +#include +#include +#include "CActiveWindow.h" +CFesData::CFesData(QWidget *parent) : + QWidget(parent), + ui(new Ui::CFesData), + ptrAiMonDlg(Q_NULLPTR), + ptrDiMonDlg(Q_NULLPTR), + ptrPiMonDlg(Q_NULLPTR), + ptrMiMonDlg(Q_NULLPTR) +{ + ui->setupUi(this); +} + +CFesData::~CFesData() +{ + if(ptrAiMonDlg != NULL) + { + delete ptrAiMonDlg; + } + if(ptrDiMonDlg != NULL) + { + delete ptrDiMonDlg; + } + if(ptrMiMonDlg != NULL) + { + delete ptrMiMonDlg; + } + if(ptrPiMonDlg != NULL) + { + delete ptrPiMonDlg; + } + delete ui; +} + +void CFesData::Init(bool isConnected) +{ + if(isConnected) + { + m_ConnectFlag = CN_CommConnect; + }else + { + m_ConnectFlag = CN_CommDisconnect; + } + initVariable(); + initSignalAndSlot(); + initView(); +} + +void CFesData::slotActiveWindow() +{ + setActiveWindow(ui->tabWidget->currentIndex()); +} + +void CFesData::initVariable() +{ + ptrAiMonDlg = new AiMonDlg((int)E_ACTIVE_WINDOW_FES_AI_DATA,this); + ptrAiMonDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesData::initSignalAndSlot() +{ + connect(ui->tabWidget,&QTabWidget::currentChanged,this,&CFesData::setActiveWindow); +} + +void CFesData::initView() +{ + QGridLayout *gridLayout = new QGridLayout(ui->tab_1); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrAiMonDlg, 0, 0, 1, 1); +} + +void CFesData::setActiveWindow(int current) +{ + switch (current) { + case 0: + { + if(ptrAiMonDlg == NULL) + { + ptrAiMonDlg = new AiMonDlg((int)E_ACTIVE_WINDOW_FES_AI_DATA,this); + ptrAiMonDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_1); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrAiMonDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_AI_DATA); + ptrAiMonDlg->OnRTURefresh(); + break; + } + case 1: + if(ptrDiMonDlg == NULL) + { + ptrDiMonDlg = new DiMonDlg((int)E_ACTIVE_WINDOW_FES_DI_DATA,this); + ptrDiMonDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_2); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrDiMonDlg, 0, 0, 1, 1); + } + + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_DI_DATA); + ptrDiMonDlg->OnRTURefresh(); + break; + case 2: + if(ptrPiMonDlg == NULL) + { + ptrPiMonDlg = new PiMonDlg((int)E_ACTIVE_WINDOW_FES_PI_DATA,this); + ptrPiMonDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_3); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrPiMonDlg, 0, 0, 1, 1); + + } + + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_PI_DATA); + ptrPiMonDlg->OnRTURefresh(); + break; + case 3: + if(ptrMiMonDlg == NULL) + { + ptrMiMonDlg = new MiMonDlg((int)E_ACTIVE_WINDOW_FES_MI_DATA,this); + ptrMiMonDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_4); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrMiMonDlg, 0, 0, 1, 1); + } + + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_MI_DATA); + ptrMiMonDlg->OnRTURefresh(); + break; + default: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES); + break; + } +} + +void CFesData::OnNetConnect() +{ + m_ConnectFlag =CN_CommConnect; + + if(ptrAiMonDlg!=NULL) + ptrAiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrDiMonDlg!=NULL) + ptrDiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrPiMonDlg!=NULL) + ptrPiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrMiMonDlg!=NULL) + ptrMiMonDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesData::OnNetDisConnect() +{ + m_ConnectFlag =CN_CommDisconnect; + + if(ptrAiMonDlg!=NULL) + ptrAiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrDiMonDlg!=NULL) + ptrDiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrPiMonDlg!=NULL) + ptrPiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrMiMonDlg!=NULL) + ptrMiMonDlg->SetConnectFlags(m_ConnectFlag); + +} diff --git a/product/src/tools/debug_tool_v2/CFesData.h b/product/src/tools/debug_tool_v2/CFesData.h new file mode 100644 index 00000000..10962f88 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesData.h @@ -0,0 +1,48 @@ +#ifndef CFESDATA_H +#define CFESDATA_H + +#include +#include "aimondlg.h" +#include "dimondlg.h" +#include "pimondlg.h" +#include "mimondlg.h" + +namespace Ui { +class CFesData; +} + +class CFesData : public QWidget +{ + Q_OBJECT + +public: + explicit CFesData(QWidget *parent = 0); + ~CFesData(); + void Init(bool isConnected); + +public slots: + void slotActiveWindow(); + +private: + void initVariable(); + void initSignalAndSlot(); + void initView(); + +private slots: + void setActiveWindow(int current); + + void OnNetConnect(); + void OnNetDisConnect(); + +public: + AiMonDlg *ptrAiMonDlg; + DiMonDlg *ptrDiMonDlg; + PiMonDlg *ptrPiMonDlg; + MiMonDlg *ptrMiMonDlg; +private: + Ui::CFesData *ui; + + int m_ConnectFlag; //连接成功标志 +}; + +#endif // CFESDATA_H diff --git a/product/src/tools/debug_tool_v2/CFesData.ui b/product/src/tools/debug_tool_v2/CFesData.ui new file mode 100644 index 00000000..6c1b5fdd --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesData.ui @@ -0,0 +1,64 @@ + + + CFesData + + + + 0 + 0 + 660 + 401 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + 0 + + + + 模拟量 + + + + + 数字量 + + + + + 累积量 + + + + + 混合量 + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CFesDataSim.cpp b/product/src/tools/debug_tool_v2/CFesDataSim.cpp new file mode 100644 index 00000000..3be09e39 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesDataSim.cpp @@ -0,0 +1,193 @@ +#include "CFesDataSim.h" +#include "ui_CFesDataSim.h" +#include "CActiveWindow.h" + +CFesDataSim::CFesDataSim(QWidget *parent) : + QWidget(parent), + ui(new Ui::CFesDataSim), + ptrSimAiDlg(Q_NULLPTR), + ptrSimDiDlg(Q_NULLPTR), + ptrSimPiDlg(Q_NULLPTR), + ptrSimMiDlg(Q_NULLPTR), + ptrSimEventDlg(Q_NULLPTR) +{ + ui->setupUi(this); +} + +CFesDataSim::~CFesDataSim() +{ + + if(ptrSimAiDlg != NULL) + { + delete ptrSimAiDlg; + } + if(ptrSimDiDlg != NULL) + { + delete ptrSimDiDlg; + } + if(ptrSimPiDlg != NULL) + { + delete ptrSimPiDlg; + } + if(ptrSimMiDlg != NULL) + { + delete ptrSimMiDlg; + } + if(ptrSimEventDlg != NULL) + { + delete ptrSimEventDlg; + } + delete ui; +} + +void CFesDataSim::Init(bool isConnected) +{ + if(isConnected) + { + m_ConnectFlag = CN_CommConnect; + }else + { + m_ConnectFlag = CN_CommDisconnect; + } + initVariable(); + initSignalAndSlot(); + initView(); +} + +void CFesDataSim::slotActiveWindow() +{ + setActiveWindow(ui->tabWidget->currentIndex()); +} + +void CFesDataSim::initVariable() +{ + ptrSimAiDlg = new SimAiDlg((int)E_ACTIVE_WINDOW_FES_AI_CTRL,this); + ptrSimAiDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesDataSim::initSignalAndSlot() +{ + connect(ui->tabWidget,&QTabWidget::currentChanged,this,&CFesDataSim::setActiveWindow); +} + +void CFesDataSim::initView() +{ + QGridLayout *gridLayout = new QGridLayout(ui->tab); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimAiDlg, 0, 0, 1, 1); +} + +void CFesDataSim::setActiveWindow(int current) +{ + switch (current) { + case 0: + if(ptrSimAiDlg == NULL) + { + ptrSimAiDlg = new SimAiDlg((int)E_ACTIVE_WINDOW_FES_AI_CTRL,this); + ptrSimAiDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimAiDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_AI_CTRL); + ptrSimAiDlg->OnRTURefresh(); + break; + case 1: + if(ptrSimDiDlg == NULL) + { + ptrSimDiDlg = new SimDiDlg((int)E_ACTIVE_WINDOW_FES_DI_CTRL,this); + ptrSimDiDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_2); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimDiDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_DI_CTRL); + ptrSimDiDlg->OnRTURefresh(); + break; + case 2: + if(ptrSimPiDlg == NULL) + { + ptrSimPiDlg = new SimPiDlg((int)E_ACTIVE_WINDOW_FES_PI_CTRL,this); + ptrSimPiDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_3); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimPiDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_PI_CTRL); + ptrSimPiDlg->OnRTURefresh(); + break; + case 3: + if(ptrSimMiDlg == NULL) + { + ptrSimMiDlg = new SimMiDlg((int)E_ACTIVE_WINDOW_FES_MI_CTRL,this); + ptrSimMiDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_4); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimMiDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_MI_CTRL); + ptrSimMiDlg->OnRTURefresh(); + break; + case 4: + if(ptrSimEventDlg == NULL) + { + ptrSimEventDlg = new SimEventDlg((int)E_ACTIVE_WINDOW_FES_EVENT_CTRL,this); + ptrSimEventDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_5); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSimEventDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_EVENT_CTRL); + ptrSimEventDlg->OnRTURefresh(); + break; + default: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES); + break; + } +} + +void CFesDataSim::OnNetConnect() +{ + m_ConnectFlag =CN_CommConnect; + + if(ptrSimAiDlg!=NULL) + ptrSimAiDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimDiDlg!=NULL) + ptrSimDiDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimPiDlg!=NULL) + ptrSimPiDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimMiDlg!=NULL) + ptrSimMiDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimEventDlg!=NULL) + ptrSimEventDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesDataSim::OnNetDisConnect() +{ + m_ConnectFlag =CN_CommDisconnect; + + if(ptrSimAiDlg!=NULL) + ptrSimAiDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimDiDlg!=NULL) + ptrSimDiDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimPiDlg!=NULL) + ptrSimPiDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimMiDlg!=NULL) + ptrSimMiDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSimEventDlg!=NULL) + ptrSimEventDlg->SetConnectFlags(m_ConnectFlag); +} diff --git a/product/src/tools/debug_tool_v2/CFesDataSim.h b/product/src/tools/debug_tool_v2/CFesDataSim.h new file mode 100644 index 00000000..f2f86327 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesDataSim.h @@ -0,0 +1,54 @@ +#ifndef CFESDATASIM_H +#define CFESDATASIM_H + +#include +#include "simaidlg.h" +#include "simdidlg.h" +#include "simpidlg.h" +#include "simmidlg.h" +#include "simeventdlg.h" + +namespace Ui { +class CFesDataSim; +} + +class CFesDataSim : public QWidget +{ + Q_OBJECT + +public: + explicit CFesDataSim(QWidget *parent = 0); + ~CFesDataSim(); + void Init(bool isConnected); + +public slots: + void slotActiveWindow(); +private: + void initVariable(); + void initSignalAndSlot(); + void initView(); + +private slots: + void setActiveWindow(int current); + void OnNetConnect(); + void OnNetDisConnect(); +public: + SimAiDlg *ptrSimAiDlg; + SimDiDlg *ptrSimDiDlg; + SimPiDlg *ptrSimPiDlg; + SimMiDlg *ptrSimMiDlg; + SimEventDlg *ptrSimEventDlg; + +private: + Ui::CFesDataSim *ui; + int m_ConnectFlag; //连接成功标志 + + RtuDevMap m_rtuDevMap; + + RtuPointMap m_rtuAiPointMap; + RtuPointMap m_rtuDiPointMap; + RtuPointMap m_rtuPiPointMap; + RtuPointMap m_rtuMiPointMap; +}; + +#endif // CFESDATASIM_H diff --git a/product/src/tools/debug_tool_v2/CFesDataSim.ui b/product/src/tools/debug_tool_v2/CFesDataSim.ui new file mode 100644 index 00000000..638c00ef --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesDataSim.ui @@ -0,0 +1,65 @@ + + + CFesDataSim + + + + 0 + 0 + 675 + 269 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + 模拟量仿真 + + + + + 数字量仿真 + + + + + 累积量仿真 + + + + + 混合量仿真 + + + + + 事件仿真 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CFesEvent.cpp b/product/src/tools/debug_tool_v2/CFesEvent.cpp new file mode 100644 index 00000000..1d150125 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesEvent.cpp @@ -0,0 +1,133 @@ +#include "CFesEvent.h" +#include "ui_CFesEvent.h" +#include "CActiveWindow.h" +CFesEvent::CFesEvent(QWidget *parent) : + QWidget(parent), + ui(new Ui::CFesEvent) +{ + ui->setupUi(this); + ui->tabWidget->setCurrentIndex(0); +} + +CFesEvent::~CFesEvent() +{ + if(ptrChanEventDlg != NULL) + { + delete ptrChanEventDlg; + } + if(ptrSoeEventDlg != NULL) + { + delete ptrSoeEventDlg; + } + if(ptrSoeMemoryDlg != NULL) + { + delete ptrSoeMemoryDlg; + } + delete ui; +} + +void CFesEvent::Init(bool isConnected) +{ + if(isConnected) + { + m_ConnectFlag = CN_CommConnect; + }else + { + m_ConnectFlag = CN_CommDisconnect; + } + initVariable(); + initSignalAndSlot(); + initView(); +} + +void CFesEvent::slotActiveWindow() +{ + setActiveWindow(ui->tabWidget->currentIndex()); +} + +void CFesEvent::initVariable() +{ + ptrChanEventDlg = new ChanEventDlg((int)E_ACTIVE_WINDOW_FES_CHAN_EVENT,this); + ptrChanEventDlg->SetConnectFlags(m_ConnectFlag); + + ptrSoeEventDlg = new SoeEventDlg((int)E_ACTIVE_WINDOW_FES_SOE_EVENT,this); + ptrSoeEventDlg->SetConnectFlags(m_ConnectFlag); + + ptrSoeMemoryDlg = new SoeMemorydlg((int)E_ACTIVE_WINDOW_FES_SOE_MEMORY,this); + ptrSoeMemoryDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesEvent::initSignalAndSlot() +{ + connect(ui->tabWidget,&QTabWidget::currentChanged,this,&CFesEvent::setActiveWindow); +} + +void CFesEvent::initView() +{ + + QGridLayout *gridLayout = new QGridLayout(ui->tab); + + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSoeEventDlg, 0, 0, 1, 1); + + gridLayout = new QGridLayout(ui->tab_2); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrChanEventDlg, 0, 0, 1, 1); + + gridLayout = new QGridLayout(ui->tab_3); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrSoeMemoryDlg, 0, 0, 1, 1); +} + +void CFesEvent::setActiveWindow(int current) +{ + switch (current) { + case 0: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_SOE_EVENT); + ptrSoeEventDlg->OnStartRefreshData(); + + break; + case 1: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_CHAN_EVENT); + ptrChanEventDlg->OnStartRefreshData(); + break; + case 2: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_SOE_MEMORY); + ptrSoeMemoryDlg->OnRefreshData(); + break; + default: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES); + break; + } +} + +void CFesEvent::OnNetConnect() +{ + m_ConnectFlag =CN_CommConnect; + + if(ptrChanEventDlg!=NULL) + ptrChanEventDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSoeEventDlg!=NULL) + ptrSoeEventDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSoeMemoryDlg!=NULL) + ptrSoeMemoryDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesEvent::OnNetDisConnect() +{ + m_ConnectFlag =CN_CommDisconnect; + + if(ptrChanEventDlg!=NULL) + ptrChanEventDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSoeEventDlg!=NULL) + ptrSoeEventDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrSoeMemoryDlg!=NULL) + ptrSoeMemoryDlg->SetConnectFlags(m_ConnectFlag); +} diff --git a/product/src/tools/debug_tool_v2/CFesEvent.h b/product/src/tools/debug_tool_v2/CFesEvent.h new file mode 100644 index 00000000..a2408636 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesEvent.h @@ -0,0 +1,42 @@ +#ifndef CFESEVENT_H +#define CFESEVENT_H + +#include +#include "chaneventdlg.h" +#include "soeeventdlg.h" +#include "soememorydlg.h" + +namespace Ui { +class CFesEvent; +} + +class CFesEvent : public QWidget +{ + Q_OBJECT + +public: + explicit CFesEvent(QWidget *parent = 0); + ~CFesEvent(); + void Init(bool isConnected); + +public slots: + void slotActiveWindow(); +private: + void initVariable(); + void initSignalAndSlot(); + void initView(); + +private slots: + void setActiveWindow(int current); + void OnNetConnect(); + void OnNetDisConnect(); +public: + ChanEventDlg * ptrChanEventDlg; + SoeEventDlg * ptrSoeEventDlg; + SoeMemorydlg * ptrSoeMemoryDlg; +private: + Ui::CFesEvent *ui; + int m_ConnectFlag; //连接成功标志 +}; + +#endif // CFESEVENT_H diff --git a/product/src/tools/debug_tool_v2/CFesEvent.ui b/product/src/tools/debug_tool_v2/CFesEvent.ui new file mode 100644 index 00000000..95cda2b2 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesEvent.ui @@ -0,0 +1,55 @@ + + + CFesEvent + + + + 0 + 0 + 684 + 298 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + SOE事件 + + + + + 通道事件 + + + + + SOE内存 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CFesForwardData.cpp b/product/src/tools/debug_tool_v2/CFesForwardData.cpp new file mode 100644 index 00000000..f54295d9 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesForwardData.cpp @@ -0,0 +1,224 @@ +#include "CFesForwardData.h" +#include "ui_CFesForwardData.h" +#include "CActiveWindow.h" + +CFesForwardData::CFesForwardData(QWidget *parent) : + QWidget(parent), + ui(new Ui::CFesForwardData), + ptrFwAiMonDlg(Q_NULLPTR), + ptrFwDiMonDlg(Q_NULLPTR), + ptrFwDDiMonDlg(Q_NULLPTR), + ptrFwAccMonDlg(Q_NULLPTR), + ptrFwMiMonDlg(Q_NULLPTR) +{ + ui->setupUi(this); +} + +CFesForwardData::~CFesForwardData() +{ + if(ptrFwAiMonDlg != NULL) + { + delete ptrFwAiMonDlg; + } + if(ptrFwDiMonDlg != NULL) + { + delete ptrFwDiMonDlg; + } + if(ptrFwDDiMonDlg != NULL) + { + delete ptrFwDDiMonDlg; + } + if(ptrFwAccMonDlg != NULL) + { + delete ptrFwAccMonDlg; + } + if(ptrFwMiMonDlg != NULL) + { + delete ptrFwMiMonDlg; + } + delete ui; +} + +void CFesForwardData::Init(bool isConnected) +{ + if(isConnected) + { + m_ConnectFlag = CN_CommConnect; + }else + { + m_ConnectFlag = CN_CommDisconnect; + } + initVariable(); + initSignalAndSlot(); + initView(); +} + +void CFesForwardData::slotActiveWindow() +{ + setActiveWindow(ui->tabWidget->currentIndex()); +} + +void CFesForwardData::initVariable() +{ + ptrFwAiMonDlg = new FwAiMonDlg((int)E_ACTIVE_WINDOW_FES_AI_FARWARD,this); + ptrFwAiMonDlg->SetConnectFlags(m_ConnectFlag); + + ptrFwDiMonDlg = new FwDiMonDlg((int)E_ACTIVE_WINDOW_FES_DI_FARWARD,this); + ptrFwDiMonDlg->SetConnectFlags(m_ConnectFlag); + + ptrFwDDiMonDlg = new FwDDiMonDlg((int)E_ACTIVE_WINDOW_FES_DDI_FARWARD,this); + ptrFwDDiMonDlg->SetConnectFlags(m_ConnectFlag); + + ptrFwAccMonDlg = new FwAccMonDlg((int)E_ACTIVE_WINDOW_FES_PI_FARWARD,this); + ptrFwAccMonDlg->SetConnectFlags(m_ConnectFlag); + + ptrFwMiMonDlg = new FwMiMonDlg((int)E_ACTIVE_WINDOW_FES_MI_FARWARD,this); + ptrFwMiMonDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesForwardData::initSignalAndSlot() +{ + connect(ui->tabWidget,&QTabWidget::currentChanged,this,&CFesForwardData::setActiveWindow); +} + +void CFesForwardData::initView() +{ + QGridLayout *gridLayout = new QGridLayout(ui->tab); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwAiMonDlg, 0, 0, 1, 1); + + gridLayout = new QGridLayout(ui->tab_2); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwDiMonDlg, 0, 0, 1, 1); + + gridLayout = new QGridLayout(ui->tab_3); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwDDiMonDlg, 0, 0, 1, 1); + + gridLayout = new QGridLayout(ui->tab_4); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwAccMonDlg, 0, 0, 1, 1); + + gridLayout = new QGridLayout(ui->tab_5); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwMiMonDlg, 0, 0, 1, 1); +} + +void CFesForwardData::setActiveWindow(int current) +{ + switch (current) { + case 0: + if(ptrFwAiMonDlg == Q_NULLPTR) + { + ptrFwAiMonDlg = new FwAiMonDlg((int)E_ACTIVE_WINDOW_FES_AI_FARWARD,this); + ptrFwAiMonDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwAiMonDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_AI_FARWARD); + ptrFwAiMonDlg->OnRTURefresh(); + break; + case 1: + if(ptrFwDiMonDlg == Q_NULLPTR) + { + ptrFwDiMonDlg = new FwDiMonDlg((int)E_ACTIVE_WINDOW_FES_DI_FARWARD,this); + ptrFwDiMonDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_2); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwDiMonDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_DI_FARWARD); + ptrFwDiMonDlg->OnRTURefresh(); + break; + case 2: + if(ptrFwDDiMonDlg == Q_NULLPTR) + { + ptrFwDDiMonDlg = new FwDDiMonDlg((int)E_ACTIVE_WINDOW_FES_DDI_FARWARD,this); + ptrFwDDiMonDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_3); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwDDiMonDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_DDI_FARWARD); + ptrFwDDiMonDlg->OnRTURefresh(); + break; + case 3: + if(ptrFwAccMonDlg == Q_NULLPTR) + { + ptrFwAccMonDlg = new FwAccMonDlg((int)E_ACTIVE_WINDOW_FES_PI_FARWARD,this); + ptrFwAccMonDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_4); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwAccMonDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_PI_FARWARD); + ptrFwAccMonDlg->OnRTURefresh(); + break; + case 4: + if(ptrFwMiMonDlg == Q_NULLPTR) + { + ptrFwMiMonDlg = new FwMiMonDlg((int)E_ACTIVE_WINDOW_FES_MI_FARWARD,this); + ptrFwMiMonDlg->SetConnectFlags(m_ConnectFlag); + QGridLayout *gridLayout = new QGridLayout(ui->tab_5); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrFwMiMonDlg, 0, 0, 1, 1); + } + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_MI_FARWARD); + ptrFwMiMonDlg->OnRTURefresh(); + break; + default: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES); + break; + } +} + +void CFesForwardData::OnNetConnect() +{ + m_ConnectFlag =CN_CommConnect; + + if(ptrFwAiMonDlg!=NULL) + ptrFwAiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrFwDiMonDlg!=NULL) + ptrFwDiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrFwDDiMonDlg!=NULL) + ptrFwDDiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrFwAccMonDlg!=NULL) + ptrFwAccMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrFwMiMonDlg!=NULL) + ptrFwMiMonDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesForwardData::OnNetDisConnect() +{ + m_ConnectFlag =CN_CommDisconnect; + + if(ptrFwAiMonDlg!=NULL) + ptrFwAiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrFwDiMonDlg!=NULL) + ptrFwDiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrFwDDiMonDlg!=NULL) + ptrFwDDiMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrFwAccMonDlg!=NULL) + ptrFwAccMonDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrFwMiMonDlg!=NULL) + ptrFwMiMonDlg->SetConnectFlags(m_ConnectFlag); +} diff --git a/product/src/tools/debug_tool_v2/CFesForwardData.h b/product/src/tools/debug_tool_v2/CFesForwardData.h new file mode 100644 index 00000000..7bca1bba --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesForwardData.h @@ -0,0 +1,51 @@ +#ifndef CFESFORWARDDATA_H +#define CFESFORWARDDATA_H + +#include +#include "fwaimondlg.h" +#include "fwddimondlg.h" +#include "fwdimondlg.h" +#include "fwaccmondlg.h" +#include "fwmimondlg.h" + +namespace Ui { +class CFesForwardData; +} + +class CFesForwardData : public QWidget +{ + Q_OBJECT + +public: + explicit CFesForwardData(QWidget *parent = 0); + ~CFesForwardData(); + void Init(bool isConnected); + +public slots: + void slotActiveWindow(); + +private: + void initVariable(); + void initSignalAndSlot(); + void initView(); + +private slots: + void setActiveWindow(int current); + + void OnNetConnect(); + void OnNetDisConnect(); + +private: + Ui::CFesForwardData *ui; + + int m_ConnectFlag; //连接成功标志 + +public: + FwAiMonDlg *ptrFwAiMonDlg; + FwDiMonDlg *ptrFwDiMonDlg; + FwDDiMonDlg *ptrFwDDiMonDlg; + FwAccMonDlg *ptrFwAccMonDlg; + FwMiMonDlg *ptrFwMiMonDlg; +}; + +#endif // CFESFORWARDDATA_H diff --git a/product/src/tools/debug_tool_v2/CFesForwardData.ui b/product/src/tools/debug_tool_v2/CFesForwardData.ui new file mode 100644 index 00000000..24286999 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesForwardData.ui @@ -0,0 +1,65 @@ + + + CFesForwardData + + + + 0 + 0 + 633 + 279 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + 模拟量 + + + + + 单点数字量 + + + + + 双点数字量 + + + + + 累积量 + + + + + 混合量 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CFesParamShow.cpp b/product/src/tools/debug_tool_v2/CFesParamShow.cpp new file mode 100644 index 00000000..c59b0101 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesParamShow.cpp @@ -0,0 +1,108 @@ +#include "CFesParamShow.h" +#include "ui_CFesParamShow.h" +#include "CActiveWindow.h" +CFesParamShow::CFesParamShow(QWidget *parent) : + QWidget(parent), + ui(new Ui::CFesParamShow) +{ + ui->setupUi(this); +} + +CFesParamShow::~CFesParamShow() +{ + if(ptrChanParamDlg != NULL) + { + delete ptrChanParamDlg; + } + if(ptrRtuParamDlg != NULL) + { + delete ptrRtuParamDlg; + } + delete ui; +} + +void CFesParamShow::Init(bool isConnected) +{ + if(isConnected) + { + m_ConnectFlag = CN_CommConnect; + }else + { + m_ConnectFlag = CN_CommDisconnect; + } + initVariable(); + initSignalAndSlot(); + initView(); +} + +void CFesParamShow::slotActiveWindow() +{ + setActiveWindow(ui->tabWidget->currentIndex()); +} + +void CFesParamShow::initVariable() +{ + ptrChanParamDlg = new ChanParamDlg((int)E_ACTIVE_WINDOW_FES_CHAN_PARAM,this); + ptrChanParamDlg->SetConnectFlags(m_ConnectFlag); + + ptrRtuParamDlg = new RtuParamDlg((int)E_ACTIVE_WINDOW_FES_RTU_PARAM,this); + ptrRtuParamDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesParamShow::initSignalAndSlot() +{ + connect(ui->tabWidget,&QTabWidget::currentChanged,this,&CFesParamShow::setActiveWindow); +} + +void CFesParamShow::initView() +{ + QGridLayout *gridLayout = new QGridLayout(ui->tab); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrChanParamDlg, 0, 0, 1, 1); + + gridLayout = new QGridLayout(ui->tab_2); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(ptrRtuParamDlg, 0, 0, 1, 1); +} + +void CFesParamShow::setActiveWindow(int current) +{ + qDebug()<<"setActiveWindow:"<setActiveWindow((int)E_ACTIVE_WINDOW_FES_CHAN_PARAM); + ptrChanParamDlg->OnRefresh(); + break; + case 1: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES_RTU_PARAM); + ptrRtuParamDlg->OnRefresh(); + break; + default: + CActiveWindow::instance()->setActiveWindow((int)E_ACTIVE_WINDOW_FES); + break; + } +} + +void CFesParamShow::OnNetConnect() +{ + m_ConnectFlag =CN_CommConnect; + + if(ptrChanParamDlg!=NULL) + ptrChanParamDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrRtuParamDlg!=NULL) + ptrRtuParamDlg->SetConnectFlags(m_ConnectFlag); +} + +void CFesParamShow::OnNetDisConnect() +{ + m_ConnectFlag =CN_CommDisconnect; + + if(ptrChanParamDlg!=NULL) + ptrChanParamDlg->SetConnectFlags(m_ConnectFlag); + + if(ptrRtuParamDlg!=NULL) + ptrRtuParamDlg->SetConnectFlags(m_ConnectFlag); +} diff --git a/product/src/tools/debug_tool_v2/CFesParamShow.h b/product/src/tools/debug_tool_v2/CFesParamShow.h new file mode 100644 index 00000000..200fa169 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesParamShow.h @@ -0,0 +1,42 @@ +#ifndef CFESPARAMSHOW_H +#define CFESPARAMSHOW_H + +#include +#include "chanparamdlg.h" +#include "rtuparamdlg.h" + +namespace Ui { +class CFesParamShow; +} + +class CFesParamShow : public QWidget +{ + Q_OBJECT + +public: + explicit CFesParamShow(QWidget *parent = 0); + ~CFesParamShow(); + void Init(bool isConnected); +public slots: + void slotActiveWindow(); + +private: + void initVariable(); + void initSignalAndSlot(); + void initView(); + +private slots: + void setActiveWindow(int current); + void OnNetConnect(); + void OnNetDisConnect(); + +public: + ChanParamDlg *ptrChanParamDlg; + RtuParamDlg *ptrRtuParamDlg; + +private: + Ui::CFesParamShow *ui; + int m_ConnectFlag; //连接成功标志 +}; + +#endif // CFESPARAMSHOW_H diff --git a/product/src/tools/debug_tool_v2/CFesParamShow.ui b/product/src/tools/debug_tool_v2/CFesParamShow.ui new file mode 100644 index 00000000..d786d438 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFesParamShow.ui @@ -0,0 +1,53 @@ + + + CFesParamShow + + + + 0 + 0 + 686 + 288 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + 0 + + + + 通道参数 + + + + + RTU参数 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CFessim.cpp b/product/src/tools/debug_tool_v2/CFessim.cpp new file mode 100644 index 00000000..62304b41 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFessim.cpp @@ -0,0 +1,581 @@ +#include "CFessim.h" +#include "ui_CFessim.h" +#include "pub_widget/MessageBox.h" +#include "CActiveWindow.h" +#include "chanmondlg.h" +#include "CDataMng.h" + +#define CN_CFG_SIMIP "FesSimIP.conf" + +CFessim::CFessim(QWidget *parent) : + QWidget(parent), + ui(new Ui::CFessim) +{ + ui->setupUi(this); + m_pFesParamShow =NULL; + m_pFesData =NULL; + m_pFesEvent =NULL; + m_pFesDataSim =NULL; + m_pFesCtrlSim =NULL; + m_pFesForwardData =NULL; + //m_pFesChanData =NULL; + m_pChanMonDlg = NULL; + m_isConnect = false; + ui->pushButton_connect->setText(tr("连接")); + ui->label_netStatus->setText(tr("通讯断开")); + ui->label_netStatus->setStyleSheet("QLabel{color:red}"); + ui->comboBox_app->setView(new QListView()); + ui->listWidget->setCurrentRow(0); + qRegisterMetaType("std::string&"); + qRegisterMetaType("std::string"); + + ui->iec61850_tool->hide(); + +} + +CFessim::~CFessim() +{ + stopThread(); + delete ui; +} + +void CFessim::Init() +{ + initVariable(); + initView(); + initSignalAndSlot(); +} + +bool CFessim::isConnect() +{ + return m_isConnect; +} + +void CFessim::brushSomeData() +{ + slot_listClick(ui->listWidget->currentIndex()); +} + +int CFessim::getCurrentIndex() +{ + return ui->listWidget->currentIndex().row(); +} + +void CFessim::initVariable() +{ + m_appVec = CDataMng::instance()->getAppInfo(); + m_pFesParamShow = new CFesParamShow; + startThread(); +} + +void CFessim::initSignalAndSlot() +{ + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_connected,this,&CFessim::ConnectOk); + connect(&m_objMbCliMngThread,SIGNAL(signal_disconnected()),this,SLOT(DisConnectOk())); + + connect(ui->comboBox_app,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(slot_modifyPort(const QString &))); + connect(ui->pushButton_connect,&QPushButton::clicked,this,&CFessim::slot_connect); + connect(ui->stackedWidget,&QStackedWidget::currentChanged,this,&CFessim::setActiveWindow); + connect(ui->listWidget,&QListWidget::clicked,this,&CFessim::slot_listClick); + connect(ui->fes_chan_data,&QPushButton::clicked,this,&CFessim::slotChanData); +// connect(ui->iec61850_tool,&QPushButton::clicked,this,&CFessim::slotOpen61850Tool); + connect(CDataMng::instance(),&CDataMng::signal_sendMsgToServer,&m_objMbCliMngThread,&CMbClientMngThread::slot_sendMsg); +} + +void CFessim::initFesParamSS() +{ + connect(&m_objMbCliMngThread,SIGNAL(signal_connected()),m_pFesParamShow,SLOT(OnNetConnect())); + connect(&m_objMbCliMngThread,SIGNAL(signal_disconnected()),m_pFesParamShow,SLOT(OnNetDisConnect())); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_chanParamResp,CDataMng::instance(),&CDataMng::signal_chanParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_rtuParamResp,CDataMng::instance(),&CDataMng::signal_rtuParamResp); + + connect(this,&CFessim::sigFesParamShowActiveWindow,m_pFesParamShow,&CFesParamShow::slotActiveWindow); +} + +void CFessim::initFesDataSS() +{ + connect(&m_objMbCliMngThread,SIGNAL(signal_connected()),m_pFesData,SLOT(OnNetConnect())); + connect(&m_objMbCliMngThread,SIGNAL(signal_disconnected()),m_pFesData,SLOT(OnNetDisConnect())); + + //模拟量 + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_aiRtuInfoResp,CDataMng::instance(),&CDataMng::signal_aiRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_aiParamResp,CDataMng::instance(),&CDataMng::signal_aiParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_aiValueResp,CDataMng::instance(),&CDataMng::signal_aiValueResp); + + //数字量 + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_diRtuInfoResp,CDataMng::instance(),&CDataMng::signal_diRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_diParamResp,CDataMng::instance(),&CDataMng::signal_diParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_diValueResp,CDataMng::instance(),&CDataMng::signal_diValueResp); + + //累积量 + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_accRtuInfoResp,CDataMng::instance(),&CDataMng::signal_accRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_accParamResp,CDataMng::instance(),&CDataMng::signal_accParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_accValueResp,CDataMng::instance(),&CDataMng::signal_accValueResp); + + //混合量 + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_miRtuInfoResp,CDataMng::instance(),&CDataMng::signal_miRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_miParamResp,CDataMng::instance(),&CDataMng::signal_miParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_miValueResp,CDataMng::instance(),&CDataMng::signal_miValueResp); + + connect(this,&CFessim::sigFesDataActiveWindow,m_pFesData,&CFesData::slotActiveWindow); +} + +void CFessim::initFesEventSS() +{ + connect(&m_objMbCliMngThread,SIGNAL(signal_connected()),m_pFesEvent,SLOT(OnNetConnect())); + connect(&m_objMbCliMngThread,SIGNAL(signal_disconnected()),m_pFesEvent,SLOT(OnNetDisConnect())); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_soeEventResp,CDataMng::instance(),&CDataMng::signal_soeEventResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_chanEventResp,CDataMng::instance(),&CDataMng::signal_chanEventResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_soeMemEventResp,CDataMng::instance(),&CDataMng::signal_soeMemEventResp); + + connect(this,&CFessim::sigFesEventActiveWindow,m_pFesEvent,&CFesEvent::slotActiveWindow); +} + +void CFessim::initFesDataSimSS() +{ + connect(&m_objMbCliMngThread,SIGNAL(signal_connected()),m_pFesDataSim,SLOT(OnNetConnect())); + connect(&m_objMbCliMngThread,SIGNAL(signal_disconnected()),m_pFesDataSim,SLOT(OnNetDisConnect())); + + //模拟量 + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAiRtuInfoResp,CDataMng::instance(),&CDataMng::signal_simAiRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAiParamResp,CDataMng::instance(),&CDataMng::signal_simAiParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAiValueResp,CDataMng::instance(),&CDataMng::signal_simAiValueResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAiStartSimResp,CDataMng::instance(),&CDataMng::signal_simAiStartSimResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAiStopSimResp,CDataMng::instance(),&CDataMng::signal_simAiStopSimResp); + + //数字量 + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDiRtuInfoResp,CDataMng::instance(),&CDataMng::signal_simDiRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDiParamResp,CDataMng::instance(),&CDataMng::signal_simDiParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDiValueResp,CDataMng::instance(),&CDataMng::signal_simDiValueResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDiStartSimResp,CDataMng::instance(),&CDataMng::signal_simDiStartSimResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDiStopSimResp,CDataMng::instance(),&CDataMng::signal_simDiStopSimResp); + + //混合量 + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simMiRtuInfoResp,CDataMng::instance(),&CDataMng::signal_simMiRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simMiParamResp,CDataMng::instance(),&CDataMng::signal_simMiParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simMiValueResp,CDataMng::instance(),&CDataMng::signal_simMiValueResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simMiStartSimResp,CDataMng::instance(),&CDataMng::signal_simMiStartSimResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simMiStopSimResp,CDataMng::instance(),&CDataMng::signal_simMiStopSimResp); + + //累计量 + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAccRtuInfoResp,CDataMng::instance(),&CDataMng::signal_simAccRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAccParamResp,CDataMng::instance(),&CDataMng::signal_simAccParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAccValueResp,CDataMng::instance(),&CDataMng::signal_simAccValueResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAccStartSimResp,CDataMng::instance(),&CDataMng::signal_simAccStartSimResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAccStopSimResp,CDataMng::instance(),&CDataMng::signal_simAccStopSimResp); + + //事件 + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simEventRtuInfoResp,CDataMng::instance(),&CDataMng::signal_simEventRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simEventDiParamResp,CDataMng::instance(),&CDataMng::signal_simEventDiParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simEventCreateResp,CDataMng::instance(),&CDataMng::signal_simEventCreateResp); + + connect(this,&CFessim::sigFesDataSimActiveWindow,m_pFesDataSim,&CFesDataSim::slotActiveWindow); +} + +void CFessim::initFesCtrlSimSS() +{ + connect(&m_objMbCliMngThread,SIGNAL(signal_connected()),m_pFesCtrlSim,SLOT(OnNetConnect())); + connect(&m_objMbCliMngThread,SIGNAL(signal_disconnected()),m_pFesCtrlSim,SLOT(OnNetDisConnect())); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAoRtuInfoResp,CDataMng::instance(),&CDataMng::signal_simAoRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAoParamResp,CDataMng::instance(),&CDataMng::signal_simAoParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simAoControlResp,CDataMng::instance(),&CDataMng::signal_simAoControlResp); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDoRtuInfoResp,CDataMng::instance(),&CDataMng::signal_simDoRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDoParamResp,CDataMng::instance(),&CDataMng::signal_simDoParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDoControlResp,CDataMng::instance(),&CDataMng::signal_simDoControlResp); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simMoRtuInfoResp,CDataMng::instance(),&CDataMng::signal_simMoRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simMoParamResp,CDataMng::instance(),&CDataMng::signal_simMoParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simMoControlResp,CDataMng::instance(),&CDataMng::signal_simMoControlResp); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDefCmdRtuInfoResp,CDataMng::instance(),&CDataMng::signal_simDefCmdRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_simDefCmdControlResp,CDataMng::instance(),&CDataMng::signal_simDefCmdControlResp); + + connect(this,&CFessim::sigFesCtrlSimActiveWindow,m_pFesCtrlSim,&CFesCtrlSim::slotActiveWindow); +} + +void CFessim::initFesForwDataSS() +{ + connect(&m_objMbCliMngThread,SIGNAL(signal_connected()),m_pFesForwardData,SLOT(OnNetConnect())); + connect(&m_objMbCliMngThread,SIGNAL(signal_disconnected()),m_pFesForwardData,SLOT(OnNetDisConnect())); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwAiRtuInfoResp,CDataMng::instance(),&CDataMng::signal_fwAiRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwAiParamResp,CDataMng::instance(),&CDataMng::signal_fwAiParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwAiValueResp,CDataMng::instance(),&CDataMng::signal_fwAiValueResp); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwDiRtuInfoResp,CDataMng::instance(),&CDataMng::signal_fwDiRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwDiParamResp,CDataMng::instance(),&CDataMng::signal_fwDiParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwDiValueResp,CDataMng::instance(),&CDataMng::signal_fwDiValueResp); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwDDiRtuInfoResp,CDataMng::instance(),&CDataMng::signal_fwDDiRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwDDiParamResp,CDataMng::instance(),&CDataMng::signal_fwDDiParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwDDiValueResp,CDataMng::instance(),&CDataMng::signal_fwDDiValueResp); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwMiRtuInfoResp,CDataMng::instance(),&CDataMng::signal_fwMiRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwMiParamResp,CDataMng::instance(),&CDataMng::signal_fwMiParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwMiValueResp,CDataMng::instance(),&CDataMng::signal_fwMiValueResp); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwAccRtuInfoResp,CDataMng::instance(),&CDataMng::signal_fwAccRtuInfoResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwAccParamResp,CDataMng::instance(),&CDataMng::signal_fwAccParamResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_fwAccValueResp,CDataMng::instance(),&CDataMng::signal_fwAccValueResp); + + connect(this,&CFessim::sigFesForwardActiveWindow,m_pFesForwardData,&CFesForwardData::slotActiveWindow); +} + +void CFessim::initFesChanDataSS() +{ +// connect(&m_TcpClient,SIGNAL(NetConnected()),m_pFesChanData,SLOT(OnNetConnect())); +// connect(&m_TcpClient,SIGNAL(NetDisConnected()),m_pFesChanData,SLOT(OnNetDisConnect())); +// connect(m_pFesChanData->ptrChanMonDlg,SIGNAL(SendCmdSig(int,QByteArray,int )),ptrProtocolThread,SLOT(OnRecvCmd(int,QByteArray,int ))); +// connect(ptrProtocolThread,SIGNAL(ChanMonStartSig(int,QByteArray,int )),m_pFesChanData->ptrChanMonDlg,SLOT(OnRecvChanMonStartResp(int,QByteArray,int ))); +// connect(ptrProtocolThread,SIGNAL(ChanMonStopSig(int,QByteArray,int )),m_pFesChanData->ptrChanMonDlg,SLOT(OnRecvChanMonStopResp(int,QByteArray,int ))); +// connect(ptrProtocolThread,SIGNAL(ChanClearSig(int,QByteArray,int )),m_pFesChanData->ptrChanMonDlg,SLOT(OnRecvChanClearResp(int,QByteArray,int ))); +// connect(this,&CFessim::sigFesChanDataActiveWindow,m_pFesChanData,&CFesChanData::slotActiveWindow); +} + +void CFessim::initView() +{ + initLocalView(); + addFesParam(); + initFesParamSS(); +} + +void CFessim::initLocalView() +{ + if(ui->comboBox_app->count()==0) + { + if(m_appVec.size()<=0) + { + ui->comboBox_app->addItem("AppName"); + ui->lineEdit_port->setText(QString::number(CN_FesSimServerBasePortNo + 4)); + ui->lineEdit_ip->setText("127.0.0.1"); + } + else + { + ui->lineEdit_port->setText(QString::number(CN_FesSimServerBasePortNo + m_appVec[0].appId)); + int i; + for(i=0;icomboBox_app->addItem(m_appVec[i].appName); + } + } + } + + QFile file(CN_CFG_SIMIP); + if(file.exists()) + { + if(file.open(QFile::ReadOnly | QFile::Text)) + { + m_IpStr = file.readAll(); + file.close(); + } + } + else + { + if(m_IpStr.isEmpty()) + m_IpStr = "127.0.0.1"; + std::string tempStr = m_IpStr.toStdString(); + if(file.open(QFile::WriteOnly | QFile::Append)) + { + file.write(tempStr.c_str(),tempStr.length()); + file.close(); + } + } + ui->lineEdit_ip->setText(m_IpStr); +} + +void CFessim::addFesParam() +{ + QGridLayout *gridLayout = new QGridLayout(ui->frame_fesParam); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pFesParamShow, 0, 0, 1, 1); + m_pFesParamShow->Init(m_isConnect); + +} + +void CFessim::addFesData() +{ + QGridLayout *gridLayout = new QGridLayout(ui->frame_fesData); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pFesData, 0, 0, 1, 1); + m_pFesData->Init(m_isConnect); +} + +void CFessim::addFesEvent() +{ + QGridLayout *gridLayout = new QGridLayout(ui->frame_fesEvent); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pFesEvent, 0, 0, 1, 1); + m_pFesEvent->Init(m_isConnect); +} + +void CFessim::addFesDataSim() +{ + QGridLayout *gridLayout = new QGridLayout(ui->frame_fesDataSim); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pFesDataSim, 0, 0, 1, 1); + m_pFesDataSim->Init(m_isConnect); +} + +void CFessim::addFesCtrlSim() +{ + QGridLayout *gridLayout = new QGridLayout(ui->frame_fesCtrlSim); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pFesCtrlSim, 0, 0, 1, 1); + m_pFesCtrlSim->Init(m_isConnect); +} + +void CFessim::addFesForwardData() +{ + QGridLayout *gridLayout = new QGridLayout(ui->frame_fesForwardData); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pFesForwardData, 0, 0, 1, 1); + m_pFesForwardData->Init(m_isConnect); +} + +void CFessim::addFesChanData() +{ +// QGridLayout *gridLayout = new QGridLayout(ui->frame_fesChanData); +// gridLayout->setSpacing(6); +// gridLayout->setContentsMargins(0, 0, 0, 0); +// gridLayout->addWidget(m_pFesChanData, 0, 0, 1, 1); +// m_pFesChanData->Init(m_isConnect); +} + +void CFessim::setEnableView(bool enable) +{ + ui->comboBox_app->setEnabled(enable); + ui->lineEdit_port->setEnabled(enable); + ui->lineEdit_ip->setEnabled(enable); +} + +void CFessim::startThread() +{ +} + +void CFessim::stopThread() +{ + m_objMbCliMngThread.disconnectToServer(); +} + +void CFessim::slot_modifyPort(const QString &text) +{ + for(int i=0;ilineEdit_port->setText(QString::number(CN_FesSimServerBasePortNo + m_appVec[i].appId)); + break; + } + } +} + +bool CFessim::slot_connect() +{ + if(m_isConnect) + { + m_objMbCliMngThread.disconnectToServer(); + return true; + } + + //上面是断开连接操作,下面是连接操作 + bool ok; + int nPort = ui->lineEdit_port->text().toInt(&ok); + if(!ok) + { + N_MessageBox::warning(this,tr("警告"),tr("网络端口错误,无法连接网络")); + return false; + } + + m_IpStr = ui->lineEdit_ip->text(); + + if(!m_objMbCliMngThread.connectToServer(m_IpStr,nPort)) + { + return false; + } + + QFile file(CN_CFG_SIMIP); + if(file.exists()) + { + std::string tempStr = m_IpStr.toStdString(); + if(file.open(QFile::WriteOnly | QFile::Truncate)) + { + file.write(tempStr.c_str(),tempStr.length()); + file.close(); + } + } + + return true; +} + +void CFessim::ConnectOk() +{ + ui->stackedWidget->currentIndex(); + m_isConnect = true; + ui->pushButton_connect->setText(tr("断开")); + ui->label_netStatus->setText(tr("通讯连接")); + ui->label_netStatus->setStyleSheet("QLabel{color:green}"); + setEnableView(false); +} + +void CFessim::DisConnectOk() +{ + if(m_objMbCliMngThread.isRunning()) + { + m_objMbCliMngThread.requestInterruption(); + m_objMbCliMngThread.quit(); + m_objMbCliMngThread.wait(); + } + + m_isConnect = false; + ui->pushButton_connect->setText(tr("连接")); + ui->label_netStatus->setText(tr("通讯断开")); + ui->label_netStatus->setStyleSheet("QLabel{color:red}"); + setEnableView(true); +} + +void CFessim::setActiveWindow(int current) +{ + switch (current) { + case 0: + { + if(m_pFesParamShow == NULL) + { + m_pFesParamShow = new CFesParamShow; + addFesParam(); + initFesParamSS(); + } + emit sigFesParamShowActiveWindow(); + break; + } + case 1: + { + if(m_pFesData == NULL) + { + m_pFesData = new CFesData; + addFesData(); + initFesDataSS(); + } + emit sigFesDataActiveWindow(); + break; + } + case 2: + { + if(m_pFesDataSim == NULL) + { + m_pFesDataSim = new CFesDataSim; + addFesDataSim(); + initFesDataSimSS(); + } + emit sigFesDataSimActiveWindow(); + break; + } + case 3: + { + if(m_pFesCtrlSim == NULL) + { + m_pFesCtrlSim = new CFesCtrlSim; + addFesCtrlSim(); + initFesCtrlSimSS(); + } + emit sigFesCtrlSimActiveWindow(); + break; + } + case 4: + { + if(m_pFesEvent == NULL) + { + m_pFesEvent = new CFesEvent; + addFesEvent(); + initFesEventSS(); + } + emit sigFesEventActiveWindow(); + break; + } + case 5: + { + if(m_pFesForwardData == NULL) + { + m_pFesForwardData = new CFesForwardData; + addFesForwardData(); + initFesForwDataSS(); + } + emit sigFesForwardActiveWindow(); + break; + } +// case 6: +// { +// if(m_pFesChanData == NULL) +// { +// m_pFesChanData = new CFesChanData; +// addFesChanData(); +// initFesChanDataSS(); +// } +// emit sigFesChanDataActiveWindow(); +// break; +// } + default: + break; + } +} + +void CFessim::slot_listClick(const QModelIndex &index) +{ + if(!index.isValid()) + { + return ; + }else + { + ui->stackedWidget->setCurrentIndex(index.row()); + //setActiveWindow(5); + } +} + +void CFessim::slotChanData() +{ + if(m_pChanMonDlg != NULL) + { + m_pChanMonDlg->show(); + } + else if(m_pChanMonDlg == NULL) + { + m_pChanMonDlg = new ChanMonDlg((int)E_ACTIVE_WINDOW_FES_CHAN_DATA,this); + if(m_pChanMonDlg==NULL) + { + return; + } + + connect(m_pChanMonDlg,&ChanMonDlg::signal_sendMsg,&m_objMbCliMngThread,&CMbClientMngThread::slot_sendMsg); + m_pChanMonDlg->SetConnectFlags(m_isConnect); //放在关联signal_sendMsg信号后 + connect(&m_objMbCliMngThread,SIGNAL(signal_connected()),m_pChanMonDlg,SLOT(OnNetConnect())); + connect(&m_objMbCliMngThread,SIGNAL(signal_disconnected()),m_pChanMonDlg,SLOT(OnNetDisConnect())); + + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_chanParamResp,m_pChanMonDlg,&ChanMonDlg::slot_OnRecvResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_chanMonStartResp,m_pChanMonDlg,&ChanMonDlg::slot_OnRecvResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_chanMonStopResp,m_pChanMonDlg,&ChanMonDlg::slot_OnRecvResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_chanMonClearResp,m_pChanMonDlg,&ChanMonDlg::slot_OnRecvResp); + connect(&m_objMbCliMngThread,&CMbClientMngThread::signal_chanMonInfo,m_pChanMonDlg,&ChanMonDlg::slot_OnRecvResp); + connect(m_pChanMonDlg, &ChanMonDlg::closed, [=](){ m_pChanMonDlg = Q_NULLPTR;}); + + m_pChanMonDlg->show(); + } +} + +void CFessim::slotOpen61850Tool() +{ +#ifdef Q_OS_WIN + QProcess p; + p.startDetached("clientScout.exe"); +#else + QProcess p; + p.startDetached("clientScout"); +#endif +} diff --git a/product/src/tools/debug_tool_v2/CFessim.h b/product/src/tools/debug_tool_v2/CFessim.h new file mode 100644 index 00000000..22b14bbd --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFessim.h @@ -0,0 +1,110 @@ +#ifndef CFESSIM_H +#define CFESSIM_H + +#include +#include "CSystemResources.h" +#include "ComProtocolThread.h" +#include "CFesData.h" +#include "CFesParamShow.h" +#include "CFesEvent.h" +#include "CFesDataSim.h" +#include "CFesCtrlSim.h" +#include "CFesForwardData.h" +#include "CFesChanData.h" +#include "MbClientMngThread.h" + +namespace Ui { +class CFessim; +} + +class CFessim : public QWidget +{ + Q_OBJECT + +public: + explicit CFessim(QWidget *parent = 0); + ~CFessim(); + void Init(); + void loadChan(); + void loadDev(); + void loadAiDesc(); + void loadDiDesc(); + void loadPiDesc(); + void loadMiDesc(); + void loadAoDesc(); + void loadDoDesc(); + void loadMoDesc(); + + bool isConnect(); + + void brushSomeData(); + + int getCurrentIndex(); + +signals: + void sigFesParamShowActiveWindow(); + void sigFesDataActiveWindow(); + void sigFesEventActiveWindow(); + void sigFesDataSimActiveWindow(); + void sigFesCtrlSimActiveWindow(); + void sigFesForwardActiveWindow(); + void sigFesChanDataActiveWindow(); +private: + void initVariable(); + void initSignalAndSlot(); + void initFesParamSS();//SS-----信号槽 + void initFesDataSS();//SS-----信号槽 + void initFesEventSS();//SS-----信号槽 + void initFesDataSimSS();//SS-----信号槽 + void initFesCtrlSimSS();//SS-----信号槽 + void initFesForwDataSS();//SS-----信号槽 + void initFesChanDataSS();//SS-----信号槽 + + void initView(); + void initLocalView(); + + void addFesParam(); + void addFesData(); + void addFesEvent(); + void addFesDataSim(); + void addFesCtrlSim(); + void addFesForwardData(); + void addFesChanData(); + + void setEnableView(bool enable); + + void startThread(); + void stopThread(); + +public slots: + void slot_modifyPort(const QString &text); + void ConnectOk(); + void DisConnectOk(); + void setActiveWindow(int current); + void slot_listClick(const QModelIndex &index); + + void slotChanData(); + void slotOpen61850Tool(); + +public slots: + bool slot_connect(); + +private: + Ui::CFessim *ui; + + QVector m_appVec; + QString m_IpStr; + bool m_isConnect; + CFesParamShow * m_pFesParamShow; + CFesData * m_pFesData; + CFesEvent * m_pFesEvent; + CFesDataSim * m_pFesDataSim; + CFesCtrlSim * m_pFesCtrlSim; + CFesForwardData * m_pFesForwardData; + //CFesChanData * m_pFesChanData; + + ChanMonDlg *m_pChanMonDlg; + CMbClientMngThread m_objMbCliMngThread; +}; + +#endif // CFESSIM_H diff --git a/product/src/tools/debug_tool_v2/CFessim.ui b/product/src/tools/debug_tool_v2/CFessim.ui new file mode 100644 index 00000000..990179a6 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CFessim.ui @@ -0,0 +1,609 @@ + + + CFessim + + + + 0 + 0 + 855 + 373 + + + + Form + + + + 0 + + + 9 + + + 0 + + + 1 + + + 0 + + + 6 + + + + + + 102 + 16777215 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 1 + + + 0 + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + -1 + + + + 通讯状态 + + + + 9 + + + + AlignCenter + + + + + 前置数据 + + + + 9 + + + + AlignCenter + + + + + 数据仿真 + + + + 9 + + + + AlignCenter + + + + + 控制仿真 + + + + 9 + + + + AlignCenter + + + + + 事件监视 + + + + 9 + + + + AlignCenter + + + + + 转发数据 + + + + 9 + + + + AlignCenter + + + + + + + + + 9 + + + + 通道报文 + + + + + + + + 9 + + + + 61850工具 + + + + + + + + + + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 10 + + + 0 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 专业名称 + + + + + + + + 100 + 23 + + + + QComboBox::AdjustToContents + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + IP地址 + + + + + + + + 0 + 23 + + + + + 100 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 网络端口 + + + + + + + + 0 + 23 + + + + + 100 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 连接/断开 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 通讯状态: + + + + + + + + 100 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CHistoryEvent.ui b/product/src/tools/debug_tool_v2/CHistoryEvent.ui new file mode 100644 index 00000000..379e5991 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CHistoryEvent.ui @@ -0,0 +1,100 @@ + + + CHistoryEvent + + + + 0 + 0 + 401 + 239 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + + + + + + 查询 + + + + + + + 打印 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 事件条数 + + + + + + + + 0 + 0 + + + + + 50 + 16777215 + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CMyCalendar.cpp b/product/src/tools/debug_tool_v2/CMyCalendar.cpp new file mode 100644 index 00000000..cb3001f7 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CMyCalendar.cpp @@ -0,0 +1,93 @@ +#include "CMyCalendar.h" +#include "ui_CMyCalendar.h" +#include +#include "pub_widget/MessageBox.h" +#include + +CMyCalendar::CMyCalendar(QWidget *parent) : + QWidget(parent), + ui(new Ui::CMyCalendar) +{ + ui->setupUi(this); + connect(ui->calendarWidget,SIGNAL(clicked(QDate)),this,SLOT(slot_startTime(QDate))); + connect(ui->calendarWidget_2,SIGNAL(clicked(QDate)),this,SLOT(slot_endTime(QDate))); + connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(slot_cancle())); + m_startTime = QDate::currentDate(); + m_endTime = QDate::currentDate(); + ui->lineEdit->setText(m_startTime.toString("yyyy-MM-dd")); + ui->lineEdit_2->setText(m_endTime.toString("yyyy-MM-dd")); + ui->lineEdit->setReadOnly(true); + ui->lineEdit_2->setReadOnly(true); +} + +CMyCalendar::~CMyCalendar() +{ + delete ui; +} + +void CMyCalendar::setView(E_ALARM_VIEW view) +{ + m_view = view; + if(m_view == E_ALARM_HIS_EVENT) + { + ui->pushButton->setEnabled(false); + }else + { + ui->pushButton->setEnabled(true); + } +} + +void CMyCalendar::keyPressEvent(QKeyEvent *event) +{ + if(event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) + { + return ; + } + QWidget::keyPressEvent(event); +} + +void CMyCalendar::slot_endTime(QDate date) +{ + ui->lineEdit_2->setText(date.toString("yyyy-MM-dd")); + m_endTime = date; + if(m_startTime.isNull() ) + { + return; + } + if(m_endTime < m_startTime) + { + return ; + } + if(m_view == E_ALARM_HIS_EVENT) + { + QTime time_1(0,0,0); + QTime time_2(23,59,59); + QDateTime startTime; + QDateTime endTime; + startTime.setDate(m_startTime); + startTime.setTime(time_1); + + endTime.setDate(m_endTime); + endTime.setTime(time_2); + if((endTime.toMSecsSinceEpoch()-startTime.toMSecsSinceEpoch())/1000/3600/24 >= 90 ) + { + return; + } + } + emit sig_endTimeClick(m_startTime,m_endTime); +} + +void CMyCalendar::slot_startTime(QDate date) +{ + m_startTime = date; + ui->lineEdit->setText(date.toString("yyyy-MM-dd")); +} + +void CMyCalendar::slot_cancle() +{ + if(m_view == E_ALARM_HIS_EVENT) + { + return; + } + emit sig_cancle(); +} diff --git a/product/src/tools/debug_tool_v2/CMyCalendar.h b/product/src/tools/debug_tool_v2/CMyCalendar.h new file mode 100644 index 00000000..44625bbf --- /dev/null +++ b/product/src/tools/debug_tool_v2/CMyCalendar.h @@ -0,0 +1,38 @@ +#ifndef CMYCALENDAR_H +#define CMYCALENDAR_H + +#include +#include +#include +#include "CEventMsgInfo.h" + +namespace Ui { +class CMyCalendar; +} + +class CMyCalendar : public QWidget +{ + Q_OBJECT +signals: + void sig_endTimeClick(QDate startDate,QDate endDate); + void sig_startTimeClick(QDate date); + void sig_cancle(); +public: + explicit CMyCalendar(QWidget *parent = 0); + ~CMyCalendar(); + void setView(E_ALARM_VIEW view); +protected: + void keyPressEvent(QKeyEvent *event); + +public slots: + void slot_endTime(QDate date); + void slot_startTime(QDate date); + void slot_cancle(); +private: + Ui::CMyCalendar *ui; + QDate m_startTime; + QDate m_endTime; + E_ALARM_VIEW m_view; +}; + +#endif // CMYCALENDAR_H diff --git a/product/src/tools/debug_tool_v2/CMyCalendar.ui b/product/src/tools/debug_tool_v2/CMyCalendar.ui new file mode 100644 index 00000000..98fb3b2c --- /dev/null +++ b/product/src/tools/debug_tool_v2/CMyCalendar.ui @@ -0,0 +1,119 @@ + + + CMyCalendar + + + + 0 + 0 + 538 + 264 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + 0 + + + + + + + + + 20 + 0 + + + + + + + Qt::AlignCenter + + + + + + + + + + 取消 + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CMyCheckBox.cpp b/product/src/tools/debug_tool_v2/CMyCheckBox.cpp new file mode 100644 index 00000000..09398cd4 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CMyCheckBox.cpp @@ -0,0 +1,22 @@ +#include "CMyCheckBox.h" +#include + +CMyCheckBox::CMyCheckBox(QString text, QWidget *parent) + :QCheckBox(text,parent) +{ + +} + +CMyCheckBox::CMyCheckBox(QWidget *parent) + :QCheckBox(parent) +{ + +} + +void CMyCheckBox::mouseReleaseEvent(QMouseEvent *e) +{ + Q_UNUSED(e); + setChecked(!isChecked()); + emit clicked(isChecked()); + +} diff --git a/product/src/tools/debug_tool_v2/CMyCheckBox.h b/product/src/tools/debug_tool_v2/CMyCheckBox.h new file mode 100644 index 00000000..1dad82e3 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CMyCheckBox.h @@ -0,0 +1,16 @@ +#ifndef MYCHECKBOX_H +#define MYCHECKBOX_H + +#include + +class CMyCheckBox : public QCheckBox +{ +public: + CMyCheckBox(QString text,QWidget *parent = Q_NULLPTR); + CMyCheckBox(QWidget *parent = Q_NULLPTR); + +protected: + void mouseReleaseEvent(QMouseEvent *e); +}; + +#endif // MYCHECKBOX_H diff --git a/product/src/tools/debug_tool_v2/CMyListWidget.cpp b/product/src/tools/debug_tool_v2/CMyListWidget.cpp new file mode 100644 index 00000000..fa73a493 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CMyListWidget.cpp @@ -0,0 +1,12 @@ +#include "CMyListWidget.h" + +CMyListWidget::CMyListWidget(QWidget *parent):QListWidget(parent) +{ + +} + +void CMyListWidget::showEvent(QShowEvent *event) +{ + this->updateGeometries(); + QListWidget::showEvent(event); +} diff --git a/product/src/tools/debug_tool_v2/CMyListWidget.h b/product/src/tools/debug_tool_v2/CMyListWidget.h new file mode 100644 index 00000000..728f308d --- /dev/null +++ b/product/src/tools/debug_tool_v2/CMyListWidget.h @@ -0,0 +1,15 @@ +#ifndef CMYLISTWIDGET_H +#define CMYLISTWIDGET_H + +#include + +class CMyListWidget : public QListWidget +{ +public: + explicit CMyListWidget(QWidget *parent = 0); + +protected: + void showEvent(QShowEvent *event); +}; + +#endif // CMYLISTWIDGET_H diff --git a/product/src/tools/debug_tool_v2/CNodeStatus.cpp b/product/src/tools/debug_tool_v2/CNodeStatus.cpp new file mode 100644 index 00000000..f4bcb9df --- /dev/null +++ b/product/src/tools/debug_tool_v2/CNodeStatus.cpp @@ -0,0 +1,14 @@ +#include "CNodeStatus.h" +#include "ui_CNodeStatus.h" + +CNodeStatus::CNodeStatus(QWidget *parent) : + QWidget(parent), + ui(new Ui::CNodeStatus) +{ + ui->setupUi(this); +} + +CNodeStatus::~CNodeStatus() +{ + delete ui; +} diff --git a/product/src/tools/debug_tool_v2/CNodeStatus.h b/product/src/tools/debug_tool_v2/CNodeStatus.h new file mode 100644 index 00000000..2d1add15 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CNodeStatus.h @@ -0,0 +1,22 @@ +#ifndef CNODESTATUS_H +#define CNODESTATUS_H + +#include + +namespace Ui { +class CNodeStatus; +} + +class CNodeStatus : public QWidget +{ + Q_OBJECT + +public: + explicit CNodeStatus(QWidget *parent = 0); + ~CNodeStatus(); + +private: + Ui::CNodeStatus *ui; +}; + +#endif // CNODESTATUS_H diff --git a/product/src/tools/debug_tool_v2/CNodeStatus.ui b/product/src/tools/debug_tool_v2/CNodeStatus.ui new file mode 100644 index 00000000..c585f65a --- /dev/null +++ b/product/src/tools/debug_tool_v2/CNodeStatus.ui @@ -0,0 +1,134 @@ + + + CNodeStatus + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + 关键字 + + + + + + + + 100 + 0 + + + + + + + + + 100 + 0 + + + + + + + + 查找 + + + + + + + 刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 200 + 16777215 + + + + + + + + + + + + + + + + + + 全部选中 + + + + + + + 全部取消 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CRdbWorker.cpp b/product/src/tools/debug_tool_v2/CRdbWorker.cpp new file mode 100644 index 00000000..eb9fd1db --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRdbWorker.cpp @@ -0,0 +1,40 @@ +#include "CRdbWorker.h" +#include "pub_logger_api/logger.h" +#include +CRdbWorker::CRdbWorker() +{ + m_pNetRdbApi = new iot_dbms::CRdbNetApi(); +} + +CRdbWorker::~CRdbWorker() +{ + if(m_pNetRdbApi) + { + delete m_pNetRdbApi; + + } + m_pNetRdbApi = NULL; +} + +void CRdbWorker::search(int domainId, int appid, iot_idl::RdbQuery msgQuery, QString tableName, int searchWays) +{ + iot_idl::RdbRet retMsg; + bool isSuccess = false; + if(m_pNetRdbApi) + { + m_pNetRdbApi->connect(domainId,appid); + if(m_pNetRdbApi->query(msgQuery,retMsg)) + { + isSuccess = true; + } + + } + + if(searchWays == 0) + { + emit sigAutoSearch(isSuccess,retMsg,tableName); + }else + { + emit sigNotAutoSearch(isSuccess,retMsg,tableName); + } +} diff --git a/product/src/tools/debug_tool_v2/CRdbWorker.h b/product/src/tools/debug_tool_v2/CRdbWorker.h new file mode 100644 index 00000000..9959ec9c --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRdbWorker.h @@ -0,0 +1,22 @@ +#ifndef CRDBWORKER_H +#define CRDBWORKER_H + +#include +#include "rdb_net_api/CRdbNetApi.h" +#include "rdb_api/CRdbAccessEx.h" +class CRdbWorker : public QObject +{ + Q_OBJECT +public: + CRdbWorker(); + ~CRdbWorker(); +signals: + void sigAutoSearch(bool isSuccess,iot_idl::RdbRet rdbRet,QString tableName); + void sigNotAutoSearch(bool isSuccess,iot_idl::RdbRet rdbRet,QString tableName); +public slots: + void search(int domainId, int appid, iot_idl::RdbQuery msgQuery,QString tableName,int searchWays); +private: + iot_dbms::CRdbNetApi *m_pNetRdbApi; //网络实时数据库接口指针 +}; + +#endif // CRDBWORKER_H diff --git a/product/src/tools/debug_tool_v2/CRealAlarm.ui b/product/src/tools/debug_tool_v2/CRealAlarm.ui new file mode 100644 index 00000000..a5dfaff0 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealAlarm.ui @@ -0,0 +1,249 @@ + + + CRealAlarm + + + + 0 + 0 + 829 + 350 + + + + Form + + + + + + + + + + 全部确认 + + + + + + + 当前页确认 + + + + + + + 所选确认 + + + + + + + 取消选择 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 刷新 + + + + + + + 停止刷新 + + + + + + + + 75 + 16777215 + + + + 选中条数 + + + + + + + + 50 + 16777215 + + + + + + + + + 90 + 16777215 + + + + 总报警条数 + + + + + + + + 50 + 16777215 + + + + + + + + + 75 + 16777215 + + + + 未确认条数 + + + + + + + + 50 + 16777215 + + + + + + + + + + + + + + + 级别排序 + + + + + + + 滚动刷新 + + + + + + + 状态筛选 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + + 0 + 0 + + + + + 100 + 16777215 + + + + 当前报警条数 + + + + + + + + 50 + 16777215 + + + + + + + + + 60 + 16777215 + + + + 选中条数 + + + + + + + + 50 + 16777215 + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CRealDataControl.cpp b/product/src/tools/debug_tool_v2/CRealDataControl.cpp new file mode 100644 index 00000000..3bd5fad5 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDataControl.cpp @@ -0,0 +1,1221 @@ +#include "CRealDataControl.h" +#include "ui_CRealDataControl.h" +#include "pub_utility_api/TimeUtil.h" +#include "CommonSheet.h" +CRealDataControl::CRealDataControl(int locationId,int subSystemId,QString pointName,QString tagName,QString tableName,CSystemResources *pSystemResources,bool isCtrl,QWidget *parent) : + CustomUiDialog(parent,true), + ui(new Ui::CRealDataControl) +{ + ui->setupUi(this); + m_pTimer = new QTimer(this); + m_isCtrl = isCtrl; + initSingalSlot(); + initControl(locationId,subSystemId,pointName,tagName,tableName,pSystemResources); + + ui->comboBox_cmdType->setView(new QListView()); + ui->comboBox_ctrlValue->setView(new QListView()); + ui->comboBox_otherArgs->setView(new QListView()); + + setAutoLayout(true); +} + + + +CRealDataControl::~CRealDataControl() +{ + + m_pSendComm->delSub(0,CH_HMI_TO_OPT_OPTCMD_DOWN); + delete m_pSendComm; + m_pSendComm = nullptr; + + m_pReceiveComm->delSub(0,CH_HMI_TO_OPT_OPTCMD_DOWN); + delete m_pReceiveComm; + m_pReceiveComm = nullptr; + delete ui; +} + + + +void CRealDataControl::initControl(int locationId,int subSystemId,QString pointName,QString tagName,QString tableName,CSystemResources *pSystemResources) +{ + initVariable(locationId,subSystemId,pointName,tagName,tableName,pSystemResources); + initView(); + +} + +void CRealDataControl::initVariable(int locationId,int subSystemId,QString pointName,QString tagName,QString tableName,CSystemResources *pSystemResources) +{ + + m_pSystemResources = pSystemResources; + m_nDestLocationId = locationId; + m_strPointName = pointName; + m_strPointTagName = tagName; + m_strTableName = tableName; + m_nDestSubSystemId = subSystemId; + m_pSystemResources->getAppInfoBySubSystemId(m_nDestSubSystemId,m_stAppInfo); + m_pDbInterface = m_pSystemResources->getDbInterface(); + + + m_strSrcTag = m_pSystemResources->getStrSrcTag(); + m_nSrcDomainId = m_pSystemResources->getSrcDomainId(); + m_nAppId = m_pSystemResources->getAppId(); + m_strHostName = m_pSystemResources->getHostName(); + m_strInstName = m_pSystemResources->getInstName(); + m_strCommName = m_pSystemResources->getCommName(); + m_nPermUserId = m_pSystemResources->getPermUserId(); + m_nPermUserGroupId = m_pSystemResources->getPermUserGroupId(); + + m_pSendComm = new iot_net::CMbCommunicator((m_strPointName+"_Sender").toStdString().c_str()); + m_pSendComm->addSub(0,CH_HMI_TO_OPT_OPTCMD_DOWN); + + m_pReceiveComm = new iot_net::CMbCommunicator((m_strPointName+"_Receiver").toStdString().c_str()); + m_pReceiveComm->addSub(0,CH_OPT_TO_HMI_OPTCMD_UP); + + + m_timeOutTimes = 0; + + m_aiLimitOtherArgs.push_back("LIMIT_UP1"); + m_aiLimitOtherArgs.push_back("LIMIT_UP2"); + m_aiLimitOtherArgs.push_back("LIMIT_UP3"); + m_aiLimitOtherArgs.push_back("LIMIT_LOW1"); + m_aiLimitOtherArgs.push_back("LIMIT_LOW2"); + m_aiLimitOtherArgs.push_back("LIMIT_LOW3"); + +} + +void CRealDataControl::initView() +{ + ui->lineEdit->setReadOnly(true); + ui->lineEdit->setText(m_strPointName); + if(QString("ANALOG") == m_strTableName) + { + addAiCmd(); + } + else if(QString("DIGITAL") == m_strTableName) + { + addDiCmd(); + } + else if(QString("MIX") == m_strTableName) + { + addMiCmd(); + } + else if(QString("ACCUML") == m_strTableName) + { + addPiCmd(); + } + else if(QString("CONST") == m_strTableName) + { + addConstCmd(); + } + else + { + ui->comboBox_cmdType->clear(); + } +} + + + +void CRealDataControl::initCmdTypeComBox() +{ + // ui->comboBox_cmdType->addItem(); +} + + + +void CRealDataControl::initSingalSlot() +{ + connect(ui->pushButton_exe,SIGNAL(clicked()), + this,SLOT(slot_exeCmd())); + connect(ui->comboBox_cmdType,SIGNAL(currentIndexChanged(int)), + this,SLOT(slot_updateOtherArgs(int))); + connect(m_pTimer,SIGNAL(timeout()), + this,SLOT(slot_timeOutReciceMsg())); + connect(ui->pushButton_exeStatus,SIGNAL(clicked()), + this,SLOT(slot_exeStatus())); +} + +void CRealDataControl::addAiCmd() +{ + ui->comboBox_cmdType->clear(); + ui->comboBox_cmdType->addItem(tr("设置AI限值"),MT_OPT_AI_LIMIT_SET_DOWN); + ui->comboBox_cmdType->addItem(tr("服务点禁止刷新报文"),MT_OPT_PINHIBIT_REF); + ui->comboBox_cmdType->addItem(tr("服务点禁止告警报文"),MT_OPT_PINHIBIT_ALARM); + //ui->comboBox_cmdType->addItem("服务点禁止控制报文",MT_OPT_PINHIBIT_CTRL); 屏蔽此功能 + ui->comboBox_cmdType->addItem(tr("人工置数报文"),MT_OPT_TAG_VALUE_SET); + if(m_isCtrl == true) + { + ui->comboBox_cmdType->addItem(tr("遥控请求"),MT_OPT_CTRL_DOWN_REQUEST); + ui->comboBox_cmdType->addItem(tr("遥控选择"),MT_OPT_CTRL_DOWN_SELECT); + ui->comboBox_cmdType->addItem(tr("遥控执行"),MT_OPT_CTRL_DOWN_EXECUTE); + ui->comboBox_cmdType->addItem(tr("遥控取消"),MT_OPT_CTRL_DOWN_CANCEL); + ui->comboBox_cmdType->addItem(tr("遥控关闭"),MT_OPT_CTRL_DOWN_CLOSE); + } + +// ui->comboBox_cmdType->addItem("自定义控制报文",MT_OPT_COMMON_DOWN); +} + +void CRealDataControl::addDiCmd() +{ + ui->comboBox_cmdType->clear(); + ui->comboBox_cmdType->addItem(tr("服务点禁止刷新报文"),MT_OPT_PINHIBIT_REF); + ui->comboBox_cmdType->addItem(tr("服务点禁止告警报文"),MT_OPT_PINHIBIT_ALARM); + //ui->comboBox_cmdType->addItem("服务点禁止控制报文",MT_OPT_PINHIBIT_CTRL); 屏蔽此功能 + ui->comboBox_cmdType->addItem(tr("人工置数报文"),MT_OPT_TAG_VALUE_SET); + if(m_isCtrl == true) + { + ui->comboBox_cmdType->addItem(tr("遥控请求"),MT_OPT_CTRL_DOWN_REQUEST); + ui->comboBox_cmdType->addItem(tr("遥控选择"),MT_OPT_CTRL_DOWN_SELECT); + ui->comboBox_cmdType->addItem(tr("遥控执行"),MT_OPT_CTRL_DOWN_EXECUTE); + ui->comboBox_cmdType->addItem(tr("遥控取消"),MT_OPT_CTRL_DOWN_CANCEL); + ui->comboBox_cmdType->addItem(tr("遥控关闭"),MT_OPT_CTRL_DOWN_CLOSE); + } + +// ui->comboBox_cmdType->addItem("自定义控制报文",MT_OPT_COMMON_DOWN); +} + +void CRealDataControl::addMiCmd() +{ + ui->comboBox_cmdType->clear(); + ui->comboBox_cmdType->addItem(tr("服务点禁止刷新报文"),MT_OPT_PINHIBIT_REF); + ui->comboBox_cmdType->addItem(tr("服务点禁止告警报文"),MT_OPT_PINHIBIT_ALARM); + //ui->comboBox_cmdType->addItem("服务点禁止控制报文",MT_OPT_PINHIBIT_CTRL); 屏蔽此功能 + ui->comboBox_cmdType->addItem(tr("人工置数报文"),MT_OPT_TAG_VALUE_SET); + if(m_isCtrl == true) + { + ui->comboBox_cmdType->addItem(tr("遥控请求"),MT_OPT_CTRL_DOWN_REQUEST); + ui->comboBox_cmdType->addItem(tr("遥控选择"),MT_OPT_CTRL_DOWN_SELECT); + ui->comboBox_cmdType->addItem(tr("遥控执行"),MT_OPT_CTRL_DOWN_EXECUTE); + ui->comboBox_cmdType->addItem(tr("遥控取消"),MT_OPT_CTRL_DOWN_CANCEL); + ui->comboBox_cmdType->addItem(tr("遥控关闭"),MT_OPT_CTRL_DOWN_CLOSE); + } + +// ui->comboBox_cmdType->addItem("自定义控制报文",MT_OPT_COMMON_DOWN); +} + +void CRealDataControl::addPiCmd() +{ + ui->comboBox_cmdType->clear(); + ui->comboBox_cmdType->addItem(tr("服务点禁止刷新报文"),MT_OPT_PINHIBIT_REF); + ui->comboBox_cmdType->addItem(tr("人工置数报文"),MT_OPT_TAG_VALUE_SET); +// ui->comboBox_cmdType->addItem("自定义控制报文",MT_OPT_COMMON_DOWN); +} + +void CRealDataControl::addConstCmd() +{ + ui->comboBox_cmdType->clear(); +// ui->comboBox_cmdType->addItem("自定义控制报文",MT_OPT_COMMON_DOWN); +} +/* +* 获取 报文头 +*/ +void CRealDataControl::getHead(SOptReqHead &head) +{ + head.strSrcTag = m_strSrcTag.toStdString(); + head.nSrcDomainID = m_nSrcDomainId; + head.nDstDomainID = m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId); + head.nAppID = m_nAppId; + head.strHostName = m_strHostName.toStdString(); + head.strInstName = m_strInstName.toStdString(); + head.strCommName = m_pSendComm->getName(); + head.nUserID = m_nPermUserId; + head.nUserGroupID = m_nPermUserGroupId; + head.nOptTime = iot_public::getUTCTimeMsec(); + //qDebug()<comboBox_otherArgs->currentText(); + QString tagName = m_strPointTagName; + aiLimitQueue.strKeyIdTag = (tableName+"."+tagName+"."+columnName).toStdString(); + bool ok = false; + float value = ui->lineEdit_ctrlValue->text().trimmed().toFloat(&ok); + if(!ok) + { + N_MessageBox::about(this,tr("提示"),tr("请输入正确的数值")); + return; + } + aiLimitQueue.fValue = value; + strAiLimitSet.stHead = head; + strAiLimitSet.vecAiLimitQueue.push_back(aiLimitQueue); + std::string jsonObj = CAiLimitSet::generate(strAiLimitSet); + + int msgType = ui->comboBox_cmdType->currentData().toInt(); + iot_net::CMbMessage msg = iot_net::CMbMessage(jsonObj,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send SetAiLimit Failed!" <comboBox_otherArgs->currentData().toInt(); + optTagQueue.fSetValue = 1; + optTagQueue.strStateText = ""; + optTagQueue.bIsPointQuery = false; + optTagQueue.nLocationId = m_nDestLocationId; + optTagQueue.nSubSystem = m_nDestSubSystemId; + optTagSet.vecTagQueue.push_back(optTagQueue); + int msgType = ui->comboBox_cmdType->currentData().toInt(); + std::string jsonObj = COptTagSet::generate(optTagSet); + iot_net::CMbMessage msg = iot_net::CMbMessage(jsonObj,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send InhibitRef Failed!" <comboBox_otherArgs->currentData().toInt(); + optTagQueue.fSetValue = 1; + optTagQueue.strStateText = ""; + optTagQueue.bIsPointQuery = false; + optTagQueue.nLocationId = m_nDestLocationId; + optTagQueue.nSubSystem = m_nDestSubSystemId; + optTagSet.vecTagQueue.push_back(optTagQueue); + + int msgType = ui->comboBox_cmdType->currentData().toInt(); + std::string jsonObj = COptTagSet::generate(optTagSet); + iot_net::CMbMessage msg = iot_net::CMbMessage(jsonObj,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send InhibitAlarm Failed!" <comboBox_otherArgs->currentData().toInt(); + optTagQueue.fSetValue = 1; + optTagQueue.strStateText = ""; + optTagQueue.bIsPointQuery = false; + optTagQueue.nLocationId = m_nDestLocationId; + optTagQueue.nSubSystem = m_nDestSubSystemId; + optTagSet.vecTagQueue.push_back(optTagQueue); + + int msgType = ui->comboBox_cmdType->currentData().toInt(); + std::string jsonObj = COptTagSet::generate(optTagSet); + iot_net::CMbMessage msg = iot_net::CMbMessage(jsonObj,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send InhibitCtrl Failed!" <comboBox_otherArgs->currentData().toInt(); + bool ok = false; + float value = ui->lineEdit_ctrlValue->text().trimmed().toFloat(&ok); + if(optTagQueue.nIsSet == 1 &&!ok) + { + N_MessageBox::about(this,tr("提示"),tr("请输入正确的数值")); + return; + } + optTagQueue.fSetValue = (double)value; + optTagQueue.strStateText = ""; + optTagQueue.bIsPointQuery = false; + optTagQueue.nLocationId = m_nDestLocationId; + optTagQueue.nSubSystem = m_nDestSubSystemId; + optTagSet.vecTagQueue.push_back(optTagQueue); + + int msgType = ui->comboBox_cmdType->currentData().toInt(); + std::string jsonObj = COptTagSet::generate(optTagSet); + iot_net::CMbMessage msg = iot_net::CMbMessage(jsonObj,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send SetValue Failed!" <comboBox_otherArgs->currentData().toBool(); + optCtrlReqQueue.bIsCtrlRequest = false; + optCtrlReqQueue.bIsGenAlarm = false; + optCtrlRequest.vecOptCtrlQueue.push_back(optCtrlReqQueue); + int msgType = ui->comboBox_cmdType->currentData().toInt(); + + std::string objJson = COptCtrlRequest::generate(optCtrlRequest); + iot_net::CMbMessage msg = iot_net::CMbMessage(objJson,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send SetValue Failed!" <start(1000); + ui->pushButton_exe->setEnabled(false); + ui->textBrowser_exeResult->setText(tr("等待返回结果中。。。。")); + } + +} +/* + * 执行遥控选择 +*/ +void CRealDataControl::exeCtrlSelect() +{ + SOptCtrlRequest optCtrlRequest ; + SOptCtrlReqQueue optCtrlReqQueue ; + getHead(optCtrlRequest.stHead); + QString tableName = m_strTableName.toLower(); + QString strTagName = m_strPointTagName; + QString columnName = "value"; + optCtrlReqQueue.strKeyIdTag = (tableName+"."+strTagName+"."+columnName).toStdString(); + optCtrlReqQueue.nCtrlType = 0; + + if("ANALOG" == m_strTableName) + { + optCtrlReqQueue.dTargetValue = ui->lineEdit_ctrlValue->text().toFloat(); + } + else + { + if(ui->comboBox_ctrlValue->count()) + { + optCtrlReqQueue.dTargetValue = ui->comboBox_ctrlValue->currentData().toInt(); + } + else + { + optCtrlReqQueue.dTargetValue = 0.0; + } + } + + optCtrlReqQueue.nCtrlActType = 0; + optCtrlReqQueue.strCtrlActName = ""; + optCtrlReqQueue.strOffsetNo = ""; + optCtrlReqQueue.bIsDeviceOccupy = ui->comboBox_otherArgs->currentData().toBool(); + optCtrlReqQueue.bIsCtrlRequest = false; + optCtrlReqQueue.bIsGenAlarm = false; + optCtrlRequest.vecOptCtrlQueue.push_back(optCtrlReqQueue); + + int msgType = ui->comboBox_cmdType->currentData().toInt(); + std::string objJson = COptCtrlRequest::generate(optCtrlRequest); + iot_net::CMbMessage msg = iot_net::CMbMessage(objJson,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send SetValue Failed!" <start(1000); + ui->pushButton_exe->setEnabled(false); + ui->textBrowser_exeResult->setText(tr("等待返回结果中。。。。")); + } + +} + +void CRealDataControl::exeCtrlExecute() +{ + SOptCtrlRequest optCtrlRequest ; + SOptCtrlReqQueue optCtrlReqQueue ; + getHead(optCtrlRequest.stHead); + QString tableName = m_strTableName.toLower(); + QString strTagName = m_strPointTagName; + QString columnName = "value"; + optCtrlReqQueue.strKeyIdTag = (tableName+"."+strTagName+"."+columnName).toStdString(); + optCtrlReqQueue.nCtrlType = 0; + + if("ANALOG" == m_strTableName) + { + optCtrlReqQueue.dTargetValue = ui->lineEdit_ctrlValue->text().toFloat(); + } + else + { + if(ui->comboBox_ctrlValue->count()) + { + optCtrlReqQueue.dTargetValue = ui->comboBox_ctrlValue->currentData().toInt(); + } + else + { + optCtrlReqQueue.dTargetValue = 0.0; + } + } + optCtrlReqQueue.nCtrlActType = 0; + optCtrlReqQueue.strCtrlActName = ""; + optCtrlReqQueue.strOffsetNo = ""; + optCtrlReqQueue.bIsDeviceOccupy = ui->comboBox_otherArgs->currentData().toBool(); + optCtrlReqQueue.bIsCtrlRequest = false; + optCtrlReqQueue.bIsGenAlarm = false; + optCtrlRequest.vecOptCtrlQueue.push_back(optCtrlReqQueue); + + int msgType = ui->comboBox_cmdType->currentData().toInt(); + + std::string objJson = COptCtrlRequest::generate(optCtrlRequest); + iot_net::CMbMessage msg = iot_net::CMbMessage(objJson,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send SetValue Failed!" <start(1000); + ui->pushButton_exe->setEnabled(false); + ui->textBrowser_exeResult->setText(tr("等待返回结果中。。。。")); + } +} + +void CRealDataControl::exeCtrlCancel() +{ + SOptCtrlRequest optCtrlRequest ; + SOptCtrlReqQueue optCtrlReqQueue ; + getHead(optCtrlRequest.stHead); + QString tableName = m_strTableName.toLower(); + QString strTagName = m_strPointTagName; + QString columnName = "value"; + optCtrlReqQueue.strKeyIdTag = (tableName+"."+strTagName+"."+columnName).toStdString(); + optCtrlReqQueue.nCtrlType = 0; + + if("ANALOG" == m_strTableName) + { + optCtrlReqQueue.dTargetValue = ui->lineEdit_ctrlValue->text().toFloat(); + } + else + { + if(ui->comboBox_ctrlValue->count()) + { + optCtrlReqQueue.dTargetValue = ui->comboBox_ctrlValue->currentData().toInt(); + } + else + { + optCtrlReqQueue.dTargetValue = 0.0; + } + } + + optCtrlReqQueue.nCtrlActType = 0; + optCtrlReqQueue.strCtrlActName = ""; + optCtrlReqQueue.strOffsetNo = ""; + optCtrlReqQueue.bIsDeviceOccupy = ui->comboBox_otherArgs->currentData().toBool(); + optCtrlReqQueue.bIsCtrlRequest = false; + optCtrlReqQueue.bIsGenAlarm = false; + optCtrlRequest.vecOptCtrlQueue.push_back(optCtrlReqQueue); + + int msgType = ui->comboBox_cmdType->currentData().toInt(); + std::string objJson = COptCtrlRequest::generate(optCtrlRequest); + iot_net::CMbMessage msg = iot_net::CMbMessage(objJson,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send SetValue Failed!" <start(1000); + ui->pushButton_exe->setEnabled(false); + ui->textBrowser_exeResult->setText(tr("等待返回结果中。。。。")); + } + +} + +void CRealDataControl::exeCtrlClose() +{ + SOptCtrlRequest optCtrlRequest ; + SOptCtrlReqQueue optCtrlReqQueue ; + getHead(optCtrlRequest.stHead); + QString tableName = m_strTableName.toLower(); + QString strTagName = m_strPointTagName; + QString columnName = "value"; + optCtrlReqQueue.strKeyIdTag = (tableName+"."+strTagName+"."+columnName).toStdString(); + optCtrlReqQueue.nCtrlType = 0; + optCtrlReqQueue.dTargetValue = 0.0; + optCtrlReqQueue.nCtrlActType = 0; + optCtrlReqQueue.strCtrlActName = ""; + optCtrlReqQueue.strOffsetNo = ""; + optCtrlReqQueue.bIsDeviceOccupy = ui->comboBox_otherArgs->currentData().toBool(); + optCtrlReqQueue.bIsCtrlRequest = false; + optCtrlReqQueue.bIsGenAlarm = false; + optCtrlRequest.vecOptCtrlQueue.push_back(optCtrlReqQueue); + + int msgType = ui->comboBox_cmdType->currentData().toInt(); + std::string objJson = COptCtrlRequest::generate(optCtrlRequest); + iot_net::CMbMessage msg = iot_net::CMbMessage(objJson,m_stAppInfo.nId,CH_HMI_TO_OPT_OPTCMD_DOWN,msgType); + if(!m_pSendComm->sendMsgToDomain(msg,m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId))) + { + qDebug() << "send SetValue Failed!" <textBrowser_exeResult->setText(tr("程序猿还在写")); +} + + +/*此点AI限值查询,远程查询实时数据库表,analog_limit_info*/ +void CRealDataControl::aiLimitQuery() +{ + iot_dbms::CRdbNetApi objRdbNetApi; + int nDestDomainId = m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId); + int nDestSubSystemId = m_nDestSubSystemId; + objRdbNetApi.connect(nDestDomainId,nDestSubSystemId); + iot_idl::RdbQuery msgQuery; + msgQuery.set_strtablename("analog_limit_info"); + + std::string *pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "limit_up1"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "limit_low1"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "limit_up2"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "limit_low2"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "limit_up3"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "limit_low3"; + + iot_idl::RdbCondition *pCondtion = msgQuery.add_msgcondition(); + pCondtion->set_enlogic(iot_idl::ENConditionLogic::enumCondAnd); + pCondtion->set_enrelation(iot_idl::ENConditionRelation::enumCondEqual); + pCondtion->set_strcolumnname("tag_name"); + iot_idl::SVariable * pCondValue = pCondtion->mutable_msgvalue(); + pCondValue->set_edatatype(iot_idl::DataType::CN_DATATYPE_STRING); + pCondValue->set_strvalue(m_strPointTagName.toStdString().c_str()); + + iot_idl::RdbRet retMsg; + QString strStatus; + if(!objRdbNetApi.query(msgQuery,retMsg)) + { + ui->textBrowser_exeStatus->clear(); + strStatus = tr("远程查询实时数据库失败"); + ui->textBrowser_exeStatus->setText(strStatus); + return; + } + if(0 == retMsg.msgrecord_size()) + { + ui->textBrowser_exeStatus->clear(); + strStatus = tr("未查询到测点")+m_strPointTagName+tr("限值"); + ui->textBrowser_exeStatus->setText(strStatus); + return; + } + //因为查询的条件是主键,所以最多只会返回一条记录。 + + double limit_up1 = retMsg.msgrecord(0).msgvaluearray(0).dvalue(); + double limit_low1 = retMsg.msgrecord(0).msgvaluearray(1).dvalue(); + double limit_up2 = retMsg.msgrecord(0).msgvaluearray(2).dvalue(); + double limit_low2 = retMsg.msgrecord(0).msgvaluearray(3).dvalue(); + double limit_up3 = retMsg.msgrecord(0).msgvaluearray(4).dvalue(); + double limit_low3 = retMsg.msgrecord(0).msgvaluearray(5).dvalue(); + strStatus.clear(); + strStatus = "limit_up1 :" + QString::number(limit_up1) + "\n"; + strStatus +="limit_low1:" + QString::number(limit_low1) + "\n"; + strStatus +="limit_up2 :" + QString::number(limit_up2) + "\n"; + strStatus +="limit_low2:" + QString::number(limit_low2) + "\n"; + strStatus +="limit_up3 :" + QString::number(limit_up3) + "\n"; + strStatus +="limit_low3:" + QString::number(limit_low3); + ui->textBrowser_exeStatus->setText(strStatus); + return; + +} +/*禁止刷新,禁止报警,禁止控制,人工置数的状态查询,远程查询实时数据库opt_tag_info*/ +void CRealDataControl::OptPointQuery() +{ + iot_dbms::CRdbNetApi objRdbNetApi; + int nDestDomainId = m_pSystemResources->getDomainIdByLocationId(m_nDestLocationId); + int nDestSubSystemId = m_nDestSubSystemId; + objRdbNetApi.connect(nDestDomainId,nDestSubSystemId); + iot_idl::RdbQuery msgQuery; + msgQuery.set_strtablename("opt_tag_info"); + + std::string *pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "tag_type"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "set_value"; + + iot_idl::RdbCondition *pCondtion = msgQuery.add_msgcondition(); + pCondtion->set_enlogic(iot_idl::ENConditionLogic::enumCondAnd); + pCondtion->set_enrelation(iot_idl::ENConditionRelation::enumCondEqual); + pCondtion->set_strcolumnname("key_id_tag"); + iot_idl::SVariable * pCondValue = pCondtion->mutable_msgvalue(); + pCondValue->set_edatatype(iot_idl::DataType::CN_DATATYPE_STRING); + QString keyIdTag = m_strTableName.toLower() + "." + m_strPointTagName + "." + "status"; + qDebug() << "keyIdTag:" << keyIdTag <set_strvalue(keyIdTag.toStdString().c_str()); + + iot_idl::RdbRet retMsg; + QString strStatus; + if(!objRdbNetApi.query(msgQuery,retMsg)) + { + ui->textBrowser_exeStatus->clear(); + strStatus = tr("远程查询实时数据库失败"); + ui->textBrowser_exeStatus->setText(strStatus); + return; + } + + //由于key_id_tag 和 tag_type 为 表 opt_tag_info 的双主键,所以每一条记录只有一个tag_type + std::map mapTagTypeToSetValue; + int tagType; + double setValue; + for(int i = 0 ; i < retMsg.msgrecord_size();++i) + { + tagType = retMsg.msgrecord(i).msgvaluearray(0).nvalue(); + setValue = retMsg.msgrecord(i).msgvaluearray(1).dvalue(); + mapTagTypeToSetValue.insert(std::pair(tagType,setValue)); + } + + keyIdTag = m_strTableName.toLower() + "." + m_strPointTagName + "." + "value"; + qDebug() << "keyIdTag:" << keyIdTag <set_strvalue(keyIdTag.toStdString().c_str()); + if(!objRdbNetApi.query(msgQuery,retMsg)) + { + ui->textBrowser_exeStatus->clear(); + strStatus = tr("远程查询实时数据库失败"); + ui->textBrowser_exeStatus->setText(strStatus); + return; + } + + for(int i = 0 ; i < retMsg.msgrecord_size();++i) + { + tagType = retMsg.msgrecord(i).msgvaluearray(0).nvalue(); + setValue = retMsg.msgrecord(i).msgvaluearray(1).dvalue(); + mapTagTypeToSetValue.insert(std::pair(tagType,setValue)); + } + if(mapTagTypeToSetValue.size() <= 0 ) + { + ui->textBrowser_exeStatus->clear(); + strStatus.clear(); + strStatus += tr("禁止刷新:未设置\n"); + strStatus += tr("禁止告警:未设置\n"); +// strStatus += "禁止控制:未设置\n"; + strStatus += tr("人工置数:未设置"); + ui->textBrowser_exeStatus->setText(strStatus); + return; + } + strStatus.clear(); + if(mapTagTypeToSetValue.find(2) != mapTagTypeToSetValue.end()) + { + strStatus += tr("禁止刷新:已设置\n"); + } + else + { + strStatus += tr("禁止刷新:未设置\n"); + } + + if(mapTagTypeToSetValue.find(3) != mapTagTypeToSetValue.end()) + { + strStatus += tr("禁止告警:已设置\n"); + } + else + { + strStatus += tr("禁止告警:未设置\n"); + } + +// if(mapTagTypeToSetValue.find(4) != mapTagTypeToSetValue.end()) +// { +// strStatus += "禁止控制:已设置\n"; +// } +// else +// { +// strStatus += "禁止控制:未设置\n"; +// } + + if(mapTagTypeToSetValue.find(1) != mapTagTypeToSetValue.end()) + { + strStatus += (tr("人工置数:") + QString::number(mapTagTypeToSetValue.at(1))); + } + else + { + strStatus += tr("人工置数:未设置"); + } + ui->textBrowser_exeStatus->clear(); + ui->textBrowser_exeStatus->setText(strStatus); + return; +} + +/* + *发送完控制命令后,收到返回报文后,解析报文,显示结果,并停止定时器的函数 +*/ +void CRealDataControl::ctrlRequestReply(const std::string &strMsg) +{ + int nRetCode = -1; + SOptCtrlReply stOptCtrlReply; + nRetCode = COptCtrlReply::parse(strMsg,stOptCtrlReply); + if(nRetCode <= 0) + { + ui->textBrowser_exeResult->setText(tr("解析返回结果出错")); + ui->pushButton_exe->setEnabled(true); + m_timeOutTimes = 0; + m_pTimer->stop(); + return; + } + ui->textBrowser_exeResult->setText(QString::fromStdString(stOptCtrlReply.stHead.strResultStr)); + ui->pushButton_exe->setEnabled(true); + m_timeOutTimes = 0; + m_pTimer->stop(); + return; +} + +/* + * 针对遥控选择,遥控执行,设置的目标值函数 +*/ +void CRealDataControl::setTargetValue(bool &bExist) +{ + bExist = false; + if(m_strTableName == "ANALOG") + { + return; + } + else if(m_strTableName == "DIGITAL") + { + + qDebug() << m_strPointTagName <execute(strSql,queryRet); + if(queryRet.isActive()) + { + if(queryRet.next()) + { + ctrlActName = queryRet.value("CTRL_ACT_NAME").toString(); + } + } + if(ctrlActName != "") + { + bExist = true; + strSql = QString("SELECT CTRL_ACT_NAME,CTRL_GRP_NO,TARGET_VALUE FROM OPT_CTRL_ACT_DEFINE WHERE CTRL_GRP_NAME = ") + "'" + ctrlActName + "'"; + m_pDbInterface->execute(strSql,queryRet); + if(queryRet.isActive()) + { + while(queryRet.next()) + { + ui->comboBox_ctrlValue->addItem(ctrlActName+"_"+queryRet.value("CTRL_ACT_NAME").toString(),queryRet.value("TARGET_VALUE").toInt()); + } + } + } + } + else if(m_strTableName == "MIX") + { + QString ctrlActName = ""; + QSqlQuery queryRet; + QString strSql = QString("SELECT CTRL_ACT_NAME FROM MIX_CONTROL WHERE TAG_NAME = ") + "'" + m_strPointTagName + "'"; + m_pDbInterface->execute(strSql,queryRet); + if(queryRet.isActive()) + { + if(queryRet.next()) + { + ctrlActName = queryRet.value("CTRL_ACT_NAME").toString(); + } + } + if(ctrlActName != "") + { + bExist = true; + strSql = QString("SELECT CTRL_ACT_NAME,CTRL_GRP_NO,TARGET_VALUE FROM OPT_CTRL_ACT_DEFINE WHERE CTRL_GRP_NAME = ") + "'" + ctrlActName + "'"; + m_pDbInterface->execute(strSql,queryRet); + if(queryRet.isActive()) + { + while(queryRet.next()) + { + ui->comboBox_ctrlValue->addItem(ctrlActName+"_"+queryRet.value("CTRL_ACT_NAME").toString(),queryRet.value("TARGET_VALUE").toInt()); + } + } + } + } + else + { + + } +} + + +void CRealDataControl::slot_exeCmd() +{ + int cmdType = ui->comboBox_cmdType->currentData().toInt(); + switch (cmdType) { + case MT_OPT_AI_LIMIT_SET_DOWN: + exeSetAiLimit(); + break; + case MT_OPT_PINHIBIT_REF: + exeInhibitRef(); + break; + case MT_OPT_PINHIBIT_ALARM: + exeInhibitAlarm(); + break; + case MT_OPT_PINHIBIT_CTRL: + exeInhibitCtrl(); + break; + case MT_OPT_TAG_VALUE_SET: + exeSetValue(); + break; + case MT_OPT_CTRL_DOWN_REQUEST: + exeCtrlRequest(); + break; + case MT_OPT_CTRL_DOWN_SELECT: + exeCtrlSelect(); + break; + case MT_OPT_CTRL_DOWN_EXECUTE: + exeCtrlExecute(); + break; + case MT_OPT_CTRL_DOWN_CANCEL: + exeCtrlCancel(); + break; + case MT_OPT_CTRL_DOWN_CLOSE: + exeCtrlClose(); + default: + qDebug() << ".........................." <35) + { + ui->textBrowser_exeResult->setText(tr("接受返回结果超时")); + ui->pushButton_exe->setEnabled(true); + m_pTimer->stop(); + m_timeOutTimes = 0; + } + iot_net::CMbMessage msgRcv; + if(m_pReceiveComm->recvMsg(msgRcv)) + { + if(msgRcv.getChannelID() == CH_OPT_TO_HMI_OPTCMD_UP) + { + int nMessageType = msgRcv.getMsgType(); + std::string strMsg((char *)msgRcv.getDataPtr(),msgRcv.getDataSize()); + switch (nMessageType) + { + case MT_OPT_CTRL_UP_REQUEST_REPLY: + case MT_OPT_CTRL_UP_SELECT_REPLY: + case MT_OPT_CTRL_UP_EXECUTE_REPLY: + case MT_OPT_CTRL_UP_CANCEL_REPLY: + ctrlRequestReply(strMsg); + break; + default: + break; + } + } + } + m_timeOutTimes++; +} + +void CRealDataControl::slot_exeStatus() +{ + int msgType = ui->comboBox_cmdType->currentData().toInt(); + switch (msgType) { + case MT_OPT_AI_LIMIT_SET_DOWN: + { + aiLimitQuery(); + break; + } + + case MT_OPT_PINHIBIT_REF: + case MT_OPT_PINHIBIT_ALARM: + case MT_OPT_PINHIBIT_CTRL: + case MT_OPT_TAG_VALUE_SET: + { + OptPointQuery(); + break; + } + default: + break; + } +} + + +void CRealDataControl::slot_updateOtherArgs(int index) +{ + int cmdType = ui->comboBox_cmdType->itemData(index).toInt(); + bool bExist; + QVector::iterator it; + switch (cmdType) { + case MT_OPT_AI_LIMIT_SET_DOWN: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(true); + ui->lineEdit_ctrlValue->setEnabled(true); + ui->comboBox_ctrlValue->hide(); + ui->textBrowser_exeResult->setText(tr("该命令无反馈结果")); + ui->pushButton_exe->setEnabled(true); + for(it = m_aiLimitOtherArgs.begin(); it != m_aiLimitOtherArgs.end();it++) + { + ui->comboBox_otherArgs->addItem(*it); + } + break; + case MT_OPT_PINHIBIT_REF: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(true); + ui->lineEdit_ctrlValue->setEnabled(false); + ui->lineEdit_ctrlValue->show(); + ui->comboBox_ctrlValue->hide(); + ui->pushButton_exe->setEnabled(true); + ui->textBrowser_exeResult->setText(tr("该命令无反馈结果")); + ui->comboBox_otherArgs->addItem(tr("取消"),0); + ui->comboBox_otherArgs->addItem(tr("设置"),1); +// ui->comboBox_otherArgs->addItem("修改",2); + break; + + case MT_OPT_PINHIBIT_ALARM: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(true); + ui->lineEdit_ctrlValue->setEnabled(false); + ui->lineEdit_ctrlValue->show(); + ui->comboBox_ctrlValue->hide(); + ui->textBrowser_exeResult->setText(tr("该命令无反馈结果")); + ui->pushButton_exe->setEnabled(true); + ui->comboBox_otherArgs->addItem(tr("取消"),0); + ui->comboBox_otherArgs->addItem(tr("设置"),1); +// ui->comboBox_otherArgs->addItem("修改",2); + break; + case MT_OPT_PINHIBIT_CTRL: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(true); + ui->lineEdit_ctrlValue->setEnabled(true); + ui->lineEdit_ctrlValue->show(); + ui->comboBox_ctrlValue->hide(); + ui->textBrowser_exeResult->setText(tr("该命令无反馈结果")); + ui->pushButton_exe->setEnabled(true); + ui->comboBox_otherArgs->addItem(tr("取消"),0); + ui->comboBox_otherArgs->addItem(tr("设置"),1); +// ui->comboBox_otherArgs->addItem("修改",2); + break; + case MT_OPT_TAG_VALUE_SET: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(true); + ui->lineEdit_ctrlValue->setEnabled(true); + ui->lineEdit_ctrlValue->show(); + ui->comboBox_ctrlValue->hide(); + ui->textBrowser_exeResult->setText(tr("该命令无反馈结果")); + ui->pushButton_exe->setEnabled(true); + ui->comboBox_otherArgs->addItem(tr("取消"),0); + ui->comboBox_otherArgs->addItem(tr("设置"),1); +// ui->comboBox_otherArgs->addItem("修改",2); + break; + case MT_OPT_CTRL_DOWN_REQUEST: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(true); + ui->lineEdit_ctrlValue->setEnabled(false); + ui->lineEdit_ctrlValue->show(); + ui->comboBox_ctrlValue->hide(); + ui->comboBox_otherArgs->addItem(tr("占用设备"),true); + ui->comboBox_otherArgs->addItem(tr("不占用设备"),false); + ui->pushButton_exe->setEnabled(true); + break; + case MT_OPT_CTRL_DOWN_SELECT: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(true); + ui->lineEdit_ctrlValue->setEnabled(true); + if("ANALOG" == m_strTableName) + { + ui->lineEdit_ctrlValue->show(); + ui->comboBox_ctrlValue->hide(); + } + else + { + ui->lineEdit_ctrlValue->hide(); + ui->comboBox_ctrlValue->show(); + } + ui->comboBox_otherArgs->addItem(tr("占用设备"),true); + ui->comboBox_otherArgs->addItem(tr("不占用设备"),false); + ui->pushButton_exe->setEnabled(true); + setTargetValue(bExist); + break; + case MT_OPT_CTRL_DOWN_EXECUTE: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(true); + ui->lineEdit_ctrlValue->setEnabled(true); + if("ANALOG" == m_strTableName) + { + ui->lineEdit_ctrlValue->show(); + ui->comboBox_ctrlValue->hide(); + } + else + { + ui->lineEdit_ctrlValue->hide(); + ui->comboBox_ctrlValue->show(); + } + + ui->comboBox_otherArgs->addItem(tr("占用设备"),true); + ui->comboBox_otherArgs->addItem(tr("不占用设备"),false); + ui->pushButton_exe->setEnabled(true); + setTargetValue(bExist); + break; + case MT_OPT_CTRL_DOWN_CANCEL: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(true); + ui->lineEdit_ctrlValue->setEnabled(true); + if("ANALOG" == m_strTableName) + { + ui->lineEdit_ctrlValue->show(); + ui->comboBox_ctrlValue->hide(); + } + else + { + ui->lineEdit_ctrlValue->hide(); + ui->comboBox_ctrlValue->show(); + } + ui->comboBox_otherArgs->addItem(tr("占用设备"),true); + ui->comboBox_otherArgs->addItem(tr("不占用设备"),false); + ui->pushButton_exe->setEnabled(true); + setTargetValue(bExist); + break; + case MT_OPT_CTRL_DOWN_CLOSE: + ui->comboBox_otherArgs->clear(); + ui->comboBox_ctrlValue->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->lineEdit_ctrlValue->show(); + ui->comboBox_ctrlValue->hide(); + ui->comboBox_otherArgs->setEnabled(false); + ui->lineEdit_ctrlValue->setEnabled(false); + ui->pushButton_exe->setEnabled(true); + ui->textBrowser_exeResult->setText(tr("该命令无反馈结果")); + break; + + + default: + ui->comboBox_otherArgs->clear(); + ui->lineEdit_ctrlValue->clear(); + ui->textBrowser_exeResult->clear(); + ui->textBrowser_exeStatus->clear(); + ui->comboBox_otherArgs->setEnabled(false); + ui->lineEdit_ctrlValue->setEnabled(false); + ui->textBrowser_exeResult->setText(tr("程序猿还没写完")); + ui->textBrowser_exeStatus->setText(tr("程序猿还没写完")); + break; + } +} + diff --git a/product/src/tools/debug_tool_v2/CRealDataControl.h b/product/src/tools/debug_tool_v2/CRealDataControl.h new file mode 100644 index 00000000..9e2810f8 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDataControl.h @@ -0,0 +1,127 @@ +#ifndef CREALDATACONTROL_H +#define CREALDATACONTROL_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include "pub_widget/MessageBox.h" +#include +#include + + +#include "CSystemResources.h" +#include "MessageChannel.h" +#include "operate_server_api/JsonMessageStruct.h" +#include "operate_server_api/JsonOptCommand.h" +#include "rdb_net_api/CRdbNetApi.h" +#include "net_msg_bus_api/MsgBusApi.h" + + + +#define APP_ID 4 + + +namespace Ui { +class CRealDataControl; +} + +class CRealDataControl : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit CRealDataControl(int locationId, + int subSystemId, + QString pointName, + QString tagName, + QString tableName, + CSystemResources *, + bool isCtrl, + QWidget *parent); + ~CRealDataControl(); + void initControl(int locationId,int subSystemId,QString pointName,QString tagName,QString tableName,CSystemResources *pSystemResources); + +private slots: + void slot_updateOtherArgs(int ); + void slot_exeCmd(); + void slot_timeOutReciceMsg(); + void slot_exeStatus(); + +private: + + Ui::CRealDataControl * ui; + + iot_net::CMbCommunicator * m_pSendComm; + iot_net::CMbCommunicator * m_pReceiveComm; + + CSystemResources * m_pSystemResources; + + iot_dbms::CDbApi * m_pDbInterface; + + iot_public::SAppInfo m_stAppInfo; + int m_nDestSubSystemId; + int m_nDestLocationId; + QString m_strPointName; + QString m_strPointTagName; + QString m_strTableName; + + QString m_strSrcTag; + int m_nSrcDomainId; + int m_nAppId; + QString m_strHostName; + QString m_strInstName; + QString m_strCommName; + int m_nPermUserId; + int m_nPermUserGroupId; + + QTimer * m_pTimer; + int m_timeOutTimes; + + QVector m_aiLimitOtherArgs; + + bool m_isCtrl; + +private: + + void initVariable(int locationId,int subSystemId,QString pointName,QString tagName,QString tableName,CSystemResources *pSystemResources); + void initView(); + void initCmdTypeComBox(); + void initCMbCommunicator(); + void initSingalSlot(); + + void addAiCmd(); + void addDiCmd(); + void addMiCmd(); + void addPiCmd(); + void addConstCmd(); + + void getHead(SOptReqHead &); + + void exeSetAiLimit(); + void exeInhibitRef(); + void exeInhibitAlarm(); + void exeInhibitCtrl(); + void exeSetValue(); + void exeCtrlRequest(); + void exeCtrlSelect(); + void exeCtrlExecute(); + void exeCtrlCancel(); + void exeCtrlClose(); + void exeCommon(); + + void aiLimitQuery(); + void OptPointQuery(); + + void ctrlRequestReply(const std::string &); + //只有在 遥控选择、遥控执行、才需要设置targetValue + void setTargetValue(bool &isExist); + + + + + + +}; + +#endif // CREALDATACONTROL_H diff --git a/product/src/tools/debug_tool_v2/CRealDataControl.ui b/product/src/tools/debug_tool_v2/CRealDataControl.ui new file mode 100644 index 00000000..8b5cdf37 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDataControl.ui @@ -0,0 +1,290 @@ + + + CRealDataControl + + + + 0 + 0 + 301 + 445 + + + + Form + + + + + + + + + 85 + 23 + + + + + 85 + 23 + + + + 控制测点: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + + + 85 + 23 + + + + + 85 + 23 + + + + 命令类型: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 85 + 23 + + + + + 85 + 23 + + + + 其他参数: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 85 + 0 + + + + + 85 + 16777215 + + + + 控制数值: + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 执行命令 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 状态查询 + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 执行状态 + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 反馈结果 + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CRealDataSelect.cpp b/product/src/tools/debug_tool_v2/CRealDataSelect.cpp new file mode 100644 index 00000000..fb668b5a --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDataSelect.cpp @@ -0,0 +1,905 @@ +#include "CRealDataSelect.h" +#include "ui_CRealDataSelect.h" +#include +#include +#include +CRealDataSelect::CRealDataSelect(QWidget *parent) : + QWidget(parent), + ui(new Ui::CRealDataSelect) +{ + ui->setupUi(this); + m_nAddModel = -1; + //ui->lineEdit->setHidden(true); + //ui->pushButton->setHidden(true); + + //ui->comboBox_devGroup->setView(new QListView()); + ui->comboBox_location->setView(new QListView()); + ui->comboBox_subSystem->setView(new QListView()); + //ui->comboBox_devGroup->setHidden(true); + //ui->devGroup->setHidden(true); + //ui->listWidget_device->setHidden(true); + //ui->device->setHidden(true); + ui->treeWidget_devGroup->setContextMenuPolicy(Qt::CustomContextMenu); + ui->tableWidget_MesurePoint->setHidden(true); + ui->pushButton->setHidden(true); + + initPntTableInfo(); +} + + + +void CRealDataSelect::setSystemResources(CSystemResources *pSystemResources) +{ + m_pSystemResources = pSystemResources; +} + +void CRealDataSelect::setRealDataWatch(CRealDataWatch *pWatch) +{ + m_pRealDataWatch = pWatch; +} + + +CRealDataSelect::~CRealDataSelect() +{ + delete ui; +} + + +void CRealDataSelect::initSelect() +{ + initVariable(); + initSignalsSlots(); + initLocationComBox(); + initSubSystemComBox(); + //initDevGroupComBox(); + +// initDeviceListWidget(); + initPointTableWidget(); + +} + +void CRealDataSelect::initVariable() +{ + m_pObjDbInterface = m_pSystemResources->getDbInterface(); +} + +void CRealDataSelect::initLocationComBox() +{ + QSqlQuery locationTable; + m_pObjDbInterface->execute("SELECT DESCRIPTION,LOCATION_ID FROM sys_model_location_info ORDER BY LOCATION_ID", locationTable); + if(locationTable.isActive()) + { + QVariant val; + val.clear(); + QString locationName = ""; + uint locationId = -1; + while(locationTable.next()) + { + val = locationTable.value("DESCRIPTION"); + locationName = val.toString(); + val = locationTable.value("LOCATION_ID"); + locationId = val.toUInt(); + ui->comboBox_location->addItem(locationName,locationId); + } + } + ui->lineEdit->setPlaceholderText(tr("请输入描述信息")); +} + +void CRealDataSelect::initSubSystemComBox() +{ + QSqlQuery subSystemTable; + m_pObjDbInterface->execute("SELECT DESCRIPTION,SUB_SYSTEM_ID FROM sys_model_sub_system_info ORDER BY SUB_SYSTEM_ID", subSystemTable); + if(subSystemTable.isActive()) + { + QVariant val; + val.clear(); + QString subSystemName = ""; + uint subSystemId = -1; + while(subSystemTable.next()) + { + val = subSystemTable.value("DESCRIPTION"); + subSystemName = val.toString(); + val = subSystemTable.value("SUB_SYSTEM_ID"); + subSystemId = val.toUInt(); + if(subSystemId > CN_AppId_COMAPP) + { + ui->comboBox_subSystem->addItem(subSystemName,subSystemId); + } + } + } +} + +//void CRealDataSelect::initDevGroupComBox() +//{ +// QSqlQuery devGroupTable; +// ui->comboBox_devGroup->clear(); + +// m_pObjDbInterface->execute("SELECT DESCRIPTION,TAG_NAME,LOCATION_ID,SUB_SYSTEM FROM dev_group ORDER BY TAG_NAME", devGroupTable); +// if(devGroupTable.isActive()) +// { +// QVariant val; +// val.clear(); +// QString devGroupName = ""; +// QString devGroupTag = ""; +// while(devGroupTable.next()) +// { +// val = devGroupTable.value("DESCRIPTION"); +// devGroupName = val.toString(); +// val = devGroupTable.value("TAG_NAME"); +// devGroupTag = val.toString(); +// ui->comboBox_devGroup->addItem(devGroupName,devGroupTag); + +// //ui->treeWidget_devGroup->addTopLevelItem(nodeItem); +// } +// } +//} + +//void CRealDataSelect::initDeviceListWidget() +//{ +// //已废弃 +// QString sqlStr= "SELECT DESCRIPTION,TAG_NAME,LOCATION_ID,SUB_SYSTEM FROM dev_info ORDER BY TAG_NAME"; +// QSqlQuery deviceTable; +// m_pObjDbInterface->execute(sqlStr,deviceTable); +// if(deviceTable.isActive()) +// { +// QVariant val; +// val.clear(); +// QString devName; +// QString devTag; +// uint locationId; +// uint subSystemId; +// QListWidgetItem *item; +// while(deviceTable.next()) +// { +// val = deviceTable.value("DESCRIPTION"); +// devName = val.toString(); +// val = deviceTable.value("TAG_NAME"); +// devTag = val.toString(); +// locationId = deviceTable.value("LOCATION_ID").toUInt(); +// subSystemId = deviceTable.value("SUB_SYSTEM").toUInt(); +// item = new QListWidgetItem(); +// item->setText(devName); +// item->setData(Qt::UserRole+1,devTag); +// item->setData(Qt::UserRole+2,locationId); +// item->setData(Qt::UserRole+3,subSystemId); +// ui->listWidget_device->addItem(item); +// } +// } + +//} + +void CRealDataSelect::initPointTableWidget() +{ + ui->tableWidget_MesurePoint->setColumnCount(2); + QStringList header; + header.append(tr("类型")); + header.append(tr("测点")); + ui->tableWidget_MesurePoint->setHorizontalHeaderLabels(header); + ui->tableWidget_MesurePoint->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->tableWidget_MesurePoint->setColumnWidth(0,50); + ui->tableWidget_MesurePoint->setColumnWidth(1,100); + //ui->tableWidget_MesurePoint->setMaximumWidth(200); + ui->tableWidget_MesurePoint->horizontalHeader()->setStretchLastSection(true); + ui->tableWidget_MesurePoint->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); + //设置table的水平滚动条 + + ui->tableWidget_MesurePoint->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui->tableWidget_MesurePoint->setEditTriggers(QAbstractItemView::NoEditTriggers); + +} + + + +void CRealDataSelect::initSignalsSlots() +{ + connect(ui->comboBox_location,SIGNAL(currentIndexChanged(int)), + this,SLOT(slot_selectTreeDevGroup(int))); + + //connect(ui->comboBox_subSystem,SIGNAL(currentIndexChanged(int)), + //this,SLOT(slot_selectDevGroup(int))); + connect(ui->comboBox_subSystem,SIGNAL(currentIndexChanged(int)), + this,SLOT(slot_selectTreeDevGroup(int))); + connect(ui->lineEdit,SIGNAL(textEdited(QString)),this,SLOT(slot_queryDev(QString))); + //connect(ui->comboBox_location,SIGNAL(currentIndexChanged(int)), + // this,SLOT(slot_selectDevice(int))); + //connect(ui->comboBox_subSystem,SIGNAL(currentIndexChanged(int)), + //this,SLOT(slot_selectDevice(int))); + + //connect(ui->comboBox_devGroup,SIGNAL(currentIndexChanged(int)), + // this,SLOT(slot_selectDevice(int))); + + //connect(ui->listWidget_device,SIGNAL(itemClicked(QListWidgetItem*)), + //this,SLOT(slot_showPoint(QListWidgetItem*))); + connect(ui->treeWidget_devGroup,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)) + ,this,SLOT(solt_showPoint(QTreeWidgetItem*,int))); +// connect(ui->tableWidget_MesurePoint,SIGNAL(cellDoubleClicked(int,int)), +// this,SLOT(slot_addPoint(int,int))); + connect(ui->pushButton,SIGNAL(clicked()), + this,SLOT(slot_queryDev())); + // connect(ui->listWidget_device,SIGNAL(itemDoubleClicked(QListWidgetItem*)), + //this,SLOT(slot_addAllCurrentPoint(QListWidgetItem*))); + +// connect(ui->treeWidget_devGroup,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), +// this,SLOT(slot_addAllCurrentPoint(QTreeWidgetItem*,int))); + +} + +//void CRealDataSelect::slot_selectDevice(int) +//{ +// ui->listWidget_device->clear(); +// ui->tableWidget_MesurePoint->clearContents(); +// ui->tableWidget_MesurePoint->setRowCount(0); +// uint locationId = ui->comboBox_location->currentData(Qt::UserRole).toUInt(); +// uint subSystemId = ui->comboBox_subSystem->currentData(Qt::UserRole).toUInt(); +// QString devGroup = ui->comboBox_devGroup->currentData(Qt::UserRole).toString(); +// QString sqlStr = QString("SELECT DESCRIPTION,TAG_NAME,LOCATION_ID,SUB_SYSTEM FROM dev_info where LOCATION_ID = %1 " +// " AND SUB_SYSTEM = %2 " +// " and group_tag_name ='%3' ORDER BY TAG_NAME").arg(locationId).arg(subSystemId).arg(devGroup); + +// QSqlQuery deviceTable; +// m_pObjDbInterface->execute(sqlStr,deviceTable); +// if(deviceTable.isActive()) +// { +// QString devName; +// QString devTag; +// uint locationId_2; +// uint subSystemId_2; +// QListWidgetItem *item; +// while(deviceTable.next()) +// { +// devName = deviceTable.value("DESCRIPTION").toString(); +// devTag = deviceTable.value("TAG_NAME").toString(); +// locationId_2 = deviceTable.value("LOCATION_ID").toUInt(); +// subSystemId_2 = deviceTable.value("SUB_SYSTEM").toUInt(); +// item = new QListWidgetItem(); +// item->setText(devName); +// item->setData(Qt::UserRole+1,devTag); +// item->setData(Qt::UserRole+2,locationId_2); +// item->setData(Qt::UserRole+3,subSystemId_2); +// ui->listWidget_device->addItem(item); +// } +// } +//} + +//void CRealDataSelect::slot_selectDevGroup(int) +//{ +// uint locationId = ui->comboBox_location->currentData(Qt::UserRole).toUInt(); +// uint subSystemId = ui->comboBox_subSystem->currentData(Qt::UserRole).toUInt(); +// ui->comboBox_devGroup->clear(); + +// QSqlQuery devGroupTable; +// devGroupTable.clear(); +// QString sqlStr = QString("SELECT DESCRIPTION,TAG_NAME,LOCATION_ID,SUB_SYSTEM FROM dev_group where SUB_SYSTEM =%1 " +// "and LOCATION_ID = %2 ORDER BY TAG_NAME").arg(subSystemId).arg(locationId); +// m_pObjDbInterface->execute(sqlStr, devGroupTable); + +// if(devGroupTable.isActive()) +// { +// QVariant val; +// val.clear(); +// QString devGroupName =""; +// QString devGroupTag = ""; +// while(devGroupTable.next()) +// { +// val = devGroupTable.value("DESCRIPTION"); +// devGroupName = val.toString(); +// val = devGroupTable.value("TAG_NAME"); +// devGroupTag = val.toString(); +// ui->comboBox_devGroup->addItem(devGroupName,devGroupTag); + +// } +// } +//} + +//void CRealDataSelect::slot_showPoint(QListWidgetItem* _item) +//{ + +// ui->tableWidget_MesurePoint->clearContents(); +// QString devTage = _item->data(Qt::UserRole+1).toString(); + +// QString analogTableName = "ANALOG"; +// QString digitalTableName = "DIGITAL"; +// QString accumlTableName = "ACCUML"; +// QString mixTableName = "MIX"; +// QString constTableName = "CONST"; + +// QStringList tableNameList; +// QStringList pointType; +// tableNameList.append(analogTableName); +// pointType.append(tr("模拟量")); +// tableNameList.append(digitalTableName); +// pointType.append(tr("数字量")); +// tableNameList.append(accumlTableName); +// pointType.append(tr("累积量")); +// tableNameList.append(mixTableName); +// pointType.append(tr("混合量")); +// tableNameList.append(constTableName); +// pointType.append(tr("常量")); +// QString strSql1 = "SELECT DESCRIPTION,TAG_NAME FROM "; + +// QString strSql2 = QString(" WHERE DEVICE = ")+QString("'")+ devTage+"'"; +// uint rowCount = 0; +// int j = 0; +// QTableWidgetItem *item; +// QSqlQuery pointTable; +// for(int i = 0 ; i < 4; i++) +// { +// pointTable.clear(); +// m_pObjDbInterface->execute(strSql1+tableNameList[i]+strSql2,pointTable); +// qDebug()<<"sql语句"<tableWidget_MesurePoint->setRowCount(rowCount); +// while(pointTable.next()) +// { +// item = new QTableWidgetItem; +// item->setData(Qt::UserRole+1,tableNameList[i]); +// item->setText(pointType[i]); +// ui->tableWidget_MesurePoint->setItem(j,0,item); +// item = new QTableWidgetItem; +// item->setData(Qt::UserRole+1,pointTable.value("TAG_NAME").toString()); +// item->setText(pointTable.value("DESCRIPTION").toString()); +// item->setToolTip(pointTable.value("DESCRIPTION").toString()); +// ui->tableWidget_MesurePoint->setItem(j++,1,item); +// } +// } +// } +//} + +void CRealDataSelect::solt_showPoint(QTreeWidgetItem* _item, int treeIndex) +{ + Q_UNUSED(treeIndex); + + if(_item == NULL || ui->treeWidget_devGroup->currentItem() == NULL || + ui->treeWidget_devGroup->currentItem()->parent() == NULL) + { + return; + } + + uint locationId = ui->treeWidget_devGroup->currentItem()->data(0,Qt::UserRole+2).toUInt(); + uint subSystemId = ui->treeWidget_devGroup->currentItem()->data(0,Qt::UserRole+3).toUInt(); + QString locationDesc = ui->comboBox_location->currentText(); + QString subSystemDesc = ui->comboBox_subSystem->currentText(); + QString devDescription = ui->treeWidget_devGroup->currentItem()->text(0); + QString devTagName = ui->treeWidget_devGroup->currentItem()->data(0,Qt::UserRole+1).toString(); + QString descDevG = ui->treeWidget_devGroup->currentItem()->parent()->text(0); + QStringList devTagSplit = devTagName.split("."); + QString devGTag =""; + if(devTagSplit.size() == 2) + { + QString devg = devTagSplit.at(1); + QStringList devg_ = devg.split("_"); + devGTag = devTagSplit.at(0)+"."+devg_.at(0); + } + QVector vecPntPtr; + vecPntPtr.reserve(20000); //<一般一个设备不会超过2万点 + + ui->tableWidget_MesurePoint->clearContents(); + QString devTage = _item->data(0,Qt::UserRole+1).toString(); + + //分页信息 + QString keyword; + int nCurPage = 0; + int nPageSize = 0; + m_pRealDataWatch->getFilterAndPageInfo(keyword,nCurPage,nPageSize); + + QString strSql1 = "SELECT DESCRIPTION,TAG_NAME,RTU_TAG,SEQ_NO,%1 FROM %2 %3"; + QString strSql2 = QString(" WHERE DEVICE = ")+QString("'")+ devTage+"'"; + + if(nCurPage != 0 && nPageSize != 0) + { + if(!keyword.isEmpty()) + { + strSql2 += QString(" and DESCRIPTION LIKE '%%1%'").arg(keyword); + } + + strSql2 += QString(" LIMIT %1,%2").arg((nCurPage -1)*nPageSize).arg(nPageSize); + } + strSql2 += " ORDER BY SEQ_NO ASC"; + + uint rowCount = 0; + int nRow = 0; + int nAddModel = 1; + QTableWidgetItem *item; + QSqlQuery pointTable; + for(int nTabIdx = 0 ; nTabIdx < 4; nTabIdx++) + { + pointTable.clear(); + QString strSQL = strSql1.arg(m_listPntIsCtrlCol[nTabIdx]).arg(m_listTableName[nTabIdx]).arg(strSql2); + m_pObjDbInterface->execute(strSQL,pointTable); + if(!pointTable.isActive()) + { + continue; + } + + rowCount += pointTable.size(); + ui->tableWidget_MesurePoint->setRowCount(rowCount); + while(pointTable.next()) + { + item = new QTableWidgetItem; + item->setData(Qt::UserRole+1,m_listTableName[nTabIdx]); + item->setText(m_listPointType[nTabIdx]); + ui->tableWidget_MesurePoint->setItem(nRow,0,item); + item = new QTableWidgetItem; + //用下标访问效率高,注意与select字段顺序对应 + QString strPntTagName = pointTable.value(1).toString(); + item->setData(Qt::UserRole+1,strPntTagName); //setText(strDesc); + item->setToolTip(strDesc); + ui->tableWidget_MesurePoint->setItem(nRow++,1,item); + + SAddPointInfoPtr ptrPntInfo = SAddPointInfoPtr::create(); + ptrPntInfo->nLocationId = locationId; + ptrPntInfo->nSubsystemId = subSystemId; + ptrPntInfo->nAddModel = nAddModel++; + ptrPntInfo->strLocationDesc = locationDesc; + ptrPntInfo->strSubsystemDesc = subSystemDesc; + ptrPntInfo->strPntType = m_listPointType[nTabIdx]; + ptrPntInfo->strTableName = m_listTableName[nTabIdx]; + ptrPntInfo->strPntDesc = strDesc; + ptrPntInfo->strPntTagName = strPntTagName; + ptrPntInfo->strDevDesc = devDescription; + ptrPntInfo->strDevTagName = devTagName; + ptrPntInfo->strDevGroupDesc = descDevG; + ptrPntInfo->strRtuTag = pointTable.value(2).toString(); //nSeqNo = pointTable.value(3).toInt(); //nIsControl = pointTable.value(4).toInt(); //treeWidget_devGroup->currentItem()->data(0,Qt::UserRole+2).toUInt(); + uint subSystemId = ui->treeWidget_devGroup->currentItem()->data(0,Qt::UserRole+3).toUInt(); + QString pointType = ui->tableWidget_MesurePoint->item(row,0)->text(); + QString tableName = ui->tableWidget_MesurePoint->item(row,0)->data(Qt::UserRole+1).toString(); + QString pointDescription = ui->tableWidget_MesurePoint->item(row,1)->text(); + QString pointTagName = ui->tableWidget_MesurePoint->item(row,1)->data(Qt::UserRole+1).toString(); + QString devDescription = ui->treeWidget_devGroup->currentItem()->text(0); + QString devTagName = ui->treeWidget_devGroup->currentItem()->data(0,Qt::UserRole+1).toString(); + QStringList devTagSplit = devTagName.split("."); + QString devGTag =""; + + if(devTagSplit.size() == 2) + { + QString devg = devTagSplit.at(1); + QStringList devg_ = devg.split("_"); + devGTag = devTagSplit.at(0)+"."+devg_.at(0); + + } + + QString descDevG =ui->treeWidget_devGroup->currentItem()->parent()->text(0); + + emit signal_addPoint(ui->comboBox_location->currentText(),locationId, + ui->comboBox_subSystem->currentText(),subSystemId, + pointType,tableName, + pointDescription,pointTagName, + devDescription,devTagName,descDevG,m_nAddModel,devTagName); +} + +void CRealDataSelect::slot_queryDev() +{ + + QString keyWord = ui->lineEdit->text().trimmed(); + QTreeWidgetItemIterator it(ui->treeWidget_devGroup); + while(*it){ + ui->treeWidget_devGroup->setItemHidden(*it,false); + it++; + } + if(keyWord.isEmpty()) + { + return; + } + else + { + + QTreeWidgetItemIterator itor(ui->treeWidget_devGroup); + while(*itor){ + if((*itor)->text(0).contains(keyWord,Qt::CaseInsensitive)) + { + for(int i=0;i<(*itor)->childCount();i++) + { + itor++; + } + itor++; + continue; + } + else + { + //确认子节点是否匹配 + bool childBool=0; + for(int i=0;i<(*itor)->childCount();i++) + { + if((*itor)->child(i)->text(0).contains(keyWord,Qt::CaseInsensitive)) + { + childBool=1; + } + else + { + ui->treeWidget_devGroup->setItemHidden((*itor)->child(i),true); + } + } + if(childBool==false) + { + ui->treeWidget_devGroup->setItemHidden(*itor,true); + } + for(int i=0;i<(*itor)->childCount();i++){ + itor++; + } + } + + itor++; + } + } +} + +void CRealDataSelect::slot_queryDev(QString) +{ + slot_selectTreeDevGroup(0); + QString keyWord = ui->lineEdit->text().trimmed(); + QString tag_name = ui->lineEdit->text(); + + /* caodingfa: 从代码逻辑来看,已经无法适配现有功能,注释掉 + if((allSelect(tag_name))||(preciseSelect())) + { + return; + } + */ + + QTreeWidgetItemIterator it(ui->treeWidget_devGroup); + while(*it){ + ui->treeWidget_devGroup->setItemHidden(*it,false); + it++; + } + if(keyWord.isEmpty()) + { + return; + } + else + { + QTreeWidgetItemIterator itor(ui->treeWidget_devGroup); + while(*itor) + { + if((*itor)->text(0).contains(keyWord,Qt::CaseInsensitive)) + { + int k=(*itor)->childCount(); + for(int i=0;ichildCount();i++) + { + if((*itor)->child(i)->text(0).contains(keyWord,Qt::CaseInsensitive)) + { + childBool=1; + } + else + { + ui->treeWidget_devGroup->setItemHidden((*itor)->child(i),true); + } + } + if(childBool==false) + { + ui->treeWidget_devGroup->setItemHidden(*itor,true); + } + for(int i=0;i<(*itor)->childCount();i++){ + itor++; + } + } + + itor++; + } + } +} + +void CRealDataSelect::slot_addAllCurrentPoint(QListWidgetItem *) +{ + int rowCount = ui->tableWidget_MesurePoint->rowCount(); + m_nAddModel = 1; + for(int i = 0; i < rowCount; ++i) + { + slot_addPoint(i,0); + m_nAddModel++; + } + m_nAddModel = -1; +} + +void CRealDataSelect::slot_selectTreeDevGroup(int) +{ + uint locationId = ui->comboBox_location->currentData(Qt::UserRole).toUInt(); + uint subSystemId = ui->comboBox_subSystem->currentData(Qt::UserRole).toUInt(); + ui->treeWidget_devGroup->clear(); +// QTreeWidgetItem *firstItem=new QTreeWidgetItem(); +// firstItem->setText(0,ui->comboBox_location->currentText()); +// ui->treeWidget_devGroup->addTopLevelItem(firstItem); + QSqlQuery devGroupTable; + devGroupTable.clear(); + QString sqlStr = QString("SELECT a.DESCRIPTION dev_group_name,b.DESCRIPTION device_name," + " b.TAG_NAME tag_name,a.LOCATION_ID location_id,a.SUB_SYSTEM sub_system FROM dev_group a,dev_info b" + " where a.LOCATION_ID= %1 and a.SUB_SYSTEM= %2 and " + "a.TAG_NAME =b.GROUP_TAG_NAME order by a.DESCRIPTION ").arg(locationId).arg(subSystemId); + + m_pObjDbInterface->execute(sqlStr, devGroupTable); + if(devGroupTable.isActive()) + { + + QVariant val; + val.clear(); + QString dev_group_name =""; + QString device_name = ""; + QString lastDevGroupName=""; + QString tag_name=""; + QString location_id=""; + QString sub_system=""; + QTreeWidgetItem *lastItem=new QTreeWidgetItem(); + + while(devGroupTable.next()) + { + dev_group_name = devGroupTable.value(0).toString(); + device_name = devGroupTable.value(1).toString(); + tag_name = devGroupTable.value(2).toString(); + location_id = devGroupTable.value(3).toString(); + sub_system = devGroupTable.value(4).toString(); + + if(lastDevGroupName!=dev_group_name){ + QTreeWidgetItem *nodeItem = new QTreeWidgetItem(ui->treeWidget_devGroup); + nodeItem->setText(0,dev_group_name); + nodeItem->setSelected(false); + QTreeWidgetItem *childItem = new QTreeWidgetItem(nodeItem); + childItem->setText(0,device_name); + childItem->setData(0,Qt::UserRole+1,tag_name); + childItem->setData(0,Qt::UserRole+2,location_id); + childItem->setData(0,Qt::UserRole+3,sub_system); + lastDevGroupName=dev_group_name; + lastItem=nodeItem; + } + else{ + QTreeWidgetItem *childItem = new QTreeWidgetItem(lastItem); + childItem->setText(0,device_name); + childItem->setData(0,Qt::UserRole+1,tag_name); + childItem->setData(0,Qt::UserRole+2,location_id); + childItem->setData(0,Qt::UserRole+3,sub_system); + } + + + } + } +// uint locationId = ui->comboBox_location->currentData(Qt::UserRole).toUInt(); +// uint subSystemId = ui->comboBox_subSystem->currentData(Qt::UserRole).toUInt(); +// QString devGroup = ui->comboBox_devGroup->currentData(Qt::UserRole).toString(); +// QString sqlStr = QString("SELECT DESCRIPTION,TAG_NAME,LOCATION_ID,SUB_SYSTEM FROM dev_info where LOCATION_ID = %1 " +// " AND SUB_SYSTEM = %2 " +// " and group_tag_name ='%3' ORDER BY TAG_NAME").arg(locationId).arg(subSystemId).arg(devGroup); + +// QSqlQuery deviceTable; +// m_pObjDbInterface->execute(sqlStr,deviceTable); +// if(deviceTable.isActive()) +// { +// QString devName; +// QString devTag; +// uint locationId_2; +// uint subSystemId_2; +// QListWidgetItem *item; +// while(deviceTable.next()) +// { +// devName = deviceTable.value("DESCRIPTION").toString(); +// devTag = deviceTable.value("TAG_NAME").toString(); +// locationId_2 = deviceTable.value("LOCATION_ID").toUInt(); +// subSystemId_2 = deviceTable.value("SUB_SYSTEM").toUInt(); +// item = new QListWidgetItem(); +// item->setText(devName); +// item->setData(Qt::UserRole+1,devTag); +// item->setData(Qt::UserRole+2,locationId_2); +// item->setData(Qt::UserRole+3,subSystemId_2); +// ui->listWidget_device->addItem(item); + + +} + +void CRealDataSelect::slot_paging() +{ + solt_showPoint(ui->treeWidget_devGroup->currentItem(),ui->treeWidget_devGroup->currentColumn()); +} + +void CRealDataSelect::slot_addAllCurrentPoint(QTreeWidgetItem *, int) +{ + int rowCount = ui->tableWidget_MesurePoint->rowCount(); + m_nAddModel = 1; + for(int i = 0; i < rowCount; ++i) + { + slot_addPoint(i,0); + m_nAddModel++; + } + m_nAddModel = -1; +} +bool CRealDataSelect::allSelect(QString tag_name) +{ + bool pointBool=false; + + QString analogTableName = "ANALOG"; + QString digitalTableName = "DIGITAL"; + QString accumlTableName = "ACCUML"; + QString mixTableName = "MIX"; + QStringList tableNameList; + QStringList pointType; + tableNameList.append(analogTableName); + pointType.append(tr("模拟量")); + tableNameList.append(digitalTableName); + pointType.append(tr("数字量")); + tableNameList.append(accumlTableName); + pointType.append(tr("累积量")); + tableNameList.append(mixTableName); + pointType.append(tr("混合量")); + uint locationId ; + uint subSystemId ; + QString tableName ; + QString pointDescription ; + QString pointTagName ; + QString point_type; + //QString devDescription = ui->listWidget_device->currentItem()->text(); + //QString devTagName = ui->listWidget_device->currentItem()->data(Qt::UserRole+1).toString(); + QString devDescription; + QString devTagName ; + QString descDevG ; + QString allName; + QString strSql1 = "select a.TAG_NAME allName,a.DESCRIPTION pointDescription,a.SEQ_NO,a.LOCATION_ID locationId," + "a.SUB_SYSTEM subSystemId ,a.RTU_TAG,a.device devTagName,di.DESCRIPTION devDescription,dg.DESCRIPTION descDevG " + "from "; + + QString strSql2 = QString(" a ,dev_info di ,dev_group dg where " + " a.TAG_NAME = ")+QString("'")+ tag_name+"' and" + " a.DEVICE =di.TAG_NAME and di.GROUP_TAG_NAME =dg.TAG_NAME "; + uint rowCount = 0; + int j = 0; + QTableWidgetItem *item; + QSqlQuery pointTable; + for(int i = 0 ; i < 4; i++) + { + pointTable.clear(); + tableName = tableNameList[i]; + point_type = pointType[i]; + + m_pObjDbInterface->execute(strSql1 + tableName + strSql2,pointTable); + if(pointTable.isActive()) + { + rowCount += pointTable.size(); + ui->tableWidget_MesurePoint->setRowCount(rowCount); + while(pointTable.next()) + { + pointBool=true; + item = new QTableWidgetItem; + item->setData(Qt::UserRole+1,tableName); + item->setText(point_type); + ui->tableWidget_MesurePoint->setItem(j,0,item); + item = new QTableWidgetItem; + allName=pointTable.value(0).toString(); + pointDescription=pointTable.value(1).toString(); + locationId=pointTable.value(3).toInt(); + subSystemId=pointTable.value(4).toInt(); + devTagName=pointTable.value(6).toString(); + devDescription=pointTable.value(7).toString(); + descDevG=pointTable.value(8).toString(); + + pointTagName=allName; + m_nAddModel=1; + } + } + } + if(pointBool==false){ + return false; + } + for(int k=0;kcomboBox_location->count();k++) + { + if(ui->comboBox_location->itemData(k,Qt::UserRole).toUInt()==locationId) + { + ui->comboBox_location->setCurrentIndex(k); + } + } + for(int k=0;kcomboBox_subSystem->count();k++) + { + if(ui->comboBox_subSystem->itemData(k,Qt::UserRole).toUInt()==subSystemId) + { + ui->comboBox_subSystem->setCurrentIndex(k); + } + } + ui->treeWidget_devGroup->clear(); + slot_selectTreeDevGroup(0); + QTreeWidgetItemIterator itor(ui->treeWidget_devGroup); + while(*itor){ + bool childNumber=false; + if((*itor)->text(0).contains(descDevG,Qt::CaseInsensitive)) + { + int itorCount=(*itor)->childCount(); + (*itor)->setHidden(false); + for(int i=0;ichild(i)->text(0).contains(devDescription,Qt::CaseInsensitive)) + { + childNumber=true; + (*itor)->child(i)->setHidden(false); + } + else{ + + (*itor)->child(i)->setHidden(true); + } + + } + if(childNumber==false){ + (*itor)->setHidden(true); + } + for(int i=0;i<=itorCount;i++){ + itor++; + } + + continue; + } + (*itor)->setHidden(true); + itor++; + } + emit signal_addPoint(ui->comboBox_location->currentText(),locationId, + ui->comboBox_subSystem->currentText(),subSystemId, + point_type,tableName, + pointDescription,pointTagName, + devDescription,devTagName,descDevG,m_nAddModel,allName); + + return true; +} + +bool CRealDataSelect::preciseSelect() +{ + QStringList devTagSplit; + QString analogTableName = "ANALOG"; + QString digitalTableName = "DIGITAL"; + QString accumlTableName = "ACCUML"; + QString mixTableName = "MIX"; + QString currTextEdit=ui->lineEdit->text(); + + devTagSplit=currTextEdit.split("."); + for(int i=0;i +#include +#include +#include +#include +#include "pub_widget/MessageBox.h" +#include "db_api_ex/CDbApi.h" +#include "CSystemResources.h" +#include +#include "CRealDataWatch.h" + + +namespace Ui { +class CRealDataSelect; +} + +class CRealDataSelect : public QWidget +{ + Q_OBJECT + +public: + explicit CRealDataSelect(QWidget *parent = 0); + void setSystemResources(CSystemResources *); + void setRealDataWatch(CRealDataWatch *pWatch); + void initSelect(); + + ~CRealDataSelect(); + +signals: + void signal_addPoint(QString,uint,QString,uint,QString,QString,QString,QString,QString,QString,QString,int,QString); + void signal_batchAddPoint(QVector &listPntInfo); + +private slots: + //void slot_selectDevice(int); + //void slot_selectDevGroup(int); + //void slot_showPoint(QListWidgetItem*); + void solt_showPoint(QTreeWidgetItem*,int); + void slot_addPoint(int,int); + void slot_queryDev(); + void slot_queryDev(QString); + void slot_addAllCurrentPoint(QListWidgetItem* pItem); + //void slot_selectTreeDevGroup(int); + void slot_addAllCurrentPoint(QTreeWidgetItem*,int); + void slot_selectTreeDevGroup(int); + void slot_paging(); + +private: + void initPntTableInfo(); + +private: + Ui::CRealDataSelect *ui; + iot_dbms::CDbApi *m_pObjDbInterface; + CSystemResources *m_pSystemResources; +// bool m_isFristQuery; + CRealDataWatch *m_pRealDataWatch; + + QStringList m_listTableName; + QStringList m_listPointType; + QStringList m_listPntIsCtrlCol; //< 用来存储每个表is_control的SQL的,因为acc表没有此字段,为了兼容加入此逻辑 + +private: + + void initView(); + void initVariable(); + void initLocationComBox(); + void initSubSystemComBox(); + void initDevGroupComBox(); + void initDeviceListWidget(); + void initPointTableWidget(); + + bool allSelect(QString tag_name); + bool preciseSelect(); + void initSignalsSlots(); + int m_nAddModel; //添加模式 +}; + +#endif // CREALDATASELECT_H diff --git a/product/src/tools/debug_tool_v2/CRealDataSelect.ui b/product/src/tools/debug_tool_v2/CRealDataSelect.ui new file mode 100644 index 00000000..2fc5ddb8 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDataSelect.ui @@ -0,0 +1,200 @@ + + + CRealDataSelect + + + + 0 + 0 + 414 + 707 + + + + + 200 + 0 + + + + Form + + + + + + + + + + + + + + + + 45 + 23 + + + + + 45 + 23 + + + + 位置 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 45 + 23 + + + + + 45 + 23 + + + + 专业 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 查询 + + + + + + + + + + + + + + 0 + 0 + + + + + 设备组 + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CRealDataWatch.cpp b/product/src/tools/debug_tool_v2/CRealDataWatch.cpp new file mode 100644 index 00000000..f58f7de3 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDataWatch.cpp @@ -0,0 +1,722 @@ +#include "CRealDataWatch.h" +#include "ui_CRealDataWatch.h" +#include +#include "perm_mng_api/PermMngApi.h" +#include +#include +#include +#include +#include +#include "toolCommon.h" +#include "CStatusDialog.h" + +CRealDataWatch::CRealDataWatch(QWidget *parent) : + QWidget(parent), + ui(new Ui::CRealDataWatch) +{ + ui->setupUi(this); + m_searchDialog = NULL; + m_bIsLgoin = false; + m_pSearchButton = new QPushButton(this); + m_pSearchButton->setObjectName("searchButton"); + m_pSearchButton->setText(""); + m_pSearchButton->setMaximumSize(28, 29); + m_pSearchButton->setCursor(QCursor(Qt::ArrowCursor)); + m_pSearchButton->setShortcut(Qt::Key_Return); + QHBoxLayout * pSearchLayout = new QHBoxLayout(); + pSearchLayout->setContentsMargins(0, 0, 0, 0); + pSearchLayout->addStretch(); + pSearchLayout->addWidget(m_pSearchButton); + ui->lineEdit->setLayout(pSearchLayout); + ui->checkBox_append->setChecked(false); + + ui->checkBox_paging->setChecked(false); //todo:分页实现不完善,临时实现 + ui->lineEdit_pageNum->setAlignment(Qt::AlignHCenter); + m_nCurPageNum = 0; + m_nPageSize = 0; +} + +CRealDataWatch::~CRealDataWatch() +{ + m_pDpcdaForApp->unsubscribeAll(); + + + delete ui; +} + +void CRealDataWatch::setSystemResources(CSystemResources *pSystemResources) +{ + m_pSystemResources = pSystemResources; +} + +void CRealDataWatch::deletePoint(int row) +{ + QString tableName = ui->tableWidget_point->item(row,3)->data(Qt::UserRole+1).toString(); + QString tagName = ui->tableWidget_point->item(row,4)->data(Qt::UserRole+1).toString(); + m_pDpcdaForApp->unsubscribe(tableName.toStdString(), + tagName.toStdString(), + QString("value").toStdString()); + m_pDpcdaForApp->unsubscribe(tableName.toStdString(), + tagName.toStdString(), + QString("status").toStdString()); + ui->tableWidget_point->removeRow(row); +} + +void CRealDataWatch::contextMenuEvent(QContextMenuEvent *event) +{ + QWidget::contextMenuEvent(event); + + if(event->pos().x() < ui->tableWidget_point->pos().x()) + { + return; + } + QRect headerRect = ui->tableWidget_point->horizontalHeader()->rect(); + headerRect.moveTopLeft(ui->tableWidget_point->mapTo(this, QPoint())); + if(!headerRect.contains(event->pos())) + { + QMenu menu(this); + + QAction *allSelectAction = menu.addAction(tr("全选")); + connect(allSelectAction,&QAction::triggered,[=](){ui->tableWidget_point->selectAll();}); + QAction *deleteSelectAction = menu.addAction(tr("删除")); + connect(deleteSelectAction,&QAction::triggered,[=](){ + slot_deleteMaxPoint(); + }); + QAction *cancleSelectAction = menu.addAction(tr("取消选择")); + connect(cancleSelectAction,&QAction::triggered,[=](){ + ui->tableWidget_point->clearSelection(); + }); + menu.exec(QCursor::pos()); + } +} + +void CRealDataWatch::keyPressEvent(QKeyEvent *event) +{ + if(event->key() == Qt::Key_Enter) + { + filter(); + } + else if(event->key() == Qt::Key_Delete) + { + slot_deleteMaxPoint(); + } + QWidget::keyPressEvent(event); +} + +bool CRealDataWatch::eventFilter(QObject *watched, QEvent *event) +{ + if(event->type() == QEvent::KeyPress) + { + QKeyEvent * theKey = static_cast(event); + if(theKey->key() == Qt::Key_Enter || theKey->key() == Qt::Key_Return) + { + filter(); + return true; + }else if(theKey->key() == Qt::Key_Delete) + { + slot_deleteMaxPoint(); + return true; + } + } + return QObject::eventFilter(watched,event); +} + +void CRealDataWatch::initWatch() +{ + initVariable(); + initView(); + initSignalSlot(); +} + +void CRealDataWatch::initVariable() +{ + m_pObjDbInterface = m_pSystemResources->getDbInterface(); + m_pDpcdaForApp = new iot_service::CDpcdaForApp; + m_searchDialog = new CStatusDialog(m_pSystemResources,this); +} + +void CRealDataWatch::initView() +{ + initCheckBox(); + initTableWidgetPoint(); + ui->lineEdit->setPlaceholderText(tr("请输入描述信息")); +} + +void CRealDataWatch::initCheckBox() +{ + ui->checkBox_all->setChecked(true); + ui->checkBox_analog->setChecked(true); + ui->checkBox_digital->setChecked(true); + ui->checkBox_accuml->setChecked(true); + ui->checkBox_mix->setChecked(true); +} + +void CRealDataWatch::initTableWidgetPoint() +{ + ui->tableWidget_point->setColumnCount(12); + ui->tableWidget_point->setColumnWidth(0,200); + ui->tableWidget_point->setColumnWidth(1,40); + ui->tableWidget_point->setColumnWidth(2,40); + ui->tableWidget_point->setColumnWidth(3,50); + ui->tableWidget_point->setColumnWidth(4,60); + ui->tableWidget_point->setColumnWidth(5,20); + ui->tableWidget_point->setColumnWidth(6,20); + ui->tableWidget_point->setColumnWidth(7,210); + ui->tableWidget_point->setColumnWidth(8,120); + ui->tableWidget_point->setColumnWidth(9,180); + ui->tableWidget_point->setColumnWidth(10,40); + + QStringList header; + header.append(tr("标签")); //0 //0 + header.append(tr("值"));//6 //1 + header.append(tr("状态"));//7 //2 + header.append(tr("类型")); //0 //3 + header.append(tr("测点")); //1 //4 + header.append(tr("位置")); //2 + header.append(tr("专业")); //3 //6 + header.append(tr("设备组"));//4 + header.append(tr("设备"));//5 //8 + header.append(tr("RTU"));//8 + header.append(tr("SEQ_NO"));//9 //10 + header.append(tr("是否可控"));//10 /11 + + ui->tableWidget_point->hideColumn(5); + ui->tableWidget_point->hideColumn(6); + + ui->tableWidget_point->setHorizontalHeaderLabels(header); + ui->tableWidget_point->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->tableWidget_point->setSelectionMode(QAbstractItemView::SingleSelection); + ui->tableWidget_point->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->tableWidget_point->horizontalHeader()->setStretchLastSection(true); + ui->tableWidget_point->setAlternatingRowColors(true); +} + +void CRealDataWatch::initSignalSlot() +{ + connect(ui->checkBox_all,SIGNAL(clicked(bool)), + this,SLOT(slot_checkBox(bool))); + connect(ui->checkBox_accuml,SIGNAL(clicked(bool)), + this,SLOT(slot_checkBox(bool))); + connect(ui->checkBox_analog,SIGNAL(clicked(bool)), + this,SLOT(slot_checkBox(bool))); + connect(ui->checkBox_digital,SIGNAL(clicked(bool)), + this,SLOT(slot_checkBox(bool))); + connect(ui->checkBox_mix,SIGNAL(clicked(bool)), + this,SLOT(slot_checkBox(bool))); + connect(m_pSearchButton,SIGNAL(clicked()), + this,SLOT(slot_pointFilter())); + connect(ui->tableWidget_point,SIGNAL(cellDoubleClicked(int,int)), + this,SLOT(slot_ctrlRealData(int,int))); + connect(ui->tableWidget_point,SIGNAL(itemClicked(QTableWidgetItem *)), + this,SLOT(slot_pointsitemClicked(QTableWidgetItem *))); +// connect(ui->tableWidget_point,SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), +// this,SLOT(slot_textChanged(QTableWidgetItem*,QTableWidgetItem*))); + connect(m_searchDialog,SIGNAL(signal_selectTextEdit(QString ,QString , int )), + this,SLOT(slot_selectTextEdit(QString ,QString , int ))); +} + +void CRealDataWatch::slot_checkBox(bool) +{ + QObject * pObjCheckBox = sender(); + QString checkBoxName = pObjCheckBox->objectName(); + QStringList nameList = checkBoxName.split('_'); + if(QString("all") == nameList[1]) + { + if(ui->checkBox_all->isChecked()) + { + ui->checkBox_analog->setChecked(true); + ui->checkBox_digital->setChecked(true); + ui->checkBox_accuml->setChecked(true); + ui->checkBox_mix->setChecked(true); + } + else + { + ui->checkBox_analog->setChecked(false); + ui->checkBox_digital->setChecked(false); + ui->checkBox_accuml->setChecked(false); + ui->checkBox_mix->setChecked(false); + } + } + else + { + if(ui->checkBox_accuml->isChecked()&& + ui->checkBox_analog->isChecked()&& + ui->checkBox_digital->isChecked()&& + ui->checkBox_mix->isChecked()) + { + ui->checkBox_all->setChecked(true); + } + else + { + ui->checkBox_all->setChecked(false); + } + } + filter(); +} + +void CRealDataWatch::addPointToTable(const SAddPointInfo &stPntInfo) +{ + if((stPntInfo.nAddModel == 1 || stPntInfo.nAddModel == -1) && !ui->checkBox_append->isChecked()) + { + m_mapPnt2Row.clear(); //< 清理掉测点与行号的缓存,在slot_deleteMaxPoint前删除,提高效率 + ui->tableWidget_point->setSelectionMode(QAbstractItemView::MultiSelection); + ui->tableWidget_point->selectAll(); + slot_deleteMaxPoint(); + ui->tableWidget_point->setSelectionMode(QAbstractItemView::SingleSelection); + } + + if(stPntInfo.strTableName == QString("CONST")) + { + N_MessageBox::about(this,tr("提示"),tr("const类型测点未配置")); + return; + } + + QString strFullTagName = stPntInfo.strTableName + "." + stPntInfo.strPntTagName; + if(m_mapPnt2Row.find(strFullTagName) != m_mapPnt2Row.end()) + { + return; + } + + m_pDpcdaForApp->subscribe(stPntInfo.strTableName.toLower().toStdString(), + stPntInfo.strPntTagName.toStdString(), + QString("value").toStdString()); + m_pDpcdaForApp->subscribe(stPntInfo.strTableName.toLower().toStdString(), + stPntInfo.strPntTagName.toStdString(), + QString("status").toStdString()); + + uint rowCount = ui->tableWidget_point->rowCount(); + ui->tableWidget_point->setRowCount(rowCount+1); + QTableWidgetItem * item = NULL; + m_mapPnt2Row[strFullTagName] = rowCount; + + item = new QTableWidgetItem; //< 值,占位 + item->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_point->setItem(rowCount,1,item); + + item = new QTableWidgetItem; //< 状态,占位 + item->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_point->setItem(rowCount,2,item); + + item = new QTableWidgetItem; + item->setText(stPntInfo.strPntType); + item->setData(Qt::UserRole+1,stPntInfo.strTableName); + ui->tableWidget_point->setItem(rowCount,3,item); + + item = new QTableWidgetItem; + item->setText(stPntInfo.strPntDesc); + item->setData(Qt::UserRole+1,stPntInfo.strPntTagName); + ui->tableWidget_point->setItem(rowCount,4,item); + + item = new QTableWidgetItem; + item->setText(stPntInfo.strLocationDesc); + item->setData(Qt::UserRole+1,stPntInfo.nLocationId); + ui->tableWidget_point->setItem(rowCount,5,item); + + item = new QTableWidgetItem; + item->setText(stPntInfo.strSubsystemDesc); + item->setData(Qt::UserRole+1,stPntInfo.nSubsystemId); + ui->tableWidget_point->setItem(rowCount,6,item); + + item = new QTableWidgetItem; + item->setText(stPntInfo.strDevDesc); + item->setData(Qt::UserRole+1,stPntInfo.strDevTagName); + ui->tableWidget_point->setItem(rowCount,8,item); + + item = new QTableWidgetItem; + item->setData(Qt::UserRole+1,0); + item->setText(stPntInfo.strDevGroupDesc); + ui->tableWidget_point->setItem(rowCount,7,item); + + item = new QTableWidgetItem; + item->setData(Qt::UserRole+1,0); + item->setText(stPntInfo.strPntTagName); + ui->tableWidget_point->setItem(rowCount,0,item); + + item = new QTableWidgetItem; + item->setText(stPntInfo.strRtuTag); + ui->tableWidget_point->setItem(rowCount,9,item); + + item = new QTableWidgetItem; + item->setText(QString::number(stPntInfo.nSeqNo,10)); + ui->tableWidget_point->setItem(rowCount,10,item); + + item = new QTableWidgetItem; + item->setData(Qt::UserRole+1,stPntInfo.nIsControl); + QString strIsCtrlDesc = (stPntInfo.nIsControl == 0) ? tr("否") : tr("是"); + item->setText(strIsCtrlDesc); + ui->tableWidget_point->setItem(rowCount,11,item); +} + +void CRealDataWatch::slot_batchAddPoint(QVector &vecPntInfo) +{ + for(int nRow = 0;nRow < vecPntInfo.size();nRow++) + { + addPointToTable(*vecPntInfo[nRow]); + } + + filter(); //< 统一执行一遍过滤 +} + +void CRealDataWatch::updateValueAndStatus(const int &nRow, const QString &strValue, const uint &nStatus) +{ + QTableWidgetItem * itemValue = ui->tableWidget_point->item(nRow,1); + if(itemValue != NULL) + { + itemValue->setText(strValue); + } + + QTableWidgetItem *itemStatus = ui->tableWidget_point->item(nRow,2); + if(itemStatus != NULL) + { + itemStatus->setText(getPointStatus(nStatus)); + itemStatus->setData(Qt::UserRole+1,nStatus); + } +} + +void CRealDataWatch::slot_updatePntRealData(iot_idl::SRealTimeDataPkg stRealData) +{ + for(int i = 0; i < stRealData.stairtd_size();++i) + { + const ::iot_idl::SAiRealTimeData &aiStru = stRealData.stairtd(i); + auto pIter = m_mapPnt2Row.find("ANALOG." + QString::fromStdString(aiStru.strtagname())); + if(pIter == m_mapPnt2Row.end()) + { + continue; + } + + updateValueAndStatus(pIter.value(),dfToString(aiStru.fvalue()),aiStru.ustatus()); + } + + for(int i = 0; i < stRealData.stdirtd_size();++i) + { + const ::iot_idl::SDiRealTimeData &diStu = stRealData.stdirtd(i); + auto pIter = m_mapPnt2Row.find("DIGITAL." + QString::fromStdString(diStu.strtagname())); + if(pIter == m_mapPnt2Row.end()) + { + continue; + } + + updateValueAndStatus(pIter.value(),QString::number(diStu.nvalue(),10),diStu.ustatus()); + } + + for(int i = 0; i < stRealData.stpirtd_size();++i) + { + const ::iot_idl::SPiRealTimeData &piStu = stRealData.stpirtd(i); + auto pIter = m_mapPnt2Row.find("ACCUML." + QString::fromStdString(piStu.strtagname())); + if(pIter == m_mapPnt2Row.end()) + { + continue; + } + + updateValueAndStatus(pIter.value(),dfToString(piStu.dvalue()),piStu.ustatus()); + } + + for(int i = 0; i < stRealData.stmirtd_size();++i) + { + const ::iot_idl::SMiRealTimeData &miStu = stRealData.stmirtd(i); + auto pIter = m_mapPnt2Row.find("MIX." + QString::fromStdString(miStu.strtagname())); + if(pIter == m_mapPnt2Row.end()) + { + continue; + } + + updateValueAndStatus(pIter.value(),QString::number(miStu.nvalue(),10),miStu.ustatus()); + } +} + +void CRealDataWatch::filter() +{ + QString tableNameList; + if(ui->checkBox_analog->isChecked()) + { + tableNameList.append("ANALOG"); + } + if(ui->checkBox_digital->isChecked()) + { + tableNameList.append("DIGITAL"); + } + if(ui->checkBox_accuml->isChecked()) + { + tableNameList.append("ACCUML"); + } + if(ui->checkBox_mix->isChecked()) + { + tableNameList.append("MIX"); + } + + int rowCount = ui->tableWidget_point->rowCount(); + + for(int i = 0 ; i < rowCount ; ++i) + { + if(!ui->checkBox_all->isChecked()&& //如果全选框勾上了,就不用作类型过滤 + !tableNameList.contains(ui->tableWidget_point->item(i,3)->data(Qt::UserRole+1).toString())) + { + ui->tableWidget_point->hideRow(i); + continue; + } + if(!filterByKeyWord(i)) + { + ui->tableWidget_point->hideRow(i); + continue; + } + + ui->tableWidget_point->showRow(i); + } +} + +void CRealDataWatch::slot_pointFilter() +{ + emit signal_paging(); + + filter(); +} + +bool CRealDataWatch::isBelongThisLocation(int &locationId, int &row) +{ + if(row < 0 || row >= ui->tableWidget_point->rowCount()) + { + return false; + } + if(ui->tableWidget_point->item(row,5)->data(Qt::UserRole+1).toInt() == locationId) + { + return true; + } + else + { + return false; + } +} + +bool CRealDataWatch::isBelongThisSubSystem(int &subSystemId, int &row) +{ + if(row < 0 || row >= ui->tableWidget_point->rowCount()) + { + return false; + } + if(ui->tableWidget_point->item(row,6)->data(Qt::UserRole+1).toInt() == subSystemId) + { + return true; + } + else + { + return false; + } +} + +bool CRealDataWatch::devNameIsContainKeyWord(QString &kv, int &row) +{ + if(row < 0 || row >= ui->tableWidget_point->rowCount()) + { + return false; + } + if(ui->tableWidget_point->item(row,8)->text().contains(kv)) + { + return true; + } + else + { + return false; + } +} + +bool CRealDataWatch::pointNameIsContainKeyWord(QString &kv, int row) +{ + if(row < 0 || row >= ui->tableWidget_point->rowCount()) + { + return false; + } + if(ui->tableWidget_point->item(row,4)->text().contains(kv)) + { + return true; + } + else + { + return false; + } +} + +//某一行,通过位置、或者专业、或者设备关键、或者测点关键字过滤某一行 +bool CRealDataWatch::filterByKeyWord(int row) +{ + QString kv = ui->lineEdit->text().trimmed(); + if(0 == kv.compare("")) + { + return true; + } + else + { + return ( devNameIsContainKeyWord(kv,row) || pointNameIsContainKeyWord(kv,row)); + } +} + +QString CRealDataWatch::dfToString(float value) +{ + QString text = QString::number(value,10,6); + return changeFomart(text); +} + +QString CRealDataWatch::dfToString(double value) +{ + QString text = QString::number(value,10,6); + return changeFomart(text); +} + +QString CRealDataWatch::changeFomart(QString &text) +{ + if(text.isEmpty()) + { + return text; + } + QStringList list =text.split("."); + if(list.count() != 2) + { + return text; + } + QString dd = list[1]; + dd.remove(QRegExp("0*$")); + + if(dd.isEmpty()) + { + return list[0]; + }else + { + return QString("%1.%2").arg(list[0]).arg(dd); + } +} + +void CRealDataWatch::slot_ctrlRealData(int _row, int) +{ + int row = _row; + + bool isCtl = ui->tableWidget_point->item(row,11)->data(Qt::UserRole+1).toBool(); + + int locationId = ui->tableWidget_point->item(row,5)->data(Qt::UserRole+1).toInt(); + + int subSystemId = ui->tableWidget_point->item(row,6)->data(Qt::UserRole+1).toInt(); + + QString tagName = ui->tableWidget_point->item(row,4)->data(Qt::UserRole+1).toString(); + + QString pointName = ui->tableWidget_point->item(row,4)->text(); + + QString tableName = ui->tableWidget_point->item(row,3)->data(Qt::UserRole+1).toString(); + + CRealDataControl *ctrlDialog = new CRealDataControl(locationId, + subSystemId, + pointName, + tagName, + tableName, + m_pSystemResources, + isCtl, + this); + + ctrlDialog->setWindowTitle(pointName + tr(" 操作")); + + ctrlDialog->exec(); + delete ctrlDialog; + ctrlDialog = nullptr; +} + + +void CRealDataWatch::slot_deleteMaxPoint() +{ + if(ui->tableWidget_point->rowCount()<= 0) + return ; + QModelIndexList modelIndexList = ui->tableWidget_point->selectionModel()->selectedRows(0); + if(modelIndexList.isEmpty()) + { + N_MessageBox::warning(this, tr("提示"), tr("当前未选中任何项!"), N_MessageBox::Ok); + return; + } + std::sort(modelIndexList.begin(), modelIndexList.end()); + for(int i = modelIndexList.size()-1;i>=0;i--) + { + deletePoint(modelIndexList.at(i).row()); + } + + //< 重新构建测点与行号的映射关系 + m_mapPnt2Row.clear(); + for(int nRow = 0; nRow < ui->tableWidget_point->rowCount(); nRow++) + { + QString tableName = ui->tableWidget_point->item(nRow,3)->data(Qt::UserRole+1).toString(); + QString tagName = ui->tableWidget_point->item(nRow,4)->data(Qt::UserRole+1).toString(); + m_mapPnt2Row[tableName + "." + tagName] = nRow; + } +} + +void CRealDataWatch::slot_pointsitemClicked(QTableWidgetItem *item) +{ + if(m_searchDialog != NULL) + { + //m_searchDialog->show(); + } + else + { + m_searchDialog = new CStatusDialog(m_pSystemResources,this); + //m_searchDialog->show(); + } + bool isDigital = QString("DIGITAL") + == ui->tableWidget_point->item(item->row(),3) + ->data(Qt::UserRole+1).toString(); + if(ui->tableWidget_point->item(item->row(),2)==0){ + return; + } + int status =int(ui->tableWidget_point->item(item->row(),2)->data(Qt::UserRole+1).toDouble()); + QString allName=ui->tableWidget_point->item(item->row(),0)->text(); + int value=int(ui->tableWidget_point->item(item->row(),1) ->text().toDouble()); + m_searchDialog->initData(isDigital ? 0:1,status,allName,value); +} + +void CRealDataWatch::slot_selectTextEdit(QString allStatus,QString m_allName, int m_value) +{ + emit signal_selectTextEdit(allStatus,m_allName,m_value); +} + + +void CRealDataWatch::getFilterAndPageInfo(QString &keyword,int &nCurPage, int &nPageSize) +{ + keyword = ui->lineEdit->text().trimmed(); + nCurPage = m_nCurPageNum; + nPageSize = m_nPageSize; +} + +void CRealDataWatch::on_checkBox_paging_stateChanged(int arg1) +{ + if(arg1 == 2) //选中 + { + m_nCurPageNum = 1; + m_nPageSize = 100; + ui->lineEdit_pageNum->setText(QString::number(m_nCurPageNum)); + } + else if(arg1 == 0) + { + m_nCurPageNum = 0; + m_nPageSize = 0; + } +} + +void CRealDataWatch::on_btn_pre_clicked() +{ + m_nCurPageNum = m_nCurPageNum > 1 ? (m_nCurPageNum-1) : 1; + ui->lineEdit_pageNum->setText(QString::number(m_nCurPageNum)); + + emit signal_paging(); +} + +void CRealDataWatch::on_btn_next_clicked() +{ + ++m_nCurPageNum; + ui->lineEdit_pageNum->setText(QString::number(m_nCurPageNum)); + + emit signal_paging(); +} + +void CRealDataWatch::on_btn_status_search_clicked() +{ + if(m_searchDialog != NULL) + m_searchDialog->show(); + else + { + m_searchDialog = new CStatusDialog(m_pSystemResources,this); + m_searchDialog->show(); + } +} diff --git a/product/src/tools/debug_tool_v2/CRealDataWatch.h b/product/src/tools/debug_tool_v2/CRealDataWatch.h new file mode 100644 index 00000000..16506d88 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDataWatch.h @@ -0,0 +1,123 @@ +#ifndef CREALDATAWATCH_H +#define CREALDATAWATCH_H + +#include +#include +#include "pub_widget/MessageBox.h" +#include +#include "CRealDataControl.h" +#include +#include "CSystemResources.h" +#include "db_api_ex/CDbApi.h" +#include "dp_chg_data_api/CDpcdaForApp.h" +#include "pub_logger_api/logger.h" +#include "net_msg_bus_api/MsgBusApi.h" +#include "perm_mng_api/PermMngApi.h" +#include "DataProcMessage.pb.h" + +namespace Ui { +class CRealDataWatch; +} + +struct SAddPointInfo +{ + int nLocationId; //< 位置ID + int nSubsystemId; //< 子系统ID + int nAddModel; //< 正常应该是添加模式,实际作用待确认 + QString strLocationDesc; //< 位置描述 + QString strSubsystemDesc; //< 子系统描述 + QString strPntType; //< 测点类型 + QString strTableName; //< 表名 + QString strPntDesc; //< 测点描述 + QString strPntTagName; //< 测点tag + QString strDevDesc; //< 设备描述 + QString strDevTagName; //< 设备tag + QString strDevGroupDesc; //< 设备组描述 + QString strRtuTag; //< RTU TAG + int nSeqNo; //< 测点表中的seq_no + int nIsControl; //< 测点表中的is_control +}; +typedef QSharedPointer SAddPointInfoPtr; + + +class CStatusDialog; +class CRealDataWatch : public QWidget +{ + Q_OBJECT + +public slots: + void slot_batchAddPoint(QVector &vecPntInfo); + void slot_updatePntRealData(iot_idl::SRealTimeDataPkg stRealData); + +private slots: + void slot_checkBox(bool); + void slot_pointFilter(); + void slot_ctrlRealData(int _row,int _col); +// void slot_textChanged(QTableWidgetItem*,QTableWidgetItem*); + void slot_deleteMaxPoint(); + void slot_pointsitemClicked(QTableWidgetItem *item); + void slot_selectTextEdit(QString allStatus,QString m_allName, int m_value); + + void on_checkBox_paging_stateChanged(int arg1); + + void on_btn_pre_clicked(); + + void on_btn_next_clicked(); + + void on_btn_status_search_clicked(); + +public: + explicit CRealDataWatch(QWidget *parent = 0); + ~CRealDataWatch(); + void initWatch(); + void setSystemResources(CSystemResources *); + void deletePoint(int row); + void getFilterAndPageInfo(QString &keyword,int &nCurPage,int &nPageSize); +signals: + void signal_selectTextEdit(QString allStatus,QString m_allName, int m_value); + void signal_paging(); + +protected: + void contextMenuEvent(QContextMenuEvent *event); + void keyPressEvent(QKeyEvent *event); + bool eventFilter(QObject *watched, QEvent *event); +private: + Ui::CRealDataWatch *ui; + iot_dbms::CDbApi *m_pObjDbInterface; + CSystemResources *m_pSystemResources; + iot_service::CDpcdaForApp *m_pDpcdaForApp; + + bool m_bIsLgoin; + QPushButton *m_pSearchButton; + + CStatusDialog* m_searchDialog; + int m_nCurPageNum;//2个值同时为0时不启用分页 + int m_nPageSize; + + QHash m_mapPnt2Row; //< 表名.测点tag -> 表中行号 + +private: + void initVariable(); + void initView(); + void initCheckBox(); + void initTableWidgetPoint(); + void initSignalSlot(); + void filter(); + + bool isBelongThisLocation(int &locationId,int &row); + bool isBelongThisSubSystem(int &subSystemId,int &row); + bool devNameIsContainKeyWord(QString &kv,int &row); + bool pointNameIsContainKeyWord(QString &kv,int row); + bool filterByKeyWord(int row); + + QString dfToString(float value); + + QString dfToString(double value); + + QString changeFomart(QString &text); + + void addPointToTable(const SAddPointInfo &stPntInfo); + void updateValueAndStatus(const int &nRow,const QString &strValue,const uint &nStatus); +}; + +#endif // CREALDATAWATCH_H diff --git a/product/src/tools/debug_tool_v2/CRealDataWatch.ui b/product/src/tools/debug_tool_v2/CRealDataWatch.ui new file mode 100644 index 00000000..6a694213 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDataWatch.ui @@ -0,0 +1,237 @@ + + + CRealDataWatch + + + + 0 + 0 + 858 + 452 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + 6 + + + + + + + + + 测点描述: + + + + + + + + 300 + 23 + + + + + 16777215 + 23 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 状态查询 + + + + + + + + + + + + + + 80 + 0 + + + + 全选 + + + + + + + + 80 + 0 + + + + 模拟量 + + + + + + + + 80 + 0 + + + + 数字量 + + + + + + + + 80 + 0 + + + + 累积量 + + + + + + + + 80 + 0 + + + + 混合量 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 启用分页 + + + + + + + 上一页 + + + + + + + + 30 + 16777215 + + + + + + + + 下一页 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 累加式 + + + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CRealDatabaseItemInfo.cpp b/product/src/tools/debug_tool_v2/CRealDatabaseItemInfo.cpp new file mode 100644 index 00000000..da01f57e --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDatabaseItemInfo.cpp @@ -0,0 +1,63 @@ +#include "CRealDatabaseItemInfo.h" +#include +CRealDatabaseItemInfo::CRealDatabaseItemInfo() +{ +} + +void CRealDatabaseItemInfo::initialize(const iot_idl::RdbRecord &msgRecord) +{ + init(msgRecord); +} + +void CRealDatabaseItemInfo::init(const iot_idl::RdbRecord &msgRecord) +{ + m_data.clear(); + for(int index(0);indexcolumn) + { + return m_data.at(column); + } + return QString(); +} + +void CRealDatabaseItemInfo::setData(int index, QString stValue) +{ + m_data[index] = stValue; +} diff --git a/product/src/tools/debug_tool_v2/CRealDatabaseItemInfo.h b/product/src/tools/debug_tool_v2/CRealDatabaseItemInfo.h new file mode 100644 index 00000000..8bef4a35 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDatabaseItemInfo.h @@ -0,0 +1,24 @@ +#ifndef CREALDATABASEITEMINFO_H +#define CREALDATABASEITEMINFO_H +#include +#include +#include +#include "rdb_net_api/CRdbNetApi.h" +#include + +class CRealDatabaseItemInfo +{ +public: + CRealDatabaseItemInfo(); + void initialize(const iot_idl::RdbRecord &msgRecord); + void init(const iot_idl::RdbRecord &msgRecord); + + QString getDataByColumn(int column); + void setData(int index,QString stValue); +public: + //公共 + QVector m_data; +}; +typedef QSharedPointer RealDatabasePtr; + +#endif // CREALDATABASEITEMINFO_H diff --git a/product/src/tools/debug_tool_v2/CRealDatabaseItemModel.cpp b/product/src/tools/debug_tool_v2/CRealDatabaseItemModel.cpp new file mode 100644 index 00000000..6c4825b7 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDatabaseItemModel.cpp @@ -0,0 +1,82 @@ +#include "CRealDatabaseItemModel.h" + +CRealDatabaseItemModel::CRealDatabaseItemModel(const QStringList &tableHeader, QObject *parent) + : QAbstractTableModel(parent), + m_header(tableHeader) +{ + +} + +QVariant CRealDatabaseItemModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(Qt::DisplayRole == role && Qt::Horizontal == orientation) + { + return QVariant(m_header.at(section)); + } + return QVariant(); +} + +int CRealDatabaseItemModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return m_data.count(); +} + +int CRealDatabaseItemModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return m_header.count(); +} + +QVariant CRealDatabaseItemModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || index.row() >= m_data.count()) + return QVariant(); + + int column1 = index.column(); + int row1 = index.row(); + + if(Qt::TextAlignmentRole == role) + { + return QVariant(Qt::AlignLeft | Qt::AlignVCenter); + } + else if(Qt::DisplayRole == role) + { + return queryData(column1,row1); + } + return QVariant(); +} + +QVariant CRealDatabaseItemModel::queryData(int column, int row) const +{ + RealDatabasePtr ptr =m_data.at(row); + return ptr->getDataByColumn(column); +} + +void CRealDatabaseItemModel::clear() +{ + beginResetModel(); + m_data.clear(); + endResetModel(); +} + +void CRealDatabaseItemModel::setHead(QStringList listHead) +{ + m_header = listHead; +} + +void CRealDatabaseItemModel::setTable(QString tableName) +{ + +} + +void CRealDatabaseItemModel::slotDataRefresh(QList data) +{ + beginResetModel(); + m_data = data; + endResetModel(); +} diff --git a/product/src/tools/debug_tool_v2/CRealDatabaseItemModel.h b/product/src/tools/debug_tool_v2/CRealDatabaseItemModel.h new file mode 100644 index 00000000..5769d9cb --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDatabaseItemModel.h @@ -0,0 +1,34 @@ +#ifndef CREALDATABASEITEMMODEL_H +#define CREALDATABASEITEMMODEL_H + +#include +#include "CRealDatabaseItemInfo.h" +class CRealDatabaseItemModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + explicit CRealDatabaseItemModel(const QStringList &tableHeader, QObject *parent = nullptr); + + // Header: + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + + // Basic functionality: + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + QVariant queryData(int column,int row) const; + + void clear(); + void setHead(QStringList listHead); + void setTable(QString tableName); +public slots: + void slotDataRefresh(QList data); +private: + QStringList m_header; + QList m_data; +}; + +#endif // CREALDATABASEITEMMODEL_H diff --git a/product/src/tools/debug_tool_v2/CRealDatabaseSelect.cpp b/product/src/tools/debug_tool_v2/CRealDatabaseSelect.cpp new file mode 100644 index 00000000..a7b2071e --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDatabaseSelect.cpp @@ -0,0 +1,966 @@ +#include "CRealDatabaseSelect.h" +#include "ui_CRealDatabaseSelect.h" +#include +#include +#include "db_sysinfo_api/CDbSysInfo.h" + + +CRealDatabaseSelect::CRealDatabaseSelect(QWidget *parent) : + QWidget(parent), + ui(new Ui::CRealDatabaseSelect), + m_pSystemResources(NULL), + m_pObjDbInterface(NULL) +{ + ui->setupUi(this); + ui->comboBox_location->setView(new QListView()); + ui->comboBox_sub->setView(new QListView()); +// ui->listWidget_column->setHidden(true); +// ui->listWidget_tableName->setHidden(true); +// ui->label_2->setHidden(true); +// ui->label_3->setHidden(true); +// ui->checkBox_allColmn->setHidden(true); + ui->listWidget_column->setHidden(true); + ui->listWidget_tableName->setHidden(true); + ui->label_2->setHidden(true); + ui->label_3->setHidden(true); + ui->checkBox_allColmn->setHidden(true); + + + +} + +CRealDatabaseSelect::~CRealDatabaseSelect() +{ + releaseRsouces(); + delete ui; +} +//初始化整个的实时数据库现实页面 +bool CRealDatabaseSelect::initRealDb(CSystemResources *_p) +{ + if(!initVariable(_p)) + { + qDebug() << QString(tr("实时数据库选择初始化变量失败"))<comboBox_tableName->clear(); + int subId = ui->comboBox_sub->currentData().toInt(); + QStringList *pTableNameList = m_subIdToTableNameMap.value(subId); + QListWidgetItem *pItem; + if(NULL != pTableNameList) + { + for(int i = 0 ; i < pTableNameList->size(); ++i) + { + pItem = new QListWidgetItem(); + pItem->setText(m_tableNameDescMap[pTableNameList->at(i)]); + pItem->setData(Qt::UserRole+1,subId); + ui->listWidget_tableName->addItem(pItem); + } + }; + ui->comboBox_tableName->addItem("accuml",subId); + ui->comboBox_tableName->addItem("analog",subId); + ui->comboBox_tableName->addItem("digital",subId); + ui->comboBox_tableName->addItem("mix",subId); + ui->comboBox_tableName->addItem("fes_rtu_para",subId); + ui->comboBox_tableName->addItem("fes_channel_para",subId); + + +} +//选择表时对应的槽函数 +void CRealDatabaseSelect::slot_selectTable(QListWidgetItem * _item) +{ + //slot_checkBoxAllStateChanged(1); + QMap isShowOrHideMap; + isShowOrHideMap.clear(); + showColumns(_item,isShowOrHideMap); + showTable(_item,isShowOrHideMap); + QMap::iterator it = isShowOrHideMap.begin(); + while (it != isShowOrHideMap.end()) { + int state = 0; + if(it.value()) + { + state = 1; + } + emit signal_showOrHideColumn(it.key(),state); + it++; + } +} + +void CRealDatabaseSelect::slot_checkBoxAllStateChanged(int state) +{ + qDebug() << "state:"<listWidget_column->count(); + for(int i = 0; i < columnCount; ++i) + { + item = ui->listWidget_column->item(i); + box = (QCheckBox*)ui->listWidget_column->itemWidget(item); + box->setChecked(flag); + } +} + +void CRealDatabaseSelect::slot_columnCheckBoxStateChanged(int state) +{ + Q_UNUSED(state); + int nColumn = ((QCheckBox *)QObject::sender())->objectName().toInt(); +// emit signal_showOrHideColumn(nColumn,state); +} + +void CRealDatabaseSelect::slot_selectTable(int) +{ + + if(ui->comboBox_location->currentData().toInt() < 0) + { + return ; + } + if(ui->listWidget_tableName->currentItem()) + { + QMap isShowOrHideMap; + isShowOrHideMap.clear(); + showColumns(ui->listWidget_tableName->currentItem(),isShowOrHideMap); + showTable(ui->listWidget_tableName->currentItem(),isShowOrHideMap); + QMap::iterator it = isShowOrHideMap.begin(); + while (it != isShowOrHideMap.end()) { + int state = 0; + if(it.value()) + { + state = 1; + } + emit signal_showOrHideColumn(it.key(),state); + it++; + } + } + //showTable(ui->comboBox_tableName->currentText().toStdString()); + if(ui->comboBox_tableName->currentText()=="fes_rtu_para"||ui->comboBox_tableName->currentText()=="fes_channel_para") + { + QTreeWidgetItemIterator it(ui->treeWidget_device); + while(*it){ + (*it)->setHidden(true); + it++; + } + } + else + { + QTreeWidgetItemIterator it(ui->treeWidget_device); + while(*it){ + (*it)->setHidden(false); + it++; + } + } +} + +//初始化成员变量 +bool CRealDatabaseSelect::initVariable(CSystemResources *_p) +{ + if(!initSystemResources(_p)) + { + qDebug() << "系统资源指针失败"<getDbInterface(); + if(NULL == m_pObjDbInterface ) + { + qDebug() << "初始化系统资源失败" <execute(strSql,ret); + if(ret.isActive()) + { + int locationId = -1; + int domainId =-1; + QString locationDesc; + while(ret.next()) + { + locationId = ret.value("LOCATION_ID").toInt(); + locationDesc = ret.value("DESCRIPTION").toString(); + domainId = ret.value("DOMAIN_ID").toInt(); + m_mapLocationToDomain[locationId] = domainId; + m_mapLocationIdToDesc[locationId] = locationDesc; + } + return true; + } + else + { + return false; + } +} + +bool CRealDatabaseSelect::initSubToApp() +{ + m_mapSubToApp.clear(); + if(NULL == m_pObjDbInterface) + { + return false; + } + QSqlQuery ret; + QString strSql = "SELECT APP_ID,SUB_SYSTEM FROM sys_model_app_info ORDER BY APP_ID"; + m_pObjDbInterface->execute(strSql,ret); + if(ret.isActive()) + { + int appId = -1; + + while(ret.next()) + { + + appId = ret.value("APP_ID").toInt(); + QString subArray = ret.value("SUB_SYSTEM").toString(); + QStringList subList = subArray.split(","); + for(int index(0);index CN_AppId_COMAPP) + { + m_mapSubToApp[subId] = appId; + } + } + } + return true; + } + else + { + return false; + } + +} + +//初始化一个专业ID(subSystemId)对应描述 +bool CRealDatabaseSelect::initMapSubSystemIdToDesc() +{ + m_mapSubSystemIdToDesc.clear(); + if(NULL == m_pObjDbInterface) + { + return false; + } + QSqlQuery ret; + QString strSql = "SELECT SUB_SYSTEM_ID,DESCRIPTION FROM sys_model_sub_system_info ORDER BY SUB_SYSTEM_ID"; + m_pObjDbInterface->execute(strSql,ret); + if(ret.isActive()) + { + int subId = -1; + QString subDesc; + while(ret.next()) + { + subId = ret.value("SUB_SYSTEM_ID").toInt(); + subDesc = ret.value("DESCRIPTION").toString(); + + if(subId >CN_AppId_COMAPP) + { + m_mapSubSystemIdToDesc.insert(subId,subDesc); + } + } + return true; + } + else + { + return false; + } +} +//初始化应用包含哪些表的map +bool CRealDatabaseSelect::initMapSubIdToTableName() +{ + //由于关系库删除rt_开头的表,所以此处需要改动(jxd,2020-4-1) + foreach (int subId, m_mapSubSystemIdToDesc.keys()) { + std::vector tableVec; + if(!CDbSysInfo::getAllRdbTableNameBySubsystemId(subId,tableVec)) + { + LOGERROR("获取应用[%d]下的表失败!",subId); + return false; + }else + { + QMap::iterator it = m_subIdToTableNameMap.find(subId); + if(it == m_subIdToTableNameMap.end()) + { + m_subIdToTableNameMap.insert(subId,new QStringList); + } + + for(int index(0);indexappend(tabName); + } + } + } + return true; +} +//初始化MapTableInfo +bool CRealDatabaseSelect::initMapTableInfo() +{ + //由于关系库删除rt_开头的表,所以此处需要改动(jxd,2020-4-1) + foreach (QString tableName, m_tableNameDescMap.keys()) { + std::vector verColumnName; + std::string tabName = tableName.toStdString(); + if(!CDbSysInfo::getAllRdbColumnNameByTableName(tabName,verColumnName)) + { + LOGERROR("获取表[%s]字段信息失败!",tableName.toStdString().c_str()); + return false; + }else + { + m_mapTableInfo.insert(tableName,new QVector); + + for(int index(0);indexinsert(2,name.toLower()); + } + else if((tableName=="accuml"||tableName=="analog"||tableName=="digital"||tableName=="mix")&&name=="STATUS") + { + + m_mapTableInfo.value(tableName)->insert(3,name.toLower()); + } + else if((tableName=="fes_rtu_para"||tableName=="fes_channel_para")&&name=="STATUS") + { + m_mapTableInfo.value(tableName)->insert(3,name.toLower()); + } + else + { + m_mapTableInfo.value(tableName)->append(name.toLower()); + } + QHash >::iterator it =m_mapTableColumnDesc.find(tableName); + if(it ==m_mapTableColumnDesc.end()) + { + QMap map; + map.insert(name.toLower(),desc); + m_mapTableColumnDesc.insert(tableName,map); + }else + { + it.value().insert(name.toLower(),desc); + } + } + } + } + return true; +} +//连接信号和槽函数 +void CRealDatabaseSelect::initSignalAndSlot() +{ + connect(ui->comboBox_sub,SIGNAL(currentIndexChanged(int)), + this,SLOT(slot_selectSub(int))); + + connect(ui->listWidget_tableName,SIGNAL(itemClicked(QListWidgetItem*)), + this,SLOT(slot_selectTable(QListWidgetItem*))); + // connect(ui->comboBox_tableName,SIGNAL(currentIndexChanged(int),this,SLOT(slot_selectTable(int))); + // connect(ui->checkBox_allColmn,SIGNAL(stateChanged(int)), + //this,SLOT(slot_checkBoxAllStateChanged(int))); + connect(ui->comboBox_location,SIGNAL(currentIndexChanged(int)),this,SLOT(slot_selectTable(int))); + connect(ui->comboBox_location,SIGNAL(currentIndexChanged(int)),this,SLOT(slot_selectTreeGevice(int))); + connect(ui->comboBox_sub,SIGNAL(currentIndexChanged(int)),this,SLOT(slot_selectTreeGevice(int))); + connect(ui->comboBox_tableName,SIGNAL(currentIndexChanged(int)),this,SLOT(slot_selectListWidget(int))); + connect(ui->treeWidget_device,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(solt_showPoint(QTreeWidgetItem*,int))); + connect(ui->lineEdit_devgroup,SIGNAL(textChanged(QString)),this,SLOT(solt_showTreeWidget(QString))); + +} + + +void CRealDatabaseSelect::initView() +{ + initSubInfo(); +} + +void CRealDatabaseSelect::initLocationInfo() +{ + QMap::iterator it; + int locationId; + QString locationDesc; + for(it = m_mapLocationIdToDesc.begin(); it != m_mapLocationIdToDesc.end() ; ++it) + { + locationId = it.key(); + locationDesc = it.value(); + ui->comboBox_location->addItem(locationDesc,locationId); + } +} + +void CRealDatabaseSelect::initSubInfo() +{ + QMap::iterator it; + int subId; + QString subDesc; + for(it = m_mapSubSystemIdToDesc.begin(); it != m_mapSubSystemIdToDesc.end() ; ++it) + { + subId = it.key(); + subDesc = it.value(); + ui->comboBox_sub->addItem(subDesc,subId); + } +} +//初始化列信息 +void CRealDatabaseSelect::initColumnInfo() +{ + ui->checkBox_allColmn->setChecked(false); +} +//释放一些资源,NEW 出来的内存 +void CRealDatabaseSelect::releaseRsouces() +{ + QMap::iterator it; + for(it = m_subIdToTableNameMap.begin(); it != m_subIdToTableNameMap.end(); ++it) + { + delete it.value(); + } + + QMap *>::iterator tableInfoIt; + for(tableInfoIt = m_mapTableInfo.begin(); tableInfoIt != m_mapTableInfo.end() ; ++tableInfoIt) + { + delete tableInfoIt.value(); + } +} +//展示一个表的列 +void CRealDatabaseSelect::showColumns(QListWidgetItem *_item,QMap &isShowOrHideMap) +{ + + ui->checkBox_allColmn->setChecked(true); + QListWidgetItem *tableItem = _item; + ui->listWidget_column->clear(); + QString tableName = m_tableNameDescMap.key(tableItem->text()); + bool isPointTable = false; + if(tableName == "analog" || tableName == "digital" || + tableName == "mix" || tableName == "accuml") + { + isPointTable =true; + } + + if(m_mapTableInfo.end() != m_mapTableInfo.find(tableName)) + { + QVector *p = m_mapTableInfo.value(tableName); + QVector::iterator it; + int i = 0; + for(it = p->begin(); it != p->end();++it,++i) + { + QListWidgetItem *columnItem = new QListWidgetItem(); + QCheckBox *box = new QCheckBox(*it,ui->listWidget_column); + box->setToolTip(m_mapTableColumnDesc.value(tableName).value(*it)); + box->setObjectName(QString::number(i)); + box->setCheckable(true); + + if(isPointTable) + { + if((*it)== "tag_name" || (*it)== "description" || + (*it)== "device" || (*it)== "value" || (*it)=="seq_no" || (*it)=="rtu_tag" || (*it)== "status") + { + isShowOrHideMap[i] = true; + box->setChecked(true); + }else + { + isShowOrHideMap[i] = true; + box->setChecked(false); + } + }else + { + isShowOrHideMap[i] = true; + box->setChecked(true); + } + + ui->listWidget_column->addItem(columnItem); + ui->listWidget_column->setItemWidget(columnItem,box); + //connect(box,SIGNAL(stateChanged(int)), + //this,SLOT(slot_columnCheckBoxStateChanged(int))); + } + } +} + +void CRealDatabaseSelect::showTable(QListWidgetItem *_item, QMap &isShowOrHideMap) +{ + QListWidgetItem *tableItem = _item; + int subId = ui->comboBox_sub->currentData().toInt(); + int locationId = ui->comboBox_location->currentData().toInt(); + int domainId = m_mapLocationToDomain.value(locationId); + int appId = m_mapSubToApp.value(subId); + QString tableName = m_tableNameDescMap.key(tableItem->text()); + if(m_mapTableInfo.end() != m_mapTableInfo.find(tableName)) + { + QVector *p = m_mapTableInfo.value(tableName); + emit signal_showTable(tableName,p,domainId,locationId,appId,subId,isShowOrHideMap); //哪张表,有哪些列(指针),应用ID + } +} + +void CRealDatabaseSelect::showTable(QString tableName) +{ + Q_UNUSED(tableName); + /* + int subId = ui->comboBox_sub->currentData().toInt(); + int locationId = ui->comboBox_location->currentData().toInt(); + int domainId = m_mapLocationToDomain.value(locationId); + int appId = m_mapSubToApp.value(subId); + if(m_mapTableInfo.end() != m_mapTableInfo.find(tableName)) + { + QVector *p = m_mapTableInfo.value(tableName); + //emit signal_showTable(); + } + */ +} +void CRealDatabaseSelect::slot_selectTreeGevice(int) +{ + uint locationId = ui->comboBox_location->currentData().toUInt(); + uint subSystemId = ui->comboBox_sub->currentData().toUInt(); + ui->treeWidget_device->clear(); +// QTreeWidgetItem *firstItem=new QTreeWidgetItem(); +// firstItem->setText(0,ui->comboBox_location->currentText()); +// ui->treeWidget_devGroup->addTopLevelItem(firstItem); + QSqlQuery devGroupTable; + devGroupTable.clear(); + QString sqlStr = QString("SELECT a.DESCRIPTION dev_group_name,b.DESCRIPTION device_name, b.tag_name allName,b.GROUP_TAG_NAME GROUP_TAG_NAME," + " b.TAG_NAME tga_name,a.LOCATION_ID location_id,a.SUB_SYSTEM sub_system FROM dev_group a,dev_info b" + " where a.LOCATION_ID= %1 and a.SUB_SYSTEM= %2 and " + "a.TAG_NAME =b.GROUP_TAG_NAME order by a.DESCRIPTION ").arg(locationId).arg(subSystemId); + m_pObjDbInterface->execute(sqlStr, devGroupTable); + if(devGroupTable.isActive()) + { + + QVariant val; + val.clear(); + QString dev_group_name =""; + QString device_name = ""; + QString lastDevGroupName=""; + QString tag_name=""; + QString location_id=""; + QString sub_system=""; + QString allName=""; + QString group_tag_name=""; + QTreeWidgetItem *lastItem=new QTreeWidgetItem(); + + while(devGroupTable.next()) + { + val = devGroupTable.value("dev_group_name"); + dev_group_name = val.toString(); + val = devGroupTable.value("GROUP_TAG_NAME"); + group_tag_name = val.toString(); + val = devGroupTable.value("device_name"); + device_name = val.toString(); + val = devGroupTable.value("tga_name"); + tag_name = val.toString(); + val = devGroupTable.value("location_id"); + location_id = val.toString(); + val = devGroupTable.value("sub_system"); + sub_system = val.toString(); + val = devGroupTable.value("allName"); + allName = val.toString(); + if(lastDevGroupName!=dev_group_name){ + QTreeWidgetItem *nodeItem = new QTreeWidgetItem(ui->treeWidget_device); + nodeItem->setText(0,dev_group_name); + nodeItem->setData(0,Qt::UserRole+1,group_tag_name); + nodeItem->setSelected(false); + QTreeWidgetItem *childItem = new QTreeWidgetItem(nodeItem); + childItem->setText(0,device_name); + childItem->setData(0,Qt::UserRole+1,tag_name); + childItem->setData(0,Qt::UserRole+2,location_id); + childItem->setData(0,Qt::UserRole+3,sub_system); + childItem->setData(0,Qt::UserRole+4,allName); + lastDevGroupName=dev_group_name; + lastItem=nodeItem; + } + else{ + QTreeWidgetItem *childItem = new QTreeWidgetItem(lastItem); + childItem->setText(0,device_name); + childItem->setData(0,Qt::UserRole+1,tag_name); + childItem->setData(0,Qt::UserRole+2,location_id); + childItem->setData(0,Qt::UserRole+3,sub_system); + childItem->setData(0,Qt::UserRole+4,allName); + } + + } + } + ui->treeWidget_device->setCurrentItem(ui->treeWidget_device->topLevelItem(0)); + if(ui->comboBox_tableName->currentText()=="fes_rtu_para"||ui->comboBox_tableName->currentText()=="fes_channel_para") + { + QTreeWidgetItem *a=new QTreeWidgetItem; + solt_showPoint(a,0); + QTreeWidgetItemIterator it(ui->treeWidget_device); + while(*it){ + (*it)->setHidden(true); + it++; + } + } + else + { + QTreeWidgetItemIterator it(ui->treeWidget_device); + while(*it){ + (*it)->setHidden(false); + it++; + } + } +} + +void CRealDatabaseSelect::slot_selectListWidget(int) +{ + + if(ui->comboBox_tableName->currentText()=="fes_rtu_para"||ui->comboBox_tableName->currentText()=="fes_channel_para") + { + QTreeWidgetItemIterator it(ui->treeWidget_device); + while(*it){ + (*it)->setHidden(true); + it++; + } + } + else + { + QTreeWidgetItemIterator it(ui->treeWidget_device); + while(*it){ + (*it)->setHidden(false); + it++; + } + } + QMap isShowOrHideMap; + int subId = ui->comboBox_sub->currentData().toInt(); + int locationId = ui->comboBox_location->currentData().toInt(); + int domainId = m_mapLocationToDomain.value(locationId); + int appId = m_mapSubToApp.value(subId); + QString tableName = m_tableNameDescMap.key(ui->comboBox_tableName->currentText()); + if(m_mapTableInfo.end() != m_mapTableInfo.find(tableName)) + { + QVector *p = m_mapTableInfo.value(tableName); + if(ui->treeWidget_device->topLevelItemCount()>1) + { + if(ui->treeWidget_device->currentItem()->childCount()>0) + { + QString devGroupName=ui->treeWidget_device->currentItem()->data(0,Qt::UserRole+1).toString(); + QString deviceName="all"; + emit signal_showTable(tableName,p,domainId,locationId,appId,subId,isShowOrHideMap,devGroupName,deviceName); + } + else + { + QString devGroupName=ui->treeWidget_device->currentItem()->parent()->data(0,Qt::UserRole+1).toString(); + QString deviceName=ui->treeWidget_device->currentItem()->data(0,Qt::UserRole+4).toString(); + + emit signal_showTable(tableName,p,domainId,locationId,appId,subId,isShowOrHideMap,devGroupName,deviceName); + } + } + emit signal_showTable(tableName,p,domainId,locationId,appId,subId,isShowOrHideMap); //哪张表,有哪些列(指针),应用ID + + } +} + +void CRealDatabaseSelect::solt_showPoint(QTreeWidgetItem *, int) +{ + QMap isShowOrHideMap; + int subId = ui->comboBox_sub->currentData().toInt(); + int locationId = ui->comboBox_location->currentData().toInt(); + int domainId = m_mapLocationToDomain.value(locationId); + int appId = m_mapSubToApp.value(subId); + QString tableName = m_tableNameDescMap.key(ui->comboBox_tableName->currentText()); + if(m_mapTableInfo.end() != m_mapTableInfo.find(tableName)) + { + QVector *p = m_mapTableInfo.value(tableName); + if(ui->treeWidget_device->topLevelItemCount()>1) + { + if(ui->treeWidget_device->currentItem()->childCount()>0) + { + QString devGroupName=ui->treeWidget_device->currentItem()->data(0,Qt::UserRole+1).toString(); + QString deviceName="all"; + emit signal_showTable(tableName,p,domainId,locationId,appId,subId,isShowOrHideMap,devGroupName,deviceName); + } + else + { + QString devGroupName=ui->treeWidget_device->currentItem()->parent()->data(0,Qt::UserRole+1).toString(); + QString deviceName=ui->treeWidget_device->currentItem()->data(0,Qt::UserRole+4).toString(); + emit signal_showTable(tableName,p,domainId,locationId,appId,subId,isShowOrHideMap,devGroupName,deviceName); + } + } + emit signal_showTable(tableName,p,domainId,locationId,appId,subId,isShowOrHideMap); //哪张表,有哪些列(指针),应用ID + + } +} + +void CRealDatabaseSelect::solt_showTreeWidget(QString) +{ + slot_selectTreeGevice(0); + QString keyWord = ui->lineEdit_devgroup->text().trimmed(); + QString tag_name = ui->lineEdit_devgroup->text(); + if(allSelect(tag_name)||preciseSelect()) + { + return; + } + QTreeWidgetItemIterator it(ui->treeWidget_device); + while(*it){ + (*it)->setHidden(false); + it++; + } +if(keyWord.isEmpty()) +{ + return; +} +else +{ + QTreeWidgetItemIterator itor(ui->treeWidget_device); + while(*itor){ + if((*itor)->text(0).contains(keyWord,Qt::CaseInsensitive)) + { + int k=(*itor)->childCount(); + for(int i=0;ichildCount(); + for(int i=0;ichild(i)->text(0).contains(keyWord,Qt::CaseInsensitive)) + { + childBool=1; + } + else + { + (*itor)->child(i)->setHidden(true); + } + } + if(childBool==false) + { + (*itor)->setHidden(true); + } + k=(*itor)->childCount(); + for(int i=0;ilistWidget_device->currentItem()->text(); + //QString devTagName = ui->listWidget_device->currentItem()->data(Qt::UserRole+1).toString(); + QString devDescription; + QString devTagName ; + QString descDevG ; + QString allName; + QString strSql1 = "select a.TAG_NAME allName,a.DESCRIPTION pointDescription,a.SEQ_NO,a.LOCATION_ID locationId," + "a.SUB_SYSTEM subSystemId ,a.RTU_TAG,a.device devTagName,di.DESCRIPTION devDescription,dg.DESCRIPTION descDevG " + "from "; + + QString strSql2 = QString(" a ,dev_info di ,dev_group dg where " + " a.TAG_NAME = ")+QString("'")+ tag_name+"' and" + " a.DEVICE =di.TAG_NAME and di.GROUP_TAG_NAME =dg.TAG_NAME "; + + uint rowCount = 0; + QSqlQuery pointTable; + for(int i = 0 ; i < 4; i++) + { + pointTable.clear(); + m_pObjDbInterface->execute(strSql1+tableNameList[i]+strSql2,pointTable); + if(pointTable.isActive()) + { + rowCount += pointTable.size(); + while(pointTable.next()) + { + pointBool=true; + locationId=pointTable.value("locationId").toInt(); + subSystemId=pointTable.value("subSystemId").toInt(); + allName=pointTable.value("allName").toString(); + pointDescription=pointTable.value("pointDescription").toString(); + descDevG=pointTable.value("descDevG").toString(); + devDescription=pointTable.value("devDescription").toString(); + pointTagName=allName; + tableName=tableNameList[i]; + point_type=pointType[i]; + devTagName=pointTable.value("devTagName").toString(); + } + } + } + if(pointBool==false){ + return false; + } + for(int k=0;kcomboBox_location->count();k++) + { + if(ui->comboBox_location->itemData(k).toInt()==locationId) + { + ui->comboBox_location->setCurrentIndex(k); + } + } + for(int k=0;kcomboBox_sub->count();k++) + { + if(ui->comboBox_sub->itemData(k).toInt()==subSystemId) + { + ui->comboBox_sub->setCurrentIndex(k); + } + } + for(int k=0;kcomboBox_tableName->count();k++) + { + if(ui->comboBox_tableName->itemText(k)==tableName) + { + ui->comboBox_tableName->setCurrentIndex(k); + } + } + ui->treeWidget_device->clear(); + slot_selectTreeGevice(0); + QString devGroupName=""; + QString deviceName=""; + QTreeWidgetItemIterator itor(ui->treeWidget_device); + + while(*itor){ + bool childNumber=false; + if((*itor)->text(0).contains(descDevG,Qt::CaseInsensitive)) + { + int itorCount=(*itor)->childCount(); + (*itor)->setHidden(false); + for(int i=0;ichild(i)->text(0).contains(devDescription,Qt::CaseInsensitive)) + { + devGroupName =(*itor)->child(i)->parent()->data(0,Qt::UserRole+1).toString(); + deviceName=(*itor)->child(i)->data(0,Qt::UserRole+4).toString(); + childNumber=true; + (*itor)->child(i)->setHidden(false); + } + else{ + + (*itor)->child(i)->setHidden(true); + } + + } + if(childNumber==false){ + (*itor)->setHidden(true); + } + for(int i=0;i<=itorCount;i++){ + itor++; + } + + continue; + } + + (*itor)->setHidden(true); + itor++; + } + QVector *p = m_mapTableInfo.value(tableName); + int subId = ui->comboBox_sub->currentData().toInt(); + int domainId = m_mapLocationToDomain.value(locationId); + int appId = m_mapSubToApp.value(subId); + QMap isShowOrHideMap; + emit signal_showTable(tableName,p,domainId,locationId,appId,subId,isShowOrHideMap,devGroupName,deviceName); + return true; +} + +bool CRealDatabaseSelect::preciseSelect() +{ + QStringList devTagSplit; + QString analogTableName = "ANALOG"; + QString digitalTableName = "DIGITAL"; + QString accumlTableName = "ACCUML"; + QString mixTableName = "MIX"; + QString currTextEdit=ui->lineEdit_devgroup->text(); + devTagSplit=currTextEdit.split("."); + for(int i=0;i +#include +#include +#include "CSystemResources.h" +#include "toolCommon.h" +#include + +namespace Ui { +class CRealDatabaseSelect; +} + +class CRealDatabaseSelect : public QWidget +{ + Q_OBJECT + +public: + explicit CRealDatabaseSelect(QWidget *parent = 0); + ~CRealDatabaseSelect(); + bool initRealDb(CSystemResources *_p); + +private slots: + void slot_selectSub(int _index); + void slot_selectTable(QListWidgetItem *); + void slot_checkBoxAllStateChanged(int state); + void slot_columnCheckBoxStateChanged(int state); + void slot_selectTable(int); + void slot_selectTreeGevice(int); + void slot_selectListWidget(int); + void solt_showPoint(QTreeWidgetItem*,int); + void solt_showTreeWidget(QString); +signals: + void signal_showTable(QString, QVector *,int,int,int,int,QMap,QString,QString); + void signal_showTable(QString, QVector *,int,int,int,int,QMap); + void signal_showOrHideColumn(int nColumn,int state); + + +private: + bool initVariable(CSystemResources *_p); + bool initSystemResources(CSystemResources *_p); + bool initDbInterface(); + //bool initMapAppIdToAppTag(); + + bool initMapLocation(); + bool initSubToApp(); + bool initMapSubSystemIdToDesc(); + bool initMapSubIdToTableName(); + bool initMapTableInfo(); + + + + bool preciseSelect(); + bool allSelect(QString tag_name); + void initSignalAndSlot(); + void initView(); + void initLocationInfo(); + void initSubInfo(); + void initColumnInfo(); + + void releaseRsouces(); + + void showColumns(QListWidgetItem *, QMap &isShowOrHideMap); + void showTable(QListWidgetItem *,QMap &isShowOrHideMap); + void showTable(QString); + +private: + + CSystemResources *m_pSystemResources; + iot_dbms::CDbApi *m_pObjDbInterface; + + QMap m_mapAppIdToAppTag; //<- 应用ID和应用名 + QMap m_mapAppTagToAppDesc; //<- 应用名和应用描述 + QMap m_mapLocationToDomain; //车站id和域id + QMap m_mapSubToApp; //专业id和应用id + QMap m_mapLocationIdToDesc; //<- 车站 + QMap m_mapSubSystemIdToDesc; //<- 子系统ID和描述 + QMap m_subIdToTableNameMap; //<- 这个专业ID下有哪些表 + QMap *> m_mapTableInfo; //<- 每一张表的信息,包括这张表的所有列名和其数据类型 + QHash > m_mapTableColumnDesc; // + QMap m_tableNameDescMap; //表名和表描述 + Ui::CRealDatabaseSelect *ui; +}; + +#endif // CREALDATABASESELECT_H diff --git a/product/src/tools/debug_tool_v2/CRealDatabaseSelect.ui b/product/src/tools/debug_tool_v2/CRealDatabaseSelect.ui new file mode 100644 index 00000000..13380c58 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDatabaseSelect.ui @@ -0,0 +1,247 @@ + + + CRealDatabaseSelect + + + + 0 + 0 + 524 + 706 + + + + + 200 + 0 + + + + Form + + + + + + + + + 45 + 23 + + + + + 45 + 23 + + + + 位置 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 45 + 23 + + + + + 45 + 23 + + + + 专业 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 45 + 23 + + + + + 45 + 23 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + 设备组 + + + + + + + + 4 + + + + + + + + 45 + 23 + + + + + 45 + 23 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + 4 + + + + + + + + 45 + 23 + + + + + 45 + 23 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 所有列 + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CRealDatabaseShow.cpp b/product/src/tools/debug_tool_v2/CRealDatabaseShow.cpp new file mode 100644 index 00000000..039a28c0 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDatabaseShow.cpp @@ -0,0 +1,1195 @@ +#include "CRealDatabaseShow.h" +#include "ui_CRealDatabaseShow.h" +#include +#include +#include "pub_widget/MessageBox.h" +#include "rdb_api/RdbDefine.h" +#include "CRealDatabaseItemModel.h" + +using namespace iot_public; +using namespace iot_idl; + +CRealDatabaseShow::CRealDatabaseShow(QWidget *parent) : + QWidget(parent), + m_bLocationFilter(false), + m_bDevFilter(false), + m_bSubFilter(false), + m_bFesDevFilter(false), + m_bRtuFilter(false), + ui(new Ui::CRealDatabaseShow), + m_pVecTableInfo(NULL), + m_pSystemResources(NULL), + m_model(Q_NULLPTR), + m_rdbThread(Q_NULLPTR), + m_worker(Q_NULLPTR), + m_canSearch(true), + m_searchDialog(NULL) +{ + ui->setupUi(this); + qRegisterMetaType< QList >("ListRealDatabasePtr"); + qRegisterMetaType("iot_idl::RdbQuery"); + qRegisterMetaType("iot_idl::RdbRet"); + m_nsubId = -2; + m_nDomainId = -2; + m_nlocationId = -2; + m_nappId = -2; + //ui->comboBox_devGroup->setView(new QListView()); +// ui->comboBox_device->setView(new QListView()); +// ui->comboBox_rtu->setView(new QListView()); +// ui->comboBox_fesDev->setView(new QListView()); + ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + + m_timer = new QTimer(); + m_timer->setInterval(1000); + + connect(this, &CRealDatabaseShow::sigTimerShot, this, &CRealDatabaseShow::slotTimerShot); + m_rdbThread = new QThread; + m_worker = new CRdbWorker; + m_worker->moveToThread(m_rdbThread); + connect(m_timer,&QTimer::timeout,this,&CRealDatabaseShow::auto_brush); + connect(m_worker,&CRdbWorker::sigAutoSearch,this,&CRealDatabaseShow::slotAutoResult); + connect(m_worker,&CRdbWorker::sigNotAutoSearch,this,&CRealDatabaseShow::slotNotAutoResult); + connect(this,&CRealDatabaseShow::sigSearch,m_worker,&CRdbWorker::search,Qt::QueuedConnection); + connect(ui->statusSearch,&QPushButton::clicked,this,&CRealDatabaseShow::statusSearch); + connect(ui->tableView,&QTableView::clicked,this,&CRealDatabaseShow::showStatus); + m_rdbThread->start(); + ui->statusSearch->setHidden(true); + + + +} + +CRealDatabaseShow::~CRealDatabaseShow() +{ + sigTimerShot(false); + if(m_timer) + { + m_timer->stop(); + m_timer->deleteLater(); + } + if(m_worker) + { + delete m_worker; + } + m_worker = NULL; + if(m_rdbThread) + { + m_rdbThread->quit(); + m_rdbThread->wait(); + } + + releaseRsouces(); + delete ui; +} + +/*这个类的初始化*/ +bool CRealDatabaseShow::initRealDatabaseShow(CSystemResources *_p) +{ + if(!initVariable(_p)) + { + qDebug() << "初始化变量失败"<getDbInterface(); + return true; + } +} + +/*内存库接口的初始化*/ +bool CRealDatabaseShow::initNetRdbApi() +{ + return true; +} + +bool CRealDatabaseShow::initMapLocationIdDesc() +{ + if(NULL == m_pObjDbInterface) + { + return false; + } + QSqlQuery columnInfoRet ; + QString strSql = "SELECT LOCATION_ID,DESCRIPTION FROM sys_model_location_info"; + m_pObjDbInterface->execute(strSql,columnInfoRet); + if(columnInfoRet.isActive()) + { + int locationId; + QString desc; + while(columnInfoRet.next()) + { + locationId = columnInfoRet.value("LOCATION_ID").toInt(); + desc = columnInfoRet.value("DESCRIPTION").toString(); + m_locationIdDescMap[locationId] = desc; + } + return true; + } + else + { + return false; + } +} + +bool CRealDatabaseShow::initMapLocSubDevGInfo() +{ + m_locSubDevGMap.clear(); + m_devGDescMap.clear(); + if(NULL == m_pObjDbInterface) + { + return false; + } + QSqlQuery columnInfoRet ; + QString strSql = "SELECT TAG_NAME,DESCRIPTION,LOCATION_ID,SUB_SYSTEM FROM dev_group"; + m_pObjDbInterface->execute(strSql,columnInfoRet); + if(columnInfoRet.isActive()) + { + QString tagName; + QString desc; + int subSystem = -1; + int locationId = -1; + while(columnInfoRet.next()) + { + tagName = columnInfoRet.value("TAG_NAME").toString(); + desc = columnInfoRet.value("DESCRIPTION").toString(); + subSystem = columnInfoRet.value("SUB_SYSTEM").toInt(); + locationId = columnInfoRet.value("LOCATION_ID").toInt(); + QString locationSub = QString::number(locationId)+"."+QString::number(subSystem); + QMap >::iterator it= m_locSubDevGMap.find(locationSub); + if(it != m_locSubDevGMap.end()) + { + it.value().append(tagName); + }else + { + QVector devGVec; + devGVec.append(tagName); + m_locSubDevGMap[locationSub] = devGVec; + } + if(desc == "") + { + m_devGDescMap[tagName] = tagName; + }else + { + m_devGDescMap[tagName] = desc; + } + } + return true; + } + else + { + return false; + } +} + +bool CRealDatabaseShow::initMapLocSubRtuInfo() +{ + m_locSubRtuMap.clear(); + m_rtuDescMap.clear(); + if(NULL == m_pObjDbInterface) + { + return false; + } + QSqlQuery columnInfoRet ; + QString strSql = "SELECT TAG_NAME,RTU_NAME,LOCATION_ID,SUB_SYSTEM FROM fes_rtu_para"; + m_pObjDbInterface->execute(strSql,columnInfoRet); + if(columnInfoRet.isActive()) + { + QString tagName; + QString desc; + int subSystem = -1; + int locationId = -1; + while(columnInfoRet.next()) + { + tagName = columnInfoRet.value("TAG_NAME").toString(); + desc = columnInfoRet.value("RTU_NAME").toString(); + subSystem = columnInfoRet.value("SUB_SYSTEM").toInt(); + locationId = columnInfoRet.value("LOCATION_ID").toInt(); + QString locationSub = QString::number(locationId)+"."+QString::number(subSystem); + QMap >::iterator it= m_locSubRtuMap.find(locationSub); + if(it != m_locSubRtuMap.end()) + { + it.value().append(tagName); + }else + { + QVector rtuVec; + rtuVec.append(tagName); + m_locSubRtuMap[locationSub] = rtuVec; + } + if(desc == "") + { + m_rtuDescMap[tagName] = tagName; + }else + { + m_rtuDescMap[tagName] = desc; + } + } + return true; + } + else + { + return false; + } +} + +bool CRealDatabaseShow::initMapDevGDevInfo() +{ + m_devGDevMap.clear(); + if(NULL == m_pObjDbInterface) + { + return false; + } + QSqlQuery columnInfoRet ; + QString strSql = "SELECT TAG_NAME,DESCRIPTION,GROUP_TAG_NAME FROM dev_info"; + m_pObjDbInterface->execute(strSql,columnInfoRet); + if(columnInfoRet.isActive()) + { + QString tagName; + QString desc; + QString groupName; + while(columnInfoRet.next()) + { + tagName = columnInfoRet.value("TAG_NAME").toString(); + desc = columnInfoRet.value("DESCRIPTION").toString(); + groupName = columnInfoRet.value("GROUP_TAG_NAME").toString(); + QMap >::iterator it = m_devGDevMap.find(groupName); + if(it != m_devGDevMap.end()) + { + it.value().append(tagName); + + }else + { + QVector vec; + vec.append(tagName); + m_devGDevMap[groupName] = vec; + } + if(desc == "") + { + m_devDescMap[tagName] = tagName; + }else + { + m_devDescMap[tagName] = desc; + } + } + return true; + } + else + { + return false; + } +} + +bool CRealDatabaseShow::initMapRtuFesDevInfo() +{ + m_rtuFesDevMap.clear(); + m_fesDevDescMap.clear(); + if(NULL == m_pObjDbInterface) + { + return false; + } + QSqlQuery columnInfoRet ; + QString strSql = "SELECT TAG_NAME,DEV_NAME,RTU_TAG FROM fes_dev_info"; + m_pObjDbInterface->execute(strSql,columnInfoRet); + if(columnInfoRet.isActive()) + { + QString tagName; + QString desc; + QString rtuTag; + while(columnInfoRet.next()) + { + tagName = columnInfoRet.value("TAG_NAME").toString(); + desc = columnInfoRet.value("DEV_NAME").toString(); + rtuTag = columnInfoRet.value("RTU_TAG").toString(); + QMap >::iterator it = m_rtuFesDevMap.find(rtuTag); + if(it != m_rtuFesDevMap.end()) + { + it.value().append(tagName); + + }else + { + QVector vec; + vec.append(tagName); + m_rtuFesDevMap[rtuTag] = vec; + } + if(desc == "") + { + m_fesDevDescMap[tagName] = tagName; + }else + { + m_fesDevDescMap[tagName] = desc; + } + } + return true; + } + else + { + return false; + } +} + +/*信号和槽函数的连接*/ +void CRealDatabaseShow::initSignalAndSlot() +{ + //connect(ui->comboBox_devGroup,SIGNAL(currentIndexChanged(int)), + //this,SLOT(slot_filterDevg(int ))); +// connect(ui->comboBox_device,SIGNAL(currentIndexChanged(int)), +// this,SLOT(slot_filterDev(int))); +// connect(ui->comboBox_rtu,SIGNAL(currentIndexChanged(int)), +// this,SLOT(slot_filterRtu(int ))); +// connect(ui->comboBox_fesDev,SIGNAL(currentIndexChanged(int)), +// this,SLOT(slot_filterFesDev(int))); + + +} + +/*界面的初始化*/ +void CRealDatabaseShow::initView() +{ + hideDevGroup(); + hideDev(); + hideRtu(); + hideFesDev(); +} + +void CRealDatabaseShow::releaseRsouces() +{ + +} + + +void CRealDatabaseShow::slotTimerShot(const bool start) +{ + if(m_timer) + { + if(start) + { + m_timer->start(); + } + else + { + m_timer->stop(); + } + } +} + +//对表格的第row行第column列进行填写 +void CRealDatabaseShow::setItemData(int &row, int &column, const iot_idl::SVariable &sVariable) +{ + QTableWidgetItem *item = new QTableWidgetItem; + switch (sVariable.edatatype()) + { + case iot_idl::DataType::CN_DATATYPE_BOOL: + item->setText(QString::number(sVariable.bvalue())); + break; + case iot_idl::DataType::CN_DATATYPE_FLOAT: + item->setText(QString::number(sVariable.fvalue())); + break; + case iot_idl::DataType::CN_DATATYPE_INT32: + item->setText(QString::number(sVariable.nvalue())); + break; + case iot_idl::DataType::CN_DATATYPE_STRING: + { + item->setText(QString::fromStdString(sVariable.strvalue())); + QString name = QString::fromStdString(sVariable.strvalue()); + break; + } + case iot_idl::DataType::CN_DATATYPE_UINT32: + item->setText(QString::number(sVariable.uvalue())); + break; + case iot_idl::DataType::CN_DATATYPE_INT64: + item->setText(QString::number(sVariable.lvalue())); + break; + case iot_idl::DataType::CN_DATATYPE_UINT64: + item->setText(QString::number(sVariable.ulvalue())); + break; + case iot_idl::DataType::CN_DATATYPE_DOUBLE: + item->setText(QString::number(sVariable.dvalue())); + break; + default: + qDebug() << "other value Type" <tableWidget_showTable->setItem(row,column,item); +} + +void CRealDatabaseShow::slot_showTable(QString _tableName , QVector *_p, int _domainId, int _locationId, int _appId, int _subId,QMap isLineShow,QString devGroupName,QString deviceName) +{ + emit sigTimerShot(false); //停止定时器 + m_strTableName = _tableName; + m_pVecTableInfo = _p; + m_nsubId = _subId; + m_nDomainId = _domainId; + m_nlocationId = _locationId; + m_nappId = _appId; + m_devGroupName=devGroupName; + m_deviceName=deviceName; + //此处逻辑 先判断是否有车站 然后判断是否有专业,如果没有专业则不判断设备 + initFilter(); +// ui->comboBox_devGroup->blockSignals(true); +// ui->comboBox_device->blockSignals(true); +// ui->comboBox_rtu->blockSignals(true); +// ui->comboBox_fesDev->blockSignals(true); +// initComboxDevG(); +// initComboxDevice(); +// initComboxRtu(); +// initComboxFesDev(); +// ui->comboBox_devGroup->blockSignals(false); +// ui->comboBox_device->blockSignals(false); +// ui->comboBox_rtu->blockSignals(false); +// ui->comboBox_fesDev->blockSignals(false); + search(); + + +} +//显示或者隐藏某列 +void CRealDatabaseShow::slot_showOrHindColumn(int nColumn, int state) +{ + + bool isHide =false; + if( state == 0 ) + { + isHide = true; + } + if(m_strTableName != "analog" && m_strTableName != "digital" && + m_strTableName != "mix" && m_strTableName != "accuml") + { + ui->tableWidget_showTable->setColumnHidden(nColumn,isHide); + } + else + { + ui->tableView->setColumnHidden(nColumn,isHide); + } +} + +//通过subSystem和device过滤记录 +void CRealDatabaseShow::initComboxDevG() +{ + return; + //ui->comboBox_devGroup->clear(); + if(m_bDevFilter == true) + { + QString locationSub = QString::number(m_nlocationId)+"."+QString::number(m_nsubId); + QMap >::iterator it = m_locSubDevGMap.find(locationSub); + if(it != m_locSubDevGMap.end()) + { + QVector & devGVec = it.value(); + if(devGVec.size()>0) + { + foreach (QString devG, devGVec) { + // ui->comboBox_devGroup->addItem(m_devGDescMap.value(devG),devG); + } + } + } + } +} + +void CRealDatabaseShow::initComboxDevice() +{ + return; +// ui->comboBox_device->clear(); +// //QString devG = ui->comboBox_devGroup->currentData().toString(); +// if(devG.isEmpty()) +// { +// return ; +// } +// if(m_bDevFilter == true) +// { +// ui->comboBox_device->addItem(tr("所有设备"),"all"); +// QVector devVec = m_devGDevMap.value(devG); +// foreach (QString dev, devVec) { +// ui->comboBox_device->addItem(m_devDescMap.value(dev),dev); +// } +// } +} + +void CRealDatabaseShow::initComboxRtu() +{ + ui->comboBox_rtu->clear(); + if(m_bRtuFilter == true) + { + QString locationSub = QString::number(m_nlocationId)+"."+QString::number(m_nsubId); + QMap >::iterator it = m_locSubRtuMap.find(locationSub); + if(it != m_locSubRtuMap.end()) + { + QVector & rtuVec = it.value(); + if(rtuVec.size()>0) + { + foreach (QString rtu, rtuVec) { + ui->comboBox_rtu->addItem(m_rtuDescMap.value(rtu),rtu); + } + } + } + } +} + +void CRealDatabaseShow::initComboxFesDev() +{ + ui->comboBox_fesDev->clear(); + QString rtu = ui->comboBox_rtu->currentData().toString(); + if(rtu.isEmpty()) + { + return ; + } + if(m_bFesDevFilter == true) + { + ui->comboBox_fesDev->addItem(tr("所有设备"),"all"); + QVector fesDevVec = m_rtuFesDevMap.value(rtu); + foreach (QString fesDev, fesDevVec) { + ui->comboBox_fesDev->addItem(m_fesDevDescMap.value(fesDev),fesDev); + } + } +} + +void CRealDatabaseShow::slot_filterDevg(int _index) +{ + if(_index <0) + { + return ; + } + //QString devGId = ui->comboBox_devGroup->currentData().toString(); +// if(m_bDevFilter == true) +// { +// ui->comboBox_device->clear(); +// ui->comboBox_device->addItem(tr("所有设备"),"all"); +// QVector devVec = m_devGDevMap.value(devGId); +// foreach (QString dev, devVec) { +// ui->comboBox_device->addItem(m_devDescMap.value(dev),dev); +// } +// }else +// { +// search(); +// } +} + +void CRealDatabaseShow::slot_filterRtu(int _index) +{ + if(_index <0) + { + return ; + } + QString rtuTag = ui->comboBox_rtu->currentData().toString(); + if(m_bFesDevFilter == true) + { + ui->comboBox_fesDev->clear(); + ui->comboBox_fesDev->addItem(tr("所有设备"),"all"); + QVector fesDevVec = m_rtuFesDevMap.value(rtuTag); + foreach (QString fesDev, fesDevVec) { + ui->comboBox_fesDev->addItem(m_rtuDescMap.value(fesDev),fesDev); + } + }else + { + search(); + } + return ; +} + +void CRealDatabaseShow::slot_filterDev(int _index) +{ + if(_index<0) + { + return ; + } + + search(); +} + +void CRealDatabaseShow::slot_filterFesDev(int _index) +{ + if(_index<0) + { + return ; + } + search(); +} + +void CRealDatabaseShow::auto_brush() +{ + if(m_canSearch) + { + RdbQuery msgQuery; + if(!makeUpdateQuery(msgQuery)) + { + return; + } + emit sigSearch(m_nDomainId,m_nappId,msgQuery,m_strTableName,0); + m_canSearch = false; + } +} + +void CRealDatabaseShow::not_auto_brush() +{ + RdbQuery msgQuery; + if(!makeQuery(msgQuery)) + { + return; + } + emit sigSearch(m_nDomainId,m_nappId,msgQuery,m_strTableName,1); +} + +void CRealDatabaseShow::slotAutoResult(const bool &isSuccess, const RdbRet &retMsg, const QString &tableName) +{ + if(isSuccess && tableName == m_strTableName) + { + int msgCount = retMsg.msgrecord_size(); + for(int i = 0 ; i < msgCount; ++i) + { + if(retMsg.msgrecord(i).msgvaluearray_size() != 3) + { + LOGERROR("刷新数据出错!"); + qDebug()<<"刷新数据出错!"; + return ; + } + QString tag_name = dataTypeToQString(retMsg.msgrecord(i).msgvaluearray(0)); + QString value = dataTypeToQString(retMsg.msgrecord(i).msgvaluearray(1)); + QString status = dataTypeToQString(retMsg.msgrecord(i).msgvaluearray(2)); + //updateDi(tag_name,value,status); + if(m_showdata.value(tag_name,NULL) == NULL) + { + return ; + } + int valueIndex = m_pVecTableInfo->indexOf(QString("value")); + int statusIndex = m_pVecTableInfo->indexOf(QString("status")); + m_showdata.value(tag_name)->setData(valueIndex,value); + m_showdata.value(tag_name)->setData(statusIndex,status); + } + } + if(isSuccess) + { + m_canSearch = true; + } +} + +void CRealDatabaseShow::slotNotAutoResult(const bool & isSuccess,const RdbRet &retMsg,const QString& tableName) +{ + if(isSuccess && tableName == m_strTableName) + { + if(m_strTableName == "analog" || m_strTableName == "digital" || m_strTableName == "mix" || m_strTableName == "accuml") + { + makeData(retMsg); + } + else + { + int msgCount = retMsg.msgrecord_size(); + ui->tableWidget_showTable->setRowCount(msgCount); + for(int i = 0 ; i < msgCount; ++i) + { + for(int j = 0; j < retMsg.msgrecord(i).msgvaluearray_size();++j) + { + setItemData(i,j,retMsg.msgrecord(i).msgvaluearray(j)); + } + ui->tableWidget_showTable->showRow(i); + } + } + } + if(!isSuccess) + { + //N_MessageBox::warning(this,tr("告警"),tr("查询超时")); + }else + { + m_canSearch = true; + } +} + +void CRealDatabaseShow::statusSearch() +{ + if(m_searchDialog != NULL) + m_searchDialog->show(); + else + { + m_searchDialog = new CStatusDialog(m_pSystemResources,this); + m_searchDialog->show(); + } +} + + +void CRealDatabaseShow::showStatus(const QModelIndex &index) +{ + int value =0; + + if(!index.isValid()) + { + return ; + } + + if(m_strTableName != "analog" && m_strTableName != "digital"&& m_strTableName != "mix" && m_strTableName != "accuml") + { + return ; + } + value=m_model->queryData(3,index.row()).toInt(); + if(m_searchDialog == NULL) + { + m_searchDialog = new CStatusDialog(m_pSystemResources,this); + } + m_searchDialog->initData(m_strTableName == "digital"? 0:1,value,m_model->queryData(0,index.row()).toString(),int(m_model->queryData(2,index.row()).toDouble())); + //m_searchDialog->show(); + QString textEdit_all=m_searchDialog->all_textEditQstring(); + emit signal_selectTextEdit(textEdit_all); + return; +} + +bool CRealDatabaseShow::makeData(const RdbRet &retMsg) +{ + m_showdata.clear(); + + int msgCount = retMsg.msgrecord_size(); + for(int i = 0 ; i < msgCount; ++i) + { + RealDatabasePtr dataPtr(new CRealDatabaseItemInfo); + dataPtr->initialize(retMsg.msgrecord(i)); + int tag_nameIndex = m_pVecTableInfo->indexOf(QString("tag_name")); + QString tag_name =QString::fromStdString(retMsg.msgrecord(i).msgvaluearray(tag_nameIndex).strvalue()); + m_showdata.insert(tag_name,dataPtr); + } + emit sigDataRefresh(m_showdata.values()); + return true; +} + +QStringList CRealDatabaseShow::getTableHead() +{ + int columnNum = m_pVecTableInfo->size(); + QString columnName; + QStringList columnNameList; + for(int i = 0 ; i < columnNum; ++i) + { + columnName = m_pVecTableInfo->at(i).toLower(); + columnNameList.append(columnName); + } + return columnNameList; +} + +void CRealDatabaseShow::setTableHead() +{ + ui->tableWidget_showTable->clear(); + int columnNum = m_pVecTableInfo->size(); + ui->tableWidget_showTable->setColumnCount(columnNum); + + QString columnName; + QStringList columnNameList; + for(int i = 0 ; i < columnNum; ++i) + { + columnName = m_pVecTableInfo->at(i).toLower(); + ui->tableWidget_showTable->setColumnWidth(i,9*columnName.size()); //设置每一列列宽 + columnNameList.append(columnName); + } + ui->tableWidget_showTable->setHorizontalHeaderLabels(columnNameList); + + ui->tableWidget_showTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->tableWidget_showTable->setEditTriggers(QAbstractItemView::NoEditTriggers); +} + +QString CRealDatabaseShow::dataTypeToQString(const iot_idl::SVariable &sVariable) +{ + switch (sVariable.edatatype()) + { + case iot_idl::DataType::CN_DATATYPE_BOOL: + return QString::number(sVariable.bvalue()); + break; + case iot_idl::DataType::CN_DATATYPE_FLOAT: + return QString::number(sVariable.fvalue()); + break; + case iot_idl::DataType::CN_DATATYPE_INT32: + return QString::number(sVariable.nvalue()); + break; + case iot_idl::DataType::CN_DATATYPE_STRING: + return QString::fromStdString(sVariable.strvalue()); + break; + case iot_idl::DataType::CN_DATATYPE_UINT32: + return QString::number(sVariable.uvalue()); + break; + case iot_idl::DataType::CN_DATATYPE_INT64: + return QString::number(sVariable.lvalue()); + break; + case iot_idl::DataType::CN_DATATYPE_UINT64: + return QString::number(sVariable.ulvalue()); + break; + case iot_idl::DataType::CN_DATATYPE_DOUBLE: + return QString::number(sVariable.dvalue()); + break; + default: + qDebug() << "other value Type" <indexOf(QString("location_id")); + int subSystemColumn = m_pVecTableInfo->indexOf(QString("sub_system")); + int deviceColumn = m_pVecTableInfo->indexOf(QString("device")); + int fesDevColumn = m_pVecTableInfo->indexOf(QString("dev_tag")); + int rtuColumn = m_pVecTableInfo->indexOf(QString("rtu_tag")); + if(locationColumn == -1) + { + m_bLocationFilter = false; + }else + { + m_bLocationFilter = true; + } + + if(subSystemColumn == -1) + { + m_bSubFilter = false; + m_bDevFilter = false; + m_bFesDevFilter = false; + m_bRtuFilter = false; + // hideRtu(); + // hideFesDev(); + // hideDevGroup(); + // hideDev(); + return ; + }else + { + m_bSubFilter = true; + } + + if(deviceColumn == -1) + { + //隐藏掉设备组和设备 + // hideDevGroup(); + // hideDev(); + m_bDevFilter = false; + }else + { + // showDevGroup(); + // showDev(); + // hideRtu(); + // hideFesDev(); + m_bDevFilter = true; + m_bFesDevFilter = false; + m_bRtuFilter = false; + return ; + } + + if(rtuColumn == -1) + { + m_bFesDevFilter = false; + m_bRtuFilter = false; + //hideRtu(); + //hideFesDev(); + return ; + }else + { + //showRtu(); + m_bRtuFilter = true; + } + + if(fesDevColumn == -1) + { + //hideFesDev(); + m_bFesDevFilter = false; + }else + { + //showFesDev(); + m_bFesDevFilter = true; + } +} + +void CRealDatabaseShow::hideDevGroup() +{ + ui->label_devG->setHidden(true); + ui->comboBox_devGroup->setHidden(true); +} + +void CRealDatabaseShow::showDevGroup() +{ + ui->label_devG->setHidden(false); + // ui->comboBox_devGroup->setHidden(false); +} + +void CRealDatabaseShow::hideDev() +{ + ui->label_dev->setHidden(true); + ui->comboBox_device->setHidden(true); +} + +void CRealDatabaseShow::showDev() +{ + ui->label_dev->setHidden(false); + ui->comboBox_device->setHidden(false); +} + +void CRealDatabaseShow::hideRtu() +{ + ui->label_rtu->setHidden(true); + ui->comboBox_rtu->setHidden(true); +} + +void CRealDatabaseShow::showRtu() +{ + ui->label_rtu->setHidden(false); + ui->comboBox_rtu->setHidden(false); +} + +void CRealDatabaseShow::hideFesDev() +{ + ui->label_fesDev->setHidden(true); + ui->comboBox_fesDev->setHidden(true); +} + +void CRealDatabaseShow::showFesDev() +{ + ui->label_fesDev->setHidden(false); + ui->comboBox_fesDev->setHidden(false); +} + +void CRealDatabaseShow::search() +{ + emit sigTimerShot(false); //停止定时器 + ui->tableWidget_showTable->clear(); + ui->tableWidget_showTable->setRowCount(0); + + if(m_strTableName != "analog" && m_strTableName != "digital" && + m_strTableName != "mix" && m_strTableName != "accuml") //非四遥点 + { + ui->stackedWidget->setCurrentIndex(0); + setTableHead(); + not_auto_brush(); + } + else //需要模型支持,不然界面卡顿 + { + ui->stackedWidget->setCurrentIndex(1); + QStringList header = getTableHead(); + if(!m_model) + { + m_model = new CRealDatabaseItemModel(header,this); + connect(this,&CRealDatabaseShow::sigDataRefresh,m_model,&CRealDatabaseItemModel::slotDataRefresh,Qt::UniqueConnection); + ui->tableView->setModel(m_model); + } + else + { + m_model->clear(); + m_model->setHead(header); + } + m_canSearch = false; + not_auto_brush(); + emit sigTimerShot(true); + } +} + +bool CRealDatabaseShow::makeQuery(RdbQuery &msgQuery) +{ + int columnNum = m_pVecTableInfo->size(); + + QStringList columnNameList; + for(int i = 0 ; i < columnNum; ++i) + { + columnNameList.append(m_pVecTableInfo->at(i).toLower()); + } + msgQuery.set_strtablename(m_strTableName.toStdString()); + std::string *pColName; + for(int i = 0 ; i < columnNameList.size() ; ++i) + { + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = columnNameList.at(i).toStdString(); + } + return makeCondition(msgQuery); +} + +bool CRealDatabaseShow::makeUpdateQuery(RdbQuery &msgQuery) +{ + QStringList columnNameList; + columnNameList.append("tag_name"); + columnNameList.append("value"); + columnNameList.append("status"); + msgQuery.set_strtablename(m_strTableName.toStdString()); + std::string *pColName; + for(int i = 0 ; i < 3 ; ++i) + { + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = columnNameList.at(i).toStdString(); + } + return makeCondition(msgQuery); +} + +bool CRealDatabaseShow::makeCondition(RdbQuery &msgQuery) +{ + RdbCondition *condition; + + //先设备 后专业 和车站 (顺序不能变)@jxd 2020-6-11 + if(m_bDevFilter) + { + QString devG = m_devGroupName; + if(devG.isEmpty()) + { + return false; + }else + { + //若设备组不为空 + QString dev = m_deviceName; + if(dev == "all") + { + //查询所有则按设备组查(因为没有包含接口,需要查询设备组下的所有设备,用设备判断) + QVector strVec = m_devGDevMap.value(devG); + for(int index(0);indexset_enlogic(enumCondOr); + condition->set_enrelation(enumCondEqual); + condition->set_strcolumnname("device"); + SVariable variable; + variable.set_edatatype(CN_DATATYPE_STRING); + variable.set_strvalue(strVec.at(index).toStdString()); + + condition->mutable_msgvalue()->CopyFrom(variable); + } + } + else + { + //按设备查 + condition =msgQuery.add_msgcondition(); + condition->set_enrelation(enumCondEqual); + condition->set_strcolumnname("device"); + SVariable variable; + variable.set_edatatype(CN_DATATYPE_STRING); + variable.set_strvalue(dev.toStdString()); + condition->mutable_msgvalue()->CopyFrom(variable); + } + } + }else if(m_bFesDevFilter) + { + QString rtu = ui->comboBox_rtu->currentData().toString(); + if( rtu.isEmpty()) + { + return false; + }else + { + //若RTU不为空 + QString fesDev = ui->comboBox_fesDev->currentData().toString(); + if(fesDev == "all") + { + //查询所有则按设备组查(因为没有包含接口,需要查询设备组下的所有设备,用设备判断) + QVector strVec = m_rtuFesDevMap.value(rtu); + + for(int index(0);indexset_enlogic(enumCondOr); + condition->set_enrelation(enumCondEqual); + condition->set_strcolumnname("dev_tag"); + SVariable variable; + variable.set_edatatype(CN_DATATYPE_STRING); + variable.set_strvalue(strVec.at(index).toStdString()); + condition->mutable_msgvalue()->CopyFrom(variable); + } + }else + { + //按设备查 + condition =msgQuery.add_msgcondition(); + condition->set_enlogic(enumCondOr); + condition->set_enrelation(enumCondEqual); + condition->set_strcolumnname("dev_tag"); + SVariable variable; + variable.set_edatatype(CN_DATATYPE_STRING); + variable.set_strvalue(fesDev.toStdString()); + condition->mutable_msgvalue()->CopyFrom(variable); + } + } + }else if(m_bRtuFilter) + { + QString rtu = ui->comboBox_rtu->currentData().toString(); + if( rtu.isEmpty()) + { + return false; + }else + { + //按RTU查 + condition =msgQuery.add_msgcondition(); + condition->set_enlogic(enumCondOr); + condition->set_enrelation(enumCondEqual); + condition->set_strcolumnname("rtu_tag"); + SVariable variable; + variable.set_edatatype(CN_DATATYPE_STRING); + variable.set_strvalue(rtu.toStdString()); + condition->mutable_msgvalue()->CopyFrom(variable); + } + } + if(m_bLocationFilter) + { + condition =msgQuery.add_msgcondition(); + condition->set_enlogic(enumCondAnd); + condition->set_enrelation(enumCondEqual); + condition->set_strcolumnname("location_id"); + SVariable variable; + variable.set_edatatype(CN_DATATYPE_INT32); + variable.set_nvalue(m_nlocationId); + condition->mutable_msgvalue()->CopyFrom(variable); + } + if(m_bSubFilter) + { + //按专业查 + condition =msgQuery.add_msgcondition(); + condition->set_enlogic(enumCondAnd); + condition->set_enrelation(enumCondEqual); + condition->set_strcolumnname("sub_system"); + SVariable variable; + variable.set_edatatype(CN_DATATYPE_INT32); + variable.set_nvalue(m_nsubId); + condition->mutable_msgvalue()->CopyFrom(variable); + } + return true; + +} + + diff --git a/product/src/tools/debug_tool_v2/CRealDatabaseShow.h b/product/src/tools/debug_tool_v2/CRealDatabaseShow.h new file mode 100644 index 00000000..84d9510c --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDatabaseShow.h @@ -0,0 +1,148 @@ +#ifndef CREALDATABASESHOW_H +#define CREALDATABASESHOW_H + +#include "toolCommon.h" +#include "CSystemResources.h" +#include "rdb_net_api/CRdbNetApi.h" +#include "net_msg_bus_api/MsgBusApi.h" +#include "rdb_api/CRdbAccessEx.h" +#include "CRealDatabaseItemInfo.h" +#include +#include +#include +#include "CRdbWorker.h" +#include "CStatusDialog.h" +class CRealDatabaseItemModel; +namespace Ui { +class CRealDatabaseShow; +} +class CStatusDialog; +class CRealDatabaseShow : public QWidget +{ + Q_OBJECT + +public: + explicit CRealDatabaseShow(QWidget *parent = 0); + ~CRealDatabaseShow(); + +private: + void releaseRsouces(); + +public: + bool initRealDatabaseShow(CSystemResources *_p); + +private: + bool initVariable(CSystemResources *_p); + bool initSystemResources(CSystemResources *_p); + bool initNetRdbApi(); + bool initMapLocationIdDesc(); + bool initMapLocSubDevGInfo(); + bool initMapLocSubRtuInfo(); + bool initMapDevGDevInfo(); + bool initMapRtuFesDevInfo(); + void initSignalAndSlot(); + void initView(); + void initFilter(); + void initComboxDevG(); + void initComboxDevice(); + void initComboxRtu(); + void initComboxFesDev(); + +signals: + void sigTimerShot(const bool bStop); + void sigDataRefresh(QList); + void sigSearch(int domainId,int appid,iot_idl::RdbQuery rdbQuery,QString tableName,int searchWays); + void signal_selectTextEdit(QString allQString); + +public slots: + void slotTimerShot(const bool start); + + void slot_showTable(QString, QVector *,int _domainId,int _locationId,int _appId, int _subId,QMap isLineShow,QString devGroupName,QString deviceName); + void slot_showOrHindColumn(int nColumn, int state); + + + void slot_filterDevg(int _index); + void slot_filterRtu(int _index); + void slot_filterDev(int _index); + void slot_filterFesDev(int _index); + + void auto_brush(); + void not_auto_brush(); + void slotAutoResult(const bool & isSuccess,const iot_idl::RdbRet & retMsg,const QString& tableName); + void slotNotAutoResult(const bool &isSuccess, const iot_idl::RdbRet &retMsg, const QString &tableName); + void statusSearch(); + + void showStatus(const QModelIndex &index); +private: + bool makeData(const iot_idl::RdbRet &retMsg); + void setItemData(int &row,int &column,const iot_idl::SVariable &); + + QStringList getTableHead(); + void setTableHead(); + QString dataTypeToQString(const iot_idl::SVariable &sVariable); + + void hideDevGroup(); + void showDevGroup(); + void hideDev(); + void showDev(); + void hideRtu(); + void showRtu(); + void hideFesDev(); + void showFesDev(); + void search(); + + bool makeQuery(iot_idl::RdbQuery &msgQuery); + bool makeUpdateQuery(iot_idl::RdbQuery &msgQuery); + bool makeCondition(iot_idl::RdbQuery &msgQuery); + +private: + Ui::CRealDatabaseShow *ui; + CRealDatabaseItemModel *m_model; //< 模型 + QMap m_showdata; //< 模型数据 + CSystemResources *m_pSystemResources; //< 系统资源类指针 + QVector * m_pVecTableInfo; //< 表的列名数组指针 + iot_dbms::CDbApi *m_pObjDbInterface; //< mysql数据库的接口指针 + + int m_nsubId; //< 专业ID + int m_nDomainId; //< 域ID + int m_nlocationId; //< 车站id + int m_nappId; //< 应用id + QString m_strTableName; //< 表的名 + QString m_devGroupName; //< 设备组名 + QString m_deviceName; //< 设备名 + + QMap m_locationIdDescMap; //< <车站id,描述> + QMap > m_locSubDevGMap; //< <车站id.专业id,DevVec> + QMap > m_locSubRtuMap; //< <车站id.专业id,RtuVec> + QMap m_devGDescMap; //< <设备组标签,描述> + QMap m_devDescMap; //< <设备标签,描述> + QMap m_rtuDescMap; //< + QMap m_fesDevDescMap; //< <前置设备标签,描述> + QMap > m_devGDevMap; //< <设备组标签,DevVec> + QMap > m_rtuFesDevMap; //< + + /** + * @brief 此处多处过滤只为缓解网络查询负担(还包括大数据量的自动查询和界面刷新压力) + * @brief 一般来说 所有设备组 设备 RTU 前置设备 总会属于某一个车站的某一个专业 + * @brief 若当前查询的表中包含 location_id 则 m_bLocationFilter生效 ,包含 sub_system 则 m_bSubFilter生效 + * @brief 若包含 device 则 m_bDevFilter生效,m_bRtuFilter和 m_bFesDevFilter 则无需判断,可直接认为无效(m_bDevFilter生效则足以缓解网络查询负担,后续条件则不判断) + * @brief 若不包含device(后台设备) ,但包含 dev_tag(前置设备) ,则m_bFesDevFilter生效,m_bRtuFilter不生效(但是dev_tag是由rtu_tag得到,有关联关系,只不过不作为查询条件) + * @brief 若既不包含device,也不包含dev_tag,只包含rtu_tag,则m_bRtuFilter生效,可以作为查询条件 + * @brief 若均不包含则认为此表数据量不大,可以不用缓解网络查询负担 + */ + bool m_bLocationFilter; //< 是否车站过滤 (m_strTableName 中包含location_id字段时可用) + bool m_bSubFilter; //< 是否专业过滤 (m_strTableName 中包含sub_system字段时可用) + bool m_bDevFilter; //< 是否设备过滤 (m_strTableName 中包含device字段时可用) + bool m_bRtuFilter; //< 是否RTU过滤 (m_strTableName 中包含rtu_tag字段时可用) + bool m_bFesDevFilter; //< 是否前置设备过滤 (m_strTableName 中包含dev_tag字段时可用) + bool m_canSearch; //< 主线程是否可以通知查询线程查询(自动刷新需要判断) + + QTimer *m_timer; //< 定时器 默认1秒 定时查询Ai Di Mi Pi + QThread *m_rdbThread; //< 查询线程 + CRdbWorker *m_worker; //< 工作线程 + + CStatusDialog *m_searchDialog; + +}; + +#endif // CREALDATABASESHOW_H diff --git a/product/src/tools/debug_tool_v2/CRealDatabaseShow.ui b/product/src/tools/debug_tool_v2/CRealDatabaseShow.ui new file mode 100644 index 00000000..167f9544 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealDatabaseShow.ui @@ -0,0 +1,228 @@ + + + CRealDatabaseShow + + + + 0 + 0 + 783 + 626 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 1 + + + 0 + + + + + 6 + + + + + 6 + + + + + + + + + 0 + 23 + + + + + 45 + 23 + + + + 设备组 + + + + + + + QComboBox::AdjustToContents + + + + + + + + 0 + 23 + + + + + 30 + 23 + + + + 设备 + + + + + + + QComboBox::AdjustToContents + + + + + + + + 30 + 0 + + + + + 30 + 16777215 + + + + RTU + + + + + + + QComboBox::AdjustToContents + + + + + + + + 60 + 23 + + + + + 60 + 23 + + + + 前置设备 + + + + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 0 + 0 + + + + + + + + 状态查询 + + + + + + + + + + + + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CRealEvent.ui b/product/src/tools/debug_tool_v2/CRealEvent.ui new file mode 100644 index 00000000..7d2fa8f0 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CRealEvent.ui @@ -0,0 +1,96 @@ + + + CRealEvent + + + + 0 + 0 + 437 + 243 + + + + Form + + + + + + + + + + + + + 滚动刷新 + + + + + + + 筛选状态 + + + + + + + 筛选 + + + + + + + 打印 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 事件条数 + + + + + + + + 0 + 0 + + + + + 50 + 16777215 + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CSelectAppDlg.cpp b/product/src/tools/debug_tool_v2/CSelectAppDlg.cpp new file mode 100644 index 00000000..6facee34 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CSelectAppDlg.cpp @@ -0,0 +1,162 @@ +#include +#include "CSelectAppDlg.h" +#include "ui_CSelectAppDlg.h" +#include +#include +#include "common/Common.h" +CSelectAppDlg::CSelectAppDlg(QWidget *parent) : + QDialog(parent), + ui(new Ui::CSelectAppDlg) +{ + ui->setupUi(this); + this->setWindowTitle(tr("专业选择")); + ui->AppcomboBox->setView(new QListView()); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + setFixedSize(this->width(),this->height());//固定窗口大小 + setStyleSheet("QComboBox QAbstractItemView::item{height: 30px;}"); + memset(m_IpAddr,0,sizeof(m_IpAddr)); + + connect(ui->ConnectButton,SIGNAL(clicked()),this,SLOT(OnConnect())); + connect(ui->DisConnectButton,SIGNAL(clicked()),this,SLOT(OnDisConnect())); + connect(&m_TcpClient,SIGNAL(NetConnected()),this,SLOT(ConnectOk())); + connect(&m_TcpClient,SIGNAL(NetDisConnected()),this,SLOT(DisConnectOk())); + connect(ui->AppcomboBox,&QComboBox::currentTextChanged,this,&CSelectAppDlg::OnAppId); + ui->ConnectButton->setEnabled(true); + ui->DisConnectButton->setEnabled(false); + + m_IpStr.clear(); +} + +CSelectAppDlg::~CSelectAppDlg() +{ + delete ui; +} + +void CSelectAppDlg::SelectApp(const std::vector &vecAppName) +{ + m_vecName = vecAppName; + + if(ui->AppcomboBox->count()==0) + { + if(m_vecName.size()<=0) + { + ui->AppcomboBox->addItem("AppName"); + ui->NetPortNo->setText("18001"); + } + else + { + int i; + for(i=0;iAppcomboBox->addItem(m_vecName[i].appName); + } + } + } + + QFile file("FesSimIP.txt"); + if(file.exists()) + { + if(file.open(QFile::ReadOnly | QFile::Text)) + { + m_IpStr = file.readAll(); + file.close(); + } + } + else + { + if(m_IpStr.isEmpty()) + m_IpStr = "192.168.77.18"; + std::string tempStr = m_IpStr.toStdString(); + if(file.open(QFile::WriteOnly | QFile::Append)) + { + file.write(tempStr.c_str(),tempStr.length()); + file.close(); + } + } + ui->IPAddr->setText(m_IpStr); +} + +void CSelectAppDlg::OnConnect() +{ + QString tempStr ; + + tempStr = ui->NetPortNo->text(); + bool ok; + m_NetPortNo = tempStr.toInt(&ok,10); + if(ok == false) + { + QPalette pe; + pe.setColor(QPalette::WindowText,Qt::red); + ui->ConnectStatusStr->setPalette(pe); + ui->ConnectStatusStr->setText(tr("网络端口错误,无法连接网络。")); + return; + } + m_IpStr = ui->IPAddr->text(); + QByteArray ba=m_IpStr.toLocal8Bit(); + strcpy(m_IpAddr,ba.data()); + m_TcpClient.Init(m_IpAddr,m_NetPortNo); + + if(m_TcpClient.TcpConnect()==iotSuccess) + { + } + else + { + } + + + //save FesSimIp.txt + QFile file("FesSimIP.txt"); + if(file.exists()) + { + std::string tempStr = m_IpStr.toStdString(); + if(file.open(QFile::WriteOnly | QFile::Truncate)) + { + file.write(tempStr.c_str(),tempStr.length()); + file.close(); + } + } +} + +void CSelectAppDlg::OnDisConnect() +{ + m_TcpClient.TcpClose(); +} + +void CSelectAppDlg::ConnectOk() +{ + QPalette pe; + pe.setColor(QPalette::WindowText,Qt::green); + ui->ConnectStatusStr->setPalette(pe); + ui->ConnectStatusStr->setText(tr("网络连接")); + ui->ConnectButton->setEnabled(false); + ui->DisConnectButton->setEnabled(true); +} + +void CSelectAppDlg::DisConnectOk() +{ + QPalette pe; + pe.setColor(QPalette::WindowText,Qt::red); + ui->ConnectStatusStr->setPalette(pe); + ui->ConnectStatusStr->setText(tr("网络断开")); + ui->ConnectButton->setEnabled(true); + ui->DisConnectButton->setEnabled(false); +} + +void CSelectAppDlg::OnAppId(const QString &text) +{ + + for(size_t i=0;iNetPortNo->setText(QString::number(18000+m_vecName[i].appId)); + break; + } + } +} diff --git a/product/src/tools/debug_tool_v2/CSelectAppDlg.h b/product/src/tools/debug_tool_v2/CSelectAppDlg.h new file mode 100644 index 00000000..8eb74b8f --- /dev/null +++ b/product/src/tools/debug_tool_v2/CSelectAppDlg.h @@ -0,0 +1,41 @@ +#ifndef CSELECTAPPDLG_H +#define CSELECTAPPDLG_H + +#include +#include "FesSimProtocol.h" +#include "CTcpClient.h" + +namespace Ui { +class CSelectAppDlg; +} + +class CSelectAppDlg : public QDialog +{ + Q_OBJECT + +public: + explicit CSelectAppDlg(QWidget *parent = 0); + ~CSelectAppDlg(); + + int m_AppType; + CTcpClient m_TcpClient; + int m_NetPortNo; + char m_IpAddr[64]; + + void SelectApp(const std::vector &vecAppName); + +private slots: + void OnConnect(); + void OnDisConnect(); + void ConnectOk(); + void DisConnectOk(); + + void OnAppId(const QString &); +private: + Ui::CSelectAppDlg *ui; + + std::vector m_vecName; + QString m_IpStr; +}; + +#endif // CSELECTAPPDLG_H diff --git a/product/src/tools/debug_tool_v2/CSelectAppDlg.ui b/product/src/tools/debug_tool_v2/CSelectAppDlg.ui new file mode 100644 index 00000000..8cf1457b --- /dev/null +++ b/product/src/tools/debug_tool_v2/CSelectAppDlg.ui @@ -0,0 +1,263 @@ + + + CSelectAppDlg + + + + 0 + 0 + 356 + 303 + + + + Dialog + + + + + 50 + 50 + 245 + 188 + + + + + + + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + 专业名称: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + FES IP地址: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + FES网络端口: + + + + + + + + 0 + 30 + + + + + 16777215 + 30 + + + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 连接状态: + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 连接 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 断开连接 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CStatusDialog.cpp b/product/src/tools/debug_tool_v2/CStatusDialog.cpp new file mode 100644 index 00000000..4b993119 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CStatusDialog.cpp @@ -0,0 +1,154 @@ +#include "CStatusDialog.h" +#include "ui_CStatusDialog.h" +#include "pub_widget/MessageBox.h" +CStatusDialog::CStatusDialog(CSystemResources *_p,QWidget *parent) : + CustomUiDialog(parent), + ui(new Ui::CStatusDialog) +{ + m_pSystemResources = _p; + ui->setupUi(this); + setWindowTitle( "状态查询" ); + if(initDbInterface()) + { + loadData(); + } + ui->comboBox->setView(new QListView()); + connect(ui->pushButton,&QPushButton::clicked,this,&CStatusDialog::search); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&CStatusDialog::switchWidget); + + initCombox(); + + CustomUiDialog::setAutoLayout(true); +} + +CStatusDialog::~CStatusDialog() +{ + delete ui; +} + +bool CStatusDialog::initDbInterface() +{ + m_pObjDbInterface = m_pSystemResources->getDbInterface(); + if(m_pObjDbInterface != NULL) + return true; + + return false; +} + +void CStatusDialog::initData(int type, int status,QString allName,int value) +{ + ui->comboBox->setCurrentIndex(type); + ui->lineEdit->setText(QString::number((uint)status)); + m_allName=allName; + m_value=value; + search(); +} + +QString CStatusDialog::all_textEditQstring() +{ + return all_textEditQst; +} + +void CStatusDialog::initCombox() +{ + ui->comboBox->clear(); + // ui->comboBox->addItem("menu1"); + // ui->comboBox->addItem("menu2"); + // ui->comboBox->addItem("menu3"); + // ui->comboBox->addItem(QString::number(m_dict_menu.size())); + foreach (QString menu, m_dict_menu.keys()) { + if(menu == "数字量状态" || menu == "模拟量状态") + ui->comboBox->addItem(menu); + } +} + +void CStatusDialog::loadData() +{ + m_dict_menu.clear(); + QSqlQuery sqlQueue; + m_pObjDbInterface->execute("SELECT MENU_NAME,ACTUAL_VALUE,DISPLAY_VALUE FROM dict_menu_info", sqlQueue); + if(sqlQueue.isActive()) + { + while(sqlQueue.next()) + { + QString menu = sqlQueue.value("MENU_NAME").toString(); + int value = sqlQueue.value("ACTUAL_VALUE").toInt(); + QString desc = sqlQueue.value("DISPLAY_VALUE").toString(); + + QMap >::iterator it =m_dict_menu.find(menu); + if(it != m_dict_menu.end()) + { + QMap& valueDesc = it.value(); + valueDesc[value] = desc; + }else + { + QMap valueDesc; + valueDesc[value] = desc; + m_dict_menu[menu] = valueDesc; + } + } + } +} + +void CStatusDialog::setCheck(quint64 status) +{ + QString allStatus = QString("%1,").arg(status); + for ( int i=0; idata(Qt::UserRole).toInt()) ) + { + item->setCheckState(Qt::Checked); + item->setTextColor(Qt::red); + allStatus=allStatus+item->text()+","; + } + else + { + item->setCheckState(Qt::Unchecked); + item->setTextColor(Qt::black); + } + } + allStatus.chop(1); + allStatus=allStatus+"。"; + emit signal_selectTextEdit(allStatus,m_allName,m_value); + all_textEditQst="当前标签为"+m_allName+", 值为" + +QString::number(m_value)+", 状态为" + +allStatus; +} + +void CStatusDialog::resetView() +{ + ui->listWidget->clear(); +} + +void CStatusDialog::search() +{ + QString lineText = ui->lineEdit->text(); + if(lineText.isEmpty()) + { + N_MessageBox::warning(this,tr("提示"),tr("请输入状态值!")); + } + quint64 status = lineText.toULongLong(); + setCheck(status); + +} + +void CStatusDialog::switchWidget(const QString &text) +{ + resetView(); + m_listItem.clear(); + QMap valueDesc = m_dict_menu.value(text); + QMap::iterator it =valueDesc.begin(); + while (it != valueDesc.end()) { + QListWidgetItem *item; + item = new QListWidgetItem(); + item->setFlags(item->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable); +// item->setText(QString::number(it.key())+":"+ it.value()); + item->setText(it.value()); + item->setData(Qt::UserRole,it.key()); + item->setCheckState(Qt::Unchecked); + ui->listWidget->addItem(item); + m_listItem.append(item); + it++; + } +} diff --git a/product/src/tools/debug_tool_v2/CStatusDialog.h b/product/src/tools/debug_tool_v2/CStatusDialog.h new file mode 100644 index 00000000..11644497 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CStatusDialog.h @@ -0,0 +1,45 @@ +#ifndef CSTATUSDIALOG_H +#define CSTATUSDIALOG_H + +#include "pub_widget/CustomDialog.h" +#include "CSystemResources.h" +#include +#include +#include +namespace Ui { +class CStatusDialog; +} + +class CStatusDialog : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit CStatusDialog(CSystemResources *_p,QWidget *parent); + ~CStatusDialog(); + bool initDbInterface(); + void initData(int type,int status,QString allName,int value); + QString all_textEditQstring(); +private: + void initCombox(); + void loadData(); + void setCheck(quint64 status); + void resetView(); +private slots: + void search(); + void switchWidget(const QString& text); +signals: + void signal_selectTextEdit(QString allStatus,QString m_allName,int m_value); +private: + Ui::CStatusDialog *ui; + iot_dbms::CDbApi *m_pObjDbInterface; + CSystemResources *m_pSystemResources; + QMap > m_dict_menu; + QList m_listItem; + QString all_textEditQst; + QVector m_allNameVec; + QString m_allName; + int m_value; +}; + +#endif // CSTATUSDIALOG_H diff --git a/product/src/tools/debug_tool_v2/CStatusDialog.ui b/product/src/tools/debug_tool_v2/CStatusDialog.ui new file mode 100644 index 00000000..541a9e1d --- /dev/null +++ b/product/src/tools/debug_tool_v2/CStatusDialog.ui @@ -0,0 +1,83 @@ + + + CStatusDialog + + + + 0 + 0 + 328 + 481 + + + + Dialog + + + + + + + + + + 16777215 + 80 + + + + + + + + + + + 类型: + + + + + + + + + + + + + 值: + + + + + + + + + + 0 + 0 + + + + + 16777215 + 46 + + + + 查询 + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/CSystemResources.cpp b/product/src/tools/debug_tool_v2/CSystemResources.cpp new file mode 100644 index 00000000..9e3e61c4 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CSystemResources.cpp @@ -0,0 +1,209 @@ +#include "CSystemResources.h" +#include +CSystemResources::CSystemResources() +{ + m_pObjDbInterface = NULL; +} + +CSystemResources::~CSystemResources() +{ + releaseResources(); +} + + +//设置权限用户Id +void CSystemResources::setPermUserId(int &_userID) +{ + m_nPermUserID = _userID; +} +//设置权限用户组ID +void CSystemResources::setPermUserGroupId(int &_userGroupId) +{ + m_nPermUserGroupID = _userGroupId; +} +//初始化一些系统资源 +int CSystemResources::initSystemResources() +{ + initLogSystem(); + if(!initMsgBus()) + { + + qDebug() << QObject::tr("初始化消息总线失败") <getAppInfoBySubsystemId(SubSystemId,appInfo); + return 0; +} + +//得到进程名 +QString CSystemResources::getStrSrcTag() +{ + return m_strSrcTag; +} +//得到当前域ID +int CSystemResources::getSrcDomainId() +{ + return m_nSrcDomainID; +} +//得到当前应用ID +int CSystemResources::getAppId() +{ + return m_nAppID; +} +//得到当前主机名 +QString CSystemResources::getHostName() +{ + return m_strHostName; +} +//得到当前实例名 +QString CSystemResources::getInstName() +{ + return m_strInstName; +} +//得到通讯器名 +QString CSystemResources::getCommName() +{ + return m_strCommName; +} +//得到权限用户ID +int CSystemResources::getPermUserId() +{ + return m_nPermUserID; +} +//得到权限用户组ID +int CSystemResources::getPermUserGroupId() +{ + return m_nPermUserGroupID; +} + + + +void CSystemResources::initLogSystem() +{ + //iot_public::StartLogSystem("PUBLIC", "debugTool"); +} + +bool CSystemResources::initMsgBus() +{ + //< 初始化消息总线库 + if (!(iot_net::initMsgBus("debugToolAppName", "debugToolProcessName"))) + { + qDebug() << "初始化消息总线失败" <open()) + { + qDebug() << "数据库接口打开失败" <execute(strSql,locIdAndDomId); + if(locIdAndDomId.isActive()) + { + int locationId; + int domainId; + while(locIdAndDomId.next()) + { + locationId = locIdAndDomId.value("LOCATION_ID").toInt(); + domainId = locIdAndDomId.value("DOMAIN_ID").toInt(); + m_mapLocationId2DomainId[locationId] = domainId; + } + } + else + { + qDebug() << "查询表sys_model_location_info失败" <getLocalNodeInfo(stNodeInfo); + m_strSrcTag = SRC_PROCESS_NAME; + m_nSrcDomainID = stNodeInfo.nDomainId; + m_nAppID = APP_ID; + m_strHostName = QString::fromStdString(stNodeInfo.strName); + m_strInstName = SRC_INST_NMAE; + m_strCommName = SRC_COMM_NAME; + m_nPermUserID = -1; + m_nPermUserGroupID = -1; + + return true; +} + +void CSystemResources::releaseResources() +{ + m_pSysInfoInterfacePtr.reset(); + + if(NULL != m_pObjDbInterface) + { + m_pObjDbInterface->close(); + m_pObjDbInterface = NULL; + } + + + iot_service::CDpcdaForApp::releaseGlobalThread(); + + //< 释放消息总线库 + iot_net::releaseMsgBus(); + + //< 停止日志系统 + //iot_public::StopLogSystem(); +} diff --git a/product/src/tools/debug_tool_v2/CSystemResources.h b/product/src/tools/debug_tool_v2/CSystemResources.h new file mode 100644 index 00000000..a4ca8018 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CSystemResources.h @@ -0,0 +1,78 @@ +#ifndef CSYSTEMRESOURCES_H +#define CSYSTEMRESOURCES_H + +#include +#include + + + +#include "db_api_ex/CDbApi.h" +#include "pub_sysinfo_api/SysInfoApi.h" +#include "pub_logger_api/logger.h" +#include "net_msg_bus_api/MsgBusApi.h" +#include "dp_chg_data_api/CDpcdaForApp.h" +#include "Common.h" + + + +#define SRC_PROCESS_NAME "debug_tool" +#define APP_ID 4 +#define SRC_INST_NMAE "debugToolInst" +#define SRC_COMM_NAME "debugToolCtlComm" +//#define USER_ID 1 +//#define USER_GROUP_ID 1 + + +class CSystemResources +{ +public: + CSystemResources(); + ~CSystemResources(); + + + void setPermUserId(int &_userID); + void setPermUserGroupId(int &_userGroupId); + + int initSystemResources(); + + iot_dbms::CDbApi *getDbInterface(); + + int getDomainIdByLocationId(int locationId); + int getAppInfoBySubSystemId(int SubSystemId,iot_public::SAppInfo &appInfo); + + QString getStrSrcTag(); + int getSrcDomainId(); + int getAppId(); + QString getHostName(); + QString getInstName(); + QString getCommName(); + int getPermUserId(); + int getPermUserGroupId(); + void releaseResources(); + +private: + void initLogSystem(); + bool initMsgBus(); + bool initDbInterface(); + bool initLcId2DomainId(); + bool initSysVariable(); +private: + + + iot_dbms::CDbApi *m_pObjDbInterface; + QMap m_mapLocationId2DomainId; + QString m_strSrcTag ; //源标签(即发送端进程名) + int m_nSrcDomainID ; //消息发送源域名 + int m_nAppID ; //所属应用ID + QString m_strHostName ; //发送端主机名 + QString m_strInstName ; //发送端实例名 + QString m_strCommName ; + int m_nPermUserID ; //发送端用户ID + int m_nPermUserGroupID ; //发送端用户组ID + iot_public::CSysInfoInterfacePtr m_pSysInfoInterfacePtr; + + +}; + + +#endif // CSYSTEMRESOURCES_H diff --git a/product/src/tools/debug_tool_v2/CUpdateThread.cpp b/product/src/tools/debug_tool_v2/CUpdateThread.cpp new file mode 100644 index 00000000..e09278c1 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CUpdateThread.cpp @@ -0,0 +1,73 @@ +#include "CUpdateThread.h" +#include "pub_logger_api/logger.h" + +CUpdateThread::CUpdateThread(QObject *parent) : QThread(parent) +{ + bIsRun = true; + m_pMbComm = new iot_net::CMbCommunicator("updatePoint"); + //< 获取通讯器名称(可选) + qDebug() << "My communicator name is " << m_pMbComm->getName().c_str() << endl; + + if (m_pMbComm->addSub(0, CH_SCADA_TO_HMI_DATA_CHANGE)) + qDebug() << "addSub() successed !" << endl; + else + qDebug() << "addSub() failed !" << endl; +} + +CUpdateThread::~CUpdateThread() +{ + stopThread(); + quit(); + wait(); + m_pMbComm->delSub(0, CH_SCADA_TO_HMI_DATA_CHANGE); + delete m_pMbComm; + m_pMbComm = nullptr; +} + +void CUpdateThread::run() +{ + while (bIsRun) + { + if(m_pMbComm->recvMsg(objMsg,1000)) + { + if(!objMsg.isValid()) + { + continue; + } + + switch (objMsg.getChannelID()) + { + case CH_SCADA_TO_HMI_DATA_CHANGE: + if(iot_idl::MT_DP_CHANGE_DATA == objMsg.getMsgType()) + { + parserMsg(objMsg); + } + break; + default: + break; + } + } + } +} + +void CUpdateThread::stopThread() +{ + bIsRun = false; +} + +int CUpdateThread::parserMsg(const iot_net::CMbMessage &msg) +{ + ::iot_idl::SRealTimeDataPkg changeDataPackage; + try + { + if(changeDataPackage.ParseFromArray(msg.getDataPtr(),(int)msg.getDataSize())) + { + signal_updatePntRealData(changeDataPackage); + } + } + catch(...) + { + return 0; + } + return 1; +} diff --git a/product/src/tools/debug_tool_v2/CUpdateThread.h b/product/src/tools/debug_tool_v2/CUpdateThread.h new file mode 100644 index 00000000..9a56e3f4 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CUpdateThread.h @@ -0,0 +1,34 @@ +#ifndef CUPDATETHREAD_H +#define CUPDATETHREAD_H + + +#include +#include +#include "net_msg_bus_api/MsgBusApi.h" +#include "MessageChannel.h" +#include "DataProcMessage.pb.h" + + +class CUpdateThread : public QThread +{ + Q_OBJECT +public: + explicit CUpdateThread(QObject *parent = 0 ); + ~CUpdateThread(); + + virtual void run() Q_DECL_OVERRIDE; + void stopThread(); + +signals: + void signal_updatePntRealData(iot_idl::SRealTimeDataPkg stRealData); + +private: + iot_net::CMbCommunicator *m_pMbComm; + iot_net::CMbMessage objMsg; + bool bIsRun; + +private: + int parserMsg(const iot_net::CMbMessage &); +}; + +#endif // CUPDATETHREAD_H diff --git a/product/src/tools/debug_tool_v2/ComProtocolThread.h b/product/src/tools/debug_tool_v2/ComProtocolThread.h new file mode 100644 index 00000000..005dd5f7 --- /dev/null +++ b/product/src/tools/debug_tool_v2/ComProtocolThread.h @@ -0,0 +1,180 @@ +#ifndef HEARTBEATTHREAD_H +#define HEARTBEATTHREAD_H + +#include +#include +#include +#include "FesSimProtocol.h" + +const int EN_HeartBeatCount =500; +const int EN_MaxRespBufSize = 4096; +const int EN_MaxCmdBufSize = 1024; +const int EN_MaxReportBufSize = 51200; //1024*50;sio monitor buffer + +//通道连接状态 +const int CN_CommDisconnect =0; //链接关闭 +const int CN_CommConnect =1; //链接成功 + +typedef struct{ + SFesSimAiParam param; + SFesSimAiData value; +}SFesSimAi; + +typedef struct{ + SFesSimFwAiParam param; + SFesSimAiData value; +}SFesSimFwAi; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int AiNum; + SFesSimAi *pAi; +}SAiMonRtu; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int AiNum; + SFesSimFwAi *pAi; +}SFwAiMonRtu; + +typedef struct{ + SFesSimDiParam param; + SFesSimDiData value; +}SFesSimDi; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int DiNum; + SFesSimDi *pDi; +}SDiMonRtu; + + +typedef struct{ + SFesSimFwDiParam param; + SFesSimDiData value; +}SFesSimFwDi; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int DiNum; + SFesSimFwDi *pDi; +}SFwDiMonRtu; + +typedef struct{ + SFesSimAccParam param; + SFesSimAccData value; +}SFesSimAcc; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int AccNum; + SFesSimAcc *pAcc; +}SAccMonRtu; + +typedef struct{ + SFesSimFwAccParam param; + SFesSimAccData value; +}SFesSimFwAcc; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int AccNum; + SFesSimFwAcc *pAcc; +}SFwAccMonRtu; + +typedef struct{ + SFesSimMiParam param; + SFesSimMiData value; +}SFesSimMi; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int DiNum; + SFesSimMi *pMi; +}SMiMonRtu; + +typedef struct{ + SFesSimFwMiParam param; + SFesSimMiData value; +}SFesSimFwMi; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int DiNum; + SFesSimFwMi *pMi; +}SFwMiMonRtu; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int DiNum; + SFesSimAoParam *pAo; +}SAoMonRtu; + + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int DiNum; + SFesSimDoParam *pDo; +}SDoMonRtu; + + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU + int DiNum; + SFesSimMoParam *pMo; +}SMoMonRtu; + +typedef struct{ + int RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU +}SSettingMonRtu; + +//本结构是通道管理的内部结构,备用通道收发的统计数据(RxNum、TxNum、ErrCnt)在自己通道结构中, +//其他数据都在主通道结构中 +typedef struct { + uint32 Writex;//写指针 + uint32 Readx; //读指针 + unsigned char Data[EN_MaxReportBufSize]; //数据内容 +}SChanRxBuf; + + +namespace Ui { +class PiMonDlg; +} + +#endif diff --git a/product/src/tools/debug_tool_v2/CommonSheet.cpp b/product/src/tools/debug_tool_v2/CommonSheet.cpp new file mode 100644 index 00000000..82c65099 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CommonSheet.cpp @@ -0,0 +1,43 @@ +#include "CommonSheet.h" +#include +#include "pub_utility_api/FileStyle.h" + +CommonSheet::CommonSheet() +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss","zh","light"); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("debug_tool.qss","zh","light"); + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + m_stSheet = qss; + } +} + +bool CommonSheet::getSheet(QString &sheet) +{ + if(m_stSheet.isEmpty()) + { + return false; + }else + { + sheet = m_stSheet; + return true; + } +} diff --git a/product/src/tools/debug_tool_v2/CommonSheet.h b/product/src/tools/debug_tool_v2/CommonSheet.h new file mode 100644 index 00000000..bf5ddea6 --- /dev/null +++ b/product/src/tools/debug_tool_v2/CommonSheet.h @@ -0,0 +1,15 @@ +#ifndef COMMONSHEET_H +#define COMMONSHEET_H + +#include +#include +class CommonSheet +{ +public: + CommonSheet(); + bool getSheet(QString &sheet); +private: + QString m_stSheet; +}; + +#endif // COMMONSHEET_H diff --git a/product/src/tools/debug_tool_v2/FesDef.h b/product/src/tools/debug_tool_v2/FesDef.h new file mode 100644 index 00000000..261d91ff --- /dev/null +++ b/product/src/tools/debug_tool_v2/FesDef.h @@ -0,0 +1,2195 @@ +/* + @file FesDef.h + @brief 头文件 + @author thxiao + @history + 2019-02-20 thxiao 增加转发规约的接口结构;DI增加转发站标志,增加转发功能 + 2019-03-11 thxiao 增加规约映射表,数据按规约点的顺序排列.方便工程在完成的情况下,现场工程又修改了点顺序。 + 2019-03-18 thxiao 转发规约遥控指令需要RtuNo,SFesRxDoCmd\SFesRxAoCmd\SFesRxMoCmd增加定义 + 2019-06-05 thxiao SFesRtuParam 增加车站描述,方便保存录波按“车站\设备”保存 + 2019-06-10 thxiao SFesRtuDevParam 增加录波路径,方便保存录波按“车站\设备”保存 + 2019-06-11 thxiao CN_SFesSimComFrameMaxLen=300 监视帧最大长度由120变为300 + 2019-08-30 thxiao SFesAi 增加 float fPercentValue; 转换后的突变比较范围 + 2019-09-18 thxiao SFesChanParam,SFesRtuParam,增加报警使能 + 2019-10-21 thxiao 点结构增加字段 + 2020-01-16 thxiao 前置点增加点描述 + 2020-03-11 thxiao SFesRtuParam 增加设备类型、整数设备类型,一般为采集串口RTU使用,避免判断字符串,优化查找时间 + +*/ +#pragma once +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +//#include +#include + +#ifdef WIN32 +#pragma warning(disable: 4100)//未引用的形参 +#pragma warning(disable: 4101)//未引用的局部变量 +#pragma warning(disable: 4251)//需要有dll接口由class"xxxx"的客户端使用 +#pragma warning(disable: 4267)// “=”: 从“size_t”转换到“int”,可能丢失数据 +#pragma warning(disable: 4305)// “初始化”: 从“double”到“float”截断 +#pragma warning(disable: 4275)// 非 dll 接口 class“google::protobuf::Message”用作 dll 接口 class“iot_idl:: +#pragma warning(disable: 4819)//该文件包含不能在当前代码页(0)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 +#pragma warning(disable: 4474)// sprintf: 格式字符串中传递的参数太多 +#pragma warning(disable: 4313)//“sprintf”: 格式字符串中的“%d”与“char *”类型的参数 5 冲突 + +#include +#include +#define in_addr_t unsigned long +#define SHUT_RDWR 2 +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN 16 +#endif +#define socklen_t int +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +typedef int SOCKET; +#define INVALID_SOCKET -1 +#define SOCKET_ERROR -1 +#define closesocket close +#define ioctlsocket ioctl +#endif + +#ifndef FESSIM +// 以下头文件FES仿真程序不需要使用,如有包含会编译出错 +#include +#include +#include +#include "pub_utility_api/TimerThreadBase.h" +#include "pub_utility_api/TimeUtil.h" +#include "pub_logger_api/logger.h" +#endif +#include "common/Common.h" +#include "common/DataType.h" +#include "FesRdbStruct.h" + + +#ifdef PROTOCOLBASE_API_EXPORTS +#define PROTOCOLBASE_API G_DECL_EXPORT +#else +#define PROTOCOLBASE_API G_DECL_IMPORT +#endif + +/* +#ifdef PROTOCOLBASE_API_EXPORTS +#ifdef WIN32 +#define PROTOCOLBASE_API G_DECL_EXPORT +#else +//LINUX下 默认情况下会使用C++ API函数命名规则(函数名会增加字符),使用extern "C"修饰后变为C的函数名,便于使用。 +#define PROTOCOLBASE_API extern "C" +#endif +#else +#define PROTOCOLBASE_API G_DECL_IMPORT +#endif +*/ + +using namespace std; + +const float CN_FesFloatCompare = 0.000001;//用于浮点型数据的比较 + +const int CN_FesMaxProtocolNum = 64; //系统可接入规约数 +const int CN_FesMaxRtuNumPerChan = 32; //每个通道可接设备数(只对通道为polling方式) +const int CN_FesMaxChangeMultiple = 5; //变化数据缓冲区为数据个数的倍数 +const int CN_FesMaxDzParamSize =800; //定值参数最大长度 +const int CN_FesMaxDzNum =40; //定值最大个数一帧的定值个数最大40个(KBD104中规定) +const int CN_FesMaxDefCmdSize =512; //自定义命令最大长度 +const int CN_FesMaxWaveFileNameSize =256; //录波文件名最大长度 +const int CN_FesMaxModbusTxCmdNum =200; //MODBUS命令发送缓冲区最大条数 +const int CN_FesMaxFaultNum =4; //事件中最大故障数据 +const int CN_FesFwMaxCollectRtuNum =256; //RTU转发表里的采集RTU最大个数 +const int CN_Fes_Fw_MaxMapping = 16; //转发协议最大转发站数目 + +//模拟量死区类型 +const int CN_FesDeadbandType_Percent = 0; //上下限百分比 +const int CN_FesDeadbandType_Abs = 1; //绝对值 +const int CN_FesDeadbandType_None = 2; //不判断死区 + +//点值状态 +const int CN_FesValueNotUpdate =0x00; //BIT0: 0:点值未更新 1:点已更新 +const int CN_FesValueUpdate =0x01; //BIT0: 0:点值未更新 1:点已更新 +const int CN_FesValueInvaild =0x02; //BIT1:0:点值有效 1:点值无效 设备报告无效 +const int CN_FesValueExceed =0x04; //BIT2:0:点值正常 1:点值超限 +const int CN_FesValueComDown =0x08; //BIT3:0:通信正常 1: 通信中断 +const int CN_FesDoUnBlocked =0x80; //BIT7:0:五防闭锁 1: 五防解锁 + +//RTU状态 +const int CN_FesRtuNotUsed = 0; //保留未用 +const int CN_FesRtuNormal = 1; //RTU正常 +const int CN_FesRtuComDown = 2; //RTU通信中断 + +//通道状态 +const int CN_FesChanNotUsed = 0; //保留未用 +const int CN_FesChanCheck = 1; //通道检测,使用但未正常通信 +const int CN_FesChanRun = 2; //通道运行 +const int CN_FesChanStop = 3; //通道停止 +const int CN_FesChanErrRate = 4; //接收帧错误率高 错误率可以设置 + +//事件类型 +const int CN_FesRtuSoeEvent = 1; //接入设备(RTU)SOE事件 +const int CN_FesFepSoeEvent = 2; //前置终端(FEP)生成SOE事件 +const int CN_FesRtuEvent = 3; //RTU事件 +const int CN_FesChanEvent = 4; //通道事件 + +//通道性质 +const int CN_FesComProperty_Collect = 0; //采集通道 +const int CN_FesComProperty_Transmit = 1; //转发通道 + +//通道类型 +const int CN_FesComNone =0; +const int CN_FesTcpClient =1; +const int CN_FesTcpServer =2; +const int CN_FesUdpClient =3; +const int CN_FesUdpServer =4; +const int CN_FesSerialPort =5; + +//通道方式 +const int CN_FesDoubleChanMode = 0; //0:双通道通信方式 +const int CN_FesSingleChanMode = 1; //1:单通道方式 + + +//通道方式 +const int CN_FesRunFlag = 1; //运行标志 +const int CN_FesStopFlag = 0; //停运标志 + +//通道数据LinkStatus状态定义 +const int CN_FesChanDisconnect =0; //通道停运 +const int CN_FesChanConnecting =1; //正在连接 +const int CN_FesChanConnect =2; //链接成功,通道运行 + + +//控制命令定义:选择、取消、执行 +const int CN_ControlSelect =1; +const int CN_ControlAbort =2; +const int CN_ControlExecute =3; +const int CN_ControlPrevent = 4; + +//定值命令定义: 读取、切区、下装、确定 +const int CN_SettingRead =1; +const int CN_SettingAreaSwitch =2; +const int CN_SettingDownload =3; +const int CN_SettingAck =4; + +//控制命令返回状态 +const int CN_ControlFailed =0; +const int CN_ControlSuccess =1; +const int CN_ControlPointErr =2; + +//AO命令数值类型 +const int CN_AoValueType_Float =0; +const int CN_AoValueType_Int =1; + +//FesSimServer +const int CN_FesSimSoeEventMaxBufSize =1024; +const int CN_FesSimRtuEventMaxBufSize =256; +const int CN_FesSimChanEventMaxBufSize =256; +const int CN_FesSimChanMonMaxBufSize =512; + +//通信监视数据 +const int CN_SFesSimComFrameMaxLen =300; //监视帧最大长度 +const int CN_SFesSimComFrameTypeRecv = 0; //监视帧类型:接收 +const int CN_SFesSimComFrameTypeSend = 1; //监视帧类型:发送 +const int CN_SFesSimComDataType_Data = 0; //监视帧数据类型:数据 +const int CN_SFesSimComDataType_Str = 1; //监视帧数据类型:字符数据 +const int CN_SFesSimComFrameMaxNum = 7; //每次发送监视帧最大个数 + +const int CN_FesControlStrParamSize = 256; + +//故障相定义 (SFesSoeEvent结构中FaultValTag定义) +const int CN_Fes_IA =1; +const int CN_Fes_IB =2; +const int CN_Fes_IC =3; +const int CN_Fes_I0 =4; +const int CN_Fes_I2 =5; +const int CN_Fes_UA =6; +const int CN_Fes_UB =7; +const int CN_Fes_UC =8; +const int CN_Fes_U0 =9; +const int CN_Fes_U2 =10; +const int CN_Fes_UAB =11; +const int CN_Fes_UBC =12; +const int CN_Fes_UCA =13; +const int CN_Fes_CLOSE_NUM =14; + +//控制方向 0:FES外部(HMI) 1:FES内部(转发规约) +const int CN_Fes_CtrlDir_OutSide=0; +const int CN_Fes_CtrlDir_InSide=1; + +//转发点数据来源 +const int CN_FesFw_FesSrc = 0; //来源于FES +const int CN_FesFw_DPSrc = 1; //来源于DP + +//遥信点类型 +const int CN_FesFw_SDI = 0; //单点 +const int CN_FesFw_DDI = 1; //双点 + +//点所属专业最多个数 +const int CN_FesSubSystem_Max_Num = 16; + +//点类型 +const int CN_Fes_AI = 1; +const int CN_Fes_DI = 2; +const int CN_Fes_ACC = 3; +const int CN_Fes_MI = 4; +const int CN_Fes_DO = 5; +const int CN_Fes_A0 = 6; +const int CN_Fes_MO = 7; +const int CN_Fes_Setting = 8; + +const float CN_FesFwAIChangeScale = 0.0001; + +//RTU 类型 +const int CN_Fes_RTU_Collect = 0;//采集RTU +const int CN_Fes_RTU_Forward = 1;//转发RTU + +//Modbus Frame Type +#define DI_BYTE_LH 0 //数字量帧(单字节) +#define DI_UWord_HL 1 //数字量帧(16bit 高字节前) +#define DI_UWord_LH 2 //数字量帧(16bit 低字节前) +#define AI_Word_HL 3 //模拟量帧(16bit 有符号 高字节前) +#define AI_Word_LH 4 //模拟量帧(16bit 有符号 低字节前) +#define AI_UWord_HL 5 //模拟量帧(16bit 无符号 高字节前) +#define AI_UWord_LH 6 //模拟量帧(16bit 无符号 低字节前) +#define AI_DWord_HH 7 //模拟量帧(32bit 有符号 高字前 高字节前) +#define AI_DWord_LH 8 //模拟量帧(32bit 有符号 低字前 高字节前) +#define AI_DWord_LL 9 //模拟量帧(32bit 有符号 低字前 低字节前) +#define AI_UDWord_HH 10 //模拟量帧(32bit 无符号 高字前 高字节前) +#define AI_UDWord_LH 11 //模拟量帧(32bit 无符号 低字前 高字节前) +#define AI_UDWord_LL 12 //模拟量帧(32bit 无符号 低字前 低字节前) +#define AI_Float_HH 13 //模拟量帧(四字节浮点 高字前 高字节前) +#define AI_Float_LH 14 //模拟量帧(四字节浮点 低字前 高字节前) +#define AI_Float_LL 15 //模拟量帧(四字节浮点 低字前 低字节前) +#define ACC_Word_HL 16 //整形量帧(16bit 有符号 高字节前) +#define ACC_Word_LH 17 //整形量帧(16bit 有符号 低字节前) +#define ACC_UWord_HL 18 //整形量帧(16bit 无符号 高字节前) +#define ACC_UWord_LH 19 //整形量帧(16bit 无符号 低字节前) +#define ACC_DWord_HH 20 //整形量帧(32bit 有符号 高字前 高字节前) +#define ACC_DWord_LH 21 //整形量帧(32bit 有符号 低字前 高字节前) +#define ACC_DWord_LL 22 //整形量帧(32bit 有符号 低字前 低字节前) +#define ACC_UDWord_HH 23 //整形量帧(32bit 无符号 高字前 高字节前) +#define ACC_UDWord_LH 24 //整形量帧(32bit 无符号 低字前 高字节前) +#define ACC_UDWord_LL 25 //整形量帧(32bit 无符号 低字前 低字节前) +#define ACC_Float_HH 26 //整形量帧(四字节浮点 高字前 高字节前) +#define ACC_Float_LH 27 //整形量帧(四字节浮点 低字前 高字节前) +#define ACC_Float_LL 28 //整形量帧(四字节浮点 低字前 低字节前) +#define MI_Word_HL 29 //混合量帧(16bit 有符号 高字节前) +#define MI_Word_LH 30 //混合量帧(16bit 有符号 低字节前) +#define MI_UWord_HL 31 //混合量帧(16bit 无符号 高字节前) +#define MI_UWord_LH 32 //混合量帧(16bit 无符号 低字节前) +#define MI_DWord_HH 33 //混合量帧(32bit 有符号 高字前 高字节前) +#define MI_DWord_LH 34 //混合量帧(32bit 有符号 低字前 高字节前) +#define MI_DWord_LL 35 //混合量帧(32bit 有符号 低字前 低字节前) +#define MI_UDWord_HH 36 //混合量帧(32bit 无符号 高字前 高字节前) +#define MI_UDWord_LH 37 //混合量帧(32bit 无符号 低字前 高字节前) +#define MI_UDWord_LL 38 //混合量帧(32bit 无符号 低字前 低字节前) + +#define SPEAM_SOE 40 //施耐德SOE帧 +#define PLC_DZ 41 //PLC_DZ +#define PLC_SOE 42 //PLC_SOE +#define PLC_DZ_DWord_HH 43 //PLC_DZ(四字节定值,高字前、高字节前) + +#define AI_Hybrid_Type 44 //模拟量混合量帧 +#define ACC_Hybrid_Type 45 //累积量混合量帧 + +#define DZ_DI_BYTE_LH 46 //数字量帧(单字节) +#define DZ_DI_UWord_HL 47 //数字量帧(16bit 高字节前) +#define DZ_DI_UWord_LH 48 //数字量帧(16bit 低字节前) +#define DZ_AI_Word_HL 49 //模拟量帧(16bit 有符号 高字节前) +#define DZ_AI_Word_LH 50 //模拟量帧(16bit 有符号 低字节前) +#define DZ_AI_UWord_HL 51 //模拟量帧(16bit 无符号 高字节前) +#define DZ_AI_UWord_LH 52 //模拟量帧(16bit 无符号 低字节前) +#define DZ_AI_DWord_HH 53 //模拟量帧(32bit 有符号 高字前 高字节前) +#define DZ_AI_DWord_LH 54 //模拟量帧(32bit 有符号 低字前 高字节前) +#define DZ_AI_DWord_LL 55 //模拟量帧(32bit 有符号 低字前 低字节前) +#define DZ_AI_UDWord_HH 56 //模拟量帧(32bit 无符号 高字前 高字节前) +#define DZ_AI_UDWord_LH 57 //模拟量帧(32bit 无符号 低字前 高字节前) +#define DZ_AI_UDWord_LL 58 //模拟量帧(32bit 无符号 低字前 低字节前) +#define DZ_AI_Float_HH 59 //模拟量帧(四字节浮点 高字前 高字节前) +#define DZ_AI_Float_LH 60 //模拟量帧(四字节浮点 低字前 高字节前) +#define DZ_AI_Float_LL 61 //模拟量帧(四字节浮点 低字前 低字节前) + + +/********************************************************************************************************************/ +//以下内部结构 +//主备通道状态 +#define EN_MAIN_CHAN 0 +#define EN_BACKUP_CHAN 1 + +//线程运行状态 +#define EN_THREAD_STOP 0 +#define EN_THREAD_RUN 1 + + +//转发五防闭锁标志 +#define CN_FW_YK_UNBLOCK 0x8000 //五防解锁 +#define CN_FW_YK_BLOCK 0x0000 //五防闭锁 +#define CN_FW_YK_UNBLOCKCLEAR 0x7fff //五防解锁清除 + + +//MODBUS配置 +typedef struct _SModbusCmd{ + int Index; //序号 + int Rtuaddr; //设备站址 + int FunCode; //功能码(即MODBUS中的命令码) + int StartAddr; //数据起始地址 + int DataLen; //数据长度 + int PollTime; //命令下发周期(相对时间,一个周期=50ms) + int Type; //帧类别 + int PollTimeCount; //命令下发周期计数 + int IsCreateSoe; //对遥信帧有效,0:不产生SOE,1:产生SOE + int Param1; //保留参数1 + int Param2; //保留参数2 + int Param3; //保留参数3 + int Param4; //保留参数4 + int Used; //块使能 + bool CommandSendFlag; //数据块轮询时间到就开始发送 + int64 lastPollTime; + _SModbusCmd() + { + Index=0; //序号 + Rtuaddr=0; //设备站址 + FunCode=0; //功能码(即MODBUS中的命令码) + StartAddr=0; //数据起始地址 + DataLen=0; //数据长度 + PollTime=0; //命令下发周期(相对时间,一个周期=50ms) + Type=0; //帧类别 + PollTimeCount=0; //命令下发周期计数 + IsCreateSoe=0; //对遥信帧有效,0:不产生SOE,1:产生SOE + Param1 = 0; //保留参数1 + Param2 = 0; //保留参数2 + Param3 = 0; //保留参数3 + Param4 = 0; //保留参数4 + Used = 1; + CommandSendFlag = true; //数据块轮询时间到就开始发送(数据块第一次都会发送) + lastPollTime = 0; + } +}SModbusCmd; + +typedef struct { + int num; + int readx; + int writex; + SModbusCmd *pCmd; +}SModbusCmdBuf; + +typedef struct { + int readx; + int writex; + SModbusCmd cmd[CN_FesMaxModbusTxCmdNum]; +}SModbuTxCmdBuf; + +typedef struct { + int MappingIndex; + int RemoteNo; +}SFesFwMapping; + +typedef struct { + int SrcSubSystem; //点所属专业 + int AiFlag; + int DiFlag; + int AccFlag; + int MiFlag; +}SFesSubSystem; + +//变化数据缓存区 +const int CN_SFesAiJudge_Deadband = 0x01; +const int CN_SFesAiJudge_Limit = 0x02; + +typedef struct _SFesAi{ + int PointNo; + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char PointTagName[CN_FesMaxTagSize]; + char PointDesc[CN_FesMaxDescSize];//2020-01-16 thxiao 增加点描述 + short IsFilter; //是否过滤AI突变 + short IsZeroBand;//是否判断归零死区 + int Percent; //突变百分比 + float fPercentValue; //2019-08-30 thxiao 转换后的突变比较范围 + int DeadBandType;//死区类型 + float DeadBand; //死区值 + float ZeroBand; //归零死区 + float Base; //基值 + float Coeff; //系数; + float MaxRange; //度上限 + float MinRange; //度下限 + int Param1; //规约参数,每种协议含义相同。 + int Param2; //规约参数,每种协议含义相同。 如modbus FunNo + int Param3; //规约参数,每种协议含义相同。 如modbus DataAddress + int Param4; //规约参数,每种协议含义相同。 + int Param5; //规约参数,每种协议含义相同。 + int Param6; //规约参数,每种协议含义相同。 + int Param7; //规约参数,每种协议含义相同。 + int Param8; //规约参数,每种协议含义相同。 + int Used; + float DeadBandValue;//根据配置计算处理的死区 + int JudgeFlag; //判断标志,置位了,才做对应的判断 + float Value; + float LastFilterValue; //上次收到的值,用于过滤AI突变 + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + int FwMapNum; //转发映射个数 + SFesFwMapping FwMapping[CN_Fes_Fw_MaxMapping];//对应的转发点号,快速找到转发点 + _SFesAi(){ + PointNo = 0; + memset(TableName, 0, CN_FesMaxTableNameSize); + memset(ColumnName, 0, CN_FesMaxColumnNameSize); + memset(TagName, 0, CN_FesMaxTagSize); + memset(PointTagName, 0, CN_FesMaxTagSize); + memset(PointDesc, 0, CN_FesMaxDescSize); + IsFilter = 0; + Percent = 0; + fPercentValue = 0; + DeadBandType = 0; + DeadBand = 0; + ZeroBand = 0; + Base = 0.0; + Coeff = 0.0; + MaxRange = 0.0; + MinRange = 0.0; + Param1 = 0; + Param2 = 0; + Param3 = 0; + Param4 = 0; + Param5 = 0; + Param6 = 0; + Param7 = 0; + Param8 = 0; + Used = 0; + DeadBandValue = 0; + JudgeFlag = 0; + Value = 0; + LastFilterValue = 0; + Status = 0; + time = 0; + FwMapNum = 0; + memset(&FwMapping[0], 0, sizeof(SFesFwMapping)*CN_Fes_Fw_MaxMapping); + } + +}SFesAi; + +typedef struct _SFesDi { + int PointNo; + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char PointTagName[CN_FesMaxTagSize]; + char PointDesc[CN_FesMaxDescSize];//2020-01-16 thxiao 增加点描述 + int IsFilterErr; //是否过滤错误DI + int IsFilterDisturb;//是否过滤DI抖动 + int DisturbTime; //抖动时限 + int Revers; //取反 + int Attribute; //点属性 + int RelateDI; //关联遥信 + int Param1; //规约参数,每种协议含义相同。 如modbus FunNo + int Param2; //规约参数,每种协议含义相同。 如modbus DataAddress + int Param3; //规约参数,每种协议含义相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 + int Param5; //规约参数,每种协议含义相同。 + int Param6; //规约参数,每种协议含义相同。 + int Param7; //规约参数,每种协议含义相同。 + int Param8; //规约参数,每种协议含义相同。 + int Used; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + int FwMapNum; //转发映射个数 + SFesFwMapping FwMapping[CN_Fes_Fw_MaxMapping];//对应的转发点号,快速找到转发点 + _SFesDi() { + PointNo = 0; + memset(TableName, 0, CN_FesMaxTableNameSize); + memset(ColumnName, 0, CN_FesMaxColumnNameSize); + memset(TagName, 0, CN_FesMaxTagSize); + memset(PointTagName, 0, CN_FesMaxTagSize); + memset(PointDesc, 0, CN_FesMaxDescSize); + IsFilterErr = 0; + IsFilterDisturb = 0; + DisturbTime = 0; + Revers = 0; + Attribute = 0; + RelateDI = 0; + Param1 = 0; + Param2 = 0; + Param3 = 0; + Param4 = 0; + Param5 = 0; + Param6 = 0; + Param7 = 0; + Param8 = 0; + Used = 0; + Value = 0; + Status = 0; + time = 0; + FwMapNum = 0; + memset(&FwMapping[0], 0, sizeof(SFesFwMapping)*CN_Fes_Fw_MaxMapping); + } +}SFesDi; + +typedef struct _SFesAcc { + int PointNo; + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char PointTagName[CN_FesMaxTagSize]; + char PointDesc[CN_FesMaxDescSize];//2020-01-16 thxiao 增加点描述 + float Base; //基值 + double Coeff; //系数; + int Param1; //规约参数,每种协议各不相同。 如modbus FunNo + int Param2; //规约参数,每种协议各不相同。 如modbus DataAddress + int Param3; //规约参数,每种协议各不相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 如modbus ValueType + int Param5; //规约参数,每种协议含义相同。 + int Param6; //规约参数,每种协议含义相同。 + int Param7; //规约参数,每种协议含义相同。 + int Param8; //规约参数,每种协议含义相同。 + int Used; + int64 Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + int FwMapNum; //转发映射个数 + SFesFwMapping FwMapping[CN_Fes_Fw_MaxMapping];//对应的转发点号,快速找到转发点 + _SFesAcc() { + PointNo = 0; + memset(TableName, 0, CN_FesMaxTableNameSize); + memset(ColumnName, 0, CN_FesMaxColumnNameSize); + memset(TagName, 0, CN_FesMaxTagSize); + memset(PointTagName, 0, CN_FesMaxTagSize); + memset(PointDesc, 0, CN_FesMaxDescSize); + Base = 0; + Coeff = 0; + Param1 = 0; + Param2 = 0; + Param3 = 0; + Param4 = 0; + Param5 = 0; + Param6 = 0; + Param7 = 0; + Param8 = 0; + Used = 0; + Value = 0; + Status = 0; + time = 0; + FwMapNum = 0; + memset(&FwMapping[0], 0, sizeof(SFesFwMapping)*CN_Fes_Fw_MaxMapping); + } +}SFesAcc; + + +typedef struct _SFesMi { + int PointNo; + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char PointTagName[CN_FesMaxTagSize]; + char PointDesc[CN_FesMaxDescSize];//2020-01-16 thxiao 增加点描述 + int Base; //基值 + int Coeff; //系数; + int MaxRange; //度上限 + int MinRange; //度下限 + int Param1; //规约参数,每种协议各不相同。 如modbus FunNo + int Param2; //规约参数,每种协议各不相同。 如modbus DataAddress + int Param3; //规约参数,每种协议各不相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 如modbus ValueType + int Param5; //规约参数,每种协议含义相同。 + int Param6; //规约参数,每种协议含义相同。 + int Param7; //规约参数,每种协议含义相同。 + int Param8; //规约参数,每种协议含义相同。 + int Used; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + int FwMapNum; //转发映射个数 + SFesFwMapping FwMapping[CN_Fes_Fw_MaxMapping];//对应的转发点号,快速找到转发点 + _SFesMi() { + PointNo = 0; + memset(TableName, 0, CN_FesMaxTableNameSize); + memset(ColumnName, 0, CN_FesMaxColumnNameSize); + memset(TagName, 0, CN_FesMaxTagSize); + memset(PointTagName, 0, CN_FesMaxTagSize); + memset(PointDesc, 0, CN_FesMaxDescSize); + Base = 0; + Coeff = 0; + MaxRange = 0; + MinRange = 0; + Param1 = 0; + Param2 = 0; + Param3 = 0; + Param4 = 0; + Param5 = 0; + Param6 = 0; + Param7 = 0; + Param8 = 0; + Used = 0; + Value = 0; + Status = 0; + time = 0; + FwMapNum = 0; + memset(&FwMapping[0], 0, sizeof(SFesFwMapping)*CN_Fes_Fw_MaxMapping); + } +}SFesMi; + +typedef struct { + char used; + char unBlockFlag; //1:解锁 0:闭锁 +}SFesWfParam; + + +//Attribute +//Bit0 遥控类型。0脉冲输出,1自保持输出(需要程序清零)。 +//Bit1 遥控复归。0:表示普通遥控,1:表示复归。 +//Bit2 特殊遥控点0:表示普通遥控,1:特殊遥控点。 +const int CN_FesDo_Normal = 0x00; +const int CN_FesDo_Pulse = 0x00; +const int CN_FesDo_Keep = 0x01; +const int CN_FesDo_Reset = 0x02; +const int CN_FesDo_Special = 0x04; + +typedef struct _SFesDo { + int PointNo; + char PointTagName[CN_FesMaxTagSize]; + char PointDesc[CN_FesMaxDescSize];//2020-01-16 thxiao 增加点描述 + int Attribute; //点属性 + int ControlParam; //遥控参数 + int Param1; //规约参数,每种协议含义相同。 如modbus FunNo + int Param2; //规约参数,每种协议含义相同。 如modbus DataAddress + int Param3; //规约参数,每种协议含义相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 + int Param5; //规约参数,每种协议含义相同。 + int Param6; //规约参数,每种协议含义相同。 + int Param7; //规约参数,每种协议含义相同。 + int Param8; //规约参数,每种协议含义相同。 + int Used; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + SFesWfParam wfParam;//五防参数 + _SFesDo() { + PointNo = 0; + memset(PointTagName, 0, CN_FesMaxTagSize); + memset(PointDesc, 0, CN_FesMaxDescSize); + memset(&wfParam, 0, sizeof(wfParam)); + Attribute = 0; + ControlParam = 0; + Param1 = 0; + Param2 = 0; + Param3 = 0; + Param4 = 0; + Param5 = 0; + Param6 = 0; + Param7 = 0; + Param8 = 0; + Used = 0; + Value = 0; + Status = 0; + time = 0; + } +}SFesDo; + +typedef struct _SFesAo { + int PointNo; + char PointTagName[CN_FesMaxTagSize]; + char PointDesc[CN_FesMaxDescSize];//2020-01-16 thxiao 增加点描述 + float Base; //基值 + float Coeff; //系数; + float MaxRange; //度上限 + float MinRange; //度下限 + int Param1; //规约参数,每种协议含义相同。 如modbus FunNo + int Param2; //规约参数,每种协议含义相同。 如modbus DataAddress + int Param3; //规约参数,每种协议含义相同。 如modbus InfoNo + int Param4; //规约参数,每种协议含义相同。 + int Param5; //规约参数,每种协议含义相同。 + int Param6; //规约参数,每种协议含义相同。 + int Param7; //规约参数,每种协议含义相同。 + int Param8; //规约参数,每种协议含义相同。 + int Used; + float Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + _SFesAo() { + PointNo = 0; + memset(PointTagName, 0, CN_FesMaxTagSize); + memset(PointDesc, 0, CN_FesMaxDescSize); + Base = 0; + Coeff = 0; + MaxRange = 0; + MinRange = 0; + Param1 = 0; + Param2 = 0; + Param3 = 0; + Param4 = 0; + Param5 = 0; + Param6 = 0; + Param7 = 0; + Param8 = 0; + Used = 0; + Value = 0; + Status = 0; + time = 0; + } +}SFesAo; + +typedef struct _SFesMo{ + int PointNo; + char PointTagName[CN_FesMaxTagSize]; + char PointDesc[CN_FesMaxDescSize];//2020-01-16 thxiao 增加点描述 + int Base; //基值 + int Coeff; //系数; + int MaxRange; //度上限 + int MinRange; //度下限 + int Param1; //规约参数,每种协议各不相同。 如modbus FunNo + int Param2; //规约参数,每种协议各不相同。 如modbus DataAddress + int Param3; //规约参数,每种协议各不相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 如modbus ValueType + int Param5; //规约参数,每种协议含义相同。 + int Param6; //规约参数,每种协议含义相同。 + int Param7; //规约参数,每种协议含义相同。 + int Param8; //规约参数,每种协议含义相同。 + int Used; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + _SFesMo() { + PointNo = 0; + memset(PointTagName, 0, CN_FesMaxTagSize); + memset(PointDesc, 0, CN_FesMaxDescSize); + Base = 0; + Coeff = 0; + MaxRange = 0; + MinRange = 0; + Param1 = 0; + Param2 = 0; + Param3 = 0; + Param4 = 0; + Param5 = 0; + Param6 = 0; + Param7 = 0; + Param8 = 0; + Used = 0; + Value = 0; + Status = 0; + time = 0; + } +}SFesMo; + + +typedef struct { + int PointNo; + // char TagName[CN_FesMaxTagSize]; + char PointTagName[CN_FesMaxTagSize]; + int GroupNo; //定值组号 + int CodeNo; //定值代号 + int SeqNo; //定值序号 + int DzType; //定值类型 + int Unit; //单位 + double Base; //基值 + double Coeff; //系数; + double MaxRange; //度上限 + double MinRange; //度下限 + int Param1; //规约参数 + int Param2; //规约参数 + int Param3; //规约参数 + int Param4; //规约参数 + int Param5; //规约参数,每种协议含义相同。 + int Param6; //规约参数,每种协议含义相同。 + int Param7; //规约参数,每种协议含义相同。 + int Param8; //规约参数,每种协议含义相同。 + int Used; + int ValueType; + union + { + int iVal; + float fVal; + + }Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesDz; + +//转发表变化数据缓冲区 +typedef struct { + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + char DPTagName[CN_FesMaxTagSize]; //后台标签名 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + int DpSeqNo; //组号 + double Coeff; //系数; + double Base; //修正值 + int DeadBandType; //死区类型 + double DeadBand; //配置死区值 + float RealDeadBandValue; //< 根据死区类型计算后的实际死区,运行时不再需要进行死区类型的判断 + int Property; //属性 + int SrcLocationID; //所属厂站 + int SrcSubSystem; //所属专业 + int ResParam1; //规约参数1 + int ResParam2; //规约参数2 + int ResParam3; //规约参数3 + int ResParam4; //规约参数4 + int ResParam5; //规约参数5 + int ResParam6; //规约参数6 + int ResParam7; //规约参数7 + char StrParam[CN_FesMaxTagSize]; + int SrcType; //点来源(0:FES 1:DP) + int Used; + float Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwAi; + +typedef struct { + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + char DPTagName[CN_FesMaxTagSize]; //后台标签名 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + int DpSeqNo; //后台点序号 + int Property; //属性 + int SrcLocationID; //所属厂站 + int SrcSubSystem; //所属专业 + int ResParam1; //规约参数1 + int ResParam2; //规约参数2 + int ResParam3; //规约参数3 + int ResParam4; //规约参数4 + int ResParam5; //规约参数5 + int ResParam6; //规约参数6 + int ResParam7; //规约参数7 + char StrParam[CN_FesMaxTagSize]; + int SrcType; //点来源(0:FES 1:DP) + short Used; + short InitFlag; //数值已更新,因为DP->FES数据要产生SOE,所以需要。 + int Value; + uint32 Status; //bit7:1 (五防解锁) 0(五防闭锁) + uint64 time; //1970-01-01 00:00 至今的毫秒数 + //五防信息 + int DORemoteNo; //对应的转发遥控号 +}SFesFwDi; + +typedef struct { + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + char DPTagName[CN_FesMaxTagSize]; //后台标签名 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + int DpSeqNo; //后台点序号 + double Coeff; //系数; + double Base; //修正值 + int Property; //属性 + int SrcLocationID; //所属厂站 + int SrcSubSystem; //所属专业 + int ResParam1; //规约参数1 + int ResParam2; //规约参数2 + int ResParam3; //规约参数3 + int ResParam4; //规约参数4 + int ResParam5; //规约参数5 + int ResParam6; //规约参数6 + int ResParam7; //规约参数7 + char StrParam[CN_FesMaxTagSize]; + int SrcType; //点来源(0:FES 1:DP) + int Used; + int64 Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwAcc; + +typedef struct { + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + char DPTagName[CN_FesMaxTagSize]; //后台标签名 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + int DpSeqNo; //组号 + double Coeff; //系数; + double Base; //修正值 + int Property; //属性 + int SrcLocationID; //所属厂站 + int SrcSubSystem; //所属专业 + int ResParam1; //规约参数1 + int ResParam2; //规约参数2 + int ResParam3; //规约参数3 + int ResParam4; //规约参数4 + int ResParam5; //规约参数5 + int ResParam6; //规约参数6 + int ResParam7; //规约参数7 + char StrParam[CN_FesMaxTagSize]; + int SrcType; //点来源(0:FES 1:DP) + int Used; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwMi; + +typedef struct { + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + double MaxRange; //度上限 + double MinRange; //度下限 + double Coeff; //系数; + double Base; //修正值 + int Property; //属性 + int SrcLocationID; //所属厂站 + int SrcSubSystem; //所属专业 + int ResParam1; //规约参数1 + int ResParam2; //规约参数2 + int ResParam3; //规约参数3 + int ResParam4; //规约参数4 + int ResParam5; //规约参数5 + int ResParam6; //规约参数6 + int ResParam7; //规约参数7 + char StrParam[CN_FesMaxTagSize]; + int SrcType; //点来源(0:FES 1:DP) + int Used; + float Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwAo; + +const int CN_FesFwDoPointNum=5; + +typedef struct { + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + int FesRtuNo; //采集rtu号 + int FesPointNum;//分量数 + int FesPointNo[CN_FesFwDoPointNum]; //采集点号 + int Property; //属性 + int SrcLocationID; //所属厂站 + int SrcSubSystem; //所属专业 + int ResParam1; //规约参数1 + int ResParam2; //规约参数2 + int ResParam3; //规约参数3 + int ResParam4; //规约参数4 + int ResParam5; //规约参数5 + int ResParam6; //规约参数6 + int ResParam7; //规约参数7 + char StrParam[CN_FesMaxTagSize]; + int SrcType; //点来源(0:FES 1:DP) + int Used; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + //五防信息 + int DIRemoteNo; //对应的转发遥信号 + uint64 WfBlockedTimeout; //五防闭锁时间 +}SFesFwDo; + +typedef struct { + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + double MaxRange; //度上限 + double MinRange; //度下限 + int Property; //属性 + int SrcLocationID; //所属厂站 + int SrcSubSystem; //所属专业 + int ResParam1; //规约参数1 + int ResParam2; //规约参数2 + int ResParam3; //规约参数3 + int ResParam4; //规约参数4 + int ResParam5; //规约参数5 + int ResParam6; //规约参数6 + int ResParam7; //规约参数7 + char StrParam[CN_FesMaxTagSize]; + int SrcType; //点来源(0:FES 1:DP) + int Used; + float Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwMo; + + +//FES间的RTU数据交互 +typedef struct { + int PointNo; + float Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesRtuAiValue; + +typedef struct { + int PointNo; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesRtuDiValue; + +typedef struct { + int PointNo; + int64 Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesRtuAccValue; + +typedef struct { + int PointNo; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesRtuMiValue; + +//Fes间采集RTU与转发RTU数据交互 +typedef struct { + int PointNo; + float Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwRtuAiValue; + +typedef struct { + int PointNo; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwRtuDiValue; + +typedef struct { + int PointNo; + int64 Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwRtuAccValue; + + +//SCADA 与FES间的数据交互 变化数据缓存区 +typedef struct { + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + uint32 Status; + float Value; + uint64 time; + int RtuNo; + int PointNo; +}SFesChgAi; + +typedef struct { + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + uint32 Status; + int Value; + uint64 time; + int RtuNo; + int PointNo; +}SFesChgDi; + +typedef struct { + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + uint32 Status; + int64 Value; + uint64 time; + int RtuNo; + int PointNo; +}SFesChgAcc; + +typedef struct { + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + uint32 Status; + int Value; + uint64 time; + int RtuNo; + int PointNo; +}SFesChgMi; + +//SCADA 与FES间的数据交互 全数据 +typedef struct { + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + uint32 Status; + float Value; +}SFesAllAi; + +typedef struct { + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + uint32 Status; + int Value; +}SFesAllDi; + +typedef struct { + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + uint32 Status; + int64 Value; +}SFesAllAcc; + +typedef struct { + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + uint32 Status; + int Value; +}SFesAllMi; + +typedef struct{ + int ChanNo; + int Status; + float ErrRate; + uint64 time; +}SFesChanStatus; + +typedef struct{ + int RtuNo; + int Status; + uint64 time; +}SFesRtuStatus; + +typedef struct{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + uint32 Status; //遥测信状态 + int Value; //点值 + uint64 time; //1970-01-01 00:00 至今的毫秒数 + int FaultNum; //故障值个数 + int FaultValTag [CN_FesMaxFaultNum];//表明以下数值的来源 + float FaultVal[CN_FesMaxFaultNum]; + int RtuNo; //RTU号 + int PointNo; +}SFesSoeEvent; + +typedef struct{ + char ChanTagName[CN_FesMaxTagSize];//通道标签 + int nChannelNo; //通道号 + char ChanName[CN_FesMaxNameSize];//通道名词 + char ChanDesc[CN_FesMaxDescSize];//通道描述 + int nLocationId; //车站 + int nSubSystem; //专业 + int nRegionId; //责任区ID + uint32 Status; //通道状态 + float ErrRate; //通道误码率 + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesChanEvent; + +typedef struct{ + char RtuTagName[CN_FesMaxTagSize];//RTU标签 + int nRtuNo; //RTU号 + char RtuName[CN_FesMaxNameSize];//rtu名词 + char RtuDesc[CN_FesMaxDescSize];//rtu描述 + int nLocationId; //车站 + int nSubSystem; //专业 + int nRegionId; //责任区ID + uint32 Status; //RTU状态 + int CurrentChanNo; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesRtuEvent; + + +typedef struct _SFesRxDoCmd{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int CtrlDir; //控制方向 0:FES外部(HMI) 1:FES内部(转发规约) + int FwSubSystem; //转发专业 + int FwRtuNo; //转发RTU号 + int FwPointNo; //转发点号 + int RtuNo; //源RTU号 + int PointID; //源点号 + int SubSystem; //源专业 + int iValue; //目标值(DO、MO) + int CtrlActType; //控制类型 选择、取消、执行, + int TagtState; + uint64 Param1; + uint64 Param2; + float fParam; + char strParam[CN_FesControlStrParamSize]; + _SFesRxDoCmd() + { + memset(TableName,0,sizeof(TableName)); + memset(ColumnName,0,sizeof(ColumnName)); + memset(TagName,0,sizeof(TagName)); + memset(RtuName,0,sizeof(RtuName)); + CtrlDir=0; + RtuNo = 0; + PointID = 0; + SubSystem = 0; + FwSubSystem = 0; + FwRtuNo = 0; + FwPointNo = 0; + iValue = 0; //目标值(DO、MO) + CtrlActType = 0; //控制类型 选择、取消、执行, + TagtState = 0; + Param1 = 0; + Param2 = 0; + fParam = 0; + memset(strParam,0,sizeof(strParam)); + } +}SFesRxDoCmd; + +typedef struct _SFesTxDoCmd{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int CtrlDir; //控制方向 0:FES外部(HMI) 1:FES内部(转发规约) + int FwSubSystem; //转发专业 + int FwRtuNo; //转发RTU号 + int FwPointNo; //转发点号 + int RtuNo; //源RTU号 + int PointID; //源点号 + int SubSystem; //源专业 + int retStatus; //返回状态 + uint64 Param1; + uint64 Param2; + float fParam; + char strParam[CN_FesControlStrParamSize]; + int CtrlActType; //控制类型 选择、取消、执行, + _SFesTxDoCmd() + { + memset(TableName,0,sizeof(TableName)); + memset(ColumnName,0,sizeof(ColumnName)); + memset(TagName,0,sizeof(TagName)); + memset(RtuName,0,sizeof(RtuName)); + CtrlDir=0; + RtuNo = 0; + PointID = 0; + SubSystem = 0; + FwSubSystem = 0; + FwRtuNo = 0; + FwPointNo = 0; + retStatus = 0; //返回状态 + CtrlActType = 0; //控制类型 选择、取消、执行, + Param1 = 0; + Param2 = 0; + fParam = 0; + memset(strParam,0,sizeof(strParam)); + } +}SFesTxDoCmd; + +typedef struct _SFesRxAoCmd{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int CtrlDir; //控制方向 0:FES外部(HMI) 1:FES内部(转发规约) + int FwSubSystem; //转发专业 + int FwRtuNo; //转发RTU号 + int FwPointNo; //转发点号 + int RtuNo; //源RTU号 + int PointID; //源点号 + int SubSystem; //源专业 + float fValue; //目标值(AO) + int CtrlActType; //控制类型 选择、取消、执行, + int TagtState; + uint64 Param1; + uint64 Param2; + float fParam; + char strParam[CN_FesControlStrParamSize]; + _SFesRxAoCmd() + { + memset(TableName,0,sizeof(TableName)); + memset(ColumnName,0,sizeof(ColumnName)); + memset(TagName,0,sizeof(TagName)); + memset(RtuName,0,sizeof(RtuName)); + CtrlDir=0; + RtuNo = 0; + PointID = 0; + SubSystem = 0; + FwSubSystem = 0; + FwRtuNo = 0; + FwPointNo = 0; + fValue = 0; //目标值(AO) + CtrlActType = 0; //控制类型 选择、取消、执行, + TagtState = 0; + Param1 = 0; + Param2 = 0; + fParam = 0; + memset(strParam,0,sizeof(strParam)); + } +}SFesRxAoCmd; + +typedef struct _SFesTxAoCmd{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int CtrlDir; //控制方向 0:FES外部(HMI) 1:FES内部(转发规约) + int FwSubSystem; //转发专业 + int FwRtuNo; //转发RTU号 + int FwPointNo; //转发点号 + int RtuNo; //源RTU号 + int PointID; //源点号 + int SubSystem; //源专业 + int retStatus; //返回状态 + uint64 Param1; + uint64 Param2; + float fParam; + char strParam[CN_FesControlStrParamSize]; + int CtrlActType; //控制类型 选择、取消、执行, + _SFesTxAoCmd() + { + memset(TableName,0,sizeof(TableName)); + memset(ColumnName,0,sizeof(ColumnName)); + memset(TagName,0,sizeof(TagName)); + memset(RtuName,0,sizeof(RtuName)); + CtrlDir=0; + RtuNo = 0; + PointID = 0; + SubSystem = 0; + FwSubSystem = 0; + FwRtuNo = 0; + FwPointNo = 0; + retStatus = 0; + CtrlActType = 0; //控制类型 选择、取消、执行, + Param1 = 0; + Param2 = 0; + fParam = 0; + memset(strParam,0,sizeof(strParam)); + } +}SFesTxAoCmd; + +typedef struct _SFesRxMoCmd{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int CtrlDir; //控制方向 0:FES外部(HMI) 1:FES内部(转发规约) + int FwSubSystem; //转发专业 + int FwRtuNo; //转发RTU号 + int FwPointNo; //转发点号 + int RtuNo; //源RTU号 + int PointID; //源点号 + int SubSystem; //源专业 + int iValue; //目标值(DO、MO) + int CtrlActType; //控制类型 选择、取消、执行, + int TagtState; + uint64 Param1; + uint64 Param2; + float fParam; + char strParam[CN_FesControlStrParamSize]; + _SFesRxMoCmd() + { + memset(TableName,0,sizeof(TableName)); + memset(ColumnName,0,sizeof(ColumnName)); + memset(TagName,0,sizeof(TagName)); + memset(RtuName,0,sizeof(RtuName)); + CtrlDir=0; + RtuNo = 0; + PointID = 0; + SubSystem = 0; + FwSubSystem = 0; + FwRtuNo = 0; + FwPointNo = 0; + iValue = 0; //目标值(DO、MO) + CtrlActType = 0; //控制类型 选择、取消、执行, + TagtState = 0; + Param1 = 0; + Param2 = 0; + fParam = 0; + memset(strParam,0,sizeof(strParam)); + } +}SFesRxMoCmd; + +typedef struct _SFesTxMoCmd{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int CtrlDir; //控制方向 0:FES外部(HMI) 1:FES内部(转发规约) + int FwSubSystem; //转发专业 + int FwRtuNo; //转发RTU号 + int FwPointNo; //转发点号 + int RtuNo; //源RTU号 + int PointID; //源点号 + int SubSystem; //源专业 + int retStatus; //返回状态 + uint64 Param1; + uint64 Param2; + float fParam; + char strParam[CN_FesControlStrParamSize]; + int CtrlActType; //控制类型 选择、取消、执行, + _SFesTxMoCmd() + { + memset(TableName,0,sizeof(TableName)); + memset(ColumnName,0,sizeof(ColumnName)); + memset(TagName,0,sizeof(TagName)); + memset(RtuName,0,sizeof(RtuName)); + CtrlDir=0; + RtuNo = 0; + PointID = 0; + SubSystem = 0; + FwSubSystem = 0; + FwRtuNo = 0; + FwPointNo = 0; + retStatus = 0; + CtrlActType = 0; //控制类型 选择、取消、执行, + Param1 = 0; + Param2 = 0; + fParam = 0; + memset(strParam,0,sizeof(strParam)); + } +}SFesTxMoCmd; + +typedef struct{ + char TagName[CN_FesMaxTagSize];//Point tag + int Index; //Point index + int iValue; //Point Value +}SFesRxSetting; + +typedef struct{ + int RtuNo; + int DevId; //PCS3000 下的DevId + int CtrlActType; //控制类型 读取,下装、确定 + int Num; //定值个数,下装定值和确定修改定值(Num=0), 读取保护定值(Num!=0),不超过100点 + SFesRxSetting Setting[CN_FesMaxDzNum];//定值 +}SFesRxSettingCmd; + +typedef struct{ + int RtuNo; + int DevId; //PCS3000 下的DevId + int CtrlActType; //控制类型 读取,下装、确定 + int retStatus; //返回状态 + int Num; //定值个数,下装定值和确定修改定值(Num=0), 读取保护定值(Num!=0),不超过100点 + SFesRxSetting Setting[CN_FesMaxDzNum];//定值 + char strParam[CN_FesControlStrParamSize]; +}SFesTxSettingCmd; + +/* +typedef struct{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int DevId; //PCS3000 下的DevId + int ParamLen; + byte Param[CN_FesMaxDefCmdSize]; //自定义命令 +}SFesRxDefCmd; + +typedef struct{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int DevId; //PCS3000 下的DevId + int retStatus; //返回状态 + int ParamLen; + byte Param[CN_FesMaxDefCmdSize]; //自定义命令 + char strParam[CN_FesControlStrParamSize]; +}SFesTxDefCmd; +*/ + +typedef struct{ + std::string name; + std::string value; +}FesDefCmd; + + +typedef struct _SFesRxDefCmd { + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int DevId; //PCS3000 下的DevId + int CmdNum; + int CtrlDir; //控制方向 0:FES外部(HMI) 1:FES内部(转发规约) + int SrcRtuNo; //转发规约源RTU号 + std::vector VecCmd; + _SFesRxDefCmd() + { + memset(TableName, 0, sizeof(TableName)); + memset(ColumnName, 0, sizeof(ColumnName)); + memset(TagName, 0, sizeof(TagName)); + memset(RtuName, 0, sizeof(RtuName)); + DevId = 0; + CmdNum = 0; + CtrlDir = 0; + SrcRtuNo = 0; + //VecCmd.clear(); + } +}SFesRxDefCmd; + +typedef struct _SFesTxDefCmd{ + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char RtuName[CN_FesMaxNameSize]; + int DevId; //PCS3000 下的DevId + int retStatus; //返回状态 + int CmdNum; + std::vector VecCmd; + char strParam[CN_FesControlStrParamSize]; + int CtrlDir; //控制方向 0:FES外部(HMI) 1:FES内部(转发规约) + int SrcRtuNo; //转发规约源RTU号 + _SFesTxDefCmd() + { + memset(TableName,0,sizeof(TableName)); + memset(ColumnName,0,sizeof(ColumnName)); + memset(TagName,0,sizeof(TagName)); + memset(RtuName,0,sizeof(RtuName)); + DevId = 0; + retStatus = 0; + CmdNum = 0; + SrcRtuNo = 0; + memset(strParam,0,sizeof(strParam)); + } +}SFesTxDefCmd; + +typedef struct{ + int RtuNo; + int DevId; + int fileSize; + char fileName[CN_FesMaxWaveFileNameSize]; +}SFesWaveForm; + +typedef struct +{ + int ProtocolId; + char Name[CN_FesMaxNameSize]; +}SFesProtocolName; + +typedef struct{ + char NetDesc[CN_FesMaxNetDescSize]; //通道IP + int PortNo;//通道网络端口 +}SFesNetRoute; + +typedef struct{ + int ChanNo; //通道号 + char TagName[CN_FesMaxTagSize]; //RTU + char ChanName[CN_FesMaxNameSize];//通道名 + char ChanDesc[CN_FesMaxDescSize];//通道描述 + int nLocationId; //车站 + int nSubSystem; //专业 + int nRegionId; //责任区ID + int Used; //通道使用标志 + float ErrRateLimit; //帧错误标准 + SFesNetRoute NetRoute[CN_FesMaxNetRouteNum]; + int CommProperty; //通道性质 0:接收通道 1:转发通道 + int CommType; //通信方式 + int ChanMode; //通道方式0:双通道通信方式 1:单通道方式 + int ProtocolId; //规约类型 + int ConnectWaitSec; + int RespTimeout; //响应超时 + int RetryTimes; //最大重连次数 + int RecvTimeout; //接收超时,单位ms + int ConnectTimeout; //链接超时 + int MaxRxSize; //接收缓存区长度 + int MaxTxSize; //发送缓存区长度 + int BackupChanNo[CN_FesMaxChangeChanNum-1];//实际配置的备用通道号 + //char ComPortName[CN_FesMaxNameSize];//串口端口名 + int BaudRate; //波特率设置 + int Parity; //校验位 + int DataBit; //数据位 + int StopBit; //停止位 + int ResParam1; + int ResParam2; + int SetTimeEnable; //通道对时使能 + int LocalPortNo; //本地端口号 + int AlarmEnable; //2019-09-18 thxiao 增加报警使能 +}SFesChanParam; + +//本结构是通道管理的内部结构,备用通道收发的统计数据(RxNum、TxNum、ErrCnt)在自己通道结构中, +//其他数据都在主通道结构中 +typedef struct{ + uint32 Writex;//写指针 + uint32 Readx; //读指针 + byte *pData; //数据内容 +}SFesChanRxBuf; + +typedef struct{ + uint32 Writex;//写指针 + uint32 Readx; //读指针 + byte *pData; //数据内容 +}SFesChanTxBuf; + +typedef struct{ + int RtuNo; //RTU号 + char TagName[CN_FesMaxTagSize]; //RTU + char RtuName[CN_FesMaxNameSize]; //RTU + char RtuDesc[CN_FesMaxDescSize];//rtu描述 + int nLocationId;//车站 + char LocationDesc[CN_FesMaxDescSize];//2019-06-05 thxiao 车站描述 + int nSubSystem; //专业 + int Used; //使用标志 + int RtuAddr; //RTU地址 + int ChanNo; //通道号 + int RecvFailLimit; //连续接收数据失败计数(>5代表停运) + int ProtocolId; //规约类型 2018-12-25 add by thxiao + int AlarmEnable; //报警使能 2019-09-18 add by thxiao + int ResParam1; + int ResParam2; + int ResParam3; + int ControlDisable; //遥控禁止 1:禁止 0:允许 + int ClearDataEnable; //设备离线数据清零 1:清零 0:保持数据 + char DevType[CN_FesMaxTagSize]; //2020-03-09 thxiao 设备类型 + int iDevType; //2020-03-11 thxiao 整数设备类型,一般为采集串口RTU使用,避免判断字符串,优化查找时间 + int WaveEnable; //录波使能 1:是 0:否 + SModbusCmdBuf ModbusCmdBuf; +}SFesRtuParam; + +//FesSimServer +typedef struct +{ + int RefreshFlag; //数据刷新标志为1:事件写入缓冲区 0:不写入缓存区 + int Overflow; //事件溢出标志 1:溢出 0:正常 + int Readx; + int Writex; + SFesSoeEvent Event[CN_FesSimSoeEventMaxBufSize]; +}SFesSimServerSoeEventBuf; + +typedef struct +{ + int RefreshFlag; //数据刷新标志为1:事件写入缓冲区 0:不写入缓存区 + int Overflow; //事件溢出标志 1:溢出 0:正常 + int Readx; + int Writex; + SFesRtuEvent Event[CN_FesSimRtuEventMaxBufSize]; +}SFesSimServerRtuEventBuf; + +typedef struct +{ + int RefreshFlag; //数据刷新标志为1:事件写入缓冲区 0:不写入缓存区 + int Overflow; //事件溢出标志 1:溢出 0:正常 + int Readx; + int Writex; + SFesChanEvent Event[CN_FesSimChanEventMaxBufSize]; +}SFesSimServerChanEventBuf; + +typedef struct{ + int RxNum; // + int TxNum; // + int ErrNum; +}SFesChanStatistics; + +typedef struct{ + char FrameType; //0:data 1:string + char DataType; + short FrameLen; + uint64 Time; //1970-01-01 00:00 至今的毫秒数 + byte Data[CN_SFesSimComFrameMaxLen]; +}SFesChanFrame; + +typedef struct +{ + int RefreshFlag; //数据刷新标志为1:事件写入缓冲区 0:不写入缓存区 + int ChanNo; + int Overflow; //事件溢出标志 1:溢出 0:正常 + int RxNum; // + int TxNum; // + int ErrNum; + int Readx; + int Writex; + SFesChanFrame Frame[CN_FesSimChanMonMaxBufSize]; +}SFesSimServerChanMonBuf; + +//网络通信事件队列结构,通信层和应用层互相交互 +const int CN_FesNetEvent_Waitting_Connect = 1; +const int CN_FesNetEvent_Connect = 2; +const int CN_FesNetEvent_Disconnect = 3; + +typedef struct +{ + uint64 Time; + int EventType; +}SFesNetEvent; + +//应用层事件请求,应用层和通信层互相交互 +const int CN_FesAppNetEvent_CloseSock = 1; +const int CN_FesAppNetEvent_ReopenChan = 2; + +typedef struct +{ + uint64 Time; + int EventType; +}SFesAppNetEvent; + + +//设备信息表 +typedef struct{ + int CfgSize; + int DataSize; + int Year; + int Mon; + int Day; + int Hour; + int Min; + //int Sec; + int mSec; //sec*1000+msec; +}SFesRtuWareform; + +typedef struct{ + int DevId; + char DevDesc[CN_FesMaxNameSize]; + int ChildDevId; + SFesRtuWareform Record; + char LuboPath[CN_FesMaxDescSize];//2019-06-10 thxiao 增加录波路径,方便保存录波按“车站\设备”保存 +}SFesRtuDevParam; + +typedef struct{ + int RtuNo; + int DevNum; + SFesRtuDevParam *pDev; + //int WfDataLen; //录波数据长度 + //byte *pWfData; //录波数据缓存区 + //int RecvDataIndex; //录波数据保存当前数据长度 +}SFesRtuDevInfo; +//增加一个数据初始化筛选转发表的采集RTU号 +typedef struct { + int CollectRtuNum; + int CollectRtuCount; + int CollectRtuNo[CN_FesFwMaxCollectRtuNum]; +}SFesCollectRtu; + +//转发规约的接口结构 +typedef struct { + int RemoteNo; //远动号 + int RtuNo; //RTU号 + int PointNo; + uint32 Status; + float Value; + uint64 time; +}SFesFwChgAi; + +typedef struct { + int RemoteNo; //远动号 + int RtuNo; //RTU号 + int PointNo; + uint32 Status; + int Value; + uint64 time; +}SFesFwChgDi; + +typedef struct{ + int RemoteNo; //远动号 + int RtuNo; //RTU号 + int PointNo; + uint32 Status; //遥测信状态 + int Value; //点值 + uint64 time; //1970-01-01 00:00 至今的毫秒数 + int FaultNum; //故障值个数 + int FaultValTag [CN_FesMaxFaultNum];//表明以下数值的来源 + float FaultVal[CN_FesMaxFaultNum]; +}SFesFwSoeEvent; + + +typedef struct { + int RemoteNo; //远动号 + int RtuNo; //RTU号 + int PointNo; + uint32 Status; + int64 Value; + uint64 time; +}SFesFwChgAcc; + +typedef struct { + int RemoteNo; //远动号 + int RtuNo; //RTU号 + int PointNo; + uint32 Status; + int Value; + uint64 time; +}SFesFwChgMi; + +typedef struct { + int SrcSubSystem; //所属专业 + int SrcRtuNo; //RTU号 + int SrcPointNo; + uint32 Status; +}SFesFwChgDo; + +typedef struct _SFesFwDoRespCmd{ + int FwRtuNo; //RTU号 + int FwPointNo; //遥控点号 + int retStatus; //返回状态 + int CtrlActType; //控制类型 选择、取消、执行, + uint64 Param1; + uint64 Param2; + float fParam; + _SFesFwDoRespCmd() + { + FwRtuNo=0; + FwPointNo = 0; //遥控点号 + retStatus = 0; //返回状态 + CtrlActType = 0; //控制类型 选择、取消、执行, + Param1 = 0; + Param2 = 0; + fParam = 0; + } +}SFesFwDoRespCmd; + +typedef struct _SFesFwAoRespCmd{ + int FwRtuNo; //RTU号 + int FwPointNo; //遥控点号 + int retStatus; //返回状态 + uint64 Param1; + uint64 Param2; + float fParam; + int CtrlActType; //控制类型 选择、取消、执行, + _SFesFwAoRespCmd() + { + FwRtuNo =0; + FwPointNo =0; + retStatus = 0; + CtrlActType = 0; //控制类型 选择、取消、执行, + Param1 = 0; + Param2 = 0; + fParam = 0; + } +}SFesFwAoRespCmd; + +typedef struct _SFesFwMoRespCmd { + int FwRtuNo; //RTU号 + int FwPointNo; //遥控点号 + int retStatus; //返回状态 + uint64 Param1; + uint64 Param2; + float fParam; + int CtrlActType; //控制类型 选择、取消、执行, + _SFesFwMoRespCmd() + { + FwRtuNo =0; + FwPointNo = 0; //遥控点号 + retStatus = 0; + CtrlActType = 0; //控制类型 选择、取消、执行, + Param1 = 0; + Param2 = 0; + fParam = 0; + } +}SFesFwMoRespCmd; + +//201-03-011 thxiao 增加规约映射表,数据按规约点的顺序排列.方便工程在完成的情况下,现场工程又修改了点顺序。 +typedef struct { + int Used; + int PIndex; //use param1. + int PointNo; + int Param2; //规约参数,每种协议含义不相同。 如modbus FunNo + int Param3; //规约参数,每种协议含义不相同。 如modbus DataAddress + int Param4; //规约参数,每种协议含义不相同。 如modbus InfoNo +}SFesAiIndex; + +typedef struct { + int Used; + int PIndex; //use param1. + int PointNo; + int Param2; //规约参数,每种协议含义不相同。 如modbus FunNo + int Param3; //规约参数,每种协议含义不相同。 如modbus DataAddress + int Param4; //规约参数,每种协议含义不相同。 如modbus InfoNo +}SFesDiIndex; + +typedef struct { + int Used; + int PIndex; //use param1. + int PointNo; + int Param2; //规约参数,每种协议含义不相同。 如modbus FunNo + int Param3; //规约参数,每种协议含义不相同。 如modbus DataAddress + int Param4; //规约参数,每种协议含义不相同。 如modbus InfoNo +}SFesAccIndex; + +typedef struct { + int Used; + int PIndex; //use param1. + int PointNo; + int Param2; //规约参数,每种协议含义不相同。 如modbus FunNo + int Param3; //规约参数,每种协议含义不相同。 如modbus DataAddress + int Param4; //规约参数,每种协议含义不相同。 如modbus InfoNo +}SFesMiIndex; + +typedef struct { + int Used; + int PIndex; //use param1. + int PointNo; + int Param2; //规约参数,每种协议含义不相同。 如modbus FunNo + int Param3; //规约参数,每种协议含义不相同。 如modbus DataAddress + int Param4; //规约参数,每种协议含义不相同。 如modbus InfoNo +}SFesDoIndex; + +typedef struct { + int Used; + int PIndex; //use param1. + int PointNo; + int Param2; //规约参数,每种协议含义相同。 如modbus FunNo + int Param3; //规约参数,每种协议含义相同。 如modbus DataAddress + int Param4; //规约参数,每种协议含义相同。 如modbus InfoNo +}SFesAoIndex; + +typedef struct { + int Used; + int PIndex; //use param1. + int PointNo; + int Param2; //规约参数,每种协议含义不相同。 如modbus FunNo + int Param3; //规约参数,每种协议含义不相同。 如modbus DataAddress + int Param4; //规约参数,每种协议含义不相同。 如modbus InfoNo +}SFesMoIndex; + +typedef struct { + int Used; + int PIndex; //use param1. + int PointNo; + int Param2; //规约参数,每种协议含义不相同。 如modbus FunNo + int Param3; //规约参数,每种协议含义不相同。 如modbus DataAddress + int Param4; //规约参数,每种协议含义不相同。 如modbus InfoNo +}SFesDzIndex; + +//车站 +typedef struct { + int nLocationId;//车站 + char LocationDesc[CN_FesMaxDescSize];//2019-06-05 thxiao 车站描述 +}SFesLocation; + +/******************************************************************************** +/* 转发公共数据 +*********************************************************************************/ +typedef struct _SFesFwPubAi { + int SrcLocationID; //点所属厂站 + int SrcSubSystem; //点所属专业 + char DPTagName[CN_FesMaxTagSize]; //后台标签名 + int FesRtuNo; //采集rtu号 + int SrcPointNo; //采集点号 + float Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + int FwMapNum; //转发映射个数 + SFesFwMapping FwMapping[CN_Fes_Fw_MaxMapping];//对应的转发点号,快速找到转发点 + _SFesFwPubAi() + { + SrcLocationID = 0; + SrcSubSystem = 0; + memset(DPTagName, 0, CN_FesMaxTagSize); + FesRtuNo = 0; + SrcPointNo = 0; + Value = 0; + Status = 0; + time = 0; + FwMapNum = 0; + memset(&FwMapping[0], 0, sizeof(SFesFwMapping)*CN_Fes_Fw_MaxMapping); + } +}SFesFwPubAi; + +typedef struct _SFesFwPubDi { + int SrcLocationID; //点所属厂站 + int SrcSubSystem; //点所属专业 + char DPTagName[CN_FesMaxTagSize]; //后台标签名 + int FesRtuNo; //采集rtu号 + int SrcPointNo; //采集点号/DP点号 + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + short PointType; //0:单点 1:双点 + short FwMapNum; //转发映射个数 + SFesFwMapping FwMapping[CN_Fes_Fw_MaxMapping];//对应的转发点号,快速找到转发点 + _SFesFwPubDi() + { + SrcLocationID = 0; + SrcSubSystem = 0; + memset(DPTagName, 0, CN_FesMaxTagSize); + FesRtuNo = 0; + SrcPointNo = 0; + Value = 0; + Status = 0; + time = 0; + FwMapNum = 0; + memset(&FwMapping[0], 0, sizeof(SFesFwMapping)*CN_Fes_Fw_MaxMapping); + } +}SFesFwPubDi; + +typedef struct _SFesFwPubAcc { + int SrcLocationID; //点所属厂站 + int SrcSubSystem; //点所属专业 + char DPTagName[CN_FesMaxTagSize]; //后台标签名 + int FesRtuNo; //采集rtu号 + int SrcPointNo; //采集点号 + uint64 Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + int FwMapNum; //转发映射个数 + SFesFwMapping FwMapping[CN_Fes_Fw_MaxMapping];//对应的转发点号,快速找到转发点 + _SFesFwPubAcc() + { + SrcLocationID = 0; + SrcSubSystem = 0; + memset(DPTagName, 0, CN_FesMaxTagSize); + FesRtuNo = 0; + SrcPointNo = 0; + Value = 0; + Status = 0; + time = 0; + FwMapNum = 0; + memset(&FwMapping[0], 0, sizeof(SFesFwMapping)*CN_Fes_Fw_MaxMapping); + } +}SFesFwPubAcc; + +typedef struct _SFesFwPubMi { + int SrcLocationID; //点所属厂站 + int SrcSubSystem; //点所属专业 + char DPTagName[CN_FesMaxTagSize]; //后台标签名 + int FesRtuNo; //采集rtu号 + int SrcPointNo; //采集点号 + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 + int FwMapNum; //转发映射个数 + SFesFwMapping FwMapping[CN_Fes_Fw_MaxMapping];//对应的转发点号,快速找到转发点 + _SFesFwPubMi() + { + SrcLocationID = 0; + SrcSubSystem = 0; + memset(DPTagName, 0, CN_FesMaxTagSize); + FesRtuNo = 0; + SrcPointNo = 0; + Value = 0; + Status = 0; + time = 0; + FwMapNum = 0; + memset(&FwMapping[0], 0, sizeof(SFesFwMapping)*CN_Fes_Fw_MaxMapping); + } +}SFesFwPubMi; + +typedef struct _SFesFwPubDo { + int SrcLocationID; //点所属厂站 + int SrcSubSystem; //点所属专业 + int FesRtuNo; //采集rtu号 + int SrcPointNo; //采集点号/DP点号 + uint32 Status; + _SFesFwPubDo() + { + SrcLocationID = 0; + SrcSubSystem = 0; + FesRtuNo = 0; + SrcPointNo = 0; + Status = 0; + } +}SFesFwPubDo; + + +typedef struct _SFesFwDoBusCmd { + int FwSubSystem; //转发专业 + int FwRtuNo; //转发RTU号 + int FwPointNo; //转发点号 + int SubSystem; //源专业 + int RtuNo; //源RTU号 + int PointID; //源点号 + int retStatus; //返回状态 + int CtrlActType; //控制类型 选择、取消、执行, + int iValue; //目标值(DO、MO) + uint64 Param1; + uint64 Param2; + float fParam; + _SFesFwDoBusCmd() + { + FwSubSystem = 0; + FwRtuNo = 0; + FwPointNo = 0; + RtuNo = 0; + PointID = 0; + SubSystem = 0; + retStatus = 0; //返回状态 + CtrlActType = 0; //控制类型 选择、取消、执行, + iValue = 0; + Param1 = 0; + Param2 = 0; + fParam = 0; + } +}SFesFwDoBusCmd; + +typedef struct _SFesFwAoBusCmd { + int FwSubSystem; //转发专业 + int FwRtuNo; //转发RTU号 + int FwPointNo; //转发点号 + int SubSystem; //源专业 + int RtuNo; //源RTU号 + int PointID; //源点号 + int retStatus; //返回状态 + int CtrlActType; //控制类型 选择、取消、执行, + float fValue; //目标值(AO) + uint64 Param1; + uint64 Param2; + float fParam; + _SFesFwAoBusCmd() + { + FwSubSystem = 0; + FwRtuNo = 0; + FwPointNo = 0; + RtuNo = 0; + PointID = 0; + SubSystem = 0; + retStatus = 0; + CtrlActType = 0; //控制类型 选择、取消、执行, + fValue = 0; + Param1 = 0; + Param2 = 0; + fParam = 0; + } +}SFesFwAoBusCmd; + +typedef struct _SFesFwMoBusCmd { + int FwSubSystem; //转发专业 + int FwRtuNo; //转发RTU号 + int FwPointNo; //转发点号 + int SubSystem; //源专业 + int RtuNo; //源RTU号 + int PointID; //源点号 + int retStatus; //返回状态 + int CtrlActType; //控制类型 选择、取消、执行, + int iValue; //目标值(DO、MO) + uint64 Param1; + uint64 Param2; + float fParam; + _SFesFwMoBusCmd() + { + FwSubSystem = 0; + FwRtuNo = 0; + FwPointNo = 0; + RtuNo = 0; + PointID = 0; + SubSystem = 0; + retStatus = 0; + CtrlActType = 0; //控制类型 选择、取消、执行, + iValue = 0; + Param1 = 0; + Param2 = 0; + fParam = 0; + } +}SFesFwMoBusCmd; + +typedef struct { + float Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwAiValue; + +typedef struct { + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwDiValue; + +typedef struct { + int64 Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwAccValue; + +typedef struct { + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesFwMiValue; + diff --git a/product/src/tools/debug_tool_v2/FesRdbStruct.h b/product/src/tools/debug_tool_v2/FesRdbStruct.h new file mode 100644 index 00000000..c9cb039b --- /dev/null +++ b/product/src/tools/debug_tool_v2/FesRdbStruct.h @@ -0,0 +1,321 @@ +/* + @file fesrdbstruct.cpp + @brief fes 实时库数据结构 + + @author thxiao +*/ + +#pragma once + +const int CN_FesMaxTableNameSize =32; //TagName最大长度 +const int CN_FesMaxColumnNameSize =16; //TagName最大长度 +const int CN_FesMaxTagSize =64; //TagName最大长度 +const int CN_FesMaxDescSize =128; //TagName最大长度 +const int CN_FesMaxNameSize =64; //Name最大长度 +const int CN_FesMaxNetDescSize =32; //"127.0.0.1" +const int CN_FesMaxChangeChanNum =4; //RTU允许切换的最大通道数 +const int CN_FesMaxNetRouteNum =4; //每个通道最大路由数 + +#define RT_DICT_TEXT_TBL "dict_text_define" +#define RT_FES_RTU_TBL "fes_rtu_para" +#define RT_FES_CHAN_TBL "fes_channel_para" +#define RT_FES_PROTOCOL_TBL "fes_protocol" +#define RT_FES_AI_TBL "fes_analog" +#define RT_FES_AO_TBL "fes_analog_ctrl" +#define RT_FES_DI_TBL "fes_digital" +#define RT_FES_DO_TBL "fes_digital_ctrl" +#define RT_FES_ACC_TBL "fes_accuml" +#define RT_FES_MI_TBL "fes_mix" +#define RT_FES_MO_TBL "fes_mix_ctrl" +#define RT_FES_DATA_BLOCK_TBL "fes_data_block" +#define RT_FES_DEV_INFO_TBL "fes_dev_info" +//转发点表 +#define RT_FES_FW_AI_TBL "fes_forwarding_anaolg" +#define RT_FES_FW_AO_TBL "fes_forwarding_anaolg_ctrl" +#define RT_FES_FW_DI_TBL "fes_forwarding_digital" +#define RT_FES_FW_DO_TBL "fes_forwarding_digital_ctrl" +#define RT_FES_FW_ACC_TBL "fes_forwarding_accuml" + +typedef struct{ + int RtuNo; //RTU号 + char TagName[CN_FesMaxTagSize]; //RTU + char RtuName[CN_FesMaxNameSize]; //RTU + char RtuDesc[CN_FesMaxDescSize];//rtu描述 + int nLocationId;//位置 + int nSubSystem; //专业 + int Used; //使用标志 + int RtuAddr; //RTU地址 + int ChanNo; //通道号 + int RecvFailLimit; //连续接收数据失败计数(>5代表停运) +}SFesRdbRtuParam; + +typedef struct{ + int ChanNo; //通道号 + char TagName[CN_FesMaxTagSize]; //RTU + char ChanName[CN_FesMaxNameSize];//通道名 + char ChanDesc[CN_FesMaxDescSize];//通道描述 + int nLocationId; //位置 + int nSubSystem; //专业 + int nRegionId; //责任区ID + int Used; //通道使用标志 + double ErrRateLimit; //帧错误标准 + char NetDesc1[CN_FesMaxNetDescSize]; //通道IP + int PortNo1; //通道网络端口 + char NetDesc2[CN_FesMaxNetDescSize]; //通道IP + int PortNo2; //通道网络端口 + char NetDesc3[CN_FesMaxNetDescSize]; //通道IP + int PortNo3; //通道网络端口 + char NetDesc4[CN_FesMaxNetDescSize]; //通道IP + int PortNo4; //通道网络端口 + int CommProperty; //通道性质 0:接收通道 1:转发通道 + int CommType; //通信方式 + int ChanMode; //通道方式0:双通道通信方式 1:单通道方式 + int ProtocolId; //规约类型 + int ConnectWaitSec; //连接等待重连时间,单位秒 + int ConnectTimeout; //链接超时,单位秒 + int RetryTimes; //最大重连次数 + int RespTimeout; //响应超时,单位毫秒 + int RecvTimeout; //接收超时,单位秒,判断是否需要端开连接重新连接 + int MaxRxSize; //接收缓存区长度 + int MaxTxSize; //发送缓存区长度 + int BackupChanNo1;//实际配置的备用通道号 + int BackupChanNo2;//实际配置的备用通道号 + int BackupChanNo3;//实际配置的备用通道号 + int ResParam1; + int ResParam2; + int ResParam3; + int ResParam4; +}SFesRdbChanParam; + +typedef struct +{ + int ProtocolId; + char Name[CN_FesMaxNameSize]; +}SFesRdbProtocolParam; + +typedef struct { + int RtuNo; + int Index; //序号 + int FunCode; //功能码(即MODBUS中的命令码) + int StartAddr; //数据起始地址 + int DataLen; //数据长度 + int PollTime; //命令下发周期(相对时间,一个周期=50ms) + int FrameType; //帧类别 + int IsCreateSoe; //对遥信帧有效,0:不产生SOE,1:产生SOE + int Param1; //保留参数1 + int Param2; //保留参数2 +}SFesRdbDataBlock; + +typedef struct { + int RtuNo; + int PointNo; + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char PointTagName[CN_FesMaxTagSize]; + int IsFilter; //是否过滤AI突变 + int Percent; //突变百分比 + int DeadBandType;//死区类型 + double DeadBand; //死区值 + double ZeroBand; //归零死区 + double Base; //基值 + double Coeff; //系数; + double MaxRange; //度上限 + double MinRange; //度下限 + int Param1; //规约参数,每种协议含义相同。 如modbus FunNo + int Param2; //规约参数,每种协议含义相同。 如modbus DataAddress + int Param3; //规约参数,每种协议含义相同。 如modbus InfoNo + int Param4; //规约参数,每种协议含义相同。 +}SFesRdbAiParam; + +typedef struct { + int RtuNo; + int PointNo; + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char PointTagName[CN_FesMaxTagSize]; + int IsFilterErr; //是否过滤错误DI + int IsFilterDisturb;//是否过滤DI抖动 + int DisturbTime; //抖动时限 + int Revers; //取反 + int Param1; //规约参数,每种协议含义相同。 如modbus FunNo + int Param2; //规约参数,每种协议含义相同。 如modbus DataAddress + int Param3; //规约参数,每种协议含义相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 +}SFesRdbDiParam; + +typedef struct { + int RtuNo; + int PointNo; + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char PointTagName[CN_FesMaxTagSize]; + double Base; //基值 + double Coeff; //系数; + int Param1; //规约参数,每种协议各不相同。 如modbus FunNo + int Param2; //规约参数,每种协议各不相同。 如modbus DataAddress + int Param3; //规约参数,每种协议各不相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 如modbus ValueType +}SFesRdbAccParam; + + +typedef struct { + int RtuNo; + int PointNo; + char TableName[CN_FesMaxTableNameSize]; + char ColumnName[CN_FesMaxColumnNameSize]; + char TagName[CN_FesMaxTagSize]; + char PointTagName[CN_FesMaxTagSize]; + int Base; //基值 + int Coeff; //系数; + int MaxRange; //度上限 + int MinRange; //度下限 + int Param1; //规约参数,每种协议各不相同。 如modbus FunNo + int Param2; //规约参数,每种协议各不相同。 如modbus DataAddress + int Param3; //规约参数,每种协议各不相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 如modbus ValueType +}SFesRdbMiParam; + +typedef struct { + int RtuNo; + int PointNo; + char PointTagName[CN_FesMaxTagSize]; + int Revers; //取反 + int Param1; //规约参数,每种协议含义相同。 如modbus FunNo + int Param2; //规约参数,每种协议含义相同。 如modbus DataAddress + int Param3; //规约参数,每种协议含义相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 +}SFesRdbDoParam; + +typedef struct { + int RtuNo; + int PointNo; + char PointTagName[CN_FesMaxTagSize]; + double Base; //基值 + double Coeff; //系数; + double MaxRange; //度上限 + double MinRange; //度下限 + int Param1; //规约参数,每种协议含义相同。 如modbus FunNo + int Param2; //规约参数,每种协议含义相同。 如modbus DataAddress + int Param3; //规约参数,每种协议含义相同。 如modbus InfoNo + int Param4; //规约参数,每种协议含义相同。 +}SFesRdbAoParam; + +typedef struct { + int RtuNo; + int PointNo; + char PointTagName[CN_FesMaxTagSize]; + int Base; //基值 + int Coeff; //系数; + int MaxRange; //度上限 + int MinRange; //度下限 + int Param1; //规约参数,每种协议各不相同。 如modbus FunNo + int Param2; //规约参数,每种协议各不相同。 如modbus DataAddress + int Param3; //规约参数,每种协议各不相同。 如modbus InfoNo + int Param4; //规约参数,每种协议各不相同。 如modbus ValueType +}SFesRdbMoParam; + +typedef struct { + int RtuNo; + int DevID; //FEP 的设备ID号 + char DevDesc[CN_FesMaxNameSize]; //设备描述 +}SFesRdbDevInfo; +//转发表Rdb结构参数 +typedef struct { + char FwRtuTagName[CN_FesMaxNameSize]; //所属转发rtu + int PointId; //点ID 从0开始递增 + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + char PointShortName[CN_FesMaxNameSize]; //点名缩写 + char FesRtuTagName[CN_FesMaxNameSize]; //采集rtu标签 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + int GroupNo; //组号 + double Coeff; //系数; + double Base; //修正值 + double DeadBand; //死区值 + double ZeroDeadBand; //归零死区值 + int Property; //属性 + long paralong1; //备用参数1 + long paralong2; //备用参数2 + char parastring[CN_FesMaxNameSize]; //备用字符串 +}SFesRdbFwAiParam; + +typedef struct { + char FwRtuTagName[CN_FesMaxNameSize]; //所属转发rtu + int PointId; //点ID 从0开始递增 + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + char PointShortName[CN_FesMaxNameSize]; //点名缩写 + char FesRtuTagName[CN_FesMaxNameSize]; //采集rtu标签 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + int GroupNo; //组号 + int Revert; //取反; + int Property; //属性 + long paralong1; //备用参数1 + long paralong2; //备用参数2 + char parastring[CN_FesMaxNameSize]; //备用字符串 +}SFesRdbFwDiParam; + +typedef struct { + char FwRtuTagName[CN_FesMaxNameSize]; //所属转发rtu + int PointId; //点ID 从0开始递增 + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + char PointShortName[CN_FesMaxNameSize]; //点名缩写 + char FesRtuTagName[CN_FesMaxNameSize]; //采集rtu标签 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + int GroupNo; //组号 + double Coeff; //系数; + double Base; //修正值 + int Property; //属性 + long paralong1; //备用参数1 + long paralong2; //备用参数2 + char parastring[CN_FesMaxNameSize]; //备用字符串 +}SFesRdbFwAccParam; + +typedef struct { + char FwRtuTagName[CN_FesMaxNameSize]; //所属转发rtu + int PointId; //点ID 从0开始递增 + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + char PointShortName[CN_FesMaxNameSize]; //点名缩写 + char FesRtuTagName[CN_FesMaxNameSize]; //采集rtu标签 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + int GroupNo; //组号 + int Property; //属性 + long paralong1; //备用参数1 + long paralong2; //备用参数2 + char parastring[CN_FesMaxNameSize]; //备用字符串 +}SFesRdbFwAoParam; + +typedef struct { + char FwRtuTagName[CN_FesMaxNameSize]; //所属转发rtu + int PointId; //点ID 从0开始递增 + int RemoteNo; //远动序号 + char TagName[CN_FesMaxTagSize]; //采集标签名 + char PointDesc[CN_FesMaxDescSize]; //点描述 + char PointShortName[CN_FesMaxNameSize]; //点名缩写 + char FesRtuTagName[CN_FesMaxNameSize]; //采集rtu标签 + int FesRtuNo; //采集rtu号 + int FesPointNo; //采集点号 + int GroupNo; //组号 + int Property; //属性 + long paralong1; //备用参数1 + long paralong2; //备用参数2 + char parastring[CN_FesMaxNameSize]; //备用字符串 +}SFesRdbFwDoParam; + +typedef struct { + int nFaultCode; + char FaultName[CN_FesMaxNameSize]; //Fault Name +}SFesRdbFaultCode; diff --git a/product/src/tools/debug_tool_v2/FesSimProtocol.h b/product/src/tools/debug_tool_v2/FesSimProtocol.h new file mode 100644 index 00000000..afe93196 --- /dev/null +++ b/product/src/tools/debug_tool_v2/FesSimProtocol.h @@ -0,0 +1,824 @@ +/* + @file FesSimProtocol.h + @brief Fes 仿真程序规约内容的结构定义 + @ + @author thxiao +*/ +#pragma once +#include "FesDef.h" + +const int CN_FesSimServerBasePortNo = 18100; //base+ +const int CN_FesServerMaxConnects =4; + +const int CN_SFesSimMaxFrameSize = 2048; //帧最大长度 + +//命令码定义 +const int CN_SFesSimConnectReq = 0x00; +const int CN_SFesSimHeartBeatReq = 0x01; +const int CN_SFesSimChanParamReq = 0x02; +const int CN_SFesSimChanDataReq = 0x03; +const int CN_SFesSimRTUParamReq = 0x04; +const int CN_SFesSimRTUDataReq = 0x05; +const int CN_SFesSimAiParamReq = 0x06; +const int CN_SFesSimAiDataReq = 0x07; +const int CN_SFesSimDiParamReq = 0x08; +const int CN_SFesSimDiDataReq = 0x09; +const int CN_SFesSimAccParamReq = 0x0A; +const int CN_SFesSimAccDataReq = 0x0B; +const int CN_SFesSimEventReq = 0x0C; +const int CN_SFesSimChanMonStartReq = 0x0D; +const int CN_SFesSimChanMonStopReq = 0x0E; +const int CN_SFesSimChanClearReq = 0x0F; +const int CN_SFesSimAiStartReq = 0x10; +const int CN_SFesSimAiStopReq = 0x11; +const int CN_SFesSimDiStartReq = 0x12; +const int CN_SFesSimDiStopReq = 0x13; +const int CN_SFesSimAccStartReq = 0x14; +const int CN_SFesSimAccStopReq = 0x15; +const int CN_SFesSimEventCreateReq = 0x16; +const int CN_SFesSimDoCmdReq = 0x17; +const int CN_SFesSimAoCmdReq = 0x18; +const int CN_SFesSimMoCmdReq = 0x19; +const int CN_SFesSimDefCmdReq = 0x1A; +const int CN_SFesSimRTUInfoReq = 0x1B; +const int CN_SFesSimAoParamReq = 0x1C; +const int CN_SFesSimDoParamReq = 0x1D; +const int CN_SFesSimMoParamReq = 0x1E; +const int CN_SFesSimMiParamReq = 0x1F; +const int CN_SFesSimMiDataReq = 0x20; +const int CN_SFesSimMiStartReq = 0x21; +const int CN_SFesSimMiStopReq = 0x22; +const int CN_SFesSimSettingCmdReq = 0x23; +const int CN_SFesSimSOEMemoryReq = 0x24; + +//转发数据监视 +const int CN_SFesSimFwRTUInfoReq = 0x25; +const int CN_SFesSimFwAiParamReq = 0x26; +const int CN_SFesSimFwDiParamReq = 0x27; +const int CN_SFesSimFwDDiParamReq = 0x28; +const int CN_SFesSimFwAccParamReq = 0x29; +const int CN_SFesSimFwMiParamReq = 0x2A; +const int CN_SFesSimFwAiDataReq = 0x2B; +const int CN_SFesSimFwDiDataReq = 0x2C; +const int CN_SFesSimFwDDiDataReq = 0x2D; +const int CN_SFesSimFwAccDataReq = 0x2E; +const int CN_SFesSimFwMiDataReq = 0x2F; + + +const int CN_SFesSimResp = 0x80; +const int CN_SFesSimConnectResp = 0x00|CN_SFesSimResp; +const int CN_SFesSimHeartBeatResp = 0x01|CN_SFesSimResp; +const int CN_SFesSimChanParamResp = 0x02|CN_SFesSimResp; +const int CN_SFesSimChanDataResp = 0x03|CN_SFesSimResp; +const int CN_SFesSimRTUParamResp = 0x04|CN_SFesSimResp; +const int CN_SFesSimRTUDataResp = 0x05|CN_SFesSimResp; +const int CN_SFesSimAiParamResp = 0x06|CN_SFesSimResp; +const int CN_SFesSimAiDataResp = 0x07|CN_SFesSimResp; +const int CN_SFesSimDiParamResp = 0x08|CN_SFesSimResp; +const int CN_SFesSimDiDataResp = 0x09|CN_SFesSimResp; +const int CN_SFesSimAccParamResp = 0x0A|CN_SFesSimResp; +const int CN_SFesSimAccDataResp = 0x0B|CN_SFesSimResp; +const int CN_SFesSimEventResp = 0x0C|CN_SFesSimResp; +const int CN_SFesSimChanMonStartResp = 0x0D|CN_SFesSimResp; +const int CN_SFesSimChanMonStopResp = 0x0E|CN_SFesSimResp; +const int CN_SFesSimChanClearResp = 0x0F|CN_SFesSimResp; +const int CN_SFesSimAiStartResp = 0x10|CN_SFesSimResp; +const int CN_SFesSimAiStopResp = 0x11|CN_SFesSimResp; +const int CN_SFesSimDiStartResp = 0x12|CN_SFesSimResp; +const int CN_SFesSimDiStopResp = 0x13|CN_SFesSimResp; +const int CN_SFesSimAccStartResp = 0x14|CN_SFesSimResp; +const int CN_SFesSimAccStopResp = 0x15|CN_SFesSimResp; +const int CN_SFesSimEventCreateResp = 0x16|CN_SFesSimResp; +const int CN_SFesSimDoCmdResp = 0x17|CN_SFesSimResp; +const int CN_SFesSimAoCmdResp = 0x18|CN_SFesSimResp; +const int CN_SFesSimMoCmdResp = 0x19|CN_SFesSimResp; +const int CN_SFesSimDefCmdResp = 0x1A|CN_SFesSimResp; +const int CN_SFesSimRTUInfoResp = 0x1B|CN_SFesSimResp; +const int CN_SFesSimAoParamResp = 0x1C|CN_SFesSimResp; +const int CN_SFesSimDoParamResp = 0x1D|CN_SFesSimResp; +const int CN_SFesSimMoParamResp = 0x1E|CN_SFesSimResp; +const int CN_SFesSimMiParamResp = 0x1F|CN_SFesSimResp; +const int CN_SFesSimMiDataResp = 0x20|CN_SFesSimResp; +const int CN_SFesSimMiStartResp = 0x21|CN_SFesSimResp; +const int CN_SFesSimMiStopResp = 0x22|CN_SFesSimResp; +const int CN_SFesSimSettingCmdResp = 0x23 | CN_SFesSimResp; +const int CN_SFesSimSOEMemoryResp = 0x24 | CN_SFesSimResp; + +//转发数据监视 +const int CN_SFesSimFwRTUInfoResp = 0x25 | CN_SFesSimResp; +const int CN_SFesSimFwAiParamResp = 0x26 | CN_SFesSimResp; +const int CN_SFesSimFwDiParamResp = 0x27 | CN_SFesSimResp; +const int CN_SFesSimFwDDiParamResp = 0x28 | CN_SFesSimResp; +const int CN_SFesSimFwAccParamResp = 0x29 | CN_SFesSimResp; +const int CN_SFesSimFwMiParamResp = 0x2A | CN_SFesSimResp; +const int CN_SFesSimFwAiDataResp = 0x2B | CN_SFesSimResp; +const int CN_SFesSimFwDiDataResp = 0x2C | CN_SFesSimResp; +const int CN_SFesSimFwDDiDataResp = 0x2D | CN_SFesSimResp; +const int CN_SFesSimFwAccDataResp = 0x2E | CN_SFesSimResp; +const int CN_SFesSimFwMiDataResp = 0x2F | CN_SFesSimResp; + +//应用类型 +const int CN_SFesSimPscadaApp =0; +const int CN_SFesSimBasApp =1; +const int CN_SFesSimOtherApp =2; + +//响应状态:响应命令使用。 0:正常响应 非0:异常响应 +const int CN_SFesSimNormalResp =0; +const int CN_SFesSimUnNormalResp =1; + +//帧序号:bit15 1: 最后一帧 0:非最后一帧 Bit14~0 帧序号,从0开始 +//如有11帧数据,序号如下:0x0000 0x0001 0x0002 ......0x800a +const int CN_SFesSimFrameLastSeqNo =0x8000; + + +//通道参数请求================================== +typedef struct{ +}SFesSimChanParamReq; + +//通道参数响应 +typedef struct{ + int ChanNo; //通道号 + char TagName[CN_FesMaxTagSize]; //RTU + char ChanName[CN_FesMaxNameSize];//通道名 + char used; + int Status; //增加通道状态,不再单独显示 + char CommType; //通信方式 + char ChanMode; //通道方式0:双通道通信方式 1:单通道方式 + char ProtocolId; //规约类型 + SFesNetRoute NetRoute[CN_FesMaxNetRouteNum]; + int ConnectWaitSec; //连接等待时间 + int ConnectTimeout; //链接超时 + int RetryTimes; //最大重连次数 + int RecvTimeout; //接收超时 + int RespTimeout; //响应超时 + int MaxRxSize; //接收缓存区长度 + int MaxTxSize; //发送缓存区长度 + float ErrRateLimit; //帧错误标准 + int BackupChanNo[CN_FesMaxChangeChanNum-1];//实际配置的备用通道号 +}SFesSimChanParam; + +typedef struct{ + byte Num; +// SFesSimChanParam *pParam; +}SFesSimChanParamResp; + +//通道数据请求================================== +typedef struct{ +}SFesSimChanDataReq; + +//通道数据响应 +typedef struct{ + int ChanNo; //通道号 + uint32 Status; //通道状态 + int RxNum; // + int TxNum; // + int ErrCnt; //帧错误次数(包括CRC错,帧错误等) + float ErrRate; +}SFesSimChanData; + +typedef struct{ + byte Num; +// SFesSimChanData *pData; +}SFesSimChanDataResp; + +//RTU参数请求================================== +typedef struct{ +}SFesSimRTUParamReq; + +//RTU参数响应 +typedef struct{ + uint32 RtuNo; //RTU号 + char TagName[CN_FesMaxTagSize]; //RTU + char RtuName[CN_FesMaxNameSize]; //RTU + int Used; //使用标志 + int Status; //增加通道RTU,不再单独显示 + int RtuAddr; //RTU地址 + int ChanNo; //通道号 + int AiNum; //模拟量个数 + int DiNum; //数字量个数 + int PiNum; //整形数个数 + int RecvFailLimit; //连续接收数据失败计数(>5代表停运) +}SFesSimRTUParam; + +typedef struct{ + byte Num; +// SFesSimRTUParam *pParam; +}SFesSimRTUParamResp; + +//RTU数据请求================================== +typedef struct{ +}SFesSimRTUDataReq; + +//RTU数据响应 +typedef struct{ + uint32 RtuNo; //RTU号 + int m_UsedAiNum; //实际模拟量个数 + int m_UsedDiNum; //实际数字量个数 + int m_UsedPiNum; //实际整形数个数 + int m_CurrentChanNo; +}SFesSimRTUData; + +typedef struct{ + byte Num; +// SFesSimRTUData *pData; +}SFesSimRTUDataResp; + +//RTU信息请求================================== +const int CN_RTUInfoType_AI = 0; //aimondlg +const int CN_RTUInfoType_DI = 1; //dimondlg +const int CN_RTUInfoType_PI = 2; //pimondlg +const int CN_RTUInfoType_SimAI = 3; //simaidlg +const int CN_RTUInfoType_SimDI = 4; //simdidlg +const int CN_RTUInfoType_SimPI = 5; //simpidlg +const int CN_RTUInfoType_SimEvent = 6; //simeventdlg +const int CN_RTUInfoType_SimAo = 7; //simaodlg +const int CN_RTUInfoType_SimDo = 8; //simdodlg +const int CN_RTUInfoType_SimMo = 9; //simmodlg +const int CN_RTUInfoType_SimDefCmd= 10; //simDefCmdlg +const int CN_RTUInfoType_MI = 11; //mimondlg +const int CN_RTUInfoType_SimMI = 12; //simmimondlg +const int CN_RTUInfoType_SimSetting = 13; //simSetting +const int CN_RTUInfoType_DDI = 14; //ddimondlg + +typedef struct{ + uint32 RtuNo; //RTU号 + int Used; //使用标志 + int MaxPoints; + char RtuName[CN_FesMaxNameSize]; //RTU +}SFesSimRTUInfo; + +typedef struct{ + int Type; //哪种类型的窗体的询问 +}SFesSimRTUInfoReq; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + int TotalNum; //总个数 + int Num; //本帧个数 +// SFesSimRTUInfo *pData; +}SFesSimRTUInfoResp; + +//模拟量参数请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 +}SFesSimAiParamReq; + +//模拟量参数响应 +typedef struct{ + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; +}SFesSimAiParam; + +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; + int FesRtuNo; + int FesPointNo; +}SFesSimFwAiParam; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int MaxPoints; //本RTU最大点数 + int Num; //本帧点数 +// SFesSimAiParam *pParam; +}SFesSimAiParamResp; + +//模拟量数值请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int StartIndex; //-1 all data + int EndIndex; //-1 all data +}SFesSimAiDataReq; + +//模拟量数值响应 +typedef struct{ + uint32 PointNo; + float Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesSimAiData; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int Num; +// SFesSimAiData *pData; +}SFesSimAiDataResp; + +//数字量参数请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 +}SFesSimDiParamReq; + +//数字量参数响应 +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; +}SFesSimDiParam; + +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; + int FesRtuNo; + int FesPointNo; +}SFesSimFwDiParam; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int MaxPoints ; //本RTU最大点数 + int Num; //本帧点数 +// SFesSimDiParam *pParam; +}SFesSimDiParamResp; + +//数字量数值请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 +}SFesSimDiDataReq; + +//数字量数值响应 +typedef struct{ + int PointNo; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesSimDiData; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int Num; +// SFesSimDiData *pData; +}SFesSimDiDataResp; + +//整形量参数请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 +}SFesSimAccParamReq; + +//整形量参数响应 +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; +}SFesSimAccParam; + +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; + int FesRtuNo; + int FesPointNo; +}SFesSimFwAccParam; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int MaxPoints ; //本RTU最大点数 + int Num; //本帧点数 +// SFesSimAccParam *pParam; +}SFesSimAccParamResp; + + +//整形量数值请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + int RtuNo; //RTU号 +}SFesSimAccDataReq; + +//整形量数值响应 +typedef struct { + uint32 PointNo; + double Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesSimAccData; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int Num; +// SFesSimAccData *pData; +}SFesSimAccDataResp; + + +//混合量参数请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 +}SFesSimMiParamReq; + +//混合量参数响应 +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; +}SFesSimMiParam; + +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; + int FesRtuNo; + int FesPointNo; +}SFesSimFwMiParam; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int MaxPoints ; //本RTU最大点数 + int Num; //本帧点数 +// SFesSimMiParam *pParam; +}SFesSimMiParamResp; + +//混合量数值请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 +}SFesSimMiDataReq; + +//混合量数值响应 +typedef struct { + uint32 PointNo; + int Value; + uint32 Status; + uint64 time; //1970-01-01 00:00 至今的毫秒数 +}SFesSimMiData; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int Num; +// SFesSimMiData *pData; +}SFesSimMiDataResp; + +//事件监视请求================================== +const int CN_FesSimSoeEvent =0; +const int CN_FesSimRtuEvent =1; +const int CN_FesSimChanEvent =2; + +typedef struct{ + int EventType; //0:soe 1:rtu 2:chan + int Cmd; //0: refresh 1:continue +}SFesSimEventReq; + +//事件监视响应 SOE +typedef struct{ + int EventType; //0:soe 1:rtu 2:chan + int Overflow; //0:normal 1:buffer overflow + int Num; +// SFesSoeEvent *pEvent; +}SFesSimSoeEventResp; + +//事件监视响应 CHAN +typedef struct{ + int EventType; //0:soe 1:rtu 2:chan + int Status; //0:normal 1:buffer overflow + int Num; +// SFesSimChanEvent *pEvent; +}SFesSimChanResp; + +//事件监视响应 RTU +typedef struct{ + int EventType; //0:soe 1:rtu 2:chan + int Status; //0:normal 1:buffer overflow + int Num; +// SFesSimRTUEvent *pEvent; +}SFesSimRTUResp; + +//通道监视启动请求================================== +typedef struct{ + int ChanNo; //通道号 +}SFesSimChanMonStartReq; + +//通道监视启动响应 +typedef struct{ + int ChanNo; //通道号 + int RxNum; // + int TxNum; // + int ErrNum; + int FrameNum; + int Overflow; //0:normal 1:buffer overflow +// SFesChanFrame *pFrame; +}SFesSimChanMonStartResp; + +//通道监视停止请求================================== +typedef struct{ + int ChanNo; //通道号 +}SFesSimChanMonStopReq; + +//通道监视停止响应 +typedef struct{ + int ChanNo; //通道号 +}SFesSimChanMonStopResp; + +//清除通道统计请求================================== +typedef struct{ + int ChanNo; //通道号 +}SFesSimChanClearReq; + +//清除通道统计响应 +typedef struct{ + int ChanNo; //通道号 + int RxNum; + int TxNum; + int ErrNum; +}SFesSimChanClearResp; + +//模拟量仿真启动请求================================== +const int CN_FesSimSetMode_ValueSet = 1; +const int CN_FesSimSetMode_LineSet = 2; +const int CN_FesSimSetMode_RandSet = 3; + +const int CN_FesSimRange_SinglePoint = 1; +const int CN_FesSimRange_RtuPoint = 2; +const int CN_FesSimRange_AllPoint = 3; + +const int CN_FesSim_Points = -1; +const int CN_FesSim_AllRtu = -1; + +typedef struct{ + char SetMode; //设置方式 1:固定设置 2:线性设置 3:随机设置 + char Range; //设置范围 1:当前模拟量 2:当前RTU 3:所有RTU + short Period; //变化周期,单位:秒 + float SetValue; //设置值 + uint32 Status; //设值点状态 + float MinValue; //设置值最小值 + float MaxValue; //设置值最大值 + float StepValue; //设置值步长 + int RtuNo; // RTU号 -1: 所有RTU 其他:对应RTU号 + int PointNo; //点号, -1:RTU所有点 其他:对应点号 +}SFesSimAiStartReq; + +//模拟量仿真启动响应 +typedef struct{ + char SetMode; //设置方式 0:固定设置 1:线性设置 3:随机设置 +}SFesSimAiStartResp; + +//模拟量仿真停止请求================================== +typedef struct{ +}SFesSimAiStopReq; + +//模拟量仿真停止响应 +typedef struct{ +}SFesSimAiStopResp; + + +//数字量仿真启动请求================================== +typedef struct{ + char SetMode; //设置方式 1:固定设置 2:线性设置 3:随机设置 + char Range; //设置范围 1:当前模拟量 2:当前RTU 3:所有RTU + short Period; //变化周期,单位:秒 + int SetValue; //设置值 + uint32 Status; //设值点状态 + int RtuNo; // RTU号 -1: 所有RTU 其他:对应RTU号 + int PointNo; //点号, -1:RTU所有点 其他:对应点号 +}SFesSimDiStartReq; + +//数字量仿真启动响应 +typedef struct{ + char SetMode; //设置方式 1:固定设置 2:线性设置 3:随机设置 +}SFesSimDiStartResp; + +//数字量仿真停止请求================================== +typedef struct{ +}SFesSimDiStopReq; + +//数字量仿真停止响应 +typedef struct{ +}SFesSimDiStopResp; + + +//整形量仿真启动请求================================== +typedef struct{ + char SetMode; //设置方式 1:固定设置 2:线性设置 3:随机设置 + char Range; //设置范围 1:当前模拟量 2:当前RTU 3:所有RTU + short Period; //变化周期,单位:秒 + long SetValue; //设置值 + uint32 Status; //设值点状态 + float MinValue; //设置值最小值 + float MaxValue; //设置值最大值 + float StepValue; //设置值步长 + int RtuNo; // RTU号 -1: 所有RTU 其他:对应RTU号 + int PointNo; //点号, -1:RTU所有点 其他:对应点号 +}SFesSimAccStartReq; + +//整形量仿真启动响应 +typedef struct{ + char SetMode; //设置方式 1:固定设置 2:线性设置 3:随机设置 +}SFesSimAccStartResp; + +//整形量仿真停止请求================================== +typedef struct{ +}SFesSimAccStopReq; + +//整形量仿真停止响应 +typedef struct{ +}SFesSimAccStopResp; + + +//混合量仿真启动请求================================== +typedef struct{ + char SetMode; //设置方式 1:固定设置 2:线性设置 3:随机设置 + char Range; //设置范围 1:当前模拟量 2:当前RTU 3:所有RTU + short Period; //变化周期,单位:秒 + int SetValue; //设置值 + uint32 Status; //设值点状态 + int MinValue; //设置值最小值 + int MaxValue; //设置值最大值 + int StepValue; //设置值步长 + int RtuNo; // RTU号 -1: 所有RTU 其他:对应RTU号 + int PointNo; //点号, -1:RTU所有点 其他:对应点号 +}SFesSimMiStartReq; + +//混合量仿真启动响应 +typedef struct{ + char SetMode; //设置方式 1:固定设置 2:线性设置 3:随机设置 +}SFesSimMiStartResp; + +//混合量仿真停止请求================================== +typedef struct{ +}SFesSimMiStopReq; + +//混合量仿真停止响应 +typedef struct{ +}SFesSimMiStopResp; + +//事件仿真请求================================== +//事件类型 +/* EventType +const int CN_FesRtuSoeEvent = 1; //接入设备(RTU)SOE事件 +const int CN_FesFepSoeEvent = 2; //前置终端(FEP)生成SOE事件 +const int CN_FesRtuEvent = 3; //RTU事件 +const int CN_FesChanEvent = 4; //通道事件 +*/ + +typedef struct{ + int Source; //事件来源前置系统采集:装置事件、数据处理模块产生事件、前置系统事件(CHAN RTU事件) + uint32 RtuNo; + int PointId; //遥信号 + int Value; //点值 + uint32 Status; //遥测信状态 + int FaultNum; //故障值个数 + int FaultValTag [CN_FesMaxFaultNum];//表明以下数值的来源 + float FaultVal[CN_FesMaxFaultNum]; +}SFesSimSoeEvent; + +//事件仿真请求 SOE +typedef struct{ + int EventType; + SFesSimSoeEvent Event; +}SFesSimEventSetSoeReq; + +//事件仿真请求 RTU,保留暂时不实现 +typedef struct{ + int EventType; + SFesRtuEvent Event; +}SFesSimEventSetRTUReq; + +//事件仿真请求 CHAN,保留暂时不实现 +typedef struct{ + int EventType; + SFesChanEvent Event; +}SFesSimEventSetChanReq; + +//事件仿真响应 +typedef struct{ + int EventType; +}SFesSimEventSetResp; + +//DO参数请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + int RtuNo; //RTU号 +}SFesSimDoParamReq; + +//DO参数响应 +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; +}SFesSimDoParam; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int MaxPoints ; //本RTU最大点数 + int Num; //本帧点数 +// SFesSimDoParam *pParam; +}SFesSimDoParamResp; + + +//AO参数请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 +}SFesSimAoParamReq; + +//AO参数响应 +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; +}SFesSimAoParam; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int MaxPoints ; //本RTU最大点数 + int Num; //本帧点数 +// SFesSimAoParam *pParam; +}SFesSimAoParamResp; + +//MO参数请求================================== +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 +}SFesSimMoParamReq; + +//MO参数响应 +typedef struct { + uint32 PointNo; + int Used; + char PointTagName[CN_FesMaxTagSize]; +}SFesSimMoParam; + +typedef struct{ + int Type; //哪种类型的窗体的询问 + uint32 RtuNo; //RTU号 + int MaxPoints ; //本RTU最大点数 + int Num; //本帧点数 +// SFesSimMoParam *pParam; +}SFesSimMoParamResp; + +//数字量遥控仿真请求================================== +typedef struct{ + int RtuNo; + SFesRxDoCmd Cmd; +}SFesSimDoCmdReq; + +//数字量遥控仿真响应 +typedef struct{ + uint32 RtuNo; +}SFesSimDoCmdResp; + +//模拟量遥控仿真请求================================== +typedef struct{ + uint32 RtuNo; + SFesRxAoCmd Cmd; +}SFesSimAoCmdReq; + +//模拟量遥控仿真响应 +typedef struct{ + uint32 RtuNo; +}SFesSimAoCmdResp; + +//整形量遥控仿真请求================================== +typedef struct{ + uint32 RtuNo; + SFesRxMoCmd Cmd; +}SFesSimMoCmdReq; + +//整形量遥控仿真响应 +typedef struct{ + uint32 RtuNo; +}SFesSimMoCmdResp; + +//自定义命令仿真请求================================== +typedef struct{ + char keyWord[40]; + char keyValue[40]; +}SFesSimDefCmd; + +typedef struct{ + uint32 RtuNo; + uint32 DevId; + uint32 CmdNum; + SFesSimDefCmd Cmd[6]; +}SFesSimDefCmdReq; + +//自定义命令仿真响应 +typedef struct{ + int RtuNo; +}SFesSimDefCmdResp; + +//2019-09-11 thxiao 增加读取SOE内存 +typedef struct { + ; +}SFesSimSoeMemoryReq; + +typedef struct { + int StartIndex; + int Num; +// SFesSoeEvent event[Num]; +}SFesSimSoeMemoryResp; diff --git a/product/src/tools/debug_tool_v2/MbClientMngThread.cpp b/product/src/tools/debug_tool_v2/MbClientMngThread.cpp new file mode 100644 index 00000000..38371dd4 --- /dev/null +++ b/product/src/tools/debug_tool_v2/MbClientMngThread.cpp @@ -0,0 +1,415 @@ +#include "MbClientMngThread.h" +#include "FesDebugTool.pb.h" +#include "pub_logger_api/logger.h" +#include "pub_utility_api/TimeUtil.h" + +using namespace std; +using namespace iot_public; +using namespace iot_idl; + +const int CN_Heartbeat_Timeout = 1 * 1000; //心跳间隔时间 + +CMbClientMngThread::CMbClientMngThread() +{ + m_lLastHeartbeatTime = getMonotonicMsec(); + m_bIsConnected = false; + connect(this,&CMbClientMngThread::signal_clean,this,&CMbClientMngThread::disconnectToServer,Qt::QueuedConnection); +} + +CMbClientMngThread::~CMbClientMngThread() +{ + disconnectToServerSignal(false); +} + +bool CMbClientMngThread::connectToServer(const QString &strIP,const int &nPort) +{ + boost::mutex::scoped_lock lock(m_mutexComm); + m_objComm.close(); //先销毁 + + if(!m_objComm.init(strIP.toStdString(),nPort)) + { + m_objComm.close(); //要清理掉 + return false; + } + + if(sendConnectMsg()) + { + m_bIsConnected = true; + m_lLastHeartbeatTime = getMonotonicMsec(); + QThread::start(); + emit signal_connected(); + return true; + } + + m_objComm.close(); + + return false; +} + +bool CMbClientMngThread::disconnectToServer() +{ + return disconnectToServerSignal(true); +} + +bool CMbClientMngThread::disconnectToServerSignal(bool sendSignal) +{ + if(QThread::isRunning()) + { + sendDisconnectMsg(); + QThread::msleep(50); //等待断开报文发送出去 + + QThread::requestInterruption(); + QThread::quit(); + QThread::wait(); + } + + boost::mutex::scoped_lock lock(m_mutexComm); + bool bRet = m_objComm.close(); + if(sendSignal) + { + emit signal_disconnected(); + } + m_bIsConnected = false; + + return bRet; +} + +void CMbClientMngThread::run() +{ + while (!isInterruptionRequested()) + { + int64 lCurTime = getMonotonicMsec(); + if(lCurTime - m_lLastHeartbeatTime > CN_Heartbeat_Timeout) + { + if(m_bIsConnected && !sendHeartbeatMsg()) + { + emit signal_clean(); + return; + } + } + + if(lCurTime - m_lLastHeartbeatTime > 3*CN_Heartbeat_Timeout) + { + //长时间没有收到心跳 + LOGINFO("CMbClientMngThread:心跳超时"); + emit signal_clean(); + return; + } + + string strMsg; + if(!m_objComm.recvMsg(strMsg,500)) + { + continue; + } + + FesDebugToolRepMsg objRepMsg; + if(!objRepMsg.ParseFromString(strMsg)) + { + LOGERROR("CMbClientMngThread:反序列化消息失败"); + continue; + } + + switch (objRepMsg.type()) + { + case MT_FESDBG_HeartBeat: + m_lLastHeartbeatTime = getMonotonicMsec(); + break; + case MT_FESDBG_ChanParam: + emit signal_chanParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_RtuParam: + emit signal_rtuParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_AI_RtuInfo: + emit signal_aiRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_AI_Param: + emit signal_aiParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_AI_Value: + emit signal_aiValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_DI_RtuInfo: + emit signal_diRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_DI_Param: + emit signal_diParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_DI_Value: + emit signal_diValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_ACC_RtuInfo: + emit signal_accRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_ACC_Param: + emit signal_accParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_ACC_Value: + emit signal_accValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_MI_RtuInfo: + emit signal_miRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_MI_Param: + emit signal_miParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_MI_Value: + emit signal_miValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimAI_RtuInfo: + emit signal_simAiRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimAI_Param: + emit signal_simAiParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimAI_Value: + emit signal_simAiValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimAI_StartSim: + emit signal_simAiStartSimResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimAI_StopSim: + emit signal_simAiStopSimResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimDI_RtuInfo: + emit signal_simDiRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimDI_Param: + emit signal_simDiParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimDI_Value: + emit signal_simDiValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimDI_StartSim: + emit signal_simDiStartSimResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimDI_StopSim: + emit signal_simDiStopSimResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimMI_RtuInfo: + emit signal_simMiRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimMI_Param: + emit signal_simMiParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimMI_Value: + emit signal_simMiValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimMI_StartSim: + emit signal_simMiStartSimResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimMI_StopSim: + emit signal_simMiStopSimResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimACC_RtuInfo: + emit signal_simAccRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimACC_Param: + emit signal_simAccParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimACC_Value: + emit signal_simAccValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimACC_StartSim: + emit signal_simAccStartSimResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimACC_StopSim: + emit signal_simAccStopSimResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimEvent_RtuInfo: + emit signal_simEventRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimEvent_DiParam: + emit signal_simEventDiParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimEvent_Create: + emit signal_simEventCreateResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimAO_RtuInfo: + emit signal_simAoRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimAO_Param: + emit signal_simAoParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimAO_Control: + emit signal_simAoControlResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimDO_RtuInfo: + emit signal_simDoRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimDO_Param: + emit signal_simDoParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimDO_Control: + emit signal_simDoControlResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimMO_RtuInfo: + emit signal_simMoRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimMO_Param: + emit signal_simMoParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_SimMO_Control: + emit signal_simMoControlResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWAI_RtuInfo: + emit signal_fwAiRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWAI_Param: + emit signal_fwAiParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWAI_Value: + emit signal_fwAiValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWDI_RtuInfo: + emit signal_fwDiRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWDI_Param: + emit signal_fwDiParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWDI_Value: + emit signal_fwDiValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWDDI_RtuInfo: + emit signal_fwDDiRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWDDI_Param: + emit signal_fwDDiParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWDDI_Value: + emit signal_fwDDiValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWMI_RtuInfo: + emit signal_fwMiRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWMI_Param: + emit signal_fwMiParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWMI_Value: + emit signal_fwMiValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWACC_RtuInfo: + emit signal_fwAccRtuInfoResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWACC_Param: + emit signal_fwAccParamResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_FWACC_Value: + emit signal_fwAccValueResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_Event_SOE: + emit signal_soeEventResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_Event_Channel: + emit signal_chanEventResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_Event_SOEMemory: + emit signal_soeMemEventResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_Mon_ChanStart: + emit signal_chanMonStartResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_Mon_ChanStop: + emit signal_chanMonStopResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_Mon_ChanClear: + emit signal_chanMonClearResp(objRepMsg.type(),objRepMsg.body()); + break; + case MT_FESDBG_Mon_ChanInfo: + emit signal_chanMonInfo(objRepMsg.type(),objRepMsg.body()); + break; + default: + break; + } + } +} + +void CMbClientMngThread::slot_sendMsg(const string &strMsg) +{ + m_objComm.sendMsg(strMsg); +} + +bool CMbClientMngThread::sendConnectMsg() +{ + FesDebugToolReqMsg objSendMsg; + objSendMsg.set_type(MT_FESDBG_CONNECT); + objSendMsg.set_body("CONNECT"); + + string strSendMsg; + if(!objSendMsg.SerializeToString(&strSendMsg)) + { + LOGERROR("CMbClient:序列化连接消息失败"); + return false; + } + + if(!m_objComm.sendMsg(strSendMsg)) + { + LOGERROR("CMbClient:发送连接消息失败"); + return false; + } + + string strRecvMsg; + if(!m_objComm.recvMsg(strRecvMsg,CN_CONNECT_TIMEOUT)) + { + LOGERROR("CMbClient:未接收到连接反馈消息,连接失败"); + return false; + } + + FesDebugToolRepMsg objRecvMsg; + if(!objRecvMsg.ParseFromString(strRecvMsg)) + { + LOGERROR("CMbClient:反序列化连接反馈消息失败"); + return false; + } + + if(objRecvMsg.type() == MT_FESDBG_CONNECT) + { + LOGINFO("CMbClient:连接成功"); + return true; + } + + return false; +} + +bool CMbClientMngThread::sendDisconnectMsg() +{ + FesDebugToolReqMsg objSendMsg; + objSendMsg.set_type(MT_FESDBG_DISCONNECT); + objSendMsg.set_body("MT_FESDBG_DISCONNECT"); + + string strSendMsg; + if(!objSendMsg.SerializeToString(&strSendMsg)) + { + LOGERROR("CMbClient:序列化连接消息失败"); + return false; + } + + if(!m_objComm.sendMsg(strSendMsg)) + { + LOGERROR("CMbClient:发送连接消息失败"); + return false; + } + + return true; +} + +bool CMbClientMngThread::sendHeartbeatMsg() +{ + FesDebugToolReqMsg objSendMsg; + objSendMsg.set_type(MT_FESDBG_HeartBeat); + objSendMsg.set_body(""); + + string strSendMsg; + if(!objSendMsg.SerializeToString(&strSendMsg)) + { + LOGERROR("CMbClient:sendHeartbeatMsg 序列化连接消息失败"); + return false; + } + + if(!m_objComm.sendMsg(strSendMsg)) + { + return false; + } + + return true; +} diff --git a/product/src/tools/debug_tool_v2/MbClientMngThread.h b/product/src/tools/debug_tool_v2/MbClientMngThread.h new file mode 100644 index 00000000..272a2d70 --- /dev/null +++ b/product/src/tools/debug_tool_v2/MbClientMngThread.h @@ -0,0 +1,142 @@ +#ifndef MBCLIENT_H +#define MBCLIENT_H + +#include +#include "MbCommunicator.h" +#include + +const int CN_CONNECT_TIMEOUT = 1000; //单位毫秒 + +class CMbClientMngThread : public QThread +{ + Q_OBJECT +public: + CMbClientMngThread(); + virtual ~CMbClientMngThread(); + bool connectToServer(const QString &strIP,const int &nPort); + +public slots: + bool disconnectToServer(); + bool disconnectToServerSignal(bool sendSignal); + +protected: + virtual void run(); + +signals: + void signal_connected(); + void signal_disconnected(); + void signal_clean(); + + void signal_chanParamResp(int nMsgType, const std::string &strBody); + void signal_rtuParamResp(int nMsgType, const std::string &strBody); + + void signal_aiRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_aiParamResp(int nMsgType, const std::string &strBody); + void signal_aiValueResp(int nMsgType, const std::string &strBody); + + void signal_diRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_diParamResp(int nMsgType, const std::string &strBody); + void signal_diValueResp(int nMsgType, const std::string &strBody); + + void signal_accRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_accParamResp(int nMsgType, const std::string &strBody); + void signal_accValueResp(int nMsgType, const std::string &strBody); + + void signal_miRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_miParamResp(int nMsgType, const std::string &strBody); + void signal_miValueResp(int nMsgType, const std::string &strBody); + + //数据仿真 + void signal_simAiRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_simAiParamResp(int nMsgType, const std::string &strBody); + void signal_simAiValueResp(int nMsgType, const std::string &strBody); + void signal_simAiStartSimResp(int nMsgType, const std::string &strBody); + void signal_simAiStopSimResp(int nMsgType, const std::string &strBody); + + void signal_simDiRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_simDiParamResp(int nMsgType, const std::string &strBody); + void signal_simDiValueResp(int nMsgType, const std::string &strBody); + void signal_simDiStartSimResp(int nMsgType, const std::string &strBody); + void signal_simDiStopSimResp(int nMsgType, const std::string &strBody); + + void signal_simMiRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_simMiParamResp(int nMsgType, const std::string &strBody); + void signal_simMiValueResp(int nMsgType, const std::string &strBody); + void signal_simMiStartSimResp(int nMsgType, const std::string &strBody); + void signal_simMiStopSimResp(int nMsgType, const std::string &strBody); + + void signal_simAccRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_simAccParamResp(int nMsgType, const std::string &strBody); + void signal_simAccValueResp(int nMsgType, const std::string &strBody); + void signal_simAccStartSimResp(int nMsgType, const std::string &strBody); + void signal_simAccStopSimResp(int nMsgType, const std::string &strBody); + + void signal_simEventRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_simEventDiParamResp(int nMsgType, const std::string &strBody); + void signal_simEventCreateResp(int nMsgType, const std::string &strBody); + + //控制仿真 + void signal_simAoRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_simAoParamResp(int nMsgType, const std::string &strBody); + void signal_simAoControlResp(int nMsgType, const std::string &strBody); + + void signal_simDoRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_simDoParamResp(int nMsgType, const std::string &strBody); + void signal_simDoControlResp(int nMsgType, const std::string &strBody); + + void signal_simMoRtuInfoResp(int nMsgType, const std::string &strBody); + void signal_simMoParamResp(int nMsgType, const std::string &strBody); + void signal_simMoControlResp(int nMsgType, const std::string &strBody); + + //控制仿真 - 自定义命令 + void signal_simDefCmdRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_simDefCmdControlResp(int nMsgType,const std::string &strBody); + + //转发数据 + void signal_fwAiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwAiParamResp(int nMsgType,const std::string &strBody); + void signal_fwAiValueResp(int nMsgType,const std::string &strBody); + //转发数据 - 数字量(单位开关) + void signal_fwDiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwDiParamResp(int nMsgType,const std::string &strBody); + void signal_fwDiValueResp(int nMsgType,const std::string &strBody); + //转发数据 - 数字量(双位开关) + void signal_fwDDiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwDDiParamResp(int nMsgType,const std::string &strBody); + void signal_fwDDiValueResp(int nMsgType,const std::string &strBody); + //转发数据 - 混合量 + void signal_fwMiRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwMiParamResp(int nMsgType,const std::string &strBody); + void signal_fwMiValueResp(int nMsgType,const std::string &strBody); + //转发数据 - 累积量 + void signal_fwAccRtuInfoResp(int nMsgType,const std::string &strBody); + void signal_fwAccParamResp(int nMsgType,const std::string &strBody); + void signal_fwAccValueResp(int nMsgType,const std::string &strBody); + + //事件监视 + void signal_soeEventResp(int nMsgType,const std::string &strBody); + void signal_chanEventResp(int nMsgType,const std::string &strBody); + void signal_soeMemEventResp(int nMsgType,const std::string &strBody); + + //通道监视 + void signal_chanMonStartResp(int nMsgType,const std::string &strBody); + void signal_chanMonStopResp(int nMsgType,const std::string &strBody); + void signal_chanMonClearResp(int nMsgType,const std::string &strBody); + void signal_chanMonInfo(int nMsgType,const std::string &strBody); + +public slots: + void slot_sendMsg(const std::string &strMsg); + +private: + bool sendConnectMsg(); + bool sendDisconnectMsg(); + bool sendHeartbeatMsg(); + +private: + CMbCommunicator m_objComm; + qint64 m_lLastHeartbeatTime; + bool m_bIsConnected; + boost::mutex m_mutexComm; +}; + +#endif // MBCLIENT_H diff --git a/product/src/tools/debug_tool_v2/MbCommunicator.cpp b/product/src/tools/debug_tool_v2/MbCommunicator.cpp new file mode 100644 index 00000000..98825451 --- /dev/null +++ b/product/src/tools/debug_tool_v2/MbCommunicator.cpp @@ -0,0 +1,141 @@ +#include "MbCommunicator.h" +#include "czmq.h" +#include "common/Common.h" +#include "pub_logger_api/logger.h" +#include "pub_utility_api/CharUtil.h" + +#define ZMQ_FES_CLIENT_IDENTITY "fes" + +using namespace std; +using namespace iot_public; + +class CMbCommunicatorInfo +{ +public: + CMbCommunicatorInfo() { + m_pClient = NULL; + m_pPoller = NULL; + } + + zsock_t *m_pClient; + zpoller_t *m_pPoller; +}; + + +CMbCommunicator::CMbCommunicator() +{ + m_pCommInfo = new CMbCommunicatorInfo(); +} + +CMbCommunicator::~CMbCommunicator() +{ + if(m_pCommInfo != NULL) + { + close(); + delete m_pCommInfo; + } +} + +bool CMbCommunicator::init(const std::string &strIP,const int &nPort) +{ + if(iotSuccess != initClient(strIP,nPort)) + { + return false; + } + + return true; +} + +bool CMbCommunicator::recvMsg(std::string &strMsg, const int &nTimeoutMs) +{ + zsock_t *pReader = (zsock_t *)zpoller_wait(m_pCommInfo->m_pPoller,nTimeoutMs); + if(pReader == NULL) + { + return false; + } + + zmsg_t *msg = zmsg_recv (m_pCommInfo->m_pClient); + zframe_t *last = zmsg_last(msg); + strMsg.append((char*)zframe_data(last),zframe_size(last)); + zmsg_destroy(&msg); + + return true; +} + +bool CMbCommunicator::sendMsg(const string &strMsg) +{ + QMutexLocker locker(&m_commMutex); + if(m_pCommInfo->m_pClient == NULL) + { + return false; + } + + zmsg_t *sendMsg = zmsg_new (); + zmsg_addstr(sendMsg,ZMQ_FES_CLIENT_IDENTITY); + zmsg_addmem(sendMsg,strMsg.c_str(),strMsg.size()); + int nRet = zmsg_send(&sendMsg,m_pCommInfo->m_pClient); + zmsg_destroy(&sendMsg); + + return (nRet >=0); +} + +bool CMbCommunicator::close() +{ + LOGINFO("CMbCommunicator:关闭客户端"); + QMutexLocker locker(&m_commMutex); + if(iotSuccess != closeClient()) + { + return false; + } + + return true; +} + +int CMbCommunicator::initClient(const std::string &strIP,const int &nPort) +{ + m_pCommInfo->m_pClient = zsock_new(ZMQ_DEALER); + if(m_pCommInfo->m_pClient == NULL) + { + LOGERROR("CDebugMbCommunicator: 创建DEALER失败"); + return iotFailed; + } + + zsock_set_sndhwm(m_pCommInfo->m_pClient,5); + zsock_set_sndtimeo(m_pCommInfo->m_pClient,1000); + zsock_set_identity(m_pCommInfo->m_pClient,ZMQ_FES_CLIENT_IDENTITY); + //< 连接超时时间,单位ms,libzmq 4.2版本开始支持此属性 + //< 覆盖系统TCP协议栈默认值,防止重连时间过长的问题 + zsock_set_connect_timeout(m_pCommInfo->m_pClient, 1000); + + string strEndpoints = "tcp://" + strIP + ":" + IntToString(nPort); + int nRet = zsock_connect(m_pCommInfo->m_pClient,strEndpoints.c_str()); + if(nRet < 0) + { + LOGERROR("CDebugMbCommunicator: connect server failed. endpoints=%s",strEndpoints.c_str()); + closeClient(); + return iotFailed; + } + + m_pCommInfo->m_pPoller = zpoller_new (m_pCommInfo->m_pClient, NULL); + zpoller_set_nonstop (m_pCommInfo->m_pPoller, true); + + LOGINFO("CMbCommunicator: 连接套接字创建成功. endpoints=%s",strEndpoints.c_str()); + return iotSuccess; +} + +int CMbCommunicator::closeClient() +{ + if(m_pCommInfo->m_pPoller != NULL) + { + zpoller_destroy(&m_pCommInfo->m_pPoller); + m_pCommInfo->m_pPoller = NULL; + } + + if(m_pCommInfo->m_pClient != NULL) + { + zsock_destroy(&m_pCommInfo->m_pClient); + m_pCommInfo->m_pClient = NULL; + } + + return iotSuccess; +} diff --git a/product/src/tools/debug_tool_v2/MbCommunicator.h b/product/src/tools/debug_tool_v2/MbCommunicator.h new file mode 100644 index 00000000..eb9728e0 --- /dev/null +++ b/product/src/tools/debug_tool_v2/MbCommunicator.h @@ -0,0 +1,30 @@ +#ifndef DEBUGMBCOMMUNICATOR_H +#define DEBUGMBCOMMUNICATOR_H + +#include +#include + +class CMbCommunicatorInfo; + +class CMbCommunicator +{ +public: + CMbCommunicator(); + virtual ~CMbCommunicator(); + + bool init(const std::string &strIP,const int &nPort); + bool recvMsg(std::string &strMsg,const int &nTimeoutMs); + bool sendMsg(const std::string &strMsg); + bool close(); + +private: + int initClient(const std::string &strIP,const int &nPort); + int closeClient(); + +private: + CMbCommunicatorInfo *m_pCommInfo; + QMutex m_commMutex; //保护zeromq资源,防止在关闭的client上发送消息 + +}; + +#endif // DEBUGMBCOMMUNICATOR_H diff --git a/product/src/tools/debug_tool_v2/SingleApplication.cpp b/product/src/tools/debug_tool_v2/SingleApplication.cpp new file mode 100644 index 00000000..5da40fa4 --- /dev/null +++ b/product/src/tools/debug_tool_v2/SingleApplication.cpp @@ -0,0 +1,181 @@ +// The MIT License (MIT) +// +// Copyright (c) Itay Grudev 2015 - 2018 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include +#include +#include +#include +#include + +#include "SingleApplication.h" +#include "SingleApplication_p.h" + +/** + * @brief Constructor. Checks and fires up LocalServer or closes the program + * if another instance already exists + * @param argc + * @param argv + * @param {bool} allowSecondaryInstances + */ +SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSecondary, Options options, int timeout ) + : app_t( argc, argv ), d_ptr( new SingleApplicationPrivate( this ) ) +{ + Q_D(SingleApplication); + +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) + // On Android and iOS since the library is not supported fallback to + // standard QApplication behaviour by simply returning at this point. + qWarning() << "SingleApplication is not supported on Android and iOS systems."; + return; +#endif + + // Store the current mode of the program + d->options = options; + + // Generating an application ID used for identifying the shared memory + // block and QLocalServer + d->genBlockServerName(); + +#ifdef Q_OS_UNIX + // By explicitly attaching it and then deleting it we make sure that the + // memory is deleted even after the process has crashed on Unix. + d->memory = new QSharedMemory( d->blockServerName ); + d->memory->attach(); + delete d->memory; +#endif + // Guarantee thread safe behaviour with a shared memory block. + d->memory = new QSharedMemory( d->blockServerName ); + + // Create a shared memory block + if( d->memory->create( sizeof( InstancesInfo ) ) ) { + // Initialize the shared memory block + d->memory->lock(); + d->initializeMemoryBlock(); + d->memory->unlock(); + } else { + // Attempt to attach to the memory segment + if( ! d->memory->attach() ) { + qCritical() << "SingleApplication: Unable to attach to shared memory block."; + qCritical() << d->memory->errorString(); + delete d; + ::exit( EXIT_FAILURE ); + } + } + + InstancesInfo* inst = static_cast( d->memory->data() ); + QTime time; + time.start(); + + // Make sure the shared memory block is initialised and in consistent state + while( true ) { + d->memory->lock(); + + if( d->blockChecksum() == inst->checksum ) break; + + if( time.elapsed() > 5000 ) { + qWarning() << "SingleApplication: Shared memory block has been in an inconsistent state from more than 5s. Assuming primary instance failure."; + d->initializeMemoryBlock(); + } + + d->memory->unlock(); + + // Random sleep here limits the probability of a collision between two racing apps + qsrand( QDateTime::currentMSecsSinceEpoch() % std::numeric_limits::max() ); + QThread::sleep( 8 + static_cast ( static_cast ( qrand() ) / RAND_MAX * 10 ) ); + } + + if( inst->primary == false) { + d->startPrimary(); + d->memory->unlock(); + return; + } + + // Check if another instance can be started + if( allowSecondary ) { + inst->secondary += 1; + inst->checksum = d->blockChecksum(); + d->instanceNumber = inst->secondary; + d->startSecondary(); + if( d->options & Mode::SecondaryNotification ) { + d->connectToPrimary( timeout, SingleApplicationPrivate::SecondaryInstance ); + } + d->memory->unlock(); + return; + } + + d->memory->unlock(); + + d->connectToPrimary( timeout, SingleApplicationPrivate::NewInstance ); + + delete d; + + ::exit( EXIT_SUCCESS ); +} + +/** + * @brief Destructor + */ +SingleApplication::~SingleApplication() +{ + Q_D(SingleApplication); + delete d; +} + +bool SingleApplication::isPrimary() +{ + Q_D(SingleApplication); + return d->server != nullptr; +} + +bool SingleApplication::isSecondary() +{ + Q_D(SingleApplication); + return d->server == nullptr; +} + +quint32 SingleApplication::instanceId() +{ + Q_D(SingleApplication); + return d->instanceNumber; +} + +qint64 SingleApplication::primaryPid() +{ + Q_D(SingleApplication); + return d->primaryPid(); +} + +bool SingleApplication::sendMessage( QByteArray message, int timeout ) +{ + Q_D(SingleApplication); + + // Nobody to connect to + if( isPrimary() ) return false; + + // Make sure the socket is connected + d->connectToPrimary( timeout, SingleApplicationPrivate::Reconnect ); + + d->socket->write( message ); + bool dataWritten = d->socket->waitForBytesWritten( timeout ); + d->socket->flush(); + return dataWritten; +} diff --git a/product/src/tools/debug_tool_v2/SingleApplication.h b/product/src/tools/debug_tool_v2/SingleApplication.h new file mode 100644 index 00000000..cb505971 --- /dev/null +++ b/product/src/tools/debug_tool_v2/SingleApplication.h @@ -0,0 +1,135 @@ +// The MIT License (MIT) +// +// Copyright (c) Itay Grudev 2015 - 2018 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#ifndef SINGLE_APPLICATION_H +#define SINGLE_APPLICATION_H + +#include +#include + +#ifndef QAPPLICATION_CLASS + #define QAPPLICATION_CLASS QCoreApplication +#endif + +#include QT_STRINGIFY(QAPPLICATION_CLASS) + +class SingleApplicationPrivate; + +/** + * @brief The SingleApplication class handles multiple instances of the same + * Application + * @see QCoreApplication + */ +class SingleApplication : public QAPPLICATION_CLASS +{ + Q_OBJECT + + typedef QAPPLICATION_CLASS app_t; + +public: + /** + * @brief Mode of operation of SingleApplication. + * Whether the block should be user-wide or system-wide and whether the + * primary instance should be notified when a secondary instance had been + * started. + * @note Operating system can restrict the shared memory blocks to the same + * user, in which case the User/System modes will have no effect and the + * block will be user wide. + * @enum + */ + enum Mode { + User = 1 << 0, + System = 1 << 1, + SecondaryNotification = 1 << 2, + ExcludeAppVersion = 1 << 3, + ExcludeAppPath = 1 << 4 + }; + Q_DECLARE_FLAGS(Options, Mode) + + /** + * @brief Intitializes a SingleApplication instance with argc command line + * arguments in argv + * @arg {int &} argc - Number of arguments in argv + * @arg {const char *[]} argv - Supplied command line arguments + * @arg {bool} allowSecondary - Whether to start the instance as secondary + * if there is already a primary instance. + * @arg {Mode} mode - Whether for the SingleApplication block to be applied + * User wide or System wide. + * @arg {int} timeout - Timeout to wait in milliseconds. + * @note argc and argv may be changed as Qt removes arguments that it + * recognizes + * @note Mode::SecondaryNotification only works if set on both the primary + * instance and the secondary instance. + * @note The timeout is just a hint for the maximum time of blocking + * operations. It does not guarantee that the SingleApplication + * initialisation will be completed in given time, though is a good hint. + * Usually 4*timeout would be the worst case (fail) scenario. + * @see See the corresponding QAPPLICATION_CLASS constructor for reference + */ + explicit SingleApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 ); + ~SingleApplication(); + + /** + * @brief Returns if the instance is the primary instance + * @returns {bool} + */ + bool isPrimary(); + + /** + * @brief Returns if the instance is a secondary instance + * @returns {bool} + */ + bool isSecondary(); + + /** + * @brief Returns a unique identifier for the current instance + * @returns {qint32} + */ + quint32 instanceId(); + + /** + * @brief Returns the process ID (PID) of the primary instance + * @returns {qint64} + */ + qint64 primaryPid(); + + /** + * @brief Sends a message to the primary instance. Returns true on success. + * @param {int} timeout - Timeout for connecting + * @returns {bool} + * @note sendMessage() will return false if invoked from the primary + * instance. + */ + bool sendMessage( QByteArray message, int timeout = 100 ); + +Q_SIGNALS: + void instanceStarted(); + void receivedMessage( quint32 instanceId, QByteArray message ); + +private: + SingleApplicationPrivate *d_ptr; + Q_DECLARE_PRIVATE(SingleApplication) +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(SingleApplication::Options) + +#endif // SINGLE_APPLICATION_H diff --git a/product/src/tools/debug_tool_v2/SingleApplication_p.cpp b/product/src/tools/debug_tool_v2/SingleApplication_p.cpp new file mode 100644 index 00000000..d3b1b81e --- /dev/null +++ b/product/src/tools/debug_tool_v2/SingleApplication_p.cpp @@ -0,0 +1,405 @@ +// The MIT License (MIT) +// +// Copyright (c) Itay Grudev 2015 - 2018 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// +// W A R N I N G !!! +// ----------------- +// +// This file is not part of the SingleApplication API. It is used purely as an +// implementation detail. This header file may change from version to +// version without notice, or may even be removed. +// + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "SingleApplication.h" +#include "SingleApplication_p.h" + +#ifdef Q_OS_UNIX + #include + #include + #include +#endif + +#ifdef Q_OS_WIN + #include + #include +#endif + +SingleApplicationPrivate::SingleApplicationPrivate( SingleApplication *q_ptr ) + : q_ptr( q_ptr ) +{ + server = nullptr; + socket = nullptr; + memory = nullptr; + instanceNumber = -1; +} + +SingleApplicationPrivate::~SingleApplicationPrivate() +{ + if( socket != nullptr ) { + socket->close(); + delete socket; + } + + memory->lock(); + InstancesInfo* inst = static_cast(memory->data()); + if( server != nullptr ) { + server->close(); + delete server; + inst->primary = false; + inst->primaryPid = -1; + inst->checksum = blockChecksum(); + } + memory->unlock(); + + delete memory; +} + +void SingleApplicationPrivate::genBlockServerName() +{ + QCryptographicHash appData( QCryptographicHash::Sha256 ); + appData.addData( "SingleApplication", 17 ); + appData.addData( SingleApplication::app_t::applicationName().toUtf8() ); + appData.addData( SingleApplication::app_t::organizationName().toUtf8() ); + appData.addData( SingleApplication::app_t::organizationDomain().toUtf8() ); + + if( ! (options & SingleApplication::Mode::ExcludeAppVersion) ) { + appData.addData( SingleApplication::app_t::applicationVersion().toUtf8() ); + } + + if( ! (options & SingleApplication::Mode::ExcludeAppPath) ) { +#ifdef Q_OS_WIN + appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() ); +#else + appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() ); +#endif + } + + // User level block requires a user specific data in the hash + if( options & SingleApplication::Mode::User ) { +#ifdef Q_OS_WIN + wchar_t username [ UNLEN + 1 ]; + // Specifies size of the buffer on input + DWORD usernameLength = UNLEN + 1; + if( GetUserNameW( username, &usernameLength ) ) { + appData.addData( QString::fromWCharArray(username).toUtf8() ); + } else { + appData.addData( qgetenv("USERNAME") ); + } +#endif +#ifdef Q_OS_UNIX + QByteArray username; + uid_t uid = geteuid(); + struct passwd *pw = getpwuid(uid); + if( pw ) { + username = pw->pw_name; + } + if( username.isEmpty() ) { + username = qgetenv("USER"); + } + appData.addData(username); +#endif + } + + // Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with + // server naming requirements. + blockServerName = appData.result().toBase64().replace("/", "_"); +} + +void SingleApplicationPrivate::initializeMemoryBlock() +{ + InstancesInfo* inst = static_cast( memory->data() ); + inst->primary = false; + inst->secondary = 0; + inst->primaryPid = -1; + inst->checksum = blockChecksum(); +} + +void SingleApplicationPrivate::startPrimary() +{ + Q_Q(SingleApplication); + //q; + // Successful creation means that no main process exists + // So we start a QLocalServer to listen for connections + QLocalServer::removeServer( blockServerName ); + server = new QLocalServer(); + + // Restrict access to the socket according to the + // SingleApplication::Mode::User flag on User level or no restrictions + if( options & SingleApplication::Mode::User ) { + server->setSocketOptions( QLocalServer::UserAccessOption ); + } else { + server->setSocketOptions( QLocalServer::WorldAccessOption ); + } + + server->listen( blockServerName ); + QObject::connect( + server, + &QLocalServer::newConnection, + this, + &SingleApplicationPrivate::slotConnectionEstablished + ); + + // Reset the number of connections + InstancesInfo* inst = static_cast ( memory->data() ); + + inst->primary = true; + inst->primaryPid = q->applicationPid(); + inst->checksum = blockChecksum(); + + instanceNumber = 0; +} + +void SingleApplicationPrivate::startSecondary() +{ +} + +void SingleApplicationPrivate::connectToPrimary( int msecs, ConnectionType connectionType ) +{ + // Connect to the Local Server of the Primary Instance if not already + // connected. + if( socket == nullptr ) { + socket = new QLocalSocket(); + } + + // If already connected - we are done; + if( socket->state() == QLocalSocket::ConnectedState ) + return; + + // If not connect + if( socket->state() == QLocalSocket::UnconnectedState || + socket->state() == QLocalSocket::ClosingState ) { + socket->connectToServer( blockServerName ); + } + + // Wait for being connected + if( socket->state() == QLocalSocket::ConnectingState ) { + socket->waitForConnected( msecs ); + } + + // Initialisation message according to the SingleApplication protocol + if( socket->state() == QLocalSocket::ConnectedState ) { + // Notify the parent that a new instance had been started; + QByteArray initMsg; + QDataStream writeStream(&initMsg, QIODevice::WriteOnly); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + writeStream.setVersion(QDataStream::Qt_5_6); +#endif + + writeStream << blockServerName.toLatin1(); + writeStream << static_cast(connectionType); + writeStream << instanceNumber; + quint16 checksum = qChecksum(initMsg.constData(), static_cast(initMsg.length())); + writeStream << checksum; + + // The header indicates the message length that follows + QByteArray header; + QDataStream headerStream(&header, QIODevice::WriteOnly); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + headerStream.setVersion(QDataStream::Qt_5_6); +#endif + headerStream << static_cast ( initMsg.length() ); + + socket->write( header ); + socket->write( initMsg ); + socket->flush(); + socket->waitForBytesWritten( msecs ); + } +} + +quint16 SingleApplicationPrivate::blockChecksum() +{ + return qChecksum( + static_cast ( memory->data() ), + offsetof( InstancesInfo, checksum ) + ); +} + +qint64 SingleApplicationPrivate::primaryPid() +{ + qint64 pid; + + memory->lock(); + InstancesInfo* inst = static_cast( memory->data() ); + pid = inst->primaryPid; + memory->unlock(); + + return pid; +} + +/** + * @brief Executed when a connection has been made to the LocalServer + */ +void SingleApplicationPrivate::slotConnectionEstablished() +{ + QLocalSocket *nextConnSocket = server->nextPendingConnection(); + connectionMap.insert(nextConnSocket, ConnectionInfo()); + + QObject::connect(nextConnSocket, &QLocalSocket::aboutToClose, + [nextConnSocket, this]() { + auto &info = connectionMap[nextConnSocket]; + Q_EMIT this->slotClientConnectionClosed( nextConnSocket, info.instanceId ); + } + ); + + QObject::connect(nextConnSocket, &QLocalSocket::disconnected, + [nextConnSocket, this](){ + connectionMap.remove(nextConnSocket); + nextConnSocket->deleteLater(); + } + ); + + QObject::connect(nextConnSocket, &QLocalSocket::readyRead, + [nextConnSocket, this]() { + auto &info = connectionMap[nextConnSocket]; + switch(info.stage) { + case StageHeader: + readInitMessageHeader(nextConnSocket); + break; + case StageBody: + readInitMessageBody(nextConnSocket); + break; + case StageConnected: + Q_EMIT this->slotDataAvailable( nextConnSocket, info.instanceId ); + break; + default: + break; + }; + } + ); +} + +void SingleApplicationPrivate::readInitMessageHeader( QLocalSocket *sock ) +{ + if (!connectionMap.contains( sock )) { + return; + } + + if( sock->bytesAvailable() < ( qint64 )sizeof( quint64 ) ) { + return; + } + + QDataStream headerStream( sock ); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + headerStream.setVersion( QDataStream::Qt_5_6 ); +#endif + + // Read the header to know the message length + quint64 msgLen = 0; + headerStream >> msgLen; + ConnectionInfo &info = connectionMap[sock]; + info.stage = StageBody; + info.msgLen = msgLen; + + if ( sock->bytesAvailable() >= (qint64) msgLen ) { + readInitMessageBody( sock ); + } +} + +void SingleApplicationPrivate::readInitMessageBody( QLocalSocket *sock ) +{ + Q_Q(SingleApplication); + + if (!connectionMap.contains( sock )) { + return; + } + + ConnectionInfo &info = connectionMap[sock]; + if( sock->bytesAvailable() < ( qint64 )info.msgLen ) { + return; + } + + // Read the message body + QByteArray msgBytes = sock->read(info.msgLen); + QDataStream readStream(msgBytes); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + readStream.setVersion( QDataStream::Qt_5_6 ); +#endif + + // server name + QByteArray latin1Name; + readStream >> latin1Name; + + // connection type + ConnectionType connectionType = InvalidConnection; + quint8 connTypeVal = InvalidConnection; + readStream >> connTypeVal; + connectionType = static_cast ( connTypeVal ); + + // instance id + quint32 instanceId = 0; + readStream >> instanceId; + + // checksum + quint16 msgChecksum = 0; + readStream >> msgChecksum; + + const quint16 actualChecksum = qChecksum( msgBytes.constData(), static_cast( msgBytes.length() - sizeof( quint16 ) ) ); + + bool isValid = readStream.status() == QDataStream::Ok && + QLatin1String(latin1Name) == blockServerName && + msgChecksum == actualChecksum; + + if( !isValid ) { + sock->close(); + return; + } + + info.instanceId = instanceId; + info.stage = StageConnected; + + if( connectionType == NewInstance || + ( connectionType == SecondaryInstance && + options & SingleApplication::Mode::SecondaryNotification ) ) + { + Q_EMIT q->instanceStarted(); + } + + if (sock->bytesAvailable() > 0) { + Q_EMIT this->slotDataAvailable( sock, instanceId ); + } +} + +void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quint32 instanceId ) +{ + Q_Q(SingleApplication); + Q_EMIT q->receivedMessage( instanceId, dataSocket->readAll() ); +} + +void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId ) +{ + if( closedSocket->bytesAvailable() > 0 ) + Q_EMIT slotDataAvailable( closedSocket, instanceId ); +} diff --git a/product/src/tools/debug_tool_v2/SingleApplication_p.h b/product/src/tools/debug_tool_v2/SingleApplication_p.h new file mode 100644 index 00000000..c88a4d6d --- /dev/null +++ b/product/src/tools/debug_tool_v2/SingleApplication_p.h @@ -0,0 +1,99 @@ +// The MIT License (MIT) +// +// Copyright (c) Itay Grudev 2015 - 2016 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// +// W A R N I N G !!! +// ----------------- +// +// This file is not part of the SingleApplication API. It is used purely as an +// implementation detail. This header file may change from version to +// version without notice, or may even be removed. +// + +#ifndef SINGLEAPPLICATION_P_H +#define SINGLEAPPLICATION_P_H + +#include +#include +#include +#include "SingleApplication.h" + +struct InstancesInfo { + bool primary; + quint32 secondary; + qint64 primaryPid; + quint16 checksum; +}; + +struct ConnectionInfo { + explicit ConnectionInfo() : + msgLen(0), instanceId(0), stage(0) {} + qint64 msgLen; + quint32 instanceId; + quint8 stage; +}; + +class SingleApplicationPrivate : public QObject { +Q_OBJECT +public: + enum ConnectionType : quint8 { + InvalidConnection = 0, + NewInstance = 1, + SecondaryInstance = 2, + Reconnect = 3 + }; + enum ConnectionStage : quint8 { + StageHeader = 0, + StageBody = 1, + StageConnected = 2, + }; + Q_DECLARE_PUBLIC(SingleApplication) + + SingleApplicationPrivate( SingleApplication *q_ptr ); + ~SingleApplicationPrivate(); + + void genBlockServerName(); + void initializeMemoryBlock(); + void startPrimary(); + void startSecondary(); + void connectToPrimary(int msecs, ConnectionType connectionType ); + quint16 blockChecksum(); + qint64 primaryPid(); + void readInitMessageHeader(QLocalSocket *socket); + void readInitMessageBody(QLocalSocket *socket); + + SingleApplication *q_ptr; + QSharedMemory *memory; + QLocalSocket *socket; + QLocalServer *server; + quint32 instanceNumber; + QString blockServerName; + SingleApplication::Options options; + QMap connectionMap; + +public Q_SLOTS: + void slotConnectionEstablished(); + void slotDataAvailable( QLocalSocket*, quint32 ); + void slotClientConnectionClosed( QLocalSocket*, quint32 ); +}; + +#endif // SINGLEAPPLICATION_P_H diff --git a/product/src/tools/debug_tool_v2/aimondlg.cpp b/product/src/tools/debug_tool_v2/aimondlg.cpp new file mode 100644 index 00000000..ab527de7 --- /dev/null +++ b/product/src/tools/debug_tool_v2/aimondlg.cpp @@ -0,0 +1,805 @@ +/* + @file aimondlg.cpp + @brief 模拟量数据显示类。 + 发送命令通过触发信号来通知规约通信线程发送数据。 + 同样规约通信线程通过触发信号通知通道窗口参数显示类接收数据,收到的报文是 去掉报文头 eb 90 eb 90的数据。 + + @author thxiao + //2018-8-31 jacky 增加区间点刷新的非法字符判断 +*/ +#include "pub_widget/MessageBox.h" +#include +#include "aimondlg.h" +#include "ui_aimondlg.h" +#include +#include +#include +#include +#include "CActiveWindow.h" +#include +#include "pub_logger_api/logger.h" +#include +#include +#include "CDataMng.h" + +using namespace std; +using namespace iot_idl; + +AiMonDlg::AiMonDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::AiMonDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint; + setWindowFlags(flags); + // setFixedSize(this->width(),this->height());//固定窗口大小 + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + m_CurrentRtuRow = -1; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,150); + ui->PointTable->setColumnWidth(4,100); + ui->PointTable->setColumnWidth(5,100); + ui->PointTable->setColumnWidth(6,250); + ui->PointTable->setColumnWidth(7,80); + ui->PointTable->setColumnWidth(8,80); + ui->PointTable->setColumnWidth(9,120); + + m_StartIndex = -1; + m_EndIndex = -1; + + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&AiMonDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&AiMonDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); +} + +AiMonDlg::~AiMonDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipAi!= NULL) + free((m_pRtuInfo+i)->pAi); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + delete ui; +} + +void AiMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void AiMonDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + + QStandardItemModel *model =new QStandardItemModel(); + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + + ui->comboBox->setModel(model); +} + +void AiMonDlg::initSig() +{ + connect(this,&AiMonDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_aiRtuInfoResp,this,&AiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_aiParamResp,this,&AiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_aiValueResp,this,&AiMonDlg::slot_OnRecvResp); +} + +void AiMonDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadAiInfo(m_CurrentRtuNo); +} + +void AiMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void AiMonDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + changePointValueRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_AI_RtuInfo); + objMsg.set_body("MT_FESDBG_AI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void AiMonDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + //加载点描述 + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_AI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void AiMonDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_AI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_AI_Param: + onRecvAiParamResp(strBody); + break; + case MT_FESDBG_AI_Value: + onRecvAiValueResp(strBody); + break; + default: + break; + } +} + +void AiMonDlg::onRecvRtuInfoResp(const string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("AiMonDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SAiMonRtu *pAiRtu = m_pRtuInfo + nIdx; + pAiRtu->RtuNo = pRtuInfo->rtu_no(); + pAiRtu->Used = pRtuInfo->used(); + strncpy(pAiRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pAiRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void AiMonDlg::onRecvAiParamResp(const string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("AiMonDlg::onRecvAiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SAiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocAiParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pAi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getAiInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimAi *pAi = pRtu->pAi + pParam->pnt_no(); + pAi->param.PointNo = pParam->pnt_no(); + pAi->param.Used = pParam->used(); + memset(pAi->param.PointTagName,0,sizeof(pAi->param.PointTagName)); + strncpy(pAi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pAi->param.PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strAppTagName)); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,7,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + item->setTextAlignment(Qt::AlignCenter); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void AiMonDlg::onRecvAiValueResp(const string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("AiMonDlg::onRecvAiDataResp 反序列化失败"); + changePointValueRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + SAiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changePointValueRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_float_values()->size(); nIdx++) + { + FesDebugToolFloatPntValue *pParam = recvMsg.mutable_float_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimAi *pAi = pRtu->pAi + pParam->pnt_no(); + pAi->value.PointNo = pParam->pnt_no(); + pAi->value.Value = pParam->value(); + pAi->value.Status = pParam->status(); + pAi->value.time = pParam->time(); + + updateData(pAi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void AiMonDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SAiMonRtu*)realloc(m_pRtuInfo,sizeof(SAiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SAiMonRtu*)malloc(sizeof(SAiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SAiMonRtu*)malloc(sizeof(SAiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void AiMonDlg::mallocAiParam(SAiMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pAi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pAi = (SFesSimAi*)realloc(pRtu->pAi,sizeof(SFesSimAi)*pRtu->MaxPoints); + if (pRtu->pAi != NULL) + { + memset(pRtu->pAi, 0, sizeof(SFesSimAi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pAi = (SFesSimAi*)malloc(sizeof(SFesSimAi)*pRtu->MaxPoints); + if(pRtu->pAi != NULL) + { + memset(pRtu->pAi,0,sizeof(SFesSimAi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pAi==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pAi = (SFesSimAi*)malloc(sizeof(SFesSimAi)*pRtu->MaxPoints); + if (pRtu->pAi != NULL) + { + memset(pRtu->pAi, 0, sizeof(SFesSimAi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void AiMonDlg::sendAiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_AI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void AiMonDlg::OnRtuCellClick(int row, int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayAiParam(m_CurrentRtuNo); + } +} + +SAiMonRtu* AiMonDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i = 0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void AiMonDlg::DisplayAiParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + + initCombox(); + OnPointInfoRefresh(); +} + +void AiMonDlg::updateData(const SFesSimAiData &aiData) +{ + auto iter = m_dotColumnMap.find(aiData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(aiData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = aiData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + QTableWidgetItem *itemValue = new QTableWidgetItem(QString::number(aiData.Value)); + itemValue->setTextAlignment(Qt::AlignCenter); + + QTableWidgetItem *itemStatus = new QTableWidgetItem(getFesPointStatus(aiData.Status)); + itemStatus->setTextAlignment(Qt::AlignCenter); + if(aiData.Status != CN_FesValueUpdate) itemStatus->setTextColor(Qt::red) ; + + ui->PointTable->setItem(iter.value(),4,itemValue); + ui->PointTable->setItem(iter.value(),5,itemStatus); + ui->PointTable->setItem(iter.value(),9,new QTableWidgetItem(tStr)); +} + +void AiMonDlg::changePointValueRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +bool AiMonDlg::initPointBrushData() +{ + QString devTag = ui->comboBox->currentData(Qt::UserRole+1).toString(); + + if(devTag == "") + { + return false; + }else if(devTag == "ALL") + { + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + m_RefreshMode = 1; //section + + const RtuMaxAndMinPointNo &rtuMaxMinNo = CDataMng::instance()->getAiMaxMinNoRef(); + auto it = rtuMaxMinNo.find(m_CurrentRtuNo); + if(it == rtuMaxMinNo.end()) + { + LOGERROR("未找到rtu:[%d],刷新所有数据!",m_CurrentRtuNo); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + const MaxAndMinPointNo &devMap = it.value(); + auto itor = devMap.find(devTag); + if(itor == devMap.end()) + { + LOGERROR("未找到dev:[%s],刷新所有数据!",devTag.toStdString().c_str()); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + SFESDEVMAXANDMINPOINTNO maxminNo = itor.value(); + m_StartIndex = maxminNo.minPointNo; + m_EndIndex = maxminNo.maxPointNo; + } + } + } + LOGTRACE("刷新设备[%s]的数据!",devTag.toStdString().c_str()); + return true; +} + +void AiMonDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAiValueReqMsg(); + } +} + +void AiMonDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAiValueReqMsg(); + } + else + { + changePointValueRefreshBtnToStop(); + } +} + +void AiMonDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void AiMonDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void AiMonDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changePointValueRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + + sendAiValueReqMsg(); +} diff --git a/product/src/tools/debug_tool_v2/aimondlg.h b/product/src/tools/debug_tool_v2/aimondlg.h new file mode 100644 index 00000000..ad07684f --- /dev/null +++ b/product/src/tools/debug_tool_v2/aimondlg.h @@ -0,0 +1,96 @@ +#ifndef AIMONDLG_H +#define AIMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +class QTableWidgetItem; + +namespace Ui { +class AiMonDlg; +} + +class AiMonDlg : public QDialog +{ + Q_OBJECT + +public: + explicit AiMonDlg(int windowId,QWidget *parent); + ~AiMonDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvAiParamResp(const std::string &strBody); + void onRecvAiValueResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocAiParam(SAiMonRtu *pRtu,const int nSize); + void sendAiValueReqMsg(); + +private: + Ui::AiMonDlg *ui; + QTimeZone m_tz; + SAiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayAiParam(int RtuNo); + + void updateData(const SFesSimAiData & aiData); + + void changePointValueRefreshBtnToStop(); + + bool initPointBrushData(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SAiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // AIMONDLG_H diff --git a/product/src/tools/debug_tool_v2/aimondlg.ui b/product/src/tools/debug_tool_v2/aimondlg.ui new file mode 100644 index 00000000..c062ec05 --- /dev/null +++ b/product/src/tools/debug_tool_v2/aimondlg.ui @@ -0,0 +1,292 @@ + + + AiMonDlg + + + + 0 + 0 + 804 + 417 + + + + Dialog + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 1 + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + AlignLeading|AlignVCenter + + + + + 使用标志 + + + AlignLeading|AlignVCenter + + + + + RTU名称 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 点值 + + + + + 点状态 + + + + + 后台标签 + + + + + 远动号 + + + + + 使用标志 + + + + + 时间 + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/chaneventdlg.cpp b/product/src/tools/debug_tool_v2/chaneventdlg.cpp new file mode 100644 index 00000000..7e076299 --- /dev/null +++ b/product/src/tools/debug_tool_v2/chaneventdlg.cpp @@ -0,0 +1,238 @@ +#include "pub_widget/MessageBox.h" +#include +#include "chaneventdlg.h" +#include "ui_chaneventdlg.h" +#include "CActiveWindow.h" +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +ChanEventDlg::ChanEventDlg(int windowId,QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::ChanEventDlg) +{ + ui->setupUi(this); + + m_tz=QTimeZone::systemTimeZone(); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + m_ConnectFlag=CN_CommDisconnect; + m_RefreshFlag = 0; + m_TotalCounts = 0; + + ui->EventTable->setColumnWidth(0,180);//time + ui->EventTable->setColumnWidth(1,250);//tagname + + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RefreshButton,SIGNAL(clicked()),this,SLOT(OnRefreshData())); + connect(ui->ClearButton,SIGNAL(clicked()),this,SLOT(OnClearData())); + initSig(); +} + +ChanEventDlg::~ChanEventDlg() +{ + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + + delete ui; +} + +void ChanEventDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changeRefreshBtnToStop(); + return; + } + + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + + sendChanEventReqMsg(); +} + +void ChanEventDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void ChanEventDlg::initSig() +{ + connect(CDataMng::instance(),&CDataMng::signal_chanEventResp,this,&ChanEventDlg::slot_OnRecvResp); + connect(this,&ChanEventDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); +} + +void ChanEventDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void ChanEventDlg::OnRefreshData() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->RefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + sendChanEventReqMsg(); + } + else + { + changeRefreshBtnToStop(); + } +} + +void ChanEventDlg::OnStartRefreshData() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->RefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + sendChanEventReqMsg(); + } +} + +void ChanEventDlg::OnClearData() +{ + ui->EventTable->clearContents(); + ui->EventTable->setRowCount(0); + m_TotalCounts = 0; + ui->TotalCount->setText(QString::number(m_TotalCounts)); +} + +void ChanEventDlg::slot_OnRecvResp(int nMsgType, const std::string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_Event_Channel: + onRecvChanEventResp(strBody); + break; + default: + break; + } +} + +void ChanEventDlg::onRecvChanEventResp(const std::string &strBody) +{ + FesDebugToolChanEventRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("ChanEventDlg::onRecvChanEventResp 反序列化失败"); + return; + } + + int row = ui->EventTable->rowCount(); + if(recvMsg.over_flow() == 1) + { + //显示溢出提示 + ui->EventTable->insertRow(row); + ui->EventTable->setItem(row,0,new QTableWidgetItem(tr("缓冲区溢出"))); + row++; + } + + for(int i = 0; i < recvMsg.mutable_event()->size();i++) + { + if(row >= CN_FesSimChanEventMaxBufSize) + { + ui->EventTable->setRowCount(0); + ui->EventTable->clearContents(); + row = 0; + } + ui->EventTable->insertRow(row); + + FesDebugToolChanEvent *pEvent = recvMsg.mutable_event(i); + + QDateTime dt = QDateTime::fromSecsSinceEpoch(pEvent->time()/1000); + //dt = QDateTime::fromSecsSinceEpoch(event.time/1000,m_tz); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + ui->EventTable->setItem(row,0,new QTableWidgetItem(tStr)); + ui->EventTable->setItem(row,1,new QTableWidgetItem(QString(pEvent->tag_name().c_str()))); + switch (pEvent->status()) + { + case CN_FesChanNotUsed: + ui->EventTable->setItem(row,2,new QTableWidgetItem(tr("通道未使用"))); + break; + case CN_FesChanCheck: + ui->EventTable->setItem(row,2,new QTableWidgetItem(tr("通道检测"))); + break; + case CN_FesChanRun: + ui->EventTable->setItem(row,2,new QTableWidgetItem(tr("通道运行"))); + break; + case CN_FesChanStop: + ui->EventTable->setItem(row,2,new QTableWidgetItem(tr("通道停止"))); + break; + case CN_FesChanErrRate: + ui->EventTable->setItem(row,2,new QTableWidgetItem(tr("通道错误率高"))); + break; + default: + break; + } + + ui->EventTable->setItem(row,3,new QTableWidgetItem(QString::number(pEvent->err_rate()))); + m_TotalCounts++; + } + + ui->TotalCount->setText(QString::number(m_TotalCounts)); +} + +void ChanEventDlg::sendChanEventReqMsg() +{ + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_Event_Channel); + objMsg.set_body("MT_FESDBG_Event_Channel"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void ChanEventDlg::changeRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->RefreshButton->setText(tr("数据刷新")); +} diff --git a/product/src/tools/debug_tool_v2/chaneventdlg.h b/product/src/tools/debug_tool_v2/chaneventdlg.h new file mode 100644 index 00000000..2accdfee --- /dev/null +++ b/product/src/tools/debug_tool_v2/chaneventdlg.h @@ -0,0 +1,61 @@ +#ifndef CHANEVENTDLG_H +#define CHANEVENTDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "CSystemResources.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class ChanEventDlg; +} + +class ChanEventDlg : public QDialog +{ + Q_OBJECT + +public: + explicit ChanEventDlg(int windowId,QWidget *parent); + ~ChanEventDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); +protected: + void keyPressEvent(QKeyEvent *event); + +public slots: + void OnRefeshTimer(); + void OnRefreshData(); + void OnStartRefreshData(); + void OnClearData(); + + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvChanEventResp(const std::string &strBody); + void sendChanEventReqMsg(); + +private: + void changeRefreshBtnToStop(); +private: + Ui::ChanEventDlg *ui; + QTimeZone m_tz; + QTimer *m_RefreshTimer; + + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_TotalCounts; + int m_nWindowId;// 用来判断是否激活窗口 +}; + +#endif // CHANEVENTDLG_H diff --git a/product/src/tools/debug_tool_v2/chaneventdlg.ui b/product/src/tools/debug_tool_v2/chaneventdlg.ui new file mode 100644 index 00000000..4e96a9db --- /dev/null +++ b/product/src/tools/debug_tool_v2/chaneventdlg.ui @@ -0,0 +1,175 @@ + + + ChanEventDlg + + + + 0 + 0 + 573 + 352 + + + + 通道事件 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 清除事件 + + + + + + + Qt::Horizontal + + + + 256 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 事件总数: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 时间 + + + + + 通道标签名 + + + + + 通道状态 + + + + + 错误率 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/chanmondlg.cpp b/product/src/tools/debug_tool_v2/chanmondlg.cpp new file mode 100644 index 00000000..510f13cd --- /dev/null +++ b/product/src/tools/debug_tool_v2/chanmondlg.cpp @@ -0,0 +1,615 @@ +/* +@history +2020-04-30 thxiao 数据报文保存在“/log/channel"目录,通道报文采用主动刷新的方式,格式为"Chan1_2020-04-30_1839321.txt". + 每个文件超过1000000条记录会自动产生新文件。 + +*/ + +#include "pub_widget/MessageBox.h" +#include +#include +#include +#include "chanmondlg.h" +#include "ui_chanmondlg.h" +#include +#include +#include +#include +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +//#define FESSIM_K_LOG_FILE "FesSimLog.txt" +#define FESSIM_K_MAX_SHOW_LINES 50000 +#define FESSIM_K_MAX_SAVE_FILE_LINES 1000000 + +#define CHAN_AND_DESC_SEPARATOR "#" + +ChanMonDlg::ChanMonDlg(int windowId, QWidget *parent) : + CustomUiDialog(parent), + ui(new Ui::ChanMonDlg), + m_nWindowId(windowId) +{ + int i; + + setWindowTitle(tr("通道报文监视工具")); + ui->setupUi(this); + m_ConnectFlag=CN_CommDisconnect; + m_RefreshFlag=0; //刷新标志 1:正再刷新 0:停止刷新 + ui->RefreshButton->setText(tr("刷新")); + m_DispRecv=true; + m_DispSend=true; + m_AutoSave=false; + m_SelectDisp[0] = false; + m_SelectDisp[1] = false; + m_SelectDisp[2] = false; + m_SelectDisp[3] = false; + ui->DispRecv->setChecked(m_DispRecv); + ui->DispSend->setChecked(m_DispSend); + ui->AutoSave->setChecked(m_AutoSave); + ui->SelectDisp1->setChecked(m_SelectDisp[0]); + ui->SelectDisp2->setChecked(m_SelectDisp[1]); + ui->SelectDisp3->setChecked(m_SelectDisp[2]); + ui->SelectDisp4->setChecked(m_SelectDisp[3]); + ui->ChanNo->setView(new QListView()); + for(i=0;iChanNo->addItem(QString::number(i)); + } + + //m_ListModel = new QStringListModel(this); + //m_ListModel->setStringList(m_DataList); + //ui->DispListView->setModel(m_ListModel); + + + //m_RefreshTimer = new QTimer(this); + //if(m_RefreshTimer!=NULL) + // connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefreshTimer())); + + connect(ui->RefreshButton,SIGNAL(clicked()),this,SLOT(OnRefresh())); + connect(ui->ClearButton,SIGNAL(clicked()),this,SLOT(OnClearDisp())); + connect(ui->ClearStatisButton,SIGNAL(clicked()),this,SLOT(OnClearStatis())); + connect(ui->ClearFileButton,SIGNAL(clicked()),this,SLOT(OnClearFile())); + connect(ui->DispRecv,SIGNAL(clicked()),this,SLOT(OnDispRecv())); + connect(ui->DispSend,SIGNAL(clicked()),this,SLOT(OnDispSend())); + connect(ui->AutoSave,SIGNAL(clicked()),this,SLOT(OnAutoSave())); + + ui->RefreshButton->setFocus(); + + m_monFile = ""; + m_openFlag = false; + m_saveLine = 0; + m_saveChanNo = -1; + + //创健目录 + QString curPath = QDir::currentPath(); + QDir dir(curPath); + dir.cdUp(); + curPath = dir.path(); + dir.cdUp(); + QString filepath = dir.path()+"/log/channel"; + if (!dir.exists(filepath)) + dir.mkdir(filepath); + + ui->textEdit->setReadOnly(true); + + CustomUiDialog::setAutoLayout(true); +} + +ChanMonDlg::~ChanMonDlg() +{ + //if(m_RefreshTimer != NULL) + // delete m_RefreshTimer; + + if (m_openFlag) + m_file.close(); + m_saveLine = 0; + delete ui; +} + +void ChanMonDlg::closeEvent(QCloseEvent *event) +{ + sendChanMonCmdMsg(m_ChanNo,MT_FESDBG_Mon_ChanStop); + + Sleep(200); + + emit closed(); + QDialog::closeEvent(event); +} + +void ChanMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; + + if(m_ConnectFlag == CN_CommDisconnect) + { + m_RefreshFlag=0; //刷新标志 1:正再刷新 0:停止刷新 + ui->RefreshButton->setText(tr("刷新")); + //if(m_RefreshTimer != NULL) + // m_RefreshTimer->stop(); + } + else + { + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_ChanParam); + objMsg.set_body("MT_FESDBG_ChanParam"); + + emit signal_sendMsg(objMsg.SerializeAsString()); + } +} + +void ChanMonDlg::OnNetConnect() +{ + m_ConnectFlag = CN_CommConnect; +} + +void ChanMonDlg::OnNetDisConnect() +{ + m_ConnectFlag = CN_CommDisconnect; + + m_RefreshFlag=0; //刷新标志 1:正再刷新 0:停止刷新 + ui->RefreshButton->setText(tr("刷新")); + //if(m_RefreshTimer != NULL) + // m_RefreshTimer->stop(); +} + +void ChanMonDlg::OnRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + ui->RefreshButton->setText(tr("数据刷新")); + return; + } + + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + QString str=ui->ChanNo->currentText(); + str = str.left(str.indexOf(CHAN_AND_DESC_SEPARATOR)); + bool ok; + m_ChanNo = str.toInt(&ok,10); + + if(m_RefreshFlag == 0) + { + //if(m_RefreshTimer != NULL) + // m_RefreshTimer->start(300); + + //m_RefreshFlag = 1; + //ui->RefreshButton->setText(tr("停止刷新")); + m_DispRecv = ui->DispRecv->isChecked(); + m_DispSend = ui->DispSend->isChecked(); + m_AutoSave = ui->AutoSave->isChecked(); + m_SelectDisp[0] = ui->SelectDisp1->isChecked(); + m_SelectDisp[1] = ui->SelectDisp2->isChecked(); + m_SelectDisp[2] = ui->SelectDisp3->isChecked(); + m_SelectDisp[3] = ui->SelectDisp4->isChecked(); + + m_Pos[0] = ui->Pos1->text().toInt(); + m_Pos[1] = ui->Pos2->text().toInt(); + m_Pos[2] = ui->Pos3->text().toInt(); + m_Pos[3] = ui->Pos4->text().toInt(); + m_Value[0] = ui->Value1->text().toInt(); + m_Value[1] = ui->Value2->text().toInt(); + m_Value[2] = ui->Value3->text().toInt(); + m_Value[3] = ui->Value4->text().toInt(); + + sendChanMonCmdMsg(m_ChanNo,MT_FESDBG_Mon_ChanStart); + } + else + { + //if(m_RefreshTimer != NULL) + // m_RefreshTimer->stop(); + //m_RefreshFlag = 0; + //ui->RefreshButton->setText(tr("刷新")); + + sendChanMonCmdMsg(m_ChanNo,MT_FESDBG_Mon_ChanStop); + } +} + +void ChanMonDlg::onRecvChanMonStopResp(const std::string &strBody) +{ + m_RefreshFlag = 0; + ui->RefreshButton->setText(tr("刷新")); + m_monFile = ""; + if (m_openFlag) + { + m_file.close(); + m_openFlag = 0; + } + m_saveLine = 0; +} + +void ChanMonDlg::ShowData(const QString &DispStr,int openFlag, QFile &file) +{ +// int row; +// QModelIndex QIndex; +// QString tempStr; + +// row = m_ListModel->rowCount(); +// m_ListModel->insertRows(row,1); +// QIndex = m_ListModel->index(row); +// m_ListModel->setData(QIndex,DispStr); +// m_DataLine = row+1; + +// if(m_DataLine>FESSIM_K_MAX_SHOW_LINES) +// { +// QTextEdit it; +// it.append(11); +// row=m_ListModel->rowCount(); +// m_ListModel->removeRows(0,row); +// m_DataLine = 0; +// } + + +// //刷新滚动条。 +// if(m_RefreshLine>30) +// { +// m_RefreshLine = 0; +// ui->DispListView->scrollTo(QIndex); +// } +// else +// m_RefreshLine++; + + ui->textEdit->setTextColor(m_color); + ui->textEdit->append(DispStr); + m_DataLine++; + if(m_DataLine>FESSIM_K_MAX_SHOW_LINES) + { + ui->textEdit->clear(); + m_DataLine = 0; + } +} + +void ChanMonDlg::OnClearDisp() +{ +// int curRow; + +// curRow=m_ListModel->rowCount(); +// m_ListModel->removeRows(0,curRow); + ui->textEdit->clear(); + m_DataLine = 0; +} + +void ChanMonDlg::OnClearStatis() +{ + sendChanMonCmdMsg(m_ChanNo,MT_FESDBG_Mon_ChanClear); +} + +void ChanMonDlg::OnClearFile() +{ + if(ui->AutoSave->isChecked()) + { + N_MessageBox::warning(this,tr("告警"),tr("请先取消自动保存!")); + return ; + } + QString curPath = QDir::currentPath(); + QDir dir(curPath); + dir.cdUp(); + curPath = dir.path(); + dir.cdUp(); + dir.cd("log"); + dir.cd("channel"); + if(dir.isEmpty()) + { + return ; + } + + QDirIterator iter(dir.path(),QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot,QDirIterator::NoIteratorFlags); + while (iter.hasNext()) + { + if(!dir.remove(iter.next())) + { + QDir(iter.filePath()).removeRecursively();//删除目录本身以及它下属的所有文件及目录 + } + } +} + +void ChanMonDlg::OnAutoSave() +{ + m_AutoSave = ui->AutoSave->isChecked(); + if (m_AutoSave == false) + { + m_monFile = ""; + if (m_openFlag) + { + m_file.close(); + m_openFlag = false; + } + m_saveLine = 0; + } +} + +void ChanMonDlg::OnDispSend() +{ + m_DispSend = ui->DispSend->isChecked(); +} + +void ChanMonDlg::OnDispRecv() +{ + m_DispRecv = ui->DispRecv->isChecked(); +} + +void ChanMonDlg::SaveData(const QString &DispStr) +{ + QString tempStr; + + if(m_openFlag) + { + tempStr=DispStr; + tempStr.append("\n") ; + m_file.write(tempStr.toLocal8Bit().data(),tempStr.size()); + m_saveLine++; + + if (m_saveLine > FESSIM_K_MAX_SAVE_FILE_LINES) + { + //关闭当前文件,再打开新文件 + m_file.close(); + m_monFile = ""; + m_saveLine = 0; + //产生新的文件 + QDateTime curTime = QDateTime::currentDateTime(); + QString curTimeStr = curTime.toString("yyyy-MM-dd_hhmmzzz"); + QString chanStr = QString("Chan%1_").arg(QString::number(m_saveChanNo)); + QString curPath = QDir::currentPath(); + QDir dir(curPath); + dir.cdUp(); + curPath = dir.path(); + dir.cdUp(); + m_monFile = dir.path() + "/log/channel/" + chanStr + curTimeStr + ".log"; + + m_file.setFileName(m_monFile); + m_openFlag = m_file.open(QIODevice::Append | QIODevice::WriteOnly); + } + + } +} + +void ChanMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event ->key()) + { + case Qt::Key_Escape: + break; + default: + QDialog::keyPressEvent(event); + } +} + +void ChanMonDlg::slot_OnRecvResp(int nMsgType, const std::string &strBody) +{ + switch (nMsgType) + { + case MT_FESDBG_ChanParam: + onRecvChanParamResp(strBody); + break; + case MT_FESDBG_Mon_ChanStart: + onRecvChanMonStartResp(strBody); + break; + case MT_FESDBG_Mon_ChanStop: + onRecvChanMonStopResp(strBody); + break; + case MT_FESDBG_Mon_ChanClear: + onRecvChanMonClearResp(strBody); + break; + case MT_FESDBG_Mon_ChanInfo: + onRecvChanMonInfo(strBody); + break; + default: + break; + } +} + +void ChanMonDlg::sendChanMonCmdMsg(const int &nChanNo,const enFesDebugMsgType &eMsgType) +{ + FesDebugToolChanMonCmdReqMsg reqMsg; + reqMsg.set_chan_no(nChanNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(eMsgType); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void ChanMonDlg::onRecvChanParamResp(const string &strBody) +{ + FesDebugToolChanParamRepMsg repMsg; + if(!repMsg.ParseFromString(strBody)) + { + LOGERROR("ChanParamDlg:反序列化失败"); + return; + } + + ui->ChanNo->clear(); + + int nCount = repMsg.chan_param().size(); + for(int nRow = 0; nRow < nCount; nRow++) + { + FesDebugToolChanParam* pChanParam = repMsg.mutable_chan_param(nRow); + if(pChanParam->used() == 0) + { + continue; + } + + QString strDesc = QString::number(pChanParam->chan_no()) + CHAN_AND_DESC_SEPARATOR + QString(pChanParam->chan_name().c_str()); + ui->ChanNo->addItem(strDesc); + } +} + +void ChanMonDlg::onRecvChanMonStartResp(const std::string &strBody) +{ + Q_UNUSED(strBody); + if (!m_RefreshFlag) + { + m_RefreshFlag = 1; + ui->RefreshButton->setText(tr("停止刷新")); + } +} + +void ChanMonDlg::onRecvChanMonInfo(const string &strBody) +{ + FesDebugToolChanMonInfoMsg infoMsg; + if(!infoMsg.ParseFromString(strBody)) + { + LOGERROR("ChanMonDlg:onRecvChanMonInfo 反序列化失败"); + return; + } + + QString strData; + char showStr[1024]; + + if(m_AutoSave) + { + m_saveChanNo = infoMsg.chan_no(); + if (m_monFile.length() <= 0) + { + //产生新的文件 + QDateTime curTime = QDateTime::currentDateTime(); + QString curTimeStr = curTime.toString("yyyy-MM-dd_hhmmzzz"); + QString chanStr = QString("Chan%1_").arg(QString::number(m_saveChanNo)); + QString curPath = QDir::currentPath(); + QDir dir(curPath); + dir.cdUp(); + curPath = dir.path(); + dir.cdUp(); + m_monFile = dir.path()+ "/log/channel/" + chanStr + curTimeStr + ".log"; + } + } + + if (m_monFile.length() > 0) + { + m_file.setFileName(m_monFile); + m_openFlag = m_file.open(QIODevice::Append | QIODevice::WriteOnly); + } + + if(infoMsg.over_flow() == 1) + { + m_color = QColor(255,0,0); + strData = "Display data overflow!"; + SaveData(strData); + ShowData(strData, m_openFlag, m_file); + } + + for(int nFrameIndex = 0; nFrameIndex < infoMsg.mutable_frame()->size();nFrameIndex++) + { + FesDebugToolChanMonFrame *pFrame = infoMsg.mutable_frame(nFrameIndex); + if((m_DispRecv==false)&&(pFrame->frame_type() == CN_SFesSimComFrameTypeRecv)) + { + continue; + } + + if((m_DispSend==false)&&(pFrame->frame_type() == CN_SFesSimComFrameTypeSend)) + { + continue; + } + + bool bFound = false; + bool bSelectFlag = false; + if(pFrame->data_type() == CN_SFesSimComDataType_Data)//报文数据 + { + for(int nAnalyzeIdx = 0;nAnalyzeIdx < CN_ChanMonAnalyzeNum; nAnalyzeIdx++) + { + if(!m_SelectDisp[nAnalyzeIdx]) + { + continue; + } + + bSelectFlag = true; + size_t posIdx = m_Pos[nAnalyzeIdx]; + if(posIdx < pFrame->data().size() && static_cast(pFrame->data()[posIdx]) == m_Value[nAnalyzeIdx]) + { + bFound = true; + break; + } + } + + if(bSelectFlag && !bFound) + { + continue; + } + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(pFrame->time()/1000); + //dt = QDateTime::fromSecsSinceEpoch(frame.Time/1000,m_tz); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + tStr += QString(".%1").arg(QString::number(pFrame->time()%1000)); + + if(pFrame->frame_type() == CN_SFesSimComFrameTypeRecv) + { + strData = QString("Recv: %1").arg(tStr); + m_color = QColor(52,130,244); + } + else + { + strData = QString("Send: %1").arg(tStr); + m_color = QColor(14,209,69); + } + + SaveData(strData); + ShowData(strData, m_openFlag, m_file); + + if(pFrame->data_type() == CN_SFesSimComDataType_Data)//报文数据 + { + int cc = (pFrame->data().size()-1)/30+1; + for(int nLineIdx =0;nLineIdx < cc; nLineIdx++) + { + sprintf(&showStr[0]," "); + int index = 5; + int j = 0; + while(((nLineIdx*30+j)data().size())&&(j<30)) + { + sprintf(&showStr[index],"%02X ",static_cast(pFrame->data()[nLineIdx*30+j])); + index+=3; + j++; + } + showStr[index++] = 0; + strData = showStr; + SaveData(strData); + ShowData(strData, m_openFlag, m_file); + } + } + else + { + QString strData = QString(pFrame->data().c_str()); + SaveData(strData); + ShowData(strData, m_openFlag, m_file); + } + } + + if((m_AutoSave==true)&&(m_openFlag==true)) + { + m_file.close(); + m_openFlag = false; + } + + ui->RxNumEdit->setText(QString::number(infoMsg.rx_num())); + ui->TxNumEdit->setText(QString::number(infoMsg.tx_num())); + ui->ErrNumEdit->setText(QString::number(infoMsg.err_num())); +} + +void ChanMonDlg::onRecvChanMonClearResp(const std::string &strBody) +{ + FesDebugToolChanMonCmdRepMsg repMsg; + if(!repMsg.ParseFromString(strBody)) + { + LOGERROR("ChanMonDlg:onRecvChanMonClearResp 反序列化失败"); + return; + } + + ui->RxNumEdit->setText(QString::number(repMsg.rx_num())); + ui->TxNumEdit->setText(QString::number(repMsg.tx_num())); + ui->ErrNumEdit->setText(QString::number(repMsg.err_num())); +} diff --git a/product/src/tools/debug_tool_v2/chanmondlg.h b/product/src/tools/debug_tool_v2/chanmondlg.h new file mode 100644 index 00000000..9b25a61c --- /dev/null +++ b/product/src/tools/debug_tool_v2/chanmondlg.h @@ -0,0 +1,94 @@ +#ifndef CHANMONDLG_H +#define CHANMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "FesDebugTool.pb.h" + +const int CN_ChanMonAnalyzeNum = 4; + +namespace Ui { +class ChanMonDlg; +} + +class ChanMonDlg : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit ChanMonDlg(int windowId,QWidget *parent); + ~ChanMonDlg(); + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + +public slots: + void OnNetConnect(); + void OnNetDisConnect(); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +private slots: + void closeEvent(QCloseEvent *event); + void OnRefresh(); + void OnClearDisp(); + void OnClearStatis(); + void OnClearFile(); + void OnAutoSave(); + void OnDispSend(); + void OnDispRecv(); + void keyPressEvent(QKeyEvent *event) ; + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + void closed(); + +private: + void sendChanMonCmdMsg(const int &nChanNo,const iot_idl::enFesDebugMsgType &eMsgType); + void onRecvChanParamResp(const std::string &strBody); + void onRecvChanMonStartResp(const std::string &strBody); + void onRecvChanMonStopResp(const std::string &strBody); + void onRecvChanMonClearResp(const std::string &strBody); + void onRecvChanMonInfo(const std::string &strBody); + void ShowData(const QString &DispStr,int openFlag, QFile &file); + void SaveData(const QString &DispStr); + +private: + Ui::ChanMonDlg *ui; + // QTimer *m_RefreshTimer; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + bool m_DispRecv; + bool m_DispSend; + bool m_AutoSave; + bool m_SelectDisp[CN_ChanMonAnalyzeNum]; + int m_Pos[CN_ChanMonAnalyzeNum]; + int m_Value[CN_ChanMonAnalyzeNum]; +// int m_RxNum; +// int m_TxNum; +// int m_ErrNum; + int m_ChanNo; + + //QStringList m_DataList; + //QStringListModel *m_ListModel; + int m_DataLine; + int m_RefreshLine; + + int m_nWindowId; + + QColor m_color; + QString m_monFile; + bool m_openFlag; + QFile m_file; + int m_saveLine; + int m_saveChanNo; +}; + +#endif // CHANMONDLG_H diff --git a/product/src/tools/debug_tool_v2/chanmondlg.ui b/product/src/tools/debug_tool_v2/chanmondlg.ui new file mode 100644 index 00000000..9b754cfe --- /dev/null +++ b/product/src/tools/debug_tool_v2/chanmondlg.ui @@ -0,0 +1,634 @@ + + + ChanMonDlg + + + + 0 + 0 + 748 + 448 + + + + + 16777215 + 16777215 + + + + 通道监视 + + + + 9 + + + 9 + + + 9 + + + 9 + + + + + + 0 + 16777215 + + + + QAbstractItemView::NoEditTriggers + + + + + + + + + + + 200 + 0 + + + + + 200 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 通道号 + + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 发送帧数 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 接收帧数 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 错误帧数 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 显示接收 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 显示发送 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 自动保存 + + + + + + + + + 过滤显示 + + + Qt::AlignCenter + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 位置 + + + + + + + 值(0x) + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 1 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 2 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 3 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + 4 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + 清除显示 + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + 刷新 + + + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + 清除统计 + + + + + + + + 16777215 + 30 + + + + 清除文件 + + + + + + + + + Qt::Vertical + + + + 20 + 2 + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/chanparamdlg.cpp b/product/src/tools/debug_tool_v2/chanparamdlg.cpp new file mode 100644 index 00000000..6a15c6bc --- /dev/null +++ b/product/src/tools/debug_tool_v2/chanparamdlg.cpp @@ -0,0 +1,203 @@ +/* + @file ChanParamDlg.cpp + @brief 通道窗口参数显示类。 + 发送命令通过触发信号来通知规约通信线程发送数据。 + 同样规约通信线程通过触发信号通知通道窗口参数显示类接收数据,收到的报文是 去掉报文头 eb 90 eb 90的数据。 + @author thxiao +*/ +#include "pub_widget/MessageBox.h" +#include +#include "chanparamdlg.h" +#include "ui_chanparamdlg.h" +#include "FesDef.h" +#include "CDataMng.h" +#include "FesDebugTool.pb.h" +#include "pub_logger_api/logger.h" + +using namespace iot_public; +using namespace iot_idl; + +ChanParamDlg::ChanParamDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::ChanParamDlg) +{ + ui->setupUi(this); + + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + ui->ChanParamTable->setColumnWidth(14,130); + ui->ChanParamTable->setColumnWidth(15,80); + ui->ChanParamTable->setColumnWidth(16,130); + ui->ChanParamTable->setColumnWidth(17,80); + ui->ChanParamTable->setColumnWidth(18,130); + ui->ChanParamTable->setColumnWidth(19,80); + ui->ChanParamTable->setColumnWidth(20,130); + ui->ChanParamTable->setColumnWidth(21,80); + if(testAttribute(Qt::WA_DeleteOnClose)) + qDebug()<<" close is delete"; + + m_ConnectFlag = CN_CommDisconnect; + + connect(ui->RefeshButton,SIGNAL(clicked()),this,SLOT(OnRefresh())); + + m_chanInfoMap = CDataMng::instance()->getChanInfo(); + initSig(); +} + +ChanParamDlg::~ChanParamDlg() +{ + + delete ui; +} + +void ChanParamDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void ChanParamDlg::initSig() +{ + connect(CDataMng::instance(),&CDataMng::signal_chanParamResp,this,&ChanParamDlg::slot_OnRecvResp); + connect(this,&ChanParamDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); +} + +void ChanParamDlg::OnRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取通道状态数据。请连接FES系统!")); + return; + } + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_ChanParam); + objMsg.set_body("MT_FESDBG_ChanParam"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void ChanParamDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_ChanParam: + onRecvChanParamResp(strBody); + break; + default: + break; + } +} + +void ChanParamDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event ->key()) + { + case Qt::Key_Escape: + break; + default: + QDialog::keyPressEvent(event); + } +} + +void ChanParamDlg::onRecvChanParamResp(const string &strBody) +{ + ui->ChanParamTable->setRowCount(0); + ui->ChanParamTable->clearContents(); + + FesDebugToolChanParamRepMsg repMsg; + if(!repMsg.ParseFromString(strBody)) + { + LOGERROR("ChanParamDlg:onRecvChanParamResp 反序列化失败"); + return; + } + + int nCount = repMsg.chan_param().size(); + for(int nRow = 0; nRow < nCount; nRow++) + { + insertChanParamToTable(nRow,repMsg.mutable_chan_param(nRow)); + } +} + +void ChanParamDlg::insertChanParamToTable(const int nRow, FesDebugToolChanParam *pChanParam) +{ + ui->ChanParamTable->insertRow(nRow); + ui->ChanParamTable->setItem(nRow,0,new QTableWidgetItem(QString::number(pChanParam->chan_no()))); + ui->ChanParamTable->setItem(nRow,1,new QTableWidgetItem(QString(pChanParam->chan_name().c_str()))); + if(pChanParam->used() != 0) + { + ui->ChanParamTable->setItem(nRow,2,new QTableWidgetItem(tr("使用"))); + } + else + { + ui->ChanParamTable->setItem(nRow,2,new QTableWidgetItem(tr("未使用"))); + } + + switch(pChanParam->chan_status()) + { + case CN_FesChanNotUsed: + ui->ChanParamTable->setItem(nRow,3,new QTableWidgetItem(tr("未使用"))); + break; + case CN_FesChanCheck: + ui->ChanParamTable->setItem(nRow,3,new QTableWidgetItem(tr("通道检测"))); + break; + case CN_FesChanRun: + ui->ChanParamTable->setItem(nRow,3,new QTableWidgetItem(tr("通道运行"))); + break; + case CN_FesChanStop: + ui->ChanParamTable->setItem(nRow,3,new QTableWidgetItem(tr("通道停止"))); + break; + case CN_FesChanErrRate: + ui->ChanParamTable->setItem(nRow,3,new QTableWidgetItem(tr("接收帧错误率高"))); + break; + } + + switch(pChanParam->comm_type()) + { + case CN_FesTcpClient: + ui->ChanParamTable->setItem(nRow,4,new QTableWidgetItem(tr("TCP Client"))); + break; + case CN_FesTcpServer: + ui->ChanParamTable->setItem(nRow,4,new QTableWidgetItem(tr("TCP Server"))); + break; + case CN_FesUdpClient: + ui->ChanParamTable->setItem(nRow,4,new QTableWidgetItem(tr("UDP Client"))); + break; + case CN_FesUdpServer: + ui->ChanParamTable->setItem(nRow,4,new QTableWidgetItem(tr("UDP Server"))); + break; + case CN_FesSerialPort: + ui->ChanParamTable->setItem(nRow,4,new QTableWidgetItem(tr("Serial Port"))); + break; + default: + ui->ChanParamTable->setItem(nRow,4,new QTableWidgetItem(tr("Unknown Type"))); + break; + } + if(pChanParam->chan_mode() == CN_FesDoubleChanMode) + ui->ChanParamTable->setItem(nRow,5,new QTableWidgetItem(tr("双通道通信"))); + else + ui->ChanParamTable->setItem(nRow,5,new QTableWidgetItem(tr("单通道通信"))); + + ui->ChanParamTable->setItem(nRow,6,new QTableWidgetItem(QString::number(pChanParam->protocol_id()))); + ui->ChanParamTable->setItem(nRow,7,new QTableWidgetItem(QString::number(pChanParam->connect_wait_sec()))); + ui->ChanParamTable->setItem(nRow,8,new QTableWidgetItem(QString::number(pChanParam->connect_timeout()))); + ui->ChanParamTable->setItem(nRow,9,new QTableWidgetItem(QString::number(pChanParam->retry_times()))); + ui->ChanParamTable->setItem(nRow,10,new QTableWidgetItem(QString::number(pChanParam->recv_timeout()/1000))); + ui->ChanParamTable->setItem(nRow,11,new QTableWidgetItem(QString::number(pChanParam->resp_timeout()))); + ui->ChanParamTable->setItem(nRow,12,new QTableWidgetItem(QString::number(pChanParam->max_rx_size()))); + ui->ChanParamTable->setItem(nRow,13,new QTableWidgetItem(QString::number(pChanParam->max_tx_size()))); + ui->ChanParamTable->setItem(nRow,14,new QTableWidgetItem(QString::number(pChanParam->err_rate_limit()))); + for(int nRouteIdx = 0; nRouteIdx < CN_FesMaxNetRouteNum;nRouteIdx++) + { + + ui->ChanParamTable->setItem(nRow,15+nRouteIdx*2,new QTableWidgetItem(QString(pChanParam->net_route(nRouteIdx).desc().c_str()))); + ui->ChanParamTable->setItem(nRow,16+nRouteIdx*2,new QTableWidgetItem(QString::number(pChanParam->net_route(nRouteIdx).port_no()))); + } + ui->ChanParamTable->setItem(nRow,23,new QTableWidgetItem(QString::number(pChanParam->backup_chan_no(0)))); + ui->ChanParamTable->setItem(nRow,24,new QTableWidgetItem(QString::number(pChanParam->backup_chan_no(1)))); + ui->ChanParamTable->setItem(nRow,25,new QTableWidgetItem(QString::number(pChanParam->backup_chan_no(2)))); + ui->ChanParamTable->setItem(nRow,26,new QTableWidgetItem(QString::number(m_chanInfoMap.value(pChanParam->chan_no()).nLocalPort))); +} diff --git a/product/src/tools/debug_tool_v2/chanparamdlg.h b/product/src/tools/debug_tool_v2/chanparamdlg.h new file mode 100644 index 00000000..530ff0d8 --- /dev/null +++ b/product/src/tools/debug_tool_v2/chanparamdlg.h @@ -0,0 +1,45 @@ +#ifndef CHANPARAMDLG_H +#define CHANPARAMDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class ChanParamDlg; +} + +class ChanParamDlg : public QDialog +{ + Q_OBJECT + +public: + explicit ChanParamDlg(int windowId,QWidget *parent); + ~ChanParamDlg(); + int m_ConnectFlag; //连接成功标志 + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); +public slots: + void OnRefresh(); + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + void keyPressEvent(QKeyEvent *event) ; + +signals: + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvChanParamResp(const std::string &strBody); + void insertChanParamToTable(const int nRow,iot_idl::FesDebugToolChanParam *pChanParam); + +private: + Ui::ChanParamDlg *ui; + ChanInfoMap m_chanInfoMap; + int m_nWindowId;// 用来判断是否激活窗口 +}; + +#endif // CHANPARAMDLG_H diff --git a/product/src/tools/debug_tool_v2/chanparamdlg.ui b/product/src/tools/debug_tool_v2/chanparamdlg.ui new file mode 100644 index 00000000..f0e085ac --- /dev/null +++ b/product/src/tools/debug_tool_v2/chanparamdlg.ui @@ -0,0 +1,225 @@ + + + ChanParamDlg + + + + 0 + 0 + 574 + 293 + + + + 通道参数 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + Qt::ElideLeft + + + false + + + + 通道号 + + + + + 通道描述 + + + + + 使用标志 + + + + + 当前状态 + + + + + 通信方式 + + + + + 通道方式 + + + + + 规约类型 + + + + + 连接等待时间 + + + + + 链接超时 + + + + + 重连次数 + + + + + 接收超时 + + + + + 响应超时 + + + + + 接收缓存区长度 + + + + + 发送缓存区长度 + + + + + 帧错误标准 + + + + + IP1 + + + + + PortNo1 + + + + + IP2 + + + + + PortNo2 + + + + + IP1 + + + + + PortNo3 + + + + + IP4 + + + + + PortNo4 + + + + + 备用通道号1 + + + + + 备用通道号2 + + + + + 备用通道号3 + + + + + 本地端口号 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 刷新 + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/commTool/CCommTool.cpp b/product/src/tools/debug_tool_v2/commTool/CCommTool.cpp new file mode 100644 index 00000000..81ec13b9 --- /dev/null +++ b/product/src/tools/debug_tool_v2/commTool/CCommTool.cpp @@ -0,0 +1,63 @@ +#include "CCommTool.h" +#include "ui_CCommTool.h" + +#include +#include +#include +#include +#include "pub_utility_api/FileUtil.h" + +CCommTool::CCommTool(QWidget *parent) : + QWidget(parent), + ui(new Ui::CCommTool) +{ + ui->setupUi(this); + + initConn(); +} + +CCommTool::~CCommTool() +{ + delete ui; +} + +void CCommTool::initConn() +{ + connect(ui->mqttBtn , &QPushButton::clicked , this , &CCommTool::slotMqttDlg); + connect(ui->msgbusBtn , &QPushButton::clicked , this , &CCommTool::slotMsgBusDlg); +} + +void CCommTool::slotMqttDlg() +{ + const std::string strFileName = "mqtt_tool"; + std::string strPath = std::move( iot_public::CFileUtil::getPathOfBinFile(strFileName)); + if(strPath.empty()) + { + strPath = strFileName; + } + QProcess p; + if( !p.startDetached(strPath.c_str()) ) + { + qDebug() << "Error starting process:" << p.errorString(); + } +} + +void CCommTool::slotMsgBusDlg() +{ + const std::string strFileName = "net_msgbus_tool"; + std::string strPath = std::move( iot_public::CFileUtil::getPathOfBinFile(strFileName)); + if(strPath.empty()) + { + strPath = strFileName; + } + QProcess p; + if( !p.startDetached(strPath.c_str()) ) + { + qDebug() << "Error starting process:" << p.errorString(); + } +} + +void CCommTool::initView() +{ + +} diff --git a/product/src/tools/debug_tool_v2/commTool/CCommTool.h b/product/src/tools/debug_tool_v2/commTool/CCommTool.h new file mode 100644 index 00000000..90975c83 --- /dev/null +++ b/product/src/tools/debug_tool_v2/commTool/CCommTool.h @@ -0,0 +1,30 @@ +#ifndef CCOMMTOOL_H +#define CCOMMTOOL_H + +#include +namespace Ui { +class CCommTool; +} + +class CCommTool : public QWidget +{ + Q_OBJECT + +public: + explicit CCommTool(QWidget *parent = 0); + ~CCommTool(); + + void initConn(); + +public slots: + void slotMqttDlg(); + void slotMsgBusDlg(); + +private: + void initView(); + +private: + Ui::CCommTool *ui; +}; + +#endif // CCOMMTOOL_H diff --git a/product/src/tools/debug_tool_v2/commTool/CCommTool.ui b/product/src/tools/debug_tool_v2/commTool/CCommTool.ui new file mode 100644 index 00000000..775fef05 --- /dev/null +++ b/product/src/tools/debug_tool_v2/commTool/CCommTool.ui @@ -0,0 +1,154 @@ + + + CCommTool + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 9 + + + 0 + + + 0 + + + 0 + + + + + 通讯调试工具: + + + + + + + 6 + + + 6 + + + + + QFrame::HLine + + + QFrame::Raised + + + + + + + + + + 0 + + + 0 + + + 6 + + + 0 + + + 0 + + + + + MQTT工具 + + + + + + + 消息总线监控工具 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/debug_tool.ico b/product/src/tools/debug_tool_v2/debug_tool.ico new file mode 100644 index 0000000000000000000000000000000000000000..d9a231d4e4a9851b22f0d9c384e5be5e63914876 GIT binary patch literal 3198 zcmc&$F>KR76n#-FQHe@H0s&Ghu*3io10zTbVPjxmWa!XtATcm>U|^_;lV+?$M}`ax z3=9km9T=LKB2^*|0cD7{u9Z5ZQc=zO@ttu_m-ws-aP)I`|NejP-#`2Q0Tuq1mcf4? z&lZ8p0B%v1DEBC$m*)ZJE}lz4I zQHXIr#8a)8_DdQ^yVpdIa-!quH?bmP%7DJ@Jf8Rw>pAsf!6p7X(aH0@g-2R1bCkEc z0Tzh!#Ly>E19!xST#uEl*h`#8!Y_W}pUp9T!51I>2nOdz+D65j;-vg(e-@XrG5ki% z!)?uxZ}$USU~Hc?pS3OE%6vlXd<}3Zk8k#w1CRDQnNNOA(s$t^kKmZtwy}|i={!1c z(Z6TIwdrVka+Y<8zYW)>o5|yvL)zJJZMwh3Mcg)J*O2Kw%D*2D`=w%?!sPe-Lg{B? z=Xpxx(1JTuXGw>1d6~`azOFo8N6wUgxnE_ubbL_@FD-e>@?pcZ>E>amxuYT*8?LEi zO<6C(ahzW@vGthsa*^NrCr6wtR|WPRo{I~bLt4K3H|R4g@N>mC?e=~)Cszb~+eBUJ zT*edPy%|eBE|jseLoKm%GkO-@(f<%VOh+1_OkDCr{o$A6z7QTw(RLVzyCG2m7Mx*Z`lt# z_+1Zcv4{B3tHj4%bxI~TFu8?MvN=@aLsa4}uoeJ*H91Bt`Gsq!;S{wv!Sz&vdYp7O I;v`Ap-@$Ya8vp +#include "defcmddlg.h" +#include "ui_defcmddlg.h" +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +DefCmdDlg::DefCmdDlg(int windowId,QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::DefCmdDlg) +{ + ui->setupUi(this); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + + ui->RTUTable->setColumnWidth(0,80); + ui->RTUTable->setColumnWidth(1,80); + + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ControlButton,SIGNAL(clicked()),this,SLOT(OnControl())); + connect(ui->ClearButton,SIGNAL(clicked()),this,SLOT(OnClear())); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + initSig(); +} + +DefCmdDlg::~DefCmdDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipDo!= NULL) + free((m_pRtuInfo+i)->pDo); + } + free(m_pRtuInfo); + } + delete ui; +} + +void DefCmdDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void DefCmdDlg::initSig() +{ + connect(this,&DefCmdDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_simDefCmdRtuInfoResp,this,&DefCmdDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simDefCmdControlResp,this,&DefCmdDlg::slot_OnRecvResp); +} + +void DefCmdDlg::OnRTURefresh() +{ + unsigned char data[40]; + + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimDefCmd_RtuInfo); + objMsg.set_body("MT_FESDBG_SimDefCmd_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void DefCmdDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_SimDefCmd_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_SimDefCmd_Control: + onRecvControlResp(strBody); + break; + default: + break; + } +} + +void DefCmdDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("DefCmdDlg:onRecvRtuInfoResp 反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SDoMonRtu *pDoRtu = m_pRtuInfo + nIdx; + pDoRtu->RtuNo = pRtuInfo->rtu_no(); + pDoRtu->Used = pRtuInfo->used(); + strncpy(pDoRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pDoRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void DefCmdDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SDoMonRtu*)realloc(m_pRtuInfo,sizeof(SDoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SDoMonRtu*)malloc(sizeof(SDoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SDoMonRtu*)malloc(sizeof(SDoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void DefCmdDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_CurrentRtuRow == row) + { + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } +} + + +void DefCmdDlg::OnControl() +{ + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + + FesDebugToolSimDefCmdReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_dev_id(ui->DevIdEdit->text().toInt()); + + vector vecKey; + vector vecValue; + + switch (ui->CmdNum->value()) + { + case 6: + vecKey.push_back(ui->KeyWord6->text().toStdString()); + vecValue.push_back(ui->KeyValue6->text().toStdString()); + case 5: + vecKey.push_back(ui->KeyWord5->text().toStdString()); + vecValue.push_back(ui->KeyValue5->text().toStdString()); + case 4: + vecKey.push_back(ui->KeyWord4->text().toStdString()); + vecValue.push_back(ui->KeyValue4->text().toStdString()); + case 3: + vecKey.push_back(ui->KeyWord3->text().toStdString()); + vecValue.push_back(ui->KeyValue3->text().toStdString()); + case 2: + vecKey.push_back(ui->KeyWord2->text().toStdString()); + vecValue.push_back(ui->KeyValue2->text().toStdString()); + case 1: + vecKey.push_back(ui->KeyWord1->text().toStdString()); + vecValue.push_back(ui->KeyValue1->text().toStdString()); + default: + break; + } + + for(int i = vecKey.size() - 1; i >= 0; i--) + { + reqMsg.add_keys(vecKey[i]); + reqMsg.add_values(vecValue[i]); + } + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimDefCmd_Control); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void DefCmdDlg::onRecvControlResp(const std::string &strBody) +{ + FesDebugToolSimControlRepMsg repMsg; + if(!repMsg.ParseFromString(strBody)) + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行失败!原因:响应消息解析失败")); + return; + } + + if(repMsg.success()) + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行成功!")); + } + else + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行失败!原因:%1").arg(repMsg.err_msg().c_str())); + } +} + +void DefCmdDlg::StringToValue(char *data, int dataLen,unsigned char *retData,int *retDataLen) +{ + unsigned char tempData[1024]; + int len,tempLen,i,j; + unsigned char tempChar; + + //去掉末尾的回车、换行符 + i=0; + while(i=len) break; + if((data[i]>='0')&&(data[i]<='9')) + { + tempChar = 16*(data[i]-0x30); + i++; + if(i>=len) break; + } + else + if((data[i]>='A')&&(data[i]<='F')) + { + tempChar = 16*(data[i]-55); + i++; + if(i>=len) break; + } + else + if((data[i]>='a')&&(data[i]<='f')) + { + tempChar = 16*(data[i]-87); + i++; + if(i>=len) break; + } + + if((data[i]>='0')&&(data[i]<='9')) + { + tempChar = (data[i]-0x30); + retData[j] = tempChar; + j++; + i++; + if(i>=len) break; + } + else + if((data[i]>='A')&&(data[i]<='F')) + { + tempChar = (data[i]-55); + retData[j] = tempChar; + j++; + i++; + if(i>=len) break; + } + else + if((data[i]>='a')&&(data[i]<='f')) + { + tempChar = (data[i]-87); + retData[j] = tempChar; + j++; + i++; + if(i>=len) break; + } + } + *retDataLen = j; +} + +void DefCmdDlg::OnClear() +{ + ui->KeyWord1->clear(); + ui->KeyValue1->clear(); + ui->KeyWord2->clear(); + ui->KeyValue2->clear(); + ui->KeyWord3->clear(); + ui->KeyValue3->clear(); + ui->KeyWord4->clear(); + ui->KeyValue4->clear(); + ui->KeyWord5->clear(); + ui->KeyValue5->clear(); + ui->KeyWord6->clear(); + ui->KeyValue6->clear(); +} +void DefCmdDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event ->key()) + { + case Qt::Key_Escape: + break; + default: + QDialog::keyPressEvent(event); + } +} diff --git a/product/src/tools/debug_tool_v2/defcmddlg.h b/product/src/tools/debug_tool_v2/defcmddlg.h new file mode 100644 index 00000000..3b746bed --- /dev/null +++ b/product/src/tools/debug_tool_v2/defcmddlg.h @@ -0,0 +1,61 @@ +#ifndef DEFCMDDLG_H +#define DEFCMDDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class DefCmdDlg; +} + +class DefCmdDlg : public QDialog +{ + Q_OBJECT + +public: + explicit DefCmdDlg(int windowId,QWidget *parent); + ~DefCmdDlg(); + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); +public slots: + void OnRTURefresh(); + void OnRtuCellClick(int row,int column); + void OnControl(); + void OnClear(); + void keyPressEvent(QKeyEvent *event) ; + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +signals: + void SendCmdSig(int CmdCode,QByteArray Data,int DataLen); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvControlResp(const std::string &strBody); + void mallocRtuInfo(const int nSize); + +private: + Ui::DefCmdDlg *ui; + SDoMonRtu* GetRtuByRtuNo(int RtuNo); + void StringToValue(char *data, int dataLen,unsigned char *retData,int *retDataLen); + + int m_RtuNum; + SDoMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_nWindowId;// 用来判断是否激活窗口 +}; + +#endif // DEFCMDDLG_H diff --git a/product/src/tools/debug_tool_v2/defcmddlg.ui b/product/src/tools/debug_tool_v2/defcmddlg.ui new file mode 100644 index 00000000..d586a2f4 --- /dev/null +++ b/product/src/tools/debug_tool_v2/defcmddlg.ui @@ -0,0 +1,694 @@ + + + DefCmdDlg + + + + 0 + 0 + 682 + 383 + + + + 自定义命控制 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 设备ID + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 命令个数: + + + + + + + + 100 + 23 + + + + + 16777215 + 23 + + + + 6 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 序号 + + + Qt::AlignCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 关键字 + + + Qt::AlignCenter + + + + + + + 数值 + + + Qt::AlignCenter + + + + + + + + + + + Qt::LeftToRight + + + 1 + + + Qt::AlignCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 16777215 + 30 + + + + + + + + + + + + Qt::LeftToRight + + + 2 + + + Qt::AlignCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + 16777215 + 30 + + + + + + + + + + + + + + + Qt::LeftToRight + + + 3 + + + Qt::AlignCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + 16777215 + 30 + + + + + + + + + + + + + + + Qt::LeftToRight + + + 4 + + + Qt::AlignCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + 16777215 + 30 + + + + + + + + + + + + + + + Qt::LeftToRight + + + 5 + + + Qt::AlignCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + 16777215 + 30 + + + + + + + + + + + + + + + Qt::LeftToRight + + + 6 + + + Qt::AlignCenter + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + 16777215 + 30 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 控制执行 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 清除内容 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 自定义内容 + + + + + + + Qt::Horizontal + + + + 632 + 20 + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/dimondlg.cpp b/product/src/tools/debug_tool_v2/dimondlg.cpp new file mode 100644 index 00000000..91715ed8 --- /dev/null +++ b/product/src/tools/debug_tool_v2/dimondlg.cpp @@ -0,0 +1,798 @@ +//2018-8-31 jacky 增加区间点刷新的非法字符判断 +#include "pub_widget/MessageBox.h" +#include +#include +#include "dimondlg.h" +#include "ui_dimondlg.h" +#include +#include "CActiveWindow.h" +#include +#include +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; + +DiMonDlg::DiMonDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::DiMonDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint; + setWindowFlags(flags); +// setFixedSize(this->width(),this->height());//固定窗口大小 + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,150); + ui->PointTable->setColumnWidth(4,100); + ui->PointTable->setColumnWidth(5,100); + ui->PointTable->setColumnWidth(6,250); + ui->PointTable->setColumnWidth(7,80); + ui->PointTable->setColumnWidth(8,80); + ui->PointTable->setColumnWidth(9,120); + + m_StartIndex = -1; + m_EndIndex = -1; + + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&DiMonDlg::filterShow,Qt::QueuedConnection); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&DiMonDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); +} + +DiMonDlg::~DiMonDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipDi!= NULL) + free((m_pRtuInfo+i)->pDi); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + + delete ui; +} + +void DiMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void DiMonDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + + ui->comboBox->setModel(model); +} + +void DiMonDlg::initSig() +{ + connect(this,&DiMonDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_diRtuInfoResp,this,&DiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_diParamResp,this,&DiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_diValueResp,this,&DiMonDlg::slot_OnRecvResp); +} + +void DiMonDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadDiInfo(m_CurrentRtuNo); +} + +void DiMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void DiMonDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + changePointValueRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_DI_RtuInfo); + objMsg.set_body("MT_FESDBG_DI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + + +void DiMonDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_DI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void DiMonDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_DI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_DI_Param: + onRecvDiParamResp(strBody); + break; + case MT_FESDBG_DI_Value: + onRecvDiValueResp(strBody); + break; + default: + break; + } +} + +void DiMonDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("DiMonDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SDiMonRtu *pDiRtu = m_pRtuInfo + nIdx; + pDiRtu->RtuNo = pRtuInfo->rtu_no(); + pDiRtu->Used = pRtuInfo->used(); + strncpy(pDiRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pDiRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void DiMonDlg::onRecvDiParamResp(const string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("DiMonDlg::onRecvAiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SDiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocDiParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pDi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getDiInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimDi *pDi = pRtu->pDi + pParam->pnt_no(); + pDi->param.PointNo = pParam->pnt_no(); + pDi->param.Used = pParam->used(); + memset(pDi->param.PointTagName,0,sizeof(pDi->param.PointTagName)); + strncpy(pDi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pDi->param.PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strAppTagName)); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,7,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + item->setTextAlignment(Qt::AlignCenter); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void DiMonDlg::onRecvDiValueResp(const string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("DiMonDlg::onRecvDiValueResp 反序列化失败"); + changePointValueRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + SDiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changePointValueRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_int_values()->size(); nIdx++) + { + FesDebugToolIntPntValue *pParam = recvMsg.mutable_int_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimDi *pDi = pRtu->pDi + pParam->pnt_no(); + pDi->value.PointNo = pParam->pnt_no(); + pDi->value.Value = pParam->value(); + pDi->value.Status = pParam->status(); + pDi->value.time = pParam->time(); + + updateData(pDi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void DiMonDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SDiMonRtu*)realloc(m_pRtuInfo,sizeof(SDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SDiMonRtu*)malloc(sizeof(SDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SDiMonRtu*)malloc(sizeof(SDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void DiMonDlg::mallocDiParam(SDiMonRtu *pRtu, const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pDi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pDi = (SFesSimDi*)realloc(pRtu->pDi,sizeof(SFesSimDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pDi = (SFesSimDi*)malloc(sizeof(SFesSimDi)*pRtu->MaxPoints); + if(pRtu->pDi != NULL) + { + memset(pRtu->pDi,0,sizeof(SFesSimDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pDi==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pDi = (SFesSimDi*)malloc(sizeof(SFesSimDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void DiMonDlg::sendDiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_DI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void DiMonDlg::OnRtuCellClick(int row, int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayDiParam(m_CurrentRtuNo); + } +} + +SDiMonRtu* DiMonDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + { + return pRtu; + } + } + + return NULL; +} + +void DiMonDlg::DisplayDiParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + + initCombox(); + OnPointInfoRefresh(); +} + +void DiMonDlg::updateData(const SFesSimDiData &diData) +{ + auto iter = m_dotColumnMap.find(diData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(diData.time/1000); + //dt = QDateTime::fromSecsSinceEpoch(diData.time/1000,m_tz); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = diData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + QTableWidgetItem *itemValue = new QTableWidgetItem(QString::number(diData.Value)); + itemValue->setTextAlignment(Qt::AlignCenter); + + QTableWidgetItem *itemStatus = new QTableWidgetItem(getFesPointStatus(diData.Status)); + itemStatus->setTextAlignment(Qt::AlignCenter); + if(diData.Status != CN_FesValueUpdate) itemStatus->setTextColor(Qt::red) ; + + ui->PointTable->setItem(iter.value(),4,itemValue); + ui->PointTable->setItem(iter.value(),5,itemStatus); + ui->PointTable->setItem(iter.value(),9,new QTableWidgetItem(tStr)); +} + +void DiMonDlg::changePointValueRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +bool DiMonDlg::initPointBrushData() +{ + QString devTag = ui->comboBox->currentData(Qt::UserRole+1).toString(); + + if(devTag == "") + { + return false; + }else if(devTag == "ALL") + { + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + m_RefreshMode = 1; //section + const RtuMaxAndMinPointNo &rtuMaxMinNo = CDataMng::instance()->getDiMaxMinNoRef(); + auto it = rtuMaxMinNo.find(m_CurrentRtuNo); + if(it == rtuMaxMinNo.end()) + { + LOGERROR("未找到rtu:[%d],刷新所有数据!",m_CurrentRtuNo); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + const MaxAndMinPointNo &devMap = it.value(); + auto itor = devMap.find(devTag); + if(itor == devMap.end()) + { + LOGERROR("未找到dev:[%s],刷新所有数据!",devTag.toStdString().c_str()); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + SFESDEVMAXANDMINPOINTNO maxminNo = itor.value(); + m_StartIndex = maxminNo.minPointNo; + m_EndIndex = maxminNo.maxPointNo; + } + } + } + LOGTRACE("刷新设备[%s]的数据!",devTag.toStdString().c_str()); + return true; +} + +void DiMonDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + m_RefreshTimer->start(1000); + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendDiValueReqMsg(); + } +} + +void DiMonDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendDiValueReqMsg(); + } + else + { + changePointValueRefreshBtnToStop(); + } +} + +void DiMonDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void DiMonDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void DiMonDlg::OnRefeshTimer() +{ + unsigned char data[40]; + + if(m_ConnectFlag==CN_CommDisconnect) + { + changePointValueRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + + sendDiValueReqMsg(); +} diff --git a/product/src/tools/debug_tool_v2/dimondlg.h b/product/src/tools/debug_tool_v2/dimondlg.h new file mode 100644 index 00000000..0d0f0304 --- /dev/null +++ b/product/src/tools/debug_tool_v2/dimondlg.h @@ -0,0 +1,90 @@ +#ifndef DIMONDLG_H +#define DIMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" + +namespace Ui { +class DiMonDlg; +} + +class DiMonDlg : public QDialog +{ + Q_OBJECT + +public: + explicit DiMonDlg(int windowId,QWidget *parent); + ~DiMonDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvDiParamResp(const std::string &strBody); + void onRecvDiValueResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocDiParam(SDiMonRtu *pRtu,const int nSize); + void sendDiValueReqMsg(); + +private: + Ui::DiMonDlg *ui; + QTimeZone m_tz; + SDiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayDiParam(int RtuNo); + + void updateData(const SFesSimDiData &diData); + + void changePointValueRefreshBtnToStop(); + + bool initPointBrushData(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SDiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // DIMONDLG_H diff --git a/product/src/tools/debug_tool_v2/dimondlg.ui b/product/src/tools/debug_tool_v2/dimondlg.ui new file mode 100644 index 00000000..1caca429 --- /dev/null +++ b/product/src/tools/debug_tool_v2/dimondlg.ui @@ -0,0 +1,286 @@ + + + DiMonDlg + + + + 0 + 0 + 804 + 417 + + + + Dialog + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 1 + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + RTU名称 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 点值 + + + + + 点状态 + + + + + 后台标签 + + + + + 远动号 + + + + + 使用标志 + + + + + 时间 + + + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/fwaccmondlg.cpp b/product/src/tools/debug_tool_v2/fwaccmondlg.cpp new file mode 100644 index 00000000..51a00f01 --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwaccmondlg.cpp @@ -0,0 +1,645 @@ +#include "fwaccmondlg.h" +#include "ui_fwaccmondlg.h" +#include "pub_widget/MessageBox.h" +#include +#include "CActiveWindow.h" +#include +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +FwAccMonDlg::FwAccMonDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::FwAccMonDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_StartIndex = 0; + m_EndIndex = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,70); + ui->RTUTable->setColumnWidth(1,70); + //ui->RTUTable->setColumnWidth(2,250); + + ui->PointTable->setColumnWidth(0,60); + ui->PointTable->setColumnWidth(1,250); + ui->PointTable->setColumnWidth(2,80); + ui->PointTable->setColumnWidth(3,60); + ui->PointTable->setColumnWidth(4,210); + ui->PointTable->setColumnWidth(5,210); + + m_StartIndex = -1; + m_EndIndex = -1; + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&FwAccMonDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + //转发没有设备 因此隐藏 + ui->PointTable->setColumnHidden(4,true); + initSig(); +} + +FwAccMonDlg::~FwAccMonDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipAcc!= NULL) + free((m_pRtuInfo+i)->pAcc); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + delete ui; +} + +void FwAccMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void FwAccMonDlg::initSig() +{ + connect(this,&FwAccMonDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_fwAccRtuInfoResp,this,&FwAccMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwAccParamResp,this,&FwAccMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwAccValueResp,this,&FwAccMonDlg::slot_OnRecvResp); +} + +void FwAccMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void FwAccMonDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + m_CurrentRtuNo = -1; + changeRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWACC_RtuInfo); + objMsg.set_body("MT_FESDBG_FWACC_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwAccMonDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWACC_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwAccMonDlg::slot_OnRecvResp(int nMsgType, const std::string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_FWACC_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_FWACC_Param: + onRecvAccParamResp(strBody); + break; + case MT_FESDBG_FWACC_Value: + onRecvAccValueResp(strBody); + break; + default: + break; + } +} + +void FwAccMonDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("FwAccMonDlg:onRecvRtuInfoResp 反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SFwAccMonRtu *pRtu = m_pRtuInfo + nIdx; + pRtu->RtuNo = pRtuInfo->rtu_no(); + pRtu->Used = pRtuInfo->used(); + strncpy(pRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void FwAccMonDlg::onRecvAccParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolFwPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("FwAccMonDlg::onRecvMiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SFwAccMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocAccParam(pRtu,recvMsg.max_pnt_num()); + + if(pRtu->pAcc==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolFwPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + SFesSimFwAcc *pAcc = pRtu->pAcc + pParam->pnt_no(); + pAcc->param.PointNo = pParam->pnt_no(); + pAcc->param.Used = pParam->used(); + memset(pAcc->param.PointTagName,0,sizeof(pAcc->param.PointTagName)); + strncpy(pAcc->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pAcc->param.PointTagName) - 1); + pAcc->param.FesRtuNo = pParam->fes_rtu_no(); + pAcc->param.FesPointNo = pParam->fes_pnt_no(); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_rtu_no()); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_pnt_no()); + ui->PointTable->setItem(rowCount,7,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void FwAccMonDlg::onRecvAccValueResp(const std::string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("FwAccMonDlg::onRecvAccValueResp 反序列化失败"); + changeRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changeRefreshBtnToStop(); + return ; + } + + SFwAccMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changeRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_double_values()->size(); nIdx++) + { + FesDebugToolDoublePntValue *pParam = recvMsg.mutable_double_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimFwAcc *pAcc = pRtu->pAcc + pParam->pnt_no(); + pAcc->value.PointNo = pParam->pnt_no(); + pAcc->value.Value = pParam->value(); + pAcc->value.Status = pParam->status(); + pAcc->value.time = pParam->time(); + + updateData(pAcc->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void FwAccMonDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SFwAccMonRtu*)realloc(m_pRtuInfo,sizeof(SFwAccMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwAccMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SFwAccMonRtu*)malloc(sizeof(SFwAccMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwAccMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SFwAccMonRtu*)malloc(sizeof(SFwAccMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwAccMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void FwAccMonDlg::mallocAccParam(SFwAccMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pAcc != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pAcc = (SFesSimFwAcc*)realloc(pRtu->pAcc,sizeof(SFesSimFwAcc)*pRtu->MaxPoints); + if (pRtu->pAcc != NULL) + { + memset(pRtu->pAcc, 0, sizeof(SFesSimFwAcc)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pAcc = (SFesSimFwAcc*)malloc(sizeof(SFesSimFwAcc)*pRtu->MaxPoints); + if(pRtu->pAcc != NULL) + { + memset(pRtu->pAcc,0,sizeof(SFesSimFwAcc)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pAcc == NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pAcc = (SFesSimFwAcc*)malloc(sizeof(SFesSimFwAcc)*pRtu->MaxPoints); + if (pRtu->pAcc != NULL) + { + memset(pRtu->pAcc, 0, sizeof(SFesSimFwAcc)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void FwAccMonDlg::sendAccValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWACC_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwAccMonDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayPiParam(m_CurrentRtuNo); + } +} + +SFwAccMonRtu* FwAccMonDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void FwAccMonDlg::DisplayPiParam(int RtuNo) +{ + OnPointInfoRefresh(); +} + +void FwAccMonDlg::updateData(const SFesSimAccData &piData) +{ + auto iter = m_dotColumnMap.find(piData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(piData.time/1000); + //dt = QDateTime::fromSecsSinceEpoch(piData.time/1000,m_tz); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = piData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + ui->PointTable->setItem(iter.value(),2,new QTableWidgetItem(QString::number(piData.Value))); + ui->PointTable->setItem(iter.value(),3,new QTableWidgetItem(QString::number(piData.Status))); + ui->PointTable->setItem(iter.value(),5,new QTableWidgetItem(tStr)); +} + +void FwAccMonDlg::changeRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +void FwAccMonDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAccValueReqMsg(); + } +} + +void FwAccMonDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + sendAccValueReqMsg(); + } + else + { + changeRefreshBtnToStop(); + } +} + +void FwAccMonDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void FwAccMonDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changeRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + sendAccValueReqMsg(); +} diff --git a/product/src/tools/debug_tool_v2/fwaccmondlg.h b/product/src/tools/debug_tool_v2/fwaccmondlg.h new file mode 100644 index 00000000..0da293b4 --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwaccmondlg.h @@ -0,0 +1,87 @@ +#ifndef FWACCMONDLG_H +#define FWACCMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class FwAccMonDlg; +} + +class FwAccMonDlg : public QDialog +{ + Q_OBJECT + +public: + explicit FwAccMonDlg(int windowId,QWidget *parent); + ~FwAccMonDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvAccParamResp(const std::string &strBody); + void onRecvAccValueResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocAccParam(SFwAccMonRtu *pRtu,const int nSize); + void sendAccValueReqMsg(); + +private: + Ui::FwAccMonDlg *ui; + + QTimeZone m_tz; + SFwAccMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayPiParam(int RtuNo); + + void updateData(const SFesSimAccData & piData); + + void changeRefreshBtnToStop(); + + void OnPointValueStartRefresh(); + int m_RtuNum; + SFwAccMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_nWindowId;// 用来判断是否激活窗口 + + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // FWACCMONDLG_H diff --git a/product/src/tools/debug_tool_v2/fwaccmondlg.ui b/product/src/tools/debug_tool_v2/fwaccmondlg.ui new file mode 100644 index 00000000..3c39226f --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwaccmondlg.ui @@ -0,0 +1,236 @@ + + + FwAccMonDlg + + + + 0 + 0 + 762 + 266 + + + + 转发电度量 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 描述 + + + + + 点值 + + + + + 点状态 + + + + + 设备 + + + + + 时间 + + + + + 源RTU号 + + + + + 源点号 + + + + + 使用标志 + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/fwaimondlg.cpp b/product/src/tools/debug_tool_v2/fwaimondlg.cpp new file mode 100644 index 00000000..d043c2af --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwaimondlg.cpp @@ -0,0 +1,642 @@ +#include "fwaimondlg.h" +#include "ui_fwaimondlg.h" +#include "pub_widget/MessageBox.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +FwAiMonDlg::FwAiMonDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::FwAiMonDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |= Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,70); + ui->RTUTable->setColumnWidth(1,70); + + ui->PointTable->setColumnWidth(0,60); + ui->PointTable->setColumnWidth(1,250); + ui->PointTable->setColumnWidth(2,80); + ui->PointTable->setColumnWidth(3,60); + ui->PointTable->setColumnWidth(4,210); + ui->PointTable->setColumnWidth(5,210); + + m_StartIndex = -1; + m_EndIndex = -1; + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&FwAiMonDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + //转发没有设备 因此隐藏 + ui->PointTable->setColumnHidden(4,true); + initSig(); +} + +FwAiMonDlg::~FwAiMonDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipAi!= NULL) + free((m_pRtuInfo+i)->pAi); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + delete ui; +} + +void FwAiMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void FwAiMonDlg::initSig() +{ + connect(this,&FwAiMonDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_fwAiRtuInfoResp,this,&FwAiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwAiParamResp,this,&FwAiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwAiValueResp,this,&FwAiMonDlg::slot_OnRecvResp); +} + +void FwAiMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void FwAiMonDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + m_CurrentRtuNo = -1; + changeRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWAI_RtuInfo); + objMsg.set_body("MT_FESDBG_FWAI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwAiMonDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWAI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwAiMonDlg::slot_OnRecvResp(int nMsgType, const std::string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_FWAI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_FWAI_Param: + onRecvAiParamResp(strBody); + break; + case MT_FESDBG_FWAI_Value: + onRecvAiValueResp(strBody); + break; + default: + break; + } +} + +void FwAiMonDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("FwAiMonDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SFwAiMonRtu *pAiRtu = m_pRtuInfo + nIdx; + pAiRtu->RtuNo = pRtuInfo->rtu_no(); + pAiRtu->Used = pRtuInfo->used(); + strncpy(pAiRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pAiRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void FwAiMonDlg::onRecvAiParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolFwPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("FwAiMonDlg::onRecvAiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SFwAiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocAiParam(pRtu,recvMsg.max_pnt_num()); + + if(pRtu->pAi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolFwPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + SFesSimFwAi *pAi = pRtu->pAi + pParam->pnt_no(); + pAi->param.PointNo = pParam->pnt_no(); + pAi->param.Used = pParam->used(); + memset(pAi->param.PointTagName,0,sizeof(pAi->param.PointTagName)); + strncpy(pAi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pAi->param.PointTagName) - 1); + pAi->param.FesRtuNo = pParam->fes_rtu_no(); + pAi->param.FesPointNo = pParam->fes_pnt_no(); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_rtu_no()); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_pnt_no()); + ui->PointTable->setItem(rowCount,7,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void FwAiMonDlg::onRecvAiValueResp(const std::string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("FwAiMonDlg::onRecvAiValueResp 反序列化失败"); + changeRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changeRefreshBtnToStop(); + return ; + } + + SFwAiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changeRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_float_values()->size(); nIdx++) + { + FesDebugToolFloatPntValue *pParam = recvMsg.mutable_float_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimFwAi *pAi = pRtu->pAi + pParam->pnt_no(); + pAi->value.PointNo = pParam->pnt_no(); + pAi->value.Value = pParam->value(); + pAi->value.Status = pParam->status(); + pAi->value.time = pParam->time(); + + updateData(pAi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void FwAiMonDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SFwAiMonRtu*)realloc(m_pRtuInfo,sizeof(SFwAiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwAiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SFwAiMonRtu*)malloc(sizeof(SFwAiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwAiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SFwAiMonRtu*)malloc(sizeof(SFwAiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwAiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void FwAiMonDlg::mallocAiParam(SFwAiMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pAi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pAi = (SFesSimFwAi*)realloc(pRtu->pAi,sizeof(SFesSimFwAi)*pRtu->MaxPoints); + if (pRtu->pAi != NULL) + { + memset(pRtu->pAi, 0, sizeof(SFesSimFwAi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pAi = (SFesSimFwAi*)malloc(sizeof(SFesSimFwAi)*pRtu->MaxPoints); + if(pRtu->pAi != NULL) + { + memset(pRtu->pAi,0,sizeof(SFesSimFwAi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pAi==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pAi = (SFesSimFwAi*)malloc(sizeof(SFesSimFwAi)*pRtu->MaxPoints); + if (pRtu->pAi != NULL) + { + memset(pRtu->pAi, 0, sizeof(SFesSimFwAi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void FwAiMonDlg::sendAiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWAI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwAiMonDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayAiParam(m_CurrentRtuNo); + } +} + +SFwAiMonRtu* FwAiMonDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;i < m_RtuNum;i++) + { + SFwAiMonRtu *pRtu = m_pRtuInfo+i; + if(pRtu->RtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void FwAiMonDlg::DisplayAiParam(int RtuNo) +{ + OnPointInfoRefresh(); +} + +void FwAiMonDlg::updateData(const SFesSimAiData &aiData) +{ + auto iter = m_dotColumnMap.find(aiData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(aiData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = aiData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + ui->PointTable->setItem(iter.value(),2,new QTableWidgetItem(QString::number(aiData.Value))); + ui->PointTable->setItem(iter.value(),3,new QTableWidgetItem(QString::number(aiData.Status))); + ui->PointTable->setItem(iter.value(),5,new QTableWidgetItem(tStr)); +} + +void FwAiMonDlg::changeRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +void FwAiMonDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAiValueReqMsg(); + } +} + +void FwAiMonDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + sendAiValueReqMsg(); + } + else + { + changeRefreshBtnToStop(); + } +} + +void FwAiMonDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void FwAiMonDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changeRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + + sendAiValueReqMsg(); +} diff --git a/product/src/tools/debug_tool_v2/fwaimondlg.h b/product/src/tools/debug_tool_v2/fwaimondlg.h new file mode 100644 index 00000000..ad4ac849 --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwaimondlg.h @@ -0,0 +1,86 @@ +#ifndef FWAIMONDLG_H +#define FWAIMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class FwAiMonDlg; +} + +class FwAiMonDlg : public QDialog +{ + Q_OBJECT + +public: + explicit FwAiMonDlg(int windowId,QWidget *parent); + ~FwAiMonDlg(); + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvAiParamResp(const std::string &strBody); + void onRecvAiValueResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocAiParam(SFwAiMonRtu *pRtu,const int nSize); + void sendAiValueReqMsg(); + +private: + Ui::FwAiMonDlg *ui; + QTimeZone m_tz; + SFwAiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayAiParam(int RtuNo); + + void updateData(const SFesSimAiData &aiData); + + void changeRefreshBtnToStop(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SFwAiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // FWAIMONDLG_H diff --git a/product/src/tools/debug_tool_v2/fwaimondlg.ui b/product/src/tools/debug_tool_v2/fwaimondlg.ui new file mode 100644 index 00000000..d673aa5a --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwaimondlg.ui @@ -0,0 +1,236 @@ + + + FwAiMonDlg + + + + 0 + 0 + 813 + 396 + + + + 转发模拟量 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 描述 + + + + + 点值 + + + + + 点状态 + + + + + 设备 + + + + + 时间 + + + + + 源RTU号 + + + + + 源点号 + + + + + 使用标志 + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/fwddimondlg.cpp b/product/src/tools/debug_tool_v2/fwddimondlg.cpp new file mode 100644 index 00000000..3907cd16 --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwddimondlg.cpp @@ -0,0 +1,648 @@ +#include "fwddimondlg.h" +#include "ui_fwddimondlg.h" +#include "pub_widget/MessageBox.h" +#include +#include +#include "CActiveWindow.h" +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +FwDDiMonDlg::FwDDiMonDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::FwDDiMonDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_StartIndex = 0; + m_EndIndex = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,70); + ui->RTUTable->setColumnWidth(1,70); + //ui->RTUTable->setColumnWidth(2,250); + + ui->PointTable->setColumnWidth(0,60); + ui->PointTable->setColumnWidth(1,250); + ui->PointTable->setColumnWidth(2,80); + ui->PointTable->setColumnWidth(3,60); + ui->PointTable->setColumnWidth(4,210); + ui->PointTable->setColumnWidth(5,210); + + m_StartIndex = -1; + m_EndIndex = -1; + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&FwDDiMonDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + //转发没有设备 因此隐藏 + ui->PointTable->setColumnHidden(4,true); + initSig(); + +} + +FwDDiMonDlg::~FwDDiMonDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipDi!= NULL) + free((m_pRtuInfo+i)->pDi); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + delete ui; +} + +void FwDDiMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void FwDDiMonDlg::initSig() +{ + connect(this,&FwDDiMonDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_fwDDiRtuInfoResp,this,&FwDDiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwDDiParamResp,this,&FwDDiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwDDiValueResp,this,&FwDDiMonDlg::slot_OnRecvResp); +} + +void FwDDiMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void FwDDiMonDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + m_CurrentRtuNo = -1; + changeRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWDDI_RtuInfo); + objMsg.set_body("MT_FESDBG_FWDDI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwDDiMonDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWDDI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwDDiMonDlg::slot_OnRecvResp(int nMsgType, const std::string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_FWDDI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_FWDDI_Param: + onRecvDDiParamResp(strBody); + break; + case MT_FESDBG_FWDDI_Value: + onRecvDDiValueResp(strBody); + break; + default: + break; + } +} + +void FwDDiMonDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("FwDDiMonDlg:onRecvRtuInfoResp 反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SFwDiMonRtu *pRtu = m_pRtuInfo + nIdx; + pRtu->RtuNo = pRtuInfo->rtu_no(); + pRtu->Used = pRtuInfo->used(); + strncpy(pRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void FwDDiMonDlg::onRecvDDiParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolFwPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("FwDDiMonDlg::onRecvDDiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SFwDiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocDDiParam(pRtu,recvMsg.max_pnt_num()); + + if(pRtu->pDi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolFwPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + SFesSimFwDi *pDi = pRtu->pDi + pParam->pnt_no(); + pDi->param.PointNo = pParam->pnt_no(); + pDi->param.Used = pParam->used(); + memset(pDi->param.PointTagName,0,sizeof(pDi->param.PointTagName)); + strncpy(pDi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pDi->param.PointTagName) - 1); + pDi->param.FesRtuNo = pParam->fes_rtu_no(); + pDi->param.FesPointNo = pParam->fes_pnt_no(); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_rtu_no()); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_pnt_no()); + ui->PointTable->setItem(rowCount,7,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void FwDDiMonDlg::onRecvDDiValueResp(const std::string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("FwDDiMonDlg::onRecvDDiValueResp 反序列化失败"); + changeRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changeRefreshBtnToStop(); + return ; + } + + SFwDiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changeRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_int_values()->size(); nIdx++) + { + FesDebugToolIntPntValue *pParam = recvMsg.mutable_int_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimFwDi *pDi = pRtu->pDi + pParam->pnt_no(); + pDi->value.PointNo = pParam->pnt_no(); + pDi->value.Value = pParam->value(); + pDi->value.Status = pParam->status(); + pDi->value.time = pParam->time(); + + updateData(pDi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void FwDDiMonDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SFwDiMonRtu*)realloc(m_pRtuInfo,sizeof(SFwDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SFwDiMonRtu*)malloc(sizeof(SFwDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SFwDiMonRtu*)malloc(sizeof(SFwDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void FwDDiMonDlg::mallocDDiParam(SFwDiMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pDi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pDi = (SFesSimFwDi*)realloc(pRtu->pDi,sizeof(SFesSimFwDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimFwDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pDi = (SFesSimFwDi*)malloc(sizeof(SFesSimFwDi)*pRtu->MaxPoints); + if(pRtu->pDi != NULL) + { + memset(pRtu->pDi,0,sizeof(SFesSimFwDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pDi == NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pDi = (SFesSimFwDi*)malloc(sizeof(SFesSimFwDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimFwDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void FwDDiMonDlg::sendDDiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWDDI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwDDiMonDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayDiParam(m_CurrentRtuNo); + } +} + +SFwDiMonRtu* FwDDiMonDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void FwDDiMonDlg::DisplayDiParam(int RtuNo) +{ + OnPointInfoRefresh(); +} + +void FwDDiMonDlg::updateData(const SFesSimDiData &diData) +{ + auto iter = m_dotColumnMap.find(diData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(diData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = diData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + ui->PointTable->setItem(iter.value(),2,new QTableWidgetItem(QString::number(diData.Value))); + ui->PointTable->setItem(iter.value(),3,new QTableWidgetItem(QString::number(diData.Status))); + ui->PointTable->setItem(iter.value(),5,new QTableWidgetItem(tStr)); +} + +void FwDDiMonDlg::changeRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +void FwDDiMonDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendDDiValueReqMsg(); + } +} + +void FwDDiMonDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendDDiValueReqMsg(); + } + else + { + changeRefreshBtnToStop(); + } +} + +void FwDDiMonDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void FwDDiMonDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changeRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + + sendDDiValueReqMsg(); +} diff --git a/product/src/tools/debug_tool_v2/fwddimondlg.h b/product/src/tools/debug_tool_v2/fwddimondlg.h new file mode 100644 index 00000000..b13752ae --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwddimondlg.h @@ -0,0 +1,86 @@ +#ifndef FWDDIMONDLG_H +#define FWDDIMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class FwDDiMonDlg; +} + +class FwDDiMonDlg : public QDialog +{ + Q_OBJECT + +public: + explicit FwDDiMonDlg(int windowId,QWidget *parent ); + ~FwDDiMonDlg(); + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); + +protected: + void keyPressEvent(QKeyEvent *event); + +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvDDiParamResp(const std::string &strBody); + void onRecvDDiValueResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocDDiParam(SFwDiMonRtu *pRtu,const int nSize); + void sendDDiValueReqMsg(); + +private: + Ui::FwDDiMonDlg *ui; + QTimeZone m_tz; + SFwDiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayDiParam(int RtuNo); + + void updateData(const SFesSimDiData & diData); + + void changeRefreshBtnToStop(); + + void OnPointValueStartRefresh(); + int m_RtuNum; + SFwDiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // FWDDIMONDLG_H diff --git a/product/src/tools/debug_tool_v2/fwddimondlg.ui b/product/src/tools/debug_tool_v2/fwddimondlg.ui new file mode 100644 index 00000000..b94ece3d --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwddimondlg.ui @@ -0,0 +1,236 @@ + + + FwDDiMonDlg + + + + 0 + 0 + 965 + 307 + + + + 转发双点数字量 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 描述 + + + + + 点值 + + + + + 点状态 + + + + + 设备 + + + + + 时间 + + + + + 源RTU号 + + + + + 源点号 + + + + + 使用标志 + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/fwdimondlg.cpp b/product/src/tools/debug_tool_v2/fwdimondlg.cpp new file mode 100644 index 00000000..6422e044 --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwdimondlg.cpp @@ -0,0 +1,643 @@ +#include "fwdimondlg.h" +#include "ui_fwdimondlg.h" +#include "pub_widget/MessageBox.h" +#include +#include +#include +#include +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +FwDiMonDlg::FwDiMonDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::FwDiMonDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,70); + ui->RTUTable->setColumnWidth(1,70); + + ui->PointTable->setColumnWidth(0,60); + ui->PointTable->setColumnWidth(1,250); + ui->PointTable->setColumnWidth(2,80); + ui->PointTable->setColumnWidth(3,60); + ui->PointTable->setColumnWidth(4,210); + ui->PointTable->setColumnWidth(5,210); + + m_StartIndex = -1; + m_EndIndex = -1; + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&FwDiMonDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + //转发没有设备 因此隐藏 + ui->PointTable->setColumnHidden(4,true); + initSig(); + +} + +FwDiMonDlg::~FwDiMonDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipDi!= NULL) + free((m_pRtuInfo+i)->pDi); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + delete ui; +} + +void FwDiMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void FwDiMonDlg::initSig() +{ + connect(this,&FwDiMonDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_fwDiRtuInfoResp,this,&FwDiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwDiParamResp,this,&FwDiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwDiValueResp,this,&FwDiMonDlg::slot_OnRecvResp); +} + +void FwDiMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void FwDiMonDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + m_CurrentRtuNo = -1; + changeRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWDI_RtuInfo); + objMsg.set_body("MT_FESDBG_FWDI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwDiMonDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag == CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh =false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWDI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwDiMonDlg::slot_OnRecvResp(int nMsgType, const std::string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_FWDI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_FWDI_Param: + onRecvDiParamResp(strBody); + break; + case MT_FESDBG_FWDI_Value: + onRecvDiValueResp(strBody); + break; + default: + break; + } +} + +void FwDiMonDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("FwDiMonDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SFwDiMonRtu *pRtu = m_pRtuInfo + nIdx; + pRtu->RtuNo = pRtuInfo->rtu_no(); + pRtu->Used = pRtuInfo->used(); + strncpy(pRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void FwDiMonDlg::onRecvDiParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolFwPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("FwDiMonDlg::onRecvDiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SFwDiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocDiParam(pRtu,recvMsg.max_pnt_num()); + + if(pRtu->pDi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolFwPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + SFesSimFwDi *pDi = pRtu->pDi + pParam->pnt_no(); + pDi->param.PointNo = pParam->pnt_no(); + pDi->param.Used = pParam->used(); + memset(pDi->param.PointTagName,0,sizeof(pDi->param.PointTagName)); + strncpy(pDi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pDi->param.PointTagName) - 1); + pDi->param.FesRtuNo = pParam->fes_rtu_no(); + pDi->param.FesPointNo = pParam->fes_pnt_no(); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_rtu_no()); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_pnt_no()); + ui->PointTable->setItem(rowCount,7,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void FwDiMonDlg::onRecvDiValueResp(const std::string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("FwDiMonDlg::onRecvDiValueResp 反序列化失败"); + changeRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changeRefreshBtnToStop(); + return ; + } + + SFwDiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changeRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_int_values()->size(); nIdx++) + { + FesDebugToolIntPntValue *pParam = recvMsg.mutable_int_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimFwDi *pDi = pRtu->pDi + pParam->pnt_no(); + pDi->value.PointNo = pParam->pnt_no(); + pDi->value.Value = pParam->value(); + pDi->value.Status = pParam->status(); + pDi->value.time = pParam->time(); + + updateData(pDi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void FwDiMonDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SFwDiMonRtu*)realloc(m_pRtuInfo,sizeof(SFwDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SFwDiMonRtu*)malloc(sizeof(SFwDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SFwDiMonRtu*)malloc(sizeof(SFwDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void FwDiMonDlg::mallocDiParam(SFwDiMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pDi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pDi = (SFesSimFwDi*)realloc(pRtu->pDi,sizeof(SFesSimFwDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimFwDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pDi = (SFesSimFwDi*)malloc(sizeof(SFesSimFwDi)*pRtu->MaxPoints); + if(pRtu->pDi != NULL) + { + memset(pRtu->pDi,0,sizeof(SFesSimFwDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pDi == NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pDi = (SFesSimFwDi*)malloc(sizeof(SFesSimFwDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimFwDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void FwDiMonDlg::sendDiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWDI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwDiMonDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayDiParam(m_CurrentRtuNo); + } +} + +SFwDiMonRtu* FwDiMonDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void FwDiMonDlg::DisplayDiParam(int RtuNo) +{ + OnPointInfoRefresh(); +} + +void FwDiMonDlg::updateData(const SFesSimDiData &diData) +{ + auto iter = m_dotColumnMap.find(diData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(diData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = diData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + ui->PointTable->setItem(iter.value(),2,new QTableWidgetItem(QString::number(diData.Value))); + ui->PointTable->setItem(iter.value(),3,new QTableWidgetItem(QString::number(diData.Status))); + ui->PointTable->setItem(iter.value(),5,new QTableWidgetItem(tStr)); +} + +void FwDiMonDlg::changeRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +void FwDiMonDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag == CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendDiValueReqMsg(); + } +} + +void FwDiMonDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + sendDiValueReqMsg(); + } + else + { + changeRefreshBtnToStop(); + } +} + +void FwDiMonDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void FwDiMonDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changeRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!isEndOneRefresh) + { + return; + } + isEndOneRefresh = false; + + sendDiValueReqMsg(); +} diff --git a/product/src/tools/debug_tool_v2/fwdimondlg.h b/product/src/tools/debug_tool_v2/fwdimondlg.h new file mode 100644 index 00000000..9dbc21f8 --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwdimondlg.h @@ -0,0 +1,87 @@ +#ifndef FWDIMONDLG_H +#define FWDIMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class FwDiMonDlg; +} + +class FwDiMonDlg : public QDialog +{ + Q_OBJECT + +public: + explicit FwDiMonDlg(int windowId,QWidget *parent ); + ~FwDiMonDlg(); + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); + +protected: + void keyPressEvent(QKeyEvent *event); + +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvDiParamResp(const std::string &strBody); + void onRecvDiValueResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocDiParam(SFwDiMonRtu *pRtu,const int nSize); + void sendDiValueReqMsg(); + +private: + Ui::FwDiMonDlg *ui; + QTimeZone m_tz; + SFwDiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayDiParam(int RtuNo); + + void updateData(const SFesSimDiData &diData); + + void changeRefreshBtnToStop(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SFwDiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // FWDIMONDLG_H diff --git a/product/src/tools/debug_tool_v2/fwdimondlg.ui b/product/src/tools/debug_tool_v2/fwdimondlg.ui new file mode 100644 index 00000000..389cd92c --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwdimondlg.ui @@ -0,0 +1,236 @@ + + + FwDiMonDlg + + + + 0 + 0 + 762 + 280 + + + + 转发单点数字量 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 描述 + + + + + 点值 + + + + + 点状态 + + + + + 设备 + + + + + 时间 + + + + + 源RTU号 + + + + + 源点号 + + + + + 使用标志 + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/fwmimondlg.cpp b/product/src/tools/debug_tool_v2/fwmimondlg.cpp new file mode 100644 index 00000000..3c133a85 --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwmimondlg.cpp @@ -0,0 +1,641 @@ +#include "pub_widget/MessageBox.h" +#include +#include "fwmimondlg.h" +#include "ui_fwmimondlg.h" +#include "CActiveWindow.h" +#include +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +FwMiMonDlg::FwMiMonDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::FwMiMonDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + Qt::WindowFlags flags=Qt::Window; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + setAttribute(Qt::WA_DeleteOnClose); + + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,70); + ui->RTUTable->setColumnWidth(1,70); + //ui->RTUTable->setColumnWidth(2,250); + + ui->PointTable->setColumnWidth(0,60); + ui->PointTable->setColumnWidth(1,250); + ui->PointTable->setColumnWidth(2,80); + ui->PointTable->setColumnWidth(3,60); + ui->PointTable->setColumnWidth(4,210); + ui->PointTable->setColumnWidth(5,210); + + m_StartIndex = -1; + m_EndIndex = -1; + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&FwMiMonDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + //转发没有设备 因此隐藏 + ui->PointTable->setColumnHidden(4,true); + initSig(); +} + +FwMiMonDlg::~FwMiMonDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipMi!= NULL) + free((m_pRtuInfo+i)->pMi); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + delete ui; +} + +void FwMiMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void FwMiMonDlg::initSig() +{ + connect(this,&FwMiMonDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_fwMiRtuInfoResp,this,&FwMiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwMiParamResp,this,&FwMiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_fwMiValueResp,this,&FwMiMonDlg::slot_OnRecvResp); +} + +void FwMiMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void FwMiMonDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + m_CurrentRtuNo = -1; + changeRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWMI_RtuInfo); + objMsg.set_body("MT_FESDBG_FWMI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwMiMonDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWMI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwMiMonDlg::slot_OnRecvResp(int nMsgType, const std::string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_FWMI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_FWMI_Param: + onRecvMiParamResp(strBody); + break; + case MT_FESDBG_FWMI_Value: + onRecvMiValueResp(strBody); + break; + default: + break; + } +} + +void FwMiMonDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("FwMiMonDlg:onRecvRtuInfoResp 反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SFwMiMonRtu *pRtu = m_pRtuInfo + nIdx; + pRtu->RtuNo = pRtuInfo->rtu_no(); + pRtu->Used = pRtuInfo->used(); + strncpy(pRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void FwMiMonDlg::onRecvMiParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolFwPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("FwMiMonDlg::onRecvMiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SFwMiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocMiParam(pRtu,recvMsg.max_pnt_num()); + + if(pRtu->pMi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolFwPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + SFesSimFwMi *pMi = pRtu->pMi + pParam->pnt_no(); + pMi->param.PointNo = pParam->pnt_no(); + pMi->param.Used = pParam->used(); + memset(pMi->param.PointTagName,0,sizeof(pMi->param.PointTagName)); + strncpy(pMi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pMi->param.PointTagName) - 1); + pMi->param.FesRtuNo = pParam->fes_rtu_no(); + pMi->param.FesPointNo = pParam->fes_pnt_no(); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_rtu_no()); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->fes_pnt_no()); + ui->PointTable->setItem(rowCount,7,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void FwMiMonDlg::onRecvMiValueResp(const std::string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("FwMiMonDlg::onRecvMiValueResp 反序列化失败"); + changeRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changeRefreshBtnToStop(); + return ; + } + + SFwMiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changeRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_int_values()->size(); nIdx++) + { + FesDebugToolIntPntValue *pParam = recvMsg.mutable_int_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimFwMi *pMi = pRtu->pMi + pParam->pnt_no(); + pMi->value.PointNo = pParam->pnt_no(); + pMi->value.Value = pParam->value(); + pMi->value.Status = pParam->status(); + pMi->value.time = pParam->time(); + + updateData(pMi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void FwMiMonDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SFwMiMonRtu*)realloc(m_pRtuInfo,sizeof(SFwMiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwMiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SFwMiMonRtu*)malloc(sizeof(SFwMiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwMiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SFwMiMonRtu*)malloc(sizeof(SFwMiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SFwMiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void FwMiMonDlg::mallocMiParam(SFwMiMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pMi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pMi = (SFesSimFwMi*)realloc(pRtu->pMi,sizeof(SFesSimFwMi)*pRtu->MaxPoints); + if (pRtu->pMi != NULL) + { + memset(pRtu->pMi, 0, sizeof(SFesSimFwMi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pMi = (SFesSimFwMi*)malloc(sizeof(SFesSimFwMi)*pRtu->MaxPoints); + if(pRtu->pMi != NULL) + { + memset(pRtu->pMi,0,sizeof(SFesSimFwMi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pMi == NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pMi = (SFesSimFwMi*)malloc(sizeof(SFesSimFwMi)*pRtu->MaxPoints); + if (pRtu->pMi != NULL) + { + memset(pRtu->pMi, 0, sizeof(SFesSimFwMi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void FwMiMonDlg::sendMiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_FWMI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void FwMiMonDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayMiParam(m_CurrentRtuNo); + } +} + +SFwMiMonRtu* FwMiMonDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void FwMiMonDlg::DisplayMiParam(int RtuNo) +{ + OnPointInfoRefresh(); +} + +void FwMiMonDlg::updateData(const SFesSimMiData &MiData) +{ + auto iter = m_dotColumnMap.find(MiData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(MiData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = MiData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + ui->PointTable->setItem(iter.value(),2,new QTableWidgetItem(QString::number(MiData.Value))); + ui->PointTable->setItem(iter.value(),3,new QTableWidgetItem(QString::number(MiData.Status))); + ui->PointTable->setItem(iter.value(),5,new QTableWidgetItem(tStr)); +} + +void FwMiMonDlg::changeRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +void FwMiMonDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendMiValueReqMsg(); + } +} + +void FwMiMonDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + sendMiValueReqMsg(); + } + else + { + changeRefreshBtnToStop(); + } +} + +void FwMiMonDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void FwMiMonDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changeRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + + sendMiValueReqMsg(); +} diff --git a/product/src/tools/debug_tool_v2/fwmimondlg.h b/product/src/tools/debug_tool_v2/fwmimondlg.h new file mode 100644 index 00000000..33cfbe27 --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwmimondlg.h @@ -0,0 +1,84 @@ +#ifndef FWMIMONDLG_H +#define FWMIMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class FwMiMonDlg; +} + +class FwMiMonDlg : public QDialog +{ + Q_OBJECT + +public: + explicit FwMiMonDlg(int windowId,QWidget *parent ); + ~FwMiMonDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvMiParamResp(const std::string &strBody); + void onRecvMiValueResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocMiParam(SFwMiMonRtu *pRtu,const int nSize); + void sendMiValueReqMsg(); + +private: + Ui::FwMiMonDlg *ui; + QTimeZone m_tz; + SFwMiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayMiParam(int RtuNo); + + void updateData(const SFesSimMiData &MiData); + + void changeRefreshBtnToStop(); + + void OnPointValueStartRefresh(); + int m_RtuNum; + SFwMiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // FWMIMONDLG_H diff --git a/product/src/tools/debug_tool_v2/fwmimondlg.ui b/product/src/tools/debug_tool_v2/fwmimondlg.ui new file mode 100644 index 00000000..fec61863 --- /dev/null +++ b/product/src/tools/debug_tool_v2/fwmimondlg.ui @@ -0,0 +1,236 @@ + + + FwMiMonDlg + + + + 0 + 0 + 762 + 311 + + + + 转发混合量 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 描述 + + + + + 点值 + + + + + 点状态 + + + + + 设备 + + + + + 时间 + + + + + 源RTU号 + + + + + 源点号 + + + + + 使用标志 + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/images.qrc b/product/src/tools/debug_tool_v2/images.qrc new file mode 100644 index 00000000..92b8c35a --- /dev/null +++ b/product/src/tools/debug_tool_v2/images.qrc @@ -0,0 +1,6 @@ + + + images/EngineeringDebug.png + debug_tool.ico + + diff --git a/product/src/tools/debug_tool_v2/images/EngineeringDebug.png b/product/src/tools/debug_tool_v2/images/EngineeringDebug.png new file mode 100644 index 0000000000000000000000000000000000000000..2abbef321468568463930d1c814faa6340bb9308 GIT binary patch literal 6641 zcmW+*1yJ1H*InFwahC#%7k4l2?(Xic#i79BP~0gk?ohl?v=k`r6!{f*7XR}9?#!EH zCX<)so%`-R=OjTxO&$xK3>^dlVJRxeY5~XpAE?N{*-y5pd=QAVQ&Cn*C%|l@5W_&n z_Hkg#`vBfc^K62vtOVZ7fKO*pp_2CtudnZ{tk;JYu9^kk>F;_qhF^7@x0{=H`6f}{ z0{)db(#mnLd`Y5>BIfYQ=vj{w^6q=PE)udA{e(F+pdl7I!;{K0m3Mw6a()`ze;%TB zvBsP!C4ebGewR-2Ja}=A(rxOM(jzP((yzfl4QAZOArWnWo0fd4N z!c}0Ut%$_cQq|PyGOFXK{qm(Nqo^qC`02dAp}wxpwYIj_N#l!7-LrcmHM~aC4`Y*C zb}TJS4XETZxh6}Nmb$unu)n{5_1M^0nz*>QxNU|^sG0|UdeiJqRGwuZ)U10$ovCC^Y?#hQ_Y&2*X( zY#F-TXVHg0TFuoawSA?rIAK3oKuIZow`(F zFQ*bMk+7iPGOe(1kdK9hMQ48gT83BGIuc03H$1t_&Dr^DZB32BvW&_;s#_4t-%07Pl zIDOgS^BxBJoO<>1N*pn$G7cmGuGirpp{x zcXI6KUWg2{>n3MrB+@c7Z*~TwP;^H|Mm{FyW6e`QPia`d=;NcwFV zqW4WoHn zl9|2E<^$qTy;!`LkDvd}OHVI*g-aFgAzs*hwG~3c%gZ}DJL`%6D=An!WlI)I#ntsR zW^ZqA+PK|ioLhgo2Ofg$DTvY>_VSoEJ3DKDd|I{Ql*wZ-_t+Lijp}W6_u%rnwlC@V5L&?p}R+muvWwpJuIjx5>yvWV;NL} zS8em2w*(G(1p%=W9@YaAG=fv;=2qJ{!n&t#uc~6SUTb%42)!6YVM){RtJ$UWmH9TO zqo5G)ZDO+SBPqL3lb6yz;o@`DAa)i3UpvelrmQ3wk@@USeq?fmYO3XV(Mm20Sw1k|={itC2 zmxUovMGmN-Q@P~3B1&qNPeTg2GUy`49H$W}cVBhT1}8$immnIi%_#K#&lhb?AS5mz zg6~zz&5WUP^~T-@Q<^`1{&d%62AB4xjYuhe*MPq;q>7xd1DO=QNB)h=GW4ezRL>9M zglTY%moG82)U~$q3bC*_Svxs7LAG$@GK2oU+5~J}@-QX;XR*7xTZD~`z4F(9KR0KVl#=qQw-*ro5D-U$ zgc9ZW{)3g(u3wDw`v!rE%SbXBNd5rM2+qPv!64cay3=bkzQq>_q?aJ3&`(-<%^?q0 zzUHB~Su|PFC9kLoU{vf1=~C$Hb@5w)An@3A$Q$7m!kIw0eJf3SVOpv2x^1}|_yO!pMvcRASCM-sr*K zXn!XU<21Quaz2W8VnbM**d;v?B9H7qF_Z%!ky;T?hrg$59sV(Kapx0LQ@l6ZsS$hK zT<)8q=bfFMp$N#BsJuV5%RhgqMPo3f_h_IRm?g7F;Y7+n(LDX`q>2%V!->~vR!{Eg zUny%5gP&r11B%ckVD>n=)*$SxDS=AXCQ7=p4h-~xlz(b$AFJe@EW`X1fZVe4@$r#W zQkpP*b?@XJZ{uiXuHh3VJ%+(xP>6Qb55>y4SH>i|`WPor%09kAmtu)wInVQpD;&`$ z#9Z#&#o=!bbQgDl@E>q|idIdSte2VGLbH%APEaoH!078PzI=2)u94U%UP!mYGB{kC z)8L*11(Cw9f_1!l$XJKD?m105aoem$5_z5(5nqf_Nf@dl;NaluArOc&G8WklI%wHP zw+j}00)r6x6?kZ9+LF=@RQPb&f_&=`vCZZc<14Fz9JDkLh*C=j20!nvE=e&^$U=}J z7(r6Ms1*mV`*;oVse}26iHI1ZV`I+-+PpNSqvEB!7Jhx^bJhTgh8fU$r}#d?H zaEtgFnhv!%uF+y z4(~rV<|Q!P1vThm0+CGgiOgTAuuaRzD9Caok#JJ2Ku~kwz9<5AGs82ZDI>qk*7A_PYAKwlI5%Gr>I40?F zgN0&>g>s6VIj?M5pxtX*XM#;rpqzMFj}_tfpF59XoOV7Z5YFs~3)6hPue5@$p5EdX z9X-9ejje4Ps-;FxfwhH2$=@`3d9&NQJ2NCur$F`Ehlo5M(gl-4J*0#koo-@`+D?Pr z7Zi;~A5pB~Ak?&TFBvJRL6jsS_SF}l8K8^sx1Mr~Nl8ha$){38S$;-Qjlg&tw+E8vzXf;5R+<~+lo`N#OSH~3y04F@M& zL`;klL6E}%mkBZk6fv>;^DXKI9TrcqQMz%6*p!NnH&qpyEUxgK2I|3Vq(>p&PRDvH z9xZl>g<;7DS~_)Cfbw)GXR{>;`=3#8e6UC*d1=KRS1S}=cp8XAh!YhRW%Oa^tTK;8 znEc8B4M>a0-;Y*4^3C4ItI9#31dU?-N$c@S9q1J$za2mv8YGR8z;On=^mC$|0U96p4!zBF;snnYC`2uTmxVyVxEC`}^PTR9SPMD&15$b{N8zaExk( zAKLH&iMfS2+Ci+<3Ipb)2zjPT+vV3rHAA_L88lP`L)f7pJyF`o?NVNQR(8{gi3v9j zfIVyiz`I{Qp!LeqDFBG?wzzNg5uBZ!ZDzYsy!+>chaocKSla!C02;DO^v>y;2j8P< zKJuFr1MYQlc80?*Gcrw2#D6Xr7x!QANzN7XZP2GEoed3FHsa&s4Xf3QfAQ$JV()p+ zh#ltS<_2h$Y8Zq>V(4NWH;7``_M#m3Rm(Nb3She|n3wQ4^94FJ$jFnUa}V#nyGB#kys z!p4i#dB%?v3WNDGWD(DwBfs9OWQ++&S8!Q+oY(j%DvlT0PG(P^DYVVrWc-`2#!*#L zdi*myZ2gJ!(@jqMdqk(taAZb4*A6eTMd~Cr!~}xR=InnuKnlr1`Dz`O6F9y>UF zovK>E4z7>Gp$@YKGI?@(`h(sd0)zZ-k@=O;#!>Gv)uVqP<&2$HoCiURcwKTA%;-7_ zB@=kz82WYAG_$dffASUKp`&kNWJMaAw@C35gTV~3adB_-fFzjnNE{Q(!^Oq@eLj{( zpA;Gr!Vec=xRz_Yib~NlG?Y->`nzIrBq+8!`Py9P^w%6TXn{(0ICce@CiNPBCC15m zzGij(yO{}$WMMJ!qhYF|#hD=4J`*n=PU z#xwkt8Sq=ONiWps2YLt*S&knzaLdHY7#4Z)1#b|Bk@iNp{{|&cs0@w@HT(UtbFM`W zWBG4rrLjBWc|=i*19^lrOQW*_4QYFocwj9V9?@xH-86)=)#&u)=H^Dfyu5q{AkF^? z=%dLH;`i9>Ph`;xxGY0Yc6Yg3$+45Y!OVfNdE6%+z6g=7UtB%fehXs0A5#rakK%D3 zzUVN1ZK%_R4!QrtF0&Y>*l@?n__jHdTC5KF{y)|KLtD*7yNhTW!@#wUK9V=gg_Vp z*G*FsyaAUcx}_9;V-vTrYY!Q`wwBhFZ$JR-7{DH;kN|4l_>9$|yMOtU+JCt}{EZbz zGt*&-qcz=q#_&|ASEAvvj}C%u8)5~e&BQHDFJxJ?L2N8HlYgvx?Y#oW${?syM61y@ z5>t+uo%+*X`d>iT+ibEKPY+MZ=-%Zc4;9ApH#}KwJH904u{&vLZy$|IWz)l*D|}-6 z!Qi}|lC~!!0xdFH5#`7^48=+lrG(`!%K>7k9`RQ0!@f@%+!jDIHQ_^;?EZEJD&sBa>p z!_=S1>ncDQvC0-Jybw&ECT5lPZ{JQ%zBcqd0>qYu(WeQuXHIy%Sz0}pYcTA5vlowE z?$ffuyib2oVg=~^-F30OLM6*q&oRVgoNUJN^73lu0HoDcrE(4#CV!zgyw)4y@ZIT}{0BKX zDjyGz0S5PuI{uDD(-G-iN34psDVe>)em!o=AB>oE9(n@}66L)ZB+|oc7;8}>Pugj+ zSI7G>5o1fk;S5 zSpJ)<6ajdCbTvivDGLRe3^b@Z3O+qISI})|DCP}t3@GjDb#^7sbekh^XY8GQkES@c z*VaH&=$X<6jhH8OaLpJ7Fgh88rE9~0--r>06_?`p%Xejjoj3EoO-FE%SaE+mgw!W( zT_0EAKi!q>%t&!xP^-wuunwg0VikoC+7UEI;I%IfaE}G*yv{Ud-At>ri(By^1ZA^E+;Om z!EopRi91=riNlLd;}u-w@RsAY4I{$sboUB@Th3tCSoNq9&10a;yeLXE`PKP)7s1=r zBxm>!W%?Wfyh6#}rLyQAx2dr%fZCMR(a{O%4|`GB+>NUZehoKTel;Yg0p;n~4-3YJ z@6ig2I{CF34ehg#e@5f&z`yXS9#pF8QQMH)Ruh_3J$_u(GWn%BH#j;mAxw1;?#rb) z&4=kBV6%bYm3xJfAcSGH2iOpKmzS5Cg3;|%d9i03%`Bamred%p{15GHEM~>aP;qb50&PQn$(VsjSV_k@8YrB z9*Bft(iKh5I}S<_>o;9kDv{e9w*3ByzMXfel`COb)e&gAFgt%fTNPGRAL-7)^SccB z;=assK~#uY^=3O7*B3DT4jX#!R*jj|i~bx^VinurKCT!V(CmdbxH4?Nz4g@u)aLn(aI z0Z2DW|3C$VLEq-giF|2s&==uH&mDkEWelja;SVloCh~{ovbow~TyZZYEM|;G#NS}4{%_hLH=g0)?5T8xrpM!6*i;_R#%B22ivqCALijKJZ#& z>iXQ$ROj01<3pllti~&d*bGWS4h#MDo?x(OP4L3suFiMwYI}U~q^b4}4yX+K!$Mu0 zoN8e(vP;Ksxvv696|^dDr7oAdBSp?j^~rbF*T%B*t=j%57sfEk$!5N;uCC%AKv0SW zwU%ombgz>+vy7!!3;{1HW(9Pr=jUg$bOi>4Fbs{U(@(BTFEaOW!Qz?$#*4D+nG2zCxIaC5RkG5q={HrSy|B~ zptQDunB+9P8Is#m6Kd&{)zH_k?hd{`n*~(4JHY=9=!6BdF!5NAh-8%`z;d+9s!|JG zGX#t(jTq?YT5LwG|0z~#2~Do71Xk#`wQDqBaWl%t7fck}7#X$^Q(r>vaZAc>sE$HxPOgoN6j1NS<=G1joYIyVg`u>W)E{^*3s+(C*}`ad@r zaOqb%ySrDX3PqM&0iy=t^z>A$LhB2;Fa+@6P-jn(OPLcJ+15U(MOo%10u?4bU%-76 z$P9xI0E=%is&lLV`qlXW=Ny;+JDSs)Giao}j+I92#mq$<5sgrUl7b-yrEhZIs|%oc zQ=_ADa+;YsEUx|b$(AI~oXEKc2X?Biu64-j)EpcfL`46vj=>BX|Alu@CO|-Jj`Y)x z>L&%!_pu0P9>q1xnfUjnP|?eNqL%Oj%&AOg_RwUKXp*X(X+m*wrOf5Kg#KgQaUSHI pob0iBx7e +#include +#include +#include + +#include "common/QtAppGlobalSet.h" +#include "public/pub_utility_api/I18N.h" +#include "public/pub_logger_api/logger.h" +#include "sys_login_api/CLoginDlg.h" +#include "pub_widget/PubWidgetInit.h" +#include "SingleApplication.h" +#include "mainwindow.h" +#include "CSystemResources.h" +#include "pub_utility_api/FileUtil.h" +#include "CommonSheet.h" + +int main(int argc, char *argv[]) +{ + iot_common::doQtAppGlobalSet(); + + CSystemResources objRescource; + + //QApplication a(argc, argv); + SingleApplication a(argc, argv); + a.setWindowIcon(QIcon(":/debug_tool.ico")); + iot_public::StartLogSystem("BASE", "debug_tool"); + + const std::string strLanguage = std::move( iot_public::getCurLanguage()); + + std::string strFilePath = std::move( iot_public::CFileUtil::getPathOfResFile( "debug_tool/translate/" + strLanguage + ".qm")); + if ( !strFilePath.empty()) + { + auto *pTrans = new QTranslator; + pTrans->load( strFilePath.c_str()); + QApplication::installTranslator( pTrans ); + } + + iot_public::installTranslator(strLanguage); + + CommonSheet sheetStyle; + QString sheet; + if(sheetStyle.getSheet(sheet)) + { + qApp->setStyleSheet(sheet); + }else + { +// LOGERROR("MainWindow::initSheet():获取样式文件失败!"); + } + + //暂时取消国际化 +// std::string strRootPath =""; +// std::string strLanguage; +// QDir dir; + +// if(true == iot_public::initI18N(strRootPath,strLanguage)) +// { +// dir.setPath(QString::fromStdString(strRootPath)); +// dir.cd(QString::fromStdString(strLanguage)); +// dir.cd("debug_tool"); +// dir.cd("translate"); +// }else +// { +// qDebug()<<"国际化失败!"; +// } +// QTranslator translator; +// QString path = dir.absolutePath() + QDir::separator()+QString("en.qm"); +// translator.load(path); +// a.installTranslator(&translator); + QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8")); + //CLoginTool objLogin(&objRescource); + CLoginDlg dlg; + int ret = 0; + if (dlg.exec()) + { + int userId = -1; + QString userName = QString(); + QString userAlias = QString(); + dlg.getUserInfo(userId,userName,userAlias); + + int usergId = -1; + QString usergName; + int permId1; + dlg.getUserGroupInfo(usergId,usergName,permId1); + objRescource.initSystemResources(); + objRescource.setPermUserId(userId); + objRescource.setPermUserGroupId(usergId); + + MainWindow w(&objRescource); + QObject::connect( &a, &SingleApplication::instanceStarted, [ &w ]() { + w.show(); + w.showNormal(); + w.activateWindow(); + }); + w.show(); + ret = a.exec(); + } + iot_public::StopLogSystem(); + return ret; +} diff --git a/product/src/tools/debug_tool_v2/mainwindow.cpp b/product/src/tools/debug_tool_v2/mainwindow.cpp new file mode 100644 index 00000000..493a7353 --- /dev/null +++ b/product/src/tools/debug_tool_v2/mainwindow.cpp @@ -0,0 +1,307 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include "CommonSheet.h" +#include "pub_utility_api/FileUtil.h" + +MainWindow::MainWindow(CSystemResources *pSystemResources, QWidget *parent) : + CustomUiMainWindow(parent), + m_pSystemResources(pSystemResources), + m_pFessim(NULL), + m_pUpdateThread(NULL), + m_pEventFormShow(NULL), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + //setMinimumSize(1200,755); + setWindowTitle(tr("工程调试")); + initDebugTool(); + + setTitleWidget(ui->mainmenu); + connect(ui->stackedWidget,&QStackedWidget::currentChanged,this,&MainWindow::changeTab); + +} + +MainWindow::~MainWindow() +{ + //releaseResouce(); + if(m_pUpdateThread) + { + delete m_pUpdateThread; + m_pUpdateThread =NULL; + } + + delete ui; +} + + + +void MainWindow::initDebugTool() +{ + initLogSystem(); + initVariable(); + initView(); + connectSignalSlot(); + + m_pUpdateThread->start(); +} + + +void MainWindow::initVariable() +{ + m_pRealDataSelect = new CRealDataSelect; + m_pRealDataWatch = new CRealDataWatch; + m_pRealDatabaseSelect = new CRealDatabaseSelect; + m_pRealDatabaseShow = new CRealDatabaseShow; + m_pUpdateThread = new CUpdateThread; + m_pEventFormShow = new CEventFormShow; + m_pCommTool = new CCommTool; +} + +void MainWindow::initView() +{ + addRealData(); + addRealAlarm(); + addRealEvent(); + addHistoryEvent(); + addRealDataBase(); + addCommTool(); + + initMenuView(); + + ui->splitter_2->setSizes(QList()<<200<<900); + ui->splitter->setSizes(QList()<<200<<900); + + ui->memuForm->setButtonClicked(1); + ui->stackedWidget->setCurrentIndex(1); +} + +void MainWindow::initMenuView() +{ + QPushButton* btn; + + btn= new QPushButton(); + btn->setObjectName("btn_realdata"); + btn->setText(tr("实时数据")); + ui->memuForm->addToolBtn(btn,1); + + btn= new QPushButton(); + btn->setObjectName("btn_fessim"); + btn->setText(tr("前置数据")); + ui->memuForm->addToolBtn(btn,3); + + btn= new QPushButton(); + btn->setObjectName("btn_realdatabase"); + btn->setText(tr("实时库表")); + ui->memuForm->addToolBtn(btn,2); + + btn= new QPushButton(); + btn->setObjectName("btn_realalarm"); + btn->setText(tr("事件信息")); + ui->memuForm->addToolBtn(btn,0); + + btn = new QPushButton(); + btn->setObjectName("btn_commtool"); + btn->setText(tr("调试工具")); + ui->memuForm->addToolBtn(btn,4); +} + +void MainWindow::addRealData() +{ + QGridLayout *gridLayout = new QGridLayout(ui->groupBox_1); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pRealDataSelect, 0, 0, 1, 1); + m_pRealDataSelect->setSystemResources(m_pSystemResources); + m_pRealDataSelect->initSelect(); + + gridLayout = new QGridLayout(ui->groupBox_2); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pRealDataWatch, 0, 0, 1, 1); + m_pRealDataWatch->setSystemResources(m_pSystemResources); + m_pRealDataWatch->initWatch(); + ui->textEdit_status->setToolTip("具体状态"); + + m_pRealDataSelect->setRealDataWatch(m_pRealDataWatch); + +} +void MainWindow::addRealAlarm() +{ + QGridLayout *gridLayout = new QGridLayout(ui->stackedWidgetPage1); + ui->textEdit_status->setHidden(true); + ui->stackedWidgetPage1->setLayout(gridLayout); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pEventFormShow, 0, 0, 1, 1); + m_pEventFormShow->setSystemResources(m_pSystemResources); + m_pEventFormShow->initRealModel(); + //m_pEventFormShow->setSystemResources(m_pSystemResources); + // m_pAlarmFormShow->initSelect(); + +} +void MainWindow::addRealEvent() +{ + +} +void MainWindow::addHistoryEvent() +{ + +} +void MainWindow::addRealDataBase() +{ + QGridLayout *gridLayout4 = new QGridLayout(ui->groupBox_4); + gridLayout4->setSpacing(6); + gridLayout4->setContentsMargins(0, 0, 0, 0); + gridLayout4->addWidget(m_pRealDatabaseSelect, 0, 0, 1, 1); + m_pRealDatabaseSelect->initRealDb(m_pSystemResources); + + QGridLayout * gridLayout5 = new QGridLayout(ui->groupBox_5); + gridLayout5->setSpacing(6); + gridLayout5->setContentsMargins(0, 0, 0, 0); + gridLayout5->addWidget(m_pRealDatabaseShow, 0, 0, 1, 1); + m_pRealDatabaseShow->initRealDatabaseShow(m_pSystemResources); +} +void MainWindow::addNodeStatus() +{ +// QGridLayout *gridLayout = new QGridLayout(ui->tab_nodeStatus); +// gridLayout->setSpacing(6); +// gridLayout->setContentsMargins(0, 0, 0, 0); +// gridLayout->addWidget(m_pNodeStatus, 0, 0, 1, 1); +} + +void MainWindow::addFessim() +{ + QGridLayout *gridLayout = new QGridLayout(ui->stackedWidgetPage4); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pFessim, 0, 0, 1, 1); + m_pFessim->Init(); +} + +void MainWindow::addCommTool() +{ + QGridLayout *gridLayout = new QGridLayout(ui->stackedWidgetPage5); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(0, 0, 0, 0); + gridLayout->addWidget(m_pCommTool , 0 , 0 , 1 , 1); +} + +void MainWindow::initLogSystem() +{ +// QString app = QString::fromStdString(CN_AppName_BASE); +// iot_public::StartLogSystem(app.toStdString().c_str(),CN_ProcName_debug_tool.c_str()); +// LOGINFO("initLogSystem()成功!"); +} + +void MainWindow::initMsgBus() +{ + //< 初始化消息总线库 + if (!(iot_net::initMsgBus("debugToolAppName", "debugToolProcessName"))) + { + qDebug() << "Initialize message bus failed, exit !" << endl; + LOGERROR("Initialize message bus failed, exit !"); + return; + } + else + { + qDebug() << "Initialize message bus successed !" << endl; + LOGINFO("Initialize message bus successed !"); + + } + iot_service::CDpcdaForApp::initGlobalThread(); + return; +} + +void MainWindow::releaseResouce() +{ + iot_service::CDpcdaForApp::releaseGlobalThread(); + + //< 释放消息总线库 + iot_net::releaseMsgBus(); + + //< 停止日志系统 + //iot_public::StopLogSystem(); + +} + +void MainWindow::connectSignalSlot() +{ + qRegisterMetaType< QVector >("VectorAddPointInfoPtr"); + qRegisterMetaType("iot_idl::SRealTimeDataPkg"); + + connect(m_pRealDataSelect,&CRealDataSelect::signal_batchAddPoint, + m_pRealDataWatch,&CRealDataWatch::slot_batchAddPoint,Qt::UniqueConnection); + + connect(m_pUpdateThread,&CUpdateThread::signal_updatePntRealData, + m_pRealDataWatch,&CRealDataWatch::slot_updatePntRealData,Qt::UniqueConnection); + + connect(m_pRealDatabaseSelect,SIGNAL(signal_showTable(QString,QVector*,int,int,int,int,QMap,QString,QString)), + m_pRealDatabaseShow,SLOT(slot_showTable(QString,QVector*,int,int,int,int,QMap,QString,QString))); + connect(m_pRealDatabaseSelect,SIGNAL(signal_showOrHideColumn(int,int)), + m_pRealDatabaseShow,SLOT(slot_showOrHindColumn(int,int))); + connect(m_pRealDataWatch,SIGNAL(signal_selectTextEdit(QString ,QString , int )), + this,SLOT(slot_selectTextEdit(QString,QString, int ))); + connect(m_pRealDataWatch,SIGNAL(signal_paging()),m_pRealDataSelect,SLOT(slot_paging())); + connect(m_pRealDatabaseShow,SIGNAL(signal_selectTextEdit(QString)), + this,SLOT(slot_selectTextEdit(QString))); + + connect(ui->memuForm, SIGNAL(buttonClicked(int)),ui->stackedWidget, SLOT(setCurrentIndex(int))); + +} + +void MainWindow::changeTab(int index) +{ + switch (index) { + case 0: + ui->textEdit_status->setHidden(true); + break; + case 1: + ui->textEdit_status->setHidden(false); + break; + case 2:{ + ui->textEdit_status->setHidden(false); + break; + } + case 3: + { + ui->textEdit_status->setHidden(true); + if(m_pFessim == NULL) + { + m_pFessim = new CFessim; + addFessim(); + } + //此处判断是否连接 若连接 则不做处理 若断开状态 则直接调用连接 + if(!m_pFessim->isConnect()) + { + if(!m_pFessim->slot_connect()) + { + return ; + } + int index = m_pFessim->getCurrentIndex(); + m_pFessim->setActiveWindow(index); + } + break; + } + case 4:{ + ui->textEdit_status->setHidden(true); + break; + } + default: + break; + } +} + +void MainWindow::slot_selectTextEdit(QString allStatus, QString m_allName, int m_value) +{ + ui->textEdit_status->setReadOnly(true); + ui->textEdit_status->setText("当前标签为"+m_allName+", 值为" + +QString::number(m_value)+", 状态为" + +allStatus); + +} +void MainWindow::slot_selectTextEdit(QString allQString) +{ ui->textEdit_status->setReadOnly(true); + ui->textEdit_status->setText(allQString); +} diff --git a/product/src/tools/debug_tool_v2/mainwindow.h b/product/src/tools/debug_tool_v2/mainwindow.h new file mode 100644 index 00000000..655f0ac6 --- /dev/null +++ b/product/src/tools/debug_tool_v2/mainwindow.h @@ -0,0 +1,84 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "CFessim.h" +#include "CNodeStatus.h" +#include "CRealDatabaseSelect.h" +#include "CRealDatabaseShow.h" +#include "CRealDataControl.h" +#include "CRealDataSelect.h" +#include "CRealDataWatch.h" +#include "CSystemResources.h" +#include "CUpdateThread.h" +#include "CEventFormShow.h" +#include "pub_logger_api/logger.h" +#include "net_msg_bus_api/MsgBusApi.h" +#include "pub_widget/NcFramelessHelper.h" +#include "CCommTool.h" + +#include +#include +#include "pub_widget/CustomMainWindow.h" + +namespace Ui { +class MainWindow; +} + +class MainWindow : public CustomUiMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(CSystemResources *pSystemResources,QWidget *parent = 0); + ~MainWindow(); + + +private: + +// void loadStyle(); + void initDebugTool(); + + void initVariable(); + void initView(); + + void initMenuView(); + void addRealData(); + void addRealAlarm(); + void addRealEvent(); + void addHistoryEvent(); + void addRealDataBase(); + void addNodeStatus(); + void addFessim(); + void addCommTool(); + + void initMsgBus(); + void initLogSystem(); + + void releaseResouce(); + + void connectSignalSlot(); + +private slots: + void changeTab(int index); + void slot_selectTextEdit(QString allStatus,QString m_allName, int m_value); + void slot_selectTextEdit(QString allQString); + +private: + Ui::MainWindow *ui; + + CSystemResources * m_pSystemResources; + + CRealDataSelect * m_pRealDataSelect; + CRealDataWatch * m_pRealDataWatch; + CRealDatabaseSelect * m_pRealDatabaseSelect; + CRealDatabaseShow * m_pRealDatabaseShow; + CEventFormShow * m_pEventFormShow; + //CNodeStatus * m_pNodeStatus; + CFessim * m_pFessim; + CUpdateThread * m_pUpdateThread; + CCommTool * m_pCommTool; + +}; + +#endif // MAINWINDOW_H diff --git a/product/src/tools/debug_tool_v2/mainwindow.ui b/product/src/tools/debug_tool_v2/mainwindow.ui new file mode 100644 index 00000000..a2c15fa2 --- /dev/null +++ b/product/src/tools/debug_tool_v2/mainwindow.ui @@ -0,0 +1,180 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 测点选择 + + + + + 测点监控 + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 表选择 + + + + + 表内容 + + + + + + + + + + + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + + + + + + 0 + 0 + 800 + 23 + + + + + + + + WorkFrame + QWidget +
pub_widget/WorkFrame.h
+ 1 +
+ + MenuFrame + QWidget +
pub_widget/MenuFrame.h
+ 1 +
+
+ + +
diff --git a/product/src/tools/debug_tool_v2/mimondlg.cpp b/product/src/tools/debug_tool_v2/mimondlg.cpp new file mode 100644 index 00000000..52926b64 --- /dev/null +++ b/product/src/tools/debug_tool_v2/mimondlg.cpp @@ -0,0 +1,786 @@ +//2018-8-31 jacky 增加区间点刷新的非法字符判断 +#include "pub_widget/MessageBox.h" +#include +#include "mimondlg.h" +#include "ui_mimondlg.h" +#include +#include "CActiveWindow.h" +#include +#include +#include "CDataMng.h" + +using namespace std; +using namespace iot_idl; + +MiMonDlg::MiMonDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::MiMonDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint; + setWindowFlags(flags); +// setFixedSize(this->width(),this->height());//固定窗口大小 + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + m_CurrentRtuRow = -1; + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,150); + ui->PointTable->setColumnWidth(4,100); + ui->PointTable->setColumnWidth(5,100); + ui->PointTable->setColumnWidth(6,250); + ui->PointTable->setColumnWidth(7,80); + ui->PointTable->setColumnWidth(8,80); + ui->PointTable->setColumnWidth(9,120); + + m_StartIndex = -1; + m_EndIndex = -1; + + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + //ui->comboBox->setHidden(true); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&MiMonDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&MiMonDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); + getPoint(); +} + +MiMonDlg::~MiMonDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipMi!= NULL) + free((m_pRtuInfo+i)->pMi); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + delete ui; +} + +void MiMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void MiMonDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + + + ui->comboBox->setModel(model); +} + +void MiMonDlg::initSig() +{ + connect(this,&MiMonDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_miRtuInfoResp,this,&MiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_miParamResp,this,&MiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_miValueResp,this,&MiMonDlg::slot_OnRecvResp); +} + +void MiMonDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadMiInfo(m_CurrentRtuNo); +} + +void MiMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void MiMonDlg::OnRTURefresh() +{ + unsigned char data[40]; + + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + changePointValueRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_MI_RtuInfo); + objMsg.set_body("MT_FESDBG_MI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void MiMonDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_MI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void MiMonDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_MI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_MI_Param: + onRecvMiParamResp(strBody); + break; + case MT_FESDBG_MI_Value: + onRecvMiValueResp(strBody); + break; + default: + break; + } +} + +void MiMonDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("MiMonDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SMiMonRtu *pMiRtu = m_pRtuInfo + nIdx; + pMiRtu->RtuNo = pRtuInfo->rtu_no(); + pMiRtu->Used = pRtuInfo->used(); + strncpy(pMiRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pMiRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void MiMonDlg::onRecvMiParamResp(const string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("DiMonDlg::onRecvMiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SMiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocMiParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pMi == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getMiInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimMi *pMi = pRtu->pMi + pParam->pnt_no(); + pMi->param.PointNo = pParam->pnt_no(); + pMi->param.Used = pParam->used(); + memset(pMi->param.PointTagName,0,sizeof(pMi->param.PointTagName)); + strncpy(pMi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pMi->param.PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strAppTagName)); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,7,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + item->setTextAlignment(Qt::AlignCenter); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void MiMonDlg::onRecvMiValueResp(const string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("MiMonDlg::onRecvMiValueResp 反序列化失败"); + changePointValueRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + SMiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changePointValueRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_int_values()->size(); nIdx++) + { + FesDebugToolIntPntValue *pParam = recvMsg.mutable_int_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimMi *pMi = pRtu->pMi + pParam->pnt_no(); + pMi->value.PointNo = pParam->pnt_no(); + pMi->value.Value = pParam->value(); + pMi->value.Status = pParam->status(); + pMi->value.time = pParam->time(); + + updateData(pMi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void MiMonDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SMiMonRtu*)realloc(m_pRtuInfo,sizeof(SMiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SMiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SMiMonRtu*)malloc(sizeof(SMiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SMiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SMiMonRtu*)malloc(sizeof(SMiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SMiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void MiMonDlg::mallocMiParam(SMiMonRtu *pRtu, const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pMi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pMi = (SFesSimMi*)realloc(pRtu->pMi,sizeof(SFesSimMi)*pRtu->MaxPoints); + if (pRtu->pMi != NULL) + { + memset(pRtu->pMi, 0, sizeof(SFesSimMi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pMi = (SFesSimMi*)malloc(sizeof(SFesSimMi)*pRtu->MaxPoints); + if(pRtu->pMi != NULL) + { + memset(pRtu->pMi,0,sizeof(SFesSimMi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pMi == NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pMi = (SFesSimMi*)malloc(sizeof(SFesSimMi)*pRtu->MaxPoints); + if (pRtu->pMi != NULL) + { + memset(pRtu->pMi, 0, sizeof(SFesSimMi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void MiMonDlg::sendMiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_MI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + + +void MiMonDlg::OnRtuCellClick(int row, int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + OnPointValueRefresh(); + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayMiParam(m_CurrentRtuNo); + } +} + +SMiMonRtu* MiMonDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void MiMonDlg::DisplayMiParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + + initCombox(); + OnPointInfoRefresh(); +} + +void MiMonDlg::updateData(const SFesSimMiData &MiData) +{ + auto iter = m_dotColumnMap.find(MiData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(MiData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = MiData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + QTableWidgetItem *itemValue = new QTableWidgetItem(QString::number(MiData.Value)); + itemValue->setTextAlignment(Qt::AlignCenter); + + QTableWidgetItem *itemStatus = new QTableWidgetItem(getFesPointStatus(MiData.Status)); + itemStatus->setTextAlignment(Qt::AlignCenter); + if(MiData.Status != CN_FesValueUpdate) itemStatus->setTextColor(Qt::red) ; + + ui->PointTable->setItem(iter.value(),4,itemValue); + ui->PointTable->setItem(iter.value(),5,itemStatus); + ui->PointTable->setItem(iter.value(),9,new QTableWidgetItem(tStr)); +} + +void MiMonDlg::changePointValueRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + m_RefreshTimer->stop(); + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +bool MiMonDlg::initPointBrushData() +{ + QString devTag = ui->comboBox->currentData(Qt::UserRole+1).toString(); + + if(devTag == "") + { + return false; + }else if(devTag == "ALL") + { + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + m_RefreshMode = 1; //section + const RtuMaxAndMinPointNo &rtuMaxMinNo = CDataMng::instance()->getMiMaxMinNoRef(); + auto it = rtuMaxMinNo.find(m_CurrentRtuNo); + if(it == rtuMaxMinNo.end()) + { + LOGERROR("未找到rtu:[%d],刷新所有数据!",m_CurrentRtuNo); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + const MaxAndMinPointNo &devMap = it.value(); + auto itor = devMap.find(devTag); + if(itor == devMap.end()) + { + LOGERROR("未找到dev:[%s],刷新所有数据!",devTag.toStdString().c_str()); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + SFESDEVMAXANDMINPOINTNO maxminNo = itor.value(); + m_StartIndex = maxminNo.minPointNo; + m_EndIndex = maxminNo.maxPointNo; + } + } + } + LOGTRACE("刷新设备[%s]的数据!",devTag.toStdString().c_str()); + return true; +} + +void MiMonDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + m_RefreshTimer->start(1000); + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendMiValueReqMsg(); + } +} + + +void MiMonDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + m_RefreshTimer->start(1000); + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendMiValueReqMsg(); + } + else + { + changePointValueRefreshBtnToStop(); + } +} + +void MiMonDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void MiMonDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void MiMonDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changePointValueRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + + sendMiValueReqMsg(); +} diff --git a/product/src/tools/debug_tool_v2/mimondlg.h b/product/src/tools/debug_tool_v2/mimondlg.h new file mode 100644 index 00000000..2e722eca --- /dev/null +++ b/product/src/tools/debug_tool_v2/mimondlg.h @@ -0,0 +1,93 @@ +#ifndef MIMONDLG_H +#define MIMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "CSystemResources.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class MiMonDlg; +} + +class MiMonDlg : public QDialog +{ + Q_OBJECT + +public: + explicit MiMonDlg(int windowId, QWidget *parent ); + ~MiMonDlg(); + +public: + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvMiParamResp(const std::string &strBody); + void onRecvMiValueResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocMiParam(SMiMonRtu *pRtu,const int nSize); + void sendMiValueReqMsg(); + +private: + Ui::MiMonDlg *ui; + QTimeZone m_tz; + SMiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayMiParam(int RtuNo); + + void updateData(const SFesSimMiData & MiData); + + void changePointValueRefreshBtnToStop(); + + bool initPointBrushData(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SMiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // MIMONDLG_H diff --git a/product/src/tools/debug_tool_v2/mimondlg.ui b/product/src/tools/debug_tool_v2/mimondlg.ui new file mode 100644 index 00000000..b37cbe99 --- /dev/null +++ b/product/src/tools/debug_tool_v2/mimondlg.ui @@ -0,0 +1,286 @@ + + + MiMonDlg + + + + 0 + 0 + 804 + 417 + + + + Dialog + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 1 + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + RTU名称 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 点值 + + + + + 点状态 + + + + + 后台标签 + + + + + 远动号 + + + + + 使用标志 + + + + + 时间 + + + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/pimondlg.cpp b/product/src/tools/debug_tool_v2/pimondlg.cpp new file mode 100644 index 00000000..a6cf8c65 --- /dev/null +++ b/product/src/tools/debug_tool_v2/pimondlg.cpp @@ -0,0 +1,791 @@ +//2018-8-31 jacky 增加区间点刷新的非法字符判断 +#include "pub_widget/MessageBox.h" +#include +#include "pimondlg.h" +#include "ui_pimondlg.h" +#include +#include +#include +#include "pub_logger_api/logger.h" +#include +#include +#include "CDataMng.h" + +using namespace std; +using namespace iot_idl; + +PiMonDlg::PiMonDlg(int windowId,QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::PiMonDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint; + setWindowFlags(flags); +// setFixedSize(this->width(),this->height());//固定窗口大小 + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,150); + ui->PointTable->setColumnWidth(4,100); + ui->PointTable->setColumnWidth(5,100); + ui->PointTable->setColumnWidth(6,250); + ui->PointTable->setColumnWidth(7,80); + ui->PointTable->setColumnWidth(8,80); + ui->PointTable->setColumnWidth(9,120); + + m_StartIndex = -1; + m_EndIndex = -1; + + m_order = Qt::AscendingOrder; + m_bCanSort = false; + + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&PiMonDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&PiMonDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); +} + +PiMonDlg::~PiMonDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipAcc!= NULL) + free((m_pRtuInfo+i)->pAcc); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + delete ui; +} + + +void PiMonDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void PiMonDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + ui->comboBox->setModel(model); +} + +void PiMonDlg::initSig() +{ + connect(this,&PiMonDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_accRtuInfoResp,this,&PiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_accParamResp,this,&PiMonDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_accValueResp,this,&PiMonDlg::slot_OnRecvResp); +} + +void PiMonDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadAccInfo(m_CurrentRtuNo); +} + +void PiMonDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void PiMonDlg::OnRTURefresh() +{ + unsigned char data[40]; + + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + changePointValueRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_ACC_RtuInfo); + objMsg.set_body("MT_FESDBG_ACC_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + + +void PiMonDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_ACC_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void PiMonDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_ACC_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_ACC_Param: + onRecvAccParamResp(strBody); + break; + case MT_FESDBG_ACC_Value: + onRecvAccValueResp(strBody); + break; + default: + break; + } +} + +void PiMonDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("PiMonDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SAccMonRtu *pAccRtu = m_pRtuInfo + nIdx; + pAccRtu->RtuNo = pRtuInfo->rtu_no(); + pAccRtu->Used = pRtuInfo->used(); + strncpy(pAccRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pAccRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void PiMonDlg::onRecvAccParamResp(const string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("DiMonDlg::onRecvDiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SAccMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocAccParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pAcc == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getAccInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimAcc *pAcc = pRtu->pAcc + pParam->pnt_no(); + pAcc->param.PointNo = pParam->pnt_no(); + pAcc->param.Used = pParam->used(); + memset(pAcc->param.PointTagName,0,sizeof(pAcc->param.PointTagName)); + strncpy(pAcc->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pAcc->param.PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strAppTagName)); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,7,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + item->setTextAlignment(Qt::AlignCenter); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void PiMonDlg::onRecvAccValueResp(const string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("PiMonDlg::onRecvAccValueResp 反序列化失败"); + changePointValueRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + SAccMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changePointValueRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_double_values()->size(); nIdx++) + { + FesDebugToolDoublePntValue *pParam = recvMsg.mutable_double_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimAcc *pAcc = pRtu->pAcc + pParam->pnt_no(); + pAcc->value.PointNo = pParam->pnt_no(); + pAcc->value.Value = pParam->value(); + pAcc->value.Status = pParam->status(); + pAcc->value.time = pParam->time(); + + updateData(pAcc->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void PiMonDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SAccMonRtu*)realloc(m_pRtuInfo,sizeof(SAccMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAccMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SAccMonRtu*)malloc(sizeof(SAccMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAccMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SAccMonRtu*)malloc(sizeof(SAccMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAccMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void PiMonDlg::mallocAccParam(SAccMonRtu *pRtu, const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pAcc != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pAcc = (SFesSimAcc*)realloc(pRtu->pAcc,sizeof(SFesSimAcc)*pRtu->MaxPoints); + if (pRtu->pAcc != NULL) + { + memset(pRtu->pAcc, 0, sizeof(SFesSimAcc)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pAcc = (SFesSimAcc*)malloc(sizeof(SFesSimAcc)*pRtu->MaxPoints); + if(pRtu->pAcc != NULL) + { + memset(pRtu->pAcc,0,sizeof(SFesSimAcc)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pAcc == NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pAcc = (SFesSimAcc*)malloc(sizeof(SFesSimAcc)*pRtu->MaxPoints); + if (pRtu->pAcc != NULL) + { + memset(pRtu->pAcc, 0, sizeof(SFesSimAcc)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void PiMonDlg::sendAccValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_ACC_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void PiMonDlg::OnRtuCellClick(int row, int column) +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayPiParam(m_CurrentRtuNo); + } +} + +SAccMonRtu* PiMonDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void PiMonDlg::DisplayPiParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + initCombox(); + OnPointInfoRefresh(); +} + +void PiMonDlg::updateData(const SFesSimAccData &piData) +{ + auto iter = m_dotColumnMap.find(piData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(piData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = piData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + QTableWidgetItem *itemValue = new QTableWidgetItem(QString::number(piData.Value)); + itemValue->setTextAlignment(Qt::AlignCenter); + + QTableWidgetItem *itemStatus = new QTableWidgetItem(getFesPointStatus(piData.Status)); + itemStatus->setTextAlignment(Qt::AlignCenter); + if(piData.Status != CN_FesValueUpdate) itemStatus->setTextColor(Qt::red) ; + + ui->PointTable->setItem(iter.value(),4,itemValue); + ui->PointTable->setItem(iter.value(),5,itemStatus); + ui->PointTable->setItem(iter.value(),9,new QTableWidgetItem(tStr)); +} + +void PiMonDlg::changePointValueRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +bool PiMonDlg::initPointBrushData() +{ + QString devTag = ui->comboBox->currentData(Qt::UserRole+1).toString(); + + if(devTag == "") + { + return false; + }else if(devTag == "ALL") + { + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + m_RefreshMode = 1; //section + const RtuMaxAndMinPointNo &rtuMaxMinNo = CDataMng::instance()->getAccMaxMinNoRef(); + auto it = rtuMaxMinNo.find(m_CurrentRtuNo); + if(it == rtuMaxMinNo.end()) + { + LOGERROR("未找到rtu:[%d],刷新所有数据!",m_CurrentRtuNo); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + const MaxAndMinPointNo &devMap = it.value(); + auto itor = devMap.find(devTag); + if(itor == devMap.end()) + { + LOGERROR("未找到dev:[%s],刷新所有数据!",devTag.toStdString().c_str()); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + SFESDEVMAXANDMINPOINTNO maxminNo = itor.value(); + m_StartIndex = maxminNo.minPointNo; + m_EndIndex = maxminNo.maxPointNo; + } + } + } + LOGTRACE("刷新设备[%s]的数据!",devTag.toStdString().c_str()); + return true; +} + +void PiMonDlg::OnPointValueStartRefresh() +{ + unsigned char data[40]; + + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + m_RefreshTimer->start(1000); + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAccValueReqMsg(); + } +} + + +void PiMonDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + m_RefreshTimer->start(1000); + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAccValueReqMsg(); + } + else + { + changePointValueRefreshBtnToStop(); + } +} + +void PiMonDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void PiMonDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void PiMonDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changePointValueRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(!isEndOneRefresh) + { + return; + } + isEndOneRefresh = false; + + sendAccValueReqMsg(); +} diff --git a/product/src/tools/debug_tool_v2/pimondlg.h b/product/src/tools/debug_tool_v2/pimondlg.h new file mode 100644 index 00000000..2d113848 --- /dev/null +++ b/product/src/tools/debug_tool_v2/pimondlg.h @@ -0,0 +1,87 @@ +#ifndef PIMONDLG_H +#define PIMONDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" + +class PiMonDlg : public QDialog +{ + Q_OBJECT + +public: + explicit PiMonDlg(int windowId,QWidget *parent ); + ~PiMonDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvAccParamResp(const std::string &strBody); + void onRecvAccValueResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocAccParam(SAccMonRtu *pRtu,const int nSize); + void sendAccValueReqMsg(); + +private: + Ui::PiMonDlg *ui; + QTimeZone m_tz; + SAccMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayPiParam(int RtuNo); + + void updateData(const SFesSimAccData & piData); + + void changePointValueRefreshBtnToStop(); + + bool initPointBrushData(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SAccMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // PIMONDLG_H diff --git a/product/src/tools/debug_tool_v2/pimondlg.ui b/product/src/tools/debug_tool_v2/pimondlg.ui new file mode 100644 index 00000000..b10e15b8 --- /dev/null +++ b/product/src/tools/debug_tool_v2/pimondlg.ui @@ -0,0 +1,286 @@ + + + PiMonDlg + + + + 0 + 0 + 857 + 476 + + + + Dialog + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + 1 + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + RTU名称 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 点值 + + + + + 点状态 + + + + + 后台标签 + + + + + 远动号 + + + + + 使用标志 + + + + + 时间 + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/rtuparamdlg.cpp b/product/src/tools/debug_tool_v2/rtuparamdlg.cpp new file mode 100644 index 00000000..78ea51e8 --- /dev/null +++ b/product/src/tools/debug_tool_v2/rtuparamdlg.cpp @@ -0,0 +1,139 @@ +#include "pub_widget/MessageBox.h" +#include "rtuparamdlg.h" +#include "ui_rtuparamdlg.h" +#include "CDataMng.h" +#include "FesDebugTool.pb.h" + +using namespace std; +using namespace iot_idl; + +RtuParamDlg::RtuParamDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::RtuParamDlg) +{ + ui->setupUi(this); + + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + + m_ConnectFlag=CN_CommDisconnect; + + connect(ui->RefreshButton,SIGNAL(clicked()),this,SLOT(OnRefresh())); + initSig(); +} + +RtuParamDlg::~RtuParamDlg() +{ + delete ui; +} + +void RtuParamDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void RtuParamDlg::initSig() +{ +// connect(CDataMng::instance(),&CDataMng::RtuParamSig,this,&RtuParamDlg::OnRecvCmd); +// connect(this,&RtuParamDlg::SendCmdSig,CDataMng::instance(),&CDataMng::SendCmdSig); + + connect(CDataMng::instance(),&CDataMng::signal_rtuParamResp,this,&RtuParamDlg::slot_OnRecvResp); + connect(this,&RtuParamDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); +} + +void RtuParamDlg::OnRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取RTU数据。请连接FES系统!")); + return; + } + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_RtuParam); + objMsg.set_body("MT_FESDBG_RtuParam"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void RtuParamDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_RtuParam: + onRecvRtuParamResp(strBody); + break; + default: + break; + } +} + +void RtuParamDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event ->key()) + { + case Qt::Key_Escape: + break; + default: + QDialog::keyPressEvent(event); + } +} + +void RtuParamDlg::onRecvRtuParamResp(const string &strBody) +{ + ui->ParamTable->setRowCount(0); + ui->ParamTable->clearContents(); + + FesDebugToolRtuParamRepMsg repMsg; + if(!repMsg.ParseFromString(strBody)) + { + LOGERROR("ChanParamDlg:反序列化失败"); + return; + } + + int nCount = repMsg.rtu_param().size(); + for(int nRow = 0; nRow < nCount; nRow++) + { + insertRtuParamToTable(nRow,repMsg.mutable_rtu_param(nRow)); + } +} + +void RtuParamDlg::insertRtuParamToTable(const int nRow, FesDebugToolRtuParam *pRtuParam) +{ + ui->ParamTable->insertRow(nRow); + + ui->ParamTable->setItem(nRow,0,new QTableWidgetItem(QString::number(pRtuParam->rtu_no()))); + ui->ParamTable->setItem(nRow,1,new QTableWidgetItem(QString(pRtuParam->rtu_desc().c_str()))); + if(pRtuParam->used()) + { + ui->ParamTable->setItem(nRow,2,new QTableWidgetItem(tr("使用"))); + } + else + { + ui->ParamTable->setItem(nRow,2,new QTableWidgetItem(tr("未使用"))); + } + + if(pRtuParam->rtu_status() == CN_FesRtuNotUsed) + { + ui->ParamTable->setItem(nRow,3,new QTableWidgetItem(tr("未使用"))); + } + else if(pRtuParam->rtu_status() == CN_FesRtuNormal) + { + ui->ParamTable->setItem(nRow,3,new QTableWidgetItem(tr("通信正常"))); + } + else if(pRtuParam->rtu_status() == CN_FesRtuComDown) + { + ui->ParamTable->setItem(nRow,3,new QTableWidgetItem(tr("通信中断"))); + } + + ui->ParamTable->setItem(nRow,4,new QTableWidgetItem(QString::number(pRtuParam->rtu_addr()))); + ui->ParamTable->setItem(nRow,5,new QTableWidgetItem(QString::number(pRtuParam->chan_no()))); + ui->ParamTable->setItem(nRow,6,new QTableWidgetItem(QString::number(pRtuParam->max_ai_num()))); + ui->ParamTable->setItem(nRow,7,new QTableWidgetItem(QString::number(pRtuParam->max_di_num()))); + ui->ParamTable->setItem(nRow,8,new QTableWidgetItem(QString::number(pRtuParam->max_acc_num()))); + ui->ParamTable->setItem(nRow,9,new QTableWidgetItem(QString::number(pRtuParam->recv_fail_limit()))); +} diff --git a/product/src/tools/debug_tool_v2/rtuparamdlg.h b/product/src/tools/debug_tool_v2/rtuparamdlg.h new file mode 100644 index 00000000..f847eb75 --- /dev/null +++ b/product/src/tools/debug_tool_v2/rtuparamdlg.h @@ -0,0 +1,45 @@ +#ifndef RTUPARAMDLG_H +#define RTUPARAMDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include "CSystemResources.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "ComProtocolThread.h" + +namespace Ui { +class RtuParamDlg; +} + +class RtuParamDlg : public QDialog +{ + Q_OBJECT + +public: + explicit RtuParamDlg(int windowId,QWidget *parent ); + ~RtuParamDlg(); + + int m_ConnectFlag; //连接成功标志 + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); +public slots: + void OnRefresh(); + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + void keyPressEvent(QKeyEvent *event) ; + +signals: + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuParamResp(const std::string &strBody); + void insertRtuParamToTable(const int nRow,iot_idl::FesDebugToolRtuParam *pRtuParam); + +private: + Ui::RtuParamDlg *ui; + int m_nWindowId; +}; + +#endif // RTUPARAMDLG_H diff --git a/product/src/tools/debug_tool_v2/rtuparamdlg.ui b/product/src/tools/debug_tool_v2/rtuparamdlg.ui new file mode 100644 index 00000000..0302f094 --- /dev/null +++ b/product/src/tools/debug_tool_v2/rtuparamdlg.ui @@ -0,0 +1,134 @@ + + + RtuParamDlg + + + + 0 + 0 + 588 + 328 + + + + RTU参数 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 描述 + + + + + 使用标志 + + + + + 当前状态 + + + + + RTU地址 + + + + + 通道号 + + + + + 模拟量个数 + + + + + 数字量个数 + + + + + 累积量个数 + + + + + 失败计数限值 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/simaidlg.cpp b/product/src/tools/debug_tool_v2/simaidlg.cpp new file mode 100644 index 00000000..968d21d2 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simaidlg.cpp @@ -0,0 +1,1042 @@ +//2018-8-31 jacky 增加区间点刷新的非法字符判断 +#include "pub_widget/MessageBox.h" +#include +#include "simaidlg.h" +#include "ui_simaidlg.h" +#include +#include +#include +#include +#include "CDataMng.h" + +using namespace std; +using namespace iot_idl; + +SimAiDlg::SimAiDlg(int windowId,QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SimAiDlg) +{ + ui->setupUi(this); + + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |= Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentPointNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + //ui->RTUTable->setColumnWidth(2,120); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,150); + ui->PointTable->setColumnWidth(4,100); + ui->PointTable->setColumnWidth(5,100); + ui->PointTable->setColumnWidth(6,250); + ui->PointTable->setColumnWidth(7,80); + ui->PointTable->setColumnWidth(8,80); + ui->PointTable->setColumnWidth(9,120); + + m_StartIndex = -1; + m_EndIndex = -1; + + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_CurrentAiFlag = true; + ui->CurrentPointButton->setChecked(m_CurrentAiFlag); + + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->PointTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnPointCellClick(int,int))); + connect(ui->SetButton ,SIGNAL(clicked()),this,SLOT(OnSetValue())); + connect(ui->LineSetButton ,SIGNAL(clicked()),this,SLOT(OnLineSet())); + connect(ui->RandSetButton ,SIGNAL(clicked()),this,SLOT(OnRandSet())); + connect(ui->StopSetButton ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + connect(ui->StopSetButton2 ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + connect(ui->StopSetButton3 ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + //ui->comboBox->setHidden(true); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&SimAiDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&SimAiDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); +// ui->PointTable->setSortingEnabled(true); +// ui->PointTable->horizontalHeader()->setSortIndicator(0,Qt::AscendingOrder); + + initSig(); +} + +SimAiDlg::~SimAiDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipAi!= NULL) + free((m_pRtuInfo+i)->pAi); + } + free(m_pRtuInfo); + } + + delete ui; +} + +void SimAiDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SimAiDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + + ui->comboBox->setModel(model); +} + +void SimAiDlg::initSig() +{ + connect(this,&SimAiDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_simAiRtuInfoResp,this,&SimAiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAiParamResp,this,&SimAiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAiValueResp,this,&SimAiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAiStartSimResp,this,&SimAiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAiStopSimResp,this,&SimAiDlg::slot_OnRecvResp); +} + +void SimAiDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SimAiDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + m_CurrentPointNo = -1; + m_CurrentRtuRow = -1; + m_CurrentRtuNo = -1; + changePointValueRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimAI_RtuInfo); + objMsg.set_body("MT_FESDBG_SimAI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimAiDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimAI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimAiDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_SimAI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_SimAI_Param: + onRecvAiParamResp(strBody); + break; + case MT_FESDBG_SimAI_Value: + onRecvAiValueResp(strBody); + break; + case MT_FESDBG_SimAI_StartSim: + onRecvStartSimResp(strBody); + break; + case MT_FESDBG_SimAI_StopSim: + onRecvStopSimResp(strBody); + break; + default: + break; + } +} + +void SimAiDlg::onRecvRtuInfoResp(const string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("SimAiDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SAiMonRtu *pAiRtu = m_pRtuInfo + nIdx; + pAiRtu->RtuNo = pRtuInfo->rtu_no(); + pAiRtu->Used = pRtuInfo->used(); + strncpy(pAiRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pAiRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void SimAiDlg::onRecvAiParamResp(const string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SimAiDlg::onRecvAiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SAiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocAiParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pAi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getAiInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimAi *pAi = pRtu->pAi + pParam->pnt_no(); + pAi->param.PointNo = pParam->pnt_no(); + pAi->param.Used = pParam->used(); + memset(pAi->param.PointTagName,0,sizeof(pAi->param.PointTagName)); + strncpy(pAi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pAi->param.PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strAppTagName)); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,7,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + item->setTextAlignment(Qt::AlignCenter); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void SimAiDlg::onRecvAiValueResp(const string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("SimAiDlg::onRecvAiDataResp 反序列化失败"); + changePointValueRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + SAiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changePointValueRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_float_values()->size(); nIdx++) + { + FesDebugToolFloatPntValue *pParam = recvMsg.mutable_float_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimAi *pAi = pRtu->pAi + pParam->pnt_no(); + pAi->value.PointNo = pParam->pnt_no(); + pAi->value.Value = pParam->value(); + pAi->value.Status = pParam->status(); + pAi->value.time = pParam->time(); + + updateData(pAi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void SimAiDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SAiMonRtu*)realloc(m_pRtuInfo,sizeof(SAiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SAiMonRtu*)malloc(sizeof(SAiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SAiMonRtu*)malloc(sizeof(SAiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void SimAiDlg::mallocAiParam(SAiMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pAi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pAi = (SFesSimAi*)realloc(pRtu->pAi,sizeof(SFesSimAi)*pRtu->MaxPoints); + if (pRtu->pAi != NULL) + { + memset(pRtu->pAi, 0, sizeof(SFesSimAi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pAi = (SFesSimAi*)malloc(sizeof(SFesSimAi)*pRtu->MaxPoints); + if(pRtu->pAi != NULL) + { + memset(pRtu->pAi,0,sizeof(SFesSimAi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pAi==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pAi = (SFesSimAi*)malloc(sizeof(SFesSimAi)*pRtu->MaxPoints); + if (pRtu->pAi != NULL) + { + memset(pRtu->pAi, 0, sizeof(SFesSimAi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void SimAiDlg::sendAiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimAI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimAiDlg::OnRtuCellClick(int row,int column) +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + m_CurrentPointNo = -1; + + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayAiParam(m_CurrentRtuNo); + } +} + +void SimAiDlg::OnPointCellClick(int row,int column) +{ + Q_UNUSED(column); + m_CurrentPointRow = row; + QString RtuStr = ui->PointTable->item(m_CurrentPointRow,0)->text(); + bool ok; + m_CurrentPointNo=RtuStr.toInt(&ok,10); + + if(ok==false) + { + m_CurrentPointNo = -1; + } +} + +SAiMonRtu* SimAiDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void SimAiDlg::DisplayAiParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + + initCombox(); + OnPointInfoRefresh(); +} + +void SimAiDlg::updateData(const SFesSimAiData &aiData) +{ + auto iter = m_dotColumnMap.find(aiData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(aiData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = aiData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + QTableWidgetItem *itemValue = new QTableWidgetItem(QString::number(aiData.Value) ); + itemValue->setTextAlignment(Qt::AlignCenter); + + QTableWidgetItem *itemStatus = new QTableWidgetItem(getFesPointStatus(aiData.Status) ); + itemStatus->setTextAlignment(Qt::AlignCenter); + if(aiData.Status != CN_FesValueUpdate) itemStatus->setTextColor(Qt::red) ; + + ui->PointTable->setItem(iter.value(),4,itemValue); + ui->PointTable->setItem(iter.value(),5,itemStatus); + ui->PointTable->setItem(iter.value(),9,new QTableWidgetItem(tStr)); +} + +void SimAiDlg::changePointValueRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +bool SimAiDlg::initPointBrushData() +{ + QString devTag = ui->comboBox->currentData(Qt::UserRole+1).toString(); + + if(devTag == "") + { + return false; + }else if(devTag == "ALL") + { + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + m_RefreshMode = 1; //section + + const RtuMaxAndMinPointNo &rtuMaxMinNo = CDataMng::instance()->getAiMaxMinNoRef(); + auto it = rtuMaxMinNo.find(m_CurrentRtuNo); + if(it == rtuMaxMinNo.end()) + { + LOGERROR("未找到rtu:[%d],刷新所有数据!",m_CurrentRtuNo); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + const MaxAndMinPointNo &devMap = it.value(); + auto itor = devMap.find(devTag); + if(itor == devMap.end()) + { + LOGERROR("未找到dev:[%s],刷新所有数据!",devTag.toStdString().c_str()); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + SFESDEVMAXANDMINPOINTNO maxminNo = itor.value(); + m_StartIndex = maxminNo.minPointNo; + m_EndIndex = maxminNo.maxPointNo; + } + } + } + LOGTRACE("刷新设备[%s]的数据!",devTag.toStdString().c_str()); + return true; +} + +void SimAiDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAiValueReqMsg(); + } +} + + +void SimAiDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAiValueReqMsg(); + } + else + { + changePointValueRefreshBtnToStop(); + } +} + +void SimAiDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changePointValueRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + + sendAiValueReqMsg(); +} + +void SimAiDlg::OnSetValue() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_ValueSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)&&(m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.mutable_value_set_param()->set_value(ui->AiValueEdit->text().toFloat()); + reqMsg.set_status(ui->AiStatusEdit->text().toUInt()); + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimAI_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimAiDlg::OnLineSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_LineSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint) && (m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.mutable_line_set_param()->set_min_value(ui->MinValueEdit->text().toFloat()); + reqMsg.mutable_line_set_param()->set_max_value(ui->MaxValueEdit->text().toFloat()); + reqMsg.mutable_line_set_param()->set_step_value(ui->StepValueEdit->text().toFloat()); + reqMsg.mutable_line_set_param()->set_period(ui->ChangeTimeEdit->text().toInt()); + + + if(reqMsg.mutable_line_set_param()->min_value() >= reqMsg.mutable_line_set_param()->max_value()) + { + N_MessageBox::warning(this,tr("告警"),tr("最大值小于最小值")); + return; + } + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimAI_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimAiDlg::OnRandSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_RandSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint) && (m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.mutable_rand_set_param()->set_period(10); //暂时写死10秒变化一次 + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimAI_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimAiDlg::OnStopSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimAI_StopSim); + sendMsg.set_body("MT_FESDBG_SimAI_StopSim"); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimAiDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void SimAiDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void SimAiDlg::onRecvStartSimResp(const string &strBody) +{ + FesDebugToolValueSimSetRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("SimAiDlg::onRecvStartSimResp 反序列化失败"); + return; + } + + switch(recvMsg.sim_mode()) + { + case MT_FESDBG_SM_ValueSet: + N_MessageBox::warning(this,tr("信息"),tr("固定设置成功!")); + break; + case MT_FESDBG_SM_LineSet: + N_MessageBox::warning(this,tr("信息"),tr("线性设置成功!")); + break; + case MT_FESDBG_SM_RandSet: + N_MessageBox::warning(this,tr("信息"),tr("随机设置成功!")); + break; + default: + break; + } +} + +void SimAiDlg::onRecvStopSimResp(const string &strBody) +{ + Q_UNUSED(strBody); + //N_MessageBox::warning(this,tr("信息"),tr("停止设置成功!")); +} + +void SimAiDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadAiInfo(m_CurrentRtuNo); +} diff --git a/product/src/tools/debug_tool_v2/simaidlg.h b/product/src/tools/debug_tool_v2/simaidlg.h new file mode 100644 index 00000000..d9d1b81d --- /dev/null +++ b/product/src/tools/debug_tool_v2/simaidlg.h @@ -0,0 +1,106 @@ +#ifndef SIMAIDLG_H +#define SIMAIDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" + +namespace Ui { +class SimAiDlg; +} + + +class SimAiDlg : public QDialog +{ + Q_OBJECT + +public: + explicit SimAiDlg(int windowId,QWidget *parent ); + ~SimAiDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void getPoint(); + void initSig(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointCellClick(int row,int column); + void OnPointValueRefresh(); + + //固定设置 + void OnSetValue(); + void OnLineSet(); + void OnRandSet(); + void OnStopSet(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvAiParamResp(const std::string &strBody); + void onRecvAiValueResp(const std::string &strBody); + void onRecvStartSimResp(const std::string &strBody); + void onRecvStopSimResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocAiParam(SAiMonRtu *pRtu,const int nSize); + void sendAiValueReqMsg(); + +private: + Ui::SimAiDlg *ui; + SAiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayAiParam(int RtuNo); + + void updateData(const SFesSimAiData & aiData); + + void changePointValueRefreshBtnToStop(); + + bool initPointBrushData(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SAiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_CurrentPointRow; + int m_CurrentPointNo; + bool m_CurrentAiFlag; + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + + bool isEndOneRefresh; +}; + +#endif // SIMAIDLG_H diff --git a/product/src/tools/debug_tool_v2/simaidlg.ui b/product/src/tools/debug_tool_v2/simaidlg.ui new file mode 100644 index 00000000..78470c9a --- /dev/null +++ b/product/src/tools/debug_tool_v2/simaidlg.ui @@ -0,0 +1,918 @@ + + + SimAiDlg + + + + 0 + 0 + 983 + 627 + + + + + 0 + 0 + + + + 模拟量仿真 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 点值 + + + + + 点状态 + + + + + 后台标签 + + + + + 远动号 + + + + + 使用标志 + + + + + 时间 + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + QGroupBox { + border: 1px solid gray; + margin-top: 1ex; /* leave space at the top for the title */ + } + QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top center; + } + + + + + + Qt::AlignJustify|Qt::AlignVCenter + + + + 15 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 当前测点 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 当前RTU + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 所有RTU + + + + + + + + + + + + + 0 + 130 + + + + + 16777215 + 130 + + + + 0 + + + + 固定置数 + + + + 0 + + + 12 + + + 0 + + + 0 + + + 6 + + + + + 0 + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + 值: + + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + 点状态: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 固定设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 线性置数 + + + + 0 + + + 12 + + + 0 + + + 0 + + + 6 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 线性设置 + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 步长值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 周期秒: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 0 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 最小值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 最大值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 随机置数 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 随机设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/simaodlg.cpp b/product/src/tools/debug_tool_v2/simaodlg.cpp new file mode 100644 index 00000000..e9e2e965 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simaodlg.cpp @@ -0,0 +1,605 @@ +#include "pub_widget/MessageBox.h" +#include +#include "simaodlg.h" +#include "ui_simaodlg.h" +#include +#include +#include "CDataMng.h" +#include "pub_utility_api/TimeUtil.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +SimAoDlg::SimAoDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SimAoDlg) +{ + ui->setupUi(this); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentPointNo = -1; + m_CurrentRtuRow = -1; + m_StartIndex = 0; + m_EndIndex = 0; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,200); + ui->PointTable->setColumnWidth(4,80); + ui->PointTable->setColumnWidth(5,80); + + ui->SelectButton->setChecked(true); + m_order = Qt::AscendingOrder; + m_bCanSort = false; + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->PointTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnPointCellClick(int,int))); + connect(ui->ControlButton,SIGNAL(clicked()),this,SLOT(OnControl())); + + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&SimAoDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&SimAoDlg::sort,Qt::QueuedConnection); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); +} + +SimAoDlg::~SimAoDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipAo!= NULL) + free((m_pRtuInfo+i)->pAo); + } + free(m_pRtuInfo); + } + delete ui; +} + +void SimAoDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SimAoDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + ui->comboBox->setModel(model); +} + +void SimAoDlg::initSig() +{ + connect(this,&SimAoDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_simAoRtuInfoResp,this,&SimAoDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAoParamResp,this,&SimAoDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAoControlResp,this,&SimAoDlg::slot_OnRecvResp); +} + +void SimAoDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadAoInfo(m_CurrentRtuNo); +} + +void SimAoDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SimAoDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentPointNo = -1; + m_CurrentRtuNo = -1; + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimAO_RtuInfo); + objMsg.set_body("MT_FESDBG_SimAO_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimAoDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimAO_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimAoDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_SimAO_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_SimAO_Param: + onRecvAoParamResp(strBody); + break; + case MT_FESDBG_SimAO_Control: + onRecvControlResp(strBody); + break; + default: + break; + } +} + +void SimAoDlg::onRecvRtuInfoResp(const string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("SimAoDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SAoMonRtu *pAoRtu = m_pRtuInfo + nIdx; + pAoRtu->RtuNo = pRtuInfo->rtu_no(); + pAoRtu->Used = pRtuInfo->used(); + strncpy(pAoRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pAoRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void SimAoDlg::onRecvAoParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SimAoDlg::onRecvAoParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SAoMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocAoParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pAo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getAoInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimAoParam *pAo = pRtu->pAo + pParam->pnt_no(); + pAo->PointNo = pParam->pnt_no(); + pAo->Used = pParam->used(); + memset(pAo->PointTagName,0,sizeof(pAo->PointTagName)); + strncpy(pAo->PointTagName,pParam->pnt_desc().c_str(),sizeof(pAo->PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,4,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,5,item); + item->setTextAlignment(Qt::AlignCenter); + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; +} + +void SimAoDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SAoMonRtu*)realloc(m_pRtuInfo,sizeof(SAoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SAoMonRtu*)malloc(sizeof(SAoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SAoMonRtu*)malloc(sizeof(SAoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void SimAoDlg::mallocAoParam(SAoMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pAo != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pAo = (SFesSimAoParam*)realloc(pRtu->pAo,sizeof(SFesSimAoParam)*pRtu->MaxPoints); + if (pRtu->pAo != NULL) + { + memset(pRtu->pAo, 0, sizeof(SFesSimAoParam)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pAo = (SFesSimAoParam*)malloc(sizeof(SFesSimAoParam)*pRtu->MaxPoints); + if(pRtu->pAo != NULL) + { + memset(pRtu->pAo,0,sizeof(SFesSimAoParam)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pAo==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pAo = (SFesSimAoParam*)malloc(sizeof(SFesSimAoParam)*pRtu->MaxPoints); + if (pRtu->pAo != NULL) + { + memset(pRtu->pAo, 0, sizeof(SFesSimAoParam)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void SimAoDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + m_CurrentPointNo = -1; + + if(m_CurrentRtuRow == row) + { + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayAoParam(m_CurrentRtuNo); + } +} + +void SimAoDlg::OnPointCellClick(int row,int column) +{ + m_CurrentPointRow = row; + QString RtuStr = ui->PointTable->item(m_CurrentPointRow,0)->text(); + bool ok; + m_CurrentPointNo=RtuStr.toInt(&ok,10); + + if(ok==false) + { + m_CurrentPointNo = -1; + } +} + +SAoMonRtu* SimAoDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void SimAoDlg::DisplayAoParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + initCombox(); + OnPointInfoRefresh(); +} + +void SimAoDlg::OnControl() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + if(m_CurrentPointNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + FesDebugToolSimControlReqMsg reqMsg; + if(ui->SelectButton->isChecked()) + { + reqMsg.set_ctrl_type(CN_ControlSelect); + } + else if(ui->ExecuteButton->isChecked()) + { + reqMsg.set_ctrl_type(CN_ControlExecute); + } + else if(ui->AbortButton->isChecked()) + { + reqMsg.set_ctrl_type(CN_ControlAbort); + } + + m_lCtrlSeqNo = getMonotonicMsec(); + reqMsg.set_seq_no(m_lCtrlSeqNo); + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.set_float_value(ui->ValueEdit->text().toFloat()); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimAO_Control); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimAoDlg::onRecvControlResp(const std::string &strBody) +{ + FesDebugToolSimControlRepMsg repMsg; + if(!repMsg.ParseFromString(strBody)) + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行失败!原因:响应消息解析失败")); + return; + } + + if(m_lCtrlSeqNo != repMsg.seq_no()) + { + return; + } + + if(repMsg.success()) + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行成功!")); + } + else + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行失败!原因:%1").arg(repMsg.err_msg().c_str())); + } +} + +void SimAoDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void SimAoDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 4) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); +} diff --git a/product/src/tools/debug_tool_v2/simaodlg.h b/product/src/tools/debug_tool_v2/simaodlg.h new file mode 100644 index 00000000..52ad608c --- /dev/null +++ b/product/src/tools/debug_tool_v2/simaodlg.h @@ -0,0 +1,83 @@ +#ifndef SIMAODLG_H +#define SIMAODLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" + +namespace Ui { +class SimAoDlg; +} + +class SimAoDlg : public QDialog +{ + Q_OBJECT + +public: + explicit SimAoDlg(int windowId,QWidget *parent ); + ~SimAoDlg(); + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointCellClick(int row,int column); + void OnControl(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvAoParamResp(const std::string &strBody); + void onRecvControlResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocAoParam(SAoMonRtu *pRtu,const int nSize); + +private: + Ui::SimAoDlg *ui; + + SAoMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayAoParam(int RtuNo); + + int m_RtuNum; + SAoMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_StartIndex; + int m_EndIndex; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_CurrentPointRow; + int m_CurrentPointNo; + + int m_nWindowId;// 用来判断是否激活窗口 + + Qt::SortOrder m_order; + bool m_bCanSort; + + bool isEndOneRefresh; + int64 m_lCtrlSeqNo; +}; + +#endif // SIMAODLG_H diff --git a/product/src/tools/debug_tool_v2/simaodlg.ui b/product/src/tools/debug_tool_v2/simaodlg.ui new file mode 100644 index 00000000..f4174ba1 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simaodlg.ui @@ -0,0 +1,418 @@ + + + SimAoDlg + + + + 0 + 0 + 741 + 422 + + + + 模拟量仿真 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 远动号 + + + + + 使用标志 + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + + 0 + 0 + + + + QGroupBox { + border: 1px solid gray; + margin-top: 1ex; /* leave space at the top for the title */ + } + QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top center; + } + + + + + + Qt::AlignJustify|Qt::AlignVCenter + + + + 15 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 选择 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 执行 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 放弃 + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 控制值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 控制执行 + + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/simdidlg.cpp b/product/src/tools/debug_tool_v2/simdidlg.cpp new file mode 100644 index 00000000..991f2034 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simdidlg.cpp @@ -0,0 +1,1042 @@ +//2018-8-31 jacky 增加区间点刷新的非法字符判断 +#include "pub_widget/MessageBox.h" +#include +#include "simdidlg.h" +#include "ui_simdidlg.h" +#include +#include +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; + +SimDiDlg::SimDiDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SimDiDlg) +{ + ui->setupUi(this); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |= Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentPointNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + //ui->RTUTable->setColumnWidth(2,120); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,150); + ui->PointTable->setColumnWidth(4,100); + ui->PointTable->setColumnWidth(5,100); + ui->PointTable->setColumnWidth(6,250); + ui->PointTable->setColumnWidth(7,80); + ui->PointTable->setColumnWidth(8,80); + ui->PointTable->setColumnWidth(9,120); + + m_StartIndex = -1; + m_EndIndex = -1; + + m_CurrentDiFlag = true; + ui->CurrentPointButton->setChecked(m_CurrentDiFlag); + m_order = Qt::AscendingOrder; + m_bCanSort = false; + + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->PointTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnPointCellClick(int,int))); + connect(ui->SetButton ,SIGNAL(clicked()),this,SLOT(OnSetValue())); + connect(ui->LineSetButton ,SIGNAL(clicked()),this,SLOT(OnLineSet())); + connect(ui->RandSetButton ,SIGNAL(clicked()),this,SLOT(OnRandSet())); + connect(ui->StopSetButton ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + connect(ui->StopSetButton2 ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + connect(ui->StopSetButton3 ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + //ui->comboBox->setHidden(true); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&SimDiDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&SimDiDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); +// ui->PointTable->setSortingEnabled(true); +// ui->PointTable->horizontalHeader()->setSortIndicator(0,Qt::AscendingOrder); + initSig(); +} + +SimDiDlg::~SimDiDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipDi!= NULL) + free((m_pRtuInfo+i)->pDi); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + + delete ui; +} + +void SimDiDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SimDiDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + ui->comboBox->setModel(model); +} + +void SimDiDlg::initSig() +{ + connect(this,&SimDiDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_simDiRtuInfoResp,this,&SimDiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simDiParamResp,this,&SimDiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simDiValueResp,this,&SimDiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simDiStartSimResp,this,&SimDiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simDiStopSimResp,this,&SimDiDlg::slot_OnRecvResp); +} + +void SimDiDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadDiInfo(m_CurrentRtuNo); +} + +void SimDiDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SimDiDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + m_CurrentPointNo = -1; + m_CurrentRtuNo = -1; + changePointValueRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimDI_RtuInfo); + objMsg.set_body("MT_FESDBG_SimDI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimDiDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimDI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimDiDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_SimDI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_SimDI_Param: + onRecvDiParamResp(strBody); + break; + case MT_FESDBG_SimDI_Value: + onRecvDiValueResp(strBody); + break; + case MT_FESDBG_SimDI_StartSim: + onRecvStartSimResp(strBody); + break; + case MT_FESDBG_SimDI_StopSim: + onRecvStopSimResp(strBody); + break; + default: + break; + } +} + +void SimDiDlg::onRecvRtuInfoResp(const string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("SimDiDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SDiMonRtu *pDiRtu = m_pRtuInfo + nIdx; + pDiRtu->RtuNo = pRtuInfo->rtu_no(); + pDiRtu->Used = pRtuInfo->used(); + strncpy(pDiRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pDiRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void SimDiDlg::onRecvDiParamResp(const string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SimDiDlg::onRecvDiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SDiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocDiParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pDi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getDiInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimDi *pDi = pRtu->pDi + pParam->pnt_no(); + pDi->param.PointNo = pParam->pnt_no(); + pDi->param.Used = pParam->used(); + memset(pDi->param.PointTagName,0,sizeof(pDi->param.PointTagName)); + strncpy(pDi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pDi->param.PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strAppTagName)); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,7,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + item->setTextAlignment(Qt::AlignCenter); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void SimDiDlg::onRecvDiValueResp(const string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("SimDiDlg::onRecvDiDataResp 反序列化失败"); + changePointValueRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + SDiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changePointValueRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_int_values()->size(); nIdx++) + { + FesDebugToolIntPntValue *pParam = recvMsg.mutable_int_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimDi *pDi = pRtu->pDi + pParam->pnt_no(); + pDi->value.PointNo = pParam->pnt_no(); + pDi->value.Value = pParam->value(); + pDi->value.Status = pParam->status(); + pDi->value.time = pParam->time(); + + updateData(pDi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void SimDiDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SDiMonRtu*)realloc(m_pRtuInfo,sizeof(SDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SDiMonRtu*)malloc(sizeof(SDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SDiMonRtu*)malloc(sizeof(SDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void SimDiDlg::mallocDiParam(SDiMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pDi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pDi = (SFesSimDi*)realloc(pRtu->pDi,sizeof(SFesSimDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pDi = (SFesSimDi*)malloc(sizeof(SFesSimDi)*pRtu->MaxPoints); + if(pRtu->pDi != NULL) + { + memset(pRtu->pDi,0,sizeof(SFesSimDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pDi==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pDi = (SFesSimDi*)malloc(sizeof(SFesSimDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void SimDiDlg::sendDiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimDI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimDiDlg::OnRtuCellClick(int row, int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag == CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + m_CurrentPointNo = -1; + + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayDiParam(m_CurrentRtuNo); + } +} + +void SimDiDlg::OnPointCellClick(int row,int column) +{ + Q_UNUSED(column); + m_CurrentPointRow = row; + QString RtuStr = ui->PointTable->item(m_CurrentPointRow,0)->text(); + bool ok; + m_CurrentPointNo=RtuStr.toInt(&ok,10); + + if(ok==false) + { + m_CurrentPointNo = -1; + } +} + +SDiMonRtu* SimDiDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;i < m_RtuNum;i++) + { + SDiMonRtu *pRtu = m_pRtuInfo+i; + if(pRtu->RtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void SimDiDlg::DisplayDiParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + + initCombox(); + OnPointInfoRefresh(); +} + +void SimDiDlg::updateData(const SFesSimDiData &diData) +{ + auto iter = m_dotColumnMap.find(diData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(diData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = diData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + QTableWidgetItem *itemValue = new QTableWidgetItem(QString::number(diData.Value) ); + itemValue->setTextAlignment(Qt::AlignCenter); + + QTableWidgetItem *itemStatus = new QTableWidgetItem(getFesPointStatus(diData.Status) ); + itemStatus->setTextAlignment(Qt::AlignCenter); + if(diData.Status != CN_FesValueUpdate) itemStatus->setTextColor(Qt::red) ; + + ui->PointTable->setItem(iter.value(),4,itemValue); + ui->PointTable->setItem(iter.value(),5,itemStatus); + ui->PointTable->setItem(iter.value(),9,new QTableWidgetItem(tStr)); +} + +void SimDiDlg::changePointValueRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +bool SimDiDlg::initPointBrushData() +{ + QString devTag = ui->comboBox->currentData(Qt::UserRole+1).toString(); + + if(devTag == "") + { + return false; + }else if(devTag == "ALL") + { + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + m_RefreshMode = 1; //section + const RtuMaxAndMinPointNo &rtuMaxMinNo = CDataMng::instance()->getDiMaxMinNoRef(); + auto it = rtuMaxMinNo.find(m_CurrentRtuNo); + if(it == rtuMaxMinNo.end()) + { + LOGERROR("未找到rtu:[%d],刷新所有数据!",m_CurrentRtuNo); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + const MaxAndMinPointNo &devMap = it.value(); + auto itor = devMap.find(devTag); + if(itor == devMap.end()) + { + LOGERROR("未找到dev:[%s],刷新所有数据!",devTag.toStdString().c_str()); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + SFESDEVMAXANDMINPOINTNO maxminNo = itor.value(); + m_StartIndex = maxminNo.minPointNo; + m_EndIndex = maxminNo.maxPointNo; + } + } + } + LOGTRACE("刷新设备[%s]的数据!",devTag.toStdString().c_str()); + return true; +} + +void SimDiDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendDiValueReqMsg(); + } +} + + +void SimDiDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendDiValueReqMsg(); + } + else + { + changePointValueRefreshBtnToStop(); + } +} + +void SimDiDlg::OnRefeshTimer() +{ + if(m_ConnectFlag == CN_CommDisconnect) + { + changePointValueRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + sendDiValueReqMsg(); +} + +void SimDiDlg::OnSetValue() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_ValueSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else + if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else + if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)&&(m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.mutable_value_set_param()->set_value(ui->AiValueEdit->text().toInt()); + reqMsg.set_status(ui->AiStatusEdit->text().toUInt()); + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimDI_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimDiDlg::OnLineSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_LineSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint) && (m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.mutable_line_set_param()->set_min_value(0); + reqMsg.mutable_line_set_param()->set_max_value(1); + reqMsg.mutable_line_set_param()->set_step_value(1); + reqMsg.mutable_line_set_param()->set_period(ui->ChangeTimeEdit->text().toInt()); + + if(reqMsg.mutable_line_set_param()->min_value() >= reqMsg.mutable_line_set_param()->max_value()) + { + N_MessageBox::warning(this,tr("告警"),tr("最大值小于最小值")); + return; + } + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimDI_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + + +void SimDiDlg::OnRandSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_RandSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint) && (m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.mutable_rand_set_param()->set_period(10); //暂时写死10秒变化一次 + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimDI_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimDiDlg::OnStopSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimDI_StopSim); + sendMsg.set_body("MT_FESDBG_SimDI_StopSim"); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimDiDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void SimDiDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void SimDiDlg::onRecvStartSimResp(const std::string &strBody) +{ + FesDebugToolValueSimSetRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("SimDiDlg::onRecvStartSimResp 反序列化失败"); + return; + } + + switch(recvMsg.sim_mode()) + { + case MT_FESDBG_SM_ValueSet: + N_MessageBox::warning(this,tr("信息"),tr("固定设置成功!")); + break; + case MT_FESDBG_SM_LineSet: + N_MessageBox::warning(this,tr("信息"),tr("线性设置成功!")); + break; + case MT_FESDBG_SM_RandSet: + N_MessageBox::warning(this,tr("信息"),tr("随机设置成功!")); + break; + default: + break; + } +} + +void SimDiDlg::onRecvStopSimResp(const std::string &strBody) +{ + Q_UNUSED(strBody); + //N_MessageBox::warning(this,tr("信息"),tr("停止设置成功!")); +} diff --git a/product/src/tools/debug_tool_v2/simdidlg.h b/product/src/tools/debug_tool_v2/simdidlg.h new file mode 100644 index 00000000..f558176b --- /dev/null +++ b/product/src/tools/debug_tool_v2/simdidlg.h @@ -0,0 +1,107 @@ +#ifndef SIMDIDLG_H +#define SIMDIDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" + +namespace Ui { +class SimDiDlg; +} + +class SimDiDlg : public QDialog +{ + Q_OBJECT + +public: + explicit SimDiDlg(int windowId,QWidget *parent ); + ~SimDiDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void setRtuDevMap(RtuDevMap rtuDevMap); + void setRtuPointMap(RtuPointMap rtuPointMap); + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); + +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointCellClick(int row,int column); + void OnPointValueRefresh(); + + void OnSetValue(); + void OnLineSet(); + void OnRandSet(); + void OnStopSet(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvDiParamResp(const std::string &strBody); + void onRecvDiValueResp(const std::string &strBody); + void onRecvStartSimResp(const std::string &strBody); + void onRecvStopSimResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocDiParam(SDiMonRtu *pRtu,const int nSize); + void sendDiValueReqMsg(); + +private: + Ui::SimDiDlg *ui; + + SDiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayDiParam(int RtuNo); + + void updateData(const SFesSimDiData &diData); + + void changePointValueRefreshBtnToStop(); + + bool initPointBrushData(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SDiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_CurrentPointRow; + int m_CurrentPointNo; + bool m_CurrentDiFlag; + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // SIMDIDLG_H diff --git a/product/src/tools/debug_tool_v2/simdidlg.ui b/product/src/tools/debug_tool_v2/simdidlg.ui new file mode 100644 index 00000000..e3bb325a --- /dev/null +++ b/product/src/tools/debug_tool_v2/simdidlg.ui @@ -0,0 +1,778 @@ + + + SimDiDlg + + + + 0 + 0 + 916 + 603 + + + + 数字量仿真 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 30 + 20 + + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 点值 + + + + + 点状态 + + + + + 后台标签 + + + + + 远动号 + + + + + 使用标志 + + + + + 时间 + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + QGroupBox { + border: 1px solid gray; + margin-top: 1ex; /* leave space at the top for the title */ + } + QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top center; + } + + + + + + Qt::AlignJustify|Qt::AlignVCenter + + + + 15 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 当前测点 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 当前RTU + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 所有RTU + + + + + + + + + + + + + 0 + 100 + + + + + 16777215 + 100 + + + + 0 + + + + 固定设置 + + + + 0 + + + 12 + + + 0 + + + 0 + + + 6 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 固定设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + 0 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 值: + + + + + + + + 0 + 23 + + + + + 100 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 点状态: + + + + + + + + 0 + 23 + + + + + 100 + 23 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 周期设置 + + + + 0 + + + 12 + + + 0 + + + 0 + + + 6 + + + + + 0 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 周期秒: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 周期设置 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 随机设置 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 随机设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/simdodlg.cpp b/product/src/tools/debug_tool_v2/simdodlg.cpp new file mode 100644 index 00000000..27fa4a80 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simdodlg.cpp @@ -0,0 +1,605 @@ +#include "pub_widget/MessageBox.h" +#include +#include "simdodlg.h" +#include "ui_simdodlg.h" +#include "CActiveWindow.h" +#include +#include +#include "CDataMng.h" +#include "pub_utility_api/TimeUtil.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +SimDoDlg::SimDoDlg(int windowId,QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SimDoDlg) +{ + ui->setupUi(this); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentPointNo = -1; + m_CurrentRtuRow = -1; + m_StartIndex = 0; + m_EndIndex = 0; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,200); + ui->PointTable->setColumnWidth(4,80); + ui->PointTable->setColumnWidth(5,80); + + ui->SelectButton->setChecked(true); + m_order = Qt::AscendingOrder; + m_bCanSort = false; + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->PointTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnPointCellClick(int,int))); + connect(ui->ControlButton,SIGNAL(clicked()),this,SLOT(OnControl())); + //ui->comboBox->setHidden(true); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&SimDoDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&SimDoDlg::sort,Qt::QueuedConnection); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); +} + +SimDoDlg::~SimDoDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipDo!= NULL) + free((m_pRtuInfo+i)->pDo); + } + free(m_pRtuInfo); + } + delete ui; +} + +void SimDoDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SimDoDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + + ui->comboBox->setModel(model); +} + +void SimDoDlg::initSig() +{ + connect(this,&SimDoDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_simDoRtuInfoResp,this,&SimDoDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simDoParamResp,this,&SimDoDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simDoControlResp,this,&SimDoDlg::slot_OnRecvResp); +} + +void SimDoDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadDoInfo(m_CurrentRtuNo); +} + +void SimDoDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SimDoDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentPointNo = -1; + m_CurrentRtuNo = -1; + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimDO_RtuInfo); + objMsg.set_body("MT_FESDBG_SimDO_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + + +void SimDoDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimDO_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimDoDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_SimDO_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_SimDO_Param: + onRecvDoParamResp(strBody); + break; + case MT_FESDBG_SimDO_Control: + onRecvControlResp(strBody); + break; + default: + break; + } +} + +void SimDoDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("SimDoDlg:onRecvRtuInfoResp 反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SDoMonRtu *pDoRtu = m_pRtuInfo + nIdx; + pDoRtu->RtuNo = pRtuInfo->rtu_no(); + pDoRtu->Used = pRtuInfo->used(); + strncpy(pDoRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pDoRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void SimDoDlg::onRecvDoParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SimDoDlg::onRecvDoParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SDoMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocDoParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pDo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getDoInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimDoParam *pDo = pRtu->pDo + pParam->pnt_no(); + pDo->PointNo = pParam->pnt_no(); + pDo->Used = pParam->used(); + memset(pDo->PointTagName,0,sizeof(pDo->PointTagName)); + strncpy(pDo->PointTagName,pParam->pnt_desc().c_str(),sizeof(pDo->PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,4,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,5,item); + item->setTextAlignment(Qt::AlignCenter); + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; +} + +void SimDoDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SDoMonRtu*)realloc(m_pRtuInfo,sizeof(SDoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SDoMonRtu*)malloc(sizeof(SDoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SDoMonRtu*)malloc(sizeof(SDoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void SimDoDlg::mallocDoParam(SDoMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pDo != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pDo = (SFesSimDoParam*)realloc(pRtu->pDo,sizeof(SFesSimDoParam)*pRtu->MaxPoints); + if (pRtu->pDo != NULL) + { + memset(pRtu->pDo, 0, sizeof(SFesSimDoParam)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pDo = (SFesSimDoParam*)malloc(sizeof(SFesSimDoParam)*pRtu->MaxPoints); + if(pRtu->pDo != NULL) + { + memset(pRtu->pDo,0,sizeof(SFesSimDoParam)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pDo==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pDo = (SFesSimDoParam*)malloc(sizeof(SFesSimDoParam)*pRtu->MaxPoints); + if (pRtu->pDo != NULL) + { + memset(pRtu->pDo, 0, sizeof(SFesSimDoParam)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void SimDoDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayDoParam(m_CurrentRtuNo); + } +} + +void SimDoDlg::OnPointCellClick(int row,int column) +{ + Q_UNUSED(column); + m_CurrentPointRow = row; + QString RtuStr = ui->PointTable->item(m_CurrentPointRow,0)->text(); + bool ok; + m_CurrentPointNo=RtuStr.toInt(&ok,10); + + if(ok==false) + { + m_CurrentPointNo = -1; + } +} + +SDoMonRtu* SimDoDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;i < m_RtuNum;i++) + { + SDoMonRtu *pRtu = m_pRtuInfo+i; + if(pRtu->RtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void SimDoDlg::DisplayDoParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + initCombox(); + OnPointInfoRefresh(); +} + +void SimDoDlg::OnControl() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + if(m_CurrentPointNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + FesDebugToolSimControlReqMsg reqMsg; + if(ui->SelectButton->isChecked()) + { + reqMsg.set_ctrl_type(CN_ControlSelect); + } + else if(ui->ExecuteButton->isChecked()) + { + reqMsg.set_ctrl_type(CN_ControlExecute); + } + else if(ui->AbortButton->isChecked()) + { + reqMsg.set_ctrl_type(CN_ControlAbort); + } + + m_lCtrlSeqNo = getMonotonicMsec(); + reqMsg.set_seq_no(m_lCtrlSeqNo); + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.set_int_value(ui->ValueEdit->text().toInt()); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimDO_Control); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimDoDlg::onRecvControlResp(const std::string &strBody) +{ + FesDebugToolSimControlRepMsg repMsg; + if(!repMsg.ParseFromString(strBody)) + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行失败!原因:响应消息解析失败")); + return; + } + + if(m_lCtrlSeqNo != repMsg.seq_no()) + { + return; + } + + if(repMsg.success()) + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行成功!")); + } + else + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行失败!原因:%1").arg(repMsg.err_msg().c_str())); + } +} + +void SimDoDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void SimDoDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 4) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); +} diff --git a/product/src/tools/debug_tool_v2/simdodlg.h b/product/src/tools/debug_tool_v2/simdodlg.h new file mode 100644 index 00000000..0460bdcb --- /dev/null +++ b/product/src/tools/debug_tool_v2/simdodlg.h @@ -0,0 +1,80 @@ +#ifndef SIMDODLG_H +#define SIMDODLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "ComProtocolThread.h" + +namespace Ui { +class SimDoDlg; +} + +class SimDoDlg : public QDialog +{ + Q_OBJECT + +public: + explicit SimDoDlg(int windowId,QWidget *parent ); + ~SimDoDlg(); + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointCellClick(int row,int column); + void OnControl(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvDoParamResp(const std::string &strBody); + void onRecvControlResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocDoParam(SDoMonRtu *pRtu,const int nSize); + +private: + Ui::SimDoDlg *ui; + SDoMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayDoParam(int RtuNo); + + int m_RtuNum; + SDoMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_StartIndex; + int m_EndIndex; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_CurrentPointRow; + int m_CurrentPointNo; + + int m_nWindowId;// 用来判断是否激活窗口 + Qt::SortOrder m_order; + bool m_bCanSort; + + bool isEndOneRefresh; + int64 m_lCtrlSeqNo; +}; + +#endif // SIMDODLG_H diff --git a/product/src/tools/debug_tool_v2/simdodlg.ui b/product/src/tools/debug_tool_v2/simdodlg.ui new file mode 100644 index 00000000..519928f8 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simdodlg.ui @@ -0,0 +1,418 @@ + + + SimDoDlg + + + + 0 + 0 + 647 + 392 + + + + 数字量控制 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 远动号 + + + + + 使用标志 + + + + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + + 0 + 0 + + + + QGroupBox { + border: 1px solid gray; + margin-top: 1ex; /* leave space at the top for the title */ + } + QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top center; + } + + + + + + Qt::AlignJustify|Qt::AlignVCenter + + + + 15 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 选择 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 执行 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 放弃 + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 控制值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 控制执行 + + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/simeventdlg.cpp b/product/src/tools/debug_tool_v2/simeventdlg.cpp new file mode 100644 index 00000000..afcf76bc --- /dev/null +++ b/product/src/tools/debug_tool_v2/simeventdlg.cpp @@ -0,0 +1,616 @@ +#include "pub_widget/MessageBox.h" +#include +#include "simeventdlg.h" +#include "ui_simeventdlg.h" +#include +#include "CDataMng.h" + +using namespace std; +using namespace iot_idl; + +SimEventDlg::SimEventDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SimEventDlg) +{ + ui->setupUi(this); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentPointNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,80); + ui->RTUTable->setColumnWidth(1,80); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,150); + ui->PointTable->setColumnWidth(4,250); + ui->PointTable->setColumnWidth(5,80); + ui->PointTable->setColumnWidth(6,80); + + m_StartIndex = -1; + m_EndIndex = -1; + m_order = Qt::AscendingOrder; + m_bCanSort = false; + ui->FalueNumSpinBox->setRange(0,4); + + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->PointTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnPointCellClick(int,int))); + connect(ui->CreateButton,SIGNAL(clicked()),this,SLOT(OnCreateEvent())); + + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&SimEventDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&SimEventDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); +} + +SimEventDlg::~SimEventDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipDi!= NULL) + free((m_pRtuInfo+i)->pDi); + } + free(m_pRtuInfo); + } + delete ui; +} + +void SimEventDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SimEventDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + + + ui->comboBox->setModel(model); +} + +void SimEventDlg::initSig() +{ + connect(this,&SimEventDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_simEventRtuInfoResp,this,&SimEventDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simEventDiParamResp,this,&SimEventDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simEventCreateResp,this,&SimEventDlg::slot_OnRecvResp); +} + +void SimEventDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadDiInfo(m_CurrentRtuNo); +} + +void SimEventDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SimEventDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentPointNo = -1; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimEvent_RtuInfo); + objMsg.set_body("MT_FESDBG_SimEvent_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + + +void SimEventDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimEvent_DiParam); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimEventDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_SimEvent_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_SimEvent_DiParam: + onRecvDiParamResp(strBody); + break; + case MT_FESDBG_SimEvent_Create: + onRecvCreateResp(strBody); + break; + default: + break; + } +} + +void SimEventDlg::onRecvRtuInfoResp(const string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("SimEventDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SDiMonRtu *pDiRtu = m_pRtuInfo + nIdx; + pDiRtu->RtuNo = pRtuInfo->rtu_no(); + pDiRtu->Used = pRtuInfo->used(); + strncpy(pDiRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pDiRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void SimEventDlg::onRecvDiParamResp(const string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SimDiDlg::onRecvDiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SDiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocDiParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pDi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getDiInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimDi *pDi = pRtu->pDi + pParam->pnt_no(); + pDi->param.PointNo = pParam->pnt_no(); + pDi->param.Used = pParam->used(); + memset(pDi->param.PointTagName,0,sizeof(pDi->param.PointTagName)); + strncpy(pDi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pDi->param.PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strAppTagName)); + ui->PointTable->setItem(rowCount,4,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,5,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,6,item); + item->setTextAlignment(Qt::AlignCenter); + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; +} + +void SimEventDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SDiMonRtu*)realloc(m_pRtuInfo,sizeof(SDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SDiMonRtu*)malloc(sizeof(SDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SDiMonRtu*)malloc(sizeof(SDiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SDiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void SimEventDlg::mallocDiParam(SDiMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pDi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pDi = (SFesSimDi*)realloc(pRtu->pDi,sizeof(SFesSimDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pDi = (SFesSimDi*)malloc(sizeof(SFesSimDi)*pRtu->MaxPoints); + if(pRtu->pDi != NULL) + { + memset(pRtu->pDi,0,sizeof(SFesSimDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pDi==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pDi = (SFesSimDi*)malloc(sizeof(SFesSimDi)*pRtu->MaxPoints); + if (pRtu->pDi != NULL) + { + memset(pRtu->pDi, 0, sizeof(SFesSimDi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void SimEventDlg::OnRtuCellClick(int row, int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + m_CurrentPointNo = -1; + + if(m_CurrentRtuRow == row) + { + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayDiParam(m_CurrentRtuNo); + } +} + +void SimEventDlg::OnPointCellClick(int row,int column) +{ + m_CurrentPointRow = row; + QString RtuStr = ui->PointTable->item(m_CurrentPointRow,0)->text(); + bool ok; + m_CurrentPointNo=RtuStr.toInt(&ok,10); + + if(ok==false) + { + m_CurrentPointNo = -1; + } +} + +SDiMonRtu* SimEventDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void SimEventDlg::DisplayDiParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + + initCombox(); + OnPointInfoRefresh(); +} + +void SimEventDlg::OnCreateEvent() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + if(m_CurrentPointNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + FesDebugToolSimEventCreateReqMsg reqMsg; + reqMsg.set_event_type(MT_FESDBG_EST_RtuSoe); + FesDebugToolSimEventRtuSoe* pEvent = reqMsg.mutable_event(); + pEvent->set_event_source(MT_FESDBG_EST_RtuSoe); + pEvent->set_rtu_no(m_CurrentRtuNo); + pEvent->set_pnt_no(m_CurrentPointNo); + pEvent->set_value(ui->ValueEdit->text().toInt()); + pEvent->set_status(ui->StatusEdit->text().toUInt()); + pEvent->set_fault_num(ui->FalueNumSpinBox->value()); + + if(pEvent->fault_num() >= 1) + { + //第1组 + pEvent->add_fault_type(ui->FaultTypeEdit1->text().toInt()); + pEvent->add_fault_value(ui->FaultValueEdit1->text().toInt()); + } + + if(pEvent->fault_num() >= 2) + { + //第2组 + pEvent->add_fault_type(ui->FaultTypeEdit2->text().toInt()); + pEvent->add_fault_value(ui->FaultValueEdit2->text().toInt()); + } + + if(pEvent->fault_num() >= 3) + { + //第3组 + pEvent->add_fault_type(ui->FaultTypeEdit3->text().toInt()); + pEvent->add_fault_value(ui->FaultValueEdit3->text().toInt()); + } + + if(pEvent->fault_num() >= 4) + { + //第4组 + pEvent->add_fault_type(ui->FaultTypeEdit4->text().toInt()); + pEvent->add_fault_value(ui->FaultValueEdit4->text().toInt()); + } + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimEvent_Create); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimEventDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void SimEventDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 5) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); +} + +void SimEventDlg::onRecvCreateResp(const std::string &strBody) +{ + Q_UNUSED(strBody); + N_MessageBox::warning(this,tr("信息"),tr("产生事件成功!")); +} diff --git a/product/src/tools/debug_tool_v2/simeventdlg.h b/product/src/tools/debug_tool_v2/simeventdlg.h new file mode 100644 index 00000000..02e6f87d --- /dev/null +++ b/product/src/tools/debug_tool_v2/simeventdlg.h @@ -0,0 +1,85 @@ +#ifndef SIMEVENTDLG_H +#define SIMEVENTDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "CSystemResources.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" + +namespace Ui { +class SimEventDlg; +} + +class SimEventDlg : public QDialog +{ + Q_OBJECT + +public: + explicit SimEventDlg(int windowId,QWidget *parent ); + ~SimEventDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointCellClick(int row,int column); + void OnCreateEvent(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvDiParamResp(const std::string &strBody); + void onRecvCreateResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocDiParam(SDiMonRtu *pRtu,const int nSize); + +private: + Ui::SimEventDlg *ui; + + SDiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayDiParam(int RtuNo); + + int m_RtuNum; + SDiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_CurrentPointRow; + int m_CurrentPointNo; + + int m_nWindowId;// 用来判断是否激活窗口 + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // SIMEVENTDLG_H diff --git a/product/src/tools/debug_tool_v2/simeventdlg.ui b/product/src/tools/debug_tool_v2/simeventdlg.ui new file mode 100644 index 00000000..b27a23ce --- /dev/null +++ b/product/src/tools/debug_tool_v2/simeventdlg.ui @@ -0,0 +1,823 @@ + + + SimEventDlg + + + + 0 + 0 + 663 + 389 + + + + + 0 + 0 + + + + 事件仿真 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + QGroupBox { + border: 1px solid gray; + margin-top: 1ex; /* leave space at the top for the title */ + } + QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top center; + } + + + + + + Qt::AlignJustify|Qt::AlignVCenter + + + + 10 + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 故障值个数: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 1#故障类型: + + + + + + + + 20 + 23 + + + + + 80 + 23 + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 故障值1: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 60 + 10 + + + + + 16777215 + 30 + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 2#故障类型: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 60 + 10 + + + + + 16777215 + 30 + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 3#故障类型: + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 故障值2: + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 故障值3: + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 4#故障类型: + + + + + + + + 60 + 10 + + + + + 16777215 + 30 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 故障值4: + + + + + + + + 60 + 10 + + + + + 16777215 + 30 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + QGroupBox { + border: 1px solid gray; + margin-top: 1ex; /* leave space at the top for the title */ + } + QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top center; + } + + + + + + Qt::AlignJustify|Qt::AlignVCenter + + + + 10 + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 点值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 点状态: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + + 305 + 25 + + + + + 305 + 28 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 产生事件 + + + + + + + Qt::Horizontal + + + + 967 + 20 + + + + + + + + + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 后台标签 + + + + + 远动号 + + + + + 使用标志 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/simmidlg.cpp b/product/src/tools/debug_tool_v2/simmidlg.cpp new file mode 100644 index 00000000..87dfd13f --- /dev/null +++ b/product/src/tools/debug_tool_v2/simmidlg.cpp @@ -0,0 +1,1044 @@ +//2018-8-31 jacky 增加区间点刷新的非法字符判断 +#include "pub_widget/MessageBox.h" +#include +#include "simmidlg.h" +#include "ui_simmidlg.h" +#include +#include +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; + +SimMiDlg::SimMiDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SimMiDlg) +{ + ui->setupUi(this); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |= Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + // ui->RTUTable->setColumnWidth(2,120); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,150); + ui->PointTable->setColumnWidth(4,100); + ui->PointTable->setColumnWidth(5,100); + ui->PointTable->setColumnWidth(6,250); + ui->PointTable->setColumnWidth(7,80); + ui->PointTable->setColumnWidth(8,80); + ui->PointTable->setColumnWidth(9,120); + + m_CurrentPointNo = -1; + + m_StartIndex = -1; + m_EndIndex = -1; + + m_CurrentMiFlag = true; + ui->CurrentPointButton->setChecked(m_CurrentMiFlag); + + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->PointTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnPointCellClick(int,int))); + connect(ui->SetButton ,SIGNAL(clicked()),this,SLOT(OnSetValue())); + connect(ui->LineSetButton ,SIGNAL(clicked()),this,SLOT(OnLineSet())); + connect(ui->RandSetButton ,SIGNAL(clicked()),this,SLOT(OnRandSet())); + connect(ui->StopSetButton ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + connect(ui->StopSetButton2 ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + connect(ui->StopSetButton3 ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + //ui->comboBox->setHidden(true); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&SimMiDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&SimMiDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); +} + +SimMiDlg::~SimMiDlg() +{ + delete ui; + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipMi!= NULL) + free((m_pRtuInfo+i)->pMi); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; +} + +void SimMiDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SimMiDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + + ui->comboBox->setModel(model); +} + +void SimMiDlg::initSig() +{ + connect(this,&SimMiDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_simMiRtuInfoResp,this,&SimMiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simMiParamResp,this,&SimMiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simMiValueResp,this,&SimMiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simMiStartSimResp,this,&SimMiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simMiStopSimResp,this,&SimMiDlg::slot_OnRecvResp); +} + +void SimMiDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadMiInfo(m_CurrentRtuNo); +} + +void SimMiDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SimMiDlg::OnRTURefresh() +{ + unsigned char data[40]; + + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + m_CurrentPointNo = -1; + m_CurrentRtuNo = -1; + changePointValueRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimMI_RtuInfo); + objMsg.set_body("MT_FESDBG_SimMI_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimMiDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimMI_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimMiDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_SimMI_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_SimMI_Param: + onRecvMiParamResp(strBody); + break; + case MT_FESDBG_SimMI_Value: + onRecvMiValueResp(strBody); + break; + case MT_FESDBG_SimMI_StartSim: + onRecvStartSimResp(strBody); + break; + case MT_FESDBG_SimMI_StopSim: + onRecvStopSimResp(strBody); + break; + default: + break; + } +} + +void SimMiDlg::onRecvRtuInfoResp(const string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("SimMiDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SMiMonRtu *pMiRtu = m_pRtuInfo + nIdx; + pMiRtu->RtuNo = pRtuInfo->rtu_no(); + pMiRtu->Used = pRtuInfo->used(); + strncpy(pMiRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pMiRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void SimMiDlg::onRecvMiParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SimMiDlg::onRecvMiParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SMiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocMiParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pMi==NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getMiInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimMi *pMi = pRtu->pMi + pParam->pnt_no(); + pMi->param.PointNo = pParam->pnt_no(); + pMi->param.Used = pParam->used(); + memset(pMi->param.PointTagName,0,sizeof(pMi->param.PointTagName)); + strncpy(pMi->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pMi->param.PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strAppTagName)); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,7,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + item->setTextAlignment(Qt::AlignCenter); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + +void SimMiDlg::onRecvMiValueResp(const std::string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("SimMiDlg::onRecvMiDataResp 反序列化失败"); + changePointValueRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + SMiMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changePointValueRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_int_values()->size(); nIdx++) + { + FesDebugToolIntPntValue *pParam = recvMsg.mutable_int_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimMi *pMi = pRtu->pMi + pParam->pnt_no(); + pMi->value.PointNo = pParam->pnt_no(); + pMi->value.Value = pParam->value(); + pMi->value.Status = pParam->status(); + pMi->value.time = pParam->time(); + + updateData(pMi->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void SimMiDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SMiMonRtu*)realloc(m_pRtuInfo,sizeof(SMiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SMiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SMiMonRtu*)malloc(sizeof(SMiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SMiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SMiMonRtu*)malloc(sizeof(SMiMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SMiMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void SimMiDlg::mallocMiParam(SMiMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pMi != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pMi = (SFesSimMi*)realloc(pRtu->pMi,sizeof(SFesSimMi)*pRtu->MaxPoints); + if (pRtu->pMi != NULL) + { + memset(pRtu->pMi, 0, sizeof(SFesSimMi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pMi = (SFesSimMi*)malloc(sizeof(SFesSimMi)*pRtu->MaxPoints); + if(pRtu->pMi != NULL) + { + memset(pRtu->pMi,0,sizeof(SFesSimMi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pMi==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pMi = (SFesSimMi*)malloc(sizeof(SFesSimMi)*pRtu->MaxPoints); + if (pRtu->pMi != NULL) + { + memset(pRtu->pMi, 0, sizeof(SFesSimMi)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void SimMiDlg::sendMiValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimMI_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimMiDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + m_CurrentPointNo = -1; + + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayMiParam(m_CurrentRtuNo); + } +} + +void SimMiDlg::OnPointCellClick(int row,int column) +{ + Q_UNUSED(column); + m_CurrentPointRow = row; + QString RtuStr = ui->PointTable->item(m_CurrentPointRow,0)->text(); + bool ok; + m_CurrentPointNo=RtuStr.toInt(&ok,10); + + if(ok==false) + { + m_CurrentPointNo = -1; + } +} + +SMiMonRtu* SimMiDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;i < m_RtuNum;i++) + { + SMiMonRtu *pRtu = m_pRtuInfo+i; + if(pRtu->RtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void SimMiDlg::DisplayMiParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + + initCombox(); + OnPointInfoRefresh(); +} + +void SimMiDlg::updateData(const SFesSimMiData &MiData) +{ + auto iter = m_dotColumnMap.find(MiData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(MiData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = MiData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + QTableWidgetItem *itemValue = new QTableWidgetItem(QString::number(MiData.Value) ); + itemValue->setTextAlignment(Qt::AlignCenter); + + QTableWidgetItem *itemStatus = new QTableWidgetItem(getFesPointStatus(MiData.Status) ); + itemStatus->setTextAlignment(Qt::AlignCenter); + if(MiData.Status != CN_FesValueUpdate) itemStatus->setTextColor(Qt::red) ; + + ui->PointTable->setItem(iter.value(),4,itemValue); + ui->PointTable->setItem(iter.value(),5,itemStatus); + ui->PointTable->setItem(iter.value(),9,new QTableWidgetItem(tStr)); +} + +void SimMiDlg::changePointValueRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +bool SimMiDlg::initPointBrushData() +{ + QString devTag = ui->comboBox->currentData(Qt::UserRole+1).toString(); + + if(devTag == "") + { + return false; + }else if(devTag == "ALL") + { + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + m_RefreshMode = 1; //section + const RtuMaxAndMinPointNo &rtuMaxMinNo = CDataMng::instance()->getMiMaxMinNoRef(); + auto it = rtuMaxMinNo.find(m_CurrentRtuNo); + if(it == rtuMaxMinNo.end()) + { + LOGERROR("未找到rtu:[%d],刷新所有数据!",m_CurrentRtuNo); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + const MaxAndMinPointNo &devMap = it.value(); + auto itor = devMap.find(devTag); + if(itor == devMap.end()) + { + LOGERROR("未找到dev:[%s],刷新所有数据!",devTag.toStdString().c_str()); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + SFESDEVMAXANDMINPOINTNO maxminNo = itor.value(); + m_StartIndex = maxminNo.minPointNo; + m_EndIndex = maxminNo.maxPointNo; + } + } + } + LOGTRACE("刷新设备[%s]的数据!",devTag.toStdString().c_str()); + return true; +} + +void SimMiDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendMiValueReqMsg(); + } +} + +void SimMiDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendMiValueReqMsg(); + } + else + { + changePointValueRefreshBtnToStop(); + } +} + +void SimMiDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changePointValueRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(!isEndOneRefresh) + { + return; + } + + isEndOneRefresh = false; + + sendMiValueReqMsg(); +} + +void SimMiDlg::OnSetValue() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_ValueSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)&&(m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.mutable_value_set_param()->set_value(ui->ValueEdit->text().toFloat()); + reqMsg.set_status(ui->StatusEdit->text().toUInt()); + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimMI_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimMiDlg::OnLineSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_LineSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint) && (m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.mutable_line_set_param()->set_min_value(ui->MinValueEdit->text().toFloat()); + reqMsg.mutable_line_set_param()->set_max_value(ui->MaxValueEdit->text().toFloat()); + reqMsg.mutable_line_set_param()->set_step_value(ui->StepValueEdit->text().toFloat()); + reqMsg.mutable_line_set_param()->set_period(ui->ChangeTimeEdit->text().toInt()); + + if(reqMsg.mutable_line_set_param()->min_value() >= reqMsg.mutable_line_set_param()->max_value()) + { + N_MessageBox::warning(this,tr("告警"),tr("最大值小于最小值")); + return; + } + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimMI_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimMiDlg::OnRandSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_RandSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint) && (m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.mutable_rand_set_param()->set_period(10); //暂时写死10秒变化一次 + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimMI_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimMiDlg::OnStopSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimMI_StopSim); + sendMsg.set_body("MT_FESDBG_SimMI_StopSim"); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimMiDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void SimMiDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void SimMiDlg::onRecvStartSimResp(const std::string &strBody) +{ + FesDebugToolValueSimSetRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("SimMiDlg::onRecvStartSimResp 反序列化失败"); + return; + } + + switch(recvMsg.sim_mode()) + { + case MT_FESDBG_SM_ValueSet: + N_MessageBox::warning(this,tr("信息"),tr("固定设置成功!")); + break; + case MT_FESDBG_SM_LineSet: + N_MessageBox::warning(this,tr("信息"),tr("线性设置成功!")); + break; + case MT_FESDBG_SM_RandSet: + N_MessageBox::warning(this,tr("信息"),tr("随机设置成功!")); + break; + default: + break; + } +} + +void SimMiDlg::onRecvStopSimResp(const std::string &strBody) +{ + Q_UNUSED(strBody); + //N_MessageBox::warning(this,tr("信息"),tr("停止设置成功!")); +} + diff --git a/product/src/tools/debug_tool_v2/simmidlg.h b/product/src/tools/debug_tool_v2/simmidlg.h new file mode 100644 index 00000000..effea66d --- /dev/null +++ b/product/src/tools/debug_tool_v2/simmidlg.h @@ -0,0 +1,104 @@ +#ifndef SIMMIDLG_H +#define SIMMIDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" + +namespace Ui { +class SimMiDlg; +} + +class SimMiDlg : public QDialog +{ + Q_OBJECT + +public: + explicit SimMiDlg(int windowId,QWidget *parent ); + ~SimMiDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + + void OnPointCellClick(int row,int column); + void OnSetValue(); + void OnLineSet(); + void OnRandSet(); + void OnStopSet(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvMiParamResp(const std::string &strBody); + void onRecvMiValueResp(const std::string &strBody); + void onRecvStartSimResp(const std::string &strBody); + void onRecvStopSimResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocMiParam(SMiMonRtu *pRtu,const int nSize); + void sendMiValueReqMsg(); + +private: + Ui::SimMiDlg *ui; + SMiMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayMiParam(int RtuNo); + + void updateData(const SFesSimMiData & MiData); + + void changePointValueRefreshBtnToStop(); + + bool initPointBrushData(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SMiMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_CurrentPointRow; + int m_CurrentPointNo; + bool m_CurrentMiFlag; + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // SIMMIDLG_H diff --git a/product/src/tools/debug_tool_v2/simmidlg.ui b/product/src/tools/debug_tool_v2/simmidlg.ui new file mode 100644 index 00000000..a2600d2c --- /dev/null +++ b/product/src/tools/debug_tool_v2/simmidlg.ui @@ -0,0 +1,938 @@ + + + SimMiDlg + + + + 0 + 0 + 953 + 622 + + + + + 0 + 0 + + + + 混合量仿真 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + + 0 + 0 + + + + QGroupBox { + border: 1px solid gray; + margin-top: 1ex; /* leave space at the top for the title */ + } + QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top center; + } + + + + + + Qt::AlignJustify|Qt::AlignVCenter + + + + 15 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 当前测点 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 当前RTU + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 所有RTU + + + + + + + + + + + + + 0 + 130 + + + + + 16777215 + 130 + + + + + Agency FB + 9 + + + + 0 + + + + 固定置数 + + + + 0 + + + 12 + + + 0 + + + 0 + + + 6 + + + + + 0 + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 值: + + + + + + + + 0 + 23 + + + + + 100 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 点状态: + + + + + + + + 0 + 23 + + + + + 100 + 23 + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 固定设置 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 线性置数 + + + + 0 + + + 12 + + + 0 + + + 0 + + + 6 + + + + + 0 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 最小值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 最大值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 步长值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 周期秒: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 线性设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止置数 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 随机置数 + + + + 0 + + + 0 + + + 1 + + + 0 + + + 6 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 随机设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + Qt::Vertical + + + + 296 + 88 + + + + + + + + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 30 + 20 + + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 点值 + + + + + 点状态 + + + + + 后台标签 + + + + + 远动号 + + + + + 使用标志 + + + + + 时间 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/simmodlg.cpp b/product/src/tools/debug_tool_v2/simmodlg.cpp new file mode 100644 index 00000000..bf884caf --- /dev/null +++ b/product/src/tools/debug_tool_v2/simmodlg.cpp @@ -0,0 +1,602 @@ +#include "pub_widget/MessageBox.h" +#include +#include "simmodlg.h" +#include "ui_simmodlg.h" +#include +#include +#include +#include "CDataMng.h" +#include "pub_utility_api/TimeUtil.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +SimMoDlg::SimMoDlg(int windowId,QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SimMoDlg) +{ + ui->setupUi(this); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentPointNo = -1; + m_CurrentRtuRow = -1; + m_StartIndex = 0; + m_EndIndex = 0; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,200); + ui->PointTable->setColumnWidth(4,80); + ui->PointTable->setColumnWidth(5,80); + + ui->SelectButton->setChecked(true); + m_order = Qt::AscendingOrder; + m_bCanSort = false; + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->PointTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnPointCellClick(int,int))); + connect(ui->ControlButton,SIGNAL(clicked()),this,SLOT(OnControl())); + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&SimMoDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&SimMoDlg::sort,Qt::QueuedConnection); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); +} + +SimMoDlg::~SimMoDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipMo!= NULL) + free((m_pRtuInfo+i)->pMo); + } + free(m_pRtuInfo); + } + delete ui; +} + +void SimMoDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SimMoDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + + ui->comboBox->setModel(model); +} + +void SimMoDlg::initSig() +{ + connect(this,&SimMoDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_simMoRtuInfoResp,this,&SimMoDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simMoParamResp,this,&SimMoDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simMoControlResp,this,&SimMoDlg::slot_OnRecvResp); +} + +void SimMoDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadMoInfo(m_CurrentRtuNo); +} + +void SimMoDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SimMoDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentPointNo = -1; + m_CurrentRtuNo = -1; + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimMO_RtuInfo); + objMsg.set_body("MT_FESDBG_SimMO_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimMoDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimMO_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimMoDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_SimMO_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_SimMO_Param: + onRecvMoParamResp(strBody); + break; + case MT_FESDBG_SimMO_Control: + onRecvControlResp(strBody); + break; + default: + break; + } +} + +void SimMoDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("SimMoDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SMoMonRtu *pMoRtu = m_pRtuInfo + nIdx; + pMoRtu->RtuNo = pRtuInfo->rtu_no(); + pMoRtu->Used = pRtuInfo->used(); + strncpy(pMoRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pMoRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void SimMoDlg::onRecvMoParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SimMoDlg::onRecvMoParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SMoMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocMoParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pMo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getMoInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimMoParam *pMo = pRtu->pMo + pParam->pnt_no(); + pMo->PointNo = pParam->pnt_no(); + pMo->Used = pParam->used(); + memset(pMo->PointTagName,0,sizeof(pMo->PointTagName)); + strncpy(pMo->PointTagName,pParam->pnt_desc().c_str(),sizeof(pMo->PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,4,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,5,item); + item->setTextAlignment(Qt::AlignCenter); + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; +} + +void SimMoDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SMoMonRtu*)realloc(m_pRtuInfo,sizeof(SMoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SMoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SMoMonRtu*)malloc(sizeof(SMoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SMoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SMoMonRtu*)malloc(sizeof(SMoMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SMoMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void SimMoDlg::mallocMoParam(SMoMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pMo != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pMo = (SFesSimMoParam*)realloc(pRtu->pMo,sizeof(SFesSimMoParam)*pRtu->MaxPoints); + if (pRtu->pMo != NULL) + { + memset(pRtu->pMo, 0, sizeof(SFesSimMoParam)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pMo = (SFesSimMoParam*)malloc(sizeof(SFesSimMoParam)*pRtu->MaxPoints); + if(pRtu->pMo != NULL) + { + memset(pRtu->pMo,0,sizeof(SFesSimMoParam)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pMo==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pMo = (SFesSimMoParam*)malloc(sizeof(SFesSimMoParam)*pRtu->MaxPoints); + if (pRtu->pMo != NULL) + { + memset(pRtu->pMo, 0, sizeof(SFesSimMoParam)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void SimMoDlg::OnRtuCellClick(int row,int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuRow == row) + { + return ; + } + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayMoParam(m_CurrentRtuNo); + } +} + +void SimMoDlg::OnPointCellClick(int row,int column) +{ + Q_UNUSED(column); + m_CurrentPointRow = row; + QString RtuStr = ui->PointTable->item(m_CurrentPointRow,0)->text(); + bool ok; + m_CurrentPointNo=RtuStr.toInt(&ok,10); + + if(ok==false) + { + m_CurrentPointNo = -1; + } +} + +SMoMonRtu* SimMoDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void SimMoDlg::DisplayMoParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + + initCombox(); + OnPointInfoRefresh(); +} + +void SimMoDlg::OnControl() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + if(m_CurrentPointNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + FesDebugToolSimControlReqMsg reqMsg; + if(ui->SelectButton->isChecked()) + { + reqMsg.set_ctrl_type(CN_ControlSelect); + } + else if(ui->ExecuteButton->isChecked()) + { + reqMsg.set_ctrl_type(CN_ControlExecute); + } + else if(ui->AbortButton->isChecked()) + { + reqMsg.set_ctrl_type(CN_ControlAbort); + } + + m_lCtrlSeqNo = getMonotonicMsec(); + reqMsg.set_seq_no(m_lCtrlSeqNo); + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.set_int_value(ui->ValueEdit->text().toInt()); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimMO_Control); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimMoDlg::onRecvControlResp(const std::string &strBody) +{ + FesDebugToolSimControlRepMsg repMsg; + if(!repMsg.ParseFromString(strBody)) + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行失败!原因:响应消息解析失败")); + return; + } + + if(m_lCtrlSeqNo != repMsg.seq_no()) + { + return; + } + + if(repMsg.success()) + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行成功!")); + } + else + { + N_MessageBox::warning(this,tr("信息"),tr("控制执行失败!原因:%1").arg(repMsg.err_msg().c_str())); + } +} + +void SimMoDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void SimMoDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 4) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); +} diff --git a/product/src/tools/debug_tool_v2/simmodlg.h b/product/src/tools/debug_tool_v2/simmodlg.h new file mode 100644 index 00000000..db72e098 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simmodlg.h @@ -0,0 +1,79 @@ +#ifndef SIMMODLG_H +#define SIMMODLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "ComProtocolThread.h" + +namespace Ui { +class SimMoDlg; +} + +class SimMoDlg : public QDialog +{ + Q_OBJECT + +public: + explicit SimMoDlg(int windowId,QWidget *parent ); + ~SimMoDlg(); + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointCellClick(int row,int column); + void OnControl(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvMoParamResp(const std::string &strBody); + void onRecvControlResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocMoParam(SMoMonRtu *pRtu,const int nSize); + +private: + Ui::SimMoDlg *ui; + SMoMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayMoParam(int RtuNo); + + int m_RtuNum; + SMoMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_StartIndex; + int m_EndIndex; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_CurrentPointRow; + int m_CurrentPointNo; + + int m_nWindowId;// 用来判断是否激活窗口 + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; + int64 m_lCtrlSeqNo; +}; + +#endif // SIMMODLG_H diff --git a/product/src/tools/debug_tool_v2/simmodlg.ui b/product/src/tools/debug_tool_v2/simmodlg.ui new file mode 100644 index 00000000..06aa305f --- /dev/null +++ b/product/src/tools/debug_tool_v2/simmodlg.ui @@ -0,0 +1,418 @@ + + + SimMoDlg + + + + 0 + 0 + 647 + 280 + + + + 混合量输出 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 远动号 + + + + + 使用标志 + + + + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + + 0 + 0 + + + + QGroupBox { + border: 1px solid gray; + margin-top: 1ex; /* leave space at the top for the title */ + } + QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top center; + } + + + + + + Qt::AlignJustify|Qt::AlignVCenter + + + + 15 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 选择 + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 执行 + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 放弃 + + + + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 控制值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 控制执行 + + + + + + + + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/simpidlg.cpp b/product/src/tools/debug_tool_v2/simpidlg.cpp new file mode 100644 index 00000000..c1f4bef3 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simpidlg.cpp @@ -0,0 +1,1048 @@ +//2018-8-31 jacky 增加区间点刷新的非法字符判断 +#include "pub_widget/MessageBox.h" +#include +#include "simpidlg.h" +#include "ui_simpidlg.h" +#include +#include +#include +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; + +SimPiDlg::SimPiDlg(int windowId, QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SimPiDlg) +{ + ui->setupUi(this); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |= Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + ui->comboBox->setView(new QListView()); + m_ConnectFlag=CN_CommDisconnect; + m_RtuNum = 0; + m_pRtuInfo = NULL; + m_CurrentRtuNo = -1; + m_CurrentRtuRow = -1; + m_RefreshMode = 0; + m_RefreshFlag = 0; + m_RefreshTimer = NULL; + m_FrameProcess = 0; + + ui->RTUTable->setColumnWidth(0,60); + ui->RTUTable->setColumnWidth(1,60); + //ui->RTUTable->setColumnWidth(2,120); + + ui->PointTable->setColumnWidth(0,40); + ui->PointTable->setColumnWidth(1,60); + ui->PointTable->setColumnWidth(2,150); + ui->PointTable->setColumnWidth(3,150); + ui->PointTable->setColumnWidth(4,100); + ui->PointTable->setColumnWidth(5,100); + ui->PointTable->setColumnWidth(6,250); + ui->PointTable->setColumnWidth(7,80); + ui->PointTable->setColumnWidth(8,80); + ui->PointTable->setColumnWidth(9,120); + + m_CurrentPointNo = -1; + m_StartIndex = -1; + m_EndIndex = -1; + + + m_CurrentPiFlag = true; + ui->CurrentPointButton->setChecked(m_CurrentPiFlag); + m_order = Qt::AscendingOrder; + m_bCanSort = false; + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RtuRefreshButton,SIGNAL(clicked()),this,SLOT(OnRTURefresh())); + connect(ui->RTUTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnRtuCellClick(int,int))); + connect(ui->ValueRefreshButton ,SIGNAL(clicked()),this,SLOT(OnPointValueRefresh())); + connect(ui->PointTable,SIGNAL(cellClicked(int,int)),this,SLOT(OnPointCellClick(int,int))); + connect(ui->SetButton ,SIGNAL(clicked()),this,SLOT(OnSetValue())); + connect(ui->LineSetButton ,SIGNAL(clicked()),this,SLOT(OnLineSet())); + connect(ui->RandSetButton ,SIGNAL(clicked()),this,SLOT(OnRandSet())); + connect(ui->StopSetButton ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + connect(ui->StopSetButton2 ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + connect(ui->StopSetButton3 ,SIGNAL(clicked()),this,SLOT(OnStopSet())); + + connect(ui->comboBox,&QComboBox::currentTextChanged,this,&SimPiDlg::filterShow); + connect(ui->PointTable->horizontalHeader(),&QHeaderView::sectionClicked,this,&SimPiDlg::sort,Qt::QueuedConnection); + ui->PointTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->horizontalHeader()->setStretchLastSection(true); + ui->RTUTable->setSelectionMode(QAbstractItemView::SingleSelection); + ui->RTUTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->RTUTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui->PointTable->setColumnHidden(1,true); + + initSig(); + +} + +SimPiDlg::~SimPiDlg() +{ + if(m_pRtuInfo!=NULL) + { + for(int i=0;ipAcc!= NULL) + free((m_pRtuInfo+i)->pAcc); + } + free(m_pRtuInfo); + } + + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + delete ui; +} + +void SimPiDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SimPiDlg::initCombox() +{ + ui->comboBox->clear(); + const DevInfoMap &devinfoMap = CDataMng::instance()->getDevInfoRef().value(m_CurrentRtuNo); + QStandardItemModel *model =new QStandardItemModel(); + + QStandardItem *item = new QStandardItem("ALL"); + item->setData("ALL",Qt::UserRole+1); + model->appendRow(item); + + auto it = devinfoMap.begin(); + while (it != devinfoMap.end()) { + QStandardItem *item = new QStandardItem(it.value().strDesc); + item->setData(it.key(),Qt::UserRole+1); + model->appendRow(item); + it++; + } + + ui->comboBox->setModel(model); +} + +void SimPiDlg::initSig() +{ + connect(this,&SimPiDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); + connect(CDataMng::instance(),&CDataMng::signal_simAccRtuInfoResp,this,&SimPiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAccParamResp,this,&SimPiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAccValueResp,this,&SimPiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAccStartSimResp,this,&SimPiDlg::slot_OnRecvResp); + connect(CDataMng::instance(),&CDataMng::signal_simAccStopSimResp,this,&SimPiDlg::slot_OnRecvResp); +} + +void SimPiDlg::getPoint() +{ + CDataMng::instance()->loadAllDevInfo(); + CDataMng::instance()->loadAccInfo(m_CurrentRtuNo); +} + +void SimPiDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SimPiDlg::OnRTURefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + //stop other windows data refresh + m_CurrentRtuRow = -1; + m_CurrentPointNo = -1; + m_CurrentRtuNo = -1; + changePointValueRefreshBtnToStop(); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimACC_RtuInfo); + objMsg.set_body("MT_FESDBG_SimACC_RtuInfo"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + + +void SimPiDlg::OnPointInfoRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + isEndOneRefresh = false; + + FesDebugToolPntParamReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimACC_Param); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimPiDlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_SimACC_RtuInfo: + onRecvRtuInfoResp(strBody); + break; + case MT_FESDBG_SimACC_Param: + onRecvAccParamResp(strBody); + break; + case MT_FESDBG_SimACC_Value: + onRecvAccValueResp(strBody); + break; + case MT_FESDBG_SimACC_StartSim: + onRecvStartSimResp(strBody); + break; + case MT_FESDBG_SimACC_StopSim: + onRecvStopSimResp(strBody); + break; + default: + break; + } +} + +void SimPiDlg::onRecvRtuInfoResp(const std::string &strBody) +{ + //清除表格 + ui->RTUTable->setRowCount(0); + ui->RTUTable->clearContents(); + + FesDebugToolRtuInfoRepMsg respMsg; + if(!respMsg.ParseFromString(strBody)) + { + LOGINFO("SimPiDlg:反序列化失败"); + return; + } + + int nTotalNum = respMsg.mutable_rtu_info()->size(); + mallocRtuInfo(nTotalNum); + + if(m_pRtuInfo == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < nTotalNum; nIdx++) + { + FesDebugToolRtuInfo *pRtuInfo = respMsg.mutable_rtu_info(nIdx); + + SAccMonRtu *pAccRtu = m_pRtuInfo + nIdx; + pAccRtu->RtuNo = pRtuInfo->rtu_no(); + pAccRtu->Used = pRtuInfo->used(); + strncpy(pAccRtu->RtuName,pRtuInfo->rtu_desc().c_str(),sizeof(pAccRtu->RtuName) - 1); + + ui->RTUTable->insertRow(nIdx); + + QTableWidgetItem *itemRtuNo = new QTableWidgetItem(QString::number(pRtuInfo->rtu_no())); + QTableWidgetItem *itemRtuUse = new QTableWidgetItem(QString::number(pRtuInfo->used())); + QTableWidgetItem *itemRtuName = new QTableWidgetItem(QString(pRtuInfo->rtu_desc().c_str())); + itemRtuNo->setTextAlignment(Qt::AlignCenter); + itemRtuUse->setTextAlignment(Qt::AlignCenter); + + ui->RTUTable->setItem(nIdx,0,itemRtuNo); + ui->RTUTable->setItem(nIdx,1,itemRtuUse); + ui->RTUTable->setItem(nIdx,2,itemRtuName); + } +} + +void SimPiDlg::onRecvAccParamResp(const std::string &strBody) +{ + //清除表格 + ui->PointTable->setRowCount(0); + m_dotColumnMap.clear(); + ui->PointTable->clearContents(); + + FesDebugToolPntParamRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SimPiDlg::onRecvAccParamResp 反序列化失败"); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + return; + } + + SAccMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + return; + } + + mallocAccParam(pRtu,recvMsg.max_pnt_num()); + if(pRtu->pAcc == NULL) + { + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_pnt_param()->size(); nIdx++) + { + FesDebugToolPntParam *pParam = recvMsg.mutable_pnt_param(nIdx); + if(pParam->pnt_no() >= pRtu->MaxPoints) + { + continue; + } + + const RtuPointMap &mapRtu2Pnt = CDataMng::instance()->getAccInfoRef(); + auto rtuIter = mapRtu2Pnt.find(pRtu->RtuNo); + if(rtuIter == mapRtu2Pnt.end()) + { + continue; + } + + auto pntIter = rtuIter.value().find(pParam->pnt_no()); + if(pntIter == rtuIter.value().end()) + { + continue; + } + + const SFESPOINTINFO &pntInfo = pntIter.value(); + + SFesSimAcc *pAcc = pRtu->pAcc + pParam->pnt_no(); + pAcc->param.PointNo = pParam->pnt_no(); + pAcc->param.Used = pParam->used(); + memset(pAcc->param.PointTagName,0,sizeof(pAcc->param.PointTagName)); + strncpy(pAcc->param.PointTagName,pParam->pnt_desc().c_str(),sizeof(pAcc->param.PointTagName) - 1); + + int rowCount = ui->PointTable->rowCount(); + ui->PointTable->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->pnt_no()); + ui->PointTable->setItem(rowCount,0,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pParam->pnt_desc().c_str())); + ui->PointTable->setItem(rowCount,1,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDevDesc)); + ui->PointTable->setItem(rowCount,2,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strDesc)); + ui->PointTable->setItem(rowCount,3,item); + + item = new QTableWidgetItem(); + item->setText(QString(pntInfo.strAppTagName)); + ui->PointTable->setItem(rowCount,6,item); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pntInfo.nRespPara); + ui->PointTable->setItem(rowCount,7,item); + item->setTextAlignment(Qt::AlignCenter); + + item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole,pParam->used()); + ui->PointTable->setItem(rowCount,8,item); + item->setTextAlignment(Qt::AlignCenter); + + m_dotColumnMap[pParam->pnt_no()] = rowCount; + } + + ui->PointTable->viewport()->update(); + + isEndOneRefresh = true; + m_bCanSort = true; + m_RefreshFlag = 0; + OnPointValueStartRefresh(); +} + + +void SimPiDlg::onRecvAccValueResp(const std::string &strBody) +{ + FesDebugToolPntValueRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("SimPiDlg::onRecvPiDataResp 反序列化失败"); + changePointValueRefreshBtnToStop(); + return; + } + + if(m_CurrentRtuNo != recvMsg.rtu_no()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + SAccMonRtu *pRtu = GetRtuByRtuNo(recvMsg.rtu_no()); + if(pRtu == NULL) + { + changePointValueRefreshBtnToStop(); + return; + } + + for(int nIdx = 0; nIdx < recvMsg.mutable_double_values()->size(); nIdx++) + { + FesDebugToolDoublePntValue *pParam = recvMsg.mutable_double_values(nIdx); + + if(pParam->pnt_no() < pRtu->MaxPoints) + { + SFesSimAcc *pAcc = pRtu->pAcc + pParam->pnt_no(); + pAcc->value.PointNo = pParam->pnt_no(); + pAcc->value.Value = pParam->value(); + pAcc->value.Status = pParam->status(); + pAcc->value.time = pParam->time(); + + updateData(pAcc->value); + } + } + + m_FrameProcess = 0; + isEndOneRefresh = true; + ui->PointTable->viewport()->update(); +} + +void SimPiDlg::mallocRtuInfo(const int nSize) +{ + if(nSize != m_RtuNum) + { + m_RtuNum = nSize; + if(m_pRtuInfo != NULL)//清除原有的空间,从新分配空间 + { + m_pRtuInfo = (SAccMonRtu*)realloc(m_pRtuInfo,sizeof(SAccMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAccMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + else + { + m_pRtuInfo = (SAccMonRtu*)malloc(sizeof(SAccMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAccMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((m_pRtuInfo == NULL) && (m_RtuNum > 0)) + { + m_pRtuInfo = (SAccMonRtu*)malloc(sizeof(SAccMonRtu)*m_RtuNum); + if(m_pRtuInfo != NULL) + { + memset(m_pRtuInfo,0,sizeof(SAccMonRtu)*m_RtuNum); + } + else + { + m_RtuNum = 0; + } + } + } +} + +void SimPiDlg::mallocAccParam(SAccMonRtu *pRtu,const int nSize) +{ + if(nSize != pRtu->MaxPoints) + { + pRtu->MaxPoints = nSize; + if(pRtu->pAcc != NULL)//清除原有的空间,从新分配空间 + { + pRtu->pAcc = (SFesSimAcc*)realloc(pRtu->pAcc,sizeof(SFesSimAcc)*pRtu->MaxPoints); + if (pRtu->pAcc != NULL) + { + memset(pRtu->pAcc, 0, sizeof(SFesSimAcc)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + else + { + pRtu->pAcc = (SFesSimAcc*)malloc(sizeof(SFesSimAcc)*pRtu->MaxPoints); + if(pRtu->pAcc != NULL) + { + memset(pRtu->pAcc,0,sizeof(SFesSimAcc)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } + else //数量相同,应该已分配过 + { + if((pRtu->pAcc==NULL)&&(pRtu->MaxPoints>0)) + { + pRtu->pAcc = (SFesSimAcc*)malloc(sizeof(SFesSimAcc)*pRtu->MaxPoints); + if (pRtu->pAcc != NULL) + { + memset(pRtu->pAcc, 0, sizeof(SFesSimAcc)*pRtu->MaxPoints); + } + else + { + pRtu->MaxPoints = 0; + } + } + } +} + +void SimPiDlg::sendAccValueReqMsg() +{ + FesDebugToolPntValueReqMsg reqMsg; + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_start_index(m_StartIndex); + reqMsg.set_end_index(m_EndIndex); + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_SimACC_Value); + objMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SimPiDlg::OnRtuCellClick(int row, int column) +{ + Q_UNUSED(column); + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + m_CurrentPointNo = -1; + + if(m_CurrentRtuRow == row) + { + OnPointValueStartRefresh(); + return ; + } + + m_CurrentRtuRow = row; + QString RtuStr = ui->RTUTable->item(m_CurrentRtuRow,0)->text(); + bool ok; + m_CurrentRtuNo=RtuStr.toInt(&ok,10); + if(ok==false) + { + m_CurrentRtuNo = -1; + } + else + { + m_bCanSort = false; + DisplayPiParam(m_CurrentRtuNo); + } +} + +void SimPiDlg::OnPointCellClick(int row,int column) +{ + Q_UNUSED(column); + m_CurrentPointRow = row; + QString RtuStr = ui->PointTable->item(m_CurrentPointRow,0)->text(); + bool ok; + m_CurrentPointNo=RtuStr.toInt(&ok,10); + + if(ok==false) + { + m_CurrentPointNo = -1; + } +} + +SAccMonRtu* SimPiDlg::GetRtuByRtuNo(int RtuNo) +{ + for(int i=0;iRtuNo == RtuNo) + return pRtu; + } + return NULL; +} + +void SimPiDlg::DisplayPiParam(int RtuNo) +{ + Q_UNUSED(RtuNo); + getPoint(); + + initCombox(); + OnPointInfoRefresh(); +} + +void SimPiDlg::updateData(const SFesSimAccData &piData) +{ + auto iter = m_dotColumnMap.find(piData.PointNo); + if(iter == m_dotColumnMap.end()) + { + return; + } + + QDateTime dt = QDateTime::fromSecsSinceEpoch(piData.time/1000); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss"); + qint64 msTime = piData.time%1000; + tStr = QString("%1.%2").arg(tStr).arg(msTime,3,10,QLatin1Char('0')); + + QTableWidgetItem *itemValue = new QTableWidgetItem(QString::number(piData.Value) ); + itemValue->setTextAlignment(Qt::AlignCenter); + + QTableWidgetItem *itemStatus = new QTableWidgetItem(getFesPointStatus(piData.Status) ); + itemStatus->setTextAlignment(Qt::AlignCenter); + if(piData.Status != CN_FesValueUpdate) itemStatus->setTextColor(Qt::red) ; + + + ui->PointTable->setItem(iter.value(),4,itemValue); + ui->PointTable->setItem(iter.value(),5,itemStatus); + ui->PointTable->setItem(iter.value(),9,new QTableWidgetItem(tStr)); + +} + +void SimPiDlg::changePointValueRefreshBtnToStop() +{ + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } + m_RefreshFlag = 0; + ui->ValueRefreshButton->setText(tr("数据刷新")); + m_FrameProcess = 0; +} + +bool SimPiDlg::initPointBrushData() +{ + QString devTag = ui->comboBox->currentData(Qt::UserRole+1).toString(); + + if(devTag == "") + { + return false; + }else if(devTag == "ALL") + { + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + m_RefreshMode = 1; //section + const RtuMaxAndMinPointNo &rtuMaxMinNo = CDataMng::instance()->getAccMaxMinNoRef(); + auto it = rtuMaxMinNo.find(m_CurrentRtuNo); + if(it == rtuMaxMinNo.end()) + { + LOGERROR("未找到rtu:[%d],刷新所有数据!",m_CurrentRtuNo); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + const MaxAndMinPointNo &devMap = it.value(); + auto itor = devMap.find(devTag); + if(itor == devMap.end()) + { + LOGERROR("未找到dev:[%s],刷新所有数据!",devTag.toStdString().c_str()); + m_RefreshMode = 0; + m_StartIndex = -1; + m_EndIndex = -1; + }else + { + SFESDEVMAXANDMINPOINTNO maxminNo = itor.value(); + m_StartIndex = maxminNo.minPointNo; + m_EndIndex = maxminNo.maxPointNo; + } + } + } + LOGTRACE("刷新设备[%s]的数据!",devTag.toStdString().c_str()); + return true; +} + +void SimPiDlg::OnPointValueStartRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAccValueReqMsg(); + } +} + +void SimPiDlg::OnPointValueRefresh() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changePointValueRefreshBtnToStop(); + return; + } + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->ValueRefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + isEndOneRefresh = true; + m_FrameProcess = 1; + + sendAccValueReqMsg(); + } + else + { + changePointValueRefreshBtnToStop(); + } +} + +void SimPiDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changePointValueRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + if(m_FrameProcess == 1)//一次数据读取过程结束,才开始新的读取 + { + return; + } + + if(!initPointBrushData()) + { + changePointValueRefreshBtnToStop(); + return ; + } + + if(!isEndOneRefresh) + { + return; + } + isEndOneRefresh = false; + + sendAccValueReqMsg(); +// ui->PointTable->viewport()->update(); +} + + +void SimPiDlg::OnSetValue() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_ValueSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)&&(m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.mutable_value_set_param()->set_value(ui->ValueEdit->text().toDouble()); + reqMsg.set_status(ui->StatusEdit->text().toUInt()); + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimACC_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimPiDlg::OnLineSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_LineSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint) && (m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.mutable_line_set_param()->set_min_value(ui->MinValueEdit->text().toFloat()); + reqMsg.mutable_line_set_param()->set_max_value(ui->MaxValueEdit->text().toFloat()); + reqMsg.mutable_line_set_param()->set_step_value(ui->StepValueEdit->text().toFloat()); + reqMsg.mutable_line_set_param()->set_period(ui->ChangeTimeEdit->text().toInt()); + + + if(reqMsg.mutable_line_set_param()->min_value() >= reqMsg.mutable_line_set_param()->max_value()) + { + N_MessageBox::warning(this,tr("告警"),tr("最大值小于最小值")); + return; + } + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimACC_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + + +void SimPiDlg::OnRandSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + //if(!this->isActiveWindow())//只有激活的窗口才可发送数据,避免发送数据冲突。 + // return; + + FesDebugToolValueSimSetReqMsg reqMsg; + reqMsg.set_sim_mode(MT_FESDBG_SM_RandSet); + + if(ui->CurrentPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_SinglePoint); + } + else if(ui->RTUPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_RtuPoint); + } + else if(ui->AllPointButton->isChecked()) + { + reqMsg.set_sim_range(MT_FESDBG_RT_AllPoint); + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_RtuPoint) || (reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint)) + { + if(m_CurrentRtuNo == -1) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择RTU,请选择!")); + return; + } + } + + if((reqMsg.sim_range() == MT_FESDBG_RT_SinglePoint) && (m_CurrentPointNo == -1)) + { + N_MessageBox::warning(this,tr("告警"),tr("没有选择点,请选择!")); + return; + } + + reqMsg.set_rtu_no(m_CurrentRtuNo); + reqMsg.set_pnt_no(m_CurrentPointNo); + reqMsg.mutable_rand_set_param()->set_period(10); //暂时写死10秒变化一次 + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimACC_StartSim); + sendMsg.set_body(reqMsg.SerializeAsString()); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimPiDlg::OnStopSet() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + FesDebugToolReqMsg sendMsg; + sendMsg.set_type(MT_FESDBG_SimACC_StopSim); + sendMsg.set_body("MT_FESDBG_SimACC_StopSim"); + + emit signal_sendMsg(sendMsg.SerializeAsString()); +} + +void SimPiDlg::filterShow(const QString &text) +{ + if(text.isEmpty()) + { + return ; + } + + int rowCount = ui->PointTable->rowCount(); + for(int i = 0 ; i < rowCount; ++i) + { + if(text == "ALL") + { + ui->PointTable->setRowHidden(i,false); + continue; + } + QString cellText = ui->PointTable->item(i,2)->text(); + if(cellText.compare(text) == 0) + { + ui->PointTable->setRowHidden(i,false); + }else + { + ui->PointTable->setRowHidden(i,true); + } + } +} + +void SimPiDlg::sort(int logicalIndex) +{ + if(!m_bCanSort) + { + return ; + } + if(logicalIndex != 0 && logicalIndex != 7) + { + ui->PointTable->horizontalHeader()->setSortIndicatorShown(false); + return ; + } + ui->PointTable->setSortingEnabled(true); + if(m_order == Qt::DescendingOrder) + { + m_order = Qt::AscendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + }else + { + m_order = Qt::DescendingOrder; + ui->PointTable->horizontalHeader()->setSortIndicator(logicalIndex,m_order); + } + ui->PointTable->setSortingEnabled(false); + ui->PointTable->horizontalHeader()->setSortIndicatorShown(true); + + m_dotColumnMap.clear(); + int rowCount = ui->PointTable->rowCount(); + for (int i = 0; i < rowCount; ++i) + { + int nPntNo = ui->PointTable->item(i, 0)->text().toInt(); + m_dotColumnMap[nPntNo] = i; + } +} + +void SimPiDlg::onRecvStartSimResp(const std::string &strBody) +{ + FesDebugToolValueSimSetRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGERROR("SimPiDlg::onRecvStartSimResp 反序列化失败"); + return; + } + + switch(recvMsg.sim_mode()) + { + case MT_FESDBG_SM_ValueSet: + N_MessageBox::warning(this,tr("信息"),tr("固定设置成功!")); + break; + case MT_FESDBG_SM_LineSet: + N_MessageBox::warning(this,tr("信息"),tr("线性设置成功!")); + break; + case MT_FESDBG_SM_RandSet: + N_MessageBox::warning(this,tr("信息"),tr("随机设置成功!")); + break; + default: + break; + } +} + +void SimPiDlg::onRecvStopSimResp(const std::string &strBody) +{ + Q_UNUSED(strBody); + //N_MessageBox::warning(this,tr("信息"),tr("停止设置成功!")); +} diff --git a/product/src/tools/debug_tool_v2/simpidlg.h b/product/src/tools/debug_tool_v2/simpidlg.h new file mode 100644 index 00000000..2f3fc611 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simpidlg.h @@ -0,0 +1,104 @@ +#ifndef SIMPIDLG_H +#define SIMPIDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "CSystemResources.h" +#include "toolCommon.h" +#include "FesDebugTool.pb.h" +#include "FesSimProtocol.h" +#include "ComProtocolThread.h" + +namespace Ui { +class SimPiDlg; +} + +class SimPiDlg : public QDialog +{ + Q_OBJECT + +public: + explicit SimPiDlg(int windowId,QWidget *parent ); + ~SimPiDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initCombox(); + void initSig(); + void getPoint(); + +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRTURefresh(); + void OnPointInfoRefresh(); + void OnRtuCellClick(int row,int column); + void OnPointValueRefresh(); + + void OnPointCellClick(int row,int column); + void OnSetValue(); + void OnLineSet(); + void OnRandSet(); + void OnStopSet(); + void filterShow(const QString &text); + + void sort(int logicalIndex); + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvRtuInfoResp(const std::string &strBody); + void onRecvAccParamResp(const std::string &strBody); + void onRecvAccValueResp(const std::string &strBody); + void onRecvStartSimResp(const std::string &strBody); + void onRecvStopSimResp(const std::string &strBody); + + void mallocRtuInfo(const int nSize); + void mallocAccParam(SAccMonRtu *pRtu,const int nSize); + void sendAccValueReqMsg(); + +private: + Ui::SimPiDlg *ui; + SAccMonRtu* GetRtuByRtuNo(int RtuNo); + void DisplayPiParam(int RtuNo); + + void updateData(const SFesSimAccData &piData); + + void changePointValueRefreshBtnToStop(); + + bool initPointBrushData(); + + void OnPointValueStartRefresh(); + + int m_RtuNum; + SAccMonRtu *m_pRtuInfo; + int m_CurrentRtuRow; + int m_CurrentRtuNo; + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_RefreshMode; //0: all 1:区间 + int m_StartIndex; + int m_EndIndex; + QTimer *m_RefreshTimer; + int m_FrameProcess; //1 :正在读取中(包括多帧情况) 0:一次数据读取过程结束 + + int m_CurrentPointRow; + int m_CurrentPointNo; + bool m_CurrentPiFlag; + + int m_nWindowId;// 用来判断是否激活窗口 + QMap m_dotColumnMap; + + Qt::SortOrder m_order; + bool m_bCanSort; + bool isEndOneRefresh; +}; + +#endif // SIMPIDLG_H diff --git a/product/src/tools/debug_tool_v2/simpidlg.ui b/product/src/tools/debug_tool_v2/simpidlg.ui new file mode 100644 index 00000000..4b78c230 --- /dev/null +++ b/product/src/tools/debug_tool_v2/simpidlg.ui @@ -0,0 +1,913 @@ + + + SimPiDlg + + + + 0 + 0 + 848 + 607 + + + + + 0 + 0 + + + + 电度量仿真 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 30 + 20 + + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 前置设备 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 250 + 23 + + + + QComboBox::AdjustToContents + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 点号 + + + + + 标签名 + + + + + 设备 + + + + + 点描述 + + + + + 点值 + + + + + 点状态 + + + + + 后台标签 + + + + + 远动号 + + + + + 使用标志 + + + + + 时间 + + + + + + + + + 305 + 23 + + + + + 305 + 25 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + RTU刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + 305 + 0 + + + + + 305 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked + + + QAbstractItemView::SelectRows + + + false + + + + RTU号 + + + + + 使用标志 + + + + + 描述 + + + + + + + + + 0 + 0 + + + + QGroupBox { + border: 1px solid gray; + margin-top: 1ex; /* leave space at the top for the title */ + } + QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top center; + } + + + + + + Qt::AlignJustify|Qt::AlignVCenter + + + + 15 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 当前测点 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 当前RTU + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 所有RTU + + + + + + + + + + + + + 0 + 130 + + + + + 16777215 + 130 + + + + 0 + + + + 固定置数 + + + + 0 + + + 12 + + + 0 + + + 0 + + + 6 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 10 + + + + + 16777215 + 30 + + + + 点状态: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 固定设置 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 线性置数 + + + + 0 + + + 12 + + + 0 + + + 0 + + + 6 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 线性设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 步长值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 周期秒: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 最小值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 最大值: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 随机置数 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 随机设置 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 停止设置 + + + + + + + Qt::Vertical + + + + 296 + 88 + + + + + + + + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/soeeventdlg.cpp b/product/src/tools/debug_tool_v2/soeeventdlg.cpp new file mode 100644 index 00000000..64f39d7c --- /dev/null +++ b/product/src/tools/debug_tool_v2/soeeventdlg.cpp @@ -0,0 +1,228 @@ +#include "pub_widget/MessageBox.h" +#include +#include "soeeventdlg.h" +#include "ui_soeeventdlg.h" +#include "CActiveWindow.h" +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +SoeEventDlg::SoeEventDlg(int windowId,QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SoeEventDlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + + m_ConnectFlag=CN_CommDisconnect; + m_RefreshFlag = 0; + m_TotalCounts = 0; + + ui->EventTable->setColumnWidth(0,180);//time + ui->EventTable->setColumnWidth(1,250);//tagName + + m_RefreshTimer = new QTimer(this); + if(m_RefreshTimer!=NULL) + connect(m_RefreshTimer,SIGNAL(timeout()),this,SLOT(OnRefeshTimer())); + connect(ui->RefreshButton,SIGNAL(clicked()),this,SLOT(OnRefreshData())); + connect(ui->ClearButton,SIGNAL(clicked()),this,SLOT(OnClearData())); + initSig(); +} + +SoeEventDlg::~SoeEventDlg() +{ + if(m_RefreshTimer != NULL) + delete m_RefreshTimer; + + delete ui; +} + +void SoeEventDlg::OnRefeshTimer() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + changeRefreshBtnToStop(); + return; + } + if(CActiveWindow::instance()->getActiveWindow() != m_nWindowId) + { + return ; + } + + sendSoeEventReqMsg(); +} + + +void SoeEventDlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SoeEventDlg::initSig() +{ + connect(CDataMng::instance(),&CDataMng::signal_soeEventResp,this,&SoeEventDlg::slot_OnRecvResp); + connect(this,&SoeEventDlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); +} + +void SoeEventDlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SoeEventDlg::OnRefreshData() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->RefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + sendSoeEventReqMsg(); + } + else + { + changeRefreshBtnToStop(); + } +} + +void SoeEventDlg::OnStartRefreshData() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + m_RefreshFlag = 0; + changeRefreshBtnToStop(); + return; + } + + if(m_RefreshFlag == 0) + { + m_RefreshFlag = 1; + ui->RefreshButton->setText(tr("停止刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->start(1000); + } + + sendSoeEventReqMsg(); + } +} + +void SoeEventDlg::OnClearData() +{ + ui->EventTable->clearContents(); + ui->EventTable->setRowCount(0); + m_TotalCounts = 0; + ui->TotalCount->setText(QString::number(m_TotalCounts)); +} + +void SoeEventDlg::slot_OnRecvResp(int nMsgType, const std::string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_Event_SOE: + onRecvSoeEventResp(strBody); + break; + default: + break; + } +} + +void SoeEventDlg::onRecvSoeEventResp(const std::string &strBody) +{ + FesDebugToolSoeEventRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SoeEventDlg::onRecvSoeEventResp 反序列化失败"); + return; + } + + int row = ui->EventTable->rowCount(); + if(recvMsg.over_flow() == 1) + { + //显示溢出提示 + ui->EventTable->insertRow(row); + ui->EventTable->setItem(row,0,new QTableWidgetItem(tr("缓冲区溢出"))); + row++; + } + + for(int i = 0; i < recvMsg.mutable_event()->size();i++) + { + if(row >= CN_FesSimSoeEventMaxBufSize) + { + ui->EventTable->setRowCount(0); + ui->EventTable->clearContents(); + row = 0; + } + ui->EventTable->insertRow(row); + + FesDebugToolSoeEvent *pEvent = recvMsg.mutable_event(i); + + QDateTime dt = QDateTime::fromSecsSinceEpoch(pEvent->time()/1000); + //dt = QDateTime::fromSecsSinceEpoch(event.time/1000,m_tz); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss") + "."; + tStr += QString::number(pEvent->time()%1000); + + ui->EventTable->setItem(row,0,new QTableWidgetItem(tStr)); + ui->EventTable->setItem(row,1,new QTableWidgetItem(QString(pEvent->tag_name().c_str()))); + ui->EventTable->setItem(row,2,new QTableWidgetItem(QString::number(pEvent->value()))); + ui->EventTable->setItem(row,3,new QTableWidgetItem(QString::number(pEvent->status()))); + ui->EventTable->setItem(row,4,new QTableWidgetItem(QString::number(pEvent->fault_num()))); + + for(int nFaultIdx = 0; nFaultIdx < pEvent->fault_num();nFaultIdx++) + { + ui->EventTable->setItem(row,5 + 2*nFaultIdx,new QTableWidgetItem(QString::number(pEvent->fault_type(nFaultIdx)))); + ui->EventTable->setItem(row,6 + 2*nFaultIdx,new QTableWidgetItem(QString::number(pEvent->fault_value(nFaultIdx)))); + } + + m_TotalCounts++; + } + + ui->TotalCount->setText(QString::number(m_TotalCounts)); +} + +void SoeEventDlg::sendSoeEventReqMsg() +{ + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_Event_SOE); + objMsg.set_body("MT_FESDBG_Event_SOE"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SoeEventDlg::changeRefreshBtnToStop() +{ + m_RefreshFlag = 0; + ui->RefreshButton->setText(tr("数据刷新")); + if(m_RefreshTimer != NULL) + { + m_RefreshTimer->stop(); + } +} diff --git a/product/src/tools/debug_tool_v2/soeeventdlg.h b/product/src/tools/debug_tool_v2/soeeventdlg.h new file mode 100644 index 00000000..e5296e88 --- /dev/null +++ b/product/src/tools/debug_tool_v2/soeeventdlg.h @@ -0,0 +1,61 @@ +#ifndef SOEEVENTDLG_H +#define SOEEVENTDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "CSystemResources.h" +#include "FesDebugTool.pb.h" +#include "ComProtocolThread.h" + +namespace Ui { +class SoeEventDlg; +} + +class SoeEventDlg : public QDialog +{ + Q_OBJECT + +public: + explicit SoeEventDlg(int windowId,QWidget *parent ); + ~SoeEventDlg(); + + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + void initSig(); +protected: + void keyPressEvent(QKeyEvent *event); +public slots: + void OnRefeshTimer(); + void OnRefreshData(); + void OnStartRefreshData(); + void OnClearData(); + + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvSoeEventResp(const std::string &strBody); + void sendSoeEventReqMsg(); + +private: + void changeRefreshBtnToStop(); + + +private: + Ui::SoeEventDlg *ui; + QTimeZone m_tz; + QTimer *m_RefreshTimer; + + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_TotalCounts; + int m_nWindowId;// 用来判断是否激活窗口 +}; + +#endif // SOEEVENTDLG_H diff --git a/product/src/tools/debug_tool_v2/soeeventdlg.ui b/product/src/tools/debug_tool_v2/soeeventdlg.ui new file mode 100644 index 00000000..71ad8075 --- /dev/null +++ b/product/src/tools/debug_tool_v2/soeeventdlg.ui @@ -0,0 +1,220 @@ + + + SoeEventDlg + + + + 0 + 0 + 558 + 333 + + + + SOE事件 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 清除事件 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 事件总数: + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SelectRows + + + false + + + + 时间 + + + + + 标签名 + + + + + 点值 + + + + + 点状态 + + + + + 故障个数 + + + + + 故障源1 + + + + + 故障值1 + + + + + 故障源2 + + + + + 故障值2 + + + + + 故障源3 + + + + + 故障值3 + + + + + 故障源4 + + + + + 故障值4 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/soememorydlg.cpp b/product/src/tools/debug_tool_v2/soememorydlg.cpp new file mode 100644 index 00000000..861aed8c --- /dev/null +++ b/product/src/tools/debug_tool_v2/soememorydlg.cpp @@ -0,0 +1,130 @@ +#include "pub_widget/MessageBox.h" +#include +#include "soememorydlg.h" +#include "ui_soememorydlg.h" +#include "CActiveWindow.h" +#include "FesSimProtocol.h" +#include "CDataMng.h" +#include "pub_logger_api/logger.h" + +using namespace std; +using namespace iot_idl; +using namespace iot_public; + +SoeMemorydlg::SoeMemorydlg(int windowId,QWidget *parent) : + QDialog(parent), + m_nWindowId(windowId), + ui(new Ui::SoeMemorydlg) +{ + ui->setupUi(this); + m_tz=QTimeZone::systemTimeZone(); + Qt::WindowFlags flags=Qt::Window; + // flags |=Qt::WindowMinMaxButtonsHint|Qt::WindowCloseButtonHint; + flags |=Qt::WindowCloseButtonHint; + setWindowFlags(flags); + //setFixedSize(this->width(),this->height());//固定窗口大小 + setAttribute(Qt::WA_DeleteOnClose); + + m_ConnectFlag=CN_CommDisconnect; + m_RefreshFlag = 0; + + ui->SoeTable->setColumnWidth(0,80);//序号 + ui->SoeTable->setColumnWidth(1,180);//time + ui->SoeTable->setColumnWidth(2,250);//标签名 + + connect(ui->RefreshButton,SIGNAL(clicked()),this,SLOT(OnRefreshData())); + + initSig(); +} + +SoeMemorydlg::~SoeMemorydlg() +{ + delete ui; +} + +void SoeMemorydlg::SetConnectFlags(int flags) //主界面传输连接标志到本窗口 +{ + m_ConnectFlag = flags; +} + +void SoeMemorydlg::initSig() +{ + connect(CDataMng::instance(),&CDataMng::signal_soeMemEventResp,this,&SoeMemorydlg::slot_OnRecvResp); + connect(this,&SoeMemorydlg::signal_sendMsg,CDataMng::instance(),&CDataMng::signal_sendMsgToServer); +} + +void SoeMemorydlg::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Escape: + + break; + default: + QDialog::keyPressEvent(event); + break; + } +} + +void SoeMemorydlg::OnRefreshData() +{ + if(m_ConnectFlag==CN_CommDisconnect) + { + N_MessageBox::warning(this,tr("告警"),tr("通信中断,无法读取数据。请连接FES系统!")); + return; + } + + FesDebugToolReqMsg objMsg; + objMsg.set_type(MT_FESDBG_Event_SOEMemory); + objMsg.set_body("MT_FESDBG_Event_SOEMemory"); + + emit signal_sendMsg(objMsg.SerializeAsString()); +} + +void SoeMemorydlg::slot_OnRecvResp(int nMsgType, const string &strBody) +{ + switch (nMsgType) { + case MT_FESDBG_Event_SOEMemory: + onRecvSoeEventResp(strBody); + break; + default: + break; + } +} + +void SoeMemorydlg::onRecvSoeEventResp(const std::string &strBody) +{ + FesDebugToolSoeEventRepMsg recvMsg; + if(!recvMsg.ParseFromString(strBody)) + { + LOGINFO("SoeMemorydlg::onRecvSoeEventResp 反序列化失败"); + return; + } + + ui->SoeTable->setRowCount(0); + ui->SoeTable->clearContents(); + + for(int row = 0; row < recvMsg.mutable_event()->size();row++) + { + ui->SoeTable->insertRow(row); + + FesDebugToolSoeEvent *pEvent = recvMsg.mutable_event(row); + + QDateTime dt = QDateTime::fromSecsSinceEpoch(pEvent->time()/1000); + //dt = QDateTime::fromSecsSinceEpoch(event.time/1000,m_tz); + QString tStr = dt.toString("yyyy-MM-dd hh:mm:ss") + "."; + tStr += QString::number(pEvent->time()%1000); + + ui->SoeTable->setItem(row,0,new QTableWidgetItem(QString::number(row))); + ui->SoeTable->setItem(row,1,new QTableWidgetItem(tStr)); + ui->SoeTable->setItem(row,2,new QTableWidgetItem(QString(pEvent->tag_name().c_str()))); + ui->SoeTable->setItem(row,3,new QTableWidgetItem(QString::number(pEvent->value()))); + ui->SoeTable->setItem(row,4,new QTableWidgetItem(QString::number(pEvent->status()))); + ui->SoeTable->setItem(row,5,new QTableWidgetItem(QString::number(pEvent->fault_num()))); + + for(int nFaultIdx = 0; nFaultIdx < pEvent->fault_num();nFaultIdx++) + { + ui->SoeTable->setItem(row,6 + 2*nFaultIdx,new QTableWidgetItem(QString::number(pEvent->fault_type(nFaultIdx)))); + ui->SoeTable->setItem(row,7 + 2*nFaultIdx,new QTableWidgetItem(QString::number(pEvent->fault_value(nFaultIdx)))); + } + } +} diff --git a/product/src/tools/debug_tool_v2/soememorydlg.h b/product/src/tools/debug_tool_v2/soememorydlg.h new file mode 100644 index 00000000..250ac127 --- /dev/null +++ b/product/src/tools/debug_tool_v2/soememorydlg.h @@ -0,0 +1,53 @@ +#ifndef SOEMEMORYDLG_H +#define SOEMEMORYDLG_H + +#include "pub_widget/CustomDialog.h" +#include +#include +#include +#include +#include "CSystemResources.h" +#include "FesDebugTool.pb.h" +#include "ComProtocolThread.h" + +namespace Ui { +class SoeMemorydlg; +} + +class SoeMemorydlg : public QDialog +{ + Q_OBJECT + +public: + explicit SoeMemorydlg(int windowId,QWidget *parent ); + ~SoeMemorydlg(); + void SetConnectFlags(int flags); //主界面传输连接标志到本窗口 + + void initSig(); +protected: + void keyPressEvent(QKeyEvent *event); + +public slots: + void OnRefreshData(); + + //接收FES消息的入口 + void slot_OnRecvResp(int nMsgType,const std::string &strBody); + +signals: + //发送请求消息到FES + void signal_sendMsg(const std::string &strMsg); + +private: + void onRecvSoeEventResp(const std::string &strBody); + +private: + Ui::SoeMemorydlg *ui; + QTimeZone m_tz; + QTimer *m_RefreshTimer; + + int m_ConnectFlag; //连接成功标志 + int m_RefreshFlag; //刷新标志 1:正再刷新 0:停止刷新 + int m_nWindowId;// 用来判断是否激活窗口 +}; + +#endif // SOEMEMORYDLG_H diff --git a/product/src/tools/debug_tool_v2/soememorydlg.ui b/product/src/tools/debug_tool_v2/soememorydlg.ui new file mode 100644 index 00000000..78e8b8f4 --- /dev/null +++ b/product/src/tools/debug_tool_v2/soememorydlg.ui @@ -0,0 +1,155 @@ + + + SoeMemorydlg + + + + 0 + 0 + 581 + 347 + + + + SOE内存 + + + + 0 + + + 6 + + + 0 + + + 0 + + + 1 + + + 6 + + + + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + 数据刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + false + + + + 序号 + + + + + 时间 + + + + + 标签名 + + + + + 点值 + + + + + 点状态 + + + + + 故障个数 + + + + + 故障源1 + + + + + 故障值1 + + + + + 故障源2 + + + + + 故障值2 + + + + + 故障源3 + + + + + 故障值3 + + + + + 故障源4 + + + + + 故障值4 + + + + + + + + + diff --git a/product/src/tools/debug_tool_v2/toolCommon.h b/product/src/tools/debug_tool_v2/toolCommon.h new file mode 100644 index 00000000..7880bd05 --- /dev/null +++ b/product/src/tools/debug_tool_v2/toolCommon.h @@ -0,0 +1,113 @@ +#ifndef TOOLCOMMON_H +#define TOOLCOMMON_H + +#include +#include +#include "FesDef.h" + +const std::string CN_ProcName_debug_tool = "debug_tool";//当前进程名 + +#define POINT_INVALID_STATUS 4 //测点无效状态 + +struct SFESPOINTINFO +{ + int nDotNo; + int nRtuNo; + QString strTagName; //前置标签 + QString strDesc; //前置点描述 + QString strAppTagName; //后台点标签 + int nRespPara; //远动号 + QString strDevTag; //设备标签 + QString strDevDesc; //设备描述 + SFESPOINTINFO() { + nDotNo =-1; + nRtuNo =-1; + strTagName =QString(); + strDesc =QString(); + strAppTagName =QString(); + nRespPara = -1; + strDevTag =QString(); + strDevDesc =QString(); + } +}; +struct SFESDEVINFO +{ + int nRtuNo; + QString strTagName; + QString strDevName; + QString strDesc; + SFESDEVINFO() { + nRtuNo = -1; + strTagName = QString(); + strDevName = QString(); + strDesc =QString(); + } +}; +struct SFESCHANINFO +{ + int nChanNo; + QString strTagName; + QString strDesc; + int nLocalPort; + + SFESCHANINFO() { + nChanNo = -1; + strTagName = QString(); + strDesc = QString(); + nLocalPort = -1; + } +}; +struct SFESDEVMAXANDMINPOINTNO +{ +// int nRtuNo; +// QString dev; + int minPointNo; + int maxPointNo; + SFESDEVMAXANDMINPOINTNO() { +// nRtuNo = -1; +// dev = QString(); + minPointNo = 10000000; + maxPointNo = -1; + } +}; + + +typedef struct{ + int appId; + QString appName; + QString desc; +}FesAppName; + +typedef QHash PointInfoMap; //<点号,测点信息> +typedef QHash RtuPointMap; // + +typedef QHash DevInfoMap; +typedef QHash RtuDevMap; // +typedef QHash ChanInfoMap; + +typedef QHash MaxAndMinPointNo; +typedef QHash RtuMaxAndMinPointNo; + +inline QString getFesPointStatus(int nStatus) +{ + QString strStatus = QString(QObject::tr("状态正常")); + //点值状态 + if( (nStatus & CN_FesValueUpdate) != CN_FesValueUpdate ) strStatus = QString(QObject::tr("值未更新")) ; //BIT0: 0:值未更新 1:点值更新 + if( (nStatus & CN_FesValueInvaild) == CN_FesValueInvaild ) strStatus = QString(QObject::tr("点值无效")) ; //BIT1:0:点值有效 1:点值无效 设备报告无效 + if( (nStatus & CN_FesValueExceed) == CN_FesValueExceed ) strStatus = QString(QObject::tr("点值超限")) ; //BIT2:0:点值正常 1:点值超限 + if( (nStatus & CN_FesValueComDown) == CN_FesValueComDown ) strStatus = QString(QObject::tr("通信中断")) ; //BIT3:0:通信正常 1: 通信中断 + // if( (nStatus & CN_FesDoUnBlocked) != CN_FesDoUnBlocked ) strStatus = QString(QObject::tr("五防闭锁")) ; //BIT7:0:五防闭锁 1: 五防解锁 + + return strStatus; +} + +inline QString getPointStatus(int nStatus) +{ + QString strStatus = QString(QObject::tr("正常")); + //点值状态 + if( (nStatus & POINT_INVALID_STATUS) == POINT_INVALID_STATUS ) strStatus = QString(QObject::tr("无效")) ; + + return strStatus; +} + +#endif // TOOLCOMMON_H diff --git a/product/src/tools/link_seq_tool/link_seq_tool.pro b/product/src/tools/link_seq_tool/link_seq_tool.pro new file mode 100644 index 00000000..4ea35c0e --- /dev/null +++ b/product/src/tools/link_seq_tool/link_seq_tool.pro @@ -0,0 +1,11 @@ + +#各子工程按书写顺序编译,清注意各子工程的依赖关系,被依赖的库应写在前面。 + +TEMPLATE = subdirs + +SUBDIRS += \ + linkage_server_tool \ + linkage_tuihuamian_tool \ + sequence_server_tool \ + trigger_tool + diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CGetDBData.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/CGetDBData.cpp new file mode 100644 index 00000000..927796b8 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CGetDBData.cpp @@ -0,0 +1,542 @@ +#include "CGetDBData.h" +#include "dbms/db_sysinfo_api/CDbSysInfo.h" +#include +#include + +CGetDBData::CGetDBData(): + m_objLocalDbConn(DB_CONN_MODEL_READ) +{ + +} + +bool CGetDBData::openDb() +{ + using namespace iot_dbms; + if (isOpen()) { + return true; + } + + return m_objLocalDbConn.open(); +} + +void CGetDBData::closeDb() +{ + m_objLocalDbConn.close(); +} + +bool CGetDBData::isOpen() +{ + return m_objLocalDbConn.isOpen(); +} + + +bool CGetDBData::remapDbTableLinkSettingInfo(CLinkageDbContainer& dbContainer) +{ + dbContainer.clearLinkDefineInfo(); + + QString strExecute = QString("SELECT " + "name," + "description," + "trigger_type," + "exec_type," + "link_type," + "trigger_condition," + "location_id," + "timeflag" + " FROM linkage_setting"); + + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SLinkDefineInfo* info = new SLinkDefineInfo; + info->name + = queryTableMode.value(0).toString().toStdString(); + info->description + = queryTableMode.value(1).toString().toStdString(); + info->trigger_type + = queryTableMode.value(2).toInt(); + info->exec_type + = queryTableMode.value(3).toInt(); + info->link_type + = queryTableMode.value(4).toInt(); + info->trigger_condition + = queryTableMode.value(5).toString().toStdString(); + info->location_id + = queryTableMode.value(6).toInt(); + info->timeflag + = queryTableMode.value(7).toULongLong(); + + dbContainer.pushLinkDefineInfo(info); + } + } + return true; +} + +bool CGetDBData::remapDbTableLinkDefineInfo(CLinkageDbContainer& dbContainer) +{ + dbContainer.clearLinkConfigInfo(); + + QString strExecute = QString("SELECT " + "linkage_name," + "func_name," + "func_no," + "relation," + "timeflag" + " FROM linkage_define order by func_no"); + + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SLinkConfigInfo* info = new SLinkConfigInfo; + info->linkage_name + = queryTableMode.value(0).toString().toStdString(); + info->func_name + = queryTableMode.value(1).toString().toStdString(); + info->func_no + = queryTableMode.value(2).toInt(); + info->relation + = queryTableMode.value(3).toInt(); + info->timeflag + = queryTableMode.value(4).toULongLong(); + + dbContainer.pushLinkConfigInfo(info); + } + } + + return true; +} + +bool CGetDBData::remapDbTableFuncInfo(CLinkageDbContainer& dbContainer) +{ + dbContainer.clearFuncInfo(); + + QString strExecute = QString("SELECT " + "name," + "description," + "action_no," + "action_name," + "enable," + "delaytime," + "failstrage," + "retrytimes," + "timeflag," + "func_type" + " FROM linkage_function order by action_no"); + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SFuncInfo* info = new SFuncInfo; + info->name = queryTableMode.value(0).toString().toStdString(); + info->description = queryTableMode.value(1).toString().toStdString(); + info->action_no = queryTableMode.value(2).toInt(); + info->action_name = queryTableMode.value(3).toString().toStdString(); + info->enable = queryTableMode.value(4).toBool(); + info->delaytime = queryTableMode.value(5).toInt(); + info->failstrage = queryTableMode.value(6).toInt(); + info->retrytimes = queryTableMode.value(7).toInt(); + info->timeflag = queryTableMode.value(8).toULongLong(); + info->func_type = queryTableMode.value(9).toInt(); + + dbContainer.pushFuncInfo(info); + } + } + + return true; +} + +bool CGetDBData::remapDbTableActionInfo(CLinkageDbContainer& dbContainer) +{ + dbContainer.clearActionInfo(); + + QString strExecute = QString("SELECT " + "name, " + "description, " + "linkage_string, " + "ctrl_timeout, " + "action_type, " + "sub_system," + "location_id, " + "timeflag " + " FROM linkage_action "); + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SActionInfo* info = new SActionInfo; + info->name = queryTableMode.value(0).toString().toStdString(); + info->description = queryTableMode.value(1).toString().toStdString(); + info->linkage_string = queryTableMode.value(2).toString().toStdString(); + info->ctrl_timeout = queryTableMode.value(3).toInt(); + info->action_type = queryTableMode.value(4).toInt(); + info->sub_system = queryTableMode.value(5).toInt(); + info->location_id = queryTableMode.value(6).toInt(); + info->timeflag = queryTableMode.value(7).toULongLong(); + + dbContainer.pushActionInfo(info); + } + } + + return true; +} + +bool CGetDBData::remapDbTable(CLinkageDbContainer& dbContainer) +{ + BOOST_ASSERT(m_objLocalDbConn.isOpen()); + + bool bRet = remapDbTableLinkSettingInfo(dbContainer); + bRet = remapDbTableLinkDefineInfo(dbContainer); + bRet = remapDbTableFuncInfo(dbContainer); + bRet = remapDbTableActionInfo(dbContainer); + + return bRet; +} + +QString CGetDBData::triggerType(int triggerTypeNum) +{ + QString str; + switch(triggerTypeNum){ + case 0: + str = ("不触发"); + break; + case 1: + str = ("条件触发"); + break; + case 2: + str = ("定时触发"); + break; + case 3: + str = ("周期触发"); + break; + default: + break; + } + return str; +} + +QString CGetDBData::execType(int execTypeNum) +{ + QString str; + switch(execTypeNum){ + case 0: + str = ("全自动"); + break; + case 1: + str = ("半自动"); + break; + case 2: + str = ("手动"); + break; + default: + break; + } + return str; +} + +QString CGetDBData::linkType(int linkTypeNum) +{ + QString str; + switch(linkTypeNum){ + case 0: + str = ("车站火灾"); + break; + case 1: + str = ("区间阻塞"); + break; + case 2: + str = ("日常运营"); + break; + case 3: + str = ("自定义1"); + break; + case 4: + str = ("自定义2"); + break; + default: + break; + } + return str; +} + +QString CGetDBData::relationType(int relationNum) +{ + QString str; + switch(relationNum){ + case 0: + str = ("串行"); + break; + case 1: + str = ("并行"); + break; + default: + break; + } + return str; +} + +QString CGetDBData::enableType(bool enable) +{ + QString str; + if(enable){ + str = ("是"); + }else{ + str = ("否"); + } + + return str; +} + +QString CGetDBData::failStrageType(int failNum) +{ + QString str; + switch(failNum){ + case 0: + str = ("跳过失败动作"); + break; + case 1: + str = ("人工干预"); + break; + case 2: + str = ("终止联动"); + break; + case 3: + str = ("自动重做"); + break; + default: + break; + } + return str; +} + +QString CGetDBData::actionType(int actionNum) +{ + QString str; + switch(actionNum){ + case 0: + str = ("电力"); + break; + case 1: + str = ("环控"); + break; + case 2: + str = ("广播"); + break; + case 3: + str = ("CCTV"); + break; + case 4: + str = ("乘客信息"); + break; + case 5: + str = ("推画面"); + break; + case 6: + str = ("提示信息"); + break; + default: + break; + } + return str; +} + +QString CGetDBData::isSesExe(int issesNum) +{ + QString str; + switch(issesNum){ + case 0: + str = ("不是"); + break; + case 1: + str = ("是"); + break; + default: + break; + } + return str; +} + +QMap CGetDBData::readLinkLocation() +{ + QMap linkLocationMap; + + if(openDb()) + { + QString Execute = QString("SELECT name,location_id FROM linkage_setting "); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + linkLocationMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return linkLocationMap; +} + +QMap CGetDBData::readLocationDomainId() +{ + QMap locationMap; + + if(openDb()) + { + QString Execute = QString("select location_id,domain_id from sys_model_location_info"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + locationMap.insert(Query.value(0).toInt(), Query.value(1).toInt()); + } + } + } + + return locationMap; +} + +QMap CGetDBData::readLocationInfo() +{ + QMap locationMap; + + if(openDb()) + { + QString Execute = QString("select description,location_id from sys_model_location_info"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + locationMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return locationMap; +} + +QMap CGetDBData::readDomainInfo() +{ + QMap domainMap; + + if(openDb()) + { + QString Execute = QString("select description,domain_id from sys_model_domain_info"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + domainMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return domainMap; +} + +QMap CGetDBData::readUserInfo() +{ + QMap userMap; + + if(openDb()) + { + QString Execute = QString("select perm_name,perm_id from rm_user_def"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + userMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return userMap; +} + +QMap CGetDBData::readUsergInfo() +{ + QMap usergMap; + + if(openDb()) + { + QString Execute = QString("select perm_name,perm_id from rm_userg_def"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + usergMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return usergMap; +} + +QStringList CGetDBData::hostNameList() +{ + QStringList List; + + if(openDb()) + { + QString Execute = QString("select node_name from sys_model_node_info"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + List.append(Query.value(0).toString()); + } + } + } + + return List; +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CGetDBData.h b/product/src/tools/link_seq_tool/linkage_server_tool/CGetDBData.h new file mode 100644 index 00000000..996e89c3 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CGetDBData.h @@ -0,0 +1,49 @@ +#ifndef CGETDBDATA_H +#define CGETDBDATA_H + +#include +#include +#include "db_api_ex/CDbApi.h" +#include "CLinkageDbContainer.h" + +class CGetDBData +{ +public: + CGetDBData(); + + bool remapDbTable(CLinkageDbContainer &dbContainer); + + + bool openDb(); + void closeDb(); + bool isOpen(); + + static QString triggerType(int triggerTypeNum); + static QString execType(int execTypeNum); + static QString linkType(int linkTypeNum); + static QString isSesExe(int issesNum); + static QString relationType(int relationNum); + static QString enableType(bool enable); + static QString failStrageType(int failNum); + static QString actionType(int actionNum); + + QMap readLinkLocation(); + QMap readLocationDomainId(); + QMap readLocationInfo(); + QMap readDomainInfo(); + QMap readUserInfo(); + QMap readUsergInfo(); + QStringList hostNameList(); + +private: + bool remapDbTableLinkSettingInfo(CLinkageDbContainer& dbContainer); + bool remapDbTableLinkDefineInfo(CLinkageDbContainer& dbContainer); + bool remapDbTableFuncInfo(CLinkageDbContainer &dbContainer); + bool remapDbTableActionInfo(CLinkageDbContainer &dbContainer); + +private: + iot_dbms::CDbApi m_objLocalDbConn; + +}; + +#endif // CGETDBDATA_H diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CGetRdbData.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/CGetRdbData.cpp new file mode 100644 index 00000000..5fcadef3 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CGetRdbData.cpp @@ -0,0 +1,146 @@ +#include "CGetRdbData.h" +#include "boost/date_time.hpp" +#include "rdb_net_api/CRdbNetApi.h" +#include "mainwindow.h" +#include "CRdbLinkRunningAccess.h" +#include "CRecoverNode.h" + +CGetRdbData::CGetRdbData() + :CTimerThreadBase("CGetRdbData thread", 100) +{ + +} + +CGetRdbData::~CGetRdbData() +{ + this->quit(); +} + +bool CGetRdbData::getRdbData(CRecoverNodeContainer& container) +{ + CRdbLinkRunningAccess runAccess(LinkName, m_domainId); + CRdbLinkRunningAccessLocker Accesslocker(runAccess); + if(Accesslocker.isLock()) + { + CGetRdbDataLocker locker(*this); + if(runAccess.remapRunningTable(container)){ + return true; + }else{ + return false; + } + } + else + return false; +} + +Qt::CheckState CGetRdbData::getCheckState(int checkStateNum) +{ + if(checkStateNum == 0) + return Qt::Unchecked; + else if(checkStateNum == 1) + return Qt::PartiallyChecked; + else + return Qt::Checked; +} + +QString CGetRdbData::statusType(int statusNum) +{ + QString str; + switch(statusNum){ + case 0: + str = ("未执行"); + break; + case 1: + str = ("正在执行"); + break; + case 2: + str = ("已触发"); + break; + case 3: + str = ("执行失败"); + break; + case 4: + str = ("执行成功"); + break; + case 5: + str = ("执行终止"); + break; + case 6: + str = ("执行暂停"); + break; + case 7: + str = ("执行跳过"); + break; + default: + break; + } + return str; +} + +QString CGetRdbData::nodeType(int nodeNum) +{ + QString str; + switch(nodeNum){ + case 0: + str = ("联动"); + break; + case 1: + str = ("功能"); + break; + case 2: + str = ("动作"); + break; + default: + break; + } + return str; +} + +QString CGetRdbData::timeToDT(uint64 time) +{ + QString str; + if(time == 0) + { + str = "0"; + } + else{ + QDateTime triggerUtc = QDateTime::fromTime_t(time); + str = triggerUtc.toString("yyyy-MM-dd hh:mm::ss"); + } + return str; +} + +bool CGetRdbData::start(const std::string &linkName, int domainId) +{ + m_containerUpdate.clearData(); + LinkName = linkName; + m_domainId = domainId; + this->resume(); + return true; +} + +bool CGetRdbData::stop() +{ + this->suspend(); + return true; +} + +void CGetRdbData::lock() +{ + mutex.lock(); +} + +void CGetRdbData::unlock() +{ + mutex.unlock(); +} + +void CGetRdbData::clear() +{ + m_containerUpdate.clearData(); +} + +void CGetRdbData::execute() +{ + getRdbData(m_containerUpdate); +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CGetRdbData.h b/product/src/tools/link_seq_tool/linkage_server_tool/CGetRdbData.h new file mode 100644 index 00000000..2aff18cb --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CGetRdbData.h @@ -0,0 +1,65 @@ +#ifndef CGETRDBDATA_H +#define CGETRDBDATA_H + +#include +#include "pub_utility_api/TimerThreadBase.h" +#include "CRecoverNodeContainer.h" +#include "CRdbLinkRunningAccess.h" + +class MainWindow; +class CGetRdbData + : public QObject, public iot_public::CTimerThreadBase +{ + + Q_OBJECT + +public: + CGetRdbData(); + ~CGetRdbData(); + + bool getRdbData(CRecoverNodeContainer& container); + + static Qt::CheckState getCheckState(int checkStateNum); + static QString statusType(int statusNum); + static QString nodeType(int nodeNum); + static QString timeToDT(uint64 time); + + //开启线程 + bool start(const std::string &linkName, int domainId); + + //停止线程 + bool stop(); + + void clear(); + +protected: + friend class MainWindow; + void execute(); + friend class CGetRdbDataLocker; + void lock(); + void unlock(); + +private: + std::string LinkName; + int m_domainId; + CRecoverNodeContainer m_containerUpdate; + QMutex mutex; +}; + +class CGetRdbDataLocker +{ +public: + CGetRdbDataLocker(CGetRdbData& rdbData): + m_objRdbData(rdbData) + { + m_objRdbData.lock(); + } + ~CGetRdbDataLocker() + { + m_objRdbData.unlock(); + } +private: + CGetRdbData& m_objRdbData; +}; + +#endif // CGETRDBDATA_H diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageDbContainer.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageDbContainer.cpp new file mode 100644 index 00000000..3555542c --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageDbContainer.cpp @@ -0,0 +1,314 @@ +#include "CLinkageDbContainer.h" +#include "boost/assert.hpp" + +CLinkageDbContainer::CLinkageDbContainer() + :m_nTimeFlag(0) +{ +} + +CLinkageDbContainer::~CLinkageDbContainer() +{ + clearAll(); +} + +void CLinkageDbContainer::clearAll() +{ + clearLinkDefineInfo(); + clearLinkConfigInfo(); + clearFuncInfo(); + clearActionInfo(); +} + +void CLinkageDbContainer::clearLinkDefineInfo() +{ + TLinkDefineMap::iterator iter = m_mapLinkDefineInfo.begin(); + for (; iter != m_mapLinkDefineInfo.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapLinkDefineInfo.clear(); +} + +void CLinkageDbContainer::pushActionInfo(SActionInfo* info) +{ + m_mapActionInfo.insert(std::make_pair(info->name, info)); +} + +void CLinkageDbContainer::setTimeFlag(uint64 time) +{ + m_nTimeFlag = time; +} + +uint64 CLinkageDbContainer::getTimeFlag() const +{ + return m_nTimeFlag; +} + +void CLinkageDbContainer::pushFuncInfo(SFuncInfo* info) +{ + BOOST_ASSERT(!info->name.empty()); + m_mapFuncInfo[info->name].push_back(info); +} + +void CLinkageDbContainer::clearActionInfo() +{ + TActionMap::iterator iter = m_mapActionInfo.begin(); + for (; iter != m_mapActionInfo.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapActionInfo.clear(); +} + +void CLinkageDbContainer::pushLinkConfigInfo(SLinkConfigInfo* info) +{ + BOOST_ASSERT(!info->linkage_name.empty()); + m_mapLinkConfigInfo[info->linkage_name].push_back(info); +} + +void CLinkageDbContainer::clearFuncInfo() +{ + TFuncMap::iterator mapIter = m_mapFuncInfo.begin(); + std::vector::iterator vecIter; + for (; mapIter != m_mapFuncInfo.end(); ++mapIter) + { + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + delete *vecIter; + *vecIter = NULL; + } + (mapIter->second).clear(); + } + m_mapFuncInfo.clear(); +} + +void CLinkageDbContainer::pushLinkDefineInfo(SLinkDefineInfo* info) +{ + m_mapLinkDefineInfo.insert(std::make_pair(info->name, info)); +} + +void CLinkageDbContainer::clearLinkConfigInfo() +{ + TLinkConfigMap::iterator mapIter + = m_mapLinkConfigInfo.begin(); + std::vector::iterator vecIter; + for (; mapIter != m_mapLinkConfigInfo.end(); ++mapIter) + { + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + delete *vecIter; + *vecIter = NULL; + } + (mapIter->second).clear(); + } + m_mapLinkConfigInfo.clear(); +} + +/*! @brief 联动定义 迭代器 . */ +SLinkDefineInfoIterator::SLinkDefineInfoIterator(const CLinkageDbContainer& container) +{ + TLinkDefineMap::const_iterator iter + = container.m_mapLinkDefineInfo.begin(); + for (; iter != container.m_mapLinkDefineInfo.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SLinkDefineInfoIterator::SLinkDefineInfoIterator(const CLinkageDbContainer& container, const std::string& linkName) +{ + TLinkDefineMap::const_iterator iter + = container.m_mapLinkDefineInfo.find(linkName); + if (iter != container.m_mapLinkDefineInfo.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SLinkDefineInfoIterator::~SLinkDefineInfoIterator() +{ + m_vec.clear(); +} + +bool SLinkDefineInfoIterator::hasNext() const +{ + return m_iter != m_vec.end(); +} + +const SLinkDefineInfo& SLinkDefineInfoIterator::getNext() +{ + SLinkDefineInfo *pNode = *m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} + +/*! @brief 联动设置 迭代器 . */ +SLinkConfigInfoIterator::SLinkConfigInfoIterator(const CLinkageDbContainer& container) +{ + TLinkConfigMap::const_iterator + mapIter = container.m_mapLinkConfigInfo.begin(); + TLinkConfigVec::const_iterator vecIter; + for (; mapIter != container.m_mapLinkConfigInfo.end(); ++mapIter) + { + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + m_vec.push_back(*vecIter); + } + } + + m_iter = m_vec.begin(); +} + +SLinkConfigInfoIterator::SLinkConfigInfoIterator(const CLinkageDbContainer& container, const std::string& linkName) +{ + TLinkConfigMap::const_iterator + mapIter = container.m_mapLinkConfigInfo.find(linkName); + if (mapIter != container.m_mapLinkConfigInfo.end()) + { + TLinkConfigVec::const_iterator vecIter; + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + m_vec.push_back(*vecIter); + } + } + + m_iter = m_vec.begin(); +} + +SLinkConfigInfoIterator::~SLinkConfigInfoIterator() +{ + m_vec.clear(); +} + +bool SLinkConfigInfoIterator::hasNext() const +{ + return m_iter != m_vec.end(); +} + +const SLinkConfigInfo& SLinkConfigInfoIterator::getNext() +{ + SLinkConfigInfo *pNode = *m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} + +/*! @brief 联动功能 迭代器 . */ +SFuncInfoIterator::SFuncInfoIterator( + const CLinkageDbContainer& container) +{ + TFuncMap::const_iterator + mapIter = container.m_mapFuncInfo.begin(); + TFuncVec::const_iterator vecIter; + for (; mapIter != container.m_mapFuncInfo.end(); ++mapIter) + { + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + m_vec.push_back(*vecIter); + } + } + + m_iter = m_vec.begin(); +} + +SFuncInfoIterator::SFuncInfoIterator( + const CLinkageDbContainer& container, + const std::string& funcName) +{ + TFuncMap::const_iterator + mapIter = container.m_mapFuncInfo.find(funcName); + + if (mapIter != container.m_mapFuncInfo.end()) + { + TFuncVec::const_iterator vecIter; + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + m_vec.push_back(*vecIter); + } + } + + m_iter = m_vec.begin(); +} + +SFuncInfoIterator::~SFuncInfoIterator() +{ + m_vec.clear(); +} + +bool SFuncInfoIterator::hasNext() const +{ + return m_iter != m_vec.end(); +} + +const SFuncInfo& SFuncInfoIterator::getNext() +{ + SFuncInfo *pNode = *m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} + +/*! @brief 联动动作 迭代器 . */ +SActionInfoIterator::SActionInfoIterator( + const CLinkageDbContainer& container) +{ + TActionMap::const_iterator iter + = container.m_mapActionInfo.begin(); + for (; iter != container.m_mapActionInfo.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SActionInfoIterator::SActionInfoIterator( + const CLinkageDbContainer& container, + const std::string& actionName) +{ + TActionMap::const_iterator iter + = container.m_mapActionInfo.find(actionName); + if (iter != container.m_mapActionInfo.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SActionInfoIterator::~SActionInfoIterator() +{ + m_vec.clear(); +} + +bool SActionInfoIterator::hasNext() const +{ + return m_iter != m_vec.end(); +} + +const SActionInfo& SActionInfoIterator::getNext() +{ + SActionInfo *pNode = *m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageDbContainer.h b/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageDbContainer.h new file mode 100644 index 00000000..fe08d57b --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageDbContainer.h @@ -0,0 +1,136 @@ +#pragma once +/*! + * @breif 联动数据表数据结构 基础数据 容器 + * + * @author sjq + * @date 五月 2018 + */ + +#include +#include + +#include "DbTableDefine.h" + +typedef std::vector TLinkConfigVec; +typedef std::vector TFuncVec; +typedef std::map TLinkDefineMap; +typedef std::map TLinkConfigMap; +typedef std::map TFuncMap; +typedef std::map TActionMap; + +/*! @brief 联动数据表数据结构 基础数据 容器 */ +class CLinkageDbContainer +{ +public: + + CLinkageDbContainer(); + ~CLinkageDbContainer(); + //清空所有数据 + void clearAll(); + //添加基础数据 + void clearLinkDefineInfo(); + void pushLinkDefineInfo(SLinkDefineInfo* info); + + void clearLinkConfigInfo(); + void pushLinkConfigInfo(SLinkConfigInfo* info); + + void clearFuncInfo(); + void pushFuncInfo(SFuncInfo* info); + + void clearActionInfo(); + void pushActionInfo(SActionInfo* info); + + //本地时标 + void setTimeFlag(uint64 time); + uint64 getTimeFlag() const; +protected: + friend class SLinkDefineInfoIterator; + friend class SLinkConfigInfoIterator; + friend class SFuncInfoIterator; + friend class SActionInfoIterator; + + //使用map,是为了检索更快点,在数据生成可运行的节点需要大量的检索,第二级不要求检索,只要求可以遍历所以使用vector + TLinkDefineMap m_mapLinkDefineInfo;//联动名 - 联动信息表 + TLinkConfigMap m_mapLinkConfigInfo;//联动名 - 联动和功能关系表 + TFuncMap m_mapFuncInfo;//功能名 - 功能和动作关系列表 + TActionMap m_mapActionInfo; //动作名-动作 + +private: + uint64 m_nTimeFlag;//时标 0 表示没有数据, 非零值表示最后的更新时间 +}; + +/*! @brief 联动定义 迭代器 . */ +class SLinkDefineInfoIterator +{ +public: + SLinkDefineInfoIterator( + const CLinkageDbContainer& container); + + SLinkDefineInfoIterator( + const CLinkageDbContainer& container, + const std::string& linkName); + + ~SLinkDefineInfoIterator(); + bool hasNext() const; + const SLinkDefineInfo& getNext(); +private: + std::vector m_vec; + std::vector::iterator m_iter; +}; + +/*! @brief 联动设置 迭代器 . */ +class SLinkConfigInfoIterator +{ +public: + SLinkConfigInfoIterator( + const CLinkageDbContainer& container); + + SLinkConfigInfoIterator( + const CLinkageDbContainer& container, + const std::string& linkName); + + ~SLinkConfigInfoIterator(); + bool hasNext() const; + const SLinkConfigInfo& getNext(); +private: + std::vector m_vec; + std::vector::iterator m_iter; +}; + +/*! @brief 联动功能 迭代器 . */ +class SFuncInfoIterator +{ +public: + SFuncInfoIterator( + const CLinkageDbContainer& container); + + SFuncInfoIterator( + const CLinkageDbContainer& container, + const std::string& funcName); + + ~SFuncInfoIterator(); + bool hasNext() const; + const SFuncInfo& getNext(); +private: + std::vector m_vec; + std::vector::iterator m_iter; +}; + +/*! @brief 联动动作 迭代器 . */ +class SActionInfoIterator +{ +public: + SActionInfoIterator( + const CLinkageDbContainer& container); + + SActionInfoIterator( + const CLinkageDbContainer& container, + const std::string& actionName); + + ~SActionInfoIterator(); + bool hasNext() const; + const SActionInfo& getNext(); +private: + std::vector m_vec; + std::vector::iterator m_iter; +}; diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageForHmiApiInterface.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageForHmiApiInterface.cpp new file mode 100644 index 00000000..4cf0a450 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageForHmiApiInterface.cpp @@ -0,0 +1,333 @@ +#include "CLinkageForHmiApiInterface.h" +#include "mainwindow.h" +#include "common/DataType.h" +#include +#include + +using namespace iot_idl::linkage; +CLinkageForHmiApiInterface::CLinkageForHmiApiInterface(MainWindow* mainWindow) + :m_ptrMain(mainWindow) +{ + this->start(); +} + +CLinkageForHmiApiInterface::~CLinkageForHmiApiInterface() +{ + this->stop(); +} + +bool CLinkageForHmiApiInterface::handleLinkOperateResponse( + LinkOperateMessageAck &msg) +{ + QString msgStr; + const LinkNodeStatusParameter& link + = msg.link_node(); + + const ::std::string& linkName = link.link_name(); + ENLcsStatus state = link.node_state(); + std::string linkStateStr = nodeStatusStr(state); + + std::string funcName; + std::string funcStateStr; + + std::string actionName; + std::string actionStateStr; + + std::string retStr; + int retCore; + const ExecuteStatusParameter& + executeStateParam = msg.execute_status(); + retCore = executeStateParam.statuscode(); + if (retCore != 0) + { + const ::ErrorParameter& + errorParam = executeStateParam.erro_param(); + retStr = errorParam.errordescription(); + } + + const google::protobuf::RepeatedPtrField< FucNodeStatusParameter >& + funcList = link.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + funcListIter = funcList.begin(); + if (funcListIter != funcList.end()) + { + const FucNodeStatusParameter& func = *funcListIter; + funcName = func.fuc_name(); + funcStateStr = nodeStatusStr(func.node_state()); + + const google::protobuf::RepeatedPtrField< ActionNodeStatusParameter >& + actionList = func.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + actionListIter = actionList.begin(); + + if (actionListIter != actionList.end()) + { + const ActionNodeStatusParameter& action = *actionListIter; + + actionName = action.action_name(); + actionStateStr = nodeStatusStr(action.node_state()); + } + } + + msgStr = QString("联动操作应答:联动名:%1,状态:%2 应答状态:%3 描述:%4") + .arg(QString::fromStdString(linkName)) + .arg(QString::fromStdString(linkStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)); + + m_ptrMain->showMsg(msgStr); + return true; +} + +bool CLinkageForHmiApiInterface::handleUserInterveneRequest( + UiRequestMessage &msg) +{ + QString msgStr; + const LinkNodeStatusParameter& link + = msg.nodelist(); + + const ::std::string& linkName = link.link_name(); + ENLcsStatus state = link.node_state(); + std::string linkStateStr = nodeStatusStr(state); + + std::string funcName; + std::string funcStateStr; + + std::string actionName; + std::string actionStateStr; + + const google::protobuf::RepeatedPtrField< FucNodeStatusParameter >& + funcList = link.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + funcListIter = funcList.begin(); + if (funcListIter != funcList.end()) + { + const FucNodeStatusParameter& func = *funcListIter; + funcName = func.fuc_name(); + funcStateStr = nodeStatusStr(func.node_state()); + + const google::protobuf::RepeatedPtrField< ActionNodeStatusParameter >& + actionList = func.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + actionListIter = actionList.begin(); + + if (actionListIter != actionList.end()) + { + const ActionNodeStatusParameter& action = *actionListIter; + + actionName = action.action_name(); + actionStateStr = nodeStatusStr(action.node_state()); + } + } + + std::string retStr; + int retCore; + const ExecuteStatusParameter& + executeStateParam = msg.execute_status(); + retCore = executeStateParam.statuscode(); + if (retCore != 0) + { + const ::ErrorParameter& + errorParam = executeStateParam.erro_param(); + retStr = errorParam.errordescription(); + } + + msgStr = QString("人工干预 状态:[%1]:[%2] [%3]:[%4] [%5]:[%6] 状态码:[%7] 描述:[%8]") + .arg(QString::fromStdString(linkName)) + .arg(QString::fromStdString(linkStateStr)) + .arg(QString::fromStdString(funcName)) + .arg(QString::fromStdString(funcStateStr)) + .arg(QString::fromStdString(actionName)) + .arg(QString::fromStdString(actionStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)); + + m_ptrMain->showUiMsg(msgStr, msg); + return true; +} + +bool CLinkageForHmiApiInterface::handleLinkStartRequest( + LinkStartRequestMessage &msg) +{ + QString msgStr; + const LinkNodeStatusParameter& link + = msg.nodelist(); + + uint64 triggerTime = msg.trigger_time(); + + const ::std::string& linkName = link.link_name(); + ENLcsStatus state = link.node_state(); + std::string linkStateStr = nodeStatusStr(state); + + std::string funcName; + std::string funcStateStr; + + std::string actionName; + std::string actionStateStr; + + const google::protobuf::RepeatedPtrField< FucNodeStatusParameter >& + funcList = link.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + funcListIter = funcList.begin(); + if (funcListIter != funcList.end()) + { + const FucNodeStatusParameter& func = *funcListIter; + funcName = func.fuc_name(); + funcStateStr = nodeStatusStr(func.node_state()); + + const google::protobuf::RepeatedPtrField< ActionNodeStatusParameter >& + actionList = func.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + actionListIter = actionList.begin(); + + if (actionListIter != actionList.end()) + { + const ActionNodeStatusParameter& action = *actionListIter; + + actionName = action.action_name(); + actionStateStr = nodeStatusStr(action.node_state()); + } + } + + QString dateStr = + QDateTime::fromSecsSinceEpoch(triggerTime, Qt::UTC) + .toString("yyyy-MM-dd hh:mm:ss"); + + msgStr = QString("联动触发 状态:[%1]:[%2] 触发时间[%3] ") + .arg(QString::fromStdString(linkName)) + .arg(QString::fromStdString(linkStateStr)) + .arg(dateStr); + + m_ptrMain->showMsg(msgStr); + return true; +} + +bool CLinkageForHmiApiInterface::handleLinkStateChange( + StatusChangeMessage &msg) +{ + QString msgStr; + const LinkNodeStatusParameter& link + = msg.nodelist(); + + const ::std::string& linkName = link.link_name(); + ENLcsStatus linkState = link.node_state(); + std::string linkStateStr = nodeStatusStr(linkState); + + std::string funcName; + std::string funcStateStr; + + std::string actionName; + std::string actionStateStr; + + const google::protobuf::RepeatedPtrField< FucNodeStatusParameter >& + funcList = link.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + funcListIter = funcList.begin(); + if (funcListIter != funcList.end()) + { + const FucNodeStatusParameter& func = *funcListIter; + funcName = func.fuc_name(); + funcStateStr = nodeStatusStr(func.node_state()); + + const google::protobuf::RepeatedPtrField< ActionNodeStatusParameter >& + actionList = func.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + actionListIter = actionList.begin(); + + if (actionListIter != actionList.end()) + { + const ActionNodeStatusParameter& action = *actionListIter; + + actionName = action.action_name(); + actionStateStr = nodeStatusStr(action.node_state()); + } + } + int retCore = 0; + std::string retStr; + const google::protobuf::RepeatedPtrField< ::ExecuteStatusParameter >& + executeStatusList = msg.execute_status(); + if (executeStatusList.begin() != executeStatusList.end()) + { + const ExecuteStatusParameter& executeStatus = *(executeStatusList.begin()); + retCore = executeStatus.statuscode(); + if (retCore != 0) + { + const ::ErrorParameter& erroParam = + executeStatus.erro_param(); + retStr = erroParam.errordescription(); + } + } + + if (!actionName.empty()) + { + msgStr = QString("动作 状态变化:[%1]:[%2] [%3]:[%4] [%5]:[%6] 执行状态[%7]:[%8]") + .arg(QString::fromStdString(linkName)) + .arg(QString::fromStdString(linkStateStr)) + .arg(QString::fromStdString(funcName)) + .arg(QString::fromStdString(funcStateStr)) + .arg(QString::fromStdString(actionName)) + .arg(QString::fromStdString(actionStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)) + ; + } + else if (!funcName.empty()) + { + msgStr = QString("功能 状态变化:[%1]:[%2] [%3]:[%4] 执行状态[%5]:[%6]") + .arg(QString::fromStdString(linkName)) + .arg(QString::fromStdString(linkStateStr)) + .arg(QString::fromStdString(funcName)) + .arg(QString::fromStdString(funcStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)) + ; + } + else + { + msgStr = QString("联动 状态变化:[%1]:[%2] 执行状态[%3]:[%4]") + .arg(QString::fromStdString(linkName)) + .arg(QString::fromStdString(linkStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)); + } + + m_ptrMain->showMsg(msgStr); + return true; +} + +std::string CLinkageForHmiApiInterface::nodeStatusStr( + ENLcsStatus type) +{ + using namespace iot_idl; + std::string strRet; + switch (type) + { + case enumLINK_RESTING_STATUS: + strRet = ("未执行"); + break; + case enumLINK_RUNNING_STATUS: + strRet = ("正在执行"); + break; + case enumLINK_TRIGGERED_STATUS: + strRet = ("已触发"); + break; + case enumLINK_FAILED_STATUS: + strRet = ("执行失败"); + break; + case enumLINK_SUCCESS_STATUS: + strRet = ("执行成功"); + break; + case enumLINK_STOP_STATUS: + strRet = ("执行中止"); + break; + case enumLINK_PAUSE_STATUS: + strRet = ("执行暂停"); + break; + case enumLINK_SKIP_STATUS: + strRet = ("执行跳过"); + break; + default: + break; + } + return strRet; +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageForHmiApiInterface.h b/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageForHmiApiInterface.h new file mode 100644 index 00000000..9c1ac272 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CLinkageForHmiApiInterface.h @@ -0,0 +1,38 @@ +#ifndef CLINKCTRLFORHMIAPIINTERFACE_H +#define CLINKCTRLFORHMIAPIINTERFACE_H +#include "application/linkage_server_api/CLinkageForHmiApi.h" + +class MainWindow; +using namespace iot_idl::linkage; + +class CLinkageForHmiApiInterface + : public iot_app::CLinkageForHmiApi +{ +public: + CLinkageForHmiApiInterface(MainWindow* mainWindow); + ~CLinkageForHmiApiInterface(); + + //2 server->hmi 请求联动操作 的 应答 + virtual bool handleLinkOperateResponse( + LinkOperateMessageAck& msg); + + //1 server->hmi 发起的人工干预 请求 + virtual bool handleUserInterveneRequest( + UiRequestMessage& msg); + + //server->hmi 请求联动操作 应答 server 发起的 半自动请求开始 + virtual bool handleLinkStartRequest( + LinkStartRequestMessage& msg); + + //server->hmi 联动状态更新 + virtual bool handleLinkStateChange( + StatusChangeMessage& msg); + +private: + std::string nodeStatusStr( + ENLcsStatus type); +private: + MainWindow* m_ptrMain; +}; + +#endif // CLINKCTRLFORHMIAPIINTERFACE_H diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CRdbLinkRunningAccess.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/CRdbLinkRunningAccess.cpp new file mode 100644 index 00000000..3f1de036 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CRdbLinkRunningAccess.cpp @@ -0,0 +1,132 @@ +#include "CRdbLinkRunningAccess.h" +#include + +CRdbLinkRunningAccess::CRdbLinkRunningAccess(const std::string& linkName, int domainId) + :m_strLinkName(linkName),m_domainId(domainId) +{ + +} + +CRdbLinkRunningAccess::~CRdbLinkRunningAccess() +{ + +} + +bool CRdbLinkRunningAccess::remapRunningTable(CRecoverNodeContainer& info) +{ + info.clearData(); + + iot_idl::RdbQuery msgQuery; + msgQuery.set_strtablename("linkage_running"); + std::string *pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "linkage_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "func_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "action_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "node_desc"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "action_no"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "func_no"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "node_type"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "status"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "checked"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "trigger_time"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "start_time"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "user_id"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "user_groupid"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "host_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "location_id"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "timeflag"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "relation"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "link_type"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "exe_type"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "delay_time"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "fail_strage"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "isses"; + + pColName = msgQuery.add_strordercolnamearr(); + *pColName = "node_type"; + + iot_idl::RdbCondition *pCondtion = msgQuery.add_msgcondition(); + pCondtion->set_enlogic(ENConditionLogic::enumCondAnd); + pCondtion->set_enrelation(ENConditionRelation::enumCondEqual); + pCondtion->set_strcolumnname("linkage_name"); + + SVariable *pCondValue = pCondtion->mutable_msgvalue(); + pCondValue->set_edatatype(DataType::CN_DATATYPE_STRING); + pCondValue->set_strvalue(m_strLinkName); + + iot_idl::RdbRet retMsg; + bool bRet = objNetApi.query(msgQuery, retMsg); + if (false == bRet) { + std::cout << "query failed." << std::endl; + return false; + } + else { + for (int i = 0 ; i < retMsg.msgrecord_size() ; ++i) { + SLinkageRunning *run = new SLinkageRunning(); + run->linkage_name = retMsg.msgrecord(i).msgvaluearray(0).strvalue(); + run->func_name = retMsg.msgrecord(i).msgvaluearray(1).strvalue(); + run->action_name = retMsg.msgrecord(i).msgvaluearray(2).strvalue(); + run->node_desc = retMsg.msgrecord(i).msgvaluearray(3).strvalue(); + run->action_no = retMsg.msgrecord(i).msgvaluearray(4).nvalue(); + run->func_no = retMsg.msgrecord(i).msgvaluearray(5).nvalue(); + run->node_type = retMsg.msgrecord(i).msgvaluearray(6).nvalue(); + run->status = retMsg.msgrecord(i).msgvaluearray(7).nvalue(); + run->checked = retMsg.msgrecord(i).msgvaluearray(8).nvalue(); + run->trigger_time = retMsg.msgrecord(i).msgvaluearray(9).ulvalue(); + run->start_time = retMsg.msgrecord(i).msgvaluearray(10).ulvalue(); + run->user_id = retMsg.msgrecord(i).msgvaluearray(11).nvalue(); + run->user_groupid = retMsg.msgrecord(i).msgvaluearray(12).nvalue(); + run->host_name = retMsg.msgrecord(i).msgvaluearray(13).strvalue(); + run->location_id = retMsg.msgrecord(i).msgvaluearray(14).nvalue(); + run->timeflag = retMsg.msgrecord(i).msgvaluearray(15).ulvalue(); + run->relation = retMsg.msgrecord(i).msgvaluearray(16).nvalue(); + run->link_type = retMsg.msgrecord(i).msgvaluearray(17).nvalue(); + run->exe_type = retMsg.msgrecord(i).msgvaluearray(18).nvalue(); + run->delay_time = retMsg.msgrecord(i).msgvaluearray(19).nvalue(); + run->fail_strage = retMsg.msgrecord(i).msgvaluearray(20).nvalue(); + run->isses = retMsg.msgrecord(i).msgvaluearray(21).nvalue(); + info.pushData(run); + } + info.createModel(); + } + return true; +} + +bool CRdbLinkRunningAccess::lockTable() +{ + objNetApi.connect(m_domainId, 3); + bool bRet = objNetApi.lock("linkage_running"); + if (false == bRet) { + std::cout << "lock failed." << std::endl; + } + return bRet; +} + +void CRdbLinkRunningAccess::unLockTable() +{ + bool bRet = objNetApi.unLock("linkage_running"); + if (false == bRet) { + std::cout << "unlock failed." << std::endl; + } +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CRdbLinkRunningAccess.h b/product/src/tools/link_seq_tool/linkage_server_tool/CRdbLinkRunningAccess.h new file mode 100644 index 00000000..e3d352e7 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CRdbLinkRunningAccess.h @@ -0,0 +1,70 @@ +#pragma once +/*! + * @breif 实时服务访问 运行表 + * + * @author sjq + * @date 五月 2018 + */ + +#include "boost/thread/mutex.hpp" + +#include "rdb_api/CRdbAccess.h" +#include "rdb_api/CRdbAccessEx.h" +#include "rdb_api/CVarType.h" +#include "rdb_net_api/CRdbNetApi.h" + +#include "DbTableDefine.h" + +#include "CRecoverNodeContainer.h" +#include "CGetDBData.h" + +using namespace iot_dbms; +using namespace iot_idl; + +class CRdbLinkRunningAccess +{ +public: + CRdbLinkRunningAccess(const std::string& linkName, int domainId); + virtual ~CRdbLinkRunningAccess(); + + //读取运行表 + virtual bool remapRunningTable(CRecoverNodeContainer& info); + +protected: + friend class CRdbLinkRunningAccessLocker; + //手动锁 + virtual bool lockTable(); + virtual void unLockTable(); + +private: + CRdbNetApi objNetApi; + std::string m_strLinkName; + int m_domainId; + boost::mutex m_muLock; +}; + +/* + * @brief 运行表锁 + * @author sjq + * @date 六月 2018 + */ +class CRdbLinkRunningAccessLocker +{ +public: + CRdbLinkRunningAccessLocker(CRdbLinkRunningAccess& access) + :m_objAccess(access) + { + m_isLock = m_objAccess.lockTable(); + } + ~CRdbLinkRunningAccessLocker() + { + m_objAccess.unLockTable(); + } + bool isLock() + { + return m_isLock; + } +private: + CRdbLinkRunningAccess& m_objAccess; + bool m_isLock; +}; diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNode.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNode.cpp new file mode 100644 index 00000000..7a9b187b --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNode.cpp @@ -0,0 +1,425 @@ +#include "CRecoverNode.h" +#include "boost/assert.hpp" + +#include "CRecoverNodeContainer.h" + +CRecoverNode::CRecoverNode(SLinkageRunning* info) + :m_ptrRunnningInfo(info) +{ + m_strHostName = (m_ptrRunnningInfo->host_name); + //m_strUserName = (m_ptrRunnningInfo->user_name); + m_strNodeDesc = (m_ptrRunnningInfo->node_desc); +} + +CRecoverNode::CRecoverNode(const CRecoverNode& recover) +{ + this->m_strNodeName = recover.m_strNodeName; + this->m_strHostName = recover.m_strHostName; + //this->m_strUserName = recover.m_strUserName; + this->m_strNodeDesc = recover.m_strNodeDesc; + this->m_ptrRunnningInfo = new SLinkageRunning(*(recover.m_ptrRunnningInfo)); +} + +CRecoverNode& CRecoverNode::operator=( + const CRecoverNode& recover) +{ + if (this == &recover) + { + return *this; + } + + if (this->m_ptrRunnningInfo) + { + delete this->m_ptrRunnningInfo; + this->m_ptrRunnningInfo = NULL; + } + + clearChild(); + + this->m_strNodeName = recover.m_strNodeName; + this->m_strHostName = recover.m_strHostName; + //this->m_strUserName = recover.m_strUserName; + this->m_strNodeDesc = recover.m_strNodeDesc; + this->m_ptrRunnningInfo = new SLinkageRunning(*(recover.m_ptrRunnningInfo)); + + return *this; +} + +CRecoverNode::~CRecoverNode() +{ + clearChild(); + + if (m_ptrRunnningInfo) + { + delete m_ptrRunnningInfo; + m_ptrRunnningInfo = NULL; + } +} + +void CRecoverNode::addChild(CRecoverNode* ch) +{ + m_mapChild.insert(std::make_pair(ch->nodeName(), ch)); +} + +int CRecoverNode::childNum() +{ + return m_mapChild.size(); +} + +const std::string& CRecoverNode::nodeName() const +{ + BOOST_ASSERT(!m_strNodeName.empty()); + return m_strNodeName; +} + +const std::string &CRecoverNode::description() const +{ + return m_strNodeDesc; +} + +uint64 CRecoverNode::timeFlag() const +{ + return m_ptrRunnningInfo->timeflag; +} + +int CRecoverNode::linkType() const +{ + return m_ptrRunnningInfo->link_type; +} + +uint64 CRecoverNode::startTime() const +{ + return m_ptrRunnningInfo->start_time; +} + +int CRecoverNode::locationId() const +{ + return m_ptrRunnningInfo->location_id; +} + +int CRecoverNode::getState() const +{ + return m_ptrRunnningInfo->status; +} + +void CRecoverNode::setState(int stateNum) +{ + m_ptrRunnningInfo->status = stateNum; +} + +int CRecoverNode::exeType() const +{ + return m_ptrRunnningInfo->exe_type; +} + +uint64 CRecoverNode::triggerTime() const +{ + return m_ptrRunnningInfo->trigger_time; +} + +int CRecoverNode::checkState() const +{ + return m_ptrRunnningInfo->checked; +} + +int CRecoverNode::relation() const +{ + return m_ptrRunnningInfo->relation; +} + +int CRecoverNode::delayTime() const +{ + return m_ptrRunnningInfo->delay_time; +} + +int CRecoverNode::failStrage() const +{ + return m_ptrRunnningInfo->fail_strage; +} + +int CRecoverNode::userId() const +{ + return m_ptrRunnningInfo->user_id; +} + +int CRecoverNode::userGrounpId() const +{ + return m_ptrRunnningInfo->user_groupid; +} + +const std::string& CRecoverNode::hostName() const +{ + return m_strHostName; +} + +const std::string& CRecoverNode::userName() const +{ + return m_strUserName; +} + +int CRecoverNode::isSesExe() const +{ + return m_ptrRunnningInfo->isses; +} + +int CRecoverNode::nodeType() const +{ + return m_ptrRunnningInfo->node_type; +} + +int CRecoverNode::actionNo() const +{ + return m_ptrRunnningInfo->action_no; +} + +int CRecoverNode::funcNo() const +{ + return m_ptrRunnningInfo->func_no; +} + +void CRecoverNode::clearChild() +{ + std::map::iterator iter = m_mapChild.begin(); + for (; iter != m_mapChild.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapChild.clear(); +} + +CRecoverNodeLink::CRecoverNodeLink(SLinkageRunning* info) + :CRecoverNode(info) +{ + m_strNodeName = std::string(info->linkage_name); +} + +CRecoverNodeLink::CRecoverNodeLink(const CRecoverNodeLink& recover) + : CRecoverNode(recover) +{ + CRecoverIterator iter(recover); + while (iter.hasNext()) + { + CRecoverNodeFunc& func = (CRecoverNodeFunc&)iter.getNext(); + CRecoverNodeFunc* newFunc = new CRecoverNodeFunc(func); + this->addChild(newFunc); + } +} + +CRecoverNodeLink& CRecoverNodeLink::operator=(const CRecoverNodeLink& recover) +{ + if (this == &recover) + { + return *this; + } + + CRecoverNode::operator=(recover); + + CRecoverIterator iter(recover); + while (iter.hasNext()) + { + CRecoverNodeFunc& func = (CRecoverNodeFunc&)iter.getNext(); + CRecoverNodeFunc* newFunc = new CRecoverNodeFunc(func); + this->addChild(newFunc); + } + + return *this; +} + +CRecoverNodeLink::~CRecoverNodeLink() +{ +} + +const std::string& CRecoverNodeLink::linkName() const +{ + return CRecoverNode::nodeName(); +} + +CRecoverNodeFunc::CRecoverNodeFunc(SLinkageRunning* info) + :CRecoverNode(info) +{ + m_strNodeName = std::string(info->func_name); + m_strLinkName = std::string(info->linkage_name); +} + +CRecoverNodeFunc::CRecoverNodeFunc(const CRecoverNodeFunc& recover) + :CRecoverNode(recover) +{ + this->m_strLinkName = recover.m_strLinkName; + + CRecoverIterator iter(recover); + while (iter.hasNext()) + { + CRecoverNodeAction& action = (CRecoverNodeAction&)iter.getNext(); + CRecoverNodeAction* newAction = new CRecoverNodeAction(action); + this->addChild(newAction); + } +} + +CRecoverNodeFunc& CRecoverNodeFunc::operator=(const CRecoverNodeFunc& recover) +{ + if (this == &recover) + { + return *this; + } + + CRecoverNode::operator=(recover); + + this->m_strLinkName = recover.m_strLinkName; + + CRecoverIterator iter(recover); + while (iter.hasNext()) + { + CRecoverNodeAction& action = (CRecoverNodeAction&)iter.getNext(); + CRecoverNodeAction* newAction = new CRecoverNodeAction(action); + this->addChild(newAction); + } + + return *this; +} + +CRecoverNodeFunc::~CRecoverNodeFunc() +{ +} + +const std::string& CRecoverNodeFunc::linkName() const +{ + return m_strLinkName; +} + +const std::string& CRecoverNodeFunc::funcName() const +{ + return CRecoverNode::nodeName(); +} + +CRecoverNodeAction::CRecoverNodeAction(SLinkageRunning* info) + :CRecoverNode(info) +{ + m_strNodeName = std::string(info->action_name); + m_strFuncName = std::string(info->func_name); + m_strLinkName = std::string(info->linkage_name); +} + +CRecoverNodeAction::CRecoverNodeAction(const CRecoverNodeAction& recover) + :CRecoverNode(recover) +{ + this->m_strLinkName = recover.m_strLinkName; + this->m_strFuncName = recover.m_strFuncName; + + CRecoverIterator iter(recover); + BOOST_ASSERT(!iter.hasNext()); +} + +CRecoverNodeAction& CRecoverNodeAction::operator=(const CRecoverNodeAction& recover) +{ + if (this == &recover) + { + return *this; + } + + CRecoverNode::operator=(recover); + + this->m_strLinkName = recover.m_strLinkName; + this->m_strFuncName = recover.m_strFuncName; + + CRecoverIterator iter(recover); + BOOST_ASSERT(!iter.hasNext()); + + return *this; +} + +CRecoverNodeAction::~CRecoverNodeAction() +{ +} + +const std::string& CRecoverNodeAction::linkName() const +{ + return m_strLinkName; +} + +const std::string& CRecoverNodeAction::funcName() const +{ + return m_strFuncName; +} + +const std::string& CRecoverNodeAction::actionName() const +{ + return CRecoverNode::nodeName(); +} + +CRecoverIterator::CRecoverIterator() +{ + m_iter = m_vec.begin(); +} + +CRecoverIterator::CRecoverIterator( + const CRecoverNode& parent) +{ + std::map::const_iterator iter + = parent.m_mapChild.begin(); + for (; iter != parent.m_mapChild.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +CRecoverIterator::CRecoverIterator( + const CRecoverNode& parent, + const std::string& chName) +{ + std::map::const_iterator iter + = parent.m_mapChild.find(chName); + if (iter != parent.m_mapChild.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +CRecoverIterator::CRecoverIterator( + const CRecoverNodeContainer& pParent) +{ + std::map::const_iterator iter + = pParent.m_mapRecoverNodeLink.begin(); + for (; iter != pParent.m_mapRecoverNodeLink.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +CRecoverIterator::CRecoverIterator( + const CRecoverNodeContainer& pParent, + const std::string& chName) +{ + std::map::const_iterator iter + = pParent.m_mapRecoverNodeLink.find(chName); + if (iter != pParent.m_mapRecoverNodeLink.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +CRecoverIterator::~CRecoverIterator() +{ + m_vec.clear(); +} + +bool CRecoverIterator::hasNext() const +{ + return m_iter != m_vec.end(); +} + +CRecoverNode& CRecoverIterator::getNext() +{ + CRecoverNode *pNode = *m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNode.h b/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNode.h new file mode 100644 index 00000000..7f6f6aa1 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNode.h @@ -0,0 +1,125 @@ +#pragma once +/* + * @brief 恢复节点 从运行库中取出的数据节点 + * @author sjq + * @date 六月 2018 + */ +#include +#include + +#include "DbTableDefine.h" +class CRecoverNode +{ +public: + CRecoverNode(SLinkageRunning* info); + + CRecoverNode(const CRecoverNode& recover); + CRecoverNode& operator=(const CRecoverNode& recover); + + virtual ~CRecoverNode(); + + void addChild(CRecoverNode* ch); + int childNum(); + const std::string& nodeName() const; + const std::string& description() const; + int checkState() const; + int relation() const; + int delayTime() const; + int failStrage() const; + int getState() const; + void setState(int stateNum); + int exeType() const; + uint64 triggerTime() const; + uint64 startTime() const; + int locationId() const; + int userId() const; + int userGrounpId() const; + const std::string& hostName() const; + uint64 timeFlag() const; + int linkType() const; + int isSesExe() const; + int nodeType() const; + int actionNo() const; + int funcNo() const; + + const std::string& userName() const; + +private: + void clearChild(); +protected: + friend class CRecoverIterator; + std::string m_strNodeName; + std::string m_strNodeDesc; + std::string m_strHostName; + std::string m_strUserName; + SLinkageRunning* m_ptrRunnningInfo; + std::map m_mapChild; +}; + +class CRecoverNodeLink : public CRecoverNode +{ +public: + CRecoverNodeLink(SLinkageRunning* info); + + CRecoverNodeLink(const CRecoverNodeLink& recover); + CRecoverNodeLink& operator=(const CRecoverNodeLink& recover); + + ~CRecoverNodeLink(); + const std::string& linkName() const; +}; + +class CRecoverNodeFunc : public CRecoverNode +{ +public: + CRecoverNodeFunc(SLinkageRunning* info); + CRecoverNodeFunc(const CRecoverNodeFunc& recover); + CRecoverNodeFunc& operator=(const CRecoverNodeFunc& recover); + ~CRecoverNodeFunc(); + const std::string& linkName() const; + const std::string& funcName() const; +private: + std::string m_strLinkName; +}; + +class CRecoverNodeAction : public CRecoverNode +{ +public: + CRecoverNodeAction(SLinkageRunning* info); + CRecoverNodeAction(const CRecoverNodeAction& recover); + CRecoverNodeAction& operator=(const CRecoverNodeAction& recover); + ~CRecoverNodeAction(); + const std::string& linkName() const; + const std::string& funcName() const; + const std::string& actionName() const; +private: + std::string m_strLinkName; + std::string m_strFuncName; +}; + +// 运行节点 迭代器 +class CRecoverNodeContainer; +class CRecoverIterator +{ +public: + CRecoverIterator(); + CRecoverIterator( + const CRecoverNode& parent); + CRecoverIterator( + const CRecoverNode& parent, + const std::string& chName); + + CRecoverIterator( + const CRecoverNodeContainer& pParent); + CRecoverIterator( + const CRecoverNodeContainer& pParent, + const std::string& chName); + + virtual ~CRecoverIterator(); + + virtual bool hasNext() const; + CRecoverNode& getNext(); + +protected: + std::vector m_vec; + std::vector::iterator m_iter; +}; diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNodeContainer.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNodeContainer.cpp new file mode 100644 index 00000000..01db3d41 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNodeContainer.cpp @@ -0,0 +1,211 @@ +#include "pub_logger_api/logger.h" + +#include "CRecoverNodeContainer.h" +#include "predifineforlinkageserver.h" + +CRecoverNodeContainer::CRecoverNodeContainer() +{ + +} + +CRecoverNodeContainer::CRecoverNodeContainer(const CRecoverNodeContainer& container) +{ + std::map::const_iterator iter + = container.m_mapRecoverNodeLink.begin(); + for (; iter != container.m_mapRecoverNodeLink.end(); ++iter) + { + CRecoverNodeLink* pNode = new CRecoverNodeLink(*iter->second); + this->m_mapRecoverNodeLink.insert(std::make_pair(pNode->nodeName(), pNode)); + } +} + +CRecoverNodeContainer& CRecoverNodeContainer::operator=(const CRecoverNodeContainer &container) +{ + if (this == &container) + { + return *this; + } + + this->clearRecoverNode(); + + std::map::const_iterator iter + = container.m_mapRecoverNodeLink.begin(); + for (; iter != container.m_mapRecoverNodeLink.end(); ++iter) + { + CRecoverNodeLink* pNode = new CRecoverNodeLink(*iter->second); + this->m_mapRecoverNodeLink.insert(std::make_pair(pNode->nodeName(), pNode)); + } + + return *this; +} + +CRecoverNodeContainer::~CRecoverNodeContainer() +{ + clearData(); +} + +bool CRecoverNodeContainer::isEmpty() +{ + return m_mapRecoverNodeLink.begin() + == m_mapRecoverNodeLink.end(); +} + +void CRecoverNodeContainer::clearData() +{ + clearRecoverNode(); + clearLinkInfo(); + clearFuncInfo(); + clearActionInfo(); +} + +void CRecoverNodeContainer::pushData(SLinkageRunning* data) +{ + if (data->node_type == 0) + { + m_vecLinkInfo.push_back(data); + } + else if (data->node_type == 1) + { + m_vecFuncInfo.push_back(data); + } + else if (data->node_type == 2) + { + m_vecActionInfo.push_back(data); + } + else + { + delete data; + data = NULL; + } +} + +void CRecoverNodeContainer::createModel() +{ + LOGINFO("创建联动运行表结构"); + createRecoverNodeLink(); + createRecoverNodeFunc(); + createRecoverNodeAction(); + LOGINFO("结束创建联动运行表结构"); +} + +void CRecoverNodeContainer::clearRecoverNode() +{ + std::map::iterator iter + = m_mapRecoverNodeLink.begin(); + for (; iter != m_mapRecoverNodeLink.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapRecoverNodeLink.clear(); +} + +void CRecoverNodeContainer::clearLinkInfo() +{ + std::vector::iterator iter; + + iter = m_vecLinkInfo.begin(); + for (; iter != m_vecLinkInfo.end(); ++iter) + { + delete *iter; + *iter = NULL; + } + m_vecLinkInfo.clear(); +} + +void CRecoverNodeContainer::clearFuncInfo() +{ + std::vector::iterator iter; + + iter = m_vecFuncInfo.begin(); + for (; iter != m_vecFuncInfo.end(); ++iter) + { + delete *iter; + *iter = NULL; + } + m_vecFuncInfo.clear(); +} + +void CRecoverNodeContainer::clearActionInfo() +{ + std::vector::iterator iter; + + iter = m_vecActionInfo.begin(); + for (; iter != m_vecActionInfo.end(); ++iter) + { + delete *iter; + *iter = NULL; + } + m_vecActionInfo.clear(); +} + +void CRecoverNodeContainer::createRecoverNodeLink() +{ + std::vector::iterator iter = m_vecLinkInfo.begin(); + for (; iter != m_vecLinkInfo.end(); ++iter) + { + CRecoverNodeLink* pNode = new CRecoverNodeLink(*iter); + m_mapRecoverNodeLink.insert(std::make_pair(pNode->nodeName(), pNode)); + } + + //把数据移交给 节点管理 + m_vecLinkInfo.clear(); +} + +void CRecoverNodeContainer::createRecoverNodeFunc() +{ + std::vector::iterator iter = m_vecFuncInfo.begin(); + for (; iter != m_vecFuncInfo.end(); ++iter) + { + CRecoverNodeFunc* pFuncNode = new CRecoverNodeFunc(*iter); + + CRecoverIterator linkNodeIter(*this, pFuncNode->linkName()); + if (linkNodeIter.hasNext()) + { + CRecoverNode& linkNode = linkNodeIter.getNext(); + linkNode.addChild(pFuncNode); + } + else + { + delete pFuncNode; + pFuncNode = NULL; + } + } + + //把数据移交给 节点管理 + m_vecFuncInfo.clear(); +} + +void CRecoverNodeContainer::createRecoverNodeAction() +{ + std::vector::iterator iter = m_vecActionInfo.begin(); + for (; iter != m_vecActionInfo.end(); ++iter) + { + CRecoverNodeAction* pActionNode = new CRecoverNodeAction(*iter); + + CRecoverIterator linkNodeIter(*this, pActionNode->linkName()); + if (linkNodeIter.hasNext()) + { + CRecoverNode& linkNode = linkNodeIter.getNext(); + CRecoverIterator funcNodeIter(linkNode, pActionNode->funcName()); + if (funcNodeIter.hasNext()) + { + CRecoverNode& funcNode = funcNodeIter.getNext(); + funcNode.addChild(pActionNode); + } + else + { + delete pActionNode; + pActionNode = NULL; + } + } + else + { + delete pActionNode; + pActionNode = NULL; + } + } + + //把数据移交给 节点管理 + m_vecActionInfo.clear(); +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNodeContainer.h b/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNodeContainer.h new file mode 100644 index 00000000..c4037a4d --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CRecoverNodeContainer.h @@ -0,0 +1,44 @@ +#pragma once +/*! + * @breif 运行表数据容器 + * 用于存放用于恢复运行态数据的临时数据结构 + * + * @author sjq + * @date 五月 2018 + */ +#include + +#include "DbTableDefine.h" +#include "CRecoverNode.h" + +class CRecoverNodeContainer +{ +public: + CRecoverNodeContainer(); + CRecoverNodeContainer(const CRecoverNodeContainer& container); + CRecoverNodeContainer& operator=(const CRecoverNodeContainer& container); + ~CRecoverNodeContainer(); + + bool isEmpty(); + void clearData(); + void pushData(SLinkageRunning* data); + void createModel(); + +private: + void clearRecoverNode(); + void clearLinkInfo(); + void clearFuncInfo(); + void clearActionInfo(); + + void createRecoverNodeLink(); + void createRecoverNodeFunc(); + void createRecoverNodeAction(); +protected: + friend class CRecoverIterator; + std::map m_mapRecoverNodeLink; + +private: + std::vector m_vecLinkInfo; //所有联动 + std::vector m_vecFuncInfo; //所有功能 + std::vector m_vecActionInfo; //所有动作 +}; diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CSetReqMsgInfo.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/CSetReqMsgInfo.cpp new file mode 100644 index 00000000..502dfc23 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CSetReqMsgInfo.cpp @@ -0,0 +1,134 @@ +#include "CSetReqMsgInfo.h" +#include "CRecoverNode.h" + + +CSetReqMsgInfo::CSetReqMsgInfo(const SSetReqMsg& reqMsg) +{ + m_stSeqMsg = reqMsg; + getLinkNode(); +} + +CSetReqMsgInfo::~CSetReqMsgInfo() +{ + +} + +void CSetReqMsgInfo::setMsgInfo(LinkOperateMessage &msg, enLcsMsgType msgType, ENLinkOperateType type) +{ + LinkNodeStatusParameter* link_node + = cterateLink(); + LcsPkgHead* pkg_head + = cterateHead(msgType); + ActorParameter* actor + = createActor(); + + msg.set_opreate_type(type); + msg.set_allocated_pkg_head(pkg_head); + msg.set_allocated_link_node(link_node); + msg.set_allocated_actor(actor); +} + +LcsPkgHead *CSetReqMsgInfo::cterateHead(enLcsMsgType msgType) +{ + LcsPkgHead* head = new LcsPkgHead; + head->set_source_domain(m_stSeqMsg.source_domainId); + head->set_target_domain(m_stSeqMsg.target_domainId); + head->set_msg_type(msgType); + head->set_source_tag(std::string("hmi")); + head->set_para1(0); + head->set_para2(0); + return head; +} + +LinkNodeStatusParameter *CSetReqMsgInfo::cterateLink() +{ + LinkNodeStatusParameter* link + = new LinkNodeStatusParameter; + + link->set_link_name(m_ptrLinkNode->nodeName()); + link->set_link_desc(m_ptrLinkNode->description()); + link->set_timeflag(m_ptrLinkNode->timeFlag()); + link->set_node_state(enumLINK_RUNNING_STATUS); + MapCheckState::iterator iter = m_stSeqMsg.mapCheck.find(m_ptrLinkNode->nodeName()); + assert(iter != m_stSeqMsg.mapCheck.end()); + link->set_check_state(getNodeCheckStatus(iter->second)); + + CRecoverIterator funcIter(*m_ptrLinkNode); + + while(funcIter.hasNext()) + { + CRecoverNode& funcNode = funcIter.getNext(); + FucNodeStatusParameter* func + = link->add_nodelist(); + cterateFunc(func, funcNode); + } + + return link; +} + +FucNodeStatusParameter *CSetReqMsgInfo::cterateFunc(FucNodeStatusParameter *pFunc, const CRecoverNode& funcNode) +{ + pFunc->set_fuc_name(funcNode.nodeName()); + pFunc->set_fuc_desc(funcNode.description()); + pFunc->set_timeflag(funcNode.timeFlag()); + pFunc->set_node_state(enumLINK_RUNNING_STATUS); + + MapCheckState::iterator iter = m_stSeqMsg.mapCheck.find(funcNode.nodeName()); + assert(iter != m_stSeqMsg.mapCheck.end()); + pFunc->set_check_state(getNodeCheckStatus(iter->second)); + + CRecoverIterator actionIter(funcNode); + + while(actionIter.hasNext()) + { + CRecoverNode& actionNode = actionIter.getNext(); + ActionNodeStatusParameter* action + = pFunc->add_nodelist(); + cterateAction(action, actionNode); + } + + return pFunc; +} + +ActionNodeStatusParameter *CSetReqMsgInfo::cterateAction(ActionNodeStatusParameter *pAction, const CRecoverNode& actionNode) +{ + pAction->set_action_name(actionNode.nodeName()); + pAction->set_action_desc(actionNode.description()); + pAction->set_timeflag(actionNode.timeFlag()); + pAction->set_node_state(enumLINK_RUNNING_STATUS); + + MapCheckState::iterator iter = m_stSeqMsg.mapCheck.find(actionNode.nodeName()); + assert(iter != m_stSeqMsg.mapCheck.end()); + pAction->set_check_state(getNodeCheckStatus(iter->second)); + + return pAction; +} + +ActorParameter *CSetReqMsgInfo::createActor() +{ + ActorParameter* pActor + = new ActorParameter; + pActor->set_host_name(m_stSeqMsg.userinfo->host_name.toStdString()); + pActor->set_user_name(m_stSeqMsg.userinfo->user_name.toStdString()); + pActor->set_user_id(m_stSeqMsg.userId); + pActor->set_user_groupid(m_stSeqMsg.usergId); + return pActor; +} + +void CSetReqMsgInfo::getLinkNode() +{ + CRecoverIterator linkIter(*m_stSeqMsg.container); + assert(linkIter.hasNext()); + + m_ptrLinkNode = &(linkIter.getNext()); +} + +ENLcsNodeCheckStatus CSetReqMsgInfo::getNodeCheckStatus(int state) +{ + if(state == 0) + return ENLcsNodeCheckStatus::enumNodeUnChecked; + else if(state == 1) + return ENLcsNodeCheckStatus::enumnodePartiallyChecked; + else + return ENLcsNodeCheckStatus::enumNodeChecked; +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/CSetReqMsgInfo.h b/product/src/tools/link_seq_tool/linkage_server_tool/CSetReqMsgInfo.h new file mode 100644 index 00000000..6591864d --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/CSetReqMsgInfo.h @@ -0,0 +1,55 @@ +#ifndef CSETREQMSGINFO_H +#define CSETREQMSGINFO_H + +#include +#include "LinkageMessage.pb.h" +#include "predifineforlinkageserver.h" +#include "CRecoverNodeContainer.h" +#include "ConfigureDialog.h" + +class CRecoverNode; +using namespace iot_idl::linkage; +typedef std::map MapCheckState; +class QTreeWidgetItem; + +struct SSetReqMsg +{ + SUserInfo* userinfo; + CRecoverNodeContainer* container; + MapCheckState mapCheck; + int source_domainId; + int target_domainId; + int userId; + int usergId; +}; + +class CSetReqMsgInfo +{ +public: + CSetReqMsgInfo(const SSetReqMsg& reqMsg); + ~CSetReqMsgInfo(); + + void setMsgInfo(LinkOperateMessage& msg, + enLcsMsgType msgType, + ENLinkOperateType type); + + ENLcsNodeCheckStatus getNodeCheckStatus(int state); + +private: + LcsPkgHead* cterateHead( + enLcsMsgType msgType); + + LinkNodeStatusParameter* cterateLink(); + FucNodeStatusParameter* cterateFunc(FucNodeStatusParameter* pFunc, const CRecoverNode &funcNode); + ActionNodeStatusParameter* cterateAction(ActionNodeStatusParameter* pAction, const CRecoverNode &actionNode); + + ActorParameter* createActor(); + + void getLinkNode(); + +private: + SSetReqMsg m_stSeqMsg; + CRecoverNode* m_ptrLinkNode; +}; + +#endif // CSETREQMSGINFO_H diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.cpp new file mode 100644 index 00000000..ee67110f --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.cpp @@ -0,0 +1,375 @@ +#include "ConfigureDialog.h" +#include "ui_ConfigureDialog.h" +#include + +ConfigureDialog::ConfigureDialog(QWidget *parent) : + CustomUiDialog(parent), + ui(new Ui::ConfigureDialog) +{ + setWindowTitle(tr("配置")); + + m_dbData = new CGetDBData(); + m_settings = new QSettings("../../data/link_seq_test_cache/LinkTestUserInfo.ini", QSettings::IniFormat); + m_settings->setIniCodec("UTF-8"); + m_settings->beginGroup("UserInfo"); + ui->setupUi(this); + + ui->treeWidget->setColumnCount(2); + ui->treeWidget->setHeaderLabels(QStringList()<<"参数"<<"值"); + userInfo = new QTreeWidgetItem(ui->treeWidget); + userItem = new QTreeWidgetItem(userInfo); + hostItem = new QTreeWidgetItem(userInfo); + locationItem = new QTreeWidgetItem(userInfo); + userGroupItem = new QTreeWidgetItem(userInfo); + domainItem = new QTreeWidgetItem(userInfo); + domainItem->setDisabled(true); + userGroupItem->setDisabled(true); + userInfo->setText(0,"用户信息"); + userItem->setText(0,"用户名"); + userGroupItem->setText(0,"用户组名"); + hostItem->setText(0,"主机名"); + locationItem->setText(0,"车站"); + domainItem->setText(0,"域"); + + initUserInfo(); + + m_linkLocationMap = m_dbData->readLinkLocation(); + m_locationDomainIdMap = m_dbData->readLocationDomainId(); + m_userMap = m_dbData->readUserInfo(); + m_usergMap = m_dbData->readUsergInfo(); + m_locationMap = m_dbData->readLocationInfo(); + m_domainMap = m_dbData->readDomainInfo(); + m_hostList = m_dbData->hostNameList(); + + dbPara = new QTreeWidgetItem(ui->treeWidget); + dbPara->setDisabled(true); + dbPara->setText(0,"数据库信息"); + + QHeaderView *head = ui->treeWidget->header(); + head->setSectionResizeMode(QHeaderView::ResizeToContents); + ui->treeWidget->expandAll(); + + setAutoLayout(true); +} + +ConfigureDialog::~ConfigureDialog() +{ + delete ui; + if(m_dbData) + { + if(m_dbData->isOpen()) + { + m_dbData->closeDb(); + } + delete m_dbData; + m_dbData = NULL; + } + if(m_settings) + { + delete m_settings; + m_settings = NULL; + } +} + +void ConfigureDialog::showDbPara() +{ +} + +QString ConfigureDialog::getdbType() +{ + QString str; + return str; +} + +void ConfigureDialog::preChange(QTreeWidgetItem *item) +{ + if(ui->treeWidget->itemWidget(item,1)){ + QComboBox *box = (QComboBox*)ui->treeWidget->itemWidget(item,1); + item->setText(1,box->currentText()); + ui->treeWidget->closePersistentEditor(item,1); + if(ui->treeWidget->topLevelItem(0)->indexOfChild(item) == 2){ + QString locationName = ui->treeWidget->topLevelItem(0)->child(2)->text(1); + int domainId = getDomainIdByLocationId(getLocationId(locationName)); + QString domainName = getDomainName(domainId); + ui->treeWidget->topLevelItem(0)->child(4)->setText(1,domainName); + } + if(ui->treeWidget->topLevelItem(0)->indexOfChild(item) == 0) + { + QString userName = ui->treeWidget->topLevelItem(0)->child(0)->text(1); + int usergId = getUserId(userName); + QString usergName = getUsergName(usergId); + ui->treeWidget->topLevelItem(0)->child(3)->setText(1,usergName); + } + } +} + +void ConfigureDialog::setSUserInfo() +{ + m_stUserInfo.user_name = userItem->text(1); + m_stUserInfo.userg_Name = userGroupItem->text(1); + m_stUserInfo.host_name = hostItem->text(1); + m_stUserInfo.location_name = locationItem->text(1); + m_stUserInfo.domain_name = domainItem->text(1); +} + +void ConfigureDialog::slot_editSave() +{ + preChange(m_item); + m_settings->setValue("user_name",QVariant(userItem->text(1))); + m_settings->setValue("userg_name",QVariant(userGroupItem->text(1))); + m_settings->setValue("host_name",QVariant(hostItem->text(1))); + m_settings->setValue("location_name",QVariant(locationItem->text(1))); + m_settings->setValue("domain_name",QVariant(domainItem->text(1))); + setSUserInfo(); +} + +void ConfigureDialog::slot_initUserInfo() +{ + userItem->setText(1,"1"); + userGroupItem->setText(1,"系统管理员"); + hostItem->setText(1,"host"); + locationItem->setText(1,"东孚站"); + domainItem->setText(1,"东孚站域"); + + m_settings->setValue("user_name",QVariant(userItem->text(1))); + m_settings->setValue("userg_name",QVariant(userGroupItem->text(1))); + m_settings->setValue("host_name",QVariant(hostItem->text(1))); + m_settings->setValue("location_name",QVariant(locationItem->text(1))); + m_settings->setValue("domain_name",QVariant(domainItem->text(1))); + + setSUserInfo(); +} + +void ConfigureDialog::slot_editUserInfo(QTreeWidgetItem *item, int column) +{ + if(item->parent() == ui->treeWidget->topLevelItem(0) && item != ui->treeWidget->topLevelItem(0)->child(4) + && item != ui->treeWidget->topLevelItem(0)->child(3) && column == 1){ + m_item = item; + ui->treeWidget->openPersistentEditor(item,column); + QComboBox *box = new QComboBox(this); + switch (ui->treeWidget->topLevelItem(0)->indexOfChild(item)) { + case 0: + { + QMap::iterator iter = m_userMap.begin(); + for(;iter != m_userMap.end();++iter) + { + box->insertItem(iter.value(),iter.key()); + } + break; + } + case 1: + { + box->addItems(m_hostList); + break; + } + case 2: + { + QMap::iterator iter = m_locationMap.begin(); + for(;iter != m_locationMap.end();++iter) + { + box->insertItem(iter.value(),iter.key()); + } + break; + } + case 3: + { + QMap::iterator iter = m_usergMap.begin(); + for(;iter != m_usergMap.end();++iter) + { + box->insertItem(iter.value(),iter.key()); + } + break; + } + case 4: + { + QMap::iterator iter = m_domainMap.begin(); + for(;iter != m_domainMap.end();++iter) + { + box->insertItem(iter.value(),iter.key()); + } + break; + } + default: + break; + } + + ui->treeWidget->setItemWidget(item,1,box); + } +} + +void ConfigureDialog::slot_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) +{ + preChange(previous); +} + +void ConfigureDialog::initUserInfo() +{ + QStringList list = m_settings->allKeys(); + if(list.isEmpty()) + { + slot_initUserInfo(); + } + else + { + userItem->setText(1,m_settings->value("user_name").toString()); + userGroupItem->setText(1,m_settings->value("userg_name").toString()); + hostItem->setText(1,m_settings->value("host_name").toString()); + locationItem->setText(1,m_settings->value("location_name").toString()); + domainItem->setText(1,m_settings->value("domain_name").toString()); + } + setSUserInfo(); +} + +SUserInfo& ConfigureDialog::getConfigurInfo() +{ + return m_stUserInfo; +} + +int ConfigureDialog::getDomainId(const QString& domainName) +{ + int id; + QMap::const_iterator iter = m_domainMap.find(domainName); + if(iter != m_domainMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +QString ConfigureDialog::getDomainName(int domainId) +{ + QString name; + QMap::const_iterator iter = m_domainMap.begin(); + for(;iter != m_domainMap.end();++iter) + { + if(iter.value() == domainId) + { + name = iter.key(); + return name; + } + } + name = ""; + return name; +} + +int ConfigureDialog::getLocationId(const QString &locationName) +{ + int id; + QMap::const_iterator iter = m_locationMap.find(locationName); + if(iter != m_locationMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +QString ConfigureDialog::getLocationName(int locationId) +{ + QString name; + QMap::const_iterator iter = m_locationMap.begin(); + for(;iter != m_locationMap.end();++iter) + { + if(iter.value() == locationId) + { + name = iter.key(); + return name; + } + } + name = ""; + return name; +} + +int ConfigureDialog::getUserId(const QString &userName) +{ + int id; + QMap::const_iterator iter = m_userMap.find(userName); + if(iter != m_userMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +QString ConfigureDialog::getUserName(int userId) +{ + QString name; + QMap::const_iterator iter = m_userMap.begin(); + for(;iter != m_userMap.end();++iter) + { + if(iter.value() == userId) + { + name = iter.key(); + return name; + } + } + name = ""; + return name; +} + +int ConfigureDialog::getUsergId(const QString &usergName) +{ + int id; + QMap::const_iterator iter = m_usergMap.find(usergName); + if(iter != m_usergMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +QString ConfigureDialog::getUsergName(int usergId) +{ + QString name; + QMap::const_iterator iter = m_usergMap.begin(); + for(;iter != m_usergMap.end();++iter) + { + if(iter.value() == usergId) + { + name = iter.key(); + return name; + } + } + name = ""; + return name; +} + +int ConfigureDialog::getLocationIdByLinkName(const QString& linkName) +{ + int id; + QMap::const_iterator iter = m_linkLocationMap.find(linkName); + if(iter != m_linkLocationMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +int ConfigureDialog::getDomainIdByLocationId(int locationId) +{ + int id; + QMap::const_iterator iter = m_locationDomainIdMap.find(locationId); + if(iter != m_locationDomainIdMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.h b/product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.h new file mode 100644 index 00000000..a00030bb --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.h @@ -0,0 +1,74 @@ +#ifndef CONFIGUREDIALOG_H +#define CONFIGUREDIALOG_H + +#include +#include "CGetDBData.h" +#include "predifineforlinkageserver.h" +#include "pub_widget/CustomDialog.h" + +namespace Ui { +class ConfigureDialog; +} + +using namespace iot_dbms; +class ConfigureDialog : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit ConfigureDialog(QWidget *parent); + ~ConfigureDialog(); + + SUserInfo& getConfigurInfo(); + + int getDomainId(const QString& domainName); + QString getDomainName(int domainId); + int getLocationId(const QString& locationName); + QString getLocationName(int locationId); + int getUserId(const QString& userName); + QString getUserName(int userId); + int getUsergId(const QString& usergName); + QString getUsergName(int usergId); + int getLocationIdByLinkName(const QString& linkName); + int getDomainIdByLocationId(int locationId); + +private slots: + void slot_editSave(); + void slot_initUserInfo(); + void slot_editUserInfo(QTreeWidgetItem *item, int column); + void slot_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); + +private: + void initUserInfo(); + void showDbPara(); + static QString getdbType(); + void preChange(QTreeWidgetItem *item); + void setSUserInfo(); + +private: + Ui::ConfigureDialog *ui; + + CGetDBData *m_dbData; + QTreeWidgetItem * m_item = 0; + + QTreeWidgetItem * userInfo; + QTreeWidgetItem * userItem; + QTreeWidgetItem * userGroupItem; + QTreeWidgetItem * hostItem; + QTreeWidgetItem * domainItem; + QTreeWidgetItem * locationItem; + + QMap m_linkLocationMap; + QMap m_locationDomainIdMap; + QMap m_userMap; + QMap m_usergMap; + QMap m_locationMap; + QMap m_domainMap; + QStringList m_hostList; + + QTreeWidgetItem * dbPara; + QSettings* m_settings; + SUserInfo m_stUserInfo; +}; + +#endif // CONFIGUREDIALOG_H diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.ui b/product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.ui new file mode 100644 index 00000000..8ed71eb7 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/ConfigureDialog.ui @@ -0,0 +1,132 @@ + + + ConfigureDialog + + + + 0 + 0 + 391 + 280 + + + + Dialog + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 初始化全部 + + + + + + + 保存 + + + + + + + + + + 1 + + + + + + + + + + treeWidget + itemDoubleClicked(QTreeWidgetItem*,int) + ConfigureDialog + slot_editUserInfo(QTreeWidgetItem*,int) + + + 363 + 85 + + + 387 + 85 + + + + + treeWidget + currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) + ConfigureDialog + slot_currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) + + + 332 + 139 + + + 386 + 139 + + + + + pushButton + clicked() + ConfigureDialog + slot_initUserInfo() + + + 221 + 252 + + + 196 + 251 + + + + + pushButton_2 + clicked() + ConfigureDialog + slot_editSave() + + + 361 + 252 + + + 385 + 250 + + + + + + slot_editSave() + slot_initUserInfo() + slot_editUserInfo(QTreeWidgetItem*,int) + slot_currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) + + diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/DbTableDefine.h b/product/src/tools/link_seq_tool/linkage_server_tool/DbTableDefine.h new file mode 100644 index 00000000..05079f5d --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/DbTableDefine.h @@ -0,0 +1,197 @@ +#pragma once +/*! + * @breif 联动数据表结构 + * + * @author sjq + * @date 五月 2018 + */ + +#include +#include +#include + +#include "common/DataType.h" + + //失败处理类型 +enum ACTION_FAILED_STRAGE +{ + ACTION_FAILED_STRAGE_AUTO_SKIP = 0,//自动跳过 + ACTION_FAILED_STRAGE_USER_INTERVENE = 1,//人工干预 + ACTION_FAILED_STRAGE_AUTO_STOP = 2,//自动终止 + ACTION_FAILED_STRAGE_AUTO_RETYR = 3,//自动重试 +}; + +enum LINKEXEC_TYPE +{ + LINKEXEC_TYPE_AUTO = 0,//全自动 + LINKEXEC_TYPE_SEMI_AUTO = 1,//半自动 + LINKEXEC_TYPE_TPYE_MANUAL = 2,//手动 +}; + + +// 联动定义表,描述联动的配置信息 + +struct SLinkDefineInfo +{ + std::string name;//联动名称 + std::string description;//描述 + int trigger_type;//触发方式 + int exec_type;//执行方式 + int link_type;//联动类型 + std::string trigger_condition;//触发条件 + int location_id;//域 + uint64 timeflag;//时标 +}; + + +// 联动信息表,描述联动和功能的关系 + +struct SLinkConfigInfo +{ + std::string linkage_name;//联动名称 + std::string func_name;//功能名 + int func_no;//功能编号 + int relation;//串 / 并 0串 1并 + uint64 timeflag;//时标 +}; + + +// 联动功能定义表,描述 功能和动作的关系,功能的配置信息 + +struct SFuncInfo +{ + std::string name;//功能名称 + std::string description;//功能描述 + int action_no;//动作编号 + std::string action_name;//动作名称 + bool enable;//是否可用 + int delaytime;//延时时间 + int failstrage;//失败处理 + int retrytimes;//重试次数 + uint64 timeflag;//时标 + int func_type;//功能类型 +}; + + +// 联动动作定义表 ,描述动作的配置信息 + +struct SActionInfo +{ + std::string name;//动作名称 + std::string description;//动作描述 + std::string linkage_string;//动作解析串 + int ctrl_timeout;//控制超时时间 + int action_type;//动作类型 + int sub_system;//动作所属子系统 + int location_id;//动作所在车站 + uint64 timeflag;//时标 +}; + +//联动输出的四张表 + + +// 联动历史信息表 + +struct SLinkageHistory +{ + std::string linkage_name;//联动名称 + uint64 time;//执行时间 + std::string func_name;//功能名 + std::string status;//执行状态 + int location_id;//车站id +}; + + +// 联动运行表 - 调用实时服务 读写数据 + +struct SLinkageRunning +{ + std::string linkage_name;//1 联动名称 + std::string func_name;//2 功能名 + std::string action_name;//3 动作名 + std::string node_desc;//4 节点描述 + int action_no;//5 动作序号 + int func_no;//6 功能序号 + int node_type;//7 节点类型 0 联动节点 1 功能节点 2 动作节点 + int status;//8 执行状态 + int checked;//9 勾选状态 + uint64 trigger_time;//10 触发时间 + uint64 start_time;//11 开始时间 + int user_id;//12 操作员id + int user_groupid;//13 用户组id + std::string host_name;//14 主机名 + int location_id;//15 车站id + uint64 timeflag;//16 时标 + int relation;//17串并行方式 0 串 1并', + int link_type;//18 联动类型 ', + int exe_type;//19 执行方式 0 全自动 1 半自动 2 手动', + int delay_time;//20 延迟时间', + int fail_strage;//21 失败处理方式 0自动跳过 1人工干预 2 自动终止 3自动重试', + int isses;//22 是否是单步执行 0 不是 1是单步 + + SLinkageRunning() + { + }; + SLinkageRunning(const SLinkageRunning& info) + { + this->linkage_name = info.linkage_name; + this->func_name = info.func_name; + this->action_name = info.action_name; + this->node_desc = info.node_desc; + this->action_no = info.action_no; + this->func_no = info.func_no; + this->node_type = info.node_type; + this->status = info.status; + this->checked = info.checked; + this->trigger_time = info.trigger_time; + this->start_time = info.start_time; + this->user_id = info.user_id; + this->user_groupid = info.user_groupid; + this->host_name = info.host_name; + this->location_id = info.location_id; + this->timeflag = info.timeflag; + this->relation = info.relation; + this->link_type = info.link_type; + this->exe_type = info.exe_type; + this->delay_time = info.delay_time; + this->fail_strage = info.fail_strage; + this->isses = info.isses; + }; +}; + +struct SLinkageUpdate +{ + QString status; + QString trigger_time; + QString start_time; + QString user_name; + QString user_groupname; + QString host_name; + QString isses; + int node_type; + int func_no; + int action_no; +}; + +// 联动动作事件 + +struct SLinkageActionEvent +{ + std::string linkage_name;//联动名称 + uint64 time;//触发时间 + std::string func_name;//功能名 + int action_no;//动作编号 + std::string action_name;//动作名称 + std::string status;//执行状态 + uint64 starttime;//开始时间 + uint64 stoptime;//结束时间 + int location_id;//车站id +}; + +//实时库 联动配置表 +struct SRdbLinkageSetting +{ + char name[128];//1 联动名称 + int location_id;//车站 + uint64 timeflag;//时标 +}; diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/RefreshExeStateThread.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/RefreshExeStateThread.cpp new file mode 100644 index 00000000..e7ed1701 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/RefreshExeStateThread.cpp @@ -0,0 +1,134 @@ +#include "RefreshExeStateThread.h" +#include "rdb_net_api/CRdbNetApi.h" + +using namespace iot_dbms; +using namespace iot_idl; + +RefreshExeStateThread::RefreshExeStateThread() + :CTimerThreadBase("RefreshExeState thread", 500, iot_public::CN_DeadlockTimeoutMsec, false) +{ + +} + +RefreshExeStateThread::~RefreshExeStateThread() +{ + +} + +bool RefreshExeStateThread::getDomainLinkStatue() +{ + RefreshExeStateThreadStatusLocker lock(*this); + linkStatus.clear(); + + iot_idl::RdbQuery msgQuery; + msgQuery.set_strtablename("linkage_running"); + std::string *pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "linkage_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "node_type"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "status"; + + iot_idl::RdbCondition *pCondtion = msgQuery.add_msgcondition(); + pCondtion->set_enlogic(ENConditionLogic::enumCondAnd); + pCondtion->set_enrelation(ENConditionRelation::enumCondEqual); + pCondtion->set_strcolumnname("node_type"); + + SVariable *pCondValue = pCondtion->mutable_msgvalue(); + pCondValue->set_edatatype(DataType::CN_DATATYPE_INT32); + pCondValue->set_nvalue(0); + + iot_idl::RdbRet retMsg; + bool bRet = objNetApi.query(msgQuery, retMsg); + if (false == bRet) { + std::cout << "query failed." << std::endl; + } + else { + for (int i = 0 ; i < retMsg.msgrecord_size() ; ++i) { + linkStatus.insert(QString::fromStdString(retMsg.msgrecord(i).msgvaluearray(0).strvalue()), + CGetRdbData::statusType(retMsg.msgrecord(i).msgvaluearray(2).nvalue())); + } + } + + return true; +} + +void RefreshExeStateThread::getAllLinkStatue() +{ + for(int domainNum=0;domainNum domainIdList) +{ + m_domainId = domainIdList; +} + +bool RefreshExeStateThread::start() +{ + this->resume(); + return true; +} + +bool RefreshExeStateThread::stop() +{ + this->suspend(); + return true; +} + +bool RefreshExeStateThread::isEmpty() +{ + return linkStatus.isEmpty(); +} + +void RefreshExeStateThread::clear() +{ + linkStatus.clear(); +} + +QString RefreshExeStateThread::getStatus(const QString& linkName) +{ + return linkStatus.take(linkName); +} + + +void RefreshExeStateThread::lock() +{ + mutex.lock(); +} + +void RefreshExeStateThread::unlock() +{ + mutex.unlock(); +} + + +void RefreshExeStateThread::execute() +{ + getAllLinkStatue(); +} + +bool RefreshExeStateThread::lockTable(int domainId) +{ + objNetApi.connect(domainId, 3); + bool bRet = objNetApi.lock("linkage_running"); + if (false == bRet) { + std::cout << "lock failed." << std::endl; + } + return bRet; +} + +void RefreshExeStateThread::unLockTable() +{ + bool bRet = objNetApi.unLock("linkage_running"); + if (false == bRet) { + std::cout << "unlock failed." << std::endl; + } +} + diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/RefreshExeStateThread.h b/product/src/tools/link_seq_tool/linkage_server_tool/RefreshExeStateThread.h new file mode 100644 index 00000000..99ca1760 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/RefreshExeStateThread.h @@ -0,0 +1,86 @@ +#ifndef REFRESHEXESTATETHREAD_H +#define REFRESHEXESTATETHREAD_H + +#include "pub_utility_api/TimerThreadBase.h" +#include "CGetRdbData.h" + +class RefreshExeStateThread + :public iot_public::CTimerThreadBase +{ +public: + RefreshExeStateThread(); + ~RefreshExeStateThread(); + + bool getDomainLinkStatue(); + + void getAllLinkStatue(); + + void setDomainId(QList domainIdList); + //开启线程 + bool start(); + + //停止线程 + bool stop(); + + bool isEmpty(); + + void clear(); + + QString getStatus(const QString& linkName); + +protected: + void execute(); + friend class RefreshExeStateThreadLocker; + bool lockTable(int domainId); + void unLockTable(); + friend class RefreshExeStateThreadStatusLocker; + void lock(); //linkStatus + void unlock(); + +private: + QList m_domainId; + QMap linkStatus; + boost::mutex mutex; + CRdbNetApi objNetApi; +}; + +class RefreshExeStateThreadStatusLocker +{ +public: + RefreshExeStateThreadStatusLocker(RefreshExeStateThread& access) + :m_objAccess(access) + { + m_objAccess.lock(); + }; + ~RefreshExeStateThreadStatusLocker() + { + m_objAccess.unlock(); + }; +private: + RefreshExeStateThread& m_objAccess; +}; + +class RefreshExeStateThreadLocker +{ +public: + RefreshExeStateThreadLocker(RefreshExeStateThread& access, int domainId) + :m_objAccess(access),m_domainId(domainId) + { + m_isLock = m_objAccess.lockTable(m_domainId); + }; + ~RefreshExeStateThreadLocker() + { + m_objAccess.unLockTable(); + }; + bool isLock() + { + return m_isLock; + } +private: + RefreshExeStateThread& m_objAccess; + int m_domainId; + bool m_isLock; +}; + + +#endif // REFRESHEXESTATETHREAD_H diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/linkage_server_tool.pro b/product/src/tools/link_seq_tool/linkage_server_tool/linkage_server_tool.pro new file mode 100644 index 00000000..11d23e43 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/linkage_server_tool.pro @@ -0,0 +1,92 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-05-28T09:42:46 +# +#------------------------------------------------- + +QT += core gui sql + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = linkage_server_tool +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + CLinkageForHmiApiInterface.cpp \ + CGetDBData.cpp \ + CGetRdbData.cpp \ + CRdbLinkRunningAccess.cpp \ + CRecoverNodeContainer.cpp \ + CRecoverNode.cpp \ + ConfigureDialog.cpp \ + RefreshExeStateThread.cpp \ + CLinkageDbContainer.cpp \ + CSetReqMsgInfo.cpp + +HEADERS += \ + mainwindow.h \ + CLinkageForHmiApiInterface.h \ + CGetDBData.h \ + CGetRdbData.h \ + CRdbLinkRunningAccess.h \ + DbTableDefine.h \ + CRecoverNodeContainer.h \ + CRecoverNode.h \ + predifineforlinkageserver.h \ + ConfigureDialog.h \ + RefreshExeStateThread.h \ + CLinkageDbContainer.h \ + CSetReqMsgInfo.h + +FORMS += \ + mainwindow.ui \ + ConfigureDialog.ui + +HEADERS += \ + ../../../idl_files/LinkageMessage.pb.h \ + ../../../include/application/linkage_server_api/CLinkageApiExport.h \ + ../../../include/application/linkage_server_api/CLinkageForHmiApi.h + +DISTFILES += \ + ../../../idl_files/LinkageMessage.proto + +LIBS += \ + -lpub_logger_api \ + -llog4cplus \ + -lprotobuf \ + -lnet_msg_bus_api \ + -llinkage_server_api \ + -lboost_date_time \ + -lboost_system \ + -lboost_thread \ + -ldb_sysinfo_api \ + -ldb_api_ex \ + -lrdb_net_api \ + -lpub_utility_api \ + -lrdb_api \ + -lpub_widget + +#------------------------------------------------------------------- +include($$PWD/../../../idl_files/idl_files.pri) + + +COMMON_PRI=$$PWD/../../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/main.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/main.cpp new file mode 100644 index 00000000..cc58b29f --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/main.cpp @@ -0,0 +1,62 @@ +#include "mainwindow.h" +#include +#include +#include "pub_logger_api/logger.h" +#include "net/net_msg_bus_api/MsgBusApi.h" +#include "pub_utility_api/FileStyle.h" + +void loadStyle() +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss","zh","light"); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("linkage_server_tool.qss","zh","light"); + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + qApp->setStyleSheet(qss); + } +} + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + loadStyle(); + + iot_public::StartLogSystem("comapp", "hmi-test"); + + int nRet = iot_net::initMsgBus( + std::string("hmi").c_str(), + std::string("hmiInstance").c_str()); + if (false == nRet) { + return 0; + } + + { + MainWindow w; + w.show(); + + nRet = a.exec(); + w.quit(); + } + + iot_net::releaseMsgBus(); + iot_public::StopLogSystem(); + + return nRet; +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.cpp b/product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.cpp new file mode 100644 index 00000000..96744c1e --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.cpp @@ -0,0 +1,890 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "boost/date_time.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include "boost/filesystem.hpp" + +MainWindow::MainWindow(QWidget *parent) : + CustomUiMainWindow(parent), + ui(new Ui::MainWindow), + m_objMsgBox(this), + m_objLocalDbConn(DB_CONN_MODEL_READ) +{ + setAutoLayout(true); + setWindowTitle(tr("联动调试工具")); + + ui->setupUi(this); + showMaximized(); + RunTabTimer = new QTimer(this); + connect(RunTabTimer, SIGNAL(timeout()), this, SLOT(slot_updateRunTab())); + exeStatusTimer = new QTimer(this); + connect(exeStatusTimer, SIGNAL(timeout()), this, SLOT(slot_updateStatus())); + + m_ptrShowMsgList = ui->listWidget; + m_ptrDbData = new CGetDBData(); + m_ptrRdbData = new CGetRdbData(); + m_ptrInterface = new CLinkageForHmiApiInterface(this); + m_ptrConfig = NULL; + + initButton(); + if(initDbTab()){ + QList domainIdList = getDomainId(); + m_ptrState = new RefreshExeStateThread(); + m_ptrState->setDomainId(domainIdList); + exeStatusTimer->start(500); + } + else + { + showMsg("关系库连接失败"); + } + initUserInfo(); + initRunTab(); + + connect(ui->actionconfigure,SIGNAL(triggered(bool)),this,SLOT(slot_configUserInfo())); + + m_btnRetry = + m_objMsgBox.addButton(QString("重试"), QMessageBox::ActionRole); + m_btnStop = + m_objMsgBox.addButton(QString("终止"), QMessageBox::ActionRole); + m_btnSkip = + m_objMsgBox.addButton(QString("跳过"), QMessageBox::ActionRole); + +} + +MainWindow::~MainWindow() +{ + quit(); + + delete ui; +} + +void MainWindow::quit() +{ + if (m_ptrInterface) + { + m_ptrInterface->stop(); + delete m_ptrInterface; + m_ptrInterface = NULL; + } + + if(m_ptrDbData) + { + if(m_ptrDbData->isOpen()) + { + m_ptrDbData->closeDb(); + } + delete m_ptrDbData; + m_ptrDbData = NULL; + } + + if (m_ptrRdbData) + { + m_ptrRdbData->stop(); + delete m_ptrRdbData; + m_ptrRdbData = NULL; + } + + if (m_ptrState) + { + m_ptrState->stop(); + delete m_ptrState; + m_ptrState = NULL; + } + + if(RunTabTimer) + { + RunTabTimer->stop(); + delete RunTabTimer; + RunTabTimer = NULL; + } + + if(exeStatusTimer) + { + exeStatusTimer->stop(); + delete exeStatusTimer; + exeStatusTimer = NULL; + } + + if(m_ptrConfig) + { + delete m_ptrConfig; + m_ptrConfig = NULL; + } +} + +void MainWindow::showMsg(const QString & msg) +{ + refreshBuf.append(msg); + if(ui->checkBox->isChecked()){ + for(int i = 0;i < refreshBuf.size();++i){ + QMetaObject::invokeMethod(this, "slot_showMsg", + Qt::QueuedConnection, Q_ARG(QString, refreshBuf.at(i))); + } + refreshBuf.clear(); + } +} + +void MainWindow::showUiMsg( + const QString& msgStr, + UiRequestMessage& msg) +{ + UiRequestMessage* newMsg = new UiRequestMessage(msg); + QMetaObject::invokeMethod(this, "slot_showUiMsg", + Qt::QueuedConnection, Q_ARG(QString, msgStr), Q_ARG(void*, newMsg)); +} + +QList MainWindow::getDomainId() +{ + QList domainIdList; + QTreeWidgetItemIterator it(ui->dbTable); + while(*it) + if((*it)->parent()){ + ++it; + continue; + } + else{ + int locationId = m_ptrConfig->getLocationIdByLinkName((*it)->text(0)); + int domainId = m_ptrConfig->getDomainIdByLocationId(locationId); + int i = 0; + for(; idbTable->setColumnCount(11); + ui->dbTable->setHeaderLabels(QStringList()<<"联动名称"<<"描述"<<"触发方式/是否可用" + <<"执行方式/延时时间"<<"联动类型/失败处理" + <<"触发条件/重做次数"<<"车站/专业"<<"时标" + <<"超时时间"<<"动作类型"<<"执行状态"); + + QHeaderView *head = ui->dbTable->header(); + head->setSectionResizeMode(QHeaderView::ResizeToContents); + + if(m_ptrDbData->openDb()){ + m_ptrConfig = new ConfigureDialog(this); + bool bRet = m_ptrDbData->remapDbTable(m_dbContainer); + if(bRet) + { + initDbTabData(); + return true; + } + else + return false; + } + else{ + return false; + } +} + +void MainWindow::initRunTab() +{ + ui->rdbTable->setColumnCount(20); + ui->rdbTable->setHeaderLabels(QStringList()<<"名称"<<"描述"<<"选择" + <<"执行方式"<<"延时时间"<<"失败处理" + <<"执行状态"<<"执行类型"<<"触发时间" + <<"开始时间"<<"车站"<<"用户"<<"用户组" + <<"主机名"<<"时标"<<"联动类型"<<"是否单步" + <<"节点类型"<<"功能序号"<<"动作序号"); + + QHeaderView *head = ui->rdbTable->header(); + head->setSectionResizeMode(QHeaderView::ResizeToContents); +} + +void MainWindow::initButton() +{ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(false); + ui->seqStartButton->setEnabled(false); + ui->seqContinueButton->setEnabled(false); +} + +void MainWindow::initDbTabData() +{ + SLinkDefineInfoIterator linkDefineIter(m_dbContainer); + + while(linkDefineIter.hasNext()) + { + const SLinkDefineInfo& defineInfo = linkDefineIter.getNext(); + + initDbDefineData(defineInfo); + } +} + +void MainWindow::initDbDefineData(const SLinkDefineInfo& defineInfo) +{ + QTreeWidgetItem *defineItem = new QTreeWidgetItem(ui->dbTable); + defineItem->setText(0,QString::fromStdString(defineInfo.name)); + defineItem->setText(1,QString::fromStdString(defineInfo.description)); + defineItem->setText(2,CGetDBData::triggerType(defineInfo.trigger_type)); + defineItem->setText(3,CGetDBData::execType(defineInfo.exec_type)); + defineItem->setText(4,CGetDBData::linkType(defineInfo.link_type)); + defineItem->setText(5,QString::fromStdString(defineInfo.trigger_condition)); + defineItem->setText(6,m_ptrConfig->getLocationName(defineInfo.location_id)); + defineItem->setText(7,CGetRdbData::timeToDT(defineInfo.timeflag)); + + SLinkConfigInfoIterator linkConfigIter(m_dbContainer,defineInfo.name); + while(linkConfigIter.hasNext()) + { + const SLinkConfigInfo& configInfo = linkConfigIter.getNext(); + + initDbConfigData(configInfo, defineItem); + } +} + +void MainWindow::initDbConfigData(const SLinkConfigInfo& configInfo, QTreeWidgetItem* defineItem) +{ + QTreeWidgetItem *configItem = new QTreeWidgetItem(defineItem); + configItem->setText(0,QString::fromStdString(configInfo.func_name)); + configItem->setText(3,CGetDBData::relationType(configInfo.relation)); + + SFuncInfoIterator linkFuncIter(m_dbContainer,configInfo.func_name); + while(linkFuncIter.hasNext()) + { + const SFuncInfo& funcInfo = linkFuncIter.getNext(); + + initDbFuncData(funcInfo, defineItem->text(6).toInt(), configItem); + } +} + +void MainWindow::initDbFuncData(const SFuncInfo& funcInfo, int locationId, QTreeWidgetItem* configItem) +{ + configItem->setText(1,QString::fromStdString(funcInfo.description)); + configItem->setText(4,CGetDBData::linkType(funcInfo.func_type)); + configItem->setText(6,m_ptrConfig->getLocationName(locationId)); + configItem->setText(7,CGetRdbData::timeToDT(funcInfo.timeflag)); + + SActionInfoIterator linkActionIter(m_dbContainer,funcInfo.action_name); + QTreeWidgetItem *actionItem = new QTreeWidgetItem(configItem); + initDbActionData(funcInfo, actionItem); + + while(linkActionIter.hasNext()) + { + const SActionInfo& actionInfo = linkActionIter.getNext(); + initDbActionData(actionInfo, actionItem); + } +} + +void MainWindow::initDbActionData(const SFuncInfo& funcInfo, QTreeWidgetItem* actionItem) +{ + actionItem->setText(2,CGetDBData::enableType(funcInfo.enable)); + actionItem->setText(3,QString("%1").arg(funcInfo.delaytime)); + actionItem->setText(4,CGetDBData::failStrageType(funcInfo.failstrage)); + actionItem->setText(5,QString("%1").arg(funcInfo.retrytimes)); +} + +void MainWindow::initDbActionData(const SActionInfo& actionInfo, QTreeWidgetItem* actionItem) +{ + actionItem->setText(0,QString::fromStdString(actionInfo.name)); + actionItem->setText(1,QString::fromStdString(actionInfo.description)); + actionItem->setText(6,m_ptrConfig->getLocationName(actionInfo.location_id)); + actionItem->setText(7,CGetRdbData::timeToDT(actionInfo.timeflag)); + actionItem->setText(8,QString("%1").arg(actionInfo.ctrl_timeout)); + actionItem->setText(9,CGetDBData::actionType(actionInfo.action_type)); +} + +QTreeWidgetItem* MainWindow::getLinkTreeWidgetItem(const CRecoverNode& linkRecover) +{ + QTreeWidgetItem *runLinkItem = new QTreeWidgetItem(); + + runLinkItem->setText(0,QString::fromStdString(linkRecover.nodeName())); + runLinkItem->setText(1,QString::fromStdString(linkRecover.description())); + runLinkItem->setCheckState(2,CGetRdbData::getCheckState(linkRecover.checkState())); + runLinkItem->setText(6,CGetRdbData::statusType(linkRecover.getState())); + runLinkItem->setText(7,CGetDBData::execType(linkRecover.exeType())); + runLinkItem->setText(8,CGetRdbData::timeToDT(linkRecover.triggerTime())); + runLinkItem->setText(9,CGetRdbData::timeToDT(linkRecover.startTime())); + runLinkItem->setText(10,m_ptrConfig->getLocationName(linkRecover.locationId())); + runLinkItem->setText(11,m_ptrConfig->getUserName(linkRecover.userId())); + runLinkItem->setText(12,m_ptrConfig->getUsergName(linkRecover.userGrounpId())); + runLinkItem->setText(13,QString::fromStdString(linkRecover.hostName())); + runLinkItem->setText(14,CGetRdbData::timeToDT(linkRecover.timeFlag())); + runLinkItem->setText(15,CGetDBData::linkType(linkRecover.linkType())); + runLinkItem->setText(16,CGetDBData::isSesExe(linkRecover.isSesExe())); + runLinkItem->setText(17,CGetRdbData::nodeType(linkRecover.nodeType())); + runLinkItem->setData(18,Qt::DisplayRole,linkRecover.funcNo()); + runLinkItem->setData(19,Qt::DisplayRole,linkRecover.actionNo()); + + switch(linkRecover.nodeType()) + { + case 0: + { + runLinkItem->setText(3,QString("%1").arg("")); + runLinkItem->setText(4,QString("%1").arg("")); + runLinkItem->setText(5,QString("%1").arg("")); + break; + } + case 1: + { + runLinkItem->setText(3,CGetDBData::relationType(linkRecover.relation())); + runLinkItem->setText(4,QString("%1").arg("")); + runLinkItem->setText(5,QString("%1").arg("")); + break; + } + case 2: + { + runLinkItem->setText(3,QString("%1").arg("")); + runLinkItem->setText(4,QString("%1").arg(linkRecover.delayTime())); + runLinkItem->setText(5,CGetDBData::failStrageType(linkRecover.failStrage())); + break; + } + default: + break; + } + + return runLinkItem; +} + +void MainWindow::initRunLinkData(CRecoverNodeContainer& container) +{ + CRecoverIterator linkIter(container); + + while (linkIter.hasNext()) + { + CRecoverNode& linkRecover = linkIter.getNext(); + updateButton((ELinkage_NodeState)linkRecover.getState(),(ELinkage_Isses)linkRecover.isSesExe()); + QTreeWidgetItem *runLinkItem = getLinkTreeWidgetItem(linkRecover); + ui->rdbTable->addTopLevelItem(runLinkItem); + initRunFuncData(linkRecover, runLinkItem); + runLinkItem->sortChildren(18,Qt::AscendingOrder); + } + ui->rdbTable->expandAll(); +} + +void MainWindow::initRunFuncData(CRecoverNode& linkRecover, QTreeWidgetItem* runLinkItem) +{ + CRecoverIterator funcIter(linkRecover); + + while(funcIter.hasNext()) + { + CRecoverNode& funcRecover = funcIter.getNext(); + QTreeWidgetItem *runFuncItem = getLinkTreeWidgetItem(funcRecover); + runLinkItem->addChild(runFuncItem); + initRunActionData(funcRecover, runFuncItem); + runFuncItem->sortChildren(19,Qt::AscendingOrder); + } +} + +void MainWindow::initRunActionData(CRecoverNode& funcRecover, QTreeWidgetItem* runFuncItem) +{ + CRecoverIterator actionIter(funcRecover); + + while(actionIter.hasNext()) + { + CRecoverNode& actionRecover = actionIter.getNext(); + QTreeWidgetItem *runActionItem = getLinkTreeWidgetItem(actionRecover); + runFuncItem->addChild(runActionItem); + } +} + +bool MainWindow::updateRunTab() +{ + CGetRdbDataLocker locker(*m_ptrRdbData); + + if(m_ptrRdbData->m_containerUpdate.isEmpty()) + { + return false; + } + + if(m_container.isEmpty()) + { + m_container = m_ptrRdbData->m_containerUpdate; + initRunLinkData(m_container); + } + else + { + updateRunLinkData(); + } + return true; +} + +void MainWindow::updateData(QTreeWidgetItem* item, CRecoverNode& linkRecoverUpdate) +{ + item->setText(6,CGetRdbData::statusType(linkRecoverUpdate.getState())); + item->setText(8,CGetRdbData::timeToDT(linkRecoverUpdate.triggerTime())); + item->setText(9,CGetRdbData::timeToDT(linkRecoverUpdate.startTime())); + item->setText(11,m_ptrConfig->getUserName(linkRecoverUpdate.userId())); + item->setText(12,m_ptrConfig->getUsergName(linkRecoverUpdate.userGrounpId())); + item->setText(13,QString::fromStdString(linkRecoverUpdate.hostName())); + item->setText(16,CGetDBData::isSesExe(linkRecoverUpdate.isSesExe())); +} + +void MainWindow::updateRunLinkData() +{ + CRecoverIterator linkIter(m_container); + CRecoverIterator linkIterUpdate(m_ptrRdbData->m_containerUpdate); + + while (linkIter.hasNext() && linkIterUpdate.hasNext()) + { + CRecoverNode& linkRecover = linkIter.getNext(); + CRecoverNode& linkRecoverUpdate = linkIterUpdate.getNext(); + + updateButton((ELinkage_NodeState)linkRecoverUpdate.getState(),(ELinkage_Isses)linkRecoverUpdate.isSesExe()); + if(linkRecover.getState() != linkRecoverUpdate.getState()) + { + QTreeWidgetItem *runLinkItem = ui->rdbTable->topLevelItem(0); + updateData(runLinkItem, linkRecoverUpdate); + isupdate = true; + } + updateRunFuncData(linkRecover, linkRecoverUpdate); + if((linkRecoverUpdate.getState() == 0) && isupdate) + { + resumeRunTab(); + isupdate = false; + } + } +} + +void MainWindow::updateRunFuncData(CRecoverNode& linkRecover, CRecoverNode& linkRecoverUpdate) +{ + CRecoverIterator funcIter(linkRecover); + CRecoverIterator funcIterUpdate(linkRecoverUpdate); + while(funcIter.hasNext() && funcIterUpdate.hasNext()) + { + CRecoverNode& funcRecover = funcIter.getNext(); + CRecoverNode& funcRecoverUpdate = funcIterUpdate.getNext(); + if(funcRecover.getState() != funcRecoverUpdate.getState()) + { + QTreeWidgetItem *runFuncItem = getItemByNo(funcRecoverUpdate.funcNo(), funcRecoverUpdate.actionNo()); + updateData(runFuncItem, funcRecoverUpdate); + } + updateRunActionData(funcRecover, funcRecoverUpdate); + } +} + +void MainWindow::updateRunActionData(CRecoverNode& funcRecover, CRecoverNode& funcRecoverUpdate) +{ + CRecoverIterator actionIter(funcRecover); + CRecoverIterator actionIterUpdate(funcRecoverUpdate); + + while(actionIter.hasNext() && actionIterUpdate.hasNext()) + { + CRecoverNode& actionRecover = actionIter.getNext(); + CRecoverNode& actionRecoverUpdate = actionIterUpdate.getNext(); + + if(actionRecover.getState() != actionRecoverUpdate.getState()) + { + QTreeWidgetItem *runActionItem = getItemByNo(actionRecoverUpdate.funcNo(), actionRecoverUpdate.actionNo()); + updateData(runActionItem, actionRecoverUpdate); + } + } +} + +void MainWindow::resumeRunTab() +{ + QTreeWidgetItemIterator it(ui->rdbTable); + SResumeRunData data; + while(*it) + { + (*it)->setText(6,data.status); + (*it)->setText(8,data.trigger_time); + (*it)->setText(9,data.start_time); + (*it)->setText(11,data.user_name); + (*it)->setText(12,data.userg_name); + (*it)->setText(13,data.host_name); + (*it)->setText(16,data.isses); + ++it; + } +} + +void MainWindow::updateButton(const ELinkage_NodeState& status,const ELinkage_Isses& isses) +{ + if(status == LINK_RUNNING_STATUS && isses == EnumNotSes){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(true); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(true); + ui->seqStartButton->setEnabled(false); + ui->seqContinueButton->setEnabled(false); + }else if(status == LINK_RUNNING_STATUS && isses == EnumSes){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(true); + ui->seqStartButton->setEnabled(false); + ui->seqContinueButton->setEnabled(false); + }else if(status == LINK_PAUSE_STATUS && isses == EnumNotSes){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(true); + ui->stopButton->setEnabled(true); + ui->seqStartButton->setEnabled(false); + ui->seqContinueButton->setEnabled(false); + }else if(status == LINK_PAUSE_STATUS && isses == EnumSes){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(true); + ui->seqStartButton->setEnabled(false); + ui->seqContinueButton->setEnabled(true); + }else if(status == LINK_RESTING_STATUS){ + ui->startButton->setEnabled(true); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(false); + ui->seqStartButton->setEnabled(true); + ui->seqContinueButton->setEnabled(false); + }else if(status == LINK_TRIGGERED_STATUS){ + ui->startButton->setEnabled(true); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(true); + ui->seqStartButton->setEnabled(true); + ui->seqContinueButton->setEnabled(false); + }else if(status == LINK_FAILED_STATUS + || status == LINK_SUCCESS_STATUS + ||status == LINK_STOP_STATUS + ||status == LINK_SKIP_STATUS){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(false); + ui->seqStartButton->setEnabled(false); + ui->seqContinueButton->setEnabled(false); + } +} + +void MainWindow::slot_updateStatus() +{ + RefreshExeStateThreadStatusLocker lock(*m_ptrState); + while(!m_ptrState->isEmpty()){ + QTreeWidgetItemIterator it(ui->dbTable); + while (*it) { + if((*it)->parent()) + ++it; + else{ + (*it)->setText(10,m_ptrState->getStatus((*it)->text(0))); + ++it; + } + } + m_ptrState->clear(); + } +} + +void MainWindow::slot_showMsg(const QString & msg) +{ + QListWidgetItem * item = new QListWidgetItem(); + item->setText(msg); + m_ptrShowMsgList->addItem(item); +} + +void MainWindow::slot_showUiMsg(const QString& msgStr, void* pData) +{ + using namespace iot_idl; + UiRequestMessage* msg + = (UiRequestMessage*)pData; + UiRequestMessageAck retMsg; + LcsPkgHead* head = new LcsPkgHead(msg->pkg_head()); + head->set_msg_type(enumUiRequestMessageAck); + head->set_source_tag(std::string("hmi")); + retMsg.set_allocated_pkg_head(head); + retMsg.set_allocated_nodelist( + new LinkNodeStatusParameter(msg->nodelist())); + + ActorParameter* actor + = new ActorParameter(); + actor->set_user_id(m_ptrConfig->getUserId(m_stUserInfo.user_name)); + actor->set_user_groupid(m_ptrConfig->getUsergId(m_stUserInfo.userg_Name)); + actor->set_host_name(m_stUserInfo.host_name.toStdString()); + actor->set_user_name(m_stUserInfo.user_name.toStdString()); + retMsg.set_allocated_actor(actor); + + slot_showMsg(msgStr); + + if (!m_objMsgBox.isHidden()) + { + return; + } + + QMessageBox& messageBox = m_objMsgBox; + + messageBox.setText(msgStr); + + messageBox.exec(); + + if (messageBox.clickedButton() == m_btnRetry) + { + retMsg.set_optype(enumUI_OP_RETRY); + } + else if (messageBox.clickedButton() == m_btnStop) + { + retMsg.set_optype(enumUI_OP_STOP); + } + else if (messageBox.clickedButton() == m_btnSkip) + { + retMsg.set_optype(enumUI_OP_SKIP); + } + else + { + delete msg; + msg = NULL; + return; + } + + m_ptrInterface->userInterveneResponse(retMsg); + + delete msg; + msg = NULL; +} + +SSetReqMsg MainWindow::getReqMsgObj() +{ + SSetReqMsg m_stReqMsg; + + QTreeWidgetItemIterator it(ui->rdbTable); + while(*it) + { + m_stReqMsg.mapCheck.insert(std::make_pair((*it)->text(0).toStdString(), (*it)->checkState(2))); + ++it; + } + + m_stReqMsg.container = &m_container; + m_stReqMsg.userinfo = &m_stUserInfo; + m_stReqMsg.source_domainId = m_ptrConfig->getDomainId(m_stUserInfo.domain_name); + m_stReqMsg.target_domainId = m_ptrConfig + ->getDomainIdByLocationId(m_ptrConfig->getLocationIdByLinkName(QString::fromStdString(m_strLinkName))); + m_stReqMsg.userId = m_ptrConfig->getUserId(m_stUserInfo.user_name); + m_stReqMsg.usergId = m_ptrConfig->getUsergId(m_stUserInfo.userg_Name); + + return m_stReqMsg; +} + +void MainWindow::slot_startLink() +{ + try + { + SSetReqMsg stMsg = getReqMsgObj(); + CSetReqMsgInfo info(stMsg); + LinkOperateMessage msg; + info.setMsgInfo(msg, + enumLinkOperateMessage, + enumOP_LINK_START); + m_ptrInterface->linkOperateRequest(msg); + } + catch (const std::exception& e) + { + e.what(); + } +} + +void MainWindow::slot_stopLink() +{ + SSetReqMsg stMsg = getReqMsgObj(); + CSetReqMsgInfo info(stMsg); + LinkOperateMessage msg; + info.setMsgInfo(msg, + enumLinkOperateMessage, + enumOP_LINK_STOP); + m_ptrInterface->linkOperateRequest(msg); +} + +void MainWindow::slot_continueLink() +{ + SSetReqMsg stMsg = getReqMsgObj(); + CSetReqMsgInfo info(stMsg); + LinkOperateMessage msg; + info.setMsgInfo(msg, + enumLinkOperateMessage, + enumOP_LINK_CONTINUE); + m_ptrInterface->linkOperateRequest(msg); +} + +void MainWindow::slot_pauseLink() +{ + SSetReqMsg stMsg = getReqMsgObj(); + CSetReqMsgInfo info(stMsg); + LinkOperateMessage msg; + info.setMsgInfo(msg, + enumLinkOperateMessage, + enumOP_LINK_PAUSE); + m_ptrInterface->linkOperateRequest(msg); +} + +void MainWindow::slot_sesStartLink() +{ + try + { + SSetReqMsg stMsg = getReqMsgObj(); + CSetReqMsgInfo info(stMsg); + LinkOperateMessage msg; + info.setMsgInfo(msg, + enumLinkOperateMessage, + enumOP_SES_START); + m_ptrInterface->linkOperateRequest(msg); + } + catch (const std::exception& e) + { + e.what(); + } +} + +void MainWindow::slot_sesContinue() +{ + SSetReqMsg stMsg = getReqMsgObj(); + CSetReqMsgInfo info(stMsg); + LinkOperateMessage msg; + info.setMsgInfo(msg, + enumLinkOperateMessage, + enumOP_SES_CONTINUE); + m_ptrInterface->linkOperateRequest(msg); +} + +void MainWindow::slot_configUserInfo() +{ + if (!m_ptrConfig) + { + return; + } + + m_ptrConfig->exec(); + + m_stUserInfo = m_ptrConfig->getConfigurInfo(); +} + +void MainWindow::slot_search() +{ + RunTabTimer->stop(); + m_strLinkName = ""; + m_container.clearData(); + QString key = ui->lineEdit->text(); + QRegExp re("\\S*"+key+"\\S*"); + ui->dbTable->clear(); + ui->rdbTable->clear(); + + SLinkDefineInfoIterator linkDefineIter(m_dbContainer); + + while(linkDefineIter.hasNext()) + { + const SLinkDefineInfo& defineInfo = linkDefineIter.getNext(); + if(re.exactMatch(QString::fromStdString(defineInfo.name))) + { + initDbDefineData(defineInfo); + } + } +} + +void MainWindow::slot_itemClicked(QTreeWidgetItem *item, int column) +{ + Q_UNUSED(column); + + while(item->parent()) + { + item = item->parent(); + } + std::string linkName = (item->text(0)).toStdString(); + if(linkName != m_strLinkName) + { + m_strLinkName = linkName; + int domainId = m_ptrConfig + ->getDomainIdByLocationId(m_ptrConfig->getLocationIdByLinkName(QString::fromStdString(m_strLinkName))); + ui->rdbTable->clear(); + initButton(); + m_container.clearData(); + + m_ptrRdbData->start(m_strLinkName, domainId); + RunTabTimer->start(200); + } +} + +void MainWindow::slot_itemCheckChange(QTreeWidgetItem *item, int column) +{ + if(!(column == 2)) + return; + + for(int i = 0;ichildCount();++i) + { + item->child(i)->setCheckState(column,item->checkState(column)); + if(item->child(i)->childCount() != 0) + for(int j = 0;jchild(i)->childCount();++j) + { + item->child(i)->child(j)->setCheckState(column,item->checkState(column)); + } + } + + QTreeWidgetItem *parent = item->parent(); + if(parent != 0) + { + parent->setCheckState(column,item->checkState(column)); + if(parent->parent() != 0) + parent->parent()->setCheckState(column,item->checkState(column)); + + for(int j = 0;jchildCount();++j) + { + if(parent->checkState(column) != parent->child(j)->checkState(column)) + parent->setCheckState(column,Qt::PartiallyChecked); + } + + if(parent->parent() != 0) + { + for(int j = 0; jparent()->childCount(); ++j) + { + if(parent->parent()->checkState(column) != parent->parent()->child(j)->checkState(column)) + parent->parent()->setCheckState(column, Qt::PartiallyChecked); + } + } + } +} + +void MainWindow::slot_updateRunTab() +{ + updateRunTab(); +} + +void MainWindow::slot_refreshChanged(int arg1) +{ + if(refreshBuf.isEmpty()) + { + return; + } + + if(arg1 == 2) + { + for(int i = 0;i < refreshBuf.size();++i){ + QMetaObject::invokeMethod(this, "slot_showMsg", + Qt::QueuedConnection, Q_ARG(QString, refreshBuf.at(i))); + } + refreshBuf.clear(); + } +} + +void MainWindow::initUserInfo() +{ + if (!m_ptrConfig) + { + return; + } + m_stUserInfo = m_ptrConfig->getConfigurInfo(); +} + +QTreeWidgetItem* MainWindow::getItemByNo(int funcNo, int actionNo) +{ + QTreeWidgetItemIterator it(ui->rdbTable); + while(*it) + { + if((*it)->text(18).toInt() == funcNo + && (*it)->text(19).toInt()== actionNo) + { + return *it; + } + ++it; + } + return NULL; +} diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.h b/product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.h new file mode 100644 index 00000000..0c1ffcb7 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.h @@ -0,0 +1,116 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "CLinkageForHmiApiInterface.h" +#include "predifineforlinkageserver.h" +#include "CGetDBData.h" +#include "CGetRdbData.h" +#include "ConfigureDialog.h" +#include "CSetReqMsgInfo.h" +#include "RefreshExeStateThread.h" +#include "CLinkageDbContainer.h" +#include +#include +#include "pub_widget/CustomMainWindow.h" + +namespace Ui { + class MainWindow; +} + +class QAbstractButton; +class QListWidget; +class QListWidgetItem; +class QTreeWidget; +class QTreeWidgetItem; +using namespace iot_idl::linkage; + +class MainWindow : public CustomUiMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + void quit(); + + void showMsg(const QString& msg); + + void showUiMsg(const QString& msgStr, + UiRequestMessage& msg);//人工干预 + +private slots: + void slot_showMsg(const QString& msg); + void slot_showUiMsg(const QString& msg, void* pData);//人工干预 + void slot_startLink(); + void slot_stopLink(); + void slot_continueLink(); + void slot_pauseLink(); + void slot_sesStartLink(); + void slot_sesContinue(); + void slot_configUserInfo(); //配置初始信息 + void slot_search(); + void slot_itemClicked(QTreeWidgetItem *item, int column); + void slot_itemCheckChange(QTreeWidgetItem *item, int column); //勾选 + void slot_updateRunTab(); + void slot_updateStatus(); + void slot_refreshChanged(int arg1); //是否刷新 + +private: + bool initDbTab(); + void initRunTab(); + void initButton(); + void initUserInfo(); + + void initDbTabData(); + void initDbDefineData(const SLinkDefineInfo &defineInfo); + void initDbConfigData(const SLinkConfigInfo &configInfo, QTreeWidgetItem *configItem); + void initDbFuncData(const SFuncInfo &funcInfo, int locationId, QTreeWidgetItem *configItem); + void initDbActionData(const SFuncInfo &funcInfo, QTreeWidgetItem *actionItem); + void initDbActionData(const SActionInfo &actionInfo, QTreeWidgetItem *actionItem); + + bool updateRunTab(); + void initRunLinkData(CRecoverNodeContainer& container); + void initRunFuncData(CRecoverNode &linkRecover, QTreeWidgetItem *runLinkItem); + void initRunActionData(CRecoverNode &funcRecover, QTreeWidgetItem *runFuncItem); + QTreeWidgetItem *getLinkTreeWidgetItem(const CRecoverNode &linkRecover); + void updateRunLinkData(); + void updateRunFuncData(CRecoverNode &linkRecover, CRecoverNode &linkRecoverUpdate); + void updateRunActionData(CRecoverNode &funcRecover, CRecoverNode &funcRecoverUpdate); + void updateData(QTreeWidgetItem *item, CRecoverNode& linkRecoverUpdate); + void resumeRunTab(); + void updateButton(const ELinkage_NodeState& status,const ELinkage_Isses& isses); + + QList getDomainId(); + SSetReqMsg getReqMsgObj(); + QTreeWidgetItem *getItemByNo(int funcNo, int actionNo); + +private: + Ui::MainWindow *ui; + CLinkageForHmiApiInterface * m_ptrInterface; + CGetDBData * m_ptrDbData; + CGetRdbData * m_ptrRdbData; + RefreshExeStateThread * m_ptrState; + ConfigureDialog * m_ptrConfig; + CRecoverNodeContainer m_container; + CLinkageDbContainer m_dbContainer; + + QListWidget* m_ptrShowMsgList; + QMessageBox m_objMsgBox; + QAbstractButton * m_btnRetry; + QAbstractButton * m_btnStop; + QAbstractButton * m_btnSkip; + + iot_dbms::CDbApi m_objLocalDbConn; + + QStringList refreshBuf; + QTimer *RunTabTimer; + QTimer *exeStatusTimer; + bool isupdate = false; + SUserInfo m_stUserInfo; + std::string m_strLinkName; + +}; + +#endif // MAINWINDOW_H diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.ui b/product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.ui new file mode 100644 index 00000000..8433d9e4 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/mainwindow.ui @@ -0,0 +1,413 @@ + + + MainWindow + + + + 0 + 0 + 771 + 643 + + + + Qt::NoFocus + + + MainWindow + + + + + + + + + + 搜索 + + + + + + + + 0 + 0 + + + + + 1 + + + + + + + + + 0 + 0 + + + + false + + + + 1 + + + + + + + + + + 开始联动 + + + + + + + false + + + 暂停联动 + + + + + + + false + + + 继续联动 + + + + + + + false + + + 停止联动 + + + + + + + 单步开始 + + + + + + + false + + + 单步执行 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + + 清空 + + + + + + + 刷新 + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + 0 + 0 + 771 + 25 + + + + + 配置 + + + + + + + + 初始化全部 + + + + + 保存修改 + + + Ctrl+S + + + + + 初始信息 + + + + + + + pushButton_5 + clicked() + listWidget + clear() + + + 760 + 467 + + + 249 + 608 + + + + + startButton + clicked() + MainWindow + slot_startLink() + + + 760 + 238 + + + 316 + 301 + + + + + pauseButton + clicked() + MainWindow + slot_pauseLink() + + + 760 + 272 + + + 344 + 423 + + + + + stopButton + clicked() + MainWindow + slot_stopLink() + + + 760 + 340 + + + 405 + 325 + + + + + continueButton + clicked() + MainWindow + slot_continueLink() + + + 760 + 306 + + + 439 + 424 + + + + + seqStartButton + clicked() + MainWindow + slot_sesStartLink() + + + 760 + 374 + + + 516 + 324 + + + + + seqContinueButton + clicked() + MainWindow + slot_sesContinue() + + + 760 + 408 + + + 545 + 426 + + + + + dbTable + itemClicked(QTreeWidgetItem*,int) + MainWindow + slot_itemClicked(QTreeWidgetItem*,int) + + + 639 + 181 + + + 673 + 164 + + + + + rdbTable + itemClicked(QTreeWidgetItem*,int) + MainWindow + slot_itemCheckChange(QTreeWidgetItem*,int) + + + 673 + 432 + + + 767 + 446 + + + + + pushButton_7 + clicked() + MainWindow + slot_search() + + + 745 + 42 + + + 766 + 39 + + + + + checkBox + stateChanged(int) + MainWindow + slot_refreshChanged(int) + + + 721 + 502 + + + 720 + 527 + + + + + + slot_startLink() + slot_stopLink() + slot_continueLink() + slot_pauseLink() + slot_sesStartLink() + slot_sesContinue() + slot_editUserInfo(QTreeWidgetItem*,int) + slot_editSave() + slot_initUserInfo() + slot_currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) + slot_itemClicked(QTreeWidgetItem*,int) + slot_itemCheckChange(QTreeWidgetItem*,int) + slot_search() + slot_refreshChanged(int) + + diff --git a/product/src/tools/link_seq_tool/linkage_server_tool/predifineforlinkageserver.h b/product/src/tools/link_seq_tool/linkage_server_tool/predifineforlinkageserver.h new file mode 100644 index 00000000..257dc787 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_server_tool/predifineforlinkageserver.h @@ -0,0 +1,193 @@ +#pragma once +/*! + * @breif 联动的定义 + * + * @author sjq + * @date 五月 2018 + */ + +#include +#include +#include "common/DataType.h" + +static const std::string LINKAGE_PROCESSNAME = "linkage_server"; + +//配置文件 +static const std::string CONFING_IS_CREATE_ALARM = "isGenAlarmToOpt"; +static const std::string CONFING_UI_TIMER_TO_SEND_SECONDS = "UiTimerToSendSeconds"; +static const std::string CONFING_TRIGGER_LINK_TIMER_TO_SEND_SECONDS = "TriggerLinkTimerToSendSeconds"; + +//动作解析串头 +static const std::string ACTION_TYPE_DO_CTRL = "do_ctrl"; +static const std::string ACTION_TYPE_AO_CTRL = "ao_ctrl"; +static const std::string ACTION_TYPE_PA_CTRL = "pa_ctrl"; +static const std::string ACTION_TYPE_CCTV_CTRL = "cctv_ctrl"; +static const std::string ACTION_TYPE_PIS_CTRL = "pis_ctrl"; +static const std::string ACTION_TYPE_PUSH_CTRL = "push_ctrl"; +static const std::string ACTION_TYPE_HINT_CTRL = "hint_ctrl"; + +//配置用户信息 +struct SUserInfo +{ + QString user_name; + QString userg_Name; + QString host_name; + QString domain_name; + QString location_name; +}; + +//运行表恢复为未执行状态 +struct SResumeRunData +{ + QString status; + QString trigger_time; + QString start_time; + QString user_name; + QString userg_name; + QString host_name; + QString isses; + + SResumeRunData() + { + status = "未执行"; + trigger_time = "0"; + start_time = "0"; + user_name = " "; + userg_name = " "; + host_name = " "; + isses = "不是"; + }; +}; + +//是否单步执行 +enum ELinkage_Isses +{ + EnumNotSes = 0, //不是单步 + EnumSes = 1 //单步 +}; + +//联动操作类型 +enum ELinkage_HmiOpType +{ + OP_LINK_START = 0,//联动开始 + OP_LINK_STOP = 1,//联动终止 + OP_LINK_PAUSE = 2,//暂停 + OP_LINK_CONTINUE = 3,//继续 + OP_SES_START = 4,//单步开始 + OP_SES_CONTINUE = 5,//单步继续 +}; + +//联动执行状态 +enum ELinkage_NodeState +{ + LINK_RESTING_STATUS = 0, /*未执行 */ + LINK_RUNNING_STATUS = 1,/* 正在执行 */ + LINK_TRIGGERED_STATUS = 2,/* 已触发 */ + LINK_FAILED_STATUS = 3,/* 执行失败 */ + LINK_SUCCESS_STATUS = 4,/* 执行成功 */ + LINK_STOP_STATUS = 5,/* 执行终止 */ + LINK_PAUSE_STATUS = 6,/* 执行暂停 */ + LINK_SKIP_STATUS = 7,/* 执行跳过 */ +}; + +enum ELinkage_FailedActionType +{ + //联动动作失败处理 + LINK_ACT_FAILED_CONTINUE = 0,/* 跳过失败动作 */ + LINK_ACT_FAILED_HMI_CONTROL = 1,/* 人工干预 */ + LINK_ACT_FAILED_EXIT = 2,/* 终止 */ + LINK_ACT_FAILED_AUTO_RETRY = 3,/* 自动重做 */ +}; + +//人工干预执行 操作 结果 +enum UI_OP_RESULT_TYPE +{ + UI_TYPE_INIT = 0,//初始化状态 + UI_TYPE_RETYR = 1,//重试 + UI_TYPE_STOP = 2,//终止 + UI_TYPE_SKIP = 3,//跳过 +}; + +//OPT 执行的操作结果 +enum OPT_RESPONSE_TYPE +{ + OPT_RESPONSE_TYPE_INIT,//还未返回 + OPT_RESPONSE_TYPE_FAILED,//执行失败 + OPT_RESPONSE_TYPE_SUCCESS,//执行成功 +}; + +//动作类型 +enum ENLcsActionType +{ + enumLcs_Action_DO, + enumLcs_Action_AO, + enumLcs_Action_PA, + enumLcs_Action_CCTV, + enumLcs_Action_PIS, + enumLcs_Action_PUSH, + enumLcs_Action_HINT, +}; + +// 联动执行者 +struct SNodeLinkActor +{ + int user_id; + int user_grounp_id; + std::string user_name; + std::string host_name; +}; + + + +//opt 操作结果 +struct SOptResult +{ + std::string keyTag; + OPT_RESPONSE_TYPE resultCode; + std::string resultDesc; +}; + +//动作执行错误信息 +struct SActionErrorInfo +{ + int nCode; + std::string erroStr; + SActionErrorInfo() {}; + SActionErrorInfo(int code, const std::string& str) + :nCode(code), erroStr(str) + { + }; +}; + + +//hmi 操作 信息 +struct SHmiOpInfo +{ + ELinkage_HmiOpType eResult; + SNodeLinkActor actor; +}; + + +/*! +* @brief 人工干预操作 +*/ + +struct SOpResultUi +{ + UI_OP_RESULT_TYPE eResult; + SNodeLinkActor actor; +}; + + +/*! @brief 人工干预应答信息*/ +struct SUiResultInfo +{ + std::string linkName; + std::string funcName; + std::string actionName; + uint64 linkTimeFlag; + uint64 funcTimeFlag; + uint64 actionTimeFlag; + SOpResultUi result; +}; + diff --git a/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/clinkageforhmiapiimpl.cpp b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/clinkageforhmiapiimpl.cpp new file mode 100644 index 00000000..09e34392 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/clinkageforhmiapiimpl.cpp @@ -0,0 +1,157 @@ +#include "public/pub_logger_api/logger.h" +#include "MessageChannel.h" +#include "Common.h" + +#include "clinkageforhmiapiimpl.h" + + +using namespace iot_idl::linkage; +class MainWindow; + +CLinkageForHmiApiImpl::CLinkageForHmiApiImpl( + int appid, + MainWindow* mainwindow) : + m_nServerAppId(appid), + CTimerThreadBase("CLinkageForHmiApiImpl thread", 500), + m_ptrInterface(mainwindow) +{ +} + +CLinkageForHmiApiImpl::~CLinkageForHmiApiImpl() +{ + this->quit(); +} + +bool CLinkageForHmiApiImpl::start() +{ + this->resume(); + return true; +} + +bool CLinkageForHmiApiImpl::stop() +{ + this->suspend(); + return true; +} + +void CLinkageForHmiApiImpl::afterResume() +{ + LOGINFO("订阅联动服务通道 appid[%d] channel[%d]", + m_nServerAppId, + CH_LINK_TO_HMI_CTRL_UP); + + m_objRecvLinkCMb.addSub( + m_nServerAppId, + CH_LINK_TO_HMI_CTRL_UP); +} + +void CLinkageForHmiApiImpl::afterSuspend() +{ + m_objRecvLinkCMb.delSub( + m_nServerAppId, + CH_LINK_TO_HMI_CTRL_UP); + + LOGINFO("取消订阅联动服务通道 appid[%d] channel[%d]", + m_nServerAppId, + CH_LINK_TO_HMI_CTRL_UP); +} +void CLinkageForHmiApiImpl::execute() +{ + using namespace iot_idl; + if (!m_objRecvLinkCMb.recvMsg(m_objRecvMsg)) + { + return; + } + + recvMsgLink(m_objRecvMsg); +} + +bool CLinkageForHmiApiImpl::handleLinkActionToHmiMessage(ActionToHmiMessage &msg) +{ + QString msgStr; + std::string pushname; + std::string hintinf; + + + const std::string& hostname = msg.host_name(); + + if (msg.has_push_param()) + { + const PushParameter& push = msg.push_param(); + pushname = push.graph_name(); + + msgStr = QString("主机名:%1,推图:%2") + .arg(QString::fromStdString(hostname)) + .arg(QString::fromStdString(pushname)); + + } + + if (msg.has_hint_param()) + { + const HintParameter& hint = msg.hint_param(); + hintinf = hint.hint_info(); + + msgStr = QString("主机名:%1,提示信息:%2") + .arg(QString::fromStdString(hostname)) + .arg(QString::fromStdString(hintinf)); + } + + m_ptrInterface->showMsg(msgStr); + return true; + +} + +bool CLinkageForHmiApiImpl::recvMsgLink( + iot_net::CMbMessage& msg) +{ + try { + using namespace iot_idl; + + if (msg.getMsgType() != MT_LINKAGE_ACTION_UP) + { + LOGERROR("在MT_LINKAGE_ACTION_UP这个通道中收到 其他类型的消息:[%d]", + msg.getMsgType()); + return false; + } + + LOGINFO("recvMsgLink msgType[%d]", + msg.getMsgType()); + + int msgType = msg.getPara1(); + switch (msgType) + { + case enumActionToHmiMessage: + { + ActionToHmiMessage dataMsg; + if (!dataMsg.ParseFromArray(msg.getDataPtr(), + msg.getDataSize())) + { + BOOST_ASSERT(false); + return false; + } + return handleLinkActionToHmiMessage(dataMsg); + } + break; + default: + BOOST_ASSERT(false); + break; + } + } + catch (std::exception &ex) + { + LOGERROR(ex.what()); + return false; + } + + return false; +} + + + + + + + + + + diff --git a/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/clinkageforhmiapiimpl.h b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/clinkageforhmiapiimpl.h new file mode 100644 index 00000000..98f5468b --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/clinkageforhmiapiimpl.h @@ -0,0 +1,46 @@ +#ifndef CLINKAGEFORHMIAPIIMPL_H +#define CLINKAGEFORHMIAPIIMPL_H + + +#include +#include "pub_utility_api/TimerThreadBase.h" +#include "net/net_msg_bus_api/CMbCommunicator.h" +#include "LinkageMessage.pb.h" +#include "mainwindow.h" + +using namespace iot_idl::linkage; +class MainWindow; +class CLinkageForHmiApiImpl + : public iot_public::CTimerThreadBase +{ +public: + CLinkageForHmiApiImpl(int appid, MainWindow* mainwindow); + ~CLinkageForHmiApiImpl(); + + //开启线程 + bool start(); + + //停止线程 + bool stop(); + +protected: + void afterSuspend(); + void afterResume(); + void execute(); +private: + + bool handleLinkActionToHmiMessage( + ActionToHmiMessage& msg); + + bool recvMsgLink(iot_net::CMbMessage& msg); +private: + MainWindow* m_ptrInterface; + iot_net::CMbMessage m_objRecvMsg; + + iot_net::CMbCommunicator m_objSendLinkCMb;//发送 linkage + iot_net::CMbCommunicator m_objRecvLinkCMb;//接收 linkage + + const int m_nServerAppId; +}; + +#endif // CLINKAGEFORHMIAPIIMPL_H diff --git a/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/linkage_tuihuamian_tool.pro b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/linkage_tuihuamian_tool.pro new file mode 100644 index 00000000..d7b438c7 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/linkage_tuihuamian_tool.pro @@ -0,0 +1,63 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-08-29T16:29:21 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = linkage_msg_monitor +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + clinkageforhmiapiimpl.cpp + +HEADERS += \ + mainwindow.h \ + ../../../idl_files/LinkageMessage.pb.h \ + clinkageforhmiapiimpl.h + +FORMS += \ + mainwindow.ui + +LIBS += -lpub_widget + + +DISTFILES += \ + ../../../idl_files/LinkageMessage.proto + + +LIBS += -llog4cplus \ + -lpub_logger_api \ + -lboost_system \ + -lboost_thread \ + -lboost_date_time \ + -lnet_msg_bus_api \ + -lprotobuf \ + -lpub_utility_api \ + -lpub_sysinfo_api + +include($$PWD/../../../idl_files/idl_files.pri) + +COMMON_PRI=$$PWD/../../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} diff --git a/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/main.cpp b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/main.cpp new file mode 100644 index 00000000..7de5e038 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/main.cpp @@ -0,0 +1,63 @@ +#include "mainwindow.h" +#include +#include +#include "pub_logger_api/logger.h" +#include "net/net_msg_bus_api/MsgBusApi.h" +#include "pub_utility_api/FileStyle.h" +#include + +void loadStyle() +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss","zh","light"); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("linkage_msg_monitor.qss","zh","light"); + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + qApp->setStyleSheet(qss); + } +} + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + loadStyle(); + + iot_public::StartLogSystem("comapp", "hmi-test"); + + int nRet = iot_net::initMsgBus( + std::string("hmi").c_str(), + std::string("hmiInstance").c_str()); + if (false == nRet) { + return 0; + } + + { + MainWindow w; + w.show(); + + nRet = a.exec(); + w.quit(); + } + + iot_net::releaseMsgBus(); + iot_public::StopLogSystem(); + + return nRet; +} diff --git a/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.cpp b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.cpp new file mode 100644 index 00000000..b1408b79 --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.cpp @@ -0,0 +1,54 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "public/pub_logger_api/logger.h" +#include + +class CLinkageForHmiApiImpl; +MainWindow::MainWindow(QWidget *parent) : + CustomUiMainWindow(parent), + ui(new Ui::MainWindow) +{ + setAutoLayout(true); + setWindowTitle(tr("联动消息监控工具")); + + ui->setupUi(this); + m_ptrInterface = new CLinkageForHmiApiImpl(0,this); + m_ptrInterface->start(); + + ui->mainToolBar->hide(); + ui->menuBar->hide(); +} + +MainWindow::~MainWindow() +{ + if (m_ptrInterface) + { + delete m_ptrInterface; + m_ptrInterface = NULL; + } + delete ui; +} + +void MainWindow::quit() +{ + if (m_ptrInterface) + { + m_ptrInterface->stop(); + delete m_ptrInterface; + m_ptrInterface = NULL; + } +} + +void MainWindow::showMsg(const QString & msg) +{ + qDebug()<setText(msg); + ui->listWidget->addItem(item); +} diff --git a/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.h b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.h new file mode 100644 index 00000000..06ea8dfb --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.h @@ -0,0 +1,33 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "clinkageforhmiapiimpl.h" +#include "MessageChannel.h" +#include "pub_widget/CustomMainWindow.h" + +namespace Ui { +class MainWindow; +} + +class CLinkageForHmiApiImpl; +class MainWindow : public CustomUiMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + void quit(); + + void showMsg(const QString &msg); + private slots: + void slot_showMsg(const QString &msg); + +private: + Ui::MainWindow *ui; + CLinkageForHmiApiImpl *m_ptrInterface; +}; + +#endif // MAINWINDOW_H diff --git a/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.ui b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.ui new file mode 100644 index 00000000..6936f8bd --- /dev/null +++ b/product/src/tools/link_seq_tool/linkage_tuihuamian_tool/mainwindow.ui @@ -0,0 +1,46 @@ + + + MainWindow + + + + 0 + 0 + 514 + 339 + + + + MainWindow + + + + + + + + + + + + 0 + 0 + 514 + 23 + + + + + + TopToolBarArea + + + false + + + + + + + + diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.cpp new file mode 100644 index 00000000..a5699567 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.cpp @@ -0,0 +1,382 @@ +#include "CConfigureDialog.h" +#include "ui_CConfigureDialog.h" +#include + +CConfigureDialog::CConfigureDialog(QWidget *parent): + CustomUiDialog(parent), + ui(new Ui::CConfigureDialog), + m_objLocalDbConn(DB_CONN_MODEL_READ) +{ + setWindowTitle(tr("配置")); + + m_objDbCtrl = new CSqlDbCtrl(); + m_settings = new QSettings("../../data/link_seq_test_cache/SeqTestUserInfo.ini", QSettings::IniFormat); + m_settings->setIniCodec("UTF-8"); + m_settings->beginGroup("UserInfo"); + ui->setupUi(this); + + ui->treeWidget->setColumnCount(2); + ui->treeWidget->setHeaderLabels(QStringList()<<"参数"<<"值"); + m_objUserInfo = new QTreeWidgetItem(ui->treeWidget); + m_objUserName = new QTreeWidgetItem(m_objUserInfo); + m_objHostName = new QTreeWidgetItem(m_objUserInfo); + m_objLocationName = new QTreeWidgetItem(m_objUserInfo); + m_objUsergName = new QTreeWidgetItem(m_objUserInfo); + m_objDomainName = new QTreeWidgetItem(m_objUserInfo); + m_objDomainName->setDisabled(true); + m_objUsergName->setDisabled(true); + m_objUserInfo->setText(0,"用户信息"); + m_objUserName->setText(0,"用户名"); + m_objUsergName->setText(0,"用户组名"); + m_objHostName->setText(0,"主机名"); + m_objLocationName->setText(0,"车站"); + m_objDomainName->setText(0,"域"); + + initUserInfo(); + + m_subMap = m_objDbCtrl->readSubInfo(); + m_seqLocationMap = m_objDbCtrl->readSeqLocation(); + m_locationDomainIdMap = m_objDbCtrl->readLocationDomainId(); + m_userMap = m_objDbCtrl->readUserInfo(); + m_usergMap = m_objDbCtrl->readUsergInfo(); + m_locationMap = m_objDbCtrl->readLocationInfo(); + m_domainMap = m_objDbCtrl->readDomainInfo(); + m_hostList = m_objDbCtrl->hostNameList(); + + m_objDbParaItem = new QTreeWidgetItem(ui->treeWidget); + m_objDbParaItem->setDisabled(true); + m_objDbParaItem->setText(0,"数据库信息"); + + QHeaderView *head = ui->treeWidget->header(); + head->setSectionResizeMode(QHeaderView::ResizeToContents); + ui->treeWidget->expandAll(); + + setAutoLayout(true); +} + +CConfigureDialog::~CConfigureDialog() +{ + delete ui; + if(m_objDbCtrl) + { + if(m_objDbCtrl->isOpen()) + { + m_objDbCtrl->closeDb(); + } + delete m_objDbCtrl; + m_objDbCtrl = NULL; + } + if(m_settings) + { + delete m_settings; + m_settings = NULL; + } +} + +SUserInfo& CConfigureDialog::getConfigurInfo() +{ + return m_stUserInfo; +} + + +void CConfigureDialog::preChange(QTreeWidgetItem *item) +{ + if(ui->treeWidget->itemWidget(item,1)){ + QComboBox *box = (QComboBox*)ui->treeWidget->itemWidget(item,1); + item->setText(1,box->currentText()); + ui->treeWidget->closePersistentEditor(item,1); + if(ui->treeWidget->topLevelItem(0)->indexOfChild(item) == 2){ + QString locationName = ui->treeWidget->topLevelItem(0)->child(2)->text(1); + int domainId = getDomainIdByLocationId(getLocationId(locationName)); + QString domainName = getDomainName(domainId); + ui->treeWidget->topLevelItem(0)->child(4)->setText(1,domainName); + } + if(ui->treeWidget->topLevelItem(0)->indexOfChild(item) == 0) + { + QString userName = ui->treeWidget->topLevelItem(0)->child(0)->text(1); + int usergId = getUserId(userName); + QString usergName = getUsergName(usergId); + ui->treeWidget->topLevelItem(0)->child(3)->setText(1,usergName); + } + } +} + +void CConfigureDialog::setSUserInfo() +{ + m_stUserInfo.user_name = m_objUserName->text(1); + m_stUserInfo.userg_Name = m_objUsergName->text(1); + m_stUserInfo.host_name = m_objHostName->text(1); + m_stUserInfo.location_name = m_objLocationName->text(1); + m_stUserInfo.domain_name = m_objDomainName->text(1); +} + +void CConfigureDialog::slot_editSave() +{ + preChange(m_objItem); + m_settings->setValue("user_name",QVariant(m_objUserName->text(1))); + m_settings->setValue("userg_name",QVariant(m_objUsergName->text(1))); + m_settings->setValue("host_name",QVariant(m_objHostName->text(1))); + m_settings->setValue("location_name",QVariant(m_objLocationName->text(1))); + m_settings->setValue("domain_name",QVariant(m_objDomainName->text(1))); + setSUserInfo(); +} + +void CConfigureDialog::slot_initUserInfo() +{ + m_objUserName->setText(1,"1"); + m_objUsergName->setText(1,"系统管理员"); + m_objHostName->setText(1,"kbd-rd-shj"); + m_objLocationName->setText(1,"东孚站"); + m_objDomainName->setText(1,"东孚站域"); + + m_settings->setValue("user_name",QVariant(m_objUserName->text(1))); + m_settings->setValue("userg_name",QVariant(m_objUsergName->text(1))); + m_settings->setValue("host_name",QVariant(m_objHostName->text(1))); + m_settings->setValue("location_name",QVariant(m_objLocationName->text(1))); + m_settings->setValue("domain_name",QVariant(m_objDomainName->text(1))); + + setSUserInfo(); +} + +void CConfigureDialog::slot_editUserInfo(QTreeWidgetItem *item, int column) +{ + if(item->parent() == ui->treeWidget->topLevelItem(0) && item != ui->treeWidget->topLevelItem(0)->child(4) && column == 1){ + m_objItem = item; + ui->treeWidget->openPersistentEditor(item,column); + QComboBox *box = new QComboBox(this); + switch (ui->treeWidget->topLevelItem(0)->indexOfChild(item)) { + case 0: + { + QMap::iterator iter = m_userMap.begin(); + for(;iter != m_userMap.end();++iter) + { + box->insertItem(iter.value(), iter.key()); + } + break; + } + case 1: + { + box->addItems(m_hostList); + break; + } + case 2: + { + QMap::iterator iter = m_locationMap.begin(); + for(;iter != m_locationMap.end();++iter) + { + box->insertItem(iter.value(), iter.key()); + } + break; + } + case 3: + { + QMap::iterator iter = m_usergMap.begin(); + for(;iter != m_usergMap.end();++iter) + { + box->insertItem(iter.value(), iter.key()); + } + break; + } + case 4: + { + QMap::iterator iter = m_domainMap.begin(); + for(;iter != m_domainMap.end();++iter) + { + box->insertItem(iter.value(), iter.key()); + } + break; + } + default: + break; + } + + ui->treeWidget->setItemWidget(item,1,box); + } +} + +void CConfigureDialog::slot_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) +{ + preChange(previous); +} + +void CConfigureDialog::initUserInfo() +{ + QStringList list = m_settings->allKeys(); + if(list.isEmpty()) + { + slot_initUserInfo(); + } + else + { + m_objUserName->setText(1,m_settings->value("user_name").toString()); + m_objUsergName->setText(1,m_settings->value("userg_name").toString()); + m_objHostName->setText(1,m_settings->value("host_name").toString()); + m_objLocationName->setText(1,m_settings->value("location_name").toString()); + m_objDomainName->setText(1,m_settings->value("domain_name").toString()); + } + setSUserInfo(); +} + +int CConfigureDialog::getDomainId(const QString& domainName) +{ + int id; + QMap::const_iterator iter = m_domainMap.find(domainName); + if(iter != m_domainMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +QString CConfigureDialog::getDomainName(int domainId) +{ + QString name; + QMap::const_iterator iter = m_domainMap.begin(); + for(;iter != m_domainMap.end();++iter) + { + if(iter.value() == domainId) + { + name = iter.key(); + return name; + } + } + name = ""; + return name; +} + +int CConfigureDialog::getLocationId(const QString &locationName) +{ + int id; + QMap::const_iterator iter = m_locationMap.find(locationName); + if(iter != m_locationMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +QString CConfigureDialog::getLocationName(int locationId) +{ + QString name; + QMap::const_iterator iter = m_locationMap.begin(); + for(;iter != m_locationMap.end();++iter) + { + if(iter.value() == locationId) + { + name = iter.key(); + return name; + } + } + name = ""; + return name; +} + +int CConfigureDialog::getUserId(const QString &userName) +{ + int id; + QMap::const_iterator iter = m_userMap.find(userName); + if(iter != m_userMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +QString CConfigureDialog::getUserName(int userId) +{ + QString name; + QMap::const_iterator iter = m_userMap.begin(); + for(;iter != m_userMap.end();++iter) + { + if(iter.value() == userId) + { + name = iter.key(); + return name; + } + } + name = ""; + return name; +} + +int CConfigureDialog::getUsergId(const QString &usergName) +{ + int id; + QMap::const_iterator iter = m_usergMap.find(usergName); + if(iter != m_usergMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +QString CConfigureDialog::getUsergName(int usergId) +{ + QString name; + QMap::const_iterator iter = m_usergMap.begin(); + for(;iter != m_usergMap.end();++iter) + { + if(iter.value() == usergId) + { + name = iter.key(); + return name; + } + } + name = ""; + return name; +} + +int CConfigureDialog::getLocationIdBySeqName(const QString &seqName) +{ + int id; + QMap::const_iterator iter = m_seqLocationMap.find(seqName); + if(iter != m_seqLocationMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +int CConfigureDialog::getDomainIdByLocationId(int locationId) +{ + int id; + QMap::const_iterator iter = m_locationDomainIdMap.find(locationId); + if(iter != m_locationDomainIdMap.end()) + { + id = iter.value(); + } + else{ + id = 0; + } + return id; +} + +QString CConfigureDialog::getSubName(int subId) +{ + QString name; + QMap::const_iterator iter = m_subMap.begin(); + for(;iter != m_subMap.end();++iter) + { + if(iter.value() == subId) + { + name = iter.key(); + return name; + } + } + name = ""; + return name; +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.h b/product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.h new file mode 100644 index 00000000..dbaa7c37 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.h @@ -0,0 +1,77 @@ +#ifndef CCONFIGUREDIALOG_H +#define CCONFIGUREDIALOG_H + +#include +#include "CSqlDbCtrl.h" +#include "predifineforseqserver.h" +#include "pub_widget/CustomDialog.h" + +namespace Ui { +class CConfigureDialog; +} + +using namespace iot_dbms; +class CConfigureDialog : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit CConfigureDialog(QWidget *parent); + ~CConfigureDialog(); + + SUserInfo& getConfigurInfo(); + + int getDomainId(const QString& domainName); + QString getDomainName(int domainId); + int getLocationId(const QString& locationName); + QString getLocationName(int locationId); + int getUserId(const QString& userName); + QString getUserName(int userId); + int getUsergId(const QString& usergName); + QString getUsergName(int usergId); + int getLocationIdBySeqName(const QString& seqName); + int getDomainIdByLocationId(int locationId); + QString getSubName(int subId); + +private slots: + void slot_editSave(); + void slot_initUserInfo(); + void slot_editUserInfo(QTreeWidgetItem *item, int column); + void slot_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); + +private: + void initUserInfo(); + void preChange(QTreeWidgetItem *item); + void setSUserInfo(); + +private: + Ui::CConfigureDialog *ui; + + CSqlDbCtrl *m_objDbCtrl; + iot_dbms::CDbPara m_objDbPara; + iot_dbms::CDbApi m_objLocalDbConn; + + QTreeWidgetItem * m_objItem = 0; + QTreeWidgetItem * m_objDbParaItem; + QTreeWidgetItem * m_objUserInfo; + QTreeWidgetItem * m_objUserName; + QTreeWidgetItem * m_objUsergName; + QTreeWidgetItem * m_objHostName; + QTreeWidgetItem * m_objDomainName; + QTreeWidgetItem * m_objLocationName; + + QMap m_subMap; + QMap m_seqLocationMap; + QMap m_locationDomainIdMap; + QMap m_userMap; + QMap m_usergMap; + QMap m_locationMap; + QMap m_domainMap; + QStringList m_hostList; + + QSettings* m_settings; + SUserInfo m_stUserInfo; + +}; + +#endif // CCONFIGUREDIALOG_H diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.ui b/product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.ui new file mode 100644 index 00000000..c60f4bde --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CConfigureDialog.ui @@ -0,0 +1,128 @@ + + + CConfigureDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + + 1 + + + + + + + + Qt::Horizontal + + + + 204 + 20 + + + + + + + + 初始化全部 + + + + + + + 保存 + + + + + + + + + pushButton_2 + clicked() + CConfigureDialog + slot_editSave() + + + 360 + 272 + + + 398 + 260 + + + + + pushButton + clicked() + CConfigureDialog + slot_initUserInfo() + + + 256 + 272 + + + 211 + 268 + + + + + treeWidget + itemDoubleClicked(QTreeWidgetItem*,int) + CConfigureDialog + slot_editUserInfo(QTreeWidgetItem*,int) + + + 351 + 127 + + + 396 + 110 + + + + + treeWidget + currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) + CConfigureDialog + slot_currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) + + + 377 + 62 + + + 397 + 55 + + + + + + slot_editSave() + slot_initUserInfo() + slot_editUserInfo(QTreeWidgetItem*,int) + slot_currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) + + diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CGetRdbDataThread.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CGetRdbDataThread.cpp new file mode 100644 index 00000000..fd97725e --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CGetRdbDataThread.cpp @@ -0,0 +1,135 @@ +#include "CGetRdbDataThread.h" +#include "boost/date_time.hpp" +#include "rdb_net_api/CRdbNetApi.h" +#include "mainwindow.h" +#include "CRdbSeqRunningAccess.h" +#include "CRecoverNode.h" + +CGetRdbDataThread::CGetRdbDataThread() + :CTimerThreadBase("CGetRdbData thread", 100) +{ + +} + +CGetRdbDataThread::~CGetRdbDataThread() +{ + this->quit(); +} + +bool CGetRdbDataThread::getRdbData(CRecoverNodeContainer& container) +{ + CRdbSeqRunningAccess runAccess(m_strSeqName, m_domainId); + CRdbSeqRunningAccessLocker locker(runAccess); + if(locker.isLock()) + { + CGetRdbDataThreadLocker lock(*this); + if(runAccess.remapRunningTable(container)) + { + return true; + } + else + { + return false; + } + } + else + return false; +} + +Qt::CheckState CGetRdbDataThread::getCheckState(int checkStateNum) +{ + if(checkStateNum == 0) + return Qt::Unchecked; + else if(checkStateNum == 1) + return Qt::PartiallyChecked; + else + return Qt::Checked; +} + +QString CGetRdbDataThread::statusType(int statusNum) +{ + QString str; + switch(statusNum){ + case 0: + str = ("未执行"); + break; + case 1: + str = ("正在执行"); + break; + case 2: + str = ("已触发"); + break; + case 3: + str = ("执行失败"); + break; + case 4: + str = ("执行成功"); + break; + case 5: + str = ("执行终止"); + break; + case 6: + str = ("执行暂停"); + break; + case 7: + str = ("执行跳过"); + break; + default: + break; + } + return str; +} + +QString CGetRdbDataThread::nodeType(int nodeNum) +{ + QString str; + switch(nodeNum){ + case 0: + str = ("联动"); + break; + case 1: + str = ("功能"); + break; + case 2: + str = ("动作"); + break; + default: + break; + } + return str; +} + +bool CGetRdbDataThread::start(const std::string& seqName, int domainId) +{ + m_objUpdateContainer.clearData(); + m_strSeqName = seqName; + m_domainId= domainId; + this->resume(); + return true; +} + +bool CGetRdbDataThread::stop() +{ + this->suspend(); + return true; +} + +void CGetRdbDataThread::lock() +{ + mutex.lock(); +} + +void CGetRdbDataThread::unlock() +{ + mutex.unlock(); +} + +void CGetRdbDataThread::clear() +{ + m_objUpdateContainer.clearData(); +} + +void CGetRdbDataThread::execute() +{ + getRdbData(m_objUpdateContainer); +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CGetRdbDataThread.h b/product/src/tools/link_seq_tool/sequence_server_tool/CGetRdbDataThread.h new file mode 100644 index 00000000..a3487531 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CGetRdbDataThread.h @@ -0,0 +1,67 @@ +#ifndef CGETRDBDATATHREAD_H +#define CGETRDBDATATHREAD_H + +#include +#include +#include "pub_utility_api/TimerThreadBase.h" +#include "CRecoverNodeContainer.h" +#include "CRdbSeqRunningAccess.h" + +class MainWindow; +class CGetRdbDataThread + : public QObject, public iot_public::CTimerThreadBase +{ + + Q_OBJECT + +public: + CGetRdbDataThread(); + ~CGetRdbDataThread(); + + static Qt::CheckState getCheckState(int checkStateNum); + static QString statusType(int statusNum); + static QString nodeType(int nodeNum); + + //开启线程 + bool start(const std::string &seqName, int domainId); + + //停止线程 + bool stop(); + + void clear(); + +protected: + friend class MainWindow; + void execute(); + friend class CGetRdbDataThreadLocker; + void lock(); + void unlock(); + +private: + bool getRdbData(CRecoverNodeContainer& container); + +private: + std::string m_strSeqName; + int m_domainId; + CRecoverNodeContainer m_objUpdateContainer; + QMutex mutex; + +}; + +class CGetRdbDataThreadLocker +{ +public: + CGetRdbDataThreadLocker(CGetRdbDataThread& rdbData): + m_objRdbData(rdbData) + { + m_objRdbData.lock(); + } + ~CGetRdbDataThreadLocker() + { + m_objRdbData.unlock(); + } +private: + CGetRdbDataThread& m_objRdbData; +}; + +#endif // CGETRDBDATATHREAD_H diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CRdbSeqRunningAccess.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CRdbSeqRunningAccess.cpp new file mode 100644 index 00000000..b8394c6d --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CRdbSeqRunningAccess.cpp @@ -0,0 +1,140 @@ +#include "CRdbSeqRunningAccess.h" +#include +#include "rdb_net_api/CRdbNetApi.h" + +using namespace iot_dbms; +using namespace iot_idl; +CRdbSeqRunningAccess::CRdbSeqRunningAccess(const std::string& seqName, int domainId): + m_strSeqName(seqName),m_domainId(domainId) +{ + +} + +CRdbSeqRunningAccess::~CRdbSeqRunningAccess() +{ + +} + +bool CRdbSeqRunningAccess::remapRunningTable(CRecoverNodeContainer& info) +{ + info.clearData(); + + iot_idl::RdbQuery msgQuery; + msgQuery.set_strtablename("sequence_running"); + std::string *pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "seq_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "func_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "action_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "node_desc"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "action_no"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "func_no"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "node_type"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "status"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "checked"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "start_time"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "user_id"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "user_groupid"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "host_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "user_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "timeflag"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "relation"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "delay_time"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "fail_strage"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "isses"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "key_id_tag"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "targetvalue"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "location_id"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "seq_type"; + + pColName = msgQuery.add_strordercolnamearr(); + *pColName = "node_type"; + + iot_idl::RdbCondition *pCondtion = msgQuery.add_msgcondition(); + pCondtion->set_enlogic(ENConditionLogic::enumCondAnd); + pCondtion->set_enrelation(ENConditionRelation::enumCondEqual); + pCondtion->set_strcolumnname("seq_name"); + + SVariable *pCondValue = pCondtion->mutable_msgvalue(); + pCondValue->set_edatatype(DataType::CN_DATATYPE_STRING); + pCondValue->set_strvalue(m_strSeqName); + + iot_idl::RdbRet retMsg; + bool bRet = objNetApi.query(msgQuery, retMsg); + if (false == bRet) { + std::cout << "query failed." << std::endl; + return false; + } + else { + for (int i = 0 ; i < retMsg.msgrecord_size() ; ++i) { + SSeqCtrlRunning *run = new SSeqCtrlRunning(); + strcpy(run->seq_name,retMsg.msgrecord(i).msgvaluearray(0).strvalue().c_str()); + strcpy(run->func_name,retMsg.msgrecord(i).msgvaluearray(1).strvalue().c_str()); + strcpy(run->action_name,retMsg.msgrecord(i).msgvaluearray(2).strvalue().c_str()); + strcpy(run->node_desc,retMsg.msgrecord(i).msgvaluearray(3).strvalue().c_str()); + run->action_no = retMsg.msgrecord(i).msgvaluearray(4).nvalue(); + run->func_no = retMsg.msgrecord(i).msgvaluearray(5).nvalue(); + run->node_type = retMsg.msgrecord(i).msgvaluearray(6).nvalue(); + run->status = retMsg.msgrecord(i).msgvaluearray(7).nvalue(); + run->checked = retMsg.msgrecord(i).msgvaluearray(8).nvalue(); + run->start_time = retMsg.msgrecord(i).msgvaluearray(9).ulvalue(); + run->user_id = retMsg.msgrecord(i).msgvaluearray(10).nvalue(); + run->user_groupid = retMsg.msgrecord(i).msgvaluearray(11).nvalue(); + strcpy(run->host_name,retMsg.msgrecord(i).msgvaluearray(12).strvalue().c_str()); + strcpy(run->user_name,retMsg.msgrecord(i).msgvaluearray(13).strvalue().c_str()); + run->timeflag = retMsg.msgrecord(i).msgvaluearray(14).ulvalue(); + run->relation = retMsg.msgrecord(i).msgvaluearray(15).nvalue(); + run->delay_time = retMsg.msgrecord(i).msgvaluearray(16).nvalue(); + run->fail_strage = retMsg.msgrecord(i).msgvaluearray(17).nvalue(); + run->isses = retMsg.msgrecord(i).msgvaluearray(18).nvalue(); + strcpy(run->key_id_tag,retMsg.msgrecord(i).msgvaluearray(19).strvalue().c_str()); + run->targetvalue = retMsg.msgrecord(i).msgvaluearray(20).nvalue(); + run->location_id = retMsg.msgrecord(i).msgvaluearray(21).nvalue(); + run->seq_type = retMsg.msgrecord(i).msgvaluearray(22).nvalue(); + + info.pushData(run); + } + info.createModel(); + } + + return true; +} + +bool CRdbSeqRunningAccess::lockTable() +{ + objNetApi.connect(m_domainId, 3); + bool bRet = objNetApi.lock("sequence_running"); + if (false == bRet) { + std::cout << "lock failed." << std::endl; + } + return bRet; +} + +void CRdbSeqRunningAccess::unLockTable() +{ + bool bRet = objNetApi.unLock("sequence_running"); + if (false == bRet) { + std::cout << "unlock failed." << std::endl; + } +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CRdbSeqRunningAccess.h b/product/src/tools/link_seq_tool/sequence_server_tool/CRdbSeqRunningAccess.h new file mode 100644 index 00000000..1a9e9639 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CRdbSeqRunningAccess.h @@ -0,0 +1,60 @@ +#pragma once +/*! + * @breif 实时服务访问 运行表 + * + * @author sjq + * @date 五月 2018 + */ + +#include "boost/thread/mutex.hpp" + +#include "rdb_api/CRdbAccess.h" +#include "rdb_api/CRdbAccessEx.h" +#include "rdb_api/CVarType.h" +#include "rdb_net_api/CRdbNetApi.h" + +#include "DbTableDefine.h" +#include "CRecoverNodeContainer.h" + +using namespace iot_dbms; +using namespace iot_idl; +class CRdbSeqRunningAccess +{ +public: + CRdbSeqRunningAccess(const std::string& seqName, int domainId); + virtual ~CRdbSeqRunningAccess(); + + virtual bool remapRunningTable(CRecoverNodeContainer& info); + +protected: + friend class CRdbSeqRunningAccessLocker; + bool lockTable(); + void unLockTable(); + +private: + CRdbNetApi objNetApi; + std::string m_strSeqName; + boost::mutex m_muLock; + int m_domainId; +}; + +class CRdbSeqRunningAccessLocker +{ +public: + CRdbSeqRunningAccessLocker(CRdbSeqRunningAccess& access) + :m_objAccess(access) + { + m_isLock = m_objAccess.lockTable(); + }; + ~CRdbSeqRunningAccessLocker() + { + m_objAccess.unLockTable(); + }; + bool isLock() + { + return m_isLock; + } +private: + CRdbSeqRunningAccess& m_objAccess; + bool m_isLock; +}; diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNode.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNode.cpp new file mode 100644 index 00000000..71391c92 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNode.cpp @@ -0,0 +1,411 @@ +#include "CRecoverNode.h" +#include "boost/assert.hpp" + +#include "CRecoverNodeContainer.h" + +CRecoverNode::CRecoverNode(SSeqCtrlRunning* info) + :m_ptrRunnningInfo(info) +{ + m_strHostName = (m_ptrRunnningInfo->host_name); + m_strUserName = (m_ptrRunnningInfo->user_name); + m_strNodeDesc = (m_ptrRunnningInfo->node_desc); +} + +CRecoverNode::CRecoverNode(const CRecoverNode& recover) +{ + this->m_strNodeName = recover.m_strNodeName; + this->m_strHostName = recover.m_strHostName; + this->m_strUserName = recover.m_strUserName; + this->m_strNodeDesc = recover.m_strNodeDesc; + this->m_ptrRunnningInfo = new SSeqCtrlRunning(*(recover.m_ptrRunnningInfo)); +} + +CRecoverNode& CRecoverNode::operator=(const CRecoverNode& recover) +{ + if (this == &recover) + { + return *this; + } + + if (this->m_ptrRunnningInfo) + { + delete this->m_ptrRunnningInfo; + this->m_ptrRunnningInfo = NULL; + } + + clearChild(); + + this->m_strNodeName = recover.m_strNodeName; + this->m_strHostName = recover.m_strHostName; + this->m_strUserName = recover.m_strUserName; + this->m_strNodeDesc = recover.m_strNodeDesc; + this->m_ptrRunnningInfo = new SSeqCtrlRunning(*(recover.m_ptrRunnningInfo)); + + return *this; +} + +CRecoverNode::~CRecoverNode() +{ + clearChild(); + + if (m_ptrRunnningInfo) + { + delete m_ptrRunnningInfo; + m_ptrRunnningInfo = NULL; + } +} + +void CRecoverNode::addChild(CRecoverNode* ch) +{ + m_mapChild.insert(std::make_pair(ch->nodeName(), ch)); +} + +const std::string& CRecoverNode::nodeName() const +{ + BOOST_ASSERT(!m_strNodeName.empty()); + return m_strNodeName; +} + +uint64 CRecoverNode::timeFlag() const +{ + return m_ptrRunnningInfo->timeflag; +} + +uint64 CRecoverNode::startTime() const +{ + return m_ptrRunnningInfo->start_time; +} + +int CRecoverNode::getState() const +{ + return m_ptrRunnningInfo->status; +} + +int CRecoverNode::checkState() const +{ + return m_ptrRunnningInfo->checked; +} + +int CRecoverNode::userId() const +{ + return m_ptrRunnningInfo->user_id; +} + +int CRecoverNode::userGrounpId() const +{ + return m_ptrRunnningInfo->user_groupid; +} + +const std::string& CRecoverNode::hostName() const +{ + return m_strHostName; +} + +const std::string& CRecoverNode::userName() const +{ + return m_strUserName; +} + +const std::string &CRecoverNode::description() const +{ + return m_strNodeDesc; +} + +bool CRecoverNode::isSesExe() const +{ + return m_ptrRunnningInfo->isses == 1; +} + +int CRecoverNode::seqType() const +{ + return m_ptrRunnningInfo->seq_type; +} + +int CRecoverNode::locationId() const +{ + return m_ptrRunnningInfo->location_id; +} + +int CRecoverNode::nodeType() const +{ + return m_ptrRunnningInfo->node_type; +} + +int CRecoverNode::actionNo() const +{ + return m_ptrRunnningInfo->action_no; +} + +int CRecoverNode::funcNo() const +{ + return m_ptrRunnningInfo->func_no; +} + +std::string CRecoverNode::key_id_tag() const +{ + return m_ptrRunnningInfo->key_id_tag; +} + +int CRecoverNode::targetValue() const +{ + return m_ptrRunnningInfo->targetvalue; +} + +int CRecoverNode::relation() const +{ + return m_ptrRunnningInfo->relation; +} + +int CRecoverNode::delayTime() const +{ + return m_ptrRunnningInfo->delay_time; +} + +int CRecoverNode::failStrage() const +{ + return m_ptrRunnningInfo->fail_strage; +} + +void CRecoverNode::clearChild() +{ + std::map::iterator iter = m_mapChild.begin(); + for (; iter != m_mapChild.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapChild.clear(); +} + +CRecoverNodeSeq::CRecoverNodeSeq(SSeqCtrlRunning* info) + :CRecoverNode(info) +{ + m_strNodeName = std::string(info->seq_name); +} + +CRecoverNodeSeq::CRecoverNodeSeq(const CRecoverNodeSeq& recover) + : CRecoverNode(recover) +{ + CRecoverIterator iter(recover); + while (iter.hasNext()) + { + CRecoverNodeFunc& func = (CRecoverNodeFunc&)iter.getNext(); + CRecoverNodeFunc* newFunc = new CRecoverNodeFunc(func); + this->addChild(newFunc); + } +} + +CRecoverNodeSeq& CRecoverNodeSeq::operator=(const CRecoverNodeSeq& recover) +{ + if (this == &recover) + { + return *this; + } + + CRecoverNode::operator=(recover); + + CRecoverIterator iter(recover); + while (iter.hasNext()) + { + CRecoverNodeFunc& func = (CRecoverNodeFunc&)iter.getNext(); + CRecoverNodeFunc* newFunc = new CRecoverNodeFunc(func); + this->addChild(newFunc); + } + + return *this; +} + +CRecoverNodeSeq::~CRecoverNodeSeq() +{ +} + +const std::string& CRecoverNodeSeq::seqName() const +{ + return CRecoverNode::nodeName(); +} + +CRecoverNodeFunc::CRecoverNodeFunc(SSeqCtrlRunning* info) + :CRecoverNode(info) +{ + m_strNodeName = std::string(info->func_name); + m_strSeqName = std::string(info->seq_name); +} + +CRecoverNodeFunc::CRecoverNodeFunc(const CRecoverNodeFunc& recover) + :CRecoverNode(recover) +{ + this->m_strSeqName = recover.m_strSeqName; + + CRecoverIterator iter(recover); + while (iter.hasNext()) + { + CRecoverNodeAction& action = (CRecoverNodeAction&)iter.getNext(); + CRecoverNodeAction* newAction = new CRecoverNodeAction(action); + this->addChild(newAction); + } +} + +CRecoverNodeFunc& CRecoverNodeFunc::operator=(const CRecoverNodeFunc& recover) +{ + if (this == &recover) + { + return *this; + } + + CRecoverNode::operator=(recover); + + this->m_strSeqName = recover.m_strSeqName; + + CRecoverIterator iter(recover); + while (iter.hasNext()) + { + CRecoverNodeAction& action = (CRecoverNodeAction&)iter.getNext(); + CRecoverNodeAction* newAction = new CRecoverNodeAction(action); + this->addChild(newAction); + } + + return *this; +} + +CRecoverNodeFunc::~CRecoverNodeFunc() +{ +} + +const std::string& CRecoverNodeFunc::seqName() const +{ + return m_strSeqName; +} + +const std::string& CRecoverNodeFunc::funcName() const +{ + return CRecoverNode::nodeName(); +} + +CRecoverNodeAction::CRecoverNodeAction(SSeqCtrlRunning* info) + :CRecoverNode(info) +{ + m_strNodeName = std::string(info->action_name); + m_strFuncName = std::string(info->func_name); + m_strSeqName = std::string(info->seq_name); +} + +CRecoverNodeAction::CRecoverNodeAction(const CRecoverNodeAction& recover) + :CRecoverNode(recover) +{ + this->m_strSeqName = recover.m_strSeqName; + this->m_strFuncName = recover.m_strFuncName; + + CRecoverIterator iter(recover); + BOOST_ASSERT(!iter.hasNext()); +} + +CRecoverNodeAction& CRecoverNodeAction::operator=(const CRecoverNodeAction& recover) +{ + if (this == &recover) + { + return *this; + } + + CRecoverNode::operator=(recover); + + this->m_strSeqName = recover.m_strSeqName; + this->m_strFuncName = recover.m_strFuncName; + + CRecoverIterator iter(recover); + BOOST_ASSERT(!iter.hasNext()); + + return *this; +} + +CRecoverNodeAction::~CRecoverNodeAction() +{ +} + +const std::string& CRecoverNodeAction::seqName() const +{ + return m_strSeqName; +} + +const std::string& CRecoverNodeAction::funcName() const +{ + return m_strFuncName; +} + +const std::string& CRecoverNodeAction::actionName() const +{ + return CRecoverNode::nodeName(); +} + +CRecoverIterator::CRecoverIterator() +{ + m_iter = m_vec.begin(); +} + +CRecoverIterator::CRecoverIterator(const CRecoverNode& parent) +{ + std::map::const_iterator iter + = parent.m_mapChild.begin(); + for (; iter != parent.m_mapChild.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +CRecoverIterator::CRecoverIterator(const CRecoverNode& parent, + const std::string& chName) +{ + std::map::const_iterator iter + = parent.m_mapChild.find(chName); + if (iter != parent.m_mapChild.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +CRecoverIterator::CRecoverIterator(const CRecoverNodeContainer& parent) +{ + CRecoverNodeContainer::recoverSeqMap::const_iterator iter + = parent.m_mapRecoverNodeSeq.begin(); + for (; iter != parent.m_mapRecoverNodeSeq.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +CRecoverIterator::CRecoverIterator( + const CRecoverNodeContainer& parent, + const std::string& chName) +{ + CRecoverNodeContainer::recoverSeqMap::const_iterator iter + = parent.m_mapRecoverNodeSeq.find(chName); + if (iter != parent.m_mapRecoverNodeSeq.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +CRecoverIterator::~CRecoverIterator() +{ + m_vec.clear(); +} + +bool CRecoverIterator::hasNext() const +{ + return m_iter != m_vec.end(); +} + +CRecoverNode& CRecoverIterator::getNext() +{ + CRecoverNode *pNode = *m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNode.h b/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNode.h new file mode 100644 index 00000000..cf4bb07d --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNode.h @@ -0,0 +1,113 @@ +#pragma once +#include +#include + +#include "DbTableDefine.h" + +class CRecoverNode +{ +public: + CRecoverNode(SSeqCtrlRunning* info); + CRecoverNode(const CRecoverNode& recover); + CRecoverNode& operator=(const CRecoverNode& recover); + + virtual ~CRecoverNode(); + + void addChild(CRecoverNode* ch); + const std::string& nodeName() const; + uint64 timeFlag() const; + uint64 startTime() const; + int getState() const; + int checkState() const; + int userId() const; + int userGrounpId() const; + const std::string& hostName() const; + const std::string& userName() const; + const std::string& description() const; + bool isSesExe() const; + int seqType() const; + int locationId() const; + int nodeType() const; + int actionNo() const; + int funcNo() const; + std::string key_id_tag() const; + int targetValue() const; + int relation() const; + int delayTime() const; + int failStrage() const; +private: + void clearChild(); +protected: + friend class CRecoverIterator; + std::string m_strNodeName; + std::string m_strHostName; + std::string m_strUserName; + std::string m_strNodeDesc; + SSeqCtrlRunning* m_ptrRunnningInfo; + std::map m_mapChild; +}; + +class CRecoverNodeSeq : public CRecoverNode +{ +public: + CRecoverNodeSeq(SSeqCtrlRunning* info); + CRecoverNodeSeq(const CRecoverNodeSeq& recover); + CRecoverNodeSeq& operator=(const CRecoverNodeSeq& recover); + ~CRecoverNodeSeq(); + const std::string& seqName() const; +}; + +class CRecoverNodeFunc : public CRecoverNode +{ +public: + CRecoverNodeFunc(SSeqCtrlRunning* info); + CRecoverNodeFunc(const CRecoverNodeFunc& recover); + CRecoverNodeFunc& operator=(const CRecoverNodeFunc& recover); + ~CRecoverNodeFunc(); + const std::string& seqName() const; + const std::string& funcName() const; +private: + std::string m_strSeqName; +}; + +class CRecoverNodeAction : public CRecoverNode +{ +public: + CRecoverNodeAction(SSeqCtrlRunning* info); + CRecoverNodeAction(const CRecoverNodeAction& recover); + CRecoverNodeAction& operator=(const CRecoverNodeAction& recover); + + ~CRecoverNodeAction(); + const std::string& seqName() const; + const std::string& funcName() const; + const std::string& actionName() const; +private: + std::string m_strSeqName; + std::string m_strFuncName; +}; + +//运行节点 迭代器 +class CRecoverNodeContainer; +class CRecoverIterator +{ +public: + CRecoverIterator(); + CRecoverIterator(const CRecoverNode& parent); + CRecoverIterator( + const CRecoverNode& parent, + const std::string& chName); + + CRecoverIterator(const CRecoverNodeContainer& parent); + CRecoverIterator( + const CRecoverNodeContainer& parent, + const std::string& chName); + + virtual ~CRecoverIterator(); + + virtual bool hasNext() const; + CRecoverNode& getNext(); + +protected: + std::vector m_vec; + std::vector::iterator m_iter; +}; diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNodeContainer.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNodeContainer.cpp new file mode 100644 index 00000000..3bf62ed3 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNodeContainer.cpp @@ -0,0 +1,208 @@ +#include "pub_logger_api/logger.h" + +#include "CRecoverNodeContainer.h" +#include "predifineforseqserver.h" + +CRecoverNodeContainer::CRecoverNodeContainer() +{ +} + +CRecoverNodeContainer::CRecoverNodeContainer(const CRecoverNodeContainer &container) +{ + recoverSeqMap::const_iterator iter + = container.m_mapRecoverNodeSeq.begin(); + for (; iter != container.m_mapRecoverNodeSeq.end(); ++iter) + { + CRecoverNodeSeq* pNode = new CRecoverNodeSeq(*iter->second); + this->m_mapRecoverNodeSeq.insert(std::make_pair(pNode->nodeName(), pNode)); + } +} + +CRecoverNodeContainer& CRecoverNodeContainer::operator=(const CRecoverNodeContainer &container) +{ + if (this == &container) + { + return *this; + } + + this->clearData(); + + recoverSeqMap::const_iterator iter + = container.m_mapRecoverNodeSeq.begin(); + for (; iter != container.m_mapRecoverNodeSeq.end(); ++iter) + { + CRecoverNodeSeq* pNode = new CRecoverNodeSeq(*iter->second); + this->m_mapRecoverNodeSeq.insert(std::make_pair(pNode->nodeName(), pNode)); + } + + return *this; +} + +CRecoverNodeContainer::~CRecoverNodeContainer() +{ + clearData(); +} + +bool CRecoverNodeContainer::isEmpty() const +{ + return m_mapRecoverNodeSeq.begin() == m_mapRecoverNodeSeq.end(); +} + +void CRecoverNodeContainer::clearData() +{ + clearAllNode(); + clearSeqInfo(); + clearFuncInfo(); + clearActionInfo(); +} + +void CRecoverNodeContainer::pushData(SSeqCtrlRunning* data) +{ + if (data->node_type == 0) + { + m_vecSeqInfo.push_back(data); + } + else if (data->node_type == 1) + { + m_vecFuncInfo.push_back(data); + } + else if (data->node_type == 2) + { + m_vecActionInfo.push_back(data); + } + else + { + delete data; + data = NULL; + } +} + +void CRecoverNodeContainer::createModel() +{ + LOGINFO("创建顺控运行表结构"); + createSeqNode(); + createFuncNode(); + createActionNode(); + LOGINFO("结束创建顺控运行表结构"); +} + +void CRecoverNodeContainer::clearAllNode() +{ + recoverSeqMap::iterator iter = m_mapRecoverNodeSeq.begin(); + for (; iter != m_mapRecoverNodeSeq.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapRecoverNodeSeq.clear(); +} + +void CRecoverNodeContainer::clearSeqInfo() +{ + std::vector::iterator iter; + + iter = m_vecSeqInfo.begin(); + for (; iter != m_vecSeqInfo.end(); ++iter) + { + delete *iter; + *iter = NULL; + } + m_vecSeqInfo.clear(); +} + +void CRecoverNodeContainer::clearFuncInfo() +{ + std::vector::iterator iter; + + iter = m_vecFuncInfo.begin(); + for (; iter != m_vecFuncInfo.end(); ++iter) + { + delete *iter; + *iter = NULL; + } + m_vecFuncInfo.clear(); +} + +void CRecoverNodeContainer::clearActionInfo() +{ + std::vector::iterator iter; + + iter = m_vecActionInfo.begin(); + for (; iter != m_vecActionInfo.end(); ++iter) + { + delete *iter; + *iter = NULL; + } + m_vecActionInfo.clear(); +} + +void CRecoverNodeContainer::createSeqNode() +{ + std::vector::iterator iter = m_vecSeqInfo.begin(); + for (; iter != m_vecSeqInfo.end(); ++iter) + { + CRecoverNodeSeq* seq = new CRecoverNodeSeq(*iter); + m_mapRecoverNodeSeq.insert(std::make_pair(seq->nodeName(), seq)); + } + + //把数据移交给 节点管理 + m_vecSeqInfo.clear(); +} + +void CRecoverNodeContainer::createFuncNode() +{ + std::vector::iterator iter = m_vecFuncInfo.begin(); + for (; iter != m_vecFuncInfo.end(); ++iter) + { + CRecoverNodeFunc* func = new CRecoverNodeFunc(*iter); + + CRecoverIterator seqNodeIter(*this, func->seqName()); + if (seqNodeIter.hasNext()) + { + CRecoverNode& seq = seqNodeIter.getNext(); + seq.addChild(func); + } + else + { + delete func; + func = NULL; + } + } + + //把数据移交给 节点管理 + m_vecFuncInfo.clear(); +} + +void CRecoverNodeContainer::createActionNode() +{ + std::vector::iterator iter = m_vecActionInfo.begin(); + for (; iter != m_vecActionInfo.end(); ++iter) + { + CRecoverNodeAction* action = new CRecoverNodeAction(*iter); + + CRecoverIterator seqNodeIter(*this, action->seqName()); + if (seqNodeIter.hasNext()) + { + CRecoverNode& seq = seqNodeIter.getNext(); + CRecoverIterator funcNodeIter(seq, action->funcName()); + if (funcNodeIter.hasNext()) + { + CRecoverNode& func = funcNodeIter.getNext(); + func.addChild(action); + } + else + { + delete action; + action = NULL; + } + } + else + { + delete action; + action = NULL; + } + } + + //把数据移交给 节点管理 + m_vecActionInfo.clear(); +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNodeContainer.h b/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNodeContainer.h new file mode 100644 index 00000000..9cc3ae98 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CRecoverNodeContainer.h @@ -0,0 +1,45 @@ +#pragma once +/*! + * @breif 恢复运行节点容器 + * + * @author sjq + * @date 五月 2018 + */ +#include + +#include "DbTableDefine.h" +#include "CRecoverNode.h" + +class CRecoverNodeContainer +{ +public: + CRecoverNodeContainer(); + CRecoverNodeContainer(const CRecoverNodeContainer &container); + CRecoverNodeContainer &operator =(const CRecoverNodeContainer &container); + ~CRecoverNodeContainer(); + + bool isEmpty() const; + + void pushData(SSeqCtrlRunning* data); + void createModel(); + + void clearData(); + +private: + void clearAllNode(); + void clearSeqInfo(); + void clearFuncInfo(); + void clearActionInfo(); + + void createSeqNode(); + void createFuncNode(); + void createActionNode(); +protected: + friend class CRecoverIterator; + typedef std::map recoverSeqMap; + recoverSeqMap m_mapRecoverNodeSeq; +private: + std::vector m_vecSeqInfo; //所有顺控 + std::vector m_vecFuncInfo; //所有功能 + std::vector m_vecActionInfo; //所有动作 +}; diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CRefreshExeStatusThread.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CRefreshExeStatusThread.cpp new file mode 100644 index 00000000..447e6530 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CRefreshExeStatusThread.cpp @@ -0,0 +1,134 @@ +#include "CRefreshExeStatusThread.h" +#include "rdb_net_api/CRdbNetApi.h" + +using namespace iot_dbms; +using namespace iot_idl; + +CRefreshExeStateThread::CRefreshExeStateThread() + :CTimerThreadBase("RefreshExeState thread", 500, iot_public::CN_DeadlockTimeoutMsec, false) +{ + +} + +CRefreshExeStateThread::~CRefreshExeStateThread() +{ + +} + +bool CRefreshExeStateThread::getDomainSeqStatue() +{ + CRefreshExeStateThreadStatusLocker lock(*this); + m_mapLinkStatus.clear(); + + iot_idl::RdbQuery msgQuery; + msgQuery.set_strtablename("sequence_running"); + std::string *pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "seq_name"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "node_type"; + pColName = msgQuery.add_strselectcolnamearr(); + *pColName = "status"; + + iot_idl::RdbCondition *pCondtion = msgQuery.add_msgcondition(); + pCondtion->set_enlogic(ENConditionLogic::enumCondAnd); + pCondtion->set_enrelation(ENConditionRelation::enumCondEqual); + pCondtion->set_strcolumnname("node_type"); + + SVariable *pCondValue = pCondtion->mutable_msgvalue(); + pCondValue->set_edatatype(DataType::CN_DATATYPE_INT32); + pCondValue->set_nvalue(0); + + iot_idl::RdbRet retMsg; + bool bRet = objNetApi.query(msgQuery, retMsg); + if (false == bRet) { + std::cout << "query failed." << std::endl; + return false; + } + else { + for (int i = 0 ; i < retMsg.msgrecord_size() ; ++i) { + m_mapLinkStatus.insert(QString::fromStdString(retMsg.msgrecord(i).msgvaluearray(0).strvalue()), + CGetRdbDataThread::statusType(retMsg.msgrecord(i).msgvaluearray(2).nvalue())); + } + } + + return true; +} + +void CRefreshExeStateThread::getAllSeqStatus() +{ + for(int domainNum=0;domainNum domainIdList) +{ + m_domainId = domainIdList; +} + +bool CRefreshExeStateThread::start() +{ + this->resume(); + return true; +} + +bool CRefreshExeStateThread::stop() +{ + this->suspend(); + return true; +} + +bool CRefreshExeStateThread::isEmpty() +{ + return m_mapLinkStatus.isEmpty(); +} + +void CRefreshExeStateThread::clear() +{ + m_mapLinkStatus.clear(); +} + +QString CRefreshExeStateThread::getStatus(const QString& seqName) +{ + return m_mapLinkStatus.take(seqName); +} + + +void CRefreshExeStateThread::lock() +{ + mutex.lock(); +} + +void CRefreshExeStateThread::unlock() +{ + mutex.unlock(); +} + + +void CRefreshExeStateThread::execute() +{ + getAllSeqStatus(); +} + +bool CRefreshExeStateThread::lockTable(int domainId) +{ + objNetApi.connect(domainId, 3); + bool bRet = objNetApi.lock("sequence_running"); + if (false == bRet) { + std::cout << "lock failed." << std::endl; + } + return bRet; +} + +void CRefreshExeStateThread::unLockTable() +{ + bool bRet = objNetApi.unLock("sequence_running"); + if (false == bRet) { + std::cout << "unlock failed." << std::endl; + } +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CRefreshExeStatusThread.h b/product/src/tools/link_seq_tool/sequence_server_tool/CRefreshExeStatusThread.h new file mode 100644 index 00000000..6cc31f3b --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CRefreshExeStatusThread.h @@ -0,0 +1,87 @@ +#ifndef CREFRESHEXESTATETHREAD_H +#define CREFRESHEXESTATETHREAD_H + +#include "pub_utility_api/TimerThreadBase.h" +#include "CGetRdbDataThread.h" + +class CRefreshExeStateThread + :public iot_public::CTimerThreadBase +{ +public: + CRefreshExeStateThread(); + ~CRefreshExeStateThread(); + + void setDomainId(QList domainIdList); + + QString getStatus(const QString& seqName); + + //开启线程 + bool start(); + + //停止线程 + bool stop(); + + bool isEmpty(); + + void clear(); + +protected: + void execute(); + friend class CRefreshExeStateThreadLocker; + bool lockTable(int domainId); + void unLockTable(); + friend class CRefreshExeStateThreadStatusLocker; + void lock(); + void unlock(); + +private: + bool getDomainSeqStatue(); + + void getAllSeqStatus(); + +private: + QList m_domainId; + QMap m_mapLinkStatus; + boost::mutex mutex; + CRdbNetApi objNetApi; +}; + +class CRefreshExeStateThreadStatusLocker +{ +public: + CRefreshExeStateThreadStatusLocker(CRefreshExeStateThread& access) + :m_objAccess(access) + { + m_objAccess.lock(); + }; + ~CRefreshExeStateThreadStatusLocker() + { + m_objAccess.unlock(); + }; +private: + CRefreshExeStateThread& m_objAccess; +}; + +class CRefreshExeStateThreadLocker +{ +public: + CRefreshExeStateThreadLocker(CRefreshExeStateThread& access, int domainId) + :m_objAccess(access), m_domainId(domainId) + { + m_isLock = m_objAccess.lockTable(m_domainId); + }; + ~CRefreshExeStateThreadLocker() + { + m_objAccess.unLockTable(); + }; + bool isLock() + { + return m_isLock; + } +private: + CRefreshExeStateThread& m_objAccess; + int m_domainId; + bool m_isLock; +}; + +#endif // CREFRESHEXESTATETHREAD_H diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CSeqDbContainer.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CSeqDbContainer.cpp new file mode 100644 index 00000000..f127c268 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CSeqDbContainer.cpp @@ -0,0 +1,304 @@ +#include "CSeqDbContainer.h" +#include "boost/assert.hpp" + +CSeqDbContainer::CSeqDbContainer() + :m_nTimeFlag(0) +{} + +CSeqDbContainer::~CSeqDbContainer() +{ + clearAll(); +} + +void CSeqDbContainer::clearAll() +{ + clearSeqDefineInfo(); + clearSeqConfigInfo(); + clearFuncInfo(); + clearActionInfo(); +} + +void CSeqDbContainer::clearSeqDefineInfo() +{ + std::map::iterator iter = m_mapSeqDefineInfo.begin(); + for (; iter != m_mapSeqDefineInfo.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapSeqDefineInfo.clear(); +} + +void CSeqDbContainer::pushActionInfo(SActionInfo* info) +{ + m_mapActionInfo.insert(std::make_pair(info->name, info)); +} + +void CSeqDbContainer::setTimeFlag(uint64 time) +{ + m_nTimeFlag = time; +} + +uint64 CSeqDbContainer::getTimeFlag() const +{ + return m_nTimeFlag; +} + +void CSeqDbContainer::pushFuncInfo(SFuncInfo* info) +{ + BOOST_ASSERT(!info->name.empty()); + m_mapFuncInfo[info->name].push_back(info); +} + +void CSeqDbContainer::clearActionInfo() +{ + std::map::iterator iter = m_mapActionInfo.begin(); + for (; iter != m_mapActionInfo.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapActionInfo.clear(); +} + +void CSeqDbContainer::pushSeqConfigInfo(SSeqConfigInfo* info) +{ + BOOST_ASSERT(!info->seq_name.empty()); + m_mapSeqConfigInfo[info->seq_name].push_back(info); +} + +void CSeqDbContainer::clearFuncInfo() +{ + std::map >::iterator mapIter = m_mapFuncInfo.begin(); + std::vector::iterator vecIter; + for (; mapIter != m_mapFuncInfo.end(); ++mapIter) + { + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + delete *vecIter; + *vecIter = NULL; + } + (mapIter->second).clear(); + } + m_mapFuncInfo.clear(); +} + +void CSeqDbContainer::pushSeqDefineInfo(SSeqDefineInfo* info) +{ + m_mapSeqDefineInfo[info->name] = info; +} + +void CSeqDbContainer::clearSeqConfigInfo() +{ + std::map >::iterator mapIter + = m_mapSeqConfigInfo.begin(); + std::vector::iterator vecIter; + for (; mapIter != m_mapSeqConfigInfo.end(); ++mapIter) + { + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + delete *vecIter; + *vecIter = NULL; + } + (mapIter->second).clear(); + } + m_mapSeqConfigInfo.clear(); +} + +// 顺控定义迭代器 +SSeqDefineInfoIterator::SSeqDefineInfoIterator(CSeqDbContainer& container) +{ + std::map::iterator iter + = container.m_mapSeqDefineInfo.begin(); + for (; iter != container.m_mapSeqDefineInfo.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SSeqDefineInfoIterator::SSeqDefineInfoIterator(CSeqDbContainer& container, const std::string& seqName) +{ + std::map::iterator iter + = container.m_mapSeqDefineInfo.find(seqName); + if (iter != container.m_mapSeqDefineInfo.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SSeqDefineInfoIterator::~SSeqDefineInfoIterator() +{ + m_vec.clear(); +} + +bool SSeqDefineInfoIterator::hasNext() +{ + return m_iter != m_vec.end(); +} + +const SSeqDefineInfo* SSeqDefineInfoIterator::getNext() +{ + SSeqDefineInfo *pNode = *m_iter; + ++m_iter; + return pNode; +} + +// 顺控设置 迭代器 +SSeqConfigInfoIterator::SSeqConfigInfoIterator(CSeqDbContainer& container) +{ + std::map > ::iterator mapIter + = container.m_mapSeqConfigInfo.begin(); + std::vector::iterator vecIter; + for (; mapIter != container.m_mapSeqConfigInfo.end(); ++mapIter) + { + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + m_vec.push_back(*vecIter); + } + } + + m_iter = m_vec.begin(); +} + +SSeqConfigInfoIterator::SSeqConfigInfoIterator(CSeqDbContainer& container, const std::string& seqName) +{ + std::map > ::iterator mapIter + = container.m_mapSeqConfigInfo.find(seqName); + if (mapIter != container.m_mapSeqConfigInfo.end()) + { + std::vector::iterator vecIter; + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + m_vec.push_back(*vecIter); + } + } + + m_iter = m_vec.begin(); +} + +SSeqConfigInfoIterator::~SSeqConfigInfoIterator() +{ + m_vec.clear(); +} + +bool SSeqConfigInfoIterator::hasNext() +{ + return m_iter != m_vec.end(); +} + +const SSeqConfigInfo* SSeqConfigInfoIterator::getNext() +{ + SSeqConfigInfo *pNode = *m_iter; + ++m_iter; + return pNode; +} + +// 顺控功能 迭代器 + +SFuncInfoIterator::SFuncInfoIterator(CSeqDbContainer& container) +{ + std::map > ::iterator mapIter + = container.m_mapFuncInfo.begin(); + std::vector::iterator vecIter; + for (; mapIter != container.m_mapFuncInfo.end(); ++mapIter) + { + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + m_vec.push_back(*vecIter); + } + } + + m_iter = m_vec.begin(); +} + +SFuncInfoIterator::SFuncInfoIterator(CSeqDbContainer& container, const std::string& funcName) +{ + std::map > ::iterator mapIter + = container.m_mapFuncInfo.find(funcName); + + if (mapIter != container.m_mapFuncInfo.end()) + { + std::vector::iterator vecIter; + for (vecIter = (mapIter->second).begin(); + vecIter != (mapIter->second).end(); + ++vecIter) + { + m_vec.push_back(*vecIter); + } + } + + m_iter = m_vec.begin(); +} + +SFuncInfoIterator::~SFuncInfoIterator() +{ + m_vec.clear(); +} + +bool SFuncInfoIterator::hasNext() +{ + return m_iter != m_vec.end(); +} + +const SFuncInfo* SFuncInfoIterator::getNext() +{ + SFuncInfo *pNode = *m_iter; + ++m_iter; + return pNode; +} + +// 顺控动作 迭代器 +SActionInfoIterator::SActionInfoIterator(CSeqDbContainer& container) +{ + std::map::iterator iter + = container.m_mapActionInfo.begin(); + for (; iter != container.m_mapActionInfo.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SActionInfoIterator::SActionInfoIterator(CSeqDbContainer& container, const std::string& actionName) +{ + std::map::iterator iter + = container.m_mapActionInfo.find(actionName); + if (iter != container.m_mapActionInfo.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SActionInfoIterator::~SActionInfoIterator() +{ + m_vec.clear(); +} + +bool SActionInfoIterator::hasNext() +{ + return m_iter != m_vec.end(); +} + +const SActionInfo* SActionInfoIterator::getNext() +{ + SActionInfo *pNode = *m_iter; + ++m_iter; + return pNode; +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CSeqDbContainer.h b/product/src/tools/link_seq_tool/sequence_server_tool/CSeqDbContainer.h new file mode 100644 index 00000000..33f1b4f4 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CSeqDbContainer.h @@ -0,0 +1,107 @@ +#pragma once +/*! + * @breif 顺控数据表数据结构 基础数据 容器 + * + * @author sjq + * @date 五月 2018 + */ + +#include +#include + +#include "DbTableDefine.h" + +class CSeqDbContainer +{ +public: + CSeqDbContainer(); + ~CSeqDbContainer(); + + void clearAll(); + + void clearSeqDefineInfo(); + void pushSeqDefineInfo(SSeqDefineInfo* info); + + void clearSeqConfigInfo(); + void pushSeqConfigInfo(SSeqConfigInfo* info); + + void clearFuncInfo(); + void pushFuncInfo(SFuncInfo* info); + + void clearActionInfo(); + void pushActionInfo(SActionInfo* info); + + void setTimeFlag(uint64 time); + uint64 getTimeFlag() const; + +protected: + friend class SSeqDefineInfoIterator; + friend class SSeqConfigInfoIterator; + friend class SFuncInfoIterator; + friend class SActionInfoIterator; + + //使用map,是为了检索更快点,在数据生成可运行的节点需要大量的检索,第二级不要求检索,只要求可以遍历所以使用vector + std::map m_mapSeqDefineInfo;//顺控名 - 顺控信息表 + std::map > m_mapSeqConfigInfo;//顺控名 - 顺控和功能关系表 + std::map > m_mapFuncInfo;//功能名 - 功能和动作关系列表 + std::map m_mapActionInfo; //动作名-动作 + +private: + uint64 m_nTimeFlag;//时标 0 表示没有数据, 非零值表示最后的更新时间 +}; + +// 顺控定义 迭代器 +class SSeqDefineInfoIterator +{ +public: + SSeqDefineInfoIterator(CSeqDbContainer& container); + SSeqDefineInfoIterator(CSeqDbContainer& container, const std::string& seqName); + ~SSeqDefineInfoIterator(); + bool hasNext(); + const SSeqDefineInfo* getNext(); +private: + std::vector m_vec; + std::vector::iterator m_iter; +}; + +//顺控设置 迭代器 +class SSeqConfigInfoIterator +{ +public: + SSeqConfigInfoIterator(CSeqDbContainer& container); + SSeqConfigInfoIterator(CSeqDbContainer& container, const std::string& seqName); + ~SSeqConfigInfoIterator(); + bool hasNext(); + const SSeqConfigInfo* getNext(); +private: + std::vector m_vec; + std::vector::iterator m_iter; +}; + +// 顺控功能 迭代器 +class SFuncInfoIterator +{ +public: + SFuncInfoIterator(CSeqDbContainer& container); + SFuncInfoIterator(CSeqDbContainer& container, const std::string& funcName); + ~SFuncInfoIterator(); + bool hasNext(); + const SFuncInfo* getNext(); +private: + std::vector m_vec; + std::vector::iterator m_iter; +}; + +// 顺控动作 迭代器 +class SActionInfoIterator +{ +public: + SActionInfoIterator(CSeqDbContainer& container); + SActionInfoIterator(CSeqDbContainer& container, const std::string& actionName); + ~SActionInfoIterator(); + bool hasNext(); + const SActionInfo* getNext(); +private: + std::vector m_vec; + std::vector::iterator m_iter; +}; diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CSequenceForHmiApiInterface.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CSequenceForHmiApiInterface.cpp new file mode 100644 index 00000000..dd17bf0e --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CSequenceForHmiApiInterface.cpp @@ -0,0 +1,285 @@ +#include "CSequenceForHmiApiInterface.h" +#include "mainwindow.h" +#include "common/DataType.h" +#include + +using namespace iot_idl::sequence; +CSequenceForHmiApiInterface::CSequenceForHmiApiInterface(MainWindow* mainWindow) + :m_ptrMain(mainWindow) +{ + this->start(); +} + +CSequenceForHmiApiInterface::~CSequenceForHmiApiInterface() +{ + this->stop(); +} + +bool CSequenceForHmiApiInterface::handleSeqOperateResponse( + SeqOperateMessageAck &msg) +{ + QString msgStr; + + const SeqPkgHead& head + = msg.pkg_head(); + const SeqNodeStatusParameter& seq + = msg.seq_node(); + + const ::std::string& seqName = seq.seq_name(); + ENSeqStatus state = seq.node_state(); + std::string seqStateStr = nodeStatusStr(state); + + std::string funcName; + std::string funcStateStr; + + std::string actionName; + std::string actionStateStr; + + std::string retStr; + int retCore; + const ExecuteStatusParameter& + executeStateParam = msg.execute_status(); + retCore = executeStateParam.statuscode(); + if (retCore != 0) + { + const ::ErrorParameter& + errorParam = executeStateParam.erro_param(); + retStr = errorParam.errordescription(); + } + + const google::protobuf::RepeatedPtrField< FucNodeStatusParameter >& + funcList = seq.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + funcListIter = funcList.begin(); + if (funcListIter != funcList.end()) + { + const FucNodeStatusParameter& func = *funcListIter; + funcName = func.fuc_name(); + funcStateStr = nodeStatusStr(func.node_state()); + + const google::protobuf::RepeatedPtrField< ActionNodeStatusParameter >& + actionList = func.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + actionListIter = actionList.begin(); + + if (actionListIter != actionList.end()) + { + const ActionNodeStatusParameter& action = *actionListIter; + + actionName = action.action_name(); + actionStateStr = nodeStatusStr(action.node_state()); + } + } + + msgStr = QString("顺控操作应答:顺控名:%1,状态:%2 应答状态:%3 描述:%4") + .arg(QString::fromStdString(seqName)) + .arg(QString::fromStdString(seqStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)); + + m_ptrMain->showMsg(msgStr); + return true; +} + +bool CSequenceForHmiApiInterface::handleUserInterveneRequest( + UiRequestMessage &msg) +{ + QString msgStr; + + const SeqPkgHead& head + = msg.pkg_head(); + const SeqNodeStatusParameter& seq + = msg.nodelist(); + + const ::std::string& seqName = seq.seq_name(); + ENSeqStatus state = seq.node_state(); + std::string seqStateStr = nodeStatusStr(state); + + std::string funcName; + std::string funcStateStr; + + std::string actionName; + std::string actionStateStr; + + const google::protobuf::RepeatedPtrField< FucNodeStatusParameter >& + funcList = seq.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + funcListIter = funcList.begin(); + if (funcListIter != funcList.end()) + { + const FucNodeStatusParameter& func = *funcListIter; + funcName = func.fuc_name(); + funcStateStr = nodeStatusStr(func.node_state()); + + const google::protobuf::RepeatedPtrField< ActionNodeStatusParameter >& + actionList = func.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + actionListIter = actionList.begin(); + + if (actionListIter != actionList.end()) + { + const ActionNodeStatusParameter& action = *actionListIter; + + actionName = action.action_name(); + actionStateStr = nodeStatusStr(action.node_state()); + } + } + + std::string retStr; + int retCore; + const ExecuteStatusParameter& + executeStateParam = msg.execute_status(); + retCore = executeStateParam.statuscode(); + if (retCore != 0) + { + const ::ErrorParameter& + errorParam = executeStateParam.erro_param(); + retStr = errorParam.errordescription(); + } + + msgStr = QString("人工干预 状态:[%1]:[%2] [%3]:[%4] [%5]:[%6] 状态码:[%7] 描述:[%8]") + .arg(QString::fromStdString(seqName)) + .arg(QString::fromStdString(seqStateStr)) + .arg(QString::fromStdString(funcName)) + .arg(QString::fromStdString(funcStateStr)) + .arg(QString::fromStdString(actionName)) + .arg(QString::fromStdString(actionStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)); + + m_ptrMain->showUiMsg(msgStr, msg); + return true; +} + +bool CSequenceForHmiApiInterface::handleSeqStateChange( + StatusChangeMessage &msg) +{ + QString msgStr; + + const SeqPkgHead& head + = msg.pkg_head(); + const SeqNodeStatusParameter& seq + = msg.nodelist(); + + const ::std::string& seqName = seq.seq_name(); + ENSeqStatus seqState = seq.node_state(); + std::string seqStateStr = nodeStatusStr(seqState); + + std::string funcName; + std::string funcStateStr; + + std::string actionName; + std::string actionStateStr; + + const google::protobuf::RepeatedPtrField< FucNodeStatusParameter >& + funcList = seq.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + funcListIter = funcList.begin(); + if (funcListIter != funcList.end()) + { + const FucNodeStatusParameter& func = *funcListIter; + funcName = func.fuc_name(); + funcStateStr = nodeStatusStr(func.node_state()); + + const google::protobuf::RepeatedPtrField< ActionNodeStatusParameter >& + actionList = func.nodelist(); + google::protobuf::RepeatedPtrField::const_iterator + actionListIter = actionList.begin(); + + if (actionListIter != actionList.end()) + { + const ActionNodeStatusParameter& action = *actionListIter; + + actionName = action.action_name(); + actionStateStr = nodeStatusStr(action.node_state()); + } + } + int retCore = 0; + std::string retStr; + const google::protobuf::RepeatedPtrField< ::ExecuteStatusParameter >& + executeStatusList = msg.execute_status(); + if (executeStatusList.begin() != executeStatusList.end()) + { + const ExecuteStatusParameter& executeStatus = *(executeStatusList.begin()); + retCore = executeStatus.statuscode(); + if (retCore != 0) + { + const ::ErrorParameter& erroParam = + executeStatus.erro_param(); + retStr = erroParam.errordescription(); + } + } + + if (!actionName.empty()) + { + msgStr = QString("动作 状态变化:[%1]:[%2] [%3]:[%4] [%5]:[%6] 执行状态[%7]:[%8]") + .arg(QString::fromStdString(seqName)) + .arg(QString::fromStdString(seqStateStr)) + .arg(QString::fromStdString(funcName)) + .arg(QString::fromStdString(funcStateStr)) + .arg(QString::fromStdString(actionName)) + .arg(QString::fromStdString(actionStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)) + ; + } + else if (!funcName.empty()) + { + msgStr = QString("功能 状态变化:[%1]:[%2] [%3]:[%4] 执行状态[%5]:[%6]") + .arg(QString::fromStdString(seqName)) + .arg(QString::fromStdString(seqStateStr)) + .arg(QString::fromStdString(funcName)) + .arg(QString::fromStdString(funcStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)) + ; + } + else + { + msgStr = QString("顺控 状态变化:[%1]:[%2] 执行状态[%3]:[%4]") + .arg(QString::fromStdString(seqName)) + .arg(QString::fromStdString(seqStateStr)) + .arg(retCore) + .arg(QString::fromStdString(retStr)); + } + + m_ptrMain->showMsg(msgStr); + return true; +} + +std::string CSequenceForHmiApiInterface::nodeStatusStr( + ENSeqStatus type) +{ + using namespace iot_idl; + std::string strRet; + switch (type) + { + case enumSEQ_RESTING_STATUS: + strRet = ("未执行"); + break; + case enumSEQ_RUNNING_STATUS: + strRet = ("正在执行"); + break; + case enumSEQ_TRIGGERED_STATUS: + strRet = ("已触发"); + break; + case enumSEQ_FAILED_STATUS: + strRet = ("执行失败"); + break; + case enumSEQ_SUCCESS_STATUS: + strRet = ("执行成功"); + break; + case enumSEQ_STOP_STATUS: + strRet = ("执行中止"); + break; + case enumSEQ_PAUSE_STATUS: + strRet = ("执行暂停"); + break; + case enumSEQ_SKIP_STATUS: + strRet = ("执行跳过"); + break; + default: + break; + } + return strRet; +} \ No newline at end of file diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CSequenceForHmiApiInterface.h b/product/src/tools/link_seq_tool/sequence_server_tool/CSequenceForHmiApiInterface.h new file mode 100644 index 00000000..e992fb73 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CSequenceForHmiApiInterface.h @@ -0,0 +1,33 @@ +#ifndef CSEQCTRLFORHMIAPIINTERFACE_H +#define CSEQCTRLFORHMIAPIINTERFACE_H +#include "application/sequence_server_api/CSeqForHmiApi.h" + +class MainWindow; +using namespace iot_idl::sequence; +class CSequenceForHmiApiInterface + : public iot_app::CSeqForHmiApi +{ +public: + CSequenceForHmiApiInterface(MainWindow* mainWindow); + ~CSequenceForHmiApiInterface(); + + //2 server->hmi 请求顺控操作 的 应答 + virtual bool handleSeqOperateResponse( + SeqOperateMessageAck& msg); + + //1 server->hmi 发起的人工干预 请求 + virtual bool handleUserInterveneRequest( + UiRequestMessage& msg); + + //server->hmi 顺控状态更新 + virtual bool handleSeqStateChange( + StatusChangeMessage& msg); + +private: + std::string nodeStatusStr( + ENSeqStatus type); +private: + MainWindow* m_ptrMain; +}; + +#endif // CSEQCTRLFORHMIAPIINTERFACE_H diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CSetSeqMsgInfo.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CSetSeqMsgInfo.cpp new file mode 100644 index 00000000..6c04ec71 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CSetSeqMsgInfo.cpp @@ -0,0 +1,133 @@ +#include "CSetSeqMsgInfo.h" + +CSetSeqMsgInfo::CSetSeqMsgInfo(const SSetReqMsg &reqMsg) +{ + m_stSeqMsg = reqMsg; + getLinkNode(); +} + +CSetSeqMsgInfo::~CSetSeqMsgInfo() +{ + +} + +void CSetSeqMsgInfo::setMsgInfo( + SeqOperateMessage& msg, + enSeqMsgType msgType, + ENSeqOperateType type) +{ + SeqPkgHead* pkg_head + = cterateHead(msgType); + SeqNodeStatusParameter* seq_node + = cterateSeq(); + ActorParameter* actor + = createActor(); + + msg.set_opreate_type(type); + msg.set_allocated_pkg_head(pkg_head); + msg.set_allocated_seq_node(seq_node); + msg.set_allocated_actor(actor); +} + +SeqPkgHead* CSetSeqMsgInfo::cterateHead(enSeqMsgType msgType) +{ + SeqPkgHead* head = new SeqPkgHead; + head->set_source_domain(m_stSeqMsg.source_domainId); + head->set_target_domain(m_stSeqMsg.target_domainId); + head->set_msg_type(msgType); + head->set_source_tag(std::string("hmi")); + head->set_para1(0); + head->set_para2(0); + return head; +} + +SeqNodeStatusParameter* CSetSeqMsgInfo::cterateSeq() +{ + SeqNodeStatusParameter* seq + = new SeqNodeStatusParameter; + seq->set_seq_name(m_ptrSeqNode->nodeName()); + seq->set_seq_desc(m_ptrSeqNode->description()); + seq->set_timeflag(m_ptrSeqNode->timeFlag()); + seq->set_node_state(enumSEQ_RUNNING_STATUS); + MapCheckState::iterator iter = m_stSeqMsg.mapCheck.find(m_ptrSeqNode->nodeName()); + assert(iter != m_stSeqMsg.mapCheck.end()); + seq->set_check_state(getNodeCheckStatus(iter->second)); + + CRecoverIterator funcIter(*m_ptrSeqNode); + + while(funcIter.hasNext()) + { + CRecoverNode& funcNode = funcIter.getNext(); + FucNodeStatusParameter* func + = seq->add_nodelist(); + cterateFunc(func, funcNode); + } + + return seq; +} + +FucNodeStatusParameter* CSetSeqMsgInfo::cterateFunc(FucNodeStatusParameter* pFunc, const CRecoverNode &funcNode) +{ + pFunc->set_fuc_name(funcNode.nodeName()); + pFunc->set_fuc_desc(funcNode.description()); + pFunc->set_timeflag(funcNode.timeFlag()); + pFunc->set_node_state(enumSEQ_RUNNING_STATUS); + MapCheckState::iterator iter = m_stSeqMsg.mapCheck.find(funcNode.nodeName()); + assert(iter != m_stSeqMsg.mapCheck.end()); + pFunc->set_check_state(getNodeCheckStatus(iter->second)); + + CRecoverIterator actionIter(funcNode); + + while(actionIter.hasNext()) + { + CRecoverNode& actionNode = actionIter.getNext(); + ActionNodeStatusParameter* action + = pFunc->add_nodelist(); + cterateAction(action, actionNode); + } + + return pFunc; +} + +ActionNodeStatusParameter *CSetSeqMsgInfo::cterateAction(ActionNodeStatusParameter* pAction, const CRecoverNode &actionNode) +{ + pAction->set_action_name(actionNode.nodeName()); + pAction->set_action_desc(actionNode.description()); + pAction->set_timeflag(actionNode.timeFlag()); + pAction->set_node_state(enumSEQ_RUNNING_STATUS); + + MapCheckState::iterator iter = m_stSeqMsg.mapCheck.find(actionNode.nodeName()); + assert(iter != m_stSeqMsg.mapCheck.end()); + pAction->set_check_state(getNodeCheckStatus(iter->second)); + + return pAction; +} + +ActorParameter* CSetSeqMsgInfo::createActor() +{ + ActorParameter* pActor + = new ActorParameter; + pActor->set_host_name(m_stSeqMsg.userinfo->host_name.toStdString()); + pActor->set_user_id(m_stSeqMsg.userId); + pActor->set_user_groupid(m_stSeqMsg.usergId); + pActor->set_user_name(m_stSeqMsg.userinfo->user_name.toStdString()); + return pActor; +} + +void CSetSeqMsgInfo::getLinkNode() +{ + CRecoverIterator seqIter(*m_stSeqMsg.container); + assert(seqIter.hasNext()); + + m_ptrSeqNode = &(seqIter.getNext()); +} + +ENSeqNodeCheckStatus CSetSeqMsgInfo::getNodeCheckStatus(int state) +{ + if(state == 0) + return ENSeqNodeCheckStatus::enumNodeUnChecked; + else if(state == 1) + return ENSeqNodeCheckStatus::enumnodePartiallyChecked; + else + return ENSeqNodeCheckStatus::enumNodeChecked; +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CSetSeqMsgInfo.h b/product/src/tools/link_seq_tool/sequence_server_tool/CSetSeqMsgInfo.h new file mode 100644 index 00000000..b266f66e --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CSetSeqMsgInfo.h @@ -0,0 +1,51 @@ +#ifndef CSETSEQMSGINFO_H +#define CSETSEQMSGINFO_H + +#include "SequenceMessage.pb.h" +#include "predifineforseqserver.h" +#include "CRecoverNodeContainer.h" +using namespace iot_idl::sequence; +typedef std::map MapCheckState; + +struct SSetReqMsg +{ + SUserInfo* userinfo; + CRecoverNodeContainer* container; + MapCheckState mapCheck; + int source_domainId; + int target_domainId; + int userId; + int usergId; +}; + +class CSetSeqMsgInfo +{ +public: + CSetSeqMsgInfo(const SSetReqMsg& reqMsg); + ~CSetSeqMsgInfo(); + + void setMsgInfo( + SeqOperateMessage& msg, + enSeqMsgType msgType, + ENSeqOperateType type); + + ENSeqNodeCheckStatus getNodeCheckStatus(int state); + +private: + SeqPkgHead* cterateHead( + enSeqMsgType msgType); + + SeqNodeStatusParameter* cterateSeq(); + FucNodeStatusParameter* cterateFunc(FucNodeStatusParameter* pFunc, const CRecoverNode &funcNode); + ActionNodeStatusParameter* cterateAction(ActionNodeStatusParameter* pAction, const CRecoverNode &actionNode); + + ActorParameter* createActor(); + + void getLinkNode(); + +private: + SSetReqMsg m_stSeqMsg; + CRecoverNode* m_ptrSeqNode; +}; + +#endif // CSETSEQMSGINFO_H diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CSqlDbCtrl.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/CSqlDbCtrl.cpp new file mode 100644 index 00000000..2a68df92 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CSqlDbCtrl.cpp @@ -0,0 +1,491 @@ +#include +#include +#include +#include "CSqlDbCtrl.h" +#include "public/pub_logger_api/logger.h" +#include "dbms/db_sysinfo_api/CDbSysInfo.h" +#include "pub_sysinfo_api/SysInfoApi.h" +#include "boost/assert.hpp" + + +CSqlDbCtrl::CSqlDbCtrl():m_objLocalDbConn(DB_CONN_MODEL_READ) +{ +} + +CSqlDbCtrl::~CSqlDbCtrl() +{ + if (isOpen()) + { + closeDb(); + } +} + +bool CSqlDbCtrl::openDb() +{ + using namespace iot_dbms; + if (m_objLocalDbConn.isOpen()) { + return true; + } + return m_objLocalDbConn.open(); +} + + +bool CSqlDbCtrl::remapDbTableSeqSettingInfo( + CSeqDbContainer& dbContainer) +{ + dbContainer.clearSeqDefineInfo(); + + QString strExecute = QString("SELECT " + "name," + "description," + "seq_type," + "location_id," + "timeflag" + " FROM sequence_setting"); + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SSeqDefineInfo* info = new SSeqDefineInfo; + info->name = queryTableMode.value(0).toString().toStdString(); + info->description = queryTableMode.value(1).toString().toStdString(); + info->seq_type = queryTableMode.value(2).toInt(); + info->location_id = queryTableMode.value(3).toInt(); + info->timeflag = queryTableMode.value(4).toULongLong(); + + dbContainer.pushSeqDefineInfo(info); + } + } + + return true; +} + +bool CSqlDbCtrl::remapDbTableSeqDefineInfo( + CSeqDbContainer& dbContainer) +{ + dbContainer.clearSeqConfigInfo(); + + QString strExecute = QString("SELECT " + "seq_name," + "func_name," + "func_no," + "relation," + "timeflag " + " FROM sequence_define order by func_no"); + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SSeqConfigInfo* info = new SSeqConfigInfo; + info->seq_name = queryTableMode.value(0).toString().toStdString(); + info->func_name = queryTableMode.value(1).toString().toStdString(); + info->func_no = queryTableMode.value(2).toInt(); + info->relation = queryTableMode.value(3).toInt(); + info->timeflag = queryTableMode.value(4).toULongLong(); + + dbContainer.pushSeqConfigInfo(info); + } + } + + return true; +} + +bool CSqlDbCtrl::remapDbTableFuncInfo( + CSeqDbContainer& dbContainer) +{ + dbContainer.clearFuncInfo(); + + QString strExecute = QString("select " + "name," + "action_name," + "description," + "action_no," + "enable," + "delaytime," + "timeflag," + "failstrage," + "retrytimes " + " from sequence_function order by action_no"); + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SFuncInfo* info = new SFuncInfo; + info->name = queryTableMode.value(0).toString().toStdString(); + info->action_name = queryTableMode.value(1).toString().toStdString(); + info->descrpition = queryTableMode.value(2).toString().toStdString(); + info->action_no = queryTableMode.value(3).toInt(); + info->enable = queryTableMode.value(4).toBool(); + info->delaytime = queryTableMode.value(5).toInt(); + info->timeflag = queryTableMode.value(6).toULongLong(); + info->failstrage = queryTableMode.value(7).toInt(); + info->retrytimes = queryTableMode.value(8).toInt(); + + dbContainer.pushFuncInfo(info); + } + } + + return true; +} + +bool CSqlDbCtrl::remapDbTableActionInfo( + CSeqDbContainer& dbContainer) +{ + dbContainer.clearActionInfo(); + + QString strExecute = QString("SELECT " + "name," + "description," + "key_id_tag," + "timeflag," + "ctrl_timeout," + "target_value," + "location_id, " + "sub_system" + " FROM sequence_action "); + + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SActionInfo* info = new SActionInfo; + info->name = queryTableMode.value(0).toString().toStdString(); + info->description = queryTableMode.value(1).toString().toStdString(); + info->key_id_tag = queryTableMode.value(2).toString().toStdString(); + info->timeflag = queryTableMode.value(3).toLongLong(); + info->ctrl_timeout = queryTableMode.value(4).toInt(); + info->target_value = queryTableMode.value(5).toInt(); + info->location_id = queryTableMode.value(6).toInt(); + info->sub_system = queryTableMode.value(7).toInt(); + + dbContainer.pushActionInfo(info); + } + } + + return true; +} + +bool CSqlDbCtrl::remapDbTable( + CSeqDbContainer& dbContainer) +{ + BOOST_ASSERT(m_objLocalDbConn.isOpen()); + + bool bRet = remapDbTableSeqSettingInfo(dbContainer); + bRet = remapDbTableSeqDefineInfo(dbContainer); + bRet = remapDbTableFuncInfo(dbContainer); + bRet = remapDbTableActionInfo(dbContainer); + + return bRet; +} + +void CSqlDbCtrl::closeDb() +{ + m_objLocalDbConn.close(); +} + +bool CSqlDbCtrl::isOpen() +{ + return m_objLocalDbConn.isOpen(); +} + +QString CSqlDbCtrl::SeqType(int SeqTypeNum) +{ + QString str; + switch (SeqTypeNum) { + case 0: + str = "标准顺控"; + break; + case 1: + str = "自定义顺控"; + break; + default: + break; + } + return str; +} + +QString CSqlDbCtrl::relationType(int relationNum) +{ + QString str; + switch(relationNum){ + case 0: + str = ("串行"); + break; + case 1: + str = ("并行"); + break; + default: + break; + } + return str; +} + +QString CSqlDbCtrl::enableType(bool enable) +{ + QString str; + if(enable){ + str = ("是"); + }else{ + str = ("否"); + } + + return str; +} + +QString CSqlDbCtrl::failStrageType(int failNum) +{ + QString str; + switch(failNum){ + case 0: + str = ("跳过失败动作"); + break; + case 1: + str = ("人工干预"); + break; + case 2: + str = ("终止联动"); + break; + case 3: + str = ("自动重做"); + break; + default: + break; + } + return str; +} + +QString CSqlDbCtrl::isSesExe(int issesNum) +{ + QString str; + switch(issesNum){ + case 0: + str = ("不是"); + break; + case 1: + str = ("是"); + break; + default: + break; + } + return str; +} + +QMap CSqlDbCtrl::readSeqLocation() +{ + QMap seqLocationMap; + + if(openDb()) + { + QString Execute = QString("SELECT name,location_id FROM sequence_setting "); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + seqLocationMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + return seqLocationMap; +} + +QMap CSqlDbCtrl::readLocationDomainId() +{ + QMap locationMap; + + if(openDb()) + { + QString Execute = QString("select location_id,domain_id from sys_model_location_info"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + locationMap.insert(Query.value(0).toInt(), Query.value(1).toInt()); + } + } + } + return locationMap; +} + +QMap CSqlDbCtrl::readLocationInfo() +{ + QMap locationMap; + + if(openDb()) + { + QString Execute = QString("select description,location_id from sys_model_location_info"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + locationMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return locationMap; +} + +QMap CSqlDbCtrl::readDomainInfo() +{ + QMap domainMap; + + if(openDb()) + { + QString Execute = QString("select description,domain_id from sys_model_domain_info"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + domainMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return domainMap; +} + +QMap CSqlDbCtrl::readUserInfo() +{ + QMap userMap; + + if(openDb()) + { + QString Execute = QString("select perm_name,perm_id from rm_user_def"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + userMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return userMap; +} + +QMap CSqlDbCtrl::readUsergInfo() +{ + QMap usergMap; + + if(openDb()) + { + QString Execute = QString("select perm_name,perm_id from rm_userg_def"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + usergMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return usergMap; +} + +QStringList CSqlDbCtrl::hostNameList() +{ + QStringList List; + + if(openDb()) + { + QString Execute = QString("select node_name from sys_model_node_info"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + List.append(Query.value(0).toString()); + } + } + } + + return List; +} + +QMap CSqlDbCtrl::readSubInfo() +{ + QMap subMap; + + if(openDb()) + { + QString Execute = QString("select description,sub_system_id from sys_model_sub_system_info"); + + QSqlQuery Query; + + m_objLocalDbConn.execute(Execute,Query); + + if(Query.isActive()) + { + while(Query.next()) + { + subMap.insert(Query.value(0).toString(), Query.value(1).toInt()); + } + } + } + + return subMap; +} + +QString CSqlDbCtrl::timeToDT(uint64 time) +{ + QString str; + if(time == 0) + { + str = "0"; + } + else{ + QDateTime triggerUtc = QDateTime::fromTime_t(time); + str = triggerUtc.toString("yyyy-MM-dd hh:mm::ss"); + } + return str; +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/CSqlDbCtrl.h b/product/src/tools/link_seq_tool/sequence_server_tool/CSqlDbCtrl.h new file mode 100644 index 00000000..7385e909 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/CSqlDbCtrl.h @@ -0,0 +1,48 @@ +#pragma once +/*! + * @breif 顺控输入数据库-关系库控制 + * + * @author sjq + * @date 五月 2018 + */ + +#include "db_api_ex/CDbApi.h" +#include "CSeqDbContainer.h" + +class CSqlDbCtrl +{ +public: + CSqlDbCtrl(); + ~CSqlDbCtrl(); + + bool remapDbTable(CSeqDbContainer& dbContainer); + + bool openDb(); + void closeDb(); + bool isOpen(); + + static QString SeqType(int SeqTypeNum); + static QString relationType(int relationNum); + static QString timeToDT(uint64 time); + static QString enableType(bool enable); + static QString failStrageType(int failNum); + static QString isSesExe(int issesNum); + + QMap readSubInfo(); + QMap readSeqLocation(); + QMap readLocationDomainId(); + QMap readLocationInfo(); + QMap readDomainInfo(); + QMap readUserInfo(); + QMap readUsergInfo(); + QStringList hostNameList(); + +private: + bool remapDbTableSeqSettingInfo(CSeqDbContainer& dbContainer); + bool remapDbTableSeqDefineInfo(CSeqDbContainer& dbContainer); + bool remapDbTableFuncInfo(CSeqDbContainer& dbContainer); + bool remapDbTableActionInfo(CSeqDbContainer& dbContainer); + +private: + iot_dbms::CDbApi m_objLocalDbConn; +}; diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/DbTableDefine.h b/product/src/tools/link_seq_tool/sequence_server_tool/DbTableDefine.h new file mode 100644 index 00000000..233f7504 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/DbTableDefine.h @@ -0,0 +1,191 @@ +#pragma once +/*! + * @breif 顺控数据表结构 + * + * @author sjq + * @date 五月 2018 + */ + +#include +#include +#include "common/DataType.h" + + //失败处理类型 +enum ACTION_FAILED_STRAGE +{ + ACTION_FAILED_STRAGE_AUTO_SKIP = 0,//自动跳过 + ACTION_FAILED_STRAGE_USER_INTERVENE = 1,//人工干预 + ACTION_FAILED_STRAGE_AUTO_STOP = 2,//自动终止 + ACTION_FAILED_STRAGE_AUTO_RETYR = 3,//自动重试 +}; + +// 顺控定义表,描述顺控的配置信息 + +struct SSeqDefineInfo +{ + std::string name;//顺控名称 + std::string description;//顺控描述 + int seq_type;//顺控类型 + int location_id;//车站id + int64 timeflag;//时标 +}; + +// 顺控信息表,描述顺控和功能的关系 + +struct SSeqConfigInfo +{ + std::string seq_name;//顺控名 + std::string func_name;//功能名 + int func_no;//功能编号 + int relation;//串 / 并 0串 1并 + int64 timeflag;//时标 +}; + +// 顺控功能定义表,描述 功能和动作的关系,功能的配置信息 + +struct SFuncInfo +{ + std::string name;//功能名称 + std::string action_name;//动作名称 + std::string descrpition;//功能描述 + int action_no;//动作编号 + bool enable;//是否可用 + int delaytime;//延时时间 + uint64 timeflag;//时标 + int failstrage;//失败处理 + int retrytimes;//重试次数 +}; + +// 顺控动作定义表 ,描述动作的配置信息 + +struct SActionInfo +{ + std::string name;// 动作名称 + std::string description;//动作描述 + std::string key_id_tag;//点名(表名+’.’+TAG_NAME) + uint64 timeflag;//修改时标 + int ctrl_timeout;//控制超时时间 + int target_value;//目标值 + int location_id;//车站ID + int sub_system;//所属子系统 +}; + +//顺控输出的四张表 + +// 顺控动作事件 + +struct SSeqCtrlActionEvent +{ + std::string seq_name;//顺控名称 + uint64 time;//执行时间 + std::string func_name;//功能名 + int action_no;//动作编号 + std::string action_name;//动作名称 + std::string action_desc;//动作描述 + std::string status;//执行状态 + uint64 starttime;//开始时间 + uint64 stoptime;//结束时间 + std::string key_id_tag;//点名 + int targetvalue;//目标值 + int location_id;//车站id + std::string discribe;//描述 +}; + +// 顺控功能历史信息表 + +struct SSeqFunctionHistory +{ + std::string seq_name;//顺控名称 + uint64 time;//执行时间 + std::string func_name;//功能名 + std::string func_desc;//功能描述 + int func_no;//功能序号 + int relation;//串并行方式 0 串 1并', + std::string status;//执行状态 + int location_id;//车站id +}; + +// 顺控历史信息表 +struct SSeqHistory +{ + std::string seq_name;//顺控名称 + uint64 time;//执行时间 + std::string seq_desc;//顺控描述 + std::string status;//执行状态 + int location_id;//车站id + int user_id;//操作员id + int user_group;//用户id组 + std::string host_name;//主机名 + std::string user_name;//用户名 + int seq_type;//顺控类型 +}; + +// 顺控运行表 - 调用实时服务 读写数据 + +struct SSeqCtrlRunning +{ + char seq_name[128];//1 顺控名称 + char func_name[128];//2 功能名 + char action_name[128];//3 动作名 + char node_desc[256];//4 节点描述 + int action_no;//5 动作序号 + int func_no;//6 功能序号 + int node_type;//7 节点类型 0 顺控节点 1 功能节点 2 动作节点 + int status;//8 执行状态 + int checked;//9 勾选状态 + uint64 start_time;//10 开始时间 + int user_id;//11 操作员id + int user_groupid;//12 用户组id + char host_name[128];//13 主机名 + char user_name[128];//14 用户名 + uint64 timeflag;//15 时标 + int relation;//16串并行方式 0 串 1并', + int delay_time;//17 延迟时间', + int fail_strage;//18 失败处理方式 0自动跳过 1人工干预 2 自动终止 3自动重试', + int isses;//19 是否是单步执行 0 不是 1是单步 + char key_id_tag[128]; //20点名 + int targetvalue;//21目标值 + int location_id;//22车站id + int seq_type;//23顺控类型 + + + SSeqCtrlRunning() + { + memset(this, 0, sizeof(SSeqCtrlRunning)); + }; + SSeqCtrlRunning(const SSeqCtrlRunning& info) + { + strcpy(this->seq_name,info.seq_name); + strcpy(this->func_name,info.func_name); + strcpy(this->action_name,info.action_name); + strcpy(this->node_desc, info.node_desc); + + this->action_no = info.action_no; + this->func_no = info.func_no; + this->node_type = info.node_type; + this->status = info.status; + this->checked = info.checked; + this->start_time = info.start_time; + this->user_id = info.user_id; + this->user_groupid = info.user_groupid; + strcpy(this->host_name,info.host_name); + strcpy(this->user_name, info.user_name); + this->timeflag = info.timeflag; + this->relation = info.relation; + this->delay_time = info.delay_time; + this->fail_strage = info.fail_strage; + this->isses = info.isses; + strcpy(this->key_id_tag,info.key_id_tag); + this->targetvalue = info.targetvalue; + this->location_id = info.location_id; + this->seq_type = info.seq_type; + }; +}; + +//实时库 顺控配置表 +struct SRdbSequenceSetting +{ + char name[128];//顺控名 + int location_id;//车站 + uint64 timeflag;//时标 +}; diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/main.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/main.cpp new file mode 100644 index 00000000..8151991e --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/main.cpp @@ -0,0 +1,62 @@ +#include "mainwindow.h" +#include +#include +#include "pub_logger_api/logger.h" +#include "net/net_msg_bus_api/MsgBusApi.h" +#include "pub_utility_api/FileStyle.h" + +void loadStyle() +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss","zh","light"); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("sequence_server_tool.qss","zh","light"); + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + qApp->setStyleSheet(qss); + } +} + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + loadStyle(); + + iot_public::StartLogSystem("comapp", "hmi-test"); + + int nRet = iot_net::initMsgBus( + std::string("hmi").c_str(), + std::string("hmiInstance").c_str()); + if (false == nRet) { + return 0; + } + + { + MainWindow w; + w.show(); + + nRet = a.exec(); + w.quit(); + } + + iot_net::releaseMsgBus(); + iot_public::StopLogSystem(); + + return nRet; +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.cpp b/product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.cpp new file mode 100644 index 00000000..f7534107 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.cpp @@ -0,0 +1,855 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include +#include + +using namespace iot_idl::sequence; + +MainWindow::MainWindow(QWidget *parent) : + CustomUiMainWindow(parent), + ui(new Ui::MainWindow), + m_objMsgBox(this) +{ + setAutoLayout(true); + setWindowTitle(tr("顺控调试工具")); + + ui->setupUi(this); + showMaximized(); + m_ptrShowMsgList = ui->listWidget; + m_ptrInterface = new CSequenceForHmiApiInterface(this); + m_dbCtrl = new CSqlDbCtrl(); + m_rdbDataThread = new CGetRdbDataThread(); + + RunTabTimer = new QTimer(this); + connect(RunTabTimer, SIGNAL(timeout()), this, SLOT(slot_updateRunTab())); + exeStatusTimer = new QTimer(this); + connect(exeStatusTimer, SIGNAL(timeout()), this, SLOT(slot_updateStatus())); + + initButton(); + if(initSeqDbTable()){ + QList domainIdList = getDomainId(); + m_refreshState = new CRefreshExeStateThread(); + m_refreshState->setDomainId(domainIdList); + exeStatusTimer->start(500); + } + initUserInfo(); + initSeqRdbTable(); + + connect(ui->action,SIGNAL(triggered(bool)),this,SLOT(slot_configUserInfo())); + + m_btnRetry = + m_objMsgBox.addButton(QString("重试"), QMessageBox::ActionRole); + m_btnStop = + m_objMsgBox.addButton(QString("终止"), QMessageBox::ActionRole); + m_btnSkip = + m_objMsgBox.addButton(QString("跳过"), QMessageBox::ActionRole); + +} + +MainWindow::~MainWindow() +{ + quit(); + + delete ui; +} + +void MainWindow::quit() +{ + if (m_ptrInterface) + { + m_ptrInterface->stop(); + delete m_ptrInterface; + m_ptrInterface = NULL; + } + + if(m_dbCtrl) + { + if(m_dbCtrl->isOpen()) + { + m_dbCtrl->closeDb(); + } + delete m_dbCtrl; + m_dbCtrl = NULL; + } + + if(m_rdbDataThread) + { + m_rdbDataThread->stop(); + delete m_rdbDataThread; + m_rdbDataThread = NULL; + } + + if(m_refreshState) + { + m_refreshState->stop(); + delete m_refreshState; + m_refreshState = NULL; + } + + if(RunTabTimer) + { + RunTabTimer->stop(); + delete RunTabTimer; + RunTabTimer = NULL; + } + + if(exeStatusTimer) + { + exeStatusTimer->stop(); + delete exeStatusTimer; + exeStatusTimer = NULL; + } + + if(m_ptrConfig) + { + delete m_ptrConfig; + m_ptrConfig = NULL; + } +} + +void MainWindow::showMsg(const QString & msg) +{ + refreshBuf.append(msg); + if(ui->checkBox->isChecked()){ + for(int i = 0;i < refreshBuf.size();++i){ + QMetaObject::invokeMethod(this, "slot_showMsg", + Qt::QueuedConnection, Q_ARG(QString, refreshBuf.at(i))); + } + refreshBuf.clear(); + } +} + +void MainWindow::showUiMsg( + const QString& msgStr, + UiRequestMessage& msg) +{ + UiRequestMessage* newMsg = new UiRequestMessage(msg); + QMetaObject::invokeMethod(this, "slot_showUiMsg", + Qt::QueuedConnection, Q_ARG(QString, msgStr), Q_ARG(void*, newMsg)); +} + +void MainWindow::slot_showMsg(const QString & msg) +{ + QListWidgetItem * item = new QListWidgetItem(); + item->setText(msg); + m_ptrShowMsgList->addItem(item); +} + +void MainWindow::slot_showUiMsg(const QString& msgStr, void* pData) +{ + using namespace iot_idl; + UiRequestMessage* msg + = (UiRequestMessage*)pData; + UiRequestMessageAck retMsg; + SeqPkgHead* head = new SeqPkgHead(msg->pkg_head()); + head->set_msg_type(enumUiRequestMessageAck); + head->set_source_tag(std::string("hmi")); + retMsg.set_allocated_pkg_head(head); + retMsg.set_allocated_nodelist( + new SeqNodeStatusParameter(msg->nodelist())); + + ActorParameter* actor + = new ActorParameter(); + actor->set_user_id(m_ptrConfig->getUserId(m_stUserInfo.user_name)); + actor->set_user_groupid(m_ptrConfig->getUsergId(m_stUserInfo.userg_Name)); + actor->set_host_name(m_stUserInfo.host_name.toStdString()); + actor->set_user_name(m_stUserInfo.user_name.toStdString()); + retMsg.set_allocated_actor(actor); + + slot_showMsg(msgStr); + + if (!m_objMsgBox.isHidden()) + { + return; + } + + QMessageBox& messageBox = m_objMsgBox; + + messageBox.setText(msgStr); + + messageBox.exec(); + + if (messageBox.clickedButton() == m_btnRetry) + { + retMsg.set_optype(enumUI_OP_RETRY); + } + else if (messageBox.clickedButton() == m_btnStop) + { + retMsg.set_optype(enumUI_OP_STOP); + } + else if (messageBox.clickedButton() == m_btnSkip) + { + retMsg.set_optype(enumUI_OP_SKIP); + } + else + { + delete msg; + msg = NULL; + return; + } + + m_ptrInterface->userInterveneResponse(retMsg); + + delete msg; + msg = NULL; +} + +SSetReqMsg MainWindow::getReqMsgObj() +{ + SSetReqMsg m_stReqMsg; + QTreeWidgetItemIterator it(ui->rdbTable); + while(*it) + { + m_stReqMsg.mapCheck.insert(std::make_pair((*it)->text(0).toStdString(), (*it)->checkState(2))); + ++it; + } + + m_stReqMsg.container = &m_objRdbContainer; + m_stReqMsg.userinfo = &m_stUserInfo; + m_stReqMsg.source_domainId = m_ptrConfig->getDomainId(m_stUserInfo.domain_name); + m_stReqMsg.target_domainId = m_ptrConfig + ->getDomainIdByLocationId(m_ptrConfig->getLocationIdBySeqName(QString::fromStdString(m_strSeqName))); + m_stReqMsg.userId = m_ptrConfig->getUserId(m_stUserInfo.user_name); + m_stReqMsg.usergId = m_ptrConfig->getUsergId(m_stUserInfo.userg_Name); + + return m_stReqMsg; +} + +void MainWindow::slot_start() +{ + try + { + SSetReqMsg stMsg = getReqMsgObj(); + CSetSeqMsgInfo info(stMsg); + SeqOperateMessage msg; + info.setMsgInfo(msg, + enumSeqOperateMessage, + enumOP_SEQ_START); + m_ptrInterface->seqOperateRequest(msg); + } + catch (const std::exception& e) + { + e.what(); + } +} + +void MainWindow::slot_stop() +{ + SSetReqMsg stMsg = getReqMsgObj(); + CSetSeqMsgInfo info(stMsg); + SeqOperateMessage msg; + info.setMsgInfo(msg, + enumSeqOperateMessage, + enumOP_SEQ_STOP); + m_ptrInterface->seqOperateRequest(msg); +} + +void MainWindow::slot_continue() +{ + SSetReqMsg stMsg = getReqMsgObj(); + CSetSeqMsgInfo info(stMsg); + SeqOperateMessage msg; + info.setMsgInfo(msg, + enumSeqOperateMessage, + enumOP_SEQ_CONTINUE); + m_ptrInterface->seqOperateRequest(msg); +} + +void MainWindow::slot_pause() +{ + SSetReqMsg stMsg = getReqMsgObj(); + CSetSeqMsgInfo info(stMsg); + SeqOperateMessage msg; + info.setMsgInfo(msg, + enumSeqOperateMessage, + enumOP_SEQ_PAUSE); + m_ptrInterface->seqOperateRequest(msg); +} + +void MainWindow::slot_sesStart() +{ + try + { + SSetReqMsg stMsg = getReqMsgObj(); + CSetSeqMsgInfo info(stMsg); + SeqOperateMessage msg; + info.setMsgInfo(msg, + enumSeqOperateMessage, + enumOP_SES_START); + m_ptrInterface->seqOperateRequest(msg); + } + catch (const std::exception& e) + { + e.what(); + } +} + +void MainWindow::slot_sesContinue() +{ + SSetReqMsg stMsg = getReqMsgObj(); + CSetSeqMsgInfo info(stMsg); + SeqOperateMessage msg; + info.setMsgInfo(msg, + enumSeqOperateMessage, + enumOP_SES_CONTINUE); + m_ptrInterface->seqOperateRequest(msg); +} + +void MainWindow::slot_itemClicked(QTreeWidgetItem *item, int column) +{ + while(item->parent()) + { + item = item->parent(); + } + std::string seqName = (item->text(0)).toStdString(); + if(seqName != m_strSeqName) + { + m_strSeqName = seqName; + int domainId = m_ptrConfig + ->getDomainIdByLocationId(m_ptrConfig->getLocationIdBySeqName(QString::fromStdString(m_strSeqName))); + + ui->rdbTable->clear(); + initButton(); + m_objRdbContainer.clearData(); + + m_rdbDataThread->start(m_strSeqName, domainId); + RunTabTimer->start(200); + } +} + +void MainWindow::slot_updateStatus() +{ + CRefreshExeStateThreadStatusLocker lock(*m_refreshState); + while(!m_refreshState->isEmpty()){ + QTreeWidgetItemIterator it(ui->dbTable); + while (*it) { + if((*it)->parent()) + ++it; + else{ + (*it)->setText(4,m_refreshState->getStatus((*it)->text(0))); + ++it; + } + } + m_refreshState->clear(); + } +} + +void MainWindow::resumeRunTab() +{ + QTreeWidgetItemIterator it(ui->rdbTable); + SResumeRunData data; + while(*it) + { + (*it)->setText(6,data.status); + (*it)->setText(8,data.start_time); + (*it)->setText(10,data.user_name); + (*it)->setText(11,data.userg_name); + (*it)->setText(12,data.host_name); + (*it)->setText(14,data.isses); + ++it; + } +} + +void MainWindow::updateButton(const ESeqCtrl_NodeState &status, const ESeq_Isses &isses) +{ + if(status == SEQ_RUNNING_STATUS && isses == EnumNotSes){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(true); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(true); + ui->sesStartButton->setEnabled(false); + ui->sesContinueButton->setEnabled(false); + }else if(status == SEQ_RUNNING_STATUS && isses == EnumSes){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(true); + ui->sesStartButton->setEnabled(false); + ui->sesContinueButton->setEnabled(false); + }else if(status == SEQ_PAUSE_STATUS && isses == EnumNotSes){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(true); + ui->stopButton->setEnabled(true); + ui->sesStartButton->setEnabled(false); + ui->sesContinueButton->setEnabled(false); + }else if(status == SEQ_PAUSE_STATUS && isses == EnumSes){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(true); + ui->sesStartButton->setEnabled(false); + ui->sesContinueButton->setEnabled(true); + }else if(status == SEQ_RESTING_STATUS){ + ui->startButton->setEnabled(true); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(false); + ui->sesStartButton->setEnabled(true); + ui->sesContinueButton->setEnabled(false); + }else if(status == SEQ_TRIGGERED_STATUS){ + ui->startButton->setEnabled(true); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(true); + ui->sesStartButton->setEnabled(true); + ui->sesContinueButton->setEnabled(false); + }else if(status == SEQ_FAILED_STATUS + || status == SEQ_SUCCESS_STATUS + ||status == SEQ_STOP_STATUS + ||status == SEQ_SKIP_STATUS){ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(false); + ui->sesStartButton->setEnabled(false); + ui->sesContinueButton->setEnabled(false); + } +} + +bool MainWindow::initSeqDbTable() +{ + ui->dbTable->setColumnCount(14); + ui->dbTable->setHeaderLabels(QStringList()<<"名称"<<"描述"<<"车站"<<"时标"<<"执行状态" + <<"顺控类型"<<"串/并"<<"是否可用"<<"延时时间"<<"失败处理" + <<"重做次数"<<"超时时间"<<"专业"<<"目标值"); + + QHeaderView *head = ui->dbTable->header(); + head->setSectionResizeMode(QHeaderView::ResizeToContents); + + if(m_dbCtrl->openDb()){ + m_ptrConfig = new CConfigureDialog(this); + bool bRet = m_dbCtrl->remapDbTable(m_objDbContainer); + if(bRet) + { + initDbTabData(); + return true; + } + else + return false; + } + else + { + return false; + } +} + +void MainWindow::initDbTabData() +{ + SSeqDefineInfoIterator SeqDefineIter(m_objDbContainer); + + while(SeqDefineIter.hasNext()) + { + const SSeqDefineInfo* defineInfo = SeqDefineIter.getNext(); + + initDbDefineData(defineInfo); + } +} + +void MainWindow::initDbDefineData(const SSeqDefineInfo* defineInfo) +{ + QTreeWidgetItem *defineItem = new QTreeWidgetItem(ui->dbTable); + defineItem->setText(0,QString::fromStdString(defineInfo->name)); + defineItem->setText(1,QString::fromStdString(defineInfo->description)); + defineItem->setText(2,m_ptrConfig->getLocationName(defineInfo->location_id)); + defineItem->setText(3,CSqlDbCtrl::timeToDT(defineInfo->timeflag)); + defineItem->setText(5,CSqlDbCtrl::SeqType(defineInfo->seq_type)); + + SSeqConfigInfoIterator SeqConfigIter(m_objDbContainer,defineInfo->name); + while(SeqConfigIter.hasNext()) + { + const SSeqConfigInfo* configInfo = SeqConfigIter.getNext(); + + initDbConfigData(configInfo, defineItem); + } +} + +void MainWindow::initDbConfigData(const SSeqConfigInfo* configInfo, QTreeWidgetItem* defineItem) +{ + QTreeWidgetItem *configItem = new QTreeWidgetItem(defineItem); + configItem->setText(0,QString::fromStdString(configInfo->func_name)); + configItem->setText(6,CSqlDbCtrl::relationType(configInfo->relation)); + SFuncInfoIterator SeqFuncIter(m_objDbContainer,configInfo->func_name); + while(SeqFuncIter.hasNext()) + { + const SFuncInfo* funcInfo = SeqFuncIter.getNext(); + + initDbFuncData(funcInfo, defineItem->text(2).toInt(), configItem); + } +} + +void MainWindow::initDbFuncData(const SFuncInfo* funcInfo, int locationId, QTreeWidgetItem* configItem) +{ + configItem->setText(1,QString::fromStdString(funcInfo->descrpition)); + configItem->setText(2,m_ptrConfig->getLocationName(locationId)); + configItem->setText(3,CSqlDbCtrl::timeToDT(funcInfo->timeflag)); + + SActionInfoIterator SeqActionIter(m_objDbContainer,funcInfo->action_name); + QTreeWidgetItem *actionItem = new QTreeWidgetItem(configItem); + initDbActionData(funcInfo, actionItem); + while(SeqActionIter.hasNext()) + { + const SActionInfo* actionInfo = SeqActionIter.getNext(); + + initDbActionData(actionInfo, actionItem); + } +} + +void MainWindow::initDbActionData(const SFuncInfo* funcInfo, QTreeWidgetItem* actionItem) +{ + actionItem->setText(7,CSqlDbCtrl::enableType(funcInfo->enable)); + actionItem->setText(8,QString("%1").arg(funcInfo->delaytime)); + actionItem->setText(9,CSqlDbCtrl::failStrageType(funcInfo->failstrage)); + actionItem->setText(10,QString("%1").arg(funcInfo->retrytimes)); +} + +void MainWindow::initDbActionData(const SActionInfo *actionInfo, QTreeWidgetItem* actionItem) +{ + actionItem->setText(0,QString::fromStdString(actionInfo->name)); + actionItem->setText(1,QString::fromStdString(actionInfo->description)); + actionItem->setText(2,m_ptrConfig->getLocationName(actionInfo->location_id)); + actionItem->setText(3,CSqlDbCtrl::timeToDT(actionInfo->timeflag)); + actionItem->setText(11,QString("%1").arg(actionInfo->ctrl_timeout)); + actionItem->setText(12,m_ptrConfig->getSubName(actionInfo->sub_system)); + actionItem->setText(13,QString("%1").arg(actionInfo->target_value)); +} + +void MainWindow::initSeqRdbTable() +{ + ui->rdbTable->setColumnCount(20); + ui->rdbTable->setHeaderLabels(QStringList()<<"名称"<<"描述"<<"选择"<<"执行方式"<<"延时时间" + <<"失败处理"<<"执行状态"<<"顺控类型"<<"开始时间"<<"车站" + <<"用户"<<"用户组"<<"主机名"<<"时标"<<"是否单步" + <<"节点类型"<<"功能序号"<<"动作序号"<<"点名"<<"目标值"); + + QHeaderView *head = ui->rdbTable->header(); + head->setSectionResizeMode(QHeaderView::ResizeToContents); +} + +QTreeWidgetItem* MainWindow::getSeqItemData(CRecoverNode& SeqRecover) +{ + QTreeWidgetItem *runSeqItem = new QTreeWidgetItem(); + runSeqItem->setText(0,QString::fromStdString(SeqRecover.nodeName())); + runSeqItem->setText(1,QString::fromStdString(SeqRecover.description())); + runSeqItem->setCheckState(2,CGetRdbDataThread::getCheckState(SeqRecover.checkState())); + runSeqItem->setText(6,CGetRdbDataThread::statusType(SeqRecover.getState())); + runSeqItem->setText(7,CSqlDbCtrl::SeqType(SeqRecover.seqType())); + runSeqItem->setText(8,CSqlDbCtrl::timeToDT(SeqRecover.startTime())); + runSeqItem->setText(9,m_ptrConfig->getLocationName(SeqRecover.locationId())); + runSeqItem->setText(10,m_ptrConfig->getUserName(SeqRecover.userId())); + runSeqItem->setText(11,m_ptrConfig->getUsergName(SeqRecover.userGrounpId())); + runSeqItem->setText(12,QString::fromStdString(SeqRecover.hostName())); + runSeqItem->setText(13,CSqlDbCtrl::timeToDT(SeqRecover.timeFlag())); + runSeqItem->setText(14,CSqlDbCtrl::isSesExe(SeqRecover.isSesExe())); + runSeqItem->setText(15,CGetRdbDataThread::nodeType(SeqRecover.nodeType())); + runSeqItem->setData(16,Qt::DisplayRole,SeqRecover.funcNo()); + runSeqItem->setData(17,Qt::DisplayRole,SeqRecover.actionNo()); + + switch(SeqRecover.nodeType()) + { + case 0: + { + runSeqItem->setText(3,QString("%1").arg("")); + runSeqItem->setText(4,QString("%1").arg("")); + runSeqItem->setText(5,QString("%1").arg("")); + break; + } + case 1: + { + runSeqItem->setText(3,CSqlDbCtrl::relationType(SeqRecover.relation())); + runSeqItem->setText(4,QString("%1").arg("")); + runSeqItem->setText(5,QString("%1").arg("")); + break; + } + case 2: + { + runSeqItem->setText(3,QString("%1").arg("")); + runSeqItem->setText(4,QString("%1").arg(SeqRecover.delayTime())); + runSeqItem->setText(5,CSqlDbCtrl::failStrageType(SeqRecover.failStrage())); + break; + } + default: + break; + } + + return runSeqItem; +} + +void MainWindow::initRunSeqData(CRecoverNodeContainer &rdbContainer) +{ + CRecoverIterator SeqIter(rdbContainer); + + while (SeqIter.hasNext()) + { + CRecoverNode& SeqRecover = SeqIter.getNext(); + updateButton((ESeqCtrl_NodeState)SeqRecover.getState(),(ESeq_Isses)SeqRecover.isSesExe()); + QTreeWidgetItem *runSeqItem = getSeqItemData(SeqRecover); + ui->rdbTable->addTopLevelItem(runSeqItem); + + initRunFuncData(SeqRecover, runSeqItem); + runSeqItem->sortChildren(16,Qt::AscendingOrder); + } + ui->rdbTable->expandAll(); +} + +void MainWindow::initRunFuncData(CRecoverNode& seqRecover, QTreeWidgetItem* runSeqItem) +{ + CRecoverIterator funcIter(seqRecover); + + while(funcIter.hasNext()) + { + CRecoverNode& funcRecover = funcIter.getNext(); + QTreeWidgetItem *runFuncItem = getSeqItemData(funcRecover); + runSeqItem->addChild(runFuncItem); + + initRunActionData(funcRecover, runFuncItem); + runFuncItem->sortChildren(17,Qt::AscendingOrder); + } +} + +void MainWindow::initRunActionData(CRecoverNode& funcRecover, QTreeWidgetItem* runFuncItem) +{ + CRecoverIterator actionIter(funcRecover); + + while(actionIter.hasNext()) + { + CRecoverNode& actionRecover = actionIter.getNext(); + QTreeWidgetItem *runActionItem = getSeqItemData(actionRecover); + runFuncItem->addChild(runActionItem); + } +} + +void MainWindow::updateData(QTreeWidgetItem* item, CRecoverNode& SeqRecoverUpdate) +{ + item->setText(6,CGetRdbDataThread::statusType(SeqRecoverUpdate.getState())); + item->setText(8,CSqlDbCtrl::timeToDT(SeqRecoverUpdate.startTime())); + item->setText(10,m_ptrConfig->getUserName(SeqRecoverUpdate.userId())); + item->setText(11,m_ptrConfig->getUsergName(SeqRecoverUpdate.userGrounpId())); + item->setText(12,QString::fromStdString(SeqRecoverUpdate.hostName())); + item->setText(14,CSqlDbCtrl::isSesExe(SeqRecoverUpdate.isSesExe())); +} + +void MainWindow::updateRunSeqData() +{ + CRecoverIterator SeqIter(m_objRdbContainer); + CRecoverIterator SeqIterUpdate(m_rdbDataThread->m_objUpdateContainer); + + while (SeqIter.hasNext() && SeqIterUpdate.hasNext()) + { + CRecoverNode& SeqRecover = SeqIter.getNext(); + CRecoverNode& SeqRecoverUpdate = SeqIterUpdate.getNext(); + updateButton((ESeqCtrl_NodeState)SeqRecoverUpdate.getState(),(ESeq_Isses)SeqRecoverUpdate.isSesExe()); + + if(SeqRecover.getState() != SeqRecoverUpdate.getState()) + { + QTreeWidgetItem *runSeqItem = ui->rdbTable->topLevelItem(0); + updateData(runSeqItem, SeqRecoverUpdate); + isUpdate = true; + } + updateRunFuncData(SeqRecover, SeqRecoverUpdate); + if((SeqRecoverUpdate.getState() == 0) && isUpdate) + { + resumeRunTab(); + isUpdate = false; + } + } +} + +void MainWindow::updateRunFuncData(CRecoverNode& seqRecover, CRecoverNode& seqRecoverUpdate) +{ + CRecoverIterator funcIter(seqRecover); + CRecoverIterator funcIterUpdate(seqRecoverUpdate); + while(funcIter.hasNext() && funcIterUpdate.hasNext()) + { + CRecoverNode& funcRecover = funcIter.getNext(); + CRecoverNode& funcRecoverUpdate = funcIterUpdate.getNext(); + if(funcRecover.getState() != funcRecoverUpdate.getState()) + { + QTreeWidgetItem *runFuncItem = getItemByNo(funcRecoverUpdate.funcNo(), funcRecoverUpdate.actionNo()); + updateData(runFuncItem, funcRecoverUpdate); + } + updateRunActionData(funcRecover, funcRecoverUpdate); + } +} + +void MainWindow::updateRunActionData(CRecoverNode& funcRecover, CRecoverNode& funcRecoverUpdate) +{ + CRecoverIterator actionIter(funcRecover); + CRecoverIterator actionIterUpdate(funcRecoverUpdate); + + while(actionIter.hasNext() && actionIterUpdate.hasNext()) + { + CRecoverNode& actionRecover = actionIter.getNext(); + CRecoverNode& actionRecoverUpdate = actionIterUpdate.getNext(); + + if(actionRecover.getState() != actionRecoverUpdate.getState()) + { + QTreeWidgetItem *runActionItem = getItemByNo(actionRecoverUpdate.funcNo(), actionRecoverUpdate.actionNo()); + updateData(runActionItem, actionRecoverUpdate); + } + } +} + +void MainWindow::slot_updateRunTab() +{ + updateRunTab(); +} + +bool MainWindow::updateRunTab() +{ + CGetRdbDataThreadLocker locker(*m_rdbDataThread); + + if(m_rdbDataThread->m_objUpdateContainer.isEmpty()) + { + return false; + } + + if(m_objRdbContainer.isEmpty()) + { + m_objRdbContainer = m_rdbDataThread->m_objUpdateContainer; + initRunSeqData(m_objRdbContainer); + } + else + { + updateRunSeqData(); + } + return true; +} + +QList MainWindow::getDomainId() +{ + QList domainIdList; + QTreeWidgetItemIterator it(ui->dbTable); + while(*it){ + if((*it)->parent()){ + ++it; + continue; + } + else{ + int locationId = m_ptrConfig->getLocationIdBySeqName((*it)->text(0)); + int domainId = m_ptrConfig->getDomainIdByLocationId(locationId); + int i = 0; + for(; ichildCount();++i) + { + item->child(i)->setCheckState(column,item->checkState(column)); + if(item->child(i)->childCount() != 0) + for(int j = 0;jchild(i)->childCount();++j) + { + item->child(i)->child(j)->setCheckState(column,item->checkState(column)); + } + } + + QTreeWidgetItem *parent = item->parent(); + if(parent != 0) + { + parent->setCheckState(column,item->checkState(column)); + if(parent->parent() != 0) + parent->parent()->setCheckState(column,item->checkState(column)); + + for(int j = 0;jchildCount();++j) + { + if(parent->checkState(column) != parent->child(j)->checkState(column)) + parent->setCheckState(column,Qt::PartiallyChecked); + } + + if(parent->parent() != 0) + { + for(int j = 0; jparent()->childCount(); ++j) + { + if(parent->parent()->checkState(column) != parent->parent()->child(j)->checkState(column)) + parent->parent()->setCheckState(column, Qt::PartiallyChecked); + } + } + } +} + +void MainWindow::slot_configUserInfo() +{ + m_ptrConfig->exec(); + + m_stUserInfo = m_ptrConfig->getConfigurInfo(); +} + +void MainWindow::slot_search() +{ + RunTabTimer->stop(); + m_strSeqName = ""; + m_objRdbContainer.clearData(); + QString key = ui->lineEdit->text(); + QRegExp re("\\S*"+key+"\\S*"); + ui->dbTable->clear(); + ui->rdbTable->clear(); + + SSeqDefineInfoIterator SeqDefineIter(m_objDbContainer); + + while(SeqDefineIter.hasNext()) + { + const SSeqDefineInfo *defineInfo = SeqDefineIter.getNext(); + if(re.exactMatch(QString::fromStdString(defineInfo->name))) + { + initDbDefineData(defineInfo); + } + } +} + +void MainWindow::slot_refreshChanged(int arg1) +{ + if(arg1 == 2 && !refreshBuf.isEmpty()) + { + for(int i = 0;i < refreshBuf.size();++i){ + QMetaObject::invokeMethod(this, "slot_showMsg", + Qt::QueuedConnection, Q_ARG(QString, refreshBuf.at(i))); + } + refreshBuf.clear(); + } +} + +void MainWindow::initButton() +{ + ui->startButton->setEnabled(false); + ui->pauseButton->setEnabled(false); + ui->continueButton->setEnabled(false); + ui->stopButton->setEnabled(false); + ui->sesStartButton->setEnabled(false); + ui->sesContinueButton->setEnabled(false); +} + +void MainWindow::initUserInfo() +{ + m_stUserInfo = m_ptrConfig->getConfigurInfo(); +} + +QTreeWidgetItem* MainWindow::getItemByNo(int funcNo, int actionNo) +{ + QTreeWidgetItemIterator it(ui->rdbTable); + while(*it) + { + if((*it)->text(16).toInt() == funcNo + && (*it)->text(17).toInt()== actionNo) + { + return *it; + } + ++it; + } + return NULL; +} diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.h b/product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.h new file mode 100644 index 00000000..e4137ab4 --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.h @@ -0,0 +1,109 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "CSequenceForHmiApiInterface.h" +#include "predifineforseqserver.h" +#include "CRdbSeqRunningAccess.h" +#include +#include +#include "CSeqDbContainer.h" +#include "CSqlDbCtrl.h" +#include "CGetRdbDataThread.h" +#include "CRefreshExeStatusThread.h" +#include "CConfigureDialog.h" +#include "CSetSeqMsgInfo.h" +#include "pub_widget/CustomMainWindow.h" + +namespace Ui { + class MainWindow; +} + +class QAbstractButton; +class QListWidget; +class QListWidgetItem; +class MainWindow : public CustomUiMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + void quit(); + + void showMsg(const QString& msg); + + void showUiMsg(const QString& msgStr, + UiRequestMessage& msg);//人工干预 + +private slots: + void slot_showMsg(const QString& msg); + void slot_showUiMsg(const QString& msg, void* pData);//人工干预 + void slot_start(); + void slot_stop(); + void slot_continue(); + void slot_pause(); + void slot_sesStart(); + void slot_sesContinue(); + void slot_itemClicked(QTreeWidgetItem *item, int column); + void slot_itemCheckChange(QTreeWidgetItem *item, int column); + void slot_configUserInfo(); + void slot_search(); + void slot_refreshChanged(int arg1); + void slot_updateStatus(); + void slot_updateRunTab(); + +private: + bool initSeqDbTable(); + void initSeqRdbTable(); + void initButton(); + void initUserInfo(); + + void initDbTabData(); + void initDbDefineData(const SSeqDefineInfo *defineInfo); + void initDbConfigData(const SSeqConfigInfo *configInfo, QTreeWidgetItem *defineItem); + void initDbFuncData(const SFuncInfo *funcInfo, int locationId, QTreeWidgetItem *configItem); + void initDbActionData(const SFuncInfo *funcInfo, QTreeWidgetItem *actionItem); + void initDbActionData(const SActionInfo *actionInfo, QTreeWidgetItem *actionItem); + + bool updateRunTab(); + QTreeWidgetItem *getSeqItemData(CRecoverNode &SeqRecover); + void initRunSeqData(CRecoverNodeContainer& rdbContainer); + void initRunFuncData(CRecoverNode &seqRecover, QTreeWidgetItem *runSeqItem); + void initRunActionData(CRecoverNode &funcRecover, QTreeWidgetItem *runFuncItem); + void updateData(QTreeWidgetItem *item, CRecoverNode &SeqRecoverUpdate); + void updateRunSeqData(); + void updateRunFuncData(CRecoverNode &seqRecover, CRecoverNode &seqRecoverUpdate); + void updateRunActionData(CRecoverNode &funcRecover, CRecoverNode &funcRecoverUpdate); + void resumeRunTab(); + void updateButton(const ESeqCtrl_NodeState &status, const ESeq_Isses &isses); + + QList getDomainId(); + SSetReqMsg getReqMsgObj(); + QTreeWidgetItem *getItemByNo(int funcNo, int actionNo); + +private: + Ui::MainWindow *ui; + CSequenceForHmiApiInterface * m_ptrInterface; + CSqlDbCtrl * m_dbCtrl; + CGetRdbDataThread * m_rdbDataThread; + CRefreshExeStateThread * m_refreshState; + CSeqDbContainer m_objDbContainer; + CRecoverNodeContainer m_objRdbContainer; + QListWidget* m_ptrShowMsgList; + QMessageBox m_objMsgBox; + QAbstractButton * m_btnRetry; + QAbstractButton * m_btnStop; + QAbstractButton * m_btnSkip; + QTimer *RunTabTimer; + QTimer *exeStatusTimer; + bool isUpdate; + QStringList refreshBuf; + SUserInfo m_stUserInfo; + CConfigureDialog *m_ptrConfig; + std::string m_strSeqName; + +}; + +#endif // MAINWINDOW_H diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.ui b/product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.ui new file mode 100644 index 00000000..bf48642b --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/mainwindow.ui @@ -0,0 +1,359 @@ + + + MainWindow + + + + 0 + 0 + 748 + 603 + + + + MainWindow + + + + + + + + + 开始 + + + + + + + 暂停 + + + + + + + 继续 + + + + + + + 停止 + + + + + + + 单步开始 + + + + + + + 单步执行 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + 清空 + + + + + + + 刷新 + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 1 + + + + + + + + + 1 + + + + + + + + + + + 搜索 + + + + + + + + + 0 + 0 + 748 + 25 + + + + + 配置 + + + + + + + + + 初始信息 + + + + + + + pushButton_5 + clicked() + listWidget + clear() + + + 737 + 441 + + + 533 + 568 + + + + + startButton + clicked() + MainWindow + slot_start() + + + 737 + 224 + + + 300 + 72 + + + + + stopButton + clicked() + MainWindow + slot_stop() + + + 737 + 326 + + + 541 + 34 + + + + + pauseButton + clicked() + MainWindow + slot_pause() + + + 737 + 258 + + + 212 + 74 + + + + + continueButton + clicked() + MainWindow + slot_continue() + + + 737 + 292 + + + 646 + 28 + + + + + sesStartButton + clicked() + MainWindow + slot_sesStart() + + + 737 + 360 + + + 643 + 56 + + + + + sesContinueButton + clicked() + MainWindow + slot_sesContinue() + + + 737 + 394 + + + 659 + 80 + + + + + dbTable + itemClicked(QTreeWidgetItem*,int) + MainWindow + slot_itemClicked(QTreeWidgetItem*,int) + + + 712 + 116 + + + 741 + 116 + + + + + rdbTable + itemClicked(QTreeWidgetItem*,int) + MainWindow + slot_itemCheckChange(QTreeWidgetItem*,int) + + + 650 + 406 + + + 744 + 230 + + + + + pushButton_8 + clicked() + MainWindow + slot_search() + + + 724 + 42 + + + 743 + 34 + + + + + checkBox + stateChanged(int) + MainWindow + slot_refreshChanged(int) + + + 692 + 479 + + + 696 + 506 + + + + + + slot_start() + slot_stop() + slot_pause() + slot_continue() + slot_sesStart() + slot_sesContinue() + slot_itemClicked(QTreeWidgetItem*,int) + slot_itemCheckChange(QTreeWidgetItem*,int) + slot_search() + slot_refreshChanged(int) + + diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/predifineforseqserver.h b/product/src/tools/link_seq_tool/sequence_server_tool/predifineforseqserver.h new file mode 100644 index 00000000..93ade86b --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/predifineforseqserver.h @@ -0,0 +1,158 @@ +#pragma once +/*! + * @breif 顺控的定义 + * + * @author sjq + * @date 五月 2018 + */ + +#include +#include +#include "common/DataType.h" + +static const std::string SEQUENCE_PROCESSNAME = "sequence_server"; + +static const std::string CONFING_IS_CREATE_ALARM = "isGenAlarmToOpt"; +static const std::string CONFING_UI_TIMER_TO_SEND_SECONDS = "UiTimerToSendSeconds"; + +//配置用户信息 +struct SUserInfo +{ + QString user_name; + QString userg_Name; + QString host_name; + QString domain_name; + QString location_name; +}; + +//运行表恢复为未执行状态 +struct SResumeRunData +{ + QString status = "未执行"; + QString trigger_time = "0"; + QString start_time = "0"; + QString user_name = " "; + QString userg_name = " "; + QString host_name = " "; + QString isses = "不是"; +}; + +//是否单步执行 +enum ESeq_Isses +{ + EnumNotSes = 0, //不是单步 + EnumSes = 1 //单步 +}; + +//顺控操作类型 +enum ESeqCtrl_HmiOpType +{ + OP_SEQ_START = 0,//顺控开始 + OP_SEQ_STOP = 1,//顺控终止 + OP_SEQ_PAUSE = 2,//暂停 + OP_SEQ_CONTINUE = 3,//继续 + OP_SES_START = 4,//单步开始 + OP_SES_CONTINUE = 5,//单步继续 +}; + +//顺控执行状态 +enum ESeqCtrl_NodeState +{ + SEQ_RESTING_STATUS = 0, /*未执行 */ + SEQ_RUNNING_STATUS = 1,/* 正在执行 */ + SEQ_TRIGGERED_STATUS = 2,/* 已触发 */ + SEQ_FAILED_STATUS = 3,/* 执行失败 */ + SEQ_SUCCESS_STATUS = 4,/* 执行成功 */ + SEQ_STOP_STATUS = 5,/* 执行终止 */ + SEQ_PAUSE_STATUS = 6,/* 执行暂停 */ + SEQ_SKIP_STATUS = 7,/* 执行跳过 */ +}; + + +enum ESeqCtrl_FailedActionType +{ + //顺控动作失败处理 + SEQ_ACT_FAILED_CONTINUE = 0,/* 跳过失败动作 */ + SEQ_ACT_FAILED_HMI_CONTROL = 1,/* 人工干预 */ + SEQ_ACT_FAILED_EXIT = 2,/* 终止 */ + SEQ_ACT_FAILED_AUTO_RETRY = 3,/* 自动重做 */ +}; + + +//人工干预执行 操作 结果 +enum UI_OP_RESULT_TYPE +{ + UI_TYPE_INIT = 0,//初始化状态 + UI_TYPE_RETYR = 1,//重试 + UI_TYPE_STOP = 2,//终止 + UI_TYPE_SKIP = 3,//跳过 +}; + +//OPT 执行的操作结果 +enum OPT_RESPONSE_TYPE +{ + OPT_RESPONSE_TYPE_INIT,//还未返回 + OPT_RESPONSE_TYPE_FAILED,//执行失败 + OPT_RESPONSE_TYPE_SUCCESS,//执行成功 +}; + +// 顺控执行者 +struct SNodeSeqActor +{ + int user_id; + int user_grounp_id; + std::string host_name; + std::string user_name; +}; + +//opt 操作结果 +struct SOptResult +{ + std::string keyTag; + OPT_RESPONSE_TYPE resultCode; + std::string resultDesc; +}; + + +//hmi 操作 信息 +struct SHmiOpInfo +{ + ESeqCtrl_HmiOpType eResult; + SNodeSeqActor actor; +}; + + +//人工干预 +struct SOpResultUi +{ + UI_OP_RESULT_TYPE eResult; + SNodeSeqActor actor; +}; + +/*! @brief 人工干预应答信息*/ +struct SUiResultInfo +{ + std::string seqName; + std::string funcName; + std::string actionName; + uint64 seqTimeFlag; + uint64 funcTimeFlag; + uint64 actionTimeFlag; + SOpResultUi result; +}; + +//动作执行错误信息 +struct SActionErrorInfo +{ + int nCode; + std::string erroStr; + SActionErrorInfo() : + nCode(0), erroStr() + { + }; + SActionErrorInfo(int code, const std::string& str) + :nCode(code), erroStr(str) + { + }; +}; + diff --git a/product/src/tools/link_seq_tool/sequence_server_tool/sequence_server_tool.pro b/product/src/tools/link_seq_tool/sequence_server_tool/sequence_server_tool.pro new file mode 100644 index 00000000..b4d04bce --- /dev/null +++ b/product/src/tools/link_seq_tool/sequence_server_tool/sequence_server_tool.pro @@ -0,0 +1,93 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-05-28T09:42:46 +# +#------------------------------------------------- + +QT += core gui sql + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = sequence_server_tool +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + CSequenceForHmiApiInterface.cpp \ + CSeqDbContainer.cpp \ + CSqlDbCtrl.cpp \ + CRecoverNode.cpp \ + CRecoverNodeContainer.cpp \ + CRdbSeqRunningAccess.cpp \ + CGetRdbDataThread.cpp \ + CRefreshExeStatusThread.cpp \ + CConfigureDialog.cpp \ + CSetSeqMsgInfo.cpp + +HEADERS += \ + mainwindow.h \ + CSequenceForHmiApiInterface.h \ + DbTableDefine.h \ + CSeqDbContainer.h \ + CSqlDbCtrl.h \ + CRecoverNode.h \ + CRecoverNodeContainer.h \ + CRdbSeqRunningAccess.h \ + CGetRdbDataThread.h \ + CRefreshExeStatusThread.h \ + predifineforseqserver.h \ + CConfigureDialog.h \ + CSetSeqMsgInfo.h + +FORMS += \ + mainwindow.ui \ + CConfigureDialog.ui + +HEADERS += \ + ../../../idl_files/SequenceMessage.pb.h \ + ../../../include/application/sequence_server_api/CSeqApiExport.h \ + ../../../include/application/sequence_server_api/CSeqForHmiApi.h + +DISTFILES += \ + ../../../idl_files/SequenceMessage.proto + +LIBS += \ + -lpub_logger_api \ + -llog4cplus \ + -lprotobuf \ + -lnet_msg_bus_api \ + -lsequence_server_api \ + -ldb_sysinfo_api \ + -ldb_base_api \ + -ldb_api_ex \ + -lboost_date_time \ + -lboost_system \ + -lboost_thread \ + -lrdb_net_api \ + -lpub_utility_api \ + -lrdb_api \ + -lpub_widget + +#------------------------------------------------------------------- + +include($$PWD/../../../idl_files/idl_files.pri) + +COMMON_PRI=$$PWD/../../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CDbContainer.cpp b/product/src/tools/link_seq_tool/trigger_tool/CDbContainer.cpp new file mode 100644 index 00000000..8cc62466 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CDbContainer.cpp @@ -0,0 +1,129 @@ +#include "CDbContainer.h" + +CDbContainer::CDbContainer() +{ +} + +CDbContainer::~CDbContainer() +{ + clearAll(); +} + +void CDbContainer::clearAll() +{ + clearTimer(); + clearPeriod(); + clearFunction(); + clearCondition(); +} + +void CDbContainer::clearTimer() +{ + TTimerMap::iterator iter = m_mapTimerMap.begin(); + for (; iter != m_mapTimerMap.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapTimerMap.clear(); +} + +void CDbContainer::pushTimer(STimerDefine* info) +{ + m_mapTimerMap.insert(std::make_pair(info->tag_name, info)); +} + +void CDbContainer::clearPeriod() +{ + TPeriodMap::iterator iter = m_mapPeriodMap.begin(); + for (; iter != m_mapPeriodMap.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapPeriodMap.clear(); +} + +void CDbContainer::pushPeriod(SPeriodDefine* info) +{ + m_mapPeriodMap.insert(std::make_pair(info->tag_name, info)); +} + +void CDbContainer::clearFunction() +{ + TFunctionMap::iterator iter = m_mapFunctionMap.begin(); + for (; iter != m_mapFunctionMap.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapFunctionMap.clear(); +} + +void CDbContainer::pushFunction(SFunctionDefine* info) +{ + m_mapFunctionMap.insert(std::make_pair(info->func_name, info)); +} + +void CDbContainer::clearCondition() +{ + TConditionMap::iterator iter = m_mapConditionMap.begin(); + for (; iter != m_mapConditionMap.end(); ++iter) + { + delete iter->second; + iter->second = NULL; + } + m_mapConditionMap.clear(); +} + +void CDbContainer::pushCondition(SConditionDefine* info) +{ + m_mapConditionMap.insert(std::make_pair(info->tag_name, info)); +} + + +QString CDbContainer::getTriggerTypeStr(TriggerType type) +{ + QString retStr; + switch (type) + { + case TRIGGERTYPE_ALL: + retStr = "全部"; + break; + case TRIGGERTYPE_CONDITION: + retStr = "条件触发"; + break; + case TRIGGERTYPE_TIMER: + retStr = "定时触发"; + break; + case TRIGGERTYPE_PERIOD: + retStr = "周期触发"; + break; + default: + break; + } + + return retStr; +}; + +QString CDbContainer::getTriggerTypeStr(iot_app::CTriggerPara::TRIGGER_TYPE type) +{ + QString retStr; + using namespace iot_app; + switch (type) + { + case CTriggerPara::TRIGGER_TYPE_CONDITION: + retStr = "条件触发"; + break; + case CTriggerPara::TRIGGER_TYPE_TIMER: + retStr = "定时触发"; + break; + case CTriggerPara::TRIGGER_TYPE_PERIOD: + retStr = "周期触发"; + break; + default: + break; + } + + return retStr; +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CDbContainer.h b/product/src/tools/link_seq_tool/trigger_tool/CDbContainer.h new file mode 100644 index 00000000..40709319 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CDbContainer.h @@ -0,0 +1,39 @@ +#pragma once +#include "TriggerCommonDefine.h" +#include "application/trigger_api/CTriggerApi.h" + +class CDbContainer +{ +public: + CDbContainer(); + ~CDbContainer(); + + void clearAll(); + + void clearTimer(); + void pushTimer(STimerDefine* info); + + void clearPeriod(); + void pushPeriod(SPeriodDefine* info); + + void clearFunction(); + void pushFunction(SFunctionDefine* info); + + void clearCondition(); + void pushCondition(SConditionDefine* info); + + static QString getTriggerTypeStr(TriggerType type); + static QString getTriggerTypeStr(iot_app::CTriggerPara::TRIGGER_TYPE type); +protected: + friend class CIterator; + friend class STimerIterator; + friend class SPeriodIterator; + friend class SFunctionIterator; + friend class SConditionIterator; + + TTimerMap m_mapTimerMap; + TPeriodMap m_mapPeriodMap; + TFunctionMap m_mapFunctionMap; + TConditionMap m_mapConditionMap; +}; + diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditBaseWidget.cpp b/product/src/tools/link_seq_tool/trigger_tool/CEditBaseWidget.cpp new file mode 100644 index 00000000..e7f9da52 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditBaseWidget.cpp @@ -0,0 +1,35 @@ +#include "CEditBaseWidget.h" + +CEditBaseWidget::CEditBaseWidget(QWidget *parent) + : QWidget(parent) +{ +} + +CEditBaseWidget::~CEditBaseWidget() +{ +} + +void CEditBaseWidget::setParam(SBaseDefine* info) +{ + +} + +bool CEditBaseWidget::del(const QString& name) +{ + return false; +} + +bool CEditBaseWidget::add() +{ + return false; +} + +bool CEditBaseWidget::update(const QString& name) +{ + return false; +} + +QString CEditBaseWidget::getName() +{ + return QString(); +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditBaseWidget.h b/product/src/tools/link_seq_tool/trigger_tool/CEditBaseWidget.h new file mode 100644 index 00000000..1a35c154 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditBaseWidget.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include "TriggerCommonDefine.h" + +class CEditBaseWidget : public QWidget +{ + Q_OBJECT + +public: + CEditBaseWidget(QWidget *parent = Q_NULLPTR); + virtual ~CEditBaseWidget(); + + virtual void setParam(SBaseDefine* info); + virtual bool del(const QString& name); + virtual bool add(); + virtual bool update(const QString& name); + virtual QString getName(); +}; diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.cpp b/product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.cpp new file mode 100644 index 00000000..70dd4038 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.cpp @@ -0,0 +1,26 @@ +#include "CEditConditionWidget.h" + +CEditConditionWidget::CEditConditionWidget(QWidget *parent) + : CEditBaseWidget(parent) +{ + ui.setupUi(this); +} + +CEditConditionWidget::~CEditConditionWidget() +{ +} + +void CEditConditionWidget::setParam(SBaseDefine* info) +{ + ui.lineEdit->setText(info->tag_name); +} + +const SBaseDefine& CEditConditionWidget::getParam() +{ + return SBaseDefine(); +} + +bool CEditConditionWidget::checkParam() +{ + return false; +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.h b/product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.h new file mode 100644 index 00000000..842f7b77 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include "ui_CEditConditionWidget.h" +#include "TriggerCommonDefine.h" +#include "CEditBaseWidget.h" + +class CEditConditionWidget : public CEditBaseWidget +{ + Q_OBJECT + +public: + CEditConditionWidget(QWidget *parent = Q_NULLPTR); + ~CEditConditionWidget(); + + void setParam(SBaseDefine* info); + const SBaseDefine& getParam(); + bool checkParam(); +private: + Ui::CEditConditionWidget ui; +}; diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.ui b/product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.ui new file mode 100644 index 00000000..0af7ea80 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditConditionWidget.ui @@ -0,0 +1,32 @@ + + + CEditConditionWidget + + + + 0 + 0 + 400 + 300 + + + + CEditConditionWidget + + + + + + 名称 + + + + + + + + + + + + diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditDialog.cpp b/product/src/tools/link_seq_tool/trigger_tool/CEditDialog.cpp new file mode 100644 index 00000000..45b3cfc1 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditDialog.cpp @@ -0,0 +1,187 @@ +#include "CEditDialog.h" +#include "ui_CEditDialog.h" +#include "CEditTimerWidget.h" +#include "CEditPeriodWidget.h" +#include "CEditConditionWidget.h" +#include +#include "CDbContainer.h" +#include "CIterator.h" + +CEditDialog::CEditDialog(CDbContainer& container, QWidget *parent) : + CustomUiDialog(parent), + ui(new Ui::CEditDialog), + m_objContainer(container) +{ + ui->setupUi(this); + setWindowTitle("触发器编辑"); + + m_typeCbb = ui->comboBox; + m_nameCbb = ui->comboBox_2; + m_stacked = ui->stackedWidget; + m_addBtn = ui->pushButton_3; + m_delBtn = ui->pushButton_2; + m_updateBtn = ui->pushButton; + m_cannelBtn = ui->pushButton_4; + + m_conditionWidget = new CEditConditionWidget(m_stacked); + m_timerWidget = new CEditTimerWidget(m_stacked); + m_periodWidget = new CEditPeriodWidget(m_stacked); + + m_typeCbb->addItem("条件触发"); + m_typeCbb->addItem("定时触发"); + m_typeCbb->addItem("周期触发"); + + m_stacked->addWidget(m_conditionWidget); + m_stacked->addWidget(m_timerWidget); + m_stacked->addWidget(m_periodWidget); + m_editWidgetList.append(m_conditionWidget); + m_editWidgetList.append(m_timerWidget); + m_editWidgetList.append(m_periodWidget); + + connect(m_typeCbb, SIGNAL(currentIndexChanged(int)), this, SLOT(slot_typeIndexChange(int))); + connect(m_nameCbb, SIGNAL(currentIndexChanged(int)), this, SLOT(slot_nameIndexChange(int))); + + connect(m_addBtn, SIGNAL(clicked()), this, SLOT(slot_addBtn())); + connect(m_delBtn, SIGNAL(clicked()), this, SLOT(slot_delBtn())); + connect(m_updateBtn, SIGNAL(clicked()), this, SLOT(slot_updateBtn())); + connect(m_cannelBtn, SIGNAL(clicked()), this, SLOT(slot_cannelBtn())); + + setAutoLayout(true); +} + +CEditDialog::~CEditDialog() +{ + delete ui; +} + + +void CEditDialog::setParam(SBaseDefine* info) +{ + if (!info) + { + return; + } + + m_typeCbb->setCurrentIndex((info->type-1)); + slot_typeIndexChange(m_typeCbb->currentIndex()); + + int index = m_nameCbb->findText(info->tag_name); + m_nameCbb->setCurrentIndex(index); + slot_nameIndexChange(m_nameCbb->currentIndex()); +} + +void CEditDialog::initView() +{ + int index = m_typeCbb->currentIndex(); + TriggerType type = (TriggerType)(index+1); + initView(type); +} + +void CEditDialog::initView(TriggerType type) +{ + m_nameCbb->clear(); + CIterator iter(m_objContainer, type); + while (iter.hasNext()) + { + SBaseDefine& info = iter.getNext(); + m_nameCbb->addItem(info.tag_name); + } +} + +void CEditDialog::slot_typeIndexChange(int index) +{ + m_stacked->setCurrentIndex(index); + TriggerType type = (TriggerType)(index + 1); + initView(type); +} + +void CEditDialog::slot_nameIndexChange(int) +{ + QString name = m_nameCbb->currentText(); + int index = m_typeCbb->currentIndex(); + TriggerType type = (TriggerType)(index + 1); + + CIterator iter(m_objContainer, type,name); + if (iter.hasNext()) + { + SBaseDefine& info = iter.getNext(); + CEditBaseWidget* pWidget = m_editWidgetList.at(index); + pWidget->setParam(&info); + } +} + +void CEditDialog::slot_addBtn() +{ + int type = m_typeCbb->currentIndex(); + CEditBaseWidget* pWidget = m_editWidgetList.at(type); + QString name = pWidget->getName(); + + if (!pWidget->add()) + { + QMessageBox::about(this, + "添加失败", + QString("添加[%1]失败").arg(name)); + } + else + { + QMessageBox::about(this, + "添加成功", + QString("添加[%1]成功").arg(name)); + } +} + +void CEditDialog::slot_delBtn() +{ + QString name = m_nameCbb->currentText(); + if (name.isEmpty()) + { + return; + } + + int type = m_typeCbb->currentIndex(); + CEditBaseWidget* pWidget = m_editWidgetList.at(type); + + if (!pWidget->del(name)) + { + QMessageBox::about(this, + "删除", + QString("删除[%1]失败").arg(name)); + return; + } + else + { + QMessageBox::about(this, + "删除", + QString("删除[%1]成功").arg(name)); + } +} + +void CEditDialog::slot_updateBtn() +{ + QString name = m_nameCbb->currentText(); + if (name.isEmpty()) + { + return; + } + + int type = m_typeCbb->currentIndex(); + CEditBaseWidget* pWidget = m_editWidgetList.at(type); + + if (!pWidget->update(name)) + { + QMessageBox::about(this, + "更新失败", + QString("更新[%1]失败").arg(name)); + } + else + { + QMessageBox::about(this, + "修改成功", + QString("修改[%1]成功").arg(pWidget->getName())); + } +} + +void CEditDialog::slot_cannelBtn() +{ + this->reject(); +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditDialog.h b/product/src/tools/link_seq_tool/trigger_tool/CEditDialog.h new file mode 100644 index 00000000..7e79b2e7 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditDialog.h @@ -0,0 +1,57 @@ +#ifndef CEDITDIALOG_H +#define CEDITDIALOG_H + +#include +#include "TriggerCommonDefine.h" +#include "CEditBaseWidget.h" +#include "pub_widget/CustomDialog.h" + +namespace Ui { +class CEditDialog; +} +class QLabel; +class QComboBox; +class QStackedWidget; +class CEditTimerWidget; +class CEditPeriodWidget; +class CEditConditionWidget; +class CDbContainer; +class CEditDialog : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit CEditDialog(CDbContainer& container,QWidget *parent = 0); + ~CEditDialog(); + + void setParam(SBaseDefine* info); + void initView(); + void initView(TriggerType type); +private slots: + void slot_typeIndexChange(int); + void slot_nameIndexChange(int); + void slot_addBtn(); + void slot_delBtn(); + void slot_updateBtn(); + void slot_cannelBtn(); + +private: + Ui::CEditDialog *ui; + + QComboBox* m_typeCbb; + QComboBox* m_nameCbb; + QStackedWidget* m_stacked; + CEditConditionWidget* m_conditionWidget; + CEditTimerWidget* m_timerWidget; + CEditPeriodWidget* m_periodWidget; + + QList m_editWidgetList; + QPushButton* m_addBtn; + QPushButton* m_delBtn; + QPushButton* m_updateBtn; + QPushButton* m_cannelBtn; + + CDbContainer& m_objContainer; +}; + +#endif // CEDITDIALOG_H diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditDialog.ui b/product/src/tools/link_seq_tool/trigger_tool/CEditDialog.ui new file mode 100644 index 00000000..57afa3fb --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditDialog.ui @@ -0,0 +1,119 @@ + + + CEditDialog + + + + 0 + 0 + 495 + 351 + + + + Dialog + + + + + + + + 触发器名称 + + + + + + + 触发类型 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 添加 + + + + + + + 修改 + + + + + + + 删除 + + + + + + + 取消 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.cpp b/product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.cpp new file mode 100644 index 00000000..fd4a2559 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.cpp @@ -0,0 +1,22 @@ +#include "CEditPeriodWidget.h" + +CEditPeriodWidget::CEditPeriodWidget(QWidget *parent) + : CEditBaseWidget(parent) +{ + ui.setupUi(this); +} + +CEditPeriodWidget::~CEditPeriodWidget() +{ +} + +void CEditPeriodWidget::setParam(SBaseDefine* info) +{ + +} + + +bool CEditPeriodWidget::checkParam() +{ + return false; +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.h b/product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.h new file mode 100644 index 00000000..9c1f0c6c --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include "ui_CEditPeriodWidget.h" +#include "TriggerCommonDefine.h" +#include "CEditBaseWidget.h" + +class CEditPeriodWidget : public CEditBaseWidget +{ + Q_OBJECT + +public: + CEditPeriodWidget(QWidget *parent = Q_NULLPTR); + ~CEditPeriodWidget(); + + void setParam(SBaseDefine* info); + + bool checkParam(); + +private: + Ui::CEditPeriodWidget ui; +}; diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.ui b/product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.ui new file mode 100644 index 00000000..1fa6c86d --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditPeriodWidget.ui @@ -0,0 +1,32 @@ + + + CEditPeriodWidget + + + + 0 + 0 + 400 + 300 + + + + CEditPeriodWidget + + + + + + 名称 + + + + + + + + + + + + diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.cpp b/product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.cpp new file mode 100644 index 00000000..d8440891 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.cpp @@ -0,0 +1,149 @@ +#include "CEditTimerWidget.h" +#include +#include "CSqlDbCtrl.h" + +CEditTimerWidget::CEditTimerWidget(QWidget *parent) + : CEditBaseWidget(parent) +{ + ui.setupUi(this); + m_nameEdit = ui.lineEdit; + m_descEdit = ui.textEdit; + m_timeEdit = ui.dateTimeEdit; + m_sysTimeCkb = ui.checkBox; + m_delayTimeCkb = ui.checkBox_2; + m_delayEdit = ui.spinBox; + + m_delayEdit->setValue(5); + m_delayEdit->setMinimum(0); + m_sysTimeCkb->setChecked(true); + + m_info.trigger_time + = QDateTime::currentDateTime().toSecsSinceEpoch(); + m_info.tag_name = "定时触发器1"; + + connect(m_sysTimeCkb, SIGNAL(stateChanged(int)), this, SLOT(slot_sysTimeStateChanged(int))); + connect(m_delayTimeCkb, SIGNAL(stateChanged(int)), this, SLOT(slot_delayTimeStateChanged(int))); + + initView(); + + slot_sysTimeStateChanged(m_sysTimeCkb->checkState()); + slot_delayTimeStateChanged(m_delayTimeCkb->checkState()); +} + +CEditTimerWidget::~CEditTimerWidget() +{ +} + +void CEditTimerWidget::setParam(SBaseDefine* info) +{ + m_info = (STimerDefine&)*info; + initView(); +} + +const STimerDefine& CEditTimerWidget::getParam() +{ + m_info.type = TRIGGERTYPE_TIMER; + m_info.tag_name = m_nameEdit->text(); + m_info.description = m_descEdit->toPlainText(); + m_info.trigger_time = getTriggerTime(); + + return m_info; +} + +bool CEditTimerWidget::checkParam() +{ + if (m_nameEdit->text().isEmpty()) + { + return false; + } + + return true; +} + +bool CEditTimerWidget::del(const QString& name) +{ + CSqlDbCtrl dbCtrl; + if (!dbCtrl.openDb()) + { + return false; + } + + bool bRet = dbCtrl.delTimer(name); + + return bRet; +} + +bool CEditTimerWidget::add() +{ + if (!checkParam()) + { + return false; + } + + CSqlDbCtrl dbCtrl; + if (!dbCtrl.openDb()) + { + return false; + } + + bool bRet = dbCtrl.addTimer(&m_info); + + return bRet; +} + +bool CEditTimerWidget::update(const QString& name) +{ + if (!checkParam()) + { + return false; + } + + CSqlDbCtrl dbCtrl; + if (!dbCtrl.openDb()) + { + return false; + } + + bool bRet = dbCtrl.upateTimer(name,&m_info); + + return bRet; +} + +QString CEditTimerWidget::getName() +{ + return m_nameEdit->text(); +} + +void CEditTimerWidget::initView() +{ + m_nameEdit->setText(m_info.tag_name); + m_descEdit->setText(m_info.description); + m_timeEdit->setDateTime(QDateTime::fromSecsSinceEpoch(m_info.trigger_time)); + +} + +uint64 CEditTimerWidget::getTriggerTime() +{ + uint64 retTime = 0; + if (m_sysTimeCkb->isChecked()) + { + retTime = QDateTime::currentDateTime().toSecsSinceEpoch(); + } + + if (m_delayTimeCkb->isChecked()) + { + retTime += m_delayEdit->value(); + } + + return retTime; +} + +void CEditTimerWidget::slot_sysTimeStateChanged(int state) +{ + m_timeEdit->setEnabled(state == Qt::Unchecked); +} + +void CEditTimerWidget::slot_delayTimeStateChanged(int state) +{ + m_delayEdit->setEnabled(state != Qt::Unchecked); +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.h b/product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.h new file mode 100644 index 00000000..0a0a7380 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.h @@ -0,0 +1,47 @@ +#pragma once + +#include +#include "ui_CEditTimerWidget.h" +#include "TriggerCommonDefine.h" +#include "CEditBaseWidget.h" + +class QLineEdit; +class QTextEdit; +class QDateTimeEdit; +class QCheckBox; +class QSpinBox; +class CEditTimerWidget : public CEditBaseWidget +{ + Q_OBJECT + +public: + CEditTimerWidget(QWidget *parent = Q_NULLPTR); + ~CEditTimerWidget(); + + void setParam(SBaseDefine* info); + const STimerDefine& getParam(); + bool checkParam(); + + bool del(const QString& name); + bool add(); + bool update(const QString& name); + QString getName(); +private: + void initView(); + uint64 getTriggerTime(); + +private slots: + void slot_sysTimeStateChanged(int); + void slot_delayTimeStateChanged(int); + +private: + Ui::CEditTimerWidget ui; + STimerDefine m_info; + + QLineEdit* m_nameEdit; + QTextEdit* m_descEdit; + QDateTimeEdit* m_timeEdit; + QCheckBox* m_sysTimeCkb; + QCheckBox* m_delayTimeCkb; + QSpinBox* m_delayEdit; +}; diff --git a/product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.ui b/product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.ui new file mode 100644 index 00000000..18e3bcc3 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CEditTimerWidget.ui @@ -0,0 +1,140 @@ + + + CEditTimerWidget + + + + 0 + 0 + 345 + 323 + + + + CEditTimerWidget + + + + + + + + 触发名 + + + + + + + + + + 触发描述 + + + + + + + + + + 定时时间 + + + + + + + + + 系统时间 + + + + + + + + + + 延迟时间 + + + + + + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + diff --git a/product/src/tools/link_seq_tool/trigger_tool/CIterator.cpp b/product/src/tools/link_seq_tool/trigger_tool/CIterator.cpp new file mode 100644 index 00000000..84c44458 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CIterator.cpp @@ -0,0 +1,281 @@ +#include "boost/assert.hpp" + +#include "CIterator.h" +#include "CDbContainer.h" + +CIterator::CIterator() +{ + m_vec.clear(); + m_iter = m_vec.begin(); +} + +CIterator::CIterator(const CDbContainer& container) +{ + readTimer(container); + readPeriod(container); + readCondition(container); + m_iter = m_vec.begin(); +} + +CIterator::CIterator(const CDbContainer& container, + TriggerType type, + const QString& name) +{ + switch (type) + { + case TRIGGERTYPE_ALL: + readCondition(container, name); + readTimer(container, name); + readPeriod(container, name); + break; + case TRIGGERTYPE_CONDITION: + readCondition(container, name); + break; + case TRIGGERTYPE_TIMER: + readTimer(container, name); + break; + case TRIGGERTYPE_PERIOD: + readPeriod(container, name); + break; + default: + break; + } + m_iter = m_vec.begin(); +} + +CIterator::CIterator(const CDbContainer& container, + TriggerType type) +{ + switch (type) + { + case TRIGGERTYPE_ALL: + readCondition(container); + readTimer(container); + readPeriod(container); + break; + case TRIGGERTYPE_CONDITION: + readCondition(container); + break; + case TRIGGERTYPE_TIMER: + readTimer(container); + break; + case TRIGGERTYPE_PERIOD: + readPeriod(container); + break; + default: + break; + } + m_iter = m_vec.begin(); +} + +void CIterator::readTimer(const CDbContainer& container) +{ + TTimerMap::const_iterator iter + = container.m_mapTimerMap.begin(); + for (; iter != container.m_mapTimerMap.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +void CIterator::readTimer(const CDbContainer& container, const QString& name) +{ + TTimerMap::const_iterator iter + = container.m_mapTimerMap.find(name); + if (iter != container.m_mapTimerMap.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +void CIterator::readPeriod(const CDbContainer& container) +{ + TPeriodMap::const_iterator iter + = container.m_mapPeriodMap.begin(); + for (; iter != container.m_mapPeriodMap.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +void CIterator::readPeriod(const CDbContainer& container, const QString& name) +{ + TPeriodMap::const_iterator iter + = container.m_mapPeriodMap.find(name); + if (iter != container.m_mapPeriodMap.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +void CIterator::readCondition(const CDbContainer& container) +{ + TConditionMap::const_iterator iter + = container.m_mapConditionMap.begin(); + for (; iter != container.m_mapConditionMap.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +void CIterator::readCondition(const CDbContainer& container, const QString& name) +{ + TConditionMap::const_iterator iter + = container.m_mapConditionMap.find(name); + if (iter != container.m_mapConditionMap.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +CIterator::~CIterator() +{ + m_vec.clear(); +} + +bool CIterator::hasNext() const +{ + return m_iter != m_vec.end(); +} + +SBaseDefine& CIterator::getNext() +{ + SBaseDefine *pNode = *m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} + +STimerIterator::STimerIterator(const CDbContainer& container) + :CIterator(container, TRIGGERTYPE_TIMER) +{ + +} + +STimerIterator::STimerIterator( + const CDbContainer& container, + const QString& name) + : CIterator(container , TRIGGERTYPE_TIMER, name) +{ + +} + +STimerIterator::~STimerIterator() +{ +} + +STimerDefine& STimerIterator::getNext() +{ + STimerDefine *pNode = (STimerDefine *)*m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} + +SPeriodIterator::SPeriodIterator(const CDbContainer& container) + :CIterator(container, TRIGGERTYPE_PERIOD) +{ + +} + +SPeriodIterator::SPeriodIterator( + const CDbContainer& container, + const QString& name) + : CIterator(container, TRIGGERTYPE_PERIOD,name) +{ +} + +SPeriodIterator::~SPeriodIterator() +{ + +} + +SPeriodDefine& SPeriodIterator::getNext() +{ + SPeriodDefine *pNode = (SPeriodDefine *)*m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} + +SFunctionIterator::SFunctionIterator(const CDbContainer& container) +{ + TFunctionMap::const_iterator iter + = container.m_mapFunctionMap.begin(); + for (; iter != container.m_mapFunctionMap.end(); ++iter) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SFunctionIterator::SFunctionIterator( + const CDbContainer& container, + const QString& name) +{ + TFunctionMap::const_iterator iter + = container.m_mapFunctionMap.find(name); + if (iter != container.m_mapFunctionMap.end()) + { + m_vec.push_back(iter->second); + } + + m_iter = m_vec.begin(); +} + +SFunctionIterator::~SFunctionIterator() +{ + m_vec.clear(); +} + +bool SFunctionIterator::hasNext() const +{ + return m_iter != m_vec.end(); +} + +SFunctionDefine& SFunctionIterator::getNext() +{ + SFunctionDefine *pNode = *m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} + +SConditionIterator::SConditionIterator(const CDbContainer& container) + :CIterator(container, TRIGGERTYPE_CONDITION) +{ +} + +SConditionIterator::SConditionIterator( + const CDbContainer& container, + const QString& name) + : CIterator(container, TRIGGERTYPE_CONDITION,name) +{ + +} + +SConditionIterator::~SConditionIterator() +{ + +} + +SConditionDefine& SConditionIterator::getNext() +{ + SConditionDefine *pNode = (SConditionDefine *)*m_iter; + BOOST_ASSERT(pNode); + ++m_iter; + return *pNode; +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CIterator.h b/product/src/tools/link_seq_tool/trigger_tool/CIterator.h new file mode 100644 index 00000000..d63405d9 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CIterator.h @@ -0,0 +1,102 @@ +#pragma once +#include "TriggerCommonDefine.h" +#include + +class CDbContainer; + +class CIterator +{ +public: + CIterator(const CDbContainer& container); + CIterator(const CDbContainer& container, + TriggerType type); + CIterator( + const CDbContainer& container, + TriggerType type, + const QString& name ); + + virtual ~CIterator(); + + virtual bool hasNext() const; + virtual SBaseDefine& getNext(); + +protected: + CIterator(); + + void readTimer(const CDbContainer& container); + void readPeriod(const CDbContainer& container); + void readCondition(const CDbContainer& container); + + void readTimer(const CDbContainer& container, const QString& name); + void readPeriod(const CDbContainer& container, const QString& name); + void readCondition(const CDbContainer& container, const QString& name); + +protected: + std::vector m_vec; + std::vector::iterator m_iter; +}; + +class STimerIterator :public CIterator +{ +public: + STimerIterator( + const CDbContainer& container); + + STimerIterator( + const CDbContainer& container, + const QString& name); + + ~STimerIterator(); + STimerDefine& getNext(); +}; + + +class SPeriodIterator :public CIterator +{ +public: + SPeriodIterator( + const CDbContainer& container); + + SPeriodIterator( + const CDbContainer& container, + const QString& name); + + ~SPeriodIterator(); + SPeriodDefine& getNext(); +private: +}; + + +class SFunctionIterator +{ +public: + SFunctionIterator( + const CDbContainer& container); + + SFunctionIterator( + const CDbContainer& container, + const QString& name); + + ~SFunctionIterator(); + bool hasNext() const; + SFunctionDefine& getNext(); +private: + std::vector m_vec; + std::vector::iterator m_iter; +}; + + +class SConditionIterator :public CIterator +{ +public: + SConditionIterator( + const CDbContainer& container); + + SConditionIterator( + const CDbContainer& container, + const QString& name); + + ~SConditionIterator(); + SConditionDefine& getNext(); + +}; \ No newline at end of file diff --git a/product/src/tools/link_seq_tool/trigger_tool/CSqlDbCtrl.cpp b/product/src/tools/link_seq_tool/trigger_tool/CSqlDbCtrl.cpp new file mode 100644 index 00000000..3353c4df --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CSqlDbCtrl.cpp @@ -0,0 +1,270 @@ +#include +#include "public/pub_logger_api/logger.h" +#include "dbms/db_sysinfo_api/CDbSysInfo.h" +#include "boost/assert.hpp" + +#include "CSqlDbCtrl.h" +#include "CDbContainer.h" + +CSqlDbCtrl::CSqlDbCtrl():m_objLocalDbConn(DB_CONN_MODEL_READ) +{ +} + +CSqlDbCtrl::~CSqlDbCtrl() +{ + if (isOpen()) + { + closeDb(); + } +} + + +bool CSqlDbCtrl::openDb() +{ + using namespace iot_dbms; + if (m_objLocalDbConn.isOpen()) { + return true; + } + + return m_objLocalDbConn.open(); +} + +bool CSqlDbCtrl::remapDbTable(CDbContainer& container) +{ + BOOST_ASSERT(m_objLocalDbConn.isOpen()); + + bool bRet = remapTimer(container); + bRet = remapPeriod(container); + bRet = remapFunction(container); + bRet = remapCondition(container); + + return bRet; +} + +bool CSqlDbCtrl::addTimer(STimerDefine* info) +{ + return false; +} + +bool CSqlDbCtrl::upateTimer(const QString& name, STimerDefine* info) +{ + return false; +} + +bool CSqlDbCtrl::delTimer(const QString& name) +{ + return false; +} + +bool CSqlDbCtrl::addPeriod(SPeriodDefine* info) +{ + return false; +} + +bool CSqlDbCtrl::upatePeriod(const QString& name, SPeriodDefine* info) +{ + return false; +} + +bool CSqlDbCtrl::delPeriod(const QString& name) +{ + return false; +} + +bool CSqlDbCtrl::addCondition(SConditionDefine* info) +{ + return false; +} + +bool CSqlDbCtrl::upateCondition(const QString& name, SConditionDefine* info) +{ + return false; +} + +bool CSqlDbCtrl::delCondition(const QString& name) +{ + return false; +} + +void CSqlDbCtrl::closeDb() +{ + m_objLocalDbConn.close(); +} + +bool CSqlDbCtrl::isOpen() +{ + return m_objLocalDbConn.isOpen(); +} + +bool CSqlDbCtrl::remapTimer(CDbContainer& container) +{ + container.clearTimer(); + + QString strExecute = QString("SELECT " + "tag_name," + "description," + "trigger_time" + " FROM trigger_timer_define "); + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + STimerDefine* info = new STimerDefine; + info->type = TRIGGERTYPE_TIMER; + info->tag_name = queryTableMode.value(0).toString(); + info->description = queryTableMode.value(1).toString(); + info->trigger_time = queryTableMode.value(2).toULongLong(); + container.pushTimer(info); + } + } + + return true; +} + +bool CSqlDbCtrl::remapPeriod(CDbContainer& container) +{ + container.clearPeriod(); + + QString strExecute = QString("SELECT " + "tag_name," + "description," + "period_type," + "start_time," + "stop_time," + "period_str" + " FROM trigger_period_define "); + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SPeriodDefine* info = new SPeriodDefine; + info->type = TRIGGERTYPE_PERIOD; + info->tag_name = queryTableMode.value(0).toString(); + info->description = queryTableMode.value(1).toString(); + info->period_type = queryTableMode.value(2).toInt(); + info->start_time = queryTableMode.value(3).toULongLong(); + info->stop_time = queryTableMode.value(3).toULongLong(); + info->period_str = queryTableMode.value(3).toString(); + container.pushPeriod(info); + } + } + + return true; +} + +bool CSqlDbCtrl::remapFunction(CDbContainer& container) +{ + container.clearFunction(); + + QString strExecute = QString("SELECT " + "func_name," + "description," + "sub_system," + "func_str" + " FROM trigger_function_define "); + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SFunctionDefine* info = new SFunctionDefine; + info->func_name = queryTableMode.value(0).toString(); + info->description = queryTableMode.value(1).toString(); + info->sub_system = queryTableMode.value(2).toInt(); + info->func_str = queryTableMode.value(3).toString(); + container.pushFunction(info); + } + } + + return true; +} + +bool CSqlDbCtrl::remapCondition(CDbContainer& container) +{ + container.clearCondition(); + + QString strExecute = QString("SELECT " + "tag_name," + "description," + "sub_system," + "exe_type," + "is_repeat," + "space_time," + "function_name," + "param_count," + "param_1," + "param_2," + "param_3," + "param_4," + "param_5," + "param_6," + "param_7," + "param_8," + "param_9," + "param_10," + "param_11," + "param_12," + "param_13," + "param_14," + "param_15," + "param_16," + "param_17," + "param_18," + "param_19," + "param_20" + " FROM trigger_condition_define "); + QSqlQuery queryTableMode; + + m_objLocalDbConn.execute(strExecute, queryTableMode); + + if (queryTableMode.isActive()) + { + while (queryTableMode.next()) + { + SConditionDefine* info = new SConditionDefine; + info->type = TRIGGERTYPE_CONDITION; + info->tag_name = queryTableMode.value(0).toString(); + info->description = queryTableMode.value(1).toString(); + info->sub_system = queryTableMode.value(2).toInt(); + info->exe_type = queryTableMode.value(3).toInt(); + info->is_repeat = queryTableMode.value(4).toInt(); + info->space_time = queryTableMode.value(5).toInt(); + info->function_name = queryTableMode.value(6).toString(); + info->param_count = queryTableMode.value(7).toInt(); + info->param_1 = queryTableMode.value(8).toString(); + info->param_2 = queryTableMode.value(9).toString(); + info->param_3 = queryTableMode.value(10).toString(); + info->param_4 = queryTableMode.value(11).toString(); + info->param_5 = queryTableMode.value(12).toString(); + info->param_6 = queryTableMode.value(13).toString(); + info->param_7 = queryTableMode.value(14).toString(); + info->param_8 = queryTableMode.value(15).toString(); + info->param_9 = queryTableMode.value(16).toString(); + info->param_10 = queryTableMode.value(17).toString(); + info->param_11 = queryTableMode.value(18).toString(); + info->param_12 = queryTableMode.value(19).toString(); + info->param_13 = queryTableMode.value(20).toString(); + info->param_14 = queryTableMode.value(21).toString(); + info->param_15 = queryTableMode.value(22).toString(); + info->param_16 = queryTableMode.value(23).toString(); + info->param_17 = queryTableMode.value(24).toString(); + info->param_18 = queryTableMode.value(25).toString(); + info->param_19 = queryTableMode.value(26).toString(); + info->param_20 = queryTableMode.value(27).toString(); + container.pushCondition(info); + } + } + + return true; +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CSqlDbCtrl.h b/product/src/tools/link_seq_tool/trigger_tool/CSqlDbCtrl.h new file mode 100644 index 00000000..a0fb1b48 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CSqlDbCtrl.h @@ -0,0 +1,45 @@ +#pragma once +/*! + * @breif 关系库 + * + * @author sjq + * @date 五月 2018 + */ + +#include "db_api_ex/CDbApi.h" +#include "TriggerCommonDefine.h" + +class CDbContainer; +class CSqlDbCtrl +{ +public: + CSqlDbCtrl(); + ~CSqlDbCtrl(); + + bool openDb(); + bool remapDbTable(CDbContainer& container); + + bool addTimer(STimerDefine* info); + bool upateTimer(const QString& name,STimerDefine* info); + bool delTimer(const QString& name); + + bool addPeriod(SPeriodDefine* info); + bool upatePeriod(const QString& name, SPeriodDefine* info); + bool delPeriod(const QString& name); + + bool addCondition(SConditionDefine* info); + bool upateCondition(const QString& name, SConditionDefine* info); + bool delCondition(const QString& name); + + void closeDb(); + bool isOpen(); + +private: + bool remapTimer(CDbContainer& container); + bool remapPeriod(CDbContainer& container); + bool remapFunction(CDbContainer& container); + bool remapCondition(CDbContainer& container); + +private: + iot_dbms::CDbApi m_objLocalDbConn; +}; diff --git a/product/src/tools/link_seq_tool/trigger_tool/CTriggerInterface.cpp b/product/src/tools/link_seq_tool/trigger_tool/CTriggerInterface.cpp new file mode 100644 index 00000000..d0950d04 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CTriggerInterface.cpp @@ -0,0 +1,20 @@ +#include "CTriggerInterface.h" +#include "CTriggerMngr.h" + + +CTriggerInterface::CTriggerInterface(CTriggerMngr* ptr) + : m_ptrMngr(ptr) +{ + +} + +CTriggerInterface::~CTriggerInterface() +{ + m_ptrMngr = NULL; +} + +bool CTriggerInterface::triggered( + const iot_app::CTriggerPara* param, uint64 triggerTime) +{ + return m_ptrMngr->triggered(param, triggerTime); +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CTriggerInterface.h b/product/src/tools/link_seq_tool/trigger_tool/CTriggerInterface.h new file mode 100644 index 00000000..a100ac78 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CTriggerInterface.h @@ -0,0 +1,20 @@ +#pragma once +#include "application/trigger_api/CTriggerApi.h" + +class CTriggerMngr; +class CTriggerInterface : public iot_app::CTriggerApi +{ +public: + CTriggerInterface(CTriggerMngr* ptr); + ~CTriggerInterface(); + +protected: + bool triggered( + const iot_app::CTriggerPara* param, + uint64 triggerTime); + +private: + CTriggerMngr* m_ptrMngr; + +}; + diff --git a/product/src/tools/link_seq_tool/trigger_tool/CTriggerMngr.cpp b/product/src/tools/link_seq_tool/trigger_tool/CTriggerMngr.cpp new file mode 100644 index 00000000..580b83ed --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CTriggerMngr.cpp @@ -0,0 +1,153 @@ +#include "public/pub_logger_api/logger.h" +#include "common/Common.h" + +#include "CTriggerMngr.h" + +using namespace iot_public; + +CTriggerMngr::CTriggerMngr() + :m_objInterface(this) +{ +} + +CTriggerMngr::~CTriggerMngr() +{ + stop(); + clear(); +} + + +void CTriggerMngr::start() +{ + m_objInterface.start(); +} + + +void CTriggerMngr::stop() +{ + m_objInterface.stop(); +} + +void CTriggerMngr::queryTrigged() +{ + using namespace iot_app; + uint64 nTriggerTime; + + std::vector::iterator iter + = m_vecTriggerParam.begin(); + + for (; iter != m_vecTriggerParam.end(); ++iter) + { + CTriggerPara* param = *iter; + + if (m_objInterface.isTrigged(param, nTriggerTime)) + { + emit signal_isTriggered(param, true, nTriggerTime); + } + else + { + emit signal_isTriggered(param, false, nTriggerTime); + } + } +} + +bool CTriggerMngr::triggered( + const iot_app::CTriggerPara* param, + uint64 triggerTime) +{ + emit signal_triggered(param, triggerTime); + return true; +} + +void CTriggerMngr::clear() +{ + using namespace iot_app; + + std::vector::iterator iter + = m_vecTriggerParam.begin(); + for (; iter != m_vecTriggerParam.end(); ++iter) + { + m_objInterface.delTrigger(*iter); + delete *iter; + *iter = NULL; + } + + m_vecTriggerParam.clear(); +} + +iot_app::CTriggerPara* CTriggerMngr::addParam( + iot_app::CTriggerPara::TRIGGER_TYPE type, + const std::string& triggerName) +{ + using namespace iot_app; + + CTriggerPara* pParam + = new CTriggerPara(type, triggerName); + + if (m_objInterface.addTrigger(pParam)) + { + m_vecTriggerParam.push_back(pParam); + } + else + { + delete pParam; + pParam = NULL; + } + return pParam; +} + +bool CTriggerMngr::delParam( + iot_app::CTriggerPara* _pPara) +{ + using namespace iot_app; + CTriggerPara* pPara = _pPara; + std::vector::iterator iter + = m_vecTriggerParam.begin(); + for (; iter != m_vecTriggerParam.end(); ++iter) + { + if (*iter == pPara) + { + if (m_objInterface.delTrigger(pPara)) + { + m_vecTriggerParam.erase(iter); + delete pPara; + pPara = NULL; + return true; + } + else + { + return false; + } + } + } + return false; +} + + +void CTriggerMngr::ignoreCurTime(iot_app::CTriggerPara *pPram, uint64 time) +{ + if (pPram) + { + m_objInterface.ignoreBeforeTime(pPram, time); + } +} + +iot_app::CTriggerPara *CTriggerMngr::findPara( + iot_app::CTriggerPara::TRIGGER_TYPE type, + const std::string &triggerName) +{ + using namespace iot_app; + CTriggerPara* pPara = NULL; + std::vector::iterator iter + = m_vecTriggerParam.begin(); + for (; iter != m_vecTriggerParam.end(); ++iter) + { + pPara = *iter; + if (pPara->getTriggerName().compare(triggerName) == 0) + { + return pPara; + } + } + + return NULL; +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/CTriggerMngr.h b/product/src/tools/link_seq_tool/trigger_tool/CTriggerMngr.h new file mode 100644 index 00000000..e90513b0 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/CTriggerMngr.h @@ -0,0 +1,54 @@ +#include "pub_utility_api//TimerThreadBase.h" +#include "application/trigger_api/CTriggerApi.h" +#include +#include + +#include "CTriggerInterface.h" + +class CTriggerMngr : public QObject +{ + Q_OBJECT +public: + CTriggerMngr(); + virtual ~CTriggerMngr(); + + void start(); + void stop(); + + virtual void queryTrigged(); + void clear(); + + iot_app::CTriggerPara * addParam( + iot_app::CTriggerPara::TRIGGER_TYPE type, + const std::string& triggerName); + + bool delParam(iot_app::CTriggerPara*); + + void ignoreCurTime( + iot_app::CTriggerPara *pPram, + uint64 time); + + iot_app::CTriggerPara* findPara( + iot_app::CTriggerPara::TRIGGER_TYPE type, + const std::string& triggerName); + + bool triggered( + const iot_app::CTriggerPara* param, + uint64 triggerTime); + +signals: + void showMsg(const QString& msgStr); + void signal_triggered( + const iot_app::CTriggerPara*, + uint64); + void signal_isTriggered( + const iot_app::CTriggerPara*, + bool, + uint64); + +private: + CTriggerInterface m_objInterface; + std::vector m_vecTriggerParam; +}; + +typedef boost::shared_ptr CAppThreadPtr; diff --git a/product/src/tools/link_seq_tool/trigger_tool/TriggerCommonDefine.h b/product/src/tools/link_seq_tool/trigger_tool/TriggerCommonDefine.h new file mode 100644 index 00000000..7c9dd4ea --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/TriggerCommonDefine.h @@ -0,0 +1,111 @@ +#pragma once +#include "DataType.h" +#include +#include + + +enum TriggerType +{ + TRIGGERTYPE_ALL = 0, + TRIGGERTYPE_CONDITION, + TRIGGERTYPE_TIMER , + TRIGGERTYPE_PERIOD, +}; + +struct SBaseDefine +{ + QString tag_name; + QString description; + TriggerType type; + SBaseDefine() + { + type = TRIGGERTYPE_ALL; + }; +}; + +struct STimerDefine :public SBaseDefine +{ + uint64 trigger_time; + STimerDefine() + { + trigger_time = 0; + type = TRIGGERTYPE_TIMER; + } +}; + +struct SPeriodDefine :public SBaseDefine +{ + int period_type; + uint64 start_time; + uint64 stop_time; + QString period_str; + + SPeriodDefine() + { + period_type = 0; + start_time = 0; + stop_time = 0; + type = TRIGGERTYPE_PERIOD; + } +}; + +struct SFunctionDefine +{ + QString func_name; + QString description; + int sub_system; + QString func_str; + + SFunctionDefine() + { + sub_system = 0; + } +}; + +struct SConditionDefine :public SBaseDefine +{ + int sub_system; + int exe_type; + int is_repeat; + int space_time; + QString function_name; + int param_count; + QString param_1; + QString param_2; + QString param_3; + QString param_4; + QString param_5; + QString param_6; + QString param_7; + QString param_8; + QString param_9; + QString param_10; + QString param_11; + QString param_12; + QString param_13; + QString param_14; + QString param_15; + QString param_16; + QString param_17; + QString param_18; + QString param_19; + QString param_20; + + SConditionDefine() + { + sub_system = 0 ; + exe_type = 0; + is_repeat = 0; + space_time = 0; + param_count = 0; + type = TRIGGERTYPE_CONDITION; + } +}; + +typedef std::map TTriggerMap; +typedef std::map TTimerMap; +typedef std::map TPeriodMap; +typedef std::map TFunctionMap; +typedef std::map TConditionMap; + + diff --git a/product/src/tools/link_seq_tool/trigger_tool/main.cpp b/product/src/tools/link_seq_tool/trigger_tool/main.cpp new file mode 100644 index 00000000..26acbad8 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/main.cpp @@ -0,0 +1,64 @@ +#include "mainwindow.h" +#include +#include +#include "pub_logger_api/logger.h" +#include "net/net_msg_bus_api/MsgBusApi.h" +#include "pub_utility_api/FileStyle.h" +#include + +void loadStyle() +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss","zh","light"); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("trigger_tool.qss","zh","light"); + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + qApp->setStyleSheet(qss); + } +} + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + loadStyle(); + + iot_public::StartLogSystem("COMAPP", "trigger-test"); + + int nRet = iot_net::initMsgBus( + std::string("hmi").c_str(), + std::string("hmiInstance").c_str()); + if (false == nRet) + { + return 0; + } + + { + MainWindow w; + w.show(); + + nRet = a.exec(); + w.quit(); + } + + iot_net::releaseMsgBus(); + iot_public::StopLogSystem(); + + return nRet; +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/mainwindow.cpp b/product/src/tools/link_seq_tool/trigger_tool/mainwindow.cpp new file mode 100644 index 00000000..da7e4d14 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/mainwindow.cpp @@ -0,0 +1,506 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include "pub_logger_api/logger.h" +#include +#include +#include +#include +#include +#include "CSqlDbCtrl.h" +#include "CIterator.h" + +MainWindow::MainWindow(QWidget *parent) : + CustomUiMainWindow(parent), + ui(new Ui::MainWindow) +{ + setAutoLayout(true); + + ui->setupUi(this); + setWindowTitle("触发器测试工具"); + + m_ptrShowMsgList = ui->listWidget; + m_conditionCbb = ui->comboBox; + m_ptrTriggerList = ui->treeWidget_1; + m_ptrRegeditList = ui->treeWidget_2; + m_refeshCkb = ui->checkBox; + m_receateBtn = ui->pushButton_6; + m_regeditBtn = ui->pushButton_2; + m_unRegeditBtn = ui->pushButton_3; + m_ignoreTimeBtn = ui->pushButton; + m_clearMsgBtn = ui->pushButton_4; + + + m_ptrTriggerList->setColumnCount(3); + QTreeWidgetItem* item = new QTreeWidgetItem(); + item->setText(0, "类型"); + item->setText(1, "名称"); + item->setText(2, "描述"); + m_ptrTriggerList->setHeaderItem(item); + m_ptrTriggerList->setSelectionMode(QAbstractItemView::MultiSelection); + + m_ptrRegeditList->setColumnCount(5); + item = new QTreeWidgetItem(); + item->setText(0, "类型"); + item->setText(1, "名称"); + item->setText(2, "描述"); + item->setText(3, "是否触发"); + item->setText(4, "触发时间"); + m_ptrRegeditList->setHeaderItem(item); + m_ptrRegeditList->setColumnHidden(2,true); + m_ptrRegeditList->setSelectionMode(QAbstractItemView::MultiSelection); + + m_ptrTriggerMngr = new CTriggerMngr(); + m_timer = new QTimer(this); + + connect(m_ptrTriggerMngr, SIGNAL(showMsg(const QString&)), this, SLOT(slot_showMsg(const QString&))); + //connect(m_ptrTriggerMngr, SIGNAL(signal_triggered(const iot_app::CTriggerPara*, uint64)), + // this, SLOT(slot_triggered(const iot_app::CTriggerPara*, uint64)),Qt::QueuedConnection); + connect(m_ptrTriggerMngr, &CTriggerMngr::signal_triggered, this, &MainWindow::slot_triggered, Qt::BlockingQueuedConnection); + connect(m_ptrTriggerMngr, SIGNAL(signal_isTriggered(const iot_app::CTriggerPara*,bool, uint64)), + this, SLOT(slot_isTriggered(const iot_app::CTriggerPara*,bool, uint64))); + + connect(m_receateBtn, SIGNAL(clicked()), this, SLOT(slot_recreateBtn())); + connect(m_regeditBtn, SIGNAL(clicked()), this, SLOT(slot_regedit())); + connect(m_unRegeditBtn, SIGNAL(clicked()), this, SLOT(slot_unRegedit())); + connect(m_ignoreTimeBtn, SIGNAL(clicked()), this, SLOT(slot_igoreCurTime())); + connect(m_clearMsgBtn, SIGNAL(clicked()), this, SLOT(slot_clearMsg())); + + connect(m_conditionCbb, SIGNAL(currentIndexChanged(int)), this, SLOT(slot_showTrigger(int))); + connect(m_timer, SIGNAL(timeout()), this, SLOT(slot_timerOut())); + + m_ptrTriggerMngr->start(); + m_timer->start(500); + + slot_recreateBtn(); +} + + +MainWindow::~MainWindow() +{ + quit(); + delete ui; +} + +void MainWindow::quit() +{ + if (m_timer) + { + m_timer->stop(); + delete m_timer; + m_timer = NULL; + } + + if (m_ptrTriggerMngr != NULL) + { + m_ptrTriggerMngr->stop(); + delete m_ptrTriggerMngr; + m_ptrTriggerMngr = NULL; + } +} + +void MainWindow::slot_timerOut() +{ + if (m_ptrTriggerMngr) + { + m_ptrTriggerMngr->queryTrigged(); + } + + if (m_refeshCkb->isChecked()) + { + showCacheMsg(); + } +} + +void MainWindow::slot_showMsg(const QString & msg) +{ + QString curTimeStr = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); + QString showStr = QString("%1,%2").arg(curTimeStr).arg(msg); + + if (!m_refeshCkb->isChecked()) + { + m_msgCacheList.push_back(showStr); + return; + } + + if (!m_msgCacheList.isEmpty()) + { + showCacheMsg(); + } + + QListWidgetItem * item = new QListWidgetItem(); + item->setText(showStr); + m_ptrShowMsgList->addItem(item); +} + +void MainWindow::slot_regedit() +{ + QList list = m_ptrTriggerList->selectedItems(); + QListIterator iter(list); + QTreeWidgetItem * item; + while (iter.hasNext()) + { + item = iter.next(); + regeditItem(item); + } +} + +void MainWindow::slot_unRegedit() +{ + QList list = m_ptrRegeditList->selectedItems(); + QListIterator iter(list); + QTreeWidgetItem * item; + while (iter.hasNext()) + { + item = iter.next(); + if (unRegeditItem(item)) + { + delete item; + item = NULL; + } + } +} + +void MainWindow::slot_igoreCurTime() +{ + QList list = m_ptrRegeditList->selectedItems(); + QListIterator iter(list); + QTreeWidgetItem * item; + while (iter.hasNext()) + { + item = iter.next(); + ignoreItem(item); + } +} + +void MainWindow::slot_clearMsg() +{ + m_msgCacheList.clear(); + m_ptrShowMsgList->clear(); +} + +void MainWindow::slot_showTrigger(int index) +{ + m_ptrTriggerList->clear(); + + TriggerType type = (TriggerType)index; + CIterator iter(m_objContainer,type); + while (iter.hasNext()) + { + SBaseDefine& info = iter.getNext(); + QTreeWidgetItem* item = new QTreeWidgetItem(m_ptrTriggerList); + + item->setText(0, CDbContainer::getTriggerTypeStr(info.type)); + item->setData(0, Qt::UserRole + 1, QVariant::fromValue((void*)&info)); + item->setText(1, info.tag_name); + item->setText(2, info.description); + + m_ptrTriggerList->addTopLevelItem(item); + } +} + +void MainWindow::slot_recreateBtn() +{ + recreateModel(); + slot_showTrigger(m_conditionCbb->currentIndex()); +} + +bool MainWindow::recreateModel() +{ + CSqlDbCtrl dbCtrl; + if (!dbCtrl.openDb()) + { + return false; + } + + bool bRet = dbCtrl.remapDbTable(m_objContainer); + + return bRet; +} + +iot_app::CTriggerPara::TRIGGER_TYPE +MainWindow::trTriggerType(TriggerType type) +{ + using namespace iot_app; + switch (type) + { + case TRIGGERTYPE_ALL: + BOOST_ASSERT(false); + break; + case TRIGGERTYPE_CONDITION: + return CTriggerPara::TRIGGER_TYPE_CONDITION; + break; + case TRIGGERTYPE_TIMER: + return CTriggerPara::TRIGGER_TYPE_TIMER; + break; + case TRIGGERTYPE_PERIOD: + return CTriggerPara::TRIGGER_TYPE_PERIOD; + break; + default: + BOOST_ASSERT(false); + break; + } + return CTriggerPara::TRIGGER_TYPE_TIMER; +} + + +TriggerType MainWindow::trTriggerType( + iot_app::CTriggerPara::TRIGGER_TYPE type) +{ + using namespace iot_app; + switch (type) + { + case CTriggerPara::TRIGGER_TYPE_CONDITION: + return TRIGGERTYPE_CONDITION; + break; + case CTriggerPara::TRIGGER_TYPE_TIMER: + return TRIGGERTYPE_TIMER; + break; + case CTriggerPara::TRIGGER_TYPE_PERIOD: + return TRIGGERTYPE_PERIOD; + break; + default: + break; + } + + return TRIGGERTYPE_CONDITION; +} + +void MainWindow::showCacheMsg() +{ + QStringListIterator listIter(m_msgCacheList); + while (listIter.hasNext()) + { + QListWidgetItem * item = new QListWidgetItem(); + const QString& showStr = listIter.next(); + item->setText(showStr); + m_ptrShowMsgList->addItem(item); + } + m_msgCacheList.clear(); +} + + +void MainWindow::inserCacheMsg(const QString& msg) +{ + m_msgCacheList.push_back(msg); +} + +void MainWindow::showRegistered( + SBaseDefine* info, + iot_app::CTriggerPara * para) +{ + using namespace iot_app; + + QTreeWidgetItem* item = new QTreeWidgetItem(); + + item->setText(0, CDbContainer::getTriggerTypeStr(info->type)); + item->setData(0, Qt::UserRole + 1, QVariant::fromValue((void*)para)); + item->setText(1, info->tag_name); + item->setText(2, info->description); + item->setText(3, getTriggeredDesc(false)); + item->setData(3, Qt::UserRole+1, false); + item->setText(4, ""); + item->setData(4, Qt::UserRole+1, 0); + + m_ptrRegeditList->addTopLevelItem(item); +} + + +bool MainWindow::regeditItem(QTreeWidgetItem* item) +{ + SBaseDefine* info = + (SBaseDefine*)item->data(0, Qt::UserRole + 1).value(); + + if (!info) + { + return false; + } + + iot_app::CTriggerPara *pParam = NULL; + pParam = m_ptrTriggerMngr->addParam( + trTriggerType(info->type), + info->tag_name.toStdString()); + + QString showMsg; + if (pParam != NULL) + { + showMsg = QString("注册触发器 成功,类型:%1,名称:%2") + .arg(CDbContainer::getTriggerTypeStr(info->type)) + .arg(info->tag_name); + + showRegistered(info, pParam); + } + else + { + showMsg = QString("注册触发器 失败,类型:%1,名称:%2") + .arg(CDbContainer::getTriggerTypeStr(info->type)) + .arg(info->tag_name); + } + + slot_showMsg(showMsg); + + return true; +} + +bool MainWindow::unRegeditItem(QTreeWidgetItem* item) +{ + iot_app::CTriggerPara * para = + (iot_app::CTriggerPara *)item->data(0, Qt::UserRole + 1).value(); + + if (!para) + { + return false; + } + + bool bRet = false; + QString showMsg; + QString triggerName = QString::fromStdString(para->getTriggerName()); + QString triggerType = CDbContainer::getTriggerTypeStr(para->getTriggerType()); + + if (m_ptrTriggerMngr->delParam(para)) + { + showMsg = QString("取消注册触发器 成功,类型:%1,名称:%2") + .arg(triggerType) + .arg(triggerName); + + item->setData(0, Qt::UserRole + 1, 0); + + bRet = true; + } + else + { + showMsg = QString("取消注册触发器 失败,类型:%1,名称:%2") + .arg(triggerType) + .arg(triggerName); + } + + slot_showMsg(showMsg); + + return bRet; +} + +bool MainWindow::ignoreItem(QTreeWidgetItem* item) +{ + iot_app::CTriggerPara * para = + (iot_app::CTriggerPara *)item->data(0, Qt::UserRole + 1).value(); + + QDateTime dateTime = QDateTime::currentDateTime(); + uint64 curTime = dateTime.toSecsSinceEpoch(); + + m_ptrTriggerMngr->ignoreCurTime(para, curTime); + + QString showMsg = QString("%1,忽略时间:%2") + .arg(QString::fromStdString(para->getTriggerName())) + .arg(dateTime.toString("yyyy-MM-dd hh:mm:ss")); + + slot_showMsg(showMsg); + + return true; +} + +QTreeWidgetItem* +MainWindow::findRegeditItem(const iot_app::CTriggerPara * para) +{ + QTreeWidgetItemIterator it(m_ptrRegeditList); + QVariant data; + while (*it) + { + data = (*it)->data(0, Qt::UserRole + 1); + if (para == (iot_app::CTriggerPara*)data.value()) + { + return *it; + } + it++; + } + + return NULL; +} + + +QString MainWindow::getTriggeredDesc(bool isTrigged) +{ + if (isTrigged) + { + return "已触发"; + } + return "未触发"; +} + +void MainWindow::slot_triggered( + const iot_app::CTriggerPara *pParam, + uint64 time) +{ + QString strTime = + QDateTime::fromSecsSinceEpoch(time).toString("yyyy-MM-dd hh:mm:ss"); + + QTreeWidgetItem* item = findRegeditItem(pParam); + + QString showMsg; + if (item) + { + item->setText(3, getTriggeredDesc(true)); + item->setData(3, Qt::UserRole + 1, true); + item->setText(4, strTime); + item->setData(4, Qt::UserRole + 1, QVariant((qulonglong)time)); + + showMsg = QString("触发通知:%1 名称:%2 触发时间:%3") + .arg(strTime) + .arg(QString::fromStdString(pParam->getTriggerName())) + .arg(strTime); + } + else + { + showMsg = QString("触发通知:%1 未找到触发器 名称:%1 触发时间:%2") + .arg(strTime) + .arg(QString::fromStdString(pParam->getTriggerName())) + .arg(strTime); + } + + slot_showMsg(showMsg); +} + +void MainWindow::slot_isTriggered( + const iot_app::CTriggerPara* pParam, + bool isTrigger, + uint64 time) +{ + QString strTime; + if (time != 0) + { + strTime = QDateTime::fromSecsSinceEpoch(time).toString("yyyy-MM-dd hh:mm:ss"); + } + + QTreeWidgetItem* item = findRegeditItem(pParam); + + QString showMsg; + if (item) + { + bool isOldTrigged = item->data(3, Qt::UserRole + 1).toBool(); + uint64 nOldTime = item->data(4, Qt::UserRole + 1).toULongLong(); + item->setText(3, getTriggeredDesc(isTrigger)); + item->setData(3,Qt::UserRole+1, isTrigger); + item->setText(4, strTime); + item->setData(4, Qt::UserRole + 1, QVariant((qulonglong)time)); + + if (isOldTrigged != isTrigger || nOldTime != time) + { + showMsg = QString("触发查询:%1 名称:%2 触发时间:%3") + .arg(getTriggeredDesc(isTrigger)) + .arg(QString::fromStdString(pParam->getTriggerName())) + .arg(strTime); + } + } + else + { + showMsg = QString("触发查询:%1 未找到触发器 名称:%2 触发时间:%3") + .arg(getTriggeredDesc(isTrigger)) + .arg(QString::fromStdString(pParam->getTriggerName())) + .arg(strTime); + } + + if (!showMsg.isEmpty()) + { + slot_showMsg(showMsg); + } + +} diff --git a/product/src/tools/link_seq_tool/trigger_tool/mainwindow.h b/product/src/tools/link_seq_tool/trigger_tool/mainwindow.h new file mode 100644 index 00000000..d380e8a6 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/mainwindow.h @@ -0,0 +1,92 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include "CDbContainer.h" +#include "CTriggerMngr.h" +#include "pub_widget/CustomMainWindow.h" + +namespace Ui { + class MainWindow; +} +class QListWidget; +class QTimer; +class QCheckBox; +class QTreeWidget; +class QComboBox; +class QPushButton; + +class MainWindow : public CustomUiMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + void quit(); + +private slots: + void slot_timerOut(); + void slot_showMsg(const QString&); + + void slot_triggered( + const iot_app::CTriggerPara*, + uint64 time); + + void slot_isTriggered( + const iot_app::CTriggerPara*, + bool isTrigger, + uint64 time); + + void slot_regedit(); + void slot_unRegedit(); + void slot_igoreCurTime(); + void slot_clearMsg(); + + void slot_showTrigger(int index); + + void slot_recreateBtn(); +private: + bool recreateModel(); + iot_app::CTriggerPara::TRIGGER_TYPE + trTriggerType(TriggerType type); + TriggerType + trTriggerType(iot_app::CTriggerPara::TRIGGER_TYPE type); + + void showCacheMsg(); + void inserCacheMsg(const QString& msg); + + void showRegistered(SBaseDefine* info, + iot_app::CTriggerPara * para); + + bool regeditItem(QTreeWidgetItem* item); + bool unRegeditItem(QTreeWidgetItem* item); + bool ignoreItem(QTreeWidgetItem* item); + + QTreeWidgetItem* findRegeditItem(const iot_app::CTriggerPara * para); + + static QString getTriggeredDesc(bool isTrigged); +private: + Ui::MainWindow *ui; + QTimer* m_timer; + CTriggerMngr* m_ptrTriggerMngr; + + QTreeWidget* m_ptrTriggerList; + QTreeWidget* m_ptrRegeditList; + QListWidget* m_ptrShowMsgList; + QComboBox* m_conditionCbb; + QCheckBox* m_refeshCkb; + + QPushButton* m_receateBtn; + QPushButton* m_regeditBtn; + QPushButton* m_unRegeditBtn; + QPushButton* m_ignoreTimeBtn; + QPushButton* m_clearMsgBtn; + + QStringList m_msgCacheList; + CDbContainer m_objContainer; +}; + +#endif // MAINWINDOW_H diff --git a/product/src/tools/link_seq_tool/trigger_tool/mainwindow.ui b/product/src/tools/link_seq_tool/trigger_tool/mainwindow.ui new file mode 100644 index 00000000..dd1f7560 --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/mainwindow.ui @@ -0,0 +1,257 @@ + + + MainWindow + + + + 0 + 0 + 870 + 528 + + + + MainWindow + + + + + + + + + + + + 1 + + + + + + + + + + + 全部 + + + + + 条件触发 + + + + + 定时触发 + + + + + 周期触发 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 注册 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 取消注册 + + + + + + + 忽略触发 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 清空 + + + + + + + 刷新 + + + true + + + + + + + + + + + + + + + + + + + + 重新加载 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + 0 + 870 + 23 + + + + + + + + + slot_regedit() + slot_unRegedit() + slot_igoreCurTime() + slot_stopRefesh() + + diff --git a/product/src/tools/link_seq_tool/trigger_tool/trigger_tool.pro b/product/src/tools/link_seq_tool/trigger_tool/trigger_tool.pro new file mode 100644 index 00000000..9567c03b --- /dev/null +++ b/product/src/tools/link_seq_tool/trigger_tool/trigger_tool.pro @@ -0,0 +1,64 @@ +QT += core gui sql +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +TEMPLATE = app +TARGET = trigger_tool + +# CONFIG += console + +INCLUDEPATH += ../../include + +# Input +HEADERS += \ + mainwindow.h \ + CTriggerInterface.h \ + CSqlDbCtrl.h \ + CDbContainer.h \ + TriggerCommonDefine.h \ + CIterator.h \ + CEditConditionWidget.h \ + CEditPeriodWidget.h \ + CEditTimerWidget.h \ + CTriggerMngr.h \ + CEditDialog.h \ + CEditBaseWidget.h + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + CTriggerInterface.cpp \ + CSqlDbCtrl.cpp \ + CDbContainer.cpp \ + CIterator.cpp \ + CEditConditionWidget.cpp \ + CEditPeriodWidget.cpp \ + CEditTimerWidget.cpp \ + CTriggerMngr.cpp \ + CEditDialog.cpp \ + CEditBaseWidget.cpp + +LIBS += -lboost_filesystem -lboost_system -lboost_thread -lboost_date_time +LIBS += -llog4cplus \ + -lpub_logger_api \ + -lpub_utility_api \ + -lnet_msg_bus_api \ + -ltrigger_api \ + -ldb_sysinfo_api \ + -ldb_base_api \ + -ldb_api_ex \ + -lpub_widget + + +#------------------------------------------------------------------- +COMMON_PRI=$$PWD/../../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} + +FORMS += \ + mainwindow.ui \ + CEditConditionWidget.ui \ + CEditPeriodWidget.ui \ + CEditTimerWidget.ui \ + CEditDialog.ui diff --git a/product/src/tools/model_plugin/StaticsWidget/statics_analysis_EN.ts b/product/src/tools/model_plugin/StaticsWidget/statics_analysis_EN.ts new file mode 100644 index 00000000..07404d5b --- /dev/null +++ b/product/src/tools/model_plugin/StaticsWidget/statics_analysis_EN.ts @@ -0,0 +1,671 @@ + + + + + KbdPointDlg + + + 位置 + + + + + 专业 + + + + + 设备组 + + + + + 点类型 + + + + + 模拟量 + + + + + 数字量 + + + + + 累积量 + + + + + 混合量 + + + + + StatLinkInstDlg + + + + + + + + + + 消息 + + + + + 是否开始关联统计实例[ %1 ] +这将清空现有的参数组的子参数以及参数的测点绑定 + + + + + + + 关联失败 + + + + + + + 关联成功 + + + + + + + + 当前设备模板 + + + + + + + 当前统计关联 + + + + + + 开始关联统计实例[ %1 ] +这将清空与[ %2 ]有关的参数组下的子参数和关联 +是否继续 + + + + + + 开始关联统计实例[ %1 ] +这将清空[ %2 ]有关的关联和 +是否继续 + + + + + 关联列表 + + + + + 点绑定信息 + + + + + 开始关联 + + + + + 取消 + + + + + 数据库链接错误 + + + + + + 删除 + + + + + 添加设备到左侧列表 + + + + + + 关联 + + + + + 输入 + + + + + 输出 + + + + + 此次修改失败,已启动回滚! + + + + + StaticsWidget + + + + + + + 添加记录 + + + + + + + + + 修改记录 + + + + + + + + + 删除记录 + + + + + + 输入 + + + + + + 输出 + + + + + + 参数编辑 + + + + + + + 保存 + + + + + 输入生成 + + + + + 输出生成 + + + + + 生成输入/输出并保存 + + + + + 函数体 + + + + + 位置 + + + + + 专业 + + + + + 禁用所有统计实例 + + + + + 输入参数关联 + + + + + 输出参数关联 + + + + + + 添加 + + + + + + + + 删除 + + + + + + + + 上移 + + + + + + + + 下移 + + + + + + + + 置顶 + + + + + + + + 置底 + + + + + + + + 添加子参数 + + + + + + 生成 + + + + + 开始关联 + + + + + 复制关联 + + + + + + + + + 添加失败 + + + + + + + + + + + 读取数据库失败 + + + + + + + + + 删除失败 + + + + + + 请先选择要添加的函数模板 + + + + + + 数据库链接不成功 + + + + + + + 请选中要修改的条目 + + + + + 请先选择要删除的函数模板 + + + + + 复制关联-请输入新的关联名 + + + + + 标签名已存在,请修改 + + + + + 复制失败! + + + + + + 保存失败: + + + + + + + 保存失败 + + + + + + + 保存成功 + + + + + + 获取系统信息失败 + + + + + + + 修改失败 + + + + + 禁用失败 + + + + + 禁用成功 + + + + + + 请先选择前置设备 + + + + + + 添加成功 + + + + + + 修改成功 + + + + + + + + 删除失败! + + + + + + 删除成功! + + + + + + 无法读取数据库 + + + + + + + + + + + 数据库链接错误 + + + + + 无法查询该数据类型 + + + + + + 无法查询位置和专业 + + + + + + + + + + + + + + 请选中函数实例 + + + + + + 删除成功 + + + + + + + + + + + + 请选中对应函数 + + + + + + + + + + + + + + + + + + + + 请选中要移动的条目 + + + + + + + + + + + + + + + + + + + + 数据库查询失败! + + + + + + + + 上移失败 + + + + + + + + 下移失败 + + + + + + + + + 置顶失败 + + + + + + + 置底失败 + + + + + 统计实例绑定数据异常 + + + + + 暂无可用统计关联,请创建 + + + + + 请选择要绑定的计算实例 + + + + + 数据格式不对 + + + + + 消息 + + + + + %1 与 %2 进行绑定? + + + + + 绑定失败 + + + + + 绑定成功 + + + + + + 无法识别拖拽数据的格式 + + + + + 请拖拽到正确的输入参数上 + + + + + 请拖拽到正确的输出参数上 + + + + diff --git a/product/src/tools/mqtt_tool/CommonSheet.cpp b/product/src/tools/mqtt_tool/CommonSheet.cpp new file mode 100644 index 00000000..856035fb --- /dev/null +++ b/product/src/tools/mqtt_tool/CommonSheet.cpp @@ -0,0 +1,43 @@ +#include "CommonSheet.h" +#include +#include "pub_utility_api/FileStyle.h" + +CommonSheet::CommonSheet() +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss","zh","light"); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("mqtt_tool.qss","zh","light"); + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + m_stSheet = qss; + } +} + +bool CommonSheet::getSheet(QString &sheet) +{ + if(m_stSheet.isEmpty()) + { + return false; + }else + { + sheet = m_stSheet; + return true; + } +} diff --git a/product/src/tools/mqtt_tool/CommonSheet.h b/product/src/tools/mqtt_tool/CommonSheet.h new file mode 100644 index 00000000..bf5ddea6 --- /dev/null +++ b/product/src/tools/mqtt_tool/CommonSheet.h @@ -0,0 +1,15 @@ +#ifndef COMMONSHEET_H +#define COMMONSHEET_H + +#include +#include +class CommonSheet +{ +public: + CommonSheet(); + bool getSheet(QString &sheet); +private: + QString m_stSheet; +}; + +#endif // COMMONSHEET_H diff --git a/product/src/tools/mqtt_tool/QMqttClient.cpp b/product/src/tools/mqtt_tool/QMqttClient.cpp new file mode 100644 index 00000000..76ef544a --- /dev/null +++ b/product/src/tools/mqtt_tool/QMqttClient.cpp @@ -0,0 +1,205 @@ +#include "QMqttClient.h" +#include +#include + +//-------------------------------------------------------------------- +QMqttClient::QMqttClient(const QString& mqtt_id, QObject *parent) + : QObject(parent), + mosquittopp(mqtt_id.toLocal8Bit().data()), + m_id(mqtt_id), + m_port(1883), + m_keepAlive(60), + m_connected(false), + MID(0) +{ + +} +//-------------------------------------------------------------------- +QMqttClient::QMqttClient(const QString& mqtt_id, const QHostAddress& host, int port, QObject* parent) + : QObject(parent), + mosquittopp(mqtt_id.toLocal8Bit().data()), + m_id(mqtt_id), + m_host(host), + m_port(port), + m_keepAlive(60), //seconds + m_connected(false), + MID(0) +{ + +} +//-------------------------------------------------------------------- +QMqttClient::~QMqttClient() +{ + disconnect(); +} +//-------------------------------------------------------------------- +void QMqttClient::connect() +{ + if(!m_connected) + { + mosqpp::lib_init(); + if( !m_username.isEmpty()) + { + username_pw_set(m_username.toUtf8().constData(), m_password.toUtf8().constData()); + } + int connect_rslt = connect_async(m_host.toString().toLatin1().data(), m_port, m_keepAlive); + if( connect_rslt != MOSQ_ERR_SUCCESS) + { + QString errorMessage = mosquitto_strerror(connect_rslt); + emit error(errorMessage); + }else + { + m_connected = true; + QtConcurrent::run(this, &QMqttClient::runLoop); + } + } +} +//-------------------------------------------------------------------- +void QMqttClient::disconnect() +{ + if(m_connected) { + int rslt = mosquittopp::disconnect(); + if(rslt != MOSQ_ERR_SUCCESS) { + QString errorMessage = mosquitto_strerror(rslt); + emit error(errorMessage); + } + } +} +//-------------------------------------------------------------------- +void QMqttClient::on_connect(int rc) +{ + if(rc != MOSQ_ERR_SUCCESS) { + m_connected = false; + QString errorMessage = mosquitto_strerror(rc); + emit error(errorMessage); + }else{ + m_connected = true; + emit connected(); + } +} +//-------------------------------------------------------------------- +int QMqttClient::send_message(const QString& topic, const QString& data, bool retain, QMqttMessage::QoS qos) +{ + return mosquittopp::publish(&MID, + topic.toLocal8Bit().data(), + strlen(data.toLocal8Bit().data()), + data.toLocal8Bit().data(), + qos, + retain); +} +//-------------------------------------------------------------------- +void QMqttClient::on_disconnect(int rc) +{ + Q_UNUSED(rc) + if( rc != MOSQ_ERR_SUCCESS ) + { + QString errorMessage = QString("Disconnect failed with return code: %1").arg(rc); + emit error(errorMessage); + return; + } + m_connected = false; + loop_stop(true); + if (QThread::currentThread()->isRunning()) + { + QThread::currentThread()->quit(); + QThread::currentThread()->wait(); + } + emit disconnected(); +} +//-------------------------------------------------------------------- +void QMqttClient::on_message(const mosquitto_message *mqtt_message) +{ + if(mqtt_message->payloadlen) { + QByteArray message_received = (char*)mqtt_message->payload; + QMqttMessage message(QString(mqtt_message->topic), message_received, mqtt_message->retain); + emit messageReceived(message); + } +} +//-------------------------------------------------------------------- +void QMqttClient::on_subscribe(int mid, int qos_count, const int *granted_qos) +{ + if(mid != 0) { + QString subscribedTopic = m_subscribingTopics.value(mid); + if(!subscribedTopic.isEmpty()) { + m_subscribingTopics.remove(mid); + m_subscribedTopics.insert(mid ,subscribedTopic); + emit subscribed(subscribedTopic); + } + } + MID++; +} +//-------------------------------------------------------------------- +void QMqttClient::on_publish(int mid) +{ + MID++; + emit published(); +} + +void QMqttClient::on_unsubscribe(int mid) +{ + if(mid != 0) { + QString unsubscribedTopic = m_unsubscribingTopics.value(mid); + if( !unsubscribedTopic.isEmpty()) { + m_unsubscribingTopics.remove(mid); + emit unsubscribed(unsubscribedTopic); + } + } +} + +void QMqttClient::runLoop() +{ + qDebug() << "runLoop started"; + while (m_connected) + { + int loopResult = loop(); + if (loopResult != MOSQ_ERR_SUCCESS) { + QString errorMessage = mosquitto_strerror(loopResult); + emit error(errorMessage); + } + QThread::msleep(10); + } +} +//-------------------------------------------------------------------- +void QMqttClient::publish(QString topic, QByteArray data, QMqttMessage::QoS qos, bool retain) +{ + //publish(QMqttMessage(topic, data, retain), qos); +} +//-------------------------------------------------------------------- +void QMqttClient::publish(QMqttMessage message, QMqttMessage::QoS qos) +{ + int rslt = send_message(message.topic(), message.payload(), message.hasRetainFlag(), qos); + if(rslt != MOSQ_ERR_SUCCESS) { + QString errorMessage = mosquitto_strerror(rslt); + emit error(errorMessage); + } +} +//-------------------------------------------------------------------- +void QMqttClient::subscribe(QString topic, QMqttMessage::QoS qos) +{ + int rslt = mosquittopp::subscribe(&MID, topic.toLocal8Bit().data(), qos); + m_subscribingTopics.insert(MID, topic); + if(rslt != MOSQ_ERR_SUCCESS) { + QString errorMessage = mosquitto_strerror(rslt); + emit error(errorMessage); + } +} +//-------------------------------------------------------------------- +void QMqttClient::unsubscribe(QString topic) +{ + int rslt = mosquittopp::unsubscribe(&MID, topic.toLocal8Bit().data()); + m_unsubscribingTopics.insert(MID, topic); + if(rslt != MOSQ_ERR_SUCCESS) { + QString errorMessage = mosquitto_strerror(rslt); + emit error(errorMessage); + } + MID++; +} + +void QMqttClient::setWillMsg(QString willtopic, QString willMsg, int qos, bool retain) +{ + int rslt = mosquittopp::will_set(willtopic.toLocal8Bit().data() , willMsg.length() , willMsg.toLocal8Bit().data() , qos , retain); + if(rslt != MOSQ_ERR_SUCCESS) { + QString errorMessage = mosquitto_strerror(rslt); + emit error(errorMessage); + } +} diff --git a/product/src/tools/mqtt_tool/QMqttClient.h b/product/src/tools/mqtt_tool/QMqttClient.h new file mode 100644 index 00000000..b17d18da --- /dev/null +++ b/product/src/tools/mqtt_tool/QMqttClient.h @@ -0,0 +1,237 @@ +#ifndef MOSQUITTOCLIENT_H +#define MOSQUITTOCLIENT_H + + +#include +#include +#include +#include +#include "mosquittopp.h" +#include "mosquitto.h" +#include "QMqttMessage.h" + +class QMqttClient : public QObject, public mosqpp::mosquittopp +{ + Q_OBJECT +private: + const QString m_id; + QHostAddress m_host; + int m_port; + int m_keepAlive; + bool m_connected; + int MID; + QMap m_subscribedTopics; + QMap m_subscribingTopics; + QMap m_unsubscribingTopics; + QMqttMessage m_lastWillMessage; + QString m_username; + QString m_password; + + void on_disconnect(int rc); + void on_connect(int rc); + void on_message(const struct mosquitto_message* mqtt_message); + void on_subscribe(int mid, int qos_count, const int* granted_qos); + int send_message(const QString& topic, const QString& data, bool retain, QMqttMessage::QoS qos = QMqttMessage::AT_MOST_ONCE); + void on_publish(int mid); + void on_unsubscribe(int mid); + +public: + /** + * Creates a QMqttClient object. + * parent is passed on to the QObject constructor. + */ + explicit QMqttClient(const QString& mqtt_id, QObject *parent = 0); + + /** + * Creates a QMqttClient object with the specified id. parent is passed on to the QObject constructor. + * @param id + * @param address + * @param port + * @param parent + */ + QMqttClient(const QString& id, const QHostAddress& address, int port, QObject* parent = 0); + + /** + * Destroys the object, closing the connection if necessary. + */ + ~QMqttClient(); + + /** + * @brief isConnected + * @return Returs true if the client is actually connected to a broker. Otherwise, returns false. + */ + bool isConnected() const { return m_connected; } + + /** + * @brief host Returns the host address of the broker. + * @return + */ + const QHostAddress& host() const { return m_host; } + + /** + * @brief setHost + * @param host + */ + void setHost(const QHostAddress& host) { m_host = host; } + + /** + * @brief subscribedTopics + * @return + */ + const QStringList& subscribedTopics() const { return m_subscribedTopics.values(); } + + /** + * @brief id + * @return + */ + const QString& id() const { return m_id; } + + /* + * @brief setId + * @param id + */ + //void setId(const QString& aid) { m_id = aid; } + + /** + * @brief port + * @return + */ + int port() const { return m_port; } + + /** + * @brief setPort + * @param port + */ + void setPort(int _port) { m_port = _port; } + + /** + * @brief keepAlive + * @return + */ + int keepAlive() const { return m_keepAlive; } + + /** + * @brief setKeepAlive + * @param keepAlive + */ + void setKeepAlive(int _keepAlive) { m_keepAlive = _keepAlive; } + + /** + * @brief setLastWillMessage + * @param will + */ + void setLastWillMessage(const QMqttMessage& will) { m_lastWillMessage = will; } + + /** + * @brief getLastWillMessage + * @return + */ + const QMqttMessage& getLastWillMessage() const { return m_lastWillMessage; } + + /** + * @brief setUsername + * @param _username + */ + void setUsername(QString _username){ m_username = _username; } + + /** + * @brief setPassword + * @param _password + */ + void setPassword(QString _password){ m_password = _password;} + + void runLoop(); + + +signals: + /** + * @brief connected + * This signal is emitted when the client is connected + */ + void connected(); + /** + * @brief disconnected + * This signal is emitted when the client is disconnected + */ + void disconnected(); + /** + * @brief subscribed + * This signal is emitted when the client has subscribed successfully to a topic + */ + void subscribed(QString topic = ""); + /** + * @brief subscribed + * @param topic + */ + void unsubscribed(QString topic = ""); + /** + * @brief published + * This signal is emitted when the client has successfully published a message + */ + void published(); + /** + * @brief messageReceived + * This signal is emitted when the mqtt-client has received a mqtt-message + */ + void messageReceived(QMqttMessage message); + /** + * @brief error + * this signal is emitted when an error occured. + * @param errorMessage A human-readable string that describes the error + */ + void error(QString errorMessage); + + /** + * @brief sigOpenTimer + * @param flag + */ + void sigOpenTimer(bool flag); + +public slots: + /** + * @brief publish + * Publish a data to the specified topic + * @param topic + * @param data + * @param qos + * @param retain + */ + void publish(QString topic, QByteArray data, + QMqttMessage::QoS qos = QMqttMessage::AT_MOST_ONCE, + bool retain = false); + /** + * @brief publish + * @param message + */ + void publish(QMqttMessage message, QMqttMessage::QoS qos = QMqttMessage::AT_MOST_ONCE); + /** + * Subscribe to a topic. + * @param topic + */ + void subscribe(QString topic, QMqttMessage::QoS qos = QMqttMessage::AT_MOST_ONCE); + /** + * Initiate a connection to a broker. + */ + void connect(); + /** + * Disable the connection with the broker. + */ + void disconnect(); + + /** + * @brief unsubscribe + * @param topic + */ + void unsubscribe(QString topic); + + /** + * @brief setWillMsg + * @param willtopic + * @param willMsg + * @param qos + * @param retain + */ + void setWillMsg(QString willtopic, QString willMsg , int qos = 0 , bool retain = false); +}; + +#endif // MOSQUITTOCLIENT_H diff --git a/product/src/tools/mqtt_tool/QMqttMessage.cpp b/product/src/tools/mqtt_tool/QMqttMessage.cpp new file mode 100644 index 00000000..b236d94d --- /dev/null +++ b/product/src/tools/mqtt_tool/QMqttMessage.cpp @@ -0,0 +1,73 @@ +#include "QMqttMessage.h" + +#include + +//----------------------------------------------------------- +/* + * metatype registration + */ +class QMqttMessageInit { +public: + QMqttMessageInit() { + qRegisterMetaType(); + } +}; +static QMqttMessageInit mosquittoMessageInit; +//----------------------------------------------------------- +QMqttMessage::QMqttMessage() + : d(new QMqttMessageData) +{ + setRetainFlag(false); +} +//----------------------------------------------------------- +QMqttMessage::QMqttMessage(const QString& topic, const QByteArray &payload, bool retain) + : d(new QMqttMessageData) +{ + setTopic(topic); + setPayload(payload); + setRetainFlag(retain); +} +//----------------------------------------------------------- +QMqttMessage::QMqttMessage(const QMqttMessage &other) + : d(other.d) +{ + +} +//----------------------------------------------------------- +QMqttMessage& QMqttMessage::operator =(const QMqttMessage& other) +{ + if(other.d != d) { + d = other.d; + } + return *this; +} +//----------------------------------------------------------- +const QString& QMqttMessage::topic() const +{ + return d->topic; +} +//----------------------------------------------------------- +void QMqttMessage::setTopic(const QString &topic) +{ + d->topic = topic; +} +//----------------------------------------------------------- +const QByteArray& QMqttMessage::payload() const +{ + return d->payload; +} +//----------------------------------------------------------- +void QMqttMessage::setPayload(const QByteArray &data) +{ + d->payload = data; +} +//----------------------------------------------------------- +bool QMqttMessage::hasRetainFlag() const +{ + return d->retainFlag; +} +//----------------------------------------------------------- +void QMqttMessage::setRetainFlag(bool flag) +{ + d->retainFlag = flag; +} diff --git a/product/src/tools/mqtt_tool/QMqttMessage.h b/product/src/tools/mqtt_tool/QMqttMessage.h new file mode 100644 index 00000000..d5cd2288 --- /dev/null +++ b/product/src/tools/mqtt_tool/QMqttMessage.h @@ -0,0 +1,96 @@ +#ifndef QMQTTMESSAGE_H +#define QMQTTMESSAGE_H + +#include +#include +#include +#include + +/* + * private data used for shared pointer + */ +class QMqttMessageData : public QSharedData +{ +public: + QString topic; + QByteArray payload; + bool retainFlag; +}; +//----------------------------------------------------------- +/** + * @brief The QMqttMessage class represents a mqtt message. + */ +class QMqttMessage +{ +public: + /** + * + * + */ + typedef enum { + AT_MOST_ONCE = 0, + AT_LEAST_ONCE = 1, + EXACTLY_ONCE = 2 + } QoS; + + + /** + * @brief QMqttMessage + */ + QMqttMessage(); + /** + * @brief QMqttMessage + * @param topic + * @param payload + * @param retain + */ + QMqttMessage(const QString& topic, const QByteArray& payload, bool retain = false); + /** + * @brief QMqttMessage + * @param other + */ + QMqttMessage(const QMqttMessage& other); + /** + * @brief operator = + * @param other + * @return + */ + QMqttMessage& operator=(const QMqttMessage& other); + /** + * @brief getTopic + * @return + */ + const QString& topic() const; + /** + * @brief setTopic + * @param topic + */ + void setTopic(const QString& topic); + /** + * @brief payload + * @return + */ + const QByteArray& payload() const; + /** + * @brief setPayload + * @param data + */ + void setPayload(const QByteArray& data); + /** + * @brief hasRetainFlag + * @return + */ + bool hasRetainFlag() const; + /** + * @brief setRetainFlag + * @param flag + */ + void setRetainFlag(bool flag); + +private: + QSharedDataPointer d; +}; + +Q_DECLARE_METATYPE(QMqttMessage) + +#endif // QMQTTMESSAGE_H diff --git a/product/src/tools/mqtt_tool/connform.cpp b/product/src/tools/mqtt_tool/connform.cpp new file mode 100644 index 00000000..aa738d88 --- /dev/null +++ b/product/src/tools/mqtt_tool/connform.cpp @@ -0,0 +1,64 @@ +#include "connform.h" +#include "ui_connform.h" + +#include + +ConnForm::ConnForm(QWidget *parent) : + MqttForm(parent), + ui(new Ui::ConnForm) +{ + ui->setupUi(this); + ui->disconnButton->setEnabled(false); +} + +ConnForm::~ConnForm() +{ + delete ui; +} + +void ConnForm::onConnect() +{ + QString clientId = ui->leClientId->text(); + QString username = ui->leUser->text(); + QString passwd = ui->lePasswd->text(); + QString willtopic = ui->leWillTopic->text(); + QString willmsg = ui->teWillMsg->toPlainText(); + + if(!_client->isConnected()) { + + QHostAddress hostAdd(ui->leHost->text()); + _client->setHost(hostAdd); + _client->setPort(ui->sbPort->value()); + _client->setKeepAlive(ui->sbKeepalive->value()); + + if( !clientId.isEmpty() ) + { + _client->reinitialise(clientId.toUtf8().data() , ui->cbCleanSess->isChecked()); + } + if(!username.isEmpty()) _client->setUsername(username); + if(!passwd.isEmpty()) _client->setPassword(passwd.toUtf8()); + if(!willtopic.isEmpty() && !willmsg.isEmpty()) { + _client->setWillMsg(willtopic , willmsg); + } + _client->connect(); + } +} + +void ConnForm::onDisconnect() +{ + if(_client->isConnected()) { + _client->disconnect(); + } +} + +void ConnForm::initView() +{ + //do something +} + +void ConnForm::updateUiStatus() +{ + ui->connButton->setEnabled(!_client->isConnected()); + ui->disconnButton->setEnabled(_client->isConnected()); +} + diff --git a/product/src/tools/mqtt_tool/connform.h b/product/src/tools/mqtt_tool/connform.h new file mode 100644 index 00000000..0905837d --- /dev/null +++ b/product/src/tools/mqtt_tool/connform.h @@ -0,0 +1,49 @@ +/** + * Copyright (C) 2013-2017 Feng Lee + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef CONNFORM_H +#define CONNFORM_H + +#include +#include "mqttform.h" + +namespace Ui { +class ConnForm; +} + +class ConnForm : public MqttForm +{ + Q_OBJECT + +public: + explicit ConnForm(QWidget *parent = 0); + ~ConnForm(); + +public slots: + void updateUiStatus(); + +private slots: + void onConnect(); + void onDisconnect(); + +private: + void initView(); + +private: + Ui::ConnForm *ui; +}; + +#endif // CONNFORM_H diff --git a/product/src/tools/mqtt_tool/connform.ui b/product/src/tools/mqtt_tool/connform.ui new file mode 100644 index 00000000..d90a70bc --- /dev/null +++ b/product/src/tools/mqtt_tool/connform.ui @@ -0,0 +1,276 @@ + + + ConnForm + + + + 0 + 0 + 562 + 309 + + + + + 16777215 + 16777215 + + + + Form + + + + + + + + + + + + 密码: + + + lePasswd + + + + + + + Will Topic: + + + leWillTopic + + + + + + + 用户ID: + + + leClientId + + + + + + + Will Msg: + + + teWillMsg + + + + + + + Qt::Horizontal + + + + + + + + + + + + + localhost + + + + + + + 用户名: + + + leUser + + + + + + + Server(*): + + + leHost + + + + + + + 1 + + + 65535 + + + 1883 + + + + + + + + + + 端口(*): + + + sbPort + + + + + + + + + + + + + + + + + Keepalive: + + + sbKeepalive + + + + + + + (s) + + + 3600 + + + 300 + + + + + + + CleanSess: + + + cbCleanSess + + + + + + + + + + true + + + + + + + + + + + + 连接 + + + + + + + 取消连接 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + leHost + sbPort + sbKeepalive + cbCleanSess + leClientId + leUser + lePasswd + leWillTopic + teWillMsg + connButton + disconnButton + + + + + connButton + clicked() + ConnForm + onConnect() + + + 455 + 23 + + + 533 + 17 + + + + + disconnButton + clicked() + ConnForm + onDisconnect() + + + 473 + 70 + + + 529 + 67 + + + + + + onConnect() + onDisconnect() + + diff --git a/product/src/tools/mqtt_tool/main.cpp b/product/src/tools/mqtt_tool/main.cpp new file mode 100644 index 00000000..48b93cd9 --- /dev/null +++ b/product/src/tools/mqtt_tool/main.cpp @@ -0,0 +1,14 @@ +#include "mainwindow.h" +#include + +#include "QMqttClient.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication::setApplicationName("MQTT_TOOL"); + QApplication a(argc, argv); + MainWindow w(new QMqttClient(QString("yxmqtt_test"))); + w.show(); + + return a.exec(); +} diff --git a/product/src/tools/mqtt_tool/mainwindow.cpp b/product/src/tools/mqtt_tool/mainwindow.cpp new file mode 100644 index 00000000..7478aed6 --- /dev/null +++ b/product/src/tools/mqtt_tool/mainwindow.cpp @@ -0,0 +1,160 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "CommonSheet.h" + +#include + +MainWindow::MainWindow(QMqttClient *client , QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow), + _client(client) +{ + ui->setupUi(this); + + setWindowTitle(tr("MQTT通讯工具")); + + ui->conForm->init(client); + ui->pubForm->init(client); + ui->subForm->init(client); + + initQss(); + initView(); + initConn(); + +} + +MainWindow::~MainWindow() +{ + delete ui; + if( _client ) + { + if( _client->isConnected() ) + { + _client->disconnect(); + _client->loop_stop(); + } + } + _client = NULL; + mosqpp::lib_cleanup(); +} + +void MainWindow::initQss() +{ + CommonSheet sheetStyle; + QString sheet; + if(sheetStyle.getSheet(sheet)) + { + setStyleSheet(sheet); + }else + { +// LOGERROR("MainWindow::initSheet():获取样式文件失败!"); + } +} + +void MainWindow::initConn() +{ + connect(ui->pushButtonConnect,SIGNAL(clicked(bool)),this,SLOT(connectServer())); + connect(ui->pushButtonPusblish,SIGNAL(clicked(bool)),this,SLOT(publishTopic())); + connect(ui->pushButtonSubscribe,SIGNAL(clicked(bool)),this,SLOT(subscribeTopic())); + connect(ui->pushButtonQuit,SIGNAL(clicked(bool)),this,SLOT(quitApp())); + connect(ui->pushButtonClear,SIGNAL(clicked(bool)),this,SLOT(clearMsg())); + connect(ui->pushButtonAbout,SIGNAL(clicked(bool)),this,SLOT(aboutApp())); + + connect(_client , &QMqttClient::disconnected , ui->conForm , &ConnForm::updateUiStatus); + connect(_client , &QMqttClient::connected , ui->conForm , &ConnForm::updateUiStatus); + connect(_client , &QMqttClient::connected , this , &MainWindow::slotConnected); + connect(_client, &QMqttClient::error , this, &MainWindow::slotError); + connect(_client, &QMqttClient::published , this , &MainWindow::slotPublished); + connect(_client , &QMqttClient::messageReceived , this , &MainWindow::slotReceiveMsg); + connect(_client, &QMqttClient::subscribed , this , &MainWindow::slotSubscribed); + connect(_client , &QMqttClient::disconnected , this , &MainWindow::slotDisconnected); + +} + +void MainWindow::initView() +{ + //do something +} + +void MainWindow::slotError(QString errorMessage) +{ + log(errorMessage); +} + +void MainWindow::slotPublished() +{ + log(tr("published success!")); //待定 +} + +void MainWindow::slotSubscribed(const QString &topic) +{ + log(tr("subscribed %1").arg(topic)); +} + +void MainWindow::slotDisconnected() +{ + ui->pushButtonPusblish->setEnabled(false); + ui->pushButtonSubscribe->setEnabled(false); + log("disconnected"); +} + +void MainWindow::slotReceiveMsg(QMqttMessage message) +{ + log(tr("message recevied from %1:").arg(message.topic())); + log(message.payload()); +} + +void MainWindow::on_actionAbout_triggered() +{ + aboutApp(); +} + +void MainWindow::on_actionQuit_triggered() +{ + quitApp(); +} + +void MainWindow::slotConnected() +{ + log(tr("connected to %1:%2").arg(_client->host().toString()).arg(_client->port())); + ui->pushButtonPusblish->setEnabled(true); + ui->pushButtonSubscribe->setEnabled(true); +} + +void MainWindow::aboutApp() +{ + QMessageBox::information(NULL, tr("About QMQTT"), + tr("MQTT_TOOL")); +} + +void MainWindow::publishTopic() +{ + ui->stackedWidget->setCurrentWidget(ui->pubForm); + ui->pubForm->lineEditSetFocus(); +} + +void MainWindow::subscribeTopic() +{ + ui->stackedWidget->setCurrentWidget(ui->subForm); + ui->subForm->clearLineEdit(); // also sets focus to lineEdit +} + +void MainWindow::connectServer() +{ + ui->stackedWidget->setCurrentWidget(ui->conForm); +} + +void MainWindow::quitApp() +{ + qApp->quit(); +} + +void MainWindow::clearMsg() +{ + ui->logConsole->clear(); +} + +void MainWindow::log(const QString &msg) +{ + ui->logConsole->append(msg); +} diff --git a/product/src/tools/mqtt_tool/mainwindow.h b/product/src/tools/mqtt_tool/mainwindow.h new file mode 100644 index 00000000..04171ed6 --- /dev/null +++ b/product/src/tools/mqtt_tool/mainwindow.h @@ -0,0 +1,54 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +#include "QMqttClient.h" +#include "connform.h" +#include "subform.h" +#include "pubform.h" + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QMqttClient *client , QWidget *parent = 0); + ~MainWindow(); + +private slots: + void slotConnected(); + void slotError(QString errorMessage); + void slotPublished(); + void slotSubscribed(const QString &topic); + void slotDisconnected(); + void slotReceiveMsg(QMqttMessage message); + + void on_actionAbout_triggered(); + void on_actionQuit_triggered(); + + void aboutApp(); + void publishTopic(); + void subscribeTopic(); + void connectServer(); + void quitApp(); + void clearMsg(); + +private: + void log(const QString & msg); + void initQss(); + void initConn(); + void initView(); +private: + Ui::MainWindow *ui; + QMqttClient *_client; + ConnForm * _connDialog; + PubForm * _pubDialog; + SubForm * _subDialog; +}; + +#endif // MAINWINDOW_H diff --git a/product/src/tools/mqtt_tool/mainwindow.ui b/product/src/tools/mqtt_tool/mainwindow.ui new file mode 100644 index 00000000..2d49656e --- /dev/null +++ b/product/src/tools/mqtt_tool/mainwindow.ui @@ -0,0 +1,256 @@ + + + MainWindow + + + true + + + + 0 + 0 + 860 + 720 + + + + + 0 + 0 + + + + + 100000 + 100000 + + + + QMQTT + + + 1.000000000000000 + + + true + + + + true + + + Qt::LeftToRight + + + true + + + + + + + + 连接 + + + + + + + false + + + 订阅 + + + + + + + false + + + 发布 + + + + + + + 清除 + + + + + + + 退出 + + + + + + + + 0 + 0 + + + + 关于 + + + + + + + + + + + + 0 + 0 + + + + + + + + 9 + + + 0 + + + 9 + + + 9 + + + 6 + + + + + + 0 + 180 + + + + + 16777215 + 300 + + + + 0 + + + + + + + + + + + 0 + 400 + + + + + + logConsole + stackedWidget + + + + + + + + Qt::Vertical + + + + 20 + 495 + + + + + + + + + + 0 + 0 + 860 + 23 + + + + + 50 + false + + + + false + + + + File + + + + + + Help + + + + + + + + + Quit + + + + + About + + + + + + + ConnForm + QWidget +
connform.h
+ 1 +
+ + PubForm + QWidget +
pubform.h
+ 1 +
+ + SubForm + QWidget +
subform.h
+ 1 +
+
+ + +
diff --git a/product/src/tools/mqtt_tool/mqtt_tool.pro b/product/src/tools/mqtt_tool/mqtt_tool.pro new file mode 100644 index 00000000..294221ad --- /dev/null +++ b/product/src/tools/mqtt_tool/mqtt_tool.pro @@ -0,0 +1,72 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2024-09-29T09:39:56 +# +#------------------------------------------------- +# ARM板上资源有限,不会与云平台混用,不编译 +message("Compile only in x86 environment") +# requires(contains(QMAKE_HOST.arch, x86_64)) +requires(!contains(QMAKE_HOST.arch, aarch64):!linux-aarch64*) + +QT += core gui network concurrent + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = mqtt_tool +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +INCLUDEPATH += ../../fes/fes_idl_files/\ + ../../3rd/include/\ + ../../3rd/include/mosquitto/ \ + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + connform.cpp \ + pubform.cpp \ + subform.cpp \ + QMqttClient.cpp \ + QMqttMessage.cpp \ + CommonSheet.cpp + +HEADERS += \ + mainwindow.h \ + connform.h \ + pubform.h \ + subform.h \ + mqttform.h \ + QMqttClient.h \ + QMqttMessage.h \ + CommonSheet.h + +FORMS += \ + mainwindow.ui \ + connform.ui \ + pubform.ui \ + subform.ui + +LIBS = -ldb_base_api -ldb_api_ex -ldp_chg_data_api -lpub_logger_api\ + -lnet_msg_bus_api -lprotobuf -lpub_sysinfo_api -lpub_utility_api +LIBS += -lmosquitto -lmosquittopp + +include($$PWD/../../idl_files/idl_files.pri) +include($$PWD/../../fes/fes_idl_files/fes_idl_files.pri) + +#------------------------------------------------------------------- +COMMON_PRI=$$PWD/../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} diff --git a/product/src/tools/mqtt_tool/mqttform.h b/product/src/tools/mqtt_tool/mqttform.h new file mode 100644 index 00000000..63fc94a7 --- /dev/null +++ b/product/src/tools/mqtt_tool/mqttform.h @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2013-2017 Feng Lee + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#ifndef MQTTFORM_H +#define MQTTFORM_H + +#include +#include "QMqttClient.h" + +class MqttForm : public QWidget +{ + Q_OBJECT + +public: + explicit MqttForm(QWidget *parent = 0) : + QWidget(parent) { + } + + ~MqttForm() { + } + void init(QMqttClient *client) { + _client = client; + } + +protected: + QMqttClient *_client; + +}; + +#endif // MQTTFORM_H diff --git a/product/src/tools/mqtt_tool/pubform.cpp b/product/src/tools/mqtt_tool/pubform.cpp new file mode 100644 index 00000000..a5ba7e95 --- /dev/null +++ b/product/src/tools/mqtt_tool/pubform.cpp @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2013-2017 Feng Lee + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#include "pubform.h" +#include "ui_pubform.h" + +PubForm::PubForm(QWidget *parent) : + MqttForm(parent), + ui(new Ui::PubForm) +{ + ui->setupUi(this); + onPublishReady(); + + ui->pubButton->setShortcut(QKeySequence(tr("Ctrl+P"))); + +// connect(ui->pubButton , &QPushButton::clicked , this , &PubForm::onPublish); +} + +PubForm::~PubForm() +{ + delete ui; +} + +void PubForm::onPublishReady() +{ + ui->pubButton->setEnabled(!ui->topicLineEdit->text().isEmpty() + && !ui->payloadEdit->toPlainText().isEmpty()); +} + +void PubForm::onPublish() +{ + QMqttMessage msg( ui->topicLineEdit->text(), ui->payloadEdit->toPlainText().toUtf8()); + _client->publish(msg); +} + +void PubForm::lineEditSetFocus() +{ + ui->topicLineEdit->setFocus(); +} diff --git a/product/src/tools/mqtt_tool/pubform.h b/product/src/tools/mqtt_tool/pubform.h new file mode 100644 index 00000000..61643612 --- /dev/null +++ b/product/src/tools/mqtt_tool/pubform.h @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2013-2017 Feng Lee + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef PUBFORM_H +#define PUBFORM_H + +#include +#include "mqttform.h" + +namespace Ui { +class PubForm; +} + +class PubForm : public MqttForm +{ + Q_OBJECT + +public: + explicit PubForm(QWidget *parent = 0); + ~PubForm(); + void lineEditSetFocus(); + +public slots: + void onPublishReady(); + void onPublish(); + +private: + Ui::PubForm *ui; +}; + +#endif // PUBFORM_H diff --git a/product/src/tools/mqtt_tool/pubform.ui b/product/src/tools/mqtt_tool/pubform.ui new file mode 100644 index 00000000..9f0f1049 --- /dev/null +++ b/product/src/tools/mqtt_tool/pubform.ui @@ -0,0 +1,176 @@ + + + PubForm + + + + 0 + 0 + 540 + 222 + + + + Form + + + + 0 + + + 9 + + + + + + + + + + + + QOS0 + + + + + QOS1 + + + + + QOS2 + + + + + + + + 主题(*): + + + + + + + 发布信息(*): + + + + + + + QOS: + + + + + + + + + + + + + Retain: + + + + + + + + + + + + + + + 发布 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + topicLineEdit + qOSComboBox + retainCheckBox + payloadEdit + pubButton + + + + + pubButton + clicked() + PubForm + onPublish() + + + 507 + 23 + + + 539 + 104 + + + + + topicLineEdit + textEdited(QString) + PubForm + onPublishReady() + + + 193 + 38 + + + 435 + 3 + + + + + payloadEdit + textChanged() + PubForm + onPublishReady() + + + 371 + 152 + + + 446 + 252 + + + + + + onPublishReady() + onPublish() + + diff --git a/product/src/tools/mqtt_tool/subform.cpp b/product/src/tools/mqtt_tool/subform.cpp new file mode 100644 index 00000000..6c925641 --- /dev/null +++ b/product/src/tools/mqtt_tool/subform.cpp @@ -0,0 +1,104 @@ +#include + +#include "subform.h" +#include "ui_subform.h" + +SubForm::SubForm(QWidget *parent) : + MqttForm(parent), + ui(new Ui::SubForm) +{ + ui->setupUi(this); + topics = new QMap(); + + // clicking listWidget item, loads it into topicLineEdit (for "quick" unsubscribing) + connect(ui->listWidget, &QListWidget::itemClicked, [&](QListWidgetItem * item) {ui->topicLineEdit->setText(item->text());}); + ui->listWidget->setSelectionMode(QAbstractItemView::SingleSelection); + + // hitting Return in topicLineEdit, will subscribe or unsubscribe, if possible + connect(ui->topicLineEdit, &QLineEdit::returnPressed, + [&]() + {if (ui->subButton->isEnabled()) + onSubscribe(); + else if (ui->unsubButton->isEnabled()) + onUnsubscribe(); + }); + + ui->subButton->setShortcut(QKeySequence(tr("Ctrl+S"))); + ui->unsubButton->setShortcut(QKeySequence(tr("Ctrl+N"))); +} + +SubForm::~SubForm() +{ + delete ui; + delete topics; +} + +void SubForm::init(QMqttClient *client) +{ + MqttForm::init(client); + connect(_client, SIGNAL(subscribed(const QString &)), this, SLOT(onSubscribed(const QString &))); + connect(_client, SIGNAL(unsubscribed(const QString &)), this, SLOT(onUnsubscribed(const QString &))); +} + +void SubForm::onSubscribed(const QString &topic) +{ + if(!topics->contains(topic)) { + QListWidgetItem *item = new QListWidgetItem(topic); + topics->insert(topic, item); + ui->listWidget->addItem(item); + } + clearLineEdit(); +} + +void SubForm::onUnsubscribed(const QString &topic) +{ + if(topics->contains(topic)) { + QListWidgetItem *item = topics->take(topic); + ui->listWidget->removeItemWidget(item); + delete item; + } + clearLineEdit(); +} + +void SubForm::onTopicInput(QString topic) { + const bool topicAlreadSub = topics->contains(topic); + ui->subButton->setEnabled(!topic.isEmpty() && !topicAlreadSub); + ui->unsubButton->setEnabled(!topic.isEmpty() && topicAlreadSub); +} + +void SubForm::onSubscribe() +{ + QString topic = ui->topicLineEdit->text(); + int qos = ui->qosComboBox->currentIndex(); + QMqttMessage::QoS qqos; + switch (qos) { + case 0: + qqos = QMqttMessage::AT_MOST_ONCE; + break; + case 1: + qqos = QMqttMessage::AT_LEAST_ONCE; + break; + case 2: + qqos = QMqttMessage::EXACTLY_ONCE; + break; + default: + qqos = QMqttMessage::AT_MOST_ONCE; + break; + } + _client->subscribe(topic, qqos); +} + +void SubForm::onUnsubscribe() +{ + QString topic = ui->topicLineEdit->text(); + _client->unsubscribe(topic); +} + +void SubForm::clearLineEdit() +{ + ui->topicLineEdit->clear(); + ui->subButton->setEnabled(false); + ui->unsubButton->setEnabled(false); + ui->topicLineEdit->setFocus(); + ui->listWidget->clearSelection(); +} diff --git a/product/src/tools/mqtt_tool/subform.h b/product/src/tools/mqtt_tool/subform.h new file mode 100644 index 00000000..f84cc9f4 --- /dev/null +++ b/product/src/tools/mqtt_tool/subform.h @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2013-2017 Feng Lee + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#ifndef SUBFORM_H +#define SUBFORM_H + +#include +#include +#include "mqttform.h" + +namespace Ui { +class SubForm; +} + +class SubForm : public MqttForm +{ + Q_OBJECT + +public: + explicit SubForm(QWidget *parent = 0); + ~SubForm(); + void init(QMqttClient *client); + void clearLineEdit(); + +public slots: + void onTopicInput(QString topic); + void onSubscribe(); + void onUnsubscribe(); + +private slots: + void onSubscribed(const QString &topic); + void onUnsubscribed(const QString &topic); + +private: + Ui::SubForm *ui; + QMap *topics; +}; + +#endif // SUBFORM_H diff --git a/product/src/tools/mqtt_tool/subform.ui b/product/src/tools/mqtt_tool/subform.ui new file mode 100644 index 00000000..83ee68df --- /dev/null +++ b/product/src/tools/mqtt_tool/subform.ui @@ -0,0 +1,188 @@ + + + SubForm + + + + 0 + 0 + 540 + 235 + + + + Form + + + + 0 + + + 9 + + + + + + + + + + + + + + + 订阅主题: + + + topicLineEdit + + + + + + + + QOS0 + + + + + QOS1 + + + + + QOS2 + + + + + + + + Qos: + + + qosComboBox + + + + + + + + + + + + 订阅主题类: + + + + + + + + + + + + + + + + + 订阅 + + + + + + + 取消订阅 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + topicLineEdit + qosComboBox + subButton + unsubButton + listWidget + + + + + topicLineEdit + textChanged(QString) + SubForm + onTopicInput(QString) + + + 129 + 42 + + + 268 + 0 + + + + + subButton + clicked() + SubForm + onSubscribe() + + + 449 + 32 + + + 395 + 47 + + + + + unsubButton + clicked() + SubForm + onUnsubscribe() + + + 470 + 62 + + + 396 + 99 + + + + + + onSubscribe() + onUnsubscribe() + onTopicInput(QString) + + diff --git a/product/src/tools/net_msg_tool/NetThread.cpp b/product/src/tools/net_msg_tool/NetThread.cpp new file mode 100644 index 00000000..d3c7caba --- /dev/null +++ b/product/src/tools/net_msg_tool/NetThread.cpp @@ -0,0 +1,145 @@ +#include "NetThread.h" +#include "MessageChannel.h" +#include "Common.h" +#include +#include +#include "MessageChannel.h" + +NetThread::NetThread() : + CTimerThreadBase("NetThread thread", 50) +{ + m_nServerAppId = 0; + m_subChannelList.clear(); +} + +NetThread::~NetThread() +{ + auto iter = m_msgList.begin(); + for (; iter!=m_msgList.end(); ++iter) + { + delete *iter; + *iter = NULL; + } + m_msgList.clear(); + this->quit(); +} + +void NetThread::setAppID(int appid) +{ + m_nServerAppId = appid; +} + +bool NetThread::start() +{ + this->resume(); + return true; +} + +bool NetThread::stop() +{ + this->suspend(); + + auto iter = m_msgList.begin(); + for (; iter != m_msgList.end(); ++iter) + { + delete *iter; + *iter = NULL; + } + m_msgList.clear(); + + + return true; +} + +void NetThread::addSub(int channelId) +{ + m_subChannelList.push_back(channelId); +} + +void NetThread::removeSub(int channelID) +{ + m_subChannelList.remove(channelID); +} + +void NetThread::clearAllSub() +{ + m_subChannelList.clear(); +} + +bool NetThread::getMsg(std::list& msgList) +{ + QMutexLocker locker(&m_MsgMutex); + auto iter = m_msgList.begin(); + for (; iter != m_msgList.end(); ++iter) + { + msgList.push_back(*iter); + } + m_msgList.clear(); + + return true; +} + +int NetThread::getMsgNum() +{ + QMutexLocker locker(&m_MsgMutex); + return static_cast(m_msgList.size()); +} + +void NetThread::afterSuspend() +{ + auto iter = m_subChannelList.begin(); + for (; iter != m_subChannelList.end(); ++iter) + { + m_objRecvCMb.delSub(m_nServerAppId, *iter); + } +} + +void NetThread::afterResume() +{ + auto iter = m_subChannelList.begin(); + for (; iter != m_subChannelList.end(); ++iter) + { + m_objRecvCMb.addSub(m_nServerAppId, *iter); + } +} + +void NetThread::execute() +{ + //using namespace iot_idl; + + + if (!m_objRecvCMb.recvMsg(m_objRecvMsg, 500)) + { + return; + } + + QMutexLocker locker(&m_MsgMutex); + + iot_net::CMbMessage* msg = new iot_net::CMbMessage(m_objRecvMsg); + m_msgList.push_back(msg); + /* int appID = m_objRecvMsg.getAppID(); + int channelID = m_objRecvMsg.getChannelID(); + int msgType = m_objRecvMsg.getMsgType(); + int MsgPara1 = m_objRecvMsg.getPara1(); + int MsgPara2 = m_objRecvMsg.getPara2(); + std::string srcHost = m_objRecvMsg.getSrcHost(); + std::string srcProc = m_objRecvMsg.getSrcProc(); + std::string srcInst = m_objRecvMsg.getSrcInst(); + std::string srcComm = m_objRecvMsg.getSrcComm(); + int srcPid = m_objRecvMsg.getSrcPid(); + + QString dataTimeStr = QDateTime::currentDateTime().toString("YYYY-MM-DD hh:mm:ss.zzz"); + + std::string dataStr((const char*)m_objRecvMsg.getDataPtr(), m_objRecvMsg.getDataSize()); + + QString itemStr = QString("时间:[%1],消息主题应用ID:[%2],消息主题通道ID:[%3],消息内容类型:[%4],\ + 消息属性1:[%5],消息属性2:[%6],发送端主机名:[%7],发送端进程名:[%8],发送端实例名:[%9],发送端通讯器名:[%10],发送端进程ID:[%11],数据[%12]") + .arg(dataTimeStr).arg(appID).arg(channelID).arg(msgType).arg(MsgPara1).arg(MsgPara2) + .arg(QString::fromStdString(srcHost)) + .arg(QString::fromStdString(srcProc)) + .arg(QString::fromStdString(srcInst)) + .arg(QString::fromStdString(srcComm)) + .arg(srcPid).arg(""); + ;*/ + +} diff --git a/product/src/tools/net_msg_tool/NetThread.h b/product/src/tools/net_msg_tool/NetThread.h new file mode 100644 index 00000000..b40bfc35 --- /dev/null +++ b/product/src/tools/net_msg_tool/NetThread.h @@ -0,0 +1,47 @@ +#ifndef NETTHREAD_H +#define NETTHREAD_H +#include +#include +#include "pub_utility_api/TimerThreadBase.h" +#include "net/net_msg_bus_api/CMbCommunicator.h" + +class NetThread : public iot_public::CTimerThreadBase +{ +public: + NetThread(); + ~NetThread(); + + void setAppID(int appid); + + //开启线程 + bool start(); + + //停止线程 + bool stop(); + + void addSub(int channelId); + void removeSub(int channelID); + void clearAllSub(); + + bool getMsg(std::list& msgList); + int getMsgNum(); + + +protected: + void afterSuspend(); + void afterResume(); + void execute(); +private: + int m_nServerAppId; + std::list m_subChannelList; + iot_net::CMbMessage m_objRecvMsg; + + + iot_net::CMbCommunicator m_objSendCMb;//发送 + iot_net::CMbCommunicator m_objRecvCMb;//接收 + + QMutex m_MsgMutex; + std::list m_msgList; +}; + +#endif // NETTHREAD_H diff --git a/product/src/tools/net_msg_tool/main.cpp b/product/src/tools/net_msg_tool/main.cpp new file mode 100644 index 00000000..dee12a33 --- /dev/null +++ b/product/src/tools/net_msg_tool/main.cpp @@ -0,0 +1,64 @@ +#include "mainwindow.h" +#include +#include +#include "pub_logger_api/logger.h" +#include "net/net_msg_bus_api/MsgBusApi.h" +#include "pub_utility_api/FileStyle.h" +#include + +void loadStyle() +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss","zh","light"); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("net_msgbus_tool.qss","zh","light"); + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + qApp->setStyleSheet(qss); + } +} + + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + loadStyle(); + + iot_public::StartLogSystem("BASE", "net_msg_tool"); + + int nRet = iot_net::initMsgBus( + std::string("net_msg_tool").c_str(), + std::string("net_msg_tool").c_str()); + if (false == nRet) + { + return 0; + } + + { + MainWindow w; + w.showMaximized(); + + nRet = a.exec(); + } + + iot_net::releaseMsgBus(); + iot_public::StopLogSystem(); + + return nRet; +} diff --git a/product/src/tools/net_msg_tool/mainwindow.cpp b/product/src/tools/net_msg_tool/mainwindow.cpp new file mode 100644 index 00000000..680091bb --- /dev/null +++ b/product/src/tools/net_msg_tool/mainwindow.cpp @@ -0,0 +1,631 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "pub_logger_api/logger.h" +#include +#include +#include +#include +#include "net/net_msg_bus_api/MsgBusApi.h" +#include "public/pub_sysinfo_api/SysInfoApi.h" +#include "google/protobuf/compiler/importer.h" + +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/compiler/importer.h" +#include "google/protobuf/descriptor.h" + +#include +#include +#include + +#include "FesMessage.pb.h" + +MainWindow::MainWindow(QWidget *parent) : + CustomUiMainWindow(parent), + mRecvTimer(this), + ui(new Ui::MainWindow) +{ + setAutoLayout(true); + + ui->setupUi(this); + this->setWindowTitle("消息总线监控工具"); + mRecvTimer.setInterval(500); + + initViewData(); + + connect(ui->btnStart, SIGNAL(clicked()), + this, SLOT(slot_btnStartChicked())); + connect(ui->btnStop, SIGNAL(clicked()), + this, SLOT(slot_btnStopChicked())); + connect(ui->checkTreeBtn, SIGNAL(clicked()), + this, SLOT(slot_btnCheckTreeChicked())); + connect(ui->unCheckTreeBtn, SIGNAL(clicked()), + this, SLOT(slot_btnUnCheckTreeChicked())); + connect(ui->btnClear, SIGNAL(clicked()), + this, SLOT(slot_btnClear())); + connect(ui->btnPause, SIGNAL(clicked()), + this, SLOT(slot_btnPause())); + connect(ui->refreshBtn, SIGNAL(clicked()), + this, SLOT(slot_btnRefreshChicked())); + connect(&mRecvTimer, &QTimer::timeout, + this, &MainWindow::slot_timerTimeout); + connect(ui->ChanelList, SIGNAL(itemChanged(QTreeWidgetItem *,int)), + this, SLOT(slot_treeItemChanged(QTreeWidgetItem*, int))); + connect(ui->dataTree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), + this, SLOT(slot_treeItemClicked(QTreeWidgetItem*, int))); + + ui->ChanelList->setSelectionMode(QAbstractItemView::MultiSelection); + ui->splitter_3->setStretchFactor(0,7); + ui->splitter_3->setStretchFactor(1,3); + + ui->splitter->setStretchFactor(0,3); + ui->splitter->setStretchFactor(1,7); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::initViewData() +{ + ui->ChanelList->setColumnCount(3); + QStringList headerList; + headerList << "通道号"; + headerList << "描述"; + headerList << "key"; + ui->ChanelList->setHeaderLabels(headerList); + loadCfg(); + using namespace iot_public; + + CSysInfoInterfacePtr ptr; + bool ret = createSysInfoInstance(ptr); + if (!ret) + { + showMessage("创建createSysInfoInstance失败"); + return; + } + + ui->recvSubCb->clear(); + ui->recvSubCb->addItem("全部",0); + + mAppDescMap.clear(); + std::vector vecAppInfo; + ret = ptr->getAllAppInfo(vecAppInfo); + auto iter = vecAppInfo.begin(); + for (; iter!=vecAppInfo.end();++iter) + { + ui->recvSubCb->addItem(QString::fromStdString(iter->strDesc), iter->nId); + + mAppDescMap.insert(iter->nId, QString::fromStdString(iter->strDesc)); + } + ui->recvSubCb->setCurrentIndex(4); + + ui->dataTree->setColumnCount(12); + headerList.clear(); + headerList << "时间"; + headerList << "主题应用"; + headerList << "主题通道"; + headerList << "内容类型"; + headerList << "属性1"; + headerList << "属性2"; + headerList << "发送端主机名"; + headerList << "发送端进程名"; + headerList << "发送端实例名"; + headerList << "发送端通讯器名"; + headerList << "发送端进程ID"; + headerList << "数据长度"; + ui->dataTree->setHeaderLabels(headerList); + ui->dataTree->setColumnWidth(0,180); + ui->dataTree->setColumnWidth(3,40); + ui->dataTree->setColumnWidth(4,40); + ui->dataTree->setColumnWidth(5,40); +} + +bool MainWindow::loadCfg() +{ + mChannelDescMap.clear(); + mChannelFileNameMap.clear(); + mChannelMsgNameMap.clear(); + ui->ChanelList->clear(); + + QString exeFile = QApplication::applicationDirPath(); + QString cfgFIle = QString("%1/%2").arg(exeFile).arg(CN_XML_CONFIG_FILE_PATHFILE); + QFile xmlFile(cfgFIle); + + if (!xmlFile.exists()) { + LOGERROR("配置不存在:[%s]" ,xmlFile.fileName().toStdString().c_str()); + return false; + } + + if (!xmlFile.open(QIODevice::ReadOnly)) { + LOGERROR("文档打开失败:[%s]", xmlFile.fileName().toStdString().c_str()); + return false; + } + + QString moduleName; + QString moduleDesc; + + QString paramKey; + int paramNum; + + QTreeWidgetItem* topItem = NULL; + + QXmlStreamReader xmlReader(&xmlFile); + while (!xmlReader.atEnd() && !xmlReader.hasError()) { + QXmlStreamReader::TokenType token = xmlReader.readNext(); + if (token == QXmlStreamReader::StartElement && xmlReader.name().toString() == "module") { + topItem = new QTreeWidgetItem(ui->ChanelList); + paramNum = 0; + moduleName = xmlReader.attributes().value("name").toString(); + moduleDesc = xmlReader.attributes().value("description").toString(); + qDebug() << "Start module:name- " << moduleName << "desc-" << moduleDesc; + topItem->setText(0, moduleName); + topItem->setText(1, moduleDesc); + topItem->setCheckState(0, Qt::Unchecked); + } + else if (token == QXmlStreamReader::EndElement && xmlReader.name().toString() == "module") { + qDebug() << "End module:name- " << moduleName <<"desc-"<< moduleDesc; + } + + + if (token == QXmlStreamReader::StartElement && xmlReader.name().toString() == "param") { + paramKey = xmlReader.attributes().value("key").toString(); + QString paramvalue = xmlReader.attributes().value("value").toString(); + QString paramDesc = xmlReader.attributes().value("desc").toString(); + QString paramEnable = xmlReader.attributes().value("enable").toString(); + QString paramInfo = QString("Start param:key[%1],value[%2],desc[%3],enable[%4]") + .arg(paramKey).arg(paramvalue).arg(paramDesc).arg(paramEnable); + QString paramFileName = xmlReader.attributes().value("fileName").toString(); + QString paramMsg = xmlReader.attributes().value("msg").toString(); + + if (paramEnable != "true") + { + continue; + } + + int chlId = paramvalue.toInt(); + mChannelDescMap.insert(chlId, paramDesc); + mChannelFileNameMap.insert(chlId, paramFileName); + mChannelMsgNameMap.insert(chlId, paramMsg); + + paramNum++; + + if (topItem != NULL) + { + QTreeWidgetItem* item = new QTreeWidgetItem(topItem); + + item->setText(0, paramvalue); + item->setText(1, paramDesc); + item->setText(2, paramKey); + item->setCheckState(0, Qt::Unchecked); + } + + qDebug() << paramInfo; + + } + else if (token == QXmlStreamReader::EndElement && xmlReader.name().toString() == "param") { + + QString paramInfo = QString("end param:key[%1]") + .arg(paramKey); + qDebug() << paramInfo; + } + } + + if (xmlReader.hasError()) { + LOGERROR("XML Parsing Error: [%s]", xmlReader.errorString().toStdString().c_str()); + } + + xmlFile.close(); + + return true; +} + + +void MainWindow::showMessage(const QString& msg) +{ + ui->statusbar->showMessage(msg); +} + +void MainWindow::slot_btnStartChicked() +{ + m_itemCount = 0; + bool isCnt = iot_net::isConnected(); + + if (!isCnt) + { + showMessage("总线未连接上"); + return; + } + + mNetMng.clearAllSub(); + int itemCount = ui->ChanelList->topLevelItemCount(); + for (int i = 0; i < itemCount; i++) + { + QTreeWidgetItem* item = ui->ChanelList->topLevelItem(i); + if (!item) + { + continue; + } + + for (int i = 0; i < itemCount; i++) + { + QTreeWidgetItem* childItem = item->child(i); + if (!childItem) + { + continue; + } + + if (childItem->checkState(0) == Qt::Checked) + { + if (childItem->text(0).toInt() == 0) + { + QString desc = childItem->text(1); + showMessage(desc); + } + mNetMng.addSub(childItem->text(0).toInt()); + } + } + } + + QString customListStr = ui->customChannelText->text(); + if (!customListStr.isEmpty()) + { + QStringList customList = customListStr.split(","); + for (int i = 0; i < customList.size(); ++i) + { + mNetMng.addSub(customList.at(i).toInt()); + } + } + int appID = ui->recvSubCb->currentData().toInt(); + mNetMng.setAppID(appID); + mRecvTimer.start(); + mNetMng.start(); + + ui->btnStart->setEnabled(false); + ui->btnStop->setEnabled(true); + ui->btnPause->setEnabled(true); + ui->btnPause->setText("暂停"); + ui->conbfigGbbox->setEnabled(false); + + showMessage("开启成功"); +} + +void MainWindow::slot_btnStopChicked() +{ + mNetMng.stop(); + mRecvTimer.stop(); + showMessage("停止成功"); + + ui->btnStart->setEnabled(true); + ui->btnStop->setEnabled(false); + ui->btnPause->setEnabled(false); + ui->btnPause->setText("恢复"); + ui->conbfigGbbox->setEnabled(true); +} + +void MainWindow::slot_btnRefreshChicked() +{ + loadCfg(); +} + +void MainWindow::slot_btnCheckTreeChicked() +{ + QTreeWidgetItemIterator iter(ui->ChanelList); + + while (*iter) + { + (*iter)->setCheckState(0, Qt::Checked); + ++iter; + } +} + +void MainWindow::slot_btnUnCheckTreeChicked() +{ + QTreeWidgetItemIterator iter(ui->ChanelList); + + while (*iter) + { + (*iter)->setCheckState(0, Qt::Unchecked); + ++iter; + } +} + +void MainWindow::slot_timerTimeout() +{ + std::list msgList; + bool isRet = mNetMng.getMsg(msgList); + if (!isRet) + { + return; + } + + auto iter = msgList.begin(); + for (; iter!=msgList.end(); ++iter) + { + iot_net::CMbMessage* msg = *iter; + + showMsg(*msg); + + delete msg; + msg = NULL; + } + + msgList.clear(); + +} + +void MainWindow::slot_btnClear() +{ + ui->dataTree->clear(); +} + +void MainWindow::slot_btnPause() +{ + if (mRecvTimer.isActive()) + { + mRecvTimer.stop(); + ui->btnPause->setText("恢复"); + showMessage("暂停成功"); + } + else + { + mRecvTimer.start(); + ui->btnPause->setText("暂停"); + showMessage("恢复成功"); + } +} + +void MainWindow::slot_treeItemChanged(QTreeWidgetItem *item, int column) +{ + Q_UNUSED(column); + QString itemText = item->text(0); + + //选中时 + if (Qt::Checked == item->checkState(0)) + { + + int count = item->childCount(); + if (count > 0) + { + for (int i = 0; i < count; i++) + { + //子节点也被选中 + item->child(i)->setCheckState(0, Qt::Checked); + } + updateParentItem(item); + } + else + { + //是子节点 + updateParentItem(item); + } + } + else if (Qt::Unchecked == item->checkState(0)) + { + int count = item->childCount(); + if (count > 0) + { + for (int i = 0; i < count; i++) + { + item->child(i)->setCheckState(0, Qt::Unchecked); + } + updateParentItem(item); + } + else + { + //是子节点 + updateParentItem(item); + } + } + else if (Qt::PartiallyChecked == item->checkState(0)) + { + updateParentItem(item); + } +} + +void MainWindow::slot_treeItemClicked(QTreeWidgetItem *item, int column) +{ + Q_UNUSED(column); + + QVariant itemData = item->data(11,Qt::UserRole+1); + QByteArray data = itemData.toByteArray(); + + int chId = item->data(2,Qt::UserRole+1).toInt(); + QString dataStr = potobufDataToStr(chId,data); + if(dataStr.isEmpty()) + { + dataStr = "解析错误!"; + } + + ui->dataSizeText->setText(QString::number(data.size())); + ui->dataText->setText(dataStr); +} + +void MainWindow::updateParentItem(QTreeWidgetItem *item) +{ + QTreeWidgetItem* parent = item->parent(); + if (parent == NULL) + { + return; + } + //选中的子节点个数 + int selectCount = 0; + int partiallySelectCount = 0; + + int childCount = parent->childCount(); + for (int i = 0; i < childCount; i++) + { + QTreeWidgetItem* childItem = parent->child(i); + if (childItem->checkState(0) == Qt::Checked) + { + selectCount++; + } + else if (childItem->checkState(0) == Qt::PartiallyChecked) + { + partiallySelectCount++; + } + } + if (selectCount <= 0 && partiallySelectCount <= 0) + { + //未选中状态 + parent->setCheckState(0, Qt::Unchecked); + } + else if ((selectCount > 0 && selectCount < childCount) || (partiallySelectCount > 0)) + { + //部分选中状态 + parent->setCheckState(0, Qt::PartiallyChecked); + } + else if (selectCount == childCount) + { + //选中状态 + parent->setCheckState(0, Qt::Checked); + } +} + +void MainWindow::showMsg(const iot_net::CMbMessage& msg) +{ + std::string msgInfo = msg.printInfoToStr(); + if (msgInfo.empty()) + { + return; + } + + LOGINFO(msgInfo.c_str()); + + int appID = msg.getAppID(); + int channelID = msg.getChannelID(); + int msgType = msg.getMsgType(); + int MsgPara1 = msg.getPara1(); + int MsgPara2 = msg.getPara2(); + std::string srcHost = msg.getSrcHost(); + std::string srcProc = msg.getSrcProc(); + std::string srcInst = msg.getSrcInst(); + std::string srcComm = msg.getSrcComm(); + int srcPid = msg.getSrcPid(); + + + QString dataTimeStr = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"); + + QByteArray dataStr ((const char*)msg.getDataPtr(), static_cast(msg.getDataSize()) ); + + +// QString itemStr = QString("时间:[%1],消息主题应用ID:[%2],消息主题通道ID:[%3],消息内容类型:[%4],\ +// 消息属性1:[%5],消息属性2:[%6],发送端主机名:[%7],发送端进程名:[%8],发送端实例名:[%9],发送端通讯器名:[%10],发送端进程ID:[%11],数据[%12]") +// .arg(dataTimeStr).arg(appID).arg(channelID).arg(msgType).arg(MsgPara1).arg(MsgPara2) +// .arg(QString::fromStdString(srcHost)) +// .arg(QString::fromStdString(srcProc)) +// .arg(QString::fromStdString(srcInst)) +// .arg(QString::fromStdString(srcComm)) +// .arg(srcPid).arg(QString(dataStr)); + + m_itemCount++; + QTreeWidgetItem* item = new QTreeWidgetItem(ui->dataTree); + item->setText(0, dataTimeStr); + item->setText(1, QString("%1(%2)").arg(appID).arg(mAppDescMap.value(appID))); + item->setText(2, QString("%1(%2)").arg(channelID).arg(mChannelDescMap.value(channelID))); + item->setData(2,Qt::UserRole+1,channelID); + item->setText(3, QString::number(msgType)); + item->setText(4, QString::number(MsgPara1)); + item->setText(5, QString::number(MsgPara2)); + item->setText(6, QString::fromStdString(srcHost)); + item->setText(7, QString::fromStdString(srcProc)); + item->setText(8, QString::fromStdString(srcInst)); + item->setText(9, QString::fromStdString(srcComm)); + item->setText(10, QString::number(srcPid)); + item->setText(11, QString::number(dataStr.size())); + item->setData(11, Qt::UserRole+1,QVariant(dataStr)); + + if (ui->dataTree->topLevelItemCount() > 500) + { + QList list; + for (int i=0; i<200; ++i) + { + list.push_back(ui->dataTree->topLevelItem(i)); + } + + auto iter = list.begin(); + for (; iter!=list.end(); ++iter) + { + delete *iter; + *iter = NULL; + } + list.clear(); + } +} + +QString MainWindow::potobufDataToStr(int chId, const QByteArray &data) +{ + std::string serialized_data(data.toStdString().c_str(),data.length()); + + using namespace iot_idl; + using namespace google::protobuf; + using namespace google::protobuf::compiler; + + QString fixPath = "..\\common\\sysconfig\\potobuf"; + +#ifdef Q_OS_UNIX + fixPath.replace("\\", "/"); +#endif + + google::protobuf::compiler::DiskSourceTree sourceTree; + sourceTree.MapPath("", fixPath.toStdString()); + google::protobuf::compiler::Importer importer(&sourceTree, NULL); + + QString fileName = mChannelFileNameMap.value(chId); + if(fileName.isEmpty()) + { + return QString("potobuf配置为空,消息内容:[%1]").arg(QString(data)); + } + + const google::protobuf::FileDescriptor *file = importer.Import(fileName.toStdString()); + if (file == NULL) { + return QString("未找到potobuf文件,文件名[%2],消息内容:[%1]").arg(QString(data)).arg(fileName); + } + + QString msgListStr = mChannelMsgNameMap.value(chId); + if(msgListStr.isEmpty()) + { + return QString("potobuf消息配置为空,消息内容:[%1]").arg(QString(data)); + } + + QStringList msgList = msgListStr.split(","); + for(int i=0; iFindMessageTypeByName(msgStr.toStdString()); + + if(!descptor) + { + continue; + } + + const Message* msg = message_factory.GetPrototype(descptor); + if(!msg) + { + continue; + } + + Message* newMessage = msg->New(); + if(!newMessage) + { + continue; + } + + bool ret = newMessage->ParseFromString(serialized_data); + if(!ret) + { + continue; + } + + std::string content= newMessage->DebugString(); + + delete newMessage; + newMessage = NULL; + + return QString::fromStdString(content); + } + + return QString("未匹配对应的消息结构体,消息内容:[%1]").arg(QString(data)); +} diff --git a/product/src/tools/net_msg_tool/mainwindow.h b/product/src/tools/net_msg_tool/mainwindow.h new file mode 100644 index 00000000..95ca22f8 --- /dev/null +++ b/product/src/tools/net_msg_tool/mainwindow.h @@ -0,0 +1,64 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include "NetThread.h" +#include "net/net_msg_bus_api/CMbCommunicator.h" +#include "pub_widget/CustomMainWindow.h" + +namespace Ui { +class MainWindow; +} + +const QString CN_XML_CONFIG_FILE_PATHFILE = "../common/sysconfig/netbus_channel_cfg.xml"; //配置文件所在目录 + +class MainWindow : public CustomUiMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); +private: + void initViewData(); + bool loadCfg(); + + + void showMessage(const QString& msg); + +private slots: + void slot_timerTimeout(); + void slot_btnClear(); + void slot_btnPause(); + void slot_treeItemChanged(QTreeWidgetItem *item, int column); + void slot_treeItemClicked(QTreeWidgetItem *item, int column); + + void slot_btnStartChicked(); + void slot_btnStopChicked(); + + void slot_btnRefreshChicked(); + + void slot_btnCheckTreeChicked(); + void slot_btnUnCheckTreeChicked(); +private: + void updateParentItem(QTreeWidgetItem *item); + void showMsg(const iot_net::CMbMessage& msg); + QString potobufDataToStr(int chId, const QByteArray& data); + +private: + Ui::MainWindow *ui; + + QTimer mRecvTimer; + NetThread mNetMng; + + QMap mAppDescMap; + QMap mChannelDescMap; + QMap mChannelFileNameMap; + QMap mChannelMsgNameMap; + + int m_itemCount; +}; + +#endif // MAINWINDOW_H diff --git a/product/src/tools/net_msg_tool/mainwindow.ui b/product/src/tools/net_msg_tool/mainwindow.ui new file mode 100644 index 00000000..87f642ce --- /dev/null +++ b/product/src/tools/net_msg_tool/mainwindow.ui @@ -0,0 +1,341 @@ + + + MainWindow + + + + 0 + 0 + 906 + 654 + + + + MainWindow + + + + + + + Qt::Vertical + + + + Qt::Horizontal + + + + + + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 自定义通道号 + + + + + + + + + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 刷新 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 全勾选 + + + + + + + 全取消 + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 接收 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 1 + + + + + + + + + + + + + + + 应用 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 开始 + + + + + + + 停止 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 暂停 + + + + + + + 清理 + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 数据长度 + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + 906 + 22 + + + + + + + + diff --git a/product/src/tools/net_msg_tool/net_msg_tool.pro b/product/src/tools/net_msg_tool/net_msg_tool.pro new file mode 100644 index 00000000..2f6f093c --- /dev/null +++ b/product/src/tools/net_msg_tool/net_msg_tool.pro @@ -0,0 +1,60 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-05-28T09:42:46 +# +#------------------------------------------------- + +QT += core gui sql + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = net_msgbus_tool +TEMPLATE = app + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + NetThread.cpp + +HEADERS += \ + mainwindow.h \ + NetThread.h + + + + +FORMS += \ + mainwindow.ui + + +LIBS += -lboost_filesystem -lboost_system -lboost_thread -lboost_date_time +LIBS += -llog4cplus \ + -lprotobuf \ + -lpub_logger_api \ + -lpub_utility_api \ + -lnet_msg_bus_api \ + -lpub_sysinfo_api \ + -lpub_widget + +include($$PWD/../../idl_files/idl_files.pri) + +COMMON_PRI=$$PWD/../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} diff --git a/product/src/tools/style_tool/AboutDlg.cpp b/product/src/tools/style_tool/AboutDlg.cpp new file mode 100644 index 00000000..f57036ba --- /dev/null +++ b/product/src/tools/style_tool/AboutDlg.cpp @@ -0,0 +1,138 @@ +#include "AboutDlg.h" +#include +#include +#include +#include + +AboutDlg::AboutDlg( QWidget *parent ) + : CustomDialog( parent ) +{ + QString txt = QString( "%1 %2" ).arg( tr( "关于" ) ).arg( tr( "EMS能量管理系统" ) ); + setWindowTitle( txt ); + + //setCloseBtnVisible( false ); + + QGridLayout* gridLayout_2 = new QGridLayout(this); + gridLayout_2->setContentsMargins(0, 0, 0, 0); + gridLayout_2->setSpacing(0); + gridLayout_2->setObjectName(QStringLiteral("gridLayout_2")); + + QWidget*centralWidget = initWidget(); + gridLayout_2->addWidget(centralWidget); + this->setLayout(gridLayout_2); + + //this->setCentralWidget(centralWidget); + + connect( m_btnEnter, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect(m_btnEnter, SIGNAL(clicked()), this,SLOT(slot_test())); + + resize( 500, 300 ); +} + +AboutDlg::~AboutDlg() +{ +} + +void AboutDlg::resizeEvent( QResizeEvent *ev ) +{ + CustomDialog::resizeEvent( ev ); + +// const int y = 65; +// const int w = ev->size().width(); +// const int h = ev->size().height(); + +// m_icon->setGeometry( 20, y + 60, 48, 48 ); +// m_label1->setGeometry( 96, y, w - 100, 48 ); +// m_label2->setGeometry( 96, y + 40 , w - 100, 48 ); +// m_label3->setGeometry( 96, y + 80, w - 100, 48 ); +// m_label4->setGeometry( 96, y + 120, w - 100, 48 ); + // m_btnEnter->setGeometry( w - 120, h - 45, 90, 35 ); +} + +void AboutDlg::slot_test() +{ + +} + +QWidget *AboutDlg::initWidget() +{ + QWidget*centralWidget = new QWidget(this); + QString txt; + + m_icon = new AdaptImage( ":/skin/NVMS-9000.ico", centralWidget ); + + txt = QString( "%1: %2" ).arg( tr( "系统名称" ) ).arg( tr( "EMS能量管理系统" ) ); + m_label1 = new CustomLabel( txt, centralWidget );//名称 + + txt = QString( "%1: %2" ).arg( tr( "版本" ) ).arg( "v1.0.1" ); + m_label2 = new CustomLabel( txt, centralWidget );//版本 + + + txt = __DATE__;//编译时的日期 + QLocale english( QLocale::English ); + QDate date = english.toDate( txt, "MMM d yyyy" );//"Jul 17 2013" + txt = date.toString( "yyyy/MM/dd" ); + txt = tr( "日期" ) + txt; + m_label3 = new CustomLabel( txt, centralWidget ); + + m_label4 = new CustomLabel( tr( "版权" ), centralWidget );//版权 + + m_btnEnter = new CustomPushButton( tr( "确认" ), centralWidget ); + + + + centralWidget->setObjectName(QStringLiteral("centralWidget")); + + QGridLayout* gridLayout_2 = new QGridLayout(centralWidget); + gridLayout_2->setObjectName(QStringLiteral("gridLayout_2")); + QGridLayout* gridLayout = new QGridLayout(); + gridLayout->setObjectName(QStringLiteral("gridLayout")); + QSpacerItem* verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + gridLayout->addItem(verticalSpacer_2, 0, 1, 1, 1); + + QSpacerItem* horizontalSpacer_3 = new QSpacerItem(38, 18, QSizePolicy::Expanding, QSizePolicy::Minimum); + + gridLayout->addItem(horizontalSpacer_3, 1, 0, 1, 1); + + QVBoxLayout* verticalLayout = new QVBoxLayout(); + verticalLayout->setObjectName(QStringLiteral("verticalLayout")); + + + verticalLayout->addWidget(m_icon); + verticalLayout->addWidget(m_label1); + verticalLayout->addWidget(m_label2); + verticalLayout->addWidget(m_label3); + verticalLayout->addWidget(m_label4); + + gridLayout->addLayout(verticalLayout, 1, 1, 1, 1); + + QSpacerItem* horizontalSpacer_4 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + gridLayout->addItem(horizontalSpacer_4, 1, 2, 1, 1); + + QSpacerItem* verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + gridLayout->addItem(verticalSpacer, 2, 1, 1, 1); + + + gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1); + + QHBoxLayout* horizontalLayout = new QHBoxLayout(); + horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); + QSpacerItem* horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + horizontalLayout->addItem(horizontalSpacer); + + horizontalLayout->addWidget(m_btnEnter); + + QSpacerItem* horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + horizontalLayout->addItem(horizontalSpacer_2); + + + gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1); + + + return centralWidget; +} diff --git a/product/src/tools/style_tool/AboutDlg.h b/product/src/tools/style_tool/AboutDlg.h new file mode 100644 index 00000000..6bb031de --- /dev/null +++ b/product/src/tools/style_tool/AboutDlg.h @@ -0,0 +1,31 @@ +#ifndef ABOUTDLG_H +#define ABOUTDLG_H + +#include "pub_widget/CustomDialog.h" + +class AboutDlg : public CustomDialog +{ + Q_OBJECT +public: + explicit AboutDlg( QWidget *parent = 0 ); + ~AboutDlg(); + +protected: + virtual void resizeEvent( QResizeEvent *ev ); + +private slots: + void slot_test(); + +private: + QWidget* initWidget(); + +private: + AdaptImage *m_icon; + CustomLabel *m_label1; + CustomLabel *m_label2; + CustomLabel *m_label3; + CustomLabel *m_label4; + CustomPushButton *m_btnEnter; +}; + +#endif // ABOUTDLG_H diff --git a/product/src/tools/style_tool/LoginDlg.cpp b/product/src/tools/style_tool/LoginDlg.cpp new file mode 100644 index 00000000..f04cff15 --- /dev/null +++ b/product/src/tools/style_tool/LoginDlg.cpp @@ -0,0 +1,19 @@ +#include "LoginDlg.h" +#include "ui_LoginDlg.h" + +LoginDlg::LoginDlg(QWidget *parent) : + CustomUiDialog(parent), + ui(new Ui::LoginDlg) +{ + ui->setupUi(this); + + //如果不需要关闭 + //setCloseBtnVisible( false ); + + setAutoLayout(true); +} + +LoginDlg::~LoginDlg() +{ + delete ui; +} diff --git a/product/src/tools/style_tool/LoginDlg.h b/product/src/tools/style_tool/LoginDlg.h new file mode 100644 index 00000000..de5c3b54 --- /dev/null +++ b/product/src/tools/style_tool/LoginDlg.h @@ -0,0 +1,23 @@ +#ifndef LOGINDLG_H +#define LOGINDLG_H + +#include +#include "pub_widget/CustomDialog.h" + +namespace Ui { +class LoginDlg; +} + +class LoginDlg : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit LoginDlg(QWidget *parent = 0); + ~LoginDlg(); + +private: + Ui::LoginDlg *ui; +}; + +#endif // LOGINDLG_H diff --git a/product/src/tools/style_tool/LoginDlg.ui b/product/src/tools/style_tool/LoginDlg.ui new file mode 100644 index 00000000..583b0af8 --- /dev/null +++ b/product/src/tools/style_tool/LoginDlg.ui @@ -0,0 +1,145 @@ + + + LoginDlg + + + + 0 + 0 + 293 + 233 + + + + Dialog + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 登录 + + + + + + + 取消 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 账号 + + + + + + + + + + 密码 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + pushButton + clicked() + LoginDlg + accept() + + + 120 + 206 + + + 37 + 204 + + + + + diff --git a/product/src/tools/style_tool/MainWindow2.cpp b/product/src/tools/style_tool/MainWindow2.cpp new file mode 100644 index 00000000..27b02f05 --- /dev/null +++ b/product/src/tools/style_tool/MainWindow2.cpp @@ -0,0 +1,151 @@ +#include "MainWindow2.h" +#include +#include "pub_utility_api/FileStyle.h" + +MainWindow2::MainWindow2(QWidget *parent) : CustomMainWindow(parent) +{ + QString txt = QString( "%1 %2" ).arg( tr( "关于" ) ).arg( tr( "EMS能量管理系统" ) ); + setWindowTitle( txt ); + + QGridLayout* gridLayout_2 = new QGridLayout(this); + gridLayout_2->setContentsMargins(0, 0, 0, 0); + gridLayout_2->setSpacing(0); + gridLayout_2->setObjectName(QStringLiteral("gridLayout_2")); + + QWidget*centralWidget = initWidget(); + gridLayout_2->addWidget(centralWidget); + this->setLayout(gridLayout_2); + + connect( m_btnEnter, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect(m_btnEnter, SIGNAL(clicked()), this,SLOT(slot_test())); + + resize( 500, 300 ); + + initStyleSheet("zh", "light"); +} + +MainWindow2::~MainWindow2() +{ + +} + +void MainWindow2::slot_test() +{ + +} + +QWidget *MainWindow2::initWidget() +{ + QWidget*centralWidget = new QWidget(this); + QString txt; + + m_icon = new AdaptImage( ":/skin/NVMS-9000.ico", centralWidget ); + + txt = QString( "%1: %2" ).arg( tr( "系统名称" ) ).arg( tr( "EMS能量管理系统" ) ); + m_label1 = new CustomLabel( txt, centralWidget );//名称 + + txt = QString( "%1: %2" ).arg( tr( "版本" ) ).arg( "v1.0.1" ); + m_label2 = new CustomLabel( txt, centralWidget );//版本 + + + txt = __DATE__;//编译时的日期 + QLocale english( QLocale::English ); + QDate date = english.toDate( txt, "MMM d yyyy" );//"Jul 17 2013" + txt = date.toString( "yyyy/MM/dd" ); + txt = tr( "日期" ) + txt; + m_label3 = new CustomLabel( txt, centralWidget ); + + m_label4 = new CustomLabel( tr( "版权" ), centralWidget );//版权 + + m_btnEnter = new CustomPushButton( tr( "确认" ), centralWidget ); + + + + centralWidget->setObjectName(QStringLiteral("centralWidget")); + + QGridLayout* gridLayout_2 = new QGridLayout(centralWidget); + gridLayout_2->setObjectName(QStringLiteral("gridLayout_2")); + QGridLayout* gridLayout = new QGridLayout(); + gridLayout->setObjectName(QStringLiteral("gridLayout")); + QSpacerItem* verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + gridLayout->addItem(verticalSpacer_2, 0, 1, 1, 1); + + QSpacerItem* horizontalSpacer_3 = new QSpacerItem(38, 18, QSizePolicy::Expanding, QSizePolicy::Minimum); + + gridLayout->addItem(horizontalSpacer_3, 1, 0, 1, 1); + + QVBoxLayout* verticalLayout = new QVBoxLayout(); + verticalLayout->setObjectName(QStringLiteral("verticalLayout")); + + + verticalLayout->addWidget(m_icon); + verticalLayout->addWidget(m_label1); + verticalLayout->addWidget(m_label2); + verticalLayout->addWidget(m_label3); + verticalLayout->addWidget(m_label4); + + gridLayout->addLayout(verticalLayout, 1, 1, 1, 1); + + QSpacerItem* horizontalSpacer_4 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + gridLayout->addItem(horizontalSpacer_4, 1, 2, 1, 1); + + QSpacerItem* verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + gridLayout->addItem(verticalSpacer, 2, 1, 1, 1); + + + gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1); + + QHBoxLayout* horizontalLayout = new QHBoxLayout(); + horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); + QSpacerItem* horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + horizontalLayout->addItem(horizontalSpacer); + + horizontalLayout->addWidget(m_btnEnter); + + QSpacerItem* horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + horizontalLayout->addItem(horizontalSpacer_2); + + + gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1); + + + return centralWidget; +} + +void MainWindow2::initStyleSheet(const QString &strLang, const QString &strStyle) +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss", + strLang.toStdString(), + strStyle.toStdString()); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("style_tool.qss", + strLang.toStdString(), + strStyle.toStdString()); + + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + setStyleSheet(qss); + } +} diff --git a/product/src/tools/style_tool/MainWindow2.h b/product/src/tools/style_tool/MainWindow2.h new file mode 100644 index 00000000..f9af388a --- /dev/null +++ b/product/src/tools/style_tool/MainWindow2.h @@ -0,0 +1,34 @@ +#ifndef MAINWINDOW2_H +#define MAINWINDOW2_H + +#include +#include +#include "pub_widget/Widgets.h" +#include "pub_widget/CustomMainWindow.h" + +class MainWindow2 : public CustomMainWindow +{ + Q_OBJECT +public: + explicit MainWindow2(QWidget *parent = nullptr); + ~MainWindow2(); +signals: + +private slots: + void slot_test(); + +private: + QWidget* initWidget(); + +private: + void initStyleSheet(const QString &strLang, const QString &strStyle); +private: + AdaptImage *m_icon; + CustomLabel *m_label1; + CustomLabel *m_label2; + CustomLabel *m_label3; + CustomLabel *m_label4; + CustomPushButton *m_btnEnter; +}; + +#endif // MAINWINDOW2_H diff --git a/product/src/tools/style_tool/main.cpp b/product/src/tools/style_tool/main.cpp new file mode 100644 index 00000000..a7e90e5e --- /dev/null +++ b/product/src/tools/style_tool/main.cpp @@ -0,0 +1,20 @@ +#include "MainWindow2.h" +#include "mainwindow.h" +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + int nRet = 0; + + { + MainWindow w; + w.showMaximized(); + + nRet = a.exec(); + } + + return nRet; +} diff --git a/product/src/tools/style_tool/mainwindow.cpp b/product/src/tools/style_tool/mainwindow.cpp new file mode 100644 index 00000000..d3eb96cd --- /dev/null +++ b/product/src/tools/style_tool/mainwindow.cpp @@ -0,0 +1,269 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include +#include +#include +#include "pub_logger_api/logger.h" +#include "pub_widget/MainTitle.h" +#include "pub_utility_api/FileStyle.h" +#include "pub_widget/AlertMessageBox.h" +#include "pub_widget/MessageBox.h" +#include "AboutDlg.h" +#include "LoginDlg.h" + +MainWindow::MainWindow(QWidget *parent) : + CustomUiMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + this->setWindowTitle("EMS能量管理系统-样式测试工具"); + + ui->rbd_zh->setChecked(true); + ui->rdb_light->setChecked(true); + ui->tabWidget->setCurrentIndex(0); + + connect(ui->btn_refresh, SIGNAL(clicked()),this, SLOT(slot_btnRefreshChick())); + connect(ui->msgbox_info_btn, SIGNAL(clicked()),this, SLOT(slot_msgbox_info_btn_Chick())); + connect(ui->msgbox_critical_btn, SIGNAL(clicked()),this, SLOT(slot_msgbox_critical_btn_Chick())); + connect(ui->msgbox_warning_btn, SIGNAL(clicked()),this, SLOT(slot_msgbox_warning_btn_Chick())); + connect(ui->msgbox_question_btn, SIGNAL(clicked()),this, SLOT(slot_msgbox_question_btn_Chick())); + connect(ui->msgbox_about_btn, SIGNAL(clicked()),this, SLOT(slot_msgbox_about_btn_Chick())); + connect(ui->msgbox_exec_btn, SIGNAL(clicked()),this, SLOT(slot_msgbox_exec_btn_Chick())); + + connect(ui->cst_msg_info_btn, SIGNAL(clicked()),this, SLOT(slot_cst_msgbox_info_btn_Chick())); + connect(ui->cst_msg_warning_btn, SIGNAL(clicked()),this, SLOT(slot_cst_msgbox_warning_btn_Chick())); + connect(ui->cst_msg_question_btn, SIGNAL(clicked()),this, SLOT(slot_cst_msgbox_question_btn_Chick())); + connect(ui->cst_msg_choice_btn, SIGNAL(clicked()),this, SLOT(slot_cst_msgbox_choice_btn_Chick())); + connect(ui->cst_msg_error_btn, SIGNAL(clicked()),this, SLOT(slot_cst_msgbox_error_btn_Chick())); + connect(ui->cst_msg_error_choice_btn, SIGNAL(clicked()),this, SLOT(slot_cst_msgbox_error_choice_btn_Chick())); + + connect(ui->login_dlg_exec_btn, SIGNAL(clicked()),this, SLOT(slot_login_dlg_btn_Chick())); + connect(ui->about_dlg_exec_btn, SIGNAL(clicked()),this, SLOT(slot_about_dlg_btn_Chick())); + + connect(ui->alert_msg_info_btn, SIGNAL(clicked()),this, SLOT(slot_alert_msgbox_info_btn_Chick())); + connect(ui->alert_msg_warning_btn, SIGNAL(clicked()),this, SLOT(slot_alert_msgbox_warning_btn_Chick())); + connect(ui->alert_msg_error_btn, SIGNAL(clicked()),this, SLOT(slot_alert_msgbox_error_btn_Chick())); + + connect(ui->memuForm, SIGNAL(buttonClicked(int)),ui->tabWidget, SLOT(setCurrentIndex(int))); + + + slot_btnRefreshChick(); + + QStringList list; + list<setObjectName("btn_sysState"); + btn->setText(list.at(i)); + ui->memuForm->addToolBtn(btn); + } + + + setTitleWidget(ui->mainmenu); +} + +MainWindow::~MainWindow() +{ + delete ui; + + AlertMessageBox::ReleaseInstance(); +} + +void MainWindow::initStyleSheet(const QString &strLang, const QString &strStyle) +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss", + strLang.toStdString(), + strStyle.toStdString()); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("style_tool.qss", + strLang.toStdString(), + strStyle.toStdString()); + + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + setStyleSheet(qss); + } +} + +void MainWindow::slot_btnRefreshChick() +{ + QString curExePath = QApplication::applicationFilePath(); + + + QString strLang; + QString strStyle; + if (ui->rbd_zh->isChecked()) + { + strLang = "zh"; + } + else + { + strLang = "en"; + } + + if (ui->rdb_dark->isChecked()) + { + strStyle = "dark"; + } + else + { + strStyle = "light"; + } + + qApp->setStyleSheet(""); + initStyleSheet(strLang, strStyle); +} + +void MainWindow::slot_msgbox_info_btn_Chick() +{ + QMessageBox::StandardButton button + = QMessageBox::information(this, "information", "是否退出窗口", + QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton); + if (button == QMessageBox::StandardButton::Yes) { + qDebug() << "QMessageBox::StandardButton::Yes"; + } else if (button == QMessageBox::StandardButton::No) { + qDebug() << "QMessageBox::StandardButton::No"; + } +} + +void MainWindow::slot_msgbox_critical_btn_Chick() +{ + QMessageBox::StandardButton button = QMessageBox::critical(this, "critical", "文件下载出错,是否重新下载?", + QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton); + if (button == QMessageBox::StandardButton::Yes) { + qDebug() << "QMessageBox::StandardButton::Yes"; + } else if (button == QMessageBox::StandardButton::No) { + qDebug() << "QMessageBox::StandardButton::No"; + } +} + +void MainWindow::slot_msgbox_warning_btn_Chick() +{ + QMessageBox::StandardButton button = QMessageBox::warning(this, "warning", "是否删除文件?", + QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton); + if (button == QMessageBox::StandardButton::Yes) { + qDebug() << "QMessageBox::StandardButton::Yes"; + } else if (button == QMessageBox::StandardButton::No) { + qDebug() << "QMessageBox::StandardButton::No"; + } +} + +void MainWindow::slot_msgbox_question_btn_Chick() +{ + QMessageBox::StandardButton button = QMessageBox::question(this, "question", "您确定要删除文件?", + QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton); + if (button == QMessageBox::StandardButton::Yes) { + qDebug() << "QMessageBox::StandardButton::Yes"; + } else if (button == QMessageBox::StandardButton::No) { + qDebug() << "QMessageBox::StandardButton::No"; + } +} + +void MainWindow::slot_msgbox_about_btn_Chick() +{ + QMessageBox::about(this, "about", "默认提示信息框"); +} + +void MainWindow::slot_msgbox_exec_btn_Chick() +{ + QMessageBox messageBox(QMessageBox::NoIcon, "登录", "用户和密码验证是否成功?", QMessageBox::Yes | QMessageBox::No,this); + int iResult = messageBox.exec(); + switch (iResult) { + case QMessageBox::Yes: + QMessageBox::about(nullptr, "提示", "您好,您已经点击了yes按钮"); + break; + case QMessageBox::No: + QMessageBox::about(nullptr, "提示", "您好,您已经点击了no按钮"); + break; + default: + break; + } +} + +void MainWindow::slot_cst_msgbox_info_btn_Chick() +{ + N_MessageBox::information(this,tr("消息"), tr("系统启动成功") ); +} + +void MainWindow::slot_cst_msgbox_warning_btn_Chick() +{ + N_MessageBox::warning(this,"", tr("密码为空。") ); + +} + +void MainWindow::slot_cst_msgbox_question_btn_Chick() +{ + if( N_MessageBox::question(this,tr("问题"), tr("是否删除文件?")) != N_MessageBox::Ok ) + return; +} + +void MainWindow::slot_cst_msgbox_error_btn_Chick() +{ + N_MessageBox::error(this,"", tr("超出最大输入个数!") ); +} + +void MainWindow::slot_cst_msgbox_choice_btn_Chick() +{ + if( N_MessageBox::choice(this,"",tr("是否继续安装?")) == N_MessageBox::Yes ) + { + + } +} + +void MainWindow::slot_cst_msgbox_error_choice_btn_Chick() +{ + if( N_MessageBox::error_choice(this,"",tr("登录失败,原因:密码错误。是否找回密码?")) == N_MessageBox::Yes ) + { + AlertMessageBox::Information(this, tr("密码恢复成功!") ); + } +} + +void MainWindow::slot_about_dlg_btn_Chick() +{ + AboutDlg dlg(this); + dlg.exec(); +} + +void MainWindow::slot_login_dlg_btn_Chick() +{ + LoginDlg dlg(this); + dlg.exec(); +} + +void MainWindow::slot_alert_msgbox_info_btn_Chick() +{ + AlertMessageBox::Information(this,tr("请输入密码!") ); +} + +void MainWindow::slot_alert_msgbox_warning_btn_Chick() +{ + AlertMessageBox::Warning(this,tr("密码为空。") ); +} + +void MainWindow::slot_alert_msgbox_error_btn_Chick() +{ + AlertMessageBox::Error(this,tr("输入信息有误,请重新输入!") ); +} + + diff --git a/product/src/tools/style_tool/mainwindow.h b/product/src/tools/style_tool/mainwindow.h new file mode 100644 index 00000000..5d268c45 --- /dev/null +++ b/product/src/tools/style_tool/mainwindow.h @@ -0,0 +1,52 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include "pub_widget/NcFramelessHelper.h" +#include "pub_widget/CustomMainWindow.h" + +namespace Ui { +class MainWindow; +} + + +class MainWindow : public CustomUiMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); +private: + void initStyleSheet(const QString &strLang, const QString &strStyle); + +private slots: + void slot_btnRefreshChick(); + void slot_msgbox_info_btn_Chick(); + void slot_msgbox_critical_btn_Chick(); + void slot_msgbox_warning_btn_Chick(); + void slot_msgbox_question_btn_Chick(); + void slot_msgbox_about_btn_Chick(); + void slot_msgbox_exec_btn_Chick(); + + void slot_cst_msgbox_info_btn_Chick(); + void slot_cst_msgbox_warning_btn_Chick(); + void slot_cst_msgbox_question_btn_Chick(); + void slot_cst_msgbox_error_btn_Chick(); + void slot_cst_msgbox_choice_btn_Chick(); + void slot_cst_msgbox_error_choice_btn_Chick(); + + void slot_about_dlg_btn_Chick(); + void slot_login_dlg_btn_Chick(); + + void slot_alert_msgbox_info_btn_Chick(); + void slot_alert_msgbox_warning_btn_Chick(); + void slot_alert_msgbox_error_btn_Chick(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/product/src/tools/style_tool/mainwindow.ui b/product/src/tools/style_tool/mainwindow.ui new file mode 100644 index 00000000..d1174ed3 --- /dev/null +++ b/product/src/tools/style_tool/mainwindow.ui @@ -0,0 +1,1591 @@ + + + MainWindow + + + + 0 + 0 + 910 + 654 + + + + MainWindow + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + 语言: + + + + + + + 英文 + + + buttonGroup + + + + + + + 中文 + + + buttonGroup + + + + + + + + + + + + + + 风格: + + + + + + + 深色 + + + buttonGroup_2 + + + + + + + 浅色 + + + buttonGroup_2 + + + + + + + 重置样式 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 禁用/启用 + + + true + + + + + + + + + + 0 + 0 + + + + + + + 4 + + + + button + + + + + + CheckBox + + + + + + + CheckBox + + + + + + + PushButton + + + + + + + CommandLinkButton + + + + + + + ... + + + + + + + RadioButton + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + edit + + + + + + GroupBox + + + + + + + + ComboBox + + + + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + + + + line edit + + + + + + + 2222222222223 + + + + + + + spin box + + + + + + + + + + Qt::Horizontal + + + + 37 + 17 + + + + + + + + double spin box + + + + + + + + + + time edit + + + + + + + + + + date edit + + + + + + + + + + + + text edit + + + + + + + + + + plain text edit + + + + + + + + + + + + + + widget + + + + + + true + + + + + 0 + 0 + 838 + 508 + + + + + + + 24 + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建项目 + + + 222 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + + 新建子项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + + 新建子项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + + 新建子项目 + + + 新建项目 + + + + + + 新建项目 + + + 新建项目 + + + + 新建子项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + + + + + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + + 新建子项目 + + + + 新建子项目 + + + + 新建子项目 + + + + 新建子项目 + + + + + + + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + 新建项目 + + + + 新建子项目 + + + + + + + + + + + + + + + + 新建子项目 + + + + + + + + + + + + + + + + 新建子项目 + + + + + + + + + + + + + + + + 新建子项目 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 新建行 + + + + + 新建行 + + + + + 新建行 + + + + + 新建行 + + + + + 新建行 + + + + + 新建行 + + + + + 新建行 + + + + + 新建行 + + + + + 新建行 + + + + + 新建行 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建列 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + 新建项目 + + + + + + + + + + + + + + + + + + + box + + + + + + QTabWidget::West + + + + Tab 1 + + + + + + QTabWidget::South + + + 0 + + + + Tab 1 + + + + + + GroupBox + + + + + + QTabWidget::East + + + + Tab 1 + + + + + + 0 + + + + + 0 + 0 + 714 + 340 + + + + Page 1 + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + text Browser + + + + + + + + + + + + + + + 0 + 0 + 222 + 107 + + + + Page 2 + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + mdi + + + + + + + + + + + + + + + + + + Tab 2 + + + + + + + + + + + + Tab 2 + + + + + + + + + Tab 2 + + + + + + + + + dialog + + + + + + 系统默认弹出框 + + + + + + question + + + + + + + about + + + + + + + warning + + + + + + + critical + + + + + + + information + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + exec + + + + + + + + + + 自动 隐藏的弹出 窗 + + + + + + warning + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + error + + + + + + + information + + + + + + + + + + 自定义弹出窗口 + + + + + + Error_Choice + + + + + + + error + + + + + + + warning + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + question + + + + + + + information + + + + + + + Choice + + + + + + + + + + GroupBox + + + + + + 关于 窗口 + + + + + + + 登录 窗口 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + + + dd + + + + + ddd + + + + + xiangm2 + + + + + + WorkFrame + QWidget +
pub_widget/WorkFrame.h
+ 1 +
+ + MenuFrame + QWidget +
pub_widget/MenuFrame.h
+ 1 +
+
+ + + + pushButton + clicked(bool) + tabWidget + setEnabled(bool) + + + 899 + 51 + + + 393 + 90 + + + + + + + + +
diff --git a/product/src/tools/style_tool/style_tool.pro b/product/src/tools/style_tool/style_tool.pro new file mode 100644 index 00000000..756d26f8 --- /dev/null +++ b/product/src/tools/style_tool/style_tool.pro @@ -0,0 +1,57 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2021-04-07T16:28:26 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = style_tool +TEMPLATE = app + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + AboutDlg.cpp \ + LoginDlg.cpp \ + MainWindow2.cpp + +HEADERS += \ + mainwindow.h \ + AboutDlg.h \ + LoginDlg.h \ + MainWindow2.h + +FORMS += \ + mainwindow.ui \ + LoginDlg.ui + + +LIBS += -lpub_widget \ + -lpub_utility_api + +#------------------------------------------------------------------- +COMMON_PRI=$$PWD/../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} + + diff --git a/product/src/tools/workBench/AppMngForm.cpp b/product/src/tools/workBench/AppMngForm.cpp new file mode 100644 index 00000000..28ac8616 --- /dev/null +++ b/product/src/tools/workBench/AppMngForm.cpp @@ -0,0 +1,384 @@ +#include "AppMngForm.h" +#include "ui_AppMngForm.h" +#include "DataMng.h" +#include "../include/sys/sys_login_api/CLoginDlg.h" + +#include +#include + +AppMngForm::AppMngForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::AppMngForm) +{ + ui->setupUi(this); + ui->appTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); + initAppTree(); + connect(ui->appTreeWidget,&QTreeWidget::customContextMenuRequested,this,&AppMngForm::customContext); + connect(ui->appTreeWidget,&QTreeWidget::itemClicked,this,&AppMngForm::appItemClicked); +} + +AppMngForm::~AppMngForm() +{ + delete ui; +} + +void AppMngForm::updateAppTree() +{ + std::vector runAppVec = DataMng::instance()->getRunAppInfo(); + + for(size_t i=0;iappTreeWidget->topLevelItemCount(); + for(int topIndex(0);topIndexappTreeWidget->topLevelItem(topIndex); + if(item->text(0).toStdString() == runAppVec[i].m_nodeName) + { + updateItem(runAppVec[i],item); + break; + } + } + } + ui->appTreeWidget->expandAll(); +} + +void AppMngForm::customContext(const QPoint &pos) +{ + QModelIndex index = ui->appTreeWidget->indexAt(pos); + + if(!index.isValid()) + { + ui->appTreeWidget->clearSelection(); + if(!DataMng::instance()->getSysStatus()) + { + QMenu menu(this); + QAction * selectAction = menu.addAction(tr("刷新")); + connect(selectAction, &QAction::triggered, [=](){ + emit sigReloadAppAndProc(); + }); + menu.exec(QCursor::pos()); + } + + return ; + } + + //右键应用 + QTreeWidgetItem *item=ui->appTreeWidget->currentItem(); + //空指针判断 + if (!item) + { + return; + } + //判断是否右键应用 + if(item->data(0,Qt::UserRole+5).toInt() == EN_TREE_NODE_IS_APP) + { + //判断是否右键Base应用 + if(item->data(0,Qt::UserRole).toInt() == CN_AppId_BASE) + { + return ; + } + //判断是否本节点 + if(item->data(0,Qt::UserRole+6).toString() != DataMng::instance()->getHostName()) + { + return ; + } + //判断当前是否可以右键操作(防止并行操作) + if(!DataMng::instance()->getAllowedStatus()) + { + return ; + } + QMenu menu(this); + QAction * appStart = menu.addAction(tr("启动")); + QAction * appStop = menu.addAction(tr("停止")); + QAction * appRestart = menu.addAction(tr("重启")); + QAction * appUp = menu.addAction(tr("升主")); + QAction * appDown = menu.addAction(tr("降备")); + + connect(appStart, &QAction::triggered, [=](){ + emit sigStartApp(item->data(0,Qt::UserRole+1).toString()); + }); + connect(appStop, &QAction::triggered, [=](){ + CLoginDlg dlg(this); + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigStopApp(item->data(0,Qt::UserRole+1).toString()); + } + }); + connect(appRestart, &QAction::triggered, [=](){ + CLoginDlg dlg(this); + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigRestartApp(item->data(0,Qt::UserRole+1).toString()); + } + }); + if(DataMng::instance()->getBaseStatus()) //基础应用处于启动状态 + { + //获取本应用状态 + int appStatus = item->data(1,Qt::UserRole).toInt(); + if(appStatus == EN_APP_RUNNING) + { + appStart->setEnabled(false); + appStop->setEnabled(true); + appRestart->setEnabled(true); + }else if(appStatus == EN_APP_STOP) + { + if(checkAppStatus(item->data(0,Qt::UserRole).toInt())== EN_APP_HALF)//半运行状态 + { + appStart->setEnabled(false); + appStop->setEnabled(true); + appRestart->setEnabled(true); + }else + { + appStart->setEnabled(true); + appStop->setEnabled(false); + appRestart->setEnabled(false); + } + }else if(appStatus == EN_APP_UNKNOW) + { + appStart->setEnabled(false); + appStop->setEnabled(false); + appRestart->setEnabled(false); + } + }else //基础应用处于停止状态 + { + appStart->setEnabled(false); + appStop->setEnabled(false); + appRestart->setEnabled(false); + } + + appUp->setEnabled(false); + appDown->setEnabled(false); + menu.exec(QCursor::pos()); + } +} + +void AppMngForm::appItemClicked(QTreeWidgetItem *item, int column) +{ + if(!item) + { + return ; + } + if(column != 3) + { + return ; + } + //判断是否点击应用 + if(item->data(0,Qt::UserRole+5).toInt() == EN_TREE_NODE_IS_APP) + { + //判断是否点击Base应用 + if(item->data(0,Qt::UserRole).toInt() == CN_AppId_BASE) + { + return ; + } + //判断是否本节点 + if(item->data(0,Qt::UserRole+6).toString() != DataMng::instance()->getHostName()) + { + return ; + } + //判断当前是否可以点击操作(防止并行操作) + if(!DataMng::instance()->getAllowedStatus()) + { + return ; + } + if(!DataMng::instance()->getBaseStatus()) //基础应用处于启动状态 + { + return ; + } + //获取本应用状态 + int appStatus = item->data(1,Qt::UserRole).toInt(); + if(appStatus == EN_APP_RUNNING) + { + CLoginDlg dlg(this); + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigRestartApp(item->data(0,Qt::UserRole+1).toString()); + } + }else if(appStatus == EN_APP_STOP) + { + if(checkAppStatus(item->data(0,Qt::UserRole).toInt())== EN_APP_HALF)//半运行状态 + { + CLoginDlg dlg(this); + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigRestartApp(item->data(0,Qt::UserRole+1).toString()); + } + }else + { + emit sigStartApp(item->data(0,Qt::UserRole+1).toString()); + } + } + } +} + +void AppMngForm::initAppTree() +{ + QMap > deployInfo = DataMng::instance()->getDeployInfo(); + ui->appTreeWidget->clear(); + ui->appTreeWidget->setColumnWidth(0,150); + ui->appTreeWidget->setColumnCount(4); + QMap >::iterator pos = deployInfo.begin(); + while (pos != deployInfo.end()) { + QTreeWidgetItem *nodeItem = new QTreeWidgetItem(ui->appTreeWidget); + nodeItem->setText(0,pos.key()); + nodeItem->setData(0,Qt::UserRole+5,EN_TREE_NODE_IS_NODE); + nodeItem->setTextColor(0 , "#003764"); + ui->appTreeWidget->addTopLevelItem(nodeItem); + QMap appMap = pos.value(); + QMap::iterator it = appMap.begin(); + while (it != appMap.end()) { + QTreeWidgetItem *appItem = new QTreeWidgetItem(); + appItem->setTextColor(0 , "#003764"); + appItem->setText(0,QString::fromStdString((*it).m_desc)); + appItem->setData(0,Qt::UserRole,(*it).m_appId); + appItem->setData(0,Qt::UserRole+1,QString::fromStdString((*it).m_appName)); + appItem->setData(0,Qt::UserRole+5,EN_TREE_NODE_IS_APP); + appItem->setData(0,Qt::UserRole+6,pos.key()); + if((*it).m_appId != CN_AppId_BASE && (*it).m_nodeName == DataMng::instance()->getHostName().toStdString()) + { + appItem->setIcon(3,QIcon(":/images/restart.png")); + } + if((*it).m_isActive == 1) + { + appItem->setText(1,tr("运行中")); + appItem->setTextColor(1,"#058D02"); + appItem->setData(1,Qt::UserRole,EN_APP_RUNNING); + if((*it).m_isMaster == 0 && (*it).m_isSlave==0) + { + appItem->setText(2, tr("异常")); + appItem->setTextColor(2,"#FF0000"); + } + else if((*it).m_isMaster == 1 && (*it).m_isSlave==0) + { + appItem->setText(2, tr("主")); + appItem->setTextColor(2,"#058D02"); + + } + else if((*it).m_isMaster == 0 && (*it).m_isSlave==1) + { + appItem->setText(2, tr("备")); + appItem->setTextColor(2,"#058D02"); + } + else + { + appItem->setText(2, tr("异常")); + appItem->setTextColor(2,"#FF0000"); + } + }else if((*it).m_isActive == 0) + { + appItem->setText(1,tr("已停止")); + appItem->setTextColor(1,"#FF0000"); + appItem->setData(1,Qt::UserRole,EN_APP_STOP); + appItem->setText(2, "-"); + appItem->setTextColor(2,Qt::black); + }else if((*it).m_isActive == 2) + { + appItem->setText(1,tr("未知")); + appItem->setTextColor(1,Qt::black); + appItem->setData(1,Qt::UserRole,EN_APP_UNKNOW); + appItem->setText(2, "-"); + appItem->setTextColor(2,Qt::black); + } + nodeItem->addChild(appItem); + it++; + } + pos++; + } + ui->appTreeWidget->expandAll(); + + return; +} + +void AppMngForm::updateItem(const SApp &app, QTreeWidgetItem *item) +{ + int num = item->childCount(); + for(int i =0;ichild(i)->data(0,Qt::UserRole).toInt() == app.m_appId) + { + if(app.m_isActive == 1) + { + item->child(i)->setText(1,tr("运行中")); + item->child(i)->setTextColor(1,"#058D02"); + item->child(i)->setData(1,Qt::UserRole,EN_APP_RUNNING); + if(app.m_isMaster == 0 && app.m_isSlave==0) + { + item->child(i)->setText(2, tr("异常")); + item->child(i)->setTextColor(2,"#FF0000"); + } + else if(app.m_isMaster == 1 && app.m_isSlave==0) + { + item->child(i)->setText(2, tr("主")); + item->child(i)->setTextColor(2,"#058D02"); + + } + else if(app.m_isMaster == 0 && app.m_isSlave==1) + { + item->child(i)->setText(2, tr("备")); + item->child(i)->setTextColor(2,"#058D02"); + } + else + { + item->child(i)->setText(2, tr("异常")); + item->child(i)->setTextColor(2,"#FF0000"); + } + }else if(app.m_isActive == 0) + { + item->child(i)->setText(1,tr("已停止")); + item->child(i)->setTextColor(1,"#FF0000"); + item->child(i)->setData(1,Qt::UserRole,EN_APP_STOP); + item->child(i)->setText(2, "-"); + item->child(i)->setTextColor(2,Qt::black); + }else if(app.m_isActive == 2) + { + item->child(i)->setText(1,tr("未知")); + item->child(i)->setTextColor(1,Qt::black); + item->child(i)->setData(1,Qt::UserRole,EN_APP_UNKNOW); + item->child(i)->setText(2, "-"); + item->child(i)->setTextColor(2,Qt::black); + } + break; + } + } +} + +void AppMngForm::blockAppSignals(bool b) +{ + ui->appTreeWidget->blockSignals(b); +} + +int AppMngForm::checkAppStatus(const int appId) +{ + float disk = 0.0; + std::vector procVec; + + DataMng::instance()->getRunProcInfo(procVec,disk); + + foreach (SProcess var, procVec) + { + if( appId == var.m_appId && EN_PROC_RUNNING == var.m_isStartUp) + { + return EN_APP_HALF; + } + } + return EN_APP_STOP; +} diff --git a/product/src/tools/workBench/AppMngForm.h b/product/src/tools/workBench/AppMngForm.h new file mode 100644 index 00000000..1ac522f6 --- /dev/null +++ b/product/src/tools/workBench/AppMngForm.h @@ -0,0 +1,58 @@ +#ifndef APPMNGFORM_H +#define APPMNGFORM_H + +#include +#include + +#include "MonitorCommon.h" + +using namespace workBench; + +namespace Ui { +class AppMngForm; +} + +class AppMngForm : public QWidget +{ + Q_OBJECT + +public: + explicit AppMngForm(QWidget *parent = 0); + ~AppMngForm(); + +signals: + void sigReloadAppAndProc(); + + void sigStartApp(const QString appName); + + void sigStopApp(const QString appName); + + void sigRestartApp(const QString appName); + +public slots: + void updateAppTree(); + + void customContext(const QPoint &pos); + + void appItemClicked(QTreeWidgetItem *item, int column); + +public: + void initAppTree(); + + void updateItem(const SApp &app,QTreeWidgetItem *item ); + + void blockAppSignals(bool b); + +private: + /** + * @brief checkAppStatus 根据appId 判断应用状态 + * @param appId 应用id + * @return true-半运行状态(应用下部分进程在运行) false-已停止状态 + */ + int checkAppStatus(const int appId); + +private: + Ui::AppMngForm *ui; +}; + +#endif // APPMNGFORM_H diff --git a/product/src/tools/workBench/AppMngForm.ui b/product/src/tools/workBench/AppMngForm.ui new file mode 100644 index 00000000..d8aa58d0 --- /dev/null +++ b/product/src/tools/workBench/AppMngForm.ui @@ -0,0 +1,60 @@ + + + AppMngForm + + + + 0 + 0 + 450 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 节点应用 + + + + + 状态 + + + + + 主/备 + + + + + 重启 + + + + + + + + + diff --git a/product/src/tools/workBench/AutoStart.cpp b/product/src/tools/workBench/AutoStart.cpp new file mode 100644 index 00000000..d9cbd58c --- /dev/null +++ b/product/src/tools/workBench/AutoStart.cpp @@ -0,0 +1,62 @@ +#include "AutoStart.h" +#include "ui_AutoStart.h" + +AutoStart::AutoStart(bool hmiAuto, bool sysAuto, QWidget *parent) : + CustomUiDialog(parent), + ui(new Ui::AutoStart) +{ + ui->setupUi(this); + CustomUiDialog::setAutoLayout(true); + m_hmiAuto = hmiAuto; + m_sysAuto = sysAuto; + ui->sysCheckBox->setChecked(sysAuto); + ui->hmiCheckBox->setChecked(hmiAuto); + if(m_sysAuto) + { + ui->hmiCheckBox->setEnabled(true); + }else + { + ui->hmiCheckBox->setEnabled(false); + } + setWindowTitle(tr("自启动设置")); +} + +AutoStart::~AutoStart() +{ + delete ui; +} + +void AutoStart::init() +{ + +} + +bool AutoStart::isHmiAutoStart() +{ + return ui->hmiCheckBox->isChecked(); +} + +bool AutoStart::isSysAutoStart() +{ + return ui->sysCheckBox->isChecked(); +} + +void AutoStart::showEvent(QShowEvent *) +{ + ui->sysCheckBox->setChecked(m_sysAuto); + ui->hmiCheckBox->setChecked(m_hmiAuto); +} + +void AutoStart::on_sysCheckBox_clicked(bool checked) +{ + if (!checked) + { + ui->hmiCheckBox->setEnabled(false); + ui->hmiCheckBox->setChecked(false); + } + else + { + ui->hmiCheckBox->setEnabled(true); + ui->hmiCheckBox->setChecked(m_hmiAuto); + } +} diff --git a/product/src/tools/workBench/AutoStart.h b/product/src/tools/workBench/AutoStart.h new file mode 100644 index 00000000..6d318fb9 --- /dev/null +++ b/product/src/tools/workBench/AutoStart.h @@ -0,0 +1,34 @@ +#ifndef AUTOSTARTDIALOG_H +#define AUTOSTARTDIALOG_H + +#include +#include "pub_widget/CustomDialog.h" + +namespace Ui { +class AutoStart; +} + +class AutoStart : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit AutoStart(bool hmiAuto = false,bool sysAuto =false,QWidget *parent = 0); + ~AutoStart(); + void init(); + bool isHmiAutoStart(); + bool isSysAutoStart(); +protected: + void showEvent(QShowEvent *) override; + +private slots: + + void on_sysCheckBox_clicked(bool checked); + +private: + Ui::AutoStart *ui; + bool m_hmiAuto; + bool m_sysAuto; +}; + +#endif // AUTOSTARTDIALOG_H diff --git a/product/src/tools/workBench/AutoStart.ui b/product/src/tools/workBench/AutoStart.ui new file mode 100644 index 00000000..24c7593a --- /dev/null +++ b/product/src/tools/workBench/AutoStart.ui @@ -0,0 +1,146 @@ + + + AutoStart + + + + 0 + 0 + 234 + 166 + + + + + 234 + 166 + + + + + 234 + 166 + + + + Dialog + + + + :/auto_start.ico:/auto_start.ico + + + + + + Qt::LeftToRight + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + 开机自启动 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + 系统开机自启动 + + + + + + + HMI 开机自启动 + + + + + + + + + + + + + + + + buttonBox + accepted() + AutoStart + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AutoStart + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/product/src/tools/workBench/BrushDataThread.cpp b/product/src/tools/workBench/BrushDataThread.cpp new file mode 100644 index 00000000..ea346410 --- /dev/null +++ b/product/src/tools/workBench/BrushDataThread.cpp @@ -0,0 +1,233 @@ +#include "BrushDataThread.h" +#include "common/Common.h" + +#include "DataMng.h" + +BrushDataThread::BrushDataThread(): + CTimerThreadBase("CGetRunProcThread",1000) +,sigar_mem(nullptr),m_domainId(0),m_appId(0) +{ + m_mutex = new QMutex; + sigar_open(&m_sigar); + +} + +BrushDataThread::~BrushDataThread() +{ + sigar_close(m_sigar); + if(m_mutex) + { + delete m_mutex; + } + m_mutex = Q_NULLPTR; +} + +int BrushDataThread::beforeExecute() +{ + m_sysRunAppInfoVec = DataMng::instance()->getInitAppInfoVec(); + m_sysRunProcInfoVec = DataMng::instance()->getInitProcInfoVec(); + return iotSuccess; +} + +void BrushDataThread::execute() +{ + QString hostName ; + hostName = DataMng::instance()->getHostName(); + if(m_hostName != hostName) + { + m_hostName = hostName; + m_objRdbNetApi.connect(m_domainId,m_appId); + return ; + } + + float disk =0.0; + + if(queryAppRunInfo() && queryProcRunInfo()) + { + for(size_t i=0;i 1 && m_sysRunProcInfoVec[i].m_isStartUp == 1) + { + m_sysRunProcInfoVec[i].m_disk = get_proc_memory(m_sysRunProcInfoVec[i].m_procId,m_sysRunProcInfoVec[i].m_procName); + m_sysRunProcInfoVec[i].m_cpu = get_proc_cpu(m_sysRunProcInfoVec[i].m_procId,m_sysRunProcInfoVec[i].m_procName); + } + else + { + m_sysRunProcInfoVec[i].m_disk = 0; + m_sysRunProcInfoVec[i].m_cpu = 0; + } + disk += m_sysRunProcInfoVec[i].m_disk; + } + }else + { + initData(); + } + for(size_t i=0;igetModelAppInfoById(m_sysRunAppInfoVec[i].m_appId); + m_sysRunAppInfoVec[i].m_appName = modelAppInfo.m_tagName; + m_sysRunAppInfoVec[i].m_desc=modelAppInfo.m_desc; + } + + for(size_t i=0;igetAppDescByAppId(m_sysRunProcInfoVec[i].m_appId); + m_sysRunProcInfoVec[i].m_procDesc = DataMng::instance()->getProcDescByAppIdAndProcName(m_sysRunProcInfoVec[i].m_appId,m_sysRunProcInfoVec[i].m_procName); + } + + { + DataMng::instance()->setRunAppInfo(m_sysRunAppInfoVec); + DataMng::instance()->setRunProcInfo(m_sysRunProcInfoVec,disk); + } +} + +float BrushDataThread::get_proc_memory(long long pid,const std::string &procName) +{ + sigar_proc_mem_t mem; + int nRc= sigar_proc_mem_get(m_sigar,pid,&mem); + if (SIGAR_OK == nRc) + { + return (float)mem.resident/1024/1024; + }else + { + LOGERROR("获取进程内存失败!name:[%s],pid:[%lld],错误码:%d",procName.c_str(),pid,nRc); + float defaultValue = 0; + return defaultValue; + } +} + +float BrushDataThread::get_proc_cpu(long long pid, const string &procName) +{ + sigar_proc_cpu_t cpu; + int nRc= sigar_proc_cpu_get(m_sigar,pid,&cpu); + if (SIGAR_OK == nRc) + { + return (float)cpu.percent; + }else + { + LOGERROR("获取cpu失败!name:[%s],pid:[%lld],错误码:%d",procName.c_str(),pid,nRc); + float defaultValue = 1.0; + return defaultValue; + } +} + +int BrushDataThread::initialize(int domainId, int appId) +{ + m_hostName = DataMng::instance()->getHostName(); + m_domainId = domainId; + m_appId = appId; + m_objRdbNetApi.connect(domainId,appId); + return iotSuccess; +} + +bool BrushDataThread::queryRunInfo() +{ + return true; +} + +bool BrushDataThread::queryAppRunInfo() +{ + bool bRet = false; + iot_idl::RdbRet objRdbRet; + const std::vector vecColumn = {"app_id","node_name","is_active","is_master","is_slave"}; + bRet = m_objRdbNetApi.queryTotal(CN_TN_SysRunRedundancyInfo,vecColumn,objRdbRet,false,false); + if(!bRet ||objRdbRet.msgrecord_size() < 0) + { + //先初始化数据,然后直接返回 + //initData(); + return false; + } + + m_sysRunAppInfoVec.clear(); + + for(int i=0;isetBaseStatus(true); + } + } + return true; +} + +bool BrushDataThread::queryProcRunInfo() +{ + bool bRet = false; + iot_idl::RdbRet objRdbRet; + vector vecColumn = {"app_id","node_name","proc_name","proc_param","proc_id","is_startup","to_quit","is_quit","is_master","is_slave"}; + + bRet=m_objRdbNetApi.queryTotal(CN_TN_SysRunProcInfo,vecColumn,objRdbRet,false,false); + + if(!bRet ||objRdbRet.msgrecord_size() < 0) + { + //先初始化数据,然后直接返回 + //initData(); + return false; + } + + m_sysRunProcInfoVec.clear(); + for(int i=0;igetInitAppInfoVec(); + //先设置Base状态为false + DataMng::instance()->setBaseStatus(false); + + //设置应用信息状态为未知 + bool bSysStatus = DataMng::instance()->getSysStatus(); + + for(vector::iterator it = m_sysRunAppInfoVec.begin();it !=m_sysRunAppInfoVec.end();it++) + { + if(bSysStatus == true) + { + it->m_isActive = 2; + } + else + { + it->m_isActive = 0; + } + + } + //设置进程信息为未知 并且cpu和硬盘置0 + for(vector::iterator it = m_sysRunProcInfoVec.begin();it !=m_sysRunProcInfoVec.end();it++) + { + if(bSysStatus == true) + { + it->m_isStartUp = 2; + it->m_disk = 0.0; + it->m_cpu = 0.0; + }else + { + it->m_isStartUp = 0; + it->m_disk = 0.0; + it->m_cpu = 0.0; + } + } +} diff --git a/product/src/tools/workBench/BrushDataThread.h b/product/src/tools/workBench/BrushDataThread.h new file mode 100644 index 00000000..7acf31e7 --- /dev/null +++ b/product/src/tools/workBench/BrushDataThread.h @@ -0,0 +1,103 @@ +#ifndef BRUSHDATATHREAD_H +#define BRUSHDATATHREAD_H + +#include "pub_utility_api/TimerThreadBase.h" +#include "rdb_net_api/CRdbNetApi.h" +#include "sigar.h" +#include "sigar_format.h" +#include "MonitorCommon.h" +#include "rdb_net_api/CRdbNetApi.h" + +#include + +using namespace std; +using namespace workBench; +using namespace iot_dbms; + +class BrushDataThread : public iot_public::CTimerThreadBase +{ + +public: + + /** + * @brief BrushDataThread 构造函数 + */ + BrushDataThread(); + virtual ~BrushDataThread(); + + /** + * @brief beforeExecute 执行execute函数前的处理,只会调用一次 + * @return + */ + virtual int beforeExecute(); + + /** + * @brief execute 业务处理函数,必须继承实现自己的业务逻辑 + */ + virtual void execute(); + + /** + * @brief get_proc_memory 获取进程内存 + * @param pid 进程id + * @param procName 进程名称 + * @return 进程内存 + */ + float get_proc_memory(long long pid, const string &procName); + + /** + * @brief get_proc_cpu 获取进程CPU + * @param pid 进程id + * @param procName 进程名称 + * @return 返回cpu百分比 + */ + float get_proc_cpu(long long pid, const string &procName); + + /** + * @brief initialize 初始化网络查询 + * @param domainId 连接域 + * @param appId 连接应用 + * @return iotSuccess-成功 iotFailed-失败 + */ + int initialize(int domainId,int appId); + +private: + + bool queryRunInfo(); + + /** + * @brief queryAppRunInfo 查询应用信息 + * @return true-成功 false-失败 + */ + bool queryAppRunInfo(); + + /** + * @brief queryProcRunInfo 查询进程信息 + * @return true-成功 false-失败 + */ + bool queryProcRunInfo(); + + /** + * @brief initData 初始化数据(网络查询不到,初始化数据,设置为未知) + */ + void initData(); + +private: + QMutex *m_mutex; //< 锁 + + sigar_t *m_sigar; //< sigar对象 + sigar_t *sigar_mem; //< 获取内存 + SCpuAndDisk m_stNodeSigar; //< CPU和Disk + CRdbNetApi m_objRdbNetApi; //< 网络查询对象 + + vector m_sysRunAppInfoVec; //< 远程查询应用结果 + vector m_sysRunProcInfoVec; //< 远程查询进程结果 + + QString m_hostName; //< 本节点名称 + int m_domainId; //< 订阅域ID + int m_appId; //< 订阅应用ID + +}; + +typedef boost::shared_ptr BrushDataThreadPtr; + +#endif // BRUSHDATATHREAD_H diff --git a/product/src/tools/workBench/ButtonForm.cpp b/product/src/tools/workBench/ButtonForm.cpp new file mode 100644 index 00000000..4a49d1ce --- /dev/null +++ b/product/src/tools/workBench/ButtonForm.cpp @@ -0,0 +1,354 @@ + +#if defined(WIN32) +#include +#endif + +#include "ButtonForm.h" +#include "ui_ButtonForm.h" +#include "DataMng.h" +#include "MonitorCommon.h" +#include "DogCheck.h" +#include "DbCheck.h" +#include "SetupFunc.h" +#include "AutoStart.h" +#include "InputDialog.h" + +#include +#include +#include +#include +#include +#include + +#include "pub_utility_api/FileUtil.h" +#include "../include/sys/sys_login_api/CLoginDlg.h" + +using namespace workBench; + +ButtonForm::ButtonForm(int mode, QString language ,QWidget *parent): + QWidget(parent), + ui(new Ui::ButtonForm), + m_mode(mode), + m_language(language) +{ + ui->setupUi(this); +} + +ButtonForm::~ButtonForm() +{ + delete ui; +} + +void ButtonForm::setTitleHide(bool hide) +{ + ui->label->setHidden(hide); +} + +void ButtonForm::addToolButtons(QVector &buttonVec ,int groupIndex) +{ +// QHBoxLayout *layOut = new QHBoxLayout(ui->widget); +// layOut->setMargin(0); +// layOut->setSpacing(30); + QWidget *scrollWidget = new QWidget(this); + QHBoxLayout *scrollLayout = new QHBoxLayout(scrollWidget); + scrollLayout->setContentsMargins(0, 0, 0, 0); + //scrollLayout->setSpacing(30); + + QScrollArea *scrollArea = new QScrollArea(ui->widget); + scrollArea->setWidget(scrollWidget); + scrollArea->setWidgetResizable(true); + + if(m_mode == EN_SYS_STARTUP_PAGE1) + { + ui->frame->setObjectName("frame_page1"); + }else + { + ui->frame->setObjectName("frame_page3"); + //scrollLayout->setContentsMargins(30, 0, 0, 0); + } + for(int index(0);indexgetButtonInfoByName(buttonName,buttonInfo) != true) + { + continue; + } + QToolButton *toolBtn = new QToolButton(scrollWidget); + toolBtn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + QIcon icon = QIcon(buttonInfo.m_icon); + QSize size(45,45); + toolBtn->setIconSize(size); + toolBtn->setMaximumHeight(80); + toolBtn->setMinimumHeight(80); + toolBtn->setMaximumWidth(80); + toolBtn->setMinimumWidth(80); + toolBtn->setIcon(icon); + toolBtn->setText(buttonInfo.m_desc); + if( "custom" == buttonInfo.m_param) + { + toolBtn->setObjectName("customButton"); + toolBtn->setProperty("groupIndex" , groupIndex); + } + connect(toolBtn,&QToolButton::clicked, this ,[this , toolBtn ,buttonInfo](){ + executeTask(buttonInfo.m_cmd,buttonInfo.m_param , toolBtn); + }); + scrollLayout->addWidget(toolBtn); + } + + if(m_mode == EN_SYS_STARTUP_PAGE3) + { + scrollLayout->addStretch(); + scrollLayout->setSpacing(30); + } + ui->widget->setLayout(new QVBoxLayout()); + ui->widget->layout()->addWidget(scrollArea); + +} + +void ButtonForm::setTitleText(const QString &title) +{ + ui->label->setText(title); +} + +void ButtonForm::executeTask(QString cmd,QString param , QToolButton *btn) +{ + if(cmd =="DogCheck") + { + dogCheckDlg(); + return ; + } + if(cmd =="DbCheck") + { + dbCheckDlg(); + return ; + } + if(cmd =="AutoStart") + { + autoStartDlg(); + return ; + } + if( cmd == "Custom") + { + customTools(btn); + return; + } + + if(cmd == "sys_command.bat") + { +#ifdef Q_OS_WIN + WinExec("sys_command.bat", SW_NORMAL); +#else + QProcess::startDetached("./sys_command.sh"); +#endif + return ; + } + + if(cmd.contains("ReportEdit")) + { + CLoginDlg dlg(this); + QString perm ="FUNC_NOM_RPT_EDIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res != QDialog::Accepted) + { + return; + } + } + + if(cmd == "sys_command-platform.bat") + { +#ifdef Q_OS_WIN + WinExec("sys_command-platform.bat", SW_NORMAL); +#else + QProcess::startDetached("./sys_command-platform.sh"); +#endif + return ; + } + + if(cmd.endsWith(".exe")) + { + const std::string strFileName = + cmd.remove(cmd.size()-4,4).toStdString() + iot_public::CFileUtil::getProcSuffix(); + std::string strPath = std::move( iot_public::CFileUtil::getPathOfBinFile(strFileName)); + if(strPath.empty()) + { + //< 也许配置的是外部程序,不在我们的路径中 + strPath = strFileName; + } + if(param.isEmpty()) + { + QProcess::startDetached(strPath.c_str()); + }else + { + QString pathParam = QString("%1 %2").arg(strPath.c_str()).arg(param); + QProcess::startDetached(pathParam); + } + } + else if(cmd.endsWith(".bat")) + { +#ifdef Q_OS_WIN + const std::string strFileName = std::move(cmd.toStdString()); + std::string strPath = std::move( iot_public::CFileUtil::getPathOfBinFile(strFileName)); + if(strPath.empty()) + { + //< 也许配置的是外部脚本,不在我们的路径中 + strPath = strFileName; + } + system(strPath.c_str()); +#else + const std::string strFileName = cmd.remove(cmd.size()-4,4).toStdString() + ".sh"; + std::string strPath = std::move( iot_public::CFileUtil::getPathOfBinFile(strFileName)); + if(strPath.empty()) + { + //< 也许配置的是外部脚本,不在我们的路径中 + strPath = strFileName; + } + QProcess::startDetached(QString("bash -c '%1'").arg(strPath.c_str())); +#endif + } +} + +void ButtonForm::autoStartDlg() +{ + QString strSysErr; + QString strHmiErr; + bool isHmi = false; + bool isSys = false; + + isSys = iot_sys::isSysService(strSysErr); +#ifdef OS_WINDOWS + isHmi = iot_sys::isSysStartupVbsExist(); +#endif +#ifdef OS_LINUX + isHmi = iot_sys::isHmiAutoStart(strHmiErr); +#endif + + AutoStart *dlg =new AutoStart(isHmi,isSys,this); + int res =dlg->exec(); + + if(res == QDialog::Accepted) + { + QString text; + if(isSys != dlg->isSysAutoStart()) + { + setSysAuto(!isSys,text); + } + + if(isHmi != dlg->isHmiAutoStart()) + { + setHmiAuto(!isHmi,text); + } + emit sigLogText(text); + } + delete dlg; + dlg =NULL; +} + +void ButtonForm::dogCheckDlg() +{ + DogCheck dogCheck(this); + dogCheck.exec(); +} + +void ButtonForm::dbCheckDlg() +{ + DbCheck dbCheck(this); + dbCheck.exec(); +} + +void ButtonForm::setSysAuto(bool enable, QString &text) +{ + QString strErr; + if(enable==true) + { + if(iot_sys::regSysService(strErr)) + { + text+=tr("设置系统开机自启动成功..."); + } + else + { + text+=tr("设置系统开机自启动失败...错误:%1").arg(strErr); + } + } + else if(enable==false) + { + if(iot_sys::unregSysService(strErr)) + { + text+=tr("注销系统开机自启动成功..."); + } + else + { + text+=tr("注销系统开机自启动失败......错误:%1").arg(strErr); + } + } +} + +void ButtonForm::setHmiAuto(bool enable,QString &text) +{ + QString strErr; + if(enable==true) + { +#ifdef OS_WINDOWS + if (iot_sys::setSysStartupAutoStartByVbs(strErr)) +#endif +#ifdef OS_LINUX + if (iot_sys::setHmiAutoStart(strErr)) +#endif + { + text+=tr("设置HMI开机自启动成功..."); + } + else + { + text+=tr("设置HMI开机自启动失败...错误:%1").arg(strErr); + } + } + else if(enable==false) + { +#ifdef OS_WINDOWS + if (iot_sys::unsetSysStartupAutoStartByVbs(strErr)) +#endif +#ifdef OS_LINUX + if (iot_sys::unsetHmiAutoStart(strErr)) +#endif + { + text+=tr("注销HMI开机自启动成功..."); + } + else + { + text+=tr("注销HMI开机自启动失败...错误:%1").arg(strErr); + } + } +} + +void ButtonForm::customTools( QToolButton *btn ) +{ + QString name = ""; + QString picturePath = ""; + QString exePath = ""; + int groupIndex = -1; + + InputDialog *dialog = new InputDialog(this); + if( QDialog::Accepted == dialog->exec()) + { + dialog->getDataInput(name , picturePath , exePath); + + //修改json文件 + workBench::SButtonInfo buttonInfo; + buttonInfo.m_desc = name; + buttonInfo.m_icon = picturePath; + buttonInfo.m_cmd = exePath; + + //获取哪一个自定义按钮 + groupIndex = btn->property("groupIndex").toInt(); + DataMng::instance()->addPage3ButtonInfo(groupIndex ,buttonInfo); + + //修改成功后更改控件 + emit sigUpdataButton(EN_SYS_STARTUP_PAGE3); + } + delete dialog; + dialog = NULL; + +} diff --git a/product/src/tools/workBench/ButtonForm.h b/product/src/tools/workBench/ButtonForm.h new file mode 100644 index 00000000..45a1a641 --- /dev/null +++ b/product/src/tools/workBench/ButtonForm.h @@ -0,0 +1,51 @@ +#ifndef BOXFORM_H +#define BOXFORM_H + +#include +#include + +namespace Ui { +class ButtonForm; +} + +class ButtonForm : public QWidget +{ + Q_OBJECT + +public: + explicit ButtonForm(int mode, QString language ,QWidget *parent = 0); + ~ButtonForm(); + + void setTitleHide(bool hide); + + void addToolButtons(QVector &buttonVec , int groupIndex = -1); + + void setTitleText(const QString & title); +signals: + void sigLogText(const QString &logText); + void sigUpdataButton(int model); + +private: + void executeTask(QString cmd, QString param , QToolButton *btn); + + void autoStartDlg(); + + void dogCheckDlg(); + + void dbCheckDlg(); + + void setSysAuto(bool enable,QString &text); + + void setHmiAuto(bool enable,QString &text); + + void customTools( QToolButton *btn); + +private: + Ui::ButtonForm *ui; + + int m_mode; + + QString m_language; +}; + +#endif // BOXFORM_H diff --git a/product/src/tools/workBench/ButtonForm.ui b/product/src/tools/workBench/ButtonForm.ui new file mode 100644 index 00000000..0aba3c22 --- /dev/null +++ b/product/src/tools/workBench/ButtonForm.ui @@ -0,0 +1,91 @@ + + + ButtonForm + + + + 0 + 0 + 635 + 223 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 20 + + + + + 16777215 + 25 + + + + + + + + + + + + + + + + + + diff --git a/product/src/tools/workBench/DbCheck.cpp b/product/src/tools/workBench/DbCheck.cpp new file mode 100644 index 00000000..8610ada0 --- /dev/null +++ b/product/src/tools/workBench/DbCheck.cpp @@ -0,0 +1,732 @@ +#include "DbCheck.h" +#include "ui_DbCheck.h" +#include +#include "pub_logger_api/logger.h" +#include +#include "DbCheckSync.h" +#include +#include +#include "pub_widget/MessageBox.h" + +using namespace iot_public; +using namespace iot_dbms; + +struct SInfo +{ + char cHostName[32]; // 节点名,即机器名 + uint32 nGroup; // 组号,用于区分不同的项目 + int nMaxId; // dbop_list表最大id + int nHoldTime; // 持有时间,单位秒 + int nWeight; // 权重,作用在持有时间相同时 + bool bIpAdd; // 本机是否已添加虚拟IP + SInfo() + { + memset( cHostName, 0, 32 ); + nGroup = 0; + nMaxId = 0; + nHoldTime = 0; + nWeight = 0; + bIpAdd = false; + } +}; + +DbCheckThread::DbCheckThread(QObject *parent): + m_ptrSysInfo(Q_NULLPTR),m_pRecvUdp(NULL) +{ + m_isEnableSync = false; + initTsdbApi(); +} + +DbCheckThread::~DbCheckThread() +{ + stopKeepAliveUdp(); + wait(); + releaseTsdbApi(); +} + +bool DbCheckThread::startKeepAliveUdp() +{ + if(!m_pRecvUdp) + m_pRecvUdp = new QUdpSocket( this ); + + bool bRet = m_pRecvUdp->bind(6034); + if ( bRet == false ) + { + mLastErroStr = tr("UDP绑定失败,端口号【%1】").arg(6034); + return false; + } + connect( m_pRecvUdp, SIGNAL(readyRead()), this, SLOT(slotReceiveNetKeepAlivedInfo()) ); + return true; +} + +void DbCheckThread::stopKeepAliveUdp() +{ + if(m_pRecvUdp) + { + m_pRecvUdp->close(); + delete m_pRecvUdp; + m_pRecvUdp = NULL; + } + +} + +QMap &DbCheckThread::getDbResult() +{ + return m_mapDBInfo; +} + +SModelInfo &DbCheckThread::getSModelInfo() +{ + return mModelInfo; +} + +bool DbCheckThread::isEnableSync() +{ + return m_isEnableSync; +} + +QString DbCheckThread::getLastErro() +{ + return mLastErroStr; +} + +void DbCheckThread::run() +{ + qint64 starTime = QDateTime::currentDateTime().toTime_t(); + mLastErroStr = ""; + + updateModelInfo(); + + if(QThread::isInterruptionRequested()) + { + mLastErroStr = "查询终止"; + return; + } + + if(!resetSysInfo()) + { + return; + } + + if(QThread::isInterruptionRequested()) + { + mLastErroStr = "查询终止"; + return; + } + + if(!initDbInfoVec()) + { + return; + } + + if(QThread::isInterruptionRequested()) + { + mLastErroStr = "查询终止"; + return; + } + + if(!checkDbInfoVec()) + { + return; + } + + if(QThread::isInterruptionRequested()) + { + mLastErroStr = "查询终止"; + return; + } + + qint64 endTime = QDateTime::currentDateTime().toTime_t(); + + if(endTime-starTime <3000) + { + msleep(3000 - (endTime-starTime)); + } + else + { + msleep(100); + } + +} + +bool DbCheckThread::resetSysInfo() +{ + if(!createSysInfoInstance(m_ptrSysInfo)) + { + mLastErroStr = tr("创建系统信息访问库失败"); + return false; + } + + if(m_ptrSysInfo == NULL) + { + mLastErroStr = tr("创建系统信息访问库失败"); + return false; + } + + return true; +} + +void DbCheckThread::updateModelInfo() +{ + CDbApi readApi(DB_CONN_MODEL_READ); + if(readApi.open()) + { + mModelInfo.modelReadStatus = 1; + readApi.close(); + }else + { + mModelInfo.modelReadStatus = -1; + } + + CDbApi writeApi(DB_CONN_MODEL_WRITE); + if(writeApi.open()) + { + mModelInfo.modelWriteStatus = 1; + writeApi.close(); + }else + { + mModelInfo.modelWriteStatus = -1; + } + + CDbApi hisApi(DB_CONN_HIS_READ); + if(hisApi.open()) + { + mModelInfo.hisReaderStatus = 1; + hisApi.close(); + }else + { + mModelInfo.hisReaderStatus = -1; + } + + if(NULL!= getOneUseableConn(true)) + { + mModelInfo.tsdbStatus = 1; + } + else + { + mModelInfo.tsdbStatus = -1; + } +} + +bool DbCheckThread::initDbInfoVec() +{ + { + QMutexLocker locker(&m_mapDbInfoMx); + m_mapDBInfo.clear(); + } + + //查询 + SDomainInfo domainInfo; + int res = m_ptrSysInfo->getDomainInfoByNodeName( + QHostInfo::localHostName().toStdString(), + domainInfo); + + if(res != iotSuccess) + { + mLastErroStr = tr("获取域信息失败"); + return false; + } + + iot_public::SDatabaseInfo stFirstConnect; + std::vector vecLocalDBInfo; + std::vector vecRemoteDBInfo; + + res = m_ptrSysInfo->getDBInfoByDomainId(domainInfo.nId, + stFirstConnect, + vecLocalDBInfo, + vecRemoteDBInfo); + + if(res != iotSuccess) + { + + mLastErroStr = tr("获取数据库信息失败"); + return false; + } + + QMutexLocker locker(&m_mapDbInfoMx); + + SDbItemInfo firstInfo; + firstInfo.connect = stFirstConnect; + firstInfo.sNodeName = QString::fromStdString(stFirstConnect.strNodeName); + + SNodeInfo nodeInfo; + res = m_ptrSysInfo->getNodeInfoByName(stFirstConnect.strNodeName,nodeInfo); + if(res == iotSuccess) + { + if(nodeInfo.eNodeType == ENodeType_VirtualNode) + { + m_isEnableSync = true; + firstInfo.keepAliveStatus = 1; + firstInfo.keepAliveTime = QDateTime::currentDateTime().toString("hh:mm:ss"); + } + } + + firstInfo.isFirst = true; + m_mapDBInfo.insert(firstInfo.sNodeName,firstInfo); + + std::vector::iterator iter = vecLocalDBInfo.begin(); + for(; iter!=vecLocalDBInfo.end(); ++iter) + { + if(iter->strNodeName == stFirstConnect.strNodeName) + { + continue; + } + + SDbItemInfo info; + SNodeInfo nodeInfo; + + info.connect = *iter; + res = m_ptrSysInfo->getNodeInfoByName(iter->strNodeName,nodeInfo); + if(res != iotSuccess) + { + continue; + } + + //有虚拟节点则判断有启用同步 + if(nodeInfo.eNodeType == ENodeType_VirtualNode) + { + m_isEnableSync = true; + info.keepAliveStatus = 1; + info.keepAliveTime = QDateTime::currentDateTime().toString("hh:mm:ss"); + } + + info.isFirst = false; + info.sNodeName = QString::fromStdString(iter->strNodeName); + m_mapDBInfo.insert(info.sNodeName,info); + } + + return true; +} + +bool DbCheckThread::checkDbInfoVec() +{ + bool bRet = true; + QMap::iterator iter = m_mapDBInfo.begin(); + for(; iter!=m_mapDBInfo.end(); ++iter) + { + if(QThread::isInterruptionRequested()) + { + mLastErroStr = "查询终止"; + return false; + } + if(!checkDbInfo(iter.value())) + { + bRet = false; + } + } + + return bRet; +} + +bool DbCheckThread::checkDbInfo(SDbItemInfo &info) +{ + //获取首链接节点信息 + SNodeInfo stNodeInfo; + int res = m_ptrSysInfo->getNodeInfoByName(info.connect.strNodeName,stNodeInfo); + if(res != iotSuccess) + { + mLastErroStr = tr("获取节点信息失败"); + return false; + } + + return check(info,stNodeInfo); +} + +bool DbCheckThread::check(SDbItemInfo &stConnect, + SNodeInfo &stNodeInfo) +{ + if(!stNodeInfo.bIsUsed) + { + return true; + } + + for(int index(1);index <= stNodeInfo.nNicNum;index++) + { + CDbPara para; + if(index == 1) + { + para.setHostName(QString::fromStdString(stNodeInfo.strNic1Addr)); + } + if(index == 2) + { + para.setHostName(QString::fromStdString(stNodeInfo.strNic2Addr)); + } + QString firstColumn = QString("%1/%2").arg(QString::fromStdString(stNodeInfo.strName)).arg(para.getHostName()); + + + stConnect.first = firstColumn; + stConnect.isUsed = false; + stConnect.maxSyncId = -1; + stConnect.sNodeName = QString::fromStdString(stNodeInfo.strName); + + if(!DbCheck::getDbPara(stConnect.connect,para)) + { + mLastErroStr = tr("[%s]数据库类型错误!参数错误,直接默认为数据库状态不正常",firstColumn.toStdString().c_str()); + continue; + } + + CDbBaseApi baseApi(para); + + if(baseApi.open()) + { + stConnect.maxSyncId = DbCheckSync::getSyncMaxId(baseApi); + stConnect.isUsed = true; + baseApi.close(); + }else + { + baseApi.close(); + } + } + + return true; +} + +void DbCheckThread::slotReceiveNetKeepAlivedInfo() +{ + QMutexLocker locker(&m_mapDbInfoMx); + while ( m_pRecvUdp->hasPendingDatagrams() ) + { + QNetworkDatagram objDatagram = m_pRecvUdp->receiveDatagram(); + QByteArray byMsg = objDatagram.data(); + if ( byMsg.count() != sizeof(SInfo) ) + { + LOGERROR("接收的消息长度错误"); + continue; + } + + SInfo stTmp; + memcpy( &stTmp, byMsg.data(), sizeof(SInfo) ); + QMap::iterator iter = m_mapDBInfo.find(QString(stTmp.cHostName)); + if(iter!=m_mapDBInfo.end()) + { + iter.value().keepAliveStatus = 1; + iter.value().keepAliveTime =QDateTime::currentDateTime().toString("hh:mm:ss"); + + if(stTmp.bIpAdd) + { + iter.value().isDriftAddr = true; + } + } + } +} + +DbCheck::DbCheck(QWidget *parent) : + CustomUiDialog(parent), + ui(new Ui::DbCheck) +{ + setWindowTitle(tr("数据库检测")); + ui->setupUi(this); +// this->setWindowFlags(windowFlags()&~Qt::WindowContextHelpButtonHint); + + ui->tableWidget->setColumnWidth(0,220); + ui->tableWidget->setColumnWidth(1,90); + ui->tableWidget->setColumnWidth(2,90); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); + ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection); + ui->tableWidget->setFocusPolicy(Qt::NoFocus); + ui->pushButton->setFocusPolicy(Qt::NoFocus); + connect(ui->pushButton,&QPushButton::clicked,this,&DbCheck::brush); + connect( &m_checkThread, SIGNAL(finished()), this, SLOT(slotDbCheckFinished()) ); + + m_checkThread.startKeepAliveUdp(); + + brush(); + CustomUiDialog::setAutoLayout(true); +} + +DbCheck::~DbCheck() +{ + delete ui; +} + +void DbCheck::brush() +{ + if( m_checkThread.isRunning()) + { + ui->tip->setText(tr("正在刷新,无需再次提交刷新!")); + return ; + } + + m_checkThread.start(); + ui->tip->setText(tr("正在刷新,请稍后!")); +} + +void DbCheck::slotDbCheckFinished() +{ + QString lastErro = m_checkThread.getLastErro(); + if(lastErro.isEmpty()) + { + ui->tip->setText(tr("查询成功!")); + updateModelInfo(); + updateDbInfo(); + updateDbSync(); + updateDbKeepAlive(); + } + else + { + ui->tip->setText(tr("%1").arg(lastErro)); + } +} + +void DbCheck::updateModelInfo() +{ + SModelInfo & modelInfo = m_checkThread.getSModelInfo(); + updateModelInfo(modelInfo.modelReadStatus,ui->modelread); + updateModelInfo(modelInfo.modelWriteStatus,ui->modelwrite); + updateModelInfo(modelInfo.hisReaderStatus,ui->hisread); + updateModelInfo(modelInfo.tsdbStatus,ui->label); +} + +void DbCheck::updateDbInfo() +{ + ui->tableWidget->setRowCount(0); + //QMessageBox::warning(this,tr("提示"),tr("查询成功")); + QMap & resultMap = m_checkThread.getDbResult(); + + QMap::iterator iter = resultMap.begin(); + for(; iter!=resultMap.end(); ++iter) + { + SDbItemInfo& info = iter.value(); + addTable(info); + } +} + +void DbCheck::updateDbSync() +{ + QString isSyncStatus = tr("未知"); + int syncId = -1; + QString maxIdNode = tr("未知"); + + int isAbnormal = 0; + int maxSyncId = -1; + + bool isSync = m_checkThread.isEnableSync(); + + QMap & resultMap = m_checkThread.getDbResult(); + QMap::iterator iter = resultMap.begin(); + for(; iter!=resultMap.end(); ++iter) + { + SDbItemInfo& info = iter.value(); + + + if(iter == resultMap.begin()) + { + maxSyncId = info.maxSyncId; + maxIdNode = info.sNodeName; + isAbnormal = -1; + isSyncStatus = tr("正常"); + } + else + { + if(maxSyncId > info.maxSyncId && info.maxSyncId != -1) + { + isSyncStatus = QString(tr("同步ID相差:%1")).arg(syncId-info.maxSyncId); + isAbnormal = 1; + } + else if(maxSyncId < info.maxSyncId && info.maxSyncId != -1) + { + isSyncStatus = QString(tr("同步ID相差:%1")).arg(info.maxSyncId-syncId); + maxSyncId = info.maxSyncId; + maxIdNode = info.sNodeName; + isAbnormal = 1; + } + + if( info.maxSyncId == -1) + { + isAbnormal = 1; + isSyncStatus = QString(tr("读取失败:%1")).arg(info.sNodeName); + } + } + } + + if(!isSync) + { + ui->maxSyncID->setText(QString("%1(%2)").arg(maxIdNode).arg(maxSyncId)); + ui->syncStatus->setText(tr("未启用")); + } + else + { + ui->maxSyncID->setText(QString("%1(%2)").arg(maxIdNode).arg(maxSyncId)); + ui->syncStatus->setText(isSyncStatus); + } + + if(isAbnormal == 1) + { + ui->maxSyncID->setStyleSheet("QLabel{color:red}"); + ui->syncStatus->setStyleSheet("QLabel{color:red}"); + } + else if(isAbnormal == -1) + { + ui->maxSyncID->setStyleSheet("QLabel{color:green}"); + ui->syncStatus->setStyleSheet("QLabel{color:green}"); + } + else + { + ui->maxSyncID->setStyleSheet("QLabel{color:black}"); + ui->syncStatus->setStyleSheet("QLabel{color:black}"); + } +} + +void DbCheck::updateDbKeepAlive() +{ + ui->virtualNode->setText(tr("无")); + //ui->virtualNodeTime->setText(tr("未知")); + ui->serverStatus->setText(tr("未知")); + + QMap & resultMap = m_checkThread.getDbResult(); + QMap::iterator iter = resultMap.begin(); + + QString virtualNode = tr("无"); + QString erroStr =""; + bool isSync = m_checkThread.isEnableSync(); + + for(; iter!=resultMap.end(); ++iter) + { + SDbItemInfo& info = iter.value(); + if(info.keepAliveStatus == 0) + { + erroStr = tr("服务未开启:%1").arg(info.sNodeName); + } + + if(info.isDriftAddr) + { + virtualNode = info.sNodeName; + } + } + + if(!isSync) + { + ui->serverStatus->setText(tr("未启用")); + ui->virtualNode->setText(tr("")); + ui->virtualNode->setStyleSheet("QLabel{color:green}"); + } + else + { + if(!erroStr.isEmpty()) + { + ui->serverStatus->setText(erroStr); + ui->serverStatus->setStyleSheet("QLabel{color:red}"); + } + else + { + ui->serverStatus->setText(tr("正常")); + ui->serverStatus->setStyleSheet("QLabel{color:green}"); + } + + // 2022-09-02 注释,经讨论只要IP漂移主机有值,就是绿色,否则就显示“” + ui->virtualNode->setStyleSheet("QLabel{color:green}"); + ui->virtualNode->setText(virtualNode); + } + +} + + + +void DbCheck::updateModelInfo(int status, QLabel *lable) +{ + if(status == 1) + { + lable->setText(tr("正常")); + lable->setStyleSheet("QLabel{color:green}"); + } + else if(status == -1) + { + lable->setText(tr("异常")); + lable->setStyleSheet("QLabel{color:red}"); + } + else + { + lable->setText(tr("未知")); + lable->setStyleSheet("QLabel{color:black}"); + } +} + +void DbCheck::addTable(const SDbItemInfo &info) +{ + int rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->setRowCount(rowCount+1); + + QTableWidgetItem *item = new QTableWidgetItem(); + if(info.isFirst) + { + item->setData(Qt::DisplayRole,info.first+tr("(首链接)")); + item->setTextAlignment(Qt::AlignCenter); + ui->tableWidget->setItem(rowCount,0,item); + }else + { + item->setData(Qt::DisplayRole,info.first); + item->setTextAlignment(Qt::AlignCenter); + ui->tableWidget->setItem(rowCount,0,item); + } + + if(info.isUsed) + { + item = new QTableWidgetItem(); + item->setTextColor(Qt::darkGreen); + item->setData(Qt::DisplayRole,tr("正常")); + item->setTextAlignment(Qt::AlignCenter); + ui->tableWidget->setItem(rowCount,1,item); + }else + { + item = new QTableWidgetItem(); + item->setTextColor(Qt::red); + item->setData(Qt::DisplayRole,tr("异常")); + item->setTextAlignment(Qt::AlignCenter); + ui->tableWidget->setItem(rowCount,1,item); + } +} + + +bool DbCheck::getDbPara(SDatabaseInfo &stConnect, CDbPara ¶) +{ + para.setDatabaseName(QString::fromStdString(stConnect.strServiceName)); + LOGDEBUG("ServiceName:%s",stConnect.strServiceName.c_str()); + para.setUserName(QString::fromStdString(stConnect.strUserName)); + LOGDEBUG("UserName:%s",stConnect.strUserName.c_str()); + para.setPassword(QString::fromStdString(stConnect.strUserPassword)); + LOGDEBUG("Password:%s",stConnect.strUserPassword.c_str()); + para.setPort(stConnect.nPort); + LOGDEBUG("Port:%d",stConnect.nPort); + switch (stConnect.eDBType) { + case EDBType_ORACLE: + para.setDbType(DB_ORACLE); + LOGDEBUG("DBType:DB_ORACLE"); + break; + case EDBType_MYSQL: + para.setDbType(DB_MYSQL); + LOGDEBUG("DBType:DB_MYSQL"); + break; + case EDBType_OPENGAUSS: + para.setDbType(DB_OPENGAUSS); + LOGDEBUG("DBType:DB_OPENGAUSS"); + break; + case EDBType_KINGBASE: + para.setDbType(DB_KINGBASE); + LOGDEBUG("DBType:DB_KINGBASE"); + break; + default: + LOGDEBUG("DBType:EDBType_Invalid"); + return false; + break; + } + return true; +} + +void DbCheck::closeEvent(QCloseEvent *event) +{ + if(m_checkThread.isRunning()) + { + int resultButton = N_MessageBox::information (this,tr("提示"),tr("正在查询,是否终止查询?"), + N_MessageBox::Yes | N_MessageBox::No, N_MessageBox::Yes); + if(resultButton == N_MessageBox::Yes) + { + m_checkThread.requestInterruption(); + } + event->ignore(); + return; + } + + QDialog::closeEvent(event); +} + + diff --git a/product/src/tools/workBench/DbCheck.h b/product/src/tools/workBench/DbCheck.h new file mode 100644 index 00000000..4a799860 --- /dev/null +++ b/product/src/tools/workBench/DbCheck.h @@ -0,0 +1,142 @@ +#ifndef DBCHECK_H +#define DBCHECK_H + +#include +#include "pub_sysinfo_api/SysInfoApi.h" +#include "db_base_api/CDbBaseApi.h" +#include "tsdb_api/TsdbApi.h" +#include "db_api_ex/CDbApi.h" +#include +#include +# include +#include "pub_widget/CustomDialog.h" + +namespace Ui { +class DbCheck; +} + +struct SModelInfo +{ + //1 正常 -1异常 0未知 + int modelReadStatus; + int modelWriteStatus; + int hisReaderStatus; + int tsdbStatus; + + SModelInfo() + { + modelReadStatus = 0; + modelWriteStatus = 0; + hisReaderStatus = 0; + tsdbStatus = 0; + } +}; + +struct DbItemData +{ + QString first; + bool isFirst; + bool isUsed; + QString sNodeName; + int maxSyncId; +}; + +struct SDbItemInfo +{ + iot_public::SDatabaseInfo connect; + + QString first; + bool isFirst; + bool isUsed; + bool isVirNode; //是否虚拟节点 + QString sNodeName; + int maxSyncId; + + bool isDriftAddr; + int keepAliveStatus; //1 收到 0 未收到 + QString keepAliveTime;//收到的时间 + SDbItemInfo(): + isVirNode(false) + { + isDriftAddr = false; + isFirst = false; + isUsed = false; + maxSyncId = 0; + keepAliveStatus = 0; + } +}; + +class DbCheckThread : public QThread +{ + Q_OBJECT +public: + explicit DbCheckThread(QObject *parent = Q_NULLPTR); + ~DbCheckThread(); + + bool startKeepAliveUdp(); + void stopKeepAliveUdp(); + + QMap& getDbResult(); + SModelInfo& getSModelInfo(); + bool isEnableSync(); + QString getLastErro(); +private: + void run(); + + void updateModelInfo(); + + bool resetSysInfo(); + bool initDbInfoVec(); + bool checkDbInfoVec(); + + + bool checkDbInfo(SDbItemInfo& info); + bool check(SDbItemInfo &stConnect, + iot_public::SNodeInfo &stNodeInfo); + +private slots: + void slotReceiveNetKeepAlivedInfo(); + +private: + iot_public::CSysInfoInterfacePtr m_ptrSysInfo; + + SModelInfo mModelInfo;//模型状态 + QMutex m_mapDbInfoMx; + QMap m_mapDBInfo;//数据库连接状态 + bool m_isEnableSync; + + QUdpSocket* m_pRecvUdp; // 接收socket + QString mLastErroStr; +}; + + +class DbCheck : public CustomUiDialog +{ + Q_OBJECT +public: + explicit DbCheck(QWidget *parent = 0); + ~DbCheck(); + + static bool getDbPara(iot_public::SDatabaseInfo &stConnect, iot_dbms::CDbPara ¶); +protected: + void closeEvent(QCloseEvent *event); +private slots: + void brush(); + void slotDbCheckFinished(); + +private: + void updateModelInfo(); + void updateModelInfo(int status, QLabel* lable); + + void updateDbInfo(); + void updateDbSync(); + void updateDbKeepAlive(); + + void addTable(const SDbItemInfo& info); + +private: + Ui::DbCheck *ui; + DbCheckThread m_checkThread; +}; + +#endif // DBCHECK_H diff --git a/product/src/tools/workBench/DbCheck.ui b/product/src/tools/workBench/DbCheck.ui new file mode 100644 index 00000000..bc2fa9a5 --- /dev/null +++ b/product/src/tools/workBench/DbCheck.ui @@ -0,0 +1,273 @@ + + + DbCheck + + + + 0 + 0 + 629 + 354 + + + + 数据库检测 + + + + :/db_check.ico:/db_check.ico + + + + + + 连接状态 + + + + + + true + + + QAbstractItemView::NoEditTriggers + + + 118 + + + 100 + + + true + + + + 节点名/IP + + + AlignCenter + + + + + 连接状态 + + + AlignCenter + + + + + + + + + + + 同步状态 + + + + + + + 0 + 0 + + + + 同步状态: + + + + + + + - + + + + + + + + 0 + 0 + + + + 最大ID主机: + + + + + + + - + + + + + + + 服务状态: + + + + + + + - + + + + + + + IP漂移主机: + + + + + + + - + + + + + + + + + + + 150 + 0 + + + + 读写状态 + + + + + + + + 模型(读): + + + + + + + - + + + + + + + 模型(写): + + + + + + + - + + + + + + + 历史(读): + + + + + + + - + + + + + + + 时序库状态 + + + + + + + - + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 刷新 + + + + + + + + + + + + diff --git a/product/src/tools/workBench/DbCheckSync.cpp b/product/src/tools/workBench/DbCheckSync.cpp new file mode 100644 index 00000000..1d43bba0 --- /dev/null +++ b/product/src/tools/workBench/DbCheckSync.cpp @@ -0,0 +1,81 @@ +#include "DbCheckSync.h" +#include +#include "pub_logger_api/logger.h" +#include "DbCheck.h" + +using namespace iot_public; +using namespace iot_dbms; + +DbCheckSync::DbCheckSync() +{ + if(!createSysInfoInstance(m_ptrSysInfo)) + { + LOGERROR("创建系统信息访问库失败"); + } +} + +DbCheckSync::DbCheckSync(CSysInfoInterfacePtr sysInfo):m_ptrSysInfo(sysInfo) +{ + +} + +int DbCheckSync::getSyncMaxId(SDatabaseInfo &info) +{ + //获取首链接节点信息 + SNodeInfo stNodeInfo; + int res = m_ptrSysInfo->getNodeInfoByName(info.strNodeName,stNodeInfo); + if(res != iotSuccess) + { + return -1; + } + + return getSyncMaxId(info,stNodeInfo); +} + +int DbCheckSync::getSyncMaxId(SDatabaseInfo &stConnect, SNodeInfo &stNodeInfo) +{ + if(!stNodeInfo.bIsUsed) + { + return -1; + } + + for(int index(1);index <= stNodeInfo.nNicNum;index++) + { + CDbPara para; + if(index == 1) + { + para.setHostName(QString::fromStdString(stNodeInfo.strNic1Addr)); + } + if(index == 2) + { + para.setHostName(QString::fromStdString(stNodeInfo.strNic2Addr)); + } + QString firstColumn = QString("%1/%2").arg(QString::fromStdString(stNodeInfo.strName)).arg(para.getHostName()); + + if(!DbCheck::getDbPara(stConnect,para)) + { + LOGERROR("[%s]数据库类型错误!参数错误,直接默认为数据库状态不正常",firstColumn.toStdString().c_str()); + continue; + } + + CDbBaseApi baseApi(para); + if(baseApi.open()) + { + int maxId = getSyncMaxId(baseApi); + baseApi.close(); + return maxId; + }else + { + baseApi.close(); + } + } + + return -1; +} + +int DbCheckSync::getSyncMaxId(CDbBaseApi &baseApi) +{ + int maxId = baseApi.getMaxValueByCol("dbop_list","ID").toInt(); + return maxId; +} + diff --git a/product/src/tools/workBench/DbCheckSync.h b/product/src/tools/workBench/DbCheckSync.h new file mode 100644 index 00000000..500f964b --- /dev/null +++ b/product/src/tools/workBench/DbCheckSync.h @@ -0,0 +1,24 @@ +#ifndef DBCHECKSYNC_H +#define DBCHECKSYNC_H + +#include "db_api_ex/CDbApi.h" +#include "pub_sysinfo_api/SysInfoApi.h" +#include "db_base_api/CDbBaseApi.h" + +using namespace iot_public; +using namespace iot_dbms; +class DbCheckSync +{ +public: + DbCheckSync(); + DbCheckSync( iot_public::CSysInfoInterfacePtr sysInfo); + + //返回非 -1 则查询成功 + int getSyncMaxId(SDatabaseInfo &info); + static int getSyncMaxId(SDatabaseInfo &stConnect, SNodeInfo &stNodeInfo); + static int getSyncMaxId(CDbBaseApi& baseApi); +private: + iot_public::CSysInfoInterfacePtr m_ptrSysInfo; +}; + +#endif // DBCHECKSYNC_H diff --git a/product/src/tools/workBench/DogCheck.cpp b/product/src/tools/workBench/DogCheck.cpp new file mode 100644 index 00000000..5f64fd83 --- /dev/null +++ b/product/src/tools/workBench/DogCheck.cpp @@ -0,0 +1,97 @@ +#include "DogCheck.h" +#include "ui_DogCheck.h" +#include "sys_dog_auth_api/DogAuthInterface.h" +#include +#include +#include +#include +#include +#include "pub_widget/MessageBox.h" + +using namespace iot_sys; +DogCheck::DogCheck(QWidget *parent) : + CustomUiDialog(parent), + ui(new Ui::DogCheck) +{ + setWindowTitle(tr("授权检测")); + ui->setupUi(this); + slot_recheckBtn(); + ui->recheckBtn->setText(tr("重新检测")); + connect(ui->recheckBtn, &QPushButton::clicked, this, &DogCheck::slot_recheckBtn); + connect(ui->pushButton_2,&QPushButton::clicked,this,&DogCheck::slot_openLicenseDir); + connect(ui->pushButton,&QPushButton::clicked,this,&DogCheck::slot_selectLicense); + CustomUiDialog::setAutoLayout(true); + adjustSize(); + +} + +DogCheck::~DogCheck() +{ + delete ui; +} + +void DogCheck::slot_recheckBtn() +{ + CDogAuthInterfacePtr ptrDogAuth = getDogAuthInstance(); + int nRet = ptrDogAuth->checkAuthStatus(); + if (nRet > 0) + { + + ui->statusLab->setText(tr("异常,错误码[%1]").arg(nRet)); + } + else + { + ui->statusLab->setText(tr("正常")); + } +} + +void DogCheck::slot_openLicenseDir() +{ + QString strDir = QCoreApplication::applicationDirPath(); + QString licenseDir = QString("%1/../common/license/").arg(strDir); + if(!QFileInfo::exists(licenseDir)) + { + + } + QDesktopServices::openUrl(QUrl::fromLocalFile(licenseDir)); +} + +void DogCheck::slot_selectLicense() +{ + QString strBinDir = QCoreApplication::applicationDirPath(); + QString licenseFile = QString("%1/../common/license/license.txt").arg(strBinDir); + + QFile destFile(licenseFile); + if(destFile.exists()) + { + if(!destFile.remove()) + { + N_MessageBox::warning( this, tr("提示"), tr("删除原文件失败") ); + return ; + } + } + + QFileDialog fileDialog; + QString strDir = fileDialog.getOpenFileName(this, tr("选择授权文件"),"license.txt",tr("txt (*.txt)")); + + if (strDir.isEmpty()) + { + return ; + } + + QFile sourceFile(strDir); + if (!sourceFile.exists()) { + N_MessageBox::warning(this, tr("提示"), tr("文件不存在")); + return ; + } + + bool ret = sourceFile.copy(licenseFile); + if(!ret) + { + N_MessageBox::warning(this, tr("提示"), tr("导入失败![%1]").arg(sourceFile.errorString())); + return; + } + + + QMessageBox::warning(this, tr("提示"),tr("导入成功!")); +} diff --git a/product/src/tools/workBench/DogCheck.h b/product/src/tools/workBench/DogCheck.h new file mode 100644 index 00000000..061eb015 --- /dev/null +++ b/product/src/tools/workBench/DogCheck.h @@ -0,0 +1,26 @@ +#ifndef DOGCHECK_H +#define DOGCHECK_H + +#include +#include "pub_widget/CustomDialog.h" + +namespace Ui { +class DogCheck; +} + +class DogCheck : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit DogCheck(QWidget *parent = 0); + ~DogCheck(); +private slots: + void slot_recheckBtn(); + void slot_openLicenseDir(); + void slot_selectLicense(); +private: + Ui::DogCheck *ui; +}; + +#endif // DOGCHECK_H diff --git a/product/src/tools/workBench/DogCheck.ui b/product/src/tools/workBench/DogCheck.ui new file mode 100644 index 00000000..cc201d77 --- /dev/null +++ b/product/src/tools/workBench/DogCheck.ui @@ -0,0 +1,151 @@ + + + DogCheck + + + + 0 + 0 + 423 + 245 + + + + + + + Qt::Vertical + + + + 20 + 27 + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + 1、请将操作系统信息(re_code.txt)发给系统提供商,获取授权文件 + + + true + + + + + + + 拷贝操作系统信息 + + + + + + + + + 激活状态: + + + + + + + 正常 + + + + + + + 重新检测 + + + + + + + + + 导入授权文件 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 2、获取授权文件后,进行系统激活 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Qt::Vertical + + + + 20 + 28 + + + + + + + + + diff --git a/product/src/tools/workBench/Main.cpp b/product/src/tools/workBench/Main.cpp new file mode 100644 index 00000000..86e47a8a --- /dev/null +++ b/product/src/tools/workBench/Main.cpp @@ -0,0 +1,50 @@ + +#include +#include +#include +#include + +#include "common/QtAppGlobalSet.h" +#include "pub_utility_api/I18N.h" +#include "pub_utility_api/FileUtil.h" +#include "SingleApplication.h" +#include "MainWindow.h" +#include "pub_widget/MessageBox.h" + +int main(int argc, char *argv[]) +{ + iot_common::doQtAppGlobalSet(); + + SingleApplication a(argc, argv); + + QDir::setCurrent(iot_public::CFileUtil::getCurModuleDir().c_str()); + + const std::string strLanguage = std::move( iot_public::getCurLanguage()); + const std::string strQmFile = std::move( iot_public::CFileUtil::getPathOfResFile( + "workBench/translate/" + strLanguage + ".qm" ) ); + if ( !strQmFile.empty()) + { + auto *pTrans = new QTranslator; + pTrans->load( strQmFile.c_str()); + QApplication::installTranslator( pTrans ); + } + + MainWindow w(strLanguage.c_str()); + QObject::connect( &a, &SingleApplication::instanceStarted, [ &w ]() { + w.startWork(); + w.show(); + w.showNormal(); + w.activateWindow(); + }); + if(w.isRunning()) + { + N_MessageBox::critical(0, QObject::tr("警告"), QObject::tr("正在运行")); + return 0; + } + + w.show(); + + w.startAutoStartHmiTimer(); + + return a.exec(); +} diff --git a/product/src/tools/workBench/MainWindow.cpp b/product/src/tools/workBench/MainWindow.cpp new file mode 100644 index 00000000..19f4d8c3 --- /dev/null +++ b/product/src/tools/workBench/MainWindow.cpp @@ -0,0 +1,1484 @@ +#include "MainWindow.h" +#include "ui_mainwindow.h" +#include "MonitorCommon.h" +#include "StartUpForm.h" +#include "AppMngForm.h" +#include "ProcMngForm.h" +#include "DataMng.h" +#include "ButtonForm.h" +#include "BrushDataThread.h" +#include "StatusForm.h" +#include "SystemSetForm.h" +#include "SetupFunc.h" +#include "localstateform.h" +#include "CheckBoxDialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pub_utility_api/FileUtil.h" +#include "pub_utility_api/I18N.h" +#include "pub_utility_api/FileStyle.h" +#include "pub_widget/MessageBox.h" +#include "pub_widget/PubWidgetInit.h" + + +using namespace workBench; +using namespace iot_public; +using namespace iot_idl; +using namespace iot_sys; + +static QString restartAppName = QString(); + +MainWindow::MainWindow(QString language, QWidget *parent) : + CustomUiMainWindow(parent), + ui(new Ui::MainWindow), + m_bRunning(false), + m_pLocalServer(Q_NULLPTR), + m_language(language), + m_pStartUp(Q_NULLPTR), + m_pAppMng(Q_NULLPTR), + m_pProcMng(Q_NULLPTR), + m_pStatusMng(Q_NULLPTR), + m_pSysSetMng(Q_NULLPTR), + m_pSysTrayIcon(Q_NULLPTR), + m_updateTreeTimer(Q_NULLPTR), + m_updateSysTimer(Q_NULLPTR), + m_startSysTimer(Q_NULLPTR), + m_stopSysTimer(Q_NULLPTR), + m_appRestartTimer(Q_NULLPTR), + m_dogAndLocalNetTimer(Q_NULLPTR), + m_hmiAutoStartTimer(Q_NULLPTR), + m_brushDataThread(Q_NULLPTR), + m_checkObj(Q_NULLPTR), + m_checkThread(Q_NULLPTR), + m_pProcess(Q_NULLPTR), + m_ptrDogAuthApi(Q_NULLPTR), + m_bLastDogStatus(false), + m_pShowAction(nullptr), + m_pExitAction(nullptr), + m_pLocalState(Q_NULLPTR) +{ + ui->setupUi(this); + + DataMng::instance(); + + + initLog(); + + initMsgBus(); + + // 初始化变量 + initVariables(); + + // 初始化界面 + initUi(); + + //初始化信号槽 + initConn(); + + // 加载qss样式 + initSheet(); + + //校验ip + verifyIp(); + + //启动线程和定时器 + startThread(); + + initLocalConnection(); +} + +MainWindow::~MainWindow() +{ + if(m_pProcess) + { + delete m_pProcess; + } + m_pProcess = Q_NULLPTR; + + if(m_startSysTimer) + { + m_startSysTimer->stop(); + delete m_startSysTimer; + } + m_startSysTimer = Q_NULLPTR; + + if(m_stopSysTimer) + { + m_stopSysTimer->stop(); + delete m_stopSysTimer; + } + m_stopSysTimer = Q_NULLPTR; + + if(m_dogAndLocalNetTimer) + { + m_dogAndLocalNetTimer->stop(); + delete m_dogAndLocalNetTimer; + } + m_dogAndLocalNetTimer = Q_NULLPTR; + + if(m_hmiAutoStartTimer) + { + m_hmiAutoStartTimer->stop(); + delete m_hmiAutoStartTimer; + } + m_hmiAutoStartTimer = Q_NULLPTR; + + if(m_appRestartTimer) + { + m_appRestartTimer->stop(); + delete m_appRestartTimer; + } + m_appRestartTimer = Q_NULLPTR; + + if(m_updateTreeTimer) + { + m_updateTreeTimer->stop(); + delete m_updateTreeTimer; + } + m_updateTreeTimer = Q_NULLPTR; + + if(m_updateSysTimer) + { + m_updateSysTimer->stop(); + delete m_updateSysTimer; + } + m_updateSysTimer = Q_NULLPTR; + + if(m_checkThread) + { + m_checkThread->exit(); + m_checkThread->wait(); + delete m_checkThread; + } + m_checkThread = Q_NULLPTR; + + if(m_brushDataThread) + { + m_brushDataThread->suspend(); + m_brushDataThread->quit(); + m_brushDataThread.reset(); + } + + if(m_pSysTrayIcon) + { + delete m_pSysTrayIcon; + } + m_pSysTrayIcon = Q_NULLPTR; + + DataMng::instance()->destory(); + + if(! iot_net::releaseMsgBus()) + { + LOGERROR("释放消息总线失败"); + } + + iot_public::StopLogSystem(); + + if (m_pLocalServer) + { + delete m_pLocalServer; + m_pLocalServer = NULL; + } + + if(m_pStopProcess) + { + delete m_pStopProcess; + } + + delete ui; +} + +bool MainWindow::isRunning() +{ + return m_bRunning; +} + +void MainWindow::initLocalConnection() +{ + // 已经用了SingleApplication,为什么还要增加这种方式: + // SingleApplication只能解决同一个文件执行多次的情况 + // 如果是不同的文件,比如安装了两份软件在不同目录,要靠本函数的机制防止 + m_bRunning = false; + QLocalSocket socket; + socket.connectToServer(STARTUP_SERVER_NAME); + if(socket.waitForConnected(500)) + { + m_bRunning = true; + return; + } + newLocalServer(); +} + +void MainWindow::newLocalServer() +{ + m_pLocalServer = new QLocalServer(this); + if(!m_pLocalServer->listen(STARTUP_SERVER_NAME)) + { + if(m_pLocalServer->serverError() == QAbstractSocket::AddressInUseError) + { + QLocalServer::removeServer(STARTUP_SERVER_NAME); + m_pLocalServer->listen(STARTUP_SERVER_NAME); + } + } +} + +void MainWindow::startWork() +{ + m_brushDataThread->resume(); + m_updateTreeTimer->start(); + m_updateSysTimer->start(); + m_dogAndLocalNetTimer->start(); +} + +void MainWindow::stopWork() +{ + m_dogAndLocalNetTimer->stop(); + m_updateSysTimer->stop(); + m_updateTreeTimer->stop(); + m_brushDataThread->suspend(); +} + +void MainWindow::startAutoStartHmiTimer() +{ + m_hmiAutoStartTimer->start(); +} + +void MainWindow::initSheet() +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss","zh","light"); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("workBench.qss","","light") ; + QFile qssfile(QString::fromStdString(strFullPath)) ; + qssfile.open(QFile::ReadOnly); + if (qssfile.isOpen()) + { + qss += QLatin1String(qssfile.readAll()); + qssfile.close(); + } + + if (!qss.isEmpty()) + { + qApp->setStyleSheet(qss); + } + iot_public::installTranslator(iot_public::getCurLanguage()); +} + +void MainWindow::initVariables() +{ + if(m_pStartUp == Q_NULLPTR) + { + m_pStartUp = new StartUpForm; + } + if(m_pAppMng == Q_NULLPTR) + { + m_pAppMng = new AppMngForm; + } + if(m_pProcMng == Q_NULLPTR) + { + m_pProcMng = new ProcMngForm; + } + if(m_pStatusMng == Q_NULLPTR) + { + m_pStatusMng = new StatusForm; + } + if(m_pSysSetMng == Q_NULLPTR) + { + m_pSysSetMng = new SystemSetForm; + } + + if( m_pLocalState == Q_NULLPTR) + { + m_pLocalState = new LocalStateForm; + } + if(m_pSysTrayIcon == Q_NULLPTR) + { + m_pSysTrayIcon = new QSystemTrayIcon; + QString sysIcon = DataMng::instance()->getSysIcon(); + if(sysIcon.isEmpty()) + m_pSysTrayIcon->setIcon(QIcon(":/sys_startup.ico")); + else + m_pSysTrayIcon->setIcon(QIcon(sysIcon)); + + QMenu* pMenu = new QMenu(this); + m_pShowAction = pMenu->addAction(tr("显示")); + m_pExitAction = pMenu->addAction(tr("退出")); + connect(m_pShowAction, &QAction::triggered, [=](){ + startWork(); + this->show(); + this->showNormal(); + this->activateWindow(); + }); + connect(m_pExitAction, &QAction::triggered, [=](){ + qApp->quit(); + }); + + m_pSysTrayIcon->setContextMenu(pMenu); + m_pSysTrayIcon->show(); + } + m_brushDataThread = boost::make_shared(); + m_brushDataThread->initialize(DataMng::instance()->getDomainId(),1); + m_updateTreeTimer = new QTimer; + m_updateTreeTimer->setInterval(5000); + + m_checkObj = new OnTimeCheckThread(nullptr); + m_checkThread = new QThread(); + m_checkObj->moveToThread(m_checkThread); + m_updateSysTimer = new QTimer; + m_updateSysTimer->setInterval(1000); + m_pProcess=new QProcess(this); + { + const std::string strProc = std::move( iot_public::CFileUtil::getPathOfBinFile( + std::string("sys_ctrl") + iot_public::CFileUtil::getProcSuffix())); + if(strProc.empty()) + LOGERROR("未找到可执行文件sys_ctrl"); + else + m_strSysCtrlPath = QString::fromStdString(strProc); + } + + m_startSysTimer = new QTimer; + m_startSysTimer->setInterval(1000); + + m_stopSysTimer = new QTimer; + m_stopSysTimer->setInterval(1000); + + m_appRestartTimer = new QTimer; + m_appRestartTimer->setInterval(1000); + + m_dogAndLocalNetTimer = new QTimer; + m_dogAndLocalNetTimer->setInterval(60000); + + m_hmiAutoStartTimer = new QTimer; + m_hmiAutoStartTimer->setInterval(2000); + + m_nStartStopResult = E_PROCESS_DEFAULT; + + m_ptrDogAuthApi = getDogAuthInstance(); + if (!m_ptrDogAuthApi) + { + LOGERROR("创建加密狗实例失败"); + } +} + +void MainWindow::initUi() +{ + //标题栏 +#ifdef OS_LINUX + setWindowIcon( QIcon( ":/sys_startup.ico" ) ); +#endif + setWindowTitle(DataMng::instance()->getTitle()); + m_pSysTrayIcon->setToolTip(DataMng::instance()->getTitle()); + + //菜单栏 + QPushButton* btn; + btn = new QPushButton(); + btn->setObjectName("btn_sysState"); + btn->setText(tr("系统状态")); + ui->widget_menu->addToolBtn(btn); + + btn = new QPushButton(); + btn->setObjectName("btn_sysProcess"); + btn->setText(tr("系统进程")); + ui->widget_menu->addToolBtn(btn); + + btn = new QPushButton(); + btn->setObjectName("btn_sysManage"); + btn->setText(tr("系统管理")); + ui->widget_menu->addToolBtn(btn); + + btn = new QPushButton(); + btn->setObjectName("btn_sysTool"); + btn->setText(tr("系统工具")); + ui->widget_menu->addToolBtn(btn); + + btn = new QPushButton(); + btn->setObjectName("btn_sysSetting"); + btn->setText(tr("系统设置")); + ui->widget_menu->addToolBtn(btn); + + //进度条 + QGridLayout *startUpLayout = new QGridLayout(ui->startUpFrame); + startUpLayout->setSpacing(6); + startUpLayout->setContentsMargins(0, 0, 0, 0); + startUpLayout->addWidget(m_pStartUp); + + //应用树 + QGridLayout * appLayout = new QGridLayout(ui->appFrame); + appLayout->setSpacing(6); + appLayout->setContentsMargins(0, 0, 0, 0); + appLayout->addWidget(m_pAppMng); + + //进程表格 + QGridLayout *procLayout = new QGridLayout(ui->procWidget); + procLayout->setSpacing(6); + procLayout->setContentsMargins(0, 0, 0, 0); + procLayout->addWidget(m_pProcMng); + + //本机应用状态 + QGridLayout *localStaLayout = new QGridLayout(ui->localstate); + localStaLayout->setSpacing(6); + localStaLayout->setContentsMargins(0, 0, 0, 0); + localStaLayout->addWidget(m_pLocalState); + + + //首页快捷按钮 + ButtonForm *page1form = new ButtonForm(EN_SYS_STARTUP_PAGE1,m_language,this); + page1form->setTitleHide(true); + QVector buttons = DataMng::instance()->getPage1ButtonInfo(); + page1form->addToolButtons(buttons); + connect(page1form,&ButtonForm::sigLogText,m_pStatusMng,&StatusForm::slotLogText); + QGridLayout *page1layout = new QGridLayout(ui->customWidget); + page1layout->setSpacing(0); + page1layout->setContentsMargins(0,0,0,0); + page1layout->addWidget(page1form); + + //工具箱按钮 + QMap buttonGroupMap = DataMng::instance()->getPage3ButtonInfo(); + QMap::iterator it = buttonGroupMap.begin(); + QVBoxLayout *page3layout = new QVBoxLayout(ui->boxWidget); + page3layout->setSpacing(20); + while (it != buttonGroupMap.end()) { + ButtonForm *page3form = new ButtonForm(EN_SYS_STARTUP_PAGE3,m_language,this); + page3form->setTitleText(it.value().m_desc); + page3form->addToolButtons(it.value().m_buttonVec , it.key()); + connect(page3form,&ButtonForm::sigLogText,m_pStatusMng,&StatusForm::slotLogText); + connect(page3form , &ButtonForm::sigUpdataButton , this , &MainWindow::updataButtonForm); + page3layout->addWidget(page3form); + it++; + } + page3layout->addStretch(); + + //状态栏视图 + QGridLayout *statusLayout = new QGridLayout(ui->status_mng); + statusLayout->setSpacing(6); + statusLayout->setContentsMargins(0, 0, 0, 0); + statusLayout->addWidget(m_pStatusMng); + + //版本 + QGridLayout *versionLayout = new QGridLayout(ui->verWidget); + versionLayout->setSpacing(6); + versionLayout->setContentsMargins(0, 0, 0, 0); + versionLayout->addWidget(m_pSysSetMng); + connect(m_pSysSetMng,&SystemSetForm::sigLogText,m_pStatusMng,&StatusForm::slotLogText); + + setTitleWidget(ui->titleMenu); + setSendCloseSignal(true); + ui->widget_menu->setButtonClicked(0); +} + +void MainWindow::initConn() +{ + connect(m_updateTreeTimer,&QTimer::timeout,m_pAppMng,&AppMngForm::updateAppTree); + connect(m_updateTreeTimer,&QTimer::timeout,m_pLocalState,&LocalStateForm::updataLocalState); + + // connect(m_updateTreeTimer,&QTimer::timeout,m_pProcMng,&ProcMngForm::updateProcTree); + + connect(m_updateSysTimer,&QTimer::timeout,m_checkObj,&OnTimeCheckThread::brush,Qt::QueuedConnection); + connect(m_checkObj,&OnTimeCheckThread::changeTab,m_pStartUp,&StartUpForm::changeIndex,Qt::QueuedConnection); + + connect(m_checkThread, &QThread::finished, m_checkObj, &QObject::deleteLater); + connect(m_checkThread, &QThread::finished, m_updateSysTimer, &QTimer::deleteLater); + + connect(m_pStartUp,&StartUpForm::sigStartSystem,this,&MainWindow::slotStartSystem); + connect(m_pStartUp,&StartUpForm::sigStopSystem,this,&MainWindow::slotStopSystem); + + connect(m_pProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(outPut())); + connect(m_pProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(finish(int,QProcess::ExitStatus))); + + connect(m_startSysTimer,&QTimer::timeout,this,&MainWindow::startPercent); + connect(m_stopSysTimer,&QTimer::timeout,this,&MainWindow::stopPercent); + + connect(this,&MainWindow::changeTab,m_pStartUp,&StartUpForm::changeIndex); + connect(m_pAppMng,&AppMngForm::sigReloadAppAndProc,this,&MainWindow::reloadData); + connect(m_pAppMng,&AppMngForm::sigStartApp,this,&MainWindow::startApp); + connect(m_pAppMng,&AppMngForm::sigStopApp,this,&MainWindow::stopApp); + connect(m_pAppMng,&AppMngForm::sigRestartApp,this,&MainWindow::restartApp); + + connect(m_pLocalState , &LocalStateForm::sigStartServer , this , &MainWindow::startApp); + connect(m_pLocalState , &LocalStateForm::sigStopServer , this , &MainWindow::stopApp); + connect(m_pLocalState , &LocalStateForm::sigRestartServer , this , &MainWindow::restartApp); + + connect(m_appRestartTimer,&QTimer::timeout,this,&MainWindow::ifStartApp); + + connect(m_pProcMng,&ProcMngForm::sigReloadAppAndProc,this,&MainWindow::reloadData); + connect(m_pProcMng,&ProcMngForm::sigStartProc,this,&MainWindow::startProc); + connect(m_pProcMng,&ProcMngForm::sigStopProc,this,&MainWindow::stopProc); + connect(m_pProcMng,&ProcMngForm::sigRestartProc,this,&MainWindow::reStartProc); + connect(m_pProcMng,&ProcMngForm::sigForceStopProc,this,&MainWindow::forceStopProc); + + connect(m_dogAndLocalNetTimer,&QTimer::timeout,this,&MainWindow::dogAndNetCheck); + + connect(m_hmiAutoStartTimer,&QTimer::timeout,this,&MainWindow::autoStartHmi); + connect(m_pSysTrayIcon,&QSystemTrayIcon::activated,this,&MainWindow::iconActived); + + connect(ui->widget_menu, SIGNAL(buttonClicked(int)),ui->stackedWidget, SLOT(setCurrentIndex(int))); + connect(ui->stackedWidget, &QStackedWidget::currentChanged,this,&MainWindow::tabWidget_currentIdxChanged); + + connect(m_pSysSetMng , &SystemSetForm::signalUpdataPage1 , this , &MainWindow::updataButtonForm); + + connect(this, &MainWindow::closeClicked , this , &MainWindow::slot_closeWindow ); +} + +void MainWindow::initLog() +{ + //注册日志 + iot_public::StartLogSystem(CN_AppName_BASE.c_str(),STARTUP_SERVER_NAME); +} + +void MainWindow::initMsgBus() +{ + //初始化消息总线 + if(! iot_net::initMsgBus(STARTUP_SERVER_NAME,STARTUP_SERVER_NAME)) + { + LOGERROR("初始化消息总线失败"); + } +} + +void MainWindow::startThread() +{ + dogAndNetCheck(); + m_checkThread->start(); + startWork(); +} + +void MainWindow::showMessDialog(const QString &mess) +{ + N_MessageBox::warning(this,tr("提示"),mess); +} + +void MainWindow::reloadAppTree() +{ + m_pAppMng->initAppTree(); +} + +void MainWindow::reloadProcTree() +{ + m_pProcMng->initProcTree(); +} + +void MainWindow::reloadLocalState() +{ + m_pLocalState->initlocalState(); +} + +void MainWindow::slotStartSystem() +{ + //1.检查系统是否全部退出 + if(OnTimeCheckThread::isSystemRunning()) + { + LOGDEBUG("内存库可能被占用,现在先停止系统,清除共享内存!"); + if(m_pStopProcess == nullptr) + { + m_pStopProcess = new QProcess; + } + else + { + m_pStopProcess->close(); + } + disconnect(m_pStopProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(startSystem(int,QProcess::ExitStatus))); + connect(m_pStopProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(startSystem(int,QProcess::ExitStatus))); + m_pStopProcess->start(m_strSysCtrlPath + " -s"); + return ; + }else + { + startSystem(); + } +} + +void MainWindow::slotStopSystem() +{ + //1.屏蔽信号 + blockSignal(true); + + //2.切换到正在停止界面 + emit changeTab(EN_SYSTEM_STOPPING); + + m_nStartStopResult = E_PROCESS_DEFAULT; + DataMng::instance()->setAllowedStatus(false); + + m_pProcess->start(m_strSysCtrlPath + " -s"); + + //更新状态 + QString text = tr("开始停止系统"); + m_pStatusMng->slotLogText(text); + m_stopSysTimer->start(); //启动停止定时器 + m_pProcess->waitForStarted(); +} + +void MainWindow::outPut() +{ + QString ret = QString::fromLocal8Bit(m_pProcess->readAllStandardOutput()); + ret=ret.trimmed(); + QStringList list=ret.split("\n"); + for(int i=0;islotLogText(list.at(i)); + } + } +} + +void MainWindow::finish(int res, QProcess::ExitStatus exit) +{ + Q_UNUSED(exit); + m_nStartStopResult = (E_PROCESS_RESULT)res; + DataMng::instance()->setAllowedStatus(true); +} + +void MainWindow::startPercent() +{ + int num = 0; + emit changeTab(EN_SYSTEM_STARTING); + if(m_nStartStopResult == E_PROCESS_FAILD || m_nStartStopResult == E_PROCESS_SUCCEED) + { + m_startSysTimer->stop(); + DataMng::instance()->setAllowedStatus(true); + blockSignal(false); + m_nStartStopResult = E_PROCESS_DEFAULT; + m_pStartUp->initStartValue(); + return ; + }else + { + float disk = 0.0; + vector procVec ; + DataMng::instance()->getRunProcInfo(procVec,disk); + vector::iterator it = procVec.begin(); + for(;it!=procVec.end();it++) + { + if(it->m_isStartUp == 1) + { + num++; + } + } + int localProcNum = DataMng::instance()->getLocalProcNum(); + + m_pStartUp->changeStartValue(num*100/localProcNum); + } +} + +void MainWindow::stopPercent() +{ + int num = 0; + emit changeTab(EN_SYSTEM_STOPPING); + if(m_nStartStopResult == E_PROCESS_FAILD || m_nStartStopResult == E_PROCESS_SUCCEED) + { + m_stopSysTimer->stop(); + DataMng::instance()->setAllowedStatus(true); + blockSignal(false); + m_nStartStopResult = E_PROCESS_DEFAULT; + m_pStartUp->initStopValue(); + return ; + }else + { + float disk = 0.0; + vector procVec ; + DataMng::instance()->getRunProcInfo(procVec,disk); + vector::iterator it = procVec.begin(); + for(;it!=procVec.end();it++) + { + if(it->m_isStartUp == 0) + { + num++; + } + } + int localProcNum = DataMng::instance()->getLocalProcNum(); + + m_pStartUp->changeStopValue(num*100/localProcNum); + } +} + +void MainWindow::reloadData() +{ + DataMng::instance()->loadXml(); + reloadAppTree(); + reloadProcTree(); + reloadLocalState(); +} + +void MainWindow::startApp(const QString appName) +{ + DataMng::instance()->setAllowedStatus(false); + m_nStartStopResult = E_PROCESS_DEFAULT; + m_pProcess->start(QString("%1 -a %2").arg(m_strSysCtrlPath).arg(appName)); +} + +void MainWindow::stopApp(const QString appName) +{ + DataMng::instance()->setAllowedStatus(false); + m_nStartStopResult = E_PROCESS_DEFAULT; + m_pProcess->start(QString("%1 -s -a %2").arg(m_strSysCtrlPath).arg(appName)); +} + +void MainWindow::restartApp(const QString appName) +{ + restartAppName = appName; + stopApp(appName); + m_appRestartTimer->start(); +} + +void MainWindow::ifStartApp() +{ + if(m_nStartStopResult == E_PROCESS_FAILD) + { + m_appRestartTimer->stop(); + m_nStartStopResult = E_PROCESS_DEFAULT; + }else if(m_nStartStopResult == E_PROCESS_SUCCEED) + { + m_appRestartTimer->stop(); + m_nStartStopResult = E_PROCESS_DEFAULT; + QString appName = restartAppName; + restartAppName = QString(); + startApp(appName); + } +} + +void MainWindow::startProc(int appId, const QString procName) +{ + vector procVec; + float disk = 0.0; + DataMng::instance()->getRunProcInfo(procVec,disk); + for(size_t index(0);indexsetAllowedStatus(false); + QString logText = QString(tr("开始启动进程:%1")).arg(QString::fromStdString(procVec[index].m_procName)); + LOGDEBUG("startProc()-%s",logText.toStdString().c_str()); + m_pStatusMng->slotLogText(logText); + + string strArgs; + + if (appId != CN_AppId_BASE) + { + strArgs += "-a " + DataMng::instance()->getAppNameByAppId(appId); + } + + if (!procVec[index].m_procParam.empty()) + { + strArgs += " " + procVec[index].m_procParam; + } + + string strModulePath; + CFileUtil::getPathOfBinFile(procName.toStdString() + CFileUtil::getProcSuffix(), &strModulePath); + + if(!CProcUtil::startProcess(strModulePath, procName.toStdString(), procVec[index].m_procParam, false,false)) + { + logText = QString(tr("启动进程:%1失败")).arg(QString::fromStdString(procVec[index].m_procName)); + LOGERROR("startProc()-%s",logText.toStdString().c_str()); + m_pStatusMng->slotLogText(logText); + }else + { + if(isProcStartSuccess(appId,procName)) + { + logText = QString(tr("启动进程:%1成功")).arg(QString::fromStdString(procVec[index].m_procName)); + LOGDEBUG("startProc()-%s",logText.toStdString().c_str()); + m_pStatusMng->slotLogText(logText); + } + else + { + logText = QString(tr("启动进程:%1失败")).arg(QString::fromStdString(procVec[index].m_procName)); + LOGDEBUG("startProc()-%s",logText.toStdString().c_str()); + m_pStatusMng->slotLogText(logText); + } + } + + DataMng::instance()->setAllowedStatus(true); + break; + } + } +} + +bool MainWindow::stopProc(int appId, const QString procName) +{ + CRdbNetApi netApi; + netApi.connect(DataMng::instance()->getDomainId(),1); + + vector procVec; + float disk = 0.0; + DataMng::instance()->getRunProcInfo(procVec,disk); + for(size_t index(0);indexsetAllowedStatus(false); + QString logText = QString(tr("开始停止进程:%1")).arg(QString::fromStdString(procVec[index].m_procName)); + LOGDEBUG("stopProc()-%s",logText.toStdString().c_str()); + m_pStatusMng->slotLogText(logText); + iot_idl::RdbUpdate rdbupdate; + + rdbupdate.set_strtablename(CN_TN_SysRunProcInfo); + + rdbupdate.add_msgcondition(); + rdbupdate.mutable_msgcondition(0)->set_enlogic(enumCondAnd); + rdbupdate.mutable_msgcondition(0)->set_enrelation(enumCondEqual); + rdbupdate.mutable_msgcondition(0)->set_strcolumnname("node_name"); + rdbupdate.mutable_msgcondition(0)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_STRING); + rdbupdate.mutable_msgcondition(0)->mutable_msgvalue()->set_strvalue(procVec[index].m_nodeName); + + rdbupdate.add_msgcondition(); + rdbupdate.mutable_msgcondition(1)->set_enlogic(enumCondAnd); + rdbupdate.mutable_msgcondition(1)->set_enrelation(enumCondEqual); + rdbupdate.mutable_msgcondition(1)->set_strcolumnname("proc_name"); + rdbupdate.mutable_msgcondition(1)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_STRING); + rdbupdate.mutable_msgcondition(1)->mutable_msgvalue()->set_strvalue(procName.toStdString()); + + rdbupdate.add_msgcondition(); + rdbupdate.mutable_msgcondition(2)->set_enlogic(enumCondAnd); + rdbupdate.mutable_msgcondition(2)->set_enrelation(enumCondEqual); + rdbupdate.mutable_msgcondition(2)->set_strcolumnname("app_id"); + rdbupdate.mutable_msgcondition(2)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgcondition(2)->mutable_msgvalue()->set_nvalue(appId); + + rdbupdate.add_msgupdatevalue(); + rdbupdate.mutable_msgupdatevalue(0)->set_strcolumnname("to_quit"); + rdbupdate.mutable_msgupdatevalue(0)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgupdatevalue(0)->mutable_msgvalue()->set_nvalue(1); + + bool bRet = false; + bRet=netApi.update(rdbupdate); + if(bRet==false) + { + LOGERROR("stopProc()-写表失败:%s",netApi.getErr().c_str()); + logText = QString(tr("停止进程:%1失败")).arg(QString::fromStdString(procVec[index].m_procName)); + m_pStatusMng->slotLogText(logText); + DataMng::instance()->setAllowedStatus(true); + return false; + + } + + if(isProcStopSuccess(appId,procName)) + { + logText = QString(tr("停止进程:%1成功")).arg(QString::fromStdString(procVec[index].m_procName)); + LOGDEBUG("stopProc()-%s",logText.toStdString().c_str()); + m_pStatusMng->slotLogText(logText); + DataMng::instance()->setAllowedStatus(true); + return true; + } + else + { + logText = QString(tr("停止进程:%1失败")).arg(QString::fromStdString(procVec[index].m_procName)); + LOGERROR("stopProc()-%s",logText.toStdString().c_str()); + m_pStatusMng->slotLogText(logText); + DataMng::instance()->setAllowedStatus(true); + return false; + } + } + } + return false; +} + +void MainWindow::reStartProc(int appId, const QString procName) +{ + if(stopProc(appId,procName)) + { + startProc(appId,procName); + } +} + +void MainWindow::forceStopProc(int appId, const QString procName) +{ + CRdbNetApi netApi; + netApi.connect(DataMng::instance()->getDomainId(),1); + vector procVec; + float disk = 0.0; + DataMng::instance()->getRunProcInfo(procVec,disk); + for(size_t index(0);indexsetAllowedStatus(false); + QString logText = QString(tr("强制停止进程:%1")).arg(QString::fromStdString(procVec[index].m_procName)); + LOGDEBUG("forceStopProc()-%s",logText.toStdString().c_str()); + m_pStatusMng->slotLogText(logText); + iot_idl::RdbUpdate rdbupdate; + + rdbupdate.set_strtablename(CN_TN_SysRunProcInfo); + + rdbupdate.add_msgcondition(); + rdbupdate.mutable_msgcondition(0)->set_enlogic(enumCondAnd); + rdbupdate.mutable_msgcondition(0)->set_enrelation(enumCondEqual); + rdbupdate.mutable_msgcondition(0)->set_strcolumnname("node_name"); + rdbupdate.mutable_msgcondition(0)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_STRING); + rdbupdate.mutable_msgcondition(0)->mutable_msgvalue()->set_strvalue(procVec[index].m_nodeName); + + rdbupdate.add_msgcondition(); + rdbupdate.mutable_msgcondition(1)->set_enlogic(enumCondAnd); + rdbupdate.mutable_msgcondition(1)->set_enrelation(enumCondEqual); + rdbupdate.mutable_msgcondition(1)->set_strcolumnname("proc_name"); + rdbupdate.mutable_msgcondition(1)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_STRING); + rdbupdate.mutable_msgcondition(1)->mutable_msgvalue()->set_strvalue(procName.toStdString()); + + rdbupdate.add_msgcondition(); + rdbupdate.mutable_msgcondition(2)->set_enlogic(enumCondAnd); + rdbupdate.mutable_msgcondition(2)->set_enrelation(enumCondEqual); + rdbupdate.mutable_msgcondition(2)->set_strcolumnname("app_id"); + rdbupdate.mutable_msgcondition(2)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgcondition(2)->mutable_msgvalue()->set_nvalue(appId); + + + rdbupdate.add_msgupdatevalue(); + rdbupdate.mutable_msgupdatevalue(0)->set_strcolumnname("is_fault"); + rdbupdate.mutable_msgupdatevalue(0)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgupdatevalue(0)->mutable_msgvalue()->set_nvalue(0); + + rdbupdate.add_msgupdatevalue(); + rdbupdate.mutable_msgupdatevalue(1)->set_strcolumnname("is_startup"); + rdbupdate.mutable_msgupdatevalue(1)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgupdatevalue(1)->mutable_msgvalue()->set_nvalue(0); + + rdbupdate.add_msgupdatevalue(); + rdbupdate.mutable_msgupdatevalue(2)->set_strcolumnname("to_quit"); + rdbupdate.mutable_msgupdatevalue(2)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgupdatevalue(2)->mutable_msgvalue()->set_nvalue(1); + + rdbupdate.add_msgupdatevalue(); + rdbupdate.mutable_msgupdatevalue(3)->set_strcolumnname("is_quit"); + rdbupdate.mutable_msgupdatevalue(3)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgupdatevalue(3)->mutable_msgvalue()->set_nvalue(1); + + rdbupdate.add_msgupdatevalue(); + rdbupdate.mutable_msgupdatevalue(4)->set_strcolumnname("is_regist"); + rdbupdate.mutable_msgupdatevalue(4)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgupdatevalue(4)->mutable_msgvalue()->set_nvalue(0); + + rdbupdate.add_msgupdatevalue(); + rdbupdate.mutable_msgupdatevalue(5)->set_strcolumnname("is_active"); + rdbupdate.mutable_msgupdatevalue(5)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgupdatevalue(5)->mutable_msgvalue()->set_nvalue(0); + + rdbupdate.add_msgupdatevalue(); + rdbupdate.mutable_msgupdatevalue(6)->set_strcolumnname("is_master"); + rdbupdate.mutable_msgupdatevalue(6)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgupdatevalue(6)->mutable_msgvalue()->set_nvalue(0); + + rdbupdate.add_msgupdatevalue(); + rdbupdate.mutable_msgupdatevalue(7)->set_strcolumnname("is_slave"); + rdbupdate.mutable_msgupdatevalue(7)->mutable_msgvalue()->set_edatatype(CN_DATATYPE_INT32); + rdbupdate.mutable_msgupdatevalue(7)->mutable_msgvalue()->set_nvalue(0); + + bool bRet = false; + bRet=netApi.update(rdbupdate); + if(bRet==false) + { + LOGERROR("forceStopProc()写表失败:%s",netApi.getErr().c_str()); + logText = QString(tr("停止进程:%1失败")).arg(QString::fromStdString(procVec[index].m_procName)); + m_pStatusMng->slotLogText(logText); + DataMng::instance()->setAllowedStatus(true); + return ; + } + + if(procVec[index].m_procId <= 0) + { + logText = QString(tr("停止进程:%1成功")).arg(QString::fromStdString(procVec[index].m_procName)); + LOGDEBUG("forceStopProc()-%s",logText.toStdString().c_str()); + m_pStatusMng->slotLogText(logText); + DataMng::instance()->setAllowedStatus(true); + return ; + } + QProcess process; + QStringList stList; +#ifdef Q_OS_WIN + stList<<"TASKKILL"<<"/PID"<slotLogText(logText); + + DataMng::instance()->setAllowedStatus(true); + break; + } + } +} + +void MainWindow::dogAndNetCheck() +{ + checkNet(); + checkDog(); + checkSysIsRun(); +} + +void MainWindow::autoStartHmi() +{ + QString strHmiErr; + bool isHmi = false; +#ifdef OS_WINDOWS + isHmi = iot_sys::isSysStartupVbsExist(); +#endif +#ifdef OS_LINUX + isHmi = iot_sys::isHmiAutoStart(strHmiErr); +#endif + if(!isHmi) + { + m_hmiAutoStartTimer->stop(); + }else + { + if(DataMng::instance()->getBaseStatus()) + { + m_hmiAutoStartTimer->stop(); + openHmi(); + } + } +} + +void MainWindow::iconActived(QSystemTrayIcon::ActivationReason reason) +{ + switch (reason) { + case QSystemTrayIcon::DoubleClick: + LOGINFO("右下角双击应用图标,开始工作!"); + startWork(); + this->show(); + this->showNormal(); + this->activateWindow(); + break; + case QSystemTrayIcon::Context: + { + if(!DataMng::instance()->getAllowedStatus()) + m_pExitAction->setEnabled(false); + else + m_pExitAction->setEnabled(true); + break; + } + default: + break; + } +} + +void MainWindow::startSystem(int res,QProcess::ExitStatus exit) +{ + Q_UNUSED(exit); + Q_UNUSED(res); + //1.检查系统是否全部退出 + if(OnTimeCheckThread::isSystemRunning()) + { + QString mess = tr("系统启动失败,请检查所有配置工具和人机界面是否已经全部退出!"); + m_pStatusMng->slotLogText(mess); + showMessDialog(mess); + return ; + } + + //2.重新加载数据、重新初始化应用树和进程树 + reloadData(); + + //3.检查模型数据是否导出 + if(DataMng::instance()->getLocalProcNum() <= 0) + { + int result = N_MessageBox::question(this,tr("错误"),tr("系统模型配置信息异常,是否打开系统建模工具检查配置并导出?") , + N_MessageBox::Yes | N_MessageBox::No, N_MessageBox::Yes); + if(result == N_MessageBox::Yes) + { + const std::string strProc = std::move( iot_public::CFileUtil::getPathOfBinFile( + std::string("model_system_config") + iot_public::CFileUtil::getProcSuffix())); + if(strProc.empty()) + { + LOGERROR("未找到可执行文件model_system_config"); + return; + } + QProcess::startDetached(strProc.c_str()); + } + return ; + } + + //4.校验ip + verifyIp(); + + //5.屏蔽其他信号 + blockSignal(true); + + //6.切换到正在启动界面 + emit changeTab(EN_SYSTEM_STARTING); + + //7.启动系统 + DataMng::instance()->setAllowedStatus(false); + m_pProcess->start(m_strSysCtrlPath); + m_startSysTimer->start(); + m_pProcess->waitForStarted(); +} + +void MainWindow::tabWidget_currentIdxChanged(int /*index*/) +{ + + if( ui->stackedWidget->currentWidget() == ui->stackedWidgetPage1) + { + disconnect(m_updateTreeTimer,&QTimer::timeout,m_pProcMng,&ProcMngForm::updateProcTree); + disconnect(m_updateTreeTimer,&QTimer::timeout,m_pAppMng,&AppMngForm::updateAppTree); + connect(m_updateTreeTimer,&QTimer::timeout , m_pLocalState , &LocalStateForm::updataLocalState); + } + else if( ui->stackedWidget->currentWidget() == ui->stackedWidgetPage2 ) + { + connect(m_updateTreeTimer,&QTimer::timeout,m_pProcMng,&ProcMngForm::updateProcTree); + disconnect(m_updateTreeTimer,&QTimer::timeout,m_pAppMng,&AppMngForm::updateAppTree); + disconnect(m_updateTreeTimer,&QTimer::timeout , m_pLocalState , &LocalStateForm::updataLocalState); + + }else if( ui->stackedWidget->currentWidget() == ui->stackedWidgetPage3 ) + { + disconnect(m_updateTreeTimer,&QTimer::timeout,m_pProcMng,&ProcMngForm::updateProcTree); + disconnect(m_updateTreeTimer,&QTimer::timeout , m_pLocalState , &LocalStateForm::updataLocalState); + connect(m_updateTreeTimer,&QTimer::timeout,m_pAppMng,&AppMngForm::updateAppTree); + } + else + { + disconnect(m_updateTreeTimer,&QTimer::timeout,m_pProcMng,&ProcMngForm::updateProcTree); + disconnect(m_updateTreeTimer,&QTimer::timeout,m_pAppMng,&AppMngForm::updateAppTree); + disconnect(m_updateTreeTimer,&QTimer::timeout , m_pLocalState , &LocalStateForm::updataLocalState); + } + +} + +void MainWindow::changeTabWidgetIndex(int index) +{ + ui->stackedWidget->setCurrentIndex(index); +} + +void MainWindow::updataButtonForm( int model ) +{ + // 获取新的按钮信息集合 + if( EN_SYS_STARTUP_PAGE3 == model) + { + QMap buttonGroupMap = DataMng::instance()->getPage3ButtonInfo(); + if(buttonGroupMap.isEmpty()) return; + QLayout *oldLayout = ui->boxWidget->layout(); + if (oldLayout) { + QLayoutItem *item; + while ((item = oldLayout->takeAt(0)) != nullptr) { + if (item->widget()) { + delete item->widget(); + } + delete item; + } + delete oldLayout; + } + + // 重新生成并添加新的按钮控件 + QVBoxLayout *page3layout = new QVBoxLayout(ui->boxWidget); + //page3layout->setSpacing(20); + QMap::iterator it = buttonGroupMap.begin(); + while (it != buttonGroupMap.end()) { + ButtonForm *page3form = new ButtonForm(EN_SYS_STARTUP_PAGE3,m_language,this); + page3form->setTitleText(it.value().m_desc); + page3form->addToolButtons(it.value().m_buttonVec , it.key()); + connect(page3form,&ButtonForm::sigLogText,m_pStatusMng,&StatusForm::slotLogText); + connect(page3form , &ButtonForm::sigUpdataButton , this , &MainWindow::updataButtonForm); + page3layout->addWidget(page3form); + it++; + } + + //page3layout->addStretch(); + ui->boxWidget->update(); + }else + { + QVector buttons = DataMng::instance()->getPage1ButtonInfo(); + if(buttons.isEmpty()) return; + QLayout *oldLayout = ui->customWidget->layout(); + if (oldLayout) { + QLayoutItem *item; + while ((item = oldLayout->takeAt(0)) != nullptr) { + if (item->widget()) { + delete item->widget(); + } + delete item; + } + delete oldLayout; + } + + ButtonForm *page1form = new ButtonForm(EN_SYS_STARTUP_PAGE1,m_language,this); + page1form->setTitleHide(true); + page1form->addToolButtons(buttons); + connect(page1form,&ButtonForm::sigLogText,m_pStatusMng,&StatusForm::slotLogText); + QGridLayout *page1layout = new QGridLayout(ui->customWidget); + page1layout->setSpacing(0); + page1layout->setContentsMargins(0,0,0,0); + page1layout->addWidget(page1form); + + ui->customWidget->update(); + } + +} + +void MainWindow::slot_closeWindow() +{ +#ifdef KBD_ARM + QApplication::exit(0); +#endif + + QMap qmap; + qmap.clear(); + qmap.insert(0 , QString(tr("缩小至托盘"))); + qmap.insert(1 , QString(tr("退出程序"))); + CheckBoxDialog dia(true , QString(tr("提示")) ,QString(tr("确认退出?")) , qmap , 0, this); + if( QDialog::Accepted == dia.exec()) + { + QList number = dia.getCheckedNumbers(); + if( number.indexOf(1) != -1 ) + { + qApp->quit(); + }else + { + this->hide(); + LOGINFO("点击应用关闭按钮,停止工作!"); + stopWork(); + } + } +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ +#ifdef KBD_ARM + QApplication::exit(0); +#endif + + event->ignore(); + this->hide(); + LOGINFO("点击应用关闭按钮,停止工作!"); + stopWork(); +} + +void MainWindow::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); +} + +void MainWindow::keyPressEvent(QKeyEvent *event) +{ + if(event->modifiers().testFlag(Qt::ControlModifier) && + event->key() == Qt::Key_B) + { + DataMng::instance()->setAllowedStatus(true); + } +} + +bool MainWindow::isProcStartSuccess(int appId, const QString &strProcName) +{ + int checkCount =0; + while(true) + { + if(checkCount > processOptOuttime) + { + return false; + } + QEventLoop eventloop; + QTimer::singleShot(1000,&eventloop,SLOT(quit())); + eventloop.exec(); + vector procVec; + float disk = 0.0; + DataMng::instance()->getRunProcInfo(procVec,disk); + for(size_t index(0);index processOptOuttime) + { + return false; + } + QEventLoop eventloop; + QTimer::singleShot(1000,&eventloop,SLOT(quit())); + eventloop.exec(); + vector procVec; + float disk = 0.0; + DataMng::instance()->getRunProcInfo(procVec,disk); + for(size_t index(0);indexblockSignals(block); + m_checkObj->blockSignals(block); + m_pAppMng->blockAppSignals(block); + m_pProcMng->blockAppSignals(block); + m_pLocalState->blockSignals(block); +} + +bool MainWindow::checkNet() +{ + QNetworkConfigurationManager manager; + + #ifdef OS_LINUX + QList activeConfigs = manager.allConfigurations(QNetworkConfiguration::Active); + bool hasNonLocal = false; + for (int i = 0; i < activeConfigs.size(); i++) + { + + if (!activeConfigs[i].identifier().contains("/org/freedesktop/NetworkManager/Settings/")) + { + hasNonLocal = true; + } + } +#endif + if(manager.isOnline() + #ifdef OS_LINUX + && hasNonLocal + #endif + ) + { + m_pStatusMng->netIsOnline(); + return true; + } + else + { + m_pStatusMng->netIsNotOnline(); + return false; + } +} + +void MainWindow::checkDog() +{ + if(!m_ptrDogAuthApi) + { + LOGERROR("创建加密狗实例失败"); + m_pStatusMng->dogUncheck(); + m_pSysSetMng->setAuthorityLabelText(0); + return ; + } + if(iotSuccess != m_ptrDogAuthApi->checkAuthStatus()) + { + m_pStatusMng->dogIsNotHave(); + m_pSysSetMng->setAuthorityLabelText(1); + if(m_bLastDogStatus == true) + { + m_bLastDogStatus = false; + N_MessageBox::information(this , tr("提示") , tr("加密狗退出") , N_MessageBox::Yes); + } + } + else + { + m_bLastDogStatus = true; + m_pStatusMng->dogIsHave(); + m_pSysSetMng->setAuthorityLabelText(2); + } +} + +void MainWindow::checkSysIsRun() +{ + if( DataMng::instance()->getSysStatus() ) + m_pStatusMng->sysIsRun(); + else + m_pStatusMng->sysIsNotRun(); +} + +void MainWindow::verifyIp() +{ + updateVerifyIp(checkNet() == true ? IP_VERIFY:IP_NOT_VERIFY); +} + +void MainWindow::updateVerifyIp(int verifyValue) +{ + return;//暂时不写sys_ctrl文件,一直写这个文件会存在问题, 在linux系统下,突然断电会经常导致此文件损坏 + QString path = iot_public::CFileUtil::getPathOfCfgFile("sys_ctrl.xml",CN_DIR_PLATFORM).c_str(); + QFile file(path); + if(!file.open(QFile::ReadOnly)) + { + file.close(); + LOGERROR("updateVerifyIp(): 文件打开失败,路径:[%s]",path.toStdString().c_str()); + return ; + } + QDomDocument doc; + if(!doc.setContent(&file)) + { + file.close(); + LOGERROR("updateVerifyIp(): 文件读取失败,路径:[%s]",path.toStdString().c_str()); + return ; + } + file.close(); + QDomElement root=doc.documentElement(); + if(root.tagName()!="root") + { + LOGERROR("updateVerifyIp(): 文件内容错误,不包含[root],路径:[%s]",path.toStdString().c_str()); + return ; + } + QDomNode module=root.firstChild(); + QDomElement element=module.toElement(); + if(!element.isNull()) + { + if(element.nodeName()=="module") + { + QDomNodeList list=element.childNodes(); + for(int i=0;i +#include +#include +#include +#include +#include +#include + +#include "BrushDataThread.h" +#include "rdb_net_api/CRdbNetApi.h" +#include "net_msg_bus_api/MsgBusApi.h" +#include "OnTimeCheckThread.h" +#include "pub_utility_api/ProcUtil.h" +#include "sys_dog_auth_api/DogAuthInterface.h" +#include "pub_widget/MessageBox.h" + +#include "pub_widget/CustomMainWindow.h" +#include "pub_widget/MenuFrame.h" +#include "pub_widget/WorkFrame.h" + +class QLocalServer; +class StartUpForm; +class AppMngForm; +class ProcMngForm; +class StatusForm; +class SystemSetForm; +class LocalStateForm; + + +const int kMouseRegionLeft = 5; +const int kMouseRegionTop = 5; +const int kMouseRegionButtom = 5; +const int kMouseRegionRight = 5; + + +enum MousePosition +{ + kMouseDrag = 0, // 可拖拽 + kMousePositionLeftTop = 11, + kMousePositionTop = 12, + kMousePositionRightTop = 13, + kMousePositionLeft = 21, + kMousePositionMid = 22, + kMousePositionRight = 23, + kMousePositionLeftButtom = 31, + kMousePositionButtom = 32, + kMousePositionRightButtom = 33, +}; + + +namespace Ui { +class MainWindow; +} + +class MainWindow : public CustomUiMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QString language,QWidget *parent = 0); + ~MainWindow(); + +public: + //main中调用 + bool isRunning(); + + void initLocalConnection(); + void newLocalServer(); + + void startWork(); + void stopWork(); + + void startAutoStartHmiTimer(); + +private: + void initSheet(); + void initVariables(); + + void initUi(); + void initConn(); + + void initLog(); + void initMsgBus(); + + void startThread(); + + void showMessDialog(const QString &mess); + + void reloadAppTree(); + + void reloadProcTree(); + + void reloadLocalState(); //重载本机应用状态 + + +signals: + void sigLogText(const QString &logText); + + void changeTab(int index); + + void sigStartValue(int value); + + void sigStopValue(int value); + + void sigNetIsNotOnline(); + + void sigNetIsOnline(); + +public slots: + + void slotStartSystem(); + + void slotStopSystem(); + + void outPut(); + + void finish(int res,QProcess::ExitStatus exit); + + void startPercent(); + void stopPercent(); + + void reloadData(); + + void startApp(const QString appName); + void stopApp(const QString appName); + void restartApp(const QString appName); + + void ifStartApp(); + + void startProc(int appId,const QString procName); + bool stopProc(int appId,const QString procName); + void reStartProc(int appId,const QString procName); + void forceStopProc(int appId,const QString procName); + + void dogAndNetCheck(); + + void autoStartHmi(); + + void iconActived(QSystemTrayIcon::ActivationReason reason); + + void startSystem(int res = E_PROCESS_SUCCEED,QProcess::ExitStatus exit = QProcess::NormalExit); + + void tabWidget_currentIdxChanged(int index); + + void changeTabWidgetIndex( int index ); + + void updataButtonForm(int model); //更新按钮栏按钮 + + void slot_closeWindow(); + +protected: + virtual void closeEvent(QCloseEvent *event); + virtual void changeEvent(QEvent* e); + virtual void keyPressEvent(QKeyEvent *event); + + + +private: + bool isProcStartSuccess(int appId ,const QString& strProcName); + bool isProcStopSuccess(int appId ,const QString& strProcName); + + void blockSignal(bool block); + + bool checkNet(); + + void checkDog(); + + void checkSysIsRun(); //< 检测系统状态 + + void verifyIp(); + + void updateVerifyIp(int verifyValue); + + void openHmi(); + +private: + Ui::MainWindow *ui; + + //本工具相关 + bool m_bRunning; //< 本工具在此操作系统只允许同时存在一个 + QLocalServer *m_pLocalServer; //< 监听此操作系统此工具的服务 + + //系统相关 + QString m_language; //< 国际化 zh-中文 en-英文 fr-法文 + + //界面视图 + //titleBarForm *m_pTitleBar; //< 标题栏 + StartUpForm *m_pStartUp; //< 进度条 启停视图 + AppMngForm *m_pAppMng; //< 应用树视图 + ProcMngForm *m_pProcMng; //< 进程树视图 + StatusForm *m_pStatusMng; //< 状态栏视图 + SystemSetForm *m_pSysSetMng; //< 版本视图 + QSystemTrayIcon *m_pSysTrayIcon; //< 托盘图标 + MenuFrame* m_pMenuSide; //< 侧边菜单栏 + LocalStateForm *m_pLocalState; //< 本机状态视图 + + //定时器 + QTimer *m_updateTreeTimer; //< 刷新应用和进程定时器 + QTimer *m_updateSysTimer; //< 刷新系统状态定时器 + QTimer *m_startSysTimer; //< 系统启动定时器 + QTimer *m_stopSysTimer; //< 系统启动定时器 + QTimer *m_appRestartTimer; //< 应用重启定时器 + QTimer *m_dogAndLocalNetTimer; //< 狗和本地网络检测定时器 + QTimer *m_hmiAutoStartTimer; //< hmi自启动定时器 + + //其他相关 + BrushDataThreadPtr m_brushDataThread; //< 获取表内容线程 + OnTimeCheckThread *m_checkObj; //< 定时检测系统是否正在运行对象 + QThread *m_checkThread; //< 定时检测系统是否正在运行线程 + QProcess *m_pProcess; //< 用来启停系统 + QString m_strSysCtrlPath; //< sys_ctrl的全路径 + int m_nStartStopResult; //< 启停返回结果 + QProcess *m_pStopProcess=nullptr; //< 用来启停系统 + + //加密狗相关 + iot_sys::CDogAuthInterfacePtr m_ptrDogAuthApi; //< 加密狗接口 + bool m_bLastDogStatus; //< 上一次狗状态 + + // 托盘图标右键菜单 + QAction* m_pShowAction; + QAction* m_pExitAction; + +}; + +#endif // MAINWINDOW_H diff --git a/product/src/tools/workBench/ModifyButtonForm.cpp b/product/src/tools/workBench/ModifyButtonForm.cpp new file mode 100644 index 00000000..64cd3499 --- /dev/null +++ b/product/src/tools/workBench/ModifyButtonForm.cpp @@ -0,0 +1,214 @@ +#include "ModifyButtonForm.h" +#include "ui_ModifyButtonForm.h" + +#include "DataMng.h" + +using namespace workBench; + +ModifyButtonForm::ModifyButtonForm(QString language ,QWidget *parent) : + CustomUiDialog(parent), + m_language(language), + ui(new Ui::ModifyButtonForm) +{ + ui->setupUi(this); + CustomUiDialog::setAutoLayout(true); + setWindowTitle(tr("编辑快捷键")); + groupMap.clear(); + listButton.clear(); + QVector resButton; + resButton.clear(); + groupMap = DataMng::instance()->getPage3ButtonInfo(); + resButton = DataMng::instance()->getPage1ButtonInfo(); + listButton = filterMap(resButton , groupMap); + initTree(ui->treeWidget , groupMap); + initList(ui->listWidget ,listButton); + + initConn(); + +} + +ModifyButtonForm::~ModifyButtonForm() +{ + delete ui; +} + +void ModifyButtonForm::initTree(QTreeWidget *treeWidget, const QMap &map) +{ + if( NULL == treeWidget || map.isEmpty()) return; + treeWidget->setColumnCount(1); + treeWidget->setHeaderHidden(true); + treeWidget->setSelectionMode(QAbstractItemView::NoSelection); + for (const auto& key : map.keys()) + { + SButtonGroup group = map.value(key); + QTreeWidgetItem* rootItem = new QTreeWidgetItem(treeWidget); + rootItem->setText(0 , group.m_desc); + rootItem->setData(0 , Qt::UserRole + 2 , key); + rootItem->setFlags(rootItem->flags() | Qt::ItemIsUserCheckable); + rootItem->setCheckState(0, Qt::Unchecked); + + const QVector& children = group.m_buttonVec; + for (const QString& child : children) { + SButtonInfo buttonInfo ; + if(DataMng::instance()->getButtonInfoByName(child,buttonInfo) != true) + { + continue; + } + QTreeWidgetItem* childItem = new QTreeWidgetItem(rootItem); + childItem->setText(0, buttonInfo.m_desc); + childItem->setData(0 , Qt::UserRole + 1 , child); + childItem->setData(0 , Qt::UserRole + 2 , key); + childItem->setFlags(childItem->flags() | Qt::ItemIsUserCheckable); + childItem->setCheckState(0, Qt::Unchecked); + } + + } + + +} + +void ModifyButtonForm::initList(QListWidget *listWidget, const QMap &dataVect) +{ + if( NULL == listWidget || dataVect.isEmpty()) return; + QMap::const_iterator itor ; + for (itor = dataVect.begin() ; itor != dataVect.end() ; itor ++) + { + SButtonInfo buttonInfo ; + if(DataMng::instance()->getButtonInfoByName(itor.key(),buttonInfo) != true) + { + continue; + } + + QString name = ""; + name = buttonInfo.m_desc; + QListWidgetItem *listItem = new QListWidgetItem(name); + listItem->setCheckState(Qt::Unchecked); + listItem->setData(Qt::UserRole + 1 , itor.value() ); + listItem->setData(Qt::UserRole + 2 , itor.key() ); + listWidget->addItem(listItem); + } +} + +void ModifyButtonForm::initConn() +{ + connect(ui->treeWidget , &QTreeWidget::itemChanged , [=](QTreeWidgetItem *item, int column){ + if (column != 0) return; + + if (item->parent() == nullptr) + { + Qt::CheckState state = item->checkState(0); + for (int i = 0; i < item->childCount(); ++i) { + item->child(i)->setCheckState(0, state); + } + } else + { + QTreeWidgetItem *parent = item->parent(); + bool allChecked = true; + bool noneChecked = true; + + for (int i = 0; i < parent->childCount(); ++i) { + Qt::CheckState state = parent->child(i)->checkState(0); + if (state == Qt::Unchecked) { + allChecked = false; + } else if (state == Qt::Checked) { + noneChecked = false; + } + } + + if (allChecked) { + parent->setCheckState(0, Qt::Checked); + } else if (noneChecked) { + parent->setCheckState(0, Qt::Unchecked); + } + } + }); + + connect(ui->btn_Save , &QToolButton::clicked , this , &ModifyButtonForm::slotBtnSaveClicked); + connect(ui->btn_Delete , &QToolButton::clicked , this , &ModifyButtonForm::slotBtnDeleteClicked); + connect(ui->btn_confirm , &QToolButton::clicked , this , &ModifyButtonForm::slotBtnConfirmClicked); + +} + +void ModifyButtonForm::slotBtnSaveClicked() +{ + for (int i = 0; i < ui->treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *rootItem = ui->treeWidget->topLevelItem(i); + for (int j = 0; j < rootItem->childCount(); ++j) { + QTreeWidgetItem *childItem = rootItem->child(j); + if (childItem->checkState(0) == Qt::Checked) { + QListWidgetItem *newItem = new QListWidgetItem(childItem->text(0)); + newItem->setData(Qt::UserRole +1 , childItem->data(0 ,Qt::UserRole + 2)); + newItem->setData(Qt::UserRole +2 , childItem->data(0 ,Qt::UserRole + 1)); + newItem->setCheckState(Qt::Unchecked); + ui->listWidget->addItem(newItem); + listButton[childItem->data(0 ,Qt::UserRole + 1).toString()] = childItem->data(0 ,Qt::UserRole + 2).toInt(); + delete rootItem->takeChild(j); + --j; + } + } + } +} + +void ModifyButtonForm::slotBtnDeleteClicked() +{ + for (int i = 0; i < ui->listWidget->count(); ++i) { + QListWidgetItem *listItem = ui->listWidget->item(i); + if (listItem->checkState() == Qt::Checked) { + int index = listItem->data(Qt::UserRole + 1).toInt(); + QString dataName = listItem->data(Qt::UserRole + 2).toString(); + QString itemName = listItem->text(); + + if( groupMap.contains(index)) + { + QString rootName = ""; + rootName = groupMap.value(index).m_desc; + + for(int j = 0;j< ui->treeWidget->topLevelItemCount() ; j++) + { + QTreeWidgetItem *rootItem = ui->treeWidget->topLevelItem(j); + if (rootItem->text(0) == rootName ) { + QTreeWidgetItem *childItem = new QTreeWidgetItem(rootItem); + childItem->setText(0, itemName); + childItem->setData(0 , Qt::UserRole + 1 , index); + childItem->setData(0 , Qt::UserRole + 2 , dataName); + childItem->setCheckState(0, Qt::Unchecked); + break; + } + } + } + + listButton.remove(dataName); + delete ui->listWidget->takeItem(i); + --i; + } + } +} + +void ModifyButtonForm::slotBtnConfirmClicked() +{ + DataMng::instance()->addPage1ButtonInfo(listButton.keys()); + accept(); +} + +QMap ModifyButtonForm::filterMap(const QVector &dataVect, QMap &map) +{ + QMap res; + res.clear(); + if( dataVect.isEmpty() || map.isEmpty()) return res; + foreach (QString var, dataVect) + { + QMap::iterator itr = map.begin(); + for(; itr != map.end() ; itr ++) + { + int index = -1; + if( ( index = itr.value().m_buttonVec.indexOf(var)) >= 0 ) + { + res[var] = itr.key(); + itr.value().m_buttonVec.removeAt(index); + break; + } + } + } + + return res; +} diff --git a/product/src/tools/workBench/ModifyButtonForm.h b/product/src/tools/workBench/ModifyButtonForm.h new file mode 100644 index 00000000..80c63c2f --- /dev/null +++ b/product/src/tools/workBench/ModifyButtonForm.h @@ -0,0 +1,49 @@ +#ifndef MODIFYBUTTONFORM_H +#define MODIFYBUTTONFORM_H + +#include +#include +#include +#include +#include + +#include "MonitorCommon.h" +#include "pub_widget/CustomDialog.h" + +namespace Ui { +class ModifyButtonForm; +} + +class ModifyButtonForm : public CustomUiDialog +{ + Q_OBJECT + +public: + explicit ModifyButtonForm(QString language ,QWidget *parent = 0); + ~ModifyButtonForm(); + + void initTree(QTreeWidget *treeWidget,const QMap &map); + + void initList(QListWidget *listWidget ,const QMap &dataVect); + + void initConn(); + +public slots: + void slotBtnSaveClicked(); + void slotBtnDeleteClicked(); + void slotBtnConfirmClicked(); + +private: + QMap filterMap(const QVector &dataVect , QMap &map); + +private: + Ui::ModifyButtonForm *ui; + + QMap groupMap; + + QMap listButton; + + QString m_language; +}; + +#endif // MODIFYBUTTONFORM_H diff --git a/product/src/tools/workBench/ModifyButtonForm.ui b/product/src/tools/workBench/ModifyButtonForm.ui new file mode 100644 index 00000000..8dda1db5 --- /dev/null +++ b/product/src/tools/workBench/ModifyButtonForm.ui @@ -0,0 +1,141 @@ + + + ModifyButtonForm + + + + 0 + 0 + 647 + 512 + + + + Form + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 1 + + + + + + + + + + + 0 + 0 + + + + + 60 + 30 + + + + + + + + + + + + 0 + 0 + + + + + 60 + 30 + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 30 + + + + 确认 + + + + + + + + + + diff --git a/product/src/tools/workBench/MonitorCommon.h b/product/src/tools/workBench/MonitorCommon.h new file mode 100644 index 00000000..c99c9784 --- /dev/null +++ b/product/src/tools/workBench/MonitorCommon.h @@ -0,0 +1,204 @@ +#ifndef MONITORCOMMON_H +#define MONITORCOMMON_H + +#include "pub_logger_api/logger.h" +#include "common/Common.h" + +#include +#include + +#ifdef OS_LINUX +#include +#endif + +namespace workBench { + +#define STARTUP_SERVER_NAME "workBench" +#define PROCESS_RDB_SERVER "rdb_server" + +//系统运行信息定义 +const std::string CN_TN_SysRunRedundancyInfo = "sys_run_redundancy_info"; +//const std::string CN_TN_SysRunAppInfo = "sys_run_app_info"; +const std::string CN_TN_SysRunProcInfo = "sys_run_proc_info"; +//const std::string CN_ProcName_ProcMng = "sys_startup"; + +//版本信息定义 +const std::string VERSIONXMLNAME = "setup_config.xml"; +const std::string MODULENAME = "setup_config"; +const std::string SOFTWARE_NAME = "software_name"; +const std::string SOFTWARE_VERSION = "software_version"; +const std::string SOFTWARE_ISMAIN = "isMain"; +const std::string SOFTWARE_ISDB = "isDb"; +const std::string SOFTWARE_ISWEB = "isWeb"; + +//语言信息定义 +const std::string LANGUAGEXMLNAME = "language.xml"; + +#ifdef OS_WINDOWS +const std::string SOFTWARE_MAINPATH = "MainPath"; +const std::string SOFTWARE_DBPATH = "DbPath"; +#endif +#ifdef OS_LINUX +const std::string SOFTWARE_MAINPATH = "MainPathLinux"; +//const std::string CN_SOFTWARE_DBPATH = "/var/lib/mysql"; +#endif + +//ip校验 +const int IP_VERIFY = 1; +const int IP_NOT_VERIFY = 0; +// 进程启停超时时间 +const int processOptOuttime = 90; + +enum E_PROCESS_RESULT +{ + E_PROCESS_SUCCEED =0, + E_PROCESS_FAILD = 1, + E_PROCESS_DEFAULT = 2 +}; + +enum EN_SYSTEM_STATUS +{ + EN_SYSTEM_NOT_START = 0, //<已停止 + EN_SYSTEM_STARTING, //<正在启动 + EN_SYSTEM_RUNNING, //<正在运行 + EN_SYSTEM_STOPPING, //<正在停止 + EN_SYSTEM_UNKNOW //<未知 +}; + +//< 区分BoxForm +enum EN_SYS_STARTUP_PAGE +{ + EN_SYS_STARTUP_PAGE1 = 1, //<第一个Tab + EN_SYS_STARTUP_PAGE3 = 3 //<第三个Tab +}; + +enum EN_TREE_NODE_TYPE +{ + EN_TREE_NODE_IS_NODE = 0, + EN_TREE_NODE_IS_APP = 1, + EN_TREE_NODE_IS_PROC = 2 +}; + +enum EN_APP_STATUS +{ + EN_APP_STOP = 0, //<已停止 + EN_APP_RUNNING, //<正在运行 + EN_APP_UNKNOW, //<未知 + EN_APP_HALF //<半运行 +}; + +enum EN_PROC_STATUS +{ + EN_PROC_STOP = 0, //<已停止 + EN_PROC_RUNNING, //<正在运行 + EN_PROC_UNKNOW //<未知 +}; + +struct SButtonInfo +{ + QString m_name; + QString m_desc; + QString m_cmd; + QString m_param; + QString m_icon; + SButtonInfo() { + m_name = QString(); + m_desc = QString(); + m_cmd = QString(); + m_param = QString(); + m_icon = QString(); + } +}; +struct SButtonGroup +{ + int m_groupId; + QString m_desc; + QVector m_buttonVec; + SButtonGroup(){ + m_groupId = -1; + m_desc = QString(); + m_buttonVec.clear(); + } +}; +struct SCpuAndDisk +{ + float m_cpu; + float m_disk; + SCpuAndDisk() + { + m_cpu = 0.0; + m_disk = 0.0; + } +}; + +struct SApp +{ + std::string m_nodeName; + int m_appId; + std::string m_appName; + std::string m_desc; + int m_isActive ; + int m_isMaster ; + int m_isSlave ; + int m_hasMaster; + SApp() + { + m_nodeName = ""; + m_appId =0; + m_appName = ""; + m_desc = ""; + m_isActive = 0; + m_isMaster = 0; + m_isSlave = 0; + m_hasMaster = 0; + } +}; + +struct SSysModelAppInfo +{ + int m_appId; + std::string m_tagName; + std::string m_desc; + SSysModelAppInfo(){ + m_appId = -1; + m_tagName = ""; + m_desc = ""; + } +}; +struct SProcess +{ + std::string m_nodeName; + std::string m_procDesc; + std::string m_procName; + std::string m_procParam; + long long m_procId; + int m_appId; + std::string m_appDesc; + int m_isStartUp; + int m_toQuit; + int m_isQuit; + float m_cpu; + int m_procNum; + float m_disk; + int m_isMaster ; + int m_isSlave ; + SProcess() + { + m_nodeName = ""; + m_procDesc = ""; + m_procName = ""; + m_procId = -1; + m_appId = -1; + m_appDesc = ""; + m_isStartUp = 0; + m_toQuit = 0; + m_isQuit = 0; + m_cpu = 0.0; + m_procNum = -1; + m_disk = 0.0; + m_isMaster = 0; + m_isSlave = 0; + } +}; +} +#endif // MONITORCOMMON_H diff --git a/product/src/tools/workBench/MyProgressBar.cpp b/product/src/tools/workBench/MyProgressBar.cpp new file mode 100644 index 00000000..c9cff7f4 --- /dev/null +++ b/product/src/tools/workBench/MyProgressBar.cpp @@ -0,0 +1,134 @@ +#include +#include "MyProgressBar.h" + +MyProgressBar::MyProgressBar(QWidget *parent) : QProgressBar(parent) +{ + m_font.setFamily("Microsoft YaHei"); + this->resize(220,220); + this->startTimer(80); + +} + +void MyProgressBar::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; + int height = this->height(); + int width = this->width(); + int side = qMin(width, height); + + //计算当前值所占百分比 + double percent = 1 - (double)(m_value - m_minValue) / (m_maxValue - m_minValue); + + //正弦曲线公式 y = A * sin(ωx + φ) + k + //w表示周期,可以理解为水波的密度,值越大密度越大(浪越密集 ^_^),取值 密度*M_PI/宽度 + double w = m_waterDensity * M_PI / width; + //A表示振幅,可以理解为水波的高度,值越大高度越高(越浪 ^_^),取值高度的百分比 + double A = height * m_waterHeight; + //k表示y轴偏移,可以理解为进度,取值高度的进度百分比 + double k = height * percent; + + //第一条波浪路径集合 + QPainterPath waterPath1; + //第二条波浪路径集合 + QPainterPath waterPath2; + + //移动到左上角起始点 + waterPath1.moveTo(0, height); + waterPath2.moveTo(0, height); + + m_offset += 0.6; + if (m_offset > (width / 2)) { + m_offset = 0; + } + + for(int x = 0; x <= width; x++) { + //第一条波浪Y轴 + double waterY1 = (double)(A * sin(w * x + m_offset)) + k; + + //第二条波浪Y轴 + double waterY2 = (double)(A * sin(w * x + m_offset + (width / 2 * w))) + k; + + //如果当前值为最小值则Y轴为高度 + if (m_value == m_minValue) { + waterY1 = height; + waterY2 = height; + } + + //如果当前值为最大值则Y轴为0 + if (m_value == m_maxValue) { + waterY1 = 0; + waterY2 = 0; + } + + waterPath1.lineTo(x, waterY1); + waterPath2.lineTo(x, waterY2); + } + + //移动到右下角结束点,整体形成一个闭合路径 + waterPath1.lineTo(width, height); + waterPath2.lineTo(width, height); + + //大路径 + QPainterPath bigPath; + if (m_percentStyle == PercentStyle_Rect) { + width = width - m_borderWidth * 2; + height = height - m_borderWidth * 2; + bigPath.addRect(m_borderWidth, m_borderWidth, width, height); + painter.setBrush(m_boderColor); + painter.drawRect(this->rect()); + painter.setBrush(m_bgColor); + painter.drawRect(m_borderWidth, m_borderWidth, width, height); + } else if (m_percentStyle == PercentStyle_Circle) { + painter.setPen(Qt::NoPen); + painter.setBrush(m_boderColor); + painter.drawEllipse((width - side) / 2, (height - side) / 2, side, height); + side = side - m_borderWidth * 2; + bigPath.addEllipse((width - side) / 2, m_borderWidth, side, side); + painter.setBrush(m_bgColor); + painter.drawEllipse((width - side) / 2, m_borderWidth, side, side); + } else if (m_percentStyle == PercentStyle_Ellipse) { + width = width - m_borderWidth * 2; + height = height - m_borderWidth * 2; + bigPath.addEllipse(m_borderWidth, m_borderWidth, width, height); + painter.setBrush(m_boderColor); + painter.drawEllipse(this->rect()); + painter.setBrush(m_bgColor); + painter.drawEllipse(m_borderWidth, m_borderWidth, width, height); + } + + painter.save(); + + //新路径,用大路径减去波浪区域的路径,形成遮罩效果 + QPainterPath path; + painter.setPen(Qt::NoPen); + QColor waterColor1 = m_usedColor; + waterColor1.setAlpha(100); + QColor waterColor2 = m_usedColor; + waterColor2.setAlpha(180); + + //第一条波浪挖去后的路径 + path = bigPath.intersected(waterPath1); + painter.setBrush(waterColor1); + painter.drawPath(path); + + //第二条波浪挖去后的路径 + path = bigPath.intersected(waterPath2); + painter.setBrush(waterColor2); + painter.drawPath(path); + + painter.restore(); + + //绘制文字 + m_font.setPixelSize(this->width()/8); + painter.setPen(m_textColor); + painter.setFont(m_font); + painter.drawText(this->rect(), Qt::AlignBottom | Qt::AlignHCenter, QString("%1%").arg(QString::number(m_value))); +} + +void MyProgressBar::timerEvent(QTimerEvent *event) +{ + Q_UNUSED(event); + this->update(); +} diff --git a/product/src/tools/workBench/MyProgressBar.h b/product/src/tools/workBench/MyProgressBar.h new file mode 100644 index 00000000..4612e11a --- /dev/null +++ b/product/src/tools/workBench/MyProgressBar.h @@ -0,0 +1,71 @@ +#ifndef MYPROGRESSBAR_H +#define MYPROGRESSBAR_H + +#include +#include +#include +#include +#include +#include +class MyProgressBar : public QProgressBar +{ + Q_OBJECT +public: + explicit MyProgressBar(QWidget *parent = nullptr); + enum PercentStyle_Type{ + PercentStyle_Rect = 0,//矩形 + PercentStyle_Circle,//圆 + PercentStyle_Ellipse,//椭圆 + }; + + void setValue(int value) {m_value = value;} + int value() {return m_value;} + + void setMaxValue(int value) {m_maxValue = value;} + int maxValue() {return m_maxValue;} + + void setMinValue(int value) {m_minValue = value;} + int minValue() {return m_minValue;} + + void setPercentStyle(MyProgressBar::PercentStyle_Type type) {m_percentStyle = type;} + PercentStyle_Type percentStyle() {return m_percentStyle;} + + void setWaterDensity(int val) {m_waterDensity = val;} + int waterDensity() {return m_waterDensity;} + + void setColor(QColor col) {m_usedColor = col;} + QColor color() {return m_usedColor;} + + void setWaterHeight(double val) {m_waterHeight = val;} + double waterHeight() {return m_waterHeight;} + + void setBorderWidth(int val) {m_borderWidth = val;} + int borderWidth() {return m_borderWidth;} + + void setTextColor(QColor col) {m_textColor = col;} + QColor textColor() {return m_textColor;} + + void setBoderColor(QColor col) {m_boderColor = col;} + QColor boderColor() {return m_boderColor;} + + void setBgColor(QColor col) {m_bgColor = col;} + QColor bgColor() {return m_bgColor;} +protected: + void paintEvent(QPaintEvent *event); + void timerEvent(QTimerEvent *event); +private: + PercentStyle_Type m_percentStyle = PercentStyle_Rect; + QColor m_usedColor = QColor(180,255,255); + QColor m_textColor = Qt::white; + QColor m_boderColor = Qt::black; + QColor m_bgColor = Qt::gray; + QFont m_font; + int m_value = 100; + int m_minValue = 0; + int m_maxValue = 100; + int m_waterDensity = 2; // 水波的密度 + double m_waterHeight = 0.02; + double m_offset = 50; + int m_borderWidth = 10; +}; +#endif // MYPROGRESSBAR_H diff --git a/product/src/tools/workBench/OnTimeCheckThread.cpp b/product/src/tools/workBench/OnTimeCheckThread.cpp new file mode 100644 index 00000000..5adc10a5 --- /dev/null +++ b/product/src/tools/workBench/OnTimeCheckThread.cpp @@ -0,0 +1,38 @@ + +#include "rdb_api/CRdbMngInterface.h" +#include "MonitorCommon.h" +#include "DataMng.h" +#include "OnTimeCheckThread.h" + +OnTimeCheckThread::OnTimeCheckThread(QObject *parent): + QObject(parent) +{ + +} + +OnTimeCheckThread::~OnTimeCheckThread() +{ + +} + +bool OnTimeCheckThread::isSystemRunning() +{ + iot_dbms::CRdbMngIntereface objRunProcInfoTable; + if (objRunProcInfoTable.isLoadAppDb()) + return true; + + return false; +} + +void OnTimeCheckThread::brush() +{ + if(isSystemRunning()) + { + DataMng::instance()->setSysStatus(true); + emit changeTab(workBench::EN_SYSTEM_RUNNING); + }else + { + DataMng::instance()->setSysStatus(false); + emit changeTab(workBench::EN_SYSTEM_NOT_START); + } +} diff --git a/product/src/tools/workBench/OnTimeCheckThread.h b/product/src/tools/workBench/OnTimeCheckThread.h new file mode 100644 index 00000000..f709ac26 --- /dev/null +++ b/product/src/tools/workBench/OnTimeCheckThread.h @@ -0,0 +1,21 @@ +#ifndef ONTIMECHECKTHREAD_H +#define ONTIMECHECKTHREAD_H + +#include + +class OnTimeCheckThread :public QObject +{ + Q_OBJECT +public: + OnTimeCheckThread(QObject *parent); + ~OnTimeCheckThread(); + + static bool isSystemRunning(); + +public slots: + void brush(); +signals: + void changeTab(int index); +}; + +#endif // ONTIMECHECKTHREAD_H diff --git a/product/src/tools/workBench/ProcMngForm.cpp b/product/src/tools/workBench/ProcMngForm.cpp new file mode 100644 index 00000000..db445a8c --- /dev/null +++ b/product/src/tools/workBench/ProcMngForm.cpp @@ -0,0 +1,572 @@ +#include "ProcMngForm.h" +#include "ui_ProcMngForm.h" +#include "DataMng.h" +//#include "pub_utility_api/ProcUtil.h" +#include "../include/sys/sys_login_api/CLoginDlg.h" +#include "pub_utility_api/TimeUtil.h" + +#include +#include +#include +#include + +using namespace iot_public; + +ProcMngForm::ProcMngForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::ProcMngForm) +{ + ui->setupUi(this); + m_ntime = (uint64)iot_public::getUTCTimeSec(); + + m_allCheckBox = new QCheckBox(tr("全部") , this); + m_btnGroup = new QButtonGroup(this); + m_btnGroup->setExclusive(false); + + QHBoxLayout *hLayout = new QHBoxLayout(ui->select_widget); + hLayout->addWidget(m_allCheckBox); + ui->select_widget->setLayout(hLayout); + + ui->procTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); + initProcTree(); + connect(ui->procTreeWidget,&QTreeWidget::customContextMenuRequested,this,&ProcMngForm::customContext); + connect(ui->procTreeWidget,&QTreeWidget::itemClicked,this,&ProcMngForm::procItemClicked); + connect(m_allCheckBox , &QCheckBox::stateChanged , this , &ProcMngForm::allCheckBoxStateChange); + //m_allCheckBox->setCheckState(Qt::Checked); + +} + +ProcMngForm::~ProcMngForm() +{ + if( m_btnGroup ) + { + delete m_btnGroup; + } + m_btnGroup = Q_NULLPTR; + + if( m_allCheckBox ) + { + delete m_allCheckBox; + } + m_allCheckBox = Q_NULLPTR; + + delete ui; +} + +void ProcMngForm::updateProcTree() +{ + QSet setCheck; + setCheck.clear(); + setCheck = retAllCheckBoxName(); + upDataProcTreeByDesc(setCheck); +} + +void ProcMngForm::customContext(const QPoint &pos) +{ + QModelIndex index = ui->procTreeWidget->indexAt(pos); + + if(!index.isValid()) + { + ui->procTreeWidget->clearSelection(); + if(!DataMng::instance()->getSysStatus()) + { + QMenu menu(this); + QAction * selectAction = menu.addAction(tr("刷新")); + connect(selectAction, &QAction::triggered, [=](){ + emit sigReloadAppAndProc(); + }); + menu.exec(QCursor::pos()); + } + + return ; + } + //右键进程 + QTreeWidgetItem *item=ui->procTreeWidget->currentItem(); + //空指针判断 + if (!item) + { + return; + } + //判断是否右键进程 + if(item->data(0,Qt::UserRole+5).toInt() == EN_TREE_NODE_IS_PROC) + { + //判断是否右键基础应用进程 + if(item->data(2,Qt::UserRole).toInt() == CN_AppId_BASE) + { + return ; + } + //判断是否rdb_server + if(item->text(1).toStdString() == PROCESS_RDB_SERVER) + { + return ; + } + //判断当前是否可以右键操作(防止并行操作) + if(!DataMng::instance()->getAllowedStatus()) + { + return ; + } + QMenu menu(this); + QAction * procStart = menu.addAction(tr("启动")); + QAction * procStop = menu.addAction(tr("停止")); + QAction * procRestart = menu.addAction(tr("重启")); + QAction * procUp = menu.addAction(tr("升主")); + QAction * procDown = menu.addAction(tr("降备")); + QAction * procForceStop = menu.addAction(tr("强制停止")); + + int curAppId = item->data(2,Qt::UserRole).toInt(); + + connect(procStart, &QAction::triggered, [=](){ + emit sigStartProc(curAppId,item->text(1)); + }); + connect(procStop, &QAction::triggered, [=](){ + CLoginDlg dlg(this); + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigStopProc(curAppId,item->text(1)); + } + }); + connect(procRestart, &QAction::triggered, [=](){ + CLoginDlg dlg(this); + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigRestartProc(curAppId,item->text(1)); + } + }); + connect(procForceStop, &QAction::triggered, [=](){ + CLoginDlg dlg(this); + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigForceStopProc(curAppId,item->text(1)); + } + }); + if(DataMng::instance()->getBaseStatus()) //基础应用处于启动状态 + { + //获取本进程状态 + if(item->data(3,Qt::UserRole).toInt() == EN_PROC_RUNNING) + { + procStart->setEnabled(false); + procStop->setEnabled(true); + procRestart->setEnabled(true); + procForceStop->setEnabled(true); + }else if(item->data(3,Qt::UserRole).toInt() == EN_PROC_STOP) + { + if(getCurAppRdbStatus(curAppId) == EN_PROC_RUNNING) + { + procStart->setEnabled(true); + }else + { + procStart->setEnabled(false); + } + procStop->setEnabled(false); + procRestart->setEnabled(false); + procForceStop->setEnabled(false); + }else + { + return ; + } + }else //基础应用处于停止状态 + { + procStart->setEnabled(false); + procStop->setEnabled(false); + procRestart->setEnabled(false); + procForceStop->setEnabled(false); + } + + procUp->setEnabled(false); + procDown->setEnabled(false); + menu.exec(QCursor::pos()); + } +} + +void ProcMngForm::procItemClicked(QTreeWidgetItem *item, int column) +{ + if(!item) + { + return ; + } + if(column != 7) + { + return ; + } + //判断是否点击进程 + if(item->data(0,Qt::UserRole+5).toInt() == EN_TREE_NODE_IS_PROC) + { + //判断是否点击Base应用进程 + if(item->data(2,Qt::UserRole).toInt() == CN_AppId_BASE) + { + return ; + } + //判断是否点击rdb_server + if(item->text(1).toStdString() == PROCESS_RDB_SERVER) + { + return ; + } + //判断当前是否可以点击操作(防止并行操作) + if(!DataMng::instance()->getAllowedStatus()) + { + return ; + } + if(!DataMng::instance()->getBaseStatus()) //基础应用处于启动状态 + { + return ; + } + int curAppId = item->data(2,Qt::UserRole).toInt(); + if(item->data(3,Qt::UserRole).toInt() == EN_PROC_RUNNING) + { + if(getCurAppRdbStatus(curAppId) == EN_PROC_STOP) + { + return ; + } + CLoginDlg dlg(this); + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigRestartProc(curAppId,item->text(1)); + } + }else if(item->data(3,Qt::UserRole).toInt() == EN_PROC_STOP) + { + if(getCurAppRdbStatus(curAppId) == EN_PROC_RUNNING) + { + emit sigStartProc(curAppId,item->text(1)); + } + } + } +} + +void ProcMngForm::checkBoxStateChange(int state) +{ + QSet descList; + descList.clear(); + bool allChecked = true; + for (QAbstractButton *button : m_btnGroup->buttons()) { + QCheckBox *checkBox = qobject_cast(button); + if (checkBox) + { + allChecked &= checkBox->isChecked(); + if(checkBox->isChecked()) + { + descList.insert(checkBox->text()); + } + } + } + + // 更新全选框的状态 + disconnect(m_allCheckBox, &QCheckBox::stateChanged, this, &ProcMngForm::allCheckBoxStateChange); + m_allCheckBox->setChecked(allChecked); + connect(m_allCheckBox, &QCheckBox::stateChanged, this, &ProcMngForm::allCheckBoxStateChange); + upDataProcTreeByDesc(descList); +} + +void ProcMngForm::allCheckBoxStateChange(int state) +{ + for (QAbstractButton *button : m_btnGroup->buttons()) + { + QCheckBox *checkBox = qobject_cast(button); + if (checkBox) { + checkBox->setChecked(state == Qt::Checked); + } + } +} + +void ProcMngForm::initProcTree() +{ + QSet nameSet; + nameSet.clear(); + ui->procTreeWidget->clear(); + + std::vector procInfo = DataMng::instance()->getProcInfo(); + + ui->procTreeWidget->setColumnWidth(0,150); + ui->procTreeWidget->setColumnWidth(1,130); + ui->procTreeWidget->setColumnWidth(2,80); + ui->procTreeWidget->setColumnWidth(3,80); + + for(int j=4;j<7;j++) + { + ui->procTreeWidget->setColumnWidth(j,90); + } + + if(procInfo.size()<= 0) + { + return ; + } + QTreeWidgetItem *nodeItem = new QTreeWidgetItem(); + nodeItem->setText(0,DataMng::instance()->getHostName()); + nodeItem->setData(0,Qt::UserRole+5,EN_TREE_NODE_IS_NODE); + nodeItem->setText(5,QString::number(0.0)); + nodeItem->setTextColor(0 , "#003764"); + nodeItem->setTextColor(5 , "#003764"); + for(size_t index(0);indexsetTextColor(0 , "#003764"); + procItem->setTextColor(1 , "#003764"); + procItem->setTextColor(2 , "#003764"); + procItem->setTextColor(4 , "#003764"); + procItem->setTextColor(5 , "#003764"); + procItem->setText(0,QString::fromStdString(procInfo.at(index).m_procDesc)); + procItem->setData(0,Qt::UserRole+5,EN_TREE_NODE_IS_PROC); + procItem->setText(1,QString::fromStdString(procInfo.at(index).m_procName)); + procItem->setData(1,Qt::UserRole,QString::fromStdString(procInfo[index].m_procParam)); + procItem->setText(2,QString::fromStdString(procInfo.at(index).m_appDesc)); + procItem->setData(2,Qt::UserRole,procInfo.at(index).m_appId); + if(procInfo.at(index).m_isStartUp == 1) + { + procItem->setText(3,tr("运行中")); + procItem->setTextColor(3,"#038300"); + procItem->setData(3,Qt::UserRole,EN_PROC_RUNNING); + if(procInfo.at(index).m_isMaster==0 && procInfo.at(index).m_isSlave == 0) + { + procItem->setText(6, tr("异常")); + procItem->setTextColor(6,"#FF0000"); + } + else if(procInfo.at(index).m_isMaster==1 && procInfo.at(index).m_isSlave==0) + { + procItem->setText(6, tr("主")); + procItem->setTextColor(6,"#038300"); + } + else if(procInfo.at(index).m_isMaster==0 && procInfo.at(index).m_isSlave==1) + { + procItem->setText(6, tr("备")); + procItem->setTextColor(6,"#0084d4"); + } + else + { + procItem->setText(6, tr("异常")); + procItem->setTextColor(6,"#FF0000"); + } + procItem->setText(4, QString::number(procInfo.at(index).m_cpu*100,'f',1)+"%"); + procItem->setText(5, QString::number(procInfo.at(index).m_disk,'f',2)); + } + else if(procInfo.at(index).m_isStartUp==0) + { + procItem->setText(3,tr("已停止")); + procItem->setTextColor(3,"#FF0000"); + procItem->setData(3,Qt::UserRole,EN_PROC_STOP); + procItem->setText(6, "-"); + procItem->setTextColor(6,Qt::black); + procItem->setText(5, "-"); + procItem->setText(4, "-"); + }else if(procInfo.at(index).m_isStartUp==2) + { + procItem->setText(3,tr("未知")); + procItem->setTextColor(3,Qt::black); + procItem->setData(3,Qt::UserRole,EN_PROC_UNKNOW); + procItem->setText(6, "-"); + procItem->setTextColor(6,Qt::black); + procItem->setText(5, "-"); + procItem->setText(4, "-"); + } + if(procInfo.at(index).m_appId != CN_AppId_BASE && procInfo.at(index).m_procName != PROCESS_RDB_SERVER) + { + procItem->setIcon(7,QIcon(":/images/restart.png")); + } + nodeItem->addChild(procItem); + } + ui->procTreeWidget->addTopLevelItem(nodeItem); + ui->procTreeWidget->expandAll(); + + createOrUpdataCheckBox(nameSet); + return; +} + +void ProcMngForm::updateItem(const SProcess &proc, QTreeWidgetItem *item , const QSet &appDescList) +{ + int num = item->childCount(); + for(int i =0;ichild(i)->text(2) ) ) item->child(i)->setHidden(true); + else + { + item->child(i)->setHidden(false); + if(item->child(i)->data(2,Qt::UserRole).toInt() == proc.m_appId && item->child(i)->text(1).toStdString() == proc.m_procName) + { + item->child(i)->setData(1,Qt::UserRole,QString::fromStdString(proc.m_procParam)); + if(proc.m_isStartUp == 1) + { + item->child(i)->setText(3,tr("运行中")); + item->child(i)->setTextColor(3,"#038300"); + item->child(i)->setData(3,Qt::UserRole,EN_PROC_RUNNING); + if(proc.m_isMaster==0 && proc.m_isSlave == 0) + { + item->child(i)->setText(6, tr("异常")); + item->child(i)->setTextColor(6,"#FF0000"); + } + else if(proc.m_isMaster==1 && proc.m_isSlave==0) + { + item->child(i)->setText(6, tr("主")); + item->child(i)->setTextColor(6,"#038300"); + } + else if(proc.m_isMaster==0 && proc.m_isSlave==1) + { + item->child(i)->setText(6, tr("备")); + item->child(i)->setTextColor(6,"#0084d4"); + } + else + { + item->child(i)->setText(6, tr("异常")); + item->child(i)->setTextColor(6,"#FF0000"); + } + item->child(i)->setText(4, QString::number(proc.m_cpu*100,'f',1)+"%"); + item->child(i)->setText(5, QString::number(proc.m_disk,'f',2)); + } + else if(proc.m_isStartUp==0) + { + item->child(i)->setText(3,tr("已停止")); + item->child(i)->setTextColor(3,"#FF0000"); + item->child(i)->setData(3,Qt::UserRole,EN_PROC_STOP); + item->child(i)->setText(6, "-"); + item->child(i)->setTextColor(6,Qt::black); + item->child(i)->setText(5, "-"); + item->child(i)->setText(4, "-"); + }else if(proc.m_isStartUp==2) + { + item->child(i)->setText(3,tr("未知")); + item->child(i)->setTextColor(3,Qt::black); + item->child(i)->setData(3,Qt::UserRole,EN_PROC_UNKNOW); + item->child(i)->setText(6, "-"); + item->child(i)->setTextColor(6,Qt::black); + item->child(i)->setText(5, "-"); + item->child(i)->setText(4, "-"); + } + break; + } + } + + } +} + +void ProcMngForm::blockAppSignals(bool b) +{ + ui->procTreeWidget->blockSignals(b); +} + +int ProcMngForm::getCurAppRdbStatus(int appId) +{ + float disk = 0.0; + std::vector procVec; + DataMng::instance()->getRunProcInfo(procVec,disk); + for(size_t index(0);index &procInfo) +{ + if(m_ntime + 60 < (uint64)iot_public::getUTCTimeSec()) + { + if(!DataMng::instance()->getSysStatus()) + { + return ; + } + for(size_t index(0);index &appDescList) +{ + float disk = 0.0; + std::vector procInfo; + DataMng::instance()->getRunProcInfo(procInfo,disk); + + foreach (SProcess var, procInfo) + { + int topNum = ui->procTreeWidget->topLevelItemCount(); + for(int topIndex(0);topIndexprocTreeWidget->topLevelItem(topIndex); + if( var.m_nodeName == item->text(0).toStdString()) + { + item->setText(5,QString::number(disk,'f',2)); + updateItem(var,item , appDescList); + break; + } + } + + } + ui->procTreeWidget->expandAll(); + outLog(procInfo); +} + +QSet ProcMngForm::retAllCheckBoxName() +{ + QSet qset; + qset.clear(); + QListlistBtn = m_btnGroup->buttons(); + foreach (QAbstractButton *button, listBtn) + { + QCheckBox *checkBox = qobject_cast(button); + if (checkBox && checkBox->isChecked()) + { + qset.insert(checkBox->text()); + } + } + return qset; +} + +void ProcMngForm::createOrUpdataCheckBox(const QSet &appDescSet) +{ + //清除现有的布局和控件 + QList buttons = m_btnGroup->buttons(); + for (QAbstractButton *button : buttons) { + m_btnGroup->removeButton(button); + } + + QHBoxLayout *layout = static_cast(ui->select_widget->layout()); + QLayoutItem *item; + while ((item = layout->takeAt(1)) != nullptr) + { + QWidget *widget = item->widget(); + if (widget && widget != m_allCheckBox) { + m_btnGroup->removeButton(qobject_cast(widget)); + QObject::disconnect(widget, nullptr, nullptr, nullptr); + delete widget; + } + delete item; + } + + //重新添加复选框 + foreach (QString var, appDescSet) + { + QCheckBox *box = new QCheckBox(tr(var.toStdString().c_str())); + layout->addWidget(box); + m_btnGroup->addButton(box); + connect(box, &QCheckBox::stateChanged, this, &ProcMngForm::checkBoxStateChange); + } + + int index = layout->indexOf(m_allCheckBox); + if (index != 0) { + layout->removeWidget(m_allCheckBox); + layout->insertWidget(0, m_allCheckBox); + } + +} diff --git a/product/src/tools/workBench/ProcMngForm.h b/product/src/tools/workBench/ProcMngForm.h new file mode 100644 index 00000000..c6262eb6 --- /dev/null +++ b/product/src/tools/workBench/ProcMngForm.h @@ -0,0 +1,78 @@ +#ifndef PROCMNGFORM_H +#define PROCMNGFORM_H + +#include +#include +#include +#include +#include + +#include "MonitorCommon.h" + +using namespace workBench; + +namespace Ui { +class ProcMngForm; +} + +class ProcMngForm : public QWidget +{ + Q_OBJECT + +public: + explicit ProcMngForm(QWidget *parent = 0); + ~ProcMngForm(); + +signals: + void sigReloadAppAndProc(); + + void sigStartProc(int appId,const QString procName); + + void sigStopProc(int appId,const QString procName); + + void sigRestartProc(int appId,const QString procName); + + void sigForceStopProc(int appId,const QString procName); + +public slots: + void updateProcTree(); + + void customContext(const QPoint &pos); + + void procItemClicked(QTreeWidgetItem *item, int column); + + void checkBoxStateChange(int state); + + void allCheckBoxStateChange(int state); + + +public: + void initProcTree(); + + void updateItem(const SProcess &proc,QTreeWidgetItem *item , const QSet &appDescList ); + + void blockAppSignals(bool b); + +private: + int getCurAppRdbStatus(int appId); + + void outLog(const std::vector &procInfo); + + void upDataProcTreeByDesc(const QSet &appDescList = {}); //过滤树节点 + + QSet retAllCheckBoxName(); //获取所有勾选的复选框的名称 + + void createOrUpdataCheckBox(const QSet &appDescSet ); //创建与更新复选框控件 +private: + Ui::ProcMngForm *ui; + + uint64 m_ntime; + + bool m_isZh; + + QButtonGroup *m_btnGroup; + + QCheckBox *m_allCheckBox; //全选复选框 +}; + +#endif // PROCMNGFORM_H diff --git a/product/src/tools/workBench/ProcMngForm.ui b/product/src/tools/workBench/ProcMngForm.ui new file mode 100644 index 00000000..d9da0321 --- /dev/null +++ b/product/src/tools/workBench/ProcMngForm.ui @@ -0,0 +1,83 @@ + + + ProcMngForm + + + + 0 + 0 + 816 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + 节点应用进程 + + + + + 进程名 + + + + + 所属应用 + + + + + 状态 + + + + + CPU + + + + + 内存(MB) + + + + + 主/备 + + + + + 重启 + + + + + + + + + diff --git a/product/src/tools/workBench/SetupFunc.h b/product/src/tools/workBench/SetupFunc.h new file mode 100644 index 00000000..3c8596da --- /dev/null +++ b/product/src/tools/workBench/SetupFunc.h @@ -0,0 +1,56 @@ + +/********************************************************************************** +* @file SetupFunc.h +* @brief 系统设置函数等声明 +* @author yikenan +* @versiong 1.0 +* @date +**********************************************************************************/ + +#pragma once + +#include +#include + +namespace iot_sys +{ + +//< 注册系统服务,并设置自启动 +bool regSysService(QString &strErr); + +//< 注销系统服务 +bool unregSysService(QString &strErr); + +//<检测是否设置自启动服务 +bool isSysService(QString &strErr); + +//---------------------------------------- + +#ifdef OS_LINUX +//< 设置HMI自启动 +bool setHmiAutoStart(QString &strErr); + +//< 取消HMI自启动 +bool unsetHmiAutoStart(QString &strErr); + +//<检测是否设置自启动服务 +bool isHmiAutoStart(QString &strErr); +#endif +//---------------------------------------- + +//-------------------------------------- +//< 进程管理工具设置和取消自启动 + +#ifdef OS_WINDOWS +// 检测sys_startup是否自启动 +bool isSysStartupVbsExist(); +// 设置sys_startup自启动 +bool setSysStartupAutoStartByVbs(QString &strErr,QString path=QCoreApplication::applicationDirPath()); +// 取消sys_startup自启动 +bool unsetSysStartupAutoStartByVbs(QString &strErr); +#endif +//-------------------------------------- + + +} //< namespace iot_sys + diff --git a/product/src/tools/workBench/SetupFuncLinux.cpp b/product/src/tools/workBench/SetupFuncLinux.cpp new file mode 100644 index 00000000..fbab44b0 --- /dev/null +++ b/product/src/tools/workBench/SetupFuncLinux.cpp @@ -0,0 +1,284 @@ + +/********************************************************************************** +* @file SetupFuncLinux.cpp +* @brief Linux系统设置函数 +* @author yikenan +* @versiong 1.0 +* @date +**********************************************************************************/ + +//< 仅在Linux系统下编译 +#ifdef OS_LINUX + +#include +#include "pub_utility_api/FileUtil.h" +#include "SetupFunc.h" +#include "setup/CommonDef.h" + +namespace iot_sys +{ + +//< 注册系统服务,并设置自启动 +bool regSysService(QString &strErr) +{ + //< 判断服务是否已注册,普通用户权限可执行 + if (0 == QProcess::execute(QString("systemctl is-enabled %1.service").arg(g_pszLauncherServiceName) )) + { + strErr = QObject::tr("已设置服务自启动,若需重新设置,请先取消!"); + return false; + } + + const QString strExec = iot_public::CFileUtil::getPathOfBinFile("sys_launcher_srv").c_str(); + + //< 判断文件存在并设置可执行权限 + if (strExec.length() > 0) + { + if(QFileDevice::ExeOther != + (QFileDevice::ExeOther & QFile::permissions(strExec))) + { + QString strCmd = "chmod +x "; + strCmd += strExec; + if(0 != QProcess::execute(strCmd)) + { + strErr = QObject::tr("设置可执行权限失败!") + "\n" + strExec; + return false; + } + } + } + else + { + strErr = QObject::tr("文件不存在!")+ "\n" + strExec; + return false; + } + + //< 生成或修改systemd服务配置文件 + { + QSettings objIniSetting(g_pszLauncherServiceTempFile, QSettings::IniFormat); + objIniSetting.setIniCodec( QTextCodec::codecForLocale() ); + qDebug() << objIniSetting.iniCodec()->name(); + + if (!objIniSetting.isWritable()) + { + strErr = QObject::tr("服务配置文件不可写,请确认是否具有权限!") + + "\n" + g_pszLauncherServiceTempFile; + return false; + } + + //< 清空所有原有配置 + objIniSetting.setFallbacksEnabled(false); + objIniSetting.clear(); + + objIniSetting.beginGroup("Unit"); + objIniSetting.setValue("Description", g_pszLauncherServiceName); + objIniSetting.setValue("After", "network.target"); + objIniSetting.endGroup(); + + objIniSetting.beginGroup("Service"); + objIniSetting.setValue("Type", "simple"); + objIniSetting.setValue("ExecStart", strExec); + objIniSetting.setValue("KillMode", "process"); + objIniSetting.setValue("Restart", "on-failure"); + objIniSetting.setValue("RestartSec", "42s"); + QString username = qgetenv("USER"); + if( !username.isEmpty() ) + { + objIniSetting.setValue("User",username); + } + objIniSetting.endGroup(); + + + objIniSetting.beginGroup("Install"); + objIniSetting.setValue("WantedBy", "multi-user.target"); + objIniSetting.endGroup(); + + if (QSettings::NoError != objIniSetting.status()) + { + strErr = QObject::tr("写入服务配置文件失败!") + + "\n" + g_pszLauncherServiceTempFile; + return false; + } + } + + //< 设置服务开机自启动 + QString strRegSvrShell = QString("pkexec bash -c 'cp -f %1 %2 && systemctl daemon-reload && systemctl enable %3'").arg(g_pszLauncherServiceTempFile).arg(g_pszLauncherServiceFile).arg(g_pszLauncherServiceName); + if (0 != system(strRegSvrShell.toStdString().c_str())) + { + strErr = QObject::tr("设置服务开机自启动失败!"); + return false; + } + return true; +} + +//< 注销系统服务 +bool unregSysService(QString &strErr) +{ + QString strUnRegSvrShell = QString("pkexec bash -c 'systemctl enable %1 && systemctl disable %1'").arg(g_pszLauncherServiceName); + if (0 != system(strUnRegSvrShell.toStdString().c_str())) + { + strErr = QObject::tr("取消服务开机自启动失败!"); + return false; + } + + return true; +} + +//< 检测是否设置系统自启动 +bool isSysService(QString &strErr) +{ + //< 判断服务是否已注册,普通用户权限可执行 + if (0 == QProcess::execute(QString("systemctl is-enabled %1.service").arg(g_pszLauncherServiceName) )) + { + strErr = QObject::tr("已设置服务自启动,若需重新设置,请先取消!"); + return true; + } + else + return false; +} + +//---------------------------------------- + +//< 设置HMI自启动 +bool setHmiAutoStart(QString &strErr) +{ + const QString strCfgFileDir = + QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + + g_pszXdgAutoStartCfgDir; + + const QString strCfgFileFullPath = strCfgFileDir + g_pszHMIXdgDesktopCfgFile; + + if (QFile::exists(strCfgFileFullPath)) + { + strErr = QObject::tr("已设置HMI自启动,若需重新设置,请先取消!"); + return false; + } + + //< 自身肯定在同级目录,获取其他程序路径需使用 iot_public::CFileUtil::getPathOfBinFile() + const QString strExec = QCoreApplication::applicationDirPath() + "/workBench"; + + //< 判断文件存在并设置可执行权限 + if (QFile::exists(strExec)) + { + if(QFileDevice::ExeOther != + (QFileDevice::ExeOther & QFile::permissions(strExec))) + { + QString strCmd = "chmod +x "; + strCmd += strExec; + if(0 != QProcess::execute(strCmd)) + { + strErr = QObject::tr("设置可执行权限失败!") + + "\n" + strExec; + return false; + } + } + } + else + { + strErr = QObject::tr("文件不存在!") + "\n" + strExec; + return false; + } + + /* + 启动器中的Group “Desktop Entry”,中间带有空格 + 而QSettings对于Group、Key都是强制转URL的,于是空格变成 %20 + 可是这样的写法,xdg不认 + 所以,不使用QSettings + */ + + //< 生成或复写启动器文件 + { + //< 防止路径不存在,先建立 + QDir objDir(strCfgFileDir); + if(!objDir.exists()) + { + objDir.mkpath(strCfgFileDir); + } + + QFile objFile(strCfgFileFullPath); + if (!objFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + strErr = QObject::tr("启动器文件不可写,请确认是否具有权限!") + + "\n" + strCfgFileFullPath; + return false; + } + + { + QTextStream objStreamOut(&objFile); + objStreamOut << "[Desktop Entry]" << endl; + objStreamOut << "Name=" << g_pszHMIXdgDesktopName << endl; + objStreamOut << "Exec=" << strExec << endl; + objStreamOut << "Type=Application" << endl; + objStreamOut << "X-GNOME-AutoRestart=false" << endl; + } + + objFile.close(); + } + + return true; +} + +//< 取消HMI自启动 +bool unsetHmiAutoStart(QString &strErr) +{ + const QString strCfgFileFullPath = + QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + + g_pszXdgAutoStartCfgDir + g_pszHMIXdgDesktopCfgFile; + + if (QFile::exists(strCfgFileFullPath)) + { + if (!QFile::remove(strCfgFileFullPath)) + { + strErr = QObject::tr("删除启动器文件失败,请确认是否具有权限!") + + "\n" + strCfgFileFullPath; + return false; + } + } + else + { + strErr = QObject::tr("未设置HMI自启动,无需取消!"); + return false; + } + + return true; +} + +//< 检测是否设置HMI自启动 +bool isHmiAutoStart(QString &strErr) +{ + const QString strCfgFileDir = + QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + + g_pszXdgAutoStartCfgDir; + + const QString strCfgFileFullPath = strCfgFileDir + g_pszHMIXdgDesktopCfgFile; + + if (QFile::exists(strCfgFileFullPath)) + { + strErr = QObject::tr("已设置HMI自启动,若需重新设置,请先取消!"); + return true; + } + else + return false; +} + + +//---------------------------------------- + +//< 创建快捷方式 +bool creatShortcut(QString &strErr) +{ + //< todo + Q_UNUSED(strErr); + return false; +} + +//< 删除快捷方式 +bool removeShortcut(QString &strErr) +{ + //< todo + Q_UNUSED(strErr); + return false; +} + + +} //< namespace iot_sys + +#endif //< #ifdef OS_LINUX diff --git a/product/src/tools/workBench/SetupFuncWindows.cpp b/product/src/tools/workBench/SetupFuncWindows.cpp new file mode 100644 index 00000000..f7cc4b8b --- /dev/null +++ b/product/src/tools/workBench/SetupFuncWindows.cpp @@ -0,0 +1,272 @@ + +/********************************************************************************** +* @file SetupFuncWindows.cpp +* @brief Windows系统设置函数 +* @author yikenan +* @versiong 1.0 +* @date +**********************************************************************************/ + +//< 仅在Win系统下编译 +#ifdef OS_WINDOWS + +#include +#include +#include +#include +#include +#include +#include + +#include +#include "pub_utility_api/FileUtil.h" +#include "SetupFunc.h" +#include "setup/CommonDef.h" + +namespace iot_sys +{ + +//< 注册系统服务,并设置自启动 +bool regSysService(QString &strErr) +{ + bool bRet = false; + + const QString strExec = iot_public::CFileUtil::getPathOfBinFile("sys_launcher_srv").c_str(); + + //< 判断文件存在 + if (strExec.isEmpty()) + { + strErr = QObject::tr("文件不存在!") + "\n" + strExec; + return false; + } + + //< 打开服务控制管理器 + SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (NULL == hSCM) + { + strErr = QObject::tr("打开服务管理器失败,请确认是否具有权限!"); + } + else + { + //< 判断服务是否已存在 + SC_HANDLE hService = ::OpenService(hSCM, g_pTCharLauncherServiceName, SERVICE_QUERY_CONFIG); + if (NULL == hService) + { + //< 创建服务 + + //< 使用SERVICE_USER_XXX_PROCESS服务类型,用户登录时启动,不影响共享内存等的使用 + //< 若使用SERVICE_WIN32_XXX_PROCESS等服务类型,程序以system用户启动,共享内存被隔离,其他用户访问不到 + + //< todo 最好是实时库等使用共享内存、互斥锁的程序修改声明方式为Global,突破用户间的隔离,原因: + //< 1、如上面说的,SERVICE_USER_XXX_PROCESS是用户登录时才启动,服务自启的实际意义打折扣; + //< 2、多用户登录时会启动多个实例,而实际上由于端口占用等原因,是起不来的; + //< 3、本程序停止服务时存在困难,见下面unregSysService()中的注释。 + + // 20200601 已修改为注册系统服务并验证成功 + hService = ::CreateService( + hSCM, g_pTCharLauncherServiceName, g_pTCharLauncherServiceName, + SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, + SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, + strExec.toStdWString().c_str(), NULL, NULL, NULL, NULL, NULL); + + if (hService == NULL) + { + strErr = QObject::tr("注册服务失败,请确认是否具有权限!"); + } + else + { + SERVICE_DESCRIPTION stSrvDesc; + TCHAR szDesc[] = _T("监控系统加载服务"); + stSrvDesc.lpDescription = szDesc; + if (::ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &stSrvDesc)) + { + bRet = true; + } + + ::CloseServiceHandle(hService); + } + } + else + { + strErr = QObject::tr("已设置服务自启动,若需重新设置,请先取消!"); + ::CloseServiceHandle(hService); + } + + ::CloseServiceHandle(hSCM); + } + + return bRet; +} + +//< 注销系统服务 +bool unregSysService(QString &strErr) +{ + bool bRet = false; + + //< 打开服务控制管理器 + SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (hSCM == NULL) + { + strErr = QObject::tr("打开服务管理器失败,请确认是否具有权限!"); + } + else + { + SC_HANDLE hService = ::OpenService(hSCM, g_pTCharLauncherServiceName, SERVICE_QUERY_STATUS | SERVICE_STOP | DELETE); + //SC_HANDLE hService = ::OpenService(hSCM, _T("xxxx_launcher_17b5ab7"), SERVICE_QUERY_STATUS | SERVICE_STOP | DELETE); + + if (NULL == hService) + { + //< 服务不存在 + strErr = QObject::tr("未设置服务自启动,无需取消!"); + } + else + { + SERVICE_STATUS objStatus; + + if(TRUE == QueryServiceStatus(hService, &objStatus)) + { + //< todo 当使用SERVICE_USER_XXX_PROCESS类型的服务注册时,停止服务存在困难 + //< 此情况下服务的真实名称是注册名加上用户会话的ID,而ID是变化的,且微软没有开发获取的方法 + //< 比如真实的服务名是“xxxx_launcher_17b5ab7”且正在运行,如果查询“xxxx_launcher”的状态,是停止的 + //< 也无法通过停止“xxxx_launcher”服务来停止“xxxx_launcher_17b5ab7” + //< 删除“xxxx_launcher”服务后,“xxxx_launcher_17b5ab7”还可见,必须注销重新登录才会消失 + + if(SERVICE_STOPPED != objStatus.dwCurrentState + && TRUE == ControlService(hService, SERVICE_CONTROL_STOP, &objStatus)) + { + int nWaitLoop = 0; + SERVICE_STATUS objStatusTemp; + while(TRUE == QueryServiceStatus(hService, &objStatusTemp)) + { + if (SERVICE_STOPPED == objStatusTemp.dwCurrentState + || nWaitLoop >= 30) + { + objStatus = objStatusTemp; + break; + } + + QThread::msleep(500); + ++nWaitLoop; + } + } + + if (SERVICE_STOPPED == objStatus.dwCurrentState) + { + //< 删除服务 + if (::DeleteService(hService)) + { + bRet = true; + } + else + { + strErr = QObject::tr("注销服务失败!"); + } + } + else + { + strErr = QObject::tr("停止服务超时!"); + } + } + else + { + strErr = QObject::tr("获取服务状态失败!"); + } + + ::CloseServiceHandle(hService); + } + + ::CloseServiceHandle(hSCM); + } + + return bRet; +} + +//< 检测是否设置系统自启动 +bool isSysService(QString &strErr) +{ + bool bRet = false; + + //< 打开服务控制管理器 + SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (NULL == hSCM) + { + strErr = QObject::tr("打开服务管理器失败,请确认是否具有权限!"); + } + else + { + //< 判断服务是否已存在 + SC_HANDLE hService = ::OpenService(hSCM, g_pTCharLauncherServiceName, SERVICE_QUERY_CONFIG); + if (NULL != hService) + { + strErr = QObject::tr("已设置服务自启动,若需重新设置,请先取消!"); + ::CloseServiceHandle(hService); + bRet = true; + } + else + bRet = false; + ::CloseServiceHandle(hSCM); + } + + return bRet; +} + + +bool isSysStartupVbsExist() +{ + QFile vbsFile( QDir::toNativeSeparators(QString(g_pszAutoStartSysStartupPath) ) ); + return vbsFile.exists(); +} + + +bool setSysStartupAutoStartByVbs(QString &strErr,QString path) +{ + QString vbsTxt; + vbsTxt += "Set WshShell = CreateObject(\"WScript.Shell\" )\n"; + + //< 自身肯定在同级目录,获取其他程序路径需使用 iot_public::CFileUtil::getPathOfBinFile() + vbsTxt += QString("WshShell.Run \"") + "\"\"" + QDir::toNativeSeparators(path + "\\workBench.exe\"\" -hide") + "\"\n"; + vbsTxt += "Set WshShell = Nothing"; + + QFile vbsFile( QString() + QDir::toNativeSeparators(QString(g_pszAutoStartSysStartupPath) ) ); + if(!vbsFile.open(QFile::WriteOnly | QFile::Truncate)) + { + strErr = QObject::tr("启动文件无法写入"); + return false; + } + + if(vbsFile.write(vbsTxt.toLocal8Bit()) != -1) + { + vbsFile.close(); + return true; + } + else{ + strErr = QObject::tr("启动文件无法写入"); + vbsFile.close(); + return true; + } +} + +bool unsetSysStartupAutoStartByVbs(QString &strErr) +{ + Q_UNUSED(strErr) + QFile file(g_pszAutoStartSysStartupPath); + if(!file.exists()) + return true; + if(file.remove()) + { + return true; + } + else + { + return false; + } + +} + + + +} //< namespace iot_sys + + + +#endif //< #ifdef OS_WINDOWS diff --git a/product/src/tools/workBench/SingleApplication.cpp b/product/src/tools/workBench/SingleApplication.cpp new file mode 100644 index 00000000..5da40fa4 --- /dev/null +++ b/product/src/tools/workBench/SingleApplication.cpp @@ -0,0 +1,181 @@ +// The MIT License (MIT) +// +// Copyright (c) Itay Grudev 2015 - 2018 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include +#include +#include +#include +#include + +#include "SingleApplication.h" +#include "SingleApplication_p.h" + +/** + * @brief Constructor. Checks and fires up LocalServer or closes the program + * if another instance already exists + * @param argc + * @param argv + * @param {bool} allowSecondaryInstances + */ +SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSecondary, Options options, int timeout ) + : app_t( argc, argv ), d_ptr( new SingleApplicationPrivate( this ) ) +{ + Q_D(SingleApplication); + +#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) + // On Android and iOS since the library is not supported fallback to + // standard QApplication behaviour by simply returning at this point. + qWarning() << "SingleApplication is not supported on Android and iOS systems."; + return; +#endif + + // Store the current mode of the program + d->options = options; + + // Generating an application ID used for identifying the shared memory + // block and QLocalServer + d->genBlockServerName(); + +#ifdef Q_OS_UNIX + // By explicitly attaching it and then deleting it we make sure that the + // memory is deleted even after the process has crashed on Unix. + d->memory = new QSharedMemory( d->blockServerName ); + d->memory->attach(); + delete d->memory; +#endif + // Guarantee thread safe behaviour with a shared memory block. + d->memory = new QSharedMemory( d->blockServerName ); + + // Create a shared memory block + if( d->memory->create( sizeof( InstancesInfo ) ) ) { + // Initialize the shared memory block + d->memory->lock(); + d->initializeMemoryBlock(); + d->memory->unlock(); + } else { + // Attempt to attach to the memory segment + if( ! d->memory->attach() ) { + qCritical() << "SingleApplication: Unable to attach to shared memory block."; + qCritical() << d->memory->errorString(); + delete d; + ::exit( EXIT_FAILURE ); + } + } + + InstancesInfo* inst = static_cast( d->memory->data() ); + QTime time; + time.start(); + + // Make sure the shared memory block is initialised and in consistent state + while( true ) { + d->memory->lock(); + + if( d->blockChecksum() == inst->checksum ) break; + + if( time.elapsed() > 5000 ) { + qWarning() << "SingleApplication: Shared memory block has been in an inconsistent state from more than 5s. Assuming primary instance failure."; + d->initializeMemoryBlock(); + } + + d->memory->unlock(); + + // Random sleep here limits the probability of a collision between two racing apps + qsrand( QDateTime::currentMSecsSinceEpoch() % std::numeric_limits::max() ); + QThread::sleep( 8 + static_cast ( static_cast ( qrand() ) / RAND_MAX * 10 ) ); + } + + if( inst->primary == false) { + d->startPrimary(); + d->memory->unlock(); + return; + } + + // Check if another instance can be started + if( allowSecondary ) { + inst->secondary += 1; + inst->checksum = d->blockChecksum(); + d->instanceNumber = inst->secondary; + d->startSecondary(); + if( d->options & Mode::SecondaryNotification ) { + d->connectToPrimary( timeout, SingleApplicationPrivate::SecondaryInstance ); + } + d->memory->unlock(); + return; + } + + d->memory->unlock(); + + d->connectToPrimary( timeout, SingleApplicationPrivate::NewInstance ); + + delete d; + + ::exit( EXIT_SUCCESS ); +} + +/** + * @brief Destructor + */ +SingleApplication::~SingleApplication() +{ + Q_D(SingleApplication); + delete d; +} + +bool SingleApplication::isPrimary() +{ + Q_D(SingleApplication); + return d->server != nullptr; +} + +bool SingleApplication::isSecondary() +{ + Q_D(SingleApplication); + return d->server == nullptr; +} + +quint32 SingleApplication::instanceId() +{ + Q_D(SingleApplication); + return d->instanceNumber; +} + +qint64 SingleApplication::primaryPid() +{ + Q_D(SingleApplication); + return d->primaryPid(); +} + +bool SingleApplication::sendMessage( QByteArray message, int timeout ) +{ + Q_D(SingleApplication); + + // Nobody to connect to + if( isPrimary() ) return false; + + // Make sure the socket is connected + d->connectToPrimary( timeout, SingleApplicationPrivate::Reconnect ); + + d->socket->write( message ); + bool dataWritten = d->socket->waitForBytesWritten( timeout ); + d->socket->flush(); + return dataWritten; +} diff --git a/product/src/tools/workBench/SingleApplication.h b/product/src/tools/workBench/SingleApplication.h new file mode 100644 index 00000000..cb505971 --- /dev/null +++ b/product/src/tools/workBench/SingleApplication.h @@ -0,0 +1,135 @@ +// The MIT License (MIT) +// +// Copyright (c) Itay Grudev 2015 - 2018 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#ifndef SINGLE_APPLICATION_H +#define SINGLE_APPLICATION_H + +#include +#include + +#ifndef QAPPLICATION_CLASS + #define QAPPLICATION_CLASS QCoreApplication +#endif + +#include QT_STRINGIFY(QAPPLICATION_CLASS) + +class SingleApplicationPrivate; + +/** + * @brief The SingleApplication class handles multiple instances of the same + * Application + * @see QCoreApplication + */ +class SingleApplication : public QAPPLICATION_CLASS +{ + Q_OBJECT + + typedef QAPPLICATION_CLASS app_t; + +public: + /** + * @brief Mode of operation of SingleApplication. + * Whether the block should be user-wide or system-wide and whether the + * primary instance should be notified when a secondary instance had been + * started. + * @note Operating system can restrict the shared memory blocks to the same + * user, in which case the User/System modes will have no effect and the + * block will be user wide. + * @enum + */ + enum Mode { + User = 1 << 0, + System = 1 << 1, + SecondaryNotification = 1 << 2, + ExcludeAppVersion = 1 << 3, + ExcludeAppPath = 1 << 4 + }; + Q_DECLARE_FLAGS(Options, Mode) + + /** + * @brief Intitializes a SingleApplication instance with argc command line + * arguments in argv + * @arg {int &} argc - Number of arguments in argv + * @arg {const char *[]} argv - Supplied command line arguments + * @arg {bool} allowSecondary - Whether to start the instance as secondary + * if there is already a primary instance. + * @arg {Mode} mode - Whether for the SingleApplication block to be applied + * User wide or System wide. + * @arg {int} timeout - Timeout to wait in milliseconds. + * @note argc and argv may be changed as Qt removes arguments that it + * recognizes + * @note Mode::SecondaryNotification only works if set on both the primary + * instance and the secondary instance. + * @note The timeout is just a hint for the maximum time of blocking + * operations. It does not guarantee that the SingleApplication + * initialisation will be completed in given time, though is a good hint. + * Usually 4*timeout would be the worst case (fail) scenario. + * @see See the corresponding QAPPLICATION_CLASS constructor for reference + */ + explicit SingleApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 ); + ~SingleApplication(); + + /** + * @brief Returns if the instance is the primary instance + * @returns {bool} + */ + bool isPrimary(); + + /** + * @brief Returns if the instance is a secondary instance + * @returns {bool} + */ + bool isSecondary(); + + /** + * @brief Returns a unique identifier for the current instance + * @returns {qint32} + */ + quint32 instanceId(); + + /** + * @brief Returns the process ID (PID) of the primary instance + * @returns {qint64} + */ + qint64 primaryPid(); + + /** + * @brief Sends a message to the primary instance. Returns true on success. + * @param {int} timeout - Timeout for connecting + * @returns {bool} + * @note sendMessage() will return false if invoked from the primary + * instance. + */ + bool sendMessage( QByteArray message, int timeout = 100 ); + +Q_SIGNALS: + void instanceStarted(); + void receivedMessage( quint32 instanceId, QByteArray message ); + +private: + SingleApplicationPrivate *d_ptr; + Q_DECLARE_PRIVATE(SingleApplication) +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(SingleApplication::Options) + +#endif // SINGLE_APPLICATION_H diff --git a/product/src/tools/workBench/SingleApplication_p.cpp b/product/src/tools/workBench/SingleApplication_p.cpp new file mode 100644 index 00000000..122e5900 --- /dev/null +++ b/product/src/tools/workBench/SingleApplication_p.cpp @@ -0,0 +1,406 @@ +// The MIT License (MIT) +// +// Copyright (c) Itay Grudev 2015 - 2018 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// +// W A R N I N G !!! +// ----------------- +// +// This file is not part of the SingleApplication API. It is used purely as an +// implementation detail. This header file may change from version to +// version without notice, or may even be removed. +// + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "SingleApplication.h" +#include "SingleApplication_p.h" + +#ifdef Q_OS_UNIX + #include + #include + #include +#endif + +#ifdef Q_OS_WIN + #include + #include +#endif + +SingleApplicationPrivate::SingleApplicationPrivate( SingleApplication *q_ptr ) + : q_ptr( q_ptr ) +{ + server = nullptr; + socket = nullptr; + memory = nullptr; + instanceNumber = -1; +} + +SingleApplicationPrivate::~SingleApplicationPrivate() +{ + if( socket != nullptr ) { + socket->close(); + delete socket; + } + + memory->lock(); + InstancesInfo* inst = static_cast(memory->data()); + if( server != nullptr ) { + server->close(); + delete server; + inst->primary = false; + inst->primaryPid = -1; + inst->checksum = blockChecksum(); + } + memory->unlock(); + + delete memory; +} + +void SingleApplicationPrivate::genBlockServerName() +{ + QCryptographicHash appData( QCryptographicHash::Sha256 ); + appData.addData( "SingleApplication", 17 ); + appData.addData( SingleApplication::app_t::applicationName().toUtf8() ); + appData.addData( SingleApplication::app_t::organizationName().toUtf8() ); + appData.addData( SingleApplication::app_t::organizationDomain().toUtf8() ); + + if( ! (options & SingleApplication::Mode::ExcludeAppVersion) ) { + appData.addData( SingleApplication::app_t::applicationVersion().toUtf8() ); + } + + if( ! (options & SingleApplication::Mode::ExcludeAppPath) ) { +#ifdef Q_OS_WIN + appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() ); +#else + appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() ); +#endif + } + + // User level block requires a user specific data in the hash + if( options & SingleApplication::Mode::User ) { +#ifdef Q_OS_WIN + wchar_t username [ UNLEN + 1 ]; + // Specifies size of the buffer on input + DWORD usernameLength = UNLEN + 1; + if( GetUserNameW( username, &usernameLength ) ) { + appData.addData( QString::fromWCharArray(username).toUtf8() ); + } else { + appData.addData( qgetenv("USERNAME") ); + } +#endif +#ifdef Q_OS_UNIX + QByteArray username; + uid_t uid = geteuid(); + struct passwd *pw = getpwuid(uid); + if( pw ) { + username = pw->pw_name; + } + if( username.isEmpty() ) { + username = qgetenv("USER"); + } + appData.addData(username); +#endif + } + + // Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with + // server naming requirements. + blockServerName = appData.result().toBase64().replace("/", "_"); +} + +void SingleApplicationPrivate::initializeMemoryBlock() +{ + InstancesInfo* inst = static_cast( memory->data() ); + inst->primary = false; + inst->secondary = 0; + inst->primaryPid = -1; + inst->checksum = blockChecksum(); +} + +void SingleApplicationPrivate::startPrimary() +{ + Q_Q(SingleApplication); + + // Successful creation means that no main process exists + // So we start a QLocalServer to listen for connections + QLocalServer::removeServer( blockServerName ); + server = new QLocalServer(); + + // Restrict access to the socket according to the + // SingleApplication::Mode::User flag on User level or no restrictions + if( options & SingleApplication::Mode::User ) { + server->setSocketOptions( QLocalServer::UserAccessOption ); + } else { + server->setSocketOptions( QLocalServer::WorldAccessOption ); + } + + server->listen( blockServerName ); + QObject::connect( + server, + &QLocalServer::newConnection, + this, + &SingleApplicationPrivate::slotConnectionEstablished + ); + + // Reset the number of connections + InstancesInfo* inst = static_cast ( memory->data() ); + + inst->primary = true; + inst->primaryPid = q->applicationPid(); + inst->checksum = blockChecksum(); + + instanceNumber = 0; +} + +void SingleApplicationPrivate::startSecondary() +{ +} + +void SingleApplicationPrivate::connectToPrimary( int msecs, ConnectionType connectionType ) +{ + // Connect to the Local Server of the Primary Instance if not already + // connected. + if( socket == nullptr ) { + socket = new QLocalSocket(); + } + + // If already connected - we are done; + if( socket->state() == QLocalSocket::ConnectedState ) + return; + + // If not connect + if( socket->state() == QLocalSocket::UnconnectedState || + socket->state() == QLocalSocket::ClosingState ) { + socket->connectToServer( blockServerName ); + } + + // Wait for being connected + if( socket->state() == QLocalSocket::ConnectingState ) { + socket->waitForConnected( msecs ); + } + + // Initialisation message according to the SingleApplication protocol + if( socket->state() == QLocalSocket::ConnectedState ) { + // Notify the parent that a new instance had been started; + QByteArray initMsg; + QDataStream writeStream(&initMsg, QIODevice::WriteOnly); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + writeStream.setVersion(QDataStream::Qt_5_6); +#endif + + writeStream << blockServerName.toLatin1(); + writeStream << static_cast(connectionType); + writeStream << instanceNumber; + quint16 checksum = qChecksum(initMsg.constData(), static_cast(initMsg.length())); + writeStream << checksum; + + // The header indicates the message length that follows + QByteArray header; + QDataStream headerStream(&header, QIODevice::WriteOnly); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + headerStream.setVersion(QDataStream::Qt_5_6); +#endif + headerStream << static_cast ( initMsg.length() ); + + socket->write( header ); + socket->write( initMsg ); + socket->flush(); + socket->waitForBytesWritten( msecs ); + qDebug() << "111111111111111111111111111111"; + } +} + +quint16 SingleApplicationPrivate::blockChecksum() +{ + return qChecksum( + static_cast ( memory->data() ), + offsetof( InstancesInfo, checksum ) + ); +} + +qint64 SingleApplicationPrivate::primaryPid() +{ + qint64 pid; + + memory->lock(); + InstancesInfo* inst = static_cast( memory->data() ); + pid = inst->primaryPid; + memory->unlock(); + + return pid; +} + +/** + * @brief Executed when a connection has been made to the LocalServer + */ +void SingleApplicationPrivate::slotConnectionEstablished() +{ + QLocalSocket *nextConnSocket = server->nextPendingConnection(); + connectionMap.insert(nextConnSocket, ConnectionInfo()); + + QObject::connect(nextConnSocket, &QLocalSocket::aboutToClose, + [nextConnSocket, this]() { + auto &info = connectionMap[nextConnSocket]; + Q_EMIT this->slotClientConnectionClosed( nextConnSocket, info.instanceId ); + } + ); + + QObject::connect(nextConnSocket, &QLocalSocket::disconnected, + [nextConnSocket, this](){ + connectionMap.remove(nextConnSocket); + nextConnSocket->deleteLater(); + } + ); + + QObject::connect(nextConnSocket, &QLocalSocket::readyRead, + [nextConnSocket, this]() { + auto &info = connectionMap[nextConnSocket]; + switch(info.stage) { + case StageHeader: + readInitMessageHeader(nextConnSocket); + break; + case StageBody: + readInitMessageBody(nextConnSocket); + break; + case StageConnected: + Q_EMIT this->slotDataAvailable( nextConnSocket, info.instanceId ); + break; + default: + break; + }; + } + ); +} + +void SingleApplicationPrivate::readInitMessageHeader( QLocalSocket *sock ) +{ + if (!connectionMap.contains( sock )) { + return; + } + + if( sock->bytesAvailable() < ( qint64 )sizeof( quint64 ) ) { + return; + } + + QDataStream headerStream( sock ); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + headerStream.setVersion( QDataStream::Qt_5_6 ); +#endif + + // Read the header to know the message length + quint64 msgLen = 0; + headerStream >> msgLen; + ConnectionInfo &info = connectionMap[sock]; + info.stage = StageBody; + info.msgLen = msgLen; + + if ( sock->bytesAvailable() >= (qint64) msgLen ) { + readInitMessageBody( sock ); + } +} + +void SingleApplicationPrivate::readInitMessageBody( QLocalSocket *sock ) +{ + Q_Q(SingleApplication); + + if (!connectionMap.contains( sock )) { + return; + } + + ConnectionInfo &info = connectionMap[sock]; + if( sock->bytesAvailable() < ( qint64 )info.msgLen ) { + return; + } + + // Read the message body + QByteArray msgBytes = sock->read(info.msgLen); + QDataStream readStream(msgBytes); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + readStream.setVersion( QDataStream::Qt_5_6 ); +#endif + + // server name + QByteArray latin1Name; + readStream >> latin1Name; + + // connection type + ConnectionType connectionType = InvalidConnection; + quint8 connTypeVal = InvalidConnection; + readStream >> connTypeVal; + connectionType = static_cast ( connTypeVal ); + + // instance id + quint32 instanceId = 0; + readStream >> instanceId; + + // checksum + quint16 msgChecksum = 0; + readStream >> msgChecksum; + + const quint16 actualChecksum = qChecksum( msgBytes.constData(), static_cast( msgBytes.length() - sizeof( quint16 ) ) ); + + bool isValid = readStream.status() == QDataStream::Ok && + QLatin1String(latin1Name) == blockServerName && + msgChecksum == actualChecksum; + + if( !isValid ) { + sock->close(); + return; + } + + info.instanceId = instanceId; + info.stage = StageConnected; + + if( connectionType == NewInstance || + ( connectionType == SecondaryInstance && + options & SingleApplication::Mode::SecondaryNotification ) ) + { + Q_EMIT q->instanceStarted(); + } + + if (sock->bytesAvailable() > 0) { + Q_EMIT this->slotDataAvailable( sock, instanceId ); + } +} + +void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quint32 instanceId ) +{ + Q_Q(SingleApplication); + Q_EMIT q->receivedMessage( instanceId, dataSocket->readAll() ); +} + +void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId ) +{ + if( closedSocket->bytesAvailable() > 0 ) + Q_EMIT slotDataAvailable( closedSocket, instanceId ); +} diff --git a/product/src/tools/workBench/SingleApplication_p.h b/product/src/tools/workBench/SingleApplication_p.h new file mode 100644 index 00000000..ecc048ae --- /dev/null +++ b/product/src/tools/workBench/SingleApplication_p.h @@ -0,0 +1,99 @@ +// The MIT License (MIT) +// +// Copyright (c) Itay Grudev 2015 - 2016 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// +// W A R N I N G !!! +// ----------------- +// +// This file is not part of the SingleApplication API. It is used purely as an +// implementation detail. This header file may change from version to +// version without notice, or may even be removed. +// + +#ifndef SINGLEAPPLICATION_P_H +#define SINGLEAPPLICATION_P_H + +#include +#include +#include +#include "SingleApplication.h" + +struct InstancesInfo { + bool primary; + quint32 secondary; + qint64 primaryPid; + quint16 checksum; +}; + +struct ConnectionInfo { + explicit ConnectionInfo() : + msgLen(0), instanceId(0), stage(0) {} + qint64 msgLen; + quint32 instanceId; + quint8 stage; +}; + +class SingleApplicationPrivate : public QObject { +Q_OBJECT +public: + enum ConnectionType : quint8 { + InvalidConnection = 0, + NewInstance = 1, + SecondaryInstance = 2, + Reconnect = 3 + }; + enum ConnectionStage : quint8 { + StageHeader = 0, + StageBody = 1, + StageConnected = 2, + }; + Q_DECLARE_PUBLIC(SingleApplication) + + SingleApplicationPrivate( SingleApplication *q_ptr ); + ~SingleApplicationPrivate(); + + void genBlockServerName(); + void initializeMemoryBlock(); + void startPrimary(); + void startSecondary(); + void connectToPrimary(int msecs, ConnectionType connectionType ); + quint16 blockChecksum(); + qint64 primaryPid(); + void readInitMessageHeader(QLocalSocket *socket); + void readInitMessageBody(QLocalSocket *socket); + + SingleApplication *q_ptr; + QSharedMemory *memory; + QLocalSocket *socket; + QLocalServer *server; + quint32 instanceNumber; + QString blockServerName; + SingleApplication::Options options; + QMap connectionMap; + +public Q_SLOTS: + void slotConnectionEstablished(); + void slotDataAvailable( QLocalSocket*, quint32 ); + void slotClientConnectionClosed( QLocalSocket*, quint32 ); +}; + +#endif // SINGLEAPPLICATION_P_H diff --git a/product/src/tools/workBench/StartUpForm.cpp b/product/src/tools/workBench/StartUpForm.cpp new file mode 100644 index 00000000..636db979 --- /dev/null +++ b/product/src/tools/workBench/StartUpForm.cpp @@ -0,0 +1,184 @@ +#include "StartUpForm.h" +#include "ui_StartUpForm.h" +#include "MonitorCommon.h" +#include "DataMng.h" +#include "../include/sys/sys_login_api/CLoginDlg.h" + +#include +#include + +using namespace workBench; + +StartUpForm::StartUpForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::StartUpForm) +{ + ui->setupUi(this); + initVariables(); + initView(); + initConn(); +} + +StartUpForm::~StartUpForm() +{ + delete ui; +} + +int StartUpForm::getCurrentIndex() +{ + return ui->stackedWidget->currentIndex(); +} + +int StartUpForm::getStartValue() +{ + return ui->sys_start_bar->value(); +} + +int StartUpForm::getStopValue() +{ + return ui->sys_stop_bar->value(); +} + +void StartUpForm::changeIndex(int index) +{ + if(index < (int)EN_SYSTEM_UNKNOW) + { + ui->stackedWidget->setCurrentIndex(index); + } +} + +void StartUpForm::changeStartValue(int value) +{ + ui->sys_start_bar->setValue(value); +} + +void StartUpForm::changeStopValue(int value) +{ + ui->sys_stop_bar->setValue(value); +} + +void StartUpForm::initStartValue() +{ + ui->sys_start_bar->setValue(0); +} + +void StartUpForm::initStopValue() +{ + ui->sys_stop_bar->setValue(0); +} + +void StartUpForm::initValue() +{ + initStartValue(); + initStopValue(); +} + +void StartUpForm::startSystem() +{ + emit sigStartSystem(); +} + +void StartUpForm::stopSystem() +{ + if(!DataMng::instance()->getAllowedStatus()) + { + return ; + } + CLoginDlg dlg; + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigStopSystem(); + } +} + +void StartUpForm::initVariables() +{ + +} + +void StartUpForm::initView() +{ + //设置启动状态和停止状态图片 + /*QString stStartPng = DataMng::instance()->getStartPng(); + QString stStopPng = DataMng::instance()->getStopPng(); + if(stStartPng.isEmpty()) + { + ui->btn_start->setStyleSheet("QPushButton{border-image: url(:/images/start.png);}"); + }else + { + ui->btn_start->setStyleSheet(QString("QPushButton{background-image: url(%1);}").arg(stStartPng)); + } + if(stStopPng.isEmpty()) + { + ui->btn_stop->setStyleSheet("QPushButton{border-image: url(:/images/stop.png);}"); + }else + { + ui->btn_stop->setStyleSheet(QString("QPushButton{background-image: url(%1);}").arg(stStopPng)); + }*/ + + //初始化进度条 + MyProgressBar::PercentStyle_Type index = MyProgressBar::PercentStyle_Type(1); + ui->sys_start_bar->setPercentStyle(index); + ui->sys_stop_bar->setPercentStyle(index); + //设置进度条边框宽度 + ui->sys_start_bar->setBorderWidth(0); + ui->sys_stop_bar->setBorderWidth(0); + //设置外边框颜色 + QString stStartBorderColor = DataMng::instance()->getStartBorderColor(); + QString stStopBorderColor = DataMng::instance()->getStopBorderColor(); + if(stStartBorderColor.isEmpty()) + { + QColor c1(204,244,211); + ui->sys_start_bar->setBoderColor(c1); + ui->sys_start_bar->setBgColor(c1); + }else + { + QColor c1(stStartBorderColor); + ui->sys_start_bar->setBoderColor(c1); + ui->sys_start_bar->setBgColor(c1); + } + if(stStopBorderColor.isEmpty()) + { + QColor c2(255,225,217); + ui->sys_stop_bar->setBoderColor(c2); + ui->sys_stop_bar->setBgColor(c2); + }else + { + QColor c2(stStopBorderColor); + ui->sys_stop_bar->setBoderColor(c2); + ui->sys_stop_bar->setBgColor(c2); + } + + QString stStartWaterColor = DataMng::instance()->getStartWaterColor(); + QString stStopWaterColor = DataMng::instance()->getStopWaterColor(); + if(stStartWaterColor.isEmpty()) + { + QColor c3(0,202,33); + ui->sys_start_bar->setColor(c3); + }else + { + QColor c3(stStartWaterColor); + ui->sys_start_bar->setColor(c3); + } + if(stStopWaterColor.isEmpty()) + { + QColor c4(255,104,64); + ui->sys_stop_bar->setColor(c4); + }else + { + QColor c4(stStopWaterColor); + ui->sys_stop_bar->setColor(c4); + } + ui->btn_stop->setToolTip(tr("退出系统前,请将所有配置工具和人机界面退出!")); +} + +void StartUpForm::initConn() +{ + connect(ui->btn_start,&QPushButton::clicked,this,&StartUpForm::startSystem); + connect(ui->btn_stop,&QPushButton::clicked,this,&StartUpForm::stopSystem); +} diff --git a/product/src/tools/workBench/StartUpForm.h b/product/src/tools/workBench/StartUpForm.h new file mode 100644 index 00000000..847a16e9 --- /dev/null +++ b/product/src/tools/workBench/StartUpForm.h @@ -0,0 +1,62 @@ +#ifndef STARTUPFORM_H +#define STARTUPFORM_H + +#include + +namespace Ui { +class StartUpForm; +} + +class StartUpForm : public QWidget +{ + Q_OBJECT + +public: + explicit StartUpForm(QWidget *parent = 0); + ~StartUpForm(); + +public: + int getCurrentIndex(); + + int getStartValue(); + + int getStopValue(); + +signals: + void sigLogText(const QString &text); + + void sigStartSystem(); + void sigStopSystem(); + +public slots: + void changeIndex(int index); + + void changeStartValue(int value); + + void changeStopValue(int value); + + void initStartValue(); + + void initStopValue(); + + void initValue(); + + void startSystem(); + + void stopSystem(); + + + +private: + + void initVariables(); + + void initView(); + + void initConn(); + +private: + Ui::StartUpForm *ui; +}; + +#endif // STARTUPFORM_H diff --git a/product/src/tools/workBench/StartUpForm.ui b/product/src/tools/workBench/StartUpForm.ui new file mode 100644 index 00000000..f5458258 --- /dev/null +++ b/product/src/tools/workBench/StartUpForm.ui @@ -0,0 +1,318 @@ + + + StartUpForm + + + + 0 + 0 + 337 + 408 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 2 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 200 + 200 + + + + + 200 + 200 + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 200 + 200 + + + + + 200 + 200 + + + + 0 + + + Qt::AlignCenter + + + true + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 200 + 200 + + + + + 200 + 200 + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 200 + 200 + + + + + 200 + 200 + + + + 0 + + + Qt::AlignCenter + + + true + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + MyProgressBar + QProgressBar +
MyProgressBar.h
+
+
+ + +
diff --git a/product/src/tools/workBench/StatusForm.cpp b/product/src/tools/workBench/StatusForm.cpp new file mode 100644 index 00000000..5dd2a58b --- /dev/null +++ b/product/src/tools/workBench/StatusForm.cpp @@ -0,0 +1,81 @@ +#include "StatusForm.h" +#include "ui_StatusForm.h" +#include + +StatusForm::StatusForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::StatusForm) +{ + setAttribute(Qt::WA_DeleteOnClose); + setMouseTracking(true); + ui->setupUi(this); +} + +StatusForm::~StatusForm() +{ + delete ui; +} + +void StatusForm::slotLogText(const QString &logText) +{ + ui->statusText->setProperty("state" , "3"); + ui->statusText->setText(logText); + ui->statusText->style()->unpolish(ui->statusText); + ui->statusText->style()->polish(ui->statusText); +} + +void StatusForm::netIsNotOnline() +{ + ui->netText->setProperty("state" , "2"); + ui->netText->setText(tr("异常")); + ui->netText->style()->unpolish(ui->netText); + ui->netText->style()->polish(ui->netText); +} + +void StatusForm::netIsOnline() +{ + ui->netText->setProperty("state" , "1"); + ui->netText->setText(tr("正常")); + ui->netText->style()->unpolish(ui->netText); + ui->netText->style()->polish(ui->netText); +} + +void StatusForm::dogUncheck() +{ + ui->dogText->setProperty("state" , "2"); + ui->dogText->setText(tr("未检测")); + ui->dogText->style()->unpolish(ui->dogText); + ui->dogText->style()->polish(ui->dogText); +} + +void StatusForm::dogIsNotHave() +{ + ui->dogText->setProperty("state" , "2"); + ui->dogText->setText(tr("未激活")); + ui->dogText->style()->unpolish(ui->dogText); + ui->dogText->style()->polish(ui->dogText); +} + +void StatusForm::dogIsHave() +{ + ui->dogText->setProperty("state" , "1"); + ui->dogText->setText(tr("已激活")); + ui->dogText->style()->unpolish(ui->dogText); + ui->dogText->style()->polish(ui->dogText); +} + +void StatusForm::sysIsRun() +{ + ui->statusText->setProperty("state" , "1"); + ui->statusText->setText(tr("系统运行中")); + ui->statusText->style()->unpolish(ui->statusText); + ui->statusText->style()->polish(ui->statusText); +} + +void StatusForm::sysIsNotRun() +{ + ui->statusText->setProperty("state" , "2"); + ui->statusText->setText(tr("系统已停止")); + ui->statusText->style()->unpolish(ui->statusText); + ui->statusText->style()->polish(ui->statusText); +} diff --git a/product/src/tools/workBench/StatusForm.h b/product/src/tools/workBench/StatusForm.h new file mode 100644 index 00000000..c4bcd535 --- /dev/null +++ b/product/src/tools/workBench/StatusForm.h @@ -0,0 +1,41 @@ +#ifndef STATUSFORM_H +#define STATUSFORM_H + +#include + +namespace Ui { +class StatusForm; +} + +class StatusForm : public QWidget +{ + Q_OBJECT + +public: + explicit StatusForm(QWidget *parent = 0); + ~StatusForm(); + +public slots: + + void slotLogText(const QString & logText); + +public: + + void netIsNotOnline(); + + void netIsOnline(); + + void dogUncheck(); + + void dogIsNotHave(); + + void dogIsHave(); + + void sysIsRun(); + + void sysIsNotRun(); +private: + Ui::StatusForm *ui; +}; + +#endif // STATUSFORM_H diff --git a/product/src/tools/workBench/StatusForm.ui b/product/src/tools/workBench/StatusForm.ui new file mode 100644 index 00000000..72b44544 --- /dev/null +++ b/product/src/tools/workBench/StatusForm.ui @@ -0,0 +1,103 @@ + + + StatusForm + + + + 0 + 0 + 550 + 27 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 50 + 0 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 激活状态: + + + + + + + + 50 + 25 + + + + 正常 + + + + + + + 本地网络状态: + + + + + + + + 50 + 25 + + + + 正常 + + + + + + + + + + diff --git a/product/src/tools/workBench/SystemSetForm.cpp b/product/src/tools/workBench/SystemSetForm.cpp new file mode 100644 index 00000000..95c60aea --- /dev/null +++ b/product/src/tools/workBench/SystemSetForm.cpp @@ -0,0 +1,246 @@ +#include "SystemSetForm.h" +#include "ui_SystemSetForm.h" +#include "DataMng.h" +#include "DogCheck.h" +#include "SetupFunc.h" +#include "pub_utility_api/FileUtil.h" +#include "pub_utility_api/I18N.h" +#include "../include/sys/sys_login_api/CLoginDlg.h" +#include "ModifyButtonForm.h" + + +#include +#include +#include +#include +#include +#include + +using namespace workBench; +SystemSetForm::SystemSetForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SystemSetForm), + m_groupBtn(Q_NULLPTR) +{ + ui->setupUi(this); + m_language = iot_public::getCurLanguage().c_str(); + initView(); + initConn(); + ui->tabWidget->setCurrentIndex(1); + ui->mainPathValue->installEventFilter(this); + ui->backPathValue->installEventFilter(this); +} + +SystemSetForm::~SystemSetForm() +{ + delete ui; +} + +void SystemSetForm::setAuthorityLabelText(int model) +{ + switch (model) { + case 0: + ui->lbl_active_state->setText(tr("未检测")); + break; + case 1: + ui->lbl_active_state->setText(tr("未激活")); + break; + case 2: + ui->lbl_active_state->setText(tr("已激活")); + break; + default: + ui->lbl_active_state->setText(tr("未检测")); + break; + } +} + +void SystemSetForm::linkActive(const QString &link) +{ + LOGDEBUG("SystemSetForm:%s",link.toStdString().c_str()); + QDesktopServices::openUrl(QUrl("file:///"+link,QUrl::TolerantMode)); +} + +void SystemSetForm::slotActiveBtnClicked() +{ + DogCheck dogCheck(this); + dogCheck.exec(); +} + +void SystemSetForm::slotCheckBoxSelfStart(int state) +{ + QString text = ""; + QString strErr; + if( Qt::Checked == state && !m_isSys) + { + if(iot_sys::regSysService(strErr)) + { + text+=tr("设置系统开机自启动成功..."); + } + else + { + text+=tr("设置系统开机自启动失败...错误:%1").arg(strErr); + } + emit sigLogText(text); + + }else if( Qt::Unchecked == state && m_isSys) + { + if(iot_sys::unregSysService(strErr)) + { + text+=tr("注销系统开机自启动成功..."); + } + else + { + text+=tr("注销系统开机自启动失败......错误:%1").arg(strErr); + } + emit sigLogText(text); + } +} + +void SystemSetForm::slotBtnModifyClicked() +{ + ModifyButtonForm form(m_language , this); + if( QDialog::Accepted == form.exec()) + { + emit signalUpdataPage1(EN_SYS_STARTUP_PAGE1); + } +} + +void SystemSetForm::slotBtnChangeClicked() +{ + //自启动 + slotCheckBoxSelfStart(ui->checkBox_selfStart->checkState()); + + //语言 + int id = m_groupBtn->checkedId(); + QString logStr,language = ""; + switch (id) { + case 0: + language = "zh"; + break; + case 1: + language = "en"; + break; + case 2: + language = "fr"; + break; + default: + return; + } + + if( DataMng::instance()->modifyLanguageXml(language) ) + { + logStr += tr("切换成功!请重启该软件"); + }else + { + logStr += tr("切换失败..请稍后再试"); + } + emit sigLogText(logStr); + +} + +bool SystemSetForm::eventFilter(QObject *watched, QEvent *event) +{ + Q_UNUSED(watched); + QEvent::Type type = event->type(); + switch (type) { + case QEvent::MouseButtonDblClick: { + if ( ui->mainPathValue == static_cast(watched) ) + { + showInFolder(ui->mainPathValue->text()); + }else if( ui->backPathValue == static_cast(watched) ) + { + showInFolder(ui->backPathValue->text()); + } + } + break; + default: + return false; + } + return true; +} + +void SystemSetForm::initView() +{ + QMap versionMap = DataMng::instance()->getVersionInfo(); + ui->label->setProperty("type" , "titleComm" ); + ui->label_title->setProperty("type" , "titleComm" ); + ui->label_title2->setProperty("type" , "titleComm" ); + + ui->versionValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_VERSION),tr("无版本信息"))); + ui->mainValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_ISMAIN),"0") == "1" ? tr("已安装"):tr("未安装")); + ui->dbValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_ISDB),"0") == "1" ? tr("已安装"):tr("未安装")); + ui->webValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_ISWEB),"0") == "1" ? tr("已安装"):tr("未安装")); + + const std::string strFileName = "hmi_explorer.bat"; + QString strPath = QString::fromStdString( iot_public::CFileUtil::getPathOfBinDir(CN_DIR_PLATFORM)); + QDir pathFile(strPath); + pathFile.cdUp(); + pathFile.cdUp(); + + ui->mainPathValue->setText(pathFile.absolutePath()); + + if( pathFile.cd("backup")) + { + ui->backPathValue->setText(pathFile.absolutePath()); + }else + { + ui->backPathValue->setText(tr("暂无")); + } + + if(versionMap.value(QString::fromStdString(SOFTWARE_ISDB),"0") == "0") + { + ui->dbPathValue->setText(tr("无数据库路径")); + + }else + { +//#ifdef OS_WINDOWS +// ui->dbPathValue->setText(versionMap.value(QString::fromStdString(SOFTWARE_DBPATH))); +//#endif +//#ifdef OS_LINUX + ui->dbPathKey->setVisible(false); + ui->dbPathValue->setVisible(false); + adjustSize(); + //ui->db_layout->setVisible(false); +//#endif + + } + QString strSysErr; + m_isSys = false; + m_isSys = iot_sys::isSysService(strSysErr); + ui->checkBox_selfStart->setChecked(m_isSys); + + m_groupBtn = new QButtonGroup(this); + m_groupBtn->addButton(ui->checkBox_chinese , 0); + m_groupBtn->addButton(ui->checkBox_english , 1); + m_groupBtn->addButton(ui->checkBox_fr , 2); + if( m_language == "zh"){ + ui->checkBox_chinese->setChecked(true); + }else if( m_language == "en"){ + ui->checkBox_english->setChecked(true); + }else if( m_language == "fr"){ + ui->checkBox_fr->setChecked(true); + } + +} + +void SystemSetForm::initConn() +{ + connect(ui->btn_active , &QToolButton::clicked , this , &SystemSetForm::slotActiveBtnClicked); + connect(ui->btn_modeify , &QToolButton::clicked , this , &SystemSetForm::slotBtnModifyClicked); + connect(ui->btn_change , &QToolButton::clicked , this , &SystemSetForm::slotBtnChangeClicked); +} + +void SystemSetForm::showInFolder(const QString &path) +{ + //initView(); + QFileInfo info(path); +#if defined(Q_OS_WIN) + QStringList args; + if (!info.isDir()) + args << "/select,"; + args << QDir::toNativeSeparators(path); + if (QProcess::startDetached("explorer", args)) + return; +#endif + QDesktopServices::openUrl(QUrl::fromLocalFile(info.isDir()? path : info.path())); +} diff --git a/product/src/tools/workBench/SystemSetForm.h b/product/src/tools/workBench/SystemSetForm.h new file mode 100644 index 00000000..72befa24 --- /dev/null +++ b/product/src/tools/workBench/SystemSetForm.h @@ -0,0 +1,52 @@ +#ifndef SYSTEMSETFORM_H +#define SYSTEMSETFORM_H + +#include +#include +#include + +namespace Ui { +class SystemSetForm; +} + +class SystemSetForm : public QWidget +{ + Q_OBJECT + +public: + explicit SystemSetForm(QWidget *parent = 0); + ~SystemSetForm(); + + void setAuthorityLabelText(int model); + +public slots: + void linkActive(const QString &link); + void slotActiveBtnClicked(); + void slotCheckBoxSelfStart(int state); + void slotBtnModifyClicked(); + void slotBtnChangeClicked(); +signals: + void sigLogText(const QString &logText); + void signalUpdataPage1(int model); + +protected: + bool eventFilter(QObject *watched, QEvent *event); +private: + void initView(); + + void initConn(); + + void showInFolder(const QString& path); + + +private: + Ui::SystemSetForm *ui; + + bool m_isSys; + + QString m_language; + + QButtonGroup *m_groupBtn; +}; + +#endif // SYSTEMSETFORM_H diff --git a/product/src/tools/workBench/SystemSetForm.ui b/product/src/tools/workBench/SystemSetForm.ui new file mode 100644 index 00000000..9c9f1c28 --- /dev/null +++ b/product/src/tools/workBench/SystemSetForm.ui @@ -0,0 +1,712 @@ + + + SystemSetForm + + + + 0 + 0 + 615 + 455 + + + + Form + + + Qt::LeftToRight + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::RightToLeft + + + QTabWidget::North + + + 0 + + + + 设置 + + + + 0 + + + + + + + 工具设置 + + + + + + + QFrame::HLine + + + QFrame::Raised + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 70 + 30 + + + + 修改 + + + + + + + 快捷工具栏设置: + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + + + + + 基础设置 + + + + + + + QFrame::HLine + + + QFrame::Raised + + + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::LeftToRight + + + 法语 + + + + + + + Qt::LeftToRight + + + 英文 + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + Qt::LeftToRight + + + 开机时启动工具(推荐) + + + + + + + + 45 + 15 + + + + Qt::LeftToRight + + + 中文 + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 基本: + + + + + + + 切换语言: + + + + + + + + 0 + 0 + + + + + 70 + 30 + + + + Qt::LeftToRight + + + 确认修改 + + + Qt::NoArrow + + + + + + + + + + 基础信息 + + + + 0 + + + 9 + + + 0 + + + 0 + + + 0 + + + + + + + 基础信息: + + + + + + + + + 6 + + + 6 + + + + + QFrame::HLine + + + QFrame::Raised + + + + + + + + + + + + 0 + 25 + + + + + + + + + + + + 0 + 0 + + + + + 75 + 25 + + + + 授权信息 + + + + + + + + 0 + 25 + + + + + + + + + + + + 0 + 25 + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + 0 + 25 + + + + + + + + + + + + 0 + 25 + + + + + + + + + + + + 0 + 0 + + + + + 70 + 30 + + + + Qt::RightToLeft + + + 授权激活 + + + + + + + + 0 + 0 + + + + + 70 + 25 + + + + 主程序路径 + + + + + + + + 0 + 0 + + + + + 70 + 25 + + + + 版本信息 + + + + + + + + 0 + 0 + + + + + 70 + 25 + + + + 数据库路径 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 70 + 25 + + + + 主程序 + + + + + + + + + + + + + + + 0 + 25 + + + + + + + + + + + + 0 + 0 + + + + + 70 + 25 + + + + Web + + + + + + + + 0 + 25 + + + + + + + + + + + + 0 + 0 + + + + + 70 + 25 + + + + 数据库 + + + + + + + + 0 + 0 + + + + + 75 + 25 + + + + 备份路径 + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + diff --git a/product/src/tools/workBench/auto_start.ico b/product/src/tools/workBench/auto_start.ico new file mode 100644 index 0000000000000000000000000000000000000000..4d3d30aebcfc173d924420f4cb980c959f5e5183 GIT binary patch literal 4286 zcmeHKyG{a85It&viG?O6YA1z-i6tL^f8Zzh36_>_Sdh}va!c*}gf*cskr)$@P)cH9 zVPmI-aXkY&uwM7>1J)Q5mJGw4y>rgY+$X>SKjkvy8<%Uq27p}(P1vW1T^@(;)>lR{ zG|a#LRR#J@R37SZDgJ|tXX;=mE?%fxlxDw%O3_JmPEqaF(H`?DuU-3n`pg=K?_imn zUJl+-JtlE^f-y}TJqKIN`DO<0VJw2tZD2D`3=(q@+#0)J<*CDrH8;mV+g_F$$h^_G zi`Jc5`kW-EUo@}caU9x7HITKdeN**l&1-El>!kgGoXu2TSz9iSB@gyJ?7Dc$edJHoLF6+VpRpKUwcYjNePh!IoQ^-LvIv+W-3gA@SV) z;r&bNA$6E>ET+DHY7C;oIqBz^6K$@uY80c0-{Jj4_V(7dvvTxbMB;PP)^`zc%rT0q zKoETfr66z?f=}S&1E{_O+aj;Ps>lE+4HhX&BG;5x$~$EcwrOV{?XUiVC76O82uI}k E0{67^g#Z8m literal 0 HcmV?d00001 diff --git a/product/src/tools/workBench/db_check.ico b/product/src/tools/workBench/db_check.ico new file mode 100644 index 0000000000000000000000000000000000000000..ddaf3a2fb2e0b5238d3d6cb9bde1120d0ddd7d83 GIT binary patch literal 4286 zcmd5;OKuZE5G`XwkdT5UBvui4g;;U}M{HPz8^o-#BsqaC*-n-|LRhlP5r&*#MDS-B zZeR|8G`v^SWtH3G@x&8LbX4i?>h5~gRjLrEYDNLEp}_uQkyr~Ao3 z?!9i)IEDW>Pt2-#e&2%kzZ*$+b}1dhFk3d)IJ$MG@7dlR`*X&Ad3GSDv~6>anYS=c zIk)x`F|&O;_KDg0HITm9;9aMP{}l0OTuhICHAkCsoY3dHfqX9F7Visb&mo4-p7tRr z&zN3qP#5B2`mo>UF`Z+N=P~VQ-U|3n?yDc*EPXYhUmk;F^4iwf+aAV+F(R(*dkFt| zhW2R3gmdbB+q4HUxz;=E$bVwYqr1g9DceKr*f+aJrQYS4IE*vSjV->a3m9HUJzHJ= z`&g4Jz|L!y<67Wf##-cgN&Mx0m%niDO8hr_jN{T4a;mmN{R?Y}+KuXAz*6oQ4}Jc& z@gMg;nGNMF@$lYnSOYj_Gu!!0glpJ4wz=&wT+Vl_|5|^&U9(LeV!fX$Hr{K^`p@_+ z_-;*V+%{OcBfU)H7I)ydgzIjv^xKEp`FRpek>oGArrXL%=e*?4&{TPx!w#7%e zhkcB}m}hBUYw`&33H%j@$DReh)mZje%W-U)wRZ_+@x;Pj2k}{>?zpQ2QGW#Qky&v-ItS?VKiF6O-=wjTI=50#`x1w@^ zZ?-R2a`f?_Deul&@&iYu~YH#Qc6%@tQzSZJ5R zA8^-QArdgVDx^r@3JZ%9EFyT^`hC0mWOm)1+-!_knD8>0dEfWG_ulT#gov!+y|pF$ zl-C;~S4HF|3`=qc#&y1Y_^w>cEM54AK0XC<3NVm18C3xwm$o9=-1|H%`1>D>UeC$7&Vu1%jiS*#NeNlW1nYk z@SW@buP;YN|K6Ub-(`%!cj|vUke+fm9{6$rv4e8_MRSd@2v_i9uTWljL|(%J)^hI? zr+gO#&QGJd)M|q}{aesUs$edcHwtgS^vcYGV_Y*MLUKYqJ&YKuwyk!22mENNR zxknAvvyI@r$hi+}IGYdr4r4Hu4OitOhg{^|SU(QrVXnVlrD0pcZ}Hun`^<*3`Ox#H zc@4WZT$L|+BDZt>DbCmRDvWIn9G=Nj#)$iJ%Z9DPx$=t)FDR5(wKlTS!gQ5431CtZkBRvK*rCn^FhOo)q-gkte zSe?`z+23>^#85WdvM>ca2_YHA<+Try{G(ILB9(LjCyGh^w?bbq%V|1g-f^37;1m%1 zA2?T2NC&et8xl(pN$4HF^Om)6rXCtLI>^)aaC;1L+BKaYJ4F-b1HV(!%;9#?O*E$+4BWY$dGu>79{?9r0-l|*G)!TISXe3QN zk2Evgwcfh#J?A~Ez`~Zx2q?hA`t=@GjCvS8USR+B0{o>#h_HyRVhKJ9mO#Tqf;Zg-;dep$B@_amhes9! zq!RF@{%Joen!&T5)f!7rDE_Jfzzg*6^jYXB{%Jo83L(6(3>D5mcF!OPXD~T4gTZou zv6Cb=Z6eU<;}^E3M_>UUO$=2+It&bUp`?1?qX(+c3#E!Y@d*ed0q7@5h4f}8dK1@c zYL_fvk+dPeki?;%bWI^D5WyjYm_k`hVSH?6LCQ2W!o1T0Kx&MY+5jJeXL^`gRzlxI zAA&+3eANRGAPg9MBOUBH@&-Zk?=iWj3m%p>4rm}M2*nf%!6YX8C(*OFjIn#A*o1Jl zmpht|TL6gjb{P~n&Bx&C9>`z-MbQTYUCa?kItarRteSHq%?uYbDwHf`h~uCzgNmAj zR~X0Gjw#^5Z~-jwi#_H6qOOC79cTLJ8tTEs_j;Q`>#0sLm5EH-Zr8lB>3{Qj5%2$Ss%rxmbhT|dOsVtD9>he9MNjx|u!n$a#; zBmziGK=mBJ!L1Y6^k8r-nUIeOfUp|1_rfA7;bMr&AY`Rm`yqUfSIvd3_6QJINUD$@ z#w$)k6~|EY4`A7?m19BuI;sI;_(eBLOP8QBy+r#bgwMQU0T`_<3wF!`0!mm$v3ozt z`}Sk?z0*fCP>xD~FfblCs|(9|mLgP3;D@Dz1*)~Fv9Nd62#{0>{W5&9AA6_v;q<#^ zjz*vyRRGZ(M^ae3g8e9Oz9AMi5rK>!KU2+VY?wUE8ILc805Dxvg?zAGdtr~=1 zUIrm3n!qA0=1 zQ$QJgJz9}ox^Tsh<*@aKvIWgZY zUGo|sY@s?a97LfoghHizUQ3NcvXZ9|R!sJvNwFm(0;z-?B`iIt&<8vZz8_~A(&w}( zPp8XrE=Q;c6%c;NpHtK=sVqc-X|mBz+Wewm@YGA%nnNtqzf=VXiqi;!Q9S04&1Xy3 zyakB5?z9p{m#;+VFXiy_`6e|e35la$eaW#(w8B#;i0@(}CTLEA>1nB27 zKrIGDKcM=VM?p|lA_2pPFeYlHD0wM_5E4*_Sbv9@02KW^2w)EscJoguccb7PLLe$Y zSb^u2ITVBdOTHim4Do=%{Cd|MZZ9hE!+jXqvrAkzKMDN&8Z=rwNu|2vj9&CCABGn! znpY|nfkG5Q4Tz$EDtAM8U65W0P=oN)iBLEJ5XS*n$H0IpQTc`FpQ5BJ0)p}&M04Y> z6b%c3C4}J2Kav{epCHT79spYbwFLr?LyE@$F$PbTq2vriX__S(0Y(M>ya9_yilnuC^*+!_y|Gy=-m)v8I(E=%6kfg zdJ=$P02C$M1wo(?b8JOW6(~`LP%{9g0gOP2haluHA;g1FYA-@e!^ady<`Q?AH(;p% z!aIaR-cEdW^MUyUl6eCVwPAyg{*k39ieX-r52s2+>PbOr)roy9l#5QeBjR`{^$Y+{ z18@SA=!F1%M^a+mjHOx6hy#_O7!ahUJr3aK5aK>a^#rSJl5*22l->6b5Fg4YHZezw zBddWV?J8;n6T|z&rcLuAM}A(sRCV3@0=86!P%N!DtbBu|g$h}JFQ8j<1@AaOJqr-O z3#j9uL?4H=KpbJQUP^KZh)|P&*aE1#p>PibfkjOqAn8JrR2)7P%<_^-c{h$Lj*9CJ ze-`6m2Z*}xlrF4Wxe}_ll*2_1hvcvcK_o4TUN0)aa`@tzPTQ}c%+;zp z+v{jfW5~byH3WWuP~C%KVGkPTb;<#bhHOQk}5L+uvP31K>atA zdICyKz%K<*6`grGmz&LE4Ag$e!VdA-&BUn=%XZiRqBfk>gTbEFhs9E5fk7`H-eO4g z6nJ=nR->>KU|w-7Zc_mE8TISCOzt5M@FFtTK(Qd9!VzO?huCx%-P@dRhXo)EjzwK- z;D?LmRB~90R1kXb{6+BPX#idVfYhla5Q50|!lqOi0{a2n1K=A7y$2z~gD8;CXAaH8 z79^p65C>CrS6l#EO6}NF0}yyJgt`d8a{xgSV2_z&*LTsB$PBLczNf7e60Ebnl zxEhBd!uK)nd=0>NAjNJimFGz9qIc@6{g|3N;yxz;VN>p^ z;Wa4Ck+mu^+lqep;&cFi$~*&NQM)r_;dmMWbr1^oLg0%C)dMJ~i8+xbu61kY$o9D~ z0e2iA>WVXq2)kCJSXkQexGKvv=pA|(hEOjB#7hCJTHqNuLt9ZWC3XPn>rmqBkQm`B zbefyk_^nE?5B|&!vGHE&oYJwaqX6OXk%1j6;TMNG?gV7qDvl9&Lc5 zFSm)0-$B>Ted`E7)Fo&1VPMH|2)(|J#a3A>Rahy&_s@X9YXNa4fUev}Y2k#ejKB<_ z?uEi9;f41@7K4sjxpeyRB*yn|5jWpI*~*PJvv2MI;o=H|!|Nc+OHk}kN<@^nM0pwV zYzT2V0LsZ&P^p@E>z&_+;=3M(QX8SXJDHbs(iB|bf)EGLyKSrZNWQ_1xdMc9$WOsA z3UWoq0^BSa52;w3xB!rsLSfxe6KUJ|$vZb!pon3CZGiV#NOc?hkeqy-Bk!EMSx3R{`(yP$2=P*g24dhv55L#K$&M2!GpKE&%B`@34}?_f|rPO96HO=HeCS+@Xc7 z<_I)fSEBI{s)K;|I+XexLbvHp?CnJ2{Oe@u16X1%oq z5LT^L3>}BESe$#Q+$eN}2sthT)E@(4px%?V1B`Z#o%QI?;{%(T>^1Jc@v&+g5dR6O zJ_lb?IimcDJ4I-f)B)@s-O`S#HEV!yD9IHaQmvv|RB{m%MdFJ8Q;(3hGPzsXm)`%; z&QMyJ0F5Vp5;1l6SJ)4sz5szQL3#&s_mjA)*2dd+%{COJmGMbDy&|iXq}ovE&edwg zB{Qi@5uI03)*pGuGflb8PWF2HMF3bJ>*?9ef7hEJ%>t(Oeq;j1Cn3H6(#}LGIh12< zE(Qsv;oY8!<3Cxqb-bE2vHb>!c`D>85e@i*lGc! zp47+$ic-}C+(?t7otW2xbrv`xfTY3U0;2_x)B(^m6ut(58=-ByQZZ6Cc|= z+6rNB4IosNq$@lr_i&Oxh1`r2-pe#VxD-#-)(kirfgy2@43IRIQ0{7ZWJnNKi)_?z zAw7Y4g1F$Q^*isDoKCgCP!l9d?PGvIevO-d7INexoP}7KLZ$dfD^*dN1_*o1_nbY9 zvNxP-u{X;*WOycgaWxc9tQDD?NxGf4Uj+^a0MW52P`KyRr^=Qejre+_i8t3!n*IF> ziwAARaydxqcUR(M{XPqT(BMA~p>BZk@6DBuSSeBncVYRRBh7l)n+FILd>iUM2{K#t znbica&Oqs}hQONvoLeiWqmlHe2@VU046vjD;r<<)f74G!-!vGu)YnZ9a*Kml1?7gi zVaC0in~U!;2@rZ#iwis9qn}2)SSgbWNQjR>{16I%4=>!2yA#pFG)AW%ZMFbiQ}0e~ zfRAP84?|W~=1QKpzn-KX8-EUnzoq(DV;IPNk{;4HKEI9NGOA3;Pv(BZc$tm6; zpd^h8naXGjP@_(0dUqEj^oRaC8z2c#SPtTFky?_+-dF=NPcd8n3Wa|Iyh9w=nAgUw z^NPE$_rFKPChpc%cWV+LXZ2u7_er{EMot^4R+LLF?RlDhsTa!r=A=l&*Omw=$?GP`YUPUnVPzOXyahs>S1(<*8R_9p@+3H@9IufS zl1lW3fDA$V#QQ~ZgvCdC!p&Zvk0*RHV6iWww&OBBUo)U+^}hKY9gw)H6;F0w_Zbx) zNfiShk{Y!@QbVFNDMjcd{SZpM4}Nh3p(^C&Wv9hisu461g3=fue|2FO$`dEUE96(M z(^{>R_X-GH*(kT8%7mLCF$e`Tu`<4*+!2Dw|a5-c)iwb9_s^3ayAH<#B+$UVAn zPzLsl0FV4H@ZdcV`$iy?gz%_gZw-)SNRMXCz|r-!m;E=8>KX{|H@O8gT8kFCx8ug! z>eke%4-g7xU%v9hT)pN*%((@Dx*P%<08v*mwJJTV>J)*4Bu7sl)N@`4@w`6*maXJE zb}%m&EpPX{c?FLVf2;5Wn~_ z1bt?tNkW3;D@CTDun9`s#H|V?DC1c;8gdf^}nlk0M;jA)5@fg0AR zcLIWH=GF&kI#$Z6S1IYiKyoDr@r^KmDs@Ah`%;KMxENSE1cV_=m1rU{K&ZnQKXI1! zl3eYrj$Tjjq~;r`A=WZxze?<4RR4rSuhCpjUxW5f&-2WSnGrXSTOUt$C)T3?Qmbg& z`2^HgKLPQxJGCTXZerA|8hj*eB5sn07+q5B1aKWH)JKu-KZllZwlZVTw-ulIcFh>A z+5n-5-KY4+p)xa=UwtdDfnw)`WKAk@W~zB}o+Azt-1 zVATmgrEGveGnT5-n2F0TH96x+laACc^R@m#lf_Icj;3}=eU^C1nx)!w8b6ymvt6{* z5JisE<2`6{W`)l1EaWH2U@fWd66dg1EUl*6;o;dz&3%0zc;pvQpLq|&&c`AALPXqM zpz!1}(xeT5&{Zk@=~jf^KcV1_0WzP0Ym~oU>>9%_!!5NUeQN{ck_-CKHFYw4zm!Y9 z2T2b-!e;^ES_rIcMiEbXx?Mkown9b3JjFj`P=V^{hj{U&!1*s{Voug8YpAiSHN7~# z2G4tEy7L^NspSC20>zOChM5}4W6z_37X#2N?-8&p3AR3%_{2QX4F(B}`UP2=l>^8~ z+L_Ndjm84rT$_i>6^jPqdVMhP(E!s6hIwA|cUp8>pn(h=)00r&_*dZj{{c~+hF73I zs423ZMc(Up=Nrt2T~OkBi103b<2gx@Ff3!H=Mi!9ZJAXWGXc_>Y(cLA#l@xH1W>`Z z=A1v70Lf6VV(wvpQ=Wku9D=y&T@a_70gyytH7Z_FqbZURq^MWFSg=G^DKqo!${ITr zX>!mEb!CbkUiw^_JfKK&*cIFA>z=2j6Q7?-4QrJ#DWS|w@rMosW9w`x)g>YNqQ})Z zHDEBSJj=$adym!5q#QD^eefs1r*D8buot3ON~l>`maQx)(kS}Z0S&c-`wk@jfs143 zAw`AP?d(?MXYh)~m;eakO~k1Z7B?#m^t!IGnUo@06lo|}NumuymV(8i&;o$>Wq}fV zZZw|Ec#*`Vu`3iIcRU95kADNPcPB)N5=&zqVo5s#ppKf=0zhb-DFg93K>bf{QiM(v zs!3q{k*r=LH30Jb#Sqgc%8OFK)J*Y$N^=Is23W1uwcZ5hWx6Wcg}% zZ~i#Ep*8UYWR=QH7h2g}B_x{X?gZC5xL(WcrX_`y7w zAT{OS804;PQ2TZP(}(o^boW9mT?udHT8KqUAbR?Mu3iX|f-*Gx#c@6I{pl-{6yOPL z)FeyXHP9V`?&xD0cn+AXgfWuJo{OK)s%E7kPZqi zn$3eml>zZhDDOjnI*^M+%aV1~{kYip-2-VguL>X>ceQx^DtO^gE^$}n_n<66Po4qc zy$8VRMwY8+8fI9qB7&YFIb1a>EKdW=*1&(u$01g(1}YW9CroUS(UGi*WL2nWHFm68 zv8-?icf?+;{BTxjhLfW%@mC%csm;?pZ^GQ>qAh}hX8WKNlnw(T13RR zrx)J3C!z4P=b~`NSrE&H;dS@u{YV8fDx;OO2|nfOhmnWefYsbz3}y`wjS>ARtAx(q zk$z@@UnoG0?m+my*8_XE!!LDbt5~k|NJ)~`0m3)814_OP(z~Cdee+1H;__1dC=P7i znU2rO00@=xS$=YEtqVwckg6u-0m5Q9OG zcb{~4V@9Qp)nsv#Gt(?JNP2j~>rg!RMJS#12k@4!)GNNCSUbbG&4VQ*VtOSqBtEei zB!!}3CeD)Jo>0ps4WeR^0TR6Lbr8FE!0XZgsZz6CpGf-vp*3NeE1`JaO{^N_BEb@5#Tpbyf{=>E zCGz7LlbF+Kx!Uk=bE3rLNgia^Y7jVNh~PIr$IO3y7Qq8QfjV>$qGtg9iedOqdK&zb zo&s;hYIr^Ud=fb|0l9kz!pDAv@S&e09NhsmH38AL2!+$1h3<=Au-JZ# zRvk4f0gy<&%By`rlqpzv2_XNvQOs3(Q0f7snt#LqA(Bq3FG-N%TR#CYq*bgr-$<d zh?(2Jf$)jna7>wh^6BW=@H!Nqb~gJU>Vu?1Pi+8FdGD2x1c{}G4nJ|FNq$6~2k0Q+ zeHaM7kz0(GZJ&@*vyuSG+j>Q&86}nj-n9VEX|=&kGXSYF?;15LoSA|k3G%j2K&;RJ ziTn~gXOe$K(s@)3A}+N=)T}j(EXx|;VoOG`9o+d zQr1js?nfJ#oY_b~@jS@AyD;@@fD-1-D@NT+%2gG3!BU0;GloivdCeoy@#5nu8Qc zf-pdWc)4^u)y9DkY1!I5X*3=7qFYb3i7;WOpK*H_pGdUs+k<@{>cAK#zxdCX`QBFm zuYm3sY(VcHUk-2CFjP=>tVNLvMQc~a-{Q`7Es;EkLIHB$C=Pw?Gno3;7a@WQx_4<5hPP-CLQ)*41%UD18}`6pi9liGODe=BGCxET(Lg5ofO;Tk(H`A_@_Vji4nic| zqkF6c65~P7NrKSBQ4r(J@Tr}G-#%GqkRgC9?{K^3#sJ~=X>uJrHP|*9=^c>^Ux;Bq zydO|cYlWO!u%rRf$i%COI_1JBgk%9CfLtA`SjK^1U3YN^hn|6sC)|R>s6B4XUgSd8 zYEa};u?{wxbW&mFz8_-Z#_OQ=?n3Fz^U(L&YfxBog7L>t0YQ^bVbn1bsb-WEn;jc)+Sr6zG)wco9_{uvaP16QKb{6 z;_w$UELDa)e$*nFdAA#YXe*YM9$rk)UB{sTNScfAb*qzS8ZZ1hKIrFw`a38!!XZ)Z zZfx!qV|X~O!WaYO!c)4icHJrPR8QNnSCM)po(bUHfLJk`dv66Gu@x%?5Fk+MO7v4*c*=jLp5F7gi?*o*N`z8lkb+yZ~ea`eCMdX%2| zJU!9K*=JXBn#>`YpIwDYpG!+A!BT_CyS;a#*H?aeJH|hD4Z?l9(0$HJ(Er-E!CSNp zN(PC0tsZv^f>)vF9s@2mi#7rm$`6!{S!m3^WGFtIr-lQJj>E_nfR(1T=u)9ON(qgv9ZWAmlp`s68mQY0cu|a>Siu9-`G<;vc_- zwUFV`w)uyxu^R?Yh9^D}li!ku2w?Hf!)Pb4xwv1bEd1y?iNd%BC*NUYbhMCU7TvaT->+OJi zBSi66xzzNf`CBaR#ptqaV$-Hj10+xX2S@HI%4vNel=#08Slsg9+l4e0$xCylwgk}$ zQjsOg0SK9S$?=xhYD^OQu{&84$y3ou+&vA+Eff&$9mRovd;=;E-iy*{XJYZ+eh`8( z8TtC=7zW4=j9+^h!d+Y8b#dW(MBMby#%$XJUZZv(P!l_Tb<@y$R*}??TaB z%U?DWJ*y_!=1JU0MNMy#IUyFIk?s&bpA#4#KfN*Y&fH*BtOP((WZhM-@(0KP2=z}; z@>`}0vPpZK?W{{i_iBJp&E1lGQZ9W4Nkn;a5v2G_2vDnLdi%55T9Y8P0CE$=(5h&H z#+FX4ODEKRdzVqJh7)6vP&(5Yf#yI80pGm?WAA(o!tIYT{}{O99T1C`Y4ymS!vf?T zmqG5@%Aw-bTWx^wT&8mz*oW~?y_b22zve^?UiT?@D^}?WBzBRhdO{O~7-b-8>s?j? zmBw?@VH&wc>PnC~1;`8(z6wwM3wNq&H#W=mH!OP(Q4L=sLGp~h3d>O5N_gt;*-1Ei z6Gc@n$ZRDDa}cY)ThnKhJE0+>^B^oQ(VvjzO2-1)G}x$)v-W&Dt1};2C?edw9b;Gj zIZKEhR(swGv3QVIb-ohu2L{MCj9>ezCIRwU?d;^77Gr9liY(*%F>&(;F!kN9z+1iw zOW*x(@K@@%vnZ(0-hV8=tV1Vq0Y&M$CYekpZW+s(dB!**Ub7K46fg(5T$A*}B|-Em z`cp{pW(c{fZF6rbE{mR9w=@vpsn$G%vXRvjJwZ)6D~nB& z^TB{I>O?BcRdae{6LMLqak}yOT!#Zs{GD2YYdEm2qgPJHrvy9E>UQ!A?hZ+Y7Uoh!9_K0Nh% zP z%D=dqImnW~{UAIlYeZ24S~rLsj;=q)CU!+xh*9W((E%f=Y0_|QY73vz41iyN+`WCi z0AvgT?}ZfKXH#Lj`RcULL+-(EiaP`obkTPLLVr=)t(=K}$gmH-xEP8%|(K| z{U)uR7`@zLAqH+HI_l%v%~@`)@-1Oy*;1(AXDG|GA2I%A)Z77ueloC z><1~v8G{6*JtG+Z`@clUeh@D9l)5#=&P{*KNf>zRzi7!ox#_e~@L~{P`i^hn;Kmy` zq<-L%|BIdrHfX|64#jA*DpPCE)ll*iKz8rI%)90RK)5WB_%_1u11Mmu?dV=sv&0m- zyB{VA(hI-$lzbw1!!mqtC0Cx9W&BlQ4a>vKd(BOpjKr(2X35z#q|z3fG2BfWPye^ol zI_e<<+LrquSZ2ao{LAFw4s^86GFY}+!ZJl zR=3^KnTQRg*cSb#1M+>d4N%Nmg7jRYNqRhS;_7O89yx)5HpD|m21b612q@9V78r3= z!>E=HNBBz2-1B{m-}nxMdv~Mj8RxPTDXcw-Em1lUmCix&SGJsx33a!5|B$*<5|a0F9sA4c>H$&e_OjKGc@_ zaw4@DR0bf^^Fqbqr`Zi9-U=b_Yddh!wvH|bJA}IG{51&WindL>LWP`1BJg|;L2lE6 zrHN|1+;Jk*EIjGm*L)I!oM%+0H>+raHREcm#Mya99ZQmVt)lT{vx~Al$l>~`;6okU zhl!g%i0SYBCrg0t3toZ#S6sz`g_>-WW793cHP|69 zfRJ}t7p*oIOog$>tA7#>3EG^h2%`6l)s8rV)_~0OQF-)N7~l9#&L|WEOPECWzW6WT zlU0q%_7ItltV3Be-F#;FiJUm7eIb1V5acMN+FDd+i&{Hm(0qN1R$7@mHal8_T9n>W z>-b3DwQGZcAWM*)n10u553i#zdSz-H5E~)z6;KDMb|ZVqWl<^Y6YACHoP>f{(zXwT zOuPd9fO;*U{$w^8glW9w4v=;c+sg42(yk6d8A6a!G5ftt^IcnUYb-YJ3#Sr?$=UmorP?QZ`ZTV zhZtM|QS8#DUIGQHP?WDu*`G69WUhSA_c8UuZzA0CFwonJ{#U*pJs18NL|1QAkUM$= zH!3)xDOFdikDksM7l(MorCC|)imiVfJ>+Q>YwG%WB0&^aUAzTSd?=R+@Z9K0j0<(e z`rm>SeQi4lN%n`{G6+yZ&gaE%yAcd(e?M!0I0;id%t1({iKA&F^}AmpB%s66%{f`|SW;hvq4QD9gEpzy?&n>E zuCp$HH@F;vi&>i-K$CZFjc5__$B;$OVobPERBz-uiDTkpyqMo26^lsv zw!;^!7|$vi;=6(H>fA~J1(+7UElG27(=cGg|&BD3l=-4lWaE%7mwnWO!SjAcNr%l)#eR%??CxyccSw1I}mPp z#MI`kfJ=_jJrZar1F@$M{s~XveD>l~p962%5Sw)g9LzhSAVd>}XwB4S=37A*1vuKu zCaKjcwp~~$=`~mdp5jznt74Iw6TRf9(nqzBbFERa)z_Ft-Q6?IMyU_8{@hECrs2)e}kClJL-`&RYw7hwS>L9 zFlfaphSt0Uh~dv2jd! z+*lsx;5N#}%Rzn-uI}!{S`~`AqKVd*4v(d(-gB~w<&gA5(S|uqm~!q?Jq~zRL54eW z0fO~XL42PXY zX0NQz63+Gpj~f%*gpJJA^%*P?anbjhNb}Q|sNw>y%RhA&N#j&9bS7z{vIjcXulGc3 z#qzk^&mn8YnjZk!0(e&dYCD9ObtWr6y6HY8)L)+a3iJLqn z6dkv3Am6P+`ZZD__q&r{?ljIxgT>sCZI%-o8{+fChnQA%hG)ghB*rjRmS+j_uFIiD zx51wm0HJs+bvcySnhQWwD35Z0tY!{EDi#x9D?sezk34a4??S6~>q%j<=&Y59CuYRx z-CyILfrh}lWqcwlm?h5^lMb$Q@oFt2VsKg$lp{GD+d$ls&9W;CBuCEhN$qo(Wg+s9 zn5T4F%f&H`@p8Zmh0PnYrZTD(%m8^U7mz!80diEUSVYoIxH}bFar7$d_)5)kqsPQ- z+)6R4pu~!bbq*T!$sx4bn3P=2ljZ>Jv~#DR>t}H~qD8VU&X13Q8$}XFlh>MljTtu< zUMAwipvx(E=eCw}gi@5-WdkeY`!mtYzE-j3mjqEAP_d3$l1?1N0Z1Yo!&SDdViB2v zs$Dpl<|0=N#8M@Sm`!Am#NVeaM^&}#QmRp=vCN5z$93P+lB)yS=E zE4FJAOaHqm-sE)zy9Nj7>wzg%k)#RnKkML{tY$&nSM`RL1i&@5A)n|IHrm zXq`{ZX5B->gm$=WB{DcQp`ultvwE>l&CjX{n?53fLkcL&K@y+2e;d0Q_4HV|1_Kl& zeBMjpQRQ|rGDKuPPF{<8h){D<@`FTHEZZMMI|;L@yX)*pZE>4*6VKY>v_rv)d4{_~ z4noN{0=TfhxIkZ-XDbwlJc9;@FYc)XF%uBi8CKuhQph$V*)SzbiXLsPh zKfjHuji5xuq|_-Ab+oJwP12}Bb`i3D-(dZX9p(VbvZCf!HRJMovKc^4SJ=wQGC-8X`Kpp&og0) z@=82V!qh7}l`vHoAgLB?1dzzgn@TE*tV5L8R4HR>^H(wc+4qC8_H-GZ>@EE=<4NCy zeELfTYMYTLhAD1afoWoRk2L95O7`*!9D4qH=9TS!~t>aK6=O*R4jPArC0tiR* znigzsRrgMIn5ud`szV7=M_9^jLx9*Op48>G4nU&urI{*2OyBbZ9Q@d|2>0#;{H!`v z*1|bE>Cuv?XnW_l7`3y+CaVfXe1#@HNsthwQ-23b-uxjHRvxE6%eFD=Qzkfw1CRzi z3Uh10Rt=C2rQ9AtMH{TzRZGQ++8=Pj)HJYi4SJ}uA}376X{lW9#w0;$N3(z&+l}$h zydTp)y&b4f_bmqq(XSajm>O`8*rwHxMpQ*r*~`{ChqZde)~|$Km0tgix}-mLIS!3m zVc9VHUvUMx&wVlHxW_xVdpdSD3y>QwhuXCbzA0WEcbPJLBgH%NYvNfYH9J(a;Rq`G z69L2_=$5FvKV6cZRI#+n+17sI*X_8iIZxxh+YyXxHN_5+FM(ffwSh;Qj}tmmJauh7 zsi@VNPW?+}`I+4lW?oZiT|YCU*a46e8e?k(TT_f}o{sPBL+P|n0d*Q z-fbj^PH=K+VA&UMns@Ttr~k?`QSGWU->9-IWvtQF<*x33Zi7~ALTr3vF6hz{NlOv}x6hRuwPe+%U)vHvkAclVwBB~bmOpL9y29Zg zNl;L~!pL&fae#EHa9rM{N2&F*5dQ$B&Sd9Eh27yOJoAgWC`JXL1ksBa*gUwBd#;bhx{bKv7@92JN5oRk1o- zy!wb~e_&rb>-9B!A(o3+3DW)cPk?jMtL&xqOf=PNeOh|xsh2T~2zQur9fj2d-E|VOWOX=O+kTLawm&#R8t615JrYEnLrsW-Y)k+o zL4?!OtL~Q#Caha4C=tnPk85=Dw8E632xXCbi_=-+DZ1_Gc;`OS*K_wFfb7|BB#5hG z)gk8@Ui36rX7?DXgAH_!kQQuJ0C6l?ny6dPyC&@vizQZQfN+N?4nEXYoLXet7=R+H zQKWCX$*@rtVQhMeJ@n@FRt5LzgZR3RX2oaVzilJUI7`vVd5kKfy2ol`m@NhuC4|Jc z%tSj5V&|(z6W(Sd>fNmd7^N*nmOht5S(&LHfL48~-8Fr~m8@cs1W9<%&57-2dTgu1 zOmYH9=UTAwJImXWl~WT>3ktic*w7Q}2dV2cEKdW=SEK8#H^LiUs{vxHt8s~cV_}CtE$YG?$31NKuAS5^|BZBx2~=dS(r^1{2l6EK!PUOayG~lLofFrzrfxwiYx6 zxJ@-|osnp1ld~jiE0sRCTLUZVKWLIuG?0^kGPbPvY(&y`ZNbcYUkB{okpPGbiYO1n zQLFM*ulRvF*Tj>@V#8TI7%ZML-`YSo1&}JAh?XQ&wo@!!f#P4j7ygrf$59R`@PBk`vdFyast&H%hG&WO4x}3BXyDmZ*s5c3s{rG4Oia7z zZcWN-BvSNHSuEy!ys}`8%cq$-c(f7nUDH;V}f42 zctmK4ijHbYD9h6bZu=s_Z+s4*vZz$1$gy0d{U27nN~=_D6LjDJg!(5a`7J7Awb-PSW-~2Q=Kc~-zydCH{;Y%TXT(3YKZ^3kcS1h)OL$ZX z(j)&zN`h!KB*NRPgFUmysD+huJ0RZ(QT!Fcav_)b>-qceD{K>+HwRXu^>Ed5mm@5# zZo82VJy|8Fpdgk*dGCZ!&uyoWbt?d=mLefgEW$tgMJQhMDhNuPs<&m%s0ObpGu(DI zC#rLuW=~gZzh*;+?JYF8o}$9q|MeM!cizH@WgeADbyO=WC9;Tlz5t;VQt=}Q`3?kX zPcE(3sEvnT-hmr`w1>i2BlxOUpFM!0I4PH2h15*PQ#}y41i+;f?bE`FkXluf1UMq< zMn|!Pl73eCM<_{(3PE@E!h7cLq40ji|0utUkEXBr;Q_qec?uFP=kA505A` z!`1tvCy6ay^-XB@V5>7_k6J>bN?gN=Mg1YGgZz>1W|dg0qmwv1%GEZLB9g}uR4#RN zD=N4BJLEmzhbT|+IBMx(D zD$|Ay^P8z-kJi)Q5N%DjHK{jsu?%scp6%hT?T`oda;~|ajOLYF%vwes-6AEBxuN|! zvrvxjhkX2(kiWbK*u9hIkw@LF3^=N!h6PLwa-Id2))!H=8^G0ox~J{FgmiJ+{(0Nh zhsCWAQ%JW15aJ=H$aV14VB2~eojI=d{{D7bLe~UHh7@r<>`9Q2?LY#>E~sLcZo6!z zsFpmMOX#_8lz7_dYR3kO^VOc7ZpmPN(8w{OAZS3ZuJ|NXI^%!VUq6K|Y0tT97Z(SbLn>_aFn)vA^-{l;doPGso$^;E4)keEa&MU5^^ zg%dZg#DXaXiUx}Yh0^&$M7}w#mp;-}Qe+UqUwu3lUwJLMo_;RVt?0cQutluil6~`e z!klU&W_e||$S`B&6l>Q)CpI#$5@k(lhR{=14Ho*}> zsXGCAeQw>PSjCF{ACVfEQ0q3p$Kv&?P>?Hfak!8*%MVLH;U$3lYd|c@6Ckc6vDU0; z#kIwtqoUApl@z=BYpxMX6;_$7GtrX%1Sd&>gbVSvv*Bp%Hcr zTx)6s49m@{d@a@|@0OhZ000@pNklYBowq%GC}5t=zq{jY{`(9e58KryA(!%e)ckJ0)yM_g5@f(Z?C=iG=RpqITB3lFI2T zj8y2GVfCHJ&nnE99KuOQrfTART>F|yX-^Z@aSh~Re&~OKENz+g?SIQ$&V1z}_GZ9A zs{|V3@_GGkSdW*Maf9#6)Ivl0IK=vMU1L==-PEyh&hHA`SJ$^@uVqW@l#^>rJp}vM zQERTNc=4?KG%LtaRyz@c0YByMaXWz~&Nl}^poB_}v#?2ZgZdjA_?wwe(S4E`Rnc;) zzLHdbsc=$GWhw=TVKr2d&+NF1F^`55xL!@y3>KCES1G(T2ib1bQDFwH6ic)n^s-yG zW0&#VoYCjD;4j`pi4(8ZD z(oAxfeUp_;f55v?MOi2Ct3a4ENT~b7#VWPj)Pp(J&OlaMbAGhP-e24EJnm))?a=AL_I)1`C?HwV&{OXb z>G-2Pn9o34LaH;JEZc)QQnjN)^nWentk%fVp!p zK<8gJ1lNv!ic3+=^7HkOKtysy|9O1a^>A(HS8TCj(c!KZkzN=@6W|BIs@{3i5^>H} z=~1qIx&A9a(g$%3X=Vp_9`1@1f@GA4X*2&BVl9~US{9F9KdKL)b}g^!F(`~~a=521 zbVZyJco^TzP(Au>ye9hT3yR&Eh~H((e_a_Ue|>cRU`_GPscNCDXNOXdg4@1-Oh;}m z?csfG9Glm3f9Xm)Z?rKNx2ho+1*Pm21^to<`ZP+ZBs~1L-sudkVpj|S%RZXr+HlnC zWm7+?L~E{afnGn`ubGb0rJ764Ym2GaJ~u%ow<{+zJj*%~<{zL4TEM=f7kyBl=1cF( ziYY-_c!mxKeq^CwLjW$^>~ae(cT0`Ersc-bX*Ls(KFuyS*oDX7pq4lV7a%x)laGf`Biz0v<%Y?MM~SKl;L~ zHD^>G$Yqtl!d?+)t0>9FUHBxyqgS&*c)VF;+*7D$RF)K6mGXXGpX*Q&xxz4>^lF#( z(ZERTEY9zX?H{{(PHEN!>hE-a4NdG7yLxrvpIFkSG&8e}X!$`Aa1N(`@9iggj(5c0 zl@xPT|1K$1S$|$Ro8bj9V)D%KF8Kjs#Be_Coj*1wu28p|wA=P*lwbd@#3t`Ib=C@r za{b>*<&kzfRqy*WyV6;kO;~d_D^mS?4cIE{V#gcvMMQKp4Kx^IDK2;$zVSVEu-uf@ zcNgGOXVa)KRC7~GW-rkcmtM_Us*P;X3({E*KK)CM=gLp}OP;nGMWr-L7kJO5zFvP+ z14@4}+wKMp9eUMrsZ>Sv4gmK^5ppM2A9vu-%cAR^$0^}Sz_3!Cjr&};z)jEXB7#b^ zN8xR)#vMH8=}2Ic-Lk6XH#_TD^7QmYDNkX41FNI%`>Y@Nq?1$_y2Mno)g$cEH)`L6 z9e1`*7Z0Ts%0Mc4IWLivt89j~Tu6&;Y8)r-uWzGT2~6~52o5ZVeE(@s&eItVW>P?_ z((HMI$En;nFljqE2E&H(Cpc#xXy(Q>q1GJ?PAY%C#H>!J{v@Q?c#CRQgCa;E1wKa% zD>?2oZ+BisH_!X4IUq<&TYP^L{&aS!RCaQMw^3LZmB0S;0esk=O8jy`sqC>^16kIwRm1)bUfF zHB;2iRH=a(1J?Pw_Zp_8Sl)^Wlj63Kcf#gVmfh{H|BWp-s_O}Ef5#uCh{*jcy8RX5 z>kWOhXf2lpJjZy#22sWn{anbn#kOsh2kTMi|uuc0illQ@OY$i z{MW>(QJ)R3@>kls+ZSWa&I<2KQ7KoW-P?Z&2u1G!b<=1*vnkxqg2MB$EYMF`Z2 zy=R3F6`EmURkJ5<^H2J<#@^&%HMIv+&{?0hCo5VZ-3l{{`$hrm`64WHSdEsd&1pY- zhDgH4$bRH}#YfWo+(j=q6_=MGw`a>6Kxr;?UERI^`MJUO%pJ|C!FRONW9p$%KFsz2 zk55EE4q~b&<$9iA2(Rd^qUx2|Wj{Hl;!irC^h9w#$OClu`B9vEy29#Y=i$CoRdA3D zvu8o-bx2?+3d&G-*uuM-psq~2!?Fy2mjSt;Zwtx9+Gb+^TmL@N=dLb$ zyN@g4RLN@!lwn8uiYud@@0`Rb@0n=qS3q*KJkpElH(tMer`HH3|4=L$MVr?sh;S;` zO(YUw(W^vtu;8`iOm;4e(!AVyMLbdDNFA-;wYy^Zb-ovTlX?}JM@J^D{5uN!7=Gjh z;C}i2E}u%EyCgtGgK^cQ<`8oa&z}AlumL9PltI^=^Ru zJqRDwdsEml`w4~Ib-7lK{_IPO-=3(EoUe~2PAoSR! zw{x+h_SuMD^~LyogpUrY_|SFu6?j9(?bINSA++B!hy7onxC)|bzu`?WxoQKdT;%F` zKrVCAeBH51uTe<04UlVB`Jw1l)_mEw7c*D6CgltHSk}8-9EG*1Sy>_02P`jyoA*sq z7`H4N0x{epyR#RHYalr4V&H~GW0U>q--IzfAsp;?FHvaLy#zZ%5?+d`Pc!W=5M8D( z_#N*nc=Q*LLEAvm=tM?EH~k%a0!VBd1W!6=H&58 zJ_h2V@)Y3S?t#eMTn|3kl)rzuY!FVt_agrgNe1oV1O-9Whl%Ojw+G6?uxV<)@WSc+HxSn?=T%&cIg z29J|&j%RgY^+`%~t!EQ0UsxUSrBA3O!U;j*VKFC`KHtKdv7PsNNhO3R|NLgK`_E!6ks@4)(wWThF{+T?zo6m2P8+h zUiAt~FpEn@^)&Avjw>LBgs)c0TT(rAx#C&xgkkCg9tNz_d5o9!K zgRmJalFKR3MiMh)Bkx6~IB^up>3ZVnGgClEy@JS?~y= zCxQO)!nhy#@?^CA<07yJR`ARPS0hew`|K4az8QAJi&x&G3p{f|$UGM;M4!;#6rIXU zqOS>Ia-`%pLN+4XaEazmdOqNAh|KCo&Ee(6SFndot;)gB?gyQhhMDy^p0utC>uRk zkVMbbw0tp6HMSiv(o()IgNK!#aMFQhje&CE1sk7$1S%Vr29g{dcek6WEQPIR%ZZYkO z`-2nZGh^cSW5JgkxmQn=480_Tx#CX=bt~F`E z87ch8JYgy=qYy4zYt2iYv%Hz69~^+S_lk(U&}rO?d%;8i4*4eyaq=N0vQk6p(?~zA z@^}Xg+71`eB*2ydawYTH51IUnJUy)bTgM?xqxa>Kn)ZVTUYDL*Zw-36KmSBiS*0;X zcz4IA*n;(HAaC>*h+~Fogmi712r$*KWec@pLf?ET9~;7CKcvn0FQ?~Omb7EfE0&xh zo+tuT+JZ4p`}o-Q=sg5m!leQ6BNH)h*lIMrBSi&s*CR--j|h4T*9i=jEK~e=!n=7= zUx5QwcexfUzUG3u1PPUHK6V-(he{~i!tS&nKDW97iP_pv;_)-;*}`J{O%jf@EUXi< znigvVR-TXg3T*Bh$9XiA3!XZ6WU>SSV#W?+Si^>*+lnL8sbJ6o?5F70;HTpj57E;3>ldu^zaBz5sYWD)w>u2n5*pQM zyhb>;RDYh!A=cQbA1?ViJXmSZVU{`lDSfuX@N*1 zd|0{dt;RcW`X{2|Hj>0dlV-#oKO&~$aW0Oc>Ld=b2RboP0VDXW*z&l}M;G-4f4iOa z@PNe$Ltmhq8FE`0)MbI?grIag0`sztm9yN?UZfIU>ahz|skirc!nu*Uu{*nF?Nc}M zc2I|^-wlb&n01f(y&rXXy*ZpbfjkHh6zKE6O4(1|Q}t5?VRIfPNVG)=l9fk03@2y} zs{e!_5W;$3O|4#`)-^d1EMXxW{_I^9LsL*VwRmvkYCsMNi=!RUT)-yj-Hh9K1ujWy zz}hY0^I87W1J6_j4j87l3(GB6*_Fs%qe6~sQ9EMrLmudk8X(M&RJRaRpzi5PuKN$Y zW?L<12~w8Ri8q&W~0m?JA$*ff50TsrNS1*PEIK;mV zPajpBJVi`sj$LB;fWi^+_;a z6lZ@sFqBe%!}lkh(0<=&6H}(vip1WtDnHL;QOe$FMev`J@YJ_ct!geC%5lhJQl&GD zM#6hcu=%=w*k0&qgg$9~A21EqDUk<_q6k7z=Bt{@8NL8x(|=-yt{5D7S%7 zn-ocD`5Uk$crPTk8S1eu$%6T??e}Fm8G*r`_seJ835uQ@8`|uBN^`wjmAjNyIT-_G zj|z+$Cz(w)D@h)3hlRkY!cgTezY?cba#>`r3w+g;k#{T-zC}?rhl(^(vXeCs1%Q76 zi!XjFWQj}KJ+5p|+M%4h!YI)3qA#JeUZsDJllU|}CRwT7<{rM__{JgLmR*KcjWPZ| zbZ{d>F_%_&lapY`PvTk2gQ~;c{3Z%K$*yGQ8kxiWxCe;=Uwn#VrLHFeD1A`)+tS`Y zzvjepwY4RNMmhseB{e`N0o7ni3 z8q~c3r+%vdGCeWMT$inni#l<)4851a_gh%*BX@kEi>C-bk_6!(+?=@m!~TMO@1E74 zKdMPwo<|S1eu`I3!5|x2u~zf(+}{NVq~6B+DgpZ-ByXkm8H}P_`0X7PoCXpLy+$_{ zWV2`2WEk(q(%K2f%BC|ec^9jade6nFqLn6WUIqv~6~^S(MW|u_@hW4$p(`-EDHlfX zt@T6>@i?NpLl}P3G8Q9}`KD||#9&5K9n&ZBl>-Yaq95zbGUNUha>nJE_lnt{1vis@ zPOIr`t;4)Krnua&HJP^&JTA(*w`y(6a*U^~oP6&M3%=g~Hqm(aWJzIqq*9U>K%qu? zEaiOXdh&J1kEGzQhL_;wi;0qcpF?tsrGC?6?iG{_n>@^v)R}%)r7ckbpa6zenUZBs zhuX?&kXLXLBOGx7jgZDJY=7Wh&UfzyV6WV{Hemt?<&`}jJ2Amo{#YpJRO9jHd{2_K z{SU}Ur?0oVw4KtYj=C7Di@=nN{m(o8W$|2*iOd&8^f1Ewy^gvF^=7)l`(VRgaTLKc zXdRa52W|0#P5Rkkym1BFEM4!7`H-T*afF0PfhSRtUmWrHjb_P28tIrfd{D1bYH_b= zx(dTb;_wJ8b-Y-(^8FwyD>H=7e!|c@kieJ3`7;JI7J~n`PigjHcyT$7+4P$~5j*5i+Q^+Z6tnq5tpAW_xK^uGhG3sN%-pfn%EB*s^N&+A5*!voUQO$b$_ zW6A11V2vEj;we~9XI*&GzByt_1GpcZIH_jBAVVUzV_EeSVXjY06iD0dNaX%&;%^$_ zw=p84iK}}^(+MY0AS*}w+miqLu0pH)2Uk&|q)%{Ycr#h>@b>dit0XoTB*AX@$)cik z`~;VyXd^%$zu9SUlz5x`a6?p!j@_kCP=+?kMi52oFlT-nm<4a}J=w1-lZasA5BJQh zfqjM{DFNGnu4BA|Tuw!w(^@LF;-?G0h)OkVQwD~&>4`*+F-8fHs}5bM$y+i7B`>+> UBN+jA+%rH;SyQP-!6Nv70HZQQO#lD@ literal 0 HcmV?d00001 diff --git a/product/src/tools/workBench/images/stop.png b/product/src/tools/workBench/images/stop.png new file mode 100644 index 0000000000000000000000000000000000000000..b09668098a2e9d61d14c732d88b942ce32ebbf9d GIT binary patch literal 23000 zcmV)YK&-!sP)d(XRhYu z=iJ}-{Py3EVeUv~1q2-Y0uDOhAhVv~iNhY!Eh#J#i4_mSHyFa(b0 zfrCNaWA12Z1z1B@AFCG&Fnk{l*1|!)%R|n~poL}Nu?&1<;P`29*F_3|4+bXGKl)vM zCK%)|fc(7DA(&8K7XXh5`T-9D^f~>b-{~_a2*ABOJmlbu9L7Wr89#?~zmF%t@hS-# zeXnEn#nnIWIe^r%X4k;MbBQ~g;NZZX4A{aJfVaTmtzb@yARq~yIDiC$H*sAvV~!-lmDO@Id)t z9E>CF>__XCgIJHku^@gO-2jpL#mX!kcMUx-tOT;W>-ISXzovb4PM3K)Q+$dHDPQfMNVqf9_}m%FzW7 z(lO5M${@=Y!)J@RAPq?bxhH^o5B9n-f06ca|CdY<2l z(VYipyLou_0z^j7cC@0kwF7V#Kses?QN`SoC#(SDKEMxQbaV*M8ycOh`pN7B$b(2@ zw6`5BSPJH(WeCWeRcdCTl&oG9(js^s!rhD3ZNu1r{LC6;_0h~OfDqUCeR~^Ht;-O2 zZIWxu0i*g`p3XC5bTjwi`XeZe?!nWCM`jZ@nLPj@u5qAyDKhDH1cgkPPcfY@f9~0J ztUv*9Q#s`F!&ua}ceZeonGX<3PWna1JY+JRfIA&_ak;Zc5uPH3WJCzGQ=WJQ15 z0!PXuMroQWSYh;OlVn8+Ryy~DlCCJ{ivIRXI(l%$W%SWP-yO8z00o_Yyam z(Uz{64G^+Wxt)uVO)rz-AtnoN%HC)l4dL}ECe_cNaumP>mkcs`4ile;Vn!! z5aiLP-$991>OD|MJslK=PKRrfo&pZ$1P~OW9&o_%kq&%}JAwR}Pt&y$ItaLf^h^g$ z0Wxf5JiiCQ!2X$R>6*C!dGLfZMh`59$g~42HRHI3%-++02pC6(QfmD)0w)cRrDUcd zL@PM&0N7G6)&Ynm02TtQ4G?W$@@FdqBVf1?LYb%;qvWLkOmKjWLWmK7jR5o$hXA%0 zLJR?7FC1q`ox=<8MFB3)!}IdUQDiRVuy6&!Qdy35;6L$GWw^a4faQkKx@Zs^HqA%{ zekKBh;b+TRu_WCI;Vh7TjhUi|n^+{u&SQBhi;x9p8R@a-?qaxD1A$%uJrL*y6H5V> zh7cYYBQrGpQ$S!66t%9ufDk+c4rRIv;e#c7S0U0&Im7?3bY+j>yT~ zTBLjMKK!Js02pmd;VlxLUG;}tKEZdEzZaX-W^pcqa5K4DlzrG#gyb~@m)5zOZ*t~gorlkGOjF(Evc&d9DQXa|c)2DCP+=9d>my@2*1F)w7 zI8%yF5c2@E08&JnMF;6K1QvEgiekV$fVdYzY)9aXNHJ`>xr)(C3jPoZeS2nt@;?0l zxpjR8%lL9|-ac)PKN)C82|;8<5>(1(DFn`dz;gjS2~4y}ZZY$?#AE>~6jxy*5O@>} zzXZd*5PYvx_+>E%?oLa!)gfed@%Mb2$0o@fN_)uKZ-yCg<%Ln{05Bu90J=B@DVV_SDBYnoJ(V}7(H=v`d05guqh(oTJ1j)~-aTWAY$R#egKm4 z-(A*pCm^xkG}-Mb9*S>(V3z`T8oz2afE1DiY68benJ2*QBOk4~>aZ^XTldoB1QRjUnH^FuQ zH-L+cfU~dZB9{qE@txh+xMgp%YH>9WAiwTe43~GoO*b#_&?G65`Icg)1YWBhev9jT z#dD`8vjY18Yy`u1A;b=84sK@hmJD#r=MXskc=ir@cH&2K0P?`{c^J+1z;Wj_Eh;w* zEDSt2&dCtC9E_c=!p-N7Xg3<(+?C0%fDi!d2l#)0 zi`$WM4>eVJmwKo_gt46iNruTMM^u!a^T(A-5M)+0O(`dEP=u)~mGM^qcr_TvBR+S` z)D;le1K>tD;)e*>Feq}m8RC{v+TGkvoW6^)Cljfbk{m!D>}bPCOAnYwMFeAgF7(YCgGM>JgyCtXskH zEqH8qQ#gq!PM5|2PTx*WL{(#Kl1IH$ocNf#+ZVuFv|9EPPg=B!z_A>T_*=y}YVeHD z0b-Km(BNe?QIqt%-wek7y=k087S2Wv{(q}WRQB#vFE`iKgMza#ag%Ns zIwBSFzX8LA0OnVmX(PaB%~vN)_u%x`keWe8|H%b9*0^^saZ^YMEO6o(vClEyhTSyw}MV zc_VKq6$Wr{3WT^y)}$)sA+JWbrM@rv%=)9+z0BUiLc>SWYDpu z7lBisskIsb7>kudwW;tvF!79%)eEZ;LHzsh?<%0E_r8_pQ~#<~Tbih7s3Y=v!_l4jP>@F~T1{~X);v=C_t3zA2;XGNpxaOnUbc%08iuo(nbYM)ZNHhV; z=pBw&41u=*jB>}R5cI^OX0gfM<*ATh>{iwOuC#=7ZG9_O^9z|VC&uSj^6xSnWpd)! zI3R8U!`Hys{zUZ=qp*|j<<@O`>QUJ1d(BjpWRR~-Je-8O4yCDu04@L%1Q06THhFNw zxrPk}^ZR505*M{*3`JKMNWEjO#69fq;vA(KsLT+{Qk@uvU|)lSn~)cI>3B}+kXeZS z7&@FS^;AWv9U$Z}zrVW^Ij1wxVsE5(P*=S^PIKdsnVj)WL|rycZih$-Vfl}WozNqB3jv;BMykV05S`72T0N1Nq|IFq5lF`Nm9T`g<%mfKd7 z0!I;8EXBQ)juL+%rN&U(>Xm-A^i4TC`IThOs)C7lUv{U?%=1CJTtkTvtx#C;|%u9Mx+S4vV%j8yInrlmc7LYb62*{0f5o6H*wE zqE=E~cG{d725?LD5R~cwc^nz+>sbe+l4}VNS*>0PhBsHOcvwl9mfuwY2l=9?4Tb<( zomR|qvhZYIO-pXC#6>C*U9}ag_I;zGLp4CuGxjpvLkNK!3OK^YkQ3v|Jte`SfihW; zR9~Az5coPA{2+0w77AlnvSSO5tLzu4JVfFiFJHG5NBmWZ<$B0KL_Yx1$AjTx0FJM! zv6cf!t>EARTAVD7&#uRd7CalLwr#+&R6A0PIyE;+p*37j&j@Aua`Mhp45Ws!#!q2D zPUNvYw-a|Az7KaEx(j{ze)v?YjmnPEE<9i43(ehbvq172V!&6nf|S3q#xTPmAN&%*X!Se)kheUY|MP{xlA%aWK&m zB|p;Vml|u)C7M=c@J4u)8eQ>ZLL#8f<#8j0{7k?XK8^%qcyR17d~x@`W89 z5g!E@)y%EDMD=nHTc6-QT3HL;*l`iwyW$FTrB{H1BaoIvNs`5f1rVEF%aK@RFjUyB z%K@;AYC-@h$LXpAq&n9yFF-yg4iJqchgzEJ*6xpvZ^6|&{u#F%{9gpbNgU!N)|-s~ zZi6KLwyOh#cDdaEy9SKkE610F!fs-;fa>gTinR&cTGhnQf=xTWdd!C%3Faj#F1;buw*w<}%_IMMOA(Ad9!~ z;;$oxm7W)InqqDdN?DR?+1z3xFEY}JFoTK#svOD7Ia%u!-p5=JPS_@g(&$r!p~q@5 z90v|k%*EX!f5K%?ybq6$ZH92YiK3RFEHj9rzhexpI)?l_%s60TZI^tOCIxv<_B;SL$heSXA3e5ROFf6ZWel|ejzZ+@@MJj6t3<_A_ zEWig>y#sGu{#s;M7J-g-j&7rf!w>_>RrHqYhnSFMxKI) z!@&`JV&_-z^}+98l)6iktHK6>;UaN>7_ga_U!8-PGY0{FEf{{6C>IeTkCxFb<*G84 z9-eL5rTF|ra?N=`)w9As0PNhF+n$vIh!K=aaSj8PAcqyHPJDO$SMZDlr-6f9E()WP zq~s=Uc5_Y4p$s1ZM-dT~{#ECMBx+1xnt05;!kt&{`UJ8_(^1dVfYJk@&m0K=Wff9d zkpLG0ToSI)lMJyd@EQw};(j5iOID}=tH-KOjj%<}BBD1CjmBd*TL?L={HXO(fF>l# zF)`qdgTKX_w!9C6g+aj06f5fnAR!=1n1r=js z<6GCFKnkTMEJ+-C%TzR=mLbBThJ{7VhA1TYNutyQ6N1fF;ti1WeYM7K2#ucQG6t8q za;T*276f%}ApZ;ny*WrZ9@1oGg9AalPj+k8W3{=7-u;ctDEG3Euob%qwJkXS!>!CF zU~A??_zF=3ZYg3Ft$}(G^i9f1;gQiTIRD|-qc7hFcm$9#X5Tm$v8k?h4nhy!1D9O` z5!@}if+W?R+6#^V+qU40iM>Y30A%e#1fn;wgebCHF)Recy8-r+n!Cx`+{30|n}gWm zRrtFAf*e+7da&_?@1Zx_je^LBgk!`gBN`bZQuJdHjwUTdGn&}-MjrWIA~D6t7;1Qm zT`2HraZLh)q9z!|f>9g}MzA-xA6v$@qc1;z5&ww1rp;|dce)enT6(cG-HtYI9$MX2 zP})Qwd7%=Cl#ZYUHf?P(f}5ICB$_FmOM^NDjTyThx#V~eA2T4KF{x*ojYP=c>utF{ zoU`dQ*q+;=IY`XpYq&@yfYif9WcOY1KLGn81P&%*(F!XvvTZoyiGy(_HW45cch$3M z1%$UOk+>`Jd$^3kN=^n7p9B~MCf2rZR02pT{ljn%`sr(cZ1^5lXS(DLtweGyQ=5&{ zh&md83LlXOqnM5sNsKwuY|{D~TfVmhpm42;xLo1DaU2{8M$tFE8@CVt8n+Ms3XdIr z6l4Ao$wj0^NcyTt5l*AkYr~V;j>kDmo`ZARpN;P93JIP-I+?Y9G@@~(qnMQ~;vx#w zdMagBUoCbBIBOzOywaS-@DTDLZ5!{$IS*-oNDiVm5*rw1JchfJ0z_@pU}n4vf_)H7 z{27685~ES(@4=3pyW{a$6Ng5=kHf3iCDyt?at}TaU{^q}i^0kyLY0y~ZGaU0t~JVX z;uWbHhJ$P%4$_4JxnB%2LnfCsqy;C=Yqwr}9B{lCK@ z{}ASTZRpId!kLRs!)fz3V0CsS7J91e*Fk>-+sAj}{zDJqoso(9)(!AUo<7;>@pQ)<^SpQ+hRoMW^JDA6j$a5R@nIcaPg>&H0+kh~GG z$^gW0lyd%%dH|v%#Vvq%F9Nm|UIH;%6~wIKp&9WisrCg_p~Pq8wmu)gyQ;=q#ouQs z4id^1##jSl|(AmIgB%|*oR@8do35X5%Vm-NctgjukoOVJ`+bO+J8R$Fy680 zYTUE`ZY)SI!rykk4)5&w8+2z@N`;)1ZL(?+80hy9B(bn8;yU!-&fIQ%weLUi%^lyy zf!r|8Y(EQMIpO0tx$VjFesXqU=LtQoA|<|9@Go*k+8aR$pcKWXF~BoQ`k!MWRyjQ+ zQGm#oF#s+;M17RWL(;IaF75aeorV!WWLMhdOOa|>nMlPFQqBWD51#A*bt%B=50@_o zkV+OT0}w4@-Ep!3h|)pKero&~a;XgwY5#^ikrdw0*R8J#cV@#r^v-O1ngxT$TV*vX$e109=1eA5tTDmZ{3mXT+uDKCF zDE6v#bvIlrP9!mfWJ4i3A@CUhr_`mK+j?aDcWJrO$T3zd^OF*y%%g?x7E2V0-{)FFPAw ze#*6Y(!6ytt$|MWz%b&E;oo=OfIEhNi;Gvh6fa(SHkNpc6nD`RF)xUwMq(R*Wb^1& zyz7x`uyJ4`mS>jZ|8DpcUea;4bT9^C?2GZ_E2a|qK#XrE3?5M6S0GSKHiS~Br0efP z^S6+x0^7&?@xnh}gzY)wDAaG+BvcvQ!%U)_skd$sOJN(p17K7`jSWa$x6wnEpTd5O zZtpX(S<%pLU7x|y{CWtlrQy&LBVGyT3;>@1&@rj8SK=TB2xh4y=ZNVb=^hvkLgCtB zsED?Ost^rL6*7Fngi)vms~yu4%XF-kkz_*Ss3pdb$TXDOhj%}G4SurgCM?Z#;L9g{ z3g>scKyKGmU6W4tn1?;Ny?EQhAI2?veum}grMP6(D{%R$OR%=3TRvaH#CZMn^avz0 zuAlAw1>XAS_hT?OfS0eh0AD)sqv%L4flm^IBwx3F#(QV2hOhhw}UIo=qRck9XaK713 z07Q%exDG;m8$KIrxQ>=F_ZAL6foJWd77hB{OZ{WrQlx@p^bha?QhX_V=c8pyh}MFb zk{l%FBrFoM$^*ogN_sIQEVEIu1ZZ~9$Sqysdt3HXL`2H;C?CT&cl;MV{@7=w0{-a} zKZ@6^co|Ymn`1Se=e-x?YEiI$w&;Oo!A3o378A6XMcL(0=fuJVG*2}b%@Ba7 zlBFL12nx>LhOJql9^&r8MwMx(I0)$<+1@UsM0>;fhirTk`0!It0>l@<7*#8o+|g8k z6b~tG`K&hJQs)y_*qa~5dmsKdzQ6N_SlO})KY7}J;Ka7$HTQ__Dn+dPUc7nJRro0Z zM4EXWl{?Ql+SBbgf7v;BXZIU%VjH!9r=Z1XLFoENN4DUCd;bPIMt9&|J%&*dSi>r?=yG!}s8<_A_zAQ~w1kTb4_rmDABNQY0qr z$q(Vp4_$?y?$sPbhngr|%14@IaLR%WxN`LscyY(`kaaVVg;^k^h%-1ogiHSPclh z-CTW8CQ>o~HWb`KA`!k;bg$+hy;;n6j!UG^pezRGF937j4#xf(0+~s|qj(E6U@?k# z+=6ASTeg{31Eja58%o47ITDcvK+-_?zbN=Z+igM@TSP07-$Us##vDZ9>mK?>`|;v? zF2&{}Tkz5q=i#d-ejLlvOF*HBDp*nxIGrmwNGX8GQwSs+jOTH}{1b59DPP9P^Pen< z-zfP*`C+{4;cM{Yoi|}k+dABK=6BH3vJwT_42m>+`861Qm2Z5hJ`2PZUhZ>H}GW`t?^T%=awsFlt5{$p% zB9D~69K!iDz)qc%dDkFnG8`oCC_IHc>D|&%XmUUli5fz%lBMMHj5W&wj!u3my3Y6p zjDJBo&pd1!?Z-L4dnNkEci|N)FT@v4_y{^O?b2rv7GGdYrmYU`CgpD2p-L2#lBBb6goO_QD4)ibO2BY^njGY;A+#8F_ zqBU~x`!yYK5@=~)^bejo9zuLchqh0efmkAU#7%1DAVChj=^kv114L1|HdaOUOBK>> zBHfEK^d#r8{2#{VsihrdJ|zdC>tV;}PQ3V@*J1O>W@*9t>ITh0WKf}cFp;Jdkt7Fs zKYqIRPNk%WA{M8x2P{l2!nsSIhxhbehLhV)P|?2Hs6;VX`||tnu1(kAN4svqy0-PW zRdSFOii5~3NHd>EhEWVGbQy;CGu+LHffIZo+OlP&RGRCyu^9mnnh=G+zZ+iR(T4R9 zqo{MX8&BUl#H4~gf9*;Xf~5_+>q-BhK68$DHn_M7j4hr#I$~PpBt)#1H=g>hN(Z4`-Fl2M z^S=4P4=8}hTo9t@K!%>IZt1~g-LJu=D=x%}>~d+zk_p4w!bVoG-K2xu{|@|i_;)y~ z{pq;=)PIrZ1~Pk6jkm~ZW&dI38LBF3aK${vx`AcXqDxb*tAZ6t#4<|y^l%V*XZzt$ zhbsS0+269!Ohek}Q|?|IeqtAs3cA0xSLzKiFSdar3NLvrAjtpGSkPl5B9@EIK{x~({C(dl?k@8x(-`_s|p&eI7}1dnK76r1(PktREM3y$YXu%7?Hd zwOAE(ivmlm>xvK(lYaGg<`mn?TY@B{I7tap4_q|;00H%0XV<~!-%TX!M2fNAA$U)0 zV|aXh2Ky88pp*ZD%KCtj_3HoBRMw{w9uooxg}YDmgOq>pL~Bn8b5;pMs`P{Sqxkxc z|H3DvAHk}#OBNcQkhoH(6lZ?Nz-$=s%>Bh!WZj|{T5kPDq zLOo0wu_9$X(tWIRO|Et<^hAfyhH5{>L)~-Weq3_jTd;FndD6df;>Ts)hw`K=X+Rj!tY5*pFsejDg0Sh%;9Vx5k;LMd%fId zhC6!~p_Q#pB*a7oD6Rn)Uv0=iXp1}X-)mLUEfK4?wF^Pu7nyUl5lYMHky36)_S%UO z3P8oa03-4!Yml;xdCZZqSnquBAMumjH=`r76#w_6Pf5b3{0^mzld;FecrcDzhwj9^ z2Oq!%%g@DW3r<4DO)HT~12Hl$n|LUdC-SR(zsKL)_jVZ!`HHR!@ud^5#ZqZ4Q%*vI zd}FVYin+2&hXo}jYy@_oqgKbHUSg*h>w*tbNhgcl1Fy!maVuDH>aAF6u0rgD!`_Af z+Y<4pLliJ7wlmz<*?~gK%7y`A0u+H$A)J4jbbw-_97O3L5+Ga=o$+0$%`>cerOVtz zoFuBxV4H!h;Xo{m6|5O@kUz~3fKcF~;8!8QeUeEtFQ!SB7pW(FV@$oNv0YSu zcNILZqv0G7O0N}x2j;#|wQ+9Hf~Dv;Iwoz!xqUS+b~&vry4e7#C#OlVzrz#zUIEZE%wlOH&`-{w?1~FljuHoWVO<&6(RBEdt zkUVf`6W;ch591HRcVm8f5#HGI8vNaw%dom-l>{l}mm5cf#)M^k3Z*2O2SSw=_ZJSz z@<5Bd1v1>6s;!eQlhxH>ZAcYc-b&cv%9!&iTKTLmDG6*wiC6$d-+lvJ`~VKd8v=;j z<$R93GtBUZp0)7VqJ~(K6m7W=CuoCkE(h2}RofcW0-R<5q?YFAB+lPLMs~%A~ z>8;)ZoZtB(ynD@MIHB!$w7OA}rI2Cj1{6^~I)QH_7{!B!AH~R*XhTZ4z#T;Qy9Ln*^ychyx6FcO3`Mo!@X2 zFPV6`SPZw0%I($OVp0InI*9RNM^UknwI*gLvWT@<%2O6Ei}8eCs}G|L3=&funO^(T zp?A_blu6toix<_!+Br6e|K76^ z*YEl}oJPH;S96hJp&; zCjgK;q=?lm9fgr(ZIn_aaU0XCEnbA?(dZOadNZtx8*cZpr1oe&DuK?GqSRgc|A@~# z@m1V4{CgZO9K?KYK9*-!;EY92#i1X@AZkM45M5ZZP$}iiz1XmbF(Q}q0u5a$ao)Kc)w-E znpS|wUE&@v_91YQOer9zFwSsq*Gcd*jVHWICm|JS5MKb;i4E|LVwolmmTG>G5=uJl z&QeJ?^i)Jwv7R7NoU5|`Xlqi$UBXC5&3x28P^8?3gc=omCZZ#Y)e$}_Wp~m|sG!_q zBadOsACbzpN|#kuFcP__Ht&W7C*ma?FTnGcJ`=0b%hBRx!8zH$R4`&ufR`Sc4Ps?) z&}L=J$zv*%gkz7`L?k~Nju~bcnleX_*{$0sA7thLgvR|K7_LmLhy%~%8GgU!l!kpE zG&BMTMFcze3V`Eg3PA2K97N|)6j8ILYV~8{|BL2eM;gYfz8kBTal)BEkEl>?2q0ss z9rec~2cg{Z%}2J%g4T!qBhvg!qE=6KCDzYdBMUJs^5!E=h1uv^X>JWO=tEn$RemB0 zQ#7WrFcLRzI*v@bVOX#2-?0l;hdY2O{w@6=lu>y9OcAl<+j<-v?*K*OCK2{7M4sWU z)u$%X!Il8xa&kC+4Gg_A4IrVJH<5vrzezdig%Jb zJT=n^D^!$`Tx)%BLi0CPtQiFmL0)w676i_&L;%9L&+xm|r@?WZhD-gp$bko|z}Pnc z^d#~glF~tBsENs>Drtf$9@LT4vhO$9m9_)*h~j=|~k>${1Y7k)q;^0tm1JLc9r% zyHjSzHgf1z(G2&lJ`F)a0D<2P&c2yQ9F`G|8`42~aK~xdQ7Dyk(|#=aX}rrtrp;Ig zN|=&sH6#obd!zZAAjTrpL_}w2^@X}kQFTLQLX|aj!`5qRRK^Fcsv9b)Dh?gHpo4`T z6NwoMOHhiqj404{>!Rx?#u0=unFjF0M~`i-kSLAUVMf;!(CRN9`zp7VJk(uvuk$vSS!piwQ0vF;g+*+OPRLetrDPiRXo~ks-90l{UIV zi4oZrH`{7v5wc;A6ZQ2H8hp&u9aZoy!bb6=!sk+*V8cOX5I~xuq#uoDUV4!_ALI@# zVi7>99kg$T%5t@nkEZXH<+!d!Jk)P-26B)ln0b#zN8tp3bW7)2R4XcyzpVfZDKJs1 zGYSs0{o>WJ5XC52K~JH2UHSTAai-Yi7&Cd5x{+;N2&WZsuPC6wZtz(=H0qB?z88uR zHfg~{#;g*u25lg;ko0t{FDKjg><0D(~t-kB= z+u?hW<9WqR;)kJU^LhO5Qs>9%wFbJc4$3O{EA?bqiLZgvou(d7Oh-$ z_YfefamT4QXn>fkJSBW<)mAP&g{JS$?ZMw~x)%R4uu-;Zp70iH1x7M2yEc+2rS??& ztOz9P52}!|y0r^e9rsRL()Dr~7p6Fg*-UJ6wVEK4B9;j?*$#MF#jFen!ryfmEj!xc?vL1R0fd^1vBwko`bpXq9ZTAsFbkToscVVskCz2?R$ z&z#hE>bG&l1MiiQvv4RhtpcT&`f56XVS}O?=ZLSXyp{^p`FL9U8Mywmf0fl4jaOfq zp2POix*8*KTmz8%sHzD8#PmtmT%sgE67LUU&%86ShJi?{ye{n$esgry=`IeyJd<{oCOwQv#p zToR{*k5d+(h98{%HLRVtx~PU%DS1!nASD1YWjzWfjH*c~x3jKjLwx}G-&3h*1BqB9 zmPM3PMCXiQ_xK?G{^5^f@@S1AM zf0^%HA!Kc>_pN^iUbE@~se{Nk-x3d$^P#duOatV8En-o$F?~5*0BKs$hFMqkN3)KQ zYZ$%661{Yvben?+vSJmrY_>6=!YZg*`E7gd#Fo(=QZJzrJGKF80zuoNf9%R1K(ZX7vrfEG(NLKcx<0SeD~X(nwA;yBcJ1sq3JpSy zRaf8F(3@P1Fm%M?Qr30x1pA_|bn7_khbSRYqbghWnO1k-7 zXI2)m(zrfS3tKI9PSXmf%UPW}-#B`>>ksLLavZ(=(K zb*aQbi4L|QK8obV7>f$;5TQq1SKMh`0%W`&F9;olMhA(Ra&1o1JPy*#;?=XP{eh7w z%-f#8MYNm~idZ+IH`^7~x{dFsQLpqGI9hm0W!6v&<0vU5ge=!isg1yCt}#w+Ny0W) z(1dIQr|fge4zjk<6PK9)khp?wHi{4=7RyRh2We*egW1wR$0h~|3QZa1#4N)>o_ZtJ zXn=$g+r(&-7#)>UZSDM{66aLCZwYdZi%s?^6CP3gfa0&KJiOGsqQsMu^Dngup^i;D z2yqZu7mGqoh=Y{TKO|7fI0?&f+q(9vW;W27EiKsM04b-37!G4|kc`biEJa>d0VNO;n-1sNtAVOtmgzb-vWFP)b8_^H?hu*y?W> zZi*I@lV@rIF&=73e7a|0SYTS0=uzL;@Jz&)C#e&w-z_N2-9zEf(VP}M76C#>D*T8Ev4Czb673M z>dB#qR2c%o#HP?7U^tH=>yTD8p_=ACVg7iCwGz5Y5vPcZ5Awd+OsmYfhJBhmcg+Ru zUX7;edzd+?oQK3c=@^_4H>5u?&47{ zxboa-LuRNG6pI}px3M(j(5ghy!TLJ+!{QtU52odEXzdEkY05Kgt_xcaXhMx7G~Lcw ze_o_Y7isO$dPV0%8-g-QD5{m;8}3phRz~d-42M$yQ}-r#jPWsiap(WTKkfJm4)en* ze$5u4=y&rkZaNRwxM4>C4d);rJ`d*KhJssYxPd3#(F=|M+qU2g6x2{jQP1{vAtl-y zE@Ew3LHnsE0pbe{S2(djQBKS%$wjz)`KQf08P`4e^EhGNaS|YE7q!UCB8&<48$(z6 z3;VqmfqsG|$vh%$|4Z0z=+sv4klsK3t1x5H@+Sc<#-+PUx1 zz(~Z}bmTF-{?RLO|Hxld4!bE^R0IqIfTk+wJHgnMa0`z#+yYvH!xt#9VT^C<$Jy}J z@?HZ6=d4?bRIsw)Mmq9_ynqy63g7uCn0Q7*g{mqHuEZLV~e8p5aA>y?mc3FIJ_@t_YU-_XE>nT<`zrw@xQf(ja$0xRb1>fHDLm71d z$F;ac9paT@WDOkT++ugZ;~zo6*_%k~HEQEgaCc$jmc6(JJR06_md;0N{@O&!kOn~j zPqcusO943MkPsyAR=cC~C9KxJ#{BOE;g zqe5t9UU{8uy&*neGxO-eNNkE$#V+zTu|!?*J***2T-NYQvev1u?e4lYzX$6fvCKS!Y;s4hnBK#2$)OCAdc^Kr{vr%51w1LVO!O8i@T|QQ9cYY)1zow6BDR8?IKI4a5(qB*3a z;!kWP-46JQy=@)9WeU$t2)DJ7$AG>0VQd}Ufjzl>2q=WaiA)5>GcHFer>&lAT0AHn zMSVs9+gsR&dq*C`odA-v+8);34zZv+!DH8E)oZc3_l?Sgd^i* zF^^^8F;{7w_Ps-pSz5OF-u@}iBL|Yel2ivSUwsMQ*mV&Wq}oFHEh@ei7s5>C#K@~+ zLS9S-$6^3j8oZg8CS;?~o9$Z(M^wjG;PH`d_}Jzz;#d3bLV@QY9Gzbu-{IqmwTxxA zs95Vl1q2us`p3i}KCpZq##+~b>8_BCJkW?)0ZxU(J^`@K zN#Cv}fM_Z&x8uh_P!%A?r&2=4u{l&wK-S6NoolYZhmLzE7I+aC33qnw?}+^HM$3r2 z>c-a>Nge7p6UrXqUt6HUcq?0z*TA9fR4=;w57MGE=eb#M~!hsY=J0-S(a zO#dSoo~gE}k^d)B@M?_2j)%=aQ!lH?1rzj!3$PpDvM zEl23~Gf}>_E!ZjvYM6zcz+|uLjoML*r# zule8zAn;o-el570Hv_Ia000?>NkluE7zcmH(qOKyHMKo>c*b8G7a`;CdYm zw}qxBP-|$C4LzI>;9UR~OcEZ&x`KU^38Gd7PErjdHfOMZ*E)yV(yf0ass#lc-?koK zKk2hFD=%^=8d*tGQ@GP>>CRRy>}|?E&-T|8Eu7IdEdAQL2lY7o7!&IVTsW6A`Vi*e~|<@;sC0jC=LPm5`5eubzR<|^@^TPZJz^w2s?J}#;c)whL^HJ z-@A4p0@0g@xmR`yb$qyD4ZuDJfpra8zN>K&8vw<&*9c&xM6mEWtDMjTr92ivO!@~e zpex&j53hSSE?spYTBvwhjYkmJ~$i&j#(+X9I9B4AtLaj#*ck}>bPY#Yva;-LLHCJz5Wq;YulIxuhY zzKfzKa374i=&~yy*u`L|or>awQwktOpwJhD=Y`s?`XUaFk{qQ>&8?7g7>k&Xm6;WI zZ|~c2S=Xzj?h!uLQkZL?eYIz3YmvE$x`n=xc}sR+qp{BF2Uw@*sR}%PWE-x2{B!up zp4(7BPAlsb^buR+ssxG&AgKc!jdBlxaWHW`AifEafO2kLknl$_fBP0}K)y0SjF=_7 zWewYvB?0=>Q;a;GCxeMk0&HdCTqK-ij2vyCloG`%ag%a-hvXc2tjw&$dsn{=Z|r)N z>>*eZ9ENU8uDTWEQq+mo8g_`S2_TDoU|~l+yEG~v9o>QtJoahax^JUw^;TrjGMCY% zaeX9du3_d_ilfxFi|Fl4hPHnYO#B&va1x_Y=I@D%SLLysq?je2LR^G`7R9>(_7VV- zw^^6tBIQ65a)}r>Dak!74kS;HiCkK&TA3!!@ix41<*TqTMQW9W0Q+Sd6oifrz2t^l zm=s|7vATy1v@o=O0vJq&uC{{d=h#-V$Pp;;(8%NX;FeG0r~B@NPa7neeGS(#;3(zO zumLoIz~eDuF;-TN=oyKFs|o-~FuIqXA|rfhFz#6h z#5G{lPrZR-(jc)=5$7mn&BF#H0tfuhb?EzyS1q*&B?M#kWqPqAb=*o)TjbB}Q$mBFUfAw+* zbV>_>NhFxWv!hFR0pLsEuz!GH=YXLx$4)hn*c_s0SC6rpvcRycRkC(%fOdBguIzp@ z-n#PjSe#l2+2%}o?DS9Ryi>my6^F2QUs+a1Z{WHgp>zalj-^7obbC07iAZ!Zr>pCu zI=SZg^2zdaD-T55f{FPNNZz;QQ@DNqFAfTpccZf<(x|NCCJ+$ zHiC=K0?xj~xCdEU83u66_Cezuw1-iC*hxAK>4{`UQ$+h$fb)+4mN$gAasViG(^6n6 zrJvYfv47`W=0Ln?@pJLD<3EX>%t}q<%AKu~{6eWkIrmgsHACa7AEGAy$W?CO6e{WR z8Y??7d_hKxGVxL&v1-5>jE2c28mw|G$`emR*f{)ayy1~|VX!c$oQUQ=rN9wBe3Ign zy)iWWvM~toYr*h4d8;4+?jc$DMCV{_0HN5dww@jYSPUs2C2^4BkSf5lD*+@^0X`9+ z#JuI^o(3eG!sau$tn*@ga?Sg&P`S2pqL#CUKBOOSMV30*t*Xkv0jX##IYg z>~joAN&-X$C9XVFZw@X?f28 zBaDl2ZOtkXqZLn)wYXK;Cnv`(;*S`I!1p17Z-BXn8xBge@9y#uv~1lP_kGx>RGtn~ro6uDq!BJO-ie7=C=2SECGFnkQa@riPgdcjgFNVp1bUz6>{>z7@KXD&Dc3%v!} zE?XLnw!{<;tK_Mrc*DerglE-7j0`?}>=@sP9}WKux9Bv3dA75R9NeDY7zuya8}jr<&U4RQ)W9x%vhI@dI$=8qOFjdR}1+OLlC*aTH=u z{-{1x;vz5X?u6@fCWc;$(PEB|0y^P{s{lNwp}h6#3tfChDWKE?5*|pPM4r7^cuHJM zv!7mz=vU7hn_!NOMcsxDKmrA&$IAMkQTTf(K9#Ukm7;wdf z;P*(6Y7%B$^B|`%4xc}PXY`L%n?h{_N%2`-U7cX=^2E4^d?8^Vx^f_~uZaVr9xzlJyZL?s_lSvKWkjx``cmxDF5a%S7fMDw! z_8VvfEJbh3`lFPnWpjmcV5!w&RXe3L2oNn=G4UBV&Q9dHm*}Qk2lt3G)yfkiBhLNZ zod}%e$%UV254-Dd1pIVx_F*vAJ7uC)qadlqB`N`7G9al$r19^n=_c}R*Qj^YM=6Z} zgxK{qF!6B+c3+~R6^UtNxpMg+PVE~2D{r~7Cs5zMu(dafA-)d6qZ&7pdBvp{kE~j0 zmIlWKVB#$RYj0$gYreJ?fE0nCgt%oM7Qa_5t5eH4wGw9~ouMRmsRJCfj-lp-FL$CC z2Jm$-_7mhqK2fWcDe2SUY{8ms%87&@Wl!__@qE0%dI$p3_}qhfLs7H zkXTjg?CaU#3aq>@j?4B2knx@}K2%T+B)QhutpB7=@Ky@`6)cH}i5+PV$rRrY(- zyW|tej3VzgbuGq7f-zd=DP;O3eWW0s3Wg5=cv4iItX7Jz^So-rTGiTRolxywaR5~# z_{pAMiy|NHu2t5n)-l$(?9u5mV(d`}{1Z~_PYAe^s7co(L?PdgGj|T_qV_e9c5>4f z@Nmy+>WtZ*T%@laGbLB0Wt*kvK**@yuBI#PwGei#`btR$OSw?En%`6D6U)B6*cVkf zONDVvjzVgk7_DkQ1p6X{|4VSj6H9^$M?fV~*)Y!B-Uo`hsq>ip^zZCwLps|FFO^M9 z7oou$eZ&=61ngyCxEyFO1F@DxsRbnEM5?4js9MHZ?VMWPXf5YViD-pA5coH^;=d8F z@kI3wIex+57sinv--fe?Myf4csqbrDs)^T-DAnF-c)O|2k_i#~NdWSUN{_f6M(e%;d&2LSe85V#(|A#k2tAff>WDds)~@bl8y zg0&2}v1Ooe_*_>H3eLjBMJ?HghvKy;O_%EX;z9uPYnfET=hO=n`+<#I+wj2k4H|i? zja*y%_^GwPkHGnLNIClwcLvIF6o3>zh)n;EO5yC)hTQma+}*wa-lEls^f#O!s%XoW zi{%jFGJq;Hvc}uQRa=$W$RTQ-Q?hczB%Vq=&2bAD`xXKWHpOB^qLqsr`~%x@)-Xi` zPx@#aAmm~HuSg&aQy_;=xWdz!*I=!vpQi9d?A zu^rejIjdFt)g=cIav=V?b15<{D-$d7P);YI`dY5@3JAQq;r4EG#N6x^7y`qM2>1_W zJ*#GT$qhKD2t#gc7oI(^w_b-}b44t3cPbUsvZ^z&_6em%ZNx1qWh(f&%EBeOn(lFL zHW?jt_m>&@{nAp!oZBIAuxa3+wKMGt#&!;rE8#PlB~Ffmn5R=S&_(0jaGGHHHP0}9 z5^^ST_ACIGLx|(R8fefnnbn)Srt}I35r8o&w(xIo#BZb%Flj$W(UYlYCqIY-**?>J zGpSdTJV0nrh>!h9WA--cI&jHmbN(nq0#-iXE9vf1vi~(8b~NCB@gPy%;BR45U+*6xnOK@ zQVTS9pSo6n3b5S{;Jfg!1LNG0adp1e96B@pjpU#CHMW76AVZU_kcl$OxxtA{DKf$t}-2!+3D( zF1$JFNZX7hZ9YI~)MVM}$gh%~_M|h#O09|!xg6dGI41()Vt}17qrC6Uc$-sq&qEO6 zk6`S30DlPF8ELvmW#&f48S<15rFSN6u`0EEQv(os@}0d|%nw!p&cdedF!n-H$h=I} zXC2_6rahGF-rcl<*;7ZL)Ab}OwAKfKo8Vw0gcy=ybF)P%Gh31nzz^cEyAx;EUU;FA z#hN;R&?u=Y%5J|4X?MYtfP|iDxQP%gaCi@x^AZTW5R6e9xF!USHS#)U?6n05u?Gxy zK=A(ocXoiWu_@ykv@FtM863h2ufLwEB#o}<)B=P?O9kj0bis4yPZ>yzZsJkfr(ix@ z_el`qWdJ)10__dAgKP9H%+%|t?HMo(Chmq{H$w!E$QA^?U`^LG>@}hH=Ld(u(O*ls z&?J|0>H!i5N#Ht7wQkv~Wt@u+r)N@o+7rNVK7`ay$agZwQPg^ox_tml`~d=_gl_^9 zhrk^^W#W`k$a%ma0*VCQIo05hLr4;Bb=`|N2^Fkn?gBVd2ohWDB3nJ!LImtYI5-y& zX8_X4m|Uxex)x>HPaXpk`ytr90Q(sj-vo$*(#O6;w!(_qYe{w1H7gF7bRY_ACf=0HTe0S5G_HHgy0Z02n1Q4MB+C zfU!Fv#C8PYu&kR*3V2fOmTR4d0S8&DMx0$!rI42z-t=)0Ga51hcLtsCsj6a=or&dM zP-qqw4gx+8p1TABBz8Rqz>@(%4bh3KO#gb-N@SJKqZ+DX06PpJYf}9RF8%<)_X2EG zmfx8UU>LDVIsw^!47dYRValzvR5Rm+--{H+yE~BbI+`AqQfW1ejzVo?IkIqh8yKTX zk7r7+JY(H}pq%)YDQ)8S#dnF* z0GtA#7htVmXn{a_267ilVWUvaF+hw0*hX>IvTC{`%X?CzLd7j;j`XitL4~!fxy&U; z4q0aan>P>F(z~OU+ctX6%mE0^gkI@idKTdb>jV?6Gs383a}`olg#<(vuCoMzI01}3 z1z^X4@lJ5GfDu?20cNT#Vg*1DAo6f92H^|<;&BM^FkH3?0pABExx|=Mx~H346j3e> zosD9i7{Ez84kVQg*eE!rUr8@L1BM5dx57`Y0C(p%J$|d6RSXlg7zfK!{3s=CWx!Y( z%v}sF)=5PltQ!J7U}A{`ix3_dqgXKd=Ryb<IX`fcTq#S@`D=&&yrshA4Ba>(F2`CP6kQA7c0z@k~?|@*-;IJitSgPW| z*nDjvYm?{5ma`f-a@#UMkZG%u?LPbB+n6?w&4N<&%-0o zXh2XgXyO)A5d&AxW@EzDS#B76TlY-2GG1=zGZ!ERPvcXIuGPsPnwabpGtvy(wr?VM6LrS6!8WWFGm0AzS0!mB*CYD3etxHWs;V@ z0mqm9E_}yFI`ENC1CGAOOa(+-r1CKip5KFDV1JT1hPh~hr_<=~ymfvm*0HN#ny>@X1VG^(N+?!9qQ7aspueY6 zxvpnjWZ)?GrAT#nd=SqYIx>^=jZ#yY`2aDaraHg}x|br8Zbwka%xG>>578Vm=N14r zl|wE+j75EW8>yE&l}k2z0HU~wgWtEeA=SDJf!8*xxXDz$)tU4x!!=xg1clK(c=|AT z?VFMw+l*T6XhmDgGUS~FiFQPtRg^eG2P-=l^Fzpu4&j-5N!OS)T;u2fh?xahx>{E) zgp*zhN{Zs{Q65}4LjhriMScxRrsDa%7~OerCR?a#S;^VUL5gQbMfKC@Ub6^Cf+cWS zrl}=oYFXK1?Hn2KNlr;;7<;$v$9d95H|xdTqXi&}9H|!9xm_7#*<$!?vGi~^vo_PQ z27*%aC140a&dL247yI#7{khpHPR(vJZ#~3F)~?@mWdO9pa~913rJlvB@mvE8pHpjt z;iC;0W)+Su4ibO2visG_EF5`t5kf9Fum;*{>Ix*RO1Pls#OgsD0y5%6&qi{3> z!QfeXLA1x|J$f>fK-Rcx@({f;(K%#Iv3pdj7CEsTJVAA~nNhSNcb zRY$FUQ45(IyBws{>QLJ632-sKwgrA}KHT&?+5er=Q7PGoLexXOW|oDv7(meYDP-Q& zDaF)JJjfq`mpP2=6JywfV5X$I)>P`7M6j>GVn8Z4JWHsv7*Tm;;O=eg1k<8udY zN^uG6l2-c?9`97Pbb+Z59{;$Me9C fb>%v#*ZThfV^EHr0p+U700000NkvXXu0mjff$zjQ literal 0 HcmV?d00001 diff --git a/product/src/tools/workBench/img/button_background.png b/product/src/tools/workBench/img/button_background.png new file mode 100644 index 0000000000000000000000000000000000000000..7d32310d8f4450230f0c6cd18437c5ee09ed7120 GIT binary patch literal 1442 zcmV;T1zq}yP)Px)TuDShRCr$PTf43tMG!p=8zA8fG6*b@5Lm*3i$EeEvEl#qbH zIROE|4fp{32PAv|e?Y(o?7a&z((ddQnwjmLo|>wDO}Blub0@iv>8|Nh=hUO;VX(l% zED$qpK`({%Tc(%5^zTHg#WDSY=##~P-Zb>vqCjtm9$}B?ivj&F(Zj=@o&$K}>_NAQ z>*E8S9*CX+W(ClBHz)rPeNKBk1L)JCGMV!Oz1h&)=1qJ-2l^HU7t=DVfL{Mccg+g# zk-?qU0qg;|KWo?X_FAdOfp9^<0~ornGIrT*WsM`pqnN&K=&J+adjR)B7tKiq-5fiy zU4wfF2IXt;iLTN1_W@l0yTmnsHrVg)a0!F2LtyRs9MGrbwUa|@cltf+QI})+(T1xmgo^fChi20QRggXy$}VB1MtU z_}{TCyHa=O7?^cKmmqu-T&)%xi4#+qo~lX%?T*x9r&oYkZ|N@>+)Y_K7gtVv8_9^9 zgVa1XW=%_0r{W_fK~HBR9tJ4Qgt-l8imQtyvN@n9b9qwp7|-b$ih~X&C=Vs4 zhJ}ww&~i+?7Y7}4(U2578xq?I#(hJpfX-=F)NIbX&Va{aL{S{{oGvXYG$PsdRh25B zqZS{*ST{tf-7_xGnyUgjMq*KME!FF}9Z_x2bIaJtd0Gj}WV{;Fwy(%s*F*?vC}+s3 z8tB{%o-BJ$*QVL30$S=VLSSOfd$*(R$v}VlQb5m*ZJxVMDsnTsG*`q^V3TQ6xlE6D$KA8(r>p)8q%)Uh$laWS^mV3`Daxxp{ zt>=92DK#hD0VTl?wg;>2O}_qS-~5Vx+MV$xfj!<5<*l{5JVf$%;edw~mH|&kuC^puH^DSuw4}xXtuB zB>wC;g|%|Pi-C^s);MtAZed)``j&M#+>DUqzPa*tWgaeJa#J#f!NXwONKZFM={39v z)BXli&j7vN(ccDmH$@&=F`D*Pp^>AUD!fKG1@Bh&+%=o)EnSky zdyh;?XyJuO$xPbUO@+*D=aw_G+0kbQ;E(WP(?;mxmEu~Gvt&U^UH!O}4z9Cu)zHr% zJV}G4j}Et~;SsuZ4t#K8Y&P%4wQm7`xW_M)`MRVQx&C?`>tZdbxpkxG+RZ6G>m%n} zHS`$$``-6sm*g8K^Qmn-+|p!0@XV}dYQA;xu`Zr_LG;eH!TYZn+{p!RzXq`L+rMia z23Qf{9uXcGp#5HBWnCx*Lu?q-T5oZ?8=|+G9lkWc6FMrE*MYMG?Rs(D&?6l1LmRFo z+SlR?)iT(9s?p#n5q`8EqMbFk+?VsMr3Js<(yxn=w*`H*rH>W| wdXZnsj~munHRA@_U7WmcnZAK4thS{80qsO8F@fYmiU0rr07*qoM6N<$g8YufcmMzZ literal 0 HcmV?d00001 diff --git a/product/src/tools/workBench/localstateform.cpp b/product/src/tools/workBench/localstateform.cpp new file mode 100644 index 00000000..f300b293 --- /dev/null +++ b/product/src/tools/workBench/localstateform.cpp @@ -0,0 +1,311 @@ +#include "localstateform.h" +#include "ui_localstateform.h" +#include "DataMng.h" +#include "../include/sys/sys_login_api/CLoginDlg.h" +#include "CheckBoxDialog.h" +#include "CommonEnum.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +LocalStateForm::LocalStateForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::LocalStateForm) +{ + ui->setupUi(this); + + //初始化ui + initlocalState(); + +} + +LocalStateForm::~LocalStateForm() +{ + delete ui; +} + +void LocalStateForm::updataLocalState() +{ + std::vector runLocalStateVec = DataMng::instance()->getRunAppInfo(); + + foreach (SApp app, runLocalStateVec) + { + //只更新本机节点 + if( QHostInfo::localHostName() == QString::fromStdString( app.m_nodeName ) ) + { + QList tbtns = ui->state_widget->findChildren(); + foreach (QAbstractButton *btn, tbtns) + { + if( app.m_appId == btn->property("appId") ) + { + QString text = QString::fromStdString( app.m_desc ); + if(app.m_isActive == 1) + { + if(app.m_isMaster == 1 && app.m_isSlave==0) + { + text += tr("(主)"); + btn->setProperty("state" , "11"); + + } + else if(app.m_isMaster == 0 && app.m_isSlave==1) + { + text += tr("(备)"); + btn->setProperty("state" , "10"); + } + else + { + text += tr("(未知)"); + btn->setProperty("state" , "00"); + } + }else if(app.m_isActive == 0) + { + text += tr("(停止)"); + btn->setProperty("state" , "01"); + }else if(app.m_isActive == 2) + { + text += tr("(未知)"); + btn->setProperty("state" , "00"); + } + btn->setText(text); + btn->style()->unpolish(btn); + btn->style()->polish(btn); + btn->update(); + + break; + } + } + } + } +} + +void LocalStateForm::createDialogue(QToolButton *btn) +{ + int appid = 0; + QString appName = ""; + CheckBoxDialog *dia; + QMap qmap; + qmap.clear(); + QList list; + list.clear(); + bool isHalf_flag = false; //是否是半运行状态 + + + QString title = tr("提示"); + QString tips = ""; + + appName = btn->property("appName").toString(); + appid = btn->property("appId").toInt(); + + if( CN_AppId_BASE == appid || !DataMng::instance()->getAllowedStatus() ) + { + //do something + }else + { + if( DataMng::instance()->getBaseStatus()) //基础应用处于启动状态 + { + //获取本机应用状态 + if( btn->property("state") == "11" || btn->property("state") == "10") + { + //启动状态 + qmap.insert(EN_STATE_RADIOBTN_STOP , tr("停止")); + qmap.insert(EN_STATE_RADIOBTN_RESTART , tr("重启")); + } + else if( btn->property("state") == "01") + { + //停止状态 + float disk = 0.0; + std::vector procVec; + + DataMng::instance()->getRunProcInfo(procVec,disk); + foreach (SProcess var, procVec) + { + if( appid == var.m_appId && EN_PROC_RUNNING == var.m_isStartUp) + { + isHalf_flag = true; //半运行状态 + break; + } + } + + if( isHalf_flag ) + { + qmap.insert(EN_STATE_RADIOBTN_STOP , tr("停止")); + qmap.insert(EN_STATE_RADIOBTN_RESTART , tr("重启")); + } + else + { + qmap.insert(EN_STATE_RADIOBTN_START , tr("启动")); + } + } + } + } + + if( qmap.isEmpty() ) tips = tr("该应用暂不能切换成其他状态。"); + else tips = tr("当前应用状态是否切换成其他状态?"); + + dia = new CheckBoxDialog(true , title , tips , qmap , -1 ,this); + if( QDialog::Accepted == dia->exec()) + { + list = dia->getCheckedNumbers(); + foreach ( int var, list) + { + CLoginDlg dlg(this); + QString perm = ""; + switch (var) + { + case EN_STATE_RADIOBTN_START: + if( isHalf_flag ) //半运行状态 + { + QString perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + int res = dlg.exec(); + if(res == QDialog::Accepted) + { + emit sigRestartServer(appName); + } + }else + { + emit sigStartServer( appName ); + } + break; + case EN_STATE_RADIOBTN_STOP: + perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + if( QDialog::Accepted == dlg.exec()) + { + emit sigStopServer(appName); + } + break; + case EN_STATE_RADIOBTN_RESTART: + perm ="FUNC_NOM_SYSTEM_EXIT"; + dlg.setCheckPerm(perm); + dlg.setOkButtonText(tr("验证")); + dlg.setTitle(tr("权限验证")); + if( QDialog::Accepted == dlg.exec()) + { + emit sigRestartServer(appName); + } + break; + case EN_STATE_RADIOBTN_UP: + break; + case EN_STATE_RADIOBTN_DOWN: + break; + default: + break; + } + break; + } + } +} + +void LocalStateForm::initlocalState() +{ + QMap > deployInfo = DataMng::instance()->getDeployInfo(); + QMap >::iterator pos = deployInfo.begin(); + + clearLayoutAndBtn(ui->state_widget->layout()); + QHBoxLayout *layout = new QHBoxLayout(ui->state_widget); + layout->setMargin(0); + //获取本机名称 + QString hostName = QHostInfo::localHostName(); + while (pos != deployInfo.end()) + { + //只展示本机节点 + if( hostName == pos.key()) + { + QMap appMap = pos.value(); + QMap::iterator it = appMap.begin(); + + while (it != appMap.end()) + { + QToolButton *btn = new QToolButton(ui->state_widget); + btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + + QString stateText = QString::fromStdString( (*it).m_desc ); + btn->setProperty("appId" , QString::number ( (*it).m_appId ) ); + btn->setProperty("appName" ,QString::fromStdString( (*it).m_appName) ); + if((*it).m_isActive == 1) + { + //运行状态 + if((*it).m_isMaster == 1 && (*it).m_isSlave==0) + { + stateText += tr("(主)"); + btn->setProperty("state" , "11"); + } + else if((*it).m_isMaster == 0 && (*it).m_isSlave==1) + { + stateText += tr("(备)"); + btn->setProperty("state" , "10"); + } + else + { + stateText += tr("(未知)"); + btn->setProperty("state" , "00"); + } + }else if((*it).m_isActive == 0) + { + stateText += tr("(停止)"); + btn->setProperty("state" , "01"); + + }else if((*it).m_isActive == 2) + { + stateText += tr("(未知)"); + btn->setProperty("state" , "00"); + } + connect(btn ,&QToolButton::clicked , this , [this , btn](){ + this->createDialogue(btn); + }); + btn->setText(stateText); + btn->style()->unpolish(btn); + btn->style()->polish(btn); + btn->update(); + layout->addWidget(btn); + it++; + } + break; + } + pos++; + } + ui->state_widget->setLayout(layout); + return; +} + +void LocalStateForm::blockLocalStateSignals(bool b) +{ + ui->state_widget->blockSignals(b); +} + +void LocalStateForm::clearLayoutAndBtn(QLayout *layout) +{ + if (layout) + { + // 遍历并删除所有控件 + QLayoutItem *item; + while ((item = layout->takeAt(0)) != nullptr) + { + QWidget *widget = item->widget(); + if (widget) + { + widget->hide(); + widget->setParent(nullptr); + QObject::disconnect(widget, nullptr, nullptr, nullptr); + delete widget; + } + delete item; + } + delete layout; + } +} diff --git a/product/src/tools/workBench/localstateform.h b/product/src/tools/workBench/localstateform.h new file mode 100644 index 00000000..e9879fd5 --- /dev/null +++ b/product/src/tools/workBench/localstateform.h @@ -0,0 +1,43 @@ +#ifndef LOCALSTATEFORM_H +#define LOCALSTATEFORM_H + +#include +#include +#include +#include + +#include "MonitorCommon.h" + +using namespace workBench; + +namespace Ui { +class LocalStateForm; +} + +class LocalStateForm : public QWidget +{ + Q_OBJECT + +public: + explicit LocalStateForm(QWidget *parent = 0); + ~LocalStateForm(); + +signals: + void sigStartServer(const QString appName); //开启服务状态 + void sigStopServer(const QString appName); //停止服务状态 + void sigRestartServer(const QString appName); //重启服务状态 + +public slots: + void updataLocalState(); //更新函数 + void createDialogue(QToolButton *btn); //创建对话框函数 + +public: + void initlocalState(); + void blockLocalStateSignals(bool b); + void clearLayoutAndBtn(QLayout *layout); + +private: + Ui::LocalStateForm *ui; +}; + +#endif // LOCALSTATEFORM_H diff --git a/product/src/tools/workBench/localstateform.ui b/product/src/tools/workBench/localstateform.ui new file mode 100644 index 00000000..e9dc4dc4 --- /dev/null +++ b/product/src/tools/workBench/localstateform.ui @@ -0,0 +1,39 @@ + + + LocalStateForm + + + + 0 + 0 + 407 + 70 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + diff --git a/product/src/tools/workBench/mainwindow.ui b/product/src/tools/workBench/mainwindow.ui new file mode 100644 index 00000000..b152267f --- /dev/null +++ b/product/src/tools/workBench/mainwindow.ui @@ -0,0 +1,248 @@ + + + MainWindow + + + + 0 + 0 + 960 + 608 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 16777215 + 60 + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + + 10 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + 10 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + 10 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + 0 + 40 + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + MenuFrame + QWidget +
pub_widget/MenuFrame.h
+ 1 +
+ + WorkFrame + QWidget +
pub_widget/WorkFrame.h
+ 1 +
+
+ + +
diff --git a/product/src/tools/workBench/resource.qrc b/product/src/tools/workBench/resource.qrc new file mode 100644 index 00000000..da23860b --- /dev/null +++ b/product/src/tools/workBench/resource.qrc @@ -0,0 +1,11 @@ + + + images/start.png + images/stop.png + sys_startup.ico + auto_start.ico + db_check.ico + dog_auth_check.ico + images/restart.png + + diff --git a/product/src/tools/workBench/sys_startup.ico b/product/src/tools/workBench/sys_startup.ico new file mode 100644 index 0000000000000000000000000000000000000000..396f47b94649c826d0e87ce286d3738b1ab883d8 GIT binary patch literal 16958 zcmd^HO^h7X5w6);GYAm70)%ov*@>5fBOzo7AvqFgMqIcg^4OPPD^dpTcn5)i184>g zK_H@A5GY2&rQ5(4!^0XZ^1y?}v5jQ3IXX5RYin(jBRcV~7T zGgfa^y{`9Oef6qpx~E^8sKEcKRpP&8I`9zDokVni4{o9sAJT3=RifK(?jQYzz5Qz% zRNq`EL}q~&nV;QTYj$sT#(HpbfjW%cz!94h^!wejV)tia++|+tHeg2l1D-mfxBJ#j zZpJX&L$T20e*f1wu?^fh9wPHNRVKGGlNs6KK0!^XZT?tKthvSxGA+rNld*QZqq3d0 zrjG}A!aq_U7shMtctSa$3;5K*rQLU$u!RL@o(xh zR_UNygGo|_Td?D?dWz%0&Cjtg%YHby10N)CUnD9s?zZ4|hs7^G=pT#hhl%9I2;Arc zbIQ~fS%1q8$qBPi=;ZK2Eb+tr%Hqp3+!^@A5AhRc$5$r>_uHn{?8kUwtrM749LTx& zEmKQe&oUnQZt&*B6|SKUw_yK#nwl=w9cH9z{aqZ`oY-k?;B~BXJVzAKhWzxcnf* z?p51&mIH}#BCaPx-&KsU>cg3JE+>9l9}qM0ZmgF+x!e4y_v>-{A=32_=f0Nkiyxjk zzt6n->AmCdLG)*Hw1rr+_|NuDJpO~$-^GE@XD-~d?VRBCZvPc(KjN3ul z`edKYS?8P$nr7*{cFBoX{`bqw+7N=<&AEmD%v9vs9L$JRXJw?6ns@*0iv zpy4q3Xo#I!N893LtrsG@zImy}e=H>r8273VyPONLQR`&cs`WzTtg%M5Yy4@oQ1aj> zg`Z>K5tRpwzvc5m$Qo&#thLd4Au^67_vtA6__Xzx7&v}rs;&F^t_ebH)H-^6Cu_YB z+4U95>$HlpkI%#}K3Ji{*w>c_AvS6q92uzxicD^P`uZ5|35Mra&aW-kH^+IGE!{%v`Vx0$T^He)OPX>?Zc-6SiH$TMY zkI|zEKj>=$nI|m|LTuDJXfyI!FGR-vu1?8)Jhlt}-aJKF_?;h4oK41pu7zoN5Mra& z(Y85R>xIa!uTY0y=x4>`v+N58sEqhOsFWS-E&9$UFC=2%_{!8!J>hXr;yfWXY8|v0 zd94>BV}G;*4n}@%rO4p`=fZ4W-$*!Y}7hvGxAz5M8^JzUwEAd zt7V$idGPVmb@S!lm(1mVcFf=YwGbU!DR%Hks{?qC7-FN=L7S1+dLc6Q*Z4)&d2oI| z)iDN;e{Vk}?t^e_&AWTV5F53Q9?QvEFGO~Ig{I+8%L9&qHsW@C9{lzmk$)=*u~F-w z&B$xL5E=WY;g>d@2ZLG|JKT=u!7uYl9)#GabYkO zFXM&SsCCc| zdTSl*?^}O&&UZ}^ieH{5^4^0b_e|#X^+V?A_iqaJ1KNzd#ug%De}~aWB@eKV#DL3# zQTPYA+YUF#BYx1e0c}QJV+)b7e->6xdm;~HEMJaezUSq!HlWSOhv3yZ z*x!RQGZ$PQ$leIpPnMe7c`<8!R~yh~j!Ts&Sg!@`k_j#Y@eFJQJyaPXY_gtXuSv>op+*qS_RxDt@QTPS-H@`~YMjtS5 z_x2|C#z1BLn_G{@2I zJiPV8Sz2{|z`kkt^WawdLuJ4F&^sWqpX9Bp`;Osz;^B%?NLeOK%_#}Pvwo_&zGpBMZowJkNq)mjJWaBaB8--Wq+KY91|=Epo7 zBUkwSu{>+Eo4T@ZdBX32L_A00`(Zcnh0et`=H2f;D*hAi0fgGI*Lq{{LnM2}_Zr7e z=NCV4?yu&_f4wh!r#4&*{n-!l{zK&R!}W+8ea}8feg8rH!q+>AeIMBGdgH+ltN2da zZsX*~&YN@c@Y$G+nLh0n`?N)tZW3RG@@Io+PUt$3RqPU3MgBUvp=nI-E~1~!@#!0g z>Lp{A3oUA~0#Ucfuf6an2X7&&@F=%%j~VV=TIPdkaX@DVw8CvAKA!8-La$-vQtw$y z=X!@MZOV+SXL>&$&|3$zWNF+hwd8!fI) L`e2=VJc{`dt8?Qi literal 0 HcmV?d00001 diff --git a/product/src/tools/workBench/tool/CheckBoxDialog.cpp b/product/src/tools/workBench/tool/CheckBoxDialog.cpp new file mode 100644 index 00000000..f953ab49 --- /dev/null +++ b/product/src/tools/workBench/tool/CheckBoxDialog.cpp @@ -0,0 +1,75 @@ +#include "CheckBoxDialog.h" + +#include +#include + +CheckBoxDialog::CheckBoxDialog(bool isExclusive, QString title, QString tips, QMap &mapBox,int indexChecked , QWidget *parent): + CustomDialog(parent) +{ + setWindowTitle(tr("工作台")); + m_titleText = new QLabel(title , this); + m_tipsText = new QLabel(tips , this); + m_titleText->setObjectName("titleLabel"); + m_tipsText->setObjectName("tipsLabel"); + + m_groupBtn = new QButtonGroup(this); + m_groupBtn->setExclusive(isExclusive); + + m_buttonBox = new QDialogButtonBox(Qt::Horizontal , this); + confirmBtn = new QPushButton(tr("确认")); + cancelBtn = new QPushButton(tr("取消")); + m_buttonBox->addButton(confirmBtn , QDialogButtonBox::AcceptRole); + m_buttonBox->addButton(cancelBtn , QDialogButtonBox::RejectRole); + + QGridLayout *gLayout = new QGridLayout(this); + gLayout->addWidget(m_titleText , 0 , 0 , 1 ,4); + gLayout->addWidget(m_tipsText , 1 , 0 , 1 , 4); + m_tipsText->setAlignment(Qt::AlignCenter); + + int row = 2 , col = 1; + checkboxes.clear(); + foreach (const int &key , mapBox.keys()) + { + QCheckBox *checkBox = new QCheckBox(mapBox.value(key) , this); + checkboxes[key] = checkBox; + m_groupBtn->addButton(checkBox); + if(indexChecked != -1 && indexChecked == key) + { + checkBox->setChecked(true); + } + gLayout->addWidget(checkBox, row, col%3); + col++; + if ( 0 == col%4 ) { + row++; + } + } + QWidget *spacer = new QWidget(); + spacer->setFixedHeight(20); // 设置额外间距 + + gLayout->addWidget(spacer , row + 1 , 0 , 1 , 4); + gLayout->addWidget(confirmBtn, row + 2 , 3); + gLayout->addWidget(cancelBtn, row + 2 , 2); + setLayout(gLayout); + adjustSize(); + + connect(m_buttonBox , &QDialogButtonBox::rejected , this , &CheckBoxDialog::reject); + connect(m_buttonBox , &QDialogButtonBox::accepted , this , &CheckBoxDialog::accept); + +} + +QList CheckBoxDialog::getCheckedNumbers() const +{ + QList checkedNumbers; + checkedNumbers.clear(); + for (auto it = checkboxes.begin(); it != checkboxes.end(); ++it) { + if (it.value()->isChecked()) { + checkedNumbers.append(it.key()); + } + } + return checkedNumbers; +} + +void CheckBoxDialog::setTipsHidden(bool hide) +{ + m_tipsText->setHidden(hide); +} diff --git a/product/src/tools/workBench/tool/CheckBoxDialog.h b/product/src/tools/workBench/tool/CheckBoxDialog.h new file mode 100644 index 00000000..0d817072 --- /dev/null +++ b/product/src/tools/workBench/tool/CheckBoxDialog.h @@ -0,0 +1,32 @@ +#ifndef CHECKBOXDIALOG_H +#define CHECKBOXDIALOG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "pub_widget/CustomDialog.h" + +class CheckBoxDialog : public CustomDialog +{ + Q_OBJECT +public: + explicit CheckBoxDialog( bool isExclusive ,QString title, QString tips, QMap &mapBox ,int indexChecked = -1, QWidget *parent = nullptr); + QList getCheckedNumbers() const; + void setTipsHidden(bool hide); //隐藏提示文本框 + +private: + QLabel *m_titleText; //标题栏 + QLabel *m_tipsText; //提示栏 + QButtonGroup *m_groupBtn; //多选框组 + QDialogButtonBox *m_buttonBox; + QPushButton *confirmBtn; + QPushButton *cancelBtn; + QMap checkboxes; +}; + +#endif // CHECKBOXDIALOG_H diff --git a/product/src/tools/workBench/tool/CommonEnum.h b/product/src/tools/workBench/tool/CommonEnum.h new file mode 100644 index 00000000..aee87176 --- /dev/null +++ b/product/src/tools/workBench/tool/CommonEnum.h @@ -0,0 +1,14 @@ +#ifndef COMMONENUM_H +#define COMMONENUM_H + +enum EN_STATE_RADIOBTN_TYPE +{ + EN_STATE_RADIOBTN_START = 0, //<启动 + EN_STATE_RADIOBTN_STOP, //<停止 + EN_STATE_RADIOBTN_RESTART, //<重启 + EN_STATE_RADIOBTN_UP, //<升主 + EN_STATE_RADIOBTN_DOWN //<降备 +}; + + +#endif diff --git a/product/src/tools/workBench/tool/DataMng.cpp b/product/src/tools/workBench/tool/DataMng.cpp new file mode 100644 index 00000000..dfb7b485 --- /dev/null +++ b/product/src/tools/workBench/tool/DataMng.cpp @@ -0,0 +1,828 @@ +#include "DataMng.h" +#include "pub_utility_api/FileUtil.h" +#include "pub_utility_api/CommonConfigParse.h" +#include "boost/asio/ip/host_name.hpp" +#include "pub_utility_api/I18N.h" +#include "pub_utility_api/FileUtil.h" +#include "pub_utility_api/FileStyle.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace workBench; +using namespace std; +using namespace iot_public; + +DataMng *DataMng::m_pInstance = Q_NULLPTR; + +DataMng *DataMng::instance() +{ + if(m_pInstance == Q_NULLPTR) + { + m_pInstance = new DataMng(); + } + return m_pInstance; +} + +void DataMng::destory() +{ + if(m_mutex) + { + delete m_mutex; + } + m_mutex = Q_NULLPTR; + if(m_mutexApp) + { + delete m_mutexApp; + } + m_mutexApp = Q_NULLPTR; + + if(m_mutexProc) + { + delete m_mutexProc; + } + m_mutexProc = Q_NULLPTR; + + m_pInstance = Q_NULLPTR; + + delete this; +} + +bool DataMng::loadJson() +{ + const std::string strLanguage = std::move( iot_public::getCurLanguage()); + QFile loadFile(iot_public::CFileUtil::getPathOfResFile("workBench/workBench.json" , strLanguage ).c_str()); + if(!loadFile.exists() || !loadFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + return false; + } + QString allData = loadFile.readAll(); + + loadFile.close(); + + QJsonParseError error; + QJsonDocument document = QJsonDocument::fromJson(allData.toUtf8(),&error); + if(error.error != QJsonParseError::NoError) + { + qDebug()< appMap; + appMap[CN_AppId_BASE] = a; + m_modelDeployInfoMap[m_nodeVec.at(index)] = appMap; + } + + QString filename = "../../data/sys_model_info/SYS_MODEL_DEPLOY_INFO.xml"; + + QFile file( filename ); + if( !file.open(QIODevice::ReadOnly | QIODevice::Text) ) + { + return ; + } + + QDomDocument document; + if(!document.setContent(&file)) + { + qDebug()<<"error"; + return ; + } + QDomElement table = document.documentElement();//返回根节点table + QDomNode node = table.firstChild(); + while (!node.isNull()) { + int num = node.toElement().attribute("NUM").toInt(); + int app_id = node.toElement().attribute("APP_ID").toInt(); + QString app_desc = QString::fromStdString(m_modelAppInfoMap.value(app_id).m_desc); + + for(int i = 1;i <= num; i++) + { + QString nodeName = node.toElement().attribute(QString("NODE%1").arg(i)); + QMap >::iterator it = m_modelDeployInfoMap.find(nodeName); + if(it!= m_modelDeployInfoMap.end()) + { + QMap &info = it.value(); + SApp a; + a.m_appId = app_id; + a.m_appName = m_modelAppInfoMap.value(app_id).m_tagName; + a.m_desc = app_desc.toStdString(); + a.m_nodeName =node.toElement().attribute(QString("NODE%1").arg(i)).toStdString(); + if(nodeIsUsed(a.m_nodeName)) + { + info[a.m_appId] = a; + } + }else + { + QMap info; + SApp a; + a.m_appId = app_id; + a.m_appName = m_modelAppInfoMap.value(app_id).m_tagName; + a.m_desc = app_desc.toStdString(); + a.m_nodeName =node.toElement().attribute(QString("NODE%1").arg(i)).toStdString(); + if(nodeIsUsed(a.m_nodeName)) + { + info[a.m_appId] = a; + m_modelDeployInfoMap[nodeName] = info; + } + } + } + node = node.nextSibling(); + } +} + +bool DataMng::nodeIsUsed(const std::string &nodeName) +{ + bool res = false; + for(int index(0);index DataMng::getVersionInfo() +{ + return m_versionMap; +} + +QString DataMng::getTitle() +{ + return m_Title; +} + +void DataMng::addPage1ButtonInfo(const QList &buttonInfo) +{ + if(buttonInfo.isEmpty()) return; + //打开json文件 + const std::string strLanguage = std::move( iot_public::getCurLanguage()); + QFile loadFile(iot_public::CFileUtil::getPathOfResFile("workBench/workBench.json" , strLanguage ).c_str()); + if(!loadFile.exists() || !loadFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + return; + } + QString allData = loadFile.readAll(); + + loadFile.close(); + + QJsonParseError error; + QJsonDocument document = QJsonDocument::fromJson(allData.toUtf8(),&error); + if(error.error != QJsonParseError::NoError) + { + qDebug()< localAppIdList; + localAppIdList.clear(); + m_sysRunProcInfoVec.clear(); + m_modelProcInfoVec.clear(); + QMap >::iterator it = m_modelDeployInfoMap.find(getHostName()); + if(it != m_modelDeployInfoMap.end()) + { + localAppIdList.append(it.value().keys()); + } + QString filename = "../../data/sys_model_info/SYS_MODEL_PROCESS_INFO.xml"; + + QFile file( filename ); + if( !file.open(QIODevice::ReadOnly | QIODevice::Text) ) + { + return ; + } + + QDomDocument document; + if(!document.setContent(&file)) + { + qDebug()<<"error"; + return ; + } + QDomElement table = document.documentElement();//返回根节点table + QDomNode node = table.firstChild(); + while (!(node.isNull())) { + int app_id = node.toElement().attribute("APP_ID").toInt(); + if(node.toElement().attribute("NOT_USED").toInt() == 1) + { + node = node.nextSibling(); + continue; + } + if(localAppIdList.contains(app_id)) + { + SProcess proc; + proc.m_appId = app_id; + proc.m_appDesc = m_modelAppInfoMap.value(app_id).m_desc; + proc.m_nodeName = getHostName().toStdString(); + proc.m_procName = node.toElement().attribute("PROC_NAME").toStdString(); + proc.m_procDesc = node.toElement().attribute("DESCRIPTION").toStdString(); + + m_sysRunProcInfoVec.push_back(proc); + m_modelProcInfoVec.push_back(proc); + } + node = node.nextSibling(); + } + m_nLocalProcNum = (int)m_sysRunProcInfoVec.size(); + LOGINFO("本机一共需要启动%d个进程.",m_nLocalProcNum); +} + +QVector DataMng::getPage1ButtonInfo() +{ + return m_page1ButtonInfoVec; +} + +QMap DataMng::getPage3ButtonInfo() +{ + return m_page3ButtonInfoMap; +} + +bool DataMng::getButtonInfoByName(const QString &name, SButtonInfo &buttonInfo) +{ + QMap::iterator it = m_buttonInfoMap.find(name); + if(it != m_buttonInfoMap.end()) + { + buttonInfo = it.value(); + return true; + }else + { + return false; + } +} + +QString DataMng::getStartPng() +{ + return m_stStartPng; +} + +QString DataMng::getStopPng() +{ + return m_stStopPng; +} + +QString DataMng::getStartBorderColor() +{ + return m_stStartBorderColor; +} + +QString DataMng::getStopBorderColor() +{ + return m_stStopBorderColor; +} + +QString DataMng::getStartWaterColor() +{ + return m_stStartWaterColor; +} + +QString DataMng::getStopWaterColor() +{ + return m_stStopWaterColor; +} + +QString DataMng::getSysIcon() +{ + return m_stSysIcon; +} + +QString DataMng::getRestartPng() +{ + return m_stRestartPng; +} + +void DataMng::setBaseStatus(bool runStatus) +{ + QMutexLocker lock(m_mutex); + m_bBaseIsRun = runStatus; +} + +bool DataMng::getBaseStatus() +{ + QMutexLocker lock(m_mutex); + return m_bBaseIsRun; +} + +QString DataMng::getHostName() +{ + return QString::fromStdString(boost::asio::ip::host_name()); +} + +bool DataMng::getSysStatus() +{ + QMutexLocker lock(m_mutex); + return m_bSysIsRun; +} + +void DataMng::setSysStatus(bool runStatus) +{ + QMutexLocker lock(m_mutex); + m_bSysIsRun = runStatus; +} + +bool DataMng::getAllowedStatus() +{ + QMutexLocker lock(m_mutex); + return m_bIsAllowedOpt; +} + +void DataMng::setAllowedStatus(bool allowed) +{ + QMutexLocker lock(m_mutex); + m_bIsAllowedOpt = allowed; +} + +SSysModelAppInfo DataMng::getModelAppInfoById(int appId) +{ + SSysModelAppInfo appInfo; + return m_modelAppInfoMap.value(appId,appInfo); +} + +QMap > DataMng::getDeployInfo() +{ + return m_modelDeployInfoMap; +} + +std::vector DataMng::getProcInfo() +{ + return m_modelProcInfoVec; +} + +void DataMng::setRunAppInfo(const vector &runAppVec) +{ + QMutexLocker lock(m_mutexApp); + m_sysRunAppInfoVec = runAppVec; +} + +vector DataMng::getRunAppInfo() +{ + QMutexLocker lock(m_mutexApp); + return m_sysRunAppInfoVec; +} + +void DataMng::setRunProcInfo(const std::vector &runProcVec,const float &disk) +{ + QMutexLocker lock(m_mutexProc); + m_sysRunProcInfoVec = runProcVec; + m_fDisk = disk; +} + +void DataMng::getRunProcInfo(std::vector &procVec, float &disk) +{ + QMutexLocker lock(m_mutexProc); + procVec = m_sysRunProcInfoVec; + disk = m_fDisk; +} + +int DataMng::getDomainId() +{ + return m_locIdDomainOdMap.value(m_nodeLocIdMap.value(getHostName(),1),1); +} + +std::vector DataMng::getInitAppInfoVec() +{ + std::vector initAppInfoVec; + QMap >::iterator it = m_modelDeployInfoMap.begin(); + while (it != m_modelDeployInfoMap.end()) { + QMap appMap = it.value(); + QMap::iterator pos = appMap.begin(); + while (pos != appMap.end()) { + initAppInfoVec.push_back(pos.value()); + pos++; + } + it++; + } + return initAppInfoVec; +} + +std::vector DataMng::getInitProcInfoVec() +{ + return m_modelProcInfoVec; +} + +std::string DataMng::getAppDescByAppId(int appId) +{ + return m_modelAppInfoMap.value(appId).m_desc; +} + +string DataMng::getAppNameByAppId(int appId) +{ + return m_modelAppInfoMap.value(appId).m_tagName; +} + +std::string DataMng::getProcDescByAppIdAndProcName(int appId, const std::string &procName) +{ + for(int index(0);index<(int)m_modelProcInfoVec.size();index++) + { + if(m_modelProcInfoVec[index].m_appId == appId && m_modelProcInfoVec[index].m_procName == procName) + { + return m_modelProcInfoVec[index].m_procDesc; + } + } + return ""; +} + +DataMng::DataMng(): + m_mutex(Q_NULLPTR), + m_mutexApp(Q_NULLPTR), + m_mutexProc(Q_NULLPTR) +{ + loadJson(); + loadXml(); + loadVersion(); + m_bBaseIsRun = false; + m_bSysIsRun = false; + m_bIsAllowedOpt = true; + m_mutex = new QMutex; + m_mutexApp = new QMutex; + m_mutexProc = new QMutex; + m_fDisk = 0.0; +} diff --git a/product/src/tools/workBench/tool/DataMng.h b/product/src/tools/workBench/tool/DataMng.h new file mode 100644 index 00000000..41132436 --- /dev/null +++ b/product/src/tools/workBench/tool/DataMng.h @@ -0,0 +1,327 @@ +#ifndef DATAMNG_H +#define DATAMNG_H + +#include +#include +#include + +#include "MonitorCommon.h" +#include "pub_sysinfo_api/SysInfoApi.h" + +class DataMng : public QObject +{ + Q_OBJECT + +public: + + static DataMng *instance(); + void destory(); + +public: + + /** + * @brief getPage1ButtonInfo 获取首页常用按钮 + * @return 常用按钮集合 + */ + QVector getPage1ButtonInfo(); + + /** + * @brief getPage3ButtonInfo 获取工具栏按钮 + * @return 按钮组集合 + */ + QMap getPage3ButtonInfo(); + + /** + * @brief getButtonInfoByName 根据按钮标识获取按钮信息 + * @param name 按钮标识 + * @param buttonInfo 按钮信息 + * @return 成功返回true,失败返回false + */ + bool getButtonInfoByName(const QString &name,workBench::SButtonInfo &buttonInfo); + + /** + * @brief getStartPng 获取启动界面的png图片 + * @return 图片路径 + */ + QString getStartPng(); + + /** + * @brief getStopPng 获取停止界面的png图片 + * @return 图片路径 + */ + QString getStopPng(); + + /** + * @brief getStartBorderColor 获取启动边框、背景色 + * @return rgb + */ + QString getStartBorderColor(); + + /** + * @brief getStopBorderColor 获取停止边框、背景色 + * @return rgb + */ + QString getStopBorderColor(); + + /** + * @brief getStartWaterColor 获取启动界面水波纹 + * @return rgb + */ + QString getStartWaterColor(); + + /** + * @brief getStopWaterColor 获取停止界面水波纹 + * @return rgb + */ + QString getStopWaterColor(); + + /** + * @brief getSysIcon 获取任务栏图标 + * @return icon路径 + */ + QString getSysIcon(); + + /** + * @brief getRestartPng 获取重启的png图片 + * @return 图片路径 + */ + QString getRestartPng(); + + /** + * @brief setBaseStatus 设置base应用状态 + * @param runStatus true-运行 false-停止 + */ + void setBaseStatus(bool runStatus); + + /** + * @brief getBaseStatus 获取base应用状态 + * @return true-运行 false-停止 + */ + bool getBaseStatus(); + + /** + * @brief getHostName 获取本机节点名称 + * @return 节点名 + */ + QString getHostName(); + + /** + * @brief getSysStatus 获取系统运行状态(有任意一个进程运行,则认为系统运行) + * @return true-运行 false-停止 + */ + bool getSysStatus(); + + /** + * @brief setSysStatus 设置系统运行状态 + * @param runStatus 运行状态 + */ + void setSysStatus(bool runStatus); + + /** + * @brief getAllowedStatus 获取是否被允许右键操作 + * @return true-允许 false-禁止 + */ + bool getAllowedStatus(); + + /** + * @brief setAllowedStatus 设置是否被允许右键操作 + * @param allowed true-允许 false-禁止 + */ + void setAllowedStatus(bool allowed); + + /** + * @brief getModelAppInfoById 根据应用id获取建模应用信息 + * @param appId 应用id + * @return 建模应用信息 + */ + workBench::SSysModelAppInfo getModelAppInfoById(int appId); + + /** + * @brief getDeployInfo 获取需要运行的应用信息(初始化应用树使用) + * @return 应用信息 + */ + QMap > getDeployInfo(); + + /** + * @brief getProcInfo 获取需要运行的进程信息(初始化进程树使用) + * @return 进程信息 + */ + std::vector getProcInfo(); + + /** + * @brief setRunAppInfo 设置正在运行的应用状态(数据刷新线程调用) + * @param runAppVec 正在运行的应用状态 + */ + void setRunAppInfo(const std::vector &runAppVec); + + /** + * @brief getRunAppInfo 获取正在运行的应用状态(应用树调用,刷新树) + * @return 正在运行的应用状态 + */ + std::vector getRunAppInfo(); + + /** + * @brief setRunProcInfo 设置正在运行的进程信息(数据刷新线程使用) + * @param runProcVec 正在运行的进程状态 + * @param disk 内存信息 + */ + void setRunProcInfo(const std::vector &runProcVec, const float &disk); + + /** + * @brief getRunProcInfo 获取正在运行的进程信息(进程树调用,刷新树) + * @param procVec 正在运行的进程信息 + * @param disk 总内存 + */ + void getRunProcInfo(std::vector &procVec,float &disk); + + /** + * @brief getDomainId 获取本节点所属域id + * @return 域id + */ + int getDomainId(); + + /** + * @brief getInitAppInfoVec 获取初始的应用状态 + * @return 应用状态 + */ + std::vector getInitAppInfoVec(); + + /** + * @brief getInitProcInfoVec 获取初始的进程状态 + * @return 进程状态 + */ + std::vector getInitProcInfoVec(); + + /** + * @brief getAppDescByAppId 根据应用id获取应用描述 + * @param appId 应用id + * @return 应用描述 + */ + std::string getAppDescByAppId(int appId); + + /** + * @brief getAppNameByAppId 获取appName + * @param appId appId + * @return appName + */ + std::string getAppNameByAppId(int appId); + + /** + * @brief getProcDescByAppIdAndProcName 根据应用id和进程名称获取进程描述 + * @param appId 应用id + * @param procName 进程名称 + * @return 进程描述 + */ + std::string getProcDescByAppIdAndProcName(int appId, const std::string &procName); + + /** + * @brief loadXml 重新拉取进程信息 + */ + void loadXml(); + + /** + * @brief getLocalProcNum 获取本机应该启动进程个数 + * @return 进程个数 + */ + int getLocalProcNum(); + + /** + * @brief getVersionInfo 获取版本信息 + * @return 版本信息 + */ + QMap getVersionInfo(); + + /** + * @brief getTitle 获取标题 + * @return 标题 + */ + QString getTitle(); + + /** + * @brief addPage1ButtonInfo 添加相关自定义按钮组件 + * @return + */ + void addPage1ButtonInfo(const QList &buttonInfo); + + /** + * @brief addPage3ButtonInfo 针对工具栏界面添加相关自定义按钮组件 + * @return + */ + void addPage3ButtonInfo(int index , const workBench::SButtonInfo &buttonInfo); + + /** + * @brief reLoadButtonInfo 重新载入按钮的配置文件 + * @return + */ + void reLoadButtonInfo(); + + /** + * @brief modifyLanguageXml 修改语言配置文件 + * @return bool true成功 false失败 + */ + bool modifyLanguageXml(QString value); + +private: + DataMng(); + + bool loadJson(); + + void loadVersion(); + + void loadLocInfo(); + + void loadUsedNode(); + + void loadModelAppInfo(); + + void loadModelDeployInfo(); + + bool nodeIsUsed(const std::string &nodeName); + + void loadLocalProcInfo(); + +private: + static DataMng *m_pInstance; + + //视图相关 + QMap m_buttonInfoMap; //< 按钮信息 + QVector m_page1ButtonInfoVec; //< 首页常用按钮 + QMap m_page3ButtonInfoMap; //< 工具栏页按钮 + QString m_stStartPng; //< 开始前界面图片 + QString m_stStopPng; //< 停止前界面图片 + QString m_stStartBorderColor; //< 开始进度条边框和背景色 + QString m_stStopBorderColor; //< 停止进度条边框和背景色 + QString m_stStartWaterColor; //< 开始进度条水波纹 + QString m_stStopWaterColor; //< 停止进度条水波纹 + QString m_stSysIcon; //< 程序图标栏图标 + QString m_stRestartPng; //< 重启图标 + + + //节点应用相关 + QVector m_nodeVec; //< 所有启用的节点名称 + QMap m_modelAppInfoMap; //< 系统建模应用信息 + QMap > m_modelDeployInfoMap; //< 所有需要运行的应用信息 + std::vector m_modelProcInfoVec; //< 所需要运行的进程信息 + + QMap m_nodeLocIdMap; + QMap m_locIdDomainOdMap; + + //系统运行相关 + QMutex * m_mutex; //< 基础变量锁 + bool m_bBaseIsRun; //< 基础应用运行状态 + bool m_bSysIsRun; //< 系统运行状态 + bool m_bIsAllowedOpt; //< 是否备允许右键操作 + QMutex * m_mutexApp; //< 应用运行信息锁 + std::vector m_sysRunAppInfoVec; //< 应用运行信息(运行状态) + QMutex * m_mutexProc; + std::vector m_sysRunProcInfoVec; //< 进程运行信息(运行状态) + float m_fDisk; //< 所有进程所占内存 + int m_nLocalProcNum; //< 本节点运行进程的个数 + + //系统版本和安装配置数据 + QMap m_versionMap; //< 版本信息数据 + QString m_Title; //< 标题 + +}; + +#endif // DATAMNG_H diff --git a/product/src/tools/workBench/tool/InputDialog.cpp b/product/src/tools/workBench/tool/InputDialog.cpp new file mode 100644 index 00000000..9e653634 --- /dev/null +++ b/product/src/tools/workBench/tool/InputDialog.cpp @@ -0,0 +1,123 @@ +#include "InputDialog.h" +#include "pub_widget/MessageBox.h" + +#include +InputDialog::InputDialog(QWidget *parent) : + CustomDialog(parent), + m_nameLineEdit(Q_NULLPTR), + m_exePathLabel(Q_NULLPTR), + m_buttonBox(Q_NULLPTR) +{ + initView(); + + connect(m_buttonBox, &QDialogButtonBox::accepted, this, &InputDialog::validateInput); + connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); +} + +void InputDialog::initView() +{ + setWindowTitle(tr("新增快捷方式")); + m_nameLineEdit = new QLineEdit(this); + m_nameLineEdit->setPlaceholderText("请输入名称:"); + m_nameLineEdit->setObjectName("titleLabel"); + m_picturePathLabel = new QLabel(this); + m_exePathLabel = new QLabel(this); + m_buttonBox = new QDialogButtonBox(Qt::Horizontal , this); + + QPushButton *confirmbtn = new QPushButton(tr("确定")); + QPushButton *cancelbtn = new QPushButton(tr("取消")); + m_buttonBox->addButton(confirmbtn , QDialogButtonBox::AcceptRole); + m_buttonBox->addButton(cancelbtn , QDialogButtonBox::RejectRole); + + //创建布局 + QGridLayout *Layout = new QGridLayout(this); + + // 姓名输入框 + QLabel *nameLabel = new QLabel(tr("数据填写:"), this); + Layout->addWidget(nameLabel); + Layout->addWidget(m_nameLineEdit); + + // 图片文件选择 + QPushButton *pictureButton = new QPushButton(tr("请选择图片"), this); + connect(pictureButton, &QPushButton::clicked, this, &InputDialog::selectPictureFile); + Layout->addWidget(pictureButton); + Layout->addWidget(m_picturePathLabel); + + // .exe文件选择 + QPushButton *exeButton = new QPushButton(tr("请选择执行文件"), this); + connect(exeButton, &QPushButton::clicked, this, &InputDialog::selectExeFile); + Layout->addWidget(exeButton); + Layout->addWidget(m_exePathLabel); + Layout->addWidget(m_buttonBox); + + setLayout(Layout); + m_picturePathLabel->setHidden(true); + m_exePathLabel->setHidden(true); + m_picturePathLabel->setWordWrap(true); + m_exePathLabel->setWordWrap(true); + + adjustSize(); +} + +void InputDialog::getDataInput(QString &name, QString &picturePath, QString &exePath) +{ + name = m_nameLineEdit->text(); + picturePath = m_picturePathLabel->text(); + exePath = m_exePathLabel->text(); +} + +void InputDialog::selectPictureFile() +{ + QString relativeFilePath = QString(""); + QString relativeDirectory = "../../data/workBench"; + QString filePath = QFileDialog::getOpenFileName(this, tr("选择图片"), + relativeDirectory, + tr("Images (*.png *.jpg *.bmp)"), + nullptr, + QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly); + if (!filePath.isEmpty()) { + QDir dir(QDir::currentPath()); + relativeFilePath = dir.relativeFilePath(filePath); + }else + { + //设置默认的图标 + relativeFilePath = "../../data/UserPicture/default.png"; + } + m_picturePathLabel->setText(relativeFilePath); + m_picturePathLabel->setHidden(false); + adjustSize(); +} + +void InputDialog::selectExeFile() +{ + QString filePath = QFileDialog::getOpenFileName(this, tr("选择执行文件"), + "", + tr("Executables (*.exe *.bat)"), + nullptr, + QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly); + if (!filePath.isEmpty()) + { + QFileInfo fileInfo(filePath); + m_exePathLabel->setText(fileInfo.fileName()); + m_exePathLabel->setHidden(false); + adjustSize(); + } +} + +void InputDialog::validateInput() +{ + if (m_nameLineEdit->text().isEmpty() || m_picturePathLabel->text().isEmpty() || m_exePathLabel->text().isEmpty()) { + N_MessageBox::warning(this, tr("警告"), tr("请填写相应数据!")); + return; + } + + // 获取数据 + QString name = m_nameLineEdit->text(); + QString picturePath = m_picturePathLabel->text(); + QString exePath = m_exePathLabel->text(); + + // 执行其他操作 + emit dataReady(name, picturePath, exePath); + accept(); +} + diff --git a/product/src/tools/workBench/tool/InputDialog.h b/product/src/tools/workBench/tool/InputDialog.h new file mode 100644 index 00000000..4a1a8d00 --- /dev/null +++ b/product/src/tools/workBench/tool/InputDialog.h @@ -0,0 +1,44 @@ +#ifndef INPUTDIALOG_H +#define INPUTDIALOG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pub_widget/CustomDialog.h" + +class InputDialog : public CustomDialog +{ + Q_OBJECT +public: + explicit InputDialog(QWidget *parent = nullptr); + + void getDataInput(QString &name, QString &picturePath, QString &exePath); +private: + void initView(); + +private slots: + void selectPictureFile(); + + void selectExeFile(); + + void validateInput(); + +signals: + void dataReady(QString name, QString picturePath, QString exePath); + +private: + QLineEdit *m_nameLineEdit; + QLabel *m_picturePathLabel; + QLabel *m_exePathLabel; + QDialogButtonBox *m_buttonBox; +}; + +#endif // INPUTDIALOG_H diff --git a/product/src/tools/workBench/workBench.pro b/product/src/tools/workBench/workBench.pro new file mode 100644 index 00000000..f43ef765 --- /dev/null +++ b/product/src/tools/workBench/workBench.pro @@ -0,0 +1,158 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2021-01-22T11:45:30 +# +#------------------------------------------------- + +QT += core gui +QT += network +QT += xml +QT += sql + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +#提升权限测试 +win32{ +QMAKE_LFLAGS += /MANIFESTUAC:\"level=\'requireAdministrator\' uiAccess=\'false\'\" +} +TARGET = workBench +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +INCLUDEPATH += $$PWD/tool + +SOURCES += \ + Main.cpp \ + MainWindow.cpp \ + SingleApplication.cpp \ + SingleApplication_p.cpp \ + StartUpForm.cpp \ + MyProgressBar.cpp \ + AppMngForm.cpp \ + ProcMngForm.cpp \ + ButtonForm.cpp \ + BrushDataThread.cpp \ + OnTimeCheckThread.cpp \ + StatusForm.cpp \ + DogCheck.cpp \ + DbCheck.cpp \ + AutoStart.cpp \ + SetupFuncLinux.cpp \ + SetupFuncWindows.cpp \ + DbCheckSync.cpp \ + localstateform.cpp \ + tool/CheckBoxDialog.cpp \ + tool/DataMng.cpp \ + tool/InputDialog.cpp \ + SystemSetForm.cpp \ + ModifyButtonForm.cpp + +HEADERS += \ + MainWindow.h \ + SingleApplication.h \ + SingleApplication_p.h \ + MonitorCommon.h \ + StartUpForm.h \ + MyProgressBar.h \ + AppMngForm.h \ + ProcMngForm.h \ + ButtonForm.h \ + BrushDataThread.h \ + OnTimeCheckThread.h \ + StatusForm.h \ + DogCheck.h \ + DbCheck.h \ + AutoStart.h \ + SetupFunc.h \ + DbCheckSync.h \ + localstateform.h \ + tool/CheckBoxDialog.h \ + tool/DataMng.h \ + tool/CommonEnum.h \ + tool/InputDialog.h \ + SystemSetForm.h \ + ModifyButtonForm.h + +FORMS += \ + mainwindow.ui \ + StartUpForm.ui \ + AppMngForm.ui \ + ProcMngForm.ui \ + ButtonForm.ui \ + StatusForm.ui \ + DogCheck.ui \ + DbCheck.ui \ + AutoStart.ui \ + localstateform.ui \ + SystemSetForm.ui \ + ModifyButtonForm.ui + + +LIBS += -lboost_system +LIBS += -lboost_chrono +LIBS += -lnet_msg_bus_api +LIBS += -llog4cplus +LIBS += -lpub_logger_api +LIBS += -lcrypto +LIBS += -lpub_utility_api +LIBS += -lpub_sysinfo_api +LIBS += -lrdb_api +LIBS += -lrdb_net_api +LIBS += -ldb_base_api +LIBS += -ldb_sysinfo_api +LIBS += -ldb_base_api +LIBS += -ldb_api_ex +LIBS += -ltsdb_api +LIBS += -lperm_mng_api +LIBS += -lprotobuf +LIBS += -lsys_dog_auth_api +LIBS += -lsys_login_api +LIBS += -lpub_widget + +include($$PWD/../../idl_files/idl_files.pri) + +SIGAR_PRI=$$PWD/../../../../platform/src/3rd/compiled_in/sigar/sigar.pri +exists($$SIGAR_PRI) { + include($$SIGAR_PRI) +}else { + error("FATAL error: can not find sigar.pri") +} + +DEFINES += QAPPLICATION_CLASS=QApplication + +# 判架构 +contains(QMAKE_HOST.arch, x86_64): !linux-aarch64*{ + message("Host is amd64") + DEFINES += KBD_X86 +} +else{ + DEFINES += KBD_ARM + message("Host is arm64") +} + +#------------------------------------------------------------------- +COMMON_PRI=$$PWD/../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} + +contains(DEFINES, OS_WINDOWS) { + RC_ICONS = sys_startup.ico +} + +RESOURCES += \ + resource.qrc + +TRANSLATIONS = $$PWD/en.ts\ + $$PWD/fr.ts