WCAM020MF.cpp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSSkinF.h"
  5. #include "ITSUtilF.h"
  6. #include "ITSLangTransF.h"
  7. #include "ITS_OPLibF.h"
  8. #pragma hdrstop
  9. #include "WCAM020MF.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma link "cxButtons"
  13. #pragma link "cxCalc"
  14. #pragma link "cxCheckBox"
  15. #pragma link "cxClasses"
  16. #pragma link "cxContainer"
  17. #pragma link "cxControls"
  18. #pragma link "cxCustomData"
  19. #pragma link "cxData"
  20. #pragma link "cxDataStorage"
  21. #pragma link "cxEdit"
  22. #pragma link "cxFilter"
  23. #pragma link "cxGraphics"
  24. #pragma link "cxGrid"
  25. #pragma link "cxGridBandedTableView"
  26. #pragma link "cxGridCustomTableView"
  27. #pragma link "cxGridCustomView"
  28. #pragma link "cxGridLevel"
  29. #pragma link "cxGridTableView"
  30. #pragma link "cxGroupBox"
  31. #pragma link "cxLabel"
  32. #pragma link "cxLookAndFeelPainters"
  33. #pragma link "cxLookAndFeels"
  34. #pragma link "cxMaskEdit"
  35. #pragma link "cxPC"
  36. #pragma link "cxPCdxBarPopupMenu"
  37. #pragma link "cxSpinEdit"
  38. #pragma link "cxStyles"
  39. #pragma link "cxTextEdit"
  40. #pragma link "dxSkinBlue"
  41. #pragma link "dxSkinsCore"
  42. #pragma link "dxSkinscxPCPainter"
  43. #pragma link "FFBaseComponent"
  44. #pragma link "FFBasePlay"
  45. #pragma link "FFPlay"
  46. #pragma link "FRAME_WCamStateListF"
  47. #pragma link "IdBaseComponent"
  48. #pragma link "IdComponent"
  49. #pragma link "IdIcmpClient"
  50. #pragma link "IdRawBase"
  51. #pragma link "IdRawClient"
  52. #pragma link "ImageBtn"
  53. #pragma link "XNVTViewerCtrlLib_OCX"
  54. #pragma link "dxSkinBlack"
  55. #pragma link "dxSkinMcSkin"
  56. #pragma resource "*.dfm"
  57. TWCAM020M *WCAM020M = NULL;
  58. //{* Information Bar *}
  59. #define CAP_CAMERA_NAME 0x01
  60. #define CAP_TIME 0x02
  61. #define CAP_CHANNEL 0x04
  62. #define CAP_SIZE 0x08
  63. #define CAP_EVENT 0x10
  64. #define CAP_FPSCHANGED 0x20
  65. //{* Pan/tilt/Zoom and Transparent controls *}
  66. #define CTL_FOCUS_CONT 0x2001
  67. #define CTL_PTZ_CONT 0x2002
  68. #define CTL_TRANSPARENT 0x7000
  69. #define CTL_TRANSPARENT_RS232 0x7001
  70. //{* OCXState for NVSMPEG4OCX *}
  71. #define GRAPH_NONE 0x00000000
  72. #define GRAPH_PREVIEW 0x00000001
  73. #define GRAPH_CAPTURE 0x00000002
  74. #define GRAPH_PREVIEWCAPTURE 0x00000003
  75. #define GRAPH_AUDIO_LISTEN 0x00000100
  76. #define GRAPH_AUDIO_CAPTURE 0x00000200
  77. #define GRAPH_AUDIO_LISTENCAPTURE 0x00000400
  78. #define GRAPH_STATE_RUNNING 0x80000000
  79. #define SB_PAN_LEFT 0x000000C4
  80. #define SB_PAN_RIGHT 0x0000003C
  81. #define SB_TILT_UP 0x00003C00
  82. #define SB_TILT_DOWN 0x0000C400
  83. #define SB_ZOOM_IN 0x003C0000
  84. #define SB_ZOOM_OUT 0x00C40000
  85. #define SB_FOCUS_IN 0x3C
  86. #define SB_FOCUS_OUT 0xC4
  87. enum { E_MJPG=0, E_MP4S, E_DX50, E_MPEG2, E_MPEG1, E_H264 };
  88. enum { BR_32K=0, BR_64K, BR_128K, BR_256K, BR_384K, BR_500K, BR_750K, BR_1M, BR_1_5M, BR_2M, BR_4M, BR_5M, BR_6M, BR_7M, BR_8M };
  89. enum { S_1080P=0, S_720P, S_D1, S_4CIF, S_VGA, S_HD1, S_H4CIF, S_HVGA, S_CIF, S_QVGA, S_QCIF, S_QQVGA };
  90. #define PRESET_SET 0x1020 // Unsigned 1 byte
  91. #define PRESET_MOVE 0x1021 // Unsigned 1 byte
  92. #define PRESET_CLEAR 0x1022 // Unsigned 1 byte
  93. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  94. //---------------------------------------------------------------------------
  95. __fastcall TWCAM020M::TWCAM020M(TComponent* Owner)
  96. : TForm(Owner)
  97. {
  98. //::CoInitialize(NULL);
  99. LangTrans->Translate(this, ITSDb_GetConnection());
  100. ITSSkin_Load(this);
  101. LoadLocalSkin();
  102. CMM_LoadForm(g_sFormsDir, this);
  103. FSelCtlr = NULL;
  104. FRAMEWCamStateList1->PnlTop->Visible = false;
  105. FRAMEWCamStateList1->PnlBottom->Visible = false;
  106. FRAMEWCamStateList1->TvList->OptionsView->Footer = false;
  107. FRAMEWCamStateList1->Col04->Visible = false;
  108. FRAMEWCamStateList1->Col05->Visible = false;
  109. FRAMEWCamStateList1->Col06->Visible = true;
  110. FRAMEWCamStateList1->ColumnSel->Visible = false;
  111. PgControl->ActivePageIndex = 0;
  112. FSelIds = new TStringList();
  113. FTitle = Caption;
  114. //TabPreset->Visible = false;
  115. //TabPreset->TabVisible = false;
  116. FStrmPlay = false;
  117. String sAVILibDir = g_sAppDir + "LibAV";
  118. FFPlayer1->SetLicenseKey(LICENSE_KEY);
  119. FFPlayer1->DisableFPUExceptions();
  120. if (!FFPlayer1->LoadAVLib(sAVILibDir))
  121. {
  122. reMsg->Lines->Add("영상표출 라이브러리 초기화 실패.");
  123. #if 0
  124. if (g_sLang!= "kr") Application->MessageBox(L"Stream display library load failed.", L"Stream display fail", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  125. else Application->MessageBox(L"영상표출 라이브러리를 로드하지 못하였습니다.", L"영상표출 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  126. #endif
  127. }
  128. PgCam->Properties->HideTabs = true;
  129. PnlCamera->ParentColor = false;
  130. FTmrShow = true;
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TWCAM020M::CommClose()
  134. {
  135. try
  136. {
  137. SAFE_DELETE(FSelIds);
  138. CMM_SaveForm(g_sFormsDir, this);
  139. CloseWebCamera();
  140. CloseRtsp();
  141. //::CoUninitialize();
  142. }
  143. catch(...)
  144. {
  145. }
  146. }
  147. //---------------------------------------------------------------------------
  148. void __fastcall TWCAM020M::FormShow(TObject *Sender)
  149. {
  150. Refresh();
  151. TmrShow->Enabled = FTmrShow;
  152. }
  153. //---------------------------------------------------------------------------
  154. void __fastcall TWCAM020M::FormActivate(TObject *Sender)
  155. {
  156. ActivateForm(true);
  157. }
  158. //---------------------------------------------------------------------------
  159. void __fastcall TWCAM020M::FormDeactivate(TObject *Sender)
  160. {
  161. ActivateForm(false);
  162. }
  163. //---------------------------------------------------------------------------
  164. void __fastcall TWCAM020M::LoadLocalSkin()
  165. {
  166. PnlCamera->ParentColor = false;
  167. PnlCamera->Color = clBlack;
  168. //XNVTViewerCtrl1->Visible = false;
  169. Refresh();
  170. }
  171. //---------------------------------------------------------------------------
  172. void __fastcall TWCAM020M::TmrShowTimer(TObject *Sender)
  173. {
  174. TmrShow->Enabled = false;
  175. FRAMEWCamStateList1->UpdateList();
  176. FRAMEWCamStateList1->CxList->Enabled = false;
  177. UpdatePingList();
  178. FRAMEWCamStateList1->CxList->Enabled = true;
  179. }
  180. //---------------------------------------------------------------------------
  181. void __fastcall TWCAM020M::FormClose(TObject *Sender, TCloseAction &Action)
  182. {
  183. try {
  184. CommClose();
  185. WCAM020M = NULL;
  186. Action = caFree;
  187. } catch(...) {}
  188. }
  189. //---------------------------------------------------------------------------
  190. void __fastcall TWCAM020M::OnMainFormMessage(TMessage &Msg)
  191. {
  192. }
  193. //---------------------------------------------------------------------------
  194. void __fastcall TWCAM020M::OnCctvStateRefreshMessage(TMessage &Msg)
  195. {
  196. FRAMEWCamStateList1->RefreshStatus();
  197. RefreshPingList();
  198. }
  199. //---------------------------------------------------------------------------
  200. void __fastcall TWCAM020M::ActivateForm(bool AActivate)
  201. {
  202. if (AActivate) FRAMEWCamStateList1->RefreshStatus();
  203. }
  204. //---------------------------------------------------------------------------
  205. void __fastcall TWCAM020M::DisplayInfo()
  206. {
  207. ClearPreset();
  208. FSelCtlr = NULL;
  209. PnlCctv->Caption = " " + lblSelCctv->Caption + " -";//" Select CCTV: -";
  210. TcxGridBandedTableView *TvList = FRAMEWCamStateList1->TvList;
  211. TcxDataController *pGDC = TvList->DataController;
  212. int nSelIdx = CMM_GetRecordIndex(TvList);
  213. if (nSelIdx < 0) return;
  214. String CTLR_NMBR = VarToStr(pGDC->Values[nSelIdx][FRAMEWCamStateList1->Col01->Index]);
  215. int nMemPtr = (int)pGDC->Values[nSelIdx][FRAMEWCamStateList1->Col99->Index];
  216. FSelCtlr = (TWCamCtlr*)nMemPtr;
  217. if (!FSelCtlr) return;
  218. PnlCctv->Caption = " " + lblSelCctv->Caption + " [" + FSelCtlr->WCAM_CTLR_ID + "] " + FSelCtlr->WCAM_NM;
  219. PnlCamConrtol->Enabled = false;
  220. PnlPreset->Enabled = false;
  221. try
  222. {
  223. if (FSelCtlr->WCAM_TYPE_CD == "WEB")
  224. {
  225. CloseRtsp();
  226. if (OpenWebCamera())
  227. {
  228. InitPreset();
  229. PnlCamConrtol->Enabled = true;
  230. PnlPreset->Enabled = true;
  231. }
  232. }
  233. else
  234. {
  235. CloseWebCamera();
  236. if (XNVTViewerCtrl1->Visible) XNVTViewerCtrl1->Visible = false;
  237. OpenRtsp();
  238. }
  239. }
  240. catch(Exception &e)
  241. {
  242. }
  243. BtnWebCamUrl->Enabled = true;
  244. }
  245. //---------------------------------------------------------------------------
  246. bool __fastcall TWCAM020M::OpenRtsp()
  247. {
  248. if (!FSelCtlr) return false;
  249. try
  250. {
  251. reMsg->Lines->Clear();
  252. CloseRtsp();
  253. FStrmAddr = FSelCtlr->STRM_SESN_NM.Trim();
  254. if (FStrmAddr != "")
  255. {
  256. FFPlayer1->AspectRatio = -1;//ChkFullScreen->Checked ? -1 : 0;
  257. FFPlayer1->TryOpen(FStrmAddr, PnlCamera->Handle);
  258. FStrmPlay = true;
  259. }
  260. }
  261. catch(Exception &e)
  262. {
  263. }
  264. return true;
  265. }
  266. //---------------------------------------------------------------------------
  267. void __fastcall TWCAM020M::CloseRtsp()
  268. {
  269. if (!FStrmPlay) return;
  270. try
  271. {
  272. if (FFPlayer1->ScreenHandle != NULL)
  273. {
  274. FFPlayer1->Stop(true);
  275. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  276. UpdateWindow(FFPlayer1->ScreenHandle);
  277. //FFPlayer1->ScreenHandle = NULL;
  278. }
  279. }
  280. catch(Exception &e)
  281. {
  282. }
  283. FStrmPlay = false;
  284. }
  285. //---------------------------------------------------------------------------
  286. void __fastcall TWCAM020M::BtnAllSelectClick(TObject *Sender)
  287. {
  288. TcxButton *pBtn = (TcxButton*)Sender;
  289. if (PgControl->Properties->ActivePage != TabPing)
  290. CMM_CheckAllListItem(FRAMEWCamStateList1->TvList, FRAMEWCamStateList1->ColumnSel->Index, pBtn->Tag);
  291. else
  292. CMM_CheckAllListItem(TvPing, ColumnSel->Index, pBtn->Tag);
  293. }
  294. //---------------------------------------------------------------------------
  295. void __fastcall TWCAM020M::ClearCheckList()
  296. {
  297. #if 0
  298. TcxGridBandedTableView *TvList = FRAMEWCamStateList1->TvList;
  299. TcxDataController *pGDC = TvList->DataController;
  300. try
  301. {
  302. TvList->BeginUpdate();
  303. pGDC->BeginUpdate();
  304. int nRows = pGDC->RecordCount;
  305. for (int ii = 0; ii < nRows; ii++)
  306. {
  307. pGDC->Values[ii][FRAMEWCamStateList1->ColumnSel->Index] = false;
  308. }
  309. }
  310. __finally
  311. {
  312. pGDC->EndUpdate();
  313. TvList->EndUpdate();
  314. }
  315. #endif
  316. }
  317. //---------------------------------------------------------------------------
  318. void __fastcall TWCAM020M::FRAMEWCamStateList1TvListCellDblClick(TcxCustomGridTableView *Sender,
  319. TcxGridTableDataCellViewInfo *ACellViewInfo, TMouseButton AButton,
  320. TShiftState AShift, bool &AHandled)
  321. {
  322. if (!ACellViewInfo) return;
  323. ClearCheckList();
  324. TcxGridBandedTableView *TvList = FRAMEWCamStateList1->TvList;
  325. TcxDataController *pGDC = TvList->DataController;
  326. int nSelIdx = CMM_GetRecordIndex(TvList);
  327. if (nSelIdx < 0) return;
  328. pGDC->Values[nSelIdx][FRAMEWCamStateList1->ColumnSel->Index] = true;
  329. DisplayInfo();
  330. }
  331. //---------------------------------------------------------------------------
  332. int __fastcall TWCAM020M::GetSelListItems(bool ACommCheck/*=true*/)
  333. {
  334. TcxGridBandedTableView *TvList = FRAMEWCamStateList1->TvList;
  335. TcxDataController *pGDC = TvList->DataController;
  336. FSelIds->Clear();
  337. try
  338. {
  339. bool bSelected;
  340. int nRows = TvList->ViewData->RecordCount;
  341. TvList->BeginUpdate();
  342. for (int ii = 0; ii < nRows; ii++)
  343. {
  344. TcxCustomGridRow* ARow = TvList->ViewData->Rows[ii];
  345. int nMemPtr = (int)ARow->Values[FRAMEWCamStateList1->Col99->Index];
  346. TWCamCtlr *pCctv = (TWCamCtlr*)nMemPtr;
  347. if (!pCctv) continue;
  348. bSelected = (bool)ARow->Values[FRAMEWCamStateList1->ColumnSel->Index];
  349. if (bSelected)
  350. {
  351. String CTLR_NMBR = ARow->Values[FRAMEWCamStateList1->Col01->Index];
  352. if (ACommCheck)
  353. {
  354. if (pCctv->STATE.Comm == wcam_normal)
  355. {
  356. FSelIds->Add(CTLR_NMBR);
  357. }
  358. }
  359. else
  360. {
  361. FSelIds->Add(CTLR_NMBR);
  362. }
  363. }
  364. }
  365. }
  366. __finally
  367. {
  368. TvList->EndUpdate();
  369. }
  370. return FSelIds->Count;
  371. }
  372. //---------------------------------------------------------------------------
  373. void __fastcall TWCAM020M::BtnWebCamUrlClick(TObject *Sender)
  374. {
  375. if (FSelCtlr)
  376. {
  377. if (FSelCtlr->WCAM_CTLR_IP.Trim() != "")
  378. {
  379. String sUrl = "http://" + FSelCtlr->WCAM_CTLR_IP.Trim();
  380. ShellExecute(NULL, NULL, sUrl.c_str(), NULL, NULL, 0);
  381. }
  382. }
  383. }
  384. //---------------------------------------------------------------------------
  385. void __fastcall TWCAM020M::PgControlPageChanging(TObject *Sender, TcxTabSheet *NewPage,
  386. bool &AllowChange)
  387. {
  388. if (NewPage == TabPing)
  389. {
  390. BtnAllSelect->Visible = false;
  391. BtnAllClear->Visible = false;
  392. BtnReverse->Visible = false;
  393. }
  394. else
  395. {
  396. #if 0
  397. if (BtnAllSelect->Visible == false) BtnAllSelect->Visible = true;;
  398. if (BtnAllClear->Visible == false) BtnAllClear->Visible = true;;
  399. if (BtnReverse->Visible == false) BtnReverse->Visible = true;;
  400. #endif
  401. }
  402. }
  403. //---------------------------------------------------------------------------
  404. void __fastcall TWCAM020M::UpdatePingList()
  405. {
  406. CMM_ClearGridTableView(TvPing);
  407. int ii, jj;
  408. int nCols = 0;
  409. TcxDataController *pGDC = TvPing->DataController;
  410. WCamCtlrManager->FLists.Lock();
  411. try
  412. {
  413. int nRow;
  414. TvPing->BeginUpdate();
  415. pGDC->BeginUpdate();
  416. FOR_STL(TWCamCtlr*, pObj, WCamCtlrManager->FLists)
  417. {
  418. if (pObj->DEL_YN == "Y") continue;
  419. nRow = pGDC->AppendRecord();
  420. if (pObj->STATE.Comm == wcam_normal) pGDC->Values[nRow][ColumnSel->Index] = false;
  421. else pGDC->Values[nRow][ColumnSel->Index] = true;
  422. pGDC->Values[nRow][Col01->Index] = String(pObj->WCAM_CTLR_NMBR);
  423. pGDC->Values[nRow][Col02->Index] = pObj->WCAM_CTLR_ID;
  424. pGDC->Values[nRow][Col03->Index] = pObj->WCAM_NM;
  425. pGDC->Values[nRow][Col04->Index] = pObj->STATE.Comm == wcam_normal ? FrmLang->lblComm0->Caption : FrmLang->lblComm1->Caption;
  426. pGDC->Values[nRow][Col05->Index] = pObj->WCAM_CTLR_IP;
  427. pGDC->Values[nRow][Col06->Index] = "-";
  428. pGDC->Values[nRow][Col07->Index] = "-";
  429. pGDC->Values[nRow][Col08->Index] = "-";
  430. pGDC->Values[nRow][Col09->Index] = pObj->WCAM_CTLR_IP;
  431. pGDC->Values[nRow][Col10->Index] = "-";
  432. pGDC->Values[nRow][Col11->Index] = "-";
  433. pGDC->Values[nRow][Col12->Index] = "-";
  434. pGDC->Values[nRow][Col99->Index] = (int)pObj;
  435. }
  436. }
  437. __finally
  438. {
  439. WCamCtlrManager->FLists.UnLock();
  440. pGDC->EndUpdate();
  441. TvPing->EndUpdate();
  442. }
  443. }
  444. //---------------------------------------------------------------------------
  445. void __fastcall TWCAM020M::RefreshPingList(bool AInit/*=false*/)
  446. {
  447. TcxDataController *pGDC = TvPing->DataController;
  448. try
  449. {
  450. TvPing->BeginUpdate();
  451. pGDC->BeginUpdate();
  452. int nRows = pGDC->RecordCount;
  453. for(int nRow = 0; nRow < nRows; nRow++)
  454. {
  455. int nMemPtr = TvPing->DataController->Values[nRow][Col99->Index];
  456. TWCamCtlr *pObj = (TWCamCtlr*)nMemPtr;
  457. if (!pObj) continue;
  458. if (AInit == false && PgControl->Properties->ActivePage != TabPing)
  459. {
  460. if (pObj->STATE.Comm == cctv_normal) pGDC->Values[nRow][ColumnSel->Index] = false;
  461. else pGDC->Values[nRow][ColumnSel->Index] = true;
  462. }
  463. if (AInit)
  464. {
  465. pGDC->Values[nRow][Col06->Index] = "-";
  466. pGDC->Values[nRow][Col07->Index] = "-";
  467. pGDC->Values[nRow][Col08->Index] = "-";
  468. pGDC->Values[nRow][Col10->Index] = "-";
  469. pGDC->Values[nRow][Col11->Index] = "-";
  470. pGDC->Values[nRow][Col12->Index] = "-";
  471. }
  472. pGDC->Values[nRow][Col04->Index] = pObj->STATE.Comm == wcam_normal ? FrmLang->lblComm0->Caption : FrmLang->lblComm1->Caption;
  473. }
  474. }
  475. __finally
  476. {
  477. pGDC->EndUpdate();
  478. TvPing->EndUpdate();
  479. }
  480. }
  481. //---------------------------------------------------------------------------
  482. void __fastcall TWCAM020M::PingNetwork(String AIp, int APort)
  483. {
  484. try
  485. {
  486. IdIcmpClient1->Host = AIp;
  487. IdIcmpClient1->Port = EdPingPort->Value/*512*/;
  488. IdIcmpClient1->ReceiveTimeout = EdPingTimeout->Value;
  489. IdIcmpClient1->Ping(IdIcmpClient1->Host, IdIcmpClient1->Port);
  490. }
  491. catch (Exception &e)
  492. {
  493. Application->ShowException(&e);
  494. }
  495. catch(...)
  496. {
  497. ShowMessage("Ping error[Unknown]");
  498. }
  499. }
  500. //---------------------------------------------------------------------------
  501. void __fastcall TWCAM020M::BtnNwkPingClick(TObject *Sender)
  502. {
  503. TWaitCursor waitCrs;
  504. TcxDataController *pGDC = TvPing->DataController;
  505. int nRows = pGDC->RecordCount;
  506. String sMsg;
  507. int nSelCnt = CMM_GetCheckCount(TvPing, ColumnSel->Index);
  508. if (0 == nSelCnt)
  509. {
  510. sMsg = cxLabel14->Caption;
  511. Application->MessageBox(sMsg.c_str(), L"Web Camera Network Ping Test", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  512. CxPing->SetFocus();
  513. return;
  514. }
  515. RefreshPingList(true);
  516. PnlPing->Enabled = false;
  517. String sSvrIp;
  518. int nSvrPort;
  519. bool bPing;
  520. for (int ii = 0; ii < nRows; ii++)
  521. {
  522. bPing = pGDC->Values[ii][ColumnSel->Index];
  523. if (!bPing) continue;
  524. //pGDC->Values[ii][ColPingMon->Index] = Now().FormatString("yyyy-mm-dd hh:mm:ss");
  525. FPingType = 1;
  526. sSvrIp = pGDC->Values[ii][Col05->Index];
  527. if (sSvrIp == NULL || sSvrIp.IsEmpty())
  528. {
  529. continue;
  530. }
  531. pGDC->Values[ii][Col06->Index] = "?";
  532. pGDC->Values[ii][Col07->Index] = "?";
  533. pGDC->Values[ii][Col08->Index] = "?";
  534. nSvrPort = 0;
  535. FPingTimeout = false;
  536. PingNetwork(sSvrIp.Trim(), nSvrPort);
  537. if (FPingTimeout)
  538. {
  539. pGDC->Values[ii][Col08->Index] = "Time out";
  540. }
  541. Application->ProcessMessages();
  542. FPingType = 2;
  543. sSvrIp = pGDC->Values[ii][Col09->Index];
  544. if (sSvrIp == NULL || sSvrIp.IsEmpty())
  545. {
  546. continue;
  547. }
  548. pGDC->Values[ii][Col10->Index] = "?";
  549. pGDC->Values[ii][Col11->Index] = "?";
  550. pGDC->Values[ii][Col12->Index] = "?";
  551. nSvrPort = 0;
  552. FPingTimeout = false;
  553. PingNetwork(sSvrIp.Trim(), nSvrPort);
  554. if (FPingTimeout)
  555. {
  556. pGDC->Values[ii][Col12->Index] = "Time out";
  557. }
  558. Application->ProcessMessages();
  559. }
  560. PnlPing->Enabled = true;
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TWCAM020M::BtnNwkPingClearClick(TObject *Sender)
  564. {
  565. RefreshPingList(true);
  566. }
  567. //---------------------------------------------------------------------------
  568. void __fastcall TWCAM020M::Col04CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  569. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  570. {
  571. try
  572. {
  573. TColor tColor;
  574. String sStatus = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index];
  575. tColor = ACanvas->Brush->Color;
  576. if (sStatus.Pos("-")) tColor = clGray;
  577. else if (sStatus.Pos(FrmLang->lblComm1->Caption.Trim())) tColor = clRed;
  578. else tColor = clLime;
  579. ACanvas->SetBrushColor(tColor);
  580. ACanvas->Font->Color = clBlack;
  581. }
  582. catch(Exception &e)
  583. {
  584. }
  585. }
  586. //---------------------------------------------------------------------------
  587. void __fastcall TWCAM020M::IdIcmpClient1Reply(TComponent *ASender, const TReplyStatus *AReplyStatus)
  588. {
  589. try
  590. {
  591. String sRcvIp = AReplyStatus->FromIpAddress;
  592. int nRcvPort= IdIcmpClient1->Port;
  593. if (rsTimeOut == AReplyStatus->ReplyStatusType || sRcvIp == "0.0.0.0")
  594. {
  595. FPingTimeout = true;
  596. return;
  597. }
  598. TcxDataController *pGDC = TvPing->DataController;
  599. int nRows = pGDC->RecordCount;
  600. String sSvrIp;
  601. for (int ii = 0; ii < nRows; ii++)
  602. {
  603. if (FPingType == 1)
  604. sSvrIp = pGDC->Values[ii][Col05->Index];
  605. else
  606. sSvrIp = pGDC->Values[ii][Col09->Index];
  607. int nSvrPort = 0;
  608. if (sSvrIp.Trim() == sRcvIp && nRcvPort == nSvrPort)
  609. {
  610. if (FPingType == 1)
  611. {
  612. if (AReplyStatus->MsRoundTripTime > 100)
  613. {
  614. pGDC->Values[ii][Col08->Index] = "Delayed";
  615. }
  616. else
  617. {
  618. pGDC->Values[ii][Col08->Index] = "Normal";
  619. }
  620. pGDC->Values[ii][Col06->Index] = String(AReplyStatus->MsRoundTripTime) + " ";
  621. pGDC->Values[ii][Col07->Index] = String(AReplyStatus->TimeToLive) + " ";
  622. }
  623. else
  624. {
  625. if (AReplyStatus->MsRoundTripTime > 100)
  626. {
  627. pGDC->Values[ii][Col12->Index] = "Delayed";
  628. }
  629. else
  630. {
  631. pGDC->Values[ii][Col12->Index] = "Normal";
  632. }
  633. pGDC->Values[ii][Col10->Index] = String(AReplyStatus->MsRoundTripTime) + " ";
  634. pGDC->Values[ii][Col11->Index] = String(AReplyStatus->TimeToLive) + " ";
  635. }
  636. break;
  637. }
  638. }
  639. }
  640. catch(Exception &e)
  641. {
  642. }
  643. }
  644. //---------------------------------------------------------------------------
  645. void __fastcall TWCAM020M::Col08CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  646. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  647. {
  648. try
  649. {
  650. int iIndex = AViewInfo->Item->Index;
  651. ACanvas->Canvas->Brush->Style = bsSolid;
  652. String val = AViewInfo->GridRecord->DisplayTexts[iIndex];
  653. ACanvas->Canvas->Font->Color = clBlack;
  654. if (val == "Normal") ACanvas->Canvas->Brush->Color = clLime;
  655. else if (val == "Delayed") ACanvas->Canvas->Brush->Color = clRed;
  656. else if (val == "Time out") ACanvas->Canvas->Brush->Color = clRed;
  657. else ACanvas->Canvas->Brush->Color = clSilver;
  658. } catch(...) {}
  659. }
  660. //---------------------------------------------------------------------------
  661. void __fastcall TWCAM020M::TvPingCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
  662. TMouseButton AButton, TShiftState AShift,
  663. bool &AHandled)
  664. {
  665. if (!ACellViewInfo) return;
  666. TcxGridDataController *pGDC = TvPing->DataController;
  667. int nRow = pGDC->FocusedRecordIndex;
  668. if( nRow <= -1 )
  669. return;
  670. if (ACellViewInfo->Item->Index == Col05->Index ||
  671. ACellViewInfo->Item->Index == Col09->Index)
  672. {
  673. String sSvrIp = pGDC->Values[nRow][ACellViewInfo->Item->Index];
  674. ITSUtil_NetworkPing(sSvrIp);
  675. }
  676. }
  677. //---------------------------------------------------------------------------
  678. bool __fastcall TWCAM020M::OpenWebCamera()
  679. {
  680. if (!FSelCtlr) return false;
  681. try
  682. {
  683. reMsg->Lines->Clear();
  684. CloseWebCamera();
  685. if (!XNVTViewerCtrl1->Visible) XNVTViewerCtrl1->Visible = true;
  686. XNVTViewerCtrl1->IPAddress = FSelCtlr->WCAM_CTLR_IP;
  687. XNVTViewerCtrl1->Port = FSelCtlr->CMRA_PORT;
  688. XNVTViewerCtrl1->ID = FSelCtlr->CMRA_ID;
  689. XNVTViewerCtrl1->Password = FSelCtlr->CMRA_PSWD;
  690. XNVTViewerCtrl1->Channel = FSelCtlr->CMRA_CHNL;
  691. XNVTViewerCtrl1->EnableBackChannelAudio = false;
  692. if (XNVTViewerCtrl1->Preview())
  693. {
  694. BtnSaveImgFile->Enabled = true;
  695. return true;
  696. }
  697. BtnSaveImgFile->Enabled = false;
  698. }
  699. catch(...)
  700. {
  701. }
  702. return false;
  703. }
  704. //---------------------------------------------------------------------------
  705. void __fastcall TWCAM020M::CloseWebCamera()
  706. {
  707. try
  708. {
  709. XNVTViewerCtrl1->Stop();
  710. }
  711. catch(...)
  712. {
  713. }
  714. }
  715. //---------------------------------------------------------------------------
  716. void __fastcall TWCAM020M::BtnZoomInOutMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  717. {
  718. try
  719. {
  720. TImageBtn *pBtn = (TImageBtn*)Sender;
  721. if (pBtn->Tag == 0)
  722. {
  723. XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_ZOOM_IN, 3);
  724. }
  725. else
  726. {
  727. XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_ZOOM_OUT, 3);
  728. }
  729. }
  730. catch(...) {}
  731. }
  732. //---------------------------------------------------------------------------
  733. void __fastcall TWCAM020M::BtnZoomInOutMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  734. {
  735. try
  736. {
  737. TImageBtn *pBtn = (TImageBtn*)Sender;
  738. XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, 0x000000, 3);
  739. }
  740. catch(...) {}
  741. }
  742. //---------------------------------------------------------------------------
  743. void __fastcall TWCAM020M::BtnFocusInOutMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  744. {
  745. try
  746. {
  747. TImageBtn *pBtn = (TImageBtn*)Sender;
  748. if (pBtn->Tag == 0)
  749. {
  750. XNVTViewerCtrl1->PutCamCtl(CTL_FOCUS_CONT, SB_FOCUS_IN, 1);
  751. }
  752. else
  753. {
  754. XNVTViewerCtrl1->PutCamCtl(CTL_FOCUS_CONT, SB_FOCUS_OUT, 1);
  755. }
  756. }
  757. catch(...) {}
  758. }
  759. //---------------------------------------------------------------------------
  760. void __fastcall TWCAM020M::BtnFocusInOutMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  761. {
  762. try
  763. {
  764. TImageBtn *pBtn = (TImageBtn*)Sender;
  765. XNVTViewerCtrl1->PutCamCtl(CTL_FOCUS_CONT, 0x000000, 3);
  766. }
  767. catch(...) {}
  768. }
  769. //---------------------------------------------------------------------------
  770. void __fastcall TWCAM020M::BtnPanTileMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  771. {
  772. try
  773. {
  774. TImageBtn *pBtn = (TImageBtn*)Sender;
  775. switch(pBtn->Tag)
  776. {
  777. case 0: XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_TILT_UP, 3); break; // Up
  778. case 1: XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_TILT_DOWN, 3); break; // Down
  779. case 2: XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_PAN_LEFT, 3); break; // Left
  780. case 3: XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_PAN_RIGHT, 3); break; // Right
  781. }
  782. }
  783. catch(...) {}
  784. }
  785. //---------------------------------------------------------------------------
  786. void __fastcall TWCAM020M::BtnPanTileMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  787. {
  788. // Zoom In/Out MouseUp Event 와 동일
  789. try
  790. {
  791. TImageBtn *pBtn = (TImageBtn*)Sender;
  792. XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, 0x000000, 3);
  793. }
  794. catch(...) {}
  795. }
  796. //---------------------------------------------------------------------------
  797. void __fastcall TWCAM020M::BtnSaveImgFileClick(TObject *Sender)
  798. {
  799. String sSaveFileName;
  800. if (!FSelCtlr || XNVTViewerCtrl1->OCXState == GRAPH_NONE)
  801. {
  802. String sMsg = cxLabel1->Caption;
  803. Application->MessageBox(sMsg.c_str(), L"Save Snap Shot", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  804. return;
  805. }
  806. sSaveFileName.printf(L"%s\\%d_%s.bmp", g_sTempDir.c_str(), FSelCtlr->WCAM_CTLR_NMBR, Now().FormatString("yyyymmddhhnnss").c_str());
  807. if (XNVTViewerCtrl1->FileSnapShot(sSaveFileName.c_str()))
  808. {
  809. Application->MessageBox(sSaveFileName.c_str(), L"Save Snap Shot Success", MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  810. }
  811. else
  812. {
  813. Application->MessageBox(cxLabel2->Caption.c_str(), L"Save Snap Shot Fail", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  814. }
  815. }
  816. //---------------------------------------------------------------------------
  817. void __fastcall TWCAM020M::ClearPreset()
  818. {
  819. CMM_ClearGridTableView(TvPreset);
  820. SePresetNo->Value = 1;
  821. EdPresetName->Text = "";
  822. ChkCctvPresetDef->Checked = false;
  823. //PnlPreset->Enabled = false;
  824. }
  825. //---------------------------------------------------------------------------
  826. void __fastcall TWCAM020M::InitPreset()
  827. {
  828. if (!FSelCtlr) return;
  829. ClearPreset();
  830. TcxDataController* pGDC = TvPreset->DataController;
  831. TvPreset->BeginUpdate();
  832. try
  833. {
  834. FSelCtlr->FLists.Lock();
  835. try
  836. {
  837. FOR_STL(TWCamPset*, pObj, FSelCtlr->FLists)
  838. {
  839. if (pObj->DEL_YN == "Y") continue;
  840. int nRow = pGDC->AppendRecord();
  841. pGDC->Values[nRow][ColPresetNo->Index] = String(pObj->PSET_NMBR);
  842. pGDC->Values[nRow][ColPresetName->Index] = pObj->PSET_NM;
  843. pGDC->Values[nRow][ColPresetPan->Index] = String(pObj->PAN);
  844. pGDC->Values[nRow][ColPresetTilt->Index] = String(pObj->TILT);
  845. pGDC->Values[nRow][ColPresetZoom->Index] = String(pObj->ZOOM);
  846. pGDC->Values[nRow][ColPresetFocus->Index] = String(pObj->FOCS);
  847. pGDC->Values[nRow][ColPresetAngle->Index] = "";
  848. pGDC->Values[nRow][ColPresetDefault->Index] = pObj->DFLT_YN;
  849. }
  850. }
  851. __finally
  852. {
  853. FSelCtlr->FLists.UnLock();
  854. }
  855. }
  856. __finally
  857. {
  858. TvPreset->EndUpdate();
  859. PnlPreset->Enabled = true;
  860. BtnCctvPresetDel->Enabled = false;
  861. }
  862. }
  863. //---------------------------------------------------------------------------
  864. void __fastcall TWCAM020M::BtnCctvPresetClick(TObject *Sender)
  865. {
  866. //프리셋 이동
  867. if (FSelCtlr)
  868. {
  869. int nPresetNo = SePresetNo->Value;
  870. if (XNVTViewerCtrl1->PutCamCtl(PRESET_MOVE, nPresetNo, 1))
  871. {
  872. }
  873. }
  874. }
  875. //---------------------------------------------------------------------------
  876. void __fastcall TWCAM020M::BtnCctvPresetSetClick(TObject *Sender)
  877. {
  878. //프리셋 설정
  879. if (FSelCtlr)
  880. {
  881. int nPresetNo = SePresetNo->Value;
  882. String sPresetNm = EdPresetName->Text.Trim();
  883. String sDefault = ChkCctvPresetDef->Checked ? "Y" : "N";
  884. if (sPresetNm == "")
  885. {
  886. String sMsg;
  887. sMsg = cxLabel3->Caption;//"프리셋 명을 입력하세요..";
  888. Application->MessageBox(sMsg.c_str(), cxLabel4->Caption.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  889. EdPresetName->SetFocus();
  890. }
  891. if (XNVTViewerCtrl1->PutCamCtl(PRESET_SET, nPresetNo, 1))
  892. {
  893. TWCamPset *pSet = FSelCtlr->FLists.Find(nPresetNo);
  894. if (!pSet)
  895. {
  896. pSet = new TWCamPset();
  897. pSet->WCAM_CTLR_NMBR = FSelCtlr->WCAM_CTLR_NMBR;
  898. pSet->PSET_NMBR = nPresetNo;
  899. FSelCtlr->FLists.Push(pSet->PSET_NMBR, pSet);
  900. }
  901. pSet->PSET_NM = sPresetNm;
  902. pSet->DFLT_YN = sDefault;
  903. pSet->DEL_YN = "N";
  904. WCamCtlrManager->SavePreSet(FSelCtlr);
  905. InitPreset();
  906. SePresetNo->Value = nPresetNo;
  907. EdPresetName->Text = sPresetNm;
  908. ChkCctvPresetDef->Checked = sDefault == "Y" ? true : false;
  909. BtnCctvPresetDel->Enabled = true;
  910. }
  911. }
  912. }
  913. //---------------------------------------------------------------------------
  914. void __fastcall TWCAM020M::BtnCctvPresetDelClick(TObject *Sender)
  915. {
  916. //프리셋 삭제
  917. if (FSelCtlr)
  918. {
  919. int nPresetNo = SePresetNo->Value;
  920. if (XNVTViewerCtrl1->PutCamCtl(PRESET_CLEAR, nPresetNo, 1))
  921. {
  922. TWCamPset *pSet = FSelCtlr->FLists.Find(nPresetNo);
  923. if (!pSet)
  924. {
  925. return;
  926. }
  927. pSet->PSET_NM = "";
  928. pSet->DEL_YN = "Y";
  929. WCamCtlrManager->SavePreSet(FSelCtlr);
  930. InitPreset();
  931. }
  932. }
  933. }
  934. //---------------------------------------------------------------------------
  935. void __fastcall TWCAM020M::TvPresetCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
  936. TMouseButton AButton, TShiftState AShift, bool &AHandled)
  937. {
  938. if (!ACellViewInfo) return;
  939. int nRow = TvPreset->DataController->FocusedRecordIndex;
  940. if( nRow <= -1 )
  941. return;
  942. String sPresetNo = TvPreset->DataController->Values[nRow][ColPresetNo->Index];
  943. String sPresetNm = TvPreset->DataController->Values[nRow][ColPresetName->Index];
  944. String sDefault = TvPreset->DataController->Values[nRow][ColPresetDefault->Index];
  945. ChkCctvPresetDef->Checked = sDefault == "Y" ? true : false;
  946. SePresetNo->Value = sPresetNo.ToIntDef(1);
  947. EdPresetName->Text = sPresetNm;
  948. BtnCctvPresetDel->Enabled = true;
  949. }
  950. //---------------------------------------------------------------------------
  951. void __fastcall TWCAM020M::SePresetNoPropertiesEditValueChanged(TObject *Sender)
  952. {
  953. if (FSelCtlr)
  954. {
  955. int nPresetNo = SePresetNo->Value;
  956. TWCamPset* pSet = FSelCtlr->FLists.Find(nPresetNo);
  957. if (pSet) BtnCctvPresetDel->Enabled = true;
  958. else BtnCctvPresetDel->Enabled = false;
  959. }
  960. }
  961. //---------------------------------------------------------------------------
  962. void __fastcall TWCAM020M::reMsgDblClick(TObject *Sender)
  963. {
  964. reMsg->Lines->Clear();
  965. }
  966. //---------------------------------------------------------------------------
  967. void __fastcall TWCAM020M::XNVTViewerCtrl1EventNotify(TObject *Sender, BSTR message, long message_size)
  968. {
  969. reMsg->Lines->Add(message);
  970. }
  971. //---------------------------------------------------------------------------
  972. void __fastcall TWCAM020M::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  973. {
  974. switch(APlayState)
  975. {
  976. case Ffbasecomponent::psPlay: reMsg->Lines->Add("Play..."); break;
  977. case Ffbasecomponent::psResume: reMsg->Lines->Add("Resume."); break;
  978. case Ffbasecomponent::psPause: reMsg->Lines->Add("Pause.."); break;
  979. case Ffbasecomponent::psStep: reMsg->Lines->Add("Step..."); break;
  980. case Ffbasecomponent::psStop:
  981. if (FFPlayer1->ScreenHandle != NULL)
  982. {
  983. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  984. UpdateWindow(FFPlayer1->ScreenHandle);
  985. //FFPlayer1->ScreenHandle = NULL;
  986. }
  987. reMsg->Lines->Add("Stop...");
  988. break;
  989. case Ffbasecomponent::psEnd:
  990. {
  991. FFPlayer1->Stop(true);
  992. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  993. UpdateWindow(FFPlayer1->ScreenHandle);
  994. //FFPlayer1->ScreenHandle = NULL;
  995. FStrmPlay = false;
  996. }
  997. reMsg->Lines->Add("End...");
  998. break;
  999. }
  1000. }
  1001. //---------------------------------------------------------------------------