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.

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