CCAM020MF.cpp 32 KB

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