parameters.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. /********************************* (C) РОТЕК ***********************************
  2. * @module parameters
  3. * @file parameters.c
  4. * @version 1.0.0
  5. * @date XX.XX.XXXX
  6. * $brief Template
  7. *******************************************************************************
  8. * @history Version Author Comment
  9. * XX.XX.XXXX 1.0.0 Telenkov D.A. First release.
  10. *******************************************************************************
  11. */
  12. #include "stm32f4xx.h"
  13. #include "parameters.h"
  14. #include "settings_api.h"
  15. #include "rtc.h"
  16. #ifndef BT6702_SERVICE
  17. #include "snmp_api.h"
  18. #include "snmp.h"
  19. #include "megatec.h"
  20. #if defined HARDWARE_BT6706 || HARDWARE_BT6708
  21. #include "telnet_server.h"
  22. #endif
  23. #endif
  24. #include "sntp.h"
  25. #include "lwip/snmp.h"
  26. #include "lwip/sys.h"
  27. #include "common_config.h"
  28. //#include "d_inouts.h"
  29. #include "gpio.h"
  30. #include "round.h"
  31. //#if defined HARDWARE_BT6702
  32. #ifdef PRINTF_STDLIB
  33. #include <stdio.h>
  34. #endif
  35. #ifdef PRINTF_CUSTOM
  36. #include "tinystdio.h"
  37. #endif
  38. #include <string.h>
  39. #include <stdlib.h>
  40. #include <math.h>
  41. //#endif
  42. /**
  43. * @brief Структура для хранения состояний дискретных входов
  44. */
  45. //extern GPIO_INPUTS_t sGpioInputs;
  46. /**
  47. * @brief Общая структура настроек
  48. */
  49. extern SETTINGS_t sSettings;
  50. /**
  51. * @brief Структура для хранения временных сетевых настроек
  52. */
  53. extern WEB_PARAMS_t sTempWebParams;
  54. /**
  55. * @brief Флаг подтверждения новых сетевых параметров пользователем
  56. */
  57. extern bool fConfirmWebParams;
  58. #ifndef BT6702_SERVICE
  59. // ************************************************************************** //
  60. // Параметры UPS
  61. /**
  62. * @brief
  63. */
  64. void GetInputFreqStr(char *str, uint8_t *len)
  65. {
  66. sprintf(str, "%0.1f", UPS.Freq_in);
  67. *len = strlen(str);
  68. }
  69. /**
  70. * @brief
  71. */
  72. void GetOutputFreqStr(char *str, uint8_t *len)
  73. {
  74. sprintf(str, "%0.1f", UPS.Freq_in);
  75. *len = strlen(str);
  76. }
  77. /**
  78. * @brief
  79. */
  80. void GetInputVoltageStr(char *str, uint8_t *len)
  81. {
  82. sprintf(str, "%0.1f", UPS.VAC_in);
  83. *len = strlen(str);
  84. }
  85. /**
  86. * @brief
  87. */
  88. void GetOutputVoltageStr(char *str, uint8_t *len)
  89. {
  90. sprintf(str, "%0.1f", UPS.VAC_out);
  91. *len = strlen(str);
  92. }
  93. /**
  94. * @brief
  95. */
  96. void GetPowerStr(char *str, uint8_t *len)
  97. {
  98. sprintf(str, "%d", UPS.Load);
  99. *len = strlen(str);
  100. }
  101. /**
  102. * @brief
  103. */
  104. void GetBatCapacityStr(char *str, uint8_t *len)
  105. {
  106. sprintf(str, "%d", UPS.SOC);
  107. *len = strlen(str);
  108. }
  109. /**
  110. * @brief
  111. */
  112. void GetRuntimeStr(char *str, uint8_t *len)
  113. {
  114. sprintf(str, "%d", UPS.work_time);
  115. *len = strlen(str);
  116. }
  117. /**
  118. * @brief
  119. */
  120. void GetInternalTempStr(char *str, uint8_t *len)
  121. {
  122. sprintf(str, "%0.1f", UPS.Temp);
  123. *len = strlen(str);
  124. }
  125. /**
  126. * @brief
  127. */
  128. void GetAlarmMonitorStr(char *str, uint8_t *len)
  129. {
  130. sprintf(str, "%d", UPS.Alarm);
  131. *len = strlen(str);
  132. }
  133. /**
  134. * @brief
  135. */
  136. void GetConnectMonitorStr(char *str, uint8_t *len)
  137. {
  138. if(UPS.Present)
  139. strcpy(str, "0");
  140. else
  141. strcpy(str, "1");
  142. *len = strlen(str);
  143. }
  144. // ************************************************************************** //
  145. // Alarms
  146. /**
  147. * @brief Индикация аварийных ситуаций
  148. */
  149. void GetAlarmStr(char *str, uint8_t *len)
  150. {
  151. sprintf(str, "%d", UPS.Status);
  152. *len = strlen(str);
  153. }
  154. /**
  155. * @brief Индикация аварийных ситуаций
  156. */
  157. void GetUPSAlarmStr(char *str, uint8_t *len)
  158. {
  159. if(((UPS.Status>>7)&0x01) || ((UPS.Status>>4)&0x01) || (UPS.Alarm & 0x01))
  160. strcpy(str, "Авария");
  161. else if(!((UPS.Status>>7)&0x01) && !((UPS.Status>>4)&0x01) && !(UPS.Alarm & 0x01))
  162. strcpy(str, "Норма");
  163. else if(((UPS.Status>>1)&0x01))
  164. strcat(str, "/Отключение нагрузки");
  165. *len = strlen(str);
  166. }
  167. /**
  168. * @brief Индикация аварийных ситуаций
  169. */
  170. void GetAKBAlarmStr(char *str, uint8_t *len)
  171. {
  172. if(((UPS.Status>>6)&0x01) || ((UPS.Alarm>>1) & 0x01))
  173. strcpy(str, "Авария");
  174. else if(!((UPS.Status>>6)&0x01) && !((UPS.Alarm>>1) & 0x01))
  175. strcpy(str, "Норма");
  176. else if(((UPS.Status>>2)&0x01))
  177. strcat(str, "/Тестирование");
  178. *len = strlen(str);
  179. }
  180. /**
  181. * @brief Индикация аварийных ситуаций
  182. */
  183. void GetConnectUPSAlarmStr(char *str, uint8_t *len)
  184. {
  185. if(((UPS.Alarm>>2) & 0x01))
  186. strcpy(str, "Авария");
  187. else if(!((UPS.Alarm>>2) & 0x01))
  188. strcpy(str, "Норма");
  189. *len = strlen(str);
  190. }
  191. /**
  192. * @brief Индикация аварийных ситуаций
  193. */
  194. void GetUPSModeStr(char *str, uint8_t *len)
  195. {
  196. if((UPS.Status>>5)&0x01)
  197. sprintf(str, "Bypass");
  198. else
  199. sprintf(str, "Boost or Buck");
  200. *len = strlen(str);
  201. }
  202. #endif
  203. // ************************************************************************** //
  204. // Параметры даты и времени
  205. /**
  206. * @brief Дата (Ready for PRS!)
  207. */
  208. void GetDateStr(char *str, uint8_t *len)
  209. {
  210. TM_RTC_t data;
  211. uint16_t sys_year ;
  212. TM_RTC_GetDateTime(&data, TM_RTC_Format_BIN);
  213. sys_year = 2000 + data.year;
  214. sprintf(str, "%04i-%02i-%02i", sys_year, data.month, data.date);
  215. *len = strlen(str);
  216. }
  217. /**
  218. * @brief Время (Ready for PRS!)
  219. */
  220. void GetTimeStr(char *str, uint8_t *len)
  221. {
  222. TM_RTC_t data;
  223. TM_RTC_GetDateTime(&data, TM_RTC_Format_BIN);
  224. sprintf(str, "%02i:%02i", data.hours, data.minutes);
  225. *len = strlen(str);
  226. }
  227. /**
  228. * @brief Время (Ready for PRS!)
  229. */
  230. void GetUnixTimeStr(char *str, uint8_t *len)
  231. {
  232. TM_RTC_t data;
  233. TM_RTC_GetDateTime(&data, TM_RTC_Format_BIN);
  234. sprintf(str, "%d", data.unix);
  235. *len = strlen(str);
  236. }
  237. // ************************************************************************** //
  238. // Параметры SNTP
  239. /**
  240. * @brief Состояние SNTP (Ready for PRS!)
  241. */
  242. void GetSntpStateStr(char *str, uint8_t *len)
  243. {
  244. if (sSettings.sSNTP.sntpEnable)
  245. {
  246. sprintf(str, "%s", "1"); //авто
  247. *len = strlen(str);
  248. }
  249. else
  250. {
  251. sprintf(str, "%s", "0"); //ручной
  252. *len = strlen(str);
  253. }
  254. }
  255. /**
  256. * @brief Состояние SNTP (Ready for PRS!)
  257. */
  258. void GetSntpStateStrRU(char *str, uint8_t *len)
  259. {
  260. if (sSettings.sSNTP.sntpEnable)
  261. {
  262. sprintf(str, "%s", "авто"); //авто
  263. *len = strlen(str);
  264. }
  265. else
  266. {
  267. sprintf(str, "%s", "ручной"); //ручной
  268. *len = strlen(str);
  269. }
  270. }
  271. /**
  272. * @brief IP адрес SNTP сервера (Ready for PRS!)
  273. */
  274. void GetSntpServerIpStr(char *str, uint8_t *len)
  275. {
  276. sprintf(str, "%s", sSettings.sSNTP.ip);
  277. *len = strlen(str);
  278. }
  279. /**
  280. * @brief Часовой пояс контроллера (Ready for PRS!)
  281. */
  282. void GetSntpTimeZoneStr(char *str, uint8_t *len)
  283. {
  284. sprintf(str, "%0.1f", sSettings.sSNTP.timeZone);
  285. *len = strlen(str);
  286. }
  287. /**
  288. * @brief Дата последней синхронизации SNTP (Ready for PRS!)
  289. */
  290. void GetSntpLastDataStr(char *str, uint8_t *len)
  291. {
  292. sprintf(str, "%s", sSettings.sSNTP.data);
  293. *len = strlen(str);
  294. }
  295. #ifndef HARDWARE_BT6708
  296. // ************************************************************************** //
  297. // Параметры реле/сухих контактов
  298. /**
  299. * @brief Тип действий при срабатывание сухих контактов
  300. */
  301. void GetDINTypeActStr(char *str, uint8_t *len, uint8_t num)
  302. {
  303. sprintf(str, "%d", sSettings.sInOuts.din_type_act[num]);
  304. *len = strlen(str);
  305. }
  306. /**
  307. * @brief Состояние сухого контакта
  308. */
  309. void GetDINStatusStr(char *str, uint8_t *len, uint8_t num)
  310. {
  311. sprintf(str, "%d", (get_state_din_outs(DIN1+num)^1));
  312. *len = strlen(str);
  313. }
  314. /**
  315. * @brief Состояние сухого контакта
  316. */
  317. void GetDIN0StatusStr(char *str, uint8_t *len)
  318. {
  319. sprintf(str, "%d", (get_state_din_outs(DIN1)^1));
  320. *len = strlen(str);
  321. }
  322. /**
  323. * @brief Состояние сухого контакта
  324. */
  325. void GetDIN0StatusStrRU(char *str, uint8_t *len)
  326. {
  327. if(get_state_din_outs(DIN1)^1)
  328. sprintf(str, "Разомкнут" );
  329. else
  330. sprintf(str, "Замкнут" );
  331. *len = strlen(str);
  332. }
  333. /**
  334. * @brief Источник срабатывания реле
  335. */
  336. void GetROTypeActStr(char *str, uint8_t *len, uint8_t num)
  337. {
  338. sprintf(str, "%d", sSettings.sInOuts.ro_type_source[num]);
  339. *len = strlen(str);
  340. }
  341. /**
  342. * @brief Состояние релейного выхода
  343. */
  344. void GetDOUTStatusStr(char *str, uint8_t *len, uint8_t num)
  345. {
  346. #if defined HARDWARE_BT6706 || HARDWARE_BT6708
  347. sprintf(str, "%d", (get_state_din_outs(DOUT1+num)^1));
  348. #elif HARDWARE_BT6702
  349. sprintf(str, "%d", get_state_din_outs(DOUT1+num));
  350. #endif
  351. *len = strlen(str);
  352. }
  353. /**
  354. * @brief Состояние релейного выхода
  355. */
  356. void GetDOUTStatusStrRU(char *str, uint8_t *len, uint8_t num)
  357. {
  358. #if defined HARDWARE_BT6706 || HARDWARE_BT6708
  359. if (get_state_din_outs(DOUT1+num)^1)
  360. sprintf(str, "Замкнут");
  361. else
  362. sprintf(str, "Разомкнут");
  363. #elif HARDWARE_BT6702
  364. if(get_state_din_outs(DOUT1+num))
  365. sprintf(str, "Замкнут");
  366. else
  367. sprintf(str, "Разомкнут");
  368. #endif
  369. *len = strlen(str);
  370. }
  371. /**
  372. * @brief Состояние релейного выхода
  373. */
  374. void GetDOUT0StatusStr(char *str, uint8_t *len)
  375. {
  376. #if defined HARDWARE_BT6706 || HARDWARE_BT6708
  377. sprintf(str, "%d", (get_state_din_outs(DOUT1)^1));
  378. #elif HARDWARE_BT6702
  379. sprintf(str, "%d", get_state_din_outs(DOUT1));
  380. #endif
  381. *len = strlen(str);
  382. }
  383. /**
  384. * @brief Состояние релейного выхода
  385. */
  386. void GetDOUT1StatusStr(char *str, uint8_t *len)
  387. {
  388. #if defined HARDWARE_BT6706 || HARDWARE_BT6708
  389. sprintf(str, "%d", (get_state_din_outs(DOUT2)^1));
  390. #elif HARDWARE_BT6702
  391. sprintf(str, "%d", get_state_din_outs(DOUT2));
  392. #endif
  393. *len = strlen(str);
  394. }
  395. #if defined HARDWARE_BT6706 || HARDWARE_BT6708
  396. /**
  397. * @brief Состояние релейного выхода
  398. */
  399. void GetDOUT2StatusStr(char *str, uint8_t *len)
  400. {
  401. sprintf(str, "%d", (get_state_din_outs(DOUT3)^1));
  402. *len = strlen(str);
  403. }
  404. #endif
  405. #endif
  406. // ************************************************************************** //
  407. // Информация
  408. #ifndef BT6702_SERVICE
  409. /**
  410. * @brief Время работы устройства
  411. */
  412. void GetWorkTimeStr(char *str, uint8_t *len)
  413. {
  414. u32_t tick;
  415. uint16_t day;
  416. uint8_t hour;
  417. uint8_t min;
  418. // TODO открыть с новым api для snmp
  419. //snmp_get_sysuptime(&tick);
  420. MIB2_COPY_SYSUPTIME_TO(&tick);
  421. day = tick/8640000;
  422. tick = tick%8640000;
  423. hour = tick/360000;
  424. tick = tick%360000;
  425. min = tick/6000;
  426. sprintf(str, "%d дн. %d ч. %d мин.", day, hour, min);
  427. *len = strlen(str);
  428. }
  429. #endif
  430. /**
  431. * @brief Модель устройства
  432. */
  433. void GetModelStr(char *str, uint8_t *len)
  434. {
  435. *len = strlen(sSettings.sSnmp.sysName);
  436. strncpy(str, sSettings.sSnmp.sysName, *len);
  437. }
  438. /**
  439. * @brief Дата производства
  440. */
  441. void GetProductionDataStr(char *str, uint8_t *len)
  442. {
  443. *len = strlen(sSettings.sInfo.productionData);
  444. strncpy(str, sSettings.sInfo.productionData, *len);
  445. }
  446. /**
  447. * @brief Версия ПО
  448. */
  449. void GetVersionStr(char *str, uint8_t *len) // +
  450. {
  451. *len = strlen(VERSION);
  452. strncpy(str, VERSION, *len);
  453. }
  454. /**
  455. * @brief MAC адрес устройства
  456. */
  457. void GetMacStr(char *str, uint8_t *len)
  458. {
  459. *len = strlen(sSettings.sInfo.mac);
  460. strncpy(str, sSettings.sInfo.mac, *len);
  461. }
  462. /**
  463. * @brief Серийный номер устройства
  464. */
  465. void GetSerialNumberStr(char *str, uint8_t *len)
  466. {
  467. *len = strlen(sSettings.sInfo.serialNumber);
  468. strncpy(str, sSettings.sInfo.serialNumber, *len);
  469. }
  470. /**
  471. * @brief Владелец устройства
  472. */
  473. void GetOwnerStr(char *str, uint8_t *len)
  474. {
  475. *len = strlen(sSettings.sSnmp.sysContact);
  476. strncpy(str, sSettings.sSnmp.sysContact, *len);
  477. }
  478. /**
  479. * @brief Местоположение устройства
  480. */
  481. void GetLocationStr(char *str, uint8_t *len)
  482. {
  483. *len = strlen(sSettings.sSnmp.sysLocation);
  484. strncpy(str, sSettings.sSnmp.sysLocation, *len);
  485. }
  486. /**
  487. * @brief Комментарии
  488. */
  489. void GetCommentsStr(char *str, uint8_t *len)
  490. {
  491. *len = strlen(sSettings.sInfo.comments);
  492. strncpy(str, sSettings.sInfo.comments, *len);
  493. }
  494. #ifndef BT6702_SERVICE
  495. /**
  496. * @brief Модель UPS
  497. */
  498. void GetUPSModelStr(char *str, uint8_t *len)
  499. {
  500. *len = strlen(UPS.model);
  501. strncpy(str, UPS.model, *len);
  502. }
  503. /**
  504. * @brief Серийный номер UPS
  505. */
  506. void GetUPSSerialStr(char *str, uint8_t *len)
  507. {
  508. *len = strlen(UPS.serial);
  509. strncpy(str, UPS.serial, *len);
  510. }
  511. /**
  512. * @brief Версия UPS ПО
  513. */
  514. void GetUPSVersionStr(char *str, uint8_t *len) // +
  515. {
  516. *len = strlen(UPS.vertion);
  517. strncpy(str, UPS.vertion, *len);
  518. }
  519. #endif
  520. // ************************************************************************** //
  521. // Настройки аутентификации
  522. void GetUserLogin(uint8_t user_id, char *str, uint8_t *len)
  523. {
  524. sprintf(str, "%s", sSettings.sAuth[user_id].login);
  525. *len = strlen(str);
  526. }
  527. void GetUserPassword(uint8_t user_id, char *str, uint8_t *len)
  528. {
  529. sprintf(str, "%s", sSettings.sAuth[user_id].password);
  530. *len = strlen(str);
  531. }
  532. void GetUserLevel(uint8_t user_id, char *str, uint8_t *len)
  533. {
  534. sprintf(str, "%d", sSettings.sAuth[user_id].level);
  535. *len = strlen(str);
  536. }
  537. void GetUserLevelInt(uint8_t user_id, uint8_t *value)
  538. {
  539. *value = sSettings.sAuth[user_id].level;
  540. }
  541. // ************************************************************************** //
  542. // Параметры WEB
  543. /**
  544. * @brief Текущий IP адрес
  545. */
  546. void GetIpStr(char *str, uint8_t *len)
  547. {
  548. /* Если сейчас временные настройки */
  549. if (sSettings.sFlags.netsettingsChanged)
  550. sprintf(str, "%s", sSettings.sWebTempParams.ip);
  551. else
  552. sprintf(str, "%s", sSettings.sWebParams.ip);
  553. *len = strlen(str);
  554. }
  555. /**
  556. * @brief Текущий шлюз
  557. */
  558. void GetGatewayStr(char *str, uint8_t *len)
  559. {
  560. /* Если сейчас временные настройки */
  561. if (sSettings.sFlags.netsettingsChanged)
  562. sprintf(str, "%s", sSettings.sWebTempParams.gate);
  563. else
  564. sprintf(str, "%s", sSettings.sWebParams.gate);
  565. *len = strlen(str);
  566. }
  567. /**
  568. * @brief Текущая маска подсети
  569. */
  570. void GetMaskStr(char *str, uint8_t *len)
  571. {
  572. /* Если сейчас временные настройки */
  573. if (sSettings.sFlags.netsettingsChanged)
  574. sprintf(str, "%s", sSettings.sWebTempParams.mask);
  575. else
  576. sprintf(str, "%s", sSettings.sWebParams.mask);
  577. *len = strlen(str);
  578. }
  579. /**
  580. * @brief Настройка DHCP
  581. */
  582. void GetDhcpStateStr(char *str, uint8_t *len)
  583. {
  584. /* Если сейчас временные настройки */
  585. if (sSettings.sFlags.netsettingsChanged)
  586. {
  587. if (sSettings.sWebTempParams.dhcpEnable)
  588. *str = '1';
  589. else
  590. *str = '0';
  591. }
  592. else
  593. {
  594. if (sSettings.sWebParams.dhcpEnable)
  595. *str = '1';
  596. else
  597. *str = '0';
  598. }
  599. *len = 1;
  600. }
  601. /**
  602. * @brief Настройка DHCP
  603. */
  604. void GetDhcpStateUDP(char *str, uint8_t *len)
  605. {
  606. /* Если сейчас временные настройки или был загружен файл конфигурации */
  607. if (sSettings.sFlags.netsettingsChanged)
  608. {
  609. if (sSettings.sWebTempParams.dhcpEnable)
  610. sprintf(str, "%s", "True");
  611. else
  612. sprintf(str, "%s", "False");
  613. }
  614. else
  615. {
  616. if (sSettings.sWebParams.dhcpEnable)
  617. sprintf(str, "%s", "True");
  618. else
  619. sprintf(str, "%s", "False");
  620. }
  621. *len = strlen(str);
  622. }
  623. /**
  624. * @brief Настройка DHCP
  625. */
  626. void GetDhcpStateStrRu(char *str, uint8_t *len)
  627. {
  628. /* Если сейчас временные настройки или был загружен файл конфигурации */
  629. if (sSettings.sFlags.netsettingsChanged)
  630. {
  631. if (sSettings.sWebTempParams.dhcpEnable)
  632. sprintf(str, "%s", "Вкл");
  633. else
  634. sprintf(str, "%s", "Откл");
  635. }
  636. else
  637. {
  638. if (sSettings.sWebParams.dhcpEnable)
  639. sprintf(str, "%s", "Вкл");
  640. else
  641. sprintf(str, "%s", "Откл");
  642. }
  643. *len = strlen(str);
  644. }
  645. #ifdef HARDWARE_BT6708
  646. // ************************************************************************** //
  647. // Параметры довверительных хостов
  648. /**
  649. * @brief диапазон доверительных хостов
  650. */
  651. void GetWhiteListSTR(char *str, uint8_t *len, uint8_t num)
  652. {
  653. if (sSettings.sFlags.netsettingsChanged)
  654. strcpy(str, sSettings.sWhiteListTemp[num].ip_range);
  655. else
  656. strcpy(str, sSettings.sWhiteList[num].ip_range);
  657. *len = strlen(str);
  658. }
  659. /**
  660. * @brief маска диапазона доверительных хостов
  661. */
  662. void GetWhiteListMask(uint32_t *value, uint8_t num)
  663. {
  664. if (sSettings.sFlags.netsettingsChanged)
  665. *value = sSettings.sWhiteListTemp[num].mask;
  666. else
  667. *value = sSettings.sWhiteList[num].mask;
  668. }
  669. /**
  670. * @brief ip диапазона доверительных хостов
  671. */
  672. void GetWhiteListIP(uint32_t *value, uint8_t num)
  673. {
  674. if (sSettings.sFlags.netsettingsChanged)
  675. *value = sSettings.sWhiteListTemp[num].ip;
  676. else
  677. *value = sSettings.sWhiteList[num].ip;
  678. }
  679. #endif
  680. // ************************************************************************** //
  681. // Параметры SNMP
  682. /**
  683. * @brief Текущее community для чтения
  684. */
  685. void GetReadCommunity(char *str, uint8_t *len)
  686. {
  687. sprintf(str, "%s", sSettings.sSnmp.readCommunity);
  688. *len = strlen(str);
  689. }
  690. /**
  691. * @brief Текущее community для записи
  692. */
  693. void GetWriteCommunity(char *str, uint8_t *len)
  694. {
  695. sprintf(str, "%s", sSettings.sSnmp.writeCommunity);
  696. *len = strlen(str);
  697. }
  698. /**
  699. * @brief IP SNMP менеджера
  700. */
  701. void GetManagerIp(char *str, uint8_t *len)
  702. {
  703. sprintf(str, "%s", sSettings.sSnmp.managerIP);
  704. *len = strlen(str);
  705. }
  706. void GetManagerIp2(char *str, uint8_t *len)
  707. {
  708. sprintf(str, "%s", sSettings.sSnmp.managerIP2);
  709. *len = strlen(str);
  710. }
  711. void GetManagerIp3(char *str, uint8_t *len)
  712. {
  713. sprintf(str, "%s", sSettings.sSnmp.managerIP3);
  714. *len = strlen(str);
  715. }
  716. void GetManagerIp4(char *str, uint8_t *len)
  717. {
  718. sprintf(str, "%s", sSettings.sSnmp.managerIP4);
  719. *len = strlen(str);
  720. }
  721. void GetManagerIp5(char *str, uint8_t *len)
  722. {
  723. sprintf(str, "%s", sSettings.sSnmp.managerIP5);
  724. *len = strlen(str);
  725. }
  726. #ifdef HARDWARE_BT6702
  727. // ************************************************************************** //
  728. // Параметры RADIUS
  729. /**
  730. * @brief Текущий IP адрес
  731. */
  732. void GetRDSIpStr(char *str, uint8_t *len)
  733. {
  734. sprintf(str, "%s", sSettings.sRADIUS.ServerIP);
  735. *len = strlen(str);
  736. }
  737. /**
  738. * @brief Текущий Порт
  739. */
  740. void GetRDSPortStr(char *str, uint8_t *len)
  741. {
  742. sprintf(str, "%d", sSettings.sRADIUS.port);
  743. *len = strlen(str);
  744. }
  745. /**
  746. * @brief Текущий Код access
  747. */
  748. void GetRDSKeyAccesstStr(char *str, uint8_t *len)
  749. {
  750. sprintf(str, "%d", sSettings.sRADIUS.key_access);
  751. *len = strlen(str);
  752. }
  753. /**
  754. * @brief Текущая пароль RADIUS
  755. */
  756. void GetRDSPasswordkStr(char *str, uint8_t *len)
  757. {
  758. sprintf(str, "%s", sSettings.sRADIUS.rds_password);
  759. *len = strlen(str);
  760. }
  761. /**
  762. * @brief Настройка вкл/ выкл RADIUS сервера
  763. */
  764. void GetRDSEnableStateStr(char *str, uint8_t *len)
  765. {
  766. if (sSettings.sRADIUS.RDSEnable)
  767. *str = '1';
  768. else
  769. *str = '0';
  770. *len = 1;
  771. }
  772. /**
  773. * @brief Настройка вкл/ выкл авторизации
  774. */
  775. void GetAuthEnableStateStr(char *str, uint8_t *len)
  776. {
  777. if (sSettings.sRADIUS.Auth_enable)
  778. *str = '1';
  779. else
  780. *str = '0';
  781. *len = 1;
  782. }
  783. #endif
  784. #if defined HARDWARE_BT6706 || HARDWARE_BT6708
  785. // ************************************************************************** //
  786. // Параметры Telnet
  787. /**
  788. * @brief Текущий Порт
  789. */
  790. void GetTelnetPortStr(char *str, uint8_t *len)
  791. {
  792. sprintf(str, "%d", sSettings.sTelnet.port);
  793. *len = strlen(str);
  794. }
  795. /**
  796. * @brief Настройка вкл/ выкл Telnet сервера
  797. */
  798. void GetTelnetEnableStateStr(char *str, uint8_t *len)
  799. {
  800. if (sSettings.sTelnet.TelnetEnable)
  801. *str = '1';
  802. else
  803. *str = '0';
  804. *len = 1;
  805. }
  806. #endif
  807. // ************************************************************************** //
  808. // Флаги
  809. /**
  810. * @brief Вернуть признак изменения сетевых параметров
  811. */
  812. void GetWebReinitFlag(char *str, uint8_t *len)
  813. {
  814. if (sSettings.sFlags.netsettingsChanged)
  815. {
  816. sprintf(str, "%s", "true");
  817. *len = strlen(str);
  818. }
  819. else
  820. {
  821. sprintf(str, "%s", "false");
  822. *len = strlen(str);
  823. }
  824. }
  825. // ************************************************************************** //
  826. // Параметры настройки ИБП
  827. /**
  828. * @brief Минимальное напряжение на ячейках АКБ
  829. */
  830. void GetUPSVoltCellMinStr(char *str, uint8_t *len)
  831. {
  832. sprintf(str, "%0.2f", roundto(sSettings.UPS_Setting.Ucellmin, 2));
  833. *len = strlen(str);
  834. }
  835. /**
  836. * @brief Максимальное напряжение на ячейках АКБ
  837. */
  838. void GetUPSVoltCellMaxStr(char *str, uint8_t *len)
  839. {
  840. sprintf(str, "%0.2f", roundto(sSettings.UPS_Setting.Ucellmax, 2));
  841. *len = strlen(str);
  842. }
  843. // ************************************************************************** //
  844. // Установка параметрв
  845. // ************************************************************************** //
  846. /**
  847. * @brief Установить признак обновления ПО.
  848. */
  849. void SetLoadMode(void)
  850. {
  851. /* Set loadMode = 1 */
  852. RTC_WriteBackupRegister(RTC_BKP_DR1, 1);
  853. /* Set bootTry = 0 */
  854. RTC_WriteBackupRegister(RTC_BKP_DR2, 0);
  855. }
  856. /**
  857. * @brief Установить признак изменения сетевых параметров
  858. */
  859. void SetWebReinitFlag(bool value)
  860. {
  861. sSettings.sFlags.netsettingsChanged = value;
  862. }
  863. /**
  864. * @brief Установить флаг подтверждения сетевых настроек пользователем
  865. */
  866. void SetConfirmWebParamsFlag(void)
  867. {
  868. fConfirmWebParams = true;
  869. }
  870. // ************************************************************************** //
  871. // Сетевые параметры
  872. /**
  873. * @brief IP адрес
  874. */
  875. void SetIPStr(char *str)
  876. {
  877. //strcpy(sSettings.sWebParams.ip, str);
  878. strcpy(sSettings.sWebTempParams.ip, str);
  879. }
  880. /**
  881. * @brief Шлюз
  882. */
  883. void SetGatewayStr(char *str)
  884. {
  885. //strcpy(sSettings.sWebParams.gate, str);
  886. strcpy(sSettings.sWebTempParams.gate, str);
  887. }
  888. /**
  889. * @brief Текущая маска подсети
  890. */
  891. void SetMaskStr(char *str)
  892. {
  893. //strcpy(sSettings.sWebParams.mask, str);
  894. strcpy(sSettings.sWebTempParams.mask, str);
  895. }
  896. /**
  897. * @brief Настройка DHCP
  898. */
  899. void SetDhcpStateStr(char *str)
  900. {
  901. if (strncmp(str, "on", 2) == 0)
  902. //sSettings.sWebParams.dhcpEnable = 1;
  903. sSettings.sWebTempParams.dhcpEnable = 1;
  904. else
  905. //sSettings.sWebParams.dhcpEnable = 0;
  906. sSettings.sWebTempParams.dhcpEnable = 0;
  907. }
  908. /**
  909. * @brief Настройка DHCP
  910. */
  911. void SetUDPDhcpStateStr(char *str)
  912. {
  913. if (strncmp(str, "True", 4) == 0)
  914. sSettings.sWebTempParams.dhcpEnable = 1;
  915. else if (strncmp(str, "False", 5) == 0)
  916. sSettings.sWebTempParams.dhcpEnable = 0;
  917. }
  918. #ifdef HARDWARE_BT6708
  919. // ************************************************************************** //
  920. // Параметры довверительных хостов
  921. /**
  922. * @brief диапазон доверительных хостов
  923. */
  924. void SetWhiteListSTR(char *str, uint8_t num)
  925. {
  926. char ip_str[20];
  927. char *mask_str;
  928. uint32_t mask;
  929. uint8_t num_octet = 0;
  930. strcpy(sSettings.sWhiteListTemp[num].ip_range, str);
  931. if(strlen(sSettings.sWhiteListTemp[num].ip_range) != 0){
  932. mask_str = strstr(sSettings.sWhiteListTemp[num].ip_range, "/");
  933. if(mask_str != NULL){
  934. mask = atoi(&mask_str[1]);
  935. sSettings.sWhiteListTemp[num].mask = 0;
  936. for(uint8_t i = 0; i < mask; i ++){
  937. if(i < 8)
  938. num_octet = 1;
  939. else
  940. num_octet = i/8+1;
  941. sSettings.sWhiteListTemp[num].mask |= (1 << (8*num_octet - 1 - (i - 8*(num_octet - 1))));
  942. }
  943. memset(ip_str, 0, 20);
  944. strncpy(ip_str, sSettings.sWhiteListTemp[num].ip_range, (mask_str - sSettings.sWhiteListTemp[num].ip_range));
  945. sSettings.sWhiteListTemp[num].ip = ipaddr_addr(ip_str);
  946. }
  947. }
  948. else{
  949. sSettings.sWhiteListTemp[num].mask = 0;
  950. sSettings.sWhiteListTemp[num].ip = 0;
  951. strncpy(sSettings.sWhiteListTemp[num].ip_range, "0.0.0.0/0", 9);
  952. }
  953. }
  954. #endif
  955. // ************************************************************************** //
  956. // Параметры SNMP
  957. /**
  958. * @brief Community для чтения
  959. */
  960. void SetReadCommunity(char *str)
  961. {
  962. strcpy(sSettings.sSnmp.readCommunity, str);
  963. }
  964. /**
  965. * @brief Community для записи
  966. */
  967. void SetWriteCommunity(char *str)
  968. {
  969. strcpy(sSettings.sSnmp.writeCommunity, str);
  970. }
  971. #ifndef BT6702_SERVICE
  972. /**
  973. * @brief IP SNMP менеджера
  974. */
  975. void SetManagerIp(char *str)
  976. {
  977. strcpy(sSettings.sSnmp.managerIP, str);
  978. SNMP_SetManagerIP(sSettings.sSnmp.managerIP);
  979. }
  980. void SetManagerIp2(char *str)
  981. {
  982. strcpy(sSettings.sSnmp.managerIP2, str);
  983. SNMP_SetManagerIP(sSettings.sSnmp.managerIP2);
  984. }
  985. void SetManagerIp3(char *str)
  986. {
  987. strcpy(sSettings.sSnmp.managerIP3, str);
  988. SNMP_SetManagerIP(sSettings.sSnmp.managerIP3);
  989. }
  990. void SetManagerIp4(char *str)
  991. {
  992. strcpy(sSettings.sSnmp.managerIP4, str);
  993. SNMP_SetManagerIP(sSettings.sSnmp.managerIP4);
  994. }
  995. void SetManagerIp5(char *str)
  996. {
  997. strcpy(sSettings.sSnmp.managerIP5, str);
  998. SNMP_SetManagerIP(sSettings.sSnmp.managerIP5);
  999. }
  1000. /**
  1001. * @brief Установить владельца
  1002. */
  1003. void SetOwner(char *str)
  1004. {
  1005. strcpy(sSettings.sSnmp.sysContact, str);
  1006. SNMP_SetSysContact(sSettings.sSnmp.sysContact);
  1007. SNMP_SetObjDescr();
  1008. }
  1009. /**
  1010. * @brief Установить местоположение
  1011. */
  1012. void SetLocation(char *str)
  1013. {
  1014. strcpy(sSettings.sSnmp.sysLocation, str);
  1015. SNMP_SetSysLocation(sSettings.sSnmp.sysLocation);
  1016. }
  1017. #endif
  1018. /**
  1019. * @brief Установить комментарий
  1020. */
  1021. void SetComment(char *str)
  1022. {
  1023. strcpy(sSettings.sInfo.comments, str);
  1024. }
  1025. #ifdef HARDWARE_BT6702
  1026. // ************************************************************************** //
  1027. // Сетевые параметры RADIUS сервера
  1028. /**
  1029. * @brief IP адрес
  1030. */
  1031. void SetRDSIpStr(char *str)
  1032. {
  1033. strcpy(sSettings.sRADIUS.ServerIP, str);
  1034. }
  1035. /**
  1036. * @brief Порт
  1037. */
  1038. void SetRDSPortStr(char *str)
  1039. {
  1040. sSettings.sRADIUS.port = atoi(str);
  1041. }
  1042. /**
  1043. * @brief Код access
  1044. */
  1045. void SetRDSKeyAccesstStr(char *str)
  1046. {
  1047. sSettings.sRADIUS.key_access = atoi(str);
  1048. }
  1049. /**
  1050. * @brief пароль RADIUS
  1051. */
  1052. void SetRDSPasswordkStr(char *str)
  1053. {
  1054. strcpy(sSettings.sRADIUS.rds_password, str);
  1055. }
  1056. /**
  1057. * @brief Настройка вкл/ выкл RADIUS сервера
  1058. */
  1059. void SetRDSEnableStateStr(char *str)
  1060. {
  1061. if (strncmp(str, "on", 2) == 0)
  1062. sSettings.sRADIUS.RDSEnable = 1;
  1063. else
  1064. sSettings.sRADIUS.RDSEnable = 0;
  1065. }
  1066. /**
  1067. * @brief Настройка вкл/ выкл авторизации
  1068. */
  1069. void SetAuthEnableStateStr(char *str)
  1070. {
  1071. if (strncmp(str, "on", 2) == 0)
  1072. sSettings.sRADIUS.Auth_enable = 1;
  1073. else
  1074. sSettings.sRADIUS.Auth_enable = 0;
  1075. }
  1076. #endif
  1077. #if defined HARDWARE_BT6706 || HARDWARE_BT6708
  1078. // ************************************************************************** //
  1079. // Параметры Telnet
  1080. #ifndef BT6702_SERVICE
  1081. /**
  1082. * @brief Текущий Порт
  1083. */
  1084. void SetTelnetPortStr(char *str)
  1085. {
  1086. sSettings.sTelnet.port = atoi(str);
  1087. }
  1088. /**
  1089. * @brief Настройка вкл/ выкл Telnet сервера
  1090. */
  1091. void SetTelnetEnableStateStr(char *str)
  1092. {
  1093. if (strncmp(str, "on", 2) == 0)
  1094. sSettings.sTelnet.TelnetEnable = 1;
  1095. else
  1096. sSettings.sTelnet.TelnetEnable = 0;
  1097. }
  1098. #endif
  1099. #endif
  1100. // ************************************************************************** //
  1101. // Параметры даты и времени
  1102. /**
  1103. * @brief Дата
  1104. */
  1105. void SetDateStr(char *str)
  1106. {
  1107. TM_RTC_t tmp_data;
  1108. char str_data[18];
  1109. char str_time[9];
  1110. uint8_t len;
  1111. memset(str_data, 0, 18);
  1112. memset(str_time, 0, 9);
  1113. str += 2;
  1114. strncpy(str_data, (str + 6), 2);
  1115. strncat(str_data, (str + 2), 4);
  1116. strncat(str_data, str, 2);
  1117. TM_RTC_GetDateTime(&tmp_data, TM_RTC_Format_BIN);
  1118. sprintf(str_time, "-01-%02i:%02i", tmp_data.hours, tmp_data.minutes);
  1119. len = strlen(str_time);
  1120. strncat(str_data, str_time, len);
  1121. //TM_RTC_SetDateTimeString(&str_data);
  1122. TM_RTC_SetDateTimeString(str_data);
  1123. }
  1124. /**
  1125. * @brief Время
  1126. */
  1127. void SetTimeStr(char *str)
  1128. {
  1129. TM_RTC_t tmp_data;
  1130. char str_data[18];
  1131. char str_date[14];
  1132. uint8_t len;
  1133. memset(str_data, 0, 18);
  1134. memset(str_date, 0, 14);
  1135. TM_RTC_GetDateTime(&tmp_data, TM_RTC_Format_BIN);
  1136. sprintf(str_date, "%02i-%02i-%02i-01-", tmp_data.date, tmp_data.month, tmp_data.year);
  1137. len = strlen(str_date);
  1138. strncat(str_data, str_date, len);
  1139. strncat(str_data, str, 5);
  1140. //TM_RTC_SetDateTimeString(&str_data);
  1141. TM_RTC_SetDateTimeString(str_data);
  1142. }
  1143. // ************************************************************************** //
  1144. // Параметры SNTP
  1145. #ifndef BT6702_SERVICE
  1146. /**
  1147. * @brief Состояние SNTP
  1148. */
  1149. void SetSntpStateStr(char *str)
  1150. {
  1151. if (strncmp(str, "1", 1) == 0){
  1152. sSettings.sSNTP.sntpEnable = true;
  1153. }
  1154. else{
  1155. sSettings.sSNTP.sntpEnable = false;
  1156. }
  1157. }
  1158. #endif
  1159. /**
  1160. * @brief IP адрес SNTP сервера
  1161. */
  1162. void SetSntpServerIpStr(char *str)
  1163. {
  1164. strcpy(sSettings.sSNTP.ip, str);
  1165. }
  1166. /**
  1167. * @brief Часовой пояс контроллера
  1168. */
  1169. void SetSntpTimeZoneStr(char *str)
  1170. {
  1171. float newUtc;
  1172. newUtc = atof(str);
  1173. if (sSettings.sSNTP.timeZone > 0)
  1174. {
  1175. if (newUtc >= 0)
  1176. {
  1177. if (newUtc >= sSettings.sSNTP.timeZone)
  1178. TM_RTC_Correction(newUtc - sSettings.sSNTP.timeZone);
  1179. else
  1180. TM_RTC_Correction(newUtc - sSettings.sSNTP.timeZone);
  1181. }
  1182. else
  1183. {
  1184. TM_RTC_Correction(newUtc - sSettings.sSNTP.timeZone);
  1185. }
  1186. }
  1187. else if (sSettings.sSNTP.timeZone < 0)
  1188. {
  1189. if (newUtc >= 0)
  1190. {
  1191. TM_RTC_Correction(newUtc + fabs(sSettings.sSNTP.timeZone));
  1192. }
  1193. else
  1194. {
  1195. if (newUtc >= sSettings.sSNTP.timeZone)
  1196. TM_RTC_Correction(fabs(sSettings.sSNTP.timeZone) - fabs(newUtc));
  1197. else
  1198. TM_RTC_Correction(newUtc - sSettings.sSNTP.timeZone);
  1199. }
  1200. }
  1201. else if (sSettings.sSNTP.timeZone == 0)
  1202. {
  1203. TM_RTC_Correction(newUtc);
  1204. }
  1205. sSettings.sSNTP.timeZone = newUtc; // atof(str);
  1206. //TM_RTC_Correction(sSettings.sSNTP.timeZone);
  1207. }
  1208. #ifndef HARDWARE_BT6708
  1209. // ************************************************************************** //
  1210. // Параметры реле/сухих контактов
  1211. /**
  1212. * @brief Тип действий при срабатывание сухих контактов
  1213. */
  1214. void SetDINTypeActStr(char *str, uint8_t num)
  1215. {
  1216. sSettings.sInOuts.din_type_act[num] = atoi(str);
  1217. }
  1218. /**
  1219. * @brief Источник срабатывания реле
  1220. */
  1221. void SetROTypeActStr(char *str, uint8_t num)
  1222. {
  1223. static uint8_t OldROtype_Sourse[2] = {0};
  1224. OldROtype_Sourse[num] = sSettings.sInOuts.ro_type_source[num];
  1225. sSettings.sInOuts.ro_type_source[num] = atoi(str);
  1226. if(OldROtype_Sourse[num] != sSettings.sInOuts.ro_type_source[num])
  1227. SetROInt(0, num);
  1228. }
  1229. /**
  1230. * @brief
  1231. */
  1232. void SetROStr(char *str, uint8_t num)
  1233. {
  1234. set_state_douts((DOUT1+num), atoi(str));
  1235. }
  1236. /**
  1237. * @brief
  1238. */
  1239. void SetROInt(uint8_t val, uint8_t num)
  1240. {
  1241. set_state_douts((DOUT1+num), val);
  1242. }
  1243. #endif
  1244. // ************************************************************************** //
  1245. // Параметры настройки ИБП
  1246. /**
  1247. * @brief Минимальное напряжение на ячейках АКБ
  1248. */
  1249. void SetUPSVoltCellMinStr(char *str)
  1250. {
  1251. sSettings.UPS_Setting.Ucellmin = atof(str);
  1252. }
  1253. /**
  1254. * @brief Максимальное напряжение на ячейках АКБ
  1255. */
  1256. void SetUPSVoltCellMaxStr(char *str)
  1257. {
  1258. sSettings.UPS_Setting.Ucellmax = atof(str);
  1259. }
  1260. /********************************* (C) РОТЕК **********************************/