Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vcl.h>
- #include <winsock2.h>
- #include <stdio.h>
- #include <dir.h>
- #include <time.h>
- #include <Filectrl.hpp>
- #include <systdate.h>
- #include <string.h>
- #include <stdlib.h>
- #include <cv.h>
- #include <cxcore.h>
- #include "Ethernet.h"
- #include "HNPsSdkDef.hpp"
- #include "Ip.h"
- #include "HNUtil.h"
- #include "Arp.h"
- #include "Icmp.h"
- #pragma hdrstop
- #include "Consorzio.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "VITAMINDECODERLib_OCX"
- #pragma link "VrButtons"
- #pragma link "VrControls"
- #pragma link "VrDisplay"
- #pragma link "VrLabel"
- #pragma link "VrProgressBar"
- #pragma link "VrBlotter"
- #pragma link "VrLcd"
- #pragma link "dbimageen"
- #pragma link "ieview"
- #pragma link "imageenview"
- #pragma link "VrLeds"
- #pragma link "imageenio"
- #pragma link "imageenproc"
- #pragma link "VrCheckLed"
- #pragma link "VrSlider"
- #pragma link "VrMatrix"
- #pragma link "VrEdit"
- #pragma link "VrBorder"
- #pragma link "SHDocVw_OCX"
- #pragma link "ieopensavedlg"
- #pragma link "vrLedClock"
- #pragma link "VrMatrixLabel"
- #pragma link "VrNavigator"
- #pragma link "VrThreads"
- #pragma link "dbisamtb"
- #pragma link "HNAdapter"
- #pragma link "HNAdapterConfig"
- #pragma link "HNPacket"
- #pragma link "HNPSManager"
- #pragma link "HNUserFilter"
- #pragma link "ExceptionLog"
- #pragma link "dcDiskInfo"
- #pragma link "dcInternal"
- #pragma link "VrAnalog"
- #pragma link "VrTrackBar"
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #define AA(x) (isactive[x])
- #define A(x) (active[x])
- char* (__stdcall *GetSerialNumber)(int, char*);
- char* (__stdcall *GetModelNumber)(int, char*);
- char* (__stdcall *GetRevisionNo)(int, char*);
- int (__stdcall *GetBufferSize)(int, char*);
- int (__stdcall *GetCylinders)(int, char*);
- int (__stdcall *GetHeads)(int, char*);
- int (__stdcall *GetSectors)(int, char*);
- HINSTANCE DllInst = NULL;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- Adapter->ThreadCount = Adapter->MaxThreadCount;
- // Create Ip filter
- Bpf->AddCmd(BPF_LD+BPF_H+BPF_ABS, 12);
- Bpf->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_IP, 0, 1);
- Bpf->AddCmd(BPF_RET+BPF_K, sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER));
- Bpf->AddCmd(BPF_RET+BPF_K, 0);
- // Sets BPF filter for receiving IP traffic only
- Adapter->UserFilter = Bpf->Handle;
- Adapter->UserFilterActive = true;
- // Sets MAC filter to begin receive packets
- Adapter->MacFilter = mfAll;
- long Res = HNPSManager->Initialize();
- if(Res != HNERR_OK) { HNGetErrorBox(Res); return; }
- RecvArpPacket = CreateEvent(NULL,TRUE,FALSE,NULL);
- WSADATA wsaData;
- WSAStartup(MAKEWORD(2,0),&wsaData);
- // Sets the status flag of the user-settable packet filter using
- HNAdapter->UserFilterActive = true;
- // Sets the MAC filter for the network adapter
- HNAdapter->MacFilter = mfOwnerRecv;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TForm1::IsTimeout(long timeout, int video)
- {
- int remain;
- long ltime;
- time(<ime);
- remain = timeout - ltime;
- switch(video) {
- case 1:
- VrProgressBar1->Position = remain;
- break;
- case 2:
- VrProgressBar2->Position = remain;
- break;
- case 3:
- VrProgressBar3->Position = remain;
- break;
- case 4:
- VrProgressBar4->Position = remain;
- break;
- case 5:
- VrProgressBar5->Position = remain;
- break;
- case 6:
- // VrProgressBar6->Position = remain;
- // PC
- VrProgressBar7->Position = remain;
- // ----------------------------
- break;
- }
- if(timeout <= ltime)
- return true;
- return false;
- }
- long __fastcall TForm1::SetTimeout(int sec, int video)
- {
- long ltime;
- time(<ime);
- switch(video) {
- case 1:
- VrProgressBar1->MaxValue = sec;
- break;
- case 2:
- VrProgressBar2->MaxValue = sec;
- break;
- case 3:
- VrProgressBar3->MaxValue = sec;
- break;
- case 4:
- VrProgressBar4->MaxValue = sec;
- break;
- case 5:
- VrProgressBar5->MaxValue = sec;
- break;
- case 6:
- //VrProgressBar6->MaxValue = sec;
- // PC
- VrProgressBar7->MaxValue = sec;
- break;
- }
- // PC
- // is necessary?
- //Form1->Refresh();
- // -------------------
- return (ltime + (long) sec);
- }
- void __fastcall TForm1::FormActivate(TObject *Sender)
- {
- AnsiString OutString;
- AnsiString buffer;
- int n, m, len1, len2;
- isdemo = true;
- char str1[50], str2[50];
- char* RegCode = "F1PN3-T9W1C-5P2UM-91EL8-SPPH8"; //Enter your Keycode
- int iDrive;
- iDrive = 0;
- Label44->Caption = " Versione dimostrativa non registrata";
- if (DllInst == NULL) DllInst = LoadLibrary("GetDiskSerial.dll");
- if (DllInst)
- {
- n = m = 0;
- GetSerialNumber = (char* (__stdcall*)(int, char*))GetProcAddress(DllInst,"GetSerialNumber");
- Edit9->Text = GetSerialNumber(iDrive, RegCode);
- lstrcpy(str1, Edit9->Text.c_str());
- len1 = 0;
- while(str1[len1])
- n += str1[len1++];
- lstrcpy(str2,Activation.c_str());
- len2 = 0;
- while(str2[len2])
- m += str2[len2++];
- if(m == n) {
- isdemo = false;
- Label44->Caption = Registrato;
- }
- }
- for(int i=0;i!=6;i++)
- zoomval[i] = 0;
- fsm[0] = &fsm1;
- fsm[1] = &fsm2;
- fsm[2] = &fsm3;
- fsm[3] = &fsm4;
- fsm[4] = &fsm5;
- fsm[5] = &fsm6;
- VrNum1->Value = 0;
- VrNum2->Value = 0;
- VrNum3->Value = 0;
- VrNum4->Value = 0;
- VrNum5->Value = 0;
- VrNum6->Value = 0;
- records[0] = 0;
- records[1] = 0;
- records[2] = 0;
- records[3] = 0;
- records[4] = 0;
- records[5] = 0;
- vrLed[0] = VrLed1;
- vrLed[1] = VrLed2;
- vrLed[2] = VrLed3;
- vrLed[3] = VrLed4;
- vrLed[4] = VrLed5;
- // vrLed[5] = VrLed6;
- vrLed[5] = VrLed7;
- // PC
- // set 'Video Analisi' as active page in PageControl1
- PageControl1->ActivePageIndex = 1;
- // ----------------------------------------------------
- sconnessioni[0] = 0;
- sconnessioni[1] = 0;
- sconnessioni[2] = 0;
- sconnessioni[3] = 0;
- sconnessioni[4] = 0;
- sconnessioni[5] = 0;
- loadOrario();
- loadSetup();
- // if(deleteafter)
- // deleteAllrecordafter();
- // PC
- DeleteOldestVideo();
- // --------------------
- isAutoconnect = DBCheckBox54->Checked;
- if(isAutoconnect) {
- setONVideoCamera();
- if(recadora)
- Timer2->Enabled = true;
- }
- CheckProgramPassword (); // if password is empty unlock panels
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton1Click(TObject *Sender)
- {
- bool flag;
- int retcode;
- VrLabel44->Visible = false;
- VitaminCtrl1->Visible = true;
- flag = VrPowerButton1->Active;
- if(flag) {
- saveError("Attivazione video 1");
- A(0) = false;
- VitaminCtrl1->AutoServerModelType = true;
- VitaminCtrl1->EventTypes = 0;
- VitaminCtrl1->RemoteIPAddr = ip[0];
- VitaminCtrl1->UserName = login[0];
- VitaminCtrl1->Password = password[0];
- VitaminCtrl1->AutoReconnect = true;
- VitaminCtrl1->ReadWriteTimeout = Edit3->Text.ToInt();
- retcode = VitaminCtrl1->Connect();
- if(zoomval[0] != 0) {
- VitaminCtrl1->DigitalZoomEnabled = true;
- VitaminCtrl1->DigitalZoomFactor = zoomval[0];
- }
- } else {
- saveError("Disattivazione video 1");
- // PC
- // in any case i need to put 'Analisi' button to Active = false
- VrPowerButton2->Active = flag;
- // --------------------------------------
- VitaminCtrl1->Disconnect();
- }
- VrPowerButton2->Enabled = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton3Click(TObject *Sender)
- {
- bool flag;
- VrLabel19->Visible = false;
- VitaminCtrl2->Visible = true;
- if(isdemo) return;
- flag = VrPowerButton3->Active;
- if(flag) {
- saveError("Attivazione video 2");
- A(1) = false;
- VitaminCtrl2->AutoServerModelType = true;
- VitaminCtrl2->EventTypes = 0;
- VitaminCtrl2->RemoteIPAddr = ip[1];
- VitaminCtrl2->UserName = login[1];
- VitaminCtrl2->Password = password[1];
- VitaminCtrl2->AutoReconnect = true;
- VitaminCtrl2->ReadWriteTimeout = Edit3->Text.ToInt();
- VitaminCtrl2->Connect();
- if(zoomval[1] != 0) {
- VitaminCtrl2->DigitalZoomEnabled = true;
- VitaminCtrl2->DigitalZoomFactor = zoomval[1];
- }
- } else {
- saveError("Disattivazione video 2");
- // PC
- VrPowerButton2->Active = flag;
- // --------------------------------------
- // PC (was VitaminCtrl4)
- VitaminCtrl2->Disconnect();
- // --------------------------
- }
- VrPowerButton4->Enabled = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton5Click(TObject *Sender)
- {
- bool flag;
- VrLabel27->Visible = false;
- VitaminCtrl3->Visible = true;
- if(isdemo) return;
- flag = VrPowerButton5->Active;
- if(flag) {
- saveError("Attivazione video 3");
- A(2) = false;
- VitaminCtrl3->AutoServerModelType = true;
- VitaminCtrl3->EventTypes = 0;
- VitaminCtrl3->RemoteIPAddr = ip[2];
- VitaminCtrl3->UserName = login[2];
- VitaminCtrl3->Password = password[2];
- VitaminCtrl3->AutoReconnect = true;
- VitaminCtrl3->ReadWriteTimeout = Edit3->Text.ToInt();
- VitaminCtrl3->Connect();
- if(zoomval[2] != 0) {
- VitaminCtrl3->DigitalZoomEnabled = true;
- VitaminCtrl3->DigitalZoomFactor = zoomval[2];
- }
- } else {
- saveError("Disattivazione video 3");
- // PC
- VrPowerButton6->Active = flag;
- // --------------------------------------
- VitaminCtrl3->Disconnect();
- }
- VrPowerButton6->Enabled = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton7Click(TObject *Sender)
- {
- bool flag;
- VrLabel28->Visible = false;
- VitaminCtrl4->Visible = true;
- if(isdemo) return;
- flag = VrPowerButton7->Active;
- if(flag) {
- saveError("Attivazione video 4");
- A(3) = false;
- VitaminCtrl4->AutoServerModelType = true;
- VitaminCtrl4->EventTypes = 0;
- VitaminCtrl4->RemoteIPAddr = ip[3];
- VitaminCtrl4->UserName = login[3];
- VitaminCtrl4->Password = password[3];
- VitaminCtrl4->AutoReconnect = true;
- VitaminCtrl4->ReadWriteTimeout = Edit3->Text.ToInt();
- VitaminCtrl4->Connect();
- if(zoomval[3] != 0) {
- VitaminCtrl4->DigitalZoomEnabled = true;
- VitaminCtrl4->DigitalZoomFactor = zoomval[3];
- }
- } else {
- // PC
- VrPowerButton8->Active = flag;
- // --------------------------------------
- saveError("Disattivazione video 4");
- VitaminCtrl4->Disconnect();
- }
- VrPowerButton8->Enabled = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton9Click(TObject *Sender)
- {
- bool flag;
- VitaminCtrl5->Visible = true;
- if(isdemo) return;
- flag = VrPowerButton9->Active;
- if(flag) {
- saveError("Attivazione video 5");
- A(4) = false;
- VitaminCtrl5->AutoServerModelType = true;
- VitaminCtrl5->EventTypes = 0;
- VitaminCtrl5->RemoteIPAddr = ip[4];
- VitaminCtrl5->UserName = login[4];
- VitaminCtrl5->Password = password[4];
- VitaminCtrl5->AutoReconnect = true;
- VitaminCtrl5->ReadWriteTimeout = Edit3->Text.ToInt();
- VitaminCtrl5->Connect();
- if(zoomval[4] != 0) {
- VitaminCtrl5->DigitalZoomEnabled = true;
- VitaminCtrl5->DigitalZoomFactor = zoomval[4];
- }
- } else {
- // PC
- VrPowerButton10->Active = flag;
- // --------------------------------------
- saveError("Disattivazione video 1");
- VitaminCtrl5->Disconnect();
- }
- VrPowerButton10->Enabled = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton11Click(TObject *Sender)
- {
- bool flag;
- VitaminCtrl6->Visible = true;
- if(isdemo) return;
- flag = VrPowerButton11->Active;
- if(flag) {
- saveError("Attivazione video 6");
- A(5) = false;
- VitaminCtrl6->AutoServerModelType = true;
- VitaminCtrl6->EventTypes = 0;
- VitaminCtrl6->RemoteIPAddr = ip[5];
- VitaminCtrl6->UserName = login[5];
- VitaminCtrl6->Password = password[5];
- VitaminCtrl6->AutoReconnect = true;
- VitaminCtrl6->ReadWriteTimeout = Edit3->Text.ToInt();
- VitaminCtrl6->Connect();
- if(zoomval[5] != 0) {
- VitaminCtrl6->DigitalZoomEnabled = true;
- VitaminCtrl6->DigitalZoomFactor = zoomval[5];
- }
- } else {
- saveError("Disattivazione video 6");
- // PC
- VrPowerButton12->Active = flag;
- // --------------------------------------
- VitaminCtrl6->Disconnect();
- }
- VrPowerButton12->Enabled = flag;
- }
- //---------------------------------------------------------------------------
- void TForm1::loadSetup()
- {
- register int i;
- int idx = 0;
- char classifier[128];
- int millisec;
- int vNum;
- long maxSize;
- int buffSize;
- for(i=0;i!=6;i++)
- VitaminCtrl[i]->AutoAVISettings = DBCheckBox55->Checked;
- // PC
- path = ObtainVideoPath();
- //--------------------------
- // PC 2006-12-18
- //
- // commented this line
- // provocava la cancellazione iniziale di tutti gli errori
- // saveError("Lettura setup");
- //----------------------------------
- DBISAMTable11->Open();
- DBISAMTable3->First();
- DBISAMTable11->First();
- while(!DBISAMTable3->Eof) {
- vNum = DBISAMTable3->FieldByName("Numero")->AsInteger;
- ip[vNum-1] = DBISAMTable3->FieldByName("Ip")->AsString;
- VitaminCtrl[vNum-1]->DarwinConnection = DBISAMTable3->FieldByName("Darwin")->AsBoolean;
- // FB 2006-14-12
- if((extractFace[vNum-1] = DBISAMTable3->FieldByName("Faccia")->AsBoolean) == TRUE) {
- nameHaar[vNum-1] = DBISAMTable3->FieldByName("Classificatore")->AsString;
- if(nameHaar[vNum-1].Length() < 1) {
- extractFace[vNum-1] = false;
- saveError("Non specificato classificatore video numero : " + vNum-1);
- } else {
- nameHaar[vNum-1] = DBISAMTable3->FieldByName("Classificatore")->AsString;
- classifierX[vNum-1] = DBISAMTable3->FieldByName("DimX")->AsInteger;
- classifierY[vNum-1] = DBISAMTable3->FieldByName("DimY")->AsInteger;
- lstrcpy(classifier,nameHaar[vNum-1].c_str());
- if((facce[vNum-1] = (CvHaarClassifierCascade*)cvLoad(classifier, 0, 0, 0 )) == NULL) {
- saveError("Errore classificatore" + nameHaar[vNum-1]);
- extractFace[vNum-1] = false;
- }
- }
- }
- storage = cvCreateMemStorage(0);
- recadora = DBISAMTable5->FieldByName("Autostartrec")->AsBoolean;
- // ------------------------------------------------------
- hosts[vNum-1] = DBISAMTable3->FieldByName("Host")->AsString;
- videoactive[vNum-1] = DBISAMTable3->FieldByName("Active")->AsBoolean;
- login[vNum-1] = DBISAMTable3->FieldByName("Login")->AsString;
- password[vNum-1] = DBISAMTable3->FieldByName("Password")->AsString;
- MotionTimeout[vNum-1] = DBISAMTable3->FieldByName("Timeout")->AsInteger;
- VrProgressBar1->MaxValue = MotionTimeout[vNum-1];
- millisec = DBEdit16->Text.ToInt();
- if(millisec != 0)
- VitaminCtrl[idx]->ReconnectionWait = millisec;
- iris[idx] = DBISAMTable3->FieldByName("Irisauto")->AsBoolean;
- frate[idx] = DBISAMTable3->FieldByName("Framerate")->AsInteger;
- if(!DBCheckBox55->Checked) {
- VitaminCtrl[idx]->AVIVideoSizeByStream = false;
- VitaminCtrl[idx]->AVIVideoHeight = 480;
- VitaminCtrl[idx]->AVIVideoWidth = 640;
- } else
- VitaminCtrl[idx]->AVIVideoSizeByStream = true;
- idx++;
- DBISAMTable3->Next();
- DBISAMTable11->Next();
- }
- for(i=0;i!=6;i++) {
- if(DBCheckBox61->Checked )
- VitaminCtrl[i]->ConnectionTimeout = DBEdit32->Text.ToInt();
- VitaminCtrl[i]->AutoServerModelType = true;
- VitaminCtrl[i]->Deblocking = DBCheckBox58->Checked;
- VitaminCtrl[i]->DDrawOnePass = DBCheckBox57->Checked;
- // PC
- VitaminCtrl[i]->DisplayErrorMsg = false;
- // ----------------------------------
- VitaminCtrl[i]->DisplayMotionFrame = 0;
- AA(i) = false;
- }
- minx = DBISAMTable5->FieldByName("Minx")->AsInteger;
- miny = DBISAMTable5->FieldByName("Miny")->AsInteger;
- maxerrori = DBISAMTable5->FieldByName("Errori")->AsInteger;
- maxSize = DBEdit44->Text.ToInt();
- if(maxSize > 0) {
- for(int i=0;i!=6;i++)
- VitaminCtrl[i]->MaxFileSize = maxSize;
- }
- deleteafter =DBISAMTable5->FieldByName("Deleteafter")->AsInteger;
- buffSize = DBEdit31->Text.ToInt();
- convertStr2Wchar("irisauto");
- for(i=0;i!=6;i++) {
- if(iris[i])
- VitaminCtrl[i]->SendCameraCommand(destTmp, 10000);
- if(buffSize >= 256000 && buffSize < 20000000)
- VitaminCtrl1->PreBufferMemorySize = buffSize;
- }
- setCtrlConnection(DBCheckBox62->Checked);
- ramDisk.printf("%1c:", DBEdit20->Text.c_str());
- // PC
- // moved here. Before was inside loop
- SearchFaceInterval = (DBEdit15->Text.ToInt() * 1000) / 6;
- Timer1->Interval = SearchFaceInterval;
- // --------------------------
- Timer1->Enabled = true;
- // PC 2006-12-15
- tmrDelete->Enabled = true;
- //---------------------
- setDisplayPeriod();
- tmrMonitorMessage->Enabled = false;
- NMUDPMonitor->RemoteHost = dbeRemoteHost->Text;
- NMUDPMonitor->RemotePort = StrToInt(dbeRemotePort->Text);
- NMUDPMonitor->LocalPort = StrToInt(dbeLocalPort->Text);
- tmrMonitorMessage->Interval = StrToInt(dbeMonitorInterval->Text) * 1000;
- if (tmrMonitorMessage->Interval > 0)
- tmrMonitorMessage->Enabled = true;
- // PC 2005-12-18
- saveError("Lettura setup eseguita");
- //--------------------
- }
- int TForm1::createAviRecord(int video)
- {
- AnsiString tmp;
- time_t first;
- TDateTime DateTime;
- AnsiString dirTocreate;
- DBISAMTable1->Insert();
- first = time(NULL);
- DateTime = Time(); // store the current date and time
- DBISAMTable1->FieldByName("Time")->AsInteger = (long) first;
- DBISAMTable1->FieldByName("Data")->AsDateTime = DateToStr(Date());
- DBISAMTable1->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
- DBISAMTable1->FieldByName("Video")->AsInteger = video;
- DBISAMTable1->Post();
- DBISAMTable1->FindLast();
- DBISAMTable1->Edit();
- record[video-1] = DBISAMTable1->FieldByName("Record")->AsInteger;
- dirTocreate.printf("%s\\Vivotek%d_%d", path, video, record[video-1]);
- DBISAMTable1->FieldByName("Path")->AsString = dirTocreate;
- DBISAMTable1->Post();
- DBISAMTable1->FlushBuffers();
- CreateDirectory(dirTocreate.c_str(), NULL);
- VitaminCtrl[video-1]->AVIPath = dirTocreate;
- return record[video-1];
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton2Click(TObject *Sender)
- {
- bool flag = VrPowerButton2->Active;
- fsm1 = 0;
- if(flag) {
- VrPowerButton2->Caption = "Ferma";
- if(!DBCheckBox55->Checked)
- VitaminCtrl1->AVIVideoFrameRate = frate[0];
- VitaminCtrl1->EventTypes = 7;
- } else {
- if(AA(0)) {
- // PC
- StopAVIRecord(0);
- // -------------------
- saveError ("Stop Registrazione/Analisi camera 1");
- }
- VrPowerButton2->Caption = "Analisi";
- VitaminCtrl1->EventTypes = 0;
- AA(0) = false;
- }
- A(0) = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton4Click(TObject *Sender)
- {
- bool flag = VrPowerButton4->Active;
- fsm2 = 0;
- if(flag) {
- VrPowerButton4->Caption = "Ferma";
- if(!DBCheckBox55->Checked)
- VitaminCtrl2->AVIVideoFrameRate = frate[1];
- VitaminCtrl2->EventTypes = 7;
- } else {
- if(AA(1)) {
- // PC
- StopAVIRecord(1);
- // -------------------
- saveError ("Stop Registrazione/Analisi camera 2");
- }
- VrPowerButton4->Caption = "Analisi";
- VitaminCtrl2->EventTypes = 0;
- AA(1) = false;
- }
- A(1) = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton6Click(TObject *Sender)
- {
- bool flag = VrPowerButton6->Active;
- fsm3 = 0;
- if(flag) {
- VrPowerButton6->Caption = "Ferma";
- if(!DBCheckBox55->Checked)
- VitaminCtrl3->AVIVideoFrameRate = frate[2];
- VitaminCtrl3->EventTypes = 7;
- } else {
- if(AA(2)) {
- // PC
- StopAVIRecord(2);
- // -------------------
- saveError ("Stop Registrazione/Analisi camera 3");
- }
- VrPowerButton6->Caption = "Analisi";
- VitaminCtrl3->EventTypes = 0;
- AA(2) = false;
- }
- A(2) = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton8Click(TObject *Sender)
- {
- bool flag = VrPowerButton8->Active;
- fsm4 = 0;
- if(flag) {
- VrPowerButton8->Caption = "Ferma";
- if(!DBCheckBox55->Checked)
- VitaminCtrl4->AVIVideoFrameRate = frate[3];
- VitaminCtrl4->EventTypes = 7;
- } else {
- if(AA(3)) {
- // PC
- StopAVIRecord(3);
- // -------------------
- saveError ("Stop Registrazione/Analisi camera 4");
- }
- VrPowerButton8->Caption = "Analisi";
- VitaminCtrl4->EventTypes = 0;
- AA(3) = false;
- }
- A(3) = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton10Click(TObject *Sender)
- {
- bool flag = VrPowerButton10->Active;
- fsm5 = 0;
- if(flag) {
- VrPowerButton10->Caption = "Ferma";
- if(!DBCheckBox55->Checked)
- VitaminCtrl5->AVIVideoFrameRate = frate[4];
- VitaminCtrl5->EventTypes = 7;
- } else {
- if(AA(4)) {
- // PC
- StopAVIRecord(4);
- // -------------------
- saveError ("Stop Registrazione/Analisi camera 5");
- }
- VrPowerButton10->Caption = "Analisi";
- VitaminCtrl5->EventTypes = 0;
- AA(4) = false;
- }
- A(4) = flag;
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Timer1Timer(TObject *Sender)
- {
- static bool flag = false;
- AnsiString S;
- int v;
- IplImage *image;
- static __int64 diskInit;
- static int physInit;
- static int pageInit;
- static int virtInit;
- AnsiString file, file2;
- static int index = 0;
- Timer1->Enabled = false;
- MEMORYSTATUS ms;
- ms.dwLength = sizeof(MEMORYSTATUS);
- GlobalMemoryStatus(&ms);
- __int64 AmtFree = DiskFree(0);
- __int64 Total = DiskSize(0);
- if(!flag) {
- flag = true;
- diskInit = AmtFree/1024;
- physInit = ms.dwAvailPhys/1024;
- pageInit = ms.dwAvailPageFile/1024;
- virtInit = ms.dwAvailVirtual/1024 ;
- }
- 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 );
- StatusBar1->SimpleText = S;
- Total = AmtFree*1024;
- if(Total < 10000)
- deleteAllRecords();
- if(AA(index)) {
- if(DBCheckBox63->Checked)
- TakeSnapshotDiProva (index);
- if(extractFace[index]) {
- if((image=getImage(true, index)) != NULL) {
- searchObject(image, index, 0);
- cvReleaseImage(&image);
- }
- }
- Timer1->Interval = SearchFaceInterval; // sec i global and shoul be contain Timer1 interval
- }
- else
- Timer1->Interval = 1;
- ++index;
- if(index == 6)
- index = 0;
- Application->ProcessMessages();
- Timer1->Enabled = true;
- }
- IplImage * TForm1::getImage(bool tipo, int video)
- {
- IplImage* image = NULL;
- AnsiString fName;
- fName.printf("g:\\video%02d.jpg" , video);
- if(FileExists(fName))
- DeleteFile(fName);
- convertStr2Wchar(fName);
- VitaminCtrl[video]->SaveSnapshot(Vitamindecoderlib_tlb::ePicFmtJpeg, destTmp);
- ImageEnIO1->LoadFromFileJpeg(fName);
- ImageEnView5->Refresh();
- image = TBitmapToIplImage(ImageEnView5->Bitmap);
- return image;
- }
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- VitaminCtrl7->AutoServerModelType = true;
- VitaminCtrl7->UserName = DBEdit4->Text;
- VitaminCtrl7->Password = DBEdit5->Text;
- VitaminCtrl7->RemoteIPAddr = DBEdit2->Text;
- VitaminCtrl7->Connect();
- if(DBEdit27->Text.ToInt() != 0) {
- VitaminCtrl7->DigitalZoomEnabled = true;
- VitaminCtrl7->DigitalZoomFactor = DBEdit27->Text.ToInt();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrCheckLed1Click(TObject *Sender)
- {
- VitaminCtrl1->DisplayMotionFrame = VrCheckLed1->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrCheckLed2Click(TObject *Sender)
- {
- VitaminCtrl2->DisplayMotionFrame = VrCheckLed2->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrCheckLed3Click(TObject *Sender)
- {
- VitaminCtrl3->DisplayMotionFrame = VrCheckLed3->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrCheckLed4Click(TObject *Sender)
- {
- VitaminCtrl4->DisplayMotionFrame = VrCheckLed4->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrCheckLed5Click(TObject *Sender)
- {
- VitaminCtrl5->DisplayMotionFrame = VrCheckLed5->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrCheckLed6Click(TObject *Sender)
- {
- VitaminCtrl6->DisplayMotionFrame = VrCheckLed6->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- VitaminCtrl7->Disconnect();
- }
- //---------------------------------------------------------------------------
- void TForm1::activateZoom()
- {
- PageControl1->ActivePageIndex = 3;
- VitaminCtrl8->Disconnect();
- Sleep(2000);
- VitaminCtrl8->AutoServerModelType = true;
- VitaminCtrl8->EventTypes = 0;
- VitaminCtrl8->RemoteIPAddr = zip;
- VitaminCtrl8->UserName = zlogin;
- VitaminCtrl8->Password = zpassword;
- VitaminCtrl8->Connect();
- }
- void TForm1::getAviname(AnsiString & filename, int video)
- {
- AnsiString buffer;
- TSearchRec sr;
- int iAttributes = 0;
- iAttributes |= faReadOnly;
- iAttributes |= faHidden;
- iAttributes |= faSysFile;
- iAttributes |= faVolumeID;
- iAttributes |= faDirectory;
- iAttributes |= faArchive;
- iAttributes |= faAnyFile;
- buffer = DBISAMTable1->FieldByName("Path")->AsString;
- filename.printf("%s\\*.avi", buffer);
- if (FindFirst(filename, iAttributes, sr) == 0)
- filename.printf("%s\\%s",buffer, sr.Name);
- else
- filename = "";
- FindClose(sr);
- }
- //-------------------------------------------------
- // PC
- AnsiString __fastcall TForm1::ObtainVideoPath(void)
- {
- char pathChar[256];
- AnsiString OutString;
- OutString = DBISAMTable5->FieldByName("VideoDir")->AsString;
- if (OutString.IsEmpty()) {
- // field is empty so take current dir
- getcwd(pathChar, 256);
- OutString = pathChar;
- }
- return OutString;
- }
- //-------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- AnsiString str;
- // PC
- // Spostato il settaggio della variabile 'path'
- // nella loadSetup
- // ----------------------------
- // PC
- // useful for checking one instance only
- Caption = Application->Title;
- // ----------------------------
- DBISAMDatabase1->Connected = false;
- // PC
- DBISAMDatabase1->Directory = ReadDBPathFromINI();
- //---------------------------------
- DBISAMDatabase1->Connected = true;
- RepairTables();
- // PC
- // Activate all tables
- DBISAMTable1->Active = true;
- DBISAMTable2->Active = true;
- DBISAMTable3->Active = true;
- DBISAMTable4->Active = true;
- DBISAMTable5->Active = true;
- DBISAMTable6->Active = true;
- DBISAMTable7->Active = true;
- DBISAMTable8->Active = true;
- DBISAMTable9->Active = true;
- DBISAMTable10->Active = true;
- tblPanoramicheVisual->Active = true;
- //-----------------------
- VitaminCtrl[0] = VitaminCtrl1;
- VitaminCtrl[1] = VitaminCtrl2;
- VitaminCtrl[2] = VitaminCtrl3;
- VitaminCtrl[3] = VitaminCtrl4;
- VitaminCtrl[4] = VitaminCtrl5;
- VitaminCtrl[5] = VitaminCtrl6;
- VrUL[0] = VrUserLed3;
- VrUL[1] = VrUserLed1;
- VrUL[2] = VrUserLed2;
- VrUL[3] = VrUserLed4;
- VrUL[4] = VrUserLed5;
- VrUL[5] = VrUserLed6;
- VrULActive[0] = VrUserLed7;
- VrULActive[1] = VrUserLed8;
- VrULActive[2] = VrUserLed9;
- VrULActive[3] = VrUserLed10;
- VrULActive[4] = VrUserLed14;
- VrULActive[5] = VrUserLed13;
- for(int i =0;i!=6;i++) {
- VitaminCtrl[i]->MaxFileSize = 700000000;
- VitaminCtrl[i]->EventTypes = 0;
- }
- // load packet header in monitor message buffer
- LoadSFPacketHeader (SFPacketToSend);
- }
- //---------------------------------------------------------------------------
- void TForm1::saveImage(int video)
- {
- AnsiString filename;
- int x, y;
- long ltime;
- bool ch = DBISAMTable5->FieldByName("Saveimage")->AsBoolean;
- if(!ch || !motion[video])
- return;
- motion[video] = false;
- TDateTime DateTime;
- AnsiString dirTocreate;
- ltime = time(NULL);
- DBISAMTable8->Insert();
- DateTime = Time(); // store the current date and time
- DBISAMTable8->FieldByName("Data")->AsDateTime = DateToStr(Date());
- DBISAMTable8->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
- // PC
- // video is not correct!. video+1 yes.
- DBISAMTable8->FieldByName("Video")->AsInteger = video+1;
- // -----------------------------------------------------
- DBISAMTable8->FieldByName("Time")->AsInteger = (long) ltime;
- filename.printf("%s\\img.jpg", path);
- ImageEnIO1->SaveToFileJpeg(filename);
- ImageEnIO4->LoadFromFileJpeg(filename);
- DBISAMTable8->Post();
- }
- struct orari {
- int giorno;
- bool oraminuti[48];
- } orario[7];
- void TForm1::loadOrario(void)
- {
- int giorno;
- DBISAMTable6->First();
- while(!DBISAMTable6->Eof) {
- giorno = DBISAMTable6->FieldByName("Numero")->AsInteger;
- orario[giorno-1].oraminuti[0] = DBISAMTable6->FieldByName("A0000")->AsBoolean;
- orario[giorno-1].oraminuti[1] = DBISAMTable6->FieldByName("A0030")->AsBoolean;
- orario[giorno-1].oraminuti[2] = DBISAMTable6->FieldByName("A0100")->AsBoolean;
- orario[giorno-1].oraminuti[3] = DBISAMTable6->FieldByName("A0130")->AsBoolean;
- orario[giorno-1].oraminuti[4] = DBISAMTable6->FieldByName("A0200")->AsBoolean;
- orario[giorno-1].oraminuti[5] = DBISAMTable6->FieldByName("A0230")->AsBoolean;
- orario[giorno-1].oraminuti[6] = DBISAMTable6->FieldByName("A0300")->AsBoolean;
- orario[giorno-1].oraminuti[7] = DBISAMTable6->FieldByName("A0330")->AsBoolean;
- orario[giorno-1].oraminuti[8] = DBISAMTable6->FieldByName("A0400")->AsBoolean;
- orario[giorno-1].oraminuti[9] = DBISAMTable6->FieldByName("A0430")->AsBoolean;
- orario[giorno-1].oraminuti[10] = DBISAMTable6->FieldByName("A0500")->AsBoolean;
- orario[giorno-1].oraminuti[11] = DBISAMTable6->FieldByName("A0530")->AsBoolean;
- orario[giorno-1].oraminuti[12] = DBISAMTable6->FieldByName("A0600")->AsBoolean;
- orario[giorno-1].oraminuti[13] = DBISAMTable6->FieldByName("A0630")->AsBoolean;
- orario[giorno-1].oraminuti[14] = DBISAMTable6->FieldByName("A0700")->AsBoolean;
- orario[giorno-1].oraminuti[15] = DBISAMTable6->FieldByName("A0730")->AsBoolean;
- orario[giorno-1].oraminuti[16] = DBISAMTable6->FieldByName("A0800")->AsBoolean;
- orario[giorno-1].oraminuti[17] = DBISAMTable6->FieldByName("A0830")->AsBoolean;
- orario[giorno-1].oraminuti[18] = DBISAMTable6->FieldByName("A0900")->AsBoolean;
- orario[giorno-1].oraminuti[19] = DBISAMTable6->FieldByName("A0930")->AsBoolean;
- orario[giorno-1].oraminuti[20] = DBISAMTable6->FieldByName("A1000")->AsBoolean;
- orario[giorno-1].oraminuti[21] = DBISAMTable6->FieldByName("A1030")->AsBoolean;
- orario[giorno-1].oraminuti[22] = DBISAMTable6->FieldByName("A1100")->AsBoolean;
- orario[giorno-1].oraminuti[23] = DBISAMTable6->FieldByName("A1130")->AsBoolean;
- orario[giorno-1].oraminuti[24] = DBISAMTable6->FieldByName("A1200")->AsBoolean;
- orario[giorno-1].oraminuti[25] = DBISAMTable6->FieldByName("A1230")->AsBoolean;
- orario[giorno-1].oraminuti[26] = DBISAMTable6->FieldByName("A1300")->AsBoolean;
- orario[giorno-1].oraminuti[27] = DBISAMTable6->FieldByName("A1330")->AsBoolean;
- orario[giorno-1].oraminuti[28] = DBISAMTable6->FieldByName("A1400")->AsBoolean;
- orario[giorno-1].oraminuti[29] = DBISAMTable6->FieldByName("A1430")->AsBoolean;
- orario[giorno-1].oraminuti[30] = DBISAMTable6->FieldByName("A1500")->AsBoolean;
- orario[giorno-1].oraminuti[31] = DBISAMTable6->FieldByName("A1530")->AsBoolean;
- orario[giorno-1].oraminuti[32] = DBISAMTable6->FieldByName("A1600")->AsBoolean;
- orario[giorno-1].oraminuti[33] = DBISAMTable6->FieldByName("A1630")->AsBoolean;
- orario[giorno-1].oraminuti[34] = DBISAMTable6->FieldByName("A1700")->AsBoolean;
- orario[giorno-1].oraminuti[35] = DBISAMTable6->FieldByName("A1730")->AsBoolean;
- orario[giorno-1].oraminuti[36] = DBISAMTable6->FieldByName("A1800")->AsBoolean;
- orario[giorno-1].oraminuti[37] = DBISAMTable6->FieldByName("A1830")->AsBoolean;
- orario[giorno-1].oraminuti[38] = DBISAMTable6->FieldByName("A1900")->AsBoolean;
- orario[giorno-1].oraminuti[39] = DBISAMTable6->FieldByName("A1930")->AsBoolean;
- orario[giorno-1].oraminuti[40] = DBISAMTable6->FieldByName("A2000")->AsBoolean;
- orario[giorno-1].oraminuti[41] = DBISAMTable6->FieldByName("A2030")->AsBoolean;
- orario[giorno-1].oraminuti[42] = DBISAMTable6->FieldByName("A2100")->AsBoolean;
- orario[giorno-1].oraminuti[43] = DBISAMTable6->FieldByName("A2130")->AsBoolean;
- orario[giorno-1].oraminuti[44] = DBISAMTable6->FieldByName("A2200")->AsBoolean;
- orario[giorno-1].oraminuti[45] = DBISAMTable6->FieldByName("A2230")->AsBoolean;
- orario[giorno-1].oraminuti[46] = DBISAMTable6->FieldByName("A2300")->AsBoolean;
- orario[giorno-1].oraminuti[47] = DBISAMTable6->FieldByName("A2330")->AsBoolean;
- DBISAMTable6->Next();
- }
- }
- void __fastcall TForm1::VrDemoButton7Click(TObject *Sender)
- {
- DBISAMTable1->FlushBuffers();
- DBISAMTable2->FlushBuffers();
- DBISAMTable3->FlushBuffers();
- DBISAMTable4->FlushBuffers();
- DBISAMTable5->FlushBuffers();
- DBISAMTable6->FlushBuffers();
- DBISAMTable7->FlushBuffers();
- DBISAMTable8->FlushBuffers();
- Form1->Close();
- // Application->Terminate();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton8Click(TObject *Sender)
- {
- zip = ip[0];
- zlogin = login[0];
- zpassword = password[0];
- activateZoom();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton9Click(TObject *Sender)
- {
- zip = ip[1];
- zlogin = login[1];
- zpassword = password[1];
- activateZoom();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton10Click(TObject *Sender)
- {
- zip = ip[2];
- zlogin = login[2];
- zpassword = password[2];
- activateZoom();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton11Click(TObject *Sender)
- {
- zip = ip[3];
- zlogin = login[3];
- zpassword = password[3];
- activateZoom();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton13Click(TObject *Sender)
- {
- zip = ip[5];
- zlogin = login[5];
- zpassword = password[5];
- activateZoom();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button5Click(TObject *Sender)
- {
- AnsiString tmp;
- tmp.printf("http://%s", ip[0]);
- Edit1->Text = tmp;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button6Click(TObject *Sender)
- {
- AnsiString tmp;
- tmp.printf("http://%s", ip[1]);
- Edit1->Text = tmp;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button7Click(TObject *Sender)
- {
- AnsiString tmp;
- tmp.printf("http://%s", ip[2]);
- Edit1->Text = tmp;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button8Click(TObject *Sender)
- {
- AnsiString tmp;
- tmp.printf("http://%s", ip[3]);
- Edit1->Text = tmp;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button9Click(TObject *Sender)
- {
- AnsiString tmp;
- tmp.printf("http://%s", ip[4]);
- Edit1->Text = tmp;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button10Click(TObject *Sender)
- {
- AnsiString tmp;
- tmp.printf("http://%s", ip[5]);
- Edit1->Text = tmp;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- CppWebBrowser2->GoBack();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- CppWebBrowser2->GoBack();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton15Click(TObject *Sender)
- {
- static bool flag = true;
- VitaminCtrl7->MDEditMode = flag;
- flag = !flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrPowerButton13Click(TObject *Sender)
- {
- static bool flag = true;
- if(flag) {
- VitaminCtrl8->AVIPath = VrStrEdit1->Text;
- VitaminCtrl8->StartAVIConversion();
- } else
- VitaminCtrl8->StopAVIConversion();
- flag = !flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrShadowButton1Click(TObject *Sender)
- {
- TVariant pvInfo[2], pvData;
- unsigned char *arrayAccess;
- TDateTime DateTime;
- AnsiString dirTocreate;
- long lStartBound = 0;
- long lEndBound = 0;
- if (VitaminCtrl8->ControlStatus == 2) { // Status is Running
- VariantInit(&pvData);
- VariantInit(&pvInfo[0]); // Mette a VT_EMPTY vt
- VariantInit(&pvInfo[1]);
- VitaminCtrl8->GetSnapshot(Vitamindecoderlib_tlb::ePicFmtBmp, &pvData, &pvInfo[0]);
- SAFEARRAY* pSafeArray = pvData.parray;
- SafeArrayGetLBound(pSafeArray, 1, &lStartBound);
- SafeArrayGetUBound(pSafeArray, 1, &lEndBound);
- SafeArrayAccessData(pSafeArray, (void **) &arrayAccess);
- DBISAMTable7->Insert();
- ImageEnIO3->LoadFromBuffer((BYTE *) arrayAccess, lEndBound, ioBMP);
- ImageEnDBView2->Update();
- DateTime = Time(); // store the current date and time
- DBISAMTable7->FieldByName("Data")->AsDateTime = DateToStr(Date());
- DBISAMTable7->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
- DBISAMTable7->Post();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::ImageEnDBView2DblClick(TObject *Sender)
- {
- // PC
- frmView->ShowModal();
- // --------------------------
- // now the
- // if( SaveImageEnDialog1->Execute() )
- // ImageEnIO3->SaveToFile(SaveImageEnDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button11Click(TObject *Sender)
- {
- CppWebBrowser2->Navigate((TVariant)Edit1->Text.c_str());
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button13Click(TObject *Sender)
- {
- loadOrario();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrCheckLed7Click(TObject *Sender)
- {
- static bool flag = true;
- Timer2->Enabled = flag;
- flag = !flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Timer2Timer(TObject *Sender)
- {
- int giorno, indice;
- Timer2->Enabled = false;
- Word Year, Month, Day, Hour, Min, Sec, MSec;
- TDateTime DateTime = Now();
- DateTime.DecodeDate(&Year, &Month, &Day);
- DateTime.DecodeTime(&Hour, &Min, &Sec, &MSec);
- // PC 2006-14-12
- // non so perche' si cancellano solo se min==0
- // quindi lo tolgo e la procedura di cancellazione
- /*
- if(Min == 0) {
- deleteafter = DBEdit26->Text.ToInt();
- if(deleteafter)
- deleteAllrecordafter();
- }*/
- // PC
- // la cencellazione viene eseguita da un timer apposito : tmrDeleteRecord
- //
- // -------------------------
- if(Min == 0 || Min == 30) {
- giorno = DateTime.DayOfWeek();
- switch(giorno) {
- case 1:
- giorno = 6;
- break;
- case 2:
- giorno = 0;
- break;
- case 3:
- giorno = 1;
- break;
- case 4:
- giorno = 2;
- break;
- case 5:
- giorno = 3;
- break;
- case 6:
- giorno = 4;
- break;
- }
- indice = Hour * 2;
- if(Min >= 30)
- indice++;
- if(orario[giorno].oraminuti[indice])
- setON();
- else
- setOFF();
- }
- Timer2->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void TForm1::setON()
- {
- if(AnsiCompareText(ip[0], "0.0.0.0") && !A(0)) {
- VrPowerButton2->Active = true;
- VrPowerButton2Click (this);
- }
- if(AnsiCompareText(ip[1], "0.0.0.0") && !A(1)) {
- VrPowerButton4->Active = true;
- VrPowerButton4Click (this);
- }
- if(AnsiCompareText(ip[2], "0.0.0.0") && !A(2)) {
- VrPowerButton6->Active = true;
- VrPowerButton6Click (this);
- }
- if(AnsiCompareText(ip[3], "0.0.0.0") && !A(3)) {
- VrPowerButton8->Active = true;
- VrPowerButton8Click (this);
- }
- if(AnsiCompareText(ip[4], "0.0.0.0") && !A(4)) {
- VrPowerButton10->Active = true;
- VrPowerButton10Click (this);
- }
- if(AnsiCompareText(ip[5], "0.0.0.0") && !A(5)) {
- VrPowerButton12->Active = true;
- VrPowerButton12Click (this);
- }
- }
- void TForm1::setOFF()
- {
- if (VrPowerButton2->Active) {
- VrPowerButton2->Active = false;
- VrPowerButton2Click (this);
- }
- if (VrPowerButton4->Active) {
- VrPowerButton4->Active = false;
- VrPowerButton4Click (this);
- }
- if (VrPowerButton6->Active) {
- VrPowerButton6->Active = false;
- VrPowerButton6Click (this);
- }
- if (VrPowerButton8->Active) {
- VrPowerButton8->Active = false;
- VrPowerButton8Click (this);
- }
- if (VrPowerButton10->Active) {
- VrPowerButton10->Active = false;
- VrPowerButton10Click (this);
- }
- if (VrPowerButton12->Active) {
- VrPowerButton12->Active = false;
- VrPowerButton12Click (this);
- }
- }
- void __fastcall TForm1::Button14Click(TObject *Sender)
- {
- DBISAMTable8->First();
- while(!DBISAMTable8->Eof)
- DBISAMTable8->Delete();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton16Click(TObject *Sender)
- {
- int i;
- DBISAMTable6->First();
- for(i=0;i!=7;i++) {
- DBISAMTable6->Edit();
- switch(i) {
- case 0:
- if(VrCheckLed8->Checked)
- setOrario(true);
- break;
- case 1:
- if(VrCheckLed9->Checked)
- setOrario(true);
- break;
- case 2:
- if(VrCheckLed10->Checked)
- setOrario(true);
- break;
- case 3:
- if(VrCheckLed11->Checked)
- setOrario(true);
- break;
- case 4:
- if(VrCheckLed12->Checked)
- setOrario(true);
- break;
- case 5:
- if(VrCheckLed13->Checked)
- setOrario(true);
- break;
- case 6:
- if(VrCheckLed14->Checked)
- setOrario(true);
- break;
- }
- DBISAMTable6->Post();
- DBISAMTable6->Next();
- }
- }
- //---------------------------------------------------------------------------
- void TForm1::setOrario(bool flag)
- {
- DBISAMTable6->FieldByName("0000")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0030")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0100")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0130")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0200")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0230")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0300")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0330")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0400")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0430")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0500")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0530")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0600")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0630")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0700")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0730")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0800")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0830")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0900")->AsBoolean = flag;
- DBISAMTable6->FieldByName("0930")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1000")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1030")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1100")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1130")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1200")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1230")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1300")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1330")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1400")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1430")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1500")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1530")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1600")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1630")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1700")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1730")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1800")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1830")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1900")->AsBoolean = flag;
- DBISAMTable6->FieldByName("1930")->AsBoolean = flag;
- DBISAMTable6->FieldByName("2000")->AsBoolean = flag;
- DBISAMTable6->FieldByName("2030")->AsBoolean = flag;
- DBISAMTable6->FieldByName("2100")->AsBoolean = flag;
- DBISAMTable6->FieldByName("2130")->AsBoolean = flag;
- DBISAMTable6->FieldByName("2200")->AsBoolean = flag;
- DBISAMTable6->FieldByName("2230")->AsBoolean = flag;
- DBISAMTable6->FieldByName("2300")->AsBoolean = flag;
- DBISAMTable6->FieldByName("2330")->AsBoolean = flag;
- }
- void __fastcall TForm1::VrDemoButton17Click(TObject *Sender)
- {
- int i;
- DBISAMTable6->First();
- for(i=0;i!=7;i++) {
- DBISAMTable6->Edit();
- switch(i) {
- case 0:
- if(VrCheckLed8->Checked)
- setOrario(false);
- break;
- case 1:
- if(VrCheckLed9->Checked)
- setOrario(false);
- break;
- case 2:
- if(VrCheckLed10->Checked)
- setOrario(false);
- break;
- case 3:
- if(VrCheckLed11->Checked)
- setOrario(false);
- break;
- case 4:
- if(VrCheckLed12->Checked)
- setOrario(false);
- break;
- case 5:
- if(VrCheckLed13->Checked)
- setOrario(false);
- break;
- case 6:
- if(VrCheckLed14->Checked)
- setOrario(false);
- break;
- }
- DBISAMTable6->Post();
- DBISAMTable6->Next();
- }
- }
- //---------------------------------------------------------------------------
- void TForm1::deleteAllrecordafter()
- {
- time_t DateTime;
- int record;
- AnsiString buffer, filename;
- long numsec, realtime, elapsed;
- TSearchRec sr;
- int iAttributes = 0;
- numsec = deleteafter * 3600;
- DBISAMTable1->First();
- while(!DBISAMTable1->Eof) {
- DateTime = time(NULL); // store the current date and time
- realtime = DBISAMTable1->FieldByName("Time")->AsInteger;
- elapsed = (long) difftime(DateTime, realtime);
- if(elapsed >= numsec) {
- record = DBISAMTable1->FieldByName("Record")->AsInteger;
- buffer = DBISAMTable1->FieldByName("Path")->AsString;
- filename.printf("%s\\*.avi", buffer);
- iAttributes |= faReadOnly;
- iAttributes |= faHidden;
- iAttributes |= faSysFile;
- iAttributes |= faVolumeID;
- iAttributes |= faDirectory;
- iAttributes |= faArchive;
- iAttributes |= faAnyFile;
- if (FindFirst(filename, iAttributes, sr) == 0) {
- filename.printf("%s\\%s",buffer, sr.Name);
- DeleteFile(filename);
- SetCurrentDir(path);
- FindClose(sr);
- if (DirectoryExists(buffer))
- RemoveDir(buffer);
- }
- DBISAMTable2->First();
- while(!DBISAMTable2->Eof) {
- if(DBISAMTable2->FieldByName("Record")->AsInteger == record)
- DBISAMTable2->Delete();
- else
- DBISAMTable2->Next();
- }
- DBISAMTable1->Delete();
- } else
- DBISAMTable1->Next();
- }
- DBISAMTable1->FlushBuffers();
- DBISAMTable8->First();
- while(!DBISAMTable8->Eof) {
- DateTime = time(NULL); // store the current date and time
- realtime = DBISAMTable8->FieldByName("Time")->AsInteger;
- elapsed = (long) difftime(DateTime, realtime);
- if(elapsed >= numsec)
- DBISAMTable8->Delete();
- else
- DBISAMTable8->Next();
- }
- DBISAMTable8->FlushBuffers();
- }
- void __fastcall TForm1::Button15Click(TObject *Sender)
- {
- deleteafter = DBEdit26->Text.ToInt();
- if(deleteafter)
- deleteAllrecordafter();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Edit1Exit(TObject *Sender)
- {
- CppWebBrowser2->Navigate((TVariant)Edit1->Text.c_str());
- }
- //---------------------------------------------------------------------------
- void TForm1::setDisplayPeriod()
- {
- int i;
- int n = 0;
- if(!DBCheckBox53->Checked)
- return;
- if(DBCheckBox59->Checked) {
- for(i=0;i!=6;i++)
- if(A(i))
- ++n;
- for(i=0;i!=6;i++) {
- if(A(i))
- VitaminCtrl[i]->DisplayPeriod = n;
- }
- } else {
- for(i=0;i!=6;i++)
- VitaminCtrl[i]->DisplayPeriod = DBEdit28->Text.ToInt();
- }
- }
- void __fastcall TForm1::VrDemoButton14Click(TObject *Sender)
- {
- convertStr2Wchar("Scelta CODEC Audio");
- int video = DBEdit3->Text.ToInt();
- VitaminCtrl[video-1]->AutoAVISettings = false;
- VitaminCtrl[video-1]->ChooseAVIAudioCompressor(destTmp);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button16Click(TObject *Sender)
- {
- deleteAllRecords();
- }
- //---------------------------------------------------------------------------
- IplImage * TForm1::TBitmapToIplImage(Graphics::TBitmap * src)
- {
- CvRect re;
- if (!src || src->Width==0) //src->Width==0 TBitmap should come from *.bmp , but not others such as *.jpg
- {
- saveError("Errore dimensione bitmap (NULL o width=0)");
- return NULL;
- }
- if((dest = cvCreateImage(cvSize(src->Width,src->Height),IPL_DEPTH_8U,3)) == NULL) {
- saveError("Errore cvCreateImage");
- return NULL;
- }
- re.x = 0;
- re.y = 0;
- re.width = src->Width;
- re.height = src->Height;
- cvSetImageROI(dest, re);
- try
- {
- unsigned char *pLine;
- int x,y;
- for(y=0 ;y<src->Height;y++)
- {
- pLine = (unsigned char *)src->ScanLine[y];
- for(x=0 ;x <src->Width*3 ;x++)
- {
- dest->imageData[dest->widthStep*y+x]=pLine[x];
- }
- }
- }
- catch(...)
- {
- MessageBox(0,"Exception when get data ","Error", MB_OK );
- }
- return dest;
- }
- void __fastcall TForm1::VrDemoButton18Click(TObject *Sender)
- {
- int video = DBEdit3->Text.ToInt();
- convertStr2Wchar("Scelta CODEC Avi");
- VitaminCtrl[video-1]->ChooseAVIVideoCompressor(destTmp);
- }
- //---------------------------------------------------------------------------
- void TForm1::convertStr2Wchar(AnsiString src)
- {
- src.WideChar(destTmp, 256);
- }
- void __fastcall TForm1::Timer3Timer(TObject *Sender)
- {
- static int index = 0;
- Timer3->Enabled = false;
- if(AA(index)) {
- if(IsTimeout(timeout[index], index+1)) {
- VitaminCtrl[index]->StopAVIConversion();
- VrUL[index]->Active = false;
- vrLed[index]->Active = false;
- *fsm[index] = 0;
- CryptAVIHeader (record[index]);
- AA(index) = false;
- }
- }
- ++index;
- if(index == 6)
- index = 0;
- Application->ProcessMessages();
- Timer3->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl2ConnectionBroken(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel19->Visible = true;
- VitaminCtrl2->Visible = false;
- if(AA(1)) {
- // PC
- StopAVIRecord(1);
- // -------------------
- }
- VitaminCtrl2->EventTypes = 0;
- AA(1) = false;
- A(1) = false;
- saveError ("Disconnessione camera 2");
- sconnessioni[1] += 1;
- Edit4->Text = sconnessioni[1];
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl3ConnectionBroken(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel27->Visible = true;
- VitaminCtrl3->Visible = false;
- if(AA(2)) {
- // PC
- StopAVIRecord(2);
- // -------------------
- }
- VitaminCtrl3->EventTypes = 0;
- AA(2) = false;
- A(2) = false;
- saveError ("Disconnessione camera 3");
- sconnessioni[2] += 1;
- Edit5->Text = sconnessioni[2];
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl4ConnectionBroken(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel28->Visible = true;
- VitaminCtrl4->Visible = false;
- if(AA(3)) {
- // PC
- StopAVIRecord(3);
- // -------------------
- }
- VitaminCtrl4->EventTypes = 0;
- AA(3) = false;
- A(3) = false;
- saveError ("Disconnessione camera 4");
- sconnessioni[3] += 1;
- Edit6->Text = sconnessioni[3];
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl5ConnectionBroken(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel29->Visible = true;
- VitaminCtrl5->Visible = false;
- if(AA(4)) {
- // PC
- StopAVIRecord(4);
- // -------------------
- }
- VitaminCtrl5->EventTypes = 0;
- AA(4) = false;
- A(4) = false;
- saveError ("Disconnessione camera 5");
- sconnessioni[4] += 1;
- Edit7->Text = sconnessioni[4];
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl6ConnectionBroken(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel32->Visible = true;
- VitaminCtrl6->Visible = false;
- if(AA(5)) {
- // PC
- StopAVIRecord(5);
- // -------------------
- }
- VitaminCtrl6->EventTypes = 0;
- AA(5) = false;
- A(5) = false;
- saveError ("Disconnessione camera 6");
- sconnessioni[5] += 1;
- Edit8->Text = sconnessioni[5];
- }
- //---------------------------------------------------------------------------
- void TForm1::saveError(AnsiString message)
- {
- TDateTime DateTime;
- AnsiString dirTocreate;
- int dacancellare;
- int numRecord = DBISAMTable9->RecordCount;
- if(numRecord > maxerrori) {
- dacancellare = numRecord - maxerrori;
- DBISAMTable9->First();
- for(int i=0;i!=dacancellare;i++)
- DBISAMTable9->Delete();
- }
- DBISAMTable9->Insert();
- DateTime = Time();
- DBISAMTable9->FieldByName("Data")->AsDateTime = DateToStr(Date());
- DBISAMTable9->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
- DBISAMTable9->FieldByName("Messaggio")->AsString = message;
- DBISAMTable9->Post();
- }
- void __fastcall TForm1::VitaminCtrl2ConnectionOK(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel19->Visible = false;
- VitaminCtrl2->Visible = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl3ConnectionOK(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel27->Visible = false;
- VitaminCtrl3->Visible = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl4ConnectionOK(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel28->Visible = false;
- VitaminCtrl4->Visible = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl5ConnectionOK(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel29->Visible = false;
- VitaminCtrl5->Visible = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl6ConnectionOK(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel32->Visible = false;
- VitaminCtrl6->Visible = true;
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- void __fastcall TForm1::DBCheckBox61Click(TObject *Sender)
- {
- DBEdit32->ReadOnly = !DBCheckBox61->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::DBCheckBox59Click(TObject *Sender)
- {
- DBEdit28->ReadOnly = DBCheckBox59->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::DBCheckBox53Click(TObject *Sender)
- {
- DBCheckBox59->ReadOnly = !DBCheckBox53->Checked;
- DBEdit28->ReadOnly = DBCheckBox59->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl1ConnectionBroken(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel44->Visible = true;
- VitaminCtrl1->Visible = false;
- if(AA(0)) {
- // PC
- StopAVIRecord(0);
- // -------------------
- /*
- VitaminCtrl1->StopAVIConversion();
- // PC
- CryptAVIHeader (record[0]);
- // ----------------------------
- */
- }
- VitaminCtrl1->EventTypes = 0;
- AA(0) = false;
- A(0) = false;
- saveError ("Disconnessione camera 1");
- sconnessioni[0] += 1;
- Edit2->Text = sconnessioni[0];
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl1ConnectionOK(TObject *Sender,
- EConnectionType eConnType)
- {
- VrLabel44->Visible = false;
- VitaminCtrl1->Visible = true;
- }
- //---------------------------------------------------------------------------
- void TForm1::setCtrlConnection(bool flag)
- {
- if(flag) {
- VitaminCtrl1->OnConnectionBroken = VitaminCtrl1ConnectionBroken;
- VitaminCtrl1->OnConnectionOK = VitaminCtrl1ConnectionOK;
- VitaminCtrl2->OnConnectionBroken = VitaminCtrl2ConnectionBroken;
- VitaminCtrl2->OnConnectionOK = VitaminCtrl2ConnectionOK;
- VitaminCtrl3->OnConnectionBroken = VitaminCtrl3ConnectionBroken;
- VitaminCtrl3->OnConnectionOK = VitaminCtrl3ConnectionOK;
- VitaminCtrl4->OnConnectionBroken = VitaminCtrl4ConnectionBroken;
- VitaminCtrl4->OnConnectionOK = VitaminCtrl4ConnectionOK;
- VitaminCtrl5->OnConnectionBroken = VitaminCtrl5ConnectionBroken;
- VitaminCtrl5->OnConnectionOK = VitaminCtrl5ConnectionOK;
- VitaminCtrl6->OnConnectionBroken = VitaminCtrl6ConnectionBroken;
- VitaminCtrl6->OnConnectionOK = VitaminCtrl6ConnectionOK;
- } else {
- VitaminCtrl1->OnConnectionBroken = 0;
- VitaminCtrl1->OnConnectionOK = 0;
- VitaminCtrl2->OnConnectionBroken = 0;
- VitaminCtrl2->OnConnectionOK = 0;
- VitaminCtrl3->OnConnectionBroken = 0;
- VitaminCtrl3->OnConnectionOK = 0;
- VitaminCtrl4->OnConnectionBroken = 0;
- VitaminCtrl4->OnConnectionOK = 0;
- VitaminCtrl5->OnConnectionBroken = 0;
- VitaminCtrl5->OnConnectionOK = 0;
- VitaminCtrl6->OnConnectionBroken = 0;
- VitaminCtrl6->OnConnectionOK = 0;
- }
- }
- void __fastcall TForm1::DBCheckBox62Click(TObject *Sender)
- {
- setCtrlConnection(DBCheckBox62->Checked);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button27Click(TObject *Sender)
- {
- static bool flag = false;
- Panel2->Visible = flag;
- Panel3->Visible = flag;
- Panel4->Visible = flag;
- Panel5->Visible = flag;
- Panel6->Visible = flag;
- Panel7->Visible = flag;
- // PC
- Panel19->Visible = flag;
- // --------------------
- if(flag)
- Button27->Caption = "Interfaccia normale";
- else
- Button27->Caption = "Interfaccia semplificata";
- flag = !flag;
- }
- //---------------------------------------------------------------------------
- void TForm1::deleteAllRecords()
- {
- AnsiString buffer, filename;
- TSearchRec sr;
- int record;
- int iAttributes = 0;
- DBISAMTable1->First();
- while(!DBISAMTable1->Eof) {
- record = DBISAMTable1->FieldByName("Record")->AsInteger;
- buffer = DBISAMTable1->FieldByName("Path")->AsString;
- filename.printf("%s\\*.avi", buffer);
- iAttributes |= faReadOnly;
- iAttributes |= faHidden;
- iAttributes |= faSysFile;
- iAttributes |= faVolumeID;
- iAttributes |= faDirectory;
- iAttributes |= faArchive;
- iAttributes |= faAnyFile;
- if (FindFirst(filename, iAttributes, sr) == 0) {
- SetCurrentDir(path);
- filename.printf("%s\\%s",buffer, sr.Name);
- DeleteFile(filename);
- FindClose(sr);
- if (DirectoryExists(buffer))
- RemoveDir(buffer);
- }
- DBISAMTable1->Delete();
- }
- DBISAMTable1->FlushBuffers();
- DBISAMTable1->Refresh();
- DBISAMTable4->First();
- while(!DBISAMTable4->Eof)
- DBISAMTable4->Delete();
- DBISAMTable4->FlushBuffers();
- DBISAMTable4->Refresh();
- }
- void __fastcall TForm1::btnDisplayOnOffClick(TObject *Sender)
- {
- static bool flag = true;
- for(int i=0;i!=6;i++)
- if(A(i))
- VitaminCtrl[i]->Display = flag;
- // PC
- if (flag)
- btnDisplayOnOff->Caption = "Display ON";
- else
- btnDisplayOnOff->Caption = "Display OFF";
- flag = !flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
- {
- if(Key == '\r')
- CppWebBrowser2->Navigate((TVariant)Edit1->Text.c_str());
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::btnAllOnOffClick(TObject *Sender)
- {
- // PC
- static bool Status = true; // when program start system is ON
- if (Status) {
- setOFF();
- btnAllOnOff->Caption = "Registrazioni ON";
- }
- else {
- setON();
- btnAllOnOff->Caption = "Registrazioni OFF";
- }
- Status = !Status;
- // -------------------------------------------------
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button31Click(TObject *Sender)
- {
- CheckProgramPassword();
- }
- //---------------------------------------------------------------------------
- // PC 2006-12-19
- void __fastcall TForm1::CheckProgramPassword(void)
- {
- // check if password is administrator
- if(Password->Text == DBEdit45->Text) {
- EnableDisableProtectionForAdministrator (false);
- lblUser->Caption = "Amministratore";
- PageControl1->ActivePageIndex = 1; // Video Analisi
- }
- else if (Password->Text == dbeInstPassword->Text) {
- EnableDisableProtectionForInstaller (false);
- lblUser->Caption = "Installatore";
- PageControl1->ActivePageIndex = 1; // Video Analisi
- }
- else
- Beep();
- Password->Text = "";
- }
- //---------------------------------------------------------------------------
- // PC
- void __fastcall TForm1::EnableDisableProtectionForInstaller(bool flag)
- {
- // Password->Visible = flag;
- // Button31->Visible = flag; // Password Button
- // GroupBox1->Visible = flag; // Groupbox della password
- pnlInstall1->Visible = flag; // Setup UP
- // pnlInstall2->Visible = flag; // Ricarica not more used
- Panel13->Visible = flag; // Errori
- Panel18->Visible = flag; // Browser
- pnlPassword->Visible = flag;
- Panel15->Visible = !flag; // Pannello per ESCI sulla prima TAB
- Panel9->Visible = flag;
- }
- // ----------------------------------------------------------
- //---------------------------------------------------------------------------
- // PC
- void __fastcall TForm1::EnableDisableProtectionForAdministrator(bool flag)
- {
- // PC
- EnableDisableProtectionForInstaller (flag);
- // ------------------------------
- pnlAdmin->Visible = flag; // Setup DOWN
- // Registrazioni
- Panel11->Visible = flag; // Pannello centrale Tab Video Analisi
- Panel12->Visible = flag; // Orari
- Panel17->Visible = flag; // Panoramiche
- Panel9->Visible = flag; // Panoramiche
- Panel16->Visible = flag;
- }
- //---------------------------------------------------------------------------
- // PC
- void __fastcall TForm1::EnableDisableProtectionPanelsinAnalisiTab(bool flag)
- {
- Panel2->Visible = flag;
- Panel3->Visible = flag;
- Panel4->Visible = flag;
- Panel5->Visible = flag;
- Panel6->Visible = flag;
- Panel7->Visible = flag;
- // PC
- Panel19->Visible = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::btnLogoutClick(TObject *Sender)
- {
- // PC 2007-01-15
- //--------------------------
- if (DBISAMTable5->FieldByName("Password")->AsString != "") {
- Password->Text = "";
- EnableDisableProtectionForAdministrator (true);
- EnableDisableProtectionPanelsinAnalisiTab (true);
- /*
- GroupBox1->Visible = true;
- Password->Visible = true;
- Button31->Visible = true;
- Panel16->Visible = true;
- Panel8->Visible = true;
- Panel9->Visible = true;
- Panel13->Visible = true;
- Panel18->Visible = true;
- Panel10->Visible = true;
- Panel11->Visible = true;
- Panel12->Visible = true;
- Panel15->Visible = true;
- Panel17->Visible = true;
- Panel2->Visible = true;
- Panel3->Visible = true;
- Panel4->Visible = true;
- Panel5->Visible = true;
- Panel6->Visible = true;
- Panel7->Visible = true;
- // PC
- Panel19->Visible = true;
- // ----------------------
- // Image3->Visible = true;
- */
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::CheckBox2Click(TObject *Sender)
- {
- // PC 2006-14-12
- // Aggiunto il !
- // All'interno del click la proprieta' checked non e' ancora settata
- Panel16->Visible = !CheckBox2->Checked;
- //--------------------------------------
- }
- //---------------------------------------------------------------------------
- // PC
- //
- // legge il file config.ini e cerca l'entry 'DBDirectory nella section 'Options'
- // Se la trova ne restituisce il contenuto (il path del db) altrimenti restituisce
- // la directory dell'applicazione
- // Il path restituito comprende il '\' finale
- //
- AnsiString __fastcall TForm1::ReadDBPathFromINI (void)
- {
- AnsiString OutString;
- TIniFile *ConfigurationFile = new TIniFile(ChangeFileExt(Application->ExeName, ".ini"));
- try {
- OutString = ConfigurationFile->ReadString("Options","DBDirectory",".\\Database");
- Activation = ConfigurationFile->ReadString("Register","Activation","ADFSFAAF");
- Registrato = ConfigurationFile->ReadString("Register","Registrato", "Nessuna registrazione");
- }
- __finally {
- delete ConfigurationFile;
- return OutString;
- }
- }
- // -----------------------------------------------------------------------------
- // PC
- //
- void __fastcall TForm1::CryptAVIHeader (int record)
- {
- int ret,video;
- bool Bret;
- AnsiString filename;
- MainAVIHeader CrapHeader, AVIHeader;
- unsigned char *buffer = NULL;
- TVarRec SearchValue;
- try {
- buffer = (unsigned char *) malloc(DBISAMTable1->FieldByName("AVIHead_b")->Size);
- memset (&CrapHeader, 0, sizeof(MainAVIHeader));
- // search record with file to crypt
- // search in db record number
- SearchValue=(record);
- Bret = DBISAMTable1->FindKey(&SearchValue,0);
- if (!Bret) {
- saveError ("CryptAVIHeader - FindKey - Key (Record) : "+IntToStr(record));
- return;
- }
- video = DBISAMTable1->FieldByName("Video")->AsInteger;
- getAviname(filename, video);
- ret = ReadAVIHeader (filename, &AVIHeader);
- if (ret < 0) {
- saveError ("CryptAVIHeader - ReadAVIHeader - Error : "+IntToStr(ret));
- return;
- }
- try {
- // copy AVIHeader into table
- DBISAMTable1->Edit();
- memcpy (buffer, &AVIHeader, sizeof(MainAVIHeader));
- DBISAMTable1->FieldByName("AVIHead_b")->SetData(buffer, true);
- DBISAMTable1->FieldByName("Playable")->AsBoolean = true;
- DBISAMTable1->Post();
- }
- catch (Exception &E) {
- saveError ("Exception in CryptAVIHeader : " + E.Message);
- return;
- }
- // now that AVIHeader is in db, i crap AVI file
- ret = WriteAVIHeader (filename, &CrapHeader);
- if (ret < 0) {
- saveError ("CryptAVIHeader - WriteAVIHeader - Error : "+IntToStr(ret));
- return;
- }
- }
- __finally {
- if (buffer)
- free (buffer);
- }
- }
- // -----------------------------------------------------------------------------
- // -----------------------------------------------------------------------------
- // PC 2006-14-12
- //
- void __fastcall TForm1::DeleteOldestVideo (void)
- {
- AnsiString FileName, DirectoryPath;
- int RecordField = -1;
- long numsec, realtime, elapsed;
- time_t DateTime;
- try {
- if (DBISAMTable1->RecordCount <= 0)
- return;
- // realtime = DBISAMTable1->FieldByName("Time")->AsInteger;
- // elapsed = (long) difftime(DateTime, realtime);
- // if(elapsed >= numsec) {
- // PC 2006-14-12
- //
- // only for debug
- numsec = deleteafter * 3600; // original per il calcolo in ore
- //numsec = deleteafter * 60;
- //-----------------------
- DateTime = time(NULL); // store the current date and time
- /*
- // query the record to delete
- qry2->Active = false;
- qry2->SQL->Clear();
- qry2->SQL->Add("SELECT * FROM Records Where " + IntToStr(numsec) + " < " + IntToStr(DateTime) + " - Records.Time ");
- qry2->ExecSQL();
- */
- try {
- tblRecordToDelete->Filtered = false;
- tblRecordToDelete->Filter = IntToStr(numsec) + " < " + IntToStr(DateTime) + " - Time ";
- tblRecordToDelete->Filtered = true;
- tblRecordToDelete->Active = true;
- if (tblRecordToDelete->RecordCount > 0) {
- tblRecordToDelete->Refresh();
- tblRecordToDelete->First();
- while (!tblRecordToDelete->Eof) {
- RecordField = tblRecordToDelete->FieldByName("Record")->AsInteger;
- if (!(tblRecordToDelete->FieldByName("Playable")->AsBoolean) ||
- tblRecordToDelete->FieldByName("Locked")->AsBoolean) { // is record not yet finished or locked?
- // saveError ("Cancellazione non effettuata - record in uso : " + IntToStr(RecordField));
- }
- else {
- DirectoryPath = tblRecordToDelete->FieldByName("Path")->AsString;
- DeleteVideoRecord (RecordField, DirectoryPath);
- }
- // i do a refresh so I can update eventually Locked flags setted by SFPlayer
- tblRecordToDelete->Refresh();
- tblRecordToDelete->Next();
- }
- }
- // Delete Panoramiche, if Any
- DeletePanoramiche(numsec, DateTime);
- }
- __finally {
- tblRecordToDelete->Active = false;
- tblRecordToDelete->Filtered = false;
- }
- /*
- if (qry2->RecordCount > 0) {
- qry2->First();
- while (!qry2->Eof) {
- RecordField = qry2->FieldByName("Record")->AsInteger;
- if (!(qry2->FieldByName("Playable")->AsBoolean)) { // is record not yet finished?
- saveError ("Cancellazione non effettuata - record in uso : " + IntToStr(RecordField));
- }
- else {
- DirectoryPath = qry2->FieldByName("Path")->AsString;
- DeleteVideoRecord (RecordField, DirectoryPath);
- }
- qry2->Next();
- }
- }
- */
- }
- catch (Exception &E) {
- saveError ("Exception in DeleteOldestVideo : Record(Records) = "+IntToStr(RecordField));
- }
- }
- //---------------------------------------------------------------------------
- // PC 2007-01-10
- //
- void __fastcall TForm1::DeleteVideoRecord(int RecordNumber, AnsiString DirectoryPath)
- {
- try {
- // delete current record in Records Table
- tblRecordToDelete->Delete();
- // Delete all FaceFrame with the same 'Record'
- qry->Active = false;
- qry->SQL->Clear();
- qry->SQL->Add("DELETE FROM FaceFrame Where FaceFrame.Record = " +IntToStr(RecordNumber));
- qry->ExecSQL();
- DBISAMTable2->FlushBuffers();
- /*
- qry->Active = false;
- qry->SQL->Clear();
- qry->SQL->Add("DELETE FROM Records Where Records.Record = " +IntToStr(RecordNumber));
- qry->ExecSQL();
- DBISAMTable1->FlushBuffers();
- */
- if (DirectoryExists(DirectoryPath))
- DeleteDirectory (DirectoryPath);
- else
- saveError("DeleteVideoRecord - Errore cancellazione directory " + DirectoryPath);
- }
- catch (Exception &E) {
- saveError ("Exception in DeleteVideoRecord : Record(Records) = "+IntToStr(RecordNumber));
- }
- }
- //---------------------------------------------------------------------------
- // PC 2006-14-12
- //
- void __fastcall TForm1::DeleteDirectory(AnsiString DirectoryPath)
- {
- /*
- // now this is not working
- //
- SHFILEOPSTRUCT FileOperation;
- char FilePath[1024];
- int ret;
- bool bret;
- FileOperation.hwnd = Application->Handle;
- FileOperation.wFunc = FO_DELETE;
- strcpy(FilePath, AnsiString(DirectoryPath + "\\*.avi").c_str());
- FileOperation.pFrom = FilePath;
- FileOperation.pTo = 0;
- FileOperation.fFlags = FOF_NOCONFIRMATION |
- FOF_SILENT;
- ret = SHFileOperation(&FileOperation);
- if (ret > 0) {
- saveError ("SHFileOperation error - " + IntToStr(ret));
- return;
- }
- ret = RemoveDir(DirectoryPath);
- */
- //------------------------------------------------
- TSearchRec sr;
- AnsiString filename;
- int iAttributes = 0;
- bool BRet;
- filename.printf("%s\\*.avi", DirectoryPath);
- iAttributes |= faReadOnly;
- iAttributes |= faHidden;
- iAttributes |= faSysFile;
- iAttributes |= faVolumeID;
- iAttributes |= faDirectory;
- iAttributes |= faArchive;
- iAttributes |= faAnyFile;
- if (FindFirst(filename, iAttributes, sr) == 0) {
- // SetCurrentDir(path);
- filename.printf("%s\\%s",DirectoryPath, sr.Name);
- DeleteFile(filename);
- FindClose(sr);
- if (DirectoryExists(DirectoryPath)) {
- BRet = RemoveDir(DirectoryPath);
- if (!BRet)
- saveError ("Cancellazione - Errore cancellazione directory " + DirectoryPath);
- }
- }
- else
- saveError ("Cancellazione - File non trovati in " + DirectoryPath);
- }
- // -----------------------------------------------------------------------------
- void __fastcall TForm1::tmrDeleteTimer(TObject *Sender)
- {
- //---------------------------------------------------------------------------
- // PC 2006-12-15
- //
- // esegue la cancellazione dei record vecchi
- tmrDelete->Enabled = false;
- DeleteOldestVideo ();
- tmrDelete->Enabled = true;
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- // PC 2006-12-18
- //
- void __fastcall TForm1::RepairTables(void)
- {
- TDate Today;
- try {
- // Repair
- if (DBISAMTable1->VerifyTable())
- DBISAMTable1->RepairTable (false);
- if (DBISAMTable2->VerifyTable())
- DBISAMTable2->RepairTable (false);
- if (DBISAMTable3->VerifyTable())
- DBISAMTable3->RepairTable (false);
- if (DBISAMTable4->VerifyTable())
- DBISAMTable4->RepairTable (false);
- if (DBISAMTable5->VerifyTable())
- DBISAMTable5->RepairTable (false);
- if (DBISAMTable6->VerifyTable())
- DBISAMTable6->RepairTable (false);
- if (DBISAMTable7->VerifyTable())
- DBISAMTable7->RepairTable (false);
- if (DBISAMTable8->VerifyTable())
- DBISAMTable8->RepairTable (false);
- if (DBISAMTable9->VerifyTable())
- DBISAMTable9->RepairTable (false);
- if (DBISAMTable10->VerifyTable())
- DBISAMTable10->RepairTable (false);
- if (NecessaryToOptimize()) {
- // Optimize
- DBISAMTable1->OptimizeTable ("",false);
- DBISAMTable2->OptimizeTable ("",false);
- DBISAMTable3->OptimizeTable ("",false);
- DBISAMTable4->OptimizeTable ("",false);
- DBISAMTable5->OptimizeTable ("",false);
- DBISAMTable6->OptimizeTable ("",false);
- DBISAMTable7->OptimizeTable ("",false);
- DBISAMTable8->OptimizeTable ("",false);
- DBISAMTable9->OptimizeTable ("",false);
- DBISAMTable10->OptimizeTable ("",false);
- }
- }
- /*
- catch (const Exception &E) {
- if (dynamic_cast<EDatabaseError *>(E) & dynamic_cast<EDBISAMEngineError *>(E))
- if (dynamic_cast<EDBISAMEngineError &>(*E)->ErrorCode == DBISAM_OSEACCES)
- Application->MessageBox("DBISAM_OSEACCES", "Error", MB_OK);
- }
- */
- catch (const EDBISAMEngineError &E) {
- if (E.ErrorCode != DBISAM_OSEACCES) {
- DBISAMTable9->Active = true;
- saveError ("Exception in RepairTables : "+E.Message);
- DBISAMTable9->Active = false;
- }
- }
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- void __fastcall TForm1::btnSelectPathClick(TObject *Sender)
- {
- // select path directory
- AnsiString Dir = "";
- // if (SelectDirectory(Dir, TSelectDirOpts() << sdAllowCreate << sdPerformCreate << sdPrompt,SELDIRHELP))
- if (SelectDirectory("Selezione directory", "", Dir))
- DBEdit19->Text = Dir;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::DBNavigator4BeforeAction(TObject *Sender,
- TNavigateBtn Button)
- {
- if (Button == nbEdit)
- // enable Button "..." to select directory
- btnSelectPath->Enabled = true;
- else
- btnSelectPath->Enabled = false;
- }
- //---------------------------------------------------------------------------
- // PC
- bool __fastcall TForm1::IsAnyVideoActive (void)
- {
- for (int i=0; i<NUM_MAX_TELECAMERE; i++) {
- if (VitaminCtrl[i]->ControlStatus == 1 ||
- VitaminCtrl[i]->ControlStatus == 2) // is Connecting or Running
- return true;
- }
- return false;
- }
- // --------------------------------------------------------------------------
- // PC
- void __fastcall TForm1::TakeSnapshotDiProva(int video)
- {
- AnsiString fName;
- time_t first;
- TDateTime DateTime;
- fName.printf("%s\\video%02d.jpg", path, video);
- if(FileExists(fName))
- DeleteFile(fName);
- convertStr2Wchar(fName);
- VitaminCtrl[video]->SaveSnapshot(Vitamindecoderlib_tlb::ePicFmtJpeg, destTmp);
- tblPanoramicheVisual->Insert();
- ImageEnIO7->LoadFromFile(fName);
- iEnDBPanoramicaView->Update();
- first = time(NULL);
- DateTime = Time(); // store the current date and time
- tblPanoramicheVisual->FieldByName("Data")->AsDateTime = DateToStr(Date());
- tblPanoramicheVisual->FieldByName("Ora")->AsDateTime = TimeToStr(DateTime);
- tblPanoramicheVisual->FieldByName("Video")->AsInteger = video;
- tblPanoramicheVisual->Post();
- }
- // --------------------------------------------------------------------------
- // PC
- void __fastcall TForm1::PageControl1Change(TObject *Sender)
- {
- int ret;
- // here I disable all camera if Tab is Setup
- if (PageControl1->ActivePageIndex == 2) { // SETUP Page
- // enable all navigator
- DBNavigator1->Enabled = true;
- DBNavigator2->Enabled = true;
- DBNavigator4->Enabled = true;
- if (IsAnyVideoActive ()) {
- ret = Application->MessageBox ("Per editare la pagina di Setup e' necessario disabilitare le videocamere. Vuoi farlo ora?", "Messaggio", MB_YESNO);
- if (ret == IDYES) {
- setOFF();
- }
- else {
- // disable all navigator
- DBNavigator1->Enabled = false;
- DBNavigator2->Enabled = false;
- DBNavigator4->Enabled = false;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- // PC
- void __fastcall TForm1::StopAVIRecord (int i)
- {
- switch (i) {
- case 0 :
- VitaminCtrl1->StopAVIConversion();
- VrProgressBar1->Position = 0;
- VrUserLed3->Active = false;
- VrLed1->Active = false;
- // PC
- CryptAVIHeader (record[0]);
- // ----------------------------
- break;
- case 1 :
- VitaminCtrl2->StopAVIConversion();
- VrProgressBar2->Position = 0;
- VrUserLed1->Active = false;
- VrLed2->Active = false;
- // PC
- CryptAVIHeader (record[1]);
- // ----------------------------
- break;
- case 2 :
- VitaminCtrl3->StopAVIConversion();
- VrProgressBar3->Position = 0;
- VrUserLed2->Active = false;
- VrLed3->Active = false;
- // PC
- CryptAVIHeader (record[2]);
- // ----------------------------
- break;
- case 3 :
- VitaminCtrl4->StopAVIConversion();
- VrProgressBar4->Position = 0;
- VrUserLed4->Active = false;
- VrLed4->Active = false;
- // PC
- CryptAVIHeader (record[3]);
- // ----------------------------
- break;
- case 4 :
- VitaminCtrl5->StopAVIConversion();
- VrProgressBar5->Position = 0;
- VrUserLed5->Active = false;
- VrLed5->Active = false;
- // PC
- CryptAVIHeader (record[4]);
- // ----------------------------
- break;
- case 5 :
- VitaminCtrl6->StopAVIConversion();
- // VrProgressBar6->Position = 0;
- // PC
- VrProgressBar7->Position = 0;
- // -----------------------------
- VrUserLed6->Active = false;
- // PC 2007-02-01
- // VrLed6->Active = false;
- VrLed7->Active = false;
- // -------------------------
- // PC
- CryptAVIHeader (record[5]);
- // ----------------------------
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::btnSalvaPanoramicaClick(TObject *Sender)
- {
- iEnIOPanoramicaView->Params->JPEG_Quality = 90;
- // save image to file
- if (SaveImageEnDialog1->Execute())
- iEnIOPanoramicaView->SaveToFile(SaveImageEnDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::DeletePanoramiche(long numsec, time_t DateTime)
- {
- try {
- if (DBISAMTable8->RecordCount == 0)
- return;
- // query the record to delete
- qry->Active = false;
- qry->SQL->Clear();
- qry->SQL->Add("DELETE FROM Panoramica Where " + IntToStr(numsec) + " < " + IntToStr(DateTime) + " - Time ");
- qry->ExecSQL();
- // for debug - saveError ("DeletePanoramiche - Eseguito SQL");
- tblPanoramicheVisual->Refresh();
- }
- catch (const EDBISAMEngineError &E) {
- saveError ("Exception in DeletePanoramiche : " + E.Message);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::iEnDBPanoramicaViewDblClick(TObject *Sender)
- {
- btnSalvaPanoramicaClick (this);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::DBISAMTable8AfterPost(TDataSet *DataSet)
- {
- tblPanoramicheVisual->Refresh();
- }
- //---------------------------------------------------------------------------
- // PC
- // this function see if is necessary to optimize. If yes return true, if no false.
- // This function also ask confirmaton to
- bool __fastcall TForm1::NecessaryToOptimize(void)
- {
- TDate Today, LastOptimizeDate;
- bool BRet = false;
- int Ret;
- int DateDiff;
- try {
- try {
- Today = Date();
- DBISAMTable5->Active = true; // 'Generale Table'
- LastOptimizeDate = DBISAMTable5->FieldByName("LastOptimize")->AsDateTime;
- DateDiff = Today - LastOptimizeDate;
- if (DateDiff > MAX_DAYS_BEFORE_OPTIMIZE) {
- // Ask if we do optimize
- 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);
- if (Ret == IDYES) {
- DBISAMTable5->Edit();
- DBISAMTable5->FieldByName("LastOptimize")->AsDateTime = Today;
- DBISAMTable5->Post();
- BRet = true;
- }
- else
- BRet = false;
- }
- else
- BRet = false;
- }
- catch (const EDBISAMEngineError &E) {
- saveError ("Exception in NecessaryToOptimize : " + E.Message);
- }
- }
- __finally {
- DBISAMTable5->Active = false;
- return BRet;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::DBISAMTable3AfterPost(TDataSet *DataSet)
- {
- loadSetup();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::DBISAMTable5AfterPost(TDataSet *DataSet)
- {
- loadSetup();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::SendMonitorPacket(void)
- {
- // Packet
- // Header
- // Num of Active Cameras (in autorun) (4 bytes)
- // Num of Connected cameras (4 bytes)
- int i;
- int Pos = SF_PACKET_HEADER_LEN;
- int TempInt;
- // prepare message
- // count active cameras
- TempInt = 0;
- for (i=0; i<NUM_MAX_TELECAMERE; i++) {
- if (videoactive[i])
- TempInt++;
- }
- memcpy(SFPacketToSend+Pos, &TempInt, sizeof(int));
- Pos += sizeof(int);
- // count connected cameras
- TempInt = 0;
- for (i=0; i<NUM_MAX_TELECAMERE; i++) {
- if (VitaminCtrl[i]->ControlStatus == 1 ||
- VitaminCtrl[i]->ControlStatus == 2)
- TempInt++;
- }
- memcpy(SFPacketToSend+Pos, &TempInt, sizeof(int));
- Pos += sizeof(int);
- SFPacketToSend[Pos] = CalculateCRC (SFPacketToSend, SF_FULL_PACKET_LEN -1);
- // send packet
- NMUDPMonitor->SendBuffer (SFPacketToSend, SF_FULL_PACKET_LEN, SF_FULL_PACKET_LEN);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::tmrMonitorMessageTimer(TObject *Sender)
- {
- SendMonitorPacket();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
- {
- setOFF();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl1MDAlert(TObject *Sender,
- Variant *vPiece)
- {
- if(!A(0))
- return;
- switch(fsm1) {
- case 0:
- motion[0] = true;
- createAviRecord(1);
- records[0] += 1;
- VrNum1->Value = records[0];
- VitaminCtrl1->StartAVIConversion();
- VrUserLed3->Active = true;
- VrLed1->Active = true;
- fsm1 = 1;
- AA(0) = true;
- timeout[0] = SetTimeout(MotionTimeout[0], 1);
- break;
- case 1:
- motion[0] = true;
- timeout[0] = SetTimeout(MotionTimeout[0], 1);
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl2MDAlert(TObject *Sender,
- Variant *vPiece)
- {
- IplImage *image;
- if(!A(1))
- return;
- switch(fsm2) {
- case 0:
- motion[1] = true;
- createAviRecord(2);
- records[1] += 1;
- VrNum2->Value = records[1];
- VitaminCtrl2->StartAVIConversion();
- VrUserLed1->Active = true;
- VrLed2->Active = true;
- fsm2 = 1;
- AA(1) = true;
- timeout[1] = SetTimeout(MotionTimeout[1], 2);
- break;
- case 1:
- motion[1] = true;
- timeout[1] = SetTimeout(MotionTimeout[1], 2);
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl3MDAlert(TObject *Sender,
- Variant *vPiece)
- {
- IplImage *image;
- if(!A(2))
- return;
- switch(fsm3) {
- case 0:
- motion[2] = true;
- createAviRecord(3);
- records[2] += 1;
- VrNum3->Value = records[2];
- VitaminCtrl3->StartAVIConversion();
- VrUserLed2->Active = true;
- VrLed3->Active = true;
- fsm3 = 1;
- AA(2) = true;
- timeout[2] = SetTimeout(MotionTimeout[2], 3);
- break;
- case 1:
- motion[2] = true;
- timeout[2] = SetTimeout(MotionTimeout[2], 3);
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl4MDAlert(TObject *Sender,
- Variant *vPiece)
- {
- IplImage *image;
- if(!A(3))
- return;
- switch(fsm4) {
- case 0:
- motion[3] = true;
- createAviRecord(4);
- records[3] += 1;
- VrNum4->Value = records[3];
- VitaminCtrl4->StartAVIConversion();
- VrUserLed4->Active = true;
- VrLed4->Active = true;
- fsm4 = 1;
- AA(3) = true;
- timeout[3] = SetTimeout(MotionTimeout[3], 4);
- break;
- case 1:
- motion[3] = true;
- timeout[3] = SetTimeout(MotionTimeout[3], 4);
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl5MDAlert(TObject *Sender,
- Variant *vPiece)
- {
- IplImage *image;
- if(!A(4))
- return;
- switch(fsm5) {
- case 0:
- motion[4] = true;
- createAviRecord(5);
- records[4] += 1;
- VrNum5->Value = records[4];
- VitaminCtrl5->StartAVIConversion();
- VrUserLed5->Active = true;
- VrLed5->Active = true;
- fsm5 = 1;
- AA(4) = true;
- timeout[4] = SetTimeout(MotionTimeout[4], 5);
- break;
- case 1:
- motion[4] = true;
- timeout[4] = SetTimeout(MotionTimeout[4], 5);
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VitaminCtrl6MDAlert(TObject *Sender,
- Variant *vPiece)
- {
- IplImage *image;
- if(!A(5))
- return;
- switch(fsm6) {
- case 0:
- motion[5] = true;
- createAviRecord(6);
- records[5] += 1;
- VrNum6->Value = records[5];
- VitaminCtrl6->StartAVIConversion();
- VrUserLed6->Active = true;
- // VrLed6->Active = true;
- VrLed7->Active = true;
- fsm6 = 1;
- AA(5) = true;
- timeout[5] = SetTimeout(MotionTimeout[5], 6);
- break;
- case 1:
- motion[5] = true;
- timeout[5] = SetTimeout(MotionTimeout[5], 6);
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::searchObject(IplImage * image, int video, int tipo)
- {
- AnsiString filename;
- int numFaces;
- int i;
- double scale = 1.0;
- int x,y, x1, y1;
- int cx, cy;
- AnsiString buffer;
- CvSeq* faces;
- cy = cx = 24;
- if(storage == NULL || facce[video] == NULL || image == NULL) {
- saveError("searchFace : Errore nella storage o cascade");
- return;
- }
- // --------------------------------------------------
- for(int i=0;i!=6;i++)
- VrULActive[i]->Active = false;
- VrULActive[video]->Active = true;
- saveImage(video);
- IplImage* gray = cvCreateImage( cvSize(image->width,image->height), 8, 1 );
- IplImage* small_img = cvCreateImage( cvSize( cvRound (image->width/scale),cvRound (image->height/scale)),8, 1 );
- cvCvtColor( image, gray, CV_BGR2GRAY );
- cvResize( gray, small_img, CV_INTER_LINEAR );
- cvEqualizeHist( small_img, small_img );
- cvClearMemStorage( storage );
- faces = cvHaarDetectObjects(small_img, facce[video], storage, 1.1, 2, 0 | CV_HAAR_DO_CANNY_PRUNING, cvSize(classifierX[video], classifierY[video]) );
- numFaces = faces->total;
- if(!numFaces)
- faces = cvHaarDetectObjects(small_img, facce[video], storage, 1.3, 2, 0, cvSize(classifierX[video], classifierY[video]) );
- if(numFaces) {
- for(int i = 0; i < (faces ? numFaces : 0); i++ )
- {
- CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
- x = r->x*scale;
- y = r->y*scale;
- x1 = (r->width+x)*scale;
- y1 = (r->height+y)*scale;
- CvPoint center;
- int radius;
- center.x = cvRound((r->x + r->width*0.5)*scale);
- center.y = cvRound((r->y + r->height*0.5)*scale);
- radius = cvRound((r->width + r->height)*0.25*scale);
- x = center.x - radius;
- y = center.y - radius;
- x1 = center.x + radius;
- y1 = center.y + radius;
- if(r->width < minx || r->height < miny) {
- saveError("searchFace : minx >= r->width || miny >= r->height - continue");
- continue;
- }
- DBISAMTable2->Insert();
- DBISAMTable2->FieldByName("Record")->AsInteger = record[video];
- // PC 2006-12-19
- //
- DBISAMTable2->FieldByName("Data")->AsDateTime = DateToStr(Date());
- DBISAMTable2->FieldByName("Ora")->AsDateTime = TimeToStr(Time());
- //--------------------------------------
- CvMat small_img_roi;
- cvGetSubRect( small_img, &small_img_roi, *r );
- IplImageToTBitmap(small_img,ImageEnDBView1->Bitmap);
- ImageEnProc2->Update();
- ImageEnDBView1->Refresh();
- DBISAMTable2->Post();
- DBISAMTable2->FlushBuffers();
- if(DBCheckBox2->Checked) {
- NMSMTP1->Host = DBEdit11->Text;
- NMSMTP1->Port = 25;
- NMSMTP1->UserID = DBEdit12->Text;
- NMSMTP1->Connect();
- buffer.printf("%s%03d%03d.jpg", path, record[video], video);
- ImageEnIO1->SaveToFileJpeg(buffer);
- if(!DBEdit8->Text.IsEmpty()) {
- NMSMTP1->PostMessage->FromAddress = DBEdit14->Text;
- NMSMTP1->PostMessage->FromName = "Face Surveil";
- NMSMTP1->PostMessage->Subject = "Allarme di movimento da Face Surveil(C)";
- NMSMTP1->PostMessage->ToAddress->Add(DBEdit8->Text);
- NMSMTP1->PostMessage->Attachments->Add(buffer);
- NMSMTP1->PostMessage->Body->Text = "Immagine di allarme movimento\n\Face Surveil(C)\n\n";
- NMSMTP1->SendMail();
- }
- if(!DBEdit9->Text.IsEmpty()) {
- NMSMTP1->PostMessage->FromAddress = DBEdit14->Text;
- NMSMTP1->PostMessage->FromName = "Face Surveil";
- NMSMTP1->PostMessage->Subject = "Allarme di movimento da Face Surveil(C)";
- NMSMTP1->PostMessage->ToAddress->Add(DBEdit9->Text);
- NMSMTP1->PostMessage->Attachments->Add(buffer);
- NMSMTP1->PostMessage->Body->Text = "Immagine di allarme movimento\n\Face Surveil(C)\n\n";
- NMSMTP1->SendMail();
- }
- if(!DBEdit10->Text.IsEmpty()) {
- NMSMTP1->PostMessage->FromAddress = DBEdit14->Text;
- NMSMTP1->PostMessage->FromName = "Face Surveil";
- NMSMTP1->PostMessage->Subject = "Allarme di movimento da Face Surveil(C)";
- NMSMTP1->PostMessage->ToAddress->Add(DBEdit10->Text);
- NMSMTP1->PostMessage->Attachments->Add(buffer);
- NMSMTP1->PostMessage->Body->Text = "Immagine di allarme movimento\n\Face Surveil(C)\n\n";
- NMSMTP1->SendMail();
- }
- NMSMTP1->Disconnect();
- }
- }
- }
- cvReleaseImage( &gray );
- cvReleaseImage( &small_img );
- return;}
- void __fastcall TForm1::VrPowerButton12Click(TObject *Sender)
- {
- bool flag = VrPowerButton12->Active;
- fsm6 = 0;
- if(flag) {
- VrPowerButton12->Caption = "Ferma";
- if(!DBCheckBox55->Checked)
- VitaminCtrl6->AVIVideoFrameRate = frate[5];
- VitaminCtrl6->EventTypes = 7;
- } else {
- if(AA(5)) {
- // PC
- StopAVIRecord(5);
- // -------------------
- saveError ("Stop Registrazione/Analisi camera 6");
- }
- VrPowerButton12->Caption = "Analisi";
- VitaminCtrl6->EventTypes = 0;
- AA(5) = false;
- }
- A(5) = flag;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton12Click(TObject *Sender)
- {
- zip = ip[4];
- zlogin = login[4];
- zpassword = password[4];
- activateZoom();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::NMSMTP1Success(TObject *Sender)
- {
- NMSMTP1->Disconnect();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button17Click(TObject *Sender)
- {
- if (OpenDialog1->Execute())
- DBEdit17->Text = OpenDialog1->FileName;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton2Click(TObject *Sender)
- {
- VitaminCtrl1->SetFullScreen(1);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button18Click(TObject *Sender)
- {
- if(CheckBox3->Checked == true) {
- DBISAMTable9->First();
- while(!DBISAMTable9->Eof)
- DBISAMTable9->Delete();
- }
- CheckBox3->Checked = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton3Click(TObject *Sender)
- {
- VitaminCtrl2->SetFullScreen(1);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton4Click(TObject *Sender)
- {
- VitaminCtrl3->SetFullScreen(1);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton5Click(TObject *Sender)
- {
- VitaminCtrl4->SetFullScreen(1);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton6Click(TObject *Sender)
- {
- VitaminCtrl5->SetFullScreen(1);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::VrDemoButton19Click(TObject *Sender)
- {
- VitaminCtrl6->SetFullScreen(1);
- }
- //---------------------------------------------------------------------------
- bool TForm1::IplImageToTBitmap(const IplImage * src, Graphics::TBitmap * dest)
- {
- if (!src || !dest)
- return false;
- IplImage *temp;
- CvRect roi;
- if (src->roi)
- roi=cvGetImageROI(src);
- else
- roi=cvRect(0,0,src->width,src->height);
- temp=cvCreateImage(cvSize(roi.width,roi.height),IPL_DEPTH_8U,3);
- if (src->nChannels!=3)
- cvCvtColor(src,temp,CV_GRAY2RGB);
- else
- cvCopy(src,temp);
- if (dest->Width==0 || dest->Height==0){
- dest->Width = roi.width;
- dest->Height = roi.height;
- }
- else{
- IplImage *temp1=cvCloneImage(temp);
- cvReleaseImageData(temp);
- cvInitImageHeader(temp,cvSize(dest->Width,dest->Height),IPL_DEPTH_8U,3,src->origin,4);
- cvCreateImageData(temp);
- roi.width=dest->Width;
- roi.height=dest->Height;
- cvResize(temp1,temp);
- cvReleaseImage(&temp1);
- }
- dest->PixelFormat=pf24bit;
- try{
- unsigned char *pLine;
- int x,y;
- for(y=0 ;y<roi.height;y++){
- pLine = (unsigned char *)dest->ScanLine[y];
- for(x=0 ;x <roi.width*3 ;x++){
- pLine[x]= ((unsigned char*)(temp->imageData + temp->widthStep*y))[x];
- }
- }
- }
- catch(...){
- MessageBox(0,"Error while converting ...","Error", MB_OK );
- //ShowMessage("Error while converting ...");
- }
- cvReleaseImage(&temp);
- return true;
- }
- void __fastcall TForm1::StatisticsTimerTimer(TObject *Sender)
- {
- DWORD Res;
- ULARGE_INTEGER Value;
- // if value AsyncStatistics->Checked - TRUE
- // then statistics refreshes anisochronously
- if(AsyncStatistics->Checked)
- {
- Adapter->Get_AsyncStatistics(stNdisTranWithoutErr);
- Adapter->Get_AsyncStatistics(stNdisRecvWithoutErr);
- Adapter->Get_AsyncStatistics(stNdisTranWithErr);
- Adapter->Get_AsyncStatistics(stNdisRecvWithErr);
- Adapter->Get_AsyncStatistics(stNdisMissed);
- Adapter->Get_AsyncStatistics(stBpfReceive);
- Adapter->Get_AsyncStatistics(stBpfAccept);
- Adapter->Get_AsyncStatistics(stBpfReject);
- Adapter->Get_AsyncStatistics(stBpfProcess);
- return;
- }
- // update network card statistics
- Res = Adapter->UpdateAdapterStatistics();
- if(Res != HNERR_OK)
- {
- HNGetErrorBox(Res);
- return;
- }
- // update BPF filter statistics
- Res = Adapter->UpdateUserStatistics();
- if(Res != HNERR_OK)
- {
- HNGetErrorBox(Res);
- return;
- }
- // Gets adapter statistics values
- Value.LowPart = Adapter->Get_TranWithoutErr((PUINT)&Value.HighPart);
- FrameTranWithoutErr->Caption = Value.QuadPart;
- Value.LowPart = Adapter->Get_TranWithErr((PUINT)&Value.HighPart);
- FrameTranWithErr->Caption = Value.QuadPart;
- Value.LowPart = Adapter->Get_RecvWithoutErr((PUINT)&Value.HighPart);
- FrameRecvWithoutErr->Caption = Value.QuadPart;
- Value.LowPart = Adapter->Get_RecvWithErr((PUINT)&Value.HighPart);
- FrameRecvWithErr->Caption = Value.QuadPart;
- Value.LowPart = Adapter->Get_Missed((PUINT)&Value.HighPart);
- FrameMissed->Caption = Value.QuadPart;
- // Gets user statistics values
- Value.LowPart = Adapter->Get_RecvCount((PUINT)&Value.HighPart);
- Received->Caption = Value.QuadPart;
- Value.LowPart = Adapter->Get_AcceptCount((PUINT)&Value.HighPart);
- Accepted->Caption = Value.QuadPart;
- Value.LowPart = Adapter->Get_RejectCount((PUINT)&Value.HighPart);
- Rejected->Caption = Value.QuadPart;
- Value.LowPart = Adapter->Get_ProcessCount((PUINT)&Value.HighPart);
- Processed->Caption = Value.QuadPart;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::SyncSend_BtnClick(TObject *Sender)
- {
- DWORD Res;
- int i;
- int SendCount = SendCount_Edit->Text.ToIntDef(1);
- for (i = 0; i < SendCount; i++)
- {
- // Sends a packet synchronously
- Res = Adapter->SyncSend(PacketsContent_Edit->Text.c_str(),
- PacketsContent_Edit->Text.Length());
- if(Res != HNERR_OK)
- {
- HNGetErrorBox(Res);
- return;
- }
- }
- SendCount_Panel->Caption = i;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::AsyncSend_BtnClick(TObject *Sender)
- {
- DWORD Res;
- SendCount_Panel->Caption = 0;
- // Sends a packet asynchronously
- Res = Adapter->AsyncSend(PacketsContent_Edit->Text.c_str(),
- PacketsContent_Edit->Text.Length(),
- SendCount_Edit->Text.ToIntDef(1),NULL);
- if(Res != HNERR_OK) HNGetErrorBox(Res);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Init_BtnClick(TObject *Sender)
- {
- TTreeNode *pNode;
- TTreeNode *pNode2;
- char Buf[256];
- char Str[256];
- char MACStr[100];
- DWORD MACSize;
- DWORD CfgIndex;
- HANDLE hCfg;
- DWORD i;
- // Initialize PSSDK library
- DWORD Res = Mgr->Initialize();
- if(Res != HNERR_OK)
- {
- HNGetErrorBox(Res);
- return;
- }
- //processing information about network adapters which were found
- hCfg = 0;
- while((hCfg = Mgr->Get_NextAdapterCfg(hCfg)) != 0)
- {
- Cfg->Handle = hCfg;
- // Gets the network adapter description
- pNode = NetTree->Items->Add(NULL,Cfg->AdapterDescription);
- pNode->Data = Cfg->Handle;
- // Gets the network adapter accessibility status
- if(Cfg->AccessibleState) wsprintf(Str,"Accesseble ( YES )");
- else wsprintf(Str,"Accesseble ( NO )");
- NetTree->Items->AddChild(pNode,Str);
- // Gets the network adapter system name.
- wsprintf(Str,"Name %s", Cfg->AdapterName);
- NetTree->Items->AddChild(pNode,Str);
- // Gets the network adapter type
- switch(Cfg->AdapterType)
- {
- case atEthernet: wsprintf(Str,"Type = PSSDK_ETHERNET"); break;
- case atTokenRing: wsprintf(Str,"Type = PSSDK_TOKENRING"); break;
- case atFDDI: wsprintf(Str,"Type = PSSDK_FDDI"); break;
- case atWAN: wsprintf(Str,"Type = PSSDK_WAN"); break;
- default: wsprintf(Str,"Type = PSSDK_UNKNOWN");
- }
- NetTree->Items->AddChild(pNode,Str);
- // Gets the status of IP zero broadcast usage
- if(Cfg->ZeroBroadcastState) NetTree->Items->AddChild(pNode,"ZeroBroadcast ( YES )");
- else NetTree->Items->AddChild(pNode,"ZeroBroadcast ( NO )");
- // Gets the status of the DHCP using
- if(Cfg->DhcpState) NetTree->Items->AddChild(pNode,"DHCP Enabled ( YES )");
- else NetTree->Items->AddChild(pNode,"DHCP Enabled ( NO )");
- // Gets the network adapter packet maximum size
- wsprintf(Str,"MaxPacketSize %u", Cfg->MaxPacketSize);
- NetTree->Items->AddChild(pNode,Str);
- // Gets the MAC header size
- wsprintf(Str,"MACHeaderSize %u", Cfg->MACHeaderSize);
- NetTree->Items->AddChild(pNode,Str);
- // Gets the MAC address size
- MACSize = Cfg->MACAddrSize;
- wsprintf(Str,"MACAddrSize %u", MACSize);
- NetTree->Items->AddChild(pNode,Str);
- // Gets the MAC address of the network adapter
- strcpy(Str,"MAC Address: ");
- Cfg->Get_MACAddress(MACStr,sizeof(MACStr));
- for(i=0;i<MACSize;i++)
- {
- wsprintf(Buf,"%02X",(unsigned char)MACStr[i]);
- strcat(Str,Buf);
- if(i+1 != MACSize) strcat(Str,"-");
- }
- NetTree->Items->AddChild(pNode,Str);
- // Gets the number of IP addresses, assigned to the network adapter card
- wsprintf(Str,"IP (%u) ",Cfg->IpCount);
- pNode2 = NetTree->Items->AddChild(pNode,Str);
- for(i=0;i<Cfg->IpCount;i++)
- {
- // Gets one of the IP addresses, assigned to the network adapter
- wsprintf(Str,"%s ( %s ) ",Cfg->Get_Ip(i).c_str(),Cfg->Get_SubnetMask(i).c_str());
- NetTree->Items->AddChild(pNode2,Str);
- }
- // Gets the number of the IP addresses of DNS servers, set on the system
- wsprintf(Str,"DNS (%u) ",Cfg->IpDnsCount);
- pNode2 = NetTree->Items->AddChild(pNode,Str);
- for(i=0;i<Cfg->IpDnsCount;i++)
- {
- // Gets one of the IP addresses of the DNS servers, set on the system
- wsprintf(Str,"%s",Cfg->Get_IpDns(i).c_str());
- NetTree->Items->AddChild(pNode2,Str);
- }
- // Gets the number of the IP addresses of DHCP servers, set on the system
- wsprintf(Str,"DHCP (%u) ",Cfg->IpDhcpCount);
- pNode2 = NetTree->Items->AddChild(pNode,Str);
- for(i=0;i<Cfg->IpDhcpCount;i++)
- {
- // Gets one of the IP addresses of DHCP servers, set on the system
- wsprintf(Str,"%s",Cfg->Get_IpDhcp(i).c_str());
- NetTree->Items->AddChild(pNode2,Str);
- }
- // Gets the number of the gateways IP addresses
- wsprintf(Str,"Gateway (%u) ",Cfg->IpGatewayCount);
- pNode2 = NetTree->Items->AddChild(pNode,Str);
- for(i=0;i<Cfg->IpGatewayCount;i++)
- {
- // Gets one of the IP addresses of gateways, set on the system
- wsprintf(Str,"%s",Cfg->Get_IpGateway(i).c_str());
- NetTree->Items->AddChild(pNode2,Str);
- }
- }
- if(NetTree->Items->Count) NetTree->Selected = NetTree->Items->Item[0];
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Close_BtnClick(TObject *Sender)
- {
- DWORD Res;
- // disabling times for refreshing statistics
- StatisticsTimer->Enabled = false;
- // Closes the network adapter
- Res = Adapter->CloseAdapter();
- if(Res != HNERR_OK)
- {
- HNGetErrorBox(Res);
- return;
- }
- ConnectStatus->Caption = "OFF LINE";
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Open_BtnClick(TObject *Sender)
- {
- DWORD Res;
- // Sets the handle of the HNAdapterConfig object
- // See function NetTreeChange
- Adapter->ConfigHandle = (HANDLE)AdapterName_Panel->Tag;
- // For begining of work with network adapter we must call function OpenAdapter
- Res = Adapter->OpenAdapter();
- if(Res != HNERR_OK)
- {
- HNGetErrorBox(Res);
- return;
- }
- // Gets the network adapter maximum speed in 100 bps
- LinkSpeed->Caption = AnsiString(Adapter->LinkSpeed/10000) + " Mbps";
- // Gets the status of the physical connection to the network
- if(Adapter->ConnectStatus) ConnectStatus->Caption = "ON LINE";
- else ConnectStatus->Caption = "OFF LINE";
- // enabling times for refreshing statistics
- StatisticsTimer->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::ChkUseFastBpfClick(TObject *Sender)
- {
- Adapter->UseFastUserFilter = ChkUseFastBpf->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::AdapterAsyncSend(TObject *Sender, Pointer Key,
- DWORD Count)
- {
- SendCount_Panel->Caption = Count;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::AdapterPacketReceive(TObject *Sender,
- Pointer ThParam, Pointer hPacket, Pointer pPacketData,
- DWORD IncPacketSize)
- {
- HNPacket->Handle = hPacket;
- // as we have set the BPF filter to IP traffic in advance
- // we are sure that the incoming packet has the IP header
- PIP_HEADER pIp = (PIP_HEADER)&((char*)pPacketData)[sizeof(ETHERNET_HEADER)];
- // send the message of receiving the IP packet
- // see the OnIPPacketReceive function
- PostMessage(Handle,WM_USER + 1,pIp->SrcAddr,HNPacket->PacketSize);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::AdapterStatistics(TObject *Sender,
- int StatisticsType, PULargeInteger pValue)
- {
- switch(StatisticsType)
- {
- case stNdisTranWithoutErr:
- FrameTranWithoutErr->Caption = pValue->QuadPart;
- break;
- case stNdisRecvWithoutErr:
- FrameRecvWithoutErr->Caption = pValue->QuadPart;
- break;
- case stNdisTranWithErr:
- FrameTranWithErr->Caption = pValue->QuadPart;
- break;
- case stNdisRecvWithErr:
- FrameRecvWithErr->Caption = pValue->QuadPart;
- break;
- case stNdisMissed:
- FrameMissed->Caption = pValue->QuadPart;
- break;
- case stBpfReceive:
- Received->Caption = pValue->QuadPart;
- break;
- case stBpfAccept:
- Accepted->Caption = pValue->QuadPart;
- break;
- case stBpfReject:
- Rejected->Caption = pValue->QuadPart;
- break;
- case stBpfProcess:
- Processed->Caption = pValue->QuadPart;
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::NetTreeChange(TObject *Sender, TTreeNode *Node)
- {
- while(Node->Parent) Node = Node->Parent;
- AdapterName_Panel->Caption = Node->Text;
- AdapterName_Panel->Tag = (int)Node->Data;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::IPStatistics_LVCompare(TObject *Sender,
- TListItem *Item1, TListItem *Item2, int Data, int &Compare)
- {
- in_addr Ip1, Ip2;
- Ip1.S_un.S_addr = (DWORD)Item1->Data;
- Ip2.S_un.S_addr = (DWORD)Item2->Data;
- if (Ip1.S_un.S_un_b.s_b1 != Ip2.S_un.S_un_b.s_b1)
- {
- Compare = (Ip1.S_un.S_un_b.s_b1 > Ip2.S_un.S_un_b.s_b1 ? 1 : -1);
- return;
- }
- if (Ip1.S_un.S_un_b.s_b2 != Ip2.S_un.S_un_b.s_b2)
- {
- Compare = (Ip1.S_un.S_un_b.s_b2 > Ip2.S_un.S_un_b.s_b2 ? 1 : -1);
- return;
- }
- if (Ip1.S_un.S_un_b.s_b3 != Ip2.S_un.S_un_b.s_b3)
- {
- Compare = (Ip1.S_un.S_un_b.s_b3 > Ip2.S_un.S_un_b.s_b3 ? 1 : -1);
- return;
- }
- if (Ip1.S_un.S_un_b.s_b4 != Ip2.S_un.S_un_b.s_b4)
- Compare = (Ip1.S_un.S_un_b.s_b4 > Ip2.S_un.S_un_b.s_b4 ? 1 : -1);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::cbNetCardsChange(TObject *Sender)
- {
- if (cbNetCards->ItemIndex == -1) return;
- HANDLE AdpCfg = (HANDLE)cbNetCards->Items->Objects[cbNetCards->ItemIndex];
- if (HNAdapter->ConfigHandle != AdpCfg) btnOpen->Enabled = true;
- else btnOpen->Enabled = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::btnPingClick(TObject *Sender)
- {
- long Res;
- char MacAddr[6];
- DWORD ArpPacketSize = sizeof(ETHERNET_HEADER) + sizeof(ARP_HEADER);
- DWORD IcmpPacketSize = sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER) + sizeof(ICMP_HEADER) + 20;
- HANDLE hPkt = HNPacket->AllocatePacket((IcmpPacketSize > ArpPacketSize ? IcmpPacketSize : ArpPacketSize));
- if (!hPkt)
- {
- MessageBox(NULL,"Can't create packet","Error",MB_ICONINFORMATION);
- return;
- }
- HNPacket->Handle = hPkt;
- char *pPacket = (char *)HNPacket->PacketData;
- // Gets MAC address of network adapter
- HNAdapterCfg->Get_MACAddress(MacAddr,6);
- ETHERNET_HEADER *pEth = (ETHERNET_HEADER *)pPacket;
- ARP_HEADER *pArp = (ARP_HEADER *)&pPacket[sizeof(ETHERNET_HEADER)];
- // Create Ethernet ethernet header for ARP packet
- MoveMemory(pEth->EthSHost,MacAddr,6);
- FillMemory(pEth->EthDHost,6,0xFF);
- pEth->EthType = htons(ETHERTYPE_ARP);
- // Create ARP packet
- pArp->Hw_Type = htons(HW_TYPE_ETH10);
- pArp->Prot_Type = htons(ETHERTYPE_IP);
- pArp->Hw_Addr_Size = 6;
- pArp->Prot_Addr_Size = 4;
- pArp->Operation = htons(ARP_OP_ARP_QUERY);
- MoveMemory(pArp->Sndr_Hw_Addr,MacAddr,6);
- SrcIpAddr.S_un.S_addr = inet_addr(cbAdapterIp->Text.c_str());
- *((DWORD*)&(pArp->Sndr_Ip_Addr[0])) = SrcIpAddr.S_un.S_addr;
- ZeroMemory(pArp->Rcpt_Hw_Addr,6);
- DestIpAddr.S_un.S_addr = inet_addr(eIp->Text.c_str());
- DWORD RcvIpAdr;
- if(!cbNAT->Checked) RcvIpAdr = DestIpAddr.S_un.S_addr;
- else RcvIpAdr = inet_addr(ebIpNat->Text.c_str());
- *((DWORD*)&(pArp->Rcpt_Ip_Addr[0])) = RcvIpAdr;
- // Clear APR filter
- HNUserFilterArp->Clear();
- // Create ARP filter
- HNUserFilterArp->AddCmd(BPF_LD+BPF_H+BPF_ABS, 12); //
- HNUserFilterArp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_ARP, 0, 5); // jmp if false line 5
- HNUserFilterArp->AddCmd(BPF_LD+BPF_H+BPF_ABS, ((DWORD)&pArp->Operation - (DWORD)pEth)); //
- HNUserFilterArp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ARP_OP_ARP_RESP, 0, 3); // jmp if false line 3
- HNUserFilterArp->AddCmd(BPF_LD+BPF_W+BPF_ABS, ((DWORD)&pArp->Sndr_Ip_Addr - (DWORD)pEth)); //
- HNUserFilterArp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, htonl(RcvIpAdr), 0, 1); // jmp if false line 1
- HNUserFilterArp->AddCmd(BPF_RET+BPF_K, (u_int)-1); // end - TRUE
- HNUserFilterArp->AddCmd(BPF_RET+BPF_K, 0); // end - FALSE
- // Set ARP filter
- HNAdapter->UserFilter = HNUserFilterArp->Handle;
- // Reset ARP receiving packet event
- ResetEvent(RecvArpPacket);
- // Send ARP packet
- HNPacket->IncPacketSize = ArpPacketSize;
- Res = HNAdapter->SyncSendEx(hPkt);
- if(Res != HNERR_OK) { HNGetErrorBox(Res); return; }
- // Wait receive ARP packet
- Res = WaitForSingleObject(RecvArpPacket,2000);
- // Clear user filter (stop receive any packets)
- HNAdapter->UserFilter = 0;
- if((ULONG)Res != WAIT_OBJECT_0)
- {
- ShowMessage("No Arp reply");
- return;
- }
- // Create ICMP packet
- memset(pPacket,'S',IcmpPacketSize);
- pEth = (ETHERNET_HEADER *)pPacket;
- IP_HEADER *pIp = (IP_HEADER *)&pPacket[sizeof(ETHERNET_HEADER)];
- ICMP_HEADER *pIcmp = (ICMP_HEADER *)&pPacket[sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER)];
- MoveMemory(pEth->EthSHost,MacAddr,6);
- MoveMemory(pEth->EthDHost,DestMacAddr,6);
- pEth->EthType = htons(ETHERTYPE_IP);
- // Create IP Header
- ZeroMemory((char *)pIp,sizeof(IP_HEADER));
- pIp->Ver = 4;
- pIp->Len = sizeof(IP_HEADER)/sizeof(DWORD);
- pIp->TotalLength = htons(IcmpPacketSize - sizeof(ETHERNET_HEADER));
- pIp->Identification = htons((unsigned short)GetCurrentProcessId());
- pIp->Ttl = DEFAULT_TTL;
- pIp->Protocol = IPPROTO_ICMP;
- pIp->SrcAddr = SrcIpAddr.S_un.S_addr;
- pIp->DestAddr = DestIpAddr.S_un.S_addr;
- pIp->Checksum = HNPacket->InetCheckSum(pIp, sizeof(IP_HEADER));
- IcmpBufferSize = IcmpPacketSize - sizeof(ETHERNET_HEADER) - sizeof(IP_HEADER);
- unsigned short ProcID = (unsigned short)GetCurrentProcessId();
- // Clear ICMP filter
- HNUserFilterIcmp->Clear();
- // Create ICMP filter
- HNUserFilterIcmp->AddCmd(BPF_LD+BPF_H+BPF_ABS, 12); //
- HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_IP, 0, 9); // jmp if false line 9
- HNUserFilterIcmp->AddCmd(BPF_LD+BPF_B+BPF_ABS, ((DWORD)&pIp->Protocol - (DWORD)pEth)); //
- HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, IPPROTO_ICMP, 0, 7); // jmp if false line 7
- HNUserFilterIcmp->AddCmd(BPF_LD+BPF_W+BPF_ABS, ((DWORD)&pIp->SrcAddr - (DWORD)pEth)); //
- HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, htonl(DestIpAddr.S_un.S_addr), 0, 5); // jmp if false line 5
- HNUserFilterIcmp->AddCmd(BPF_LD+BPF_B+BPF_ABS, ((DWORD)&pIcmp->IcmpType - (DWORD)pEth)); //
- HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, ICMP_ECHOREPLY, 0, 3); // jmp if false line 3
- HNUserFilterIcmp->AddCmd(BPF_LD+BPF_H+BPF_ABS, ((DWORD)&pIcmp->IcmpId - (DWORD)pEth)); // //
- HNUserFilterIcmp->AddJmp(BPF_JMP+BPF_JEQ+BPF_K, htons(ProcID), 0, 1); // jmp if false line 1
- HNUserFilterIcmp->AddCmd(BPF_RET+BPF_K, (u_int)-1); // end - TRUE
- HNUserFilterIcmp->AddCmd(BPF_RET+BPF_K, 0); // end - FALSE
- // Set ICMP filter
- HNAdapter->UserFilter = HNUserFilterIcmp->Handle;
- Send = Receive = 0;
- SendCount = ebCount->Text.ToIntDef(10);
- // Send ICMP packets
- HNPacket->IncPacketSize = IcmpPacketSize;
- for(DWORD i = 0; i < SendCount; i++)
- {
- pIcmp->IcmpType = ICMP_ECHO;
- pIcmp->IcmpCode = 0;
- pIcmp->IcmpChecksum = 0;
- pIcmp->IcmpId = ProcID;
- pIcmp->IcmpSeq = 0;
- pIcmp->IcmpTimestamp = GetTickCount();
- pIcmp->IcmpChecksum = HNPacket->InetCheckSum(pIcmp,IcmpBufferSize);
- Res = HNAdapter->SyncSendEx(hPkt);
- if(Res != HNERR_OK) { HNGetErrorBox(Res); return; }
- Send++;
- }
- StatusBar->Panels->Items[1]->Text = Send;
- HNPacket->FreePacket(hPkt);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::btnOpenClick(TObject *Sender)
- {
- long Res;
- if(cbNetCards->ItemIndex == -1) return;
- HANDLE AdpCfg = (HANDLE)cbNetCards->Items->Objects[cbNetCards->ItemIndex];
- btnPing->Enabled = false;
- HNAdapterCfg->Handle = AdpCfg;
- if (HNAdapter->IsOpened()) HNAdapter->CloseAdapter();
- // Sets the handle of the HNAdapterConfig object
- HNAdapter->ConfigHandle = AdpCfg;
- // Opens the network adapter
- Res = HNAdapter->OpenAdapter();
- if(Res != HNERR_OK) {HNGetErrorBox(Res); return; }
- cbAdapterIp->Clear();
- AnsiString AdapterIp;
- // Gets IP addresses, assigned to the network adapter card
- for (DWORD i = 0; i < HNAdapterCfg->IpCount; i++)
- {
- AdapterIp = HNAdapterCfg->Get_Ip(i);
- cbAdapterIp->Items->Add(AdapterIp);
- }
- in_addr IpAddr;
- in_addr IpMask;
- if (cbAdapterIp->Items->Count)
- {
- cbAdapterIp->ItemIndex = 0;
- AdapterIp = HNAdapterCfg->Get_Ip(0);
- IpAddr.S_un.S_addr = inet_addr(AdapterIp.c_str());
- AdapterIp = HNAdapterCfg->Get_SubnetMask(0);
- IpMask.S_un.S_addr = inet_addr(AdapterIp.c_str());
- IpAddr.S_un.S_addr &= IpMask.S_un.S_addr;
- eIp->Text = inet_ntoa(IpAddr);
- }
- btnPing->Enabled = true;
- btnOpen->Enabled = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::bClearClick(TObject *Sender)
- {
- //Clear results
- mResult->Lines->Clear();
- StatusBar->Panels->Items[1]->Text = 0;
- StatusBar->Panels->Items[3]->Text = 0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::HNPSManagerConfigChange(TObject *Sender,
- Pointer hConfig, int ChangeType)
- {
- HNAdapterCfg->Handle = hConfig;
- // Gets the network adapter type
- if(HNAdapterCfg->AdapterType == atEthernet)
- cbNetCards->Items->AddObject(HNAdapterCfg->AdapterDescription,(TObject*)hConfig);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::HNAdapterPacketReceive(TObject *Sender,
- Pointer ThParam, Pointer hPacket, Pointer pPacketData,
- DWORD IncPacketSize)
- {
- ETHERNET_HEADER *pEth = (ETHERNET_HEADER *)pPacketData;
- unsigned short EthType = htons(pEth->EthType);
- char* PacketBuffer = (char*)pPacketData;
- if(EthType == ETHERTYPE_ARP)
- {
- ARP_HEADER *pArp = (ARP_HEADER *)&PacketBuffer[sizeof(ETHERNET_HEADER)];
- MoveMemory(DestMacAddr,pArp->Sndr_Hw_Addr,6);
- SetEvent(RecvArpPacket);
- return;
- }
- //We are sure that this code processes icmp packets only, because of the ICMP BPF program.
- IP_HEADER *pIp = (IP_HEADER *)&PacketBuffer[sizeof(ETHERNET_HEADER)];
- ICMP_HEADER *pIcmp = (ICMP_HEADER *)&PacketBuffer[sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER)];
- // Sending message to our application when icmp packet was received (function OnIcmpRecv)
- PostMessage(Handle,WM_USER + 2,GetTickCount() - pIcmp->IcmpTimestamp,pIp->Ttl);
- }
- //---------------------------------------------------------------------------
- void TForm1::OnIcmpRecv(TMessage& Msg)
- {
- Result = "Reply from ";
- Result += inet_ntoa(DestIpAddr);
- Result += ": bytes = " + IntToStr(IcmpBufferSize);
- Result += " time = " + IntToStr(Msg.WParam) + " ms ";
- Result += "TTL=" + IntToStr(Msg.LParam);
- mResult->Lines->Add(Result);
- StatusBar->Panels->Items[3]->Text = ++Receive;
- if (Send == SendCount &&
- Receive == SendCount) HNAdapter->UserFilter = NULL;
- }
- void TForm1::OnIPPacketReceive(TMessage& Msg)
- {
- TListItem* Item = IPStatistics_LV->FindData(0,(void*)Msg.WParam,true,false);
- if (!Item)
- {
- in_addr Ip;
- Ip.S_un.S_addr = Msg.WParam;
- IPStatistics_LV->Items->BeginUpdate();
- Item = IPStatistics_LV->Items->Add();
- Item->Data = (void*)Msg.WParam;
- Item->Caption = inet_ntoa(Ip);
- Item->SubItems->AddObject("0",(TObject*)NULL);
- Item->SubItems->AddObject("0",(TObject*)NULL);
- IPStatistics_LV->AlphaSort();
- IPStatistics_LV->Items->EndUpdate();
- }
- Item->SubItems->Objects[0] = (TObject*)((DWORD)Item->SubItems->Objects[0] + 1);
- Item->SubItems->Strings[0] = StrToInt((DWORD)Item->SubItems->Objects[0]);
- Item->SubItems->Objects[1] = (TObject*)((DWORD)Item->SubItems->Objects[1] + Msg.LParam);
- Item->SubItems->Strings[1] = StrToInt((DWORD)Item->SubItems->Objects[1]);
- }
- void __fastcall TForm1::VrTimer1Timer(TObject *Sender)
- {
- long frame;
- VrTimer1->Enabled = false;
- for(int i=0;i!=6;i++) {
- if(A(i)) {
- frame = VitaminCtrl[i]->FrameRate;
- switch(i) {
- case 0:
- Edit18->Text = frame;
- break;
- case 1:
- Edit19->Text = frame;
- break;
- case 2:
- Edit20->Text = frame;
- break;
- case 3:
- Edit21->Text = frame;
- break;
- case 4:
- Edit22->Text = frame;
- break;
- case 5:
- Edit23->Text = frame;
- break;
- }
- }
- }
- VrTimer1->Enabled = true;
- Application->ProcessMessages();
- }
- //---------------------------------------------------------------------------
- void TForm1::setONVideoCamera(void)
- {
- if(active[0]) {
- VrPowerButton1->Active = true;
- VrPowerButton1Click (this);
- }
- if(active[1]) {
- VrPowerButton3->Active = true;
- VrPowerButton3Click (this);
- }
- if(active[2]) {
- VrPowerButton5->Active = true;
- VrPowerButton5Click (this);
- }
- if(active[3]) {
- VrPowerButton7->Active = true;
- VrPowerButton7Click (this);
- }
- if(active[4]) {
- VrPowerButton9->Active = true;
- VrPowerButton9Click (this);
- }
- if(active[5]) {
- VrPowerButton11->Active = true;
- VrPowerButton11Click (this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement