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.

2885 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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. setWM(CAM_WS_READY);
  1386. break;
  1387. };
  1388. case CAM_WS_AUTOMATED_MOVE:
  1389. {
  1390. m_bCameraOnHomePosition = false;
  1391. m_nRelativeMoveCounter++;
  1392. if ((m_bRelativeMoveMatrix & 0x03) != 0)
  1393. {
  1394. // Pan Move
  1395. if ((m_bRelativeMoveMatrix & 0x01) == 0)
  1396. {
  1397. m_fRM_Pan -= m_fSpeedRise;
  1398. }
  1399. else
  1400. {
  1401. m_fRM_Pan += m_fSpeedRise;
  1402. };
  1403. };
  1404. if ((m_bRelativeMoveMatrix & 0x0C) != 0)
  1405. {
  1406. // TILT Move
  1407. if ((m_bRelativeMoveMatrix & 0x04) == 0)
  1408. {
  1409. m_fRM_Tilt -= m_fSpeedRise;
  1410. }
  1411. else
  1412. {
  1413. m_fRM_Tilt += m_fSpeedRise;
  1414. }
  1415. };
  1416. if ((m_bRelativeMoveMatrix & 0x30) != 0)
  1417. {
  1418. // ZOOM Move
  1419. if ((m_bRelativeMoveMatrix & 0x10) == 0)
  1420. {
  1421. // Wide
  1422. m_fRM_Zoom -= m_fSpeedRise;
  1423. }
  1424. else
  1425. {
  1426. // Tele
  1427. m_fRM_Zoom += m_fSpeedRise;
  1428. };
  1429. };
  1430. if (m_fRM_Pan < -1.0f)
  1431. {
  1432. m_fRM_Pan = -1.0f;
  1433. }
  1434. if (m_fRM_Pan > 1.0f)
  1435. {
  1436. m_fRM_Pan = 1.0f;
  1437. }
  1438. if (m_fRM_Tilt < -1.0f)
  1439. {
  1440. m_fRM_Tilt = -1.0f;
  1441. }
  1442. if (m_fRM_Tilt > 1.0f)
  1443. {
  1444. m_fRM_Tilt = 1.0f;
  1445. }
  1446. if (m_fRM_Zoom < -1.0f)
  1447. {
  1448. m_fRM_Zoom = -1.0f;
  1449. }
  1450. if (m_fRM_Zoom > 1.0f)
  1451. {
  1452. m_fRM_Zoom = 1.0f;
  1453. }
  1454. m_fCP_Zoom += 0.5f * m_fRM_Zoom;
  1455. if (m_fCP_Zoom < -1.0f)
  1456. {
  1457. m_fCP_Zoom = -1.0f;
  1458. }
  1459. if (m_fCP_Zoom > 1.0f)
  1460. {
  1461. m_fCP_Zoom = 1.0f;
  1462. }
  1463. if (! relativeMove(m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom))
  1464. {
  1465. m_nRelativeMoveCounter = 0;
  1466. setWM(CAM_WS_READY);
  1467. break;
  1468. };
  1469. if (m_sCamData.ptz_axel)
  1470. { // Manual
  1471. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel)
  1472. {
  1473. m_nRelativeMoveCounter = 0;
  1474. setWM(CAM_WS_READY);
  1475. };
  1476. }
  1477. else
  1478. {
  1479. // Stepping Axel by Zoom
  1480. uint8_t tVal = (uint8_t) (10.0f * (2.0f - (1.0f + m_fCP_Zoom)));
  1481. if (m_nRelativeMoveCounter > tVal)
  1482. {
  1483. m_nRelativeMoveCounter = 0;
  1484. setWM(CAM_WS_READY);
  1485. };
  1486. };
  1487. break;
  1488. };
  1489. case CAM_WS_STOP_MOVE:
  1490. {
  1491. m_nRelativeMoveCounter++;
  1492. m_fRM_Pan = .0f;
  1493. m_fRM_Pan = .0f;
  1494. m_fRM_Tilt = .0f;
  1495. m_fRM_Tilt = .0f;
  1496. m_fRM_Zoom = .0f;
  1497. m_fRM_Zoom = .0f;
  1498. if (relativeStop())
  1499. {
  1500. m_nHomingCounter = 0;
  1501. m_nRelativeMoveCounter = 0;
  1502. setWM(CAM_WS_READY);
  1503. break;
  1504. };
  1505. if (m_sCamData.ptz_axel)
  1506. {
  1507. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel)
  1508. {
  1509. setWM(CAM_WS_READY);
  1510. }
  1511. }
  1512. else
  1513. {
  1514. uint8_t tVal = (uint8_t) (10.0f * (2.0f - (1.0f + m_fCP_Zoom)));
  1515. if (m_nRelativeMoveCounter > tVal)
  1516. {
  1517. setWM(CAM_WS_READY);
  1518. }
  1519. };
  1520. break;
  1521. };
  1522. case CAM_WS_GO_ABS_ROI:
  1523. case CAM_WS_GO_ABS_POSITION:
  1524. {
  1525. m_bCameraOnHomePosition = false;
  1526. setWM(CAM_WS_BUSY);
  1527. if (m_pCurrentROI != NULL)
  1528. {
  1529. // LOG("ROI Ok");
  1530. m_nHomingCounter = 0;
  1531. if (m_pBEH)
  1532. {
  1533. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_MOVE_TO, NULL, NULL, NULL);
  1534. if (tEVT)
  1535. {
  1536. m_pBEH->broadcast(tEVT);
  1537. }
  1538. };
  1539. if (m_bNoAbsPositionning)
  1540. {
  1541. // LOG("ABS to PRESET");
  1542. uint8_t COL, ROW;
  1543. translateROI2PRESET(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom, COL, ROW);
  1544. // char tB[64];
  1545. // sprintf( tB, "Get ABS Preset Col %d Row %d!", COL, ROW );
  1546. // LOG( tB );
  1547. // sprintf( tB, "Old Preset Col %d Row %d!", m_bCurrentPresetCol, m_bCurrentPresetRow );
  1548. // LOG( tB );
  1549. if ((m_bCurrentPresetCol == COL) && (m_bCurrentPresetRow == ROW))
  1550. {
  1551. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1552. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1553. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1554. #ifdef DEBUG_EXTRA
  1555. LOG("INSTANT BCAST CAM ONPOS");
  1556. #endif
  1557. // Send Capture event
  1558. #ifndef NO_CAMERA_FUSION_ENGINE
  1559. DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
  1560. #else
  1561. DBC_SNAPSHOT_DATA * tData = NULL;
  1562. #endif
  1563. if (tData != NULL)
  1564. {
  1565. if (m_pBEH)
  1566. {
  1567. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1568. if (tEVT)
  1569. {
  1570. m_pBEH->broadcast(tEVT);
  1571. }
  1572. else
  1573. {
  1574. //free(tData);
  1575. delete(tData);
  1576. };
  1577. }
  1578. else
  1579. {
  1580. //free(tData);
  1581. delete(tData);
  1582. };
  1583. };
  1584. setWM(CAM_WS_READY);
  1585. }
  1586. else
  1587. {
  1588. CSTR token = getPresetToken(COL, ROW);
  1589. if (token)
  1590. {
  1591. // update position Info
  1592. m_bCurrentPresetCol = COL;
  1593. m_bCurrentPresetRow = ROW;
  1594. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1595. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1596. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1597. if (! m_pProtocol->goPreset(token))
  1598. {
  1599. LOG_ERROR("Cannot Issue goPreset Command!->Restart Camera?");
  1600. setWM(CAM_WS_END);
  1601. }
  1602. else
  1603. {
  1604. // Waiting Movement finish
  1605. if (m_bSkeepPositioningWait && 0)
  1606. {
  1607. #ifdef DEBUG_EXTRA
  1608. LOG("INSTANT BCAST CAM ONPOS");
  1609. #endif
  1610. // Send Capture event
  1611. #ifndef NO_CAMERA_FUSION_ENGINE
  1612. DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
  1613. #else
  1614. DBC_SNAPSHOT_DATA * tData = NULL;
  1615. #endif
  1616. if (tData != NULL)
  1617. {
  1618. if (m_pBEH)
  1619. {
  1620. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1621. if (tEVT)
  1622. {
  1623. m_pBEH->broadcast(tEVT);
  1624. }
  1625. else
  1626. {
  1627. //free(tData);
  1628. delete(tData);
  1629. };
  1630. }
  1631. else
  1632. {
  1633. //free(tData);
  1634. delete(tData);
  1635. };
  1636. };
  1637. setWM(CAM_WS_READY);
  1638. }
  1639. else
  1640. {
  1641. // utilizeROI( m_pCurrentROI );
  1642. setWM(CAM_WS_WAIT_ONPOS);
  1643. };
  1644. };
  1645. }
  1646. else
  1647. {
  1648. #ifdef DEBUG_EXTRA
  1649. LOG("Not Found!");
  1650. #endif
  1651. utilizeROI(m_pCurrentROI);
  1652. setWM(CAM_WS_READY);
  1653. };
  1654. };
  1655. }
  1656. else
  1657. {
  1658. // update position Info
  1659. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1660. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1661. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1662. // Do Movement
  1663. if (! m_pProtocol->goAbsolute(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection))
  1664. {
  1665. LOG_ERROR("Cannot Issue goAbsolute Command!->Restart Camera?");
  1666. setWM(CAM_WS_END);
  1667. }
  1668. else
  1669. {
  1670. // Waiting Movement finish
  1671. if (m_bSkeepPositioningWait)
  1672. {
  1673. #ifdef DEBUG_EXTRA
  1674. LOG("INSTANT BCAST CAM ONPOS");
  1675. #endif
  1676. // Send Capture event
  1677. #ifndef NO_CAMERA_FUSION_ENGINE
  1678. DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
  1679. #else
  1680. DBC_SNAPSHOT_DATA * tData = NULL;
  1681. #endif
  1682. if (tData != NULL)
  1683. {
  1684. if (m_pBEH)
  1685. {
  1686. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1687. if (tEVT)
  1688. {
  1689. m_pBEH->broadcast(tEVT);
  1690. }
  1691. else
  1692. {
  1693. //free(tData);
  1694. delete(tData);
  1695. };
  1696. }
  1697. else
  1698. {
  1699. //free(tData);
  1700. delete(tData);
  1701. };
  1702. };
  1703. setWM(CAM_WS_READY);
  1704. }
  1705. else
  1706. {
  1707. setWM(CAM_WS_WAIT_ONPOS);
  1708. };
  1709. };
  1710. };
  1711. }
  1712. else
  1713. {
  1714. setWM(CAM_WS_READY);
  1715. }
  1716. break;
  1717. };
  1718. case CAM_WS_WAIT_ONPOS:
  1719. {
  1720. // LOG("WaitOnPos...");
  1721. DBC_SNAPSHOT_DATA * tData = NULL;
  1722. if (m_pCurrentROI != NULL)
  1723. {
  1724. // Send Capture event
  1725. #ifndef NO_CAMERA_FUSION_ENGINE
  1726. tData = fusion_translate_ROI(m_pCurrentROI);
  1727. #else
  1728. tData = NULL;
  1729. #endif
  1730. };
  1731. // To Accept any new ROI's ??
  1732. // setWM( CAM_WS_READY );
  1733. #ifdef DEBUG_EXTRA
  1734. LOG("Start Waiting Cam On Position!");
  1735. #endif
  1736. if (! m_bSkeepPositioningWait)
  1737. {
  1738. if (! m_pProtocol->waitMoveIsDone())
  1739. {
  1740. m_bSkeepPositioningWait = true;
  1741. }
  1742. };
  1743. if (m_bSkeepPositioningWait)
  1744. {
  1745. SLEEP(3000);
  1746. }
  1747. #ifdef DEBUG_EXTRA
  1748. LOG("Done Waiting Cam On Position!");
  1749. #endif
  1750. if (tData != NULL)
  1751. {
  1752. if (m_pBEH)
  1753. {
  1754. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1755. if (tEVT)
  1756. {
  1757. #ifdef DEBUG_EXTRA
  1758. LOG("BCAST CAM ONPOS");
  1759. #endif
  1760. m_pBEH->broadcast(tEVT);
  1761. }
  1762. else
  1763. {
  1764. //free(tData);
  1765. delete(tData);
  1766. };
  1767. }
  1768. else
  1769. {
  1770. //free(tData);
  1771. delete(tData);
  1772. };
  1773. tData = NULL;
  1774. };
  1775. setWM(CAM_WS_READY);
  1776. break;
  1777. };
  1778. case CAM_WS_GO_HOMING_PRESET:
  1779. {
  1780. if (! m_bCameraOnHomePosition)
  1781. {
  1782. // For new Camera Presets
  1783. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_HOME);
  1784. if (TK)
  1785. {
  1786. #ifdef DEBUG_EXTRA
  1787. LOG("Go Home!");
  1788. LOG(TK);
  1789. #endif
  1790. if (! m_pProtocol->goPreset(TK))
  1791. {
  1792. LOG_ERROR("Cannot Issue goPreset Command!");
  1793. };
  1794. }
  1795. else
  1796. {
  1797. // Old Method
  1798. if (m_sCamData.home_token[0] != (char) 0)
  1799. {
  1800. #ifdef DEBUG_EXTRA
  1801. LOG("Go Home!");
  1802. LOG(m_sCamData.home_token);
  1803. #endif
  1804. if (! m_pProtocol->goPreset(m_sCamData.home_token))
  1805. {
  1806. LOG_ERROR("Cannot Issue goPreset Command!");
  1807. };
  1808. };
  1809. };
  1810. m_bCameraOnHomePosition = true;
  1811. m_bCurrentPresetCol = 0;
  1812. m_bCurrentPresetRow = 0;
  1813. };
  1814. setWM(CAM_WS_READY);
  1815. break;
  1816. };
  1817. case CAM_WS_GO_PRESET:
  1818. {
  1819. LOG("Go Preset!");
  1820. // if( m_sCamData.home_token[0] != (char)0 ) {
  1821. // LOG("Go Home!");
  1822. // LOG( m_sCamData.home_token );
  1823. // if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  1824. // LOG_ERROR("Cannot Issue goPreset Command!");
  1825. // };
  1826. // };
  1827. setWM(CAM_WS_READY);
  1828. break;
  1829. };
  1830. case CAM_WS_SET_PRESET:
  1831. {
  1832. LOG("Set Preset!");
  1833. // if( m_sCamData.home_token[0] != (char)0 ) {
  1834. // LOG("Go Home!");
  1835. // LOG( m_sCamData.home_token );
  1836. // if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  1837. // LOG_ERROR("Cannot Issue goPreset Command!");
  1838. // };
  1839. // };
  1840. setWM(CAM_WS_READY);
  1841. break;
  1842. };
  1843. case CAM_WS_BUSY:
  1844. {
  1845. // Handle Operation TO
  1846. setWM(CAM_WS_READY);
  1847. break;
  1848. };
  1849. case CAM_WS_READY:
  1850. {
  1851. #ifndef NO_CAMERA_FUSION_ENGINE
  1852. m_pCurrentROI = fusion_fetchROI();
  1853. #else
  1854. #endif
  1855. if (m_pCurrentROI != NULL)
  1856. {
  1857. #ifdef DEBUG_EXTRA
  1858. LOG("HAVE ROI to see!");
  1859. #endif
  1860. setWM(CAM_WS_GO_ABS_POSITION);
  1861. }
  1862. else
  1863. {
  1864. // Idle Work --->
  1865. if (m_sCamData.eco_ir)
  1866. {
  1867. m_mIRProtector.lock();
  1868. if (m_bIRIsOn)
  1869. {
  1870. if (m_bIRTO)
  1871. {
  1872. if (bNewSecondLoop)
  1873. {
  1874. m_bIRTO--;
  1875. }
  1876. }
  1877. else
  1878. {
  1879. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_OFF);
  1880. if (TK)
  1881. {
  1882. if (m_pProtocol->goPreset(TK))
  1883. {
  1884. m_bIRIsOn = false;
  1885. }
  1886. }
  1887. };
  1888. };
  1889. m_mIRProtector.unlock();
  1890. };
  1891. if (m_sCamData.homing_enable)
  1892. {
  1893. if (bNewSecondLoop)
  1894. {
  1895. if (m_nHomingCounter < m_sCamData.homing_to)
  1896. {
  1897. m_nHomingCounter++;
  1898. }
  1899. else
  1900. {
  1901. // LOG("Go Home Position!");
  1902. m_nHomingCounter = 0;
  1903. setWM(CAM_WS_GO_HOMING_PRESET);
  1904. break;
  1905. };
  1906. };
  1907. };
  1908. CAM_TASK * tTASK = fetchCamTask();
  1909. if (tTASK != NULL)
  1910. {
  1911. if (tTASK->movemet_needed)
  1912. {
  1913. CAM_PTZ_CMD * tCMD = tTASK->CMD;
  1914. if (tCMD)
  1915. {
  1916. switch (tCMD->CMD)
  1917. {
  1918. case PTZ_STOP:
  1919. {
  1920. m_nHomingCounter = 0;
  1921. setWM(CAM_WS_STOP_MOVE);
  1922. break;
  1923. };
  1924. case PTZ_MOVE:
  1925. {
  1926. if (tState != CAM_WS_AUTOMATED_MOVE)
  1927. {
  1928. m_nRelativeMoveCounter = 0;
  1929. }
  1930. m_bRelativeMoveMatrix = 0;
  1931. m_fRM_Pan = tCMD->PAN;
  1932. m_fRM_Tilt = tCMD->TILT;
  1933. m_fRM_Zoom = tCMD->ZOOM;
  1934. m_nHomingCounter = 0;
  1935. setWM(CAM_WS_AUTOMATED_MOVE);
  1936. break;
  1937. };
  1938. case PTZ_ABSOLUTE:
  1939. {
  1940. m_pCurrentROI = createCAM_ROI();
  1941. if (m_pCurrentROI != NULL)
  1942. {
  1943. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
  1944. if (tTarget != NULL)
  1945. {
  1946. memset(tTarget, 0, sizeof(CAM_TRACK_RECORD));
  1947. tTarget->evt_db_ID = tTASK->source_evt_id;
  1948. m_pCurrentROI->targets.push_back(tTarget);
  1949. m_pCurrentROI->cam_orientation.pan = tCMD->PAN;
  1950. m_pCurrentROI->cam_orientation.tilt = tCMD->TILT;
  1951. m_pCurrentROI->cam_orientation.zoom = tCMD->ZOOM;
  1952. m_nHomingCounter = 0;
  1953. setWM(CAM_WS_GO_ABS_POSITION);
  1954. }
  1955. else
  1956. {
  1957. utilizeROI(m_pCurrentROI);
  1958. };
  1959. };
  1960. break;
  1961. };
  1962. case PTZ_RELOAD_CAMERA:
  1963. {
  1964. LOG("Exit Command Rcpt");
  1965. m_bThreadStatus = TH_ENDED;
  1966. };
  1967. };
  1968. free(tCMD);
  1969. tTASK->CMD = NULL;
  1970. };
  1971. }
  1972. else
  1973. {
  1974. LOG("No Movement -> INSTCAP");
  1975. // No Movement -> Just Capture
  1976. if (m_pBEH)
  1977. {
  1978. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, NULL);
  1979. if (tEVT)
  1980. {
  1981. tEVT->m_db_id = tTASK->source_evt_id;
  1982. m_pBEH->broadcast(tEVT);
  1983. };
  1984. };
  1985. };
  1986. free(tTASK);
  1987. }
  1988. else
  1989. {
  1990. // Lowest Priority to Web Client Commands
  1991. #ifdef DEBUG_EXTRA__
  1992. LOG("Check Web CMD!");
  1993. #endif
  1994. PUSHED = m_pDBC->getNodePushedCMD(m_sNodeData.node_id);
  1995. if (PUSHED != NULL)
  1996. {
  1997. #ifdef DEBUG_EXTRA__
  1998. LOG("HAVE Web CMD!");
  1999. #endif
  2000. m_pDBC->updateNodePushedCMD(PUSHED->id, DBC_CMD_READY_TO_CLEAN);
  2001. if ((PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK) == ARGUS_CAM_PCMD_CMD_MASK)
  2002. {
  2003. switch (PUSHED->CMD)
  2004. {
  2005. case 0x80:
  2006. {
  2007. // Call Home Preset
  2008. LOG("CALL HOME PRESET!");
  2009. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_HOME);
  2010. if (TK)
  2011. {
  2012. LOG(TK);
  2013. if (m_pProtocol->goPreset(TK))
  2014. {
  2015. m_bCameraOnHomePosition = true;
  2016. m_nHomingCounter = 0;
  2017. };
  2018. };
  2019. break;
  2020. };
  2021. case 0x81:
  2022. {
  2023. // Call IR On Preset
  2024. LOG("CALL IR ON PRESET!");
  2025. m_mIRProtector.lock();
  2026. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_ON);
  2027. if (TK)
  2028. {
  2029. LOG(TK);
  2030. if (m_pProtocol->goPreset(TK))
  2031. {
  2032. m_bIRIsOn = true;
  2033. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2034. };
  2035. }
  2036. else
  2037. {
  2038. LOG("PRESET NOT FOUND!");
  2039. }
  2040. m_mIRProtector.unlock();
  2041. break;
  2042. };
  2043. case 0x82:
  2044. {
  2045. // Call IR Off Preset
  2046. LOG("CALL IR OFF PRESET!");
  2047. m_mIRProtector.lock();
  2048. CSTR TK = (m_sCamData.eco_ir) ? getPresetToken(ARGUS_PRESET_TYPE_IR_OFF) : getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  2049. if (TK)
  2050. {
  2051. LOG(TK);
  2052. if (m_pProtocol->goPreset(TK))
  2053. {
  2054. m_bIRIsOn = false;
  2055. m_bIRTO = 0;
  2056. };
  2057. }
  2058. else
  2059. {
  2060. LOG("PRESET NOT FOUND!");
  2061. }
  2062. m_mIRProtector.unlock();
  2063. break;
  2064. };
  2065. case 0x83:
  2066. {
  2067. // Call IR Auto Preset
  2068. LOG("CALL IR AUTO PRESET!");
  2069. m_mIRProtector.lock();
  2070. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  2071. if (TK)
  2072. {
  2073. LOG(TK);
  2074. if (m_pProtocol->goPreset(TK))
  2075. {
  2076. m_bIRIsOn = true;
  2077. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2078. };
  2079. }
  2080. else
  2081. {
  2082. LOG("PRESET NOT FOUND!");
  2083. }
  2084. m_mIRProtector.unlock();
  2085. break;
  2086. };
  2087. case 0x84:
  2088. {
  2089. // Call Wisher Preset
  2090. LOG("CALL WIPER PRESET!");
  2091. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_WISHER);
  2092. if (TK)
  2093. {
  2094. LOG(TK);
  2095. m_pProtocol->goPreset(TK);
  2096. };
  2097. break;
  2098. };
  2099. };
  2100. }
  2101. else if (tState == CAM_WS_READY || tState == CAM_WS_AUTOMATED_MOVE)
  2102. { // No Way to get here
  2103. // Direct Movment Mode
  2104. if (PUSHED->CMD == ARGUS_CAM_PCMD_STOP)
  2105. {
  2106. m_nHomingCounter = 0;
  2107. setWM(CAM_WS_STOP_MOVE);
  2108. }
  2109. else
  2110. {
  2111. //char tB[64];
  2112. if (tState != CAM_WS_AUTOMATED_MOVE)
  2113. {
  2114. m_nRelativeMoveCounter = 0;
  2115. }
  2116. m_bRelativeMoveMatrix = (PUSHED->CMD) >> 1;
  2117. m_nHomingCounter = 0;
  2118. setWM(CAM_WS_AUTOMATED_MOVE);
  2119. };
  2120. };
  2121. free(PUSHED);
  2122. PUSHED = NULL;
  2123. };
  2124. };
  2125. };
  2126. break;
  2127. };
  2128. case CAM_WS_END:
  2129. {
  2130. LOG("Exit Command Rcpt");
  2131. m_bThreadStatus = TH_ENDED;
  2132. break;
  2133. };
  2134. };
  2135. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  2136. };
  2137. #ifdef DEBUG
  2138. LOG("CTRL Loop End!");
  2139. #endif
  2140. }
  2141. bool deviceNodeCamera::setNoPositionWait(bool FL)
  2142. {
  2143. m_bSkeepPositioningWait = FL;
  2144. return true;
  2145. }
  2146. bool deviceNodeCamera::testFOV(C3D_DECART L)
  2147. {
  2148. // System Coords -> trans to local and go to funct
  2149. systemAnchor * tSystem = systemAnchor::getInstance();
  2150. if (tSystem == NULL)
  2151. {
  2152. return false;
  2153. }
  2154. C3D_SPH_DEGREES SL;
  2155. #ifdef DEBUG_EXTRA
  2156. LOG("Test FOV local Decart coords");
  2157. #endif
  2158. if (! tSystem->convertToLocal(&m_oPosition, L, SL))
  2159. {
  2160. return false;
  2161. }
  2162. return testFOV(SL);
  2163. }
  2164. bool deviceNodeCamera::testFOV(C3D_WGS84_LOC L)
  2165. {
  2166. // Global Coords
  2167. systemAnchor * tSystem = systemAnchor::getInstance();
  2168. if (tSystem == NULL)
  2169. {
  2170. return false;
  2171. }
  2172. C3D_SPH_DEGREES SL;
  2173. #ifdef DEBUG_EXTRA
  2174. LOG("Test FOV WGS coords");
  2175. #endif
  2176. if (! tSystem->convertToLocal(&m_oPosition, L, SL))
  2177. {
  2178. return false;
  2179. }
  2180. return testFOV(SL);
  2181. }
  2182. bool deviceNodeCamera::testFOV(C3D_SPH_RADIANS L)
  2183. {
  2184. // Local Coords
  2185. C3D_SPH_DEGREES SL;
  2186. #ifdef DEBUG_EXTRA
  2187. LOG("Test FOV local Spherical(rad) coords");
  2188. #endif
  2189. spherical2spherical(L, SL);
  2190. return testFOV(SL);
  2191. }
  2192. bool deviceNodeCamera::testFOV(C3D_SPH_DEGREES SL)
  2193. {
  2194. #ifdef DEBUG_EXTRA
  2195. char tB[128];
  2196. #endif
  2197. #ifdef DEBUG_EXTRA
  2198. LOG("Test FOV local Spherical(deg) coords");
  2199. #endif
  2200. switch (m_sCamData.triggering_mode)
  2201. {
  2202. case CAM_TRIGGER_STRICT:
  2203. {
  2204. if (SL.r > m_fMaxRange || SL.r < m_fMinRange)
  2205. {
  2206. #ifdef DEBUG_EXTRA
  2207. sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
  2208. LOG(tB);
  2209. #endif
  2210. return false;
  2211. };
  2212. break;
  2213. };
  2214. case CAM_TRIGGER_ALL_NEAR:
  2215. {
  2216. if (SL.r > m_fMaxRange)
  2217. {
  2218. #ifdef DEBUG_EXTRA
  2219. sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
  2220. LOG(tB);
  2221. #endif
  2222. return false;
  2223. };
  2224. break;
  2225. };
  2226. case CAM_TRIGGER_ALL_FAR:
  2227. {
  2228. if (SL.r < m_fMinRange)
  2229. {
  2230. #ifdef DEBUG_EXTRA
  2231. sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
  2232. LOG(tB);
  2233. #endif
  2234. return false;
  2235. };
  2236. break;
  2237. };
  2238. case CAM_TRIGGER_ALL: return true;
  2239. };
  2240. // float HS = AC_imager_width[m_sCamData.imager_type];
  2241. // float VS = AC_imager_height[m_sCamData.imager_type];
  2242. // float HS2 = HS * HS;
  2243. // float VS2 = VS * VS;
  2244. // float IR = HS / VS;
  2245. // float IR2 = IR * IR;
  2246. if (m_sCamData.pan_angles == 0)
  2247. {
  2248. // Fixed Camera
  2249. float tA = fabsf(SL.fi);
  2250. float tZ = 0.5f * (m_fMinHFov + (SL.r - m_fMinRange) * m_fR2FL);
  2251. if (tA > tZ)
  2252. {
  2253. return false;
  2254. }
  2255. }
  2256. else
  2257. {
  2258. if (m_sCamData.pan_angles < 360)
  2259. { // If endless PAN -> PASSED
  2260. // Partial Pan
  2261. switch (m_sCamData.pan_model)
  2262. {
  2263. case 1:
  2264. {
  2265. // Regular Pan
  2266. float tFOV = 0.5f * (m_fMinHFov + (SL.r - m_fMinRange) * m_fR2FL);
  2267. float tRad = deg2rad(SL.fi);
  2268. #ifdef DEBUG_EXTRA
  2269. sprintf(tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad);
  2270. LOG(tB);
  2271. #endif
  2272. if ((tRad < (-1.0 * tFOV)) || (tRad > (deg2rad(m_sCamData.pan_angles) + tFOV)))
  2273. {
  2274. return false;
  2275. }
  2276. break;
  2277. };
  2278. case 2:
  2279. {
  2280. break;
  2281. };
  2282. case 3:
  2283. {
  2284. break;
  2285. };
  2286. };
  2287. };
  2288. };
  2289. if (m_sCamData.tilt_angles == 0)
  2290. {
  2291. // Fixed Camera
  2292. if ((SL.tetta < (m_fMaxVFov / -2.0f)) || (SL.tetta > (m_fMaxVFov / 2.0f)))
  2293. {
  2294. return false;
  2295. }
  2296. }
  2297. else
  2298. {
  2299. if (m_sCamData.tilt_angles < 90)
  2300. { // if Cam CAN DO 90 -> Pass
  2301. // Partial Tilt
  2302. switch (m_sCamData.tilt_model)
  2303. {
  2304. case 1:
  2305. {
  2306. // Regular Tilt
  2307. float tFOV = 0.5f * (m_fMinVFov + (m_fMaxVFov - m_fMinVFov) * (SL.r / m_fMaxRange));
  2308. float tRad = deg2rad(SL.tetta);
  2309. if ((tRad < (-1.0 * tFOV)) || (tRad > (deg2rad(m_sCamData.tilt_angles) + tFOV)))
  2310. {
  2311. return false;
  2312. }
  2313. break;
  2314. };
  2315. case 2:
  2316. {
  2317. break;
  2318. };
  2319. };
  2320. };
  2321. };
  2322. return true;
  2323. }
  2324. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_WGS84_LOC L)
  2325. {
  2326. systemAnchor * tSystem = systemAnchor::getInstance();
  2327. if (tSystem == NULL)
  2328. {
  2329. return false;
  2330. }
  2331. C3D_SPH_DEGREES SL;
  2332. #ifdef DEBUG_EXTRA
  2333. LOG("Look at WGS coords!");
  2334. #endif
  2335. tSystem->convertToLocal(&m_oPosition, L, SL);
  2336. return lookAt(TargetRefID, SL);
  2337. }
  2338. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_DECART L)
  2339. {
  2340. systemAnchor * tSystem = systemAnchor::getInstance();
  2341. if (tSystem == NULL)
  2342. {
  2343. LOG_ERROR("Cant Get Anchor!");
  2344. return false;
  2345. }
  2346. C3D_SPH_DEGREES SL;
  2347. #ifdef DEBUG_EXTRA
  2348. LOG("Look at System Decart coords!");
  2349. #endif
  2350. tSystem->convertToLocal(&m_oPosition, L, SL);
  2351. return lookAt(TargetRefID, SL);
  2352. }
  2353. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_SPH_RADIANS L)
  2354. {
  2355. C3D_SPH_DEGREES SL;
  2356. #ifdef DEBUG_EXTRA
  2357. LOG("Look at spherical(rad) 2 spherical(deg) coords!");
  2358. #endif
  2359. spherical2spherical(L, SL);
  2360. return lookAt(TargetRefID, SL);
  2361. }
  2362. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_SPH_DEGREES L)
  2363. {
  2364. if (m_bCameraIsStatic)
  2365. {
  2366. //DBC_SNAPSHOT_DATA * tData = (DBC_SNAPSHOT_DATA *) malloc(sizeof(DBC_SNAPSHOT_DATA));
  2367. DBC_SNAPSHOT_DATA * tData = new DBC_SNAPSHOT_DATA();
  2368. if (tData)
  2369. {
  2370. //memset(tData, 0, sizeof(DBC_SNAPSHOT_DATA));
  2371. tData->stream_id = m_sNodeData.aux_parameter;
  2372. tData->assoc_event_ids.push_back(TargetRefID);
  2373. if (m_pBEH)
  2374. {
  2375. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  2376. if (tEVT)
  2377. {
  2378. #ifdef DEBUG_EXTRA
  2379. LOG("INSTANT BCAST CAM ONPOS");
  2380. #endif
  2381. m_pBEH->broadcast(tEVT);
  2382. }
  2383. else
  2384. {
  2385. //free(tData);
  2386. delete(tData);
  2387. };
  2388. }
  2389. else
  2390. {
  2391. //free(tData);
  2392. delete(tData);
  2393. };
  2394. };
  2395. return true;
  2396. };
  2397. // char tB[128];
  2398. // sprintf(tB, "Target On %.3f %.3f %.3f", L.r, L.fi, L.tetta );
  2399. // LOG( tB );
  2400. // sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
  2401. // LOG( tB );
  2402. #ifdef DEBUG_EXTRA
  2403. LOG("Look at local spherical deg. coords!(final)");
  2404. #endif
  2405. // if( getWM() == CAM_WS_READY ){
  2406. // C3D_ORIENT_ONVIF LL;
  2407. // spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  2408. // return absoluteMove( TargetRefID, LL );
  2409. // };
  2410. // Camera is Busy
  2411. if (m_bShineOnTarget)
  2412. {
  2413. m_mIRProtector.lock();
  2414. if (! m_bIRIsOn)
  2415. {
  2416. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  2417. if (TK)
  2418. {
  2419. if (m_pProtocol->goPreset(TK))
  2420. {
  2421. m_bIRIsOn = true;
  2422. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2423. };
  2424. };
  2425. }
  2426. else
  2427. {
  2428. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2429. }
  2430. m_mIRProtector.unlock();
  2431. };
  2432. // targeting by Presets -> instant ROI
  2433. if (m_bNoAbsPositionning)
  2434. {
  2435. CAM_ROI * tROI = createCAM_ROI();
  2436. if (tROI != NULL)
  2437. {
  2438. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
  2439. if (tTarget != NULL)
  2440. {
  2441. memset(tTarget, 0, sizeof(CAM_TRACK_RECORD));
  2442. tTarget->evt_db_ID = TargetRefID;
  2443. tROI->targets.push_back(tTarget);
  2444. tROI->ts_ms = getMilliseconds();
  2445. spherical2onvif(L, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  2446. tROI->cam_position.fi = L.fi;
  2447. tROI->cam_position.tetta = L.tetta;
  2448. tROI->cam_position.r = L.r;
  2449. #ifndef NO_CAMERA_FUSION_ENGINE
  2450. m_mROIsProtector.lock();
  2451. m_vROIS.push_back(tROI);
  2452. m_mROIsProtector.unlock();
  2453. #endif
  2454. }
  2455. else
  2456. {
  2457. LOG_ERROR("No MEM 4 TARGTEG DATA");
  2458. utilizeROI(tROI);
  2459. };
  2460. }
  2461. else
  2462. {
  2463. LOG_ERROR("No MEM 4 ROI");
  2464. }
  2465. return true;
  2466. };
  2467. #ifndef NO_CAMERA_FUSION_ENGINE
  2468. return fusion_consumeData(TargetRefID, L);
  2469. #else
  2470. return true;
  2471. #endif
  2472. }
  2473. bool deviceNodeCamera::makeSnap(uint32_t TargetRefID)
  2474. {
  2475. CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
  2476. if (tTask)
  2477. {
  2478. memset(tTask, 0, sizeof(CAM_TASK));
  2479. tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
  2480. if (tTask->CMD)
  2481. {
  2482. tTask->CMD->CMD = PTZ_CAPTURE_ONLY;
  2483. tTask->movemet_needed = false;
  2484. tTask->source_evt_id = TargetRefID;
  2485. return pushCamTask(tTask);
  2486. }
  2487. else
  2488. {
  2489. free(tTask);
  2490. };
  2491. };
  2492. return false;
  2493. }
  2494. bool deviceNodeCamera::connectToStream(uint32_t id)
  2495. {
  2496. /*
  2497. if( id ){
  2498. argusKernelModule * tKM = NULL;
  2499. argusKernel * tKRNL = NULL;
  2500. argusModuleFactory * tMF = NULL;
  2501. if( m_pDBC == NULL ) {
  2502. LOG_ERROR("No Database Connector!");
  2503. return false;
  2504. };
  2505. tKRNL = argusKernel::getInstance();
  2506. if( tKRNL ) {
  2507. tMF = tKRNL->getModuleFactory();
  2508. if( tMF ) {
  2509. tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
  2510. } else {
  2511. LOG_ERROR("No ModuleFactory Instance!");
  2512. return false;
  2513. };
  2514. } else {
  2515. LOG_ERROR("No Kernel Instance!");
  2516. return false;
  2517. };
  2518. if( tKM ) {
  2519. // New Module
  2520. DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
  2521. if( tDATA ) {
  2522. m_sMediaSource.mediaStreamId = id;
  2523. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  2524. if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
  2525. m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
  2526. } else {
  2527. if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
  2528. m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource );
  2529. };
  2530. if( m_pSource != NULL ) {
  2531. char tMRL[1024];
  2532. #ifdef DEBUG
  2533. LOG("Source OK");
  2534. #endif
  2535. ((videoLIVE555Source*)m_pSource)->setWM( MS_MODE_STREAM_PROXY | MS_MODE_OVERLAYED_LOOPS | MS_MODE_DECODE_FRAMES );
  2536. int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
  2537. int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
  2538. int pix = -1;
  2539. bool in_16_9 = (((tDATA->width*100) / tDATA->height ) > 140 );
  2540. bool out_16_9 = (((tW*100) / tH ) > 140 );
  2541. updateOpticalParameters( tW, tH );
  2542. if( strlen( tDATA->c_type ) ){
  2543. };
  2544. //if( tW > 0 ){
  2545. // //m_pSource->setProportionalByWidth( tW );
  2546. // m_pSource->setSize( tW, tH );
  2547. //};
  2548. if( in_16_9 != out_16_9 ){
  2549. if( in_16_9 ){
  2550. tH = ((( tW * 1000 ) / 16 ) * 9 ) / 1000;
  2551. } else {
  2552. tW = ((( tH * 1000 ) / 3 ) * 4 ) / 1000;
  2553. };
  2554. };
  2555. if (strncmp(tDATA->mrl_proto, "v4l2", 4) == 0) {
  2556. sprintf( tMRL, tDATA->mrl );
  2557. } else {
  2558. DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
  2559. if( tCAM ) {
  2560. sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
  2561. free( tCAM );
  2562. } else {
  2563. LOG_ERROR("Error Getting CAM Data!");
  2564. delete( m_pSource );
  2565. m_pSource = NULL;
  2566. return false;
  2567. };
  2568. };
  2569. LOG( tMRL );
  2570. if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
  2571. m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
  2572. if ( !m_bSourceConnected ) {
  2573. //delete( m_pSource );
  2574. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  2575. delete((videoAVLIBSource*)m_pSource);
  2576. } else {
  2577. delete((videoLIVE555Source*)m_pSource);
  2578. };
  2579. m_pSource = NULL;
  2580. } else {
  2581. m_nActiveStreamID = id;
  2582. #ifdef DEBUG
  2583. LOG("Source is Connected to Output.");
  2584. #endif
  2585. };
  2586. } else {
  2587. LOG_ERROR("Can not Open Video Source!");
  2588. //delete( m_pSource );
  2589. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  2590. delete((videoAVLIBSource*)m_pSource);
  2591. } else {
  2592. delete((videoLIVE555Source*)m_pSource);
  2593. };
  2594. m_pSource = NULL;
  2595. };
  2596. } else {
  2597. LOG_ERROR("Video Source Stream Failure!");
  2598. };
  2599. free( tDATA );
  2600. };
  2601. }
  2602. #ifdef DEBUG
  2603. else LOG("No Video Module!")
  2604. #endif
  2605. ;
  2606. };
  2607. LOG("Connect Finished!");
  2608. return m_bSourceConnected;
  2609. */
  2610. if ( id ) return true;
  2611. return true;
  2612. }
  2613. bool deviceNodeCamera::disconnectFromStream(void)
  2614. {
  2615. /*if( m_bSourceConnected ) {
  2616. if( m_pSource ){
  2617. delete( m_pSource );
  2618. m_pSource = NULL;
  2619. };
  2620. m_bSourceConnected = false;
  2621. };
  2622. return !m_bSourceConnected;
  2623. */
  2624. return true;
  2625. }
  2626. bool deviceNodeCamera::validateStream(void)
  2627. {
  2628. /*
  2629. if( m_bSourceConnected ) {
  2630. if( m_pSource ) {
  2631. if( m_pSource->isAttached() ){
  2632. if( m_pSource->getStatus() < MS_STOPED ) return true;
  2633. #ifdef DEBUG
  2634. LOG("Source is Finished!");
  2635. #endif
  2636. };
  2637. #ifdef DEBUG
  2638. LOG("Source is Disconnected!");
  2639. #endif
  2640. } else LOG_ERROR("No Source Object! Set Disconnected!");
  2641. disconnectFromStream();
  2642. };
  2643. return false;
  2644. */
  2645. return true;
  2646. }
  2647. bool deviceNodeCamera::validate()
  2648. {
  2649. if (m_pDBC == NULL)
  2650. {
  2651. return false;
  2652. }
  2653. DBC_CAM_DATA * tDATA = m_pDBC->getCamData(m_sCamData.id);
  2654. if (tDATA == NULL)
  2655. {
  2656. return false;
  2657. }
  2658. if (memcmp(tDATA, &m_sCamData, sizeof(DBC_CAM_DATA)) != 0)
  2659. {
  2660. // Settings Changed
  2661. // memcpy(&m_sCamData, tDATA, sizeof(DBC_CAM_DATA) );
  2662. free(tDATA);
  2663. return false;
  2664. };
  2665. free(tDATA);
  2666. if (! validateStream())
  2667. {
  2668. return false;
  2669. }
  2670. return deviceNode::validate();
  2671. }
  2672. bool deviceNodeCamera::load_presets(void)
  2673. {
  2674. bool bHaveIROFF = false;
  2675. bool bHaveIRON = false;
  2676. bool bHaveIRAUTO = false;
  2677. // Request PRESETS FROM CAMERA?! for some PTZ cameras without presets inpossible to
  2678. // operate by presets
  2679. if (m_pProtocol->getCameraPresets())
  2680. {
  2681. LOG("Camera Presets Loadded");
  2682. }
  2683. else
  2684. {
  2685. LOG_ERROR("Error while loadding Camera Presets!");
  2686. }
  2687. if (m_pDBC == NULL)
  2688. {
  2689. return false;
  2690. }
  2691. DBC_PRESETS_INFO * tData = m_pDBC->getCamPresetInfo(m_sCamData.id);
  2692. if (tData)
  2693. {
  2694. //memcpy(&m_sCamPresets, tData, sizeof(DBC_PRESETS_INFO));
  2695. m_sCamPresets.maxCount = tData->maxCount;
  2696. m_sCamPresets.gRows = tData->gRows;
  2697. m_sCamPresets.gCols = tData->gCols;
  2698. m_sCamPresets.presets.clear();
  2699. #ifdef DEBUG
  2700. char tB[128];
  2701. LOG("Loading Presets!");
  2702. sprintf(tB, "Cam Presets Info: CNT: %d Cols: %d Rows: %d ", m_sCamPresets.maxCount, m_sCamPresets.gCols, m_sCamPresets.gRows);
  2703. LOG(tB);
  2704. #endif
  2705. DBC_INT_LIST * tList = m_pDBC->listCamPresets(m_sCamData.id);
  2706. if (tList)
  2707. {
  2708. for (DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++)
  2709. {
  2710. CAM_PRESET * tData = m_pDBC->getCamPreset(*idx);
  2711. if (tData)
  2712. {
  2713. m_sCamPresets.presets.push_back(tData);
  2714. bHaveIRON = (tData->role == ARGUS_PRESET_TYPE_IR_ON) ? true : bHaveIRON;
  2715. bHaveIROFF = (tData->role == ARGUS_PRESET_TYPE_IR_OFF) ? true : bHaveIROFF;
  2716. bHaveIRAUTO = (tData->role == ARGUS_PRESET_TYPE_IR_AUTO) ? true : bHaveIRAUTO;
  2717. };
  2718. };
  2719. delete(tList);
  2720. };
  2721. if (m_sCamData.eco_ir)
  2722. {
  2723. m_bShineOnTarget = (bHaveIROFF && bHaveIRAUTO);
  2724. }
  2725. else
  2726. {
  2727. m_bShineOnTarget = false;
  2728. }
  2729. return true;
  2730. #ifdef DEBUG
  2731. }
  2732. else
  2733. {
  2734. LOG("No Camera Presets!");
  2735. #endif
  2736. };
  2737. return false;
  2738. }
  2739. void deviceNodeCamera::translateROI2PRESET(float P, float T, float Z, uint8_t & col, uint8_t & row)
  2740. {
  2741. //char tB[128];
  2742. if ( T ) Z = Z;
  2743. row = (uint8_t)(Z * ((float)m_sCamPresets.gRows));
  2744. if (P < 0.5)
  2745. {
  2746. P = P + 1.5f;
  2747. }
  2748. else
  2749. {
  2750. P = P - 0.5f;
  2751. };
  2752. col = (uint8_t) (P * ((float) (m_sCamPresets.gCols * (1 << row)) / 2.0f));
  2753. row++;
  2754. }
  2755. CSTR deviceNodeCamera::getPresetToken(uint8_t CCOL, uint8_t CROW)
  2756. {
  2757. if (m_sCamPresets.presets.size() > 0)
  2758. {
  2759. for (V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++)
  2760. {
  2761. if ((*idx)->role == ARGUS_PRESET_TYPE_POSITION)
  2762. {
  2763. if (((*idx)->row == CROW) && ((*idx)->col == CCOL))
  2764. {
  2765. return (CSTR) (*idx)->token;
  2766. }
  2767. }
  2768. }
  2769. }
  2770. return NULL;
  2771. }
  2772. CSTR deviceNodeCamera::getPresetToken(uint8_t specialRole)
  2773. {
  2774. if (m_sCamPresets.presets.size() > 0)
  2775. {
  2776. for (V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++)
  2777. {
  2778. if ((*idx)->role == specialRole)
  2779. {
  2780. return (CSTR) (*idx)->token;
  2781. }
  2782. }
  2783. }
  2784. return NULL;
  2785. }
  2786. #undef LOG
  2787. #undef LOG_ERROR
  2788. // #undef DEBUG_EXTRA