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.

814 lines
28 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. #include "rgooseKernel.h"
  10. #include "rgooseModuleEmbedVideo.h"
  11. #define LOG( X ) m_pLog->Log( "RCAM", this, X )
  12. #ifdef DEBUG
  13. #define LOG_ERROR( X ) {\
  14. char _tBfrErrMSG2w34[256];\
  15. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  16. m_pLog->Log( "RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  17. }
  18. #else
  19. #define LOG_ERROR( X ) m_pLog->Log( "RCAM", this, _LOG_ERROR, X );
  20. #endif
  21. // all sizes in mm
  22. 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 };
  23. 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 };
  24. 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 };
  25. ARGUS_Camera::ARGUS_Camera(): basicThread(){
  26. m_pLog = basicLogCollection::getInstance();
  27. m_pEvtHeap = basicEventHeap::getInstance();
  28. m_pDBC = argusDBC::getInstance();
  29. m_tTimeTSeconds = 0;
  30. m_pPosition = NULL;
  31. m_pProtocol = NULL;
  32. m_pTransport = NULL;
  33. m_bState = 0;
  34. m_bBusy = true;
  35. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  36. m_nRelativeMoveCounter = 0;
  37. m_bRelativeMoveMatrix = 0;
  38. m_fSpeedRise = 0.03f;
  39. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  40. m_bSourceConnected = false;
  41. m_pSource = NULL;
  42. };
  43. ARGUS_Camera::~ARGUS_Camera(){
  44. LOG("Destruct");
  45. m_mQPROTECTOR.unlock();
  46. waitThreadEnd( true );
  47. LOG("Thread Del OK");
  48. if( m_pTransport!= NULL ) {
  49. DBC_UART_DATA *tData = NULL;
  50. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  51. switch( tData->type ) {
  52. case UART_TYPE_HARDWARE:{
  53. delete((serialPort*)m_pTransport);
  54. break;
  55. };
  56. case UART_TYPE_SOL:{
  57. delete((serialSOL*)m_pTransport);
  58. break;
  59. };
  60. };
  61. };
  62. LOG("Transport Del OK");
  63. if( m_pProtocol != NULL ) {
  64. switch( m_sCamData.protocol ) {
  65. case CAM_CTRL_PROTO_VISCA:
  66. delete( (protocolPTZ_VISCA *) m_pProtocol );
  67. break;
  68. case CAM_CTRL_PROTO_PELCO:
  69. delete( (protocolPTZ_PELCO *) m_pProtocol );
  70. break;
  71. case CAM_CTRL_PROTO_ONVIF:
  72. delete( (protocolPTZ_ONVIF *) m_pProtocol );
  73. break;
  74. default:
  75. delete( m_pProtocol );
  76. };
  77. };
  78. LOG("Proto Del OK");
  79. if( m_pPosition != NULL ) delete( m_pPosition );
  80. LOG("Pos Del OK");
  81. if( m_bSourceConnected ){
  82. if( m_pSource != NULL ){
  83. m_pSource->_close();
  84. delete( m_pSource );
  85. };
  86. };
  87. LOG("Stream Del OK");
  88. };
  89. bool ARGUS_Camera::create( uint32_t id ){
  90. DBC_CAM_DATA * tData = m_pDBC->getCamData( id );
  91. if( tData != NULL ) {
  92. memcpy( &m_sCamData, tData, sizeof(DBC_CAM_DATA) );
  93. free( tData );
  94. } else {
  95. LOG_ERROR("Cannot Fetch CAM Data from Database!");
  96. return false;
  97. };
  98. if( m_sCamData.max_range == .0f ){
  99. m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_sCamData.max_f, 1280 );
  100. } else {
  101. m_fMaxRange = m_sCamData.max_range;
  102. };
  103. m_fMinHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.min_f );
  104. m_fMaxHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.max_f );
  105. m_fMinVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.min_f );
  106. m_fMaxVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.max_f );
  107. if( m_sCamData.ptz_speed_step > .0f ) {
  108. m_fSpeedRise = m_sCamData.ptz_speed_step;
  109. };
  110. #ifdef DEBUG
  111. char tB[128];
  112. LOG("Camera Info:");
  113. sprintf( tB, "Maximal Range: %0.2f m. ", m_fMaxRange);
  114. LOG(tB);
  115. sprintf( tB, "Maximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov );
  116. LOG(tB);
  117. sprintf( tB, "Minimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov );
  118. LOG(tB);
  119. #endif
  120. m_pPosition = new basicPosition( m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
  121. if( m_pPosition == NULL ) {
  122. LOG_ERROR("Position Constructor Failure!");
  123. return false;
  124. };
  125. if( m_pProtocol != NULL ){
  126. LOG_ERROR("Cannot Start: Service Already Running!");
  127. return false;
  128. };
  129. switch( m_sCamData.protocol ){
  130. case CAM_CTRL_PROTO_VISCA: {
  131. #ifdef DEBUG
  132. LOG("VISCA");
  133. #endif
  134. m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA();
  135. if( m_pProtocol!= NULL ) {
  136. DBC_UART_DATA *tData = NULL;
  137. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  138. if( tData!= NULL ) {
  139. basicTransport *tTransport = NULL;
  140. switch( tData->type ) {
  141. case UART_TYPE_HARDWARE:{ // Hardware
  142. serialPort *tT = NULL;
  143. tT = new serialPort();
  144. if( tT!= NULL ){
  145. if( tT->create( tData->path, tData->speed ) ){
  146. tTransport = (basicTransport *) tT;
  147. } else {
  148. delete( tT );
  149. };
  150. };
  151. break;
  152. };
  153. case UART_TYPE_SOL:{ // E2S
  154. serialSOL *tT = NULL;
  155. tT = new serialSOL( (SOL_TYPE) tData->mode );
  156. if( tT!= NULL ){
  157. if( tT->create( tData->path, tData->port, tData->speed ) ){
  158. tTransport = (basicTransport *) tT;
  159. } else {
  160. delete( tT );
  161. };
  162. };
  163. break;
  164. };
  165. };
  166. if( tTransport!= NULL ) {
  167. m_pProtocol->setTransport( tTransport );
  168. };
  169. free( tData );
  170. };
  171. };
  172. break;
  173. };
  174. case CAM_CTRL_PROTO_PELCO:{
  175. #ifdef DEBUG
  176. LOG("PELCO");
  177. #endif
  178. m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO();
  179. if( m_pProtocol!= NULL ) {
  180. DBC_UART_DATA *tData = NULL;
  181. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  182. if( tData!= NULL ) {
  183. basicTransport *tTransport = NULL;
  184. switch( tData->type ) {
  185. case UART_TYPE_HARDWARE:{
  186. #ifdef DEBUG
  187. LOG("HW Port");
  188. #endif
  189. serialPort *tT = NULL;
  190. tT = new serialPort();
  191. if( tT!= NULL ){
  192. if( tT->create( tData->path, tData->speed ) ){
  193. tTransport = (basicTransport *) tT;
  194. } else {
  195. delete( tT );
  196. };
  197. };
  198. break;
  199. };
  200. case UART_TYPE_SOL:{
  201. #ifdef DEBUG
  202. LOG("SOL Port");
  203. #endif
  204. serialSOL *tT = NULL;
  205. tT = new serialSOL( (SOL_TYPE)tData->mode );
  206. if( tT!= NULL ){
  207. if( tT->create( tData->path, tData->port, tData->speed ) ){
  208. tTransport = (basicTransport *) tT;
  209. } else {
  210. delete( tT );
  211. };
  212. };
  213. break;
  214. };
  215. #ifdef DEBUG
  216. default: LOG_ERROR("Unknown Port Type!");
  217. #endif
  218. };
  219. if( tTransport!= NULL ) {
  220. LOG( "Bind Transport Port!" );
  221. if( m_pProtocol->setTransport( tTransport )){
  222. if( !m_pProtocol->create() ){
  223. LOG_ERROR("Protocol <<< Create >>> Failure!");
  224. };
  225. } else {
  226. LOG_ERROR("Binding Port Failure!");
  227. };
  228. } else LOG_ERROR("Transport Creation Failure!");
  229. free( tData );
  230. }
  231. #ifdef DEBUG
  232. else LOG_ERROR("No Uart DATA loaddesd!");
  233. #endif
  234. }
  235. #ifdef DEBUG
  236. else LOG_ERROR("Protocol NEW failure!");
  237. #endif
  238. break;
  239. };
  240. case CAM_CTRL_PROTO_ONVIF:{
  241. #ifdef DEBUG
  242. LOG("ONVIF");
  243. #endif
  244. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.username, m_sCamData.password );
  245. if( m_pProtocol!=NULL ) {
  246. if( !m_pProtocol->create() ) {
  247. LOG_ERROR("Error Creating Proto!");
  248. delete( (protocolPTZ_ONVIF*) m_pProtocol );
  249. m_pProtocol = NULL;
  250. };
  251. };
  252. break;
  253. };
  254. };
  255. if( m_pProtocol == NULL ) {
  256. LOG_ERROR("No Proto Created!!");
  257. m_sCamData.online = false;
  258. } else {
  259. #ifdef DEBUG
  260. LOG("Proto is OK");
  261. #endif
  262. m_sCamData.online = init();
  263. };
  264. return m_sCamData.online;
  265. };
  266. void ARGUS_Camera::setBusy( bool Status ){
  267. m_bBusy = Status;
  268. };
  269. bool ARGUS_Camera::relativeMove( float PanSPD, float TiltSPD, float ZoomSPD ){
  270. if( m_sCamData.online ) {
  271. uint32_t MoveMatrix = 0;
  272. if( PanSPD != .0f ){
  273. if( PanSPD > 0 ) {
  274. MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
  275. } else {
  276. MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
  277. };
  278. };
  279. if( TiltSPD != .0f ){
  280. if( TiltSPD > 0 ) {
  281. MoveMatrix |= PTZ_DRIVE_TILT_UP;
  282. } else {
  283. MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
  284. };
  285. };
  286. if( ZoomSPD != .0f ){
  287. if( ZoomSPD > 0 ) {
  288. MoveMatrix |= PTZ_DRIVE_ZOOM_WIDE;
  289. } else {
  290. MoveMatrix |= PTZ_DRIVE_ZOOM_TELE;
  291. };
  292. };
  293. if( MoveMatrix != 0 ) {
  294. m_pProtocol->setPTZSpeed( fabs(PanSPD), fabs(TiltSPD), fabs(ZoomSPD) );
  295. };
  296. return m_pProtocol->move( MoveMatrix );
  297. };
  298. return false;
  299. };
  300. bool ARGUS_Camera::relativeStop(){
  301. if( m_sCamData.online ) {
  302. return m_pProtocol->move( 0 );
  303. };
  304. return false;
  305. };
  306. bool ARGUS_Camera::absoluteMove( float PanPOS, float TiltPOS, float ZoomPOS ){
  307. if( m_sCamData.online ) {
  308. CAM_PTZ_CMD *tCMD = (CAM_PTZ_CMD*) malloc( sizeof(CAM_PTZ_CMD));
  309. if( tCMD ) {
  310. memset( tCMD, 0 , sizeof(CAM_PTZ_CMD));
  311. tCMD->CMD = PTZ_ABSOLUTE;
  312. tCMD->PAN = PanPOS;
  313. tCMD->TILT = TiltPOS;
  314. tCMD->ZOOM = ZoomPOS;
  315. m_mQPROTECTOR.lock();
  316. m_qCAM_CMD.push( tCMD );
  317. m_mQPROTECTOR.unlock();
  318. return true;
  319. };
  320. };
  321. return false;
  322. };
  323. void ARGUS_Camera::m_fThreadProc( void ){
  324. m_bThreadStatus = TH_WORKING;
  325. while( m_bThreadStatus < TH_ENDED ) {
  326. //Local Recorder
  327. if( m_bSourceConnected ) {
  328. };
  329. DBC_PUSHED_CMD * PUSHED = m_pDBC->getCamPushedCMD( m_sCamData.id );
  330. if( PUSHED ) {
  331. if( ( PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK ) == ARGUS_CAM_PCMD_CMD_MASK ) {
  332. switch( PUSHED->CMD ) {
  333. case 0x80:{
  334. //m_bWM = ANODE_WM_2D_ISSUE_FULL_RESET;
  335. break;
  336. };
  337. case 0x81:{
  338. //m_bWM = ANODE_WM_2D_GET_FAST_DRAW;
  339. break;
  340. };
  341. case 0x82:{
  342. break;
  343. };
  344. };
  345. } else {
  346. //Direct Movment Mode
  347. if( PUSHED->CMD == ARGUS_CAM_PCMD_STOP ) {
  348. m_bState = CAM_WS_STOP_MOVE;
  349. } else {
  350. char tB[64];
  351. if( m_bState!= CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
  352. m_bRelativeMoveMatrix = ( PUSHED->CMD ) >> 1;
  353. m_bState = CAM_WS_AUTOMATED_MOVE;
  354. };
  355. };
  356. free( PUSHED );
  357. };
  358. switch( m_bState ) {
  359. case CAM_WS_INIT:{
  360. #ifdef DEBUG
  361. LOG("Init Camera - PowerMode");
  362. #endif
  363. if( m_pProtocol->initCamera() ) m_bState = CAM_WS_WHITE_BALLANCE;
  364. break;
  365. };
  366. case CAM_WS_WHITE_BALLANCE:{
  367. #ifdef DEBUG
  368. LOG("Set WB");
  369. #endif
  370. if( m_pProtocol->setWhiteBalanceMode( WB_AUTO ) ) m_bState = CAM_WS_BACKLIGHT;
  371. break;
  372. };
  373. case CAM_WS_BACKLIGHT:{
  374. #ifdef DEBUG
  375. LOG("Set BLC");
  376. #endif
  377. if( m_pProtocol->setBackLightMode( true ) ) m_bState = CAM_WS_AUTO_FOCUS;
  378. //if( m_pProtocol->goHomePosition() ) m_bState++;
  379. break;
  380. };
  381. case CAM_WS_AUTO_FOCUS:{
  382. #ifdef DEBUG
  383. LOG("Set AF");
  384. #endif
  385. if( m_pProtocol->setAutoFocus( true ) ) m_bState = CAM_WS_INIT_GO_HOME;
  386. break;
  387. };
  388. case CAM_WS_INIT_GO_HOME:{
  389. #ifdef DEBUG
  390. LOG("INIT GO -1 -1 -1");
  391. #endif
  392. if( m_pProtocol->goAbsolute( -1, -1, -1 ) ){
  393. m_bState = CAM_WS_READY;
  394. setBusy( false );
  395. };
  396. break;
  397. };
  398. case CAM_WS_AUTOMATED_MOVE:{
  399. m_nRelativeMoveCounter++;
  400. if( ( m_bRelativeMoveMatrix & 0x03 ) != 0 ) {
  401. //Pan Move
  402. if( ( m_bRelativeMoveMatrix & 0x01 ) == 0 ) {
  403. m_fRM_Pan -= m_fSpeedRise;
  404. } else {
  405. m_fRM_Pan += m_fSpeedRise;
  406. };
  407. };
  408. if( ( m_bRelativeMoveMatrix & 0x0C ) != 0 ) {
  409. //TILT Move
  410. if( ( m_bRelativeMoveMatrix & 0x04 ) == 0 ) {
  411. m_fRM_Tilt -= m_fSpeedRise;
  412. } else {
  413. m_fRM_Tilt += m_fSpeedRise;
  414. }
  415. };
  416. if( ( m_bRelativeMoveMatrix & 0x30 ) != 0 ) {
  417. //ZOOM Move
  418. if( ( m_bRelativeMoveMatrix & 0x10 ) == 0 ) {
  419. //Wide
  420. m_fRM_Zoom -= m_fSpeedRise;
  421. } else {
  422. //Tele
  423. m_fRM_Zoom += m_fSpeedRise;
  424. };
  425. };
  426. if( m_fRM_Pan < -1.0f ) m_fRM_Pan = -1.0f;
  427. if( m_fRM_Pan > 1.0f ) m_fRM_Pan = 1.0f;
  428. if( m_fRM_Tilt < -1.0f ) m_fRM_Tilt = -1.0f;
  429. if( m_fRM_Tilt > 1.0f ) m_fRM_Tilt = 1.0f;
  430. if( m_fRM_Zoom < -1.0f ) m_fRM_Zoom = -1.0f;
  431. if( m_fRM_Zoom > 1.0f ) m_fRM_Zoom = 1.0f;
  432. setBusy( true );
  433. if( !relativeMove( m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom ) ){
  434. m_bState = CAM_WS_READY;
  435. };
  436. setBusy( false );
  437. break;
  438. };
  439. case CAM_WS_STOP_MOVE:{
  440. m_fRM_Pan = .0f;
  441. m_fRM_Pan = .0f;
  442. m_fRM_Tilt = .0f;
  443. m_fRM_Tilt = .0f;
  444. m_fRM_Zoom = .0f;
  445. m_fRM_Zoom = .0f;
  446. setBusy( true );
  447. if( relativeStop() ){
  448. m_bState = CAM_WS_READY;
  449. };
  450. setBusy( false );
  451. break;
  452. }
  453. case CAM_WS_READY:{
  454. m_mQPROTECTOR.lock();
  455. if( m_qCAM_CMD.size() ){
  456. char tB[128];
  457. sprintf( tB,"Queue: %d commands!", m_qCAM_CMD.size() );
  458. LOG( tB );
  459. CAM_PTZ_CMD *tCMD = m_qCAM_CMD.front();
  460. if( tCMD ) {
  461. m_qCAM_CMD.pop();
  462. m_mQPROTECTOR.unlock();
  463. switch( tCMD->CMD ) {
  464. case PTZ_STOP:{
  465. m_pProtocol->goStop();
  466. setBusy( false );
  467. break;
  468. };
  469. case PTZ_MOVE:{
  470. uint32_t MoveMatrix = 0;
  471. if( m_pProtocol->setPTZSpeed( tCMD->PAN, tCMD->TILT, tCMD->ZOOM ) ){
  472. SLEEP( 5 );
  473. m_pProtocol->move( MoveMatrix );
  474. };
  475. break;
  476. };
  477. case PTZ_ABSOLUTE:{
  478. setBusy( true );
  479. if( !m_pProtocol->goAbsolute( tCMD->PAN, tCMD->TILT, tCMD->ZOOM ) ) {
  480. LOG_ERROR("Cannot Issue goAbsolute Command!");
  481. //SLEEP( 1000 );
  482. };
  483. setBusy( false );
  484. break;
  485. };
  486. case PTZ_RELOAD_CAMERA:{
  487. LOG("Exit Command Rcpt");
  488. m_bThreadStatus = TH_ENDED;
  489. setBusy( true );
  490. };
  491. };
  492. free( tCMD );
  493. } else {
  494. m_mQPROTECTOR.unlock();
  495. LOG_ERROR("Error Fetching CMD from Queue");
  496. SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  497. };
  498. } else {
  499. m_mQPROTECTOR.unlock();
  500. SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  501. };
  502. break;
  503. };
  504. case CAM_WS_END:{
  505. LOG("Exit Command Rcpt");
  506. m_bThreadStatus = TH_ENDED;
  507. setBusy( true );
  508. break;
  509. };
  510. };
  511. SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  512. };
  513. LOG("CTRL Loop End!");
  514. };
  515. bool ARGUS_Camera::inTheFOV( float lat, float lon, float alt ){
  516. bool RetVal = false;
  517. char tB[128];
  518. if( m_pPosition == NULL ) return RetVal;
  519. position3D * tPOS;
  520. transform_3 * tTrans = NULL;
  521. tPOS = new position3D();
  522. if( tPOS == NULL ) return RetVal;
  523. tPOS->setPositionWGS84( lat, lon, alt );
  524. tTrans = m_pPosition->getTransform();
  525. if(tTrans == NULL ){
  526. delete( tPOS );
  527. return RetVal;
  528. };
  529. vector_3 A, B;
  530. C3D_SPH_DEGREES tSph;
  531. C3D_DECART tLoc;
  532. tLoc = tPOS->getXYZ();
  533. A[0]= tLoc.x; A[1]= tLoc.y; A[2]= tLoc.z;
  534. tTrans->get_vector_local(A, B);
  535. tLoc.x = B[0]; tLoc.y = B[1]; tLoc.z = B[2];
  536. decart2spherical( tLoc, tSph );
  537. // sprintf( tB,"Object Dist: %0.2f ... cam range: %0.2f", tSph.r, m_fMaxRange );
  538. // LOG( tB );
  539. RetVal = ( tSph.r < m_fMaxRange );
  540. if( RetVal ) {
  541. //Checking if FOV is OK
  542. bool pOK = false;
  543. bool tOK = false;
  544. float HS = AC_imager_width[m_sCamData.imager_type];
  545. float VS = AC_imager_height[m_sCamData.imager_type];
  546. float HS2 = HS * HS;
  547. float VS2 = VS * VS;
  548. float IR = HS / VS;
  549. float IR2 = IR * IR;
  550. if( m_sCamData.pan_angles == 0 ) {
  551. // Fixed Camera
  552. pOK = ( tSph.fi > ( m_fMaxHFov / -2.0f ) ) && ( tSph.fi < ( m_fMaxHFov / 2.0f ) );
  553. } else {
  554. if( m_sCamData.pan_angles > 359 ) {
  555. // Endless Pan
  556. pOK = true;
  557. } else {
  558. // Partial Pan
  559. switch( m_sCamData.pan_model ) {
  560. case 1: {
  561. // Regular Pan
  562. float tFOV = 0.5f * ( m_fMinHFov + ( m_fMaxHFov - m_fMinHFov ) * ( tSph.r / m_fMaxRange ) ) ;
  563. float tRad = deg2rad( tSph.fi );
  564. // sprintf( tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad );
  565. //LOG( tB );
  566. pOK = ( tRad > ( -1.0 * tFOV ) ) && ( tRad < ( deg2rad( m_sCamData.pan_angles ) + tFOV ) ) ;
  567. break;
  568. };
  569. case 2:{
  570. break;
  571. };
  572. case 3:{
  573. break;
  574. };
  575. };
  576. };
  577. };
  578. if( m_sCamData.tilt_angles == 0 ) {
  579. //Fixed Camera
  580. tOK = ( tSph.tetta > ( m_fMaxVFov / -2.0f ) ) && ( tSph.tetta < ( m_fMaxVFov / 2.0f ) );
  581. } else {
  582. if( m_sCamData.tilt_angles > 89 ) {
  583. // Endless Tilt
  584. tOK = true;
  585. } else {
  586. // Partial Tilt
  587. switch( m_sCamData.tilt_model ) {
  588. case 1: {
  589. // Regular Tilt
  590. float tFOV = 0.5f * ( m_fMinVFov + ( m_fMaxVFov - m_fMinVFov ) * ( tSph.r / m_fMaxRange ) ) ;
  591. float tRad = deg2rad( tSph.tetta );
  592. tOK = ( tRad > ( -1.0 * tFOV ) ) && ( tRad < ( deg2rad( m_sCamData.tilt_angles ) + tFOV ) ) ;
  593. break;
  594. };
  595. case 2:{
  596. break;
  597. };
  598. };
  599. };
  600. };
  601. //sprintf( tB, "Pan: %d Tilt: %d", pOK, tOK );
  602. //LOG( tB );
  603. RetVal = ( pOK && tOK );
  604. } else {
  605. //LOG("Object Too Far!");
  606. }
  607. delete( tPOS );
  608. return RetVal;
  609. };
  610. bool ARGUS_Camera::lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt ){
  611. C3D_WGS84_LOC tWGS;
  612. C3D_SPH_DEGREES tSph;
  613. char tB[128];
  614. //sprintf(tB,"LookAt: %0.5f %0.5f %0.2f", lat, lon, alt );
  615. //LOG( tB );
  616. if( m_bBusy ){
  617. //LOG("CAM BUSY!");
  618. return false;
  619. };
  620. // Exit for fixed Cam
  621. if( ( m_sCamData.pan_model == 0 ) && ( m_sCamData.tilt_model == 0 ) ) return true;
  622. // Exit for unpositioned Cam
  623. if( m_pPosition == NULL ) return false;
  624. tWGS.lat = lat;
  625. tWGS.lon = lon;
  626. tWGS.alt = alt;
  627. systemAnchor* tSystem = systemAnchor::getInstance();
  628. if( tSystem != NULL ) {
  629. tSystem->convertToLocal( m_pPosition, tWGS, tSph );
  630. } else {
  631. LOG_ERROR("No SYSTEM ANCHOR!");
  632. return false;
  633. };
  634. //sprintf( tB, "local coords: %0.2fm. %0.2f� %0.2f�", tSph.r, tSph.tetta, tSph.fi );
  635. //LOG( tB );
  636. float fZ, fT, fP;
  637. if( m_fMaxRange > 0.0f ) {
  638. if( tSph.r > m_fMaxRange ) {
  639. fZ = 1;
  640. } else {
  641. fZ = tSph.r / m_fMaxRange;
  642. };
  643. } else fZ = 0.f;
  644. switch( m_sCamData.pan_model ){
  645. case 1:{
  646. fP = ( 2.0 / m_sCamData.pan_angles ) * tSph.tetta - 1.0;
  647. break;
  648. };
  649. case 2:{
  650. fP = ( 2.0 / 360.0 ) * tSph.tetta - 1.0;
  651. };
  652. };
  653. switch( m_sCamData.tilt_model ) {
  654. case 1:{
  655. fT = -2.0f * ( ( m_sCamData.tilt_angles - tSph.fi ) / m_sCamData.tilt_angles ) + 1.0;
  656. break;
  657. };
  658. case 2:{
  659. fT = ( 2.0 / m_sCamData.tilt_angles ) * ( m_sCamData.tilt_angles - tSph.fi ) - 1.0;
  660. break;
  661. };
  662. };
  663. //sprintf(tB,"EVT:%d AM: %0.2f %0.2f %0.2f", TargetRefID, fP, fT, fZ );
  664. //LOG( tB );
  665. if( absoluteMove( fP, fT, fZ ) ) {
  666. #ifdef DEBUG
  667. //LOG("CHECK CAMERA STREAMS");
  668. #endif
  669. EVENT_CONTAINER *tEVT;
  670. DBC_INT_LIST *tStreams;
  671. tStreams = m_pDBC->listCamMediaStreams( m_sCamData.id );
  672. if( tStreams!= NULL ) {
  673. for( uint32_t idx = 0; idx < tStreams->size(); idx++ ) {
  674. tEVT = createBasicTargetedEvent( m_sCamData.node_id, tStreams->at(idx), EVT_CLASS_VIDEO, EVT_CAPTURE_START );
  675. if( tEVT != NULL ) {
  676. tEVT->m_ref_id = TargetRefID;
  677. m_pEvtHeap->broadcast( tEVT );
  678. };
  679. };
  680. delete( tStreams );
  681. };
  682. return true;
  683. };
  684. return false;
  685. };
  686. bool ARGUS_Camera::captureFrame( CSTR fileName, uint8_t compression ){
  687. if( m_bSourceConnected ) {
  688. if( m_pSource != NULL ) {
  689. };
  690. };
  691. return false;
  692. };
  693. bool ARGUS_Camera::connectToStream( uint32_t id ){
  694. if( id ){
  695. argusKernelModule * tKM = NULL;
  696. argusKernel *tKRNL = NULL;
  697. if( m_pDBC == NULL ) {
  698. LOG_ERROR("No Database Connector!");
  699. return false;
  700. };
  701. tKRNL = argusKernel::getInstance();
  702. if( tKRNL ) {
  703. argusModuleFactory *tMF = NULL;
  704. tMF = tKRNL->getModuleFactory();
  705. if( tMF ) {
  706. tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
  707. };
  708. };
  709. if( tKM ) {
  710. DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
  711. LOG("Module && DB OK");
  712. if( tDATA ) {
  713. LOG( tDATA->mrl_proto );
  714. if( strncmp( tDATA->mrl_proto, "v4l2", 4 ) == 0 ){
  715. LOG( tDATA->mrl );
  716. m_pSource = new videoAVLIBSource( tDATA->mrl );
  717. } else {
  718. char tMRL[1024];
  719. DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
  720. if( tCAM ) {
  721. sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
  722. free( tCAM );
  723. LOG( tMRL );
  724. m_sMediaSource.mediaStreamId = id;
  725. m_pSource = new videoAVLIBSource( tMRL, &m_sMediaSource );
  726. };
  727. };
  728. if( m_pSource != NULL ) {
  729. LOG("Source OK");
  730. m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
  731. LOG("Finish!");
  732. m_bSourceConnected = true;
  733. free( tDATA );
  734. return true;
  735. } else {
  736. LOG_ERROR("Video Source Stream Failure!");
  737. };
  738. free( tDATA );
  739. };
  740. } else {
  741. #ifdef DEBUG
  742. LOG("No Video Module!");
  743. #endif
  744. return true;
  745. };
  746. };
  747. return false;
  748. };
  749. bool ARGUS_Camera::disconnectFromStream( void ){
  750. if( m_bSourceConnected ) {
  751. if( m_pSource ){
  752. delete( m_pSource );
  753. m_pSource = NULL;
  754. };
  755. m_bSourceConnected = false;
  756. };
  757. return !m_bSourceConnected;
  758. };
  759. #undef LOG
  760. #undef LOG_ERROR