www.pudn.com > ThermoGroup-SDK.rar > MagDevice.cpp, change:2016-05-09,size:15501b


//#include "stdafx.h" 
 
//#include "winsock2.h" 
 
#include "MagDevice.h" 
 
#ifdef _WIN64 
	#pragma comment(lib, "ThermoGroupSDKLib_x64.lib")  
#else 
	#pragma comment(lib, "ThermoGroupSDKLib.lib") 
#endif 
 
#define MAX_CHANNELINDEX	(128) 
 
CMagDevice::CMagDevice(HWND hWndMsg) :  
m_hWndMsg(hWndMsg) 
,m_bInitialized(FALSE) 
,m_intChannelIndex(-1) 
,m_bIsRecordingAvi(FALSE) 
,m_bIsRecordingMGS(FALSE) 
,m_bIsRecordingLocalAvi(FALSE) 
,m_intCamIPAddr(0) 
{ 
	memset(&m_CamInfo, 0, sizeof(m_CamInfo)); 
	memset(&m_RegContent, 0, sizeof(m_RegContent)); 
 
	Initialize(); 
} 
 
CMagDevice::~CMagDevice() 
{ 
	if (MAG_IsProcessingImage(m_intChannelIndex)) 
	{ 
		MAG_StopProcessImage(m_intChannelIndex); 
	} 
 
	if (MAG_IsListening(m_intChannelIndex)) 
	{ 
		MAG_StopListen(m_intChannelIndex); 
	} 
 
	if (MAG_IsLinked(m_intChannelIndex)) 
	{ 
		DisLinkCamera();//include stop sd storage 
	} 
 
	if (MAG_IsInitialized(m_intChannelIndex)) 
	{ 
		MAG_Free(m_intChannelIndex); 
	} 
 
	if (MAG_IsChannelAvailable(m_intChannelIndex)) 
	{ 
		MAG_DelChannel(m_intChannelIndex); 
	} 
} 
 
BOOL CMagDevice::Initialize() 
{ 
	if (m_bInitialized) 
	{ 
		return TRUE; 
	} 
 
	if (m_intChannelIndex<=0 || m_intChannelIndex>32) 
	{ 
		for (int i=1; i<=MAX_CHANNELINDEX; i++) 
		{ 
			if (!MAG_IsChannelAvailable(i))//find an unused channel 
			{ 
				BOOL bSuccess = MAG_NewChannel(i); 
				//ASSERT(bSuccess); 
 
				m_intChannelIndex = i; 
 
				break; 
			} 
		} 
	} 
 
	if (m_intChannelIndex>0 && m_intChannelIndex<=MAX_CHANNELINDEX && MAG_IsLanConnected()) 
	{ 
		m_bInitialized = MAG_Initialize(m_intChannelIndex, m_hWndMsg); 
	} 
 
	return m_bInitialized; 
} 
 
BOOL CMagDevice::IsLinked() 
{ 
	return MAG_IsLinked(m_intChannelIndex); 
} 
 
BOOL CMagDevice::LinkCamera(const char * charIp, UINT intTimeoutMS) 
{ 
	return LinkCamera(inet_addr(charIp), intTimeoutMS); 
} 
 
BOOL CMagDevice::LinkCameraEx(const char * charIp, USHORT shortPort, const char * charUser, const char * charPwd, UINT intTimeoutMS) 
{ 
	return LinkCameraEx(inet_addr(charIp), shortPort, charUser, charPwd, intTimeoutMS); 
} 
 
BOOL CMagDevice::LinkCamera(UINT intIP, UINT intTimeoutMS) 
{ 
	if (MAG_LinkCamera(m_intChannelIndex, intIP, intTimeoutMS)) 
	{ 
		m_intCamIPAddr = intIP; 
		MAG_GetCamInfo(m_intChannelIndex, &m_CamInfo, sizeof(m_CamInfo)); 
		MAG_ReadCameraRegContent(m_intChannelIndex, &m_RegContent, MAG_DEFAULT_TIMEOUT, FALSE); 
 
		return TRUE; 
	} 
	else 
	{ 
		return FALSE; 
	} 
} 
 
