📄 webcamclient.cpp
字号:
#include <stdio.h>#include <string.h>#include <stdlib.h>#include "webcamclient.h"#include "btcamera.h"#include "btsocket.h"#include "global.h"#include "bycmd.h"#include "btrmtdevmgr.h"#include "bthandsfree.h"extern int g_nSendType;extern bool ConnectToWebCamServer();extern int localx;extern int localy;extern int localwidth;extern int localheight;extern int remotex;extern int remotey;extern int remotewidth;extern int remoteheight;extern int cmdsave;int mycount;WebCamClient::WebCamClient(){ mycount=0; m_bConnected = false; m_bSend = false; m_nCurPost = 0;}void WebCamClient::OnReceive(){ char* buf = m_pData; int& pos = m_nCurPost; const int n = Receive(buf + pos, sizeof(m_pData) - pos); const int len = n; printf("%d\n", cmdsave); if (n == 0 || n < 0) { printf("WebCamClient::OnReceive close %d\n", n); if(cmdsave!=1) OnClose();// printf("%d\n", cmdsave); return; } mycount+=1; int cur_len = len + pos; buf[cur_len] = '\0'; pos += len; char cmd[10] = { 0 }; char pDataLen[10] = { 0 }; while (cur_len >= 10) { strncpy(cmd, buf, 4); strncpy(pDataLen, buf + 4, 6); int data_len = atoi(pDataLen) + 10;// if (strcmp(cmd, "0041") == 0 || strcmp(cmd, "0052") == 0)// data_len += 8;// if (strcmp(cmd, "0006") == 0 || strcmp(cmd, "0007") == 0)// data_len += 4; printf("cur_len = %d, data_len = %d\n", cur_len, data_len); if (cur_len < data_len) break; ProcessWebCamData(cmd, buf + 10, data_len); cur_len -= data_len; pos -= data_len; memmove(buf, buf + len, cur_len); }}void WebCamClient::ProcessWebCamData(const char* cmd, const char* data, int len){ if(NULL == data) { return; } if (strcmp(cmd, "0006") == 0) // 摄像头打开 { char no[10] = { 0 }; strncpy(no, data, 4); printf("web 摄像头窗口打开 %s\n", no); if (!m_bSend) { g_bCamSend = false; m_bSend = true; const int n = atoi(no); ConnectToCamera(n); printf("ConnectToCamera() %d\n", g_bCameraConnected); } } else if (strcmp(cmd, "0007") == 0) // 摄像头关闭 { printf("web 摄像头窗口关闭!!!\n"); g_bCamSend = false; m_bSend = false; DisconnectCamera(); } else if (strcmp(cmd, "0008") == 0) //connect maintain { int n; n = Send("0008", 4); if(n>0) { printf("6666666666666666666666666666666666666666666666666666666666666666666666666666666\n"); } n += Send("000000", 6); if(n>0) { printf("7777777777777777777777777777777777777777777777777777777777777777777777777777777\n"); } } else if (strcmp(cmd, "0041") == 0 || // 摄像头数据,MBOX strcmp(cmd, "0052") == 0) // 摄像头数据,EIM { const char* p = data + 8; display_jpeg_dynamic(p, len - 8,remotex,remotey,remotewidth,remoteheight); // 发送到 pc 测试/* IpcPacket o(0); o.WriteData(p, len); g_btSock.SendTo(o, BY_MAIN_PORT, "192.168.2.243");*/ }}/*void WebCamClient::OnReceive(){ char buf[1024] = { 0 }; int mysize; const int n = Receive(buf, sizeof(buf)); // printf("WebCamClient::OnReceive() %d", n); if (n == 0 || n < 0) { printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); printf("WebCamClient::OnReceive\n"); OnClose(); return; } mysize=sizeof(buf); mycount+=1; printf("%d\n",mycount); printf("%d\n",mysize); char cmd[10] = { 0 }; char no[10] = { 0 }; char pDataLen[10] = { 0 }; strncpy(cmd, buf, 4); printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); printf("%s\n", cmd); printf("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n"); strncpy(pDataLen, buf + 4, 6); printf("%s\n",pDataLen); int data_len = atoi(pDataLen); if (strcmp(cmd, "0041") == 0 || strcmp(cmd, "0052") == 0) { strncpy(no, buf + 10, 8); printf("%s\n",no); } if (strcmp(cmd, "0006") == 0 || strcmp(cmd, "0007") == 0) strncpy(no, buf + 10, 4); printf("%s\n",no); ProcessWebCamData(cmd, buf + 10, data_len);}*/void WebCamClient::OnClose(){ m_nCurPost = 0; // g_nSendType = 0; if (m_bSend) { printf("web 摄像头窗口关闭!!!\n"); g_bCamSend = false; m_bSend = false; DisconnectCamera(); } m_bConnected = false; Close(); printf("OnClose\n"); // ConnectToWebCamServer();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -