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.

1954 lines
75 KiB

​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
3 years ago
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
3 years ago
3 years ago
​
​
​
​
​
3 years ago
​
​
3 years ago
3 years ago
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 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 "kernelModuleEmbedVideo.h"
  12. #include "../mojo/mojoKernel.h"
  13. #define LOG( X ) deviceNode::m_pLog->Log( "RCAM", this, X )
  14. //#define DEBUG_EXTRA
  15. #ifdef DEBUG
  16. #define LOG_ERROR( X ) {\
  17. char _tBfrErrMSG2w34[256];\
  18. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  19. deviceNode::m_pLog->Log( "RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  20. }
  21. #else
  22. #define LOG_ERROR( X ) deviceNode::m_pLog->Log( "RCAM", this, _LOG_ERROR, X );
  23. #endif
  24. // all sizes in mm
  25. 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 };
  26. 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 };
  27. 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 };
  28. #define CAM_FOCAL_LENGTH_CNT 49
  29. static const float cam_predef_focal_length[CAM_FOCAL_LENGTH_CNT]={
  30. 2.7f,
  31. 3.0f,
  32. 3.2f,
  33. 3.5f,
  34. 3.7f,
  35. 3.9f,
  36. 4.0f,
  37. 4.3f,
  38. 4.8f,
  39. 5.0f,
  40. 5.1f,
  41. 5.5f,
  42. 5.8f,
  43. 6.0f,
  44. 6.2f,
  45. 6.6f,
  46. 7.0f,
  47. 7.1f,
  48. 7.5f,
  49. 7.6f,
  50. 8.0f,
  51. 8.6f,
  52. 8.9f,
  53. 9.0f,
  54. 9.2f,
  55. 9.3f,
  56. 10.0f,
  57. 10.5f,
  58. 10.6f,
  59. 10.7f,
  60. 11.0f,
  61. 11.3f,
  62. 12.0f,
  63. 12.9f,
  64. 13.0f,
  65. 13.5f,
  66. 13.6f,
  67. 14.0f,
  68. 14.6f,
  69. 15.0f,
  70. 15.1f,
  71. 15.5f,
  72. 16.0f,
  73. 17.0f,
  74. 17.5f,
  75. 17.7f,
  76. 18.0f,
  77. 18.2f,
  78. 19.0f
  79. };
  80. deviceNodeCamera::deviceNodeCamera( uint32_t NodeID ): deviceNode( NodeID ), basicThread(){
  81. //m_pLog = basicLogCollection::getInstance();
  82. m_pBEH = basicEventHeap::getInstance();
  83. m_bSkeepPositioningWait = true;
  84. m_bNoAbsPositionning = false;
  85. m_bCameraOnHomePosition = false;
  86. m_tTimeTSeconds = 0;
  87. m_pProtocol = NULL;
  88. m_pTransport = NULL;
  89. m_pCurrentROI = NULL;
  90. m_nRealFrameWidth = 640;
  91. //m_bState = 0;
  92. //m_bBusy = true;
  93. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  94. m_nRelativeMoveCounter = 0;
  95. m_bRelativeMoveMatrix = 0;
  96. m_bCurrentPresetCol = 0;
  97. m_bCurrentPresetRow = 0;
  98. m_bShineOnTarget = false;
  99. m_bCameraIsStatic = false;
  100. m_bIRIsOn = false;
  101. m_bIRTO = 0;
  102. m_fSpeedRise = 0.03f;
  103. m_fZoomCorrection = 1.0f;
  104. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  105. //m_bSourceConnected = false;
  106. //m_pSource = NULL;
  107. };
  108. deviceNodeCamera::deviceNodeCamera( DBC_NODE_DATA *Data ): deviceNode( Data ), basicThread(){
  109. //m_pLog = basicLogCollection::getInstance();
  110. m_pBEH = basicEventHeap::getInstance();
  111. m_bSkeepPositioningWait = true;
  112. m_bNoAbsPositionning = false;
  113. m_bCameraOnHomePosition = false;
  114. m_tTimeTSeconds = 0;
  115. m_pProtocol = NULL;
  116. m_pTransport = NULL;
  117. m_pCurrentROI = NULL;
  118. m_nRealFrameWidth = 640;
  119. //m_bState = 0;
  120. //m_bBusy = true;
  121. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  122. m_nRelativeMoveCounter = 0;
  123. m_bRelativeMoveMatrix = 0;
  124. m_bCurrentPresetCol = 0;
  125. m_bCurrentPresetRow = 0;
  126. m_bShineOnTarget = false;
  127. m_bIRIsOn = false;
  128. m_bIRTO = 0;
  129. m_fSpeedRise = 0.03f;
  130. m_fZoomCorrection = 1.0f;
  131. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  132. //m_bSourceConnected = false;
  133. //m_pSource = NULL;
  134. };
  135. deviceNodeCamera::~deviceNodeCamera(){
  136. LOG("Destruct");
  137. //m_mQPROTECTOR.unlock();
  138. waitThreadEnd( true );
  139. LOG("Thread Del OK");
  140. if( m_pTransport!= NULL ) {
  141. if( m_sCamData.uart_id ) {
  142. DBC_UART_DATA *tData = NULL;
  143. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  144. switch( tData->type ) {
  145. case UART_TYPE_HARDWARE:{
  146. delete((serialPort*)m_pTransport);
  147. break;
  148. };
  149. case UART_TYPE_SOL:{
  150. delete((serialSOL*)m_pTransport);
  151. break;
  152. };
  153. };
  154. };
  155. };
  156. LOG("Transport Del OK");
  157. if( m_pProtocol != NULL ) {
  158. switch( m_sCamData.protocol ) {
  159. case CAM_CTRL_PROTO_VISCA:
  160. delete( (protocolPTZ_VISCA *) m_pProtocol );
  161. break;
  162. case CAM_CTRL_PROTO_PELCO:
  163. delete( (protocolPTZ_PELCO *) m_pProtocol );
  164. break;
  165. case CAM_CTRL_PROTO_ONVIF:
  166. delete( (protocolPTZ_ONVIF *) m_pProtocol );
  167. break;
  168. default:
  169. delete( m_pProtocol );
  170. };
  171. };
  172. LOG("Proto Del OK");
  173. //if( m_pPosition != NULL ) delete( m_pPosition );
  174. //LOG("Pos Del OK");
  175. //if( m_bSourceConnected ){
  176. // if( m_pSource != NULL ){
  177. // m_pSource->_close();
  178. // delete( m_pSource );
  179. // };
  180. //};
  181. //LOG("Stream Del OK");
  182. };
  183. void deviceNodeCamera::updateOpticalParameters( uint16_t frame_width, uint16_t frame_heigth ){
  184. #ifdef DEBUG
  185. char tB[128];
  186. LOG("Set Optical Parameters");
  187. sprintf( tB, "\tCapturing Frame: %dx%d ", frame_width, frame_heigth );
  188. LOG(tB);
  189. #endif
  190. if( frame_width > 0 && frame_heigth > 0 ) {
  191. m_nRealFrameWidth = frame_width;
  192. m_nRealFrameHeight = frame_heigth;
  193. float tFrameDiag = sqrtf( m_nRealFrameHeight*m_nRealFrameHeight+m_nRealFrameWidth*m_nRealFrameWidth );
  194. switch( m_sCamData.zoom_model ) {
  195. case 0:{
  196. #ifdef DEBUG
  197. LOG("\tFixed Zoom");
  198. #endif
  199. m_fMaxFL = m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  200. m_fMinRange = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag );
  201. m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag );
  202. m_fR2FL = .0f;
  203. m_fZoomCorrection = .0f;
  204. m_pDBC->updateCamRange( m_sCamData.id, m_fMaxRange );
  205. break;
  206. };
  207. case 1:{
  208. #ifdef DEBUG
  209. LOG("\tAutomated Zoom");
  210. #endif
  211. m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  212. m_fMinRange = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag );
  213. m_fMaxFL = cam_predef_focal_length[m_sCamData.lens_f] * m_sCamData.zoom;
  214. m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag );
  215. if( m_fMaxRange > m_fMinRange ){
  216. m_fR2FL = ((m_fMaxFL - m_fMinFL) / (m_fMaxRange - m_fMinRange));
  217. } else {
  218. m_fR2FL = .0f;
  219. };
  220. m_fZoomCorrection = 1.0f;
  221. m_pDBC->updateCamRange(m_sCamData.id, m_fMaxRange);
  222. break;
  223. };
  224. case 2:{
  225. #ifdef DEBUG
  226. LOG("\tManual Zoom");
  227. #endif
  228. m_fMinRange = 5.0f; //Minimal 5 meters
  229. if ( m_sCamData.max_range < m_fMinRange ) {
  230. m_fMaxRange = m_fMinRange;
  231. } else {
  232. m_fMaxRange = m_sCamData.max_range;
  233. };
  234. m_fZoomCorrection = m_sCamData.zoom * 0.01f;
  235. m_fMinFL = calcCFL( AC_imager_width[m_sCamData.imager_type], m_fMinRange, tFrameDiag );
  236. m_fMaxFL = calcCFL( AC_imager_width[m_sCamData.imager_type], m_fMaxRange, tFrameDiag );
  237. break;
  238. };
  239. };
  240. m_fMinHFov = rad2deg(calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_fMaxFL ));
  241. m_fMaxHFov = rad2deg(calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_fMinFL ));
  242. m_fMinVFov = rad2deg(calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_fMaxFL ));
  243. m_fMaxVFov = rad2deg(calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_fMinFL ));
  244. #ifdef DEBUG
  245. sprintf( tB, "\tMinimal FL: %0.3fmm. Maximal FL: %0.3fmm. ", m_fMinFL, m_fMaxFL );
  246. LOG(tB);
  247. sprintf( tB, "\tMinimal Range: %0.2fm. Maximal Range: %0.2fm. ", m_fMinRange, m_fMaxRange );
  248. LOG(tB);
  249. sprintf( tB, "\tMinimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov );
  250. LOG(tB);
  251. sprintf( tB, "\tMaximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov );
  252. LOG(tB);
  253. #endif
  254. };
  255. };
  256. bool deviceNodeCamera::create(){
  257. setWM( CAM_WS_INIT );
  258. if( m_sNodeData.aux_id == 0 ) return false;
  259. DBC_CAM_DATA * tData = m_pDBC->getCamData( m_sNodeData.aux_id );
  260. if( tData != NULL ) {
  261. memcpy( &m_sCamData, tData, sizeof(DBC_CAM_DATA) );
  262. free( tData );
  263. } else {
  264. LOG_ERROR("Cannot Fetch CAM Data from Database!");
  265. return false;
  266. };
  267. if( !( m_sCamData.lens_f < CAM_FOCAL_LENGTH_CNT ) ) m_sCamData.lens_f = CAM_FOCAL_LENGTH_CNT - 1;
  268. updateOpticalParameters( 1280, 720 ); //HD Ready
  269. if( m_sCamData.ptz_speed_step > .0f ) {
  270. m_fSpeedRise = m_sCamData.ptz_speed_step;
  271. };
  272. //m_pPosition = new basicPosition();// m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
  273. //if( m_pPosition == NULL ) {
  274. // LOG_ERROR("Position Constructor Failure!");
  275. // return false;
  276. //};
  277. //m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z );
  278. //m_oPosition.setOrientationDeg( m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot );
  279. systemAnchor * SA = systemAnchor::getInstance();
  280. if( SA ){
  281. LOG("SysAnchor OK");
  282. if ( SA->beLocal() ) {
  283. LOG("SysAnchor beLocal!");
  284. m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z, 0 ); //SA->getUTMZone() );
  285. m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
  286. } else {
  287. LOG("SysAnchor is Global Position System!");
  288. C3D_DECART LD = SA->getXYZ();
  289. m_oPosition.setPositionXYZ( LD.x + m_sCamData.x, LD.y + m_sCamData.y, LD.z + m_sCamData.z, SA->getUTMZone() );
  290. m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
  291. };
  292. } else {
  293. LOG("No SysAnchor!");
  294. m_oPosition.setPositionXYZ( m_sCamData.x , m_sCamData.y, m_sCamData.z );
  295. m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
  296. };
  297. m_oPosition.updateMatrix();
  298. #ifdef DEBUG
  299. char tB[128];
  300. sprintf( tB, "Finalized Camera Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
  301. LOG( tB );
  302. sprintf( tB, "Finalized Camera Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() );
  303. LOG( tB );
  304. sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() );
  305. LOG( tB );
  306. #endif
  307. if( m_pProtocol != NULL ){
  308. LOG_ERROR("Cannot Start: Service Already Running!");
  309. return false;
  310. };
  311. switch( m_sCamData.protocol ){
  312. case CAM_CTRL_PROTO_VISCA: {
  313. #ifdef DEBUG
  314. LOG("VISCA");
  315. #endif
  316. m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA( m_sCamData.protocol_aux );
  317. if( m_pProtocol!= NULL ) {
  318. basicTransport *tTransport = NULL;
  319. hardwareManager *tHM = hardwareManager::getInstance();
  320. if( tHM ){
  321. hardwareResource *tRES = tHM->requestResource( HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id );
  322. if( tRES != NULL ) {
  323. if( tRES->isValid()) {
  324. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  325. if( m_pProtocol->setTransport( tTransport )){
  326. if( !m_pProtocol->create() ){
  327. LOG_ERROR("Protocol <<< Create >>> Failure!");
  328. };
  329. } else {
  330. LOG_ERROR("Binding Port Failure!");
  331. };
  332. };
  333. #ifdef DEBUG
  334. } else {
  335. LOG("HWM Has No UART PORT!");
  336. #endif
  337. };
  338. #ifdef DEBUG
  339. } else {
  340. LOG_ERROR("Can not get Hardware Manager!");
  341. #endif
  342. };
  343. if( tTransport!= NULL ) {
  344. LOG( "Bind Transport Port!" );
  345. } else {
  346. LOG_ERROR("Transport Creation Failure!");
  347. delete( ( protocolPTZ_VISCA * )m_pProtocol );
  348. m_pProtocol = NULL;
  349. };
  350. #ifdef DEBUG
  351. } else {
  352. LOG_ERROR("Protocol Creation failure!");
  353. #endif
  354. };
  355. break;
  356. };
  357. case CAM_CTRL_PROTO_PELCO:{
  358. #ifdef DEBUG
  359. LOG("PELCO");
  360. #endif
  361. m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO( m_sCamData.protocol_aux );
  362. if( m_pProtocol!= NULL ) {
  363. basicTransport *tTransport = NULL;
  364. hardwareManager *tHM = hardwareManager::getInstance();
  365. if ( tHM ) {
  366. hardwareResource * tRES = tHM->requestResource( HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id );
  367. if( tRES != NULL ) {
  368. if( tRES->isValid()) {
  369. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  370. if( m_pProtocol->setTransport( tTransport )){
  371. if( !m_pProtocol->create() ){
  372. LOG_ERROR("Protocol <<< Create >>> Failure!");
  373. };
  374. } else {
  375. LOG_ERROR("Binding Port Failure!");
  376. };
  377. };
  378. #ifdef DEBUG
  379. } else {
  380. LOG("HWM Has No UART PORT!");
  381. #endif
  382. };
  383. #ifdef DEBUG
  384. } else {
  385. LOG_ERROR("Can not get Hardware Manager!");
  386. #endif
  387. };
  388. if( tTransport!= NULL ) {
  389. LOG( "Bind Transport Port!" );
  390. } else {
  391. LOG_ERROR("Transport Creation Failure!");
  392. delete( ( protocolPTZ_PELCO * )m_pProtocol );
  393. m_pProtocol = NULL;
  394. };
  395. #ifdef DEBUG
  396. } else {
  397. LOG_ERROR("Protocol Creation failure!");
  398. #endif
  399. };
  400. break;
  401. };
  402. case CAM_CTRL_PROTO_ONVIF:{
  403. #ifdef DEBUG
  404. LOG("ONVIF");
  405. #endif
  406. //m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  407. if( strstr( m_sCamData.onvif_ctrl, "http" ) == NULL ) {
  408. char tURI[256];
  409. if ( m_sCamData.port ) {
  410. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  411. } else {
  412. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  413. };
  414. m_pProtocol = (protocolPTZ *)new protocolPTZ_ONVIF( tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  415. } else {
  416. m_pProtocol = (protocolPTZ *)new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  417. };
  418. #ifdef DEBUG
  419. LOG("ONVIF-END");
  420. #endif
  421. if( m_pProtocol != NULL ) {
  422. if( !m_pProtocol->create() ) {
  423. LOG_ERROR("Error Creating Proto!");
  424. delete( (protocolPTZ_ONVIF*) m_pProtocol );
  425. m_pProtocol = NULL;
  426. };
  427. #ifdef DEBUG
  428. LOG("PROTO CREATE DONE");
  429. #endif
  430. };
  431. break;
  432. };
  433. default:{
  434. #ifdef DEBUG
  435. LOG("Camera Has no defined control protocol");
  436. #endif
  437. };
  438. };
  439. //Check - No ABS Movement!
  440. if( ( m_sCamData.type == ARGUS_IP_PRESET_CAMERA ) || ( m_sCamData.type == ARGUS_ANALOG_PRESET_CAMERA ) ) m_bNoAbsPositionning = true;
  441. if (m_pProtocol == NULL) {
  442. if( m_sCamData.protocol == 0 ) {
  443. m_bCameraIsStatic = true;
  444. m_bSkeepPositioningWait = true;
  445. m_sCamData.online = true;
  446. } else LOG_ERROR("No Proto Created!");
  447. } else {
  448. #ifdef DEBUG
  449. LOG("Proto is OK");
  450. #endif
  451. //Load Presets only if we have protocol
  452. load_presets();
  453. mojoKernel *tKRNL = mojoKernel::getInstance();
  454. if( tKRNL ) {
  455. m_bSkeepPositioningWait = (( tKRNL->getMediaMode() & EVE_OUTPUT_VIDEO ) == EVE_OUTPUT_VIDEO );
  456. #ifdef DEBUG
  457. char ttTT[128];
  458. sprintf( ttTT, "Kernel Media Mode:%d", tKRNL->getMediaMode() );
  459. LOG( ttTT );
  460. if ( m_bSkeepPositioningWait ) {
  461. LOG("Camera No Wait On Pos!");
  462. } else {
  463. LOG("Camera Will Wait On Pos!");
  464. };
  465. #endif
  466. } else {
  467. LOG_ERROR("No Kernel Instance!");
  468. };
  469. m_sCamData.online = init();
  470. };
  471. m_pDBC->updateCamOnlineStatus( m_sCamData.id, m_sCamData.online );
  472. return m_sCamData.online;
  473. };
  474. //void deviceNodeCamera::setBusy( bool Status ){
  475. //m_bBusy = Status;
  476. //};
  477. bool deviceNodeCamera::relativeMove( float PanSPD, float TiltSPD, float ZoomSPD ){
  478. if( m_sCamData.online ) {
  479. uint32_t MoveMatrix = 0;
  480. if( PanSPD != .0f ){
  481. if( PanSPD > 0 ) {
  482. MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
  483. } else {
  484. MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
  485. };
  486. };
  487. if( TiltSPD != .0f ){
  488. if( TiltSPD > 0 ) {
  489. MoveMatrix |= PTZ_DRIVE_TILT_UP;
  490. } else {
  491. MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
  492. };
  493. };
  494. if( ZoomSPD != .0f ){
  495. if( ZoomSPD > 0 ) {
  496. MoveMatrix |= PTZ_DRIVE_ZOOM_WIDE;
  497. } else {
  498. MoveMatrix |= PTZ_DRIVE_ZOOM_TELE;
  499. };
  500. };
  501. if( MoveMatrix != 0 ) {
  502. m_pProtocol->setPTZSpeed( fabs(PanSPD), fabs(TiltSPD), fabs(ZoomSPD) );
  503. };
  504. return m_pProtocol->move( MoveMatrix );
  505. };
  506. return false;
  507. };
  508. bool deviceNodeCamera::relativeStop(){
  509. if( m_sCamData.online ) {
  510. return m_pProtocol->move( 0 );
  511. };
  512. return false;
  513. };
  514. CAM_TASK *deviceNodeCamera::fetchCamTask( void ){
  515. CAM_TASK *rVal = NULL;
  516. m_mQPROTECTOR.lock();
  517. if (m_qCAM_TASK.size()) {
  518. rVal = m_qCAM_TASK.front();
  519. m_qCAM_TASK.pop();
  520. };
  521. m_mQPROTECTOR.unlock();
  522. return rVal;
  523. };
  524. bool deviceNodeCamera::pushCamTask( CAM_TASK *ptr ){
  525. if ( ptr == NULL ) return false;
  526. m_mQPROTECTOR.lock();
  527. m_qCAM_TASK.push( ptr );
  528. m_mQPROTECTOR.unlock();
  529. return true;
  530. };
  531. bool deviceNodeCamera::fusion_compare( CAM_ROI *ptr, C3D_SPH_DEGREES tp ){
  532. if( ptr == NULL ) return false;
  533. float tFI = fabsf( ptr->cam_position.fi - tp.fi );
  534. float tTETTA = fabsf( ptr->cam_position.tetta - tp.tetta );
  535. #ifdef DEBUG
  536. char tB[128];
  537. 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 );
  538. LOG(tB);
  539. #endif
  540. if( tFI > ptr->h_fov ) return false;
  541. if( tTETTA > ptr->v_fov ) return false;
  542. if( tp.r < ptr->min_range ) return false;
  543. if( tp.r > ptr->max_range ) return false;
  544. return true;
  545. };
  546. bool deviceNodeCamera::fusion_consumeData( uint32_t db_id, C3D_SPH_DEGREES tOR ){
  547. if( db_id == 0 ) return false;
  548. //Preset static targeting -> instant ROI
  549. if ( m_bNoAbsPositionning ) {
  550. CAM_ROI * tROI = (CAM_ROI *)malloc(sizeof(CAM_ROI));
  551. if ( tROI ) {
  552. };
  553. return true;
  554. };
  555. CAM_TRACK_RECORD *tTrackRecord = (CAM_TRACK_RECORD *)malloc(sizeof(CAM_TRACK_RECORD));
  556. if( tTrackRecord == NULL ) return false;
  557. #ifdef DEBUG_EXTRA
  558. LOG("Fusion: Consuming new Data!");
  559. #endif
  560. memset(tTrackRecord, 0, sizeof(CAM_TRACK_RECORD));
  561. tTrackRecord->target_direction.fi = tOR.fi;
  562. tTrackRecord->target_direction.r = tOR.r;
  563. tTrackRecord->target_direction.tetta = tOR.tetta;
  564. tTrackRecord->evt_db_ID = db_id;
  565. tTrackRecord->ts_ms = getMilliseconds();
  566. m_mROIsProtector.lock();
  567. if( m_vROIS.size() ){
  568. vCAM_ROIS::iterator idx = m_vROIS.begin();
  569. for( ; idx < m_vROIS.end(); idx++ ) if ( fusion_compare( *idx, tOR ) ) break;
  570. if ( idx != m_vROIS.end() ) {
  571. // have Match!
  572. #ifdef DEBUG_EXTRA
  573. LOG("ROI MATCHED!");
  574. #endif
  575. (*idx)->targets.push_back( tTrackRecord );
  576. fusion_validateROI( tTrackRecord->ts_ms, (*idx) );
  577. } else {
  578. #ifdef DEBUG_EXTRA
  579. LOG("NO MATCH FOUND!");
  580. #endif
  581. // No mathced ROI -> create new one
  582. CAM_ROI * tROI = (CAM_ROI *)malloc(sizeof(CAM_ROI));
  583. if ( tROI ) {
  584. memset( tROI, 0 , sizeof(CAM_ROI) );
  585. tROI->ts_ms = tTrackRecord->ts_ms;
  586. spherical2onvif( tOR, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  587. tROI->cam_position.fi = tOR.fi;
  588. tROI->cam_position.tetta = tOR.tetta;
  589. tROI->cam_position.r = tOR.r;
  590. float cFL = m_fMinFL + m_fR2FL * ( tROI->cam_position.r - m_fMinRange );
  591. tROI->max_range = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  592. tROI->min_range = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  593. tROI->h_fov = rad2deg( calcFOV_mm( AC_imager_width[m_sCamData.imager_type], cFL ) ) / 2.0f; // div to no to div in comparation function
  594. tROI->v_fov = rad2deg( calcFOV_mm( AC_imager_height[m_sCamData.imager_type], cFL ) ) / 2.0f; // that will be called more ofthen
  595. tROI->targets.push_back( tTrackRecord );
  596. m_vROIS.push_back( tROI );
  597. };
  598. };
  599. } else {
  600. #ifdef DEBUG_EXTRA
  601. LOG("Fusion: NO ROI -> CREATE!");
  602. #endif
  603. //
  604. CAM_ROI * tROI = (CAM_ROI *)malloc(sizeof(CAM_ROI));
  605. if ( tROI ) {
  606. memset( tROI, 0 , sizeof(CAM_ROI) );
  607. tROI->ts_ms = tTrackRecord->ts_ms;
  608. //Set vector Cam Coordinates
  609. tROI->cam_position.fi = tOR.fi;
  610. tROI->cam_position.tetta = tOR.tetta;
  611. tROI->cam_position.r = tOR.r;
  612. // Set vector OnVIF coordinates
  613. spherical2onvif( tOR, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  614. // make fusion data BOX
  615. float cFL = m_fMinFL + m_fR2FL * ( tROI->cam_position.r );// - m_fMinRange );
  616. tROI->min_range = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  617. tROI->max_range = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  618. tROI->h_fov = rad2deg( calcFOV_mm( AC_imager_width[m_sCamData.imager_type], cFL ) )/ 2.0f; // div to prevent division in comparation
  619. tROI->v_fov = rad2deg( calcFOV_mm( AC_imager_height[m_sCamData.imager_type], cFL ) )/ 2.0f; // function that will be called more ofthen
  620. // Add ROI to vector
  621. tROI->targets.push_back( tTrackRecord );
  622. m_vROIS.push_back( tROI );
  623. } else LOG_ERROR("No MEM4ROI");
  624. };
  625. m_mROIsProtector.unlock();
  626. return true;
  627. };
  628. bool deviceNodeCamera::fusion_validateROI( uint64_t cts, CAM_ROI *ptr ){
  629. if( ptr == NULL ) return false;
  630. if( (cts - ptr->ts_ms) > LOSE_INTERES_TIME_MS ) return false;
  631. #ifdef DEBUG_EXTRA
  632. char tB[128];
  633. sprintf( tB, "\tROI [%d]", ptr->targets.size() );
  634. LOG( tB );
  635. #endif
  636. if( ptr->targets.size() ) {
  637. double tA = 0.0;
  638. double tB = 0.0;
  639. double tC = 0.0;
  640. uint32_t tCNT = 0;
  641. for( vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end(); idx++ ) {
  642. if( ( cts - (*idx)->ts_ms ) > LOSE_INTERES_TIME_MS ) {
  643. free( (*idx) );
  644. ptr->targets.erase( idx );
  645. } else {
  646. tA = tA + (*idx)->target_direction.fi;
  647. tB = tB + (*idx)->target_direction.tetta;
  648. tC = tC + (*idx)->target_direction.r;
  649. tCNT++;
  650. };
  651. };
  652. if( tCNT ) {
  653. C3D_SPH_DEGREES L = { 0 };
  654. L.fi = (float) ( tA /(double) tCNT );
  655. L.tetta = (float) ( tB /(double) tCNT );
  656. L.r = (float) ( tC /(double) tCNT );
  657. spherical2onvif(L, ptr->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  658. ptr->ts_ms = cts;
  659. float cFL = m_fMinFL + m_fR2FL * ( ptr->cam_position.r - m_fMinRange );
  660. ptr->max_range = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  661. ptr->min_range = calcMinDistance_mm( AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth );
  662. ptr->h_fov = rad2deg( calcFOV_mm(AC_imager_width[m_sCamData.imager_type], cFL) )/ 2.0f; // div to prevent division in comparation
  663. ptr->v_fov = rad2deg( calcFOV_mm( AC_imager_height[m_sCamData.imager_type], cFL ) )/ 2.0f; // function that will be called more ofthen
  664. return true;
  665. };
  666. };
  667. return false;
  668. };
  669. CAM_ROI *deviceNodeCamera::fusion_fetchROI( void ){
  670. CAM_ROI *tVAL = NULL;
  671. uint64_t cts = 0;
  672. m_mROIsProtector.lock();
  673. vCAM_ROIS::iterator sRec;
  674. if( m_vROIS.size() ){
  675. for( vCAM_ROIS::iterator idx = m_vROIS.begin(); idx < m_vROIS.end(); idx++ ){
  676. if ( tVAL == NULL ) {
  677. sRec = idx;
  678. tVAL = (*idx);
  679. cts = tVAL->ts_ms;
  680. } else {
  681. #ifdef CAM_FETCH_ROI_NEWEST
  682. if ( (*idx)->ts_ms > cts )
  683. #else
  684. if ( (*idx)->ts_ms < cts )
  685. #endif
  686. {
  687. sRec = idx;
  688. tVAL = (*idx);
  689. cts = tVAL->ts_ms;
  690. };
  691. };
  692. };
  693. m_vROIS.erase( sRec );
  694. };
  695. m_mROIsProtector.unlock();
  696. return tVAL;
  697. };
  698. DBC_SNAPSHOT_DATA *deviceNodeCamera::fusion_translate_ROI( CAM_ROI *(&ptr) ){
  699. DBC_SNAPSHOT_DATA *rVal = NULL;
  700. if( ptr == NULL ) return NULL;
  701. if( ptr->targets.size() ){
  702. //if( m_bSourceConnected ){
  703. rVal = (DBC_SNAPSHOT_DATA *)malloc(sizeof(DBC_SNAPSHOT_DATA));
  704. if( rVal ){
  705. memset( rVal, 0, sizeof(DBC_SNAPSHOT_DATA) );
  706. //rVal->stream_id = m_nActiveStreamID;
  707. rVal->stream_id = m_sNodeData.aux_parameter;
  708. for( vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end(); idx++ ) {
  709. LOG("Added Event ID");
  710. rVal->assoc_event_ids.push_back( (*idx)->evt_db_ID );
  711. };
  712. };
  713. //};
  714. ptr->targets.clear();
  715. } else {
  716. LOG("No Events ID to ROI");
  717. };
  718. // Destruct ROI MEM
  719. delete( (CAM_ROI *) ptr );
  720. ptr = NULL;
  721. // Not Setting MD5 and TS -> will set at capture time
  722. return rVal;
  723. };
  724. void deviceNodeCamera::fusion_validate( void ){
  725. m_mROIsProtector.lock();
  726. if( m_vROIS.size() ){
  727. #ifdef DEBUG_EXTRA
  728. char tB[128];
  729. sprintf( tB, "Fusion: Have [%d] Regions Of Interes", m_vROIS.size() );
  730. LOG( tB );
  731. #endif
  732. uint64_t cts = getMilliseconds();
  733. for( vCAM_ROIS::iterator idx = m_vROIS.begin(); idx < m_vROIS.end(); idx++ ){
  734. if( !fusion_validateROI( cts, *idx ) ) {
  735. free( (*idx) );
  736. m_vROIS.erase( idx );
  737. };
  738. };
  739. };
  740. m_mROIsProtector.unlock();
  741. };
  742. bool deviceNodeCamera::absoluteMove( uint32_t TargetRefID, float PanPOS, float TiltPOS, float ZoomPOS ){
  743. if( m_sCamData.online ){
  744. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  745. if( tTask ){
  746. memset(tTask, 0, sizeof(CAM_TASK));
  747. tTask->CMD = (CAM_PTZ_CMD *)malloc(sizeof(CAM_PTZ_CMD));
  748. if( tTask->CMD ){
  749. tTask->CMD->CMD = PTZ_ABSOLUTE;
  750. tTask->CMD->PAN = PanPOS;
  751. tTask->CMD->TILT = TiltPOS;
  752. tTask->CMD->ZOOM = ZoomPOS;
  753. tTask->movemet_needed = true;
  754. tTask->source_evt_id = TargetRefID;
  755. setWM( CAM_WS_BUSY );
  756. return pushCamTask( tTask );
  757. } else {
  758. LOG_ERROR("CMD malloc Error!");
  759. free( tTask );
  760. };
  761. } else LOG_ERROR("Task malloc error!");
  762. };
  763. return false;
  764. };
  765. bool deviceNodeCamera::absoluteMove( uint32_t TargetRefID, C3D_ORIENT_ONVIF O ){
  766. if( m_sCamData.online ){
  767. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  768. if( tTask ){
  769. memset(tTask, 0, sizeof(CAM_TASK));
  770. tTask->CMD = (CAM_PTZ_CMD *)malloc(sizeof(CAM_PTZ_CMD));
  771. if( tTask->CMD ){
  772. tTask->CMD->CMD = PTZ_ABSOLUTE;
  773. tTask->CMD->PAN = O.pan;
  774. tTask->CMD->TILT = O.tilt;
  775. tTask->CMD->ZOOM = O.zoom;
  776. tTask->movemet_needed = true;
  777. tTask->source_evt_id = TargetRefID;
  778. setWM( CAM_WS_BUSY );
  779. return pushCamTask( tTask );
  780. } else {
  781. LOG_ERROR("CMD malloc Error!");
  782. free( tTask );
  783. };
  784. } else LOG_ERROR("Task malloc error!");
  785. };
  786. return false;
  787. };
  788. void deviceNodeCamera::m_fThreadProc( void ){
  789. DBC_PUSHED_CMD * PUSHED = NULL;
  790. m_bThreadStatus = TH_WORKING;
  791. bool bNewSecondLoop = false;
  792. uint32_t cTimeSeconds = 0;
  793. uint32_t oTimeSeconds = 0;
  794. while( m_bThreadStatus < TH_ENDED ) {
  795. cTimeSeconds = (uint32_t) time( NULL );
  796. if ( bNewSecondLoop = ( cTimeSeconds != oTimeSeconds ) ) oTimeSeconds = cTimeSeconds;
  797. uint8_t tState = getWM();
  798. char tB[128];
  799. fusion_validate();
  800. switch( tState ) {
  801. case CAM_WS_INIT:{
  802. #ifdef DEBUG
  803. LOG("Init Camera - PowerMode");
  804. #endif
  805. //setBusy( true );
  806. if( m_pProtocol->initCamera() ) setWM( CAM_WS_WHITE_BALLANCE );
  807. //setBusy( false );
  808. break;
  809. };
  810. case CAM_WS_WHITE_BALLANCE:{
  811. #ifdef DEBUG
  812. LOG("Set WB");
  813. #endif
  814. //setBusy( true );
  815. if( m_pProtocol->setWhiteBalanceMode( WB_AUTO ) ) setWM( CAM_WS_BACKLIGHT );
  816. //setBusy( false );
  817. break;
  818. };
  819. case CAM_WS_BACKLIGHT:{
  820. #ifdef DEBUG
  821. LOG("Set BLC");
  822. #endif
  823. //setBusy( true );
  824. if( m_pProtocol->setBackLightMode( true ) ) setWM( CAM_WS_AUTO_FOCUS );
  825. //setBusy( false );
  826. break;
  827. };
  828. case CAM_WS_AUTO_FOCUS:{
  829. #ifdef DEBUG
  830. LOG("Set AF");
  831. #endif
  832. //setBusy( true );
  833. if( m_pProtocol->setAutoFocus( true ) ) setWM( CAM_WS_INIT_GO_HOME );
  834. //setBusy( false );
  835. break;
  836. };
  837. case CAM_WS_INIT_GO_HOME:{
  838. m_nHomingCounter = 0;
  839. if( !m_bNoAbsPositionning ) {
  840. #ifdef DEBUG
  841. LOG("INIT GO -1 0 -1");
  842. #endif
  843. if (m_pProtocol->goAbsolute(-1, 0, -1)) {
  844. m_fCP_Pan = -1;
  845. m_fCP_Tilt = 0;
  846. m_fCP_Zoom = -1;
  847. setWM( CAM_WS_READY );
  848. };
  849. } else {
  850. #ifdef DEBUG
  851. LOG("Go Home!");
  852. #endif
  853. CSTR TK = getPresetToken( ARGUS_PRESET_TYPE_HOME );
  854. if( TK ) {
  855. if ( !m_bCameraOnHomePosition ) {
  856. if( !m_pProtocol->goPreset( TK )){
  857. LOG_ERROR("Cannot Issue goPreset Command!");
  858. };
  859. m_bCameraOnHomePosition = true;
  860. };
  861. };
  862. setWM( CAM_WS_READY );
  863. };
  864. break;
  865. };
  866. case CAM_WS_AUTOMATED_MOVE:{
  867. m_bCameraOnHomePosition = false;
  868. m_nRelativeMoveCounter++;
  869. if( ( m_bRelativeMoveMatrix & 0x03 ) != 0 ) {
  870. //Pan Move
  871. if( ( m_bRelativeMoveMatrix & 0x01 ) == 0 ) {
  872. m_fRM_Pan -= m_fSpeedRise;
  873. } else {
  874. m_fRM_Pan += m_fSpeedRise;
  875. };
  876. };
  877. if( ( m_bRelativeMoveMatrix & 0x0C ) != 0 ) {
  878. //TILT Move
  879. if( ( m_bRelativeMoveMatrix & 0x04 ) == 0 ) {
  880. m_fRM_Tilt -= m_fSpeedRise;
  881. } else {
  882. m_fRM_Tilt += m_fSpeedRise;
  883. }
  884. };
  885. if( ( m_bRelativeMoveMatrix & 0x30 ) != 0 ) {
  886. //ZOOM Move
  887. if( ( m_bRelativeMoveMatrix & 0x10 ) == 0 ) {
  888. //Wide
  889. m_fRM_Zoom -= m_fSpeedRise;
  890. } else {
  891. //Tele
  892. m_fRM_Zoom += m_fSpeedRise;
  893. };
  894. };
  895. if( m_fRM_Pan < -1.0f ) m_fRM_Pan = -1.0f;
  896. if( m_fRM_Pan > 1.0f ) m_fRM_Pan = 1.0f;
  897. if( m_fRM_Tilt < -1.0f ) m_fRM_Tilt = -1.0f;
  898. if( m_fRM_Tilt > 1.0f ) m_fRM_Tilt = 1.0f;
  899. if( m_fRM_Zoom < -1.0f ) m_fRM_Zoom = -1.0f;
  900. if( m_fRM_Zoom > 1.0f ) m_fRM_Zoom = 1.0f;
  901. m_fCP_Zoom += 0.5f*m_fRM_Zoom;
  902. if( m_fCP_Zoom < -1.0f ) m_fCP_Zoom = -1.0f;
  903. if( m_fCP_Zoom > 1.0f ) m_fCP_Zoom = 1.0f;
  904. if( !relativeMove( m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom ) ){
  905. m_nRelativeMoveCounter = 0;
  906. setWM( CAM_WS_READY );
  907. break;
  908. };
  909. if( m_sCamData.ptz_axel ) { //Manual
  910. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel) {
  911. m_nRelativeMoveCounter = 0;
  912. setWM( CAM_WS_READY );
  913. };
  914. } else {
  915. // Stepping Axel by Zoom
  916. uint8_t tVal = (uint8_t)( 10.0f * ( 2.0f - ( 1.0f + m_fCP_Zoom ) ));
  917. if( m_nRelativeMoveCounter > tVal ) {
  918. m_nRelativeMoveCounter = 0;
  919. setWM( CAM_WS_READY );
  920. };
  921. };
  922. break;
  923. };
  924. case CAM_WS_STOP_MOVE:{
  925. m_nRelativeMoveCounter++;
  926. m_fRM_Pan = .0f;
  927. m_fRM_Pan = .0f;
  928. m_fRM_Tilt = .0f;
  929. m_fRM_Tilt = .0f;
  930. m_fRM_Zoom = .0f;
  931. m_fRM_Zoom = .0f;
  932. if( relativeStop() ) {
  933. m_nHomingCounter = 0;
  934. m_nRelativeMoveCounter = 0;
  935. setWM( CAM_WS_READY );
  936. break;
  937. };
  938. if( m_sCamData.ptz_axel ) {
  939. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel) setWM(CAM_WS_READY);
  940. } else {
  941. uint8_t tVal = (uint8_t)( 10.0f * ( 2.0f - ( 1.0f + m_fCP_Zoom ) ));
  942. if (m_nRelativeMoveCounter > tVal) setWM(CAM_WS_READY);
  943. };
  944. break;
  945. };
  946. case CAM_WS_GO_ABS_ROI:
  947. case CAM_WS_GO_ABS_POSITION:{
  948. m_bCameraOnHomePosition = false;
  949. setWM( CAM_WS_BUSY );
  950. if( m_pCurrentROI != NULL ){
  951. m_nHomingCounter = 0;
  952. if( m_pBEH ){
  953. EVENT_CONTAINER *tEVT = createBasicEvent(
  954. m_sNodeData.node_id,
  955. EVT_CLASS_CAMERA_CTRL,
  956. EVT_CAMERA_MOVE_TO,
  957. NULL, NULL, NULL );
  958. if( tEVT ){
  959. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  960. m_pBEH->broadcast( tEVT );
  961. };
  962. };
  963. if( m_bNoAbsPositionning ){
  964. uint8_t COL, ROW;
  965. translateROI2PRESET(
  966. m_pCurrentROI->cam_orientation.pan,
  967. m_pCurrentROI->cam_orientation.tilt,
  968. m_pCurrentROI->cam_orientation.zoom, COL, ROW );
  969. char tB[64];
  970. sprintf( tB, "Get ABS Preset Col %d Row %d!", COL, ROW );
  971. LOG( tB );
  972. sprintf( tB, "Old Preset Col %d Row %d!", m_bCurrentPresetCol, m_bCurrentPresetRow );
  973. LOG( tB );
  974. if ( ( m_bCurrentPresetCol == COL ) && ( m_bCurrentPresetRow == ROW ) ) {
  975. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  976. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  977. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  978. // Send Capture event
  979. DBC_SNAPSHOT_DATA *tData = fusion_translate_ROI( m_pCurrentROI );
  980. utilizeROI( m_pCurrentROI );
  981. setWM( CAM_WS_READY );
  982. if( tData != NULL ) {
  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, tData );
  989. if( tEVT ){
  990. #ifdef DEBUG
  991. LOG("INSTANT BCAST CAM ONPOS");
  992. #endif
  993. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  994. m_pBEH->broadcast( tEVT );
  995. } else {
  996. free( tData );
  997. };
  998. } else {
  999. free( tData );
  1000. };
  1001. };
  1002. } else {
  1003. CSTR token = getPresetToken( COL, ROW );
  1004. if ( token ) {
  1005. LOG("Have One!");
  1006. //update position Info
  1007. m_bCurrentPresetCol = COL;
  1008. m_bCurrentPresetRow = ROW;
  1009. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1010. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1011. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1012. if( !m_pProtocol->goPreset( token ) ){
  1013. LOG_ERROR("Cannot Issue goPreset Command!->Restart Camera?");
  1014. setWM( CAM_WS_END );
  1015. } else {
  1016. // Waiting Movement finish
  1017. if( m_bSkeepPositioningWait ){
  1018. // Send Capture event
  1019. DBC_SNAPSHOT_DATA *tData = fusion_translate_ROI( m_pCurrentROI );
  1020. utilizeROI( m_pCurrentROI );
  1021. setWM( CAM_WS_READY );
  1022. if( tData != NULL ) {
  1023. if( m_pBEH ){
  1024. EVENT_CONTAINER *tEVT = createBasicEvent(
  1025. m_sNodeData.node_id,
  1026. EVT_CLASS_CAMERA_CTRL,
  1027. EVT_CAMERA_ON_POSITION,
  1028. NULL, NULL, tData );
  1029. if( tEVT ){
  1030. #ifdef DEBUG
  1031. LOG("INSTANT BCAST CAM ONPOS");
  1032. #endif
  1033. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  1034. m_pBEH->broadcast( tEVT );
  1035. } else {
  1036. free( tData );
  1037. };
  1038. } else {
  1039. free( tData );
  1040. };
  1041. };
  1042. } else {
  1043. setWM(CAM_WS_WAIT_ONPOS);
  1044. };
  1045. };
  1046. } else {
  1047. LOG("Not Found!");
  1048. utilizeROI( m_pCurrentROI );
  1049. setWM( CAM_WS_READY );
  1050. };
  1051. };
  1052. } else {
  1053. //update position Info
  1054. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1055. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1056. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1057. // Do Movement
  1058. if( !m_pProtocol->goAbsolute(
  1059. m_pCurrentROI->cam_orientation.pan,
  1060. m_pCurrentROI->cam_orientation.tilt,
  1061. ( m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection )
  1062. )){
  1063. LOG_ERROR("Cannot Issue goAbsolute Command!->Restart Camera?");
  1064. setWM( CAM_WS_END );
  1065. } else {
  1066. // Waiting Movement finish
  1067. if( m_bSkeepPositioningWait ){
  1068. // Send Capture event
  1069. DBC_SNAPSHOT_DATA *tData = fusion_translate_ROI( m_pCurrentROI );
  1070. utilizeROI( m_pCurrentROI );
  1071. setWM( CAM_WS_READY );
  1072. if( tData != NULL ) {
  1073. if( m_pBEH ){
  1074. EVENT_CONTAINER *tEVT = createBasicEvent(
  1075. m_sNodeData.node_id,
  1076. EVT_CLASS_CAMERA_CTRL,
  1077. EVT_CAMERA_ON_POSITION,
  1078. NULL, NULL, tData );
  1079. if( tEVT ){
  1080. #ifdef DEBUG
  1081. LOG("INSTANT BCAST CAM ONPOS");
  1082. #endif
  1083. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  1084. m_pBEH->broadcast( tEVT );
  1085. } else {
  1086. free( tData );
  1087. };
  1088. } else {
  1089. free( tData );
  1090. };
  1091. };
  1092. } else {
  1093. setWM(CAM_WS_WAIT_ONPOS);
  1094. };
  1095. };
  1096. };
  1097. } else setWM( CAM_WS_READY );
  1098. break;
  1099. };
  1100. case CAM_WS_WAIT_ONPOS:{
  1101. DBC_SNAPSHOT_DATA *tData = NULL;
  1102. if( m_pCurrentROI != NULL ){
  1103. // Send Capture event
  1104. tData = fusion_translate_ROI( m_pCurrentROI );
  1105. utilizeROI(m_pCurrentROI);
  1106. };
  1107. // To Accept any new ROI's ??
  1108. setWM( CAM_WS_READY );
  1109. #ifdef DEBUG
  1110. LOG("Start Waiting Cam On Position!");
  1111. #endif
  1112. if (!m_pProtocol->waitMoveIsDone()) {
  1113. //Some Cameras does not support that :(
  1114. //LOG_ERROR("Cannot Issue getPosition Command!->Restart Camera?");
  1115. //setWM( CAM_WS_END );
  1116. m_bSkeepPositioningWait = true;
  1117. };
  1118. if( tData != NULL ) {
  1119. if( m_pBEH ){
  1120. EVENT_CONTAINER *tEVT = createBasicEvent(
  1121. m_sNodeData.node_id,
  1122. EVT_CLASS_CAMERA_CTRL,
  1123. EVT_CAMERA_ON_POSITION,
  1124. NULL, NULL, tData );
  1125. if( tEVT ){
  1126. #ifdef DEBUG
  1127. LOG("BCAST CAM ONPOS");
  1128. #endif
  1129. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  1130. m_pBEH->broadcast( tEVT );
  1131. } else {
  1132. free( tData );
  1133. };
  1134. } else {
  1135. free( tData );
  1136. };
  1137. tData = NULL;
  1138. };
  1139. break;
  1140. };
  1141. case CAM_WS_GO_HOMING_PRESET:{
  1142. CSTR TK = getPresetToken( ARGUS_PRESET_TYPE_HOME );
  1143. if( TK ) {
  1144. if ( !m_bCameraOnHomePosition ) {
  1145. LOG("Go Home!");
  1146. LOG( TK );
  1147. if( !m_pProtocol->goPreset( TK )){
  1148. LOG_ERROR("Cannot Issue goPreset Command!");
  1149. };
  1150. m_bCameraOnHomePosition = true;
  1151. };
  1152. };
  1153. setWM( CAM_WS_READY );
  1154. break;
  1155. };
  1156. case CAM_WS_GO_PRESET:{
  1157. LOG("Go Preset!");
  1158. //if( m_sCamData.home_token[0] != (char)0 ) {
  1159. // LOG("Go Home!");
  1160. // LOG( m_sCamData.home_token );
  1161. // if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  1162. // LOG_ERROR("Cannot Issue goPreset Command!");
  1163. // };
  1164. //};
  1165. setWM( CAM_WS_READY );
  1166. break;
  1167. };
  1168. case CAM_WS_SET_PRESET:{
  1169. LOG("Set Preset!");
  1170. //if( m_sCamData.home_token[0] != (char)0 ) {
  1171. // LOG("Go Home!");
  1172. // LOG( m_sCamData.home_token );
  1173. // if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  1174. // LOG_ERROR("Cannot Issue goPreset Command!");
  1175. // };
  1176. //};
  1177. setWM( CAM_WS_READY );
  1178. break;
  1179. };
  1180. case CAM_WS_BUSY:{
  1181. //Handle Operation TO
  1182. setWM( CAM_WS_READY );
  1183. break;
  1184. };
  1185. case CAM_WS_READY:{
  1186. m_pCurrentROI = fusion_fetchROI();
  1187. if( m_pCurrentROI != NULL ) {
  1188. #ifdef DEBUG_EXTRA__
  1189. LOG("HAVE ROI to see!");
  1190. #endif
  1191. setWM( CAM_WS_GO_ABS_POSITION );
  1192. } else {
  1193. //Idle Work --->
  1194. if ( m_sCamData.eco_ir ) {
  1195. m_mIRProtector.lock();
  1196. if( m_bIRIsOn ){
  1197. if ( m_bIRTO ) {
  1198. if ( bNewSecondLoop ) m_bIRTO--;
  1199. } else {
  1200. CSTR TK = getPresetToken( ARGUS_PRESET_TYPE_IR_OFF );
  1201. if ( TK ) if( m_pProtocol->goPreset( TK ) ) m_bIRIsOn = false;
  1202. };
  1203. };
  1204. m_mIRProtector.unlock();
  1205. };
  1206. if (m_sCamData.homing_enable) {
  1207. if ( bNewSecondLoop ) {
  1208. if ( m_nHomingCounter < m_sCamData.homing_to ) {
  1209. m_nHomingCounter++;
  1210. } else {
  1211. //LOG("Go Home Position!");
  1212. m_nHomingCounter = 0;
  1213. setWM( CAM_WS_GO_HOMING_PRESET );
  1214. break;
  1215. };
  1216. };
  1217. };
  1218. CAM_TASK * tTASK = fetchCamTask();
  1219. if ( tTASK != NULL ) {
  1220. if( tTASK->movemet_needed ){
  1221. CAM_PTZ_CMD *tCMD = tTASK->CMD;
  1222. if( tCMD ) {
  1223. switch( tCMD->CMD ) {
  1224. case PTZ_STOP:{
  1225. m_nHomingCounter = 0;
  1226. setWM( CAM_WS_STOP_MOVE );
  1227. break;
  1228. };
  1229. case PTZ_MOVE:{
  1230. if( tState != CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
  1231. m_bRelativeMoveMatrix = 0;
  1232. m_fRM_Pan = tCMD->PAN;
  1233. m_fRM_Tilt = tCMD->TILT;
  1234. m_fRM_Zoom = tCMD->ZOOM;
  1235. m_nHomingCounter = 0;
  1236. setWM( CAM_WS_AUTOMATED_MOVE );
  1237. break;
  1238. };
  1239. case PTZ_ABSOLUTE:{
  1240. m_pCurrentROI = createCAM_ROI();
  1241. if( m_pCurrentROI != NULL ){
  1242. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD*)malloc(sizeof(CAM_TRACK_RECORD));
  1243. if ( tTarget != NULL ) {
  1244. memset( tTarget, 0, sizeof(CAM_TRACK_RECORD) );
  1245. tTarget->evt_db_ID = tTASK->source_evt_id;
  1246. m_pCurrentROI->targets.push_back( tTarget );
  1247. m_pCurrentROI->cam_orientation.pan = tCMD->PAN;
  1248. m_pCurrentROI->cam_orientation.tilt = tCMD->TILT;
  1249. m_pCurrentROI->cam_orientation.zoom = tCMD->ZOOM;
  1250. m_nHomingCounter = 0;
  1251. setWM(CAM_WS_GO_ABS_POSITION);
  1252. } else {
  1253. utilizeROI( m_pCurrentROI );
  1254. };
  1255. };
  1256. break;
  1257. };
  1258. case PTZ_RELOAD_CAMERA:{
  1259. LOG("Exit Command Rcpt");
  1260. m_bThreadStatus = TH_ENDED;
  1261. };
  1262. };
  1263. free( tCMD );
  1264. tTASK->CMD = NULL;
  1265. };
  1266. } else {
  1267. LOG("No Movement -> INSTCAP" );
  1268. // No Movement -> Just Capture
  1269. if( m_pBEH ){
  1270. EVENT_CONTAINER *tEVT = createBasicEvent(
  1271. m_sNodeData.node_id,
  1272. EVT_CLASS_CAMERA_CTRL,
  1273. EVT_CAMERA_ON_POSITION,
  1274. NULL, NULL, NULL );
  1275. if( tEVT ){
  1276. tEVT->m_db_id = tTASK->source_evt_id;
  1277. m_pBEH->broadcast(tEVT);
  1278. };
  1279. };
  1280. };
  1281. free( tTASK );
  1282. } else {
  1283. // Lowest Priority to Web Client Commands
  1284. #ifdef DEBUG_EXTRA__
  1285. LOG("Check Web CMD!");
  1286. #endif
  1287. PUSHED = m_pDBC->getNodePushedCMD( m_sNodeData.node_id );
  1288. if( PUSHED != NULL ) {
  1289. #ifdef DEBUG_EXTRA__
  1290. LOG("HAVE Web CMD!");
  1291. #endif
  1292. m_pDBC->updateNodePushedCMD( PUSHED->id, DBC_CMD_READY_TO_CLEAN );
  1293. if( ( PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK ) == ARGUS_CAM_PCMD_CMD_MASK ) {
  1294. switch( PUSHED->CMD ) {
  1295. case 0x80:{
  1296. //Call Home Preset
  1297. LOG("CALL HOME PRESET!");
  1298. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_HOME);
  1299. if ( TK ) {
  1300. LOG(TK);
  1301. if( m_pProtocol->goPreset( TK )){
  1302. m_bCameraOnHomePosition = true;
  1303. m_nHomingCounter = 0;
  1304. };
  1305. };
  1306. break;
  1307. };
  1308. case 0x81:{
  1309. //Call IR On Preset
  1310. LOG("CALL IR ON PRESET!");
  1311. m_mIRProtector.lock();
  1312. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_ON);
  1313. if ( TK ) {
  1314. LOG(TK);
  1315. if( m_pProtocol->goPreset( TK )){
  1316. m_bIRIsOn = true;
  1317. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  1318. };
  1319. } else LOG("PRESET NOT FOUND!");
  1320. m_mIRProtector.unlock();
  1321. break;
  1322. };
  1323. case 0x82:{
  1324. //Call IR Off Preset
  1325. LOG("CALL IR OFF PRESET!");
  1326. m_mIRProtector.lock();
  1327. CSTR TK = ( m_sCamData.eco_ir )?getPresetToken(ARGUS_PRESET_TYPE_IR_OFF):getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  1328. if ( TK ) {
  1329. LOG(TK);
  1330. if( m_pProtocol->goPreset( TK )){
  1331. m_bIRIsOn = false;
  1332. m_bIRTO = 0;
  1333. };
  1334. } else LOG("PRESET NOT FOUND!");
  1335. m_mIRProtector.unlock();
  1336. break;
  1337. };
  1338. case 0x83:{
  1339. //Call IR Auto Preset
  1340. LOG("CALL IR AUTO PRESET!");
  1341. m_mIRProtector.lock();
  1342. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  1343. if ( TK ) {
  1344. LOG(TK);
  1345. if( m_pProtocol->goPreset( TK )){
  1346. m_bIRIsOn = true;
  1347. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  1348. };
  1349. } else LOG("PRESET NOT FOUND!");
  1350. m_mIRProtector.unlock();
  1351. break;
  1352. };
  1353. case 0x84:{
  1354. //Call Wisher Preset
  1355. LOG("CALL WIPER PRESET!");
  1356. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_WISHER);
  1357. if ( TK ) {
  1358. LOG(TK);
  1359. m_pProtocol->goPreset( TK );
  1360. };
  1361. break;
  1362. };
  1363. };
  1364. } else if ( tState == CAM_WS_READY || tState == CAM_WS_AUTOMATED_MOVE ){ //No Way to get here
  1365. //Direct Movment Mode
  1366. if( PUSHED->CMD == ARGUS_CAM_PCMD_STOP ) {
  1367. m_nHomingCounter = 0;
  1368. setWM( CAM_WS_STOP_MOVE );
  1369. } else {
  1370. char tB[64];
  1371. if( tState != CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
  1372. m_bRelativeMoveMatrix = ( PUSHED->CMD ) >> 1;
  1373. m_nHomingCounter = 0;
  1374. setWM( CAM_WS_AUTOMATED_MOVE );
  1375. };
  1376. };
  1377. free( PUSHED );
  1378. PUSHED = NULL;
  1379. };
  1380. };
  1381. };
  1382. break;
  1383. };
  1384. case CAM_WS_END:{
  1385. LOG("Exit Command Rcpt");
  1386. m_bThreadStatus = TH_ENDED;
  1387. break;
  1388. };
  1389. };
  1390. SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  1391. };
  1392. #ifdef DEBUG
  1393. LOG("CTRL Loop End!");
  1394. #endif
  1395. };
  1396. bool deviceNodeCamera::setNoPositionWait( bool FL ){
  1397. m_bSkeepPositioningWait = FL;
  1398. return true;
  1399. };
  1400. bool deviceNodeCamera::testFOV( C3D_DECART L ){
  1401. //System Coords -> trans to local and go to funct
  1402. systemAnchor* tSystem = systemAnchor::getInstance();
  1403. if ( tSystem == NULL ) return false;
  1404. C3D_SPH_DEGREES SL;
  1405. #ifdef DEBUG_EXTRA
  1406. LOG("Test FOV local Decart coords");
  1407. #endif
  1408. if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
  1409. return testFOV( SL );
  1410. };
  1411. bool deviceNodeCamera::testFOV( C3D_WGS84_LOC L ){
  1412. //Global Coords
  1413. systemAnchor* tSystem = systemAnchor::getInstance();
  1414. if ( tSystem == NULL ) return false;
  1415. C3D_SPH_DEGREES SL;
  1416. #ifdef DEBUG_EXTRA
  1417. LOG("Test FOV WGS coords");
  1418. #endif
  1419. if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
  1420. return testFOV( SL );
  1421. };
  1422. bool deviceNodeCamera::testFOV( C3D_SPH_RADIANS L ){
  1423. //Local Coords
  1424. C3D_SPH_DEGREES SL;
  1425. #ifdef DEBUG_EXTRA
  1426. LOG("Test FOV local Spherical(rad) coords");
  1427. #endif
  1428. spherical2spherical( L, SL );
  1429. return testFOV( SL );
  1430. };
  1431. bool deviceNodeCamera::testFOV( C3D_SPH_DEGREES SL ){
  1432. #ifdef DEBUG
  1433. char tB[128];
  1434. #endif
  1435. #ifdef DEBUG_EXTRA
  1436. LOG("Test FOV local Spherical(deg) coords");
  1437. #endif
  1438. switch ( m_sCamData.triggering_mode ) {
  1439. case CAM_TRIGGER_STRICT:{
  1440. if( SL.r > m_fMaxRange || SL.r < m_fMinRange ){
  1441. #ifdef DEBUG_EXTRA
  1442. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1443. LOG( tB );
  1444. #endif
  1445. return false;
  1446. };
  1447. break;
  1448. };
  1449. case CAM_TRIGGER_ALL_NEAR:{
  1450. if( SL.r > m_fMaxRange ){
  1451. #ifdef DEBUG_EXTRA
  1452. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1453. LOG( tB );
  1454. #endif
  1455. return false;
  1456. };
  1457. break;
  1458. };
  1459. case CAM_TRIGGER_ALL_FAR:{
  1460. if( SL.r < m_fMinRange ){
  1461. #ifdef DEBUG_EXTRA
  1462. sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange );
  1463. LOG( tB );
  1464. #endif
  1465. return false;
  1466. };
  1467. break;
  1468. };
  1469. case CAM_TRIGGER_ALL: return true;
  1470. };
  1471. float HS = AC_imager_width[m_sCamData.imager_type];
  1472. float VS = AC_imager_height[m_sCamData.imager_type];
  1473. float HS2 = HS * HS;
  1474. float VS2 = VS * VS;
  1475. float IR = HS / VS;
  1476. float IR2 = IR * IR;
  1477. if( m_sCamData.pan_angles == 0 ) {
  1478. // Fixed Camera
  1479. float tA = fabsf( SL.fi );
  1480. float tZ = 0.5f * ( m_fMinHFov + ( SL.r - m_fMinRange ) * m_fR2FL );
  1481. if ( tA > tZ ) return false;
  1482. } else {
  1483. if( m_sCamData.pan_angles < 360 ) { // If endless PAN -> PASSED
  1484. // Partial Pan
  1485. switch( m_sCamData.pan_model ) {
  1486. case 1: {
  1487. // Regular Pan
  1488. float tFOV = 0.5f * ( m_fMinHFov + ( SL.r - m_fMinRange ) * m_fR2FL );
  1489. float tRad = deg2rad( SL.fi );
  1490. #ifdef DEBUG_EXTRA
  1491. sprintf( tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad );
  1492. LOG( tB );
  1493. #endif
  1494. if( ( tRad < ( -1.0 * tFOV ) ) || ( tRad > ( deg2rad( m_sCamData.pan_angles ) + tFOV ) ) ) return false;
  1495. break;
  1496. };
  1497. case 2:{
  1498. break;
  1499. };
  1500. case 3:{
  1501. break;
  1502. };
  1503. };
  1504. };
  1505. };
  1506. if( m_sCamData.tilt_angles == 0 ){
  1507. //Fixed Camera
  1508. if ( ( SL.tetta < ( m_fMaxVFov / -2.0f ) ) || ( SL.tetta > ( m_fMaxVFov / 2.0f ) ) )return false;
  1509. } else {
  1510. if( m_sCamData.tilt_angles < 90 ) { // if Cam CAN DO 90 -> Pass
  1511. // Partial Tilt
  1512. switch( m_sCamData.tilt_model ) {
  1513. case 1: {
  1514. // Regular Tilt
  1515. float tFOV = 0.5f * ( m_fMinVFov + ( m_fMaxVFov - m_fMinVFov ) * ( SL.r / m_fMaxRange ) ) ;
  1516. float tRad = deg2rad( SL.tetta );
  1517. if( ( tRad < ( -1.0 * tFOV ) ) || ( tRad > ( deg2rad( m_sCamData.tilt_angles ) + tFOV ) ) )return false;
  1518. break;
  1519. };
  1520. case 2:{
  1521. break;
  1522. };
  1523. };
  1524. };
  1525. };
  1526. return true;
  1527. };
  1528. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ){
  1529. systemAnchor* tSystem = systemAnchor::getInstance();
  1530. if( tSystem == NULL ) return false;
  1531. C3D_SPH_DEGREES SL;
  1532. #ifdef DEBUG_EXTRA
  1533. LOG("Look at WGS coords!");
  1534. #endif
  1535. tSystem->convertToLocal(&m_oPosition, L, SL );
  1536. return lookAt(TargetRefID, SL );
  1537. };
  1538. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_DECART L ){
  1539. systemAnchor* tSystem = systemAnchor::getInstance();
  1540. if( tSystem == NULL ) return false;
  1541. C3D_SPH_DEGREES SL;
  1542. #ifdef DEBUG_EXTRA
  1543. LOG("Look at System Decart coords!");
  1544. #endif
  1545. tSystem->convertToLocal( &m_oPosition, L, SL );
  1546. return lookAt(TargetRefID, SL );
  1547. };
  1548. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ){
  1549. C3D_SPH_DEGREES SL;
  1550. #ifdef DEBUG_EXTRA
  1551. LOG("Look at spherical(rad) 2 spherical(deg) coords!");
  1552. #endif
  1553. spherical2spherical( L, SL );
  1554. return lookAt(TargetRefID, SL );
  1555. };
  1556. bool deviceNodeCamera::lookAt( uint32_t TargetRefID, C3D_SPH_DEGREES L ){
  1557. if ( m_bCameraIsStatic ) {
  1558. DBC_SNAPSHOT_DATA *tData = (DBC_SNAPSHOT_DATA*)malloc(sizeof(DBC_SNAPSHOT_DATA));
  1559. if ( tData ) {
  1560. memset( tData, 0, sizeof( DBC_SNAPSHOT_DATA ));
  1561. tData->stream_id = m_sNodeData.aux_parameter;
  1562. tData->assoc_event_ids.push_back( TargetRefID );
  1563. if (m_pBEH) {
  1564. EVENT_CONTAINER *tEVT = createBasicEvent(
  1565. m_sNodeData.node_id,
  1566. EVT_CLASS_CAMERA_CTRL,
  1567. EVT_CAMERA_ON_POSITION,
  1568. NULL, NULL, tData );
  1569. if( tEVT ){
  1570. #ifdef DEBUG
  1571. LOG("INSTANT BCAST CAM ONPOS");
  1572. #endif
  1573. //tEVT->m_db_id = tTASK->source_evt_id; // EVT ids embed in DATA
  1574. m_pBEH->broadcast( tEVT );
  1575. } else {
  1576. free( tData );
  1577. };
  1578. } else {
  1579. free( tData );
  1580. };
  1581. };
  1582. return true;
  1583. };
  1584. //char tB[128];
  1585. //sprintf(tB, "Target On %.3f %.3f %.3f", L.r, L.fi, L.tetta );
  1586. //LOG( tB );
  1587. //sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
  1588. //LOG( tB );
  1589. #ifdef DEBUG_EXTRA
  1590. LOG("Look at local spherical deg. coords!(final)");
  1591. #endif
  1592. //if( getWM() == CAM_WS_READY ){
  1593. // C3D_ORIENT_ONVIF LL;
  1594. // spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  1595. // return absoluteMove( TargetRefID, LL );
  1596. //};
  1597. // Camera is Busy
  1598. if( m_bShineOnTarget ){
  1599. m_mIRProtector.lock();
  1600. if ( !m_bIRIsOn ) {
  1601. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  1602. if ( TK ) {
  1603. if( m_pProtocol->goPreset( TK )){
  1604. m_bIRIsOn = true;
  1605. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  1606. };
  1607. };
  1608. } else m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  1609. m_mIRProtector.unlock();
  1610. };
  1611. return fusion_consumeData(TargetRefID, L);
  1612. };
  1613. bool deviceNodeCamera::makeSnap( uint32_t TargetRefID ){
  1614. CAM_TASK *tTask = (CAM_TASK *)malloc(sizeof(CAM_TASK));
  1615. if( tTask ){
  1616. memset(tTask, 0, sizeof(CAM_TASK));
  1617. tTask->CMD = (CAM_PTZ_CMD *) malloc( sizeof(CAM_PTZ_CMD) );
  1618. if( tTask->CMD ){
  1619. tTask->CMD->CMD = PTZ_CAPTURE_ONLY;
  1620. tTask->movemet_needed = false;
  1621. tTask->source_evt_id = TargetRefID;
  1622. return pushCamTask( tTask );
  1623. } else {
  1624. free( tTask );
  1625. };
  1626. };
  1627. return false;
  1628. };
  1629. bool deviceNodeCamera::connectToStream( uint32_t id ){
  1630. /*
  1631. if( id ){
  1632. argusKernelModule * tKM = NULL;
  1633. argusKernel * tKRNL = NULL;
  1634. argusModuleFactory * tMF = NULL;
  1635. if( m_pDBC == NULL ) {
  1636. LOG_ERROR("No Database Connector!");
  1637. return false;
  1638. };
  1639. tKRNL = argusKernel::getInstance();
  1640. if( tKRNL ) {
  1641. tMF = tKRNL->getModuleFactory();
  1642. if( tMF ) {
  1643. tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
  1644. } else {
  1645. LOG_ERROR("No ModuleFactory Instance!");
  1646. return false;
  1647. };
  1648. } else {
  1649. LOG_ERROR("No Kernel Instance!");
  1650. return false;
  1651. };
  1652. if( tKM ) {
  1653. // New Module
  1654. DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
  1655. if( tDATA ) {
  1656. m_sMediaSource.mediaStreamId = id;
  1657. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1658. if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
  1659. m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
  1660. } else {
  1661. if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
  1662. m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource );
  1663. };
  1664. if( m_pSource != NULL ) {
  1665. char tMRL[1024];
  1666. #ifdef DEBUG
  1667. LOG("Source OK");
  1668. #endif
  1669. ((videoLIVE555Source*)m_pSource)->setWM( MS_MODE_STREAM_PROXY | MS_MODE_OVERLAYED_LOOPS | MS_MODE_DECODE_FRAMES );
  1670. int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
  1671. int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
  1672. int pix = -1;
  1673. bool in_16_9 = (((tDATA->width*100) / tDATA->height ) > 140 );
  1674. bool out_16_9 = (((tW*100) / tH ) > 140 );
  1675. updateOpticalParameters( tW, tH );
  1676. if( strlen( tDATA->c_type ) ){
  1677. };
  1678. //if( tW > 0 ){
  1679. // //m_pSource->setProportionalByWidth( tW );
  1680. // m_pSource->setSize( tW, tH );
  1681. //};
  1682. if( in_16_9 != out_16_9 ){
  1683. if( in_16_9 ){
  1684. tH = ((( tW * 1000 ) / 16 ) * 9 ) / 1000;
  1685. } else {
  1686. tW = ((( tH * 1000 ) / 3 ) * 4 ) / 1000;
  1687. };
  1688. };
  1689. if (strncmp(tDATA->mrl_proto, "v4l2", 4) == 0) {
  1690. sprintf( tMRL, tDATA->mrl );
  1691. } else {
  1692. DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
  1693. if( tCAM ) {
  1694. sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
  1695. free( tCAM );
  1696. } else {
  1697. LOG_ERROR("Error Getting CAM Data!");
  1698. delete( m_pSource );
  1699. m_pSource = NULL;
  1700. return false;
  1701. };
  1702. };
  1703. LOG( tMRL );
  1704. if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
  1705. m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
  1706. if ( !m_bSourceConnected ) {
  1707. //delete( m_pSource );
  1708. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1709. delete((videoAVLIBSource*)m_pSource);
  1710. } else {
  1711. delete((videoLIVE555Source*)m_pSource);
  1712. };
  1713. m_pSource = NULL;
  1714. } else {
  1715. m_nActiveStreamID = id;
  1716. #ifdef DEBUG
  1717. LOG("Source is Connected to Output.");
  1718. #endif
  1719. };
  1720. } else {
  1721. LOG_ERROR("Can not Open Video Source!");
  1722. //delete( m_pSource );
  1723. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  1724. delete((videoAVLIBSource*)m_pSource);
  1725. } else {
  1726. delete((videoLIVE555Source*)m_pSource);
  1727. };
  1728. m_pSource = NULL;
  1729. };
  1730. } else {
  1731. LOG_ERROR("Video Source Stream Failure!");
  1732. };
  1733. free( tDATA );
  1734. };
  1735. }
  1736. #ifdef DEBUG
  1737. else LOG("No Video Module!")
  1738. #endif
  1739. ;
  1740. };
  1741. LOG("Connect Finished!");
  1742. return m_bSourceConnected;
  1743. */
  1744. return true;
  1745. };
  1746. bool deviceNodeCamera::disconnectFromStream( void ){
  1747. /*if( m_bSourceConnected ) {
  1748. if( m_pSource ){
  1749. delete( m_pSource );
  1750. m_pSource = NULL;
  1751. };
  1752. m_bSourceConnected = false;
  1753. };
  1754. return !m_bSourceConnected;
  1755. */
  1756. return true;
  1757. };
  1758. bool deviceNodeCamera::validateStream( void ){
  1759. /*
  1760. if( m_bSourceConnected ) {
  1761. if( m_pSource ) {
  1762. if( m_pSource->isAttached() ){
  1763. if( m_pSource->getStatus() < MS_STOPED ) return true;
  1764. #ifdef DEBUG
  1765. LOG("Source is Finished!");
  1766. #endif
  1767. };
  1768. #ifdef DEBUG
  1769. LOG("Source is Disconnected!");
  1770. #endif
  1771. } else LOG_ERROR("No Source Object! Set Disconnected!");
  1772. disconnectFromStream();
  1773. };
  1774. return false;
  1775. */
  1776. return true;
  1777. };
  1778. bool deviceNodeCamera::validate(){
  1779. if ( m_pDBC == NULL ) return false;
  1780. DBC_CAM_DATA *tDATA = m_pDBC->getCamData( m_sCamData.id );
  1781. if ( tDATA == NULL ) return false;
  1782. if ( memcmp( tDATA, &m_sCamData, sizeof(DBC_CAM_DATA) ) != 0 ) {
  1783. //Settings Changed
  1784. memcpy(&m_sCamData, tDATA, sizeof(DBC_CAM_DATA) );
  1785. };
  1786. free( tDATA );
  1787. if (!validateStream()) return false;
  1788. return deviceNode::validate();
  1789. };
  1790. bool deviceNodeCamera::load_presets( void ){
  1791. bool bHaveIROFF = false;
  1792. bool bHaveIRON = false;
  1793. bool bHaveIRAUTO = false;
  1794. if ( m_pDBC == NULL ) return false;
  1795. DBC_PRESETS_INFO *tData = m_pDBC->getCamPresetInfo(m_sCamData.id);
  1796. if ( tData ) {
  1797. memcpy( &m_sCamPresets, tData, sizeof(DBC_PRESETS_INFO));
  1798. #ifdef DEBUG
  1799. char tB[128];
  1800. LOG("Loading Presets!");
  1801. sprintf( tB, "Cam Presets Info: CNT: %d Cols: %d Rows: %d ", m_sCamPresets.maxCount, m_sCamPresets.gCols, m_sCamPresets.gRows );
  1802. LOG( tB );
  1803. #endif
  1804. DBC_INT_LIST *tList = m_pDBC->listCamPresets( m_sCamData.id );
  1805. if ( tList ) {
  1806. for( DBC_INT_LIST::iterator idx= tList->begin(); idx < tList->end(); idx++ ) {
  1807. CAM_PRESET *tData = m_pDBC->getCamPreset( *idx );
  1808. if ( tData ) {
  1809. m_sCamPresets.presets.push_back(tData);
  1810. bHaveIRON = ( tData->role == ARGUS_PRESET_TYPE_IR_ON )?true:bHaveIRON;
  1811. bHaveIROFF = ( tData->role == ARGUS_PRESET_TYPE_IR_OFF )?true:bHaveIROFF;
  1812. bHaveIRAUTO = ( tData->role == ARGUS_PRESET_TYPE_IR_AUTO )?true:bHaveIRAUTO;
  1813. };
  1814. };
  1815. delete(tList);
  1816. };
  1817. if ( m_sCamData.eco_ir ) {
  1818. m_bShineOnTarget = (bHaveIROFF && bHaveIRAUTO);
  1819. } else m_bShineOnTarget = false;
  1820. return true;
  1821. #ifdef DEBUG
  1822. } else {
  1823. LOG("No Camera Presets!");
  1824. #endif
  1825. };
  1826. return false;
  1827. };
  1828. void deviceNodeCamera::translateROI2PRESET( float P, float T, float Z, uint8_t &col, uint8_t &row ){
  1829. char tB[128];
  1830. row = (uint8_t) ( Z * ((float)m_sCamPresets.gRows));
  1831. if ( P < 0.5 ){
  1832. P = P + 1.5f;
  1833. } else {
  1834. P = P - 0.5f;
  1835. };
  1836. col = (uint8_t) ( P * ((float)(m_sCamPresets.gCols * (1 << row)) / 2.0f ));
  1837. row++;
  1838. };
  1839. CSTR deviceNodeCamera::getPresetToken( uint8_t CCOL, uint8_t CROW ){
  1840. if( m_sCamPresets.presets.size() > 0 )
  1841. for (V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++)
  1842. if ( (*idx)->role == ARGUS_PRESET_TYPE_POSITION )
  1843. if ( ( (*idx)->row == CROW ) && ( (*idx)->col == CCOL ) ) return (CSTR)(*idx)->token;
  1844. return NULL;
  1845. };
  1846. CSTR deviceNodeCamera::getPresetToken( uint8_t specialRole ){
  1847. if( m_sCamPresets.presets.size() > 0 )
  1848. for ( V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++ )
  1849. if ( (*idx)->role == specialRole ) return (CSTR)(*idx)->token;
  1850. return NULL;
  1851. };
  1852. #undef LOG
  1853. #undef LOG_ERROR
  1854. //#undef DEBUG_EXTRA