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.

2886 lines
70 KiB

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