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.

1497 lines
56 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
4 years ago
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
  1. #include "deviceNodeCamera.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 "hardwareManager.h"
  10. #include "hardwareResourceSerialProvider.h"
  11. //#include "rgooseModuleEmbedVideo.h"
  12. #define LOG( X ) deviceNode::m_pLog->Log( "RCAM", this, X )
  13. #ifdef DEBUG
  14. #define LOG_ERROR( X ) {\
  15. char _tBfrErrMSG2w34[256];\
  16. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  17. deviceNode::m_pLog->Log( "RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  18. }
  19. #else
  20. #define LOG_ERROR( X ) deviceNode::m_pLog->Log( "RCAM", this, _LOG_ERROR, X );
  21. #endif
  22. // all sizes in mm
  23. static const 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 };
  24. static const 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 };
  25. static const 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 };
  26. #define CAM_FOCAL_LENGTH_CNT 49
  27. static const float cam_predef_focal_length[CAM_FOCAL_LENGTH_CNT]={
  28. 2.7f,
  29. 3.0f,
  30. 3.2f,
  31. 3.5f,
  32. 3.7f,
  33. 3.9f,
  34. 4.0f,
  35. 4.3f,
  36. 4.8f,
  37. 5.0f,
  38. 5.1f,
  39. 5.5f,
  40. 5.8f,
  41. 6.0f,
  42. 6.2f,
  43. 6.6f,
  44. 7.0f,
  45. 7.1f,
  46. 7.5f,
  47. 7.6f,
  48. 8.0f,
  49. 8.6f,
  50. 8.9f,
  51. 9.0f,
  52. 9.2f,
  53. 9.3f,
  54. 10.0f,
  55. 10.5f,
  56. 10.6f,
  57. 10.7f,
  58. 11.0f,
  59. 11.3f,
  60. 12.0f,
  61. 12.9f,
  62. 13.0f,
  63. 13.5f,
  64. 13.6f,
  65. 14.0f,
  66. 14.6f,
  67. 15.0f,
  68. 15.1f,
  69. 15.5f,
  70. 16.0f,
  71. 17.0f,
  72. 17.5f,
  73. 17.7f,
  74. 18.0f,
  75. 18.2f,
  76. 19.0f
  77. };
  78. deviceNodeCamera::deviceNodeCamera( uint32_t NodeID ): deviceNode( NodeID ), basicThread(){
  79. //m_pLog = basicLogCollection::getInstance();
  80. m_pBEH = basicEventHeap::getInstance();
  81. m_tTimeTSeconds = 0;
  82. m_pProtocol = NULL;
  83. m_pTransport = NULL;
  84. m_pCurrentROI = NULL;
  85. m_nRealFrameWidth = 640;
  86. //m_bState = 0;
  87. //m_bBusy = true;
  88. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  89. m_nRelativeMoveCounter = 0;
  90. m_bRelativeMoveMatrix = 0;
  91. m_fSpeedRise = 0.03f;
  92. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  93. //m_bSourceConnected = false;
  94. //m_pSource = NULL;
  95. };
  96. deviceNodeCamera::deviceNodeCamera( DBC_NODE_DATA *Data ): deviceNode( Data ), basicThread(){
  97. //m_pLog = basicLogCollection::getInstance();
  98. m_pBEH = basicEventHeap::getInstance();
  99. m_tTimeTSeconds = 0;
  100. m_pProtocol = NULL;
  101. m_pTransport = NULL;
  102. m_pCurrentROI = NULL;
  103. m_nRealFrameWidth = 640;
  104. //m_bState = 0;
  105. //m_bBusy = true;
  106. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  107. m_nRelativeMoveCounter = 0;
  108. m_bRelativeMoveMatrix = 0;
  109. m_fSpeedRise = 0.03f;
  110. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  111. //m_bSourceConnected = false;
  112. //m_pSource = NULL;
  113. };
  114. deviceNodeCamera::~deviceNodeCamera(){
  115. LOG("Destruct");
  116. //m_mQPROTECTOR.unlock();
  117. waitThreadEnd( true );
  118. LOG("Thread Del OK");
  119. if( m_pTransport!= NULL ) {
  120. if( m_sCamData.uart_id ) {
  121. DBC_UART_DATA *tData = NULL;
  122. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  123. switch( tData->type ) {
  124. case UART_TYPE_HARDWARE:{
  125. delete((serialPort*)m_pTransport);
  126. break;
  127. };
  128. case UART_TYPE_SOL:{
  129. delete((serialSOL*)m_pTransport);
  130. break;
  131. };
  132. };
  133. }
  134. };
  135. LOG("Transport Del OK");
  136. if( m_pProtocol != NULL ) {
  137. switch( m_sCamData.protocol ) {
  138. case CAM_CTRL_PROTO_VISCA:
  139. delete( (protocolPTZ_VISCA *) m_pProtocol );
  140. break;
  141. case CAM_CTRL_PROTO_PELCO:
  142. delete( (protocolPTZ_PELCO *) m_pProtocol );
  143. break;
  144. case CAM_CTRL_PROTO_ONVIF:
  145. delete( (protocolPTZ_ONVIF *) m_pProtocol );
  146. break;
  147. default:
  148. delete( m_pProtocol );
  149. };
  150. };
  151. LOG("Proto Del OK");
  152. //if( m_pPosition != NULL ) delete( m_pPosition );
  153. //LOG("Pos Del OK");
  154. //if( m_bSourceConnected ){
  155. // if( m_pSource != NULL ){
  156. // m_pSource->_close();
  157. // delete( m_pSource );
  158. // };
  159. //};
  160. //LOG("Stream Del OK");
  161. };
  162. void deviceNodeCamera::updateOpticalParameters( uint16_t frame_width, uint16_t frame_heigth ){
  163. #ifdef DEBUG
  164. char tB[128];
  165. #endif
  166. if( frame_width > 0 && frame_heigth > 0 ) {
  167. m_nRealFrameWidth = frame_width;
  168. m_nRealFrameHeight = frame_heigth;
  169. float tFrameDiag = sqrtf( m_nRealFrameHeight*m_nRealFrameHeight+m_nRealFrameWidth*m_nRealFrameWidth );
  170. switch( m_sCamData.zoom_model ) {
  171. case 0:{
  172. // Fixed Zoom
  173. m_fMaxFL = m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  174. m_fMinRange = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag );
  175. m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag );
  176. m_fR2FL = .0f;
  177. break;
  178. };
  179. case 1:{
  180. m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  181. m_fMinRange = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag );
  182. m_fMaxFL = cam_predef_focal_length[m_sCamData.lens_f] * m_sCamData.zoom;
  183. m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag );
  184. if( m_fMaxRange > m_fMinRange ){
  185. m_fR2FL = ((m_fMaxFL - m_fMinFL) / (m_fMaxRange - m_fMinRange));
  186. } else {
  187. m_fR2FL = .0f;
  188. };
  189. break;
  190. };
  191. };
  192. m_pDBC->updateCamRange( m_sCamData.id, m_fMaxRange );
  193. m_fMinHFov = rad2deg(calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_fMinFL ));
  194. m_fMaxHFov = rad2deg(calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_fMaxFL ));
  195. m_fMinVFov = rad2deg(calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_fMinFL ));
  196. m_fMaxVFov = rad2deg(calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_fMaxFL ));
  197. #ifdef DEBUG
  198. LOG("Set Optical Parameters");
  199. sprintf( tB, "\tCapturing Frame: %dx%d ", frame_width, frame_heigth );
  200. LOG(tB);
  201. sprintf( tB, "\tMinimal FL: %0.3fmm. Maximal FL: %0.3fmm. ", m_fMinFL, m_fMaxFL );
  202. LOG(tB);
  203. sprintf( tB, "\tMinimal Range: %0.2fm. Maximal Range: %0.2fm. ", m_fMinRange, m_fMaxRange );
  204. LOG(tB);
  205. sprintf( tB, "\tMaximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov );
  206. LOG(tB);
  207. sprintf( tB, "\tMinimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov );
  208. LOG(tB);
  209. #endif
  210. };
  211. };
  212. bool deviceNodeCamera::create(){
  213. setWM( CAM_WS_INIT );
  214. if( m_sNodeData.aux_id == 0 ) return false;
  215. DBC_CAM_DATA * tData = m_pDBC->getCamData( m_sNodeData.aux_id );
  216. if( tData != NULL ) {
  217. memcpy( &m_sCamData, tData, sizeof(DBC_CAM_DATA) );
  218. free( tData );
  219. } else {
  220. LOG_ERROR("Cannot Fetch CAM Data from Database!");
  221. return false;
  222. };
  223. if( !( m_sCamData.lens_f < CAM_FOCAL_LENGTH_CNT ) ) m_sCamData.lens_f = CAM_FOCAL_LENGTH_CNT - 1;
  224. updateOpticalParameters( 640,480 );
  225. if( m_sCamData.ptz_speed_step > .0f ) {
  226. m_fSpeedRise = m_sCamData.ptz_speed_step;
  227. };
  228. //m_pPosition = new basicPosition();// m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
  229. //if( m_pPosition == NULL ) {
  230. // LOG_ERROR("Position Constructor Failure!");
  231. // return false;
  232. //};
  233. //m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z );
  234. //m_oPosition.setOrientationDeg( m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot );
  235. systemAnchor * SA = systemAnchor::getInstance();
  236. if( SA ){
  237. LOG("SysAnchor OK");
  238. if ( SA->beLocal() ) {
  239. LOG("SysAnchor beLocal!");
  240. m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z, 0 ); //SA->getUTMZone() );
  241. m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
  242. } else {
  243. LOG("SysAnchor is Global Position System!");
  244. C3D_DECART LD = SA->getXYZ();
  245. m_oPosition.setPositionXYZ( LD.x + m_sCamData.x, LD.y + m_sCamData.y, LD.z + m_sCamData.z, SA->getUTMZone() );
  246. m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
  247. };
  248. } else {
  249. LOG("No SysAnchor!");
  250. m_oPosition.setPositionXYZ( m_sCamData.x , m_sCamData.y, m_sCamData.z );
  251. m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
  252. };
  253. m_oPosition.updateMatrix();
  254. #ifdef DEBUG
  255. char tB[128];
  256. sprintf( tB, "Finalized Camera Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
  257. LOG( tB );
  258. sprintf( tB, "Finalized Camera Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() );
  259. LOG( tB );
  260. sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() );
  261. LOG( tB );
  262. #endif
  263. if( m_pProtocol != NULL ){
  264. LOG_ERROR("Cannot Start: Service Already Running!");
  265. return false;
  266. };
  267. switch( m_sCamData.protocol ){
  268. case CAM_CTRL_PROTO_VISCA: {
  269. #ifdef DEBUG
  270. LOG("VISCA");
  271. #endif
  272. m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA( m_sCamData.protocol_aux );
  273. if( m_pProtocol!= NULL ) {
  274. basicTransport *tTransport = NULL;
  275. hardwareManager *tHM = hardwareManager::getInstance();
  276. if( tHM ){
  277. hardwareResource *tRES = tHM->requestResource( HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id );
  278. if( tRES != NULL ) {
  279. if( tRES->isValid()) {
  280. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  281. if( m_pProtocol->setTransport( tTransport )){
  282. if( !m_pProtocol->create() ){
  283. LOG_ERROR("Protocol <<< Create >>> Failure!");
  284. };
  285. } else {
  286. LOG_ERROR("Binding Port Failure!");
  287. };
  288. };
  289. #ifdef DEBUG
  290. } else {
  291. LOG("HWM Has No UART PORT!");
  292. #endif
  293. };
  294. #ifdef DEBUG
  295. } else {
  296. LOG_ERROR("Can not get Hardware Manager!");
  297. #endif
  298. };
  299. if( tTransport!= NULL ) {
  300. LOG( "Bind Transport Port!" );
  301. } else {
  302. LOG_ERROR("Transport Creation Failure!");
  303. delete( ( protocolPTZ_VISCA * )m_pProtocol );
  304. m_pProtocol = NULL;
  305. };
  306. #ifdef DEBUG
  307. } else {
  308. LOG_ERROR("Protocol Creation failure!");
  309. #endif
  310. };
  311. break;
  312. };
  313. case CAM_CTRL_PROTO_PELCO:{
  314. #ifdef DEBUG
  315. LOG("PELCO");
  316. #endif
  317. m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO( m_sCamData.protocol_aux );
  318. if( m_pProtocol!= NULL ) {
  319. basicTransport *tTransport = NULL;
  320. hardwareManager *tHM = hardwareManager::getInstance();
  321. if ( tHM ) {
  322. hardwareResource * tRES = tHM->requestResource( HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id );
  323. if( tRES != NULL ) {
  324. if( tRES->isValid()) {
  325. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  326. if( m_pProtocol->setTransport( tTransport )){
  327. if( !m_pProtocol->create() ){
  328. LOG_ERROR("Protocol <<< Create >>> Failure!");
  329. };
  330. } else {
  331. LOG_ERROR("Binding Port Failure!");
  332. };
  333. };
  334. #ifdef DEBUG
  335. } else {
  336. LOG("HWM Has No UART PORT!");
  337. #endif
  338. };
  339. #ifdef DEBUG
  340. } else {
  341. LOG_ERROR("Can not get Hardware Manager!");
  342. #endif
  343. };
  344. if( tTransport!= NULL ) {
  345. LOG( "Bind Transport Port!" );
  346. } else {
  347. LOG_ERROR("Transport Creation Failure!");
  348. delete( ( protocolPTZ_PELCO * )m_pProtocol );
  349. m_pProtocol = NULL;
  350. };
  351. #ifdef DEBUG
  352. } else {
  353. LOG_ERROR("Protocol Creation failure!");
  354. #endif
  355. };
  356. break;
  357. };
  358. case CAM_CTRL_PROTO_ONVIF:{
  359. #ifdef DEBUG
  360. LOG("ONVIF");
  361. #endif
  362. //m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  363. if( strstr( m_sCamData.onvif_ctrl, "http" ) == NULL ) {
  364. char tURI[256];
  365. if ( m_sCamData.port ) {
  366. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  367. } else {
  368. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  369. };
  370. m_pProtocol = (protocolPTZ *)new protocolPTZ_ONVIF( tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  371. } else {
  372. m_pProtocol = (protocolPTZ *)new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  373. }
  374. if( m_pProtocol!=NULL ) {
  375. if( !m_pProtocol->create() ) {
  376. LOG_ERROR("Error Creating Proto!");
  377. delete( (protocolPTZ_ONVIF*) m_pProtocol );
  378. m_pProtocol = NULL;
  379. };
  380. };
  381. break;
  382. };
  383. default:{
  384. #ifdef DEBUG
  385. LOG("Camera Has no defined control protocol");
  386. #endif
  387. };
  388. };
  389. if( m_pProtocol == NULL ) {
  390. if( m_sCamData.protocol == 0 ) {
  391. m_sCamData.online = true;
  392. } else LOG_ERROR("No Proto Created!");
  393. } else {
  394. #ifdef DEBUG
  395. LOG("Proto is OK");
  396. #endif
  397. m_sCamData.online = init();
  398. };
  399. m_pDBC->updateCamOnlineStatus( m_sCamData.id, m_sCamData.online );
  400. return m_sCamData.online;
  401. };
  402. //void deviceNodeCamera::setBusy( bool Status ){
  403. //m_bBusy = Status;
  404. //};
  405. bool deviceNodeCamera::relativeMove( float PanSPD, float TiltSPD, float ZoomSPD ){
  406. if( m_sCamData.online ) {
  407. uint32_t MoveMatrix = 0;
  408. if( PanSPD != .0f ){
  409. if( PanSPD > 0 ) {
  410. MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
  411. } else {
  412. MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
  413. };
  414. };
  415. if( TiltSPD != .0f ){
  416. if( TiltSPD > 0 ) {
  417. MoveMatrix |= PTZ_DRIVE_TILT_UP;
  418. } else {
  419. MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
  420. };
  421. };
  422. if( ZoomSPD != .0f ){
  423. if( ZoomSPD > 0 ) {
  424. MoveMatrix |= PTZ_DRIVE_ZOOM_WIDE;
  425. } else {
  426. MoveMatrix |= PTZ_DRIVE_ZOOM_TELE;
  427. };
  428. };
  429. if( MoveMatrix != 0 ) {
  430. m_pProtocol->setPTZSpeed( fabs(PanSPD), fabs(TiltSPD), fabs(ZoomSPD) );
  431. };
  432. return m_pProtocol->move( MoveMatrix );
  433. };
  434. return false;
  435. };
  436. bool deviceNodeCamera::relativeStop(){
  437. if( m_sCamData.online ) {
  438. return m_pProtocol->move( 0 );
  439. };
  440. return false;
  441. };
  442. CAM_TASK *deviceNodeCamera::fetchCamTask( void ){
  443. CAM_TASK *rVal = NULL;
  444. m_mQPROTECTOR.lock();
  445. if (m_qCAM_TASK.size()) {
  446. rVal = m_qCAM_TASK.front();
  447. m_qCAM_TASK.pop();
  448. };
  449. m_mQPROTECTOR.unlock();
  450. return rVal;
  451. };
  452. bool deviceNodeCamera::pushCamTask( CAM_TASK *ptr ){
  453. if ( ptr == NULL ) return false;
  454. m_mQPROTECTOR.lock();
  455. m_qCAM_TASK.push( ptr );
  456. m_mQPROTECTOR.unlock();
  457. return true;
  458. };
  459. bool deviceNodeCamera::fusion_compare( CAM_ROI *ptr, C3D_SPH_DEGREES tp ){
  460. if( ptr == NULL ) return false;
  461. float tFI = fabsf( ptr->cam_position.fi - tp.fi );
  462. float tTETTA = fabsf( ptr->cam_position.tetta - tp.tetta );
  463. #ifdef DEBUG
  464. char tB[128];
  465. sprintf(tB,"FC: FOV:[%.5f:%.5f] dTG:[%.5f:%.5f] %.2f<%.2f>%.2f",ptr->h_fov ,ptr->v_fov, tFI, tTETTA, ptr->min_range, tp.r, ptr->max_range );
  466. LOG(tB);
  467. #endif
  468. if( tFI > ptr->h_fov ) return false;
  469. if( tTETTA > ptr->v_fov ) return false;
  470. if( tp.r < ptr->min_range ) return false;
  471. if( tp.r > ptr->max_range ) return false;
  472. return true;
  473. };
  474. bool deviceNodeCamera::fusion_consumeData( uint32_t db_id, C3D_SPH_DEGREES tOR ){
  475. if( db_id == 0 ) return false;
  476. CAM_TRACK_RECORD * tTrackRecords = (CAM_TRACK_RECORD * ) malloc( sizeof(CAM_TRACK_RECORD));
  477. if( tTrackRecords == NULL ) return false;
  478. #ifdef DEBUG
  479. LOG("Fusion: Consuming new Data!");
  480. #endif
  481. memset(tTrackRecords, 0, sizeof(CAM_TRACK_RECORD));
  482. tTrackRecords->target_direction.fi = tOR.fi;
  483. tTrackRecords->target_direction.r = tOR.r;
  484. tTrackRecords->target_direction.tetta = tOR.tetta;
  485. tTrackRecords->evt_db_ID = db_id;
  486. tTrackRecords->ts_ms = getMilliseconds();
  487. m_mROIsProtector.lock();
  488. if( m_vROIS.size() ){
  489. vCAM_ROIS::iterator idx = m_vROIS.begin();
  490. for( ; idx < m_vROIS.end(); idx++ ) if ( fusion_compare( *idx, tOR ) ) break;
  491. if ( idx != m_vROIS.end() ) {
  492. // have Match!
  493. LOG("ROI MATCHED!");
  494. (*idx)->targets.push_back( tTrackRecords );
  495. fusion_validateROI( tTrackRecords->ts_ms, (*idx) );
  496. } else {
  497. LOG("NO MATCH FOUND!");
  498. // No mathced ROI -> create new one
  499. CAM_ROI * tROI = (CAM_ROI *)malloc(sizeof(CAM_ROI));
  500. if ( tROI ) {
  501. memset( tROI, 0 , sizeof(CAM_ROI) );
  502. tROI->ts_ms = tTrackRecords->ts_ms;
  503. spherical2onvif( tOR, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  504. tROI->cam_position.fi = tOR.fi;
  505. tROI->cam_position.tetta = tOR.tetta;
  506. tROI->cam_position.r = tOR.r;
  507. float cFL = m_fMinFL + m_fR2FL * ( tROI->cam_position.r - m_fMinRange );
  508. tROI->max_range = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  509. tROI->min_range = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  510. tROI->h_fov = rad2deg( calcFOV_mm( AC_imager_width[m_sCamData.imager_type], cFL ) ) / 2.0f; // div to no to div in comparation function
  511. tROI->v_fov = rad2deg( calcFOV_mm( AC_imager_height[m_sCamData.imager_type], cFL ) ) / 2.0f; // that will be called more ofthen
  512. tROI->targets.push_back( tTrackRecords );
  513. m_vROIS.push_back( tROI );
  514. };
  515. };
  516. } else {
  517. // empty ROIs -> create new one
  518. CAM_ROI * tROI = (CAM_ROI *)malloc(sizeof(CAM_ROI));
  519. if ( tROI ) {
  520. memset( tROI, 0 , sizeof(CAM_ROI) );
  521. tROI->ts_ms = tTrackRecords->ts_ms;
  522. //Set vector Cam Coordinates
  523. tROI->cam_position.fi = tOR.fi;
  524. tROI->cam_position.tetta = tOR.tetta;
  525. tROI->cam_position.r = tOR.r;
  526. // Set vector OnVIF coordinates
  527. spherical2onvif( tOR, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  528. // make fusion data BOX
  529. float cFL = m_fMinFL + m_fR2FL * ( tROI->cam_position.r );// - m_fMinRange );
  530. tROI->min_range = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  531. tROI->max_range = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  532. tROI->h_fov = rad2deg( calcFOV_mm( AC_imager_width[m_sCamData.imager_type], cFL ) )/ 2.0f; // div to prevent division in comparation
  533. tROI->v_fov = rad2deg( calcFOV_mm( AC_imager_height[m_sCamData.imager_type], cFL ) )/ 2.0f; // function that will be called more ofthen
  534. // Add ROI to vector
  535. tROI->targets.push_back( tTrackRecords );
  536. m_vROIS.push_back( tROI );
  537. };
  538. };
  539. m_mROIsProtector.unlock();
  540. return true;
  541. };
  542. bool deviceNodeCamera::fusion_validateROI( uint64_t cts, CAM_ROI *ptr ){
  543. if( ptr == NULL ) return false;
  544. if( (cts - ptr->ts_ms) > LOSE_INTERES_TIME_MS ) return false;
  545. #ifdef DEBUG_EXTRA
  546. char tB[128];
  547. sprintf( tB, "\tROI [%d]", ptr->targets.size() );
  548. LOG( tB );
  549. #endif
  550. if( ptr->targets.size() ) {
  551. double tA = 0.0;
  552. double tB = 0.0;
  553. double tC = 0.0;
  554. uint32_t tCNT = 0;
  555. for( vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end(); idx++ ) {
  556. if( ( cts - (*idx)->ts_ms ) > LOSE_INTERES_TIME_MS ) {
  557. free( (*idx) );
  558. ptr->targets.erase( idx );
  559. } else {
  560. tA = tA + (*idx)->target_direction.fi;
  561. tB = tB + (*idx)->target_direction.tetta;
  562. tC = tC + (*idx)->target_direction.r;
  563. tCNT++;
  564. };
  565. };
  566. if( tCNT ) {
  567. C3D_SPH_DEGREES L = { 0 };
  568. L.fi = (float) ( tA /(double) tCNT );
  569. L.tetta = (float) ( tB /(double) tCNT );
  570. L.r = (float) ( tC /(double) tCNT );
  571. spherical2onvif(L, ptr->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  572. ptr->ts_ms = cts;
  573. float cFL = m_fMinFL + m_fR2FL * ( ptr->cam_position.r - m_fMinRange );
  574. ptr->max_range = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  575. ptr->min_range = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  576. ptr->h_fov = rad2deg( calcFOV_mm(AC_imager_width[m_sCamData.imager_type], cFL) )/ 2.0f; // div to prevent division in comparation
  577. ptr->v_fov = rad2deg( calcFOV_mm( AC_imager_height[m_sCamData.imager_type], cFL ) )/ 2.0f; // function that will be called more ofthen
  578. return true;
  579. };
  580. };
  581. return false;
  582. };
  583. CAM_ROI *deviceNodeCamera::fusion_fetchROI( void ){
  584. CAM_ROI *tVAL = NULL;
  585. uint64_t cts = 0;
  586. m_mROIsProtector.lock();
  587. vCAM_ROIS::iterator sRec;
  588. if( m_vROIS.size() ){
  589. for( vCAM_ROIS::iterator idx = m_vROIS.begin(); idx < m_vROIS.end(); idx++ ){
  590. if ( tVAL == NULL ) {
  591. sRec = idx;
  592. tVAL = (*idx);
  593. cts = tVAL->ts_ms;
  594. } else {
  595. #ifdef CAM_FETCH_ROI_NEWEST
  596. if ( (*idx)->ts_ms > cts )
  597. #else
  598. if ( (*idx)->ts_ms < cts )
  599. #endif
  600. {
  601. sRec = idx;
  602. tVAL = (*idx);
  603. cts = tVAL->ts_ms;
  604. };
  605. };
  606. };
  607. m_vROIS.erase( sRec );
  608. };
  609. m_mROIsProtector.unlock();
  610. return tVAL;
  611. };
  612. DBC_SNAPSHOT_DATA *deviceNodeCamera::fusion_translate_ROI( CAM_ROI *(&ptr) ){
  613. DBC_SNAPSHOT_DATA *rVal = NULL;
  614. if( ptr == NULL ) return NULL;
  615. if( ptr->targets.size() ){
  616. //if( m_bSourceConnected ){
  617. rVal = (DBC_SNAPSHOT_DATA *)malloc(sizeof(DBC_SNAPSHOT_DATA));
  618. if( rVal ){
  619. memset( rVal, 0, sizeof(DBC_SNAPSHOT_DATA) );
  620. //rVal->stream_id = m_nActiveStreamID;
  621. rVal->stream_id = m_sNodeData.aux_parameter;
  622. for( vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end(); idx++ ) {
  623. rVal->assoc_event_ids.push_back( (*idx)->evt_db_ID );
  624. };
  625. };
  626. //};
  627. ptr->targets.clear();
  628. };
  629. // Destruct ROI MEM
  630. delete( (CAM_ROI *) ptr );
  631. ptr = NULL;
  632. // Not Setting MD5 and TS -> will set at capture time
  633. return rVal;
  634. };
  635. void deviceNodeCamera::fusion_validate( void ){
  636. m_mROIsProtector.lock();
  637. if( m_vROIS.size() ){
  638. #ifdef DEBUG_EXTRA
  639. char tB[128];
  640. sprintf( tB, "Fusion: Have [%d] Regions Of Interes", m_vROIS.size() );
  641. LOG( tB );
  642. #endif
  643. uint64_t cts = getMilliseconds();
  644. for( vCAM_ROIS::iterator idx = m_vROIS.begin(); idx < m_vROIS.end(); idx++ ){
  645. if( !fusion_validateROI( cts, *idx ) ) {
  646. free( (*idx) );
  647. m_vROIS.erase( idx );
  648. };
  649. };
  650. };
  651. m_mROIsProtector.unlock();
  652. };
  653. bool deviceNodeCamera::absoluteMove( uint32_t TargetRefID, float PanPOS, float TiltPOS, float ZoomPOS ){
  654. if( m_sCamData.online ){
  655. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  656. if( tTask ){
  657. memset(tTask, 0, sizeof(CAM_TASK));
  658. tTask->CMD = (CAM_PTZ_CMD *)malloc(sizeof(CAM_PTZ_CMD));
  659. if( tTask->CMD ){
  660. tTask->CMD->CMD = PTZ_ABSOLUTE;
  661. tTask->CMD->PAN = PanPOS;
  662. tTask->CMD->TILT = TiltPOS;
  663. tTask->CMD->ZOOM = ZoomPOS;
  664. tTask->movemet_needed = true;
  665. tTask->source_evt_id = TargetRefID;
  666. setWM( CAM_WS_BUSY );
  667. return pushCamTask( tTask );
  668. } else {
  669. LOG_ERROR("CMD malloc Error!");
  670. free( tTask );
  671. };
  672. } else {
  673. LOG_ERROR("Task malloc error!");
  674. };
  675. };
  676. return false;
  677. };
  678. bool deviceNodeCamera::absoluteMove( uint32_t TargetRefID, C3D_ORIENT_ONVIF O ){
  679. if( m_sCamData.online ){
  680. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  681. if( tTask ){
  682. memset(tTask, 0, sizeof(CAM_TASK));
  683. tTask->CMD = (CAM_PTZ_CMD *)malloc(sizeof(CAM_PTZ_CMD));
  684. if( tTask->CMD ){
  685. tTask->CMD->CMD = PTZ_ABSOLUTE;
  686. tTask->CMD->PAN = O.pan;
  687. tTask->CMD->TILT = O.tilt;
  688. tTask->CMD->ZOOM = O.zoom;
  689. tTask->movemet_needed = true;
  690. tTask->source_evt_id = TargetRefID;
  691. setWM( CAM_WS_BUSY );
  692. return pushCamTask( tTask );
  693. } else {
  694. LOG_ERROR("CMD malloc Error!");
  695. free( tTask );
  696. };
  697. } else {
  698. LOG_ERROR("Task malloc error!");
  699. };
  700. };
  701. return false;
  702. };
  703. void deviceNodeCamera::m_fThreadProc( void ){
  704. DBC_PUSHED_CMD * PUSHED = NULL;
  705. m_bThreadStatus = TH_WORKING;
  706. bool bNewSecondLoop = false;
  707. uint32_t cTimeSeconds = 0;
  708. uint32_t oTimeSeconds = 0;
  709. while( m_bThreadStatus < TH_ENDED ) {
  710. cTimeSeconds = (uint32_t) time( NULL );
  711. if ( bNewSecondLoop = ( cTimeSeconds != oTimeSeconds ) ) oTimeSeconds = cTimeSeconds;
  712. uint8_t tState = getWM();
  713. char tB[128];
  714. fusion_validate();
  715. switch( tState ) {
  716. case CAM_WS_INIT:{
  717. #ifdef DEBUG
  718. LOG("Init Camera - PowerMode");
  719. #endif
  720. //setBusy( true );
  721. if( m_pProtocol->initCamera() ) setWM( CAM_WS_WHITE_BALLANCE );
  722. //setBusy( false );
  723. break;
  724. };
  725. case CAM_WS_WHITE_BALLANCE:{
  726. #ifdef DEBUG
  727. LOG("Set WB");
  728. #endif
  729. //setBusy( true );
  730. if( m_pProtocol->setWhiteBalanceMode( WB_AUTO ) ) setWM( CAM_WS_BACKLIGHT );
  731. //setBusy( false );
  732. break;
  733. };
  734. case CAM_WS_BACKLIGHT:{
  735. #ifdef DEBUG
  736. LOG("Set BLC");
  737. #endif
  738. //setBusy( true );
  739. if( m_pProtocol->setBackLightMode( true ) ) setWM( CAM_WS_AUTO_FOCUS );
  740. //setBusy( false );
  741. break;
  742. };
  743. case CAM_WS_AUTO_FOCUS:{
  744. #ifdef DEBUG
  745. LOG("Set AF");
  746. #endif
  747. //setBusy( true );
  748. if( m_pProtocol->setAutoFocus( true ) ) setWM( CAM_WS_INIT_GO_HOME );
  749. //setBusy( false );
  750. break;
  751. };
  752. case CAM_WS_INIT_GO_HOME:{
  753. #ifdef DEBUG
  754. LOG("INIT GO -1 0 -1");
  755. #endif
  756. m_nHomingCounter = 0;
  757. if( m_pProtocol->goAbsolute( -1, 0, -1 ) ) {
  758. m_fCP_Pan = -1;
  759. m_fCP_Tilt = 0;
  760. m_fCP_Zoom = -1;
  761. setWM( CAM_WS_READY );
  762. };
  763. break;
  764. };
  765. case CAM_WS_AUTOMATED_MOVE:{
  766. m_nRelativeMoveCounter++;
  767. if( ( m_bRelativeMoveMatrix & 0x03 ) != 0 ) {
  768. //Pan Move
  769. if( ( m_bRelativeMoveMatrix & 0x01 ) == 0 ) {
  770. m_fRM_Pan -= m_fSpeedRise;
  771. } else {
  772. m_fRM_Pan += m_fSpeedRise;
  773. };
  774. };
  775. if( ( m_bRelativeMoveMatrix & 0x0C ) != 0 ) {
  776. //TILT Move
  777. if( ( m_bRelativeMoveMatrix & 0x04 ) == 0 ) {
  778. m_fRM_Tilt -= m_fSpeedRise;
  779. } else {
  780. m_fRM_Tilt += m_fSpeedRise;
  781. }
  782. };
  783. if( ( m_bRelativeMoveMatrix & 0x30 ) != 0 ) {
  784. //ZOOM Move
  785. if( ( m_bRelativeMoveMatrix & 0x10 ) == 0 ) {
  786. //Wide
  787. m_fRM_Zoom -= m_fSpeedRise;
  788. } else {
  789. //Tele
  790. m_fRM_Zoom += m_fSpeedRise;
  791. };
  792. };
  793. if( m_fRM_Pan < -1.0f ) m_fRM_Pan = -1.0f;
  794. if( m_fRM_Pan > 1.0f ) m_fRM_Pan = 1.0f;
  795. if( m_fRM_Tilt < -1.0f ) m_fRM_Tilt = -1.0f;
  796. if( m_fRM_Tilt > 1.0f ) m_fRM_Tilt = 1.0f;
  797. if( m_fRM_Zoom < -1.0f ) m_fRM_Zoom = -1.0f;
  798. if( m_fRM_Zoom > 1.0f ) m_fRM_Zoom = 1.0f;
  799. m_fCP_Zoom += 0.5f*m_fRM_Zoom;
  800. if( m_fCP_Zoom < -1.0f ) m_fCP_Zoom = -1.0f;
  801. if( m_fCP_Zoom > 1.0f ) m_fCP_Zoom = 1.0f;
  802. if( !relativeMove( m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom ) ){
  803. m_nRelativeMoveCounter = 0;
  804. setWM( CAM_WS_READY );
  805. break;
  806. };
  807. if( m_sCamData.ptz_axel ) { //Manual
  808. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel) {
  809. m_nRelativeMoveCounter = 0;
  810. setWM( CAM_WS_READY );
  811. };
  812. } else {
  813. // Stepping Axel by Zoom
  814. uint8_t tVal = (uint8_t)( 10.0f * ( 2.0f - ( 1.0f + m_fCP_Zoom ) ));
  815. if( m_nRelativeMoveCounter > tVal ) {
  816. m_nRelativeMoveCounter = 0;
  817. setWM( CAM_WS_READY );
  818. };
  819. };
  820. break;
  821. };
  822. case CAM_WS_STOP_MOVE:{
  823. m_nRelativeMoveCounter++;
  824. m_fRM_Pan = .0f;
  825. m_fRM_Pan = .0f;
  826. m_fRM_Tilt = .0f;
  827. m_fRM_Tilt = .0f;
  828. m_fRM_Zoom = .0f;
  829. m_fRM_Zoom = .0f;
  830. if( relativeStop() ) {
  831. m_nHomingCounter = 0;
  832. m_nRelativeMoveCounter = 0;
  833. setWM( CAM_WS_READY );
  834. break;
  835. };
  836. if( m_sCamData.ptz_axel ) {
  837. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel) setWM(CAM_WS_READY);
  838. } else {
  839. uint8_t tVal = (uint8_t)( 10.0f * ( 2.0f - ( 1.0f + m_fCP_Zoom ) ));
  840. if (m_nRelativeMoveCounter > tVal) setWM(CAM_WS_READY);
  841. };
  842. break;
  843. };
  844. case CAM_WS_GO_ABS_ROI:
  845. case CAM_WS_GO_ABS_POSITION:{
  846. setWM( CAM_WS_BUSY );
  847. if( m_pCurrentROI != NULL ){
  848. m_nHomingCounter = 0;
  849. if( m_pBEH ){
  850. EVENT_CONTAINER *tEVT = createBasicEvent(
  851. m_sNodeData.node_id,
  852. EVT_CLASS_CAMERA_CTRL,
  853. EVT_CAMERA_MOVE_TO,
  854. NULL, NULL, NULL );
  855. if( tEVT ){
  856. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  857. LOG("BCAST CAM GOTO");
  858. m_pBEH->broadcast( tEVT );
  859. };
  860. };
  861. //update position Info
  862. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  863. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  864. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  865. // Do Movement
  866. if( !m_pProtocol->goAbsolute(
  867. m_pCurrentROI->cam_orientation.pan,
  868. m_pCurrentROI->cam_orientation.tilt,
  869. m_pCurrentROI->cam_orientation.zoom
  870. )){
  871. LOG_ERROR("Cannot Issue goAbsolute Command!");
  872. setWM( CAM_WS_READY );
  873. } else {
  874. // Send Capture event
  875. DBC_SNAPSHOT_DATA *tData = fusion_translate_ROI( m_pCurrentROI );
  876. if( tData != NULL ) {
  877. if( m_pBEH ){
  878. EVENT_CONTAINER *tEVT = createBasicEvent(
  879. m_sNodeData.node_id,
  880. EVT_CLASS_CAMERA_CTRL,
  881. EVT_CAMERA_ON_POSITION,
  882. NULL, NULL, tData );
  883. if( tEVT ){
  884. LOG("BCAST CAM ONPOS");
  885. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  886. m_pBEH->broadcast( tEVT );
  887. };
  888. };
  889. };
  890. // Waiting capture finish
  891. //setWM( CAM_WS_BUSY );
  892. };
  893. utilizeROI( m_pCurrentROI );
  894. } else setWM( CAM_WS_READY );
  895. break;
  896. };
  897. case CAM_WS_GO_HOMING_PRESET:{
  898. if( m_sCamData.home_token[0] != (char)0 ) {
  899. //LOG( m_sCamData.home_token );
  900. if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  901. LOG_ERROR("Cannot Issue goPreset Command!");
  902. };
  903. };
  904. setWM( CAM_WS_READY );
  905. break;
  906. };
  907. case CAM_WS_BUSY:{
  908. //Handle Operation TO
  909. setWM( CAM_WS_READY );
  910. break;
  911. };
  912. case CAM_WS_READY:{
  913. m_pCurrentROI = fusion_fetchROI();
  914. if( m_pCurrentROI != NULL ) {
  915. #ifdef DEBUG_EXTRA__
  916. LOG("HAVE ROI to see!");
  917. #endif
  918. setWM( CAM_WS_GO_ABS_POSITION );
  919. } else {
  920. //Idle Work --->
  921. if( m_sCamData.homing_enable ){
  922. if ( bNewSecondLoop ) {
  923. if ( m_nHomingCounter < m_sCamData.homing_to ) {
  924. m_nHomingCounter++;
  925. } else {
  926. //LOG("Go Home Position!");
  927. m_nHomingCounter = 0;
  928. setWM( CAM_WS_GO_HOMING_PRESET );
  929. break;
  930. };
  931. };
  932. };
  933. CAM_TASK * tTASK = fetchCamTask();
  934. if ( tTASK != NULL ) {
  935. if( tTASK->movemet_needed ){
  936. CAM_PTZ_CMD *tCMD = tTASK->CMD;
  937. if( tCMD ) {
  938. switch( tCMD->CMD ) {
  939. case PTZ_STOP:{
  940. m_nHomingCounter = 0;
  941. setWM( CAM_WS_STOP_MOVE );
  942. break;
  943. };
  944. case PTZ_MOVE:{
  945. if( tState != CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
  946. m_bRelativeMoveMatrix = 0;
  947. m_fRM_Pan = tCMD->PAN;
  948. m_fRM_Tilt = tCMD->TILT;
  949. m_fRM_Zoom = tCMD->ZOOM;
  950. m_nHomingCounter = 0;
  951. setWM( CAM_WS_AUTOMATED_MOVE );
  952. break;
  953. };
  954. case PTZ_ABSOLUTE:{
  955. m_pCurrentROI = createCAM_ROI();
  956. if( m_pCurrentROI != NULL ){
  957. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD*)malloc(sizeof(CAM_TRACK_RECORD));
  958. if ( tTarget != NULL ) {
  959. memset( tTarget, 0, sizeof(CAM_TRACK_RECORD) );
  960. tTarget->evt_db_ID = tTASK->source_evt_id;
  961. m_pCurrentROI->targets.push_back( tTarget );
  962. m_pCurrentROI->cam_orientation.pan = tCMD->PAN;
  963. m_pCurrentROI->cam_orientation.tilt = tCMD->TILT;
  964. m_pCurrentROI->cam_orientation.zoom = tCMD->ZOOM;
  965. m_nHomingCounter = 0;
  966. setWM(CAM_WS_GO_ABS_POSITION);
  967. } else {
  968. utilizeROI( m_pCurrentROI );
  969. };
  970. };
  971. break;
  972. };
  973. case PTZ_RELOAD_CAMERA:{
  974. LOG("Exit Command Rcpt");
  975. m_bThreadStatus = TH_ENDED;
  976. };
  977. };
  978. free( tCMD );
  979. tTASK->CMD = NULL;
  980. };
  981. } else {
  982. // No Movement -> Just Capture
  983. if( m_pBEH ){
  984. EVENT_CONTAINER *tEVT = createBasicEvent(
  985. m_sNodeData.node_id,
  986. EVT_CLASS_CAMERA_CTRL,
  987. EVT_CAMERA_ON_POSITION,
  988. NULL, NULL, NULL );
  989. if( tEVT ){
  990. tEVT->m_db_id = tTASK->source_evt_id;
  991. m_pBEH->broadcast(tEVT);
  992. };
  993. };
  994. };
  995. free( tTASK );
  996. } else {
  997. // Lowest Priority to Web Client Commands
  998. #ifdef DEBUG_EXTRA__
  999. LOG("Check Web CMD!");
  1000. #endif
  1001. PUSHED = m_pDBC->getNodePushedCMD( m_sNodeData.node_id );
  1002. if( PUSHED != NULL ) {
  1003. #ifdef DEBUG_EXTRA__
  1004. LOG("HAVE Web CMD!");
  1005. #endif
  1006. m_pDBC->updateNodePushedCMD( PUSHED->id, DBC_CMD_READY_TO_CLEAN );
  1007. if( ( PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK ) == ARGUS_CAM_PCMD_CMD_MASK ) {
  1008. switch( PUSHED->CMD ) {
  1009. case 0x80:{
  1010. //m_bWM = ANODE_WM_2D_ISSUE_FULL_RESET;
  1011. break;
  1012. };
  1013. case 0x81:{
  1014. //m_bWM = ANODE_WM_2D_GET_FAST_DRAW;
  1015. break;
  1016. };
  1017. case 0x82:{
  1018. break;
  1019. };
  1020. }; //?? Check if we don't miss something!!
  1021. } else if ( tState == CAM_WS_READY || tState == CAM_WS_AUTOMATED_MOVE ){ //No Way to get here
  1022. //Direct Movment Mode
  1023. if( PUSHED->CMD == ARGUS_CAM_PCMD_STOP ) {
  1024. m_nHomingCounter = 0;
  1025. setWM( CAM_WS_STOP_MOVE );
  1026. } else {
  1027. char tB[64];
  1028. if( tState != CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
  1029. m_bRelativeMoveMatrix = ( PUSHED->CMD ) >> 1;
  1030. m_nHomingCounter = 0;
  1031. setWM( CAM_WS_AUTOMATED_MOVE );
  1032. };
  1033. };
  1034. free( PUSHED );
  1035. PUSHED = NULL;
  1036. };
  1037. };
  1038. };
  1039. break;
  1040. };
  1041. case CAM_WS_END:{
  1042. LOG("Exit Command Rcpt");
  1043. m_bThreadStatus = TH_ENDED;
  1044. break;
  1045. };
  1046. };
  1047. SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  1048. };
  1049. #ifdef DEBUG
  1050. LOG("CTRL Loop End!");
  1051. #endif
  1052. };
  1053. bool deviceNodeCamera::testFOV( C3D_DECART L ){
  1054. //System Coords -> trans to local and go to funct
  1055. systemAnchor* tSystem = systemAnchor::getInstance();
  1056. if ( tSystem == NULL ) return false;
  1057. C3D_SPH_DEGREES SL;
  1058. #ifdef DEBUG
  1059. LOG("Test FOV local Decart coords");
  1060. #endif
  1061. if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
  1062. return testFOV( SL );
  1063. };
  1064. bool deviceNodeCamera::testFOV( C3D_WGS84_LOC L ){
  1065. //Global Coords
  1066. systemAnchor* tSystem = systemAnchor::getInstance();
  1067. if ( tSystem == NULL ) return false;
  1068. C3D_SPH_DEGREES SL;
  1069. #ifdef DEBUG
  1070. LOG("Test FOV WGS coords");
  1071. #endif
  1072. if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
  1073. return testFOV( SL );
  1074. };
  1075. bool deviceNodeCamera::testFOV( C3D_SPH_RADIANS L ){
  1076. //Local Coords
  1077. C3D_SPH_DEGREES SL;
  1078. #ifdef DEBUG
  1079. LOG("Test FOV local Spherical(rad) coords");
  1080. #endif
  1081. spherical2spherical( L, SL );
  1082. return testFOV( SL );
  1083. };
  1084. bool deviceNodeCamera::testFOV( C3D_SPH_DEGREES SL ){
  1085. #ifdef DEBUG
  1086. char tB[128];
  1087. #endif
  1088. #ifdef DEBUG
  1089. LOG("Test FOV local Spherical(deg) coords");
  1090. #endif
  1091. switch ( m_sCamData.triggering_mode ) {
  1092. case CAM_TRIGGER_STRICT:{
  1093. if( SL.r > m_fMaxRange || SL.r < m_fMinRange ){
  1094. #ifdef DEBUG
  1095. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1096. LOG( tB );
  1097. #endif
  1098. return false;
  1099. };
  1100. break;
  1101. };
  1102. case CAM_TRIGGER_ALL_NEAR:{
  1103. if( SL.r > m_fMaxRange ){
  1104. #ifdef DEBUG
  1105. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1106. LOG( tB );
  1107. #endif
  1108. return false;
  1109. };
  1110. break;
  1111. };
  1112. case CAM_TRIGGER_ALL_FAR:{
  1113. if( SL.r < m_fMinRange ){
  1114. #ifdef DEBUG
  1115. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1116. LOG( tB );
  1117. #endif
  1118. return false;
  1119. };
  1120. break;
  1121. };
  1122. case CAM_TRIGGER_ALL: return true;
  1123. };
  1124. float HS = AC_imager_width[m_sCamData.imager_type];
  1125. float VS = AC_imager_height[m_sCamData.imager_type];
  1126. float HS2 = HS * HS;
  1127. float VS2 = VS * VS;
  1128. float IR = HS / VS;
  1129. float IR2 = IR * IR;
  1130. if( m_sCamData.pan_angles == 0 ) {
  1131. // Fixed Camera
  1132. float tA = fabsf( SL.fi );
  1133. float tZ = 0.5f * ( m_fMinHFov + ( SL.r - m_fMinRange ) * m_fR2FL );
  1134. if ( tA > tZ ) return false;
  1135. } else {
  1136. if( m_sCamData.pan_angles < 360 ) { // If endless PAN -> PASSED
  1137. // Partial Pan
  1138. switch( m_sCamData.pan_model ) {
  1139. case 1: {
  1140. // Regular Pan
  1141. float tFOV = 0.5f * ( m_fMinHFov + ( SL.r - m_fMinRange ) * m_fR2FL );
  1142. float tRad = deg2rad( SL.fi );
  1143. #ifdef DEBUG
  1144. sprintf( tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad );
  1145. LOG( tB );
  1146. #endif
  1147. if( ( tRad < ( -1.0 * tFOV ) ) || ( tRad > ( deg2rad( m_sCamData.pan_angles ) + tFOV ) ) ) return false;
  1148. break;
  1149. };
  1150. case 2:{
  1151. break;
  1152. };
  1153. case 3:{
  1154. break;
  1155. };
  1156. };
  1157. };
  1158. };
  1159. if( m_sCamData.tilt_angles == 0 ){
  1160. //Fixed Camera
  1161. if ( ( SL.tetta < ( m_fMaxVFov / -2.0f ) ) || ( SL.tetta > ( m_fMaxVFov / 2.0f ) ) )return false;
  1162. } else {
  1163. if( m_sCamData.tilt_angles < 90 ) { // if Cam CAN DO 90 -> Pass
  1164. // Partial Tilt
  1165. switch( m_sCamData.tilt_model ) {
  1166. case 1: {
  1167. // Regular Tilt
  1168. float tFOV = 0.5f * ( m_fMinVFov + ( m_fMaxVFov - m_fMinVFov ) * ( SL.r / m_fMaxRange ) ) ;
  1169. float tRad = deg2rad( SL.tetta );
  1170. if( ( tRad < ( -1.0 * tFOV ) ) || ( tRad > ( deg2rad( m_sCamData.tilt_angles ) + tFOV ) ) )return false;
  1171. break;
  1172. };
  1173. case 2:{
  1174. break;
  1175. };
  1176. };
  1177. };
  1178. };
  1179. return true;
  1180. };
  1181. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ){
  1182. systemAnchor* tSystem = systemAnchor::getInstance();
  1183. if( tSystem == NULL ) return false;
  1184. C3D_SPH_DEGREES SL;
  1185. #ifdef DEBUG
  1186. LOG("Look at WGS coords!");
  1187. #endif
  1188. tSystem->convertToLocal(&m_oPosition, L, SL );
  1189. return lookAt(TargetRefID, SL );
  1190. };
  1191. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_DECART L ){
  1192. systemAnchor* tSystem = systemAnchor::getInstance();
  1193. if( tSystem == NULL ) return false;
  1194. C3D_SPH_DEGREES SL;
  1195. #ifdef DEBUG
  1196. LOG("Look at System Decart coords!");
  1197. #endif
  1198. tSystem->convertToLocal( &m_oPosition, L, SL );
  1199. return lookAt(TargetRefID, SL );
  1200. };
  1201. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ){
  1202. C3D_SPH_DEGREES SL;
  1203. #ifdef DEBUG
  1204. LOG("Look at spherical(rad) 2 spherical(deg) coords!");
  1205. #endif
  1206. spherical2spherical( L, SL );
  1207. return lookAt(TargetRefID, SL );
  1208. };
  1209. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_DEGREES L ){
  1210. //char tB[128];
  1211. //sprintf(tB, "Target On %.3f %.3f %.3f", L.r, L.fi, L.tetta );
  1212. //LOG( tB );
  1213. //sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
  1214. //LOG( tB );
  1215. #ifdef DEBUG
  1216. LOG("Look at local spherical deg. coords!(final)");
  1217. #endif
  1218. //if( getWM() == CAM_WS_READY ){
  1219. // C3D_ORIENT_ONVIF LL;
  1220. // spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  1221. // return absoluteMove( TargetRefID, LL );
  1222. //};
  1223. // Camera is Busy
  1224. return fusion_consumeData(TargetRefID, L);
  1225. };
  1226. bool deviceNodeCamera::makeSnap( uint32_t TargetRefID ){
  1227. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  1228. if( tTask ){
  1229. memset(tTask, 0, sizeof(CAM_TASK));
  1230. tTask->CMD = (CAM_PTZ_CMD *) malloc( sizeof(CAM_PTZ_CMD) );
  1231. if( tTask->CMD ){
  1232. tTask->CMD->CMD = PTZ_CAPTURE_ONLY;
  1233. tTask->source_evt_id = TargetRefID;
  1234. return pushCamTask( tTask );
  1235. } else {
  1236. free( tTask );
  1237. };
  1238. };
  1239. return false;
  1240. };
  1241. bool deviceNodeCamera::connectToStream( uint32_t id ){
  1242. /*
  1243. if( id ){
  1244. argusKernelModule * tKM = NULL;
  1245. argusKernel * tKRNL = NULL;
  1246. argusModuleFactory * tMF = NULL;
  1247. if( m_pDBC == NULL ) {
  1248. LOG_ERROR("No Database Connector!");
  1249. return false;
  1250. };
  1251. tKRNL = argusKernel::getInstance();
  1252. if( tKRNL ) {
  1253. tMF = tKRNL->getModuleFactory();
  1254. if( tMF ) {
  1255. tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
  1256. } else {
  1257. LOG_ERROR("No ModuleFactory Instance!");
  1258. return false;
  1259. };
  1260. } else {
  1261. LOG_ERROR("No Kernel Instance!");
  1262. return false;
  1263. };
  1264. if( tKM ) {
  1265. // New Module
  1266. DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
  1267. if( tDATA ) {
  1268. m_sMediaSource.mediaStreamId = id;
  1269. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1270. if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
  1271. m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
  1272. } else {
  1273. if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
  1274. m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource );
  1275. };
  1276. if( m_pSource != NULL ) {
  1277. char tMRL[1024];
  1278. #ifdef DEBUG
  1279. LOG("Source OK");
  1280. #endif
  1281. ((videoLIVE555Source*)m_pSource)->setWM( MS_MODE_STREAM_PROXY | MS_MODE_OVERLAYED_LOOPS | MS_MODE_DECODE_FRAMES );
  1282. int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
  1283. int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
  1284. int pix = -1;
  1285. bool in_16_9 = (((tDATA->width*100) / tDATA->height ) > 140 );
  1286. bool out_16_9 = (((tW*100) / tH ) > 140 );
  1287. updateOpticalParameters( tW, tH );
  1288. if( strlen( tDATA->c_type ) ){
  1289. };
  1290. //if( tW > 0 ){
  1291. // //m_pSource->setProportionalByWidth( tW );
  1292. // m_pSource->setSize( tW, tH );
  1293. //};
  1294. if( in_16_9 != out_16_9 ){
  1295. if( in_16_9 ){
  1296. tH = ((( tW * 1000 ) / 16 ) * 9 ) / 1000;
  1297. } else {
  1298. tW = ((( tH * 1000 ) / 3 ) * 4 ) / 1000;
  1299. };
  1300. };
  1301. if (strncmp(tDATA->mrl_proto, "v4l2", 4) == 0) {
  1302. sprintf( tMRL, tDATA->mrl );
  1303. } else {
  1304. DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
  1305. if( tCAM ) {
  1306. sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
  1307. free( tCAM );
  1308. } else {
  1309. LOG_ERROR("Error Getting CAM Data!");
  1310. delete( m_pSource );
  1311. m_pSource = NULL;
  1312. return false;
  1313. };
  1314. };
  1315. LOG( tMRL );
  1316. if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
  1317. m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
  1318. if ( !m_bSourceConnected ) {
  1319. //delete( m_pSource );
  1320. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1321. delete((videoAVLIBSource*)m_pSource);
  1322. } else {
  1323. delete((videoLIVE555Source*)m_pSource);
  1324. };
  1325. m_pSource = NULL;
  1326. } else {
  1327. m_nActiveStreamID = id;
  1328. #ifdef DEBUG
  1329. LOG("Source is Connected to Output.");
  1330. #endif
  1331. };
  1332. } else {
  1333. LOG_ERROR("Can not Open Video Source!");
  1334. //delete( m_pSource );
  1335. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1336. delete((videoAVLIBSource*)m_pSource);
  1337. } else {
  1338. delete((videoLIVE555Source*)m_pSource);
  1339. };
  1340. m_pSource = NULL;
  1341. };
  1342. } else {
  1343. LOG_ERROR("Video Source Stream Failure!");
  1344. };
  1345. free( tDATA );
  1346. };
  1347. }
  1348. #ifdef DEBUG
  1349. else LOG("No Video Module!")
  1350. #endif
  1351. ;
  1352. };
  1353. LOG("Connect Finished!");
  1354. return m_bSourceConnected;
  1355. */
  1356. return true;
  1357. };
  1358. bool deviceNodeCamera::disconnectFromStream( void ){
  1359. /*if( m_bSourceConnected ) {
  1360. if( m_pSource ){
  1361. delete( m_pSource );
  1362. m_pSource = NULL;
  1363. };
  1364. m_bSourceConnected = false;
  1365. };
  1366. return !m_bSourceConnected;
  1367. */
  1368. return true;
  1369. };
  1370. bool deviceNodeCamera::validateStream( void ){
  1371. /*
  1372. if( m_bSourceConnected ) {
  1373. if( m_pSource ) {
  1374. if( m_pSource->isAttached() ){
  1375. if( m_pSource->getStatus() < MS_STOPED ) return true;
  1376. #ifdef DEBUG
  1377. LOG("Source is Finished!");
  1378. #endif
  1379. };
  1380. #ifdef DEBUG
  1381. LOG("Source is Disconnected!");
  1382. #endif
  1383. } else LOG_ERROR("No Source Object! Set Disconnected!");
  1384. disconnectFromStream();
  1385. };
  1386. return false;
  1387. */
  1388. return true;
  1389. };
  1390. bool deviceNodeCamera::validate(){
  1391. DBC_CAM_DATA *tDATA = m_pDBC->getCamData( m_sCamData.id );
  1392. if ( tDATA == NULL ) return false;
  1393. if ( memcmp( tDATA, &m_sCamData, sizeof(DBC_CAM_DATA) ) != 0 ) {
  1394. //Settings Changed
  1395. memcpy(&m_sCamData, tDATA, sizeof(DBC_CAM_DATA) );
  1396. };
  1397. free( tDATA );
  1398. if (!validateStream()) return false;
  1399. return deviceNode::validate();
  1400. };
  1401. #undef LOG
  1402. #undef LOG_ERROR