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.

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