You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

650 lines
13 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "HvdllStr.h"
#include <string.h>
//#include <stdio.h>
static int RecordInfoBeginCallBack(PVOID pUserData, DWORD dwCarID)
{
// printf("%s pUserData = %p, dwCarID = %lu\n", __FUNCTION__, pUserData, dwCarID);
HvdllStr *pThis = (HvdllStr *)pUserData;
if ((pUserData == NULL) || (pThis == NULL))
{
return 0;
}
// printf("bigen dwCarID = %lu\n", dwCarID);
//return 0;
return pThis->OnRecordInfoBegin(dwCarID);
};
static int RecordInfoEndCallBack(PVOID pUserData, DWORD dwCarID)
{
// printf("%s pUserData = %p, dwCarID = %lu\n", __FUNCTION__, pUserData, dwCarID);
HvdllStr *pThis = (HvdllStr *)pUserData;
if ((pUserData == NULL) || (pThis == NULL))
{
return 0;
}
// printf("end dwCarID = %lu\n", dwCarID);
// return 0;
return pThis->OnRecordInfoEnd(dwCarID);
};
static int RecordInfoPlateCallBack(PVOID pUserData,
DWORD dwCarID,
LPCSTR pcPlateNo,
LPCSTR pcAppendInfo,
DWORD dwRecordType,
DWORD64 dw64TimeMS)
{
HvdllStr *pThis = (HvdllStr *)pUserData;
if ((pUserData == NULL) || (pThis == NULL))
{
return 0;
}
//string temp;
//temp = gbk2utf8(pcPlateNo);
//printf("the str is %s\n",temp.c_str());
//printf("the str is %s\n",pcPlateNo);
//return 0;
return pThis->OnRecordInfoPlate(dwCarID, pcPlateNo, pcAppendInfo, dwRecordType, dw64TimeMS);
}
static int RecordInfoBigImageCallBack(PVOID pUserData,
DWORD dwCarID,
WORD wImgType,
WORD wWidth,
WORD wHeight,
PBYTE pbPicData,
DWORD dwImgDataLen,
DWORD dwRecordType,
DWORD64 dw64TimeMS)
{
HvdllStr *pThis = (HvdllStr *)pUserData;
if ((pUserData == NULL) || (pThis == NULL))
{
return 0;
}
// return 0;
return pThis->OnRecordInfoBigImage(dwCarID, wImgType, wWidth, wHeight, pbPicData, dwImgDataLen, dwRecordType, dw64TimeMS);
}
static int RecordInfoSmallImageCallBack(PVOID pUserData,
DWORD dwCarID,
WORD wWidth,
WORD wHeight,
PBYTE pbPicData,
DWORD dwImgDataLen,
DWORD dwRecordType,
DWORD64 dw64TimeMS)
{
HvdllStr *pThis = (HvdllStr *)pUserData;
if ((pUserData == NULL) || (pThis == NULL))
{
return 0;
}
//return 0;
return pThis->OnRecordInfoSmallImage(dwCarID, wWidth, wHeight, pbPicData, dwImgDataLen, dwRecordType, dw64TimeMS);
}
static int RecordInfoBinaryImageCallBack(PVOID pUserData,
DWORD dwCarID,
WORD wWidth,
WORD wHeight,
PBYTE pbPicData,
DWORD dwImgDataLen,
DWORD dwRecordType,
DWORD64 dw64TimeMS)
{
HvdllStr *pThis = (HvdllStr *)pUserData;
if ((pUserData == NULL) || (pThis == NULL))
{
return 0;
}
// return 0;
return pThis->OnRecordInfoBinaryImage(dwCarID, wWidth, wHeight, pbPicData, dwImgDataLen, dwRecordType, dw64TimeMS);
}
HvdllStr::HvdllStr()
{
}
HvdllStr::~HvdllStr()
{
}
int HvdllStr::InitStr()
{
m_hDevice = NULL;
memset(m_ipAddr, 0, sizeof(m_ipAddr));
memset(m_PlateNoBuf, 0, sizeof(m_PlateNoBuf));
InitCallBackStr(m_BeginFunStr);
InitCallBackStr(m_EndFunStr);
InitCallBackStr(m_PlateFunStr);
InitCallBackStr(m_BiglmgFunStr);
InitCallBackStr(m_SmallImgFunStr);
InitCallBackStr(m_BinaryImgFunStr);
return 0;
}
void HvdllStr::InitCallBackStr(myFunCallBack &callstr)
{
callstr.pFirstParameter = NULL;
callstr.pFunction = NULL;
callstr.wVideoID = 0;
}
int HvdllStr::OpenHv(char *pcIP)
{
InitStr();
if (m_hDevice != NULL)
{
HVAPI_CloseEx(m_hDevice);
m_hDevice = NULL;
}
strcpy(m_ipAddr, pcIP);
m_hDevice = HVAPI_OpenEx(pcIP, NULL);
if (m_hDevice == NULL)
{
return -1;
}
return S_OK;
}
HRESULT HvdllStr::CloseHv()
{
if (m_hDevice != NULL)
{
HVAPI_CloseEx(m_hDevice);
m_hDevice = NULL;
}
return S_OK;
}
HRESULT HvdllStr::HvIsConnected(INT32 *piStatus)
{
if (!m_hDevice)
{
*piStatus = -1;
}
else
{
*piStatus = 0;
}
return S_OK;
}
HRESULT HvdllStr::SetHvCallBack(
void *pFunction,
void *pFirstParameter,
WORD wVideoID,
WORD wStream)
{
HRESULT hRet;
switch (wStream)
{
case _TYPE_PLATE_STR:
hRet = HVAPI_SetCallBackEx(m_hDevice, (PVOID)RecordInfoPlateCallBack, this, 0, CALLBACK_TYPE_RECORD_PLATE, NULL);
if (S_OK == hRet)
{
m_PlateFunStr.wVideoID = wVideoID;
m_PlateFunStr.pFunction = pFunction;
}
break;
case _TYPE_BIG_IMAGE:
hRet = HVAPI_SetCallBackEx(m_hDevice, (PVOID)RecordInfoBigImageCallBack, this, 0, CALLBACK_TYPE_RECORD_BIGIMAGE, NULL);
if (S_OK == hRet)
{
m_BiglmgFunStr.wVideoID = wVideoID;
m_BiglmgFunStr.pFunction = pFunction;
}
break;
case _TYPE_SMALL_IMAGE:
hRet = HVAPI_SetCallBackEx(m_hDevice, (PVOID)RecordInfoSmallImageCallBack, this, 0, CALLBACK_TYPE_RECORD_SMALLIMAGE, NULL);
if (S_OK == hRet)
{
m_SmallImgFunStr.wVideoID = wVideoID;
m_SmallImgFunStr.pFunction = pFunction;
}
break;
case _TYPE_BINARY_IMAGE:
hRet = HVAPI_SetCallBackEx(m_hDevice, (PVOID)RecordInfoBinaryImageCallBack, this, 0, CALLBACK_TYPE_RECORD_BINARYIMAGE, NULL);
if (S_OK == hRet)
{
m_BinaryImgFunStr.wVideoID = wVideoID;
m_BinaryImgFunStr.pFunction = pFunction;
}
break;
case _TYPE_CARINFO_BEGIN:
hRet = HVAPI_SetCallBackEx(m_hDevice, (PVOID)RecordInfoBeginCallBack, this, 0, CALLBACK_TYPE_RECORD_INFOBEGIN, NULL);
if (S_OK == hRet)
{
m_BeginFunStr.wVideoID = wVideoID;
m_BeginFunStr.pFunction = pFunction;
}
break;
case _TYPE_CARINFO_END:
hRet = HVAPI_SetCallBackEx(m_hDevice, (PVOID)RecordInfoEndCallBack, this, 0, CALLBACK_TYPE_RECORD_INFOEND, NULL);
if (S_OK == hRet)
{
m_EndFunStr.wVideoID = wVideoID;
m_EndFunStr.pFunction = pFunction;
}
break;
default:
hRet = -1;
break;
}
return hRet;
}
int HvdllStr::OnRecordInfoBegin(DWORD dwCarID)
{
if (!m_BeginFunStr.pFunction)
{
return 0;
}
CARINFO_BEGIN_CALLBACK pFun = (CARINFO_BEGIN_CALLBACK)(m_BeginFunStr.pFunction);
pFun(m_BeginFunStr.pFirstParameter, dwCarID);
return 0;
}
int HvdllStr::OnRecordInfoEnd(DWORD dwCarID)
{
if (!m_EndFunStr.pFunction)
{
return 0;
}
CARINFO_END_CALLBACK pFun = (CARINFO_END_CALLBACK)(m_EndFunStr.pFunction);
pFun(m_EndFunStr.pFirstParameter, dwCarID);
return 0;
}
int HvdllStr::OnRecordInfoPlate(
DWORD dwCarID,
LPCSTR pcPlateNo,
LPCSTR pcAppendInfo,
DWORD dwRecordType,
DWORD64 dw64TimeMS)
{
if (!m_PlateFunStr.pFunction)
{
return 0;
}
char szPlateNo[32]; // 车牌号码,不包含颜色
char szPlateColor[8]; // 车牌颜色
// char szPlate[64]; // 车牌包括颜色蓝桂123456
string splateno;
string scolor;
int iLen;
int iRet;
BYTE bone,btwo;
PLATE_NO_CALLBACK pFun = (PLATE_NO_CALLBACK)(m_PlateFunStr.pFunction);
memset(szPlateNo, 0, sizeof(szPlateNo));
memset(szPlateColor, 0, sizeof(szPlateColor));
// memset(szPlate, 0, sizeof(szPlate));
// memset(ptemp,0,sizeof(pTemp));
// 车牌号
if (!pcPlateNo)
{
return 0;
}
iLen = strlen(pcPlateNo);
if (iLen >= 32)
{
return 0;
}
iRet =0;
for(int i =0; i<(iLen-1); i++)
{
bone = (BYTE) (pcPlateNo[i]);
//gbk
if(bone <= 0x80)
{
continue;
}
btwo = (BYTE) (pcPlateNo[i+1]);
i++;
if((0xCE == bone) && (0xDE == btwo) )
{
iRet =1;
break;
}
}
//string strPlate = gbk2utf8(pcPlateNo);
if ( (iLen <= 9)|| (1 ==iRet)) // 无车牌
{
// strcpy(szPlateColor,"无")
// strcpy(szPlateNo,"无车牌")
//splateno = "无车牌";
//scolor = "无";
// StringCbCopy(szPlateColor, sizeof(szPlateColor), "无");
// StringCbCopy(szPlateNo, sizeof(szPlateNo), "无车牌");
// StringCbCopy(szPlate, sizeof(szPlate), "无车牌");
CreatePlateNo(NULL, NULL);
}
else
{
strncpy(szPlateColor, pcPlateNo, 2); // 车牌颜色
strcpy(szPlateNo, pcPlateNo + 2);
CreatePlateNo(szPlateNo,szPlateColor,1);
//scolor = gbk2utf8(szPlateColor);
//splateno = gbk2utf8(szPlateNo);
// StringCbCopy(szPlateNo, sizeof(szPlateNo), &pcPlateNo[2]); // 车牌号码
// StringCbCopy(szPlate, sizeof(szPlate), pcPlateNo); // 带颜色的车牌号码
}
//CreatePlateNo(splateno, scolor);
pFun(m_PlateFunStr.pFirstParameter, dwCarID, m_PlateNoBuf, dw64TimeMS);
return 0;
}
int HvdllStr::OnRecordInfoBigImage(
DWORD dwCarID,
WORD wImgType,
WORD wWidth,
WORD wHeight,
PBYTE pbPicData,
DWORD dwImgDataLen,
DWORD dwRecordType,
DWORD64 dw64TimeMS)
{
if (!m_BiglmgFunStr.pFunction)
{
return 0;
}
if ((pbPicData == NULL) || (dwImgDataLen <= 0))
{
return -1;
}
HvImage bigImage;
WORD wHighSize, wLowSize;
BIG_IMAGE_CALLBACK pFun = (BIG_IMAGE_CALLBACK)(m_BiglmgFunStr.pFunction);
// bigImage.pbImgData = new BYTE[1024];
bigImage.pbImgData = new BYTE[dwImgDataLen];
if (!bigImage.pbImgData)
{
return -2;
}
memset(bigImage.pbImgData, 0, dwImgDataLen);
memcpy(bigImage.pbImgData, pbPicData, dwImgDataLen);
bigImage.wImgType = wImgType;
bigImage.iImgWidth = wWidth;
bigImage.iImgHeight = wHeight;
bigImage.iImgSize = dwImgDataLen;
bigImage.dw64TimeMS = dw64TimeMS;
CreateImgSize(wHighSize, wLowSize, dwImgDataLen);
pFun(m_BiglmgFunStr.pFirstParameter, dwCarID, wWidth, wHeight, IMAGE_JPEG, wLowSize, bigImage.pbImgData, 1, wHighSize, 0, 0, dw64TimeMS);
// SafeDelMemory(bigImage.pbImgData, true);
DelHvImage(bigImage);
//
return 0;
}
int HvdllStr::OnRecordInfoSmallImage(
DWORD dwCarID,
WORD wWidth,
WORD wHeight,
PBYTE pbPicData,
DWORD dwImgDataLen,
DWORD dwRecordType,
DWORD64 dw64TimeMS)
{
WORD wTemp;
int iSmallLen = 1024 * 200;
int iSmallBmpLen = iSmallLen;
BYTE buf[1024 * 200];
HRESULT hr = E_FAIL;
HvImage smallImage;
SMALL_IMAGE_CALLBACK pFun;
if (!m_SmallImgFunStr.pFunction)
{
return 0;
}
if ((pbPicData == NULL) || (dwImgDataLen <= 0))
{
return -1;
}
// 小图转位图
memset(buf, 0, sizeof(buf));
hr = HVAPIUTILS_SmallImageToBitmapEx(pbPicData, wWidth, wHeight, buf, &iSmallBmpLen);
if (hr != S_OK)
{
// SafeDelMemory(m_pcurHvResult->smallImage.pbImgData, true);
return -2;
}
iSmallLen = 1024 * 100;
smallImage.pbImgData = new BYTE[iSmallLen];
if (smallImage.pbImgData == NULL)
{
return -3;
}
// ZeroMemory(m_pcurHvResult->smallImage.pbImgData, iSmallLen);
memset(smallImage.pbImgData, 0, iSmallLen);
// int iTempLen ;
// if (!Bmp2Jpg(buf, iSmallBmpLen, smallImage.pbImgData, &iSmallLen))
//{
// SafeDelMemory(smallImage.pbImgData, true);
// return -4;
// }
// m_pcurHvResult->smallImage.wImgType = RECORD_BIGIMG_PLATE;
// smallImage.iImgSize = iSmallLen;
// smallImage.dw64TimeMS = dw64TimeMS;
// wTemp = LOWORD(iSmallLen);
// pFun = (SMALL_IMAGE_CALLBACK)(m_SmallImgFunStr.pFunction);
// pFun(m_SmallImgFunStr.pFirstParameter, dwCarID, wWidth, wHeight, IMAGE_JPEG, wTemp, smallImage.pbImgData, dw64TimeMS);
// SafeDelMemory(smallImage.pbImgData, true);
DelHvImage(smallImage);
return 0;
}
int HvdllStr::OnRecordInfoBinaryImage(
DWORD dwCarID,
WORD wWidth,
WORD wHeight,
PBYTE pbPicData,
DWORD dwImgDataLen,
DWORD dwRecordType,
DWORD64 dw64TimeMS)
{
WORD wTemp;
HvImage binImage;
BINARY_IMAGE_CALLBACK pFun;
if (!m_BinaryImgFunStr.pFunction)
{
return 0;
}
if ((pbPicData == NULL) || (dwImgDataLen <= 0))
{
return -1;
}
binImage.pbImgData = new BYTE[dwImgDataLen];
if (binImage.pbImgData == NULL)
{
return -1;
}
memset(binImage.pbImgData, 0, dwImgDataLen);
memcpy(binImage.pbImgData, pbPicData, dwImgDataLen);
binImage.iImgSize = dwImgDataLen;
binImage.iImgWidth = wWidth;
binImage.iImgHeight = wHeight;
binImage.dw64TimeMS = dw64TimeMS;
// binImage.wImgType = RECORD_BIGIMG_PLATE_BIN;
wTemp = (WORD)(dwImgDataLen & 0xFFFF);
pFun = (BINARY_IMAGE_CALLBACK)(m_BinaryImgFunStr.pFunction);
pFun(m_BinaryImgFunStr.pFirstParameter, dwCarID, wWidth, wHeight, IMAGE_BIN, wTemp, binImage.pbImgData, dw64TimeMS);
// SafeDelMemory(binImage.pbImgData, true);
DelHvImage(binImage);
return 0;
}
//
void HvdllStr::CreatePlateNo(char * plateno, char * pColor, int isNoPlate)
{
int iLen;
char buf[8];
//char ptem[64];
string stemp;
BYTE bone,btwo;
//int iLen;
memset(m_PlateNoBuf, 0, sizeof(m_PlateNoBuf));
iLen = strlen(plateno);
//memset(ptem, 0, sizeof(ptem));
if( 0 == isNoPlate)
{
//strcpy(m_PlateNoBuf, "无车牌_9");
m_PlateNoBuf [0] = 0xCE;
m_PlateNoBuf [1] = 0xDE;
m_PlateNoBuf [2] = 0xB3;
m_PlateNoBuf [3] = 0xB5;
m_PlateNoBuf [4] = 0xC5;
m_PlateNoBuf [5] = 0xC6;
m_PlateNoBuf [6] = 0x5F;
m_PlateNoBuf [7] = 0x39;
return;
}
//stemp = gbk2utf8(plateno);
strcpy(m_PlateNoBuf,plateno);
strcat(m_PlateNoBuf,"_");
memset(buf, 0, sizeof(buf));
bone = (BYTE) (pColor[0]);
btwo = (BYTE) (pColor[1]);
if( ( 0xC0 == bone) && ( 0xB6 == btwo) )
//if (0 == pColor.compare("蓝"))
{
buf[0] = '0';
}
else if( ( 0xBB == bone) && ( 0xC6 == btwo) )
//else if (0 == pColor.compare("黄"))
{
buf[0] = '1';
}
else if( ( 0xBA == bone) && ( 0xDA == btwo) )
//else if (0 == pColor.compare("黑"))
{
buf[0] = '2';
}
else if( ( 0xB0 == bone) && ( 0xD7 == btwo) )
//else if (0 == pColor.compare("白"))
{
buf[0] = '3';
}
else if( ( 0xC2 == bone) && ( 0xCC == btwo) )
//else if (0 == pColor.compare("绿"))
{
//strcpy(ptem, plateno.c_str());
if (('D' == plateno[iLen - 1]) || ('F' == plateno[iLen - 1]))
{
buf[0] = '5';
}
else
{
buf[0] = '4';
}
}
else
{
buf[0] = '9';
}
strcat(m_PlateNoBuf, buf);
}
void HvdllStr::CreateImgSize(WORD &whigh, WORD &wlow, DWORD dLen)
{
WORD wTemp;
BYTE bHigh, bLow;
DWORD dTemp;
wlow = (WORD)(dLen & 0xFFFF);
dTemp = dLen >> 16;
wTemp = (WORD)(dTemp & 0xFFFF);
bLow = (BYTE) (wTemp & 0xFF);
// bLow = LOBYTE(wTemp);
bHigh = 0xFF;
whigh = bHigh * 256 + bLow;
// whigh = MAKEWORD(bLow, bHigh);
}