DSRM020MF.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "AppGlobalF.h"
  6. #include "ITSLangTransF.h"
  7. #include "CenterCommF.h"
  8. #include "CDSFacilityF.h"
  9. #pragma hdrstop
  10. #include "DSRM020MF.h"
  11. //---------------------------------------------------------------------------
  12. #pragma package(smart_init)
  13. #pragma link "cxButtons"
  14. #pragma link "cxClasses"
  15. #pragma link "cxContainer"
  16. #pragma link "cxControls"
  17. #pragma link "cxCustomData"
  18. #pragma link "cxData"
  19. #pragma link "cxDataStorage"
  20. #pragma link "cxEdit"
  21. #pragma link "cxFilter"
  22. #pragma link "cxGraphics"
  23. #pragma link "cxGrid"
  24. #pragma link "cxGridCustomTableView"
  25. #pragma link "cxGridCustomView"
  26. #pragma link "cxGridLevel"
  27. #pragma link "cxGridTableView"
  28. #pragma link "cxGroupBox"
  29. #pragma link "cxLabel"
  30. #pragma link "cxLookAndFeelPainters"
  31. #pragma link "cxLookAndFeels"
  32. #pragma link "cxRadioGroup"
  33. #pragma link "cxSplitter"
  34. #pragma link "cxStyles"
  35. #pragma link "dxSkinBlack"
  36. #pragma link "dxSkinBlue"
  37. #pragma link "dxSkinsCore"
  38. #pragma link "dxSkinscxPCPainter"
  39. #pragma link "dxSkinMcSkin"
  40. #pragma resource "*.dfm"
  41. TDSRM020M *DSRM020M = NULL;
  42. //---------------------------------------------------------------------------
  43. __fastcall TDSRM020M::TDSRM020M(TComponent* Owner)
  44. : TForm(Owner)
  45. {
  46. LangTrans->Translate(this, ITSDb_GetConnection());
  47. ITSSkin_Load(this);
  48. CMM_LoadForm(g_sFormsDir, this);
  49. FTitle = Caption;
  50. FReqSeq = 0;
  51. TvResult->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<제어전송결과>";
  52. FRAMEDsrcList1->PnlBottom->Visible = false;
  53. FRAMEDsrcList1->Column04->Visible = true; // IP Address
  54. FRAMEDsrcList1->Column05->Visible = true; // 통신상태
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TDSRM020M::CommClose()
  58. {
  59. try
  60. {
  61. CMM_SaveForm(g_sFormsDir, this);
  62. }
  63. catch(...)
  64. {
  65. }
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TDSRM020M::FormShow(TObject *Sender)
  69. {
  70. Refresh();
  71. FormInit();
  72. TmrShow->Enabled = true;
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TDSRM020M::FormInit()
  76. {
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TDSRM020M::TmrShowTimer(TObject *Sender)
  80. {
  81. TmrShow->Enabled = false;
  82. RdoController->Checked = true;
  83. FRAMEDsrcList1->UpdateListStatus();
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TDSRM020M::BtnCloseClick(TObject *Sender)
  87. {
  88. Close();
  89. }
  90. //---------------------------------------------------------------------------
  91. void __fastcall TDSRM020M::FormClose(TObject *Sender, TCloseAction &Action)
  92. {
  93. CommClose();
  94. DSRM020M = NULL;
  95. Action = caFree;
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TDSRM020M::FormCloseQuery(TObject *Sender, bool &CanClose)
  99. {
  100. FRAMEDsrcList1->OnCloseQuery(CanClose);
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TDSRM020M::BtnControlClick(TObject *Sender)
  104. {
  105. int nSelects = CMM_GetCheckCount(FRAMEDsrcList1->TvList, FRAMEDsrcList1->ColumnSel->Index);
  106. if (0 == nSelects)
  107. {
  108. Application->MessageBox(L"제어 목록을 선택하지 않았습니다.", FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
  109. FRAMEDsrcList1->CxList->SetFocus();
  110. return;
  111. }
  112. int ii;
  113. int nRowCnt = FRAMEDsrcList1->TvList->ViewData->RecordCount;
  114. int nNormalCount = 0;
  115. for (ii = 0; ii < nRowCnt; ii++)
  116. {
  117. TcxCustomGridRow* ARow = FRAMEDsrcList1->TvList->ViewData->Rows[ii];
  118. if (((bool)ARow->Values[FRAMEDsrcList1->ColumnSel->Index]))
  119. {
  120. String sComm = "";
  121. if (!VarIsNull(ARow->Values[FRAMEDsrcList1->Column06->Index]))
  122. sComm = ARow->Values[FRAMEDsrcList1->Column06->Index];
  123. if (sComm != str_state_error)
  124. nNormalCount++;
  125. }
  126. }
  127. #if 0
  128. if (0 == nNormalCount)
  129. {
  130. Application->MessageBox(L"통신상태가 정상일 경우에만 제어명령을 전송 할 수 있습니다.", FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
  131. FRAMEDsrcList1->CxList->SetFocus();
  132. return;
  133. }
  134. #endif
  135. if (!RdoController->Checked && !RdoAnt1->Checked)
  136. {
  137. Application->MessageBox(L"장치 유형을 선택하지 않았습니다.\r\n장치 유형을 선택하세요.", FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
  138. return;
  139. }
  140. if (!RdoReset->Checked && !RdoStop->Checked && !RdoStart->Checked)
  141. {
  142. Application->MessageBox(L"제어 유형을 선택하지 않았습니다.\r\n제어 유형을 선택하세요.", FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
  143. return;
  144. }
  145. if (Application->MessageBox(L"제어전송확인\r\n선택한 DSRC에 대하여 제어명령을 전송하시겠습니까??",
  146. FTitle.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;
  147. int nRow;
  148. int nResult;
  149. dsrc_device_code DeviceType;
  150. dsrc_control_code ControlType;
  151. DeviceType = dsrc_device_main;
  152. if (RdoAnt1->Checked)
  153. {
  154. DeviceType = dsrc_device_antena1;
  155. }
  156. ControlType = dsrc_control_reset;
  157. if (RdoStop->Checked)
  158. {
  159. ControlType = dsrc_control_stop;
  160. }
  161. else
  162. if (RdoStart->Checked)
  163. {
  164. ControlType = dsrc_control_start;
  165. }
  166. CMM_ClearGridTableView(TvResult);
  167. BYTE MsgSeq;
  168. INT_DSRC_CONTROL_REQ ControlReq;
  169. memset(&ControlReq, 0x00, sizeof(ControlReq));
  170. String sCmdUser = g_pLOGIN->sUserId;
  171. String sCmdTime = Now().FormatString("yyyymmddhhnnss");
  172. try
  173. {
  174. FRAMEDsrcList1->TvList->BeginUpdate();
  175. TvResult->BeginUpdate();
  176. nRowCnt = FRAMEDsrcList1->TvList->ViewData->RecordCount;
  177. for (ii = 0; ii < nRowCnt; ii++)
  178. {
  179. TcxCustomGridRow* ARow = FRAMEDsrcList1->TvList->ViewData->Rows[ii];
  180. if (((bool)ARow->Values[FRAMEDsrcList1->ColumnSel->Index]))
  181. {
  182. String sId = VarToStr(ARow->Values[FRAMEDsrcList1->Column01->Index]);
  183. nRow = TvResult->DataController->AppendRecord();
  184. TvResult->DataController->Values[nRow][ColDsrcId->Index] = sId;
  185. // TODO: 제어기 통신상태를 확인하고 전송하도록 하자.
  186. // 한패킷에 여러제어기를 합쳐서 전송할 수 있도록 하자.
  187. bool isCommNormal = true;//false;
  188. String sComm = "";
  189. if (!VarIsNull(ARow->Values[FRAMEDsrcList1->Column06->Index]))
  190. sComm = ARow->Values[FRAMEDsrcList1->Column06->Index];
  191. if (sComm != str_state_error)
  192. isCommNormal = true;
  193. if (isCommNormal)
  194. {
  195. String sSendDate = Now().FormatString("YYYYMMDD");
  196. String sSendTime = Now().FormatString("HHNNSS");
  197. memset(&ControlReq, 0x00, sizeof(ControlReq));
  198. MsgSeq = (BYTE)0x90;
  199. memcpy(ControlReq.CmdTime, AnsiString(sCmdTime).c_str(), INT_DSRC_MAX_DATETIME); /* 명령수행시각 */
  200. memcpy(ControlReq.OperId, AnsiString(sCmdUser).c_str(), INT_DSRC_MAX_OPER_ID); /* 운영자 ID */
  201. ControlReq.ReqSeq = FReqSeq;
  202. ControlReq.DSRC_CTLR_NMBR = sId.ToIntDef(0);
  203. ControlReq.DeviceType = DeviceType;
  204. ControlReq.ControlType = ControlType;
  205. TvResult->DataController->Values[nRow][ColReqSeq->Index] = String(FReqSeq);
  206. nResult = CComm_DsrcControlReq(&ControlReq);
  207. if (VERR_NONE == nResult)
  208. {
  209. TvResult->DataController->Values[nRow][ColReqResult->Index] = "성공";
  210. }
  211. else
  212. {
  213. TvResult->DataController->Values[nRow][ColReqResult->Index] = "실패";
  214. }
  215. TvResult->DataController->Values[nRow][ColResResult->Index] = "응답대기";
  216. FReqSeq++;
  217. }
  218. else
  219. {
  220. TvResult->DataController->Values[nRow][ColReqSeq->Index] = "-";
  221. TvResult->DataController->Values[nRow][ColReqResult->Index] = "통신이상";
  222. TvResult->DataController->Values[nRow][ColResResult->Index] = "-";
  223. }
  224. }
  225. }
  226. }
  227. __finally
  228. {
  229. FRAMEDsrcList1->TvList->EndUpdate();
  230. TvResult->EndUpdate();
  231. }
  232. #if 0
  233. dsrc_response_succ, /* 0: 성공 */
  234. dsrc_response_nack, /* 1: 거절 */
  235. dsrc_response_none, /* 2: 응답없음 */
  236. #endif
  237. Application->MessageBox(L"제어명령을 전송 하였습니다.", FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  238. }
  239. //---------------------------------------------------------------------------
  240. void __fastcall TDSRM020M::OnMainFormMessage(TMessage &Msg)
  241. {
  242. IPC_MSG_DATA *RcvData = (IPC_MSG_DATA*)Msg.LParam;
  243. INT_SENDER *Sender = &RcvData->Sender;
  244. INT_PACKET *Pkt = &RcvData->Pkt;
  245. INT_HEAD *head = &Pkt->head;
  246. INT_DATA *data = &Pkt->data;
  247. char *pData = &Pkt->data.Data[0];
  248. BYTE OpCode = head->OpCode;
  249. switch (Msg.WParam)
  250. {
  251. case INT_OP_DSRC_CONTROL_RES: /* 0xC1, RSE 제어정보 응답 */
  252. {
  253. INT_DSRC_CONTROL_RES *pRseCtl;
  254. pRseCtl = (INT_DSRC_CONTROL_RES *)pData;
  255. String sResId = String(pRseCtl->DSRC_CTLR_NMBR);
  256. String sResSeq = String(pRseCtl->ReqSeq);
  257. int nResult = (int)pRseCtl->ResCode;
  258. try {
  259. TvResult->BeginUpdate();
  260. int nRowCnt = TvResult->ViewData->RecordCount;
  261. for (int ii = 0; ii < nRowCnt; ii++)
  262. {
  263. TcxCustomGridRow* ARow = TvResult->ViewData->Rows[ii];
  264. {
  265. String sId = VarToStr(ARow->Values[ColDsrcId->Index]);
  266. String sSeq= VarToStr(ARow->Values[ColReqSeq->Index]);
  267. if (sResId == sId && sResSeq == sSeq)
  268. {
  269. String sResult = "Unknown";
  270. if (nResult == (int)dsrc_response_succ) sResult = "성공";
  271. else
  272. if (nResult == (int)dsrc_response_nack) sResult = "실패";
  273. else
  274. if (nResult == (int)dsrc_response_none) sResult = "응답없음";
  275. ARow->Values[ColResResult->Index] = sResult;
  276. break;
  277. }
  278. }
  279. }
  280. }
  281. __finally
  282. {
  283. TvResult->EndUpdate();
  284. }
  285. }
  286. break;
  287. default:
  288. break;
  289. }/* end switch */
  290. }
  291. //---------------------------------------------------------------------------
  292. void __fastcall TDSRM020M::RdoControllerClick(TObject *Sender)
  293. {
  294. RdoStop->Enabled = false;
  295. RdoStart->Enabled = false;
  296. RdoReset->Enabled = true;
  297. RdoReset->Checked = true;
  298. }
  299. //---------------------------------------------------------------------------
  300. void __fastcall TDSRM020M::RdoAnt1Click(TObject *Sender)
  301. {
  302. RdoReset->Enabled = false;
  303. RdoStop->Enabled = true;
  304. RdoStart->Enabled = true;
  305. RdoStop->Checked = true;
  306. }
  307. //---------------------------------------------------------------------------
  308. void __fastcall TDSRM020M::ColResResultCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  309. bool &ADone)
  310. {
  311. TColor tColor = ACanvas->Brush->Color;
  312. TColor tFont = clBlack;
  313. try
  314. {
  315. TColor tColor;
  316. String sStatus = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index];
  317. tColor = ACanvas->Brush->Color;
  318. if (sStatus.Pos("응답없음")) tColor = clRed;
  319. else if (sStatus.Pos("실패")) tColor = clRed;
  320. else if (sStatus.Pos("응답대기")) tColor = clYellow;
  321. else if (sStatus.Pos("성공")) tColor = clLime;
  322. else tColor = clGray;
  323. ACanvas->SetBrushColor(tColor);
  324. if (tColor == clRed) tFont = clWhite;
  325. ACanvas->Font->Color = tFont;
  326. }
  327. catch(Exception &e)
  328. {
  329. }
  330. }
  331. //---------------------------------------------------------------------------