📄 camera.cpp
字号:
}
}
else{
for (int i = 1; i <= 3; i++)
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
szCommandLine[0] = 0xff;
szCommandLine[1] = 0x1;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x15;
szCommandLine[4] = 0x14;
szCommandLine[5] = 0x41;
szCommandLine[6] = CheckSum();
nStrLen = 7;
if(pCameraList[m_iCurrentCamera].iAVPort == 1){// Channel 1
if(M7_WriteAuxCom(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
else{
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
szCommandLine[0] = 0xff;
szCommandLine[1] = 0x1;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x15;
szCommandLine[4] = 0x15;
szCommandLine[5] = 0x20;
szCommandLine[6] = CheckSum();
nStrLen = 7;
if(pCameraList[m_iCurrentCamera].iAVPort == 1){// Channel 1
if(M7_WriteAuxCom(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
else{
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
szCommandLine[0] = 0xff;
szCommandLine[1] = 0x1;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x15;
szCommandLine[4] = 0x16;
szCommandLine[5] = 0x20;
szCommandLine[6] = CheckSum();
nStrLen = 7;
if(pCameraList[m_iCurrentCamera].iAVPort == 1){// Channel 1
if(M7_WriteAuxCom(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
else{
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
szCommandLine[0] = 0xff;
szCommandLine[1] = 0x1;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x15;
szCommandLine[4] = 0x17;
szCommandLine[5] = 0x20;
szCommandLine[6] = CheckSum();
nStrLen = 7;
if(pCameraList[m_iCurrentCamera].iAVPort == 1){// Channel 1
if(M7_WriteAuxCom(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
else{
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
szCommandLine[0] = 0xff;
szCommandLine[1] = 0x1;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x15;
szCommandLine[4] = 0x18;
szCommandLine[5] = 0x20;
szCommandLine[6] = CheckSum();
nStrLen = 7;
if(pCameraList[m_iCurrentCamera].iAVPort == 1){// Channel 1
if(M7_WriteAuxCom(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
else{
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
/////////////////////////////////////////
szCommandLine[0] = 0xff;
szCommandLine[1] = 0x1;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x15;
szCommandLine[4] = 0x27;
szCommandLine[5] = 0x20;
szCommandLine[6] = CheckSum();
nStrLen = 7;
if(pCameraList[m_iCurrentCamera].iAVPort == 1){// Channel 1
if(M7_WriteAuxCom(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
else{
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
szCommandLine[0] = 0xff;
szCommandLine[1] = 0x1;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x3;
szCommandLine[4] = 0x0;
szCommandLine[5] = (unsigned char)nNum;
szCommandLine[6] = CheckSum();
nStrLen = 7;
if(pCameraList[m_iCurrentCamera].iAVPort == 1){// Channel 1
if(M7_WriteAuxCom(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
else{
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
return 1;
}
bool CCamera::JIMU_GotoPreset(int nNum)
{
szCommandLine[0] = 0xff;
szCommandLine[1] = 0x1;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x7;
szCommandLine[4] = 0x0;
szCommandLine[5] = (unsigned char)nNum;
szCommandLine[6] = CheckSum();
int nStrLen = 7;
if(pCameraList[m_iCurrentCamera].iAVPort == 1){// Channel 1
if(M7_WriteAuxCom(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
else{
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
return 1;
}
int CCamera::CheckSum()
{
unsigned char cCS = 0;
for (int i = 1; i <=5; i++)
cCS += szCommandLine[i];
return (int) cCS;
}
bool CCamera::JIMU_MyDial(HWND hJimuMsgHandler, int nCameraID)
{
int i,iLen;
//DWORD dwStartTime, dwElapsedTime;
char phnno[200] = "ATDT";
char pstr[200];
struct M7_SITEREPORT SiteReport;
HCURSOR hCursor;
struct M7_ENCPARA EncParam;
// Get the phone number:
iLen = strlen(pCameraList[nCameraID].lpszAdress);
if (iLen < 1) return 0;
for (i = 0; i < iLen; i ++)
{
phnno[i+4] = pCameraList[nCameraID].lpszAdress[i];
}
phnno[iLen + 4] = 0xd;
phnno[iLen + 5] = 0xa;
iLen += 6;
hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
SetCursor(hCursor);
//Create the receiver:
m_hM7 = M7_CreateReceiver();
if (m_hM7 <= 0)
{
hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
SetCursor(hCursor);
MessageBox(NULL, "Failed to create the receiver thread!", "error", MB_OK);
return 0;
}
M7_SetComDevType(m_hM7, 1); // The remote station type = JIMU-718
M7_SetMsgHandle(m_hM7, hJimuMsgHandler); // Set the message handler
// Open the COM port connected with modem:
if (M7_OpenComPort(m_hM7, 1, 115200) != 0)
{
hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
SetCursor(hCursor);
MessageBox(NULL, "Failed to open COM port.", "error", MB_OK);
return 0;
}
// Dialing to call the remote station:
strcpy(pstr,"ATZ"); pstr[3] = 0xd; pstr[4] = 0xa;
M7_WriteComPort(m_hM7,(UCHAR*)pstr,5);
Sleep(500);
M7_WriteComPort(m_hM7,(UCHAR*)phnno,iLen);
Sleep(30000);
// Build connection with the remote station:
if (M7_CheckComLinkState(m_hM7) != 0)
{
hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
SetCursor(hCursor);
MessageBox(NULL, "Unable to build the communication link!", "error", MB_OK);
JIMU_Disconnect();
return 0;
}
/* dwStartTime = GetTickCount();
while(M7_CheckComLinkState(m_hM7)){
dwElapsedTime = GetTickCount() - dwStartTime;
if (dwElapsedTime > 30000){
hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
SetCursor(hCursor);
MessageBox(NULL, "Unable to build the communication link!", "error", MB_OK);
JimuDisconnect();
return 0;
}
}
*/
// Verify the visitor:
strcpy(pstr,"6138");
for (i=4;i<8;i++) pstr[i] = 0;
if (M7_Connect(m_hM7, pstr, &SiteReport) != 0)
{
hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
SetCursor(hCursor);
MessageBox(NULL, "Failed to connect!", "error", MB_OK);
JIMU_Disconnect();
return 0;
}
if(pCameraList[nCameraID].iAVPort == 2){ // Channel 2
if (M7_OpenAuxCom2(m_hM7, 0) != 0){
hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
SetCursor(hCursor);
MessageBox(NULL, "Failed to open aux com!", "error", MB_OK);
JIMU_Disconnect();
return 0;
}
}
else
if (M7_OpenAuxCom(m_hM7, 0) != 0){
hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
SetCursor(hCursor);
MessageBox(NULL, "Failed to open aux com!", "error", MB_OK);
JIMU_Disconnect();
return 0;
}
// Setup & start the video encoder:
EncParam.ImgType = 0x8b; // CIF320
EncParam.Quality =40;
EncParam.Speed =50;
EncParam.Blk_X =4;
EncParam.Blk_Y =2;
EncParam.Blk_W =40;
EncParam.Blk_H =30;
EncParam.Channel = pCameraList[nCameraID].iAVPort;
EncParam.Brightness =55;
EncParam.Contrast =55;
EncParam.Saturation =90;
M7_ENCSetup(m_hM7,&EncParam);
M7_ENCStart(m_hM7);
m_iCurrentCamera = nCameraID;
return 1;
}
bool CCamera::JIMU_Disconnect()
{
M7_CloseAuxCom(m_hM7);
M7_Disconnect(m_hM7);
Sleep(1000);
M7_CloseReceiver(m_hM7);
m_iCurrentCamera = INVALIDCAMERA; // invalid
return 1;
}
bool CCamera::JIMU_DrawFrame(HWND hWnd, unsigned char *lpJimuEncodedBuf, int iWidth, int iHigth)
{
LONG Disp_X = 0, Disp_Y = 0, Disp_W = iWidth, Disp_H = iHigth;
LONG Img_X,Img_Y,Img_W,Img_H,Img_ClrBits,Img_CH;
if(M7_VideoDecode(lpJimuEncodedBuf, m_JIMU_DecodedBuf, &Img_X, &Img_Y, &Img_W, &Img_H, &Img_ClrBits, &Img_CH))
MessageBox(NULL, "Decodeing error", "error", MB_OK);
M7_DisplayImageZoom(hWnd,Disp_X,Disp_Y,Disp_W,Disp_H,Img_W,Img_H,Img_ClrBits,m_JIMU_DecodedBuf);
return 1;
}
bool CCamera::JIMU_GetFrame()
{
m_JIMU_iEncodedBufLen = M7_GetVideoCodeFrame(m_hM7, m_JIMU_EncodedBuf);
if (m_JIMU_iEncodedBufLen < 0)
MessageBox(NULL, "Error occur on calling M7_GetVideoFrame()", "error", MB_OK);
int nStrLen;
if(pCameraList[m_iCurrentCamera].iProtocol == PELCO_D){
szCommandLine[0] = 0x0;
szCommandLine[1] = 0x1;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x0;
szCommandLine[4] = 0x0;
szCommandLine[5] = 0x0;
szCommandLine[6] = 0x1;
nStrLen = 7;
}
else{
szCommandLine[0] = 0x0;
szCommandLine[1] = 0x0;
szCommandLine[2] = 0x0;
szCommandLine[3] = 0x0;
szCommandLine[4] = 0;//pnSpeedTable[nSpeed];
szCommandLine[5] = 0x0;
szCommandLine[6] = 0xaf;
szCommandLine[7] = 0x0f;
nStrLen = 8;
}
if(pCameraList[m_iCurrentCamera].iAVPort == 1){// Channel 1
if(M7_WriteAuxCom(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
else{
if(M7_WriteAuxCom2(m_hM7, nStrLen, szCommandLine)){
MessageBox(NULL, "WriteComm error", "error", MB_OK | MB_ICONERROR);
return 0;
}
}
return 1;
}
bool CCamera::SwitchCamera(HWND hwndMsgHandler, HWND hwndVideoWnd_MPEG, int nCamera)
{
if(m_iCurrentCamera != INVALIDCAMERA){ // if the current camera is on line, disconncet the
// connection first.
switch(pCameraList[m_iCurrentCamera].iType){
case INVALID:
break;
case JIMU:
JIMU_Disconnect();
m_iCurrentCamera = INVALIDCAMERA;
Sleep(500);
break;
case MPEG:
//MPEG_StopRecvShow();
mySocket.CloseCurrentSocket();
m_iCurrentCamera = INVALIDCAMERA;
break;
default:
break;
}
}
// connect to the new server.
switch(pCameraList[nCamera].iType){
case INVALID:
break;
case JIMU:
if(JIMU_MyDial(hwndMsgHandler, nCamera))
m_iCurrentCamera = nCamera;
break;
case MPEG:
if(pCameraList[nCamera].iAVPort == 1){
if(mySocket.ConnectToServer(hwndMsgHandler,
pCameraList[nCamera].lpszAdress, // "202.118.239.236",
88,
mySocket.GetUdpPortForVideo(), // 6000
pCameraList[nCamera].iAVPort)){
m_iCurrentCamera = nCamera;
//MPEG_StartRecvShow(hwndVideoWnd_MPEG, iUdpPort_MPEG);
SetTimer(hwndVideoWnd_MPEG, TIMER_READYFORRECVVIDEO, 10000, 0);
}
else MessageBox(NULL, "Cann't connect to server", "Error", MB_OK);
}
else if(pCameraList[nCamera].iAVPort == 2){
if(mySocket.ConnectToServer(hwndMsgHandler,
pCameraList[nCamera].lpszAdress, // "202.118.239.236",
80,
mySocket.GetUdpPortForVideo(), // 6000
pCameraList[nCamera].iAVPort)){
m_iCurrentCamera = nCamera;
//MPEG_StartRecvShow(hwndVideoWnd_MPEG, iUdpPort_MPEG);
SetTimer(hwndVideoWnd_MPEG, TIMER_READYFORRECVVIDEO, 10000, 0);
}
else MessageBox(NULL, "Cann't connect to server", "Error", MB_OK);
}
break;
default:
break;
}
return 1;
}
bool CCamera::MPEG_StartRecvShow(HWND hWnd)
{
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = 640;
rect.bottom = 480;
RecvShowMPEG(hWnd, hWnd, 1, LXD_RECEIVE_BROADCAST, rect, "",
"", mySocket.GetUdpPortForVideo(), LXD_VIDEO_MODE_PAL,
LXD_MPEG1_VIDEO,"");
ShowWindow(hWnd, SW_SHOW);
return 1;
}
bool CCamera::GetCameraInfo(CCameraInfo * pci, int nCam)
{
pci ->iAVPort = pCameraList[nCam].iAVPort;
pci ->iProtocol = pCameraList[nCam].iProtocol;
pci ->iType = pCameraList[nCam].iType;
strcpy(pci ->lpszAdress, pCameraList[nCam].lpszAdress);
for(int i = 0; i < 500; i ++)
pci ->piCmnID[i] = pCameraList[nCam].piCmnID[i];
return 1;
}
bool CCamera::SetCameraInfo(CCameraInfo * pci, int nCam)
{
HKEY hKey;
char lpszString[50];
DWORD dwValue;
char lpszValue[2000];
char lpszTemp[50];
pCameraList[nCam].iAVPort = pci ->iAVPort;
pCameraList[nCam].iProtocol = pci ->iProtocol;
pCameraList[nCam].iType = pci ->iType;
strcpy(pCameraList[nCam].lpszAdress, pci->lpszAdress);
for(int i = 0; i < 500; i ++)
pCameraList[nCam].piCmnID[i] = pci ->piCmnID[i];
if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard\\Cameras", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS){
MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);
return 0;
}
sprintf(lpszString, "Type%d", nCam);
dwValue = pci ->iType;
RegSetValueEx(hKey, lpszString, NULL, REG_DWORD, (BYTE*)&dwValue, 4);
sprintf(lpszString, "Address%d", nCam);
RegSetValueEx(hKey, lpszString, NULL, REG_SZ, (BYTE*)(pci ->lpszAdress), strlen(pci ->lpszAdress));
sprintf(lpszString, "Protocol%d", nCam);
dwValue = pci ->iProtocol;
RegSetValueEx(hKey, lpszString, NULL, REG_DWORD, (BYTE*)&dwValue, 4);
sprintf(lpszString, "Port%d", nCam);
dwValue = pci ->iAVPort;
RegSetValueEx(hKey, lpszString, NULL, REG_DWORD, (BYTE*)&dwValue, 4);
sprintf(lpszString, "CmnQ%d", nCam);
lpszValue[0] = '\0';
i = 0;
while((pci ->piCmnID[i] != -1) && (i < 500)){
sprintf(lpszTemp, "%d", pci ->piCmnID[i]);
strcat(lpszValue, lpszTemp);
if(pci ->piCmnID[i + 1] != -1){
sprintf(lpszTemp, ",");
strcat(lpszValue, lpszTemp);
}
i ++;
}
RegSetValueEx(hKey, lpszString, NULL, REG_SZ, (BYTE*)lpszValue, strlen(lpszValue));
RegCloseKey(hKey);
return 1;
}
bool CCamera::MPEG_StopRecvShow()
{
StopRecvShowMPEG(1);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -