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.

341 lines
10 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
  1. #include "basicCameraPTZ.h"
  2. // Constructor implementation
  3. basicCameraPTZ::basicCameraPTZ(config_setting_t * Settings) :
  4. basicCamera(Settings)
  5. {
  6. m_eCaps = (objectCaps) (m_eCaps | OC_EVENT_HANDLER | OC_PAN_CONTROLL | OC_TILT_CONTROLL | OC_ZOOM_CONTROLL);
  7. m_fPanShift = 0;
  8. m_fTiltShift = 0;
  9. m_bCtrlStage = 0;
  10. m_pProtocol = NULL;
  11. m_bDirectSpeedControl = false;
  12. m_bEventTrackingEnabled = false;
  13. // m_qCommandPipe clear
  14. }
  15. // Destructor implementation
  16. basicCameraPTZ::~basicCameraPTZ()
  17. {
  18. updateSettings();
  19. }
  20. bool basicCameraPTZ::create(void)
  21. {
  22. config_setting_t * pSetting;
  23. if (m_pSettings == NULL)
  24. {
  25. return false;
  26. }
  27. if (! basicCamera::create())
  28. {
  29. return false;
  30. }
  31. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PROTO_TYPE);
  32. if (pSetting == NULL)
  33. {
  34. return false;
  35. }
  36. m_sSourceInfo.protocolId = config_setting_get_int(pSetting);
  37. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_TOTTAL);
  38. if (pSetting == NULL)
  39. {
  40. return false;
  41. }
  42. m_sSourceInfo.fPanTotalDeg = config_setting_get_float(pSetting);
  43. m_sSourceInfo.fPanTotalRad = m_sSourceInfo.fPanTotalDeg * 0.01745329251994329576923690768489f;
  44. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_MIN);
  45. if (pSetting == NULL)
  46. {
  47. return false;
  48. }
  49. m_sSourceInfo.fPanMin = config_setting_get_float(pSetting);
  50. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_MAX);
  51. if (pSetting == NULL)
  52. {
  53. return false;
  54. }
  55. m_sSourceInfo.fPanMax = config_setting_get_float(pSetting);
  56. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_SPD_MIN);
  57. if (pSetting == NULL)
  58. {
  59. return false;
  60. }
  61. m_sSourceInfo.fPanSpeedMin = config_setting_get_float(pSetting);
  62. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_SPD_MAX);
  63. if (pSetting == NULL)
  64. {
  65. return false;
  66. }
  67. m_sSourceInfo.fPanSpeedMax = config_setting_get_float(pSetting);
  68. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_SPD_DYNAMIC);
  69. if (pSetting == NULL)
  70. {
  71. return false;
  72. }
  73. m_sSourceInfo.bPanSpeedDynamic = config_setting_get_bool(pSetting);
  74. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_PAN_REVERSED);
  75. if (pSetting == NULL)
  76. {
  77. return false;
  78. }
  79. m_sSourceInfo.bPanReverse = config_setting_get_bool(pSetting);
  80. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_TOTTAL);
  81. if (pSetting == NULL)
  82. {
  83. return false;
  84. }
  85. m_sSourceInfo.fTiltTotalDeg = config_setting_get_float(pSetting);
  86. m_sSourceInfo.fTiltTotalRad = m_sSourceInfo.fPanTotalDeg * 0.01745329251994329576923690768489f;
  87. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_MIN);
  88. if (pSetting == NULL)
  89. {
  90. return false;
  91. }
  92. m_sSourceInfo.fTiltMin = config_setting_get_float(pSetting);
  93. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_MAX);
  94. if (pSetting == NULL)
  95. {
  96. return false;
  97. }
  98. m_sSourceInfo.fTiltMax = config_setting_get_float(pSetting);
  99. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_SPD_MIN);
  100. if (pSetting == NULL)
  101. {
  102. return false;
  103. }
  104. m_sSourceInfo.fTiltSpeedMin = config_setting_get_float(pSetting);
  105. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_SPD_MAX);
  106. if (pSetting == NULL)
  107. {
  108. return false;
  109. }
  110. m_sSourceInfo.fTiltSpeedMax = config_setting_get_float(pSetting);
  111. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_SPD_DYNAMIC);
  112. if (pSetting == NULL)
  113. {
  114. return false;
  115. }
  116. m_sSourceInfo.bTiltSpeedDynamic = config_setting_get_bool(pSetting);
  117. pSetting = config_setting_get_member(m_pSettings, BPTZCI_TAG_TILT_REVERSED);
  118. if (pSetting == NULL)
  119. {
  120. return false;
  121. }
  122. m_sSourceInfo.bTiltReverse = config_setting_get_bool(pSetting);
  123. return basicThread::init();
  124. }
  125. bool basicCameraPTZ::create(SOURCE_INFO * SI)
  126. {
  127. config_setting_t * pSetting;
  128. int tiVal;
  129. float tfVal;
  130. if (m_pSettings == NULL)
  131. {
  132. return false;
  133. }
  134. if (SI == NULL)
  135. {
  136. return false;
  137. }
  138. if (! basicCamera::create(SI))
  139. {
  140. return false;
  141. }
  142. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PROTO_TYPE, CONFIG_TYPE_INT);
  143. if (pSetting == NULL)
  144. {
  145. return false;
  146. }
  147. config_setting_set_int(pSetting, m_sSourceInfo.protocolId);
  148. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_SPD_DYNAMIC, CONFIG_TYPE_BOOL);
  149. if (pSetting == NULL)
  150. {
  151. return false;
  152. }
  153. config_setting_set_int(pSetting, m_sSourceInfo.bPanSpeedDynamic);
  154. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_TOTTAL, CONFIG_TYPE_FLOAT);
  155. if (pSetting == NULL)
  156. {
  157. return false;
  158. }
  159. m_sSourceInfo.fPanTotalDeg = m_sSourceInfo.fPanMax - m_sSourceInfo.fPanMin;
  160. m_sSourceInfo.fPanTotalRad = m_sSourceInfo.fPanTotalDeg * 0.01745329251994329576923690768489f;
  161. config_setting_set_float(pSetting, m_sSourceInfo.fPanTotalDeg);
  162. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_MIN, CONFIG_TYPE_FLOAT);
  163. if (pSetting == NULL)
  164. {
  165. return false;
  166. }
  167. config_setting_set_float(pSetting, m_sSourceInfo.fPanMin);
  168. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_MAX, CONFIG_TYPE_FLOAT);
  169. if (pSetting == NULL)
  170. {
  171. return false;
  172. }
  173. config_setting_set_float(pSetting, m_sSourceInfo.fPanMax);
  174. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_SPD_MIN, CONFIG_TYPE_FLOAT);
  175. if (pSetting == NULL)
  176. {
  177. return false;
  178. }
  179. config_setting_set_float(pSetting, m_sSourceInfo.fPanSpeedMin);
  180. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_SPD_MAX, CONFIG_TYPE_FLOAT);
  181. if (pSetting == NULL)
  182. {
  183. return false;
  184. }
  185. config_setting_set_float(pSetting, m_sSourceInfo.fPanSpeedMax);
  186. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_PAN_REVERSED, CONFIG_TYPE_BOOL);
  187. if (pSetting == NULL)
  188. {
  189. return false;
  190. }
  191. config_setting_set_bool(pSetting, m_sSourceInfo.bPanReverse);
  192. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_MIN, CONFIG_TYPE_FLOAT);
  193. if (pSetting == NULL)
  194. {
  195. return false;
  196. }
  197. config_setting_set_float(pSetting, m_sSourceInfo.fTiltMin);
  198. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_MAX, CONFIG_TYPE_FLOAT);
  199. if (pSetting == NULL)
  200. {
  201. return false;
  202. }
  203. config_setting_set_float(pSetting, m_sSourceInfo.fTiltMax);
  204. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_TOTTAL, CONFIG_TYPE_FLOAT);
  205. if (pSetting == NULL)
  206. {
  207. return false;
  208. }
  209. m_sSourceInfo.fTiltTotalDeg = m_sSourceInfo.fTiltMax - m_sSourceInfo.fTiltMin;
  210. m_sSourceInfo.fTiltTotalRad = m_sSourceInfo.fTiltTotalDeg * 0.01745329251994329576923690768489f;
  211. config_setting_set_float(pSetting, m_sSourceInfo.fTiltTotalDeg);
  212. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_SPD_MIN, CONFIG_TYPE_FLOAT);
  213. if (pSetting == NULL)
  214. {
  215. return false;
  216. }
  217. config_setting_set_float(pSetting, m_sSourceInfo.fTiltSpeedMin);
  218. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_SPD_MAX, CONFIG_TYPE_FLOAT);
  219. if (pSetting == NULL)
  220. {
  221. return false;
  222. }
  223. config_setting_set_float(pSetting, m_sSourceInfo.fTiltSpeedMax);
  224. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_SPD_DYNAMIC, CONFIG_TYPE_BOOL);
  225. if (pSetting == NULL)
  226. {
  227. return false;
  228. }
  229. config_setting_set_bool(pSetting, m_sSourceInfo.bTiltSpeedDynamic);
  230. pSetting = config_setting_add(m_pSettings, BPTZCI_TAG_TILT_REVERSED, CONFIG_TYPE_BOOL);
  231. if (pSetting == NULL)
  232. {
  233. return false;
  234. }
  235. config_setting_set_bool(pSetting, m_sSourceInfo.bTiltReverse);
  236. basicSettingsProvider::getInstance()->compromise();
  237. return true;
  238. }
  239. void basicCameraPTZ::dispatchEvent(EVENT_CONTAINER * Evt)
  240. {
  241. basicCamera::dispatchEvent(Evt);
  242. }
  243. void basicCameraPTZ::updateSettings(void)
  244. {
  245. if (! m_pSettings)
  246. {
  247. return;
  248. }
  249. basicCamera::updateSettings();
  250. config_setting_t * pSetting;
  251. int tInt;
  252. double tFloat;
  253. CSTR tBuff;
  254. /*
  255. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LAT, &tFloat)){
  256. if (tFloat != getLat()){
  257. tFloat = getLat();
  258. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LAT);
  259. config_setting_set_float(pSetting, tFloat);
  260. basicSettingsProvider::getInstance()->compromise();
  261. };
  262. };
  263. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LON, &tFloat)){
  264. if (tFloat != getLon()){
  265. tFloat = getLon();
  266. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LON);
  267. config_setting_set_float(pSetting, tFloat);
  268. basicSettingsProvider::getInstance()->compromise();
  269. };
  270. };
  271. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ALT, &tFloat)){
  272. if (tFloat != getAlt()){
  273. tFloat = getAlt();
  274. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ALT);
  275. config_setting_set_float(pSetting, tFloat);
  276. basicSettingsProvider::getInstance()->compromise();
  277. };
  278. };
  279. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_YAW, &tFloat)){
  280. if (tFloat != getRotZ_deg()){
  281. tFloat = getRotZ_deg();
  282. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_YAW);
  283. config_setting_set_float(pSetting, tFloat);
  284. basicSettingsProvider::getInstance()->compromise();
  285. };
  286. };
  287. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ROLL, &tFloat)){
  288. if (tFloat != getRotY_deg()){
  289. tFloat = getRotY_deg();
  290. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ROLL);
  291. config_setting_set_float(pSetting, tFloat);
  292. basicSettingsProvider::getInstance()->compromise();
  293. };
  294. };
  295. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_PITCH, &tFloat)){
  296. if (tFloat != getRotX_deg()){
  297. tFloat = getRotX_deg();
  298. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_PITCH);
  299. config_setting_set_float(pSetting, tFloat);
  300. basicSettingsProvider::getInstance()->compromise();
  301. };
  302. };
  303. if (config_setting_lookup_string(m_pSettings, LGS_SET_ADDRESS, (const char**)&tBuff)){
  304. if (strcmp(m_pHost, tBuff) != 0){
  305. pSetting = config_setting_lookup(m_pSettings, LGS_SET_ADDRESS);
  306. config_setting_set_string(pSetting, m_pHost);
  307. basicSettingsProvider::getInstance()->compromise();
  308. };
  309. };
  310. if (config_setting_lookup_int(m_pSettings, LGS_SET_PORT, &tInt)){
  311. if (m_nPort != tInt){
  312. pSetting = config_setting_lookup(m_pSettings, LGS_SET_PORT);
  313. config_setting_set_int(pSetting, m_nPort);
  314. basicSettingsProvider::getInstance()->compromise();
  315. };
  316. };
  317. if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate();
  318. */
  319. }