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.

599 lines
21 KiB

​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "rgooseCamera.h"
  2. #include "../components/base/basicCameraInfo.h"
  3. #include "../components/object/objectSystemAnchor.h"
  4. #include "../hardware/uart/serialPort.h"
  5. #include "../hardware/uart/serialSOL.h"
  6. #include "../data/protocol/protocolPTZ_VISCA.h"
  7. #include "../data/protocol/protocolPTZ_ONVIF.h"
  8. #include "../data/protocol/protocolPTZ_PELCO.h"
  9. #define LOG( X ) m_pLog->Log( "RCAM", this, X )
  10. #ifdef DEBUG
  11. #define LOG_ERROR( X ) {\
  12. char _tBfrErrMSG2w34[256];\
  13. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  14. m_pLog->Log( "RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  15. }
  16. #else
  17. #define LOG_ERROR( X ) m_pLog->Log( "RCAM", this, _LOG_ERROR, X );
  18. #endif
  19. // all sizes in mm
  20. 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 };
  21. 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 };
  22. 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 };
  23. ARGUS_Camera::ARGUS_Camera(): basicThread(){
  24. m_pLog = basicLogCollection::getInstance();
  25. m_pEvtHeap = basicEventHeap::getInstance();
  26. m_tTimeTSeconds = 0;
  27. m_pPosition = NULL;
  28. m_pProtocol = NULL;
  29. m_pTransport = NULL;
  30. m_bState = 0;
  31. m_bBusy = true;
  32. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  33. m_pDBC = argusDBC::getInstance();
  34. };
  35. ARGUS_Camera::~ARGUS_Camera(){
  36. if( m_pTransport!= NULL ) {
  37. DBC_UART_DATA *tData = NULL;
  38. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  39. switch( tData->type ) {
  40. case UART_TYPE_HARDWARE:{
  41. delete((serialPort*)m_pTransport);
  42. break;
  43. };
  44. case UART_TYPE_SOL:{
  45. delete((serialSOL*)m_pTransport);
  46. break;
  47. };
  48. };
  49. };
  50. if( m_pProtocol != NULL ) {
  51. switch( m_sCamData.protocol ) {
  52. case CAM_CTRL_PROTO_VISCA:
  53. delete( (protocolPTZ_VISCA *) m_pProtocol );
  54. break;
  55. case CAM_CTRL_PROTO_PELCO:
  56. delete( (protocolPTZ_PELCO *) m_pProtocol );
  57. break;
  58. case CAM_CTRL_PROTO_ONVIF:
  59. delete( (protocolPTZ_ONVIF *) m_pProtocol );
  60. break;
  61. default:
  62. delete( m_pProtocol );
  63. };
  64. };
  65. if( m_pPosition != NULL ) delete( m_pPosition );
  66. };
  67. bool ARGUS_Camera::create( uint32_t id ){
  68. DBC_CAM_DATA * tData = m_pDBC->getCamData( id );
  69. if( tData != NULL ) {
  70. memcpy( &m_sCamData, tData, sizeof(DBC_CAM_DATA) );
  71. free( tData );
  72. } else {
  73. LOG_ERROR("Cannot Fetch CAM Data from Database!");
  74. return false;
  75. };
  76. if( m_sCamData.max_range == .0f ){
  77. m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_sCamData.max_f, 1280 );
  78. } else {
  79. m_fMaxRange = m_sCamData.max_range;
  80. };
  81. m_fMinHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.min_f );
  82. m_fMaxHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.max_f );
  83. m_fMinVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.min_f );
  84. m_fMaxVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.max_f );
  85. #ifdef DEBUG
  86. char tB[128];
  87. LOG("Camera Info:");
  88. sprintf( tB, "Maximal Range: %0.2f m. ", m_fMaxRange);
  89. LOG(tB);
  90. sprintf( tB, "Maximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov );
  91. LOG(tB);
  92. sprintf( tB, "Minimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov );
  93. LOG(tB);
  94. #endif
  95. m_pPosition = new basicPosition( m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
  96. if( m_pPosition == NULL ) {
  97. LOG_ERROR("Position Constructor Failure!");
  98. return false;
  99. };
  100. if( m_pProtocol != NULL ){
  101. LOG_ERROR("Cannot Start: Service Already Running!");
  102. return false;
  103. };
  104. switch( m_sCamData.protocol ){
  105. case CAM_CTRL_PROTO_VISCA: {
  106. #ifdef DEBUG
  107. LOG("VISCA");
  108. #endif
  109. m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA();
  110. if( m_pProtocol!= NULL ) {
  111. DBC_UART_DATA *tData = NULL;
  112. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  113. if( tData!= NULL ) {
  114. basicTransport *tTransport = NULL;
  115. switch( tData->type ) {
  116. case UART_TYPE_HARDWARE:{ // Hardware
  117. serialPort *tT = NULL;
  118. tT = new serialPort();
  119. if( tT!= NULL ){
  120. if( tT->create( tData->path, tData->speed ) ){
  121. tTransport = (basicTransport *) tT;
  122. } else {
  123. delete( tT );
  124. };
  125. };
  126. break;
  127. };
  128. case UART_TYPE_SOL:{ // E2S
  129. serialSOL *tT = NULL;
  130. tT = new serialSOL( (SOL_TYPE) tData->mode );
  131. if( tT!= NULL ){
  132. if( tT->create( tData->path, tData->port, tData->speed ) ){
  133. tTransport = (basicTransport *) tT;
  134. } else {
  135. delete( tT );
  136. };
  137. };
  138. break;
  139. };
  140. };
  141. if( tTransport!= NULL ) {
  142. m_pProtocol->setTransport( tTransport );
  143. };
  144. free( tData );
  145. };
  146. };
  147. break;
  148. };
  149. case CAM_CTRL_PROTO_PELCO:{
  150. #ifdef DEBUG
  151. LOG("PELCO");
  152. #endif
  153. m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO();
  154. if( m_pProtocol!= NULL ) {
  155. DBC_UART_DATA *tData = NULL;
  156. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  157. if( tData!= NULL ) {
  158. basicTransport *tTransport = NULL;
  159. switch( tData->type ) {
  160. case UART_TYPE_HARDWARE:{
  161. #ifdef DEBUG
  162. LOG("HW Port");
  163. #endif
  164. serialPort *tT = NULL;
  165. tT = new serialPort();
  166. if( tT!= NULL ){
  167. if( tT->create( tData->path, tData->speed ) ){
  168. tTransport = (basicTransport *) tT;
  169. } else {
  170. delete( tT );
  171. };
  172. };
  173. break;
  174. };
  175. case UART_TYPE_SOL:{
  176. #ifdef DEBUG
  177. LOG("SOL Port");
  178. #endif
  179. serialSOL *tT = NULL;
  180. tT = new serialSOL( (SOL_TYPE)tData->mode );
  181. if( tT!= NULL ){
  182. if( tT->create( tData->path, tData->port, tData->speed ) ){
  183. tTransport = (basicTransport *) tT;
  184. } else {
  185. delete( tT );
  186. };
  187. };
  188. break;
  189. };
  190. #ifdef DEBUG
  191. default: LOG_ERROR("Unknown Port Type!");
  192. #endif
  193. };
  194. if( tTransport!= NULL ) {
  195. LOG( "Bind Transport Port!" );
  196. if( m_pProtocol->setTransport( tTransport )){
  197. if( !m_pProtocol->create() ){
  198. LOG_ERROR("Protocol <<< Create >>> Failure!");
  199. };
  200. } else {
  201. LOG_ERROR("Binding Port Failure!");
  202. };
  203. } else LOG_ERROR("Transport Creation Failure!");
  204. free( tData );
  205. }
  206. #ifdef DEBUG
  207. else LOG_ERROR("No Uart DATA loaddesd!");
  208. #endif
  209. }
  210. #ifdef DEBUG
  211. else LOG_ERROR("Protocol NEW failure!");
  212. #endif
  213. break;
  214. };
  215. case CAM_CTRL_PROTO_ONVIF:{
  216. #ifdef DEBUG
  217. LOG("ONVIF");
  218. #endif
  219. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.username, m_sCamData.password );
  220. if( m_pProtocol!=NULL ) {
  221. if( !m_pProtocol->create() ) {
  222. LOG_ERROR("Error Creating Proto!");
  223. delete( (protocolPTZ_ONVIF*) m_pProtocol );
  224. m_pProtocol = NULL;
  225. };
  226. };
  227. break;
  228. };
  229. };
  230. if( m_pProtocol == NULL ) {
  231. LOG_ERROR("No Proto Created!!");
  232. m_sCamData.online = false;
  233. } else {
  234. #ifdef DEBUG
  235. LOG("Proto is OK");
  236. #endif
  237. m_sCamData.online = init();
  238. };
  239. return m_sCamData.online;
  240. };
  241. void ARGUS_Camera::setBusy( bool Status ){
  242. m_bBusy = Status;
  243. };
  244. bool ARGUS_Camera::relativeMove( float PanSPD, float TiltSPD, float ZoomSPD ){
  245. if( m_sCamData.online ) {
  246. uint32_t MoveMatrix = 0;
  247. if( PanSPD != .0f ){
  248. if( PanSPD > 0 ) {
  249. MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
  250. } else {
  251. MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
  252. };
  253. };
  254. if( TiltSPD != .0f ){
  255. if( TiltSPD > 0 ) {
  256. MoveMatrix |= PTZ_DRIVE_TILT_UP;
  257. } else {
  258. MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
  259. };
  260. };
  261. if( ZoomSPD != .0f ){
  262. if( ZoomSPD > 0 ) {
  263. MoveMatrix |= PTZ_DRIVE_ZOOM_WIDE;
  264. } else {
  265. MoveMatrix |= PTZ_DRIVE_ZOOM_TELE;
  266. };
  267. };
  268. if( MoveMatrix!= 0 ) {
  269. m_pProtocol->setPTZSpeed( PanSPD, TiltSPD, ZoomSPD );
  270. };
  271. return m_pProtocol->move( MoveMatrix );
  272. };
  273. return false;
  274. };
  275. bool ARGUS_Camera::relativeStop(){
  276. if( m_sCamData.online ) {
  277. return m_pProtocol->move( 0 );
  278. };
  279. return false;
  280. };
  281. bool ARGUS_Camera::absoluteMove( float PanPOS, float TiltPOS, float ZoomPOS ){
  282. if( m_sCamData.online ) {
  283. CAM_PTZ_CMD *tCMD = (CAM_PTZ_CMD*) malloc( sizeof(CAM_PTZ_CMD));
  284. if( tCMD ) {
  285. memset( tCMD, 0 , sizeof(CAM_PTZ_CMD));
  286. tCMD->CMD = PTZ_ABSOLUTE;
  287. tCMD->PAN = PanPOS;
  288. tCMD->TILT = TiltPOS;
  289. tCMD->ZOOM = ZoomPOS;
  290. m_mQPROTECTOR.lock();
  291. m_qCAM_CMD.push( tCMD );
  292. m_mQPROTECTOR.unlock();
  293. return true;
  294. };
  295. };
  296. return false;
  297. };
  298. void ARGUS_Camera::m_fThreadProc( void ){
  299. m_bThreadStatus = TH_WORKING;
  300. while (m_bThreadStatus < TH_ENDED) {
  301. switch( m_bState ) {
  302. case CAM_WS_INIT:{
  303. // Init Camera - PowerMode
  304. if( m_pProtocol->initCamera() ) m_bState = CAM_WS_WHITE_BALLANCE;
  305. break;
  306. };
  307. case CAM_WS_WHITE_BALLANCE:{
  308. // Set Speed
  309. if( m_pProtocol->setWhiteBalanceMode( WB_AUTO ) ) m_bState = CAM_WS_BACKLIGHT;
  310. break;
  311. };
  312. case CAM_WS_BACKLIGHT:{
  313. // Go 0
  314. if( m_pProtocol->setBackLightMode( true ) ) m_bState = CAM_WS_AUTO_FOCUS;
  315. //if( m_pProtocol->goHomePosition() ) m_bState++;
  316. break;
  317. };
  318. case CAM_WS_AUTO_FOCUS:{
  319. if( m_pProtocol->setAutoFocus( true ) ) m_bState = CAM_WS_INIT_GO_HOME;
  320. break;
  321. };
  322. case CAM_WS_INIT_GO_HOME:{
  323. LOG("INIT GO -1 -1 -1");
  324. if( m_pProtocol->goAbsolute( -1, -1, -1 ) ){
  325. m_bState = CAM_WS_READY;
  326. setBusy( false );
  327. };
  328. break;
  329. };
  330. case CAM_WS_READY:{
  331. m_mQPROTECTOR.lock();
  332. if( m_qCAM_CMD.size() > 0 ) {
  333. char tB[128];
  334. sprintf( tB,"Queue: %d commands!", m_qCAM_CMD.size() );
  335. LOG( tB );
  336. CAM_PTZ_CMD *tCMD = m_qCAM_CMD.front();
  337. if( tCMD ) {
  338. m_qCAM_CMD.pop();
  339. m_mQPROTECTOR.unlock();
  340. switch( tCMD->CMD ) {
  341. case PTZ_STOP:{
  342. m_pProtocol->goStop();
  343. setBusy( false );
  344. break;
  345. };
  346. case PTZ_MOVE:{
  347. uint32_t MoveMatrix = 0;
  348. if( m_pProtocol->setPTZSpeed( tCMD->PAN, tCMD->TILT, tCMD->ZOOM ) ){
  349. SLEEP( 5 );
  350. m_pProtocol->move( MoveMatrix );
  351. };
  352. break;
  353. };
  354. case PTZ_ABSOLUTE:{
  355. setBusy( true );
  356. if( !m_pProtocol->goAbsolute( tCMD->PAN, tCMD->TILT, tCMD->ZOOM ) ) {
  357. LOG_ERROR("Cannot Issue goAbsolute Command!");
  358. //SLEEP( 1000 );
  359. };
  360. setBusy( false );
  361. break;
  362. };
  363. };
  364. } else m_mQPROTECTOR.unlock();
  365. } else {
  366. m_mQPROTECTOR.unlock();
  367. SLEEP( 5 );
  368. };
  369. break;
  370. };
  371. case CAM_WS_END:{
  372. m_bThreadStatus = TH_ENDED;
  373. setBusy( true );
  374. break;
  375. };
  376. };
  377. };
  378. };
  379. bool ARGUS_Camera::inTheFOV( float lat, float lon, float alt ){
  380. bool RetVal = false;
  381. char tB[128];
  382. if( m_pPosition == NULL ) return RetVal;
  383. position3D * tPOS;
  384. transform_3 * tTrans = NULL;
  385. tPOS = new position3D();
  386. if( tPOS == NULL ) return RetVal;
  387. tPOS->setPositionWGS84( lat, lon, alt );
  388. tTrans = m_pPosition->getTransform();
  389. if(tTrans == NULL ){
  390. delete( tPOS );
  391. return RetVal;
  392. };
  393. vector_3 A, B;
  394. C3D_SPH_DEGREES tSph;
  395. C3D_DECART tLoc;
  396. tLoc = tPOS->getXYZ();
  397. A[0]= tLoc.x; A[1]= tLoc.y; A[2]= tLoc.z;
  398. tTrans->get_vector_local(A, B);
  399. tLoc.x = B[0]; tLoc.y = B[1]; tLoc.z = B[2];
  400. decart2spherical( tLoc, tSph );
  401. // sprintf( tB,"Object Dist: %0.2f ... cam range: %0.2f", tSph.r, m_fMaxRange );
  402. // LOG( tB );
  403. RetVal = ( tSph.r < m_fMaxRange );
  404. if( RetVal ) {
  405. //Checking if FOV is OK
  406. bool pOK = false;
  407. bool tOK = false;
  408. float HS = AC_imager_width[m_sCamData.imager_type];
  409. float VS = AC_imager_height[m_sCamData.imager_type];
  410. float HS2 = HS * HS;
  411. float VS2 = VS * VS;
  412. float IR = HS / VS;
  413. float IR2 = IR * IR;
  414. if( m_sCamData.pan_angles == 0 ) {
  415. // Fixed Camera
  416. pOK = ( tSph.fi > ( m_fMaxHFov / -2.0f ) ) && ( tSph.fi < ( m_fMaxHFov / 2.0f ) );
  417. } else {
  418. if( m_sCamData.pan_angles > 359 ) {
  419. // Endless Pan
  420. pOK = true;
  421. } else {
  422. // Partial Pan
  423. switch( m_sCamData.pan_model ) {
  424. case 1: {
  425. // Regular Pan
  426. float tFOV = 0.5f * ( m_fMinHFov + ( m_fMaxHFov - m_fMinHFov ) * ( tSph.r / m_fMaxRange ) ) ;
  427. float tRad = deg2rad( tSph.fi );
  428. // sprintf( tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad );
  429. //LOG( tB );
  430. pOK = ( tRad > ( -1.0 * tFOV ) ) && ( tRad < ( deg2rad( m_sCamData.pan_angles ) + tFOV ) ) ;
  431. break;
  432. };
  433. case 2:{
  434. break;
  435. };
  436. case 3:{
  437. break;
  438. };
  439. };
  440. };
  441. };
  442. if( m_sCamData.tilt_angles == 0 ) {
  443. //Fixed Camera
  444. tOK = ( tSph.tetta > ( m_fMaxVFov / -2.0f ) ) && ( tSph.tetta < ( m_fMaxVFov / 2.0f ) );
  445. } else {
  446. if( m_sCamData.tilt_angles > 89 ) {
  447. // Endless Tilt
  448. tOK = true;
  449. } else {
  450. // Partial Tilt
  451. switch( m_sCamData.tilt_model ) {
  452. case 1: {
  453. // Regular Tilt
  454. float tFOV = 0.5f * ( m_fMinVFov + ( m_fMaxVFov - m_fMinVFov ) * ( tSph.r / m_fMaxRange ) ) ;
  455. float tRad = deg2rad( tSph.tetta );
  456. tOK = ( tRad > ( -1.0 * tFOV ) ) && ( tRad < ( deg2rad( m_sCamData.tilt_angles ) + tFOV ) ) ;
  457. break;
  458. };
  459. case 2:{
  460. break;
  461. };
  462. };
  463. };
  464. };
  465. //sprintf( tB, "Pan: %d Tilt: %d", pOK, tOK );
  466. //LOG( tB );
  467. RetVal = ( pOK && tOK );
  468. } else {
  469. //LOG("Object Too Far!");
  470. }
  471. delete( tPOS );
  472. return RetVal;
  473. };
  474. bool ARGUS_Camera::lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt ){
  475. C3D_WGS84_LOC tWGS;
  476. C3D_SPH_DEGREES tSph;
  477. char tB[128];
  478. //sprintf(tB,"LookAt: %0.5f %0.5f %0.2f", lat, lon, alt );
  479. //LOG( tB );
  480. if( m_bBusy ){
  481. //LOG("CAM BUSY!");
  482. return false;
  483. };
  484. // Exit for fixed Cam
  485. if( ( m_sCamData.pan_model == 0 ) && ( m_sCamData.tilt_model == 0 ) ) return true;
  486. // Exit for unpositioned Cam
  487. if( m_pPosition == NULL ) return false;
  488. tWGS.lat = lat;
  489. tWGS.lon = lon;
  490. tWGS.alt = alt;
  491. systemAnchor* tSystem = systemAnchor::getInstance();
  492. if( tSystem != NULL ) {
  493. tSystem->convertToLocal( m_pPosition, tWGS, tSph );
  494. } else {
  495. LOG_ERROR("No SYSTEM ANCHOR!");
  496. return false;
  497. };
  498. //sprintf( tB, "local coords: %0.2fm. %0.2f� %0.2f�", tSph.r, tSph.tetta, tSph.fi );
  499. //LOG( tB );
  500. float fZ, fT, fP;
  501. if( m_fMaxRange > 0.0f ) {
  502. if( tSph.r > m_fMaxRange ) {
  503. fZ = 1;
  504. } else {
  505. fZ = tSph.r / m_fMaxRange;
  506. };
  507. } else fZ = 0.f;
  508. switch( m_sCamData.pan_model ){
  509. case 1:{
  510. fP = ( 2.0 / m_sCamData.pan_angles ) * tSph.tetta - 1.0;
  511. break;
  512. };
  513. case 2:{
  514. fP = ( 2.0 / 360.0 ) * tSph.tetta - 1.0;
  515. };
  516. };
  517. switch( m_sCamData.tilt_model ) {
  518. case 1:{
  519. fT = -2.0f * ( ( m_sCamData.tilt_angles - tSph.fi ) / m_sCamData.tilt_angles ) + 1.0;
  520. break;
  521. };
  522. case 2:{
  523. fT = ( 2.0 / m_sCamData.tilt_angles ) * ( m_sCamData.tilt_angles - tSph.fi ) - 1.0;
  524. break;
  525. };
  526. };
  527. //sprintf(tB,"EVT:%d AM: %0.2f %0.2f %0.2f", TargetRefID, fP, fT, fZ );
  528. //LOG( tB );
  529. if( absoluteMove( fP, fT, fZ ) ) {
  530. #ifdef DEBUG
  531. //LOG("CHECK CAMERA STREAMS");
  532. #endif
  533. EVENT_CONTAINER *tEVT;
  534. DBC_INT_LIST *tStreams;
  535. tStreams = m_pDBC->listCamMediaStreams( m_sCamData.id );
  536. if( tStreams!= NULL ) {
  537. for( uint32_t idx = 0; idx < tStreams->size(); idx++ ) {
  538. tEVT = createBasicTargetedEvent( m_sCamData.node_id, tStreams->at(idx), EVT_CLASS_VIDEO, EVT_CAPTURE_START );
  539. if( tEVT != NULL ) {
  540. tEVT->m_ref_id = TargetRefID;
  541. m_pEvtHeap->broadcast( tEVT );
  542. };
  543. };
  544. delete( tStreams );
  545. };
  546. return true;
  547. };
  548. return false;
  549. };
  550. #undef LOG
  551. #undef LOG_ERROR