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.

2865 lines
70 KiB

​
​
​
5 months ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 months ago
​
​
​
​
2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 months ago
​
​
​
​
2 months ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months 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 "../../data/protocol/protocolPTZ_ONVIF.h"
  5. #include "../../data/protocol/protocolPTZ_PELCO.h"
  6. #include "../../data/protocol/protocolPTZ_VISCA.h"
  7. #include "../../data/protocol/protocolPTZ_BRCP.h"
  8. //#include "../../hardware/uart/serialPort.h"
  9. //#include "../../hardware/uart/serialSOL.h"
  10. #include "../mojo/mojoKernel.h"
  11. #include "hardwareManager.h"
  12. #include "hardwareResourceSerialProvider.h"
  13. #include "kernelModuleEmbedVideo.h"
  14. #define LOG(X) deviceNode::m_pLog->Log("RCAM", this, X)
  15. //#define DEBUG_EXTRA
  16. #ifdef DEBUG
  17. #define LOG_ERROR(X) \
  18. { \
  19. char _tBfrErrMSG2w34[512]; \
  20. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  21. deviceNode::m_pLog->Log("RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  22. }
  23. #else
  24. #define LOG_ERROR(X) deviceNode::m_pLog->Log("RCAM", this, _LOG_ERROR, X);
  25. #endif
  26. // all sizes in mm
  27. 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};
  28. 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};
  29. 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};
  30. #define CAM_FOCAL_LENGTH_CNT 49
  31. static const float cam_predef_focal_length[CAM_FOCAL_LENGTH_CNT] = {2.7f, 3.0f, 3.2f, 3.5f, 3.7f, 3.9f, 4.0f, 4.3f, 4.8f, 5.0f, 5.1f, 5.5f, 5.8f, 6.0f, 6.2f, 6.6f, 7.0f, 7.1f, 7.5f, 7.6f, 8.0f, 8.6f, 8.9f, 9.0f, 9.2f, 9.3f, 10.0f, 10.5f, 10.6f,
  32. 10.7f, 11.0f, 11.3f, 12.0f, 12.9f, 13.0f, 13.5f, 13.6f, 14.0f, 14.6f, 15.0f, 15.1f, 15.5f, 16.0f, 17.0f, 17.5f, 17.7f, 18.0f, 18.2f, 19.0f};
  33. deviceNodeCamera::deviceNodeCamera(uint32_t NodeID) :
  34. deviceNode(NodeID),
  35. basicThread()
  36. {
  37. // m_pLog = basicLogCollection::getInstance();
  38. m_pBEH = basicEventHeap::getInstance();
  39. m_bSkeepPositioningWait = true;
  40. m_bNoMoveDoneReport = false;
  41. m_bNoAbsPositionning = false;
  42. m_bCameraOnHomePosition = false;
  43. m_tTimeTSeconds = 0;
  44. m_pProtocol = NULL;
  45. // m_pTransport = NULL;
  46. m_pCurrentROI = NULL;
  47. m_nRealFrameWidth = 640;
  48. // m_bState = 0;
  49. // m_bBusy = true;
  50. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  51. m_nRelativeMoveCounter = 0;
  52. m_bRelativeMoveMatrix = 0;
  53. m_bCurrentPresetCol = 0;
  54. m_bCurrentPresetRow = 0;
  55. m_bShineOnTarget = false;
  56. m_bCameraIsStatic = false;
  57. m_bIRIsOn = false;
  58. m_bIRTO = 0;
  59. m_fSpeedRise = 0.03f;
  60. m_fZoomCorrection = 1.0f;
  61. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  62. // m_bSourceConnected = false;
  63. // m_pSource = NULL;
  64. }
  65. deviceNodeCamera::deviceNodeCamera(DBC_NODE_DATA * Data) :
  66. deviceNode(Data),
  67. basicThread()
  68. {
  69. // m_pLog = basicLogCollection::getInstance();
  70. m_pBEH = basicEventHeap::getInstance();
  71. m_bSkeepPositioningWait = true;
  72. m_bNoMoveDoneReport = false;
  73. m_bNoAbsPositionning = false;
  74. m_bCameraOnHomePosition = false;
  75. m_tTimeTSeconds = 0;
  76. m_pProtocol = NULL;
  77. // m_pTransport = NULL;
  78. m_pCurrentROI = NULL;
  79. m_nRealFrameWidth = 640;
  80. // m_bState = 0;
  81. // m_bBusy = true;
  82. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  83. m_nRelativeMoveCounter = 0;
  84. m_bRelativeMoveMatrix = 0;
  85. m_bCurrentPresetCol = 0;
  86. m_bCurrentPresetRow = 0;
  87. m_bShineOnTarget = false;
  88. m_bIRIsOn = false;
  89. m_bIRTO = 0;
  90. m_fSpeedRise = 0.03f;
  91. m_fZoomCorrection = 1.0f;
  92. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  93. // m_bSourceConnected = false;
  94. // m_pSource = NULL;
  95. }
  96. deviceNodeCamera::~deviceNodeCamera()
  97. {
  98. LOG("Destruct");
  99. // m_mQPROTECTOR.unlock();
  100. waitThreadEnd(true);
  101. LOG("Thread Del OK");
  102. /*if( m_pTransport!= NULL ) {
  103. if( m_sCamData.uart_id ) {
  104. DBC_UART_DATA *tData = NULL;
  105. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  106. switch( tData->type ) {
  107. case UART_TYPE_HARDWARE:{
  108. delete((serialPort*)m_pTransport);
  109. break;
  110. };
  111. case UART_TYPE_SOL:{
  112. delete((serialSOL*)m_pTransport);
  113. break;
  114. };
  115. };
  116. };
  117. };
  118. LOG("Transport Del OK");
  119. */
  120. if (m_pProtocol != NULL)
  121. {
  122. switch (m_sCamData.protocol)
  123. {
  124. case CAM_CTRL_PROTO_VISCA: delete((protocolPTZ_VISCA *) m_pProtocol); break;
  125. case CAM_CTRL_PROTO_PELCO: delete((protocolPTZ_PELCO *) m_pProtocol); break;
  126. case CAM_CTRL_PROTO_ONVIF: delete((protocolPTZ_ONVIF *) m_pProtocol); break;
  127. case CAM_CTRL_PROTO_BRCP: delete((protocolPTZ_BRCP *) m_pProtocol); break;
  128. default : delete(m_pProtocol);
  129. };
  130. };
  131. LOG("Proto Del OK");
  132. // if( m_pPosition != NULL ) delete( m_pPosition );
  133. // LOG("Pos Del OK");
  134. // if( m_bSourceConnected ){
  135. // if( m_pSource != NULL ){
  136. // m_pSource->_close();
  137. // delete( m_pSource );
  138. // };
  139. // };
  140. // LOG("Stream Del OK");
  141. }
  142. void deviceNodeCamera::updateOpticalParameters(uint16_t frame_width, uint16_t frame_heigth)
  143. {
  144. #ifdef DEBUG
  145. char tB[128];
  146. LOG("Set Optical Parameters");
  147. sprintf(tB, "\tCapturing Frame: %dx%d ", frame_width, frame_heigth);
  148. LOG(tB);
  149. #endif
  150. if (frame_width > 0 && frame_heigth > 0)
  151. {
  152. m_nRealFrameWidth = frame_width;
  153. m_nRealFrameHeight = frame_heigth;
  154. float tFrameDiag = sqrtf(m_nRealFrameHeight * m_nRealFrameHeight + m_nRealFrameWidth * m_nRealFrameWidth);
  155. switch (m_sCamData.zoom_model)
  156. {
  157. case 0:
  158. {
  159. #ifdef DEBUG
  160. LOG("\tFixed Zoom");
  161. #endif
  162. m_fMaxFL = m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  163. m_fMinRange = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag);
  164. m_fMaxRange = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag);
  165. m_fR2FL = .0f;
  166. m_fZoomCorrection = .0f;
  167. m_pDBC->updateCamRange(m_sCamData.id, m_fMaxRange);
  168. break;
  169. };
  170. case 1:
  171. {
  172. #ifdef DEBUG
  173. LOG("\tAutomated Zoom");
  174. #endif
  175. m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  176. m_fMinRange = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag);
  177. m_fMaxFL = cam_predef_focal_length[m_sCamData.lens_f] * m_sCamData.zoom;
  178. m_fMaxRange = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag);
  179. if (m_fMaxRange > m_fMinRange)
  180. {
  181. m_fR2FL = ((m_fMaxFL - m_fMinFL) / (m_fMaxRange - m_fMinRange));
  182. }
  183. else
  184. {
  185. m_fR2FL = .0f;
  186. };
  187. m_fZoomCorrection = 1.0f;
  188. m_pDBC->updateCamRange(m_sCamData.id, m_fMaxRange);
  189. break;
  190. };
  191. case 2:
  192. {
  193. #ifdef DEBUG
  194. LOG("\tManual Zoom");
  195. #endif
  196. //The Fixing minimal distance from 5 meters to a 0.5
  197. m_fMinRange = 0.5f; // Minimal 0.5 meters
  198. if (m_sCamData.max_range < m_fMinRange)
  199. {
  200. m_fMaxRange = m_fMinRange;
  201. }
  202. else
  203. {
  204. m_fMaxRange = m_sCamData.max_range;
  205. };
  206. m_fZoomCorrection = m_sCamData.zoom * 0.01f;
  207. m_fMinFL = calcCFL(AC_imager_width[m_sCamData.imager_type], m_fMinRange);//, tFrameDiag);
  208. m_fMaxFL = calcCFL(AC_imager_width[m_sCamData.imager_type], m_fMaxRange);//, tFrameDiag);
  209. break;
  210. };
  211. };
  212. m_fMinHFov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], m_fMaxFL));
  213. m_fMaxHFov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], m_fMinFL));
  214. m_fMinVFov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], m_fMaxFL));
  215. m_fMaxVFov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], m_fMinFL));
  216. #ifdef DEBUG
  217. sprintf(tB, "\tMinimal FL: %0.3fmm. Maximal FL: %0.3fmm. ", m_fMinFL, m_fMaxFL);
  218. LOG(tB);
  219. sprintf(tB, "\tMinimal Range: %0.2fm. Maximal Range: %0.2fm. ", m_fMinRange, m_fMaxRange);
  220. LOG(tB);
  221. sprintf(tB, "\tMinimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov);
  222. LOG(tB);
  223. sprintf(tB, "\tMaximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov);
  224. LOG(tB);
  225. #endif
  226. };
  227. }
  228. bool deviceNodeCamera::create()
  229. {
  230. if (m_bThreadStatus == TH_WORKING)
  231. {
  232. return true;
  233. }
  234. setWM(CAM_WS_INIT);
  235. if (m_sNodeData.aux_id == 0)
  236. {
  237. return false;
  238. }
  239. DBC_CAM_DATA * tData = m_pDBC->getCamData(m_sNodeData.aux_id);
  240. if (tData != NULL)
  241. {
  242. memcpy(&m_sCamData, tData, sizeof(DBC_CAM_DATA));
  243. free(tData);
  244. }
  245. else
  246. {
  247. LOG_ERROR("Cannot Fetch CAM Data from Database!");
  248. return false;
  249. };
  250. if (! (m_sCamData.lens_f < CAM_FOCAL_LENGTH_CNT))
  251. {
  252. m_sCamData.lens_f = CAM_FOCAL_LENGTH_CNT - 1;
  253. }
  254. updateOpticalParameters(1280, 720); // HD Ready
  255. if (m_sCamData.ptz_speed_step > .0f)
  256. {
  257. m_fSpeedRise = m_sCamData.ptz_speed_step;
  258. };
  259. // m_pPosition = new basicPosition();// m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
  260. // if( m_pPosition == NULL ) {
  261. // LOG_ERROR("Position Constructor Failure!");
  262. // return false;
  263. // };
  264. // m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z );
  265. // m_oPosition.setOrientationDeg( m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot );
  266. systemAnchor * SA = systemAnchor::getInstance();
  267. if( SA ){
  268. LOG("SysAnchor OK");
  269. if( SA->beLocal() ){
  270. LOG("SysAnchor beLocal!");
  271. m_oPosition.setPositionXYZ(m_sCamData.x, m_sCamData.y, m_sCamData.z, 0); // SA->getUTMZone() );
  272. m_oPosition.setOrientationDeg(m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot);
  273. } else {
  274. LOG("SysAnchor is Global Position System!");
  275. C3D_DECART LD = SA->getXYZ();
  276. m_oPosition.setPositionXYZ(LD.x + m_sCamData.x, LD.y + m_sCamData.y, LD.z + m_sCamData.z, SA->getUTMZone());
  277. m_oPosition.setOrientationDeg(m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot);
  278. };
  279. } else {
  280. LOG("No SysAnchor!");
  281. m_oPosition.setPositionXYZ(m_sCamData.x, m_sCamData.y, m_sCamData.z);
  282. m_oPosition.setOrientationDeg(m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot);
  283. };
  284. m_oPosition.updateMatrix();
  285. #ifdef DEBUG
  286. char tB[128];
  287. sprintf(tB, "Finalized Camera Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt());
  288. LOG(tB);
  289. sprintf(tB, "Finalized Camera Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ());
  290. LOG(tB);
  291. sprintf(tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg());
  292. LOG(tB);
  293. #endif
  294. if (m_pProtocol != NULL)
  295. {
  296. LOG_ERROR("Cannot Start: Service Already Running!");
  297. return false;
  298. };
  299. #ifdef CAM_POST_INIT
  300. if ((m_sCamData.type == ARGUS_IP_PRESET_CAMERA) || (m_sCamData.type == ARGUS_ANALOG_PRESET_CAMERA))
  301. {
  302. m_bNoAbsPositionning = true;
  303. }
  304. if (m_sCamData.protocol == 0)
  305. {
  306. m_bCameraIsStatic = true;
  307. m_bSkeepPositioningWait = true;
  308. m_sCamData.online = true;
  309. m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
  310. return m_sCamData.online;
  311. };
  312. m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
  313. return init();
  314. #else //! CAM_POST_INIT
  315. switch (m_sCamData.protocol)
  316. {
  317. case CAM_CTRL_PROTO_VISCA:
  318. {
  319. #ifdef DEBUG
  320. LOG("VISCA");
  321. #endif
  322. m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA(m_sCamData.protocol_aux);
  323. if (m_pProtocol != NULL)
  324. {
  325. basicTransport * tTransport = NULL;
  326. hardwareManager * tHM = hardwareManager::getInstance();
  327. if (tHM)
  328. {
  329. hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
  330. if (tRES != NULL)
  331. {
  332. if (tRES->isValid())
  333. {
  334. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  335. if (m_pProtocol->setTransport(tTransport))
  336. {
  337. if (! m_pProtocol->create())
  338. {
  339. LOG_ERROR("Protocol <<< Create >>> Failure!");
  340. };
  341. }
  342. else
  343. {
  344. LOG_ERROR("Binding Port Failure!");
  345. };
  346. };
  347. #ifdef DEBUG
  348. }
  349. else
  350. {
  351. LOG("HWM Has No UART PORT!");
  352. #endif
  353. };
  354. #ifdef DEBUG
  355. }
  356. else
  357. {
  358. LOG_ERROR("Can not get Hardware Manager!");
  359. #endif
  360. };
  361. if (tTransport != NULL)
  362. {
  363. LOG("Bind Transport Port!");
  364. }
  365. else
  366. {
  367. LOG_ERROR("Transport Creation Failure!");
  368. delete((protocolPTZ_VISCA *) m_pProtocol);
  369. m_pProtocol = NULL;
  370. };
  371. #ifdef DEBUG
  372. }
  373. else
  374. {
  375. LOG_ERROR("Protocol Creation failure!");
  376. #endif
  377. };
  378. break;
  379. };
  380. case CAM_CTRL_PROTO_PELCO:
  381. {
  382. #ifdef DEBUG
  383. LOG("PELCO");
  384. #endif
  385. m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO(m_sCamData.protocol_aux);
  386. if (m_pProtocol != NULL)
  387. {
  388. basicTransport * tTransport = NULL;
  389. hardwareManager * tHM = hardwareManager::getInstance();
  390. if (tHM)
  391. {
  392. hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
  393. if (tRES != NULL)
  394. {
  395. if (tRES->isValid())
  396. {
  397. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  398. if (m_pProtocol->setTransport(tTransport))
  399. {
  400. if (! m_pProtocol->create())
  401. {
  402. LOG_ERROR("Protocol <<< Create >>> Failure!");
  403. };
  404. }
  405. else
  406. {
  407. LOG_ERROR("Binding Port Failure!");
  408. };
  409. };
  410. #ifdef DEBUG
  411. }
  412. else
  413. {
  414. LOG("HWM Has No UART PORT!");
  415. #endif
  416. };
  417. #ifdef DEBUG
  418. }
  419. else
  420. {
  421. LOG_ERROR("Can not get Hardware Manager!");
  422. #endif
  423. };
  424. if (tTransport != NULL)
  425. {
  426. LOG("Bind Transport Port!");
  427. }
  428. else
  429. {
  430. LOG_ERROR("Transport Creation Failure!");
  431. delete((protocolPTZ_PELCO *) m_pProtocol);
  432. m_pProtocol = NULL;
  433. };
  434. #ifdef DEBUG
  435. }
  436. else
  437. {
  438. LOG_ERROR("Protocol Creation failure!");
  439. #endif
  440. };
  441. break;
  442. };
  443. case CAM_CTRL_PROTO_ONVIF:
  444. {
  445. #ifdef DEBUG_EXTRA
  446. LOG("ONVIF");
  447. #endif
  448. // m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  449. if (strstr(m_sCamData.onvif_ctrl, "http") == NULL)
  450. {
  451. char tURI[256];
  452. if (m_sCamData.port)
  453. {
  454. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  455. }
  456. else
  457. {
  458. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  459. };
  460. LOG("PTZ BUILD URI");
  461. LOG(tURI);
  462. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  463. }
  464. else
  465. {
  466. LOG("USE FULL PTZ URI");
  467. LOG(m_sCamData.onvif_ctrl);
  468. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  469. };
  470. #ifdef DEBUG_EXTRA
  471. LOG("ONVIF-END");
  472. #endif
  473. if (m_pProtocol != NULL)
  474. {
  475. if (! m_pProtocol->create())
  476. {
  477. LOG_ERROR("Error Creating Proto!");
  478. delete((protocolPTZ_ONVIF *) m_pProtocol);
  479. m_pProtocol = NULL;
  480. };
  481. #ifdef DEBUG_EXTRA
  482. LOG("PROTO CREATE DONE");
  483. #endif
  484. };
  485. break;
  486. };
  487. case CAM_CTRL_PROTO_BRCP:{
  488. #ifdef DEBUG
  489. LOG("BRCP");
  490. #endif
  491. // m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  492. if (strstr(m_sCamData.onvif_ctrl, "http") == NULL)
  493. {
  494. char tURI[256];
  495. if (m_sCamData.port)
  496. {
  497. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  498. }
  499. else
  500. {
  501. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  502. };
  503. m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  504. }
  505. else
  506. {
  507. m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  508. };
  509. #ifdef DEBUG
  510. LOG("BRCP-END");
  511. #endif
  512. if (m_pProtocol != NULL)
  513. {
  514. if (! m_pProtocol->create())
  515. {
  516. LOG_ERROR("Error Creating Proto!");
  517. delete((protocolPTZ_BRCP *) m_pProtocol);
  518. m_pProtocol = NULL;
  519. };
  520. #ifdef DEBUG
  521. LOG("PROTO CREATE DONE");
  522. #endif
  523. };
  524. break;
  525. };
  526. default:
  527. {
  528. #ifdef DEBUG
  529. LOG("Camera Has no defined control protocol");
  530. #endif
  531. };
  532. };
  533. // Check - No ABS Movement!
  534. if ((m_sCamData.type == ARGUS_IP_PRESET_CAMERA) || (m_sCamData.type == ARGUS_ANALOG_PRESET_CAMERA))
  535. {
  536. m_bNoAbsPositionning = true;
  537. }
  538. if (m_pProtocol == NULL)
  539. {
  540. if (m_sCamData.protocol == 0)
  541. {
  542. m_bCameraIsStatic = true;
  543. m_bSkeepPositioningWait = true;
  544. m_sCamData.online = true;
  545. }
  546. else
  547. {
  548. LOG_ERROR("No Proto Created!");
  549. }
  550. }
  551. else
  552. {
  553. #ifdef DEBUG
  554. LOG("Proto is OK");
  555. #endif
  556. // Load Presets only if we have protocol
  557. load_presets();
  558. mojoKernel * tKRNL = mojoKernel::getInstance();
  559. m_bNoMoveDoneReport = false;
  560. if (tKRNL)
  561. {
  562. m_bSkeepPositioningWait = ((tKRNL->getMediaMode() & EVE_OUTPUT_VIDEO) == EVE_OUTPUT_VIDEO);
  563. #ifdef DEBUG
  564. char ttTT[128];
  565. sprintf(ttTT, "Kernel Media Mode:%d", tKRNL->getMediaMode());
  566. LOG(ttTT);
  567. if (m_bSkeepPositioningWait)
  568. {
  569. LOG("Camera No Wait On Pos!");
  570. }
  571. else
  572. {
  573. LOG("Camera Will Wait On Pos!");
  574. };
  575. #endif
  576. }
  577. else
  578. {
  579. LOG_ERROR("No Kernel Instance!");
  580. };
  581. m_sCamData.online = init();
  582. };
  583. m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
  584. return m_sCamData.online;
  585. #endif //! CAM_POST_INIT
  586. }
  587. // void deviceNodeCamera::setBusy( bool Status ){
  588. // m_bBusy = Status;
  589. //};
  590. bool deviceNodeCamera::relativeMove(float PanSPD, float TiltSPD, float ZoomSPD)
  591. {
  592. if (m_sCamData.online)
  593. {
  594. uint32_t MoveMatrix = 0;
  595. if (PanSPD != .0f)
  596. {
  597. if (PanSPD > 0)
  598. {
  599. if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 2)
  600. {
  601. MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
  602. }
  603. else
  604. {
  605. MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
  606. };
  607. }
  608. else
  609. {
  610. if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 2)
  611. {
  612. MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
  613. }
  614. else
  615. {
  616. MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
  617. };
  618. };
  619. };
  620. if (TiltSPD != .0f)
  621. {
  622. if (TiltSPD > 0)
  623. {
  624. if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 1)
  625. {
  626. MoveMatrix |= PTZ_DRIVE_TILT_UP;
  627. }
  628. else
  629. {
  630. MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
  631. };
  632. }
  633. else
  634. {
  635. if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 1)
  636. {
  637. MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
  638. }
  639. else
  640. {
  641. MoveMatrix |= PTZ_DRIVE_TILT_UP;
  642. };
  643. };
  644. };
  645. if (ZoomSPD != .0f)
  646. {
  647. if (ZoomSPD > 0)
  648. {
  649. MoveMatrix |= PTZ_DRIVE_ZOOM_WIDE;
  650. }
  651. else
  652. {
  653. MoveMatrix |= PTZ_DRIVE_ZOOM_TELE;
  654. };
  655. };
  656. if (MoveMatrix != 0)
  657. {
  658. m_pProtocol->setPTZSpeed(fabs(PanSPD), fabs(TiltSPD), fabs(ZoomSPD));
  659. };
  660. return m_pProtocol->move(MoveMatrix);
  661. };
  662. return false;
  663. }
  664. bool deviceNodeCamera::relativeStop()
  665. {
  666. if (m_sCamData.online)
  667. {
  668. return m_pProtocol->move(0);
  669. };
  670. return false;
  671. }
  672. CAM_TASK * deviceNodeCamera::fetchCamTask(void)
  673. {
  674. CAM_TASK * rVal = NULL;
  675. m_mQPROTECTOR.lock();
  676. if (m_qCAM_TASK.size())
  677. {
  678. rVal = m_qCAM_TASK.front();
  679. m_qCAM_TASK.pop();
  680. };
  681. m_mQPROTECTOR.unlock();
  682. return rVal;
  683. }
  684. bool deviceNodeCamera::pushCamTask(CAM_TASK * ptr)
  685. {
  686. if (ptr == NULL)
  687. {
  688. return false;
  689. }
  690. m_mQPROTECTOR.lock();
  691. m_qCAM_TASK.push(ptr);
  692. m_mQPROTECTOR.unlock();
  693. return true;
  694. }
  695. #ifndef NO_CAMERA_FUSION_ENGINE
  696. bool deviceNodeCamera::fusion_compare(CAM_ROI * ptr, C3D_SPH_DEGREES tp)
  697. {
  698. if (ptr == NULL)
  699. {
  700. return false;
  701. }
  702. float tFI = fabsf(ptr->cam_position.fi - tp.fi);
  703. float tTETTA = fabsf(ptr->cam_position.tetta - tp.tetta);
  704. #ifdef DEBUG_ALL
  705. char tB[128];
  706. 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);
  707. LOG(tB);
  708. #endif
  709. if (tFI > ptr->h_fov)
  710. {
  711. return false;
  712. }
  713. if (tTETTA > ptr->v_fov)
  714. {
  715. return false;
  716. }
  717. if (tp.r < ptr->min_range)
  718. {
  719. return false;
  720. }
  721. if (tp.r > ptr->max_range)
  722. {
  723. return false;
  724. }
  725. return true;
  726. }
  727. bool deviceNodeCamera::fusion_consumeData(uint32_t db_id, C3D_SPH_DEGREES tOR)
  728. {
  729. if (db_id == 0)
  730. {
  731. return false;
  732. }
  733. CAM_TRACK_RECORD * tTrackRecord = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
  734. if (tTrackRecord == NULL)
  735. {
  736. return false;
  737. }
  738. #ifdef DEBUG_EXTRA
  739. LOG("Fusion: Consuming new Data!");
  740. #endif
  741. memset(tTrackRecord, 0, sizeof(CAM_TRACK_RECORD));
  742. tTrackRecord->target_direction.fi = tOR.fi;
  743. tTrackRecord->target_direction.r = tOR.r;
  744. tTrackRecord->target_direction.tetta = tOR.tetta;
  745. tTrackRecord->evt_db_ID = db_id;
  746. tTrackRecord->ts_ms = getMilliseconds();
  747. m_mROIsProtector.lock();
  748. vCAM_ROIS::iterator idx = m_vROIS.begin();
  749. for (; idx < m_vROIS.end(); idx++)
  750. {
  751. if (fusion_compare(*idx, tOR))
  752. {
  753. break;
  754. }
  755. }
  756. if (idx != m_vROIS.end())
  757. {
  758. // have Match!
  759. #ifdef DEBUG_EXTRA
  760. LOG("ROI MATCHED!");
  761. #endif
  762. (*idx)->targets.push_back(tTrackRecord);
  763. fusion_validateROI(tTrackRecord->ts_ms, *idx);
  764. }
  765. else
  766. {
  767. #ifdef DEBUG_EXTRA
  768. LOG("NO MATCH FOUND!");
  769. #endif
  770. // No mathced ROI -> create new one
  771. //CAM_ROI * tROI = (CAM_ROI *) malloc(sizeof(CAM_ROI));
  772. CAM_ROI * tROI = new CAM_ROI();
  773. if (tROI)
  774. {
  775. tROI->ts_ms = tTrackRecord->ts_ms;
  776. spherical2onvif(tOR, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  777. tROI->cam_position.fi = tOR.fi;
  778. tROI->cam_position.tetta = tOR.tetta;
  779. tROI->cam_position.r = tOR.r;
  780. float cFL = m_fMinFL + m_fR2FL * (tROI->cam_position.r - m_fMinRange);
  781. tROI->max_range = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
  782. tROI->min_range = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
  783. tROI->h_fov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], cFL)) / 2.0f; // div to no to div in comparation function
  784. tROI->v_fov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], cFL)) / 2.0f; // that will be called more ofthen
  785. tROI->targets.push_back(tTrackRecord);
  786. m_vROIS.push_back(tROI);
  787. };
  788. };
  789. m_mROIsProtector.unlock();
  790. return true;
  791. }
  792. bool deviceNodeCamera::fusion_validateROI(uint64_t cts, CAM_ROI * ptr)
  793. {
  794. if (ptr == NULL)
  795. {
  796. return false;
  797. }
  798. if ((cts - ptr->ts_ms) > LOSE_INTERES_TIME_MS)
  799. {
  800. return false;
  801. }
  802. #ifdef DEBUG_EXTRA
  803. char tB[128];
  804. sprintf(tB, "\tROI [%d]", ptr->targets.size());
  805. LOG(tB);
  806. #endif
  807. if (ptr->targets.size())
  808. {
  809. double tA = 0.0;
  810. double tB = 0.0;
  811. double tC = 0.0;
  812. uint32_t tCNT = 0;
  813. for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end();)
  814. {
  815. if ((cts - (*idx)->ts_ms) > LOSE_INTERES_TIME_MS)
  816. {
  817. free(*idx);
  818. ptr->targets.erase(idx);
  819. }
  820. else
  821. {
  822. tA = tA + (*idx)->target_direction.fi;
  823. tB = tB + (*idx)->target_direction.tetta;
  824. tC = tC + (*idx)->target_direction.r;
  825. tCNT++;
  826. idx++;
  827. };
  828. };
  829. if (tCNT)
  830. {
  831. C3D_SPH_DEGREES L;// = {0};
  832. //memset( &L, 0, sizeof(C3D_SPH_DEGREES));
  833. L.fi = (float) (tA / (double) tCNT);
  834. L.tetta = (float) (tB / (double) tCNT);
  835. L.r = (float) (tC / (double) tCNT);
  836. spherical2onvif(L, ptr->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  837. ptr->ts_ms = cts;
  838. float cFL = m_fMinFL + m_fR2FL * (ptr->cam_position.r - m_fMinRange);
  839. ptr->max_range = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
  840. ptr->min_range = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
  841. ptr->h_fov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], cFL)) / 2.0f; // div to prevent division in comparation
  842. ptr->v_fov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], cFL)) / 2.0f; // function that will be called more ofthen
  843. return true;
  844. };
  845. };
  846. return false;
  847. }
  848. CAM_ROI * deviceNodeCamera::fusion_fetchROI(void)
  849. {
  850. CAM_ROI * tVAL = NULL;
  851. m_mROIsProtector.lock();
  852. if (m_vROIS.size())
  853. {
  854. vCAM_ROIS::iterator sRec;
  855. uint64_t cts = 0;
  856. for (vCAM_ROIS::iterator idx = m_vROIS.begin(); idx != m_vROIS.end(); idx++)
  857. {
  858. if (tVAL == NULL)
  859. {
  860. sRec = idx;
  861. tVAL = (*idx);
  862. cts = tVAL->ts_ms;
  863. }
  864. else
  865. {
  866. #ifdef CAM_FETCH_ROI_NEWEST
  867. if ((*idx)->ts_ms > cts)
  868. #else
  869. if ((*idx)->ts_ms < cts)
  870. #endif
  871. {
  872. sRec = idx;
  873. tVAL = (*idx);
  874. cts = tVAL->ts_ms;
  875. };
  876. };
  877. };
  878. m_vROIS.erase(sRec);
  879. };
  880. m_mROIsProtector.unlock();
  881. if (m_bNoAbsPositionning && tVAL)
  882. {
  883. // Skip targets older 3 seconds
  884. if (getMilliseconds() - tVAL->ts_ms > 3000)
  885. #ifdef DEBUG_EXTRA
  886. {
  887. LOG("Targetd too old! ---> Skiping");
  888. utilizeROI(tVAL);
  889. };
  890. #else
  891. utilizeROI(tVAL);
  892. #endif
  893. };
  894. return tVAL;
  895. }
  896. DBC_SNAPSHOT_DATA * deviceNodeCamera::fusion_translate_ROI(CAM_ROI *(&ptr))
  897. {
  898. DBC_SNAPSHOT_DATA * rVal = NULL;
  899. if (ptr == NULL)
  900. {
  901. return NULL;
  902. }
  903. if (ptr->targets.size())
  904. {
  905. //rVal = (DBC_SNAPSHOT_DATA *) malloc(sizeof(DBC_SNAPSHOT_DATA));
  906. rVal = new DBC_SNAPSHOT_DATA();
  907. if (rVal)
  908. {
  909. //memset(rVal, 0, sizeof(DBC_SNAPSHOT_DATA));
  910. rVal->stream_id = m_sNodeData.aux_parameter;
  911. for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end(); idx++)
  912. {
  913. rVal->assoc_event_ids.push_back((*idx)->evt_db_ID);
  914. }
  915. };
  916. ptr->targets.clear();
  917. }
  918. else
  919. {
  920. LOG_ERROR("No Events ID to ROI");
  921. };
  922. utilizeROI(ptr);
  923. // Not Setting MD5 and TS -> will set at capture time
  924. return rVal;
  925. }
  926. void deviceNodeCamera::fusion_validate(void)
  927. {
  928. if (m_bNoAbsPositionning)
  929. {
  930. return;
  931. }
  932. m_mROIsProtector.lock();
  933. if (m_vROIS.size())
  934. {
  935. #ifdef DEBUG_EXTRA
  936. char tB[128];
  937. sprintf(tB, "Fusion: Have [%d] Regions Of Interes", m_vROIS.size());
  938. LOG(tB);
  939. #endif
  940. uint64_t cts = getMilliseconds();
  941. for (vCAM_ROIS::iterator idx = m_vROIS.begin(); idx != m_vROIS.end();)
  942. {
  943. if (! fusion_validateROI(cts, *idx))
  944. {
  945. utilizeROI(*idx);
  946. m_vROIS.erase(idx);
  947. }
  948. else
  949. {
  950. idx++;
  951. }
  952. };
  953. };
  954. m_mROIsProtector.unlock();
  955. }
  956. #endif // !NO_CAMERA_FUSION_ENGINE
  957. bool deviceNodeCamera::absoluteMove(uint32_t TargetRefID, float PanPOS, float TiltPOS, float ZoomPOS)
  958. {
  959. //if (m_sCamData.online)
  960. {
  961. CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
  962. if (tTask)
  963. {
  964. memset(tTask, 0, sizeof(CAM_TASK));
  965. tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
  966. if (tTask->CMD)
  967. {
  968. tTask->CMD->CMD = PTZ_ABSOLUTE;
  969. tTask->CMD->PAN = PanPOS;
  970. tTask->CMD->TILT = TiltPOS;
  971. tTask->CMD->ZOOM = ZoomPOS;
  972. tTask->movemet_needed = true;
  973. tTask->source_evt_id = TargetRefID;
  974. setWM(CAM_WS_BUSY);
  975. return pushCamTask(tTask);
  976. }
  977. else
  978. {
  979. LOG_ERROR("CMD malloc Error!");
  980. free(tTask);
  981. };
  982. }
  983. else
  984. {
  985. LOG_ERROR("Task malloc error!");
  986. }
  987. };
  988. return false;
  989. }
  990. bool deviceNodeCamera::absoluteMove(uint32_t TargetRefID, C3D_ORIENT_ONVIF O)
  991. {
  992. //if (m_sCamData.online)
  993. {
  994. CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
  995. if (tTask)
  996. {
  997. memset(tTask, 0, sizeof(CAM_TASK));
  998. tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
  999. if (tTask->CMD)
  1000. {
  1001. tTask->CMD->CMD = PTZ_ABSOLUTE;
  1002. tTask->CMD->PAN = O.pan;
  1003. tTask->CMD->TILT = O.tilt;
  1004. tTask->CMD->ZOOM = O.zoom;
  1005. tTask->movemet_needed = true;
  1006. tTask->source_evt_id = TargetRefID;
  1007. setWM(CAM_WS_BUSY);
  1008. return pushCamTask(tTask);
  1009. }
  1010. else
  1011. {
  1012. LOG_ERROR("CMD malloc Error!");
  1013. free(tTask);
  1014. };
  1015. }
  1016. else
  1017. {
  1018. LOG_ERROR("Task malloc error!");
  1019. }
  1020. };
  1021. return false;
  1022. }
  1023. uint8_t deviceNodeCamera::getPtzStatus()
  1024. {
  1025. if (m_sCamData.protocol == 0)
  1026. {
  1027. return 1;
  1028. }
  1029. if (getWM() > CAM_WS_INIT)
  1030. {
  1031. return 1;
  1032. }
  1033. return 0;
  1034. }
  1035. uint8_t deviceNodeCamera::getStreamStatus()
  1036. {
  1037. return 1;
  1038. }
  1039. void deviceNodeCamera::m_fThreadProc(void)
  1040. {
  1041. DBC_PUSHED_CMD * PUSHED = NULL;
  1042. m_bThreadStatus = TH_WORKING;
  1043. bool bNewSecondLoop = false;
  1044. uint32_t cTimeSeconds = 0;
  1045. uint32_t oTimeSeconds = 0;
  1046. pthread_setname_np( pthread_self(), "NodeCamera" );
  1047. while (m_bThreadStatus < TH_ENDED)
  1048. {
  1049. cTimeSeconds = (uint32_t) time(NULL);
  1050. if ((bNewSecondLoop = (cTimeSeconds != oTimeSeconds))) oTimeSeconds = cTimeSeconds;
  1051. uint8_t tState = getWM();
  1052. //char tB[128];
  1053. #ifndef NO_CAMERA_FUSION_ENGINE
  1054. fusion_validate();
  1055. #endif
  1056. switch (tState)
  1057. {
  1058. case CAM_WS_INIT:
  1059. {
  1060. if (m_pProtocol != NULL)
  1061. {
  1062. switch (m_sCamData.protocol)
  1063. {
  1064. case CAM_CTRL_PROTO_VISCA: delete((protocolPTZ_VISCA *) m_pProtocol); break;
  1065. case CAM_CTRL_PROTO_PELCO: delete((protocolPTZ_PELCO *) m_pProtocol); break;
  1066. case CAM_CTRL_PROTO_ONVIF: delete((protocolPTZ_ONVIF *) m_pProtocol); break;
  1067. case CAM_CTRL_PROTO_BRCP : delete((protocolPTZ_BRCP *) m_pProtocol); break;
  1068. default : delete(m_pProtocol);
  1069. };
  1070. m_pProtocol = NULL;
  1071. m_sCamData.online = false;
  1072. };
  1073. switch (m_sCamData.protocol)
  1074. {
  1075. case CAM_CTRL_PROTO_VISCA:
  1076. {
  1077. #ifdef DEBUG
  1078. LOG("VISCA");
  1079. #endif
  1080. m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA(m_sCamData.protocol_aux);
  1081. if (m_pProtocol != NULL)
  1082. {
  1083. basicTransport * tTransport = NULL;
  1084. hardwareManager * tHM = hardwareManager::getInstance();
  1085. if (tHM)
  1086. {
  1087. hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
  1088. if (tRES != NULL)
  1089. {
  1090. if (tRES->isValid())
  1091. {
  1092. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  1093. if (m_pProtocol->setTransport(tTransport))
  1094. {
  1095. if (! m_pProtocol->create())
  1096. {
  1097. LOG_ERROR("Protocol <<< Create >>> Failure!");
  1098. };
  1099. }
  1100. else
  1101. {
  1102. LOG_ERROR("Binding Port Failure!");
  1103. };
  1104. };
  1105. #ifdef DEBUG
  1106. }
  1107. else
  1108. {
  1109. LOG("HWM Has No UART PORT!");
  1110. #endif
  1111. };
  1112. #ifdef DEBUG
  1113. }
  1114. else
  1115. {
  1116. LOG_ERROR("Can not get Hardware Manager!");
  1117. #endif
  1118. };
  1119. if (tTransport != NULL)
  1120. {
  1121. LOG("Bind Transport Port!");
  1122. }
  1123. else
  1124. {
  1125. LOG_ERROR("Transport Creation Failure!");
  1126. delete((protocolPTZ_VISCA *) m_pProtocol);
  1127. m_pProtocol = NULL;
  1128. };
  1129. #ifdef DEBUG
  1130. }
  1131. else
  1132. {
  1133. LOG_ERROR("Protocol Creation failure!");
  1134. #endif
  1135. };
  1136. break;
  1137. };
  1138. case CAM_CTRL_PROTO_PELCO:
  1139. {
  1140. #ifdef DEBUG
  1141. LOG("PELCO");
  1142. #endif
  1143. m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO(m_sCamData.protocol_aux);
  1144. if (m_pProtocol != NULL)
  1145. {
  1146. basicTransport * tTransport = NULL;
  1147. hardwareManager * tHM = hardwareManager::getInstance();
  1148. if (tHM)
  1149. {
  1150. hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
  1151. if (tRES != NULL)
  1152. {
  1153. if (tRES->isValid())
  1154. {
  1155. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  1156. if (m_pProtocol->setTransport(tTransport))
  1157. {
  1158. if (! m_pProtocol->create())
  1159. {
  1160. LOG_ERROR("Protocol <<< Create >>> Failure!");
  1161. };
  1162. }
  1163. else
  1164. {
  1165. LOG_ERROR("Binding Port Failure!");
  1166. };
  1167. };
  1168. #ifdef DEBUG
  1169. }
  1170. else
  1171. {
  1172. LOG("HWM Has No UART PORT!");
  1173. #endif
  1174. };
  1175. #ifdef DEBUG
  1176. }
  1177. else
  1178. {
  1179. LOG_ERROR("Can not get Hardware Manager!");
  1180. #endif
  1181. };
  1182. if (tTransport != NULL)
  1183. {
  1184. LOG("Bind Transport Port!");
  1185. }
  1186. else
  1187. {
  1188. LOG_ERROR("Transport Creation Failure!");
  1189. delete((protocolPTZ_PELCO *) m_pProtocol);
  1190. m_pProtocol = NULL;
  1191. };
  1192. #ifdef DEBUG
  1193. }
  1194. else
  1195. {
  1196. LOG_ERROR("Protocol Creation failure!");
  1197. #endif
  1198. };
  1199. break;
  1200. };
  1201. case CAM_CTRL_PROTO_ONVIF:
  1202. {
  1203. #ifdef DEBUG_EXTRA
  1204. LOG("ONVIF");
  1205. #endif
  1206. // m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  1207. if (strstr(m_sCamData.onvif_ctrl, "http") == NULL)
  1208. {
  1209. char tURI[512];
  1210. if (m_sCamData.port)
  1211. {
  1212. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  1213. }
  1214. else
  1215. {
  1216. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  1217. };
  1218. LOG("PTZ URI CREATE");
  1219. LOG( tURI );
  1220. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  1221. }
  1222. else
  1223. {
  1224. LOG("PTZ USE");
  1225. LOG( m_sCamData.onvif_ctrl );
  1226. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  1227. };
  1228. #ifdef DEBUG_EXTRA
  1229. LOG("ONVIF-END");
  1230. #endif
  1231. if (m_pProtocol != NULL)
  1232. {
  1233. if (! m_pProtocol->create())
  1234. {
  1235. LOG_ERROR("Error Creating Proto!");
  1236. delete((protocolPTZ_ONVIF *) m_pProtocol);
  1237. m_pProtocol = NULL;
  1238. };
  1239. #ifdef DEBUG_EXTRA
  1240. LOG("PROTO CREATE DONE");
  1241. #endif
  1242. };
  1243. break;
  1244. };
  1245. case CAM_CTRL_PROTO_BRCP:{
  1246. #ifdef DEBUG
  1247. LOG("BRCP");
  1248. #endif
  1249. // m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  1250. if (strstr(m_sCamData.onvif_ctrl, "http") == NULL){
  1251. char tURI[256];
  1252. if (m_sCamData.port) {
  1253. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  1254. } else {
  1255. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  1256. };
  1257. m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  1258. } else {
  1259. m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  1260. };
  1261. #ifdef DEBUG
  1262. LOG("BRCP-END");
  1263. #endif
  1264. if (m_pProtocol != NULL) {
  1265. if (! m_pProtocol->create()) {
  1266. LOG_ERROR("Error Creating Proto!");
  1267. delete((protocolPTZ_BRCP *) m_pProtocol);
  1268. m_pProtocol = NULL;
  1269. };
  1270. #ifdef DEBUG
  1271. LOG("PROTO CREATE DONE");
  1272. #endif
  1273. };
  1274. break;
  1275. };
  1276. default:
  1277. {
  1278. #ifdef DEBUG
  1279. LOG("Camera Has no defined control protocol");
  1280. #endif
  1281. };
  1282. };
  1283. if (m_pProtocol != NULL)
  1284. {
  1285. // Load Presets only if we have protocol
  1286. load_presets();
  1287. mojoKernel * tKRNL = mojoKernel::getInstance();
  1288. m_bNoMoveDoneReport = false;
  1289. if (tKRNL)
  1290. {
  1291. m_bSkeepPositioningWait = ((tKRNL->getMediaMode() & EVE_OUTPUT_VIDEO) == EVE_OUTPUT_VIDEO);
  1292. #ifdef DEBUG_EXTRA
  1293. char ttTT[128];
  1294. sprintf(ttTT, "Kernel Media Mode:%d", tKRNL->getMediaMode());
  1295. LOG(ttTT);
  1296. if (m_bSkeepPositioningWait)
  1297. {
  1298. LOG("Camera No Wait On Pos!");
  1299. }
  1300. else
  1301. {
  1302. LOG("Camera Will Wait On Pos!");
  1303. };
  1304. #endif
  1305. }
  1306. else
  1307. {
  1308. LOG_ERROR("No Kernel Instance!");
  1309. };
  1310. m_sCamData.online = true;
  1311. setWM(CAM_WS_POWER_INIT);
  1312. };
  1313. m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
  1314. break;
  1315. };
  1316. case CAM_WS_POWER_INIT:
  1317. {
  1318. #ifdef DEBUG
  1319. LOG("Init Camera - PowerMode");
  1320. #endif
  1321. // setBusy( true );
  1322. if (m_pProtocol->initCamera())
  1323. {
  1324. setWM(CAM_WS_WHITE_BALLANCE);
  1325. }
  1326. // setBusy( false );
  1327. break;
  1328. };
  1329. case CAM_WS_WHITE_BALLANCE:
  1330. {
  1331. #ifdef DEBUG
  1332. LOG("Set WB");
  1333. #endif
  1334. // setBusy( true );
  1335. if (m_pProtocol->setWhiteBalanceMode(WB_AUTO))
  1336. {
  1337. setWM(CAM_WS_BACKLIGHT);
  1338. }
  1339. // setBusy( false );
  1340. break;
  1341. };
  1342. case CAM_WS_BACKLIGHT:
  1343. {
  1344. #ifdef DEBUG
  1345. LOG("Set BLC");
  1346. #endif
  1347. // setBusy( true );
  1348. if (m_pProtocol->setBackLightMode(true))
  1349. {
  1350. setWM(CAM_WS_AUTO_FOCUS);
  1351. }
  1352. // setBusy( false );
  1353. break;
  1354. };
  1355. case CAM_WS_AUTO_FOCUS:
  1356. {
  1357. #ifdef DEBUG
  1358. LOG("Set AF");
  1359. #endif
  1360. // setBusy( true );
  1361. if (m_pProtocol->setAutoFocus(true))
  1362. {
  1363. setWM(CAM_WS_INIT_GO_HOME);
  1364. }
  1365. // setBusy( false );
  1366. break;
  1367. };
  1368. case CAM_WS_INIT_GO_HOME:
  1369. {
  1370. m_nHomingCounter = 0;
  1371. /* Skip For Restartin bug
  1372. if( !m_bNoAbsPositionning ) {
  1373. #ifdef DEBUG
  1374. LOG("INIT GO -1 0 -1");
  1375. #endif
  1376. if (m_pProtocol->goAbsolute(-1, 0, -1)) {
  1377. m_fCP_Pan = -1;
  1378. m_fCP_Tilt = 0;
  1379. m_fCP_Zoom = -1;
  1380. setWM( CAM_WS_READY );
  1381. };
  1382. } else {
  1383. #ifdef DEBUG
  1384. LOG("Go Home!");
  1385. #endif
  1386. CSTR TK = getPresetToken( ARGUS_PRESET_TYPE_HOME );
  1387. if( TK ) {
  1388. if ( !m_bCameraOnHomePosition ) {
  1389. if( !m_pProtocol->goPreset( TK )){
  1390. LOG_ERROR("Cannot Issue goPreset Command!");
  1391. };
  1392. m_bCameraOnHomePosition = true;
  1393. };
  1394. };
  1395. setWM( CAM_WS_READY );
  1396. };*/
  1397. LOG("INit GoHome");
  1398. setWM(CAM_WS_READY);
  1399. break;
  1400. };
  1401. case CAM_WS_AUTOMATED_MOVE:
  1402. {
  1403. m_bCameraOnHomePosition = false;
  1404. m_nRelativeMoveCounter++;
  1405. if ((m_bRelativeMoveMatrix & 0x03) != 0)
  1406. {
  1407. // Pan Move
  1408. if ((m_bRelativeMoveMatrix & 0x01) == 0)
  1409. {
  1410. m_fRM_Pan -= m_fSpeedRise;
  1411. }
  1412. else
  1413. {
  1414. m_fRM_Pan += m_fSpeedRise;
  1415. };
  1416. };
  1417. if ((m_bRelativeMoveMatrix & 0x0C) != 0)
  1418. {
  1419. // TILT Move
  1420. if ((m_bRelativeMoveMatrix & 0x04) == 0)
  1421. {
  1422. m_fRM_Tilt -= m_fSpeedRise;
  1423. }
  1424. else
  1425. {
  1426. m_fRM_Tilt += m_fSpeedRise;
  1427. }
  1428. };
  1429. if ((m_bRelativeMoveMatrix & 0x30) != 0)
  1430. {
  1431. // ZOOM Move
  1432. if ((m_bRelativeMoveMatrix & 0x10) == 0)
  1433. {
  1434. // Wide
  1435. m_fRM_Zoom -= m_fSpeedRise;
  1436. }
  1437. else
  1438. {
  1439. // Tele
  1440. m_fRM_Zoom += m_fSpeedRise;
  1441. };
  1442. };
  1443. if (m_fRM_Pan < -1.0f)
  1444. {
  1445. m_fRM_Pan = -1.0f;
  1446. }
  1447. if (m_fRM_Pan > 1.0f)
  1448. {
  1449. m_fRM_Pan = 1.0f;
  1450. }
  1451. if (m_fRM_Tilt < -1.0f)
  1452. {
  1453. m_fRM_Tilt = -1.0f;
  1454. }
  1455. if (m_fRM_Tilt > 1.0f)
  1456. {
  1457. m_fRM_Tilt = 1.0f;
  1458. }
  1459. if (m_fRM_Zoom < -1.0f)
  1460. {
  1461. m_fRM_Zoom = -1.0f;
  1462. }
  1463. if (m_fRM_Zoom > 1.0f)
  1464. {
  1465. m_fRM_Zoom = 1.0f;
  1466. }
  1467. m_fCP_Zoom += 0.5f * m_fRM_Zoom;
  1468. if (m_fCP_Zoom < -1.0f)
  1469. {
  1470. m_fCP_Zoom = -1.0f;
  1471. }
  1472. if (m_fCP_Zoom > 1.0f)
  1473. {
  1474. m_fCP_Zoom = 1.0f;
  1475. }
  1476. if (! relativeMove(m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom))
  1477. {
  1478. m_nRelativeMoveCounter = 0;
  1479. setWM(CAM_WS_READY);
  1480. break;
  1481. };
  1482. if (m_sCamData.ptz_axel)
  1483. { // Manual
  1484. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel)
  1485. {
  1486. m_nRelativeMoveCounter = 0;
  1487. setWM(CAM_WS_READY);
  1488. };
  1489. }
  1490. else
  1491. {
  1492. // Stepping Axel by Zoom
  1493. uint8_t tVal = (uint8_t) (10.0f * (2.0f - (1.0f + m_fCP_Zoom)));
  1494. if (m_nRelativeMoveCounter > tVal)
  1495. {
  1496. m_nRelativeMoveCounter = 0;
  1497. setWM(CAM_WS_READY);
  1498. };
  1499. };
  1500. break;
  1501. };
  1502. case CAM_WS_STOP_MOVE:
  1503. {
  1504. m_nRelativeMoveCounter++;
  1505. m_fRM_Pan = .0f;
  1506. m_fRM_Pan = .0f;
  1507. m_fRM_Tilt = .0f;
  1508. m_fRM_Tilt = .0f;
  1509. m_fRM_Zoom = .0f;
  1510. m_fRM_Zoom = .0f;
  1511. if (relativeStop())
  1512. {
  1513. m_nHomingCounter = 0;
  1514. m_nRelativeMoveCounter = 0;
  1515. setWM(CAM_WS_READY);
  1516. break;
  1517. };
  1518. if (m_sCamData.ptz_axel)
  1519. {
  1520. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel)
  1521. {
  1522. setWM(CAM_WS_READY);
  1523. }
  1524. }
  1525. else
  1526. {
  1527. uint8_t tVal = (uint8_t) (10.0f * (2.0f - (1.0f + m_fCP_Zoom)));
  1528. if (m_nRelativeMoveCounter > tVal)
  1529. {
  1530. setWM(CAM_WS_READY);
  1531. }
  1532. };
  1533. break;
  1534. };
  1535. case CAM_WS_GO_ABS_ROI:
  1536. case CAM_WS_GO_ABS_POSITION:
  1537. {
  1538. m_bCameraOnHomePosition = false;
  1539. setWM(CAM_WS_BUSY);
  1540. if (m_pCurrentROI != NULL)
  1541. {
  1542. // LOG("ROI Ok");
  1543. m_nHomingCounter = 0;
  1544. if (m_pBEH)
  1545. {
  1546. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_MOVE_TO, NULL, NULL, NULL);
  1547. if (tEVT)
  1548. {
  1549. m_pBEH->broadcast(tEVT);
  1550. }
  1551. };
  1552. if (m_bNoAbsPositionning)
  1553. {
  1554. // LOG("ABS to PRESET");
  1555. uint8_t COL, ROW;
  1556. translateROI2PRESET(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom, COL, ROW);
  1557. // char tB[64];
  1558. // sprintf( tB, "Get ABS Preset Col %d Row %d!", COL, ROW );
  1559. // LOG( tB );
  1560. // sprintf( tB, "Old Preset Col %d Row %d!", m_bCurrentPresetCol, m_bCurrentPresetRow );
  1561. // LOG( tB );
  1562. if ((m_bCurrentPresetCol == COL) && (m_bCurrentPresetRow == ROW))
  1563. {
  1564. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1565. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1566. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1567. #ifdef DEBUG_EXTRA
  1568. LOG("INSTANT BCAST CAM ONPOS");
  1569. #endif
  1570. // Send Capture event
  1571. #ifndef NO_CAMERA_FUSION_ENGINE
  1572. DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
  1573. #else
  1574. DBC_SNAPSHOT_DATA * tData = NULL;
  1575. #endif
  1576. if (tData != NULL)
  1577. {
  1578. if (m_pBEH)
  1579. {
  1580. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1581. if (tEVT)
  1582. {
  1583. m_pBEH->broadcast(tEVT);
  1584. }
  1585. else
  1586. {
  1587. //free(tData);
  1588. delete(tData);
  1589. };
  1590. }
  1591. else
  1592. {
  1593. //free(tData);
  1594. delete(tData);
  1595. };
  1596. };
  1597. setWM(CAM_WS_READY);
  1598. }
  1599. else
  1600. {
  1601. CSTR token = getPresetToken(COL, ROW);
  1602. if (token)
  1603. {
  1604. // update position Info
  1605. m_bCurrentPresetCol = COL;
  1606. m_bCurrentPresetRow = ROW;
  1607. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1608. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1609. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1610. if (! m_pProtocol->goPreset(token))
  1611. {
  1612. LOG_ERROR("Cannot Issue goPreset Command!->Restart Camera?");
  1613. setWM(CAM_WS_END);
  1614. }
  1615. else
  1616. {
  1617. // Waiting Movement finish
  1618. if (m_bSkeepPositioningWait && 0)
  1619. {
  1620. #ifdef DEBUG_EXTRA
  1621. LOG("INSTANT BCAST CAM ONPOS");
  1622. #endif
  1623. // Send Capture event
  1624. #ifndef NO_CAMERA_FUSION_ENGINE
  1625. DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
  1626. #else
  1627. DBC_SNAPSHOT_DATA * tData = NULL;
  1628. #endif
  1629. if (tData != NULL)
  1630. {
  1631. if (m_pBEH)
  1632. {
  1633. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1634. if (tEVT)
  1635. {
  1636. m_pBEH->broadcast(tEVT);
  1637. }
  1638. else
  1639. {
  1640. //free(tData);
  1641. delete(tData);
  1642. };
  1643. }
  1644. else
  1645. {
  1646. //free(tData);
  1647. delete(tData);
  1648. };
  1649. };
  1650. setWM(CAM_WS_READY);
  1651. }
  1652. else
  1653. {
  1654. // utilizeROI( m_pCurrentROI );
  1655. setWM(CAM_WS_WAIT_ONPOS);
  1656. };
  1657. };
  1658. }
  1659. else
  1660. {
  1661. #ifdef DEBUG_EXTRA
  1662. LOG("Not Found!");
  1663. #endif
  1664. utilizeROI(m_pCurrentROI);
  1665. setWM(CAM_WS_READY);
  1666. };
  1667. };
  1668. }
  1669. else
  1670. {
  1671. // update position Info
  1672. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1673. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1674. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1675. // Do Movement
  1676. if (! m_pProtocol->goAbsolute(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection))
  1677. {
  1678. LOG_ERROR("Cannot Issue goAbsolute Command!->Restart Camera?");
  1679. setWM(CAM_WS_END);
  1680. }
  1681. else
  1682. {
  1683. // EVT_CAMERA_ON_POSITION is sent from CAM_WS_WAIT_ONPOS once the move is done
  1684. // (before, with video output it was sent right after the command).
  1685. setWM(CAM_WS_WAIT_ONPOS);
  1686. };
  1687. };
  1688. }
  1689. else
  1690. {
  1691. setWM(CAM_WS_READY);
  1692. }
  1693. break;
  1694. };
  1695. case CAM_WS_WAIT_ONPOS:
  1696. {
  1697. // LOG("WaitOnPos...");
  1698. DBC_SNAPSHOT_DATA * tData = NULL;
  1699. if (m_pCurrentROI != NULL)
  1700. {
  1701. // Send Capture event
  1702. #ifndef NO_CAMERA_FUSION_ENGINE
  1703. tData = fusion_translate_ROI(m_pCurrentROI);
  1704. #else
  1705. tData = NULL;
  1706. #endif
  1707. };
  1708. // To Accept any new ROI's ??
  1709. // setWM( CAM_WS_READY );
  1710. #ifdef DEBUG_EXTRA
  1711. LOG("Start Waiting Cam On Position!");
  1712. #endif
  1713. // Target-driven ABS / preset move: EVT_CAMERA_ON_POSITION only after the move is done.
  1714. // Protocols that cannot report the end of a move get a fixed wait.
  1715. if (! m_bNoMoveDoneReport)
  1716. {
  1717. if (! m_pProtocol->waitMoveIsDone())
  1718. {
  1719. LOG("Protocol cannot report the end of a move -> fixed wait");
  1720. m_bNoMoveDoneReport = true;
  1721. }
  1722. };
  1723. if (m_bNoMoveDoneReport)
  1724. {
  1725. SLEEP(CAM_MOVE_FIXED_WAIT_MS);
  1726. }
  1727. #ifdef DEBUG_EXTRA
  1728. LOG("Done Waiting Cam On Position!");
  1729. #endif
  1730. if (tData != NULL)
  1731. {
  1732. if (m_pBEH)
  1733. {
  1734. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1735. if (tEVT)
  1736. {
  1737. #ifdef DEBUG_EXTRA
  1738. LOG("BCAST CAM ONPOS");
  1739. #endif
  1740. m_pBEH->broadcast(tEVT);
  1741. }
  1742. else
  1743. {
  1744. //free(tData);
  1745. delete(tData);
  1746. };
  1747. }
  1748. else
  1749. {
  1750. //free(tData);
  1751. delete(tData);
  1752. };
  1753. tData = NULL;
  1754. };
  1755. setWM(CAM_WS_READY);
  1756. break;
  1757. };
  1758. case CAM_WS_GO_HOMING_PRESET:
  1759. {
  1760. if (! m_bCameraOnHomePosition)
  1761. {
  1762. // For new Camera Presets
  1763. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_HOME);
  1764. if (TK)
  1765. {
  1766. #ifdef DEBUG_EXTRA
  1767. LOG("Go Home!");
  1768. LOG(TK);
  1769. #endif
  1770. if (! m_pProtocol->goPreset(TK))
  1771. {
  1772. LOG_ERROR("Cannot Issue goPreset Command!");
  1773. };
  1774. }
  1775. else
  1776. {
  1777. // Old Method
  1778. if (m_sCamData.home_token[0] != (char) 0)
  1779. {
  1780. #ifdef DEBUG_EXTRA
  1781. LOG("Go Home!");
  1782. LOG(m_sCamData.home_token);
  1783. #endif
  1784. if (! m_pProtocol->goPreset(m_sCamData.home_token))
  1785. {
  1786. LOG_ERROR("Cannot Issue goPreset Command!");
  1787. };
  1788. };
  1789. };
  1790. m_bCameraOnHomePosition = true;
  1791. m_bCurrentPresetCol = 0;
  1792. m_bCurrentPresetRow = 0;
  1793. };
  1794. setWM(CAM_WS_READY);
  1795. break;
  1796. };
  1797. case CAM_WS_GO_PRESET:
  1798. {
  1799. LOG("Go Preset!");
  1800. // if( m_sCamData.home_token[0] != (char)0 ) {
  1801. // LOG("Go Home!");
  1802. // LOG( m_sCamData.home_token );
  1803. // if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  1804. // LOG_ERROR("Cannot Issue goPreset Command!");
  1805. // };
  1806. // };
  1807. setWM(CAM_WS_READY);
  1808. break;
  1809. };
  1810. case CAM_WS_SET_PRESET:
  1811. {
  1812. LOG("Set Preset!");
  1813. // if( m_sCamData.home_token[0] != (char)0 ) {
  1814. // LOG("Go Home!");
  1815. // LOG( m_sCamData.home_token );
  1816. // if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  1817. // LOG_ERROR("Cannot Issue goPreset Command!");
  1818. // };
  1819. // };
  1820. setWM(CAM_WS_READY);
  1821. break;
  1822. };
  1823. case CAM_WS_BUSY:
  1824. {
  1825. // Handle Operation TO
  1826. setWM(CAM_WS_READY);
  1827. break;
  1828. };
  1829. case CAM_WS_READY:
  1830. {
  1831. #ifndef NO_CAMERA_FUSION_ENGINE
  1832. m_pCurrentROI = fusion_fetchROI();
  1833. #else
  1834. #endif
  1835. if (m_pCurrentROI != NULL)
  1836. {
  1837. #ifdef DEBUG_EXTRA
  1838. LOG("HAVE ROI to see!");
  1839. #endif
  1840. setWM(CAM_WS_GO_ABS_POSITION);
  1841. }
  1842. else
  1843. {
  1844. // Idle Work --->
  1845. if (m_sCamData.eco_ir)
  1846. {
  1847. m_mIRProtector.lock();
  1848. if (m_bIRIsOn)
  1849. {
  1850. if (m_bIRTO)
  1851. {
  1852. if (bNewSecondLoop)
  1853. {
  1854. m_bIRTO--;
  1855. }
  1856. }
  1857. else
  1858. {
  1859. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_OFF);
  1860. if (TK)
  1861. {
  1862. if (m_pProtocol->goPreset(TK))
  1863. {
  1864. m_bIRIsOn = false;
  1865. }
  1866. }
  1867. };
  1868. };
  1869. m_mIRProtector.unlock();
  1870. };
  1871. if (m_sCamData.homing_enable)
  1872. {
  1873. if (bNewSecondLoop)
  1874. {
  1875. if (m_nHomingCounter < m_sCamData.homing_to)
  1876. {
  1877. m_nHomingCounter++;
  1878. }
  1879. else
  1880. {
  1881. // LOG("Go Home Position!");
  1882. m_nHomingCounter = 0;
  1883. setWM(CAM_WS_GO_HOMING_PRESET);
  1884. break;
  1885. };
  1886. };
  1887. };
  1888. CAM_TASK * tTASK = fetchCamTask();
  1889. if (tTASK != NULL)
  1890. {
  1891. if (tTASK->movemet_needed)
  1892. {
  1893. CAM_PTZ_CMD * tCMD = tTASK->CMD;
  1894. if (tCMD)
  1895. {
  1896. switch (tCMD->CMD)
  1897. {
  1898. case PTZ_STOP:
  1899. {
  1900. m_nHomingCounter = 0;
  1901. setWM(CAM_WS_STOP_MOVE);
  1902. break;
  1903. };
  1904. case PTZ_MOVE:
  1905. {
  1906. if (tState != CAM_WS_AUTOMATED_MOVE)
  1907. {
  1908. m_nRelativeMoveCounter = 0;
  1909. }
  1910. m_bRelativeMoveMatrix = 0;
  1911. m_fRM_Pan = tCMD->PAN;
  1912. m_fRM_Tilt = tCMD->TILT;
  1913. m_fRM_Zoom = tCMD->ZOOM;
  1914. m_nHomingCounter = 0;
  1915. setWM(CAM_WS_AUTOMATED_MOVE);
  1916. break;
  1917. };
  1918. case PTZ_ABSOLUTE:
  1919. {
  1920. m_pCurrentROI = createCAM_ROI();
  1921. if (m_pCurrentROI != NULL)
  1922. {
  1923. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
  1924. if (tTarget != NULL)
  1925. {
  1926. memset(tTarget, 0, sizeof(CAM_TRACK_RECORD));
  1927. tTarget->evt_db_ID = tTASK->source_evt_id;
  1928. m_pCurrentROI->targets.push_back(tTarget);
  1929. m_pCurrentROI->cam_orientation.pan = tCMD->PAN;
  1930. m_pCurrentROI->cam_orientation.tilt = tCMD->TILT;
  1931. m_pCurrentROI->cam_orientation.zoom = tCMD->ZOOM;
  1932. m_nHomingCounter = 0;
  1933. setWM(CAM_WS_GO_ABS_POSITION);
  1934. }
  1935. else
  1936. {
  1937. utilizeROI(m_pCurrentROI);
  1938. };
  1939. };
  1940. break;
  1941. };
  1942. case PTZ_RELOAD_CAMERA:
  1943. {
  1944. LOG("Exit Command Rcpt");
  1945. m_bThreadStatus = TH_ENDED;
  1946. };
  1947. };
  1948. free(tCMD);
  1949. tTASK->CMD = NULL;
  1950. };
  1951. }
  1952. else
  1953. {
  1954. LOG("No Movement -> INSTCAP");
  1955. // No Movement -> Just Capture
  1956. if (m_pBEH)
  1957. {
  1958. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, NULL);
  1959. if (tEVT)
  1960. {
  1961. tEVT->m_db_id = tTASK->source_evt_id;
  1962. m_pBEH->broadcast(tEVT);
  1963. };
  1964. };
  1965. };
  1966. free(tTASK);
  1967. }
  1968. else
  1969. {
  1970. // Lowest Priority to Web Client Commands
  1971. #ifdef DEBUG_EXTRA__
  1972. LOG("Check Web CMD!");
  1973. #endif
  1974. PUSHED = m_pDBC->getNodePushedCMD(m_sNodeData.node_id);
  1975. if (PUSHED != NULL)
  1976. {
  1977. #ifdef DEBUG_EXTRA__
  1978. LOG("HAVE Web CMD!");
  1979. #endif
  1980. m_pDBC->updateNodePushedCMD(PUSHED->id, DBC_CMD_READY_TO_CLEAN);
  1981. if ((PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK) == ARGUS_CAM_PCMD_CMD_MASK)
  1982. {
  1983. switch (PUSHED->CMD)
  1984. {
  1985. case 0x80:
  1986. {
  1987. // Call Home Preset
  1988. LOG("CALL HOME PRESET!");
  1989. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_HOME);
  1990. if (TK)
  1991. {
  1992. LOG(TK);
  1993. if (m_pProtocol->goPreset(TK))
  1994. {
  1995. m_bCameraOnHomePosition = true;
  1996. m_nHomingCounter = 0;
  1997. };
  1998. };
  1999. break;
  2000. };
  2001. case 0x81:
  2002. {
  2003. // Call IR On Preset
  2004. LOG("CALL IR ON PRESET!");
  2005. m_mIRProtector.lock();
  2006. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_ON);
  2007. if (TK)
  2008. {
  2009. LOG(TK);
  2010. if (m_pProtocol->goPreset(TK))
  2011. {
  2012. m_bIRIsOn = true;
  2013. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2014. };
  2015. }
  2016. else
  2017. {
  2018. LOG("PRESET NOT FOUND!");
  2019. }
  2020. m_mIRProtector.unlock();
  2021. break;
  2022. };
  2023. case 0x82:
  2024. {
  2025. // Call IR Off Preset
  2026. LOG("CALL IR OFF PRESET!");
  2027. m_mIRProtector.lock();
  2028. CSTR TK = (m_sCamData.eco_ir) ? getPresetToken(ARGUS_PRESET_TYPE_IR_OFF) : getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  2029. if (TK)
  2030. {
  2031. LOG(TK);
  2032. if (m_pProtocol->goPreset(TK))
  2033. {
  2034. m_bIRIsOn = false;
  2035. m_bIRTO = 0;
  2036. };
  2037. }
  2038. else
  2039. {
  2040. LOG("PRESET NOT FOUND!");
  2041. }
  2042. m_mIRProtector.unlock();
  2043. break;
  2044. };
  2045. case 0x83:
  2046. {
  2047. // Call IR Auto Preset
  2048. LOG("CALL IR AUTO PRESET!");
  2049. m_mIRProtector.lock();
  2050. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  2051. if (TK)
  2052. {
  2053. LOG(TK);
  2054. if (m_pProtocol->goPreset(TK))
  2055. {
  2056. m_bIRIsOn = true;
  2057. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2058. };
  2059. }
  2060. else
  2061. {
  2062. LOG("PRESET NOT FOUND!");
  2063. }
  2064. m_mIRProtector.unlock();
  2065. break;
  2066. };
  2067. case 0x84:
  2068. {
  2069. // Call Wisher Preset
  2070. LOG("CALL WIPER PRESET!");
  2071. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_WISHER);
  2072. if (TK)
  2073. {
  2074. LOG(TK);
  2075. m_pProtocol->goPreset(TK);
  2076. };
  2077. break;
  2078. };
  2079. };
  2080. }
  2081. else if (tState == CAM_WS_READY || tState == CAM_WS_AUTOMATED_MOVE)
  2082. { // No Way to get here
  2083. // Direct Movment Mode
  2084. if (PUSHED->CMD == ARGUS_CAM_PCMD_STOP)
  2085. {
  2086. m_nHomingCounter = 0;
  2087. setWM(CAM_WS_STOP_MOVE);
  2088. }
  2089. else
  2090. {
  2091. //char tB[64];
  2092. if (tState != CAM_WS_AUTOMATED_MOVE)
  2093. {
  2094. m_nRelativeMoveCounter = 0;
  2095. }
  2096. m_bRelativeMoveMatrix = (PUSHED->CMD) >> 1;
  2097. m_nHomingCounter = 0;
  2098. setWM(CAM_WS_AUTOMATED_MOVE);
  2099. };
  2100. };
  2101. free(PUSHED);
  2102. PUSHED = NULL;
  2103. };
  2104. };
  2105. };
  2106. break;
  2107. };
  2108. case CAM_WS_END:
  2109. {
  2110. LOG("Exit Command Rcpt");
  2111. m_bThreadStatus = TH_ENDED;
  2112. break;
  2113. };
  2114. };
  2115. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  2116. };
  2117. #ifdef DEBUG
  2118. LOG("CTRL Loop End!");
  2119. #endif
  2120. }
  2121. bool deviceNodeCamera::setNoPositionWait(bool FL)
  2122. {
  2123. m_bSkeepPositioningWait = FL;
  2124. return true;
  2125. }
  2126. bool deviceNodeCamera::testFOV(C3D_DECART L)
  2127. {
  2128. // System Coords -> trans to local and go to funct
  2129. systemAnchor * tSystem = systemAnchor::getInstance();
  2130. if (tSystem == NULL)
  2131. {
  2132. return false;
  2133. }
  2134. C3D_SPH_DEGREES SL;
  2135. #ifdef DEBUG_EXTRA
  2136. LOG("Test FOV local Decart coords");
  2137. #endif
  2138. if (! tSystem->convertToLocal(&m_oPosition, L, SL))
  2139. {
  2140. return false;
  2141. }
  2142. return testFOV(SL);
  2143. }
  2144. bool deviceNodeCamera::testFOV(C3D_WGS84_LOC L)
  2145. {
  2146. // Global Coords
  2147. systemAnchor * tSystem = systemAnchor::getInstance();
  2148. if (tSystem == NULL)
  2149. {
  2150. return false;
  2151. }
  2152. C3D_SPH_DEGREES SL;
  2153. #ifdef DEBUG_EXTRA
  2154. LOG("Test FOV WGS coords");
  2155. #endif
  2156. if (! tSystem->convertToLocal(&m_oPosition, L, SL))
  2157. {
  2158. return false;
  2159. }
  2160. return testFOV(SL);
  2161. }
  2162. bool deviceNodeCamera::testFOV(C3D_SPH_RADIANS L)
  2163. {
  2164. // Local Coords
  2165. C3D_SPH_DEGREES SL;
  2166. #ifdef DEBUG_EXTRA
  2167. LOG("Test FOV local Spherical(rad) coords");
  2168. #endif
  2169. spherical2spherical(L, SL);
  2170. return testFOV(SL);
  2171. }
  2172. bool deviceNodeCamera::testFOV(C3D_SPH_DEGREES SL)
  2173. {
  2174. #ifdef DEBUG_EXTRA
  2175. char tB[128];
  2176. #endif
  2177. #ifdef DEBUG_EXTRA
  2178. LOG("Test FOV local Spherical(deg) coords");
  2179. #endif
  2180. switch (m_sCamData.triggering_mode)
  2181. {
  2182. case CAM_TRIGGER_STRICT:
  2183. {
  2184. if (SL.r > m_fMaxRange || SL.r < m_fMinRange)
  2185. {
  2186. #ifdef DEBUG_EXTRA
  2187. sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
  2188. LOG(tB);
  2189. #endif
  2190. return false;
  2191. };
  2192. break;
  2193. };
  2194. case CAM_TRIGGER_ALL_NEAR:
  2195. {
  2196. if (SL.r > m_fMaxRange)
  2197. {
  2198. #ifdef DEBUG_EXTRA
  2199. sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
  2200. LOG(tB);
  2201. #endif
  2202. return false;
  2203. };
  2204. break;
  2205. };
  2206. case CAM_TRIGGER_ALL_FAR:
  2207. {
  2208. if (SL.r < m_fMinRange)
  2209. {
  2210. #ifdef DEBUG_EXTRA
  2211. sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
  2212. LOG(tB);
  2213. #endif
  2214. return false;
  2215. };
  2216. break;
  2217. };
  2218. case CAM_TRIGGER_ALL: return true;
  2219. };
  2220. // float HS = AC_imager_width[m_sCamData.imager_type];
  2221. // float VS = AC_imager_height[m_sCamData.imager_type];
  2222. // float HS2 = HS * HS;
  2223. // float VS2 = VS * VS;
  2224. // float IR = HS / VS;
  2225. // float IR2 = IR * IR;
  2226. if (m_sCamData.pan_angles == 0)
  2227. {
  2228. // Fixed Camera
  2229. float tA = fabsf(SL.fi);
  2230. float tZ = 0.5f * (m_fMinHFov + (SL.r - m_fMinRange) * m_fR2FL);
  2231. if (tA > tZ)
  2232. {
  2233. return false;
  2234. }
  2235. }
  2236. else
  2237. {
  2238. if (m_sCamData.pan_angles < 360)
  2239. { // If endless PAN -> PASSED
  2240. // Partial Pan
  2241. switch (m_sCamData.pan_model)
  2242. {
  2243. case 1:
  2244. {
  2245. // Regular Pan
  2246. float tFOV = 0.5f * (m_fMinHFov + (SL.r - m_fMinRange) * m_fR2FL);
  2247. float tRad = deg2rad(SL.fi);
  2248. #ifdef DEBUG_EXTRA
  2249. sprintf(tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad);
  2250. LOG(tB);
  2251. #endif
  2252. if ((tRad < (-1.0 * tFOV)) || (tRad > (deg2rad(m_sCamData.pan_angles) + tFOV)))
  2253. {
  2254. return false;
  2255. }
  2256. break;
  2257. };
  2258. case 2:
  2259. {
  2260. break;
  2261. };
  2262. case 3:
  2263. {
  2264. break;
  2265. };
  2266. };
  2267. };
  2268. };
  2269. if (m_sCamData.tilt_angles == 0)
  2270. {
  2271. // Fixed Camera
  2272. if ((SL.tetta < (m_fMaxVFov / -2.0f)) || (SL.tetta > (m_fMaxVFov / 2.0f)))
  2273. {
  2274. return false;
  2275. }
  2276. }
  2277. else
  2278. {
  2279. if (m_sCamData.tilt_angles < 90)
  2280. { // if Cam CAN DO 90 -> Pass
  2281. // Partial Tilt
  2282. switch (m_sCamData.tilt_model)
  2283. {
  2284. case 1:
  2285. {
  2286. // Regular Tilt
  2287. float tFOV = 0.5f * (m_fMinVFov + (m_fMaxVFov - m_fMinVFov) * (SL.r / m_fMaxRange));
  2288. float tRad = deg2rad(SL.tetta);
  2289. if ((tRad < (-1.0 * tFOV)) || (tRad > (deg2rad(m_sCamData.tilt_angles) + tFOV)))
  2290. {
  2291. return false;
  2292. }
  2293. break;
  2294. };
  2295. case 2:
  2296. {
  2297. break;
  2298. };
  2299. };
  2300. };
  2301. };
  2302. return true;
  2303. }
  2304. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_WGS84_LOC L)
  2305. {
  2306. systemAnchor * tSystem = systemAnchor::getInstance();
  2307. if (tSystem == NULL)
  2308. {
  2309. return false;
  2310. }
  2311. C3D_SPH_DEGREES SL;
  2312. #ifdef DEBUG_EXTRA
  2313. LOG("Look at WGS coords!");
  2314. #endif
  2315. tSystem->convertToLocal(&m_oPosition, L, SL);
  2316. return lookAt(TargetRefID, SL);
  2317. }
  2318. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_DECART L)
  2319. {
  2320. systemAnchor * tSystem = systemAnchor::getInstance();
  2321. if (tSystem == NULL)
  2322. {
  2323. LOG_ERROR("Cant Get Anchor!");
  2324. return false;
  2325. }
  2326. C3D_SPH_DEGREES SL;
  2327. #ifdef DEBUG_EXTRA
  2328. LOG("Look at System Decart coords!");
  2329. #endif
  2330. tSystem->convertToLocal(&m_oPosition, L, SL);
  2331. return lookAt(TargetRefID, SL);
  2332. }
  2333. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_SPH_RADIANS L)
  2334. {
  2335. C3D_SPH_DEGREES SL;
  2336. #ifdef DEBUG_EXTRA
  2337. LOG("Look at spherical(rad) 2 spherical(deg) coords!");
  2338. #endif
  2339. spherical2spherical(L, SL);
  2340. return lookAt(TargetRefID, SL);
  2341. }
  2342. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_SPH_DEGREES L)
  2343. {
  2344. if (m_bCameraIsStatic)
  2345. {
  2346. //DBC_SNAPSHOT_DATA * tData = (DBC_SNAPSHOT_DATA *) malloc(sizeof(DBC_SNAPSHOT_DATA));
  2347. DBC_SNAPSHOT_DATA * tData = new DBC_SNAPSHOT_DATA();
  2348. if (tData)
  2349. {
  2350. //memset(tData, 0, sizeof(DBC_SNAPSHOT_DATA));
  2351. tData->stream_id = m_sNodeData.aux_parameter;
  2352. tData->assoc_event_ids.push_back(TargetRefID);
  2353. if (m_pBEH)
  2354. {
  2355. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  2356. if (tEVT)
  2357. {
  2358. #ifdef DEBUG_EXTRA
  2359. LOG("INSTANT BCAST CAM ONPOS");
  2360. #endif
  2361. m_pBEH->broadcast(tEVT);
  2362. }
  2363. else
  2364. {
  2365. //free(tData);
  2366. delete(tData);
  2367. };
  2368. }
  2369. else
  2370. {
  2371. //free(tData);
  2372. delete(tData);
  2373. };
  2374. };
  2375. return true;
  2376. };
  2377. // char tB[128];
  2378. // sprintf(tB, "Target On %.3f %.3f %.3f", L.r, L.fi, L.tetta );
  2379. // LOG( tB );
  2380. // sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
  2381. // LOG( tB );
  2382. #ifdef DEBUG_EXTRA
  2383. LOG("Look at local spherical deg. coords!(final)");
  2384. #endif
  2385. // if( getWM() == CAM_WS_READY ){
  2386. // C3D_ORIENT_ONVIF LL;
  2387. // spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  2388. // return absoluteMove( TargetRefID, LL );
  2389. // };
  2390. // Camera is Busy
  2391. if (m_bShineOnTarget)
  2392. {
  2393. m_mIRProtector.lock();
  2394. if (! m_bIRIsOn)
  2395. {
  2396. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  2397. if (TK)
  2398. {
  2399. if (m_pProtocol->goPreset(TK))
  2400. {
  2401. m_bIRIsOn = true;
  2402. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2403. };
  2404. };
  2405. }
  2406. else
  2407. {
  2408. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2409. }
  2410. m_mIRProtector.unlock();
  2411. };
  2412. // targeting by Presets -> instant ROI
  2413. if (m_bNoAbsPositionning)
  2414. {
  2415. CAM_ROI * tROI = createCAM_ROI();
  2416. if (tROI != NULL)
  2417. {
  2418. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
  2419. if (tTarget != NULL)
  2420. {
  2421. memset(tTarget, 0, sizeof(CAM_TRACK_RECORD));
  2422. tTarget->evt_db_ID = TargetRefID;
  2423. tROI->targets.push_back(tTarget);
  2424. tROI->ts_ms = getMilliseconds();
  2425. spherical2onvif(L, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  2426. tROI->cam_position.fi = L.fi;
  2427. tROI->cam_position.tetta = L.tetta;
  2428. tROI->cam_position.r = L.r;
  2429. #ifndef NO_CAMERA_FUSION_ENGINE
  2430. m_mROIsProtector.lock();
  2431. m_vROIS.push_back(tROI);
  2432. m_mROIsProtector.unlock();
  2433. #endif
  2434. }
  2435. else
  2436. {
  2437. LOG_ERROR("No MEM 4 TARGTEG DATA");
  2438. utilizeROI(tROI);
  2439. };
  2440. }
  2441. else
  2442. {
  2443. LOG_ERROR("No MEM 4 ROI");
  2444. }
  2445. return true;
  2446. };
  2447. #ifndef NO_CAMERA_FUSION_ENGINE
  2448. return fusion_consumeData(TargetRefID, L);
  2449. #else
  2450. return true;
  2451. #endif
  2452. }
  2453. bool deviceNodeCamera::makeSnap(uint32_t TargetRefID)
  2454. {
  2455. CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
  2456. if (tTask)
  2457. {
  2458. memset(tTask, 0, sizeof(CAM_TASK));
  2459. tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
  2460. if (tTask->CMD)
  2461. {
  2462. tTask->CMD->CMD = PTZ_CAPTURE_ONLY;
  2463. tTask->movemet_needed = false;
  2464. tTask->source_evt_id = TargetRefID;
  2465. return pushCamTask(tTask);
  2466. }
  2467. else
  2468. {
  2469. free(tTask);
  2470. };
  2471. };
  2472. return false;
  2473. }
  2474. bool deviceNodeCamera::connectToStream(uint32_t id)
  2475. {
  2476. /*
  2477. if( id ){
  2478. argusKernelModule * tKM = NULL;
  2479. argusKernel * tKRNL = NULL;
  2480. argusModuleFactory * tMF = NULL;
  2481. if( m_pDBC == NULL ) {
  2482. LOG_ERROR("No Database Connector!");
  2483. return false;
  2484. };
  2485. tKRNL = argusKernel::getInstance();
  2486. if( tKRNL ) {
  2487. tMF = tKRNL->getModuleFactory();
  2488. if( tMF ) {
  2489. tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
  2490. } else {
  2491. LOG_ERROR("No ModuleFactory Instance!");
  2492. return false;
  2493. };
  2494. } else {
  2495. LOG_ERROR("No Kernel Instance!");
  2496. return false;
  2497. };
  2498. if( tKM ) {
  2499. // New Module
  2500. DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
  2501. if( tDATA ) {
  2502. m_sMediaSource.mediaStreamId = id;
  2503. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  2504. if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
  2505. m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
  2506. } else {
  2507. if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
  2508. m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource );
  2509. };
  2510. if( m_pSource != NULL ) {
  2511. char tMRL[1024];
  2512. #ifdef DEBUG
  2513. LOG("Source OK");
  2514. #endif
  2515. ((videoLIVE555Source*)m_pSource)->setWM( MS_MODE_STREAM_PROXY | MS_MODE_OVERLAYED_LOOPS | MS_MODE_DECODE_FRAMES );
  2516. int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
  2517. int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
  2518. int pix = -1;
  2519. bool in_16_9 = (((tDATA->width*100) / tDATA->height ) > 140 );
  2520. bool out_16_9 = (((tW*100) / tH ) > 140 );
  2521. updateOpticalParameters( tW, tH );
  2522. if( strlen( tDATA->c_type ) ){
  2523. };
  2524. //if( tW > 0 ){
  2525. // //m_pSource->setProportionalByWidth( tW );
  2526. // m_pSource->setSize( tW, tH );
  2527. //};
  2528. if( in_16_9 != out_16_9 ){
  2529. if( in_16_9 ){
  2530. tH = ((( tW * 1000 ) / 16 ) * 9 ) / 1000;
  2531. } else {
  2532. tW = ((( tH * 1000 ) / 3 ) * 4 ) / 1000;
  2533. };
  2534. };
  2535. if (strncmp(tDATA->mrl_proto, "v4l2", 4) == 0) {
  2536. sprintf( tMRL, tDATA->mrl );
  2537. } else {
  2538. DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
  2539. if( tCAM ) {
  2540. sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
  2541. free( tCAM );
  2542. } else {
  2543. LOG_ERROR("Error Getting CAM Data!");
  2544. delete( m_pSource );
  2545. m_pSource = NULL;
  2546. return false;
  2547. };
  2548. };
  2549. LOG( tMRL );
  2550. if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
  2551. m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
  2552. if ( !m_bSourceConnected ) {
  2553. //delete( m_pSource );
  2554. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  2555. delete((videoAVLIBSource*)m_pSource);
  2556. } else {
  2557. delete((videoLIVE555Source*)m_pSource);
  2558. };
  2559. m_pSource = NULL;
  2560. } else {
  2561. m_nActiveStreamID = id;
  2562. #ifdef DEBUG
  2563. LOG("Source is Connected to Output.");
  2564. #endif
  2565. };
  2566. } else {
  2567. LOG_ERROR("Can not Open Video Source!");
  2568. //delete( m_pSource );
  2569. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  2570. delete((videoAVLIBSource*)m_pSource);
  2571. } else {
  2572. delete((videoLIVE555Source*)m_pSource);
  2573. };
  2574. m_pSource = NULL;
  2575. };
  2576. } else {
  2577. LOG_ERROR("Video Source Stream Failure!");
  2578. };
  2579. free( tDATA );
  2580. };
  2581. }
  2582. #ifdef DEBUG
  2583. else LOG("No Video Module!")
  2584. #endif
  2585. ;
  2586. };
  2587. LOG("Connect Finished!");
  2588. return m_bSourceConnected;
  2589. */
  2590. if ( id ) return true;
  2591. return true;
  2592. }
  2593. bool deviceNodeCamera::disconnectFromStream(void)
  2594. {
  2595. /*if( m_bSourceConnected ) {
  2596. if( m_pSource ){
  2597. delete( m_pSource );
  2598. m_pSource = NULL;
  2599. };
  2600. m_bSourceConnected = false;
  2601. };
  2602. return !m_bSourceConnected;
  2603. */
  2604. return true;
  2605. }
  2606. bool deviceNodeCamera::validateStream(void)
  2607. {
  2608. /*
  2609. if( m_bSourceConnected ) {
  2610. if( m_pSource ) {
  2611. if( m_pSource->isAttached() ){
  2612. if( m_pSource->getStatus() < MS_STOPED ) return true;
  2613. #ifdef DEBUG
  2614. LOG("Source is Finished!");
  2615. #endif
  2616. };
  2617. #ifdef DEBUG
  2618. LOG("Source is Disconnected!");
  2619. #endif
  2620. } else LOG_ERROR("No Source Object! Set Disconnected!");
  2621. disconnectFromStream();
  2622. };
  2623. return false;
  2624. */
  2625. return true;
  2626. }
  2627. bool deviceNodeCamera::validate()
  2628. {
  2629. if (m_pDBC == NULL)
  2630. {
  2631. return false;
  2632. }
  2633. DBC_CAM_DATA * tDATA = m_pDBC->getCamData(m_sCamData.id);
  2634. if (tDATA == NULL)
  2635. {
  2636. return false;
  2637. }
  2638. if (memcmp(tDATA, &m_sCamData, sizeof(DBC_CAM_DATA)) != 0)
  2639. {
  2640. // Settings Changed
  2641. // memcpy(&m_sCamData, tDATA, sizeof(DBC_CAM_DATA) );
  2642. free(tDATA);
  2643. return false;
  2644. };
  2645. free(tDATA);
  2646. if (! validateStream())
  2647. {
  2648. return false;
  2649. }
  2650. return deviceNode::validate();
  2651. }
  2652. bool deviceNodeCamera::load_presets(void)
  2653. {
  2654. bool bHaveIROFF = false;
  2655. bool bHaveIRON = false;
  2656. bool bHaveIRAUTO = false;
  2657. // Request PRESETS FROM CAMERA?! for some PTZ cameras without presets inpossible to
  2658. // operate by presets
  2659. if (m_pProtocol->getCameraPresets())
  2660. {
  2661. LOG("Camera Presets Loadded");
  2662. }
  2663. else
  2664. {
  2665. LOG_ERROR("Error while loadding Camera Presets!");
  2666. }
  2667. if (m_pDBC == NULL)
  2668. {
  2669. return false;
  2670. }
  2671. DBC_PRESETS_INFO * tData = m_pDBC->getCamPresetInfo(m_sCamData.id);
  2672. if (tData)
  2673. {
  2674. //memcpy(&m_sCamPresets, tData, sizeof(DBC_PRESETS_INFO));
  2675. m_sCamPresets.maxCount = tData->maxCount;
  2676. m_sCamPresets.gRows = tData->gRows;
  2677. m_sCamPresets.gCols = tData->gCols;
  2678. m_sCamPresets.presets.clear();
  2679. #ifdef DEBUG
  2680. char tB[128];
  2681. LOG("Loading Presets!");
  2682. sprintf(tB, "Cam Presets Info: CNT: %d Cols: %d Rows: %d ", m_sCamPresets.maxCount, m_sCamPresets.gCols, m_sCamPresets.gRows);
  2683. LOG(tB);
  2684. #endif
  2685. DBC_INT_LIST * tList = m_pDBC->listCamPresets(m_sCamData.id);
  2686. if (tList)
  2687. {
  2688. for (DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++)
  2689. {
  2690. CAM_PRESET * tData = m_pDBC->getCamPreset(*idx);
  2691. if (tData)
  2692. {
  2693. m_sCamPresets.presets.push_back(tData);
  2694. bHaveIRON = (tData->role == ARGUS_PRESET_TYPE_IR_ON) ? true : bHaveIRON;
  2695. bHaveIROFF = (tData->role == ARGUS_PRESET_TYPE_IR_OFF) ? true : bHaveIROFF;
  2696. bHaveIRAUTO = (tData->role == ARGUS_PRESET_TYPE_IR_AUTO) ? true : bHaveIRAUTO;
  2697. };
  2698. };
  2699. delete(tList);
  2700. };
  2701. if (m_sCamData.eco_ir)
  2702. {
  2703. m_bShineOnTarget = (bHaveIROFF && bHaveIRAUTO);
  2704. }
  2705. else
  2706. {
  2707. m_bShineOnTarget = false;
  2708. }
  2709. return true;
  2710. #ifdef DEBUG
  2711. }
  2712. else
  2713. {
  2714. LOG("No Camera Presets!");
  2715. #endif
  2716. };
  2717. return false;
  2718. }
  2719. void deviceNodeCamera::translateROI2PRESET(float P, float T, float Z, uint8_t & col, uint8_t & row)
  2720. {
  2721. //char tB[128];
  2722. if ( T ) Z = Z;
  2723. row = (uint8_t)(Z * ((float)m_sCamPresets.gRows));
  2724. if (P < 0.5)
  2725. {
  2726. P = P + 1.5f;
  2727. }
  2728. else
  2729. {
  2730. P = P - 0.5f;
  2731. };
  2732. col = (uint8_t) (P * ((float) (m_sCamPresets.gCols * (1 << row)) / 2.0f));
  2733. row++;
  2734. }
  2735. CSTR deviceNodeCamera::getPresetToken(uint8_t CCOL, uint8_t CROW)
  2736. {
  2737. if (m_sCamPresets.presets.size() > 0)
  2738. {
  2739. for (V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++)
  2740. {
  2741. if ((*idx)->role == ARGUS_PRESET_TYPE_POSITION)
  2742. {
  2743. if (((*idx)->row == CROW) && ((*idx)->col == CCOL))
  2744. {
  2745. return (CSTR) (*idx)->token;
  2746. }
  2747. }
  2748. }
  2749. }
  2750. return NULL;
  2751. }
  2752. CSTR deviceNodeCamera::getPresetToken(uint8_t specialRole)
  2753. {
  2754. if (m_sCamPresets.presets.size() > 0)
  2755. {
  2756. for (V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++)
  2757. {
  2758. if ((*idx)->role == specialRole)
  2759. {
  2760. return (CSTR) (*idx)->token;
  2761. }
  2762. }
  2763. }
  2764. return NULL;
  2765. }
  2766. #undef LOG
  2767. #undef LOG_ERROR
  2768. //#undef DEBUG_EXTRA