BOOL CMagDevice::LinkCameraEx(UINT intIP, USHORT shortPort, const char * charUser, const char * charPwd, UINT intTimeoutMS) 
{ 
	if (MAG_LinkCameraEx(m_intChannelIndex, intIP, shortPort, charUser, charPwd, intTimeoutMS)) 
	{ 
		m_intCamIPAddr = intIP; 
		MAG_GetCamInfo(m_intChannelIndex, &m_CamInfo, sizeof(m_CamInfo)); 
		MAG_ReadCameraRegContent(m_intChannelIndex, &m_RegContent, MAG_DEFAULT_TIMEOUT, FALSE); 
 
		return TRUE; 
	} 
	else 
	{ 
		return FALSE; 
	} 
} 
 
void CMagDevice::DisLinkCamera() 
{ 
	//remember to stop sd storage before dislink 
	if (m_bIsRecordingMGS) 
	{ 
		SDStorageMGSStop(); 
	} 
 
	if (m_bIsRecordingAvi) 
	{ 
		SDStorageAviStop(); 
	} 
 
	m_intCamIPAddr = 0; 
 
	return MAG_DisLinkCamera(m_intChannelIndex); 
} 
 
UINT CMagDevice::GetRecentHeartBeat() 
{ 
	return MAG_GetRecentHeartBeat(m_intChannelIndex); 
} 
 
BOOL CMagDevice::SetReConnectCallBack(MAG_RECONNECTCALLBACK pCallBack, void * pUserData) 
{ 
	return MAG_SetReConnectCallBack(m_intChannelIndex, pCallBack, pUserData); 
} 
 
BOOL CMagDevice::IsListening() 
{ 
	return MAG_IsListening(m_intChannelIndex); 
} 
 
BOOL CMagDevice::ListenTo(UINT intIP) 
{ 
	if (MAG_ListenTo(m_intChannelIndex, intIP)) 
	{ 
		MAG_GetCamInfo(m_intChannelIndex, &m_CamInfo, sizeof(m_CamInfo)); 
		return TRUE; 
	} 
	else 
	{ 
		return FALSE; 
	} 
} 
 
void CMagDevice::StopListen() 
{ 
	return MAG_StopListen(m_intChannelIndex); 
} 
 
BOOL CMagDevice::ResetCamera() 
{ 
	//the user should stop image process before reset 
	//if you forget, the sdk will call MAG_StopProcessImage() 
 
	//remember to stop sd storage before reset 
	if (m_bIsRecordingMGS) 
	{ 
		SDStorageMGSStop(); 
	} 
 
	if (m_bIsRecordingAvi) 
	{ 
		SDStorageAviStop(); 
	} 
 
	if (MAG_ResetCamera(m_intChannelIndex)) 
	{ 
		//MAG_ResetCamera() will call MAG_Free() and MAG_DelChannel() 
		//so the channel is invalid now 
		m_bInitialized = FALSE; 
		m_intChannelIndex = -1; 
 
		//this object is reusable after call Initialize() 
 
		return TRUE; 
	} 
	else 
	{ 
		return FALSE; 
	} 
} 
 
BOOL CMagDevice::TriggerFFC() 
{ 
	return MAG_TriggerFFC(m_intChannelIndex); 
} 
 
BOOL CMagDevice::AutoFocus() 
{ 
	return MAG_SetPTZCmd(m_intChannelIndex, PTZFocusAuto, 0); 
} 
 
BOOL CMagDevice::SetIoAlarmState(BOOL bAlarm) 
{ 
	return MAG_SetIoAlarmState(m_intChannelIndex, bAlarm); 
} 
 
BOOL CMagDevice::SetPTZCmd(enum PTZCmd cmd, DWORD dwPara) 
{ 
	return MAG_SetPTZCmd(m_intChannelIndex, cmd, dwPara); 
} 
 
