Example #1
0
int Camera::AddPreSetLocation( Location& loc, BOOL bRestoreFromConfig, const unsigned char *posCode, const unsigned char *focalCode )
{
	// TODO: 
	// 1.SET PRE SET POSITION 
	// 2.STORE THE RECALL CODE
	unsigned char SetPrePosCmd[1024], RecallPrePosCmd[1024], RecallPreFocalCmd[1024];
	int locId = loc.GetId();
	if(locId < 0)
	{
		return -1;
	}
	if(m_nProtocol == Pelco_D)
	{
		memcpy(SetPrePosCmd, PrefixOfSetPrePos, 1024);
		SetPrePosCmd[5] = (unsigned char)(locId);
		SetPrePosCmd[6] = (unsigned char)(SetPrePosCmd[1]+SetPrePosCmd[2]+SetPrePosCmd[3]+SetPrePosCmd[4]+SetPrePosCmd[5]);
		if(!bRestoreFromConfig)
		{
			sendCommand(SetPrePosCmd, RegularCmdLength);
		}

		memcpy(RecallPrePosCmd, PrefixOfRecallPrePos, 1024);
		RecallPrePosCmd[5] = (unsigned char)(locId);
		RecallPrePosCmd[6] = (unsigned char)(RecallPrePosCmd[1] + RecallPrePosCmd[2] + RecallPrePosCmd[3] + RecallPrePosCmd[4] + RecallPrePosCmd[5]);
		loc.SetCommand(RecallPrePosCmd, RegularCmdLength);
	}
	else if(m_nProtocol == VISCA)
	{
		unsigned char returnInfo[1024];
		DWORD readn;
		if(!bRestoreFromConfig)
		{
			memset(returnInfo, 0x00, sizeof(returnInfo));
			PurgeComm(m_hSeries, PURGE_RXCLEAR);
			sendCommand(VQueryPosCmd, VQueryCmdLength);
			ReadFile(m_hSeries, returnInfo, 11, &readn, NULL);
			memcpy(RecallPrePosCmd, VPrefixOfTurnToAbsolutePos, 1024);
			if(readn == 11)
			{
				for(int i=0; i<8; ++i)
				{
					RecallPrePosCmd[i+6] = returnInfo[i+2];
				}
			}
			loc.SetCommand(RecallPrePosCmd, VRecallPosCmdLength);

			memset(returnInfo, 0x00, sizeof(returnInfo));
			PurgeComm(m_hSeries, PURGE_RXCLEAR);
			sendCommand(VQueryFocalCmd, VQueryCmdLength);
			ReadFile(m_hSeries, returnInfo, 7, &readn, NULL);
			memcpy(RecallPreFocalCmd, VPrefixOfTurnToAbsoluteFocal, 1024);
			if(readn == 7)
			{
				for(int i=0; i<4; i++)
				{
					RecallPreFocalCmd[i+4] = returnInfo[i+2];
				}
			}
			loc.SetFocalCommand(RecallPreFocalCmd, VRecallFocalCmdLength);
		}
		else
		{
			// Get the recall command from config manager
			memcpy(RecallPrePosCmd, VPrefixOfTurnToAbsolutePos, 1024);
			if(posCode != NULL)
			{
				for(int i=0; i<8; ++i)
				{
					RecallPrePosCmd[i+6] = posCode[i];
				}
			}

			memcpy(RecallPreFocalCmd, VPrefixOfTurnToAbsoluteFocal, 1024);
			if(focalCode != NULL)
			{
				for(int i=0; i<4; ++i)
				{
					RecallPreFocalCmd[i+4] = focalCode[i];
				}
			}
			loc.SetCommand(RecallPrePosCmd, VRecallPosCmdLength);
			loc.SetFocalCommand(RecallPreFocalCmd, VRecallFocalCmdLength);
		}

	}
	presetLocations[locId] = loc;
	m_nPreLocNum = presetLocations.size();
	return 0;
}