|
|
|
@ -53,12 +53,14 @@ mekorotKernel::mekorotKernel(config_setting_t* ptr) : basicEngine(), basicThread |
|
|
|
|
|
|
|
m_fCamTargetPan = m_fCamTargetTilt = m_fCamTargetZoom = |
|
|
|
m_fHomePan = m_fHomeTilt = m_fHomeZoom = |
|
|
|
m_fLeftZeroPan = m_fRightZeroPan = m_fHorizontalZeroPan = 0.f; |
|
|
|
m_fLeftZeroPan = m_fRightZeroPan = m_fHorizontalZeroTilt = 0.f; |
|
|
|
m_pZoomTable[0] = 0; |
|
|
|
m_nLeftZeroShift = m_nCenterZeroShift = m_nRightZeroShift = 0; |
|
|
|
m_bBringToHome = m_bUsePTZ = m_bRecordIsSaving = m_bRecordIsActive = false; |
|
|
|
m_nCLoopMask = 0xFFFFFFFF; |
|
|
|
m_nCLoopCheck = 0; |
|
|
|
m_bRestartEna = false; |
|
|
|
m_nRestartTimer = 15000; // 15 sec
|
|
|
|
}; |
|
|
|
|
|
|
|
mekorotKernel::~mekorotKernel() { |
|
|
|
@ -83,6 +85,32 @@ bool mekorotKernel::init(void){ |
|
|
|
}; |
|
|
|
config_setting_set_string(pSetting, m_pSerialDevice); |
|
|
|
}; |
|
|
|
pSetting = config_setting_get_member(m_pSettings, KNL_SETTINGS_RESTART_ENA_FLAG); |
|
|
|
if (pSetting != NULL) { |
|
|
|
m_bRestartEna = config_setting_get_bool(pSetting); |
|
|
|
} else { |
|
|
|
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_RESTART_ENA_FLAG, CONFIG_TYPE_BOOL); |
|
|
|
basicSettingsProvider::getInstance()->compromise(); |
|
|
|
if (pSetting == NULL) { |
|
|
|
LOG_ERROR("Failure while adding setting!"); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
config_setting_set_bool(pSetting, m_bRestartEna); |
|
|
|
}; |
|
|
|
if (m_bRestartEna) { |
|
|
|
pSetting = config_setting_get_member(m_pSettings, KNL_SETTINGS_RESTART_TIMER); |
|
|
|
if (pSetting != NULL) { |
|
|
|
m_nRestartTimer = config_setting_get_int(pSetting); |
|
|
|
} else { |
|
|
|
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_RESTART_TIMER, CONFIG_TYPE_INT); |
|
|
|
basicSettingsProvider::getInstance()->compromise(); |
|
|
|
if (pSetting == NULL) { |
|
|
|
LOG_ERROR("Failure while adding setting!"); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
config_setting_set_int(pSetting, m_nRestartTimer); |
|
|
|
}; |
|
|
|
}; |
|
|
|
pSetting = config_setting_get_member(m_pSettings, MEKOROT_KRNL_SERIAL_SPEED_TAG); |
|
|
|
if (pSetting != NULL) { |
|
|
|
m_nSerialSpeed = config_setting_get_int(pSetting); |
|
|
|
@ -228,19 +256,32 @@ bool mekorotKernel::init(void){ |
|
|
|
|
|
|
|
pSetting = basicSettingsProvider::getInstance()->getSubNode(m_pSettings, (CSTR)KNL_SETTINGS_ZOOM_TABLE_SECTION); |
|
|
|
if (pSetting != NULL) { |
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Zoom Table Defined"); |
|
|
|
#endif
|
|
|
|
m_nZoomTableCount = config_setting_length(pSetting); |
|
|
|
if( m_nZoomTableCount ){ |
|
|
|
config_setting_t* tRec; |
|
|
|
config_setting_t* ttRec; |
|
|
|
for (int index = 0; index < m_nZoomTableCount; index++) { |
|
|
|
for (int index = 0; (index < m_nZoomTableCount) && (index < MAX_ZOOM_TABLE_COUNT); index++) { |
|
|
|
tRec = config_setting_get_elem(pSetting, index); |
|
|
|
if (tRec != NULL) { |
|
|
|
double tVal; |
|
|
|
if (!config_setting_lookup_float(tRec, KNL_SETTINGS_VIDEO_INPUT_FPS, &tVal)) tVal = 0; |
|
|
|
m_pZoomTable[index] = tVal; |
|
|
|
m_pZoomTable[index] = config_setting_get_float(tRec); |
|
|
|
#ifdef DEBUG
|
|
|
|
char tBuff[64]; |
|
|
|
sprintf(tBuff, "Value[%d]=%0.2f", index, m_pZoomTable[index]); |
|
|
|
LOG(tBuff); |
|
|
|
#endif
|
|
|
|
}; |
|
|
|
}; |
|
|
|
} else { |
|
|
|
// Set Default Zoom to 0
|
|
|
|
m_nZoomTableCount = 1; |
|
|
|
m_pZoomTable[0] = 0.f; |
|
|
|
}; |
|
|
|
} else { |
|
|
|
// Set Default Zoom to 0
|
|
|
|
m_nZoomTableCount = 1; |
|
|
|
m_pZoomTable[0] = 0.f; |
|
|
|
}; |
|
|
|
|
|
|
|
if (m_bHorizontal) { |
|
|
|
@ -313,17 +354,17 @@ bool mekorotKernel::init(void){ |
|
|
|
}; |
|
|
|
config_setting_set_float(pSetting, m_fRightZeroPan); |
|
|
|
}; |
|
|
|
pSetting = config_setting_get_member(m_pSettings, MEKOROT_KRNL_DEVICE_HORIZONT_PAN_TAG); |
|
|
|
pSetting = config_setting_get_member(m_pSettings, MEKOROT_KRNL_DEVICE_HORIZONT_TILT_TAG); |
|
|
|
if (pSetting != NULL) { |
|
|
|
m_fHorizontalZeroPan = config_setting_get_float(pSetting); |
|
|
|
m_fHorizontalZeroTilt = config_setting_get_float(pSetting); |
|
|
|
} else { |
|
|
|
pSetting = config_setting_add(m_pSettings, MEKOROT_KRNL_DEVICE_HORIZONT_PAN_TAG, CONFIG_TYPE_FLOAT); |
|
|
|
pSetting = config_setting_add(m_pSettings, MEKOROT_KRNL_DEVICE_HORIZONT_TILT_TAG, CONFIG_TYPE_FLOAT); |
|
|
|
basicSettingsProvider::getInstance()->compromise(); |
|
|
|
if (pSetting == NULL) { |
|
|
|
LOG_ERROR("Failure while adding setting!"); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
config_setting_set_float(pSetting, m_fHorizontalZeroPan); |
|
|
|
config_setting_set_float(pSetting, m_fHorizontalZeroTilt); |
|
|
|
}; |
|
|
|
pSetting = config_setting_get_member(m_pSettings, MEKOROT_KRNL_DEVICE_HOME_PAN_TAG); |
|
|
|
if (pSetting != NULL) { |
|
|
|
@ -456,10 +497,37 @@ bool mekorotKernel::keyboard_proc(void) { |
|
|
|
}; |
|
|
|
return true; |
|
|
|
}; |
|
|
|
|
|
|
|
void mekorotKernel::m_fThreadProc(void){ |
|
|
|
unsigned long long sTS; |
|
|
|
#ifdef DEBUG
|
|
|
|
unsigned long long dTS; |
|
|
|
dTS = getMilliseconds(); |
|
|
|
#endif
|
|
|
|
sTS = getMilliseconds() + m_nRestartTimer; |
|
|
|
m_bThreadStatus = TH_WORKING; |
|
|
|
while (m_bThreadStatus < TH_ENDED) { |
|
|
|
if (!keyboard_proc()) continue; |
|
|
|
//CHeck Times
|
|
|
|
unsigned long long cTS; |
|
|
|
cTS = getMilliseconds(); |
|
|
|
#ifdef DEBUG
|
|
|
|
// Each 5 sec print statuses
|
|
|
|
if ((cTS - dTS ) > 5000) { |
|
|
|
char tBuff[64]; |
|
|
|
//sprintf(tBuff, "Stage: %d OP: %d", m_bStage, m_nOperation );
|
|
|
|
//LOG(tBuff);
|
|
|
|
dTS = cTS; |
|
|
|
}; |
|
|
|
#endif
|
|
|
|
// Restarting if enabled
|
|
|
|
if (m_bRestartEna) { |
|
|
|
if (cTS > sTS) { |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
continue; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
switch( m_bStage ) { |
|
|
|
case MEKOROT_KRNL_STG_CONNECT:{ |
|
|
|
if (m_pSerial == NULL) { |
|
|
|
@ -618,8 +686,7 @@ void mekorotKernel::m_fThreadProc(void){ |
|
|
|
}; |
|
|
|
}; |
|
|
|
} else { |
|
|
|
unsigned long long cTS; |
|
|
|
cTS = getMilliseconds(); |
|
|
|
//TO checkub
|
|
|
|
}; |
|
|
|
SLEEP(KERNEL_SLOW_SLEEP_TIME); |
|
|
|
break; |
|
|
|
@ -650,6 +717,11 @@ bool mekorotKernel::packetHandler(protocolPackage* Package) { |
|
|
|
LOG(tBuff); |
|
|
|
#endif
|
|
|
|
m_bDeviceFlags[cDeviceIDX] = true; |
|
|
|
if ( m_bDeviceFlags[0] && m_bDeviceFlags[0] && m_bDeviceFlags[0] ) { |
|
|
|
m_nOperation = MEKOROT_KRNL_OP_QSTG_DEV0; |
|
|
|
m_bStage = MEKOROT_KRNL_STG_WORKING; |
|
|
|
return true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
switch (m_nOperation) { |
|
|
|
case MEKOROT_KRNL_OP_PONG_DEV2: m_nOperation = MEKOROT_KRNL_OP_QSTG_DEV0; m_bStage = MEKOROT_KRNL_STG_WORKING; break; |
|
|
|
@ -687,19 +759,19 @@ void mekorotKernel::treat_alarm(uint8_t devID, uint16_t az, uint16_t ra, uint32_ |
|
|
|
switch (devID) { |
|
|
|
case MEKOROT_DEV_LEFT: { |
|
|
|
tAz = ( 6000 + az + m_nLeftZeroShift ) % 6000; |
|
|
|
rEl = ((float)tAz * 360.f ) / 6000.f; |
|
|
|
rEl = ((float)tAz * 2.f ) / 6000.f - 1.f; |
|
|
|
rAz = m_fLeftZeroPan; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case MEKOROT_DEV_CENTER: { |
|
|
|
tAz = (6000 + az + m_nCenterZeroShift) % 6000; |
|
|
|
rAz = ((float)tAz * 360.f) / 6000.f; |
|
|
|
rEl = m_fHorizontalZeroPan; |
|
|
|
rAz = 1.f - ((float)tAz * 2.f) / 6000.f; |
|
|
|
rEl = m_fHorizontalZeroTilt; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case MEKOROT_DEV_RIGHT: { |
|
|
|
tAz = (6000 + az + m_nLeftZeroShift) % 6000; |
|
|
|
rEl = ((float)tAz * 360.f) / 6000.f; |
|
|
|
tAz = (6000 + az + m_nRightZeroShift) % 6000; |
|
|
|
rEl = 1.f - ((float)tAz * 2.f) / 6000.f; |
|
|
|
rAz = m_fRightZeroPan; |
|
|
|
break; |
|
|
|
}; |
|
|
|
@ -714,15 +786,55 @@ void mekorotKernel::treat_alarm(uint8_t devID, uint16_t az, uint16_t ra, uint32_ |
|
|
|
} else { |
|
|
|
rZoom = m_pZoomTable[0]; |
|
|
|
}; |
|
|
|
move_cam(rAz, rEl, rZoom); |
|
|
|
alarm(); |
|
|
|
m_pVideoOutput->getOutputName(); |
|
|
|
move_cam( rAz, rEl, rZoom ); |
|
|
|
}; |
|
|
|
|
|
|
|
void mekorotKernel::move_cam(float az, float el, float zoom){ |
|
|
|
if (!m_bUsePTZ) return; |
|
|
|
if (!m_bRecordIsActive) { |
|
|
|
m_fCamTargetPan = 1; |
|
|
|
} else { |
|
|
|
bool bHasToMove = true; |
|
|
|
#ifdef DEBUG
|
|
|
|
char tBuff[128]; |
|
|
|
sprintf( tBuff, "CAM MOVE: AZ:%0.2f EL:%0.2f ZM:%0.2f", az, el, zoom ); |
|
|
|
LOG(tBuff); |
|
|
|
#endif
|
|
|
|
|
|
|
|
if (az > 1.f || az < -1.f) return; |
|
|
|
if (el > 1.f || el < -1.f) return; |
|
|
|
if (zoom > 1.f || zoom < -1.f) return; |
|
|
|
//Check if event in camera FOV area
|
|
|
|
if ( m_fCamTargetZoom == zoom ) { |
|
|
|
float tFov; |
|
|
|
//DH-SD52C225U-HNI
|
|
|
|
//1/2.8”
|
|
|
|
//FL=4.8mm~120mm
|
|
|
|
float SensorSize = 9.0714285714285714285714285714286; |
|
|
|
float FN = ((120.0 - 4.8) * m_fCamTargetZoom) + 4.8; |
|
|
|
/*
|
|
|
|
The calculator below converts between the focal length f and the field of view (FOV) of a rectilinear lens. |
|
|
|
The formula that it implements is FOV = 2 arctan (x / (2 f)), where x is the diagonal of the film. |
|
|
|
The FOV is measured across the frame's diagonal, and is therefore smaller across the horizontal dimension, |
|
|
|
and even smaller across the vertical dimension. |
|
|
|
*/ |
|
|
|
//tFov = 57.295779513082320876798154814105 * ( 2.f * atanf( SensorSize / (2.f * FN )) ) / 2.0;
|
|
|
|
tFov = 0.31830988618379067153776752674503 * atanf( SensorSize / (2.f * FN)) / 2.; //(+-) 1/4 FOV - Ok to see both targets at same frame
|
|
|
|
#ifdef DEBUG
|
|
|
|
sprintf(tBuff, "Half FOV[%0.2f]: %0.2f", m_fCamTargetZoom, tFov ); |
|
|
|
LOG(tBuff); |
|
|
|
#endif
|
|
|
|
if( (fabsf((2 + m_fCamTargetPan) - (2 + az)) < tFov) && (fabsf((2 + m_fCamTargetTilt) - (2 + el)) < tFov)){ |
|
|
|
bHasToMove = false; |
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Camera Move Canceled!"); |
|
|
|
#endif
|
|
|
|
}; |
|
|
|
}; |
|
|
|
if (bHasToMove) { |
|
|
|
m_fCamTargetZoom = zoom; |
|
|
|
m_fCamTargetPan = az; |
|
|
|
m_fCamTargetTilt = el; |
|
|
|
m_pPTZCTRL->goAbsolute(m_fCamTargetPan, m_fCamTargetTilt, m_fCamTargetZoom ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
@ -851,6 +963,7 @@ void mekorotKernel::pushFrame(cv::Mat* Frame, void* src) { |
|
|
|
|
|
|
|
if( m_bRecordIsActive ){ |
|
|
|
rectangle((*m_pFinalFrame), Point(X + 260, 3), Point(X + 275, 12), Scalar(0, 0, 255), cv::FILLED); |
|
|
|
m_bRecordIsActive = false; |
|
|
|
} else { |
|
|
|
rectangle((*m_pFinalFrame), Point(X + 260, 3), Point(X + 275, 12), Scalar(0, 255, 0), cv::FILLED); |
|
|
|
}; |
|
|
|
|