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.
 
 
 
 
 
 

884 lines
32 KiB

#include "rgooseCamera.h"
#include "../components/base/basicCameraInfo.h"
#include "../components/object/objectSystemAnchor.h"
#include "../hardware/uart/serialPort.h"
#include "../hardware/uart/serialSOL.h"
#include "../data/protocol/protocolPTZ_VISCA.h"
#include "../data/protocol/protocolPTZ_ONVIF.h"
#include "../data/protocol/protocolPTZ_PELCO.h"
#include "rgooseKernel.h"
#include "rgooseHardwareResourceSerialProvider.h"
#include "rgooseModuleEmbedVideo.h"
#define LOG( X ) m_pLog->Log( "RCAM", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "RCAM", this, _LOG_ERROR, X );
#endif
// all sizes in mm
static 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 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 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 };
ARGUS_Camera::ARGUS_Camera(): basicThread(){
m_pLog = basicLogCollection::getInstance();
m_pBEH = basicEventHeap::getInstance();
m_pDBC = argusDBC::getInstance();
m_tTimeTSeconds = 0;
m_pPosition = NULL;
m_pProtocol = NULL;
m_pTransport = NULL;
m_bState = 0;
m_bBusy = true;
m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
m_nRelativeMoveCounter = 0;
m_bRelativeMoveMatrix = 0;
m_fSpeedRise = 0.03f;
m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
m_bSourceConnected = false;
m_pSource = NULL;
};
ARGUS_Camera::~ARGUS_Camera(){
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;
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");
};
bool ARGUS_Camera::create( uint32_t CameraID ){
if( CameraID == 0 ) return false;
DBC_CAM_DATA * tData = m_pDBC->getCamData( CameraID );
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.max_range == .0f ){
m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_sCamData.max_f, 1280 );
} else {
m_fMaxRange = m_sCamData.max_range;
};
m_fMinHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.min_f );
m_fMaxHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.max_f );
m_fMinVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.min_f );
m_fMaxVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.max_f );
if( m_sCamData.ptz_speed_step > .0f ) {
m_fSpeedRise = m_sCamData.ptz_speed_step;
};
#ifdef DEBUG
char tB[128];
LOG("Camera Info:");
sprintf( tB, "Maximal Range: %0.2f m. ", m_fMaxRange);
LOG(tB);
sprintf( tB, "Maximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov );
LOG(tB);
sprintf( tB, "Minimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov );
LOG(tB);
#endif
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_pPosition->setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z );
m_pPosition->setOrientationDeg( m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot );
if( m_pProtocol != NULL ){
LOG_ERROR("Cannot Start: Service Already Running!");
return 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 ) {
argusKernel * tKRNL = argusKernel::getInstance();
basicTransport * tTransport = NULL;
if( tKRNL!= NULL ) {
argusHardwareManager * tHM = tKRNL->getHardwareManager();
if ( tHM ) {
argusHardwareResource * tRES = tHM->requestResource( ARGUS_HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id );
if( tRES != NULL ) {
if( tRES->isValid()) {
tTransport = static_cast<basicTransport *>(static_cast<argusHardwareResourceSerialProvider *>(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 Kernel!");
#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 NEW 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 ) {
argusKernel * tKRNL = argusKernel::getInstance();
basicTransport * tTransport = NULL;
if( tKRNL!= NULL ) {
argusHardwareManager * tHM = tKRNL->getHardwareManager();
if ( tHM ) {
argusHardwareResource * tRES = tHM->requestResource( ARGUS_HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id );
if( tRES != NULL ) {
if( tRES->isValid()) {
tTransport = static_cast<basicTransport *>(static_cast<argusHardwareResourceSerialProvider *>(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 Kernel!");
#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 NEW failure!");
#endif
break;
};
case CAM_CTRL_PROTO_ONVIF:{
#ifdef DEBUG
LOG("ONVIF");
#endif
m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.username, m_sCamData.password );
if( m_pProtocol!=NULL ) {
if( !m_pProtocol->create() ) {
LOG_ERROR("Error Creating Proto!");
delete( (protocolPTZ_ONVIF*) m_pProtocol );
m_pProtocol = NULL;
};
};
break;
};
default:{
#ifdef DEBUG
LOG("Camera Has no defined control protocol");
#endif
};
};
if( m_pProtocol == NULL ) {
if(m_sCamData.protocol == 0 ) {
m_sCamData.online = true;
} else LOG_ERROR("No Proto Created!");
} else {
#ifdef DEBUG
LOG("Proto is OK");
#endif
m_sCamData.online = init();
};
return m_sCamData.online;
};
void ARGUS_Camera::setBusy( bool Status ){
m_bBusy = Status;
};
bool ARGUS_Camera::relativeMove( float PanSPD, float TiltSPD, float ZoomSPD ){
if( m_sCamData.online ) {
uint32_t MoveMatrix = 0;
if( PanSPD != .0f ){
if( PanSPD > 0 ) {
MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
} else {
MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
};
};
if( TiltSPD != .0f ){
if( TiltSPD > 0 ) {
MoveMatrix |= PTZ_DRIVE_TILT_UP;
} else {
MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
};
};
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 ARGUS_Camera::relativeStop(){
if( m_sCamData.online ) {
return m_pProtocol->move( 0 );
};
return false;
};
bool ARGUS_Camera::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;
//m_mQPROTECTOR.lock();
m_qCAM_TASK.push( tTask );
//m_mQPROTECTOR.unlock();
return true;
} else {
free( tTask );
};
};
}
return false;
};
void ARGUS_Camera::m_fThreadProc( void ){
DBC_PUSHED_CMD * PUSHED = NULL;
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ) {
//Local Recorder
if( m_bSourceConnected ) {
};
PUSHED = m_pDBC->getNodePushedCMD( m_sCamData.node_id );
if( PUSHED != NULL ) {
if( ( PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK ) == ARGUS_CAM_PCMD_CMD_MASK ) {
switch( PUSHED->CMD ) {
case 0x80:{
//m_bWM = ANODE_WM_2D_ISSUE_FULL_RESET;
break;
};
case 0x81:{
//m_bWM = ANODE_WM_2D_GET_FAST_DRAW;
break;
};
case 0x82:{
break;
};
};
} else if ( m_bState == CAM_WS_READY || m_bState == CAM_WS_AUTOMATED_MOVE ){
//Direct Movment Mode
if( PUSHED->CMD == ARGUS_CAM_PCMD_STOP ) {
m_bState = CAM_WS_STOP_MOVE;
} else {
char tB[64];
if( m_bState!= CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
m_bRelativeMoveMatrix = ( PUSHED->CMD ) >> 1;
m_bState = CAM_WS_AUTOMATED_MOVE;
};
};
free( PUSHED );
PUSHED = NULL;
};
switch( m_bState ) {
case CAM_WS_INIT:{
#ifdef DEBUG
LOG("Init Camera - PowerMode");
#endif
setBusy( true );
if( m_pProtocol->initCamera() ) m_bState = 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 ) ) m_bState = CAM_WS_BACKLIGHT;
setBusy( false );
break;
};
case CAM_WS_BACKLIGHT:{
#ifdef DEBUG
LOG("Set BLC");
#endif
setBusy( true );
if( m_pProtocol->setBackLightMode( true ) ) m_bState = 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 ) ) m_bState = CAM_WS_INIT_GO_HOME;
setBusy( false );
break;
};
case CAM_WS_INIT_GO_HOME:{
#ifdef DEBUG
LOG("INIT GO -1 -1 -1");
#endif
setBusy( true );
if( m_pProtocol->goAbsolute( -1, -1, -1 ) ) m_bState = CAM_WS_READY;
setBusy( false );
break;
};
case CAM_WS_AUTOMATED_MOVE:{
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;
setBusy( true );
if( !relativeMove( m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom ) ) m_bState = CAM_WS_READY;
setBusy( false );
if( m_nRelativeMoveCounter > 10 ) {
m_bState = CAM_WS_READY;
};
break;
};
case CAM_WS_STOP_MOVE:{
m_fRM_Pan = .0f;
m_fRM_Pan = .0f;
m_fRM_Tilt = .0f;
m_fRM_Tilt = .0f;
m_fRM_Zoom = .0f;
m_fRM_Zoom = .0f;
setBusy( true );
if( relativeStop() ) m_bState = CAM_WS_READY;
setBusy( false );
break;
}
case CAM_WS_READY:{
uint32_t tSLEEP = DEFAULT_THREAD_SLEEP_TIME;
//m_mQPROTECTOR.lock();
if( m_qCAM_TASK.size() ){
#ifdef DEBUG
char tB[128];
sprintf( tB,"Queue: %d commands!", m_qCAM_TASK.size() );
LOG( tB );
#endif
CAM_TASK *tTASK = m_qCAM_TASK.front();
if ( tTASK != NULL ) {
if( tTASK->movemet_needed ){
CAM_PTZ_CMD *tCMD = tTASK->CMD;
if( tCMD ) {
switch( tCMD->CMD ) {
case PTZ_STOP:{
setBusy( true );
m_pProtocol->goStop();
setBusy( false );
break;
};
case PTZ_MOVE:{
uint32_t MoveMatrix = 0;
if( m_pProtocol->setPTZSpeed( tCMD->PAN, tCMD->TILT, tCMD->ZOOM ) ){
tSLEEP = 15;
setBusy( true );
m_pProtocol->move( MoveMatrix );
setBusy( false );
};
break;
};
case PTZ_ABSOLUTE:{
setBusy( true );
if( !m_pProtocol->goAbsolute( tCMD->PAN, tCMD->TILT, tCMD->ZOOM ) ) {
LOG_ERROR("Cannot Issue goAbsolute Command!");
tSLEEP= 100;
};
setBusy( false );
if( m_pBEH ){
EVENT_CONTAINER *tEVT = createBasicEvent(
m_sCamData.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);
};
};
break;
};
case PTZ_RELOAD_CAMERA:{
LOG("Exit Command Rcpt");
m_bThreadStatus = TH_ENDED;
};
};
free( tCMD );
tTASK->CMD = NULL;
};
};
m_qCAM_TASK.pop();
free( tTASK );
} else {
LOG_ERROR("Error Fetching TASK from Queue");
};
//m_mQPROTECTOR.unlock();
};
if( tSLEEP ) {
SLEEP( tSLEEP );
};
break;
};
case CAM_WS_END:{
LOG("Exit Command Rcpt");
m_bThreadStatus = TH_ENDED;
setBusy( true );
break;
};
};
SLEEP( DEFAULT_THREAD_SLEEP_TIME );
};
LOG("CTRL Loop End!");
};
bool ARGUS_Camera::inTheFOV( float lat, float lon, float alt ){
bool RetVal = false;
char tB[128];
if( m_pPosition == NULL ) return RetVal;
position3D * tPOS;
transform_3 * tTrans = NULL;
tPOS = new position3D();
if( tPOS == NULL ) return RetVal;
tPOS->setPositionWGS84( lat, lon, alt );
tTrans = m_pPosition->getTransform();
if(tTrans == NULL ){
delete( tPOS );
return RetVal;
};
vector_3 A, B;
C3D_SPH_DEGREES tSph;
C3D_DECART tLoc;
tLoc = tPOS->getXYZ();
A[0]= tLoc.x; A[1]= tLoc.y; A[2]= tLoc.z;
tTrans->get_vector_local(A, B);
tLoc.x = B[0]; tLoc.y = B[1]; tLoc.z = B[2];
decart2spherical( tLoc, tSph );
// sprintf( tB,"Object Dist: %0.2f ... cam range: %0.2f", tSph.r, m_fMaxRange );
// LOG( tB );
RetVal = ( tSph.r < m_fMaxRange );
if( RetVal ) {
//Checking if FOV is OK
bool pOK = false;
bool tOK = false;
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
pOK = ( tSph.fi > ( m_fMaxHFov / -2.0f ) ) && ( tSph.fi < ( m_fMaxHFov / 2.0f ) );
} else {
if( m_sCamData.pan_angles > 359 ) {
// Endless Pan
pOK = true;
} else {
// Partial Pan
switch( m_sCamData.pan_model ) {
case 1: {
// Regular Pan
float tFOV = 0.5f * ( m_fMinHFov + ( m_fMaxHFov - m_fMinHFov ) * ( tSph.r / m_fMaxRange ) ) ;
float tRad = deg2rad( tSph.fi );
// sprintf( tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad );
//LOG( tB );
pOK = ( tRad > ( -1.0 * tFOV ) ) && ( tRad < ( deg2rad( m_sCamData.pan_angles ) + tFOV ) ) ;
break;
};
case 2:{
break;
};
case 3:{
break;
};
};
};
};
if( m_sCamData.tilt_angles == 0 ) {
//Fixed Camera
tOK = ( tSph.tetta > ( m_fMaxVFov / -2.0f ) ) && ( tSph.tetta < ( m_fMaxVFov / 2.0f ) );
} else {
if( m_sCamData.tilt_angles > 89 ) {
// Endless Tilt
tOK = true;
} else {
// Partial Tilt
switch( m_sCamData.tilt_model ) {
case 1: {
// Regular Tilt
float tFOV = 0.5f * ( m_fMinVFov + ( m_fMaxVFov - m_fMinVFov ) * ( tSph.r / m_fMaxRange ) ) ;
float tRad = deg2rad( tSph.tetta );
tOK = ( tRad > ( -1.0 * tFOV ) ) && ( tRad < ( deg2rad( m_sCamData.tilt_angles ) + tFOV ) ) ;
break;
};
case 2:{
break;
};
};
};
};
//sprintf( tB, "Pan: %d Tilt: %d", pOK, tOK );
//LOG( tB );
RetVal = ( pOK && tOK );
} else {
//LOG("Object Too Far!");
}
delete( tPOS );
return RetVal;
};
bool ARGUS_Camera::lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt ){
C3D_WGS84_LOC tWGS;
C3D_SPH_DEGREES tSph;
char tB[128];
//sprintf(tB,"LookAt: %0.5f %0.5f %0.2f", lat, lon, alt );
//LOG( tB );
if( m_bBusy ){
//LOG("CAM BUSY!");
return false;
};
// Exit for fixed Cam
if( ( m_sCamData.pan_model == 0 ) && ( m_sCamData.tilt_model == 0 ) ) return makeSnap(TargetRefID);
// Exit for unpositioned Cam
if( m_pPosition == NULL ) return false;
tWGS.lat = lat;
tWGS.lon = lon;
tWGS.alt = alt;
systemAnchor* tSystem = systemAnchor::getInstance();
if( tSystem != NULL ) {
tSystem->convertToLocal( m_pPosition, tWGS, tSph );
} else {
LOG_ERROR("No SYSTEM ANCHOR!");
return false;
};
//sprintf( tB, "local coords: %0.2fm. %0.2f° %0.2f°", tSph.r, tSph.tetta, tSph.fi );
//LOG( tB );
float fZ, fT, fP;
if( m_fMaxRange > 0.0f ) {
if( tSph.r > m_fMaxRange ) {
fZ = 1;
} else {
fZ = tSph.r / m_fMaxRange;
};
} else fZ = 0.f;
switch( m_sCamData.pan_model ){
case 1:{
fP = ( 2.0 / m_sCamData.pan_angles ) * tSph.tetta - 1.0;
break;
};
case 2:{
fP = ( 2.0 / 360.0 ) * tSph.tetta - 1.0;
};
};
switch( m_sCamData.tilt_model ) {
case 1:{
fT = -2.0f * ( ( m_sCamData.tilt_angles - tSph.fi ) / m_sCamData.tilt_angles ) + 1.0;
break;
};
case 2:{
fT = ( 2.0 / m_sCamData.tilt_angles ) * ( m_sCamData.tilt_angles - tSph.fi ) - 1.0;
break;
};
};
//sprintf(tB,"EVT:%d AM: %0.2f %0.2f %0.2f", TargetRefID, fP, fT, fZ );
//LOG( tB );
return absoluteMove( TargetRefID, fP, fT, fZ );
};
bool ARGUS_Camera::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->source_evt_id = TargetRefID;
//m_mQPROTECTOR.lock();
m_qCAM_TASK.push( tTask );
//m_mQPROTECTOR.unlock();
return true;
} else {
free( tTask );
};
};
return false;
};
bool ARGUS_Camera::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 ) {
DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
if( tDATA ) {
LOG( tDATA->mrl_proto );
m_sMediaSource.mediaStreamId = id;
m_pSource = new videoAVLIBSource( &m_sMediaSource );
if( m_pSource != NULL ) {
char tMRL[1024];
#ifdef DEBUG
LOG("Source OK");
#endif
int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
if( tW > 0 ) {
//m_pSource->setProportionalByWidth( tW );
m_pSource->setSize( tW, tH );
};
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 );
//m_pSource = new videoAVLIBSource( tMRL, &m_sMediaSource );
if( m_pSource->_open( tMRL ) ) {
m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
if ( !m_bSourceConnected ) {
delete( m_pSource );
m_pSource = NULL;
}
#ifdef DEBUG
else {
LOG("Source is Connected to Output.");
}
#endif
;
} else {
LOG_ERROR("Can not Open Video Source!");
delete( m_pSource );
m_pSource = NULL;
};
} else {
LOG_ERROR("Video Source Stream Failure!");
};
free( tDATA );
};
}
#ifdef DEBUG
else LOG("No Video Module!")
#endif
;
};
return m_bSourceConnected;
};
bool ARGUS_Camera::disconnectFromStream( void ){
if( m_bSourceConnected ) {
if( m_pSource ){
delete( m_pSource );
m_pSource = NULL;
};
m_bSourceConnected = false;
};
return !m_bSourceConnected;
};
bool ARGUS_Camera::validateStream( void ){
if( m_bSourceConnected ) {
if( m_pSource ) {
if( !m_pSource->isFinished() ){
return true;
};
LOG("Source is Finished!");
} else {
LOG_ERROR("No Source Object! Set Disconnected!");
m_bSourceConnected = false;
};
};
return false;
};
#undef LOG
#undef LOG_ERROR