You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2894 lines
70 KiB
2894 lines
70 KiB
#include "deviceNodeCamera.h"
|
|
|
|
#include "../../components/base/basicCameraInfo.h"
|
|
#include "../../components/object/objectSystemAnchor.h"
|
|
#include "../../data/protocol/protocolPTZ_ONVIF.h"
|
|
#include "../../data/protocol/protocolPTZ_PELCO.h"
|
|
#include "../../data/protocol/protocolPTZ_VISCA.h"
|
|
#include "../../data/protocol/protocolPTZ_BRCP.h"
|
|
//#include "../../hardware/uart/serialPort.h"
|
|
//#include "../../hardware/uart/serialSOL.h"
|
|
#include "../mojo/mojoKernel.h"
|
|
#include "hardwareManager.h"
|
|
#include "hardwareResourceSerialProvider.h"
|
|
#include "kernelModuleEmbedVideo.h"
|
|
|
|
#define LOG(X) deviceNode::m_pLog->Log("RCAM", this, X)
|
|
|
|
//#define DEBUG_EXTRA
|
|
|
|
#ifdef DEBUG
|
|
#define LOG_ERROR(X) \
|
|
{ \
|
|
char _tBfrErrMSG2w34[512]; \
|
|
sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
|
|
deviceNode::m_pLog->Log("RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34); \
|
|
}
|
|
#else
|
|
#define LOG_ERROR(X) deviceNode::m_pLog->Log("RCAM", this, _LOG_ERROR, X);
|
|
#endif
|
|
|
|
// all sizes in mm
|
|
|
|
static const float AC_imager_diag[12] = {5.0f, 5.68f, 6.0f, 6.592f, 8.0f, 8.933f, 11.0f, 16.0f, 22.5f, 30.1f, 43.3f, 69.7f};
|
|
static const float AC_imager_width[12] = {4.0f, 4.536f, 4.8f, 5.27f, 6.4f, 7.176f, 8.8f, 12.8f, 18.0f, 25.1f, 36.0f, 56.0f};
|
|
static const float AC_imager_height[12] = {3.0f, 3.416f, 3.6f, 3.96f, 4.8f, 5.319f, 6.6f, 9.6f, 13.5f, 16.7f, 24.0f, 41.5f};
|
|
|
|
#define CAM_FOCAL_LENGTH_CNT 49
|
|
static const float cam_predef_focal_length[CAM_FOCAL_LENGTH_CNT] = {2.7f, 3.0f, 3.2f, 3.5f, 3.7f, 3.9f, 4.0f, 4.3f, 4.8f, 5.0f, 5.1f, 5.5f, 5.8f, 6.0f, 6.2f, 6.6f, 7.0f, 7.1f, 7.5f, 7.6f, 8.0f, 8.6f, 8.9f, 9.0f, 9.2f, 9.3f, 10.0f, 10.5f, 10.6f,
|
|
10.7f, 11.0f, 11.3f, 12.0f, 12.9f, 13.0f, 13.5f, 13.6f, 14.0f, 14.6f, 15.0f, 15.1f, 15.5f, 16.0f, 17.0f, 17.5f, 17.7f, 18.0f, 18.2f, 19.0f};
|
|
|
|
deviceNodeCamera::deviceNodeCamera(uint32_t NodeID) :
|
|
deviceNode(NodeID),
|
|
basicThread()
|
|
{
|
|
// m_pLog = basicLogCollection::getInstance();
|
|
m_pBEH = basicEventHeap::getInstance();
|
|
m_bSkeepPositioningWait = true;
|
|
m_bNoAbsPositionning = false;
|
|
m_bCameraOnHomePosition = false;
|
|
m_tTimeTSeconds = 0;
|
|
m_pProtocol = NULL;
|
|
// m_pTransport = NULL;
|
|
m_pCurrentROI = NULL;
|
|
m_nRealFrameWidth = 640;
|
|
// m_bState = 0;
|
|
// m_bBusy = true;
|
|
m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
|
|
m_nRelativeMoveCounter = 0;
|
|
m_bRelativeMoveMatrix = 0;
|
|
m_bCurrentPresetCol = 0;
|
|
m_bCurrentPresetRow = 0;
|
|
m_bShineOnTarget = false;
|
|
m_bCameraIsStatic = false;
|
|
m_bIRIsOn = false;
|
|
m_bIRTO = 0;
|
|
m_fSpeedRise = 0.03f;
|
|
m_fZoomCorrection = 1.0f;
|
|
m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
|
|
// m_bSourceConnected = false;
|
|
// m_pSource = NULL;
|
|
}
|
|
|
|
deviceNodeCamera::deviceNodeCamera(DBC_NODE_DATA * Data) :
|
|
deviceNode(Data),
|
|
basicThread()
|
|
{
|
|
// m_pLog = basicLogCollection::getInstance();
|
|
m_pBEH = basicEventHeap::getInstance();
|
|
m_bSkeepPositioningWait = true;
|
|
m_bNoAbsPositionning = false;
|
|
m_bCameraOnHomePosition = false;
|
|
m_tTimeTSeconds = 0;
|
|
m_pProtocol = NULL;
|
|
// m_pTransport = NULL;
|
|
m_pCurrentROI = NULL;
|
|
m_nRealFrameWidth = 640;
|
|
// m_bState = 0;
|
|
// m_bBusy = true;
|
|
m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
|
|
m_nRelativeMoveCounter = 0;
|
|
m_bRelativeMoveMatrix = 0;
|
|
m_bCurrentPresetCol = 0;
|
|
m_bCurrentPresetRow = 0;
|
|
m_bShineOnTarget = false;
|
|
m_bIRIsOn = false;
|
|
m_bIRTO = 0;
|
|
m_fSpeedRise = 0.03f;
|
|
m_fZoomCorrection = 1.0f;
|
|
m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
|
|
// m_bSourceConnected = false;
|
|
// m_pSource = NULL;
|
|
}
|
|
|
|
deviceNodeCamera::~deviceNodeCamera()
|
|
{
|
|
LOG("Destruct");
|
|
// m_mQPROTECTOR.unlock();
|
|
waitThreadEnd(true);
|
|
LOG("Thread Del OK");
|
|
/*if( m_pTransport!= NULL ) {
|
|
if( m_sCamData.uart_id ) {
|
|
DBC_UART_DATA *tData = NULL;
|
|
tData = m_pDBC->getUartData( m_sCamData.uart_id );
|
|
switch( tData->type ) {
|
|
case UART_TYPE_HARDWARE:{
|
|
delete((serialPort*)m_pTransport);
|
|
break;
|
|
};
|
|
case UART_TYPE_SOL:{
|
|
delete((serialSOL*)m_pTransport);
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
LOG("Transport Del OK");
|
|
*/
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
switch (m_sCamData.protocol)
|
|
{
|
|
case CAM_CTRL_PROTO_VISCA: delete((protocolPTZ_VISCA *) m_pProtocol); break;
|
|
case CAM_CTRL_PROTO_PELCO: delete((protocolPTZ_PELCO *) m_pProtocol); break;
|
|
case CAM_CTRL_PROTO_ONVIF: delete((protocolPTZ_ONVIF *) m_pProtocol); break;
|
|
case CAM_CTRL_PROTO_BRCP: delete((protocolPTZ_BRCP *) m_pProtocol); break;
|
|
default : delete(m_pProtocol);
|
|
};
|
|
};
|
|
LOG("Proto Del OK");
|
|
// if( m_pPosition != NULL ) delete( m_pPosition );
|
|
// LOG("Pos Del OK");
|
|
// if( m_bSourceConnected ){
|
|
// if( m_pSource != NULL ){
|
|
// m_pSource->_close();
|
|
// delete( m_pSource );
|
|
// };
|
|
// };
|
|
// LOG("Stream Del OK");
|
|
}
|
|
|
|
void deviceNodeCamera::updateOpticalParameters(uint16_t frame_width, uint16_t frame_heigth)
|
|
{
|
|
#ifdef DEBUG
|
|
char tB[128];
|
|
LOG("Set Optical Parameters");
|
|
sprintf(tB, "\tCapturing Frame: %dx%d ", frame_width, frame_heigth);
|
|
LOG(tB);
|
|
#endif
|
|
if (frame_width > 0 && frame_heigth > 0)
|
|
{
|
|
m_nRealFrameWidth = frame_width;
|
|
m_nRealFrameHeight = frame_heigth;
|
|
float tFrameDiag = sqrtf(m_nRealFrameHeight * m_nRealFrameHeight + m_nRealFrameWidth * m_nRealFrameWidth);
|
|
switch (m_sCamData.zoom_model)
|
|
{
|
|
case 0:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("\tFixed Zoom");
|
|
#endif
|
|
m_fMaxFL = m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
|
|
m_fMinRange = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag);
|
|
m_fMaxRange = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag);
|
|
m_fR2FL = .0f;
|
|
m_fZoomCorrection = .0f;
|
|
m_pDBC->updateCamRange(m_sCamData.id, m_fMaxRange);
|
|
break;
|
|
};
|
|
case 1:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("\tAutomated Zoom");
|
|
#endif
|
|
m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
|
|
m_fMinRange = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag);
|
|
m_fMaxFL = cam_predef_focal_length[m_sCamData.lens_f] * m_sCamData.zoom;
|
|
m_fMaxRange = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag);
|
|
if (m_fMaxRange > m_fMinRange)
|
|
{
|
|
m_fR2FL = ((m_fMaxFL - m_fMinFL) / (m_fMaxRange - m_fMinRange));
|
|
}
|
|
else
|
|
{
|
|
m_fR2FL = .0f;
|
|
};
|
|
m_fZoomCorrection = 1.0f;
|
|
m_pDBC->updateCamRange(m_sCamData.id, m_fMaxRange);
|
|
break;
|
|
};
|
|
case 2:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("\tManual Zoom");
|
|
#endif
|
|
//The Fixing minimal distance from 5 meters to a 0.5
|
|
m_fMinRange = 0.5f; // Minimal 0.5 meters
|
|
if (m_sCamData.max_range < m_fMinRange)
|
|
{
|
|
m_fMaxRange = m_fMinRange;
|
|
}
|
|
else
|
|
{
|
|
m_fMaxRange = m_sCamData.max_range;
|
|
};
|
|
m_fZoomCorrection = m_sCamData.zoom * 0.01f;
|
|
m_fMinFL = calcCFL(AC_imager_width[m_sCamData.imager_type], m_fMinRange);//, tFrameDiag);
|
|
m_fMaxFL = calcCFL(AC_imager_width[m_sCamData.imager_type], m_fMaxRange);//, tFrameDiag);
|
|
break;
|
|
};
|
|
};
|
|
m_fMinHFov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], m_fMaxFL));
|
|
m_fMaxHFov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], m_fMinFL));
|
|
m_fMinVFov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], m_fMaxFL));
|
|
m_fMaxVFov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], m_fMinFL));
|
|
#ifdef DEBUG
|
|
sprintf(tB, "\tMinimal FL: %0.3fmm. Maximal FL: %0.3fmm. ", m_fMinFL, m_fMaxFL);
|
|
LOG(tB);
|
|
sprintf(tB, "\tMinimal Range: %0.2fm. Maximal Range: %0.2fm. ", m_fMinRange, m_fMaxRange);
|
|
LOG(tB);
|
|
sprintf(tB, "\tMinimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov);
|
|
LOG(tB);
|
|
sprintf(tB, "\tMaximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov);
|
|
LOG(tB);
|
|
#endif
|
|
};
|
|
}
|
|
|
|
bool deviceNodeCamera::create()
|
|
{
|
|
if (m_bThreadStatus == TH_WORKING)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
setWM(CAM_WS_INIT);
|
|
|
|
if (m_sNodeData.aux_id == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
DBC_CAM_DATA * tData = m_pDBC->getCamData(m_sNodeData.aux_id);
|
|
if (tData != NULL)
|
|
{
|
|
memcpy(&m_sCamData, tData, sizeof(DBC_CAM_DATA));
|
|
free(tData);
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Cannot Fetch CAM Data from Database!");
|
|
return false;
|
|
};
|
|
if (! (m_sCamData.lens_f < CAM_FOCAL_LENGTH_CNT))
|
|
{
|
|
m_sCamData.lens_f = CAM_FOCAL_LENGTH_CNT - 1;
|
|
}
|
|
|
|
updateOpticalParameters(1280, 720); // HD Ready
|
|
|
|
if (m_sCamData.ptz_speed_step > .0f)
|
|
{
|
|
m_fSpeedRise = m_sCamData.ptz_speed_step;
|
|
};
|
|
|
|
// m_pPosition = new basicPosition();// m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
|
|
|
|
// if( m_pPosition == NULL ) {
|
|
// LOG_ERROR("Position Constructor Failure!");
|
|
// return false;
|
|
// };
|
|
|
|
// m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z );
|
|
// m_oPosition.setOrientationDeg( m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot );
|
|
|
|
systemAnchor * SA = systemAnchor::getInstance();
|
|
if( SA ){
|
|
LOG("SysAnchor OK");
|
|
if( SA->beLocal() ){
|
|
LOG("SysAnchor beLocal!");
|
|
m_oPosition.setPositionXYZ(m_sCamData.x, m_sCamData.y, m_sCamData.z, 0); // SA->getUTMZone() );
|
|
m_oPosition.setOrientationDeg(m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot);
|
|
} else {
|
|
LOG("SysAnchor is Global Position System!");
|
|
C3D_DECART LD = SA->getXYZ();
|
|
m_oPosition.setPositionXYZ(LD.x + m_sCamData.x, LD.y + m_sCamData.y, LD.z + m_sCamData.z, SA->getUTMZone());
|
|
m_oPosition.setOrientationDeg(m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot);
|
|
};
|
|
} else {
|
|
LOG("No SysAnchor!");
|
|
m_oPosition.setPositionXYZ(m_sCamData.x, m_sCamData.y, m_sCamData.z);
|
|
m_oPosition.setOrientationDeg(m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot);
|
|
};
|
|
m_oPosition.updateMatrix();
|
|
|
|
#ifdef DEBUG
|
|
char tB[128];
|
|
sprintf(tB, "Finalized Camera Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt());
|
|
LOG(tB);
|
|
sprintf(tB, "Finalized Camera Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ());
|
|
LOG(tB);
|
|
sprintf(tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg());
|
|
LOG(tB);
|
|
#endif
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
LOG_ERROR("Cannot Start: Service Already Running!");
|
|
return false;
|
|
};
|
|
#ifdef CAM_POST_INIT
|
|
if ((m_sCamData.type == ARGUS_IP_PRESET_CAMERA) || (m_sCamData.type == ARGUS_ANALOG_PRESET_CAMERA))
|
|
{
|
|
m_bNoAbsPositionning = true;
|
|
}
|
|
if (m_sCamData.protocol == 0)
|
|
{
|
|
m_bCameraIsStatic = true;
|
|
m_bSkeepPositioningWait = true;
|
|
m_sCamData.online = true;
|
|
m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
|
|
return m_sCamData.online;
|
|
};
|
|
m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
|
|
return init();
|
|
#else //! CAM_POST_INIT
|
|
switch (m_sCamData.protocol)
|
|
{
|
|
case CAM_CTRL_PROTO_VISCA:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("VISCA");
|
|
#endif
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA(m_sCamData.protocol_aux);
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
basicTransport * tTransport = NULL;
|
|
hardwareManager * tHM = hardwareManager::getInstance();
|
|
if (tHM)
|
|
{
|
|
hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
|
|
if (tRES != NULL)
|
|
{
|
|
if (tRES->isValid())
|
|
{
|
|
tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
|
|
if (m_pProtocol->setTransport(tTransport))
|
|
{
|
|
if (! m_pProtocol->create())
|
|
{
|
|
LOG_ERROR("Protocol <<< Create >>> Failure!");
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Binding Port Failure!");
|
|
};
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG("HWM Has No UART PORT!");
|
|
#endif
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Can not get Hardware Manager!");
|
|
#endif
|
|
};
|
|
if (tTransport != NULL)
|
|
{
|
|
LOG("Bind Transport Port!");
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Transport Creation Failure!");
|
|
delete((protocolPTZ_VISCA *) m_pProtocol);
|
|
m_pProtocol = NULL;
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Protocol Creation failure!");
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
case CAM_CTRL_PROTO_PELCO:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("PELCO");
|
|
#endif
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO(m_sCamData.protocol_aux);
|
|
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
basicTransport * tTransport = NULL;
|
|
hardwareManager * tHM = hardwareManager::getInstance();
|
|
if (tHM)
|
|
{
|
|
hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
|
|
if (tRES != NULL)
|
|
{
|
|
if (tRES->isValid())
|
|
{
|
|
tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
|
|
if (m_pProtocol->setTransport(tTransport))
|
|
{
|
|
if (! m_pProtocol->create())
|
|
{
|
|
LOG_ERROR("Protocol <<< Create >>> Failure!");
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Binding Port Failure!");
|
|
};
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG("HWM Has No UART PORT!");
|
|
#endif
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Can not get Hardware Manager!");
|
|
#endif
|
|
};
|
|
if (tTransport != NULL)
|
|
{
|
|
LOG("Bind Transport Port!");
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Transport Creation Failure!");
|
|
delete((protocolPTZ_PELCO *) m_pProtocol);
|
|
m_pProtocol = NULL;
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Protocol Creation failure!");
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
case CAM_CTRL_PROTO_ONVIF:
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("ONVIF");
|
|
#endif
|
|
// m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
|
|
if (strstr(m_sCamData.onvif_ctrl, "http") == NULL)
|
|
{
|
|
char tURI[256];
|
|
if (m_sCamData.port)
|
|
{
|
|
sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
|
|
};
|
|
LOG("PTZ BUILD URI");
|
|
LOG(tURI);
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
|
|
}
|
|
else
|
|
{
|
|
LOG("USE FULL PTZ URI");
|
|
LOG(m_sCamData.onvif_ctrl);
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
|
|
};
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("ONVIF-END");
|
|
#endif
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
if (! m_pProtocol->create())
|
|
{
|
|
LOG_ERROR("Error Creating Proto!");
|
|
delete((protocolPTZ_ONVIF *) m_pProtocol);
|
|
m_pProtocol = NULL;
|
|
};
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("PROTO CREATE DONE");
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
case CAM_CTRL_PROTO_BRCP:{
|
|
#ifdef DEBUG
|
|
LOG("BRCP");
|
|
#endif
|
|
// m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
|
|
if (strstr(m_sCamData.onvif_ctrl, "http") == NULL)
|
|
{
|
|
char tURI[256];
|
|
if (m_sCamData.port)
|
|
{
|
|
sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
|
|
};
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
|
|
}
|
|
else
|
|
{
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
|
|
};
|
|
#ifdef DEBUG
|
|
LOG("BRCP-END");
|
|
#endif
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
if (! m_pProtocol->create())
|
|
{
|
|
LOG_ERROR("Error Creating Proto!");
|
|
delete((protocolPTZ_BRCP *) m_pProtocol);
|
|
m_pProtocol = NULL;
|
|
};
|
|
#ifdef DEBUG
|
|
LOG("PROTO CREATE DONE");
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
default:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Camera Has no defined control protocol");
|
|
#endif
|
|
};
|
|
};
|
|
// Check - No ABS Movement!
|
|
if ((m_sCamData.type == ARGUS_IP_PRESET_CAMERA) || (m_sCamData.type == ARGUS_ANALOG_PRESET_CAMERA))
|
|
{
|
|
m_bNoAbsPositionning = true;
|
|
}
|
|
if (m_pProtocol == NULL)
|
|
{
|
|
if (m_sCamData.protocol == 0)
|
|
{
|
|
m_bCameraIsStatic = true;
|
|
m_bSkeepPositioningWait = true;
|
|
m_sCamData.online = true;
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("No Proto Created!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Proto is OK");
|
|
#endif
|
|
// Load Presets only if we have protocol
|
|
load_presets();
|
|
|
|
mojoKernel * tKRNL = mojoKernel::getInstance();
|
|
if (tKRNL)
|
|
{
|
|
m_bSkeepPositioningWait = ((tKRNL->getMediaMode() & EVE_OUTPUT_VIDEO) == EVE_OUTPUT_VIDEO);
|
|
#ifdef DEBUG
|
|
char ttTT[128];
|
|
sprintf(ttTT, "Kernel Media Mode:%d", tKRNL->getMediaMode());
|
|
LOG(ttTT);
|
|
if (m_bSkeepPositioningWait)
|
|
{
|
|
LOG("Camera No Wait On Pos!");
|
|
}
|
|
else
|
|
{
|
|
LOG("Camera Will Wait On Pos!");
|
|
};
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("No Kernel Instance!");
|
|
};
|
|
m_sCamData.online = init();
|
|
};
|
|
m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
|
|
return m_sCamData.online;
|
|
#endif //! CAM_POST_INIT
|
|
}
|
|
|
|
// void deviceNodeCamera::setBusy( bool Status ){
|
|
// m_bBusy = Status;
|
|
//};
|
|
|
|
bool deviceNodeCamera::relativeMove(float PanSPD, float TiltSPD, float ZoomSPD)
|
|
{
|
|
if (m_sCamData.online)
|
|
{
|
|
uint32_t MoveMatrix = 0;
|
|
if (PanSPD != .0f)
|
|
{
|
|
if (PanSPD > 0)
|
|
{
|
|
if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 2)
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
|
|
}
|
|
else
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 2)
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
|
|
}
|
|
else
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
|
|
};
|
|
};
|
|
};
|
|
if (TiltSPD != .0f)
|
|
{
|
|
if (TiltSPD > 0)
|
|
{
|
|
if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 1)
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_TILT_UP;
|
|
}
|
|
else
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 1)
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
|
|
}
|
|
else
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_TILT_UP;
|
|
};
|
|
};
|
|
};
|
|
if (ZoomSPD != .0f)
|
|
{
|
|
if (ZoomSPD > 0)
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_ZOOM_WIDE;
|
|
}
|
|
else
|
|
{
|
|
MoveMatrix |= PTZ_DRIVE_ZOOM_TELE;
|
|
};
|
|
};
|
|
if (MoveMatrix != 0)
|
|
{
|
|
m_pProtocol->setPTZSpeed(fabs(PanSPD), fabs(TiltSPD), fabs(ZoomSPD));
|
|
};
|
|
return m_pProtocol->move(MoveMatrix);
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool deviceNodeCamera::relativeStop()
|
|
{
|
|
if (m_sCamData.online)
|
|
{
|
|
return m_pProtocol->move(0);
|
|
};
|
|
return false;
|
|
}
|
|
|
|
CAM_TASK * deviceNodeCamera::fetchCamTask(void)
|
|
{
|
|
CAM_TASK * rVal = NULL;
|
|
m_mQPROTECTOR.lock();
|
|
if (m_qCAM_TASK.size())
|
|
{
|
|
rVal = m_qCAM_TASK.front();
|
|
m_qCAM_TASK.pop();
|
|
};
|
|
m_mQPROTECTOR.unlock();
|
|
return rVal;
|
|
}
|
|
|
|
bool deviceNodeCamera::pushCamTask(CAM_TASK * ptr)
|
|
{
|
|
if (ptr == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
m_mQPROTECTOR.lock();
|
|
m_qCAM_TASK.push(ptr);
|
|
m_mQPROTECTOR.unlock();
|
|
return true;
|
|
}
|
|
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
|
|
bool deviceNodeCamera::fusion_compare(CAM_ROI * ptr, C3D_SPH_DEGREES tp)
|
|
{
|
|
if (ptr == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
float tFI = fabsf(ptr->cam_position.fi - tp.fi);
|
|
float tTETTA = fabsf(ptr->cam_position.tetta - tp.tetta);
|
|
#ifdef DEBUG_ALL
|
|
char tB[128];
|
|
sprintf(tB, "FC: FOV:[%.5f:%.5f] dTG:[%.5f:%.5f] %.2f<%.2f>%.2f", ptr->h_fov, ptr->v_fov, tFI, tTETTA, ptr->min_range, tp.r, ptr->max_range);
|
|
LOG(tB);
|
|
#endif
|
|
if (tFI > ptr->h_fov)
|
|
{
|
|
return false;
|
|
}
|
|
if (tTETTA > ptr->v_fov)
|
|
{
|
|
return false;
|
|
}
|
|
if (tp.r < ptr->min_range)
|
|
{
|
|
return false;
|
|
}
|
|
if (tp.r > ptr->max_range)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool deviceNodeCamera::fusion_consumeData(uint32_t db_id, C3D_SPH_DEGREES tOR)
|
|
{
|
|
if (db_id == 0)
|
|
{
|
|
return false;
|
|
}
|
|
CAM_TRACK_RECORD * tTrackRecord = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
|
|
if (tTrackRecord == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Fusion: Consuming new Data!");
|
|
#endif
|
|
memset(tTrackRecord, 0, sizeof(CAM_TRACK_RECORD));
|
|
tTrackRecord->target_direction.fi = tOR.fi;
|
|
tTrackRecord->target_direction.r = tOR.r;
|
|
tTrackRecord->target_direction.tetta = tOR.tetta;
|
|
tTrackRecord->evt_db_ID = db_id;
|
|
tTrackRecord->ts_ms = getMilliseconds();
|
|
|
|
m_mROIsProtector.lock();
|
|
|
|
vCAM_ROIS::iterator idx = m_vROIS.begin();
|
|
for (; idx < m_vROIS.end(); idx++)
|
|
{
|
|
if (fusion_compare(*idx, tOR))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if (idx != m_vROIS.end())
|
|
{
|
|
// have Match!
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("ROI MATCHED!");
|
|
#endif
|
|
(*idx)->targets.push_back(tTrackRecord);
|
|
fusion_validateROI(tTrackRecord->ts_ms, *idx);
|
|
}
|
|
else
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("NO MATCH FOUND!");
|
|
#endif
|
|
// No mathced ROI -> create new one
|
|
//CAM_ROI * tROI = (CAM_ROI *) malloc(sizeof(CAM_ROI));
|
|
CAM_ROI * tROI = new CAM_ROI();
|
|
if (tROI)
|
|
{
|
|
tROI->ts_ms = tTrackRecord->ts_ms;
|
|
spherical2onvif(tOR, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
|
|
|
|
tROI->cam_position.fi = tOR.fi;
|
|
tROI->cam_position.tetta = tOR.tetta;
|
|
tROI->cam_position.r = tOR.r;
|
|
|
|
float cFL = m_fMinFL + m_fR2FL * (tROI->cam_position.r - m_fMinRange);
|
|
|
|
tROI->max_range = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
|
|
tROI->min_range = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
|
|
tROI->h_fov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], cFL)) / 2.0f; // div to no to div in comparation function
|
|
tROI->v_fov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], cFL)) / 2.0f; // that will be called more ofthen
|
|
|
|
tROI->targets.push_back(tTrackRecord);
|
|
m_vROIS.push_back(tROI);
|
|
};
|
|
};
|
|
|
|
m_mROIsProtector.unlock();
|
|
return true;
|
|
}
|
|
|
|
bool deviceNodeCamera::fusion_validateROI(uint64_t cts, CAM_ROI * ptr)
|
|
{
|
|
if (ptr == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
if ((cts - ptr->ts_ms) > LOSE_INTERES_TIME_MS)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
#ifdef DEBUG_EXTRA
|
|
char tB[128];
|
|
sprintf(tB, "\tROI [%d]", ptr->targets.size());
|
|
LOG(tB);
|
|
#endif
|
|
|
|
if (ptr->targets.size())
|
|
{
|
|
double tA = 0.0;
|
|
double tB = 0.0;
|
|
double tC = 0.0;
|
|
uint32_t tCNT = 0;
|
|
for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end();)
|
|
{
|
|
if ((cts - (*idx)->ts_ms) > LOSE_INTERES_TIME_MS)
|
|
{
|
|
free(*idx);
|
|
ptr->targets.erase(idx);
|
|
}
|
|
else
|
|
{
|
|
tA = tA + (*idx)->target_direction.fi;
|
|
tB = tB + (*idx)->target_direction.tetta;
|
|
tC = tC + (*idx)->target_direction.r;
|
|
tCNT++;
|
|
idx++;
|
|
};
|
|
};
|
|
if (tCNT)
|
|
{
|
|
C3D_SPH_DEGREES L;// = {0};
|
|
//memset( &L, 0, sizeof(C3D_SPH_DEGREES));
|
|
L.fi = (float) (tA / (double) tCNT);
|
|
L.tetta = (float) (tB / (double) tCNT);
|
|
L.r = (float) (tC / (double) tCNT);
|
|
spherical2onvif(L, ptr->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
|
|
ptr->ts_ms = cts;
|
|
|
|
float cFL = m_fMinFL + m_fR2FL * (ptr->cam_position.r - m_fMinRange);
|
|
|
|
ptr->max_range = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
|
|
ptr->min_range = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
|
|
ptr->h_fov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], cFL)) / 2.0f; // div to prevent division in comparation
|
|
ptr->v_fov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], cFL)) / 2.0f; // function that will be called more ofthen
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
CAM_ROI * deviceNodeCamera::fusion_fetchROI(void)
|
|
{
|
|
CAM_ROI * tVAL = NULL;
|
|
m_mROIsProtector.lock();
|
|
if (m_vROIS.size())
|
|
{
|
|
vCAM_ROIS::iterator sRec;
|
|
uint64_t cts = 0;
|
|
for (vCAM_ROIS::iterator idx = m_vROIS.begin(); idx != m_vROIS.end(); idx++)
|
|
{
|
|
if (tVAL == NULL)
|
|
{
|
|
sRec = idx;
|
|
tVAL = (*idx);
|
|
cts = tVAL->ts_ms;
|
|
}
|
|
else
|
|
{
|
|
#ifdef CAM_FETCH_ROI_NEWEST
|
|
if ((*idx)->ts_ms > cts)
|
|
#else
|
|
if ((*idx)->ts_ms < cts)
|
|
#endif
|
|
{
|
|
sRec = idx;
|
|
tVAL = (*idx);
|
|
cts = tVAL->ts_ms;
|
|
};
|
|
};
|
|
};
|
|
m_vROIS.erase(sRec);
|
|
};
|
|
m_mROIsProtector.unlock();
|
|
if (m_bNoAbsPositionning && tVAL)
|
|
{
|
|
// Skip targets older 3 seconds
|
|
if (getMilliseconds() - tVAL->ts_ms > 3000)
|
|
#ifdef DEBUG_EXTRA
|
|
{
|
|
LOG("Targetd too old! ---> Skiping");
|
|
utilizeROI(tVAL);
|
|
};
|
|
#else
|
|
utilizeROI(tVAL);
|
|
#endif
|
|
};
|
|
return tVAL;
|
|
}
|
|
|
|
DBC_SNAPSHOT_DATA * deviceNodeCamera::fusion_translate_ROI(CAM_ROI *(&ptr))
|
|
{
|
|
DBC_SNAPSHOT_DATA * rVal = NULL;
|
|
if (ptr == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
if (ptr->targets.size())
|
|
{
|
|
//rVal = (DBC_SNAPSHOT_DATA *) malloc(sizeof(DBC_SNAPSHOT_DATA));
|
|
rVal = new DBC_SNAPSHOT_DATA();
|
|
if (rVal)
|
|
{
|
|
//memset(rVal, 0, sizeof(DBC_SNAPSHOT_DATA));
|
|
rVal->stream_id = m_sNodeData.aux_parameter;
|
|
for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end(); idx++)
|
|
{
|
|
rVal->assoc_event_ids.push_back((*idx)->evt_db_ID);
|
|
}
|
|
};
|
|
ptr->targets.clear();
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("No Events ID to ROI");
|
|
};
|
|
utilizeROI(ptr);
|
|
// Not Setting MD5 and TS -> will set at capture time
|
|
return rVal;
|
|
}
|
|
|
|
void deviceNodeCamera::fusion_validate(void)
|
|
{
|
|
if (m_bNoAbsPositionning)
|
|
{
|
|
return;
|
|
}
|
|
m_mROIsProtector.lock();
|
|
if (m_vROIS.size())
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
char tB[128];
|
|
sprintf(tB, "Fusion: Have [%d] Regions Of Interes", m_vROIS.size());
|
|
LOG(tB);
|
|
#endif
|
|
uint64_t cts = getMilliseconds();
|
|
for (vCAM_ROIS::iterator idx = m_vROIS.begin(); idx != m_vROIS.end();)
|
|
{
|
|
if (! fusion_validateROI(cts, *idx))
|
|
{
|
|
utilizeROI(*idx);
|
|
m_vROIS.erase(idx);
|
|
}
|
|
else
|
|
{
|
|
idx++;
|
|
}
|
|
};
|
|
};
|
|
m_mROIsProtector.unlock();
|
|
}
|
|
|
|
#endif // !NO_CAMERA_FUSION_ENGINE
|
|
|
|
bool deviceNodeCamera::absoluteMove(uint32_t TargetRefID, float PanPOS, float TiltPOS, float ZoomPOS)
|
|
{
|
|
//if (m_sCamData.online)
|
|
{
|
|
CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
|
|
if (tTask)
|
|
{
|
|
memset(tTask, 0, sizeof(CAM_TASK));
|
|
tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
|
|
if (tTask->CMD)
|
|
{
|
|
tTask->CMD->CMD = PTZ_ABSOLUTE;
|
|
tTask->CMD->PAN = PanPOS;
|
|
tTask->CMD->TILT = TiltPOS;
|
|
tTask->CMD->ZOOM = ZoomPOS;
|
|
tTask->movemet_needed = true;
|
|
tTask->source_evt_id = TargetRefID;
|
|
setWM(CAM_WS_BUSY);
|
|
return pushCamTask(tTask);
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("CMD malloc Error!");
|
|
free(tTask);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Task malloc error!");
|
|
}
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool deviceNodeCamera::absoluteMove(uint32_t TargetRefID, C3D_ORIENT_ONVIF O)
|
|
{
|
|
//if (m_sCamData.online)
|
|
{
|
|
|
|
CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
|
|
if (tTask)
|
|
{
|
|
memset(tTask, 0, sizeof(CAM_TASK));
|
|
tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
|
|
if (tTask->CMD)
|
|
{
|
|
tTask->CMD->CMD = PTZ_ABSOLUTE;
|
|
tTask->CMD->PAN = O.pan;
|
|
tTask->CMD->TILT = O.tilt;
|
|
tTask->CMD->ZOOM = O.zoom;
|
|
tTask->movemet_needed = true;
|
|
tTask->source_evt_id = TargetRefID;
|
|
setWM(CAM_WS_BUSY);
|
|
return pushCamTask(tTask);
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("CMD malloc Error!");
|
|
free(tTask);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Task malloc error!");
|
|
}
|
|
};
|
|
return false;
|
|
}
|
|
|
|
uint8_t deviceNodeCamera::getPtzStatus()
|
|
{
|
|
if (m_sCamData.protocol == 0)
|
|
{
|
|
return 1;
|
|
}
|
|
if (getWM() > CAM_WS_INIT)
|
|
{
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
uint8_t deviceNodeCamera::getStreamStatus()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
void deviceNodeCamera::m_fThreadProc(void)
|
|
{
|
|
DBC_PUSHED_CMD * PUSHED = NULL;
|
|
m_bThreadStatus = TH_WORKING;
|
|
bool bNewSecondLoop = false;
|
|
uint32_t cTimeSeconds = 0;
|
|
uint32_t oTimeSeconds = 0;
|
|
pthread_setname_np( pthread_self(), "NodeCamera" );
|
|
while (m_bThreadStatus < TH_ENDED)
|
|
{
|
|
|
|
cTimeSeconds = (uint32_t) time(NULL);
|
|
|
|
if ((bNewSecondLoop = (cTimeSeconds != oTimeSeconds))) oTimeSeconds = cTimeSeconds;
|
|
|
|
uint8_t tState = getWM();
|
|
|
|
//char tB[128];
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
fusion_validate();
|
|
#endif
|
|
switch (tState)
|
|
{
|
|
case CAM_WS_INIT:
|
|
{
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
switch (m_sCamData.protocol)
|
|
{
|
|
case CAM_CTRL_PROTO_VISCA: delete((protocolPTZ_VISCA *) m_pProtocol); break;
|
|
case CAM_CTRL_PROTO_PELCO: delete((protocolPTZ_PELCO *) m_pProtocol); break;
|
|
case CAM_CTRL_PROTO_ONVIF: delete((protocolPTZ_ONVIF *) m_pProtocol); break;
|
|
case CAM_CTRL_PROTO_BRCP : delete((protocolPTZ_BRCP *) m_pProtocol); break;
|
|
default : delete(m_pProtocol);
|
|
};
|
|
m_pProtocol = NULL;
|
|
m_sCamData.online = false;
|
|
};
|
|
switch (m_sCamData.protocol)
|
|
{
|
|
case CAM_CTRL_PROTO_VISCA:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("VISCA");
|
|
#endif
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA(m_sCamData.protocol_aux);
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
basicTransport * tTransport = NULL;
|
|
hardwareManager * tHM = hardwareManager::getInstance();
|
|
if (tHM)
|
|
{
|
|
hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
|
|
if (tRES != NULL)
|
|
{
|
|
if (tRES->isValid())
|
|
{
|
|
tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
|
|
if (m_pProtocol->setTransport(tTransport))
|
|
{
|
|
if (! m_pProtocol->create())
|
|
{
|
|
LOG_ERROR("Protocol <<< Create >>> Failure!");
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Binding Port Failure!");
|
|
};
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG("HWM Has No UART PORT!");
|
|
#endif
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Can not get Hardware Manager!");
|
|
#endif
|
|
};
|
|
if (tTransport != NULL)
|
|
{
|
|
LOG("Bind Transport Port!");
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Transport Creation Failure!");
|
|
delete((protocolPTZ_VISCA *) m_pProtocol);
|
|
m_pProtocol = NULL;
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Protocol Creation failure!");
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
case CAM_CTRL_PROTO_PELCO:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("PELCO");
|
|
#endif
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO(m_sCamData.protocol_aux);
|
|
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
basicTransport * tTransport = NULL;
|
|
hardwareManager * tHM = hardwareManager::getInstance();
|
|
if (tHM)
|
|
{
|
|
hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
|
|
if (tRES != NULL)
|
|
{
|
|
if (tRES->isValid())
|
|
{
|
|
tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
|
|
if (m_pProtocol->setTransport(tTransport))
|
|
{
|
|
if (! m_pProtocol->create())
|
|
{
|
|
LOG_ERROR("Protocol <<< Create >>> Failure!");
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Binding Port Failure!");
|
|
};
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG("HWM Has No UART PORT!");
|
|
#endif
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Can not get Hardware Manager!");
|
|
#endif
|
|
};
|
|
if (tTransport != NULL)
|
|
{
|
|
LOG("Bind Transport Port!");
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Transport Creation Failure!");
|
|
delete((protocolPTZ_PELCO *) m_pProtocol);
|
|
m_pProtocol = NULL;
|
|
};
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Protocol Creation failure!");
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
case CAM_CTRL_PROTO_ONVIF:
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("ONVIF");
|
|
#endif
|
|
// m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
|
|
if (strstr(m_sCamData.onvif_ctrl, "http") == NULL)
|
|
{
|
|
char tURI[512];
|
|
if (m_sCamData.port)
|
|
{
|
|
sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
|
|
};
|
|
LOG("PTZ URI CREATE");
|
|
LOG( tURI );
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
|
|
}
|
|
else
|
|
{
|
|
LOG("PTZ USE");
|
|
LOG( m_sCamData.onvif_ctrl );
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
|
|
};
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("ONVIF-END");
|
|
#endif
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
if (! m_pProtocol->create())
|
|
{
|
|
LOG_ERROR("Error Creating Proto!");
|
|
delete((protocolPTZ_ONVIF *) m_pProtocol);
|
|
m_pProtocol = NULL;
|
|
};
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("PROTO CREATE DONE");
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
case CAM_CTRL_PROTO_BRCP:{
|
|
#ifdef DEBUG
|
|
LOG("BRCP");
|
|
#endif
|
|
// m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
|
|
if (strstr(m_sCamData.onvif_ctrl, "http") == NULL){
|
|
char tURI[256];
|
|
if (m_sCamData.port) {
|
|
sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
|
|
} else {
|
|
sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
|
|
};
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
|
|
} else {
|
|
m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
|
|
};
|
|
#ifdef DEBUG
|
|
LOG("BRCP-END");
|
|
#endif
|
|
if (m_pProtocol != NULL) {
|
|
if (! m_pProtocol->create()) {
|
|
LOG_ERROR("Error Creating Proto!");
|
|
delete((protocolPTZ_BRCP *) m_pProtocol);
|
|
m_pProtocol = NULL;
|
|
};
|
|
#ifdef DEBUG
|
|
LOG("PROTO CREATE DONE");
|
|
#endif
|
|
};
|
|
break;
|
|
};
|
|
default:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Camera Has no defined control protocol");
|
|
#endif
|
|
};
|
|
};
|
|
if (m_pProtocol != NULL)
|
|
{
|
|
// Load Presets only if we have protocol
|
|
load_presets();
|
|
|
|
mojoKernel * tKRNL = mojoKernel::getInstance();
|
|
if (tKRNL)
|
|
{
|
|
m_bSkeepPositioningWait = ((tKRNL->getMediaMode() & EVE_OUTPUT_VIDEO) == EVE_OUTPUT_VIDEO);
|
|
#ifdef DEBUG_EXTRA
|
|
char ttTT[128];
|
|
sprintf(ttTT, "Kernel Media Mode:%d", tKRNL->getMediaMode());
|
|
LOG(ttTT);
|
|
if (m_bSkeepPositioningWait)
|
|
{
|
|
LOG("Camera No Wait On Pos!");
|
|
}
|
|
else
|
|
{
|
|
LOG("Camera Will Wait On Pos!");
|
|
};
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("No Kernel Instance!");
|
|
};
|
|
m_sCamData.online = true;
|
|
setWM(CAM_WS_POWER_INIT);
|
|
};
|
|
m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
|
|
break;
|
|
};
|
|
case CAM_WS_POWER_INIT:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Init Camera - PowerMode");
|
|
#endif
|
|
// setBusy( true );
|
|
if (m_pProtocol->initCamera())
|
|
{
|
|
setWM(CAM_WS_WHITE_BALLANCE);
|
|
}
|
|
// setBusy( false );
|
|
break;
|
|
};
|
|
case CAM_WS_WHITE_BALLANCE:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Set WB");
|
|
#endif
|
|
// setBusy( true );
|
|
if (m_pProtocol->setWhiteBalanceMode(WB_AUTO))
|
|
{
|
|
setWM(CAM_WS_BACKLIGHT);
|
|
}
|
|
// setBusy( false );
|
|
break;
|
|
};
|
|
case CAM_WS_BACKLIGHT:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Set BLC");
|
|
#endif
|
|
// setBusy( true );
|
|
if (m_pProtocol->setBackLightMode(true))
|
|
{
|
|
setWM(CAM_WS_AUTO_FOCUS);
|
|
}
|
|
// setBusy( false );
|
|
break;
|
|
};
|
|
case CAM_WS_AUTO_FOCUS:
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Set AF");
|
|
#endif
|
|
// setBusy( true );
|
|
if (m_pProtocol->setAutoFocus(true))
|
|
{
|
|
setWM(CAM_WS_INIT_GO_HOME);
|
|
}
|
|
// setBusy( false );
|
|
break;
|
|
};
|
|
case CAM_WS_INIT_GO_HOME:
|
|
{
|
|
m_nHomingCounter = 0;
|
|
/* Skip For Restartin bug
|
|
if( !m_bNoAbsPositionning ) {
|
|
#ifdef DEBUG
|
|
LOG("INIT GO -1 0 -1");
|
|
#endif
|
|
if (m_pProtocol->goAbsolute(-1, 0, -1)) {
|
|
m_fCP_Pan = -1;
|
|
m_fCP_Tilt = 0;
|
|
m_fCP_Zoom = -1;
|
|
setWM( CAM_WS_READY );
|
|
};
|
|
} else {
|
|
#ifdef DEBUG
|
|
LOG("Go Home!");
|
|
#endif
|
|
CSTR TK = getPresetToken( ARGUS_PRESET_TYPE_HOME );
|
|
if( TK ) {
|
|
if ( !m_bCameraOnHomePosition ) {
|
|
if( !m_pProtocol->goPreset( TK )){
|
|
LOG_ERROR("Cannot Issue goPreset Command!");
|
|
};
|
|
m_bCameraOnHomePosition = true;
|
|
};
|
|
};
|
|
setWM( CAM_WS_READY );
|
|
};*/
|
|
LOG("INit GoHome");
|
|
setWM(CAM_WS_READY);
|
|
break;
|
|
};
|
|
case CAM_WS_AUTOMATED_MOVE:
|
|
{
|
|
m_bCameraOnHomePosition = false;
|
|
m_nRelativeMoveCounter++;
|
|
if ((m_bRelativeMoveMatrix & 0x03) != 0)
|
|
{
|
|
// Pan Move
|
|
if ((m_bRelativeMoveMatrix & 0x01) == 0)
|
|
{
|
|
m_fRM_Pan -= m_fSpeedRise;
|
|
}
|
|
else
|
|
{
|
|
m_fRM_Pan += m_fSpeedRise;
|
|
};
|
|
};
|
|
if ((m_bRelativeMoveMatrix & 0x0C) != 0)
|
|
{
|
|
// TILT Move
|
|
if ((m_bRelativeMoveMatrix & 0x04) == 0)
|
|
{
|
|
m_fRM_Tilt -= m_fSpeedRise;
|
|
}
|
|
else
|
|
{
|
|
m_fRM_Tilt += m_fSpeedRise;
|
|
}
|
|
};
|
|
if ((m_bRelativeMoveMatrix & 0x30) != 0)
|
|
{
|
|
// ZOOM Move
|
|
if ((m_bRelativeMoveMatrix & 0x10) == 0)
|
|
{
|
|
// Wide
|
|
m_fRM_Zoom -= m_fSpeedRise;
|
|
}
|
|
else
|
|
{
|
|
// Tele
|
|
m_fRM_Zoom += m_fSpeedRise;
|
|
};
|
|
};
|
|
if (m_fRM_Pan < -1.0f)
|
|
{
|
|
m_fRM_Pan = -1.0f;
|
|
}
|
|
if (m_fRM_Pan > 1.0f)
|
|
{
|
|
m_fRM_Pan = 1.0f;
|
|
}
|
|
if (m_fRM_Tilt < -1.0f)
|
|
{
|
|
m_fRM_Tilt = -1.0f;
|
|
}
|
|
if (m_fRM_Tilt > 1.0f)
|
|
{
|
|
m_fRM_Tilt = 1.0f;
|
|
}
|
|
if (m_fRM_Zoom < -1.0f)
|
|
{
|
|
m_fRM_Zoom = -1.0f;
|
|
}
|
|
if (m_fRM_Zoom > 1.0f)
|
|
{
|
|
m_fRM_Zoom = 1.0f;
|
|
}
|
|
|
|
m_fCP_Zoom += 0.5f * m_fRM_Zoom;
|
|
|
|
if (m_fCP_Zoom < -1.0f)
|
|
{
|
|
m_fCP_Zoom = -1.0f;
|
|
}
|
|
if (m_fCP_Zoom > 1.0f)
|
|
{
|
|
m_fCP_Zoom = 1.0f;
|
|
}
|
|
|
|
if (! relativeMove(m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom))
|
|
{
|
|
m_nRelativeMoveCounter = 0;
|
|
setWM(CAM_WS_READY);
|
|
break;
|
|
};
|
|
|
|
if (m_sCamData.ptz_axel)
|
|
{ // Manual
|
|
if (m_nRelativeMoveCounter > m_sCamData.ptz_axel)
|
|
{
|
|
m_nRelativeMoveCounter = 0;
|
|
setWM(CAM_WS_READY);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
// Stepping Axel by Zoom
|
|
uint8_t tVal = (uint8_t) (10.0f * (2.0f - (1.0f + m_fCP_Zoom)));
|
|
if (m_nRelativeMoveCounter > tVal)
|
|
{
|
|
m_nRelativeMoveCounter = 0;
|
|
setWM(CAM_WS_READY);
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
case CAM_WS_STOP_MOVE:
|
|
{
|
|
m_nRelativeMoveCounter++;
|
|
m_fRM_Pan = .0f;
|
|
m_fRM_Pan = .0f;
|
|
m_fRM_Tilt = .0f;
|
|
m_fRM_Tilt = .0f;
|
|
m_fRM_Zoom = .0f;
|
|
m_fRM_Zoom = .0f;
|
|
if (relativeStop())
|
|
{
|
|
m_nHomingCounter = 0;
|
|
m_nRelativeMoveCounter = 0;
|
|
setWM(CAM_WS_READY);
|
|
break;
|
|
};
|
|
if (m_sCamData.ptz_axel)
|
|
{
|
|
if (m_nRelativeMoveCounter > m_sCamData.ptz_axel)
|
|
{
|
|
setWM(CAM_WS_READY);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
uint8_t tVal = (uint8_t) (10.0f * (2.0f - (1.0f + m_fCP_Zoom)));
|
|
if (m_nRelativeMoveCounter > tVal)
|
|
{
|
|
setWM(CAM_WS_READY);
|
|
}
|
|
};
|
|
break;
|
|
};
|
|
case CAM_WS_GO_ABS_ROI:
|
|
case CAM_WS_GO_ABS_POSITION:
|
|
{
|
|
m_bCameraOnHomePosition = false;
|
|
setWM(CAM_WS_BUSY);
|
|
if (m_pCurrentROI != NULL)
|
|
{
|
|
// LOG("ROI Ok");
|
|
m_nHomingCounter = 0;
|
|
if (m_pBEH)
|
|
{
|
|
EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_MOVE_TO, NULL, NULL, NULL);
|
|
if (tEVT)
|
|
{
|
|
m_pBEH->broadcast(tEVT);
|
|
}
|
|
};
|
|
if (m_bNoAbsPositionning)
|
|
{
|
|
// LOG("ABS to PRESET");
|
|
uint8_t COL, ROW;
|
|
translateROI2PRESET(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom, COL, ROW);
|
|
// char tB[64];
|
|
// sprintf( tB, "Get ABS Preset Col %d Row %d!", COL, ROW );
|
|
// LOG( tB );
|
|
// sprintf( tB, "Old Preset Col %d Row %d!", m_bCurrentPresetCol, m_bCurrentPresetRow );
|
|
// LOG( tB );
|
|
if ((m_bCurrentPresetCol == COL) && (m_bCurrentPresetRow == ROW))
|
|
{
|
|
m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
|
|
m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
|
|
m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("INSTANT BCAST CAM ONPOS");
|
|
#endif
|
|
// Send Capture event
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
|
|
#else
|
|
DBC_SNAPSHOT_DATA * tData = NULL;
|
|
#endif
|
|
if (tData != NULL)
|
|
{
|
|
if (m_pBEH)
|
|
{
|
|
EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
|
|
if (tEVT)
|
|
{
|
|
m_pBEH->broadcast(tEVT);
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
};
|
|
setWM(CAM_WS_READY);
|
|
}
|
|
else
|
|
{
|
|
CSTR token = getPresetToken(COL, ROW);
|
|
if (token)
|
|
{
|
|
// update position Info
|
|
m_bCurrentPresetCol = COL;
|
|
m_bCurrentPresetRow = ROW;
|
|
m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
|
|
m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
|
|
m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
|
|
if (! m_pProtocol->goPreset(token))
|
|
{
|
|
LOG_ERROR("Cannot Issue goPreset Command!->Restart Camera?");
|
|
setWM(CAM_WS_END);
|
|
}
|
|
else
|
|
{
|
|
// Waiting Movement finish
|
|
if (m_bSkeepPositioningWait && 0)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("INSTANT BCAST CAM ONPOS");
|
|
#endif
|
|
// Send Capture event
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
|
|
#else
|
|
DBC_SNAPSHOT_DATA * tData = NULL;
|
|
#endif
|
|
if (tData != NULL)
|
|
{
|
|
if (m_pBEH)
|
|
{
|
|
EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
|
|
if (tEVT)
|
|
{
|
|
m_pBEH->broadcast(tEVT);
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
};
|
|
setWM(CAM_WS_READY);
|
|
}
|
|
else
|
|
{
|
|
// utilizeROI( m_pCurrentROI );
|
|
setWM(CAM_WS_WAIT_ONPOS);
|
|
};
|
|
};
|
|
}
|
|
else
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Not Found!");
|
|
#endif
|
|
utilizeROI(m_pCurrentROI);
|
|
setWM(CAM_WS_READY);
|
|
};
|
|
};
|
|
}
|
|
else
|
|
{
|
|
// update position Info
|
|
m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
|
|
m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
|
|
m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
|
|
// Do Movement
|
|
if (! m_pProtocol->goAbsolute(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection))
|
|
{
|
|
LOG_ERROR("Cannot Issue goAbsolute Command!->Restart Camera?");
|
|
setWM(CAM_WS_END);
|
|
}
|
|
else
|
|
{
|
|
// Waiting Movement finish
|
|
if (m_bSkeepPositioningWait)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("INSTANT BCAST CAM ONPOS");
|
|
#endif
|
|
// Send Capture event
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
|
|
#else
|
|
DBC_SNAPSHOT_DATA * tData = NULL;
|
|
#endif
|
|
if (tData != NULL)
|
|
{
|
|
if (m_pBEH)
|
|
{
|
|
EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
|
|
if (tEVT)
|
|
{
|
|
m_pBEH->broadcast(tEVT);
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
};
|
|
setWM(CAM_WS_READY);
|
|
}
|
|
else
|
|
{
|
|
setWM(CAM_WS_WAIT_ONPOS);
|
|
};
|
|
};
|
|
};
|
|
}
|
|
else
|
|
{
|
|
setWM(CAM_WS_READY);
|
|
}
|
|
break;
|
|
};
|
|
case CAM_WS_WAIT_ONPOS:
|
|
{
|
|
// LOG("WaitOnPos...");
|
|
DBC_SNAPSHOT_DATA * tData = NULL;
|
|
if (m_pCurrentROI != NULL)
|
|
{
|
|
// Send Capture event
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
tData = fusion_translate_ROI(m_pCurrentROI);
|
|
#else
|
|
tData = NULL;
|
|
#endif
|
|
};
|
|
// To Accept any new ROI's ??
|
|
// setWM( CAM_WS_READY );
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Start Waiting Cam On Position!");
|
|
#endif
|
|
if (! m_bSkeepPositioningWait)
|
|
{
|
|
if (! m_pProtocol->waitMoveIsDone())
|
|
{
|
|
m_bSkeepPositioningWait = true;
|
|
}
|
|
};
|
|
if (m_bSkeepPositioningWait)
|
|
{
|
|
SLEEP(3000);
|
|
}
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Done Waiting Cam On Position!");
|
|
#endif
|
|
if (tData != NULL)
|
|
{
|
|
if (m_pBEH)
|
|
{
|
|
EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
|
|
if (tEVT)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("BCAST CAM ONPOS");
|
|
#endif
|
|
m_pBEH->broadcast(tEVT);
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
tData = NULL;
|
|
};
|
|
setWM(CAM_WS_READY);
|
|
break;
|
|
};
|
|
case CAM_WS_GO_HOMING_PRESET:
|
|
{
|
|
if (! m_bCameraOnHomePosition)
|
|
{
|
|
// For new Camera Presets
|
|
CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_HOME);
|
|
if (TK)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Go Home!");
|
|
LOG(TK);
|
|
#endif
|
|
if (! m_pProtocol->goPreset(TK))
|
|
{
|
|
LOG_ERROR("Cannot Issue goPreset Command!");
|
|
};
|
|
}
|
|
else
|
|
{
|
|
// Old Method
|
|
if (m_sCamData.home_token[0] != (char) 0)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Go Home!");
|
|
LOG(m_sCamData.home_token);
|
|
#endif
|
|
if (! m_pProtocol->goPreset(m_sCamData.home_token))
|
|
{
|
|
LOG_ERROR("Cannot Issue goPreset Command!");
|
|
};
|
|
};
|
|
};
|
|
m_bCameraOnHomePosition = true;
|
|
m_bCurrentPresetCol = 0;
|
|
m_bCurrentPresetRow = 0;
|
|
};
|
|
setWM(CAM_WS_READY);
|
|
break;
|
|
};
|
|
case CAM_WS_GO_PRESET:
|
|
{
|
|
LOG("Go Preset!");
|
|
// if( m_sCamData.home_token[0] != (char)0 ) {
|
|
// LOG("Go Home!");
|
|
// LOG( m_sCamData.home_token );
|
|
// if( !m_pProtocol->goPreset( m_sCamData.home_token )){
|
|
// LOG_ERROR("Cannot Issue goPreset Command!");
|
|
// };
|
|
// };
|
|
setWM(CAM_WS_READY);
|
|
break;
|
|
};
|
|
case CAM_WS_SET_PRESET:
|
|
{
|
|
LOG("Set Preset!");
|
|
// if( m_sCamData.home_token[0] != (char)0 ) {
|
|
// LOG("Go Home!");
|
|
// LOG( m_sCamData.home_token );
|
|
// if( !m_pProtocol->goPreset( m_sCamData.home_token )){
|
|
// LOG_ERROR("Cannot Issue goPreset Command!");
|
|
// };
|
|
// };
|
|
setWM(CAM_WS_READY);
|
|
break;
|
|
};
|
|
case CAM_WS_BUSY:
|
|
{
|
|
// Handle Operation TO
|
|
setWM(CAM_WS_READY);
|
|
break;
|
|
};
|
|
case CAM_WS_READY:
|
|
{
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
m_pCurrentROI = fusion_fetchROI();
|
|
#else
|
|
|
|
#endif
|
|
if (m_pCurrentROI != NULL)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("HAVE ROI to see!");
|
|
#endif
|
|
setWM(CAM_WS_GO_ABS_POSITION);
|
|
}
|
|
else
|
|
{
|
|
// Idle Work --->
|
|
if (m_sCamData.eco_ir)
|
|
{
|
|
m_mIRProtector.lock();
|
|
if (m_bIRIsOn)
|
|
{
|
|
if (m_bIRTO)
|
|
{
|
|
if (bNewSecondLoop)
|
|
{
|
|
m_bIRTO--;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_OFF);
|
|
if (TK)
|
|
{
|
|
if (m_pProtocol->goPreset(TK))
|
|
{
|
|
m_bIRIsOn = false;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
m_mIRProtector.unlock();
|
|
};
|
|
if (m_sCamData.homing_enable)
|
|
{
|
|
if (bNewSecondLoop)
|
|
{
|
|
if (m_nHomingCounter < m_sCamData.homing_to)
|
|
{
|
|
m_nHomingCounter++;
|
|
}
|
|
else
|
|
{
|
|
// LOG("Go Home Position!");
|
|
m_nHomingCounter = 0;
|
|
setWM(CAM_WS_GO_HOMING_PRESET);
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
CAM_TASK * tTASK = fetchCamTask();
|
|
if (tTASK != NULL)
|
|
{
|
|
if (tTASK->movemet_needed)
|
|
{
|
|
CAM_PTZ_CMD * tCMD = tTASK->CMD;
|
|
if (tCMD)
|
|
{
|
|
switch (tCMD->CMD)
|
|
{
|
|
case PTZ_STOP:
|
|
{
|
|
m_nHomingCounter = 0;
|
|
setWM(CAM_WS_STOP_MOVE);
|
|
break;
|
|
};
|
|
case PTZ_MOVE:
|
|
{
|
|
if (tState != CAM_WS_AUTOMATED_MOVE)
|
|
{
|
|
m_nRelativeMoveCounter = 0;
|
|
}
|
|
m_bRelativeMoveMatrix = 0;
|
|
m_fRM_Pan = tCMD->PAN;
|
|
m_fRM_Tilt = tCMD->TILT;
|
|
m_fRM_Zoom = tCMD->ZOOM;
|
|
m_nHomingCounter = 0;
|
|
setWM(CAM_WS_AUTOMATED_MOVE);
|
|
break;
|
|
};
|
|
case PTZ_ABSOLUTE:
|
|
{
|
|
m_pCurrentROI = createCAM_ROI();
|
|
if (m_pCurrentROI != NULL)
|
|
{
|
|
CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
|
|
if (tTarget != NULL)
|
|
{
|
|
memset(tTarget, 0, sizeof(CAM_TRACK_RECORD));
|
|
tTarget->evt_db_ID = tTASK->source_evt_id;
|
|
m_pCurrentROI->targets.push_back(tTarget);
|
|
m_pCurrentROI->cam_orientation.pan = tCMD->PAN;
|
|
m_pCurrentROI->cam_orientation.tilt = tCMD->TILT;
|
|
m_pCurrentROI->cam_orientation.zoom = tCMD->ZOOM;
|
|
m_nHomingCounter = 0;
|
|
setWM(CAM_WS_GO_ABS_POSITION);
|
|
}
|
|
else
|
|
{
|
|
utilizeROI(m_pCurrentROI);
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
case PTZ_RELOAD_CAMERA:
|
|
{
|
|
LOG("Exit Command Rcpt");
|
|
m_bThreadStatus = TH_ENDED;
|
|
};
|
|
};
|
|
free(tCMD);
|
|
tTASK->CMD = NULL;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG("No Movement -> INSTCAP");
|
|
// No Movement -> Just Capture
|
|
if (m_pBEH)
|
|
{
|
|
EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, NULL);
|
|
if (tEVT)
|
|
{
|
|
tEVT->m_db_id = tTASK->source_evt_id;
|
|
m_pBEH->broadcast(tEVT);
|
|
};
|
|
};
|
|
};
|
|
free(tTASK);
|
|
}
|
|
else
|
|
{
|
|
// Lowest Priority to Web Client Commands
|
|
#ifdef DEBUG_EXTRA__
|
|
LOG("Check Web CMD!");
|
|
#endif
|
|
PUSHED = m_pDBC->getNodePushedCMD(m_sNodeData.node_id);
|
|
if (PUSHED != NULL)
|
|
{
|
|
#ifdef DEBUG_EXTRA__
|
|
LOG("HAVE Web CMD!");
|
|
#endif
|
|
m_pDBC->updateNodePushedCMD(PUSHED->id, DBC_CMD_READY_TO_CLEAN);
|
|
if ((PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK) == ARGUS_CAM_PCMD_CMD_MASK)
|
|
{
|
|
switch (PUSHED->CMD)
|
|
{
|
|
case 0x80:
|
|
{
|
|
// Call Home Preset
|
|
LOG("CALL HOME PRESET!");
|
|
CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_HOME);
|
|
if (TK)
|
|
{
|
|
LOG(TK);
|
|
if (m_pProtocol->goPreset(TK))
|
|
{
|
|
m_bCameraOnHomePosition = true;
|
|
m_nHomingCounter = 0;
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
case 0x81:
|
|
{
|
|
// Call IR On Preset
|
|
LOG("CALL IR ON PRESET!");
|
|
m_mIRProtector.lock();
|
|
CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_ON);
|
|
if (TK)
|
|
{
|
|
LOG(TK);
|
|
if (m_pProtocol->goPreset(TK))
|
|
{
|
|
m_bIRIsOn = true;
|
|
m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG("PRESET NOT FOUND!");
|
|
}
|
|
m_mIRProtector.unlock();
|
|
break;
|
|
};
|
|
case 0x82:
|
|
{
|
|
// Call IR Off Preset
|
|
LOG("CALL IR OFF PRESET!");
|
|
m_mIRProtector.lock();
|
|
CSTR TK = (m_sCamData.eco_ir) ? getPresetToken(ARGUS_PRESET_TYPE_IR_OFF) : getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
|
|
if (TK)
|
|
{
|
|
LOG(TK);
|
|
if (m_pProtocol->goPreset(TK))
|
|
{
|
|
m_bIRIsOn = false;
|
|
m_bIRTO = 0;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG("PRESET NOT FOUND!");
|
|
}
|
|
m_mIRProtector.unlock();
|
|
break;
|
|
};
|
|
case 0x83:
|
|
{
|
|
// Call IR Auto Preset
|
|
LOG("CALL IR AUTO PRESET!");
|
|
m_mIRProtector.lock();
|
|
CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
|
|
if (TK)
|
|
{
|
|
LOG(TK);
|
|
if (m_pProtocol->goPreset(TK))
|
|
{
|
|
m_bIRIsOn = true;
|
|
m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG("PRESET NOT FOUND!");
|
|
}
|
|
m_mIRProtector.unlock();
|
|
break;
|
|
};
|
|
case 0x84:
|
|
{
|
|
// Call Wisher Preset
|
|
LOG("CALL WIPER PRESET!");
|
|
CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_WISHER);
|
|
if (TK)
|
|
{
|
|
LOG(TK);
|
|
m_pProtocol->goPreset(TK);
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
}
|
|
else if (tState == CAM_WS_READY || tState == CAM_WS_AUTOMATED_MOVE)
|
|
{ // No Way to get here
|
|
// Direct Movment Mode
|
|
if (PUSHED->CMD == ARGUS_CAM_PCMD_STOP)
|
|
{
|
|
m_nHomingCounter = 0;
|
|
setWM(CAM_WS_STOP_MOVE);
|
|
}
|
|
else
|
|
{
|
|
//char tB[64];
|
|
if (tState != CAM_WS_AUTOMATED_MOVE)
|
|
{
|
|
m_nRelativeMoveCounter = 0;
|
|
}
|
|
m_bRelativeMoveMatrix = (PUSHED->CMD) >> 1;
|
|
m_nHomingCounter = 0;
|
|
setWM(CAM_WS_AUTOMATED_MOVE);
|
|
};
|
|
};
|
|
free(PUSHED);
|
|
PUSHED = NULL;
|
|
};
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
case CAM_WS_END:
|
|
{
|
|
LOG("Exit Command Rcpt");
|
|
m_bThreadStatus = TH_ENDED;
|
|
break;
|
|
};
|
|
};
|
|
SLEEP(DEFAULT_THREAD_SLEEP_TIME);
|
|
};
|
|
#ifdef DEBUG
|
|
LOG("CTRL Loop End!");
|
|
#endif
|
|
}
|
|
|
|
bool deviceNodeCamera::setNoPositionWait(bool FL)
|
|
{
|
|
m_bSkeepPositioningWait = FL;
|
|
return true;
|
|
}
|
|
|
|
bool deviceNodeCamera::testFOV(C3D_DECART L)
|
|
{
|
|
// System Coords -> trans to local and go to funct
|
|
systemAnchor * tSystem = systemAnchor::getInstance();
|
|
if (tSystem == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
C3D_SPH_DEGREES SL;
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Test FOV local Decart coords");
|
|
#endif
|
|
if (! tSystem->convertToLocal(&m_oPosition, L, SL))
|
|
{
|
|
return false;
|
|
}
|
|
return testFOV(SL);
|
|
}
|
|
|
|
bool deviceNodeCamera::testFOV(C3D_WGS84_LOC L)
|
|
{
|
|
// Global Coords
|
|
systemAnchor * tSystem = systemAnchor::getInstance();
|
|
if (tSystem == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
C3D_SPH_DEGREES SL;
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Test FOV WGS coords");
|
|
#endif
|
|
if (! tSystem->convertToLocal(&m_oPosition, L, SL))
|
|
{
|
|
return false;
|
|
}
|
|
return testFOV(SL);
|
|
}
|
|
|
|
bool deviceNodeCamera::testFOV(C3D_SPH_RADIANS L)
|
|
{
|
|
// Local Coords
|
|
C3D_SPH_DEGREES SL;
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Test FOV local Spherical(rad) coords");
|
|
#endif
|
|
spherical2spherical(L, SL);
|
|
return testFOV(SL);
|
|
}
|
|
|
|
bool deviceNodeCamera::testFOV(C3D_SPH_DEGREES SL)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
char tB[128];
|
|
#endif
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Test FOV local Spherical(deg) coords");
|
|
#endif
|
|
switch (m_sCamData.triggering_mode)
|
|
{
|
|
case CAM_TRIGGER_STRICT:
|
|
{
|
|
if (SL.r > m_fMaxRange || SL.r < m_fMinRange)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
|
|
LOG(tB);
|
|
#endif
|
|
return false;
|
|
};
|
|
break;
|
|
};
|
|
case CAM_TRIGGER_ALL_NEAR:
|
|
{
|
|
if (SL.r > m_fMaxRange)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
|
|
LOG(tB);
|
|
#endif
|
|
return false;
|
|
};
|
|
break;
|
|
};
|
|
case CAM_TRIGGER_ALL_FAR:
|
|
{
|
|
if (SL.r < m_fMinRange)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
|
|
LOG(tB);
|
|
#endif
|
|
return false;
|
|
};
|
|
break;
|
|
};
|
|
case CAM_TRIGGER_ALL: return true;
|
|
};
|
|
|
|
// float HS = AC_imager_width[m_sCamData.imager_type];
|
|
// float VS = AC_imager_height[m_sCamData.imager_type];
|
|
// float HS2 = HS * HS;
|
|
// float VS2 = VS * VS;
|
|
// float IR = HS / VS;
|
|
// float IR2 = IR * IR;
|
|
|
|
if (m_sCamData.pan_angles == 0)
|
|
{
|
|
// Fixed Camera
|
|
float tA = fabsf(SL.fi);
|
|
float tZ = 0.5f * (m_fMinHFov + (SL.r - m_fMinRange) * m_fR2FL);
|
|
if (tA > tZ)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m_sCamData.pan_angles < 360)
|
|
{ // If endless PAN -> PASSED
|
|
// Partial Pan
|
|
switch (m_sCamData.pan_model)
|
|
{
|
|
case 1:
|
|
{
|
|
// Regular Pan
|
|
float tFOV = 0.5f * (m_fMinHFov + (SL.r - m_fMinRange) * m_fR2FL);
|
|
float tRad = deg2rad(SL.fi);
|
|
#ifdef DEBUG_EXTRA
|
|
sprintf(tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad);
|
|
LOG(tB);
|
|
#endif
|
|
if ((tRad < (-1.0 * tFOV)) || (tRad > (deg2rad(m_sCamData.pan_angles) + tFOV)))
|
|
{
|
|
return false;
|
|
}
|
|
break;
|
|
};
|
|
case 2:
|
|
{
|
|
|
|
break;
|
|
};
|
|
case 3:
|
|
{
|
|
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
if (m_sCamData.tilt_angles == 0)
|
|
{
|
|
// Fixed Camera
|
|
if ((SL.tetta < (m_fMaxVFov / -2.0f)) || (SL.tetta > (m_fMaxVFov / 2.0f)))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m_sCamData.tilt_angles < 90)
|
|
{ // if Cam CAN DO 90 -> Pass
|
|
// Partial Tilt
|
|
switch (m_sCamData.tilt_model)
|
|
{
|
|
case 1:
|
|
{
|
|
// Regular Tilt
|
|
float tFOV = 0.5f * (m_fMinVFov + (m_fMaxVFov - m_fMinVFov) * (SL.r / m_fMaxRange));
|
|
float tRad = deg2rad(SL.tetta);
|
|
if ((tRad < (-1.0 * tFOV)) || (tRad > (deg2rad(m_sCamData.tilt_angles) + tFOV)))
|
|
{
|
|
return false;
|
|
}
|
|
break;
|
|
};
|
|
case 2:
|
|
{
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
return true;
|
|
}
|
|
|
|
bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_WGS84_LOC L)
|
|
{
|
|
systemAnchor * tSystem = systemAnchor::getInstance();
|
|
if (tSystem == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
C3D_SPH_DEGREES SL;
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Look at WGS coords!");
|
|
#endif
|
|
tSystem->convertToLocal(&m_oPosition, L, SL);
|
|
return lookAt(TargetRefID, SL);
|
|
}
|
|
|
|
bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_DECART L)
|
|
{
|
|
systemAnchor * tSystem = systemAnchor::getInstance();
|
|
if (tSystem == NULL)
|
|
{
|
|
LOG_ERROR("Cant Get Anchor!");
|
|
return false;
|
|
}
|
|
C3D_SPH_DEGREES SL;
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Look at System Decart coords!");
|
|
#endif
|
|
tSystem->convertToLocal(&m_oPosition, L, SL);
|
|
return lookAt(TargetRefID, SL);
|
|
}
|
|
|
|
bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_SPH_RADIANS L)
|
|
{
|
|
C3D_SPH_DEGREES SL;
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Look at spherical(rad) 2 spherical(deg) coords!");
|
|
#endif
|
|
spherical2spherical(L, SL);
|
|
return lookAt(TargetRefID, SL);
|
|
}
|
|
|
|
bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_SPH_DEGREES L)
|
|
{
|
|
if (m_bCameraIsStatic)
|
|
{
|
|
//DBC_SNAPSHOT_DATA * tData = (DBC_SNAPSHOT_DATA *) malloc(sizeof(DBC_SNAPSHOT_DATA));
|
|
DBC_SNAPSHOT_DATA * tData = new DBC_SNAPSHOT_DATA();
|
|
if (tData)
|
|
{
|
|
//memset(tData, 0, sizeof(DBC_SNAPSHOT_DATA));
|
|
tData->stream_id = m_sNodeData.aux_parameter;
|
|
tData->assoc_event_ids.push_back(TargetRefID);
|
|
if (m_pBEH)
|
|
{
|
|
EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
|
|
if (tEVT)
|
|
{
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("INSTANT BCAST CAM ONPOS");
|
|
#endif
|
|
m_pBEH->broadcast(tEVT);
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
//free(tData);
|
|
delete(tData);
|
|
};
|
|
};
|
|
return true;
|
|
};
|
|
// char tB[128];
|
|
// sprintf(tB, "Target On %.3f %.3f %.3f", L.r, L.fi, L.tetta );
|
|
// LOG( tB );
|
|
// sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
|
|
// LOG( tB );
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Look at local spherical deg. coords!(final)");
|
|
#endif
|
|
// if( getWM() == CAM_WS_READY ){
|
|
// C3D_ORIENT_ONVIF LL;
|
|
// spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
|
|
// return absoluteMove( TargetRefID, LL );
|
|
// };
|
|
// Camera is Busy
|
|
if (m_bShineOnTarget)
|
|
{
|
|
m_mIRProtector.lock();
|
|
if (! m_bIRIsOn)
|
|
{
|
|
CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
|
|
if (TK)
|
|
{
|
|
if (m_pProtocol->goPreset(TK))
|
|
{
|
|
m_bIRIsOn = true;
|
|
m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
|
|
};
|
|
};
|
|
}
|
|
else
|
|
{
|
|
m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
|
|
}
|
|
m_mIRProtector.unlock();
|
|
};
|
|
// targeting by Presets -> instant ROI
|
|
if (m_bNoAbsPositionning)
|
|
{
|
|
CAM_ROI * tROI = createCAM_ROI();
|
|
if (tROI != NULL)
|
|
{
|
|
CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
|
|
if (tTarget != NULL)
|
|
{
|
|
memset(tTarget, 0, sizeof(CAM_TRACK_RECORD));
|
|
tTarget->evt_db_ID = TargetRefID;
|
|
tROI->targets.push_back(tTarget);
|
|
tROI->ts_ms = getMilliseconds();
|
|
spherical2onvif(L, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
|
|
tROI->cam_position.fi = L.fi;
|
|
tROI->cam_position.tetta = L.tetta;
|
|
tROI->cam_position.r = L.r;
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
m_mROIsProtector.lock();
|
|
m_vROIS.push_back(tROI);
|
|
m_mROIsProtector.unlock();
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("No MEM 4 TARGTEG DATA");
|
|
utilizeROI(tROI);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("No MEM 4 ROI");
|
|
}
|
|
return true;
|
|
};
|
|
#ifndef NO_CAMERA_FUSION_ENGINE
|
|
return fusion_consumeData(TargetRefID, L);
|
|
#else
|
|
return true;
|
|
#endif
|
|
}
|
|
|
|
bool deviceNodeCamera::makeSnap(uint32_t TargetRefID)
|
|
{
|
|
CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
|
|
if (tTask)
|
|
{
|
|
memset(tTask, 0, sizeof(CAM_TASK));
|
|
tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
|
|
if (tTask->CMD)
|
|
{
|
|
tTask->CMD->CMD = PTZ_CAPTURE_ONLY;
|
|
tTask->movemet_needed = false;
|
|
tTask->source_evt_id = TargetRefID;
|
|
return pushCamTask(tTask);
|
|
}
|
|
else
|
|
{
|
|
free(tTask);
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool deviceNodeCamera::connectToStream(uint32_t id)
|
|
{
|
|
/*
|
|
if( id ){
|
|
argusKernelModule * tKM = NULL;
|
|
argusKernel * tKRNL = NULL;
|
|
argusModuleFactory * tMF = NULL;
|
|
if( m_pDBC == NULL ) {
|
|
LOG_ERROR("No Database Connector!");
|
|
return false;
|
|
};
|
|
tKRNL = argusKernel::getInstance();
|
|
if( tKRNL ) {
|
|
tMF = tKRNL->getModuleFactory();
|
|
if( tMF ) {
|
|
tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
|
|
} else {
|
|
LOG_ERROR("No ModuleFactory Instance!");
|
|
return false;
|
|
};
|
|
} else {
|
|
LOG_ERROR("No Kernel Instance!");
|
|
return false;
|
|
};
|
|
if( tKM ) {
|
|
// New Module
|
|
DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
|
|
if( tDATA ) {
|
|
m_sMediaSource.mediaStreamId = id;
|
|
if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
|
|
if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
|
|
m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
|
|
} else {
|
|
if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
|
|
m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource );
|
|
};
|
|
|
|
if( m_pSource != NULL ) {
|
|
char tMRL[1024];
|
|
#ifdef DEBUG
|
|
LOG("Source OK");
|
|
#endif
|
|
((videoLIVE555Source*)m_pSource)->setWM( MS_MODE_STREAM_PROXY | MS_MODE_OVERLAYED_LOOPS | MS_MODE_DECODE_FRAMES );
|
|
|
|
int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
|
|
int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
|
|
int pix = -1;
|
|
bool in_16_9 = (((tDATA->width*100) / tDATA->height ) > 140 );
|
|
bool out_16_9 = (((tW*100) / tH ) > 140 );
|
|
updateOpticalParameters( tW, tH );
|
|
if( strlen( tDATA->c_type ) ){
|
|
|
|
};
|
|
//if( tW > 0 ){
|
|
// //m_pSource->setProportionalByWidth( tW );
|
|
// m_pSource->setSize( tW, tH );
|
|
//};
|
|
if( in_16_9 != out_16_9 ){
|
|
if( in_16_9 ){
|
|
tH = ((( tW * 1000 ) / 16 ) * 9 ) / 1000;
|
|
} else {
|
|
tW = ((( tH * 1000 ) / 3 ) * 4 ) / 1000;
|
|
};
|
|
};
|
|
if (strncmp(tDATA->mrl_proto, "v4l2", 4) == 0) {
|
|
sprintf( tMRL, tDATA->mrl );
|
|
} else {
|
|
DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
|
|
if( tCAM ) {
|
|
sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
|
|
free( tCAM );
|
|
} else {
|
|
LOG_ERROR("Error Getting CAM Data!");
|
|
delete( m_pSource );
|
|
m_pSource = NULL;
|
|
return false;
|
|
};
|
|
};
|
|
LOG( tMRL );
|
|
if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
|
|
m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
|
|
if ( !m_bSourceConnected ) {
|
|
//delete( m_pSource );
|
|
if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
|
|
delete((videoAVLIBSource*)m_pSource);
|
|
} else {
|
|
delete((videoLIVE555Source*)m_pSource);
|
|
};
|
|
m_pSource = NULL;
|
|
} else {
|
|
m_nActiveStreamID = id;
|
|
#ifdef DEBUG
|
|
LOG("Source is Connected to Output.");
|
|
#endif
|
|
};
|
|
} else {
|
|
LOG_ERROR("Can not Open Video Source!");
|
|
//delete( m_pSource );
|
|
if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
|
|
delete((videoAVLIBSource*)m_pSource);
|
|
} else {
|
|
delete((videoLIVE555Source*)m_pSource);
|
|
};
|
|
m_pSource = NULL;
|
|
};
|
|
} else {
|
|
LOG_ERROR("Video Source Stream Failure!");
|
|
};
|
|
free( tDATA );
|
|
};
|
|
}
|
|
#ifdef DEBUG
|
|
else LOG("No Video Module!")
|
|
#endif
|
|
;
|
|
};
|
|
LOG("Connect Finished!");
|
|
return m_bSourceConnected;
|
|
*/
|
|
if ( id ) return true;
|
|
return true;
|
|
}
|
|
|
|
bool deviceNodeCamera::disconnectFromStream(void)
|
|
{
|
|
/*if( m_bSourceConnected ) {
|
|
if( m_pSource ){
|
|
delete( m_pSource );
|
|
m_pSource = NULL;
|
|
};
|
|
m_bSourceConnected = false;
|
|
};
|
|
return !m_bSourceConnected;
|
|
*/
|
|
return true;
|
|
}
|
|
|
|
bool deviceNodeCamera::validateStream(void)
|
|
{
|
|
/*
|
|
if( m_bSourceConnected ) {
|
|
if( m_pSource ) {
|
|
if( m_pSource->isAttached() ){
|
|
if( m_pSource->getStatus() < MS_STOPED ) return true;
|
|
#ifdef DEBUG
|
|
LOG("Source is Finished!");
|
|
#endif
|
|
};
|
|
#ifdef DEBUG
|
|
LOG("Source is Disconnected!");
|
|
#endif
|
|
} else LOG_ERROR("No Source Object! Set Disconnected!");
|
|
|
|
disconnectFromStream();
|
|
};
|
|
return false;
|
|
*/
|
|
return true;
|
|
}
|
|
|
|
bool deviceNodeCamera::validate()
|
|
{
|
|
if (m_pDBC == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
DBC_CAM_DATA * tDATA = m_pDBC->getCamData(m_sCamData.id);
|
|
if (tDATA == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
if (memcmp(tDATA, &m_sCamData, sizeof(DBC_CAM_DATA)) != 0)
|
|
{
|
|
// Settings Changed
|
|
// memcpy(&m_sCamData, tDATA, sizeof(DBC_CAM_DATA) );
|
|
free(tDATA);
|
|
return false;
|
|
};
|
|
free(tDATA);
|
|
if (! validateStream())
|
|
{
|
|
return false;
|
|
}
|
|
return deviceNode::validate();
|
|
}
|
|
|
|
bool deviceNodeCamera::load_presets(void)
|
|
{
|
|
bool bHaveIROFF = false;
|
|
bool bHaveIRON = false;
|
|
bool bHaveIRAUTO = false;
|
|
|
|
// Request PRESETS FROM CAMERA?! for some PTZ cameras without presets inpossible to
|
|
// operate by presets
|
|
|
|
if (m_pProtocol->getCameraPresets())
|
|
{
|
|
LOG("Camera Presets Loadded");
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Error while loadding Camera Presets!");
|
|
}
|
|
|
|
if (m_pDBC == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
DBC_PRESETS_INFO * tData = m_pDBC->getCamPresetInfo(m_sCamData.id);
|
|
if (tData)
|
|
{
|
|
//memcpy(&m_sCamPresets, tData, sizeof(DBC_PRESETS_INFO));
|
|
m_sCamPresets.maxCount = tData->maxCount;
|
|
m_sCamPresets.gRows = tData->gRows;
|
|
m_sCamPresets.gCols = tData->gCols;
|
|
m_sCamPresets.presets.clear();
|
|
#ifdef DEBUG
|
|
char tB[128];
|
|
LOG("Loading Presets!");
|
|
sprintf(tB, "Cam Presets Info: CNT: %d Cols: %d Rows: %d ", m_sCamPresets.maxCount, m_sCamPresets.gCols, m_sCamPresets.gRows);
|
|
LOG(tB);
|
|
#endif
|
|
DBC_INT_LIST * tList = m_pDBC->listCamPresets(m_sCamData.id);
|
|
if (tList)
|
|
{
|
|
for (DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++)
|
|
{
|
|
CAM_PRESET * tData = m_pDBC->getCamPreset(*idx);
|
|
if (tData)
|
|
{
|
|
m_sCamPresets.presets.push_back(tData);
|
|
bHaveIRON = (tData->role == ARGUS_PRESET_TYPE_IR_ON) ? true : bHaveIRON;
|
|
bHaveIROFF = (tData->role == ARGUS_PRESET_TYPE_IR_OFF) ? true : bHaveIROFF;
|
|
bHaveIRAUTO = (tData->role == ARGUS_PRESET_TYPE_IR_AUTO) ? true : bHaveIRAUTO;
|
|
};
|
|
};
|
|
delete(tList);
|
|
};
|
|
if (m_sCamData.eco_ir)
|
|
{
|
|
m_bShineOnTarget = (bHaveIROFF && bHaveIRAUTO);
|
|
}
|
|
else
|
|
{
|
|
m_bShineOnTarget = false;
|
|
}
|
|
return true;
|
|
#ifdef DEBUG
|
|
}
|
|
else
|
|
{
|
|
LOG("No Camera Presets!");
|
|
#endif
|
|
};
|
|
return false;
|
|
}
|
|
|
|
void deviceNodeCamera::translateROI2PRESET(float P, float T, float Z, uint8_t & col, uint8_t & row)
|
|
{
|
|
//char tB[128];
|
|
if ( T ) Z = Z;
|
|
row = (uint8_t)(Z * ((float)m_sCamPresets.gRows));
|
|
if (P < 0.5)
|
|
{
|
|
P = P + 1.5f;
|
|
}
|
|
else
|
|
{
|
|
P = P - 0.5f;
|
|
};
|
|
col = (uint8_t) (P * ((float) (m_sCamPresets.gCols * (1 << row)) / 2.0f));
|
|
row++;
|
|
}
|
|
|
|
CSTR deviceNodeCamera::getPresetToken(uint8_t CCOL, uint8_t CROW)
|
|
{
|
|
if (m_sCamPresets.presets.size() > 0)
|
|
{
|
|
for (V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++)
|
|
{
|
|
if ((*idx)->role == ARGUS_PRESET_TYPE_POSITION)
|
|
{
|
|
if (((*idx)->row == CROW) && ((*idx)->col == CCOL))
|
|
{
|
|
return (CSTR) (*idx)->token;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
CSTR deviceNodeCamera::getPresetToken(uint8_t specialRole)
|
|
{
|
|
if (m_sCamPresets.presets.size() > 0)
|
|
{
|
|
for (V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++)
|
|
{
|
|
if ((*idx)->role == specialRole)
|
|
{
|
|
return (CSTR) (*idx)->token;
|
|
}
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|
|
//#undef DEBUG_EXTRA
|