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.

199 lines
3.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectCamera_VISCA_PTZ.h"
  2. #define LOG(X) m_pLog->Log("objectCamera_VISCA_PTZ", this, X)
  3. #define LOG_ERROR(X) m_pLog->Log("objectCamera_VISCA_PTZ", this, _LOG_ERROR, X)
  4. objectCamera_VISCA_PTZ::objectCamera_VISCA_PTZ(config_setting_t * Settings) :
  5. basicCameraPTZ(Settings)
  6. {
  7. m_pLog = basicLogCollection::getInstance();
  8. m_pProtocol = NULL;
  9. m_pTransport = NULL;
  10. m_sSourcePort = -1;
  11. m_eControllProtocolType = PTZ_PROTO_VISCA;
  12. }
  13. objectCamera_VISCA_PTZ::~objectCamera_VISCA_PTZ()
  14. {
  15. // Delete Video Source
  16. if (m_pVideoSource != NULL)
  17. {
  18. delete((videoAVLIBSource *) m_pVideoSource);
  19. };
  20. if (m_pProtocol != NULL)
  21. {
  22. delete(m_pProtocol);
  23. };
  24. if (m_pTransport != NULL)
  25. {
  26. delete(m_pTransport);
  27. };
  28. }
  29. bool objectCamera_VISCA_PTZ::create(void)
  30. {
  31. config_setting_t * pSetting;
  32. if (m_pSettings == NULL)
  33. {
  34. return false;
  35. }
  36. /* Load Srom Settings */
  37. if (! basicCameraPTZ::create())
  38. {
  39. return false;
  40. }
  41. pSetting = config_setting_get_member(m_pSettings, "COM_PORT");
  42. if (pSetting == NULL)
  43. {
  44. return false;
  45. }
  46. m_sSourcePort = config_setting_get_int(pSetting);
  47. if (m_sSourcePort < 0)
  48. {
  49. return false;
  50. }
  51. char cPortStr[8];
  52. sprintf(cPortStr, "com%d", m_sSourcePort);
  53. m_pTransport = new serialPort(cPortStr, 9600);
  54. if (m_pTransport != NULL)
  55. {
  56. m_pProtocol = new protocolPTZ_VISCA(m_pTransport);
  57. m_pProtocol->init();
  58. };
  59. // init video
  60. videoAVLIBSource * tSource;
  61. tSource = new videoAVLIBSource();
  62. if (tSource->open((CSTR) m_sCameraInfo.m_pSourcePath, false, 25, m_sCameraInfo.m_iSourcePort, m_sCameraInfo.m_iWidth, m_sCameraInfo.m_iHeight))
  63. {
  64. // tNode->setTimeLapse(3000);
  65. tSource->attachDestination(m_pVideoNode);
  66. tSource->setStreaming(true);
  67. m_pVideoSource = (basicMediaSource *) tSource;
  68. }
  69. else
  70. {
  71. delete tSource;
  72. return false;
  73. };
  74. return true;
  75. }
  76. /* ���� ������� 500 .... 10.
  77. 7:30 mispar tik 123760118
  78. */
  79. bool objectCamera_VISCA_PTZ::create(mediaSourceInfo * SI)
  80. {
  81. config_setting_t * pSetting;
  82. if (m_pSettings == NULL)
  83. {
  84. return false;
  85. }
  86. if (SI == NULL)
  87. {
  88. return false;
  89. }
  90. if (! basicCameraPTZ::create(SI))
  91. {
  92. return false;
  93. }
  94. pSetting = config_setting_get_member(m_pSettings, "COM_PORT");
  95. m_sSourcePort = SI->comTransportType;
  96. if (pSetting == NULL)
  97. {
  98. pSetting = config_setting_add(m_pSettings, "COM_PORT", CONFIG_TYPE_INT);
  99. };
  100. config_setting_set_int(pSetting, m_sSourcePort);
  101. basicSettingsProvider::getInstance()->compromise();
  102. return create();
  103. }
  104. void objectCamera_VISCA_PTZ::dispatch(basicEvent * Evt)
  105. {
  106. if (Evt->m_eClass == EVT_CLASS_SENSOR)
  107. {
  108. switch (Evt->m_eType)
  109. {
  110. case EVT_ALARM:
  111. // Basic Camera Reaction
  112. break;
  113. default: break;
  114. };
  115. }
  116. else if (Evt->m_eClass == EVT_CLASS_IMAGE)
  117. {
  118. switch (Evt->m_eType)
  119. {
  120. case EVT_COMMAND:
  121. basicCameraCommand * pData;
  122. pData = (basicCameraCommand *) Evt->m_pEvtData;
  123. // Basic Camera Commands
  124. switch (pData->m_cCode)
  125. {
  126. case CMD_CAMERA_INIT: m_pProtocol->init(); break;
  127. case CMD_CAMERA_SET_PTZ:
  128. // m_pProtocol->goAbsolute( cP, cT, cZ );
  129. break;
  130. default: break;
  131. };
  132. break;
  133. default: break;
  134. };
  135. };
  136. }
  137. void objectCamera_VISCA_PTZ::cmdBeginPanLeft(void)
  138. {
  139. m_pProtocol->goLeft();
  140. }
  141. void objectCamera_VISCA_PTZ::cmdBeginPanRight(void)
  142. {
  143. m_pProtocol->goRight();
  144. }
  145. void objectCamera_VISCA_PTZ::cmdEndManualPan(void)
  146. {
  147. m_pProtocol->goStop();
  148. }
  149. void objectCamera_VISCA_PTZ::cmdBeginTiltUp(void)
  150. {
  151. m_pProtocol->goUp();
  152. }
  153. void objectCamera_VISCA_PTZ::cmdBeginTiltDown(void)
  154. {
  155. m_pProtocol->goDown();
  156. }
  157. void objectCamera_VISCA_PTZ::cmdEndManualTilt(void)
  158. {
  159. m_pProtocol->goStop();
  160. }
  161. void objectCamera_VISCA_PTZ::cmdBeginZoomWide(void)
  162. {
  163. m_pProtocol->startZoomWide();
  164. }
  165. void objectCamera_VISCA_PTZ::cmdBeginZoomTele(void)
  166. {
  167. m_pProtocol->startZoomTele();
  168. }
  169. void objectCamera_VISCA_PTZ::cmdEndManualZoom(void)
  170. {
  171. m_pProtocol->stopZoom();
  172. }
  173. #undef LOG
  174. #undef LOG_ERROR