Advertisement
JeffClinton

Sorveglianza c++

Feb 20th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 144.02 KB | None | 0 0
  1. #include <vcl.h>
  2. #include <winsock2.h>
  3. #include <stdio.h>
  4. #include <dir.h>
  5. #include <time.h>
  6. #include <Filectrl.hpp>
  7. #include <systdate.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <cv.h>
  11. #include <cxcore.h>
  12. #include "Ethernet.h"
  13. #include "HNPsSdkDef.hpp"
  14. #include "Ip.h"
  15. #include "HNUtil.h"
  16. #include "Arp.h"
  17. #include "Icmp.h"
  18.  
  19. #pragma hdrstop
  20.  
  21.  
  22.  
  23. #include "Consorzio.h"
  24. //---------------------------------------------------------------------------
  25. #pragma package(smart_init)
  26. #pragma link "VITAMINDECODERLib_OCX"
  27. #pragma link "VrButtons"
  28. #pragma link "VrControls"
  29. #pragma link "VrDisplay"
  30. #pragma link "VrLabel"
  31. #pragma link "VrProgressBar"
  32. #pragma link "VrBlotter"
  33. #pragma link "VrLcd"
  34. #pragma link "dbimageen"
  35. #pragma link "ieview"
  36. #pragma link "imageenview"
  37. #pragma link "VrLeds"
  38. #pragma link "imageenio"
  39. #pragma link "imageenproc"
  40. #pragma link "VrCheckLed"
  41. #pragma link "VrSlider"
  42. #pragma link "VrMatrix"
  43. #pragma link "VrEdit"
  44. #pragma link "VrBorder"
  45. #pragma link "SHDocVw_OCX"
  46. #pragma link "ieopensavedlg"
  47. #pragma link "vrLedClock"
  48. #pragma link "VrMatrixLabel"
  49. #pragma link "VrNavigator"
  50. #pragma link "VrThreads"
  51. #pragma link "dbisamtb"
  52.  
  53. #pragma link "HNAdapter"
  54. #pragma link "HNAdapterConfig"
  55. #pragma link "HNPacket"
  56. #pragma link "HNPSManager"
  57. #pragma link "HNUserFilter"
  58. #pragma link "ExceptionLog"
  59. #pragma link "dcDiskInfo"
  60. #pragma link "dcInternal"
  61. #pragma link "VrAnalog"
  62. #pragma link "VrTrackBar"
  63. #pragma resource "*.dfm"
  64. TForm1 *Form1;
  65.  
  66. #define AA(x) (isactive[x])
  67. #define A(x) (active[x])
  68. char* (__stdcall *GetSerialNumber)(int, char*);
  69. char* (__stdcall *GetModelNumber)(int, char*);
  70. char* (__stdcall *GetRevisionNo)(int, char*);
  71. int (__stdcall *GetBufferSize)(int, char*);
  72. int (__stdcall *GetCylinders)(int, char*);
  73. int (__stdcall *GetHeads)(int, char*);
  74. int (__stdcall *GetSectors)(int, char*);
  75. HINSTANCE DllInst = NULL;
  76.  
  77. //---------------------------------------------------------------------------
  78. __fastcall TForm1::TForm1(TComponent* Owner)
  79. : TForm(Owner)
  80. {
  81. Adapter->ThreadCount = Adapter->MaxThreadCount;
  82.  
  83. // Create Ip filter
  84. Bpf->AddCmd(BPF_LD+BPF_H+BPF_ABS, 12);
  85. Bpf->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_IP, 0, 1);
  86. Bpf->AddCmd(BPF_RET+BPF_K, sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER));
  87. Bpf->AddCmd(BPF_RET+BPF_K, 0);
  88.  
  89. // Sets BPF filter for receiving IP traffic only
  90. Adapter->UserFilter = Bpf->Handle;
  91. Adapter->UserFilterActive = true;
  92. // Sets MAC filter to begin receive packets
  93. Adapter->MacFilter = mfAll;
  94.  
  95.  
  96. long Res = HNPSManager->Initialize();
  97. if(Res != HNERR_OK) { HNGetErrorBox(Res); return; }
  98.  
  99. RecvArpPacket = CreateEvent(NULL,TRUE,FALSE,NULL);
  100.  
  101. WSADATA wsaData;
  102. WSAStartup(MAKEWORD(2,0),&wsaData);
  103.  
  104. // Sets the status flag of the user-settable packet filter using
  105. HNAdapter->UserFilterActive = true;
  106. // Sets the MAC filter for the network adapter
  107. HNAdapter->MacFilter = mfOwnerRecv;
  108. }
  109. //---------------------------------------------------------------------------
  110.  
  111. bool __fastcall TForm1::IsTimeout(long timeout, int video)
  112. {
  113. int remain;
  114. long ltime;
  115. time(&ltime);
  116. remain = timeout - ltime;
  117. switch(video) {
  118. case 1:
  119. VrProgressBar1->Position = remain;
  120. break;
  121. case 2:
  122. VrProgressBar2->Position = remain;
  123. break;
  124. case 3:
  125. VrProgressBar3->Position = remain;
  126. break;
  127. case 4:
  128. VrProgressBar4->Position = remain;
  129. break;
  130. case 5:
  131. VrProgressBar5->Position = remain;
  132. break;
  133. case 6:
  134. // VrProgressBar6->Position = remain;
  135. // PC
  136. VrProgressBar7->Position = remain;
  137. // ----------------------------
  138. break;
  139. }
  140. if(timeout <= ltime)
  141. return true;
  142. return false;
  143. }
  144.  
  145. long __fastcall TForm1::SetTimeout(int sec, int video)
  146. {
  147. long ltime;
  148. time(&ltime);
  149. switch(video) {
  150. case 1:
  151. VrProgressBar1->MaxValue = sec;
  152. break;
  153. case 2:
  154. VrProgressBar2->MaxValue = sec;
  155. break;
  156. case 3:
  157. VrProgressBar3->MaxValue = sec;
  158. break;
  159. case 4:
  160. VrProgressBar4->MaxValue = sec;
  161. break;
  162. case 5:
  163. VrProgressBar5->MaxValue = sec;
  164. break;
  165. case 6:
  166. //VrProgressBar6->MaxValue = sec;
  167. // PC
  168. VrProgressBar7->MaxValue = sec;
  169. break;
  170. }
  171. // PC
  172. // is necessary?
  173. //Form1->Refresh();
  174. // -------------------
  175. return (ltime + (long) sec);
  176. }
  177. void __fastcall TForm1::FormActivate(TObject *Sender)
  178. {
  179.  
  180. AnsiString OutString;
  181. AnsiString buffer;
  182. int n, m, len1, len2;
  183. isdemo = true;
  184. char str1[50], str2[50];
  185. char* RegCode = "F1PN3-T9W1C-5P2UM-91EL8-SPPH8"; //Enter your Keycode
  186. int iDrive;
  187.  
  188. iDrive = 0;
  189. Label44->Caption = " Versione dimostrativa non registrata";
  190. if (DllInst == NULL) DllInst = LoadLibrary("GetDiskSerial.dll");
  191. if (DllInst)
  192. {
  193. n = m = 0;
  194. GetSerialNumber = (char* (__stdcall*)(int, char*))GetProcAddress(DllInst,"GetSerialNumber");
  195. Edit9->Text = GetSerialNumber(iDrive, RegCode);
  196. lstrcpy(str1, Edit9->Text.c_str());
  197. len1 = 0;
  198. while(str1[len1])
  199. n += str1[len1++];
  200. lstrcpy(str2,Activation.c_str());
  201. len2 = 0;
  202. while(str2[len2])
  203. m += str2[len2++];
  204. if(m == n) {
  205. isdemo = false;
  206. Label44->Caption = Registrato;
  207. }
  208.  
  209. }
  210.  
  211.  
  212.  
  213.  
  214. for(int i=0;i!=6;i++)
  215. zoomval[i] = 0;
  216.  
  217. fsm[0] = &fsm1;
  218. fsm[1] = &fsm2;
  219. fsm[2] = &fsm3;
  220. fsm[3] = &fsm4;
  221. fsm[4] = &fsm5;
  222. fsm[5] = &fsm6;
  223.  
  224.  
  225. VrNum1->Value = 0;
  226. VrNum2->Value = 0;
  227. VrNum3->Value = 0;
  228. VrNum4->Value = 0;
  229. VrNum5->Value = 0;
  230. VrNum6->Value = 0;
  231.  
  232. records[0] = 0;
  233. records[1] = 0;
  234. records[2] = 0;
  235. records[3] = 0;
  236. records[4] = 0;
  237. records[5] = 0;
  238.  
  239. vrLed[0] = VrLed1;
  240. vrLed[1] = VrLed2;
  241. vrLed[2] = VrLed3;
  242. vrLed[3] = VrLed4;
  243. vrLed[4] = VrLed5;
  244. // vrLed[5] = VrLed6;
  245. vrLed[5] = VrLed7;
  246.  
  247. // PC
  248. // set 'Video Analisi' as active page in PageControl1
  249. PageControl1->ActivePageIndex = 1;
  250. // ----------------------------------------------------
  251. sconnessioni[0] = 0;
  252. sconnessioni[1] = 0;
  253. sconnessioni[2] = 0;
  254. sconnessioni[3] = 0;
  255. sconnessioni[4] = 0;
  256. sconnessioni[5] = 0;
  257. loadOrario();
  258. loadSetup();
  259.  
  260. // if(deleteafter)
  261. // deleteAllrecordafter();
  262. // PC
  263. DeleteOldestVideo();
  264. // --------------------
  265.  
  266. isAutoconnect = DBCheckBox54->Checked;
  267. if(isAutoconnect) {
  268. setONVideoCamera();
  269. if(recadora)
  270. Timer2->Enabled = true;
  271. }
  272.  
  273. CheckProgramPassword (); // if password is empty unlock panels
  274.  
  275.  
  276. }
  277. //---------------------------------------------------------------------------
  278. void __fastcall TForm1::VrPowerButton1Click(TObject *Sender)
  279. {
  280. bool flag;
  281. int retcode;
  282. VrLabel44->Visible = false;
  283. VitaminCtrl1->Visible = true;
  284.  
  285. flag = VrPowerButton1->Active;
  286. if(flag) {
  287. saveError("Attivazione video 1");
  288. A(0) = false;
  289. VitaminCtrl1->AutoServerModelType = true;
  290. VitaminCtrl1->EventTypes = 0;
  291. VitaminCtrl1->RemoteIPAddr = ip[0];
  292. VitaminCtrl1->UserName = login[0];
  293. VitaminCtrl1->Password = password[0];
  294. VitaminCtrl1->AutoReconnect = true;
  295. VitaminCtrl1->ReadWriteTimeout = Edit3->Text.ToInt();
  296. retcode = VitaminCtrl1->Connect();
  297. if(zoomval[0] != 0) {
  298. VitaminCtrl1->DigitalZoomEnabled = true;
  299. VitaminCtrl1->DigitalZoomFactor = zoomval[0];
  300. }
  301. } else {
  302. saveError("Disattivazione video 1");
  303. // PC
  304. // in any case i need to put 'Analisi' button to Active = false
  305. VrPowerButton2->Active = flag;
  306. // --------------------------------------
  307. VitaminCtrl1->Disconnect();
  308.  
  309.  
  310. }
  311. VrPowerButton2->Enabled = flag;
  312. }
  313. //---------------------------------------------------------------------------
  314. void __fastcall TForm1::VrPowerButton3Click(TObject *Sender)
  315. {
  316. bool flag;
  317. VrLabel19->Visible = false;
  318. VitaminCtrl2->Visible = true;
  319. if(isdemo) return;
  320. flag = VrPowerButton3->Active;
  321. if(flag) {
  322. saveError("Attivazione video 2");
  323.  
  324. A(1) = false;
  325. VitaminCtrl2->AutoServerModelType = true;
  326. VitaminCtrl2->EventTypes = 0;
  327. VitaminCtrl2->RemoteIPAddr = ip[1];
  328. VitaminCtrl2->UserName = login[1];
  329. VitaminCtrl2->Password = password[1];
  330. VitaminCtrl2->AutoReconnect = true;
  331. VitaminCtrl2->ReadWriteTimeout = Edit3->Text.ToInt();
  332.  
  333. VitaminCtrl2->Connect();
  334. if(zoomval[1] != 0) {
  335. VitaminCtrl2->DigitalZoomEnabled = true;
  336. VitaminCtrl2->DigitalZoomFactor = zoomval[1];
  337. }
  338.  
  339. } else {
  340. saveError("Disattivazione video 2");
  341. // PC
  342. VrPowerButton2->Active = flag;
  343. // --------------------------------------
  344.  
  345. // PC (was VitaminCtrl4)
  346. VitaminCtrl2->Disconnect();
  347. // --------------------------
  348. }
  349. VrPowerButton4->Enabled = flag;
  350. }
  351. //---------------------------------------------------------------------------
  352. void __fastcall TForm1::VrPowerButton5Click(TObject *Sender)
  353. {
  354. bool flag;
  355. VrLabel27->Visible = false;
  356. VitaminCtrl3->Visible = true;
  357. if(isdemo) return;
  358. flag = VrPowerButton5->Active;
  359. if(flag) {
  360. saveError("Attivazione video 3");
  361.  
  362. A(2) = false;
  363. VitaminCtrl3->AutoServerModelType = true;
  364. VitaminCtrl3->EventTypes = 0;
  365. VitaminCtrl3->RemoteIPAddr = ip[2];
  366. VitaminCtrl3->UserName = login[2];
  367. VitaminCtrl3->Password = password[2];
  368. VitaminCtrl3->AutoReconnect = true;
  369. VitaminCtrl3->ReadWriteTimeout = Edit3->Text.ToInt();
  370.  
  371. VitaminCtrl3->Connect();
  372. if(zoomval[2] != 0) {
  373. VitaminCtrl3->DigitalZoomEnabled = true;
  374. VitaminCtrl3->DigitalZoomFactor = zoomval[2];
  375. }
  376. } else {
  377. saveError("Disattivazione video 3");
  378. // PC
  379. VrPowerButton6->Active = flag;
  380. // --------------------------------------
  381.  
  382. VitaminCtrl3->Disconnect();
  383. }
  384. VrPowerButton6->Enabled = flag;
  385. }
  386.  
  387. //---------------------------------------------------------------------------
  388. void __fastcall TForm1::VrPowerButton7Click(TObject *Sender)
  389. {
  390. bool flag;
  391. VrLabel28->Visible = false;
  392. VitaminCtrl4->Visible = true;
  393. if(isdemo) return;
  394. flag = VrPowerButton7->Active;
  395. if(flag) {
  396. saveError("Attivazione video 4");
  397.  
  398. A(3) = false;
  399. VitaminCtrl4->AutoServerModelType = true;
  400. VitaminCtrl4->EventTypes = 0;
  401. VitaminCtrl4->RemoteIPAddr = ip[3];
  402. VitaminCtrl4->UserName = login[3];
  403. VitaminCtrl4->Password = password[3];
  404. VitaminCtrl4->AutoReconnect = true;
  405. VitaminCtrl4->ReadWriteTimeout = Edit3->Text.ToInt();
  406.  
  407. VitaminCtrl4->Connect();
  408. if(zoomval[3] != 0) {
  409. VitaminCtrl4->DigitalZoomEnabled = true;
  410. VitaminCtrl4->DigitalZoomFactor = zoomval[3];
  411. }
  412. } else {
  413. // PC
  414. VrPowerButton8->Active = flag;
  415. // --------------------------------------
  416. saveError("Disattivazione video 4");
  417. VitaminCtrl4->Disconnect();
  418. }
  419. VrPowerButton8->Enabled = flag;
  420.  
  421.  
  422. }
  423. //---------------------------------------------------------------------------
  424. void __fastcall TForm1::VrPowerButton9Click(TObject *Sender)
  425. {
  426. bool flag;
  427. VitaminCtrl5->Visible = true;
  428. if(isdemo) return;
  429. flag = VrPowerButton9->Active;
  430. if(flag) {
  431. saveError("Attivazione video 5");
  432.  
  433. A(4) = false;
  434. VitaminCtrl5->AutoServerModelType = true;
  435. VitaminCtrl5->EventTypes = 0;
  436. VitaminCtrl5->RemoteIPAddr = ip[4];
  437. VitaminCtrl5->UserName = login[4];
  438. VitaminCtrl5->Password = password[4];
  439. VitaminCtrl5->AutoReconnect = true;
  440. VitaminCtrl5->ReadWriteTimeout = Edit3->Text.ToInt();
  441.  
  442. VitaminCtrl5->Connect();
  443. if(zoomval[4] != 0) {
  444. VitaminCtrl5->DigitalZoomEnabled = true;
  445. VitaminCtrl5->DigitalZoomFactor = zoomval[4];
  446. }
  447. } else {
  448. // PC
  449. VrPowerButton10->Active = flag;
  450. // --------------------------------------
  451. saveError("Disattivazione video 1");
  452. VitaminCtrl5->Disconnect();
  453. }
  454. VrPowerButton10->Enabled = flag;
  455. }
  456. //---------------------------------------------------------------------------
  457. void __fastcall TForm1::VrPowerButton11Click(TObject *Sender)
  458. {
  459. bool flag;
  460. VitaminCtrl6->Visible = true;
  461. if(isdemo) return;
  462. flag = VrPowerButton11->Active;
  463. if(flag) {
  464. saveError("Attivazione video 6");
  465.  
  466. A(5) = false;
  467. VitaminCtrl6->AutoServerModelType = true;
  468. VitaminCtrl6->EventTypes = 0;
  469. VitaminCtrl6->RemoteIPAddr = ip[5];
  470. VitaminCtrl6->UserName = login[5];
  471. VitaminCtrl6->Password = password[5];
  472. VitaminCtrl6->AutoReconnect = true;
  473. VitaminCtrl6->ReadWriteTimeout = Edit3->Text.ToInt();
  474.  
  475. VitaminCtrl6->Connect();
  476. if(zoomval[5] != 0) {
  477. VitaminCtrl6->DigitalZoomEnabled = true;
  478. VitaminCtrl6->DigitalZoomFactor = zoomval[5];
  479. }
  480. } else {
  481. saveError("Disattivazione video 6");
  482. // PC
  483. VrPowerButton12->Active = flag;
  484. // --------------------------------------
  485. VitaminCtrl6->Disconnect();
  486. }
  487. VrPowerButton12->Enabled = flag;
  488. }
  489. //---------------------------------------------------------------------------
  490.  
  491.  
  492. void TForm1::loadSetup()
  493. {
  494. register int i;
  495. int idx = 0;
  496. char classifier[128];
  497. int millisec;
  498. int vNum;
  499. long maxSize;
  500. int buffSize;
  501.  
  502. for(i=0;i!=6;i++)
  503. VitaminCtrl[i]->AutoAVISettings = DBCheckBox55->Checked;
  504.  
  505. // PC
  506. path = ObtainVideoPath();
  507. //--------------------------
  508.  
  509. // PC 2006-12-18
  510. //
  511. // commented this line
  512. // provocava la cancellazione iniziale di tutti gli errori
  513. // saveError("Lettura setup");
  514. //----------------------------------
  515. DBISAMTable11->Open();
  516. DBISAMTable3->First();
  517. DBISAMTable11->First();
  518. while(!DBISAMTable3->Eof) {
  519. vNum = DBISAMTable3->FieldByName("Numero")->AsInteger;
  520. ip[vNum-1] = DBISAMTable3->FieldByName("Ip")->AsString;
  521. VitaminCtrl[vNum-1]->DarwinConnection = DBISAMTable3->FieldByName("Darwin")->AsBoolean;
  522. // FB 2006-14-12
  523. if((extractFace[vNum-1] = DBISAMTable3->FieldByName("Faccia")->AsBoolean) == TRUE) {
  524. nameHaar[vNum-1] = DBISAMTable3->FieldByName("Classificatore")->AsString;
  525. if(nameHaar[vNum-1].Length() < 1) {
  526. extractFace[vNum-1] = false;
  527. saveError("Non specificato classificatore video numero : " + vNum-1);
  528. } else {
  529. nameHaar[vNum-1] = DBISAMTable3->FieldByName("Classificatore")->AsString;
  530. classifierX[vNum-1] = DBISAMTable3->FieldByName("DimX")->AsInteger;
  531. classifierY[vNum-1] = DBISAMTable3->FieldByName("DimY")->AsInteger;
  532. lstrcpy(classifier,nameHaar[vNum-1].c_str());
  533. if((facce[vNum-1] = (CvHaarClassifierCascade*)cvLoad(classifier, 0, 0, 0 )) == NULL) {
  534. saveError("Errore classificatore" + nameHaar[vNum-1]);
  535. extractFace[vNum-1] = false;
  536. }
  537. }
  538. }
  539. storage = cvCreateMemStorage(0);
  540. recadora = DBISAMTable5->FieldByName("Autostartrec")->AsBoolean;
  541. // ------------------------------------------------------
  542. hosts[vNum-1] = DBISAMTable3->FieldByName("Host")->AsString;
  543. videoactive[vNum-1] = DBISAMTable3->FieldByName("Active")->AsBoolean;
  544. login[vNum-1] = DBISAMTable3->FieldByName("Login")->AsString;
  545. password[vNum-1] = DBISAMTable3->FieldByName("Password")->AsString;
  546. MotionTimeout[vNum-1] = DBISAMTable3->FieldByName("Timeout")->AsInteger;
  547. VrProgressBar1->MaxValue = MotionTimeout[vNum-1];
  548. millisec = DBEdit16->Text.ToInt();
  549. if(millisec != 0)
  550. VitaminCtrl[idx]->ReconnectionWait = millisec;
  551.  
  552. iris[idx] = DBISAMTable3->FieldByName("Irisauto")->AsBoolean;
  553. frate[idx] = DBISAMTable3->FieldByName("Framerate")->AsInteger;
  554.  
  555. if(!DBCheckBox55->Checked) {
  556. VitaminCtrl[idx]->AVIVideoSizeByStream = false;
  557. VitaminCtrl[idx]->AVIVideoHeight = 480;
  558. VitaminCtrl[idx]->AVIVideoWidth = 640;
  559. } else
  560. VitaminCtrl[idx]->AVIVideoSizeByStream = true;
  561. idx++;
  562. DBISAMTable3->Next();
  563. DBISAMTable11->Next();
  564. }
  565. for(i=0;i!=6;i++) {
  566. if(DBCheckBox61->Checked )
  567. VitaminCtrl[i]->ConnectionTimeout = DBEdit32->Text.ToInt();
  568. VitaminCtrl[i]->AutoServerModelType = true;
  569. VitaminCtrl[i]->Deblocking = DBCheckBox58->Checked;
  570. VitaminCtrl[i]->DDrawOnePass = DBCheckBox57->Checked;
  571. // PC
  572. VitaminCtrl[i]->DisplayErrorMsg = false;
  573. // ----------------------------------
  574. VitaminCtrl[i]->DisplayMotionFrame = 0;
  575. AA(i) = false;
  576. }
  577.  
  578. minx = DBISAMTable5->FieldByName("Minx")->AsInteger;
  579. miny = DBISAMTable5->FieldByName("Miny")->AsInteger;
  580. maxerrori = DBISAMTable5->FieldByName("Errori")->AsInteger;
  581. maxSize = DBEdit44->Text.ToInt();
  582. if(maxSize > 0) {
  583. for(int i=0;i!=6;i++)
  584. VitaminCtrl[i]->MaxFileSize = maxSize;
  585. }
  586.  
  587. deleteafter =DBISAMTable5->FieldByName("Deleteafter")->AsInteger;
  588.  
  589. buffSize = DBEdit31->Text.ToInt();
  590. convertStr2Wchar("irisauto");
  591. for(i=0;i!=6;i++) {
  592. if(iris[i])
  593. VitaminCtrl[i]->SendCameraCommand(destTmp, 10000);
  594. if(buffSize >= 256000 && buffSize < 20000000)
  595. VitaminCtrl1->PreBufferMemorySize = buffSize;
  596. }
  597. setCtrlConnection(DBCheckBox62->Checked);
  598. ramDisk.printf("%1c:", DBEdit20->Text.c_str());
  599. // PC
  600. // moved here. Before was inside loop
  601. SearchFaceInterval = (DBEdit15->Text.ToInt() * 1000) / 6;
  602. Timer1->Interval = SearchFaceInterval;
  603. // --------------------------
  604. Timer1->Enabled = true;
  605. // PC 2006-12-15
  606. tmrDelete->Enabled = true;
  607. //---------------------
  608. setDisplayPeriod();
  609.  
  610. tmrMonitorMessage->Enabled = false;
  611. NMUDPMonitor->RemoteHost = dbeRemoteHost->Text;
  612. NMUDPMonitor->RemotePort = StrToInt(dbeRemotePort->Text);
  613. NMUDPMonitor->LocalPort = StrToInt(dbeLocalPort->Text);
  614. tmrMonitorMessage->Interval = StrToInt(dbeMonitorInterval->Text) * 1000;
  615. if (tmrMonitorMessage->Interval > 0)
  616. tmrMonitorMessage->Enabled = true;
  617.  
  618.  
  619. // PC 2005-12-18
  620. saveError("Lettura setup eseguita");
  621. //--------------------
  622. }
  623.  
  624. int TForm1::createAviRecord(int video)
  625. {
  626. AnsiString tmp;
  627. time_t first;
  628. TDateTime DateTime;
  629. AnsiString dirTocreate;
  630. DBISAMTable1->Insert();
  631. first = time(NULL);
  632. DateTime = Time(); // store the current date and time
  633. DBISAMTable1->FieldByName("Time")->AsInteger = (long) first;
  634. DBISAMTable1->FieldByName("Data")->AsDateTime = DateToStr(Date());
  635. DBISAMTable1->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
  636. DBISAMTable1->FieldByName("Video")->AsInteger = video;
  637. DBISAMTable1->Post();
  638.  
  639. DBISAMTable1->FindLast();
  640. DBISAMTable1->Edit();
  641. record[video-1] = DBISAMTable1->FieldByName("Record")->AsInteger;
  642. dirTocreate.printf("%s\\Vivotek%d_%d", path, video, record[video-1]);
  643. DBISAMTable1->FieldByName("Path")->AsString = dirTocreate;
  644. DBISAMTable1->Post();
  645.  
  646. DBISAMTable1->FlushBuffers();
  647.  
  648. CreateDirectory(dirTocreate.c_str(), NULL);
  649. VitaminCtrl[video-1]->AVIPath = dirTocreate;
  650. return record[video-1];
  651. }
  652.  
  653. //---------------------------------------------------------------------------
  654.  
  655. void __fastcall TForm1::VrPowerButton2Click(TObject *Sender)
  656. {
  657. bool flag = VrPowerButton2->Active;
  658. fsm1 = 0;
  659. if(flag) {
  660. VrPowerButton2->Caption = "Ferma";
  661. if(!DBCheckBox55->Checked)
  662. VitaminCtrl1->AVIVideoFrameRate = frate[0];
  663. VitaminCtrl1->EventTypes = 7;
  664. } else {
  665. if(AA(0)) {
  666. // PC
  667. StopAVIRecord(0);
  668. // -------------------
  669. saveError ("Stop Registrazione/Analisi camera 1");
  670. }
  671. VrPowerButton2->Caption = "Analisi";
  672. VitaminCtrl1->EventTypes = 0;
  673. AA(0) = false;
  674. }
  675. A(0) = flag;
  676. }
  677. //---------------------------------------------------------------------------
  678.  
  679. void __fastcall TForm1::VrPowerButton4Click(TObject *Sender)
  680. {
  681. bool flag = VrPowerButton4->Active;
  682. fsm2 = 0;
  683. if(flag) {
  684. VrPowerButton4->Caption = "Ferma";
  685. if(!DBCheckBox55->Checked)
  686. VitaminCtrl2->AVIVideoFrameRate = frate[1];
  687. VitaminCtrl2->EventTypes = 7;
  688. } else {
  689. if(AA(1)) {
  690. // PC
  691. StopAVIRecord(1);
  692. // -------------------
  693. saveError ("Stop Registrazione/Analisi camera 2");
  694.  
  695. }
  696. VrPowerButton4->Caption = "Analisi";
  697. VitaminCtrl2->EventTypes = 0;
  698. AA(1) = false;
  699. }
  700. A(1) = flag;
  701. }
  702. //---------------------------------------------------------------------------
  703.  
  704. void __fastcall TForm1::VrPowerButton6Click(TObject *Sender)
  705. {
  706. bool flag = VrPowerButton6->Active;
  707. fsm3 = 0;
  708. if(flag) {
  709. VrPowerButton6->Caption = "Ferma";
  710. if(!DBCheckBox55->Checked)
  711. VitaminCtrl3->AVIVideoFrameRate = frate[2];
  712. VitaminCtrl3->EventTypes = 7;
  713. } else {
  714. if(AA(2)) {
  715. // PC
  716. StopAVIRecord(2);
  717. // -------------------
  718. saveError ("Stop Registrazione/Analisi camera 3");
  719. }
  720.  
  721. VrPowerButton6->Caption = "Analisi";
  722. VitaminCtrl3->EventTypes = 0;
  723. AA(2) = false;
  724. }
  725. A(2) = flag;
  726. }
  727. //---------------------------------------------------------------------------
  728.  
  729. void __fastcall TForm1::VrPowerButton8Click(TObject *Sender)
  730. {
  731. bool flag = VrPowerButton8->Active;
  732. fsm4 = 0;
  733. if(flag) {
  734. VrPowerButton8->Caption = "Ferma";
  735. if(!DBCheckBox55->Checked)
  736. VitaminCtrl4->AVIVideoFrameRate = frate[3];
  737. VitaminCtrl4->EventTypes = 7;
  738. } else {
  739. if(AA(3)) {
  740. // PC
  741. StopAVIRecord(3);
  742. // -------------------
  743. saveError ("Stop Registrazione/Analisi camera 4");
  744. }
  745.  
  746. VrPowerButton8->Caption = "Analisi";
  747. VitaminCtrl4->EventTypes = 0;
  748. AA(3) = false;
  749. }
  750. A(3) = flag;
  751.  
  752. }
  753. //---------------------------------------------------------------------------
  754.  
  755. void __fastcall TForm1::VrPowerButton10Click(TObject *Sender)
  756. {
  757. bool flag = VrPowerButton10->Active;
  758. fsm5 = 0;
  759. if(flag) {
  760. VrPowerButton10->Caption = "Ferma";
  761. if(!DBCheckBox55->Checked)
  762. VitaminCtrl5->AVIVideoFrameRate = frate[4];
  763. VitaminCtrl5->EventTypes = 7;
  764. } else {
  765. if(AA(4)) {
  766. // PC
  767. StopAVIRecord(4);
  768. // -------------------
  769. saveError ("Stop Registrazione/Analisi camera 5");
  770. }
  771.  
  772. VrPowerButton10->Caption = "Analisi";
  773. VitaminCtrl5->EventTypes = 0;
  774. AA(4) = false;
  775. }
  776. A(4) = flag;
  777.  
  778. }
  779. //---------------------------------------------------------------------------
  780.  
  781.  
  782. //---------------------------------------------------------------------------
  783.  
  784. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  785. {
  786.  
  787. static bool flag = false;
  788. AnsiString S;
  789. int v;
  790. IplImage *image;
  791. static __int64 diskInit;
  792. static int physInit;
  793. static int pageInit;
  794. static int virtInit;
  795. AnsiString file, file2;
  796. static int index = 0;
  797.  
  798. Timer1->Enabled = false;
  799.  
  800. MEMORYSTATUS ms;
  801. ms.dwLength = sizeof(MEMORYSTATUS);
  802. GlobalMemoryStatus(&ms);
  803.  
  804.  
  805. __int64 AmtFree = DiskFree(0);
  806. __int64 Total = DiskSize(0);
  807.  
  808. if(!flag) {
  809. flag = true;
  810. diskInit = AmtFree/1024;
  811. physInit = ms.dwAvailPhys/1024;
  812. pageInit = ms.dwAvailPageFile/1024;
  813. virtInit = ms.dwAvailVirtual/1024 ;
  814. }
  815. S.sprintf("MemFree[In,At] : disco[%I64d k, %I64d k] fisica[%d, %d] paginata[%d, %d] virtuale[%d, %d]", diskInit, AmtFree/1024, physInit, ms.dwAvailPhys/1024, pageInit, ms.dwAvailPageFile/1024, virtInit, ms.dwAvailVirtual/1024 );
  816. StatusBar1->SimpleText = S;
  817. Total = AmtFree*1024;
  818. if(Total < 10000)
  819. deleteAllRecords();
  820.  
  821. if(AA(index)) {
  822. if(DBCheckBox63->Checked)
  823. TakeSnapshotDiProva (index);
  824. if(extractFace[index]) {
  825. if((image=getImage(true, index)) != NULL) {
  826. searchObject(image, index, 0);
  827. cvReleaseImage(&image);
  828. }
  829. }
  830.  
  831. Timer1->Interval = SearchFaceInterval; // sec i global and shoul be contain Timer1 interval
  832. }
  833. else
  834. Timer1->Interval = 1;
  835. ++index;
  836. if(index == 6)
  837. index = 0;
  838. Application->ProcessMessages();
  839. Timer1->Enabled = true;
  840. }
  841.  
  842. IplImage * TForm1::getImage(bool tipo, int video)
  843. {
  844.  
  845. IplImage* image = NULL;
  846.  
  847. AnsiString fName;
  848. fName.printf("g:\\video%02d.jpg" , video);
  849.  
  850. if(FileExists(fName))
  851. DeleteFile(fName);
  852. convertStr2Wchar(fName);
  853. VitaminCtrl[video]->SaveSnapshot(Vitamindecoderlib_tlb::ePicFmtJpeg, destTmp);
  854.  
  855. ImageEnIO1->LoadFromFileJpeg(fName);
  856. ImageEnView5->Refresh();
  857.  
  858. image = TBitmapToIplImage(ImageEnView5->Bitmap);
  859.  
  860. return image;
  861. }
  862.  
  863.  
  864.  
  865. void __fastcall TForm1::Button1Click(TObject *Sender)
  866. {
  867. VitaminCtrl7->AutoServerModelType = true;
  868. VitaminCtrl7->UserName = DBEdit4->Text;
  869. VitaminCtrl7->Password = DBEdit5->Text;
  870. VitaminCtrl7->RemoteIPAddr = DBEdit2->Text;
  871. VitaminCtrl7->Connect();
  872. if(DBEdit27->Text.ToInt() != 0) {
  873. VitaminCtrl7->DigitalZoomEnabled = true;
  874. VitaminCtrl7->DigitalZoomFactor = DBEdit27->Text.ToInt();
  875. }
  876. }
  877. //---------------------------------------------------------------------------
  878.  
  879.  
  880. void __fastcall TForm1::VrCheckLed1Click(TObject *Sender)
  881. {
  882. VitaminCtrl1->DisplayMotionFrame = VrCheckLed1->Checked;
  883. }
  884. //---------------------------------------------------------------------------
  885.  
  886. void __fastcall TForm1::VrCheckLed2Click(TObject *Sender)
  887. {
  888. VitaminCtrl2->DisplayMotionFrame = VrCheckLed2->Checked;
  889. }
  890. //---------------------------------------------------------------------------
  891.  
  892. void __fastcall TForm1::VrCheckLed3Click(TObject *Sender)
  893. {
  894. VitaminCtrl3->DisplayMotionFrame = VrCheckLed3->Checked;
  895. }
  896. //---------------------------------------------------------------------------
  897.  
  898. void __fastcall TForm1::VrCheckLed4Click(TObject *Sender)
  899. {
  900. VitaminCtrl4->DisplayMotionFrame = VrCheckLed4->Checked;
  901. }
  902. //---------------------------------------------------------------------------
  903.  
  904.  
  905. void __fastcall TForm1::VrCheckLed5Click(TObject *Sender)
  906. {
  907. VitaminCtrl5->DisplayMotionFrame = VrCheckLed5->Checked;
  908. }
  909. //---------------------------------------------------------------------------
  910.  
  911. void __fastcall TForm1::VrCheckLed6Click(TObject *Sender)
  912. {
  913. VitaminCtrl6->DisplayMotionFrame = VrCheckLed6->Checked;
  914. }
  915. //---------------------------------------------------------------------------
  916.  
  917.  
  918. void __fastcall TForm1::Button2Click(TObject *Sender)
  919. {
  920. VitaminCtrl7->Disconnect();
  921. }
  922. //---------------------------------------------------------------------------
  923.  
  924.  
  925.  
  926.  
  927.  
  928. void TForm1::activateZoom()
  929. {
  930. PageControl1->ActivePageIndex = 3;
  931. VitaminCtrl8->Disconnect();
  932. Sleep(2000);
  933. VitaminCtrl8->AutoServerModelType = true;
  934. VitaminCtrl8->EventTypes = 0;
  935. VitaminCtrl8->RemoteIPAddr = zip;
  936. VitaminCtrl8->UserName = zlogin;
  937. VitaminCtrl8->Password = zpassword;
  938. VitaminCtrl8->Connect();
  939. }
  940.  
  941.  
  942.  
  943. void TForm1::getAviname(AnsiString & filename, int video)
  944. {
  945. AnsiString buffer;
  946. TSearchRec sr;
  947. int iAttributes = 0;
  948. iAttributes |= faReadOnly;
  949. iAttributes |= faHidden;
  950. iAttributes |= faSysFile;
  951. iAttributes |= faVolumeID;
  952. iAttributes |= faDirectory;
  953. iAttributes |= faArchive;
  954. iAttributes |= faAnyFile;
  955. buffer = DBISAMTable1->FieldByName("Path")->AsString;
  956. filename.printf("%s\\*.avi", buffer);
  957. if (FindFirst(filename, iAttributes, sr) == 0)
  958. filename.printf("%s\\%s",buffer, sr.Name);
  959. else
  960. filename = "";
  961. FindClose(sr);
  962. }
  963. //-------------------------------------------------
  964. // PC
  965. AnsiString __fastcall TForm1::ObtainVideoPath(void)
  966. {
  967. char pathChar[256];
  968. AnsiString OutString;
  969.  
  970. OutString = DBISAMTable5->FieldByName("VideoDir")->AsString;
  971. if (OutString.IsEmpty()) {
  972. // field is empty so take current dir
  973. getcwd(pathChar, 256);
  974. OutString = pathChar;
  975. }
  976. return OutString;
  977. }
  978. //-------------------------------------------------
  979. void __fastcall TForm1::FormCreate(TObject *Sender)
  980. {
  981. AnsiString str;
  982.  
  983. // PC
  984. // Spostato il settaggio della variabile 'path'
  985. // nella loadSetup
  986. // ----------------------------
  987.  
  988. // PC
  989. // useful for checking one instance only
  990. Caption = Application->Title;
  991. // ----------------------------
  992.  
  993. DBISAMDatabase1->Connected = false;
  994.  
  995. // PC
  996. DBISAMDatabase1->Directory = ReadDBPathFromINI();
  997. //---------------------------------
  998. DBISAMDatabase1->Connected = true;
  999.  
  1000. RepairTables();
  1001.  
  1002. // PC
  1003. // Activate all tables
  1004. DBISAMTable1->Active = true;
  1005. DBISAMTable2->Active = true;
  1006. DBISAMTable3->Active = true;
  1007. DBISAMTable4->Active = true;
  1008. DBISAMTable5->Active = true;
  1009. DBISAMTable6->Active = true;
  1010. DBISAMTable7->Active = true;
  1011. DBISAMTable8->Active = true;
  1012. DBISAMTable9->Active = true;
  1013. DBISAMTable10->Active = true;
  1014. tblPanoramicheVisual->Active = true;
  1015. //-----------------------
  1016.  
  1017.  
  1018. VitaminCtrl[0] = VitaminCtrl1;
  1019. VitaminCtrl[1] = VitaminCtrl2;
  1020. VitaminCtrl[2] = VitaminCtrl3;
  1021. VitaminCtrl[3] = VitaminCtrl4;
  1022. VitaminCtrl[4] = VitaminCtrl5;
  1023. VitaminCtrl[5] = VitaminCtrl6;
  1024.  
  1025. VrUL[0] = VrUserLed3;
  1026. VrUL[1] = VrUserLed1;
  1027. VrUL[2] = VrUserLed2;
  1028. VrUL[3] = VrUserLed4;
  1029. VrUL[4] = VrUserLed5;
  1030. VrUL[5] = VrUserLed6;
  1031.  
  1032. VrULActive[0] = VrUserLed7;
  1033. VrULActive[1] = VrUserLed8;
  1034. VrULActive[2] = VrUserLed9;
  1035. VrULActive[3] = VrUserLed10;
  1036. VrULActive[4] = VrUserLed14;
  1037. VrULActive[5] = VrUserLed13;
  1038.  
  1039. for(int i =0;i!=6;i++) {
  1040. VitaminCtrl[i]->MaxFileSize = 700000000;
  1041. VitaminCtrl[i]->EventTypes = 0;
  1042. }
  1043.  
  1044. // load packet header in monitor message buffer
  1045. LoadSFPacketHeader (SFPacketToSend);
  1046. }
  1047. //---------------------------------------------------------------------------
  1048.  
  1049.  
  1050.  
  1051.  
  1052. void TForm1::saveImage(int video)
  1053. {
  1054. AnsiString filename;
  1055. int x, y;
  1056. long ltime;
  1057. bool ch = DBISAMTable5->FieldByName("Saveimage")->AsBoolean;
  1058. if(!ch || !motion[video])
  1059. return;
  1060.  
  1061. motion[video] = false;
  1062. TDateTime DateTime;
  1063. AnsiString dirTocreate;
  1064.  
  1065. ltime = time(NULL);
  1066. DBISAMTable8->Insert();
  1067. DateTime = Time(); // store the current date and time
  1068. DBISAMTable8->FieldByName("Data")->AsDateTime = DateToStr(Date());
  1069. DBISAMTable8->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
  1070. // PC
  1071. // video is not correct!. video+1 yes.
  1072. DBISAMTable8->FieldByName("Video")->AsInteger = video+1;
  1073. // -----------------------------------------------------
  1074. DBISAMTable8->FieldByName("Time")->AsInteger = (long) ltime;
  1075.  
  1076. filename.printf("%s\\img.jpg", path);
  1077. ImageEnIO1->SaveToFileJpeg(filename);
  1078. ImageEnIO4->LoadFromFileJpeg(filename);
  1079. DBISAMTable8->Post();
  1080.  
  1081. }
  1082.  
  1083. struct orari {
  1084. int giorno;
  1085. bool oraminuti[48];
  1086. } orario[7];
  1087.  
  1088.  
  1089. void TForm1::loadOrario(void)
  1090. {
  1091. int giorno;
  1092. DBISAMTable6->First();
  1093. while(!DBISAMTable6->Eof) {
  1094. giorno = DBISAMTable6->FieldByName("Numero")->AsInteger;
  1095. orario[giorno-1].oraminuti[0] = DBISAMTable6->FieldByName("A0000")->AsBoolean;
  1096. orario[giorno-1].oraminuti[1] = DBISAMTable6->FieldByName("A0030")->AsBoolean;
  1097. orario[giorno-1].oraminuti[2] = DBISAMTable6->FieldByName("A0100")->AsBoolean;
  1098. orario[giorno-1].oraminuti[3] = DBISAMTable6->FieldByName("A0130")->AsBoolean;
  1099. orario[giorno-1].oraminuti[4] = DBISAMTable6->FieldByName("A0200")->AsBoolean;
  1100. orario[giorno-1].oraminuti[5] = DBISAMTable6->FieldByName("A0230")->AsBoolean;
  1101. orario[giorno-1].oraminuti[6] = DBISAMTable6->FieldByName("A0300")->AsBoolean;
  1102. orario[giorno-1].oraminuti[7] = DBISAMTable6->FieldByName("A0330")->AsBoolean;
  1103. orario[giorno-1].oraminuti[8] = DBISAMTable6->FieldByName("A0400")->AsBoolean;
  1104. orario[giorno-1].oraminuti[9] = DBISAMTable6->FieldByName("A0430")->AsBoolean;
  1105. orario[giorno-1].oraminuti[10] = DBISAMTable6->FieldByName("A0500")->AsBoolean;
  1106. orario[giorno-1].oraminuti[11] = DBISAMTable6->FieldByName("A0530")->AsBoolean;
  1107.  
  1108. orario[giorno-1].oraminuti[12] = DBISAMTable6->FieldByName("A0600")->AsBoolean;
  1109. orario[giorno-1].oraminuti[13] = DBISAMTable6->FieldByName("A0630")->AsBoolean;
  1110. orario[giorno-1].oraminuti[14] = DBISAMTable6->FieldByName("A0700")->AsBoolean;
  1111. orario[giorno-1].oraminuti[15] = DBISAMTable6->FieldByName("A0730")->AsBoolean;
  1112. orario[giorno-1].oraminuti[16] = DBISAMTable6->FieldByName("A0800")->AsBoolean;
  1113. orario[giorno-1].oraminuti[17] = DBISAMTable6->FieldByName("A0830")->AsBoolean;
  1114. orario[giorno-1].oraminuti[18] = DBISAMTable6->FieldByName("A0900")->AsBoolean;
  1115. orario[giorno-1].oraminuti[19] = DBISAMTable6->FieldByName("A0930")->AsBoolean;
  1116. orario[giorno-1].oraminuti[20] = DBISAMTable6->FieldByName("A1000")->AsBoolean;
  1117. orario[giorno-1].oraminuti[21] = DBISAMTable6->FieldByName("A1030")->AsBoolean;
  1118. orario[giorno-1].oraminuti[22] = DBISAMTable6->FieldByName("A1100")->AsBoolean;
  1119. orario[giorno-1].oraminuti[23] = DBISAMTable6->FieldByName("A1130")->AsBoolean;
  1120.  
  1121. orario[giorno-1].oraminuti[24] = DBISAMTable6->FieldByName("A1200")->AsBoolean;
  1122. orario[giorno-1].oraminuti[25] = DBISAMTable6->FieldByName("A1230")->AsBoolean;
  1123. orario[giorno-1].oraminuti[26] = DBISAMTable6->FieldByName("A1300")->AsBoolean;
  1124. orario[giorno-1].oraminuti[27] = DBISAMTable6->FieldByName("A1330")->AsBoolean;
  1125. orario[giorno-1].oraminuti[28] = DBISAMTable6->FieldByName("A1400")->AsBoolean;
  1126. orario[giorno-1].oraminuti[29] = DBISAMTable6->FieldByName("A1430")->AsBoolean;
  1127. orario[giorno-1].oraminuti[30] = DBISAMTable6->FieldByName("A1500")->AsBoolean;
  1128. orario[giorno-1].oraminuti[31] = DBISAMTable6->FieldByName("A1530")->AsBoolean;
  1129. orario[giorno-1].oraminuti[32] = DBISAMTable6->FieldByName("A1600")->AsBoolean;
  1130. orario[giorno-1].oraminuti[33] = DBISAMTable6->FieldByName("A1630")->AsBoolean;
  1131. orario[giorno-1].oraminuti[34] = DBISAMTable6->FieldByName("A1700")->AsBoolean;
  1132. orario[giorno-1].oraminuti[35] = DBISAMTable6->FieldByName("A1730")->AsBoolean;
  1133.  
  1134. orario[giorno-1].oraminuti[36] = DBISAMTable6->FieldByName("A1800")->AsBoolean;
  1135. orario[giorno-1].oraminuti[37] = DBISAMTable6->FieldByName("A1830")->AsBoolean;
  1136. orario[giorno-1].oraminuti[38] = DBISAMTable6->FieldByName("A1900")->AsBoolean;
  1137. orario[giorno-1].oraminuti[39] = DBISAMTable6->FieldByName("A1930")->AsBoolean;
  1138. orario[giorno-1].oraminuti[40] = DBISAMTable6->FieldByName("A2000")->AsBoolean;
  1139. orario[giorno-1].oraminuti[41] = DBISAMTable6->FieldByName("A2030")->AsBoolean;
  1140. orario[giorno-1].oraminuti[42] = DBISAMTable6->FieldByName("A2100")->AsBoolean;
  1141. orario[giorno-1].oraminuti[43] = DBISAMTable6->FieldByName("A2130")->AsBoolean;
  1142. orario[giorno-1].oraminuti[44] = DBISAMTable6->FieldByName("A2200")->AsBoolean;
  1143. orario[giorno-1].oraminuti[45] = DBISAMTable6->FieldByName("A2230")->AsBoolean;
  1144. orario[giorno-1].oraminuti[46] = DBISAMTable6->FieldByName("A2300")->AsBoolean;
  1145. orario[giorno-1].oraminuti[47] = DBISAMTable6->FieldByName("A2330")->AsBoolean;
  1146. DBISAMTable6->Next();
  1147. }
  1148.  
  1149. }
  1150.  
  1151.  
  1152. void __fastcall TForm1::VrDemoButton7Click(TObject *Sender)
  1153. {
  1154.  
  1155. DBISAMTable1->FlushBuffers();
  1156. DBISAMTable2->FlushBuffers();
  1157. DBISAMTable3->FlushBuffers();
  1158. DBISAMTable4->FlushBuffers();
  1159. DBISAMTable5->FlushBuffers();
  1160. DBISAMTable6->FlushBuffers();
  1161. DBISAMTable7->FlushBuffers();
  1162. DBISAMTable8->FlushBuffers();
  1163. Form1->Close();
  1164. // Application->Terminate();
  1165. }
  1166. //---------------------------------------------------------------------------
  1167.  
  1168. void __fastcall TForm1::VrDemoButton8Click(TObject *Sender)
  1169. {
  1170. zip = ip[0];
  1171. zlogin = login[0];
  1172. zpassword = password[0];
  1173. activateZoom();
  1174. }
  1175. //---------------------------------------------------------------------------
  1176.  
  1177. void __fastcall TForm1::VrDemoButton9Click(TObject *Sender)
  1178. {
  1179. zip = ip[1];
  1180. zlogin = login[1];
  1181. zpassword = password[1];
  1182. activateZoom();
  1183.  
  1184. }
  1185. //---------------------------------------------------------------------------
  1186.  
  1187. void __fastcall TForm1::VrDemoButton10Click(TObject *Sender)
  1188. {
  1189. zip = ip[2];
  1190. zlogin = login[2];
  1191. zpassword = password[2];
  1192. activateZoom();
  1193.  
  1194. }
  1195. //---------------------------------------------------------------------------
  1196.  
  1197. void __fastcall TForm1::VrDemoButton11Click(TObject *Sender)
  1198. {
  1199. zip = ip[3];
  1200. zlogin = login[3];
  1201. zpassword = password[3];
  1202. activateZoom();
  1203.  
  1204. }
  1205. //---------------------------------------------------------------------------
  1206.  
  1207.  
  1208. void __fastcall TForm1::VrDemoButton13Click(TObject *Sender)
  1209. {
  1210. zip = ip[5];
  1211. zlogin = login[5];
  1212. zpassword = password[5];
  1213. activateZoom();
  1214.  
  1215.  
  1216. }
  1217. //---------------------------------------------------------------------------
  1218.  
  1219.  
  1220. void __fastcall TForm1::Button5Click(TObject *Sender)
  1221. {
  1222. AnsiString tmp;
  1223. tmp.printf("http://%s", ip[0]);
  1224. Edit1->Text = tmp;
  1225.  
  1226. }
  1227. //---------------------------------------------------------------------------
  1228.  
  1229. void __fastcall TForm1::Button6Click(TObject *Sender)
  1230. {
  1231. AnsiString tmp;
  1232. tmp.printf("http://%s", ip[1]);
  1233. Edit1->Text = tmp;
  1234.  
  1235. }
  1236. //---------------------------------------------------------------------------
  1237.  
  1238. void __fastcall TForm1::Button7Click(TObject *Sender)
  1239. {
  1240. AnsiString tmp;
  1241. tmp.printf("http://%s", ip[2]);
  1242. Edit1->Text = tmp;
  1243.  
  1244. }
  1245. //---------------------------------------------------------------------------
  1246.  
  1247. void __fastcall TForm1::Button8Click(TObject *Sender)
  1248. {
  1249. AnsiString tmp;
  1250. tmp.printf("http://%s", ip[3]);
  1251. Edit1->Text = tmp;
  1252.  
  1253. }
  1254. //---------------------------------------------------------------------------
  1255.  
  1256. void __fastcall TForm1::Button9Click(TObject *Sender)
  1257. {
  1258. AnsiString tmp;
  1259. tmp.printf("http://%s", ip[4]);
  1260. Edit1->Text = tmp;
  1261.  
  1262. }
  1263. //---------------------------------------------------------------------------
  1264.  
  1265. void __fastcall TForm1::Button10Click(TObject *Sender)
  1266. {
  1267. AnsiString tmp;
  1268. tmp.printf("http://%s", ip[5]);
  1269. Edit1->Text = tmp;
  1270.  
  1271. }
  1272. //---------------------------------------------------------------------------
  1273.  
  1274. void __fastcall TForm1::Button3Click(TObject *Sender)
  1275. {
  1276. CppWebBrowser2->GoBack();
  1277. }
  1278. //---------------------------------------------------------------------------
  1279.  
  1280. void __fastcall TForm1::Button4Click(TObject *Sender)
  1281. {
  1282. CppWebBrowser2->GoBack();
  1283. }
  1284. //---------------------------------------------------------------------------
  1285.  
  1286.  
  1287. void __fastcall TForm1::VrDemoButton15Click(TObject *Sender)
  1288. {
  1289. static bool flag = true;
  1290. VitaminCtrl7->MDEditMode = flag;
  1291. flag = !flag;
  1292. }
  1293. //---------------------------------------------------------------------------
  1294.  
  1295. void __fastcall TForm1::VrPowerButton13Click(TObject *Sender)
  1296. {
  1297. static bool flag = true;
  1298. if(flag) {
  1299. VitaminCtrl8->AVIPath = VrStrEdit1->Text;
  1300. VitaminCtrl8->StartAVIConversion();
  1301. } else
  1302. VitaminCtrl8->StopAVIConversion();
  1303. flag = !flag;
  1304. }
  1305. //---------------------------------------------------------------------------
  1306.  
  1307. void __fastcall TForm1::VrShadowButton1Click(TObject *Sender)
  1308. {
  1309. TVariant pvInfo[2], pvData;
  1310. unsigned char *arrayAccess;
  1311. TDateTime DateTime;
  1312. AnsiString dirTocreate;
  1313. long lStartBound = 0;
  1314. long lEndBound = 0;
  1315.  
  1316. if (VitaminCtrl8->ControlStatus == 2) { // Status is Running
  1317. VariantInit(&pvData);
  1318. VariantInit(&pvInfo[0]); // Mette a VT_EMPTY vt
  1319. VariantInit(&pvInfo[1]);
  1320.  
  1321. VitaminCtrl8->GetSnapshot(Vitamindecoderlib_tlb::ePicFmtBmp, &pvData, &pvInfo[0]);
  1322. SAFEARRAY* pSafeArray = pvData.parray;
  1323. SafeArrayGetLBound(pSafeArray, 1, &lStartBound);
  1324. SafeArrayGetUBound(pSafeArray, 1, &lEndBound);
  1325. SafeArrayAccessData(pSafeArray, (void **) &arrayAccess);
  1326.  
  1327. DBISAMTable7->Insert();
  1328. ImageEnIO3->LoadFromBuffer((BYTE *) arrayAccess, lEndBound, ioBMP);
  1329. ImageEnDBView2->Update();
  1330.  
  1331. DateTime = Time(); // store the current date and time
  1332. DBISAMTable7->FieldByName("Data")->AsDateTime = DateToStr(Date());
  1333. DBISAMTable7->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
  1334. DBISAMTable7->Post();
  1335. }
  1336.  
  1337. }
  1338. //---------------------------------------------------------------------------
  1339.  
  1340. void __fastcall TForm1::ImageEnDBView2DblClick(TObject *Sender)
  1341. {
  1342. // PC
  1343. frmView->ShowModal();
  1344. // --------------------------
  1345. // now the
  1346. // if( SaveImageEnDialog1->Execute() )
  1347. // ImageEnIO3->SaveToFile(SaveImageEnDialog1->FileName);
  1348.  
  1349. }
  1350. //---------------------------------------------------------------------------
  1351.  
  1352. void __fastcall TForm1::Button11Click(TObject *Sender)
  1353. {
  1354. CppWebBrowser2->Navigate((TVariant)Edit1->Text.c_str());
  1355.  
  1356. }
  1357. //---------------------------------------------------------------------------
  1358.  
  1359.  
  1360. void __fastcall TForm1::Button13Click(TObject *Sender)
  1361. {
  1362. loadOrario();
  1363. }
  1364. //---------------------------------------------------------------------------
  1365.  
  1366. void __fastcall TForm1::VrCheckLed7Click(TObject *Sender)
  1367. {
  1368. static bool flag = true;
  1369. Timer2->Enabled = flag;
  1370. flag = !flag;
  1371. }
  1372. //---------------------------------------------------------------------------
  1373.  
  1374. void __fastcall TForm1::Timer2Timer(TObject *Sender)
  1375. {
  1376. int giorno, indice;
  1377.  
  1378. Timer2->Enabled = false;
  1379. Word Year, Month, Day, Hour, Min, Sec, MSec;
  1380. TDateTime DateTime = Now();
  1381. DateTime.DecodeDate(&Year, &Month, &Day);
  1382. DateTime.DecodeTime(&Hour, &Min, &Sec, &MSec);
  1383. // PC 2006-14-12
  1384. // non so perche' si cancellano solo se min==0
  1385. // quindi lo tolgo e la procedura di cancellazione
  1386. /*
  1387. if(Min == 0) {
  1388. deleteafter = DBEdit26->Text.ToInt();
  1389. if(deleteafter)
  1390. deleteAllrecordafter();
  1391. }*/
  1392.  
  1393. // PC
  1394. // la cencellazione viene eseguita da un timer apposito : tmrDeleteRecord
  1395. //
  1396.  
  1397.  
  1398. // -------------------------
  1399. if(Min == 0 || Min == 30) {
  1400. giorno = DateTime.DayOfWeek();
  1401. switch(giorno) {
  1402. case 1:
  1403. giorno = 6;
  1404. break;
  1405. case 2:
  1406. giorno = 0;
  1407. break;
  1408. case 3:
  1409. giorno = 1;
  1410. break;
  1411. case 4:
  1412. giorno = 2;
  1413. break;
  1414. case 5:
  1415. giorno = 3;
  1416. break;
  1417. case 6:
  1418. giorno = 4;
  1419. break;
  1420. }
  1421. indice = Hour * 2;
  1422. if(Min >= 30)
  1423. indice++;
  1424. if(orario[giorno].oraminuti[indice])
  1425. setON();
  1426. else
  1427. setOFF();
  1428. }
  1429. Timer2->Enabled = true;
  1430. }
  1431. //---------------------------------------------------------------------------
  1432.  
  1433.  
  1434. void TForm1::setON()
  1435. {
  1436. if(AnsiCompareText(ip[0], "0.0.0.0") && !A(0)) {
  1437. VrPowerButton2->Active = true;
  1438. VrPowerButton2Click (this);
  1439. }
  1440. if(AnsiCompareText(ip[1], "0.0.0.0") && !A(1)) {
  1441. VrPowerButton4->Active = true;
  1442. VrPowerButton4Click (this);
  1443. }
  1444. if(AnsiCompareText(ip[2], "0.0.0.0") && !A(2)) {
  1445. VrPowerButton6->Active = true;
  1446. VrPowerButton6Click (this);
  1447. }
  1448. if(AnsiCompareText(ip[3], "0.0.0.0") && !A(3)) {
  1449. VrPowerButton8->Active = true;
  1450. VrPowerButton8Click (this);
  1451. }
  1452. if(AnsiCompareText(ip[4], "0.0.0.0") && !A(4)) {
  1453. VrPowerButton10->Active = true;
  1454. VrPowerButton10Click (this);
  1455. }
  1456. if(AnsiCompareText(ip[5], "0.0.0.0") && !A(5)) {
  1457. VrPowerButton12->Active = true;
  1458. VrPowerButton12Click (this);
  1459. }
  1460.  
  1461. }
  1462.  
  1463. void TForm1::setOFF()
  1464. {
  1465. if (VrPowerButton2->Active) {
  1466. VrPowerButton2->Active = false;
  1467. VrPowerButton2Click (this);
  1468. }
  1469.  
  1470. if (VrPowerButton4->Active) {
  1471. VrPowerButton4->Active = false;
  1472. VrPowerButton4Click (this);
  1473. }
  1474.  
  1475. if (VrPowerButton6->Active) {
  1476. VrPowerButton6->Active = false;
  1477. VrPowerButton6Click (this);
  1478. }
  1479.  
  1480. if (VrPowerButton8->Active) {
  1481. VrPowerButton8->Active = false;
  1482. VrPowerButton8Click (this);
  1483. }
  1484.  
  1485. if (VrPowerButton10->Active) {
  1486. VrPowerButton10->Active = false;
  1487. VrPowerButton10Click (this);
  1488. }
  1489.  
  1490. if (VrPowerButton12->Active) {
  1491. VrPowerButton12->Active = false;
  1492. VrPowerButton12Click (this);
  1493. }
  1494.  
  1495. }
  1496.  
  1497.  
  1498.  
  1499. void __fastcall TForm1::Button14Click(TObject *Sender)
  1500. {
  1501. DBISAMTable8->First();
  1502. while(!DBISAMTable8->Eof)
  1503. DBISAMTable8->Delete();
  1504. }
  1505. //---------------------------------------------------------------------------
  1506.  
  1507.  
  1508. void __fastcall TForm1::VrDemoButton16Click(TObject *Sender)
  1509. {
  1510. int i;
  1511. DBISAMTable6->First();
  1512. for(i=0;i!=7;i++) {
  1513. DBISAMTable6->Edit();
  1514. switch(i) {
  1515. case 0:
  1516. if(VrCheckLed8->Checked)
  1517. setOrario(true);
  1518. break;
  1519. case 1:
  1520. if(VrCheckLed9->Checked)
  1521. setOrario(true);
  1522. break;
  1523. case 2:
  1524. if(VrCheckLed10->Checked)
  1525. setOrario(true);
  1526. break;
  1527. case 3:
  1528. if(VrCheckLed11->Checked)
  1529. setOrario(true);
  1530. break;
  1531. case 4:
  1532. if(VrCheckLed12->Checked)
  1533. setOrario(true);
  1534. break;
  1535. case 5:
  1536. if(VrCheckLed13->Checked)
  1537. setOrario(true);
  1538. break;
  1539. case 6:
  1540. if(VrCheckLed14->Checked)
  1541. setOrario(true);
  1542. break;
  1543. }
  1544. DBISAMTable6->Post();
  1545. DBISAMTable6->Next();
  1546. }
  1547.  
  1548. }
  1549. //---------------------------------------------------------------------------
  1550.  
  1551.  
  1552. void TForm1::setOrario(bool flag)
  1553. {
  1554.  
  1555. DBISAMTable6->FieldByName("0000")->AsBoolean = flag;
  1556. DBISAMTable6->FieldByName("0030")->AsBoolean = flag;
  1557. DBISAMTable6->FieldByName("0100")->AsBoolean = flag;
  1558. DBISAMTable6->FieldByName("0130")->AsBoolean = flag;
  1559. DBISAMTable6->FieldByName("0200")->AsBoolean = flag;
  1560. DBISAMTable6->FieldByName("0230")->AsBoolean = flag;
  1561. DBISAMTable6->FieldByName("0300")->AsBoolean = flag;
  1562. DBISAMTable6->FieldByName("0330")->AsBoolean = flag;
  1563. DBISAMTable6->FieldByName("0400")->AsBoolean = flag;
  1564. DBISAMTable6->FieldByName("0430")->AsBoolean = flag;
  1565. DBISAMTable6->FieldByName("0500")->AsBoolean = flag;
  1566. DBISAMTable6->FieldByName("0530")->AsBoolean = flag;
  1567.  
  1568. DBISAMTable6->FieldByName("0600")->AsBoolean = flag;
  1569. DBISAMTable6->FieldByName("0630")->AsBoolean = flag;
  1570. DBISAMTable6->FieldByName("0700")->AsBoolean = flag;
  1571. DBISAMTable6->FieldByName("0730")->AsBoolean = flag;
  1572. DBISAMTable6->FieldByName("0800")->AsBoolean = flag;
  1573. DBISAMTable6->FieldByName("0830")->AsBoolean = flag;
  1574. DBISAMTable6->FieldByName("0900")->AsBoolean = flag;
  1575. DBISAMTable6->FieldByName("0930")->AsBoolean = flag;
  1576. DBISAMTable6->FieldByName("1000")->AsBoolean = flag;
  1577. DBISAMTable6->FieldByName("1030")->AsBoolean = flag;
  1578. DBISAMTable6->FieldByName("1100")->AsBoolean = flag;
  1579. DBISAMTable6->FieldByName("1130")->AsBoolean = flag;
  1580. DBISAMTable6->FieldByName("1200")->AsBoolean = flag;
  1581. DBISAMTable6->FieldByName("1230")->AsBoolean = flag;
  1582. DBISAMTable6->FieldByName("1300")->AsBoolean = flag;
  1583. DBISAMTable6->FieldByName("1330")->AsBoolean = flag;
  1584. DBISAMTable6->FieldByName("1400")->AsBoolean = flag;
  1585. DBISAMTable6->FieldByName("1430")->AsBoolean = flag;
  1586. DBISAMTable6->FieldByName("1500")->AsBoolean = flag;
  1587. DBISAMTable6->FieldByName("1530")->AsBoolean = flag;
  1588. DBISAMTable6->FieldByName("1600")->AsBoolean = flag;
  1589. DBISAMTable6->FieldByName("1630")->AsBoolean = flag;
  1590. DBISAMTable6->FieldByName("1700")->AsBoolean = flag;
  1591. DBISAMTable6->FieldByName("1730")->AsBoolean = flag;
  1592.  
  1593. DBISAMTable6->FieldByName("1800")->AsBoolean = flag;
  1594. DBISAMTable6->FieldByName("1830")->AsBoolean = flag;
  1595. DBISAMTable6->FieldByName("1900")->AsBoolean = flag;
  1596. DBISAMTable6->FieldByName("1930")->AsBoolean = flag;
  1597. DBISAMTable6->FieldByName("2000")->AsBoolean = flag;
  1598. DBISAMTable6->FieldByName("2030")->AsBoolean = flag;
  1599. DBISAMTable6->FieldByName("2100")->AsBoolean = flag;
  1600. DBISAMTable6->FieldByName("2130")->AsBoolean = flag;
  1601. DBISAMTable6->FieldByName("2200")->AsBoolean = flag;
  1602. DBISAMTable6->FieldByName("2230")->AsBoolean = flag;
  1603. DBISAMTable6->FieldByName("2300")->AsBoolean = flag;
  1604. DBISAMTable6->FieldByName("2330")->AsBoolean = flag;
  1605. }
  1606.  
  1607. void __fastcall TForm1::VrDemoButton17Click(TObject *Sender)
  1608. {
  1609. int i;
  1610. DBISAMTable6->First();
  1611. for(i=0;i!=7;i++) {
  1612. DBISAMTable6->Edit();
  1613. switch(i) {
  1614. case 0:
  1615. if(VrCheckLed8->Checked)
  1616. setOrario(false);
  1617. break;
  1618. case 1:
  1619. if(VrCheckLed9->Checked)
  1620. setOrario(false);
  1621. break;
  1622. case 2:
  1623. if(VrCheckLed10->Checked)
  1624. setOrario(false);
  1625. break;
  1626. case 3:
  1627. if(VrCheckLed11->Checked)
  1628. setOrario(false);
  1629. break;
  1630. case 4:
  1631. if(VrCheckLed12->Checked)
  1632. setOrario(false);
  1633. break;
  1634. case 5:
  1635. if(VrCheckLed13->Checked)
  1636. setOrario(false);
  1637. break;
  1638. case 6:
  1639. if(VrCheckLed14->Checked)
  1640. setOrario(false);
  1641. break;
  1642. }
  1643. DBISAMTable6->Post();
  1644. DBISAMTable6->Next();
  1645. }
  1646. }
  1647. //---------------------------------------------------------------------------
  1648.  
  1649.  
  1650. void TForm1::deleteAllrecordafter()
  1651. {
  1652. time_t DateTime;
  1653. int record;
  1654. AnsiString buffer, filename;
  1655. long numsec, realtime, elapsed;
  1656. TSearchRec sr;
  1657. int iAttributes = 0;
  1658.  
  1659. numsec = deleteafter * 3600;
  1660.  
  1661. DBISAMTable1->First();
  1662. while(!DBISAMTable1->Eof) {
  1663. DateTime = time(NULL); // store the current date and time
  1664. realtime = DBISAMTable1->FieldByName("Time")->AsInteger;
  1665. elapsed = (long) difftime(DateTime, realtime);
  1666. if(elapsed >= numsec) {
  1667. record = DBISAMTable1->FieldByName("Record")->AsInteger;
  1668. buffer = DBISAMTable1->FieldByName("Path")->AsString;
  1669. filename.printf("%s\\*.avi", buffer);
  1670. iAttributes |= faReadOnly;
  1671. iAttributes |= faHidden;
  1672. iAttributes |= faSysFile;
  1673. iAttributes |= faVolumeID;
  1674. iAttributes |= faDirectory;
  1675. iAttributes |= faArchive;
  1676. iAttributes |= faAnyFile;
  1677. if (FindFirst(filename, iAttributes, sr) == 0) {
  1678. filename.printf("%s\\%s",buffer, sr.Name);
  1679. DeleteFile(filename);
  1680. SetCurrentDir(path);
  1681. FindClose(sr);
  1682. if (DirectoryExists(buffer))
  1683. RemoveDir(buffer);
  1684.  
  1685. }
  1686. DBISAMTable2->First();
  1687. while(!DBISAMTable2->Eof) {
  1688. if(DBISAMTable2->FieldByName("Record")->AsInteger == record)
  1689. DBISAMTable2->Delete();
  1690. else
  1691. DBISAMTable2->Next();
  1692. }
  1693. DBISAMTable1->Delete();
  1694. } else
  1695. DBISAMTable1->Next();
  1696.  
  1697. }
  1698. DBISAMTable1->FlushBuffers();
  1699.  
  1700. DBISAMTable8->First();
  1701. while(!DBISAMTable8->Eof) {
  1702. DateTime = time(NULL); // store the current date and time
  1703. realtime = DBISAMTable8->FieldByName("Time")->AsInteger;
  1704. elapsed = (long) difftime(DateTime, realtime);
  1705. if(elapsed >= numsec)
  1706. DBISAMTable8->Delete();
  1707. else
  1708. DBISAMTable8->Next();
  1709. }
  1710. DBISAMTable8->FlushBuffers();
  1711. }
  1712.  
  1713. void __fastcall TForm1::Button15Click(TObject *Sender)
  1714. {
  1715. deleteafter = DBEdit26->Text.ToInt();
  1716. if(deleteafter)
  1717. deleteAllrecordafter();
  1718. }
  1719. //---------------------------------------------------------------------------
  1720.  
  1721.  
  1722. void __fastcall TForm1::Edit1Exit(TObject *Sender)
  1723. {
  1724. CppWebBrowser2->Navigate((TVariant)Edit1->Text.c_str());
  1725. }
  1726. //---------------------------------------------------------------------------
  1727.  
  1728.  
  1729.  
  1730. void TForm1::setDisplayPeriod()
  1731. {
  1732. int i;
  1733.  
  1734. int n = 0;
  1735.  
  1736. if(!DBCheckBox53->Checked)
  1737. return;
  1738. if(DBCheckBox59->Checked) {
  1739. for(i=0;i!=6;i++)
  1740. if(A(i))
  1741. ++n;
  1742. for(i=0;i!=6;i++) {
  1743. if(A(i))
  1744. VitaminCtrl[i]->DisplayPeriod = n;
  1745. }
  1746. } else {
  1747. for(i=0;i!=6;i++)
  1748. VitaminCtrl[i]->DisplayPeriod = DBEdit28->Text.ToInt();
  1749. }
  1750. }
  1751.  
  1752.  
  1753. void __fastcall TForm1::VrDemoButton14Click(TObject *Sender)
  1754. {
  1755.  
  1756. convertStr2Wchar("Scelta CODEC Audio");
  1757. int video = DBEdit3->Text.ToInt();
  1758. VitaminCtrl[video-1]->AutoAVISettings = false;
  1759. VitaminCtrl[video-1]->ChooseAVIAudioCompressor(destTmp);
  1760. }
  1761. //---------------------------------------------------------------------------
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767. void __fastcall TForm1::Button16Click(TObject *Sender)
  1768. {
  1769. deleteAllRecords();
  1770. }
  1771. //---------------------------------------------------------------------------
  1772.  
  1773.  
  1774.  
  1775. IplImage * TForm1::TBitmapToIplImage(Graphics::TBitmap * src)
  1776. {
  1777. CvRect re;
  1778. if (!src || src->Width==0) //src->Width==0 TBitmap should come from *.bmp , but not others such as *.jpg
  1779. {
  1780. saveError("Errore dimensione bitmap (NULL o width=0)");
  1781. return NULL;
  1782. }
  1783.  
  1784. if((dest = cvCreateImage(cvSize(src->Width,src->Height),IPL_DEPTH_8U,3)) == NULL) {
  1785. saveError("Errore cvCreateImage");
  1786. return NULL;
  1787. }
  1788.  
  1789. re.x = 0;
  1790. re.y = 0;
  1791. re.width = src->Width;
  1792. re.height = src->Height;
  1793.  
  1794. cvSetImageROI(dest, re);
  1795. try
  1796. {
  1797. unsigned char *pLine;
  1798. int x,y;
  1799.  
  1800. for(y=0 ;y<src->Height;y++)
  1801. {
  1802. pLine = (unsigned char *)src->ScanLine[y];
  1803. for(x=0 ;x <src->Width*3 ;x++)
  1804. {
  1805. dest->imageData[dest->widthStep*y+x]=pLine[x];
  1806. }
  1807. }
  1808. }
  1809. catch(...)
  1810. {
  1811. MessageBox(0,"Exception when get data ","Error", MB_OK );
  1812. }
  1813. return dest;
  1814. }
  1815.  
  1816. void __fastcall TForm1::VrDemoButton18Click(TObject *Sender)
  1817. {
  1818. int video = DBEdit3->Text.ToInt();
  1819. convertStr2Wchar("Scelta CODEC Avi");
  1820. VitaminCtrl[video-1]->ChooseAVIVideoCompressor(destTmp);
  1821.  
  1822. }
  1823. //---------------------------------------------------------------------------
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830. void TForm1::convertStr2Wchar(AnsiString src)
  1831. {
  1832. src.WideChar(destTmp, 256);
  1833. }
  1834.  
  1835. void __fastcall TForm1::Timer3Timer(TObject *Sender)
  1836. {
  1837. static int index = 0;
  1838. Timer3->Enabled = false;
  1839. if(AA(index)) {
  1840. if(IsTimeout(timeout[index], index+1)) {
  1841. VitaminCtrl[index]->StopAVIConversion();
  1842. VrUL[index]->Active = false;
  1843. vrLed[index]->Active = false;
  1844. *fsm[index] = 0;
  1845. CryptAVIHeader (record[index]);
  1846. AA(index) = false;
  1847. }
  1848. }
  1849. ++index;
  1850. if(index == 6)
  1851. index = 0;
  1852. Application->ProcessMessages();
  1853. Timer3->Enabled = true;
  1854.  
  1855. }
  1856. //---------------------------------------------------------------------------
  1857.  
  1858.  
  1859.  
  1860.  
  1861. void __fastcall TForm1::VitaminCtrl2ConnectionBroken(TObject *Sender,
  1862. EConnectionType eConnType)
  1863. {
  1864. VrLabel19->Visible = true;
  1865. VitaminCtrl2->Visible = false;
  1866. if(AA(1)) {
  1867. // PC
  1868. StopAVIRecord(1);
  1869. // -------------------
  1870. }
  1871.  
  1872. VitaminCtrl2->EventTypes = 0;
  1873. AA(1) = false;
  1874. A(1) = false;
  1875. saveError ("Disconnessione camera 2");
  1876. sconnessioni[1] += 1;
  1877. Edit4->Text = sconnessioni[1];
  1878. }
  1879. //---------------------------------------------------------------------------
  1880.  
  1881. void __fastcall TForm1::VitaminCtrl3ConnectionBroken(TObject *Sender,
  1882. EConnectionType eConnType)
  1883. {
  1884. VrLabel27->Visible = true;
  1885. VitaminCtrl3->Visible = false;
  1886.  
  1887. if(AA(2)) {
  1888. // PC
  1889. StopAVIRecord(2);
  1890. // -------------------
  1891. }
  1892. VitaminCtrl3->EventTypes = 0;
  1893. AA(2) = false;
  1894. A(2) = false;
  1895. saveError ("Disconnessione camera 3");
  1896. sconnessioni[2] += 1;
  1897. Edit5->Text = sconnessioni[2];
  1898. }
  1899. //---------------------------------------------------------------------------
  1900.  
  1901. void __fastcall TForm1::VitaminCtrl4ConnectionBroken(TObject *Sender,
  1902. EConnectionType eConnType)
  1903. {
  1904. VrLabel28->Visible = true;
  1905. VitaminCtrl4->Visible = false;
  1906.  
  1907. if(AA(3)) {
  1908. // PC
  1909. StopAVIRecord(3);
  1910. // -------------------
  1911. }
  1912. VitaminCtrl4->EventTypes = 0;
  1913. AA(3) = false;
  1914. A(3) = false;
  1915. saveError ("Disconnessione camera 4");
  1916. sconnessioni[3] += 1;
  1917. Edit6->Text = sconnessioni[3];
  1918. }
  1919. //---------------------------------------------------------------------------
  1920.  
  1921. void __fastcall TForm1::VitaminCtrl5ConnectionBroken(TObject *Sender,
  1922. EConnectionType eConnType)
  1923. {
  1924. VrLabel29->Visible = true;
  1925. VitaminCtrl5->Visible = false;
  1926.  
  1927. if(AA(4)) {
  1928. // PC
  1929. StopAVIRecord(4);
  1930. // -------------------
  1931. }
  1932. VitaminCtrl5->EventTypes = 0;
  1933. AA(4) = false;
  1934. A(4) = false;
  1935. saveError ("Disconnessione camera 5");
  1936. sconnessioni[4] += 1;
  1937. Edit7->Text = sconnessioni[4];
  1938. }
  1939. //---------------------------------------------------------------------------
  1940.  
  1941. void __fastcall TForm1::VitaminCtrl6ConnectionBroken(TObject *Sender,
  1942. EConnectionType eConnType)
  1943. {
  1944. VrLabel32->Visible = true;
  1945. VitaminCtrl6->Visible = false;
  1946.  
  1947. if(AA(5)) {
  1948. // PC
  1949. StopAVIRecord(5);
  1950. // -------------------
  1951. }
  1952. VitaminCtrl6->EventTypes = 0;
  1953. AA(5) = false;
  1954. A(5) = false;
  1955. saveError ("Disconnessione camera 6");
  1956. sconnessioni[5] += 1;
  1957. Edit8->Text = sconnessioni[5];
  1958. }
  1959. //---------------------------------------------------------------------------
  1960.  
  1961.  
  1962.  
  1963.  
  1964. void TForm1::saveError(AnsiString message)
  1965. {
  1966. TDateTime DateTime;
  1967. AnsiString dirTocreate;
  1968. int dacancellare;
  1969. int numRecord = DBISAMTable9->RecordCount;
  1970. if(numRecord > maxerrori) {
  1971. dacancellare = numRecord - maxerrori;
  1972. DBISAMTable9->First();
  1973. for(int i=0;i!=dacancellare;i++)
  1974. DBISAMTable9->Delete();
  1975. }
  1976. DBISAMTable9->Insert();
  1977. DateTime = Time();
  1978.  
  1979. DBISAMTable9->FieldByName("Data")->AsDateTime = DateToStr(Date());
  1980. DBISAMTable9->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
  1981. DBISAMTable9->FieldByName("Messaggio")->AsString = message;
  1982. DBISAMTable9->Post();
  1983. }
  1984.  
  1985. void __fastcall TForm1::VitaminCtrl2ConnectionOK(TObject *Sender,
  1986. EConnectionType eConnType)
  1987. {
  1988. VrLabel19->Visible = false;
  1989. VitaminCtrl2->Visible = true;
  1990.  
  1991. }
  1992. //---------------------------------------------------------------------------
  1993.  
  1994. void __fastcall TForm1::VitaminCtrl3ConnectionOK(TObject *Sender,
  1995. EConnectionType eConnType)
  1996. {
  1997. VrLabel27->Visible = false;
  1998. VitaminCtrl3->Visible = true;
  1999.  
  2000. }
  2001. //---------------------------------------------------------------------------
  2002.  
  2003. void __fastcall TForm1::VitaminCtrl4ConnectionOK(TObject *Sender,
  2004. EConnectionType eConnType)
  2005. {
  2006. VrLabel28->Visible = false;
  2007. VitaminCtrl4->Visible = true;
  2008.  
  2009. }
  2010. //---------------------------------------------------------------------------
  2011.  
  2012. void __fastcall TForm1::VitaminCtrl5ConnectionOK(TObject *Sender,
  2013. EConnectionType eConnType)
  2014. {
  2015. VrLabel29->Visible = false;
  2016. VitaminCtrl5->Visible = true;
  2017.  
  2018. }
  2019. //---------------------------------------------------------------------------
  2020.  
  2021. void __fastcall TForm1::VitaminCtrl6ConnectionOK(TObject *Sender,
  2022. EConnectionType eConnType)
  2023. {
  2024. VrLabel32->Visible = false;
  2025. VitaminCtrl6->Visible = true;
  2026.  
  2027. }
  2028. //---------------------------------------------------------------------------
  2029.  
  2030. //---------------------------------------------------------------------------
  2031.  
  2032. void __fastcall TForm1::DBCheckBox61Click(TObject *Sender)
  2033. {
  2034. DBEdit32->ReadOnly = !DBCheckBox61->Checked;
  2035. }
  2036. //---------------------------------------------------------------------------
  2037.  
  2038. void __fastcall TForm1::DBCheckBox59Click(TObject *Sender)
  2039. {
  2040. DBEdit28->ReadOnly = DBCheckBox59->Checked;
  2041. }
  2042. //---------------------------------------------------------------------------
  2043.  
  2044. void __fastcall TForm1::DBCheckBox53Click(TObject *Sender)
  2045. {
  2046. DBCheckBox59->ReadOnly = !DBCheckBox53->Checked;
  2047.  
  2048. DBEdit28->ReadOnly = DBCheckBox59->Checked;
  2049. }
  2050. //---------------------------------------------------------------------------
  2051.  
  2052. void __fastcall TForm1::VitaminCtrl1ConnectionBroken(TObject *Sender,
  2053. EConnectionType eConnType)
  2054. {
  2055. VrLabel44->Visible = true;
  2056. VitaminCtrl1->Visible = false;
  2057. if(AA(0)) {
  2058. // PC
  2059. StopAVIRecord(0);
  2060. // -------------------
  2061. /*
  2062. VitaminCtrl1->StopAVIConversion();
  2063. // PC
  2064. CryptAVIHeader (record[0]);
  2065. // ----------------------------
  2066. */
  2067. }
  2068.  
  2069. VitaminCtrl1->EventTypes = 0;
  2070. AA(0) = false;
  2071. A(0) = false;
  2072. saveError ("Disconnessione camera 1");
  2073. sconnessioni[0] += 1;
  2074. Edit2->Text = sconnessioni[0];
  2075. }
  2076. //---------------------------------------------------------------------------
  2077.  
  2078. void __fastcall TForm1::VitaminCtrl1ConnectionOK(TObject *Sender,
  2079. EConnectionType eConnType)
  2080. {
  2081. VrLabel44->Visible = false;
  2082. VitaminCtrl1->Visible = true;
  2083.  
  2084. }
  2085. //---------------------------------------------------------------------------
  2086.  
  2087.  
  2088. void TForm1::setCtrlConnection(bool flag)
  2089. {
  2090. if(flag) {
  2091. VitaminCtrl1->OnConnectionBroken = VitaminCtrl1ConnectionBroken;
  2092. VitaminCtrl1->OnConnectionOK = VitaminCtrl1ConnectionOK;
  2093.  
  2094. VitaminCtrl2->OnConnectionBroken = VitaminCtrl2ConnectionBroken;
  2095. VitaminCtrl2->OnConnectionOK = VitaminCtrl2ConnectionOK;
  2096.  
  2097. VitaminCtrl3->OnConnectionBroken = VitaminCtrl3ConnectionBroken;
  2098. VitaminCtrl3->OnConnectionOK = VitaminCtrl3ConnectionOK;
  2099.  
  2100. VitaminCtrl4->OnConnectionBroken = VitaminCtrl4ConnectionBroken;
  2101. VitaminCtrl4->OnConnectionOK = VitaminCtrl4ConnectionOK;
  2102.  
  2103. VitaminCtrl5->OnConnectionBroken = VitaminCtrl5ConnectionBroken;
  2104. VitaminCtrl5->OnConnectionOK = VitaminCtrl5ConnectionOK;
  2105.  
  2106. VitaminCtrl6->OnConnectionBroken = VitaminCtrl6ConnectionBroken;
  2107. VitaminCtrl6->OnConnectionOK = VitaminCtrl6ConnectionOK;
  2108.  
  2109. } else {
  2110. VitaminCtrl1->OnConnectionBroken = 0;
  2111. VitaminCtrl1->OnConnectionOK = 0;
  2112. VitaminCtrl2->OnConnectionBroken = 0;
  2113. VitaminCtrl2->OnConnectionOK = 0;
  2114. VitaminCtrl3->OnConnectionBroken = 0;
  2115. VitaminCtrl3->OnConnectionOK = 0;
  2116. VitaminCtrl4->OnConnectionBroken = 0;
  2117. VitaminCtrl4->OnConnectionOK = 0;
  2118. VitaminCtrl5->OnConnectionBroken = 0;
  2119. VitaminCtrl5->OnConnectionOK = 0;
  2120. VitaminCtrl6->OnConnectionBroken = 0;
  2121. VitaminCtrl6->OnConnectionOK = 0;
  2122.  
  2123. }
  2124. }
  2125. void __fastcall TForm1::DBCheckBox62Click(TObject *Sender)
  2126. {
  2127. setCtrlConnection(DBCheckBox62->Checked);
  2128. }
  2129. //---------------------------------------------------------------------------
  2130.  
  2131.  
  2132. void __fastcall TForm1::Button27Click(TObject *Sender)
  2133. {
  2134. static bool flag = false;
  2135. Panel2->Visible = flag;
  2136. Panel3->Visible = flag;
  2137. Panel4->Visible = flag;
  2138. Panel5->Visible = flag;
  2139. Panel6->Visible = flag;
  2140. Panel7->Visible = flag;
  2141. // PC
  2142. Panel19->Visible = flag;
  2143. // --------------------
  2144. if(flag)
  2145. Button27->Caption = "Interfaccia normale";
  2146. else
  2147. Button27->Caption = "Interfaccia semplificata";
  2148. flag = !flag;
  2149. }
  2150. //---------------------------------------------------------------------------
  2151.  
  2152.  
  2153.  
  2154. void TForm1::deleteAllRecords()
  2155. {
  2156. AnsiString buffer, filename;
  2157. TSearchRec sr;
  2158. int record;
  2159. int iAttributes = 0;
  2160. DBISAMTable1->First();
  2161. while(!DBISAMTable1->Eof) {
  2162. record = DBISAMTable1->FieldByName("Record")->AsInteger;
  2163. buffer = DBISAMTable1->FieldByName("Path")->AsString;
  2164. filename.printf("%s\\*.avi", buffer);
  2165. iAttributes |= faReadOnly;
  2166. iAttributes |= faHidden;
  2167. iAttributes |= faSysFile;
  2168. iAttributes |= faVolumeID;
  2169. iAttributes |= faDirectory;
  2170. iAttributes |= faArchive;
  2171. iAttributes |= faAnyFile;
  2172. if (FindFirst(filename, iAttributes, sr) == 0) {
  2173. SetCurrentDir(path);
  2174. filename.printf("%s\\%s",buffer, sr.Name);
  2175. DeleteFile(filename);
  2176. FindClose(sr);
  2177. if (DirectoryExists(buffer))
  2178. RemoveDir(buffer);
  2179.  
  2180. }
  2181. DBISAMTable1->Delete();
  2182.  
  2183. }
  2184. DBISAMTable1->FlushBuffers();
  2185. DBISAMTable1->Refresh();
  2186.  
  2187. DBISAMTable4->First();
  2188. while(!DBISAMTable4->Eof)
  2189. DBISAMTable4->Delete();
  2190. DBISAMTable4->FlushBuffers();
  2191. DBISAMTable4->Refresh();
  2192. }
  2193. void __fastcall TForm1::btnDisplayOnOffClick(TObject *Sender)
  2194. {
  2195. static bool flag = true;
  2196. for(int i=0;i!=6;i++)
  2197. if(A(i))
  2198. VitaminCtrl[i]->Display = flag;
  2199. // PC
  2200. if (flag)
  2201. btnDisplayOnOff->Caption = "Display ON";
  2202. else
  2203. btnDisplayOnOff->Caption = "Display OFF";
  2204. flag = !flag;
  2205. }
  2206. //---------------------------------------------------------------------------
  2207.  
  2208.  
  2209.  
  2210. void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
  2211. {
  2212. if(Key == '\r')
  2213. CppWebBrowser2->Navigate((TVariant)Edit1->Text.c_str());
  2214.  
  2215. }
  2216. //---------------------------------------------------------------------------
  2217.  
  2218.  
  2219. void __fastcall TForm1::btnAllOnOffClick(TObject *Sender)
  2220. {
  2221. // PC
  2222. static bool Status = true; // when program start system is ON
  2223. if (Status) {
  2224. setOFF();
  2225. btnAllOnOff->Caption = "Registrazioni ON";
  2226. }
  2227. else {
  2228. setON();
  2229. btnAllOnOff->Caption = "Registrazioni OFF";
  2230. }
  2231. Status = !Status;
  2232. // -------------------------------------------------
  2233. }
  2234. //---------------------------------------------------------------------------
  2235.  
  2236. void __fastcall TForm1::Button31Click(TObject *Sender)
  2237. {
  2238. CheckProgramPassword();
  2239. }
  2240. //---------------------------------------------------------------------------
  2241. // PC 2006-12-19
  2242. void __fastcall TForm1::CheckProgramPassword(void)
  2243. {
  2244. // check if password is administrator
  2245. if(Password->Text == DBEdit45->Text) {
  2246. EnableDisableProtectionForAdministrator (false);
  2247. lblUser->Caption = "Amministratore";
  2248. PageControl1->ActivePageIndex = 1; // Video Analisi
  2249. }
  2250. else if (Password->Text == dbeInstPassword->Text) {
  2251. EnableDisableProtectionForInstaller (false);
  2252. lblUser->Caption = "Installatore";
  2253. PageControl1->ActivePageIndex = 1; // Video Analisi
  2254. }
  2255. else
  2256. Beep();
  2257. Password->Text = "";
  2258. }
  2259. //---------------------------------------------------------------------------
  2260. // PC
  2261. void __fastcall TForm1::EnableDisableProtectionForInstaller(bool flag)
  2262. {
  2263.  
  2264. // Password->Visible = flag;
  2265. // Button31->Visible = flag; // Password Button
  2266. // GroupBox1->Visible = flag; // Groupbox della password
  2267.  
  2268. pnlInstall1->Visible = flag; // Setup UP
  2269. // pnlInstall2->Visible = flag; // Ricarica not more used
  2270. Panel13->Visible = flag; // Errori
  2271. Panel18->Visible = flag; // Browser
  2272. pnlPassword->Visible = flag;
  2273. Panel15->Visible = !flag; // Pannello per ESCI sulla prima TAB
  2274. Panel9->Visible = flag;
  2275. }
  2276. // ----------------------------------------------------------
  2277. //---------------------------------------------------------------------------
  2278. // PC
  2279. void __fastcall TForm1::EnableDisableProtectionForAdministrator(bool flag)
  2280. {
  2281. // PC
  2282. EnableDisableProtectionForInstaller (flag);
  2283. // ------------------------------
  2284.  
  2285. pnlAdmin->Visible = flag; // Setup DOWN
  2286. // Registrazioni
  2287. Panel11->Visible = flag; // Pannello centrale Tab Video Analisi
  2288. Panel12->Visible = flag; // Orari
  2289. Panel17->Visible = flag; // Panoramiche
  2290. Panel9->Visible = flag; // Panoramiche
  2291. Panel16->Visible = flag;
  2292.  
  2293. }
  2294. //---------------------------------------------------------------------------
  2295. // PC
  2296. void __fastcall TForm1::EnableDisableProtectionPanelsinAnalisiTab(bool flag)
  2297. {
  2298. Panel2->Visible = flag;
  2299. Panel3->Visible = flag;
  2300. Panel4->Visible = flag;
  2301. Panel5->Visible = flag;
  2302. Panel6->Visible = flag;
  2303. Panel7->Visible = flag;
  2304. // PC
  2305. Panel19->Visible = flag;
  2306. }
  2307. //---------------------------------------------------------------------------
  2308. void __fastcall TForm1::btnLogoutClick(TObject *Sender)
  2309. {
  2310. // PC 2007-01-15
  2311. //--------------------------
  2312. if (DBISAMTable5->FieldByName("Password")->AsString != "") {
  2313. Password->Text = "";
  2314.  
  2315. EnableDisableProtectionForAdministrator (true);
  2316. EnableDisableProtectionPanelsinAnalisiTab (true);
  2317.  
  2318. /*
  2319. GroupBox1->Visible = true;
  2320. Password->Visible = true;
  2321. Button31->Visible = true;
  2322. Panel16->Visible = true;
  2323. Panel8->Visible = true;
  2324. Panel9->Visible = true;
  2325. Panel13->Visible = true;
  2326. Panel18->Visible = true;
  2327.  
  2328.  
  2329. Panel10->Visible = true;
  2330. Panel11->Visible = true;
  2331. Panel12->Visible = true;
  2332. Panel15->Visible = true;
  2333. Panel17->Visible = true;
  2334.  
  2335.  
  2336.  
  2337.  
  2338. Panel2->Visible = true;
  2339. Panel3->Visible = true;
  2340. Panel4->Visible = true;
  2341. Panel5->Visible = true;
  2342. Panel6->Visible = true;
  2343. Panel7->Visible = true;
  2344. // PC
  2345. Panel19->Visible = true;
  2346. // ----------------------
  2347.  
  2348. // Image3->Visible = true;
  2349. */
  2350.  
  2351. }
  2352.  
  2353. }
  2354. //---------------------------------------------------------------------------
  2355.  
  2356.  
  2357.  
  2358.  
  2359. void __fastcall TForm1::CheckBox2Click(TObject *Sender)
  2360. {
  2361. // PC 2006-14-12
  2362. // Aggiunto il !
  2363. // All'interno del click la proprieta' checked non e' ancora settata
  2364. Panel16->Visible = !CheckBox2->Checked;
  2365. //--------------------------------------
  2366. }
  2367. //---------------------------------------------------------------------------
  2368. // PC
  2369. //
  2370. // legge il file config.ini e cerca l'entry 'DBDirectory nella section 'Options'
  2371. // Se la trova ne restituisce il contenuto (il path del db) altrimenti restituisce
  2372. // la directory dell'applicazione
  2373. // Il path restituito comprende il '\' finale
  2374. //
  2375. AnsiString __fastcall TForm1::ReadDBPathFromINI (void)
  2376. {
  2377. AnsiString OutString;
  2378. TIniFile *ConfigurationFile = new TIniFile(ChangeFileExt(Application->ExeName, ".ini"));
  2379.  
  2380. try {
  2381. OutString = ConfigurationFile->ReadString("Options","DBDirectory",".\\Database");
  2382. Activation = ConfigurationFile->ReadString("Register","Activation","ADFSFAAF");
  2383. Registrato = ConfigurationFile->ReadString("Register","Registrato", "Nessuna registrazione");
  2384. }
  2385. __finally {
  2386. delete ConfigurationFile;
  2387. return OutString;
  2388. }
  2389. }
  2390. // -----------------------------------------------------------------------------
  2391. // PC
  2392. //
  2393. void __fastcall TForm1::CryptAVIHeader (int record)
  2394. {
  2395. int ret,video;
  2396. bool Bret;
  2397. AnsiString filename;
  2398. MainAVIHeader CrapHeader, AVIHeader;
  2399. unsigned char *buffer = NULL;
  2400. TVarRec SearchValue;
  2401.  
  2402.  
  2403. try {
  2404. buffer = (unsigned char *) malloc(DBISAMTable1->FieldByName("AVIHead_b")->Size);
  2405. memset (&CrapHeader, 0, sizeof(MainAVIHeader));
  2406.  
  2407. // search record with file to crypt
  2408. // search in db record number
  2409. SearchValue=(record);
  2410. Bret = DBISAMTable1->FindKey(&SearchValue,0);
  2411. if (!Bret) {
  2412. saveError ("CryptAVIHeader - FindKey - Key (Record) : "+IntToStr(record));
  2413. return;
  2414. }
  2415. video = DBISAMTable1->FieldByName("Video")->AsInteger;
  2416. getAviname(filename, video);
  2417.  
  2418. ret = ReadAVIHeader (filename, &AVIHeader);
  2419. if (ret < 0) {
  2420. saveError ("CryptAVIHeader - ReadAVIHeader - Error : "+IntToStr(ret));
  2421. return;
  2422. }
  2423.  
  2424. try {
  2425. // copy AVIHeader into table
  2426. DBISAMTable1->Edit();
  2427. memcpy (buffer, &AVIHeader, sizeof(MainAVIHeader));
  2428. DBISAMTable1->FieldByName("AVIHead_b")->SetData(buffer, true);
  2429. DBISAMTable1->FieldByName("Playable")->AsBoolean = true;
  2430. DBISAMTable1->Post();
  2431. }
  2432. catch (Exception &E) {
  2433. saveError ("Exception in CryptAVIHeader : " + E.Message);
  2434. return;
  2435. }
  2436.  
  2437. // now that AVIHeader is in db, i crap AVI file
  2438. ret = WriteAVIHeader (filename, &CrapHeader);
  2439. if (ret < 0) {
  2440. saveError ("CryptAVIHeader - WriteAVIHeader - Error : "+IntToStr(ret));
  2441. return;
  2442. }
  2443. }
  2444. __finally {
  2445. if (buffer)
  2446. free (buffer);
  2447. }
  2448. }
  2449. // -----------------------------------------------------------------------------
  2450. // -----------------------------------------------------------------------------
  2451. // PC 2006-14-12
  2452. //
  2453. void __fastcall TForm1::DeleteOldestVideo (void)
  2454. {
  2455.  
  2456. AnsiString FileName, DirectoryPath;
  2457. int RecordField = -1;
  2458. long numsec, realtime, elapsed;
  2459. time_t DateTime;
  2460.  
  2461.  
  2462. try {
  2463. if (DBISAMTable1->RecordCount <= 0)
  2464. return;
  2465.  
  2466. // realtime = DBISAMTable1->FieldByName("Time")->AsInteger;
  2467. // elapsed = (long) difftime(DateTime, realtime);
  2468. // if(elapsed >= numsec) {
  2469.  
  2470.  
  2471. // PC 2006-14-12
  2472. //
  2473. // only for debug
  2474. numsec = deleteafter * 3600; // original per il calcolo in ore
  2475. //numsec = deleteafter * 60;
  2476. //-----------------------
  2477.  
  2478. DateTime = time(NULL); // store the current date and time
  2479. /*
  2480. // query the record to delete
  2481. qry2->Active = false;
  2482. qry2->SQL->Clear();
  2483. qry2->SQL->Add("SELECT * FROM Records Where " + IntToStr(numsec) + " < " + IntToStr(DateTime) + " - Records.Time ");
  2484. qry2->ExecSQL();
  2485. */
  2486. try {
  2487. tblRecordToDelete->Filtered = false;
  2488. tblRecordToDelete->Filter = IntToStr(numsec) + " < " + IntToStr(DateTime) + " - Time ";
  2489. tblRecordToDelete->Filtered = true;
  2490. tblRecordToDelete->Active = true;
  2491.  
  2492. if (tblRecordToDelete->RecordCount > 0) {
  2493.  
  2494. tblRecordToDelete->Refresh();
  2495. tblRecordToDelete->First();
  2496. while (!tblRecordToDelete->Eof) {
  2497. RecordField = tblRecordToDelete->FieldByName("Record")->AsInteger;
  2498. if (!(tblRecordToDelete->FieldByName("Playable")->AsBoolean) ||
  2499. tblRecordToDelete->FieldByName("Locked")->AsBoolean) { // is record not yet finished or locked?
  2500. // saveError ("Cancellazione non effettuata - record in uso : " + IntToStr(RecordField));
  2501. }
  2502. else {
  2503. DirectoryPath = tblRecordToDelete->FieldByName("Path")->AsString;
  2504. DeleteVideoRecord (RecordField, DirectoryPath);
  2505. }
  2506. // i do a refresh so I can update eventually Locked flags setted by SFPlayer
  2507. tblRecordToDelete->Refresh();
  2508. tblRecordToDelete->Next();
  2509. }
  2510. }
  2511.  
  2512. // Delete Panoramiche, if Any
  2513. DeletePanoramiche(numsec, DateTime);
  2514. }
  2515. __finally {
  2516. tblRecordToDelete->Active = false;
  2517. tblRecordToDelete->Filtered = false;
  2518. }
  2519.  
  2520. /*
  2521. if (qry2->RecordCount > 0) {
  2522. qry2->First();
  2523. while (!qry2->Eof) {
  2524. RecordField = qry2->FieldByName("Record")->AsInteger;
  2525. if (!(qry2->FieldByName("Playable")->AsBoolean)) { // is record not yet finished?
  2526. saveError ("Cancellazione non effettuata - record in uso : " + IntToStr(RecordField));
  2527. }
  2528. else {
  2529. DirectoryPath = qry2->FieldByName("Path")->AsString;
  2530. DeleteVideoRecord (RecordField, DirectoryPath);
  2531. }
  2532. qry2->Next();
  2533. }
  2534. }
  2535. */
  2536. }
  2537. catch (Exception &E) {
  2538. saveError ("Exception in DeleteOldestVideo : Record(Records) = "+IntToStr(RecordField));
  2539. }
  2540.  
  2541. }
  2542. //---------------------------------------------------------------------------
  2543. // PC 2007-01-10
  2544. //
  2545. void __fastcall TForm1::DeleteVideoRecord(int RecordNumber, AnsiString DirectoryPath)
  2546. {
  2547.  
  2548. try {
  2549.  
  2550. // delete current record in Records Table
  2551. tblRecordToDelete->Delete();
  2552.  
  2553. // Delete all FaceFrame with the same 'Record'
  2554. qry->Active = false;
  2555. qry->SQL->Clear();
  2556. qry->SQL->Add("DELETE FROM FaceFrame Where FaceFrame.Record = " +IntToStr(RecordNumber));
  2557. qry->ExecSQL();
  2558. DBISAMTable2->FlushBuffers();
  2559.  
  2560. /*
  2561. qry->Active = false;
  2562. qry->SQL->Clear();
  2563. qry->SQL->Add("DELETE FROM Records Where Records.Record = " +IntToStr(RecordNumber));
  2564. qry->ExecSQL();
  2565. DBISAMTable1->FlushBuffers();
  2566. */
  2567.  
  2568. if (DirectoryExists(DirectoryPath))
  2569. DeleteDirectory (DirectoryPath);
  2570. else
  2571. saveError("DeleteVideoRecord - Errore cancellazione directory " + DirectoryPath);
  2572.  
  2573. }
  2574. catch (Exception &E) {
  2575. saveError ("Exception in DeleteVideoRecord : Record(Records) = "+IntToStr(RecordNumber));
  2576. }
  2577.  
  2578. }
  2579. //---------------------------------------------------------------------------
  2580. // PC 2006-14-12
  2581. //
  2582. void __fastcall TForm1::DeleteDirectory(AnsiString DirectoryPath)
  2583. {
  2584. /*
  2585.  
  2586. // now this is not working
  2587. //
  2588. SHFILEOPSTRUCT FileOperation;
  2589. char FilePath[1024];
  2590. int ret;
  2591. bool bret;
  2592.  
  2593. FileOperation.hwnd = Application->Handle;
  2594. FileOperation.wFunc = FO_DELETE;
  2595. strcpy(FilePath, AnsiString(DirectoryPath + "\\*.avi").c_str());
  2596. FileOperation.pFrom = FilePath;
  2597. FileOperation.pTo = 0;
  2598. FileOperation.fFlags = FOF_NOCONFIRMATION |
  2599. FOF_SILENT;
  2600.  
  2601. ret = SHFileOperation(&FileOperation);
  2602. if (ret > 0) {
  2603. saveError ("SHFileOperation error - " + IntToStr(ret));
  2604. return;
  2605. }
  2606. ret = RemoveDir(DirectoryPath);
  2607. */
  2608. //------------------------------------------------
  2609.  
  2610. TSearchRec sr;
  2611. AnsiString filename;
  2612. int iAttributes = 0;
  2613. bool BRet;
  2614.  
  2615. filename.printf("%s\\*.avi", DirectoryPath);
  2616. iAttributes |= faReadOnly;
  2617. iAttributes |= faHidden;
  2618. iAttributes |= faSysFile;
  2619. iAttributes |= faVolumeID;
  2620. iAttributes |= faDirectory;
  2621. iAttributes |= faArchive;
  2622. iAttributes |= faAnyFile;
  2623. if (FindFirst(filename, iAttributes, sr) == 0) {
  2624. // SetCurrentDir(path);
  2625. filename.printf("%s\\%s",DirectoryPath, sr.Name);
  2626. DeleteFile(filename);
  2627. FindClose(sr);
  2628. if (DirectoryExists(DirectoryPath)) {
  2629. BRet = RemoveDir(DirectoryPath);
  2630. if (!BRet)
  2631. saveError ("Cancellazione - Errore cancellazione directory " + DirectoryPath);
  2632. }
  2633.  
  2634. }
  2635. else
  2636. saveError ("Cancellazione - File non trovati in " + DirectoryPath);
  2637.  
  2638. }
  2639. // -----------------------------------------------------------------------------
  2640.  
  2641. void __fastcall TForm1::tmrDeleteTimer(TObject *Sender)
  2642. {
  2643. //---------------------------------------------------------------------------
  2644. // PC 2006-12-15
  2645. //
  2646. // esegue la cancellazione dei record vecchi
  2647.  
  2648. tmrDelete->Enabled = false;
  2649. DeleteOldestVideo ();
  2650. tmrDelete->Enabled = true;
  2651. }
  2652. //---------------------------------------------------------------------------
  2653. //---------------------------------------------------------------------------
  2654. // PC 2006-12-18
  2655. //
  2656. void __fastcall TForm1::RepairTables(void)
  2657. {
  2658. TDate Today;
  2659.  
  2660. try {
  2661. // Repair
  2662. if (DBISAMTable1->VerifyTable())
  2663. DBISAMTable1->RepairTable (false);
  2664. if (DBISAMTable2->VerifyTable())
  2665. DBISAMTable2->RepairTable (false);
  2666. if (DBISAMTable3->VerifyTable())
  2667. DBISAMTable3->RepairTable (false);
  2668. if (DBISAMTable4->VerifyTable())
  2669. DBISAMTable4->RepairTable (false);
  2670. if (DBISAMTable5->VerifyTable())
  2671. DBISAMTable5->RepairTable (false);
  2672. if (DBISAMTable6->VerifyTable())
  2673. DBISAMTable6->RepairTable (false);
  2674. if (DBISAMTable7->VerifyTable())
  2675. DBISAMTable7->RepairTable (false);
  2676. if (DBISAMTable8->VerifyTable())
  2677. DBISAMTable8->RepairTable (false);
  2678. if (DBISAMTable9->VerifyTable())
  2679. DBISAMTable9->RepairTable (false);
  2680. if (DBISAMTable10->VerifyTable())
  2681. DBISAMTable10->RepairTable (false);
  2682.  
  2683.  
  2684. if (NecessaryToOptimize()) {
  2685. // Optimize
  2686. DBISAMTable1->OptimizeTable ("",false);
  2687. DBISAMTable2->OptimizeTable ("",false);
  2688. DBISAMTable3->OptimizeTable ("",false);
  2689. DBISAMTable4->OptimizeTable ("",false);
  2690. DBISAMTable5->OptimizeTable ("",false);
  2691. DBISAMTable6->OptimizeTable ("",false);
  2692. DBISAMTable7->OptimizeTable ("",false);
  2693. DBISAMTable8->OptimizeTable ("",false);
  2694. DBISAMTable9->OptimizeTable ("",false);
  2695. DBISAMTable10->OptimizeTable ("",false);
  2696. }
  2697.  
  2698. }
  2699. /*
  2700. catch (const Exception &E) {
  2701. if (dynamic_cast<EDatabaseError *>(E) & dynamic_cast<EDBISAMEngineError *>(E))
  2702. if (dynamic_cast<EDBISAMEngineError &>(*E)->ErrorCode == DBISAM_OSEACCES)
  2703. Application->MessageBox("DBISAM_OSEACCES", "Error", MB_OK);
  2704. }
  2705. */
  2706.  
  2707. catch (const EDBISAMEngineError &E) {
  2708. if (E.ErrorCode != DBISAM_OSEACCES) {
  2709. DBISAMTable9->Active = true;
  2710. saveError ("Exception in RepairTables : "+E.Message);
  2711. DBISAMTable9->Active = false;
  2712. }
  2713. }
  2714.  
  2715. }
  2716. //---------------------------------------------------------------------------
  2717.  
  2718. //---------------------------------------------------------------------------
  2719.  
  2720.  
  2721.  
  2722. void __fastcall TForm1::btnSelectPathClick(TObject *Sender)
  2723. {
  2724.  
  2725. // select path directory
  2726. AnsiString Dir = "";
  2727. // if (SelectDirectory(Dir, TSelectDirOpts() << sdAllowCreate << sdPerformCreate << sdPrompt,SELDIRHELP))
  2728. if (SelectDirectory("Selezione directory", "", Dir))
  2729. DBEdit19->Text = Dir;
  2730. }
  2731. //---------------------------------------------------------------------------
  2732.  
  2733. void __fastcall TForm1::DBNavigator4BeforeAction(TObject *Sender,
  2734. TNavigateBtn Button)
  2735. {
  2736. if (Button == nbEdit)
  2737. // enable Button "..." to select directory
  2738. btnSelectPath->Enabled = true;
  2739. else
  2740. btnSelectPath->Enabled = false;
  2741.  
  2742. }
  2743. //---------------------------------------------------------------------------
  2744. // PC
  2745. bool __fastcall TForm1::IsAnyVideoActive (void)
  2746. {
  2747. for (int i=0; i<NUM_MAX_TELECAMERE; i++) {
  2748. if (VitaminCtrl[i]->ControlStatus == 1 ||
  2749. VitaminCtrl[i]->ControlStatus == 2) // is Connecting or Running
  2750. return true;
  2751. }
  2752. return false;
  2753. }
  2754. // --------------------------------------------------------------------------
  2755. // PC
  2756. void __fastcall TForm1::TakeSnapshotDiProva(int video)
  2757. {
  2758. AnsiString fName;
  2759. time_t first;
  2760. TDateTime DateTime;
  2761.  
  2762. fName.printf("%s\\video%02d.jpg", path, video);
  2763.  
  2764. if(FileExists(fName))
  2765. DeleteFile(fName);
  2766. convertStr2Wchar(fName);
  2767. VitaminCtrl[video]->SaveSnapshot(Vitamindecoderlib_tlb::ePicFmtJpeg, destTmp);
  2768. tblPanoramicheVisual->Insert();
  2769. ImageEnIO7->LoadFromFile(fName);
  2770. iEnDBPanoramicaView->Update();
  2771. first = time(NULL);
  2772. DateTime = Time(); // store the current date and time
  2773. tblPanoramicheVisual->FieldByName("Data")->AsDateTime = DateToStr(Date());
  2774. tblPanoramicheVisual->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
  2775. tblPanoramicheVisual->FieldByName("Video")->AsInteger = video;
  2776. tblPanoramicheVisual->Post();
  2777.  
  2778. }
  2779.  
  2780.  
  2781. // --------------------------------------------------------------------------
  2782. // PC
  2783. void __fastcall TForm1::PageControl1Change(TObject *Sender)
  2784. {
  2785. int ret;
  2786. // here I disable all camera if Tab is Setup
  2787. if (PageControl1->ActivePageIndex == 2) { // SETUP Page
  2788. // enable all navigator
  2789. DBNavigator1->Enabled = true;
  2790. DBNavigator2->Enabled = true;
  2791. DBNavigator4->Enabled = true;
  2792. if (IsAnyVideoActive ()) {
  2793. ret = Application->MessageBox ("Per editare la pagina di Setup e' necessario disabilitare le videocamere. Vuoi farlo ora?", "Messaggio", MB_YESNO);
  2794. if (ret == IDYES) {
  2795. setOFF();
  2796. }
  2797. else {
  2798. // disable all navigator
  2799. DBNavigator1->Enabled = false;
  2800. DBNavigator2->Enabled = false;
  2801. DBNavigator4->Enabled = false;
  2802. }
  2803. }
  2804. }
  2805.  
  2806. }
  2807. //---------------------------------------------------------------------------
  2808. // PC
  2809. void __fastcall TForm1::StopAVIRecord (int i)
  2810. {
  2811. switch (i) {
  2812. case 0 :
  2813. VitaminCtrl1->StopAVIConversion();
  2814. VrProgressBar1->Position = 0;
  2815. VrUserLed3->Active = false;
  2816. VrLed1->Active = false;
  2817. // PC
  2818. CryptAVIHeader (record[0]);
  2819. // ----------------------------
  2820. break;
  2821. case 1 :
  2822. VitaminCtrl2->StopAVIConversion();
  2823. VrProgressBar2->Position = 0;
  2824. VrUserLed1->Active = false;
  2825. VrLed2->Active = false;
  2826. // PC
  2827. CryptAVIHeader (record[1]);
  2828. // ----------------------------
  2829. break;
  2830. case 2 :
  2831. VitaminCtrl3->StopAVIConversion();
  2832. VrProgressBar3->Position = 0;
  2833. VrUserLed2->Active = false;
  2834. VrLed3->Active = false;
  2835. // PC
  2836. CryptAVIHeader (record[2]);
  2837. // ----------------------------
  2838. break;
  2839. case 3 :
  2840. VitaminCtrl4->StopAVIConversion();
  2841. VrProgressBar4->Position = 0;
  2842. VrUserLed4->Active = false;
  2843. VrLed4->Active = false;
  2844. // PC
  2845. CryptAVIHeader (record[3]);
  2846. // ----------------------------
  2847. break;
  2848. case 4 :
  2849. VitaminCtrl5->StopAVIConversion();
  2850. VrProgressBar5->Position = 0;
  2851. VrUserLed5->Active = false;
  2852. VrLed5->Active = false;
  2853. // PC
  2854. CryptAVIHeader (record[4]);
  2855. // ----------------------------
  2856. break;
  2857. case 5 :
  2858. VitaminCtrl6->StopAVIConversion();
  2859. // VrProgressBar6->Position = 0;
  2860. // PC
  2861. VrProgressBar7->Position = 0;
  2862. // -----------------------------
  2863. VrUserLed6->Active = false;
  2864. // PC 2007-02-01
  2865. // VrLed6->Active = false;
  2866. VrLed7->Active = false;
  2867. // -------------------------
  2868. // PC
  2869. CryptAVIHeader (record[5]);
  2870. // ----------------------------
  2871. break;
  2872. }
  2873. }
  2874. //---------------------------------------------------------------------------
  2875. void __fastcall TForm1::btnSalvaPanoramicaClick(TObject *Sender)
  2876. {
  2877. iEnIOPanoramicaView->Params->JPEG_Quality = 90;
  2878. // save image to file
  2879. if (SaveImageEnDialog1->Execute())
  2880. iEnIOPanoramicaView->SaveToFile(SaveImageEnDialog1->FileName);
  2881.  
  2882. }
  2883. //---------------------------------------------------------------------------
  2884.  
  2885. void __fastcall TForm1::DeletePanoramiche(long numsec, time_t DateTime)
  2886. {
  2887. try {
  2888.  
  2889. if (DBISAMTable8->RecordCount == 0)
  2890. return;
  2891. // query the record to delete
  2892. qry->Active = false;
  2893. qry->SQL->Clear();
  2894. qry->SQL->Add("DELETE FROM Panoramica Where " + IntToStr(numsec) + " < " + IntToStr(DateTime) + " - Time ");
  2895. qry->ExecSQL();
  2896. // for debug - saveError ("DeletePanoramiche - Eseguito SQL");
  2897. tblPanoramicheVisual->Refresh();
  2898.  
  2899. }
  2900. catch (const EDBISAMEngineError &E) {
  2901. saveError ("Exception in DeletePanoramiche : " + E.Message);
  2902. }
  2903.  
  2904. }
  2905.  
  2906.  
  2907. //---------------------------------------------------------------------------
  2908. void __fastcall TForm1::iEnDBPanoramicaViewDblClick(TObject *Sender)
  2909. {
  2910. btnSalvaPanoramicaClick (this);
  2911. }
  2912. //---------------------------------------------------------------------------
  2913.  
  2914. void __fastcall TForm1::DBISAMTable8AfterPost(TDataSet *DataSet)
  2915. {
  2916. tblPanoramicheVisual->Refresh();
  2917. }
  2918. //---------------------------------------------------------------------------
  2919. // PC
  2920. // this function see if is necessary to optimize. If yes return true, if no false.
  2921. // This function also ask confirmaton to
  2922. bool __fastcall TForm1::NecessaryToOptimize(void)
  2923. {
  2924. TDate Today, LastOptimizeDate;
  2925. bool BRet = false;
  2926. int Ret;
  2927. int DateDiff;
  2928.  
  2929. try {
  2930. try {
  2931. Today = Date();
  2932. DBISAMTable5->Active = true; // 'Generale Table'
  2933. LastOptimizeDate = DBISAMTable5->FieldByName("LastOptimize")->AsDateTime;
  2934. DateDiff = Today - LastOptimizeDate;
  2935. if (DateDiff > MAX_DAYS_BEFORE_OPTIMIZE) {
  2936. // Ask if we do optimize
  2937. Ret = Application->MessageBox("Sono passati piu' di 30 giorni dal''ottimizzazione delle tabelle.\nQuesta operazione potrebbe richiedere qualche minuto.\nVuoi farlo ora?","Messaggio",MB_YESNO);
  2938. if (Ret == IDYES) {
  2939. DBISAMTable5->Edit();
  2940. DBISAMTable5->FieldByName("LastOptimize")->AsDateTime = Today;
  2941. DBISAMTable5->Post();
  2942. BRet = true;
  2943. }
  2944. else
  2945. BRet = false;
  2946. }
  2947. else
  2948. BRet = false;
  2949. }
  2950. catch (const EDBISAMEngineError &E) {
  2951. saveError ("Exception in NecessaryToOptimize : " + E.Message);
  2952. }
  2953. }
  2954. __finally {
  2955. DBISAMTable5->Active = false;
  2956. return BRet;
  2957. }
  2958. }
  2959. //---------------------------------------------------------------------------
  2960.  
  2961. void __fastcall TForm1::DBISAMTable3AfterPost(TDataSet *DataSet)
  2962. {
  2963. loadSetup();
  2964. }
  2965. //---------------------------------------------------------------------------
  2966.  
  2967. void __fastcall TForm1::DBISAMTable5AfterPost(TDataSet *DataSet)
  2968. {
  2969. loadSetup();
  2970. }
  2971. //---------------------------------------------------------------------------
  2972. void __fastcall TForm1::SendMonitorPacket(void)
  2973. {
  2974. // Packet
  2975. // Header
  2976. // Num of Active Cameras (in autorun) (4 bytes)
  2977. // Num of Connected cameras (4 bytes)
  2978. int i;
  2979.  
  2980. int Pos = SF_PACKET_HEADER_LEN;
  2981. int TempInt;
  2982. // prepare message
  2983. // count active cameras
  2984. TempInt = 0;
  2985. for (i=0; i<NUM_MAX_TELECAMERE; i++) {
  2986. if (videoactive[i])
  2987. TempInt++;
  2988. }
  2989. memcpy(SFPacketToSend+Pos, &TempInt, sizeof(int));
  2990. Pos += sizeof(int);
  2991.  
  2992. // count connected cameras
  2993. TempInt = 0;
  2994. for (i=0; i<NUM_MAX_TELECAMERE; i++) {
  2995. if (VitaminCtrl[i]->ControlStatus == 1 ||
  2996. VitaminCtrl[i]->ControlStatus == 2)
  2997. TempInt++;
  2998. }
  2999. memcpy(SFPacketToSend+Pos, &TempInt, sizeof(int));
  3000. Pos += sizeof(int);
  3001. SFPacketToSend[Pos] = CalculateCRC (SFPacketToSend, SF_FULL_PACKET_LEN -1);
  3002.  
  3003.  
  3004. // send packet
  3005. NMUDPMonitor->SendBuffer (SFPacketToSend, SF_FULL_PACKET_LEN, SF_FULL_PACKET_LEN);
  3006.  
  3007. }
  3008. //---------------------------------------------------------------------------
  3009. void __fastcall TForm1::tmrMonitorMessageTimer(TObject *Sender)
  3010. {
  3011. SendMonitorPacket();
  3012. }
  3013. //---------------------------------------------------------------------------
  3014.  
  3015. void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
  3016. {
  3017. setOFF();
  3018. }
  3019. //---------------------------------------------------------------------------
  3020.  
  3021. void __fastcall TForm1::VitaminCtrl1MDAlert(TObject *Sender,
  3022. Variant *vPiece)
  3023. {
  3024. if(!A(0))
  3025. return;
  3026.  
  3027. switch(fsm1) {
  3028. case 0:
  3029. motion[0] = true;
  3030. createAviRecord(1);
  3031. records[0] += 1;
  3032. VrNum1->Value = records[0];
  3033. VitaminCtrl1->StartAVIConversion();
  3034. VrUserLed3->Active = true;
  3035. VrLed1->Active = true;
  3036. fsm1 = 1;
  3037. AA(0) = true;
  3038. timeout[0] = SetTimeout(MotionTimeout[0], 1);
  3039. break;
  3040. case 1:
  3041. motion[0] = true;
  3042. timeout[0] = SetTimeout(MotionTimeout[0], 1);
  3043. break;
  3044. }
  3045.  
  3046. }
  3047. //---------------------------------------------------------------------------
  3048.  
  3049. void __fastcall TForm1::VitaminCtrl2MDAlert(TObject *Sender,
  3050. Variant *vPiece)
  3051. {
  3052. IplImage *image;
  3053. if(!A(1))
  3054. return;
  3055.  
  3056. switch(fsm2) {
  3057. case 0:
  3058. motion[1] = true;
  3059. createAviRecord(2);
  3060. records[1] += 1;
  3061. VrNum2->Value = records[1];
  3062. VitaminCtrl2->StartAVIConversion();
  3063. VrUserLed1->Active = true;
  3064. VrLed2->Active = true;
  3065. fsm2 = 1;
  3066. AA(1) = true;
  3067. timeout[1] = SetTimeout(MotionTimeout[1], 2);
  3068. break;
  3069. case 1:
  3070. motion[1] = true;
  3071. timeout[1] = SetTimeout(MotionTimeout[1], 2);
  3072. break;
  3073. }
  3074.  
  3075. }
  3076. //---------------------------------------------------------------------------
  3077.  
  3078. void __fastcall TForm1::VitaminCtrl3MDAlert(TObject *Sender,
  3079. Variant *vPiece)
  3080. {
  3081. IplImage *image;
  3082. if(!A(2))
  3083. return;
  3084.  
  3085. switch(fsm3) {
  3086. case 0:
  3087. motion[2] = true;
  3088. createAviRecord(3);
  3089. records[2] += 1;
  3090. VrNum3->Value = records[2];
  3091.  
  3092. VitaminCtrl3->StartAVIConversion();
  3093. VrUserLed2->Active = true;
  3094. VrLed3->Active = true;
  3095. fsm3 = 1;
  3096. AA(2) = true;
  3097. timeout[2] = SetTimeout(MotionTimeout[2], 3);
  3098. break;
  3099. case 1:
  3100. motion[2] = true;
  3101. timeout[2] = SetTimeout(MotionTimeout[2], 3);
  3102. break;
  3103. }
  3104.  
  3105.  
  3106. }
  3107. //---------------------------------------------------------------------------
  3108.  
  3109. void __fastcall TForm1::VitaminCtrl4MDAlert(TObject *Sender,
  3110. Variant *vPiece)
  3111. {
  3112. IplImage *image;
  3113. if(!A(3))
  3114. return;
  3115. switch(fsm4) {
  3116. case 0:
  3117. motion[3] = true;
  3118. createAviRecord(4);
  3119. records[3] += 1;
  3120. VrNum4->Value = records[3];
  3121.  
  3122. VitaminCtrl4->StartAVIConversion();
  3123. VrUserLed4->Active = true;
  3124. VrLed4->Active = true;
  3125. fsm4 = 1;
  3126. AA(3) = true;
  3127. timeout[3] = SetTimeout(MotionTimeout[3], 4);
  3128. break;
  3129. case 1:
  3130. motion[3] = true;
  3131. timeout[3] = SetTimeout(MotionTimeout[3], 4);
  3132. break;
  3133. }
  3134.  
  3135. }
  3136. //---------------------------------------------------------------------------
  3137.  
  3138. void __fastcall TForm1::VitaminCtrl5MDAlert(TObject *Sender,
  3139. Variant *vPiece)
  3140. {
  3141. IplImage *image;
  3142. if(!A(4))
  3143. return;
  3144. switch(fsm5) {
  3145. case 0:
  3146. motion[4] = true;
  3147. createAviRecord(5);
  3148. records[4] += 1;
  3149. VrNum5->Value = records[4];
  3150.  
  3151. VitaminCtrl5->StartAVIConversion();
  3152. VrUserLed5->Active = true;
  3153. VrLed5->Active = true;
  3154. fsm5 = 1;
  3155. AA(4) = true;
  3156. timeout[4] = SetTimeout(MotionTimeout[4], 5);
  3157. break;
  3158. case 1:
  3159. motion[4] = true;
  3160. timeout[4] = SetTimeout(MotionTimeout[4], 5);
  3161. break;
  3162. }
  3163.  
  3164. }
  3165. //---------------------------------------------------------------------------
  3166.  
  3167. void __fastcall TForm1::VitaminCtrl6MDAlert(TObject *Sender,
  3168. Variant *vPiece)
  3169. {
  3170. IplImage *image;
  3171. if(!A(5))
  3172. return;
  3173. switch(fsm6) {
  3174. case 0:
  3175. motion[5] = true;
  3176. createAviRecord(6);
  3177. records[5] += 1;
  3178. VrNum6->Value = records[5];
  3179.  
  3180. VitaminCtrl6->StartAVIConversion();
  3181. VrUserLed6->Active = true;
  3182. // VrLed6->Active = true;
  3183. VrLed7->Active = true;
  3184. fsm6 = 1;
  3185. AA(5) = true;
  3186. timeout[5] = SetTimeout(MotionTimeout[5], 6);
  3187. break;
  3188. case 1:
  3189. motion[5] = true;
  3190. timeout[5] = SetTimeout(MotionTimeout[5], 6);
  3191. break;
  3192. }
  3193.  
  3194. }
  3195. //---------------------------------------------------------------------------
  3196.  
  3197.  
  3198.  
  3199.  
  3200.  
  3201. void __fastcall TForm1::searchObject(IplImage * image, int video, int tipo)
  3202. {
  3203. AnsiString filename;
  3204. int numFaces;
  3205. int i;
  3206. double scale = 1.0;
  3207. int x,y, x1, y1;
  3208. int cx, cy;
  3209. AnsiString buffer;
  3210.  
  3211. CvSeq* faces;
  3212. cy = cx = 24;
  3213.  
  3214.  
  3215. if(storage == NULL || facce[video] == NULL || image == NULL) {
  3216. saveError("searchFace : Errore nella storage o cascade");
  3217. return;
  3218. }
  3219. // --------------------------------------------------
  3220.  
  3221. for(int i=0;i!=6;i++)
  3222. VrULActive[i]->Active = false;
  3223.  
  3224. VrULActive[video]->Active = true;
  3225.  
  3226. saveImage(video);
  3227.  
  3228. IplImage* gray = cvCreateImage( cvSize(image->width,image->height), 8, 1 );
  3229. IplImage* small_img = cvCreateImage( cvSize( cvRound (image->width/scale),cvRound (image->height/scale)),8, 1 );
  3230.  
  3231.  
  3232. cvCvtColor( image, gray, CV_BGR2GRAY );
  3233. cvResize( gray, small_img, CV_INTER_LINEAR );
  3234. cvEqualizeHist( small_img, small_img );
  3235. cvClearMemStorage( storage );
  3236.  
  3237.  
  3238. faces = cvHaarDetectObjects(small_img, facce[video], storage, 1.1, 2, 0 | CV_HAAR_DO_CANNY_PRUNING, cvSize(classifierX[video], classifierY[video]) );
  3239.  
  3240.  
  3241. numFaces = faces->total;
  3242. if(!numFaces)
  3243. faces = cvHaarDetectObjects(small_img, facce[video], storage, 1.3, 2, 0, cvSize(classifierX[video], classifierY[video]) );
  3244. if(numFaces) {
  3245.  
  3246. for(int i = 0; i < (faces ? numFaces : 0); i++ )
  3247. {
  3248. CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
  3249.  
  3250. x = r->x*scale;
  3251. y = r->y*scale;
  3252. x1 = (r->width+x)*scale;
  3253. y1 = (r->height+y)*scale;
  3254.  
  3255.  
  3256. CvPoint center;
  3257. int radius;
  3258. center.x = cvRound((r->x + r->width*0.5)*scale);
  3259. center.y = cvRound((r->y + r->height*0.5)*scale);
  3260. radius = cvRound((r->width + r->height)*0.25*scale);
  3261.  
  3262. x = center.x - radius;
  3263. y = center.y - radius;
  3264. x1 = center.x + radius;
  3265. y1 = center.y + radius;
  3266.  
  3267. if(r->width < minx || r->height < miny) {
  3268. saveError("searchFace : minx >= r->width || miny >= r->height - continue");
  3269. continue;
  3270. }
  3271.  
  3272. DBISAMTable2->Insert();
  3273. DBISAMTable2->FieldByName("Record")->AsInteger = record[video];
  3274. // PC 2006-12-19
  3275. //
  3276. DBISAMTable2->FieldByName("Data")->AsDateTime = DateToStr(Date());
  3277. DBISAMTable2->FieldByName("Ora")->AsDateTime = TimeToStr(Time());
  3278. //--------------------------------------
  3279. CvMat small_img_roi;
  3280. cvGetSubRect( small_img, &small_img_roi, *r );
  3281. IplImageToTBitmap(small_img,ImageEnDBView1->Bitmap);
  3282.  
  3283. ImageEnProc2->Update();
  3284. ImageEnDBView1->Refresh();
  3285.  
  3286. DBISAMTable2->Post();
  3287. DBISAMTable2->FlushBuffers();
  3288.  
  3289.  
  3290. if(DBCheckBox2->Checked) {
  3291. NMSMTP1->Host = DBEdit11->Text;
  3292. NMSMTP1->Port = 25;
  3293. NMSMTP1->UserID = DBEdit12->Text;
  3294. NMSMTP1->Connect();
  3295. buffer.printf("%s%03d%03d.jpg", path, record[video], video);
  3296. ImageEnIO1->SaveToFileJpeg(buffer);
  3297. if(!DBEdit8->Text.IsEmpty()) {
  3298. NMSMTP1->PostMessage->FromAddress = DBEdit14->Text;
  3299. NMSMTP1->PostMessage->FromName = "Face Surveil";
  3300. NMSMTP1->PostMessage->Subject = "Allarme di movimento da Face Surveil(C)";
  3301. NMSMTP1->PostMessage->ToAddress->Add(DBEdit8->Text);
  3302. NMSMTP1->PostMessage->Attachments->Add(buffer);
  3303. NMSMTP1->PostMessage->Body->Text = "Immagine di allarme movimento\n\Face Surveil(C)\n\n";
  3304. NMSMTP1->SendMail();
  3305. }
  3306. if(!DBEdit9->Text.IsEmpty()) {
  3307. NMSMTP1->PostMessage->FromAddress = DBEdit14->Text;
  3308. NMSMTP1->PostMessage->FromName = "Face Surveil";
  3309. NMSMTP1->PostMessage->Subject = "Allarme di movimento da Face Surveil(C)";
  3310. NMSMTP1->PostMessage->ToAddress->Add(DBEdit9->Text);
  3311. NMSMTP1->PostMessage->Attachments->Add(buffer);
  3312. NMSMTP1->PostMessage->Body->Text = "Immagine di allarme movimento\n\Face Surveil(C)\n\n";
  3313. NMSMTP1->SendMail();
  3314. }
  3315. if(!DBEdit10->Text.IsEmpty()) {
  3316. NMSMTP1->PostMessage->FromAddress = DBEdit14->Text;
  3317. NMSMTP1->PostMessage->FromName = "Face Surveil";
  3318. NMSMTP1->PostMessage->Subject = "Allarme di movimento da Face Surveil(C)";
  3319. NMSMTP1->PostMessage->ToAddress->Add(DBEdit10->Text);
  3320. NMSMTP1->PostMessage->Attachments->Add(buffer);
  3321. NMSMTP1->PostMessage->Body->Text = "Immagine di allarme movimento\n\Face Surveil(C)\n\n";
  3322. NMSMTP1->SendMail();
  3323. }
  3324. NMSMTP1->Disconnect();
  3325. }
  3326. }
  3327. }
  3328. cvReleaseImage( &gray );
  3329. cvReleaseImage( &small_img );
  3330.  
  3331. return;}
  3332.  
  3333.  
  3334.  
  3335. void __fastcall TForm1::VrPowerButton12Click(TObject *Sender)
  3336. {
  3337. bool flag = VrPowerButton12->Active;
  3338. fsm6 = 0;
  3339. if(flag) {
  3340. VrPowerButton12->Caption = "Ferma";
  3341. if(!DBCheckBox55->Checked)
  3342. VitaminCtrl6->AVIVideoFrameRate = frate[5];
  3343. VitaminCtrl6->EventTypes = 7;
  3344. } else {
  3345. if(AA(5)) {
  3346. // PC
  3347. StopAVIRecord(5);
  3348. // -------------------
  3349. saveError ("Stop Registrazione/Analisi camera 6");
  3350. }
  3351.  
  3352. VrPowerButton12->Caption = "Analisi";
  3353. VitaminCtrl6->EventTypes = 0;
  3354. AA(5) = false;
  3355. }
  3356. A(5) = flag;
  3357. }
  3358. //---------------------------------------------------------------------------
  3359.  
  3360.  
  3361. void __fastcall TForm1::VrDemoButton12Click(TObject *Sender)
  3362. {
  3363. zip = ip[4];
  3364. zlogin = login[4];
  3365. zpassword = password[4];
  3366. activateZoom();
  3367. }
  3368. //---------------------------------------------------------------------------
  3369.  
  3370. void __fastcall TForm1::NMSMTP1Success(TObject *Sender)
  3371. {
  3372. NMSMTP1->Disconnect();
  3373. }
  3374. //---------------------------------------------------------------------------
  3375.  
  3376.  
  3377.  
  3378.  
  3379. void __fastcall TForm1::Button17Click(TObject *Sender)
  3380. {
  3381. if (OpenDialog1->Execute())
  3382. DBEdit17->Text = OpenDialog1->FileName;
  3383. }
  3384. //---------------------------------------------------------------------------
  3385.  
  3386. void __fastcall TForm1::VrDemoButton2Click(TObject *Sender)
  3387. {
  3388. VitaminCtrl1->SetFullScreen(1);
  3389. }
  3390. //---------------------------------------------------------------------------
  3391.  
  3392. void __fastcall TForm1::Button18Click(TObject *Sender)
  3393. {
  3394. if(CheckBox3->Checked == true) {
  3395. DBISAMTable9->First();
  3396. while(!DBISAMTable9->Eof)
  3397. DBISAMTable9->Delete();
  3398. }
  3399. CheckBox3->Checked = false;
  3400. }
  3401. //---------------------------------------------------------------------------
  3402.  
  3403. void __fastcall TForm1::VrDemoButton3Click(TObject *Sender)
  3404. {
  3405. VitaminCtrl2->SetFullScreen(1);
  3406. }
  3407. //---------------------------------------------------------------------------
  3408.  
  3409. void __fastcall TForm1::VrDemoButton4Click(TObject *Sender)
  3410. {
  3411. VitaminCtrl3->SetFullScreen(1);
  3412. }
  3413. //---------------------------------------------------------------------------
  3414.  
  3415. void __fastcall TForm1::VrDemoButton5Click(TObject *Sender)
  3416. {
  3417. VitaminCtrl4->SetFullScreen(1);
  3418. }
  3419. //---------------------------------------------------------------------------
  3420.  
  3421. void __fastcall TForm1::VrDemoButton6Click(TObject *Sender)
  3422. {
  3423. VitaminCtrl5->SetFullScreen(1);
  3424. }
  3425. //---------------------------------------------------------------------------
  3426.  
  3427. void __fastcall TForm1::VrDemoButton19Click(TObject *Sender)
  3428. {
  3429. VitaminCtrl6->SetFullScreen(1);
  3430. }
  3431. //---------------------------------------------------------------------------
  3432.  
  3433.  
  3434. bool TForm1::IplImageToTBitmap(const IplImage * src, Graphics::TBitmap * dest)
  3435. {
  3436. if (!src || !dest)
  3437. return false;
  3438.  
  3439. IplImage *temp;
  3440.  
  3441. CvRect roi;
  3442.  
  3443. if (src->roi)
  3444. roi=cvGetImageROI(src);
  3445. else
  3446. roi=cvRect(0,0,src->width,src->height);
  3447.  
  3448. temp=cvCreateImage(cvSize(roi.width,roi.height),IPL_DEPTH_8U,3);
  3449.  
  3450. if (src->nChannels!=3)
  3451. cvCvtColor(src,temp,CV_GRAY2RGB);
  3452. else
  3453. cvCopy(src,temp);
  3454.  
  3455. if (dest->Width==0 || dest->Height==0){
  3456. dest->Width = roi.width;
  3457. dest->Height = roi.height;
  3458. }
  3459. else{
  3460. IplImage *temp1=cvCloneImage(temp);
  3461. cvReleaseImageData(temp);
  3462. cvInitImageHeader(temp,cvSize(dest->Width,dest->Height),IPL_DEPTH_8U,3,src->origin,4);
  3463. cvCreateImageData(temp);
  3464. roi.width=dest->Width;
  3465. roi.height=dest->Height;
  3466. cvResize(temp1,temp);
  3467. cvReleaseImage(&temp1);
  3468. }
  3469.  
  3470. dest->PixelFormat=pf24bit;
  3471.  
  3472. try{
  3473. unsigned char *pLine;
  3474. int x,y;
  3475.  
  3476. for(y=0 ;y<roi.height;y++){
  3477. pLine = (unsigned char *)dest->ScanLine[y];
  3478. for(x=0 ;x <roi.width*3 ;x++){
  3479. pLine[x]= ((unsigned char*)(temp->imageData + temp->widthStep*y))[x];
  3480. }
  3481. }
  3482. }
  3483. catch(...){
  3484. MessageBox(0,"Error while converting ...","Error", MB_OK );
  3485. //ShowMessage("Error while converting ...");
  3486. }
  3487.  
  3488. cvReleaseImage(&temp);
  3489. return true;
  3490.  
  3491. }
  3492. void __fastcall TForm1::StatisticsTimerTimer(TObject *Sender)
  3493. {
  3494. DWORD Res;
  3495. ULARGE_INTEGER Value;
  3496.  
  3497. // if value AsyncStatistics->Checked - TRUE
  3498. // then statistics refreshes anisochronously
  3499. if(AsyncStatistics->Checked)
  3500. {
  3501. Adapter->Get_AsyncStatistics(stNdisTranWithoutErr);
  3502. Adapter->Get_AsyncStatistics(stNdisRecvWithoutErr);
  3503. Adapter->Get_AsyncStatistics(stNdisTranWithErr);
  3504. Adapter->Get_AsyncStatistics(stNdisRecvWithErr);
  3505. Adapter->Get_AsyncStatistics(stNdisMissed);
  3506.  
  3507. Adapter->Get_AsyncStatistics(stBpfReceive);
  3508. Adapter->Get_AsyncStatistics(stBpfAccept);
  3509. Adapter->Get_AsyncStatistics(stBpfReject);
  3510. Adapter->Get_AsyncStatistics(stBpfProcess);
  3511. return;
  3512. }
  3513.  
  3514. // update network card statistics
  3515. Res = Adapter->UpdateAdapterStatistics();
  3516. if(Res != HNERR_OK)
  3517. {
  3518. HNGetErrorBox(Res);
  3519. return;
  3520. }
  3521.  
  3522. // update BPF filter statistics
  3523. Res = Adapter->UpdateUserStatistics();
  3524. if(Res != HNERR_OK)
  3525. {
  3526. HNGetErrorBox(Res);
  3527. return;
  3528. }
  3529.  
  3530. // Gets adapter statistics values
  3531. Value.LowPart = Adapter->Get_TranWithoutErr((PUINT)&Value.HighPart);
  3532. FrameTranWithoutErr->Caption = Value.QuadPart;
  3533.  
  3534. Value.LowPart = Adapter->Get_TranWithErr((PUINT)&Value.HighPart);
  3535. FrameTranWithErr->Caption = Value.QuadPart;
  3536.  
  3537. Value.LowPart = Adapter->Get_RecvWithoutErr((PUINT)&Value.HighPart);
  3538. FrameRecvWithoutErr->Caption = Value.QuadPart;
  3539.  
  3540. Value.LowPart = Adapter->Get_RecvWithErr((PUINT)&Value.HighPart);
  3541. FrameRecvWithErr->Caption = Value.QuadPart;
  3542.  
  3543. Value.LowPart = Adapter->Get_Missed((PUINT)&Value.HighPart);
  3544. FrameMissed->Caption = Value.QuadPart;
  3545.  
  3546.  
  3547. // Gets user statistics values
  3548. Value.LowPart = Adapter->Get_RecvCount((PUINT)&Value.HighPart);
  3549. Received->Caption = Value.QuadPart;
  3550.  
  3551. Value.LowPart = Adapter->Get_AcceptCount((PUINT)&Value.HighPart);
  3552. Accepted->Caption = Value.QuadPart;
  3553.  
  3554. Value.LowPart = Adapter->Get_RejectCount((PUINT)&Value.HighPart);
  3555. Rejected->Caption = Value.QuadPart;
  3556.  
  3557. Value.LowPart = Adapter->Get_ProcessCount((PUINT)&Value.HighPart);
  3558. Processed->Caption = Value.QuadPart;
  3559. }
  3560. //---------------------------------------------------------------------------
  3561.  
  3562. void __fastcall TForm1::SyncSend_BtnClick(TObject *Sender)
  3563. {
  3564. DWORD Res;
  3565. int i;
  3566. int SendCount = SendCount_Edit->Text.ToIntDef(1);
  3567. for (i = 0; i < SendCount; i++)
  3568. {
  3569. // Sends a packet synchronously
  3570. Res = Adapter->SyncSend(PacketsContent_Edit->Text.c_str(),
  3571. PacketsContent_Edit->Text.Length());
  3572. if(Res != HNERR_OK)
  3573. {
  3574. HNGetErrorBox(Res);
  3575. return;
  3576. }
  3577. }
  3578.  
  3579. SendCount_Panel->Caption = i;
  3580. }
  3581. //---------------------------------------------------------------------------
  3582.  
  3583. void __fastcall TForm1::AsyncSend_BtnClick(TObject *Sender)
  3584. {
  3585. DWORD Res;
  3586. SendCount_Panel->Caption = 0;
  3587. // Sends a packet asynchronously
  3588. Res = Adapter->AsyncSend(PacketsContent_Edit->Text.c_str(),
  3589. PacketsContent_Edit->Text.Length(),
  3590. SendCount_Edit->Text.ToIntDef(1),NULL);
  3591. if(Res != HNERR_OK) HNGetErrorBox(Res);
  3592. }
  3593. //---------------------------------------------------------------------------
  3594.  
  3595. void __fastcall TForm1::Init_BtnClick(TObject *Sender)
  3596. {
  3597. TTreeNode *pNode;
  3598. TTreeNode *pNode2;
  3599. char Buf[256];
  3600. char Str[256];
  3601. char MACStr[100];
  3602. DWORD MACSize;
  3603. DWORD CfgIndex;
  3604. HANDLE hCfg;
  3605. DWORD i;
  3606.  
  3607. // Initialize PSSDK library
  3608. DWORD Res = Mgr->Initialize();
  3609. if(Res != HNERR_OK)
  3610. {
  3611. HNGetErrorBox(Res);
  3612. return;
  3613. }
  3614.  
  3615. //processing information about network adapters which were found
  3616. hCfg = 0;
  3617. while((hCfg = Mgr->Get_NextAdapterCfg(hCfg)) != 0)
  3618. {
  3619. Cfg->Handle = hCfg;
  3620. // Gets the network adapter description
  3621. pNode = NetTree->Items->Add(NULL,Cfg->AdapterDescription);
  3622. pNode->Data = Cfg->Handle;
  3623.  
  3624. // Gets the network adapter accessibility status
  3625. if(Cfg->AccessibleState) wsprintf(Str,"Accesseble ( YES )");
  3626. else wsprintf(Str,"Accesseble ( NO )");
  3627. NetTree->Items->AddChild(pNode,Str);
  3628.  
  3629. // Gets the network adapter system name.
  3630. wsprintf(Str,"Name %s", Cfg->AdapterName);
  3631. NetTree->Items->AddChild(pNode,Str);
  3632.  
  3633. // Gets the network adapter type
  3634. switch(Cfg->AdapterType)
  3635. {
  3636. case atEthernet: wsprintf(Str,"Type = PSSDK_ETHERNET"); break;
  3637. case atTokenRing: wsprintf(Str,"Type = PSSDK_TOKENRING"); break;
  3638. case atFDDI: wsprintf(Str,"Type = PSSDK_FDDI"); break;
  3639. case atWAN: wsprintf(Str,"Type = PSSDK_WAN"); break;
  3640. default: wsprintf(Str,"Type = PSSDK_UNKNOWN");
  3641. }
  3642. NetTree->Items->AddChild(pNode,Str);
  3643.  
  3644. // Gets the status of IP zero broadcast usage
  3645. if(Cfg->ZeroBroadcastState) NetTree->Items->AddChild(pNode,"ZeroBroadcast ( YES )");
  3646. else NetTree->Items->AddChild(pNode,"ZeroBroadcast ( NO )");
  3647.  
  3648. // Gets the status of the DHCP using
  3649. if(Cfg->DhcpState) NetTree->Items->AddChild(pNode,"DHCP Enabled ( YES )");
  3650. else NetTree->Items->AddChild(pNode,"DHCP Enabled ( NO )");
  3651.  
  3652. // Gets the network adapter packet maximum size
  3653. wsprintf(Str,"MaxPacketSize %u", Cfg->MaxPacketSize);
  3654. NetTree->Items->AddChild(pNode,Str);
  3655.  
  3656. // Gets the MAC header size
  3657. wsprintf(Str,"MACHeaderSize %u", Cfg->MACHeaderSize);
  3658. NetTree->Items->AddChild(pNode,Str);
  3659.  
  3660. // Gets the MAC address size
  3661. MACSize = Cfg->MACAddrSize;
  3662. wsprintf(Str,"MACAddrSize %u", MACSize);
  3663. NetTree->Items->AddChild(pNode,Str);
  3664.  
  3665. // Gets the MAC address of the network adapter
  3666. strcpy(Str,"MAC Address: ");
  3667. Cfg->Get_MACAddress(MACStr,sizeof(MACStr));
  3668. for(i=0;i<MACSize;i++)
  3669. {
  3670. wsprintf(Buf,"%02X",(unsigned char)MACStr[i]);
  3671. strcat(Str,Buf);
  3672. if(i+1 != MACSize) strcat(Str,"-");
  3673. }
  3674. NetTree->Items->AddChild(pNode,Str);
  3675.  
  3676. // Gets the number of IP addresses, assigned to the network adapter card
  3677. wsprintf(Str,"IP (%u) ",Cfg->IpCount);
  3678. pNode2 = NetTree->Items->AddChild(pNode,Str);
  3679. for(i=0;i<Cfg->IpCount;i++)
  3680. {
  3681. // Gets one of the IP addresses, assigned to the network adapter
  3682. wsprintf(Str,"%s ( %s ) ",Cfg->Get_Ip(i).c_str(),Cfg->Get_SubnetMask(i).c_str());
  3683. NetTree->Items->AddChild(pNode2,Str);
  3684. }
  3685.  
  3686. // Gets the number of the IP addresses of DNS servers, set on the system
  3687. wsprintf(Str,"DNS (%u) ",Cfg->IpDnsCount);
  3688. pNode2 = NetTree->Items->AddChild(pNode,Str);
  3689. for(i=0;i<Cfg->IpDnsCount;i++)
  3690. {
  3691. // Gets one of the IP addresses of the DNS servers, set on the system
  3692. wsprintf(Str,"%s",Cfg->Get_IpDns(i).c_str());
  3693. NetTree->Items->AddChild(pNode2,Str);
  3694. }
  3695.  
  3696. // Gets the number of the IP addresses of DHCP servers, set on the system
  3697. wsprintf(Str,"DHCP (%u) ",Cfg->IpDhcpCount);
  3698. pNode2 = NetTree->Items->AddChild(pNode,Str);
  3699. for(i=0;i<Cfg->IpDhcpCount;i++)
  3700. {
  3701. // Gets one of the IP addresses of DHCP servers, set on the system
  3702. wsprintf(Str,"%s",Cfg->Get_IpDhcp(i).c_str());
  3703. NetTree->Items->AddChild(pNode2,Str);
  3704. }
  3705.  
  3706. // Gets the number of the gateways IP addresses
  3707. wsprintf(Str,"Gateway (%u) ",Cfg->IpGatewayCount);
  3708. pNode2 = NetTree->Items->AddChild(pNode,Str);
  3709. for(i=0;i<Cfg->IpGatewayCount;i++)
  3710. {
  3711. // Gets one of the IP addresses of gateways, set on the system
  3712. wsprintf(Str,"%s",Cfg->Get_IpGateway(i).c_str());
  3713. NetTree->Items->AddChild(pNode2,Str);
  3714. }
  3715. }
  3716.  
  3717. if(NetTree->Items->Count) NetTree->Selected = NetTree->Items->Item[0];
  3718. }
  3719. //---------------------------------------------------------------------------
  3720.  
  3721. void __fastcall TForm1::Close_BtnClick(TObject *Sender)
  3722. {
  3723. DWORD Res;
  3724. // disabling times for refreshing statistics
  3725. StatisticsTimer->Enabled = false;
  3726.  
  3727. // Closes the network adapter
  3728. Res = Adapter->CloseAdapter();
  3729. if(Res != HNERR_OK)
  3730. {
  3731. HNGetErrorBox(Res);
  3732. return;
  3733. }
  3734.  
  3735. ConnectStatus->Caption = "OFF LINE";
  3736. }
  3737. //---------------------------------------------------------------------------
  3738.  
  3739. void __fastcall TForm1::Open_BtnClick(TObject *Sender)
  3740. {
  3741. DWORD Res;
  3742.  
  3743. // Sets the handle of the HNAdapterConfig object
  3744. // See function NetTreeChange
  3745. Adapter->ConfigHandle = (HANDLE)AdapterName_Panel->Tag;
  3746.  
  3747. // For begining of work with network adapter we must call function OpenAdapter
  3748. Res = Adapter->OpenAdapter();
  3749. if(Res != HNERR_OK)
  3750. {
  3751. HNGetErrorBox(Res);
  3752. return;
  3753. }
  3754.  
  3755. // Gets the network adapter maximum speed in 100 bps
  3756. LinkSpeed->Caption = AnsiString(Adapter->LinkSpeed/10000) + " Mbps";
  3757. // Gets the status of the physical connection to the network
  3758. if(Adapter->ConnectStatus) ConnectStatus->Caption = "ON LINE";
  3759. else ConnectStatus->Caption = "OFF LINE";
  3760.  
  3761. // enabling times for refreshing statistics
  3762. StatisticsTimer->Enabled = true;
  3763. }
  3764. //---------------------------------------------------------------------------
  3765.  
  3766. void __fastcall TForm1::ChkUseFastBpfClick(TObject *Sender)
  3767. {
  3768. Adapter->UseFastUserFilter = ChkUseFastBpf->Checked;
  3769. }
  3770. //---------------------------------------------------------------------------
  3771.  
  3772. void __fastcall TForm1::AdapterAsyncSend(TObject *Sender, Pointer Key,
  3773. DWORD Count)
  3774. {
  3775. SendCount_Panel->Caption = Count;
  3776. }
  3777. //---------------------------------------------------------------------------
  3778.  
  3779. void __fastcall TForm1::AdapterPacketReceive(TObject *Sender,
  3780. Pointer ThParam, Pointer hPacket, Pointer pPacketData,
  3781. DWORD IncPacketSize)
  3782. {
  3783. HNPacket->Handle = hPacket;
  3784. // as we have set the BPF filter to IP traffic in advance
  3785. // we are sure that the incoming packet has the IP header
  3786. PIP_HEADER pIp = (PIP_HEADER)&((char*)pPacketData)[sizeof(ETHERNET_HEADER)];
  3787.  
  3788. // send the message of receiving the IP packet
  3789. // see the OnIPPacketReceive function
  3790. PostMessage(Handle,WM_USER + 1,pIp->SrcAddr,HNPacket->PacketSize);
  3791. }
  3792. //---------------------------------------------------------------------------
  3793.  
  3794. void __fastcall TForm1::AdapterStatistics(TObject *Sender,
  3795. int StatisticsType, PULargeInteger pValue)
  3796. {
  3797. switch(StatisticsType)
  3798. {
  3799. case stNdisTranWithoutErr:
  3800. FrameTranWithoutErr->Caption = pValue->QuadPart;
  3801. break;
  3802. case stNdisRecvWithoutErr:
  3803. FrameRecvWithoutErr->Caption = pValue->QuadPart;
  3804. break;
  3805. case stNdisTranWithErr:
  3806. FrameTranWithErr->Caption = pValue->QuadPart;
  3807. break;
  3808. case stNdisRecvWithErr:
  3809. FrameRecvWithErr->Caption = pValue->QuadPart;
  3810. break;
  3811. case stNdisMissed:
  3812. FrameMissed->Caption = pValue->QuadPart;
  3813. break;
  3814.  
  3815. case stBpfReceive:
  3816. Received->Caption = pValue->QuadPart;
  3817. break;
  3818. case stBpfAccept:
  3819. Accepted->Caption = pValue->QuadPart;
  3820. break;
  3821. case stBpfReject:
  3822. Rejected->Caption = pValue->QuadPart;
  3823. break;
  3824. case stBpfProcess:
  3825. Processed->Caption = pValue->QuadPart;
  3826. break;
  3827. }
  3828. }
  3829. //---------------------------------------------------------------------------
  3830.  
  3831.  
  3832. void __fastcall TForm1::NetTreeChange(TObject *Sender, TTreeNode *Node)
  3833. {
  3834. while(Node->Parent) Node = Node->Parent;
  3835. AdapterName_Panel->Caption = Node->Text;
  3836. AdapterName_Panel->Tag = (int)Node->Data;
  3837.  
  3838. }
  3839. //---------------------------------------------------------------------------
  3840.  
  3841. void __fastcall TForm1::IPStatistics_LVCompare(TObject *Sender,
  3842. TListItem *Item1, TListItem *Item2, int Data, int &Compare)
  3843. {
  3844. in_addr Ip1, Ip2;
  3845. Ip1.S_un.S_addr = (DWORD)Item1->Data;
  3846. Ip2.S_un.S_addr = (DWORD)Item2->Data;
  3847.  
  3848. if (Ip1.S_un.S_un_b.s_b1 != Ip2.S_un.S_un_b.s_b1)
  3849. {
  3850. Compare = (Ip1.S_un.S_un_b.s_b1 > Ip2.S_un.S_un_b.s_b1 ? 1 : -1);
  3851. return;
  3852. }
  3853.  
  3854. if (Ip1.S_un.S_un_b.s_b2 != Ip2.S_un.S_un_b.s_b2)
  3855. {
  3856. Compare = (Ip1.S_un.S_un_b.s_b2 > Ip2.S_un.S_un_b.s_b2 ? 1 : -1);
  3857. return;
  3858. }
  3859.  
  3860. if (Ip1.S_un.S_un_b.s_b3 != Ip2.S_un.S_un_b.s_b3)
  3861. {
  3862. Compare = (Ip1.S_un.S_un_b.s_b3 > Ip2.S_un.S_un_b.s_b3 ? 1 : -1);
  3863. return;
  3864. }
  3865.  
  3866. if (Ip1.S_un.S_un_b.s_b4 != Ip2.S_un.S_un_b.s_b4)
  3867. Compare = (Ip1.S_un.S_un_b.s_b4 > Ip2.S_un.S_un_b.s_b4 ? 1 : -1);
  3868. }
  3869. //---------------------------------------------------------------------------
  3870.  
  3871. void __fastcall TForm1::cbNetCardsChange(TObject *Sender)
  3872. {
  3873. if (cbNetCards->ItemIndex == -1) return;
  3874. HANDLE AdpCfg = (HANDLE)cbNetCards->Items->Objects[cbNetCards->ItemIndex];
  3875. if (HNAdapter->ConfigHandle != AdpCfg) btnOpen->Enabled = true;
  3876. else btnOpen->Enabled = false;
  3877. }
  3878. //---------------------------------------------------------------------------
  3879.  
  3880. void __fastcall TForm1::btnPingClick(TObject *Sender)
  3881. {
  3882. long Res;
  3883. char MacAddr[6];
  3884. DWORD ArpPacketSize = sizeof(ETHERNET_HEADER) + sizeof(ARP_HEADER);
  3885. DWORD IcmpPacketSize = sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER) + sizeof(ICMP_HEADER) + 20;
  3886. HANDLE hPkt = HNPacket->AllocatePacket((IcmpPacketSize > ArpPacketSize ? IcmpPacketSize : ArpPacketSize));
  3887. if (!hPkt)
  3888. {
  3889. MessageBox(NULL,"Can't create packet","Error",MB_ICONINFORMATION);
  3890. return;
  3891. }
  3892.  
  3893. HNPacket->Handle = hPkt;
  3894. char *pPacket = (char *)HNPacket->PacketData;
  3895.  
  3896. // Gets MAC address of network adapter
  3897. HNAdapterCfg->Get_MACAddress(MacAddr,6);
  3898.  
  3899. ETHERNET_HEADER *pEth = (ETHERNET_HEADER *)pPacket;
  3900. ARP_HEADER *pArp = (ARP_HEADER *)&pPacket[sizeof(ETHERNET_HEADER)];
  3901.  
  3902. // Create Ethernet ethernet header for ARP packet
  3903. MoveMemory(pEth->EthSHost,MacAddr,6);
  3904. FillMemory(pEth->EthDHost,6,0xFF);
  3905. pEth->EthType = htons(ETHERTYPE_ARP);
  3906.  
  3907. // Create ARP packet
  3908. pArp->Hw_Type = htons(HW_TYPE_ETH10);
  3909. pArp->Prot_Type = htons(ETHERTYPE_IP);
  3910. pArp->Hw_Addr_Size = 6;
  3911. pArp->Prot_Addr_Size = 4;
  3912. pArp->Operation = htons(ARP_OP_ARP_QUERY);
  3913.  
  3914. MoveMemory(pArp->Sndr_Hw_Addr,MacAddr,6);
  3915.  
  3916. SrcIpAddr.S_un.S_addr = inet_addr(cbAdapterIp->Text.c_str());
  3917. *((DWORD*)&(pArp->Sndr_Ip_Addr[0])) = SrcIpAddr.S_un.S_addr;
  3918.  
  3919. ZeroMemory(pArp->Rcpt_Hw_Addr,6);
  3920. DestIpAddr.S_un.S_addr = inet_addr(eIp->Text.c_str());
  3921.  
  3922. DWORD RcvIpAdr;
  3923. if(!cbNAT->Checked) RcvIpAdr = DestIpAddr.S_un.S_addr;
  3924. else RcvIpAdr = inet_addr(ebIpNat->Text.c_str());
  3925.  
  3926. *((DWORD*)&(pArp->Rcpt_Ip_Addr[0])) = RcvIpAdr;
  3927.  
  3928. // Clear APR filter
  3929. HNUserFilterArp->Clear();
  3930. // Create ARP filter
  3931. HNUserFilterArp->AddCmd(BPF_LD+BPF_H+BPF_ABS, 12); //
  3932. HNUserFilterArp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_ARP, 0, 5); // jmp if false line 5
  3933. HNUserFilterArp->AddCmd(BPF_LD+BPF_H+BPF_ABS, ((DWORD)&pArp->Operation - (DWORD)pEth)); //
  3934. HNUserFilterArp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ARP_OP_ARP_RESP, 0, 3); // jmp if false line 3
  3935. HNUserFilterArp->AddCmd(BPF_LD+BPF_W+BPF_ABS, ((DWORD)&pArp->Sndr_Ip_Addr - (DWORD)pEth)); //
  3936. HNUserFilterArp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, htonl(RcvIpAdr), 0, 1); // jmp if false line 1
  3937. HNUserFilterArp->AddCmd(BPF_RET+BPF_K, (u_int)-1); // end - TRUE
  3938. HNUserFilterArp->AddCmd(BPF_RET+BPF_K, 0); // end - FALSE
  3939.  
  3940. // Set ARP filter
  3941. HNAdapter->UserFilter = HNUserFilterArp->Handle;
  3942. // Reset ARP receiving packet event
  3943. ResetEvent(RecvArpPacket);
  3944. // Send ARP packet
  3945. HNPacket->IncPacketSize = ArpPacketSize;
  3946. Res = HNAdapter->SyncSendEx(hPkt);
  3947. if(Res != HNERR_OK) { HNGetErrorBox(Res); return; }
  3948. // Wait receive ARP packet
  3949. Res = WaitForSingleObject(RecvArpPacket,2000);
  3950. // Clear user filter (stop receive any packets)
  3951. HNAdapter->UserFilter = 0;
  3952. if((ULONG)Res != WAIT_OBJECT_0)
  3953. {
  3954. ShowMessage("No Arp reply");
  3955. return;
  3956. }
  3957.  
  3958. // Create ICMP packet
  3959. memset(pPacket,'S',IcmpPacketSize);
  3960. pEth = (ETHERNET_HEADER *)pPacket;
  3961. IP_HEADER *pIp = (IP_HEADER *)&pPacket[sizeof(ETHERNET_HEADER)];
  3962. ICMP_HEADER *pIcmp = (ICMP_HEADER *)&pPacket[sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER)];
  3963.  
  3964. MoveMemory(pEth->EthSHost,MacAddr,6);
  3965. MoveMemory(pEth->EthDHost,DestMacAddr,6);
  3966. pEth->EthType = htons(ETHERTYPE_IP);
  3967.  
  3968. // Create IP Header
  3969. ZeroMemory((char *)pIp,sizeof(IP_HEADER));
  3970. pIp->Ver = 4;
  3971. pIp->Len = sizeof(IP_HEADER)/sizeof(DWORD);
  3972. pIp->TotalLength = htons(IcmpPacketSize - sizeof(ETHERNET_HEADER));
  3973. pIp->Identification = htons((unsigned short)GetCurrentProcessId());
  3974. pIp->Ttl = DEFAULT_TTL;
  3975. pIp->Protocol = IPPROTO_ICMP;
  3976. pIp->SrcAddr = SrcIpAddr.S_un.S_addr;
  3977. pIp->DestAddr = DestIpAddr.S_un.S_addr;
  3978. pIp->Checksum = HNPacket->InetCheckSum(pIp, sizeof(IP_HEADER));
  3979.  
  3980. IcmpBufferSize = IcmpPacketSize - sizeof(ETHERNET_HEADER) - sizeof(IP_HEADER);
  3981.  
  3982. unsigned short ProcID = (unsigned short)GetCurrentProcessId();
  3983.  
  3984. // Clear ICMP filter
  3985. HNUserFilterIcmp->Clear();
  3986. // Create ICMP filter
  3987. HNUserFilterIcmp->AddCmd(BPF_LD+BPF_H+BPF_ABS, 12); //
  3988. HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_IP, 0, 9); // jmp if false line 9
  3989. HNUserFilterIcmp->AddCmd(BPF_LD+BPF_B+BPF_ABS, ((DWORD)&pIp->Protocol - (DWORD)pEth)); //
  3990. HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, IPPROTO_ICMP, 0, 7); // jmp if false line 7
  3991. HNUserFilterIcmp->AddCmd(BPF_LD+BPF_W+BPF_ABS, ((DWORD)&pIp->SrcAddr - (DWORD)pEth)); //
  3992. HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, htonl(DestIpAddr.S_un.S_addr), 0, 5); // jmp if false line 5
  3993. HNUserFilterIcmp->AddCmd(BPF_LD+BPF_B+BPF_ABS, ((DWORD)&pIcmp->IcmpType - (DWORD)pEth)); //
  3994. HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ICMP_ECHOREPLY, 0, 3); // jmp if false line 3
  3995. HNUserFilterIcmp->AddCmd(BPF_LD+BPF_H+BPF_ABS, ((DWORD)&pIcmp->IcmpId - (DWORD)pEth)); // //
  3996. HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, htons(ProcID), 0, 1); // jmp if false line 1
  3997. HNUserFilterIcmp->AddCmd(BPF_RET+BPF_K, (u_int)-1); // end - TRUE
  3998. HNUserFilterIcmp->AddCmd(BPF_RET+BPF_K, 0); // end - FALSE
  3999.  
  4000. // Set ICMP filter
  4001. HNAdapter->UserFilter = HNUserFilterIcmp->Handle;
  4002.  
  4003. Send = Receive = 0;
  4004. SendCount = ebCount->Text.ToIntDef(10);
  4005. // Send ICMP packets
  4006. HNPacket->IncPacketSize = IcmpPacketSize;
  4007. for(DWORD i = 0; i < SendCount; i++)
  4008. {
  4009. pIcmp->IcmpType = ICMP_ECHO;
  4010. pIcmp->IcmpCode = 0;
  4011. pIcmp->IcmpChecksum = 0;
  4012. pIcmp->IcmpId = ProcID;
  4013. pIcmp->IcmpSeq = 0;
  4014. pIcmp->IcmpTimestamp = GetTickCount();
  4015. pIcmp->IcmpChecksum = HNPacket->InetCheckSum(pIcmp,IcmpBufferSize);
  4016.  
  4017. Res = HNAdapter->SyncSendEx(hPkt);
  4018. if(Res != HNERR_OK) { HNGetErrorBox(Res); return; }
  4019.  
  4020. Send++;
  4021. }
  4022. StatusBar->Panels->Items[1]->Text = Send;
  4023. HNPacket->FreePacket(hPkt);
  4024. }
  4025. //---------------------------------------------------------------------------
  4026.  
  4027. void __fastcall TForm1::btnOpenClick(TObject *Sender)
  4028. {
  4029. long Res;
  4030. if(cbNetCards->ItemIndex == -1) return;
  4031. HANDLE AdpCfg = (HANDLE)cbNetCards->Items->Objects[cbNetCards->ItemIndex];
  4032.  
  4033. btnPing->Enabled = false;
  4034. HNAdapterCfg->Handle = AdpCfg;
  4035. if (HNAdapter->IsOpened()) HNAdapter->CloseAdapter();
  4036. // Sets the handle of the HNAdapterConfig object
  4037. HNAdapter->ConfigHandle = AdpCfg;
  4038. // Opens the network adapter
  4039. Res = HNAdapter->OpenAdapter();
  4040. if(Res != HNERR_OK) {HNGetErrorBox(Res); return; }
  4041.  
  4042. cbAdapterIp->Clear();
  4043. AnsiString AdapterIp;
  4044. // Gets IP addresses, assigned to the network adapter card
  4045. for (DWORD i = 0; i < HNAdapterCfg->IpCount; i++)
  4046. {
  4047. AdapterIp = HNAdapterCfg->Get_Ip(i);
  4048. cbAdapterIp->Items->Add(AdapterIp);
  4049. }
  4050.  
  4051. in_addr IpAddr;
  4052. in_addr IpMask;
  4053. if (cbAdapterIp->Items->Count)
  4054. {
  4055. cbAdapterIp->ItemIndex = 0;
  4056. AdapterIp = HNAdapterCfg->Get_Ip(0);
  4057. IpAddr.S_un.S_addr = inet_addr(AdapterIp.c_str());
  4058. AdapterIp = HNAdapterCfg->Get_SubnetMask(0);
  4059. IpMask.S_un.S_addr = inet_addr(AdapterIp.c_str());
  4060. IpAddr.S_un.S_addr &= IpMask.S_un.S_addr;
  4061. eIp->Text = inet_ntoa(IpAddr);
  4062. }
  4063.  
  4064. btnPing->Enabled = true;
  4065. btnOpen->Enabled = false;
  4066. }
  4067. //---------------------------------------------------------------------------
  4068.  
  4069. void __fastcall TForm1::bClearClick(TObject *Sender)
  4070. {
  4071. //Clear results
  4072. mResult->Lines->Clear();
  4073. StatusBar->Panels->Items[1]->Text = 0;
  4074. StatusBar->Panels->Items[3]->Text = 0;
  4075. }
  4076. //---------------------------------------------------------------------------
  4077.  
  4078. void __fastcall TForm1::HNPSManagerConfigChange(TObject *Sender,
  4079. Pointer hConfig, int ChangeType)
  4080. {
  4081. HNAdapterCfg->Handle = hConfig;
  4082. // Gets the network adapter type
  4083. if(HNAdapterCfg->AdapterType == atEthernet)
  4084. cbNetCards->Items->AddObject(HNAdapterCfg->AdapterDescription,(TObject*)hConfig);
  4085.  
  4086. }
  4087. //---------------------------------------------------------------------------
  4088.  
  4089. void __fastcall TForm1::HNAdapterPacketReceive(TObject *Sender,
  4090. Pointer ThParam, Pointer hPacket, Pointer pPacketData,
  4091. DWORD IncPacketSize)
  4092. {
  4093. ETHERNET_HEADER *pEth = (ETHERNET_HEADER *)pPacketData;
  4094. unsigned short EthType = htons(pEth->EthType);
  4095. char* PacketBuffer = (char*)pPacketData;
  4096.  
  4097. if(EthType == ETHERTYPE_ARP)
  4098. {
  4099. ARP_HEADER *pArp = (ARP_HEADER *)&PacketBuffer[sizeof(ETHERNET_HEADER)];
  4100. MoveMemory(DestMacAddr,pArp->Sndr_Hw_Addr,6);
  4101. SetEvent(RecvArpPacket);
  4102. return;
  4103. }
  4104. //We are sure that this code processes icmp packets only, because of the ICMP BPF program.
  4105. IP_HEADER *pIp = (IP_HEADER *)&PacketBuffer[sizeof(ETHERNET_HEADER)];
  4106. ICMP_HEADER *pIcmp = (ICMP_HEADER *)&PacketBuffer[sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER)];
  4107. // Sending message to our application when icmp packet was received (function OnIcmpRecv)
  4108. PostMessage(Handle,WM_USER + 2,GetTickCount() - pIcmp->IcmpTimestamp,pIp->Ttl);
  4109.  
  4110. }
  4111. //---------------------------------------------------------------------------
  4112.  
  4113.  
  4114. void TForm1::OnIcmpRecv(TMessage& Msg)
  4115. {
  4116. Result = "Reply from ";
  4117. Result += inet_ntoa(DestIpAddr);
  4118. Result += ": bytes = " + IntToStr(IcmpBufferSize);
  4119. Result += " time = " + IntToStr(Msg.WParam) + " ms ";
  4120. Result += "TTL=" + IntToStr(Msg.LParam);
  4121. mResult->Lines->Add(Result);
  4122. StatusBar->Panels->Items[3]->Text = ++Receive;
  4123. if (Send == SendCount &&
  4124. Receive == SendCount) HNAdapter->UserFilter = NULL;
  4125. }
  4126.  
  4127. void TForm1::OnIPPacketReceive(TMessage& Msg)
  4128. {
  4129. TListItem* Item = IPStatistics_LV->FindData(0,(void*)Msg.WParam,true,false);
  4130.  
  4131. if (!Item)
  4132. {
  4133. in_addr Ip;
  4134. Ip.S_un.S_addr = Msg.WParam;
  4135. IPStatistics_LV->Items->BeginUpdate();
  4136. Item = IPStatistics_LV->Items->Add();
  4137. Item->Data = (void*)Msg.WParam;
  4138. Item->Caption = inet_ntoa(Ip);
  4139. Item->SubItems->AddObject("0",(TObject*)NULL);
  4140. Item->SubItems->AddObject("0",(TObject*)NULL);
  4141. IPStatistics_LV->AlphaSort();
  4142. IPStatistics_LV->Items->EndUpdate();
  4143. }
  4144.  
  4145. Item->SubItems->Objects[0] = (TObject*)((DWORD)Item->SubItems->Objects[0] + 1);
  4146. Item->SubItems->Strings[0] = StrToInt((DWORD)Item->SubItems->Objects[0]);
  4147. Item->SubItems->Objects[1] = (TObject*)((DWORD)Item->SubItems->Objects[1] + Msg.LParam);
  4148. Item->SubItems->Strings[1] = StrToInt((DWORD)Item->SubItems->Objects[1]);
  4149.  
  4150. }
  4151.  
  4152.  
  4153.  
  4154. void __fastcall TForm1::VrTimer1Timer(TObject *Sender)
  4155. {
  4156. long frame;
  4157. VrTimer1->Enabled = false;
  4158. for(int i=0;i!=6;i++) {
  4159. if(A(i)) {
  4160. frame = VitaminCtrl[i]->FrameRate;
  4161. switch(i) {
  4162. case 0:
  4163. Edit18->Text = frame;
  4164. break;
  4165. case 1:
  4166. Edit19->Text = frame;
  4167. break;
  4168. case 2:
  4169. Edit20->Text = frame;
  4170. break;
  4171. case 3:
  4172. Edit21->Text = frame;
  4173. break;
  4174. case 4:
  4175. Edit22->Text = frame;
  4176. break;
  4177. case 5:
  4178. Edit23->Text = frame;
  4179. break;
  4180.  
  4181. }
  4182. }
  4183. }
  4184. VrTimer1->Enabled = true;
  4185. Application->ProcessMessages();
  4186. }
  4187. //---------------------------------------------------------------------------
  4188.  
  4189.  
  4190.  
  4191.  
  4192.  
  4193.  
  4194. void TForm1::setONVideoCamera(void)
  4195. {
  4196. if(active[0]) {
  4197. VrPowerButton1->Active = true;
  4198. VrPowerButton1Click (this);
  4199. }
  4200. if(active[1]) {
  4201. VrPowerButton3->Active = true;
  4202. VrPowerButton3Click (this);
  4203. }
  4204. if(active[2]) {
  4205. VrPowerButton5->Active = true;
  4206. VrPowerButton5Click (this);
  4207. }
  4208. if(active[3]) {
  4209. VrPowerButton7->Active = true;
  4210. VrPowerButton7Click (this);
  4211. }
  4212. if(active[4]) {
  4213. VrPowerButton9->Active = true;
  4214. VrPowerButton9Click (this);
  4215. }
  4216. if(active[5]) {
  4217. VrPowerButton11->Active = true;
  4218. VrPowerButton11Click (this);
  4219. }
  4220.  
  4221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement