diff --git a/lib/App/3dGUI/main_window.cpp b/lib/App/3dGUI/main_window.cpp index 2dc115f8..5d7359fb 100644 --- a/lib/App/3dGUI/main_window.cpp +++ b/lib/App/3dGUI/main_window.cpp @@ -410,15 +410,18 @@ void mainWinow::handleSilencePress(){ basicCameraCommand *tData; absCameraMoveParam *tParam; tData = (basicCameraCommand*) malloc(sizeof(basicCameraCommand)); - tParam = (absCameraMoveParam*) malloc(sizeof(absCameraMoveParam)); - tData->m_cCode = CMD_CAMERA_SET_PTZ; - tData->m_pParam = tParam; - tParam->m_fPan = 180.f; - tParam->m_fTilt = 0.f; - tParam->m_fRange = 1.f; - //pEvt = createBasicEvent( 0, EVT_CLASS_IMAGE, EVT_ERROR, "Test Event", tData ); - pEvt = createBasicEvent( 0, EVT_CLASS_IMAGE, EVT_COMMAND, "Test Event", tData ); - basicEventHeap::getInstance()->broadcast(pEvt); + if (tData != NULL) { + tParam = (absCameraMoveParam*)malloc(sizeof(absCameraMoveParam)); + if (tParam != NULL) { + tData->m_cCode = CMD_CAMERA_SET_PTZ; + tData->m_pParam = tParam; + tParam->m_fPan = 180.f; + tParam->m_fTilt = 0.f; + tParam->m_fRange = 1.f; + pEvt = createBasicEvent(0, EVT_CLASS_IMAGE, EVT_COMMAND, "Test Event", tData); + basicEventHeap::getInstance()->broadcast(pEvt); + }; + }; }; void mainWinow::handleVideoRecorder(){ basicEvent *pEvt; diff --git a/lib/components/base/basicCamera.cpp b/lib/components/base/basicCamera.cpp index 7cb881c8..4bc3dd6a 100644 --- a/lib/components/base/basicCamera.cpp +++ b/lib/components/base/basicCamera.cpp @@ -1,236 +1,236 @@ -#include "basicCamera.h" - -// Constructor implementation -basicCamera::basicCamera(config_setting_t *Settings) : basicObject(), basicPosition(), basicEventHandler() { - m_eCaps = (objectCaps)(OC_EVENT_HANDLER); - m_pSettings = Settings; - m_iStatus = PS_BORN; - m_sCameraInfo.m_pName = NULL; - m_sCameraInfo.m_pSourcePath = NULL; - m_sCameraInfo.m_bAutoExposure = false; - m_sCameraInfo.m_bAutoFocus = false; - m_sCameraInfo.m_bAutoIris = false; - m_sCameraInfo.m_bAutoWB = false; - m_sCameraInfo.m_bDigitalZoom = false; - m_sCameraInfo.m_bExpoEna = false; - m_sCameraInfo.m_bFocusEna = false; - m_sCameraInfo.m_bIrisEna = false; - m_sCameraInfo.m_bMirrored = false; - m_sCameraInfo.m_bOpticEna = false; - m_sCameraInfo.m_bOpticZoom = false; - m_sCameraInfo.m_bShuterEna = false; - m_sCameraInfo.m_bUpsideDown = false; - m_sCameraInfo.m_bWBEna = false; - m_sCameraInfo.m_bWDR = false; - m_sCameraInfo.m_bWDREna = false; - m_sCameraInfo.m_bZoomEna = false; - m_sCameraInfo.m_bZoomSpeedDynamic = false; - m_sCameraInfo.m_fDigitalZoomMax = -1.f; - m_sCameraInfo.m_fFLCurrent = -1.f; - m_sCameraInfo.m_fFLMax = -1.f; - m_sCameraInfo.m_fFLMin = -1.f; - m_sCameraInfo.m_fFOV = -1.f; - m_sCameraInfo.m_fManualExposure = -1.f; - m_sCameraInfo.m_fManualFocus = -1.f; - m_sCameraInfo.m_fManualIris = -1.f; - m_sCameraInfo.m_fManualShutter = -1.f; - m_sCameraInfo.m_fSensorSize = ( 1.f / 2.8f ) * .0254f; // in meters - m_sCameraInfo.m_fZoomSpeedMax = -1.f; - m_sCameraInfo.m_fZoomSpeedMin = -1.f; - m_sCameraInfo.m_iHeight = -1; - m_sCameraInfo.m_iWidth = -1; - m_sCameraInfo.m_bScaledOutput = false; - m_sCameraInfo.m_iOutputWidth = -1; - m_sCameraInfo.m_iOutputHeight = -1; - m_sCameraInfo.m_iSourcePort = -1; - m_sCameraInfo.m_iSourceType = -1; - m_sCameraInfo.m_iCameraType = -1; - m_sCameraInfo.m_iZoomMax = -1; - m_sCameraInfo.m_iZoomMin = -1; - m_sCameraInfo.m_fMaxRange = -1; - m_pVideoSource = NULL; - m_pVideoNode = new videoNode(m_pSettings); -}; - -// Destructor implementation -basicCamera::~basicCamera(){ - m_vOSD.clear(); - updateSettings(); - if (m_pVideoNode != NULL){ - m_pVideoNode->setStatus(TH_EXIT); - delete(m_pVideoNode); - }; - if (m_sCameraInfo.m_pName != NULL)free(m_sCameraInfo.m_pName); - if (m_sCameraInfo.m_pSourcePath != NULL)free(m_sCameraInfo.m_pSourcePath); -}; - -bool basicCamera::create(void){ - config_setting_t *pSetting; - if (m_pSettings == NULL) return false; - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE); - if (pSetting == NULL) return false; - m_sCameraInfo.m_iCameraType = config_setting_get_int(pSetting); - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE); - if (pSetting == NULL) return false; - m_sCameraInfo.m_iSourceType = config_setting_get_int(pSetting); - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH); - if (pSetting == NULL) return false; - m_sCameraInfo.m_iWidth = config_setting_get_int(pSetting); - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT); - if (pSetting == NULL) return false; - m_sCameraInfo.m_iHeight = config_setting_get_int(pSetting); - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT); - if (pSetting == NULL) return false; - m_sCameraInfo.m_iSourcePort = config_setting_get_int(pSetting); - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME); - if (pSetting == NULL) return false; - if (m_sCameraInfo.m_pName == NULL) m_sCameraInfo.m_pName = (CSTR)malloc(255); - sprintf(m_sCameraInfo.m_pName, "%s", config_setting_get_string(pSetting)); - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH); - if (pSetting == NULL) return false; - if (m_sCameraInfo.m_pSourcePath == NULL) m_sCameraInfo.m_pSourcePath = (CSTR)malloc(255); - sprintf(m_sCameraInfo.m_pSourcePath, "%s", config_setting_get_string(pSetting)); - /*Location*/ - float tLat, tLon, tAlt, tRoll, tPitch, tYaw; - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT); - if (pSetting == NULL) return false; - tLat = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON); - if (pSetting == NULL) return false; - tLon = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT); - if (pSetting == NULL) return false; - tAlt = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL); - if (pSetting == NULL) return false; - tRoll = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH); - if (pSetting == NULL) return false; - tPitch = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW); - if (pSetting == NULL) return false; - tYaw = config_setting_get_float(pSetting); - setPositionDeg(tLat, tLon, tAlt, tPitch, tRoll, tYaw); - return true; -}; - -bool basicCamera::create(mediaSourceInfo *SI){ - config_setting_t *pSetting; - - if (m_pSettings == NULL) return false; - if (SI == NULL) return false; - - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE); - m_sCameraInfo.m_iCameraType = SI->type; - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_TYPE, CONFIG_TYPE_INT); - }; - config_setting_set_int(pSetting, m_sCameraInfo.m_iCameraType); - - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE); - m_sCameraInfo.m_iSourceType = SI->subtype; - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_TYPE, CONFIG_TYPE_INT); - }; - config_setting_set_int(pSetting, m_sCameraInfo.m_iSourceType); - - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH); - if (SI->frameIsWide){ - m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_16_9[SI->sizeId]; - } else { - m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_4_3[SI->sizeId]; - }; - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_WIDTH, CONFIG_TYPE_INT); - }; - config_setting_set_int(pSetting, m_sCameraInfo.m_iWidth); - - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT); - if (SI->frameIsWide){ - m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_16_9[SI->sizeId]; - } else { - m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_4_3[SI->sizeId]; - }; - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_HEIGHT, CONFIG_TYPE_INT); - }; - config_setting_set_int(pSetting, m_sCameraInfo.m_iWidth); - - /*Location*/ - float tLat, tLon, tAlt, tRoll, tPitch, tYaw; - - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT); - tLat = systemAnchor::getInstance()->getLat(); - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT); - }; - config_setting_set_float(pSetting, tLat ); - - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON); - tLon = systemAnchor::getInstance()->getLon(); - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT); - }; - config_setting_set_float(pSetting, tLon); - - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT); - tAlt = systemAnchor::getInstance()->getAlt(); - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT); - }; - config_setting_set_float(pSetting, tAlt); - - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH); - tPitch = 0.f; - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, TAG_POSITION_PITCH, CONFIG_TYPE_FLOAT); - }; - config_setting_set_float(pSetting, tPitch); - - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL); - tRoll = 0.f; - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, TAG_POSITION_ROLL, CONFIG_TYPE_FLOAT); - }; - config_setting_set_float(pSetting, tRoll); - - pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW); - tYaw = 0.f; - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, TAG_POSITION_YAW, CONFIG_TYPE_FLOAT); - }; - config_setting_set_float(pSetting, tYaw); - - setPositionDeg(tLat, tLon, tAlt, tPitch, tRoll, tYaw); - - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT); - m_sCameraInfo.m_iSourcePort = SI->capturePin; - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PORT, CONFIG_TYPE_INT); - }; - config_setting_set_int(pSetting, m_sCameraInfo.m_iSourcePort); - - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME); - if (m_sCameraInfo.m_pName == NULL) m_sCameraInfo.m_pName = (CSTR)malloc(255); - sprintf(m_sCameraInfo.m_pName, "%s", SI->deviceName); - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_NAME, CONFIG_TYPE_STRING); - }; - config_setting_set_string(pSetting, m_sCameraInfo.m_pName); - - pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH); - if (m_sCameraInfo.m_pSourcePath == NULL) m_sCameraInfo.m_pSourcePath = (CSTR)malloc(255); - sprintf(m_sCameraInfo.m_pSourcePath, "%s", SI->devicePath); - if (pSetting == NULL){ - pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PATH, CONFIG_TYPE_STRING); - }; - config_setting_set_string(pSetting, m_sCameraInfo.m_pSourcePath); - basicSettingsProvider::getInstance()->compromise(); - return true; -}; - -void basicCamera::updateSettings(void){ - if(!m_pSettings) return; +#include "basicCamera.h" + +// Constructor implementation +basicCamera::basicCamera(config_setting_t *Settings) : basicObject(), basicPosition(), basicEventHandler() { + m_eCaps = (objectCaps)(OC_EVENT_HANDLER); + m_pSettings = Settings; + m_iStatus = PS_BORN; + m_sCameraInfo.m_pName = NULL; + m_sCameraInfo.m_pSourcePath = NULL; + m_sCameraInfo.m_bAutoExposure = false; + m_sCameraInfo.m_bAutoFocus = false; + m_sCameraInfo.m_bAutoIris = false; + m_sCameraInfo.m_bAutoWB = false; + m_sCameraInfo.m_bDigitalZoom = false; + m_sCameraInfo.m_bExpoEna = false; + m_sCameraInfo.m_bFocusEna = false; + m_sCameraInfo.m_bIrisEna = false; + m_sCameraInfo.m_bMirrored = false; + m_sCameraInfo.m_bOpticEna = false; + m_sCameraInfo.m_bOpticZoom = false; + m_sCameraInfo.m_bShuterEna = false; + m_sCameraInfo.m_bUpsideDown = false; + m_sCameraInfo.m_bWBEna = false; + m_sCameraInfo.m_bWDR = false; + m_sCameraInfo.m_bWDREna = false; + m_sCameraInfo.m_bZoomEna = false; + m_sCameraInfo.m_bZoomSpeedDynamic = false; + m_sCameraInfo.m_fDigitalZoomMax = -1.f; + m_sCameraInfo.m_fFLCurrent = -1.f; + m_sCameraInfo.m_fFLMax = -1.f; + m_sCameraInfo.m_fFLMin = -1.f; + m_sCameraInfo.m_fFOV = -1.f; + m_sCameraInfo.m_fManualExposure = -1.f; + m_sCameraInfo.m_fManualFocus = -1.f; + m_sCameraInfo.m_fManualIris = -1.f; + m_sCameraInfo.m_fManualShutter = -1.f; + m_sCameraInfo.m_fSensorSize = ( 1.f / 2.8f ) * .0254f; // in meters + m_sCameraInfo.m_fZoomSpeedMax = -1.f; + m_sCameraInfo.m_fZoomSpeedMin = -1.f; + m_sCameraInfo.m_iHeight = -1; + m_sCameraInfo.m_iWidth = -1; + m_sCameraInfo.m_bScaledOutput = false; + m_sCameraInfo.m_iOutputWidth = -1; + m_sCameraInfo.m_iOutputHeight = -1; + m_sCameraInfo.m_iSourcePort = -1; + m_sCameraInfo.m_iSourceType = -1; + m_sCameraInfo.m_iCameraType = -1; + m_sCameraInfo.m_iZoomMax = -1; + m_sCameraInfo.m_iZoomMin = -1; + m_sCameraInfo.m_fMaxRange = -1; + m_pVideoSource = NULL; + m_pVideoNode = new videoNode(m_pSettings); +}; + +// Destructor implementation +basicCamera::~basicCamera(){ + m_vOSD.clear(); + updateSettings(); + if (m_pVideoNode != NULL){ + m_pVideoNode->setStatus(TH_EXIT); + delete(m_pVideoNode); + }; + if (m_sCameraInfo.m_pName != NULL)free(m_sCameraInfo.m_pName); + if (m_sCameraInfo.m_pSourcePath != NULL)free(m_sCameraInfo.m_pSourcePath); +}; + +bool basicCamera::create(void){ + config_setting_t *pSetting; + if (m_pSettings == NULL) return false; + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE); + if (pSetting == NULL) return false; + m_sCameraInfo.m_iCameraType = config_setting_get_int(pSetting); + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE); + if (pSetting == NULL) return false; + m_sCameraInfo.m_iSourceType = config_setting_get_int(pSetting); + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH); + if (pSetting == NULL) return false; + m_sCameraInfo.m_iWidth = config_setting_get_int(pSetting); + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT); + if (pSetting == NULL) return false; + m_sCameraInfo.m_iHeight = config_setting_get_int(pSetting); + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT); + if (pSetting == NULL) return false; + m_sCameraInfo.m_iSourcePort = config_setting_get_int(pSetting); + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME); + if (pSetting == NULL) return false; + if (m_sCameraInfo.m_pName == NULL) m_sCameraInfo.m_pName = (CSTR)malloc(255); + sprintf(m_sCameraInfo.m_pName, "%s", config_setting_get_string(pSetting)); + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH); + if (pSetting == NULL) return false; + if (m_sCameraInfo.m_pSourcePath == NULL) m_sCameraInfo.m_pSourcePath = (CSTR)malloc(255); + sprintf(m_sCameraInfo.m_pSourcePath, "%s", config_setting_get_string(pSetting)); + /*Location*/ + float tLat, tLon, tAlt, tRoll, tPitch, tYaw; + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT); + if (pSetting == NULL) return false; + tLat = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON); + if (pSetting == NULL) return false; + tLon = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT); + if (pSetting == NULL) return false; + tAlt = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL); + if (pSetting == NULL) return false; + tRoll = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH); + if (pSetting == NULL) return false; + tPitch = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW); + if (pSetting == NULL) return false; + tYaw = config_setting_get_float(pSetting); + setPositionDeg(tLat, tLon, tAlt, tPitch, tRoll, tYaw); + return true; +}; + +bool basicCamera::create(mediaSourceInfo *SI){ + config_setting_t *pSetting; + + if (m_pSettings == NULL) return false; + if (SI == NULL) return false; + + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE); + m_sCameraInfo.m_iCameraType = SI->type; + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_TYPE, CONFIG_TYPE_INT); + }; + config_setting_set_int(pSetting, m_sCameraInfo.m_iCameraType); + + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE); + m_sCameraInfo.m_iSourceType = SI->subtype; + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_TYPE, CONFIG_TYPE_INT); + }; + config_setting_set_int(pSetting, m_sCameraInfo.m_iSourceType); + + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH); + if (SI->frameIsWide){ + m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_16_9[SI->sizeId]; + } else { + m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_4_3[SI->sizeId]; + }; + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_WIDTH, CONFIG_TYPE_INT); + }; + config_setting_set_int(pSetting, m_sCameraInfo.m_iWidth); + + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT); + if (SI->frameIsWide){ + m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_16_9[SI->sizeId]; + } else { + m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_4_3[SI->sizeId]; + }; + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_HEIGHT, CONFIG_TYPE_INT); + }; + config_setting_set_int(pSetting, m_sCameraInfo.m_iWidth); + + /*Location*/ + float tLat, tLon, tAlt, tRoll, tPitch, tYaw; + + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT); + tLat = systemAnchor::getInstance()->getLat(); + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT); + }; + config_setting_set_float(pSetting, tLat ); + + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON); + tLon = systemAnchor::getInstance()->getLon(); + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT); + }; + config_setting_set_float(pSetting, tLon); + + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT); + tAlt = systemAnchor::getInstance()->getAlt(); + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT); + }; + config_setting_set_float(pSetting, tAlt); + + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH); + tPitch = 0.f; + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, TAG_POSITION_PITCH, CONFIG_TYPE_FLOAT); + }; + config_setting_set_float(pSetting, tPitch); + + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL); + tRoll = 0.f; + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, TAG_POSITION_ROLL, CONFIG_TYPE_FLOAT); + }; + config_setting_set_float(pSetting, tRoll); + + pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW); + tYaw = 0.f; + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, TAG_POSITION_YAW, CONFIG_TYPE_FLOAT); + }; + config_setting_set_float(pSetting, tYaw); + + setPositionDeg(tLat, tLon, tAlt, tPitch, tRoll, tYaw); + + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT); + m_sCameraInfo.m_iSourcePort = SI->capturePin; + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PORT, CONFIG_TYPE_INT); + }; + config_setting_set_int(pSetting, m_sCameraInfo.m_iSourcePort); + + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME); + if (m_sCameraInfo.m_pName == NULL) m_sCameraInfo.m_pName = (CSTR)malloc(255); + sprintf(m_sCameraInfo.m_pName, "%s", SI->deviceName); + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_NAME, CONFIG_TYPE_STRING); + }; + config_setting_set_string(pSetting, m_sCameraInfo.m_pName); + + pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH); + if (m_sCameraInfo.m_pSourcePath == NULL) m_sCameraInfo.m_pSourcePath = (CSTR)malloc(255); + sprintf(m_sCameraInfo.m_pSourcePath, "%s", SI->devicePath); + if (pSetting == NULL){ + pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PATH, CONFIG_TYPE_STRING); + }; + config_setting_set_string(pSetting, m_sCameraInfo.m_pSourcePath); + basicSettingsProvider::getInstance()->compromise(); + return create(); +}; + +void basicCamera::updateSettings(void){ + if(!m_pSettings) return; config_setting_t *pSetting; int tInt; double tFloat; @@ -332,44 +332,44 @@ void basicCamera::updateSettings(void){ basicSettingsProvider::getInstance()->compromise(); }; }; - if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate(); -}; - -void basicCamera::dispatchEvent( basicEvent *Evt ){ - if( Evt->m_eClass == EVT_CLASS_SENSOR ) { - switch (Evt->m_eType){ - case EVT_TARGET: - case EVT_TARGET_WHITE: - case EVT_TARGET_BLACK: - case EVT_ALARM: - CLIENT_EVENT *tData; - tData = ( CLIENT_EVENT *) Evt->m_pEvtData; - // Basic Camera Reaction - Start Record - - break; - default: - break; - }; - } else - if (Evt->m_eClass == EVT_CLASS_IMAGE){ - switch (Evt->m_eType){ - case EVT_COMMAND: - basicCameraCommand *pData; - pData = (basicCameraCommand *)Evt->m_pEvtData; - // Basic Camera Commands - switch( pData->m_cCode ){ - case CMD_CAMERA_START_RECORD: - m_pVideoNode->startRecord(); - break; - case CMD_CAMERA_STOP_RECORD: - m_pVideoNode->stopRecord(); - break; - default: - break; - }; - break; - default: - break; - }; - }; + if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate(); +}; + +void basicCamera::dispatchEvent( basicEvent *Evt ){ + if( Evt->m_eClass == EVT_CLASS_SENSOR ) { + switch (Evt->m_eType){ + case EVT_TARGET: + case EVT_TARGET_WHITE: + case EVT_TARGET_BLACK: + case EVT_ALARM: + CLIENT_EVENT *tData; + tData = ( CLIENT_EVENT *) Evt->m_pEvtData; + // Basic Camera Reaction - Start Record + + break; + default: + break; + }; + } else + if (Evt->m_eClass == EVT_CLASS_IMAGE){ + switch (Evt->m_eType){ + case EVT_COMMAND: + basicCameraCommand *pData; + pData = (basicCameraCommand *)Evt->m_pEvtData; + // Basic Camera Commands + switch( pData->m_cCode ){ + case CMD_CAMERA_START_RECORD: + m_pVideoNode->startRecord(); + break; + case CMD_CAMERA_STOP_RECORD: + m_pVideoNode->stopRecord(); + break; + default: + break; + }; + break; + default: + break; + }; + }; }; \ No newline at end of file diff --git a/lib/components/base/basicCameraPTZ.cpp b/lib/components/base/basicCameraPTZ.cpp index 32d51fc6..55db851d 100644 --- a/lib/components/base/basicCameraPTZ.cpp +++ b/lib/components/base/basicCameraPTZ.cpp @@ -1,184 +1,184 @@ -#include "basicCameraPTZ.h" - -// Constructor implementation -basicCameraPTZ::basicCameraPTZ(config_setting_t *Settings) : basicCamera(Settings){ - m_eCaps = (objectCaps)( m_eCaps | OC_EVENT_HANDLER | OC_PAN_CONTROLL | OC_TILT_CONTROLL | OC_ZOOM_CONTROLL); - m_sPTZCameraInfo.m_bPanReverse = false; - m_sPTZCameraInfo.m_bPanSpeedDynamic = false; - m_sPTZCameraInfo.m_bProtoType = PTZ_PROTO_NONE; - m_sPTZCameraInfo.m_bTiltReverse = false; - m_sPTZCameraInfo.m_bTiltSpeedDynamic = false; - m_sPTZCameraInfo.m_fPanMax = -1.f; - m_sPTZCameraInfo.m_fPanMin = -1.f; - m_sPTZCameraInfo.m_fPanSpeedMax = -1.f; - m_sPTZCameraInfo.m_fPanSpeedMin = -1.f; - m_sPTZCameraInfo.m_fPanTotalDeg = -1.f; - m_sPTZCameraInfo.m_fPanTotalRad = -1.f; - m_sPTZCameraInfo.m_fTiltMax = -1.f; - m_sPTZCameraInfo.m_fTiltMin = -1.f; - m_sPTZCameraInfo.m_fTiltSpeedMax = -1.f; - m_sPTZCameraInfo.m_fTiltSpeedMin = -1.f; - m_sPTZCameraInfo.m_fTiltTotalDeg = -1.f; - m_sPTZCameraInfo.m_fTiltTotalRad = -1.f; - m_fPanShift = 0; - m_fTiltShift = 0; - m_bCtrlStage = 0; - m_pProtocol = NULL; - m_bDirectSpeedControl = false; - m_bEventTrackingEnabled = false; - //m_qCommandPipe clear -}; - -// Destructor implementation -basicCameraPTZ::~basicCameraPTZ(){ - updateSettings(); -}; - -bool basicCameraPTZ::create(void){ - config_setting_t *pSetting; - if (m_pSettings == NULL) return false; - if (!basicCamera::create()) return false; - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PROTO_TYPE); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_bProtoType = (PTZ_CAMERA_PROTOCOL_TYPE)config_setting_get_int(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_TOTTAL); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fPanTotalDeg = config_setting_get_float(pSetting); - m_sPTZCameraInfo.m_fPanTotalRad = m_sPTZCameraInfo.m_fPanTotalDeg * 0.01745329251994329576923690768489f; - //if( m_sPTZCameraInfo.m_fPanTotalDeg < 360.f ){ - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_MIN); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fPanMin = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_MAX); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fPanMax = config_setting_get_float(pSetting); - //} else { - // m_sPTZCameraInfo.m_fPanMin = 0.f; - // m_sPTZCameraInfo.m_fPanMax = 360.f; - //}; - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_SPD_MIN); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fPanSpeedMin = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_SPD_MAX); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fPanSpeedMax = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_SPD_DYNAMIC); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_bPanSpeedDynamic = config_setting_get_bool(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_REVERSED); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_bPanReverse = config_setting_get_bool(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_TOTTAL); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltTotalDeg = config_setting_get_float(pSetting); - m_sPTZCameraInfo.m_fTiltTotalRad = m_sPTZCameraInfo.m_fPanTotalDeg * 0.01745329251994329576923690768489f; - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_MIN); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltMin = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_MAX); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltMax = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_SPD_MIN); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltSpeedMin = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_SPD_MAX); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltSpeedMax = config_setting_get_float(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_SPD_DYNAMIC); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_bTiltSpeedDynamic = config_setting_get_bool(pSetting); - pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_REVERSED); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_bTiltReverse = config_setting_get_bool(pSetting); - return basicThread::init(); -}; - -bool basicCameraPTZ::create(mediaSourceInfo *SI){ - config_setting_t *pSetting; - int tiVal; - float tfVal; - if (m_pSettings == NULL) return false; - if (SI == NULL) return false; - if (!basicCamera::create(SI)) return false; - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PROTO_TYPE, CONFIG_TYPE_INT); - if( pSetting == NULL ) return false; - tiVal = SI->protocolId; - m_sPTZCameraInfo.m_bProtoType = (PTZ_CAMERA_PROTOCOL_TYPE)tiVal; - config_setting_set_int(pSetting, tiVal); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_SPD_DYNAMIC, CONFIG_TYPE_BOOL); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_bPanSpeedDynamic = SI->bPanSpeedDynamic; - config_setting_set_int(pSetting, SI->bPanSpeedDynamic); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_TOTTAL, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - tfVal = SI->fPanTotalDeg; - m_sPTZCameraInfo.m_fPanTotalDeg = tfVal; - m_sPTZCameraInfo.m_fPanTotalRad = tfVal * 0.01745329251994329576923690768489f; - config_setting_set_float(pSetting, tfVal); - if( tfVal < 360.f ){ - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_MIN, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - tfVal = SI->fPanMin; - m_sPTZCameraInfo.m_fPanMin = tfVal; - config_setting_set_float(pSetting, tfVal); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_MAX, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - tfVal = SI->fPanMax; - m_sPTZCameraInfo.m_fPanMax = tfVal; - config_setting_set_float(pSetting, tfVal); - }; - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_SPD_MIN, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fPanSpeedMin = SI->fPanSpeedMin; - config_setting_set_float(pSetting, SI->fPanSpeedMin); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_SPD_MAX, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fPanSpeedMax = SI->fPanSpeedMax; - config_setting_set_float(pSetting, SI->fPanSpeedMax); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_REVERSED, CONFIG_TYPE_BOOL); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_bPanReverse = SI->bPanReverse; - config_setting_set_bool(pSetting, SI->bPanReverse); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_MIN, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltMin = SI->fTiltMin; - config_setting_set_float(pSetting, SI->fTiltMin); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_MAX, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltMax = SI->fTiltMax; - config_setting_set_float(pSetting, SI->fTiltMax); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_TOTTAL, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltTotalDeg = SI->fTiltTotalDeg; - m_sPTZCameraInfo.m_fTiltTotalRad = m_sPTZCameraInfo.m_fTiltTotalDeg * 0.01745329251994329576923690768489f; - config_setting_set_float(pSetting, SI->fTiltTotalDeg); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_SPD_MIN, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltSpeedMin = SI->fTiltSpeedMin; - config_setting_set_float(pSetting, SI->fTiltSpeedMin); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_SPD_MAX, CONFIG_TYPE_FLOAT); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_fTiltSpeedMax = SI->fTiltSpeedMax; - config_setting_set_float(pSetting, SI->fTiltSpeedMax); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_SPD_DYNAMIC, CONFIG_TYPE_BOOL); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_bTiltSpeedDynamic = SI->bTiltSpeedDynamic; - config_setting_set_bool(pSetting, SI->bTiltSpeedDynamic); - pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_REVERSED, CONFIG_TYPE_BOOL); - if (pSetting == NULL) return false; - m_sPTZCameraInfo.m_bTiltReverse = SI->bTiltReverse; - config_setting_set_bool(pSetting, SI->bTiltReverse); - basicSettingsProvider::getInstance()->compromise(); - return true; -}; - -void basicCameraPTZ::dispatchEvent( basicEvent *Evt ){ - basicCamera::dispatchEvent( Evt ); -}; - -void basicCameraPTZ::updateSettings(void){ - if (!m_pSettings) return; - basicCamera::updateSettings(); +#include "basicCameraPTZ.h" + +// Constructor implementation +basicCameraPTZ::basicCameraPTZ(config_setting_t *Settings) : basicCamera(Settings){ + m_eCaps = (objectCaps)( m_eCaps | OC_EVENT_HANDLER | OC_PAN_CONTROLL | OC_TILT_CONTROLL | OC_ZOOM_CONTROLL); + m_sPTZCameraInfo.m_bPanReverse = false; + m_sPTZCameraInfo.m_bPanSpeedDynamic = false; + m_sPTZCameraInfo.m_bProtoType = PTZ_PROTO_NONE; + m_sPTZCameraInfo.m_bTiltReverse = false; + m_sPTZCameraInfo.m_bTiltSpeedDynamic = false; + m_sPTZCameraInfo.m_fPanMax = -1.f; + m_sPTZCameraInfo.m_fPanMin = -1.f; + m_sPTZCameraInfo.m_fPanSpeedMax = -1.f; + m_sPTZCameraInfo.m_fPanSpeedMin = -1.f; + m_sPTZCameraInfo.m_fPanTotalDeg = -1.f; + m_sPTZCameraInfo.m_fPanTotalRad = -1.f; + m_sPTZCameraInfo.m_fTiltMax = -1.f; + m_sPTZCameraInfo.m_fTiltMin = -1.f; + m_sPTZCameraInfo.m_fTiltSpeedMax = -1.f; + m_sPTZCameraInfo.m_fTiltSpeedMin = -1.f; + m_sPTZCameraInfo.m_fTiltTotalDeg = -1.f; + m_sPTZCameraInfo.m_fTiltTotalRad = -1.f; + m_fPanShift = 0; + m_fTiltShift = 0; + m_bCtrlStage = 0; + m_pProtocol = NULL; + m_bDirectSpeedControl = false; + m_bEventTrackingEnabled = false; + //m_qCommandPipe clear +}; + +// Destructor implementation +basicCameraPTZ::~basicCameraPTZ(){ + updateSettings(); +}; + +bool basicCameraPTZ::create(void){ + config_setting_t *pSetting; + if (m_pSettings == NULL) return false; + if (!basicCamera::create()) return false; + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PROTO_TYPE); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_bProtoType = (PTZ_CAMERA_PROTOCOL_TYPE)config_setting_get_int(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_TOTTAL); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fPanTotalDeg = config_setting_get_float(pSetting); + m_sPTZCameraInfo.m_fPanTotalRad = m_sPTZCameraInfo.m_fPanTotalDeg * 0.01745329251994329576923690768489f; + //if( m_sPTZCameraInfo.m_fPanTotalDeg < 360.f ){ + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_MIN); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fPanMin = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_MAX); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fPanMax = config_setting_get_float(pSetting); + //} else { + // m_sPTZCameraInfo.m_fPanMin = 0.f; + // m_sPTZCameraInfo.m_fPanMax = 360.f; + //}; + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_SPD_MIN); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fPanSpeedMin = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_SPD_MAX); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fPanSpeedMax = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_SPD_DYNAMIC); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_bPanSpeedDynamic = config_setting_get_bool(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_REVERSED); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_bPanReverse = config_setting_get_bool(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_TOTTAL); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltTotalDeg = config_setting_get_float(pSetting); + m_sPTZCameraInfo.m_fTiltTotalRad = m_sPTZCameraInfo.m_fPanTotalDeg * 0.01745329251994329576923690768489f; + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_MIN); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltMin = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_MAX); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltMax = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_SPD_MIN); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltSpeedMin = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_SPD_MAX); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltSpeedMax = config_setting_get_float(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_SPD_DYNAMIC); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_bTiltSpeedDynamic = config_setting_get_bool(pSetting); + pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_REVERSED); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_bTiltReverse = config_setting_get_bool(pSetting); + return basicThread::init(); +}; + +bool basicCameraPTZ::create(mediaSourceInfo *SI){ + config_setting_t *pSetting; + int tiVal; + float tfVal; + if (m_pSettings == NULL) return false; + if (SI == NULL) return false; + if (!basicCamera::create(SI)) return false; + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PROTO_TYPE, CONFIG_TYPE_INT); + if( pSetting == NULL ) return false; + tiVal = SI->protocolId; + m_sPTZCameraInfo.m_bProtoType = (PTZ_CAMERA_PROTOCOL_TYPE)tiVal; + config_setting_set_int(pSetting, tiVal); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_SPD_DYNAMIC, CONFIG_TYPE_BOOL); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_bPanSpeedDynamic = SI->bPanSpeedDynamic; + config_setting_set_int(pSetting, SI->bPanSpeedDynamic); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_TOTTAL, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + tfVal = SI->fPanTotalDeg; + m_sPTZCameraInfo.m_fPanTotalDeg = tfVal; + m_sPTZCameraInfo.m_fPanTotalRad = tfVal * 0.01745329251994329576923690768489f; + config_setting_set_float(pSetting, tfVal); + if( tfVal < 360.f ){ + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_MIN, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + tfVal = SI->fPanMin; + m_sPTZCameraInfo.m_fPanMin = tfVal; + config_setting_set_float(pSetting, tfVal); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_MAX, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + tfVal = SI->fPanMax; + m_sPTZCameraInfo.m_fPanMax = tfVal; + config_setting_set_float(pSetting, tfVal); + }; + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_SPD_MIN, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fPanSpeedMin = SI->fPanSpeedMin; + config_setting_set_float(pSetting, SI->fPanSpeedMin); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_SPD_MAX, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fPanSpeedMax = SI->fPanSpeedMax; + config_setting_set_float(pSetting, SI->fPanSpeedMax); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_REVERSED, CONFIG_TYPE_BOOL); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_bPanReverse = SI->bPanReverse; + config_setting_set_bool(pSetting, SI->bPanReverse); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_MIN, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltMin = SI->fTiltMin; + config_setting_set_float(pSetting, SI->fTiltMin); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_MAX, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltMax = SI->fTiltMax; + config_setting_set_float(pSetting, SI->fTiltMax); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_TOTTAL, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltTotalDeg = SI->fTiltTotalDeg; + m_sPTZCameraInfo.m_fTiltTotalRad = m_sPTZCameraInfo.m_fTiltTotalDeg * 0.01745329251994329576923690768489f; + config_setting_set_float(pSetting, SI->fTiltTotalDeg); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_SPD_MIN, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltSpeedMin = SI->fTiltSpeedMin; + config_setting_set_float(pSetting, SI->fTiltSpeedMin); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_SPD_MAX, CONFIG_TYPE_FLOAT); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_fTiltSpeedMax = SI->fTiltSpeedMax; + config_setting_set_float(pSetting, SI->fTiltSpeedMax); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_SPD_DYNAMIC, CONFIG_TYPE_BOOL); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_bTiltSpeedDynamic = SI->bTiltSpeedDynamic; + config_setting_set_bool(pSetting, SI->bTiltSpeedDynamic); + pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_REVERSED, CONFIG_TYPE_BOOL); + if (pSetting == NULL) return false; + m_sPTZCameraInfo.m_bTiltReverse = SI->bTiltReverse; + config_setting_set_bool(pSetting, SI->bTiltReverse); + basicSettingsProvider::getInstance()->compromise(); + return create(); +}; + +void basicCameraPTZ::dispatchEvent( basicEvent *Evt ){ + basicCamera::dispatchEvent( Evt ); +}; + +void basicCameraPTZ::updateSettings(void){ + if (!m_pSettings) return; + basicCamera::updateSettings(); config_setting_t *pSetting; int tInt; double tFloat; @@ -246,6 +246,6 @@ void basicCameraPTZ::updateSettings(void){ basicSettingsProvider::getInstance()->compromise(); }; }; - if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate(); - */ + if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate(); + */ }; \ No newline at end of file diff --git a/lib/components/base/basicCameraPTZ.h b/lib/components/base/basicCameraPTZ.h index f3aede83..735cc8c1 100644 --- a/lib/components/base/basicCameraPTZ.h +++ b/lib/components/base/basicCameraPTZ.h @@ -71,6 +71,7 @@ float m_fZoomSpeed; float m_fPanShift; float m_fTiltShift; + virtual void m_fThreadProc(void){}; public: // Constructor explicit basicCameraPTZ(config_setting_t *Settings = NULL); diff --git a/lib/components/base/basicEvent.h b/lib/components/base/basicEvent.h index 511dd5bf..f3f4a62a 100644 --- a/lib/components/base/basicEvent.h +++ b/lib/components/base/basicEvent.h @@ -35,6 +35,9 @@ typedef enum E_basicEventTypeID { EVT_TARGET = 10, EVT_TARGET_WHITE = 11, EVT_TARGET_BLACK = 12, + EVT_CAPTURE_START = 13, + EVT_CAPTURE_END = 14, + EVT_CAPTURE_DONE = 15, EVT_ERROR = 255 } basicEventTypeID; @@ -54,7 +57,7 @@ typedef struct S_basicEvent{ char *m_pHumanReadableMsg; void *m_pEvtData; } basicEvent; - +/* typedef struct S_alarmDataEvent{ uint32_t mRange; uint32_t mSampleID; @@ -64,6 +67,11 @@ typedef struct S_alarmDataEvent{ uint32_t mWidth; uint32_t mInfo; } alarmDataEvent; +*/ + +typedef struct S_TARGET_DATA { + float POPOS;sss +}TARGET_DATA; typedef struct S_CLIENT_EVENT{ uint8_t type; //basicEventTypeID diff --git a/lib/components/object/objectCameraPTZ.cpp b/lib/components/object/objectCameraPTZ.cpp index 00b2d9f5..2dd92f12 100644 --- a/lib/components/object/objectCameraPTZ.cpp +++ b/lib/components/object/objectCameraPTZ.cpp @@ -247,6 +247,7 @@ bool objectCameraPTZ::create(mediaSourceInfo *SI){ if (pPSettings == NULL) return false; switch (m_sPTZCameraInfo.m_bProtoType){ case PTZ_PROTO_PELCO: + // Set PelcoD+ Tag case PTZ_PROTO_VISCA: pSetting = config_setting_add(pPSettings, PPTZ_TAG_COM_PORT, CONFIG_TYPE_INT); if (pSetting == NULL) return false; @@ -271,7 +272,7 @@ bool objectCameraPTZ::create(mediaSourceInfo *SI){ break; case PTZ_PROTO_NONE: default: - //LOG_ERROR("UNKNOWN PTZ Protocol!"); + LOG_ERROR("UNKNOWN PTZ Protocol!"); return false; }; }; @@ -304,20 +305,28 @@ void objectCameraPTZ::dispatchEvent( basicEvent *Evt ){ CLIENT_EVENT *tData; tData = ( CLIENT_EVENT *) Evt->m_pEvtData; if( tData!= NULL ){ - //int sX, sY, eX, eY; int cX, cY; - float mAzimuth; // In Degreeses - float mElevation; // In Degreeses - float mRange; // In Meters - mRange = tData->range / 4095.f; - //makeCd_s( tData->mStartID, sX, sY, ( tData->mInfo & 0xFF000000 ) > 0 ); - //makeCd_s( tData->mEndID, eX, eY, ( tData->mInfo & 0xFF000000 ) > 0 ); - //cX = ((sX+eX)>>1); - //cY = ((sY+eY)>>1); + C3D_SPH_DEGREES tSph; + C3D_DECART tLoc; makeCd_s( tData->th_id, cX, cY, true ); - mAzimuth = (360.0 / TH_LINE_NODES )*cX; - mElevation = 90.0 - (90.0/Q_SCAN_COUNT )*cY; - cmdGoAbsolutePTZ( mAzimuth, mElevation, mRange ); + tSph.fi = (360.0 / TH_LINE_NODES) * cX; + tSph.tetta = 90.0 - (90.0 / Q_SCAN_COUNT) * cY; + tSph.r = tData->range / 4095.f; + transform_3 *tm; + tm = getTransform(); + if (tm != NULL) { + spherical2decart(tSph, tLoc); + vector_3 A, B; + A[0] = tLoc.x; + A[1] = tLoc.y; + A[2] = tLoc.z; + tm->get_vector_local(A, B); + tLoc.x = B[0]; + tLoc.y = B[1]; + tLoc.z = B[2]; + decart2spherical(tLoc, tSph); + cmdGoAbsolutePTZ(tSph.fi, tSph.tetta, tSph.r); + } else LOG_ERROR("Cannot get Transform Matrix!"); }; //break; case EVT_ALARM: @@ -336,23 +345,24 @@ void objectCameraPTZ::dispatchEvent( basicEvent *Evt ){ // Basic Camera Commands switch( pData->m_cCode ){ case CMD_CAMERA_INIT: - //m_pProtocol->init(); + m_pProtocol->init(); break; case CMD_CAMERA_SET_PTZ: - C3D_DECART *tParam; - tParam = (C3D_DECART *)pData->m_pParam; + absCameraMoveParam *tParam; + tParam = (absCameraMoveParam*)pData->m_pParam; if( tParam!= NULL ){ C3D_SPH_DEGREES tSph; C3D_DECART tLoc; - //S_TRANS_MATRIX *tm; - transform_3 *tm; - //tm = getTransMatrix(); + transform_3 *tm; + tSph.fi = tParam->m_fPan; + tSph.tetta = tParam->m_fTilt; + tSph.r = tParam->m_fRange; + spherical2decart(tSph, tLoc); tm = getTransform(); - //translate2local( *tm, *tParam, tLoc ); vector_3 A, B; - A[0] = tParam->x; - A[1] = tParam->y; - A[2] = tParam->z; + A[0] = tLoc.x; + A[1] = tLoc.y; + A[2] = tLoc.z; tm->get_vector_local(A, B); tLoc.x = B[0]; tLoc.y = B[1]; @@ -644,6 +654,7 @@ void objectCameraPTZ::m_fThreadProc(void){ break; case PTZ_PROTO_PELCO:{ m_pProtocol->setPanPos(tParam->m_fPan); + // Create Queue of farther commands nCMD = (basicCameraCommand*) malloc(sizeof(basicCameraCommand)); if( nCMD != NULL ){ nCMD->m_pParam = malloc( sizeof(absCameraMoveParam)); diff --git a/lib/components/object/objectLGS.cpp b/lib/components/object/objectLGS.cpp index 5f3a05d8..43392e06 100644 --- a/lib/components/object/objectLGS.cpp +++ b/lib/components/object/objectLGS.cpp @@ -832,45 +832,59 @@ bool objectLGS::packetHandler(protocolPackage* Package) { tEVT = (CLIENT_EVENT*)& pReceivedPackage[DATA_BEGIN_IDX + 1]; for (uint8_t xindex = 0; xindex < tCount; xindex++) { switch (tEVT[xindex].type) { - case EVT_TARGET_BLACK: - case EVT_TARGET_WHITE: { - char tBuffer[256]; - float fRange, fAzimuth, fElevation; - uint16_t cX, cY; - bool lMaster; - uint8_t kid; - kid = tEVT[xindex].k_id & 0x07; - lMaster = ((tEVT[xindex].k_id & 0x08) == 0x08); - fRange = 300.0 / 4095.0 * tEVT[xindex].range; - //makeCds( tData->mStartID, sX, sY, m_bIsMaster ); - //makeCds( tData->mEndID, eX, eY, m_bIsMaster ); - //cX = ((sX+eX)>>1); - //cY = ((sY+eY)>>1); - makeXY(tEVT[xindex].th_id, cX, cY, m_bIsMaster); - fAzimuth = 360.0 - (360.0 / TH_LINE_NODES) * cX; - fElevation = 90.0 - (Q_DEGREE_FOV / Q_SCAN_COUNT) * cY + Q_SHIFT_DOWN_FOV; + case EVT_TARGET_BLACK: + case EVT_TARGET_WHITE: { + char tBuffer[256]; + C3D_SPH_DEGREES tSph; + C3D_DECART tDec; + //float fRange, fAzimuth, fElevation; + uint16_t cX, cY; + bool lMaster; + uint8_t kid; + //systemAnchor *tSystem = systemAnchor::getInstance(); + transform_3 *tm = m_pPosition->getTransform(); - sprintf(tBuffer, "%s[%d] %s target \tRange: %.2fm. \tAzimuth: %.2f \tElevation: %.2f \tTS: %d@%d W:%d", - (lMaster ? "M" : "S"), - kid, - ((tEVT[xindex].type == EVT_TARGET_WHITE) ? "White" : "Black"), - fRange, - fAzimuth, - fElevation, - tEVT[xindex].uts, - tEVT[xindex].ums, - tEVT[xindex].w_cnt * tEVT[xindex].range - ); - basicEvent* bEVT = NULL; - CLIENT_EVENT* tData = NULL; - tData = (CLIENT_EVENT*)malloc(sizeof(CLIENT_EVENT)); - if (tData != NULL) { - memcpy(tData, &tEVT[xindex], sizeof(CLIENT_EVENT)); - bEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, (basicEventTypeID)tEVT[xindex].type, tBuffer, tData); - if (bEVT != NULL) m_pEventHeap->broadcast(bEVT); + kid = tEVT[xindex].k_id & 0x07; + lMaster = ((tEVT[xindex].k_id & 0x08) == 0x08); + makeXY(tEVT[xindex].th_id, cX, cY, m_bIsMaster); + tSph.r = 300.0 / 4095.0 * tEVT[xindex].range; + tSph.fi = 360.0 - (360.0 / TH_LINE_NODES) * cX; + tSph.tetta = 90.0 - (Q_DEGREE_FOV / Q_SCAN_COUNT) * cY + Q_SHIFT_DOWN_FOV; + + spherical2decart(tSph, tDec); + vector_3 A, B; + A[0] = tDec.x; + A[1] = tDec.y; + A[2] = tDec.z; + tm->get_vector_world(A, B); + //tSystem->getX(); + tDec.x = B[0]; + tDec.y = B[1]; + tDec.z = B[2]; + decart2spherical(tDec, tSph); + + sprintf(tBuffer, "%s[%d] %s target \tRange: %.2fm. \tAzimuth: %.2f \tElevation: %.2f \tTS: %d@%d W:%d", + (lMaster ? "M" : "S"), + kid, + ((tEVT[xindex].type == EVT_TARGET_WHITE) ? "White" : "Black"), + tSph.r, + tSph.fi, + tSph.tetta, + tEVT[xindex].uts, + tEVT[xindex].ums, + tEVT[xindex].w_cnt * tEVT[xindex].range + ); + basicEvent* bEVT = NULL; + CLIENT_EVENT* tData = NULL; + tData = (CLIENT_EVENT*)malloc(sizeof(CLIENT_EVENT)); + if (tData != NULL) { + //memcpy(tData, &tEVT[xindex], sizeof(CLIENT_EVENT)); + tData-> + bEVT = createBasicEvent(getID(), EVT_CLASS_SENSOR, (basicEventTypeID)tEVT[xindex].type, tBuffer, tData); + if (bEVT != NULL) m_pEventHeap->broadcast(bEVT); + }; }; }; - }; }; //set new stage2 m_nIdleTarget = m_nIdleTarget >> 1; diff --git a/lib/data/protocol/protocolPTZ_ONVIF.cpp b/lib/data/protocol/protocolPTZ_ONVIF.cpp index fa1fa51a..b0229d18 100644 --- a/lib/data/protocol/protocolPTZ_ONVIF.cpp +++ b/lib/data/protocol/protocolPTZ_ONVIF.cpp @@ -15,13 +15,13 @@ bool protocolPTZ_ONVIF::create( void ){ config_setting_t *pSetting; if (!protocolPTZ::create()) return false; m_bStatus = 0; - pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER); - if (pSetting == NULL) return false; - sprintf(m_pUser, "%s", config_setting_get_string(pSetting)); - pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_PASS); - if (pSetting == NULL) return false; - sprintf(m_pPassword, "%s", config_setting_get_string(pSetting)); - pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_DEV_URI); + pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER); + if (pSetting == NULL) return false; + sprintf(m_pUser, "%s", config_setting_get_string(pSetting)); + pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_PASS); + if (pSetting == NULL) return false; + sprintf(m_pPassword, "%s", config_setting_get_string(pSetting)); + pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_DEV_URI); if (pSetting == NULL) return false; sprintf(m_pDeviceURI, "%s", config_setting_get_string(pSetting)); std::string A(m_pUser); @@ -35,8 +35,8 @@ bool protocolPTZ_ONVIF::create( void ){ int RetVal; RetVal = m_pPTZ->GetNodes(tNodes); if (RetVal == 0){ - OnvifClientMedia media(*m_pDevice); - _trt__GetProfilesResponse profiles; + OnvifClientMedia media(*m_pDevice); + _trt__GetProfilesResponse profiles; media.GetProfiles(profiles); m_pPTZToken = profiles.Profiles.at(0)->token;// PTZConfiguration->token; //m_pPTZToken = tNodes.PTZNode.at(0)->token; diff --git a/lib/data/protocol/protocolPTZ_PELCO.cpp b/lib/data/protocol/protocolPTZ_PELCO.cpp index d1657a8f..830b841a 100644 --- a/lib/data/protocol/protocolPTZ_PELCO.cpp +++ b/lib/data/protocol/protocolPTZ_PELCO.cpp @@ -7,6 +7,7 @@ protocolPTZ_PELCO::protocolPTZ_PELCO(config_setting_t *Settings) :protocolPTZ(Settings), m_mInquiryMutex(){ m_pDataTransport = NULL; m_bReplyRequired = false; + m_bDPlusEna = false; m_bCAM_ID = 2; m_bLastCommandIssued = CMD_PTZ_NOOP; }; @@ -24,7 +25,7 @@ U8 protocolPTZ_PELCO::finishUpPackage(U8 *pBuffer){ return 7; }; -int protocolPTZ_PELCO::packetChecker( unsigned char *Buffer, size_t BufferSize ){ +int protocolPTZ_PELCO::packetChecker(U8* Buffer, size_t BufferSize) { if( Buffer[0] == 0xFF ) { if( BufferSize > 1 ){ if( Buffer[1] == 0x00 || Buffer[1] == m_bCAM_ID ) { @@ -124,6 +125,11 @@ bool protocolPTZ_PELCO::create( void ){ pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_CAM_ID); if (pSetting == NULL) return false; m_bCAM_ID = (U8)config_setting_get_int(pSetting); + pSetting = config_setting_get_member(m_pSettings, PELCO_D_PLUS_ENABLE); + if (pSetting != NULL) { + m_bDPlusEna = (bool)config_setting_get_bool(pSetting); + }; + char tBuf[16]; #ifdef __linux__ sprintf( tBuf,"/dev/ttyS%d",tPort); @@ -133,6 +139,7 @@ bool protocolPTZ_PELCO::create( void ){ m_pDataTransport = new serialPort(tBuf,tSpeed); if (m_pDataTransport != NULL){ if (m_pDataTransport->addRecipient(this)){ + setConnectionStatus(CS_CONNECTED); m_bStatus = 1; return true; }; @@ -364,6 +371,40 @@ bool protocolPTZ_PELCO::move(uint32_t MoveMatrix){ return m_pDataTransport->sendData(Buffer, finishUpPackage(Buffer)); }; +bool protocolPTZ_PELCO::goAbsolute(double dPan, double dTilt, double dZoom) { + U8 Buffer[16]; + U8 Param1, Param2; + if (m_bStatus == 0) return false; +// if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false; + if (m_bDPlusEna) { + Buffer[0] = 0x80 + m_bCAM_ID; + Buffer[1] = 0x01; + Buffer[2] = 0x06; + Buffer[3] = 0x02; + Buffer[4] = 0x18;//Max Pan Speed + Buffer[5] = 0x14;//Max Tilt Speed + uint16_t pPos, tPos; + //-880 .. 880 + pPos = (uint16_t)(880.0 * dPan); + Buffer[6] = 0x0F & (pPos >> 12); + Buffer[7] = 0x0F & (pPos >> 8); + Buffer[8] = 0x0F & (pPos >> 4); + Buffer[9] = 0x0F & pPos; + //-300 .. 300 + tPos = (uint16_t)(300.0 * dTilt); + Buffer[10] = 0x0F & (tPos >> 12); + Buffer[11] = 0x0F & (tPos >> 8); + Buffer[12] = 0x0F & (tPos >> 4); + Buffer[13] = 0x0F & tPos; + Buffer[14] = 0xFF; + LOG("ABS move"); + return m_pDataTransport->sendData(Buffer, 15); + } else { + LOG("ABS move"); + return true; + }; +}; + bool protocolPTZ_PELCO::setAutoFocus(bool nMode){ m_bAutoFocus_Mode = nMode; U8 Buffer[8]; diff --git a/lib/data/protocol/protocolPTZ_PELCO.h b/lib/data/protocol/protocolPTZ_PELCO.h index 0894fc9d..21c396a3 100644 --- a/lib/data/protocol/protocolPTZ_PELCO.h +++ b/lib/data/protocol/protocolPTZ_PELCO.h @@ -13,10 +13,12 @@ #define RESP_ACK 0x01 #define RESP_NAK 0x00 +#define PELCO_D_PLUS_ENABLE "PELCO_D_PLUS" class protocolPTZ_PELCO: public protocolPTZ{ private: U8 m_bCAM_ID; + bool m_bDPlusEna; basicMutex m_mInquiryMutex; U8 finishUpPackage(U8 *pBuffer); protected: @@ -46,6 +48,7 @@ class protocolPTZ_PELCO: public protocolPTZ{ virtual bool resetPTZDrive( void ); virtual bool goHomePosition( void ); virtual bool move(uint32_t MoveMatrix); + virtual bool goAbsolute(double dPan, double dTilt, double dZoom); virtual bool setOSD( bool nMode ); };