BOOL CMagDevice::QueryPTZState(enum PTZQuery query, int * intValue, UINT intTimeoutMS) 
{ 
	return MAG_QueryPTZState(m_intChannelIndex, query, intValue, intTimeoutMS); 
} 
 
BOOL CMagDevice::SetSerialCmd(const BYTE * buffer, UINT intBufferLen) 
{ 
	return MAG_SetSerialCmd(m_intChannelIndex, buffer, intBufferLen); 
} 
 
BOOL CMagDevice::SetSerialCallBack(MAG_SERIALCALLBACK pCallBack, void * pUserData) 
{ 
	return MAG_SetSerialCallBack(m_intChannelIndex, pCallBack, pUserData); 
} 
 
BOOL CMagDevice::GetCameraTemperature(int intT[4], UINT intTimeoutMS) 
{ 
	return MAG_GetCameraTemperature(m_intChannelIndex, intT, intTimeoutMS); 
} 
 
BOOL CMagDevice::SetCameraRegContent(const struct_CeRegContent * pContent) 
{ 
	if (MAG_SetCameraRegContent(m_intChannelIndex, pContent)) 
	{ 
		MAG_ReadCameraRegContent(m_intChannelIndex, &m_RegContent, MAG_DEFAULT_TIMEOUT, FALSE); 
		return TRUE; 
	} 
	else 
	{ 
		return FALSE; 
	} 
} 
 
BOOL CMagDevice::SetUserROIs(const struct_UserROIs * pROI) 
{ 
	return MAG_SetUserROIs(m_intChannelIndex, pROI); 
} 
 
BOOL CMagDevice::IsProcessingImage() 
{ 
	return MAG_IsProcessingImage(m_intChannelIndex); 
} 
 
BOOL CMagDevice::StartProcessImage(const OutputPara * paraOut, MAG_FRAMECALLBACK funcFrame, DWORD dwStreamType, void * pUserData) 
{ 
	return MAG_StartProcessImage(m_intChannelIndex, paraOut, funcFrame, dwStreamType, pUserData); 
} 
 
BOOL CMagDevice::StartProcessPulseImage(const OutputPara * paraOut, MAG_FRAMECALLBACK funcFrame, DWORD dwStreamType, void * pUserData) 
{ 
	return MAG_StartProcessPulseImage(m_intChannelIndex, paraOut, funcFrame, dwStreamType, pUserData); 
} 
 
BOOL CMagDevice::TransferPulseImage() 
{ 
	return MAG_TransferPulseImage(m_intChannelIndex); 
} 
 
void CMagDevice::StopProcessImage() 
{ 
	if (m_bIsRecordingLocalAvi) 
	{ 
		LocalStorageAviStop(); 
	} 
 
	return MAG_StopProcessImage(m_intChannelIndex); 
} 
 
void CMagDevice::SetColorPalette(enum ColorPalette ColorPaletteIndex) 
{ 
	return MAG_SetColorPalette(m_intChannelIndex, ColorPaletteIndex); 
} 
 
BOOL CMagDevice::SetSubsectionEnlargePara(int intX1, int intX2, UCHAR byteY1, UCHAR byteY2) 
{ 
	return MAG_SetSubsectionEnlargePara(m_intChannelIndex, intX1, intX2, byteY1, byteY2); 
} 
 
void CMagDevice::SetIsothermalPara(int intLowerLimit, int intUpperLimit) 
{ 
	return MAG_SetIsothermalPara(m_intChannelIndex, intLowerLimit, intUpperLimit); 
} 
 
void CMagDevice::SetAutoEnlargePara(DWORD dwAutoEnlargeRange, int intBrightOffset, int intContrastOffset) 
{ 
	return MAG_SetAutoEnlargePara(m_intChannelIndex, dwAutoEnlargeRange, intBrightOffset, intContrastOffset); 
} 
 
void CMagDevice::SetEXLevel(enum EX ExLevel, int intCenterX, int intCenterY) 
{ 
	return MAG_SetEXLevel(m_intChannelIndex, ExLevel, intCenterX, intCenterY); 
} 
 
enum EX CMagDevice::GetEXLevel() 
{ 
	return MAG_GetEXLevel(m_intChannelIndex); 
} 
 
void CMagDevice::SetDetailEnhancement(int intDDE, BOOL bQuickDDE) 
{ 
	return MAG_SetDetailEnhancement(m_intChannelIndex, intDDE, bQuickDDE); 
} 
 
BOOL CMagDevice::SetVideoContrast(int intContrastOffset) 
{ 
	return MAG_SetVideoContrast(m_intChannelIndex, intContrastOffset); 
} 
 
BOOL CMagDevice::SetVideoBrightness(int intBrightnessOffset) 
{ 
	return MAG_SetVideoBrightness(m_intChannelIndex, intBrightnessOffset); 
} 
 
void CMagDevice::GetFixPara(struct_FixPara * pPara) 
{ 
	return MAG_GetFixPara(m_intChannelIndex, pPara); 
} 
 
float CMagDevice::SetFixPara(const struct_FixPara * pPara, BOOL bEnableCameraCorrect) 
{ 
	return MAG_SetFixPara(m_intChannelIndex, pPara, bEnableCameraCorrect); 
} 
 
int CMagDevice::FixTemperature(int intT, float fEmissivity, DWORD dwPosX, DWORD dwPosY) 
{ 
	return MAG_FixTemperature(m_intChannelIndex, intT, fEmissivity, dwPosX, dwPosY); 
} 
 
BOOL CMagDevice::GetOutputBMPdata(UCHAR const ** pData, BITMAPINFO const ** pInfo) 
{ 
	return MAG_GetOutputBMPdata(m_intChannelIndex, pData, pInfo); 
} 
 
BOOL CMagDevice::GetOutputBMPdata_copy(UCHAR * pBmp, UINT intBufferSize) 
{ 
	return MAG_GetOutputBMPdata_copy(m_intChannelIndex, pBmp, intBufferSize); 
} 
 
BOOL CMagDevice::GetOutputColorBardata(UCHAR const ** pData, BITMAPINFO const ** pInfo) 
{ 
	return MAG_GetOutputColorBardata(m_intChannelIndex, pData, pInfo); 
} 
 
BOOL CMagDevice::GetOutputColorBardata_copy(UCHAR * pColorBar, UINT intBufferSize) 
{ 
	return MAG_GetOutputColorBardata_copy(m_intChannelIndex, pColorBar, intBufferSize); 
} 
 
BOOL CMagDevice::GetOutputVideoData(UCHAR const **  pData, BITMAPINFO const ** pInfo) 
{ 
	return MAG_GetOutputVideoData(m_intChannelIndex, pData, pInfo); 
} 
 
BOOL CMagDevice::GetOutputVideoData_copy(UCHAR * pBmp, UINT intBufferSize) 
{ 
	return MAG_GetOutputVideoData_copy(m_intChannelIndex, pBmp, intBufferSize); 
} 
 
const UCHAR * CMagDevice::GetOutputVideoYV12() 
{ 
	return MAG_GetOutputVideoYV12(m_intChannelIndex); 
} 
 
const struct_State * CMagDevice::GetFrameStatisticalData() 
{ 
	return MAG_GetFrameStatisticalData(m_intChannelIndex); 
} 
 
BOOL CMagDevice::GetTemperatureData(int * pData, UINT intBufferSize, BOOL bEnableExtCorrect) 
{ 
	return MAG_GetTemperatureData(m_intChannelIndex, pData, intBufferSize, bEnableExtCorrect); 
} 
 
BOOL CMagDevice::GetTemperatureData_Raw(int * pData, UINT intBufferSize, BOOL bEnableExtCorrect) 
{ 
	return MAG_GetTemperatureData_Raw(m_intChannelIndex, pData, intBufferSize, bEnableExtCorrect); 
} 
 
int CMagDevice::GetTemperatureProbe(DWORD dwPosX, DWORD dwPosY, UINT intSize) 
{ 
	return MAG_GetTemperatureProbe(m_intChannelIndex, dwPosX, dwPosY, intSize); 
} 
 
int CMagDevice::GetLineTemperatureInfo(int * buffer, UINT intBufferSizeByte, int info[3], UINT x0, UINT y0, UINT x1, UINT y1) 
{ 
	return MAG_GetLineTemperatureInfo(m_intChannelIndex, buffer, intBufferSizeByte, info, x0, y0, x1, y1); 
} 
 
BOOL CMagDevice::GetRectTemperatureInfo(UINT x0, UINT y0, UINT x1, UINT y1, int info[5]) 
{ 
	return MAG_GetRectTemperatureInfo(m_intChannelIndex, x0, y0, x1, y1, info); 
} 
 
BOOL CMagDevice::GetEllipseTemperatureInfo(UINT x0, UINT y0, UINT x1, UINT y1, int info[5]) 
{ 
	return MAG_GetEllipseTemperatureInfo(m_intChannelIndex, x0, y0, x1, y1, info); 
} 
 
BOOL CMagDevice::GetRgnTemperatureInfo(const UINT * Pos, UINT intPosNumber, int info[5]) 
{ 
	return MAG_GetRgnTemperatureInfo(m_intChannelIndex, Pos, intPosNumber, info); 
} 
 
BOOL CMagDevice::UseTemperatureMask(BOOL bUse) 
{ 
	return MAG_UseTemperatureMask(m_intChannelIndex, bUse); 
} 
 
BOOL CMagDevice::IsUsingTemperatureMask() 
{ 
	return MAG_IsUsingTemperatureMask(m_intChannelIndex); 
} 
 
BOOL CMagDevice::SaveBMP(DWORD dwIndex, const WCHAR * charFilename) 
{ 
	return MAG_SaveBMP(m_intChannelIndex, dwIndex, charFilename); 
} 
 
BOOL CMagDevice::SaveMGT(const WCHAR * charFilename) 
{ 
	return MAG_SaveMGT(m_intChannelIndex, charFilename); 
} 
 
BOOL CMagDevice::SaveDDT(const WCHAR * charFilename) 
{ 
	return MAG_SaveDDT(m_intChannelIndex, charFilename); 
} 
 
int CMagDevice::SaveDDT2Buffer(void * pBuffer, UINT intBufferSize) 
{ 
	return MAG_SaveDDT2Buffer(m_intChannelIndex, pBuffer, intBufferSize); 
} 
 
BOOL CMagDevice::LoadDDT(OutputPara * paraOut, const WCHAR * charFilename, MAG_FRAMECALLBACK funcFrame, void * pUserData) 
{ 
	if (!MAG_IsProcessingImage(m_intChannelIndex)) 
	{ 
		if(!MAG_LoadDDT(m_intChannelIndex, paraOut, charFilename, funcFrame, pUserData)) 
		{ 
			return FALSE; 
		} 
		 
		MAG_GetCamInfo(m_intChannelIndex, &m_CamInfo, sizeof(m_CamInfo)); 
		return TRUE; 
	} 
	else 
	{ 
		return FALSE; 
	} 
} 
 
BOOL CMagDevice::LoadBufferedDDT(OutputPara * paraOut, const void * pBuffer, UINT intBufferSize, MAG_FRAMECALLBACK funcFrame, void * pUserData) 
{ 
	if (!MAG_IsProcessingImage(m_intChannelIndex)) 
	{ 
		if(!MAG_LoadBufferedDDT(m_intChannelIndex, paraOut, pBuffer, intBufferSize, funcFrame, pUserData)) 
		{ 
			return FALSE; 
		} 
		 
		MAG_GetCamInfo(m_intChannelIndex, &m_CamInfo, sizeof(m_CamInfo)); 
		return TRUE; 
	} 
	else 
	{ 
		return FALSE; 
	} 
} 
 
BOOL CMagDevice::SetAsyncCompressCallBack(MAG_DDTCOMPRESSCALLBACK pCallBack, int intQuality) 
{ 
	return MAG_SetAsyncCompressCallBack(m_intChannelIndex, pCallBack, intQuality); 
} 
 
BOOL CMagDevice::GrabAndAsyncCompressDDT(void * pUserData) 
{ 
	return MAG_GrabAndAsyncCompressDDT(m_intChannelIndex, pUserData); 
} 
 
BOOL CMagDevice::SDCardStorage(enum SDStorageFileType filetype, UINT para) 
{ 
	BOOL bReturn = MAG_SDCardStorage(m_intChannelIndex, filetype, para); 
 
	if (bReturn && filetype==SDFileMGS) 
	{ 
		if (para==1) 
		{ 
			m_bIsRecordingMGS = TRUE; 
		} 
		else 
		{ 
			m_bIsRecordingMGS = FALSE; 
		} 
	} 
 
	if (bReturn && filetype==SDFileAVI) 
	{ 
		if (para==1) 
		{ 
			m_bIsRecordingAvi = TRUE; 
		} 
		else 
		{ 
			m_bIsRecordingAvi = FALSE; 
		} 
	} 
 
	return bReturn; 
} 
 
BOOL CMagDevice::SDStorageMGT() 
{ 
	return MAG_SDCardStorage(m_intChannelIndex, SDFileMGT, 0); 
} 
 
BOOL CMagDevice::SDStorageBMP() 
{ 
	return MAG_SDCardStorage(m_intChannelIndex, SDFileBMP, 0); 
} 
 
BOOL CMagDevice::SDStorageDDT() 
{ 
	return MAG_SDCardStorage(m_intChannelIndex, SDFileDDT, 0); 
} 
 
BOOL CMagDevice::SDStorageMGSStart() 
{ 
	return MAG_SDCardStorage(m_intChannelIndex, SDFileMGS, 1); 
} 
 
BOOL CMagDevice::SDStorageMGSStop() 
{ 
	return MAG_SDCardStorage(m_intChannelIndex, SDFileMGS, 0); 
} 
 
BOOL CMagDevice::SDStorageAviStart() 
{ 
	return MAG_SDCardStorage(m_intChannelIndex, SDFileAVI, 1); 
} 
 
BOOL CMagDevice::SDStorageAviStop() 
{ 
	return MAG_SDCardStorage(m_intChannelIndex, SDFileAVI, 0); 
} 
 
BOOL CMagDevice::LocalStorageAviStart(const WCHAR * charFilename, UINT intSamplePeriod) 
{ 
	m_bIsRecordingLocalAvi |= MAG_LocalStorageAviStart(m_intChannelIndex, charFilename, intSamplePeriod); 
	return m_bIsRecordingLocalAvi; 
} 
 
void CMagDevice::LocalStorageAviStop() 
{ 
	MAG_LocalStorageAviStop(m_intChannelIndex); 
	 
	m_bIsRecordingLocalAvi = FALSE; 
} 
 
BOOL CMagDevice::GetCurrentOffset(const WCHAR * charReferenceDDT, int * pOffsetX, int * pOffsetY) 
{ 
	return MAG_GetCurrentOffset(m_intChannelIndex, charReferenceDDT, pOffsetX, pOffsetY); 
} 
 
BOOL CMagDevice::CaptureVisibleJpeg(const WCHAR * charFileName) 
{ 
	return MAG_CaptureVisibleJpeg(m_intChannelIndex, charFileName); 
} 
 
void CMagDevice::Lock() 
{ 
	return MAG_LockFrame(m_intChannelIndex); 
} 
 
void CMagDevice::Unlock() 
{ 
	return MAG_UnLockFrame(m_intChannelIndex); 
} 
 
void CMagDevice::ConvertPos2XY(UINT intPos, UINT * pX, UINT * pY) 
{ 
	UINT W = m_CamInfo.intFPAWidth; 
	if (W && pX && pY) 
	{ 
		*pY = intPos/W; 
		*pX = intPos - (*pY)*W; 
	} 
} 
 
UINT CMagDevice::ConvertXY2Pos(UINT X, UINT Y) 
{ 
	return Y*m_CamInfo.intFPAWidth + X; 
}