parameters.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  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. else{
  948. sSettings.sWhiteListTemp[num].mask = 0;
  949. sSettings.sWhiteListTemp[num].ip = 0;
  950. }
  951. }
  952. }
  953. #endif
  954. // ************************************************************************** //
  955. // Параметры SNMP
  956. /**
  957. * @brief Community для чтения
  958. */
  959. void SetReadCommunity(char *str)
  960. {
  961. strcpy(sSettings.sSnmp.readCommunity, str);
  962. }
  963. /**
  964. * @brief Community для записи
  965. */
  966. void SetWriteCommunity(char *str)
  967. {
  968. strcpy(sSettings.sSnmp.writeCommunity, str);
  969. }
  970. #ifndef BT6702_SERVICE
  971. /**
  972. * @brief IP SNMP менеджера
  973. */
  974. void SetManagerIp(char *str)
  975. {
  976. strcpy(sSettings.sSnmp.managerIP, str);
  977. SNMP_SetManagerIP(sSettings.sSnmp.managerIP);
  978. }
  979. void SetManagerIp2(char *str)
  980. {
  981. strcpy(sSettings.sSnmp.managerIP2, str);
  982. SNMP_SetManagerIP(sSettings.sSnmp.managerIP2);
  983. }
  984. void SetManagerIp3(char *str)
  985. {
  986. strcpy(sSettings.sSnmp.managerIP3, str);
  987. SNMP_SetManagerIP(sSettings.sSnmp.managerIP3);
  988. }
  989. void SetManagerIp4(char *str)
  990. {
  991. strcpy(sSettings.sSnmp.managerIP4, str);
  992. SNMP_SetManagerIP(sSettings.sSnmp.managerIP4);
  993. }
  994. void SetManagerIp5(char *str)
  995. {
  996. strcpy(sSettings.sSnmp.managerIP5, str);
  997. SNMP_SetManagerIP(sSettings.sSnmp.managerIP5);
  998. }
  999. /**
  1000. * @brief Установить владельца
  1001. */
  1002. void SetOwner(char *str)
  1003. {
  1004. strcpy(sSettings.sSnmp.sysContact, str);
  1005. SNMP_SetSysContact(sSettings.sSnmp.sysContact);
  1006. SNMP_SetObjDescr();
  1007. }
  1008. /**
  1009. * @brief Установить местоположение
  1010. */
  1011. void SetLocation(char *str)
  1012. {
  1013. strcpy(sSettings.sSnmp.sysLocation, str);
  1014. SNMP_SetSysLocation(sSettings.sSnmp.sysLocation);
  1015. }
  1016. #endif
  1017. /**
  1018. * @brief Установить комментарий
  1019. */
  1020. void SetComment(char *str)
  1021. {
  1022. strcpy(sSettings.sInfo.comments, str);
  1023. }
  1024. #ifdef HARDWARE_BT6702
  1025. // ************************************************************************** //
  1026. // Сетевые параметры RADIUS сервера
  1027. /**
  1028. * @brief IP адрес
  1029. */
  1030. void SetRDSIpStr(char *str)
  1031. {
  1032. strcpy(sSettings.sRADIUS.ServerIP, str);
  1033. }
  1034. /**
  1035. * @brief Порт
  1036. */
  1037. void SetRDSPortStr(char *str)
  1038. {
  1039. sSettings.sRADIUS.port = atoi(str);
  1040. }
  1041. /**
  1042. * @brief Код access
  1043. */
  1044. void SetRDSKeyAccesstStr(char *str)
  1045. {
  1046. sSettings.sRADIUS.key_access = atoi(str);
  1047. }
  1048. /**
  1049. * @brief пароль RADIUS
  1050. */
  1051. void SetRDSPasswordkStr(char *str)
  1052. {
  1053. strcpy(sSettings.sRADIUS.rds_password, str);
  1054. }
  1055. /**
  1056. * @brief Настройка вкл/ выкл RADIUS сервера
  1057. */
  1058. void SetRDSEnableStateStr(char *str)
  1059. {
  1060. if (strncmp(str, "on", 2) == 0)
  1061. sSettings.sRADIUS.RDSEnable = 1;
  1062. else
  1063. sSettings.sRADIUS.RDSEnable = 0;
  1064. }
  1065. /**
  1066. * @brief Настройка вкл/ выкл авторизации
  1067. */
  1068. void SetAuthEnableStateStr(char *str)
  1069. {
  1070. if (strncmp(str, "on", 2) == 0)
  1071. sSettings.sRADIUS.Auth_enable = 1;
  1072. else
  1073. sSettings.sRADIUS.Auth_enable = 0;
  1074. }
  1075. #endif
  1076. #if defined HARDWARE_BT6706 || HARDWARE_BT6708
  1077. // ************************************************************************** //
  1078. // Параметры Telnet
  1079. #ifndef BT6702_SERVICE
  1080. /**
  1081. * @brief Текущий Порт
  1082. */
  1083. void SetTelnetPortStr(char *str)
  1084. {
  1085. sSettings.sTelnet.port = atoi(str);
  1086. }
  1087. /**
  1088. * @brief Настройка вкл/ выкл Telnet сервера
  1089. */
  1090. void SetTelnetEnableStateStr(char *str)
  1091. {
  1092. if (strncmp(str, "on", 2) == 0)
  1093. sSettings.sTelnet.TelnetEnable = 1;
  1094. else
  1095. sSettings.sTelnet.TelnetEnable = 0;
  1096. }
  1097. #endif
  1098. #endif
  1099. // ************************************************************************** //
  1100. // Параметры даты и времени
  1101. /**
  1102. * @brief Дата
  1103. */
  1104. void SetDateStr(char *str)
  1105. {
  1106. TM_RTC_t tmp_data;
  1107. char str_data[18];
  1108. char str_time[9];
  1109. uint8_t len;
  1110. memset(str_data, 0, 18);
  1111. memset(str_time, 0, 9);
  1112. str += 2;
  1113. strncpy(str_data, (str + 6), 2);
  1114. strncat(str_data, (str + 2), 4);
  1115. strncat(str_data, str, 2);
  1116. TM_RTC_GetDateTime(&tmp_data, TM_RTC_Format_BIN);
  1117. sprintf(str_time, "-01-%02i:%02i", tmp_data.hours, tmp_data.minutes);
  1118. len = strlen(str_time);
  1119. strncat(str_data, str_time, len);
  1120. //TM_RTC_SetDateTimeString(&str_data);
  1121. TM_RTC_SetDateTimeString(str_data);
  1122. }
  1123. /**
  1124. * @brief Время
  1125. */
  1126. void SetTimeStr(char *str)
  1127. {
  1128. TM_RTC_t tmp_data;
  1129. char str_data[18];
  1130. char str_date[14];
  1131. uint8_t len;
  1132. memset(str_data, 0, 18);
  1133. memset(str_date, 0, 14);
  1134. TM_RTC_GetDateTime(&tmp_data, TM_RTC_Format_BIN);
  1135. sprintf(str_date, "%02i-%02i-%02i-01-", tmp_data.date, tmp_data.month, tmp_data.year);
  1136. len = strlen(str_date);
  1137. strncat(str_data, str_date, len);
  1138. strncat(str_data, str, 5);
  1139. //TM_RTC_SetDateTimeString(&str_data);
  1140. TM_RTC_SetDateTimeString(str_data);
  1141. }
  1142. // ************************************************************************** //
  1143. // Параметры SNTP
  1144. #ifndef BT6702_SERVICE
  1145. /**
  1146. * @brief Состояние SNTP
  1147. */
  1148. void SetSntpStateStr(char *str)
  1149. {
  1150. if (strncmp(str, "1", 1) == 0){
  1151. sSettings.sSNTP.sntpEnable = true;
  1152. }
  1153. else{
  1154. sSettings.sSNTP.sntpEnable = false;
  1155. }
  1156. }
  1157. #endif
  1158. /**
  1159. * @brief IP адрес SNTP сервера
  1160. */
  1161. void SetSntpServerIpStr(char *str)
  1162. {
  1163. strcpy(sSettings.sSNTP.ip, str);
  1164. }
  1165. /**
  1166. * @brief Часовой пояс контроллера
  1167. */
  1168. void SetSntpTimeZoneStr(char *str)
  1169. {
  1170. float newUtc;
  1171. newUtc = atof(str);
  1172. if (sSettings.sSNTP.timeZone > 0)
  1173. {
  1174. if (newUtc >= 0)
  1175. {
  1176. if (newUtc >= sSettings.sSNTP.timeZone)
  1177. TM_RTC_Correction(newUtc - sSettings.sSNTP.timeZone);
  1178. else
  1179. TM_RTC_Correction(newUtc - sSettings.sSNTP.timeZone);
  1180. }
  1181. else
  1182. {
  1183. TM_RTC_Correction(newUtc - sSettings.sSNTP.timeZone);
  1184. }
  1185. }
  1186. else if (sSettings.sSNTP.timeZone < 0)
  1187. {
  1188. if (newUtc >= 0)
  1189. {
  1190. TM_RTC_Correction(newUtc + fabs(sSettings.sSNTP.timeZone));
  1191. }
  1192. else
  1193. {
  1194. if (newUtc >= sSettings.sSNTP.timeZone)
  1195. TM_RTC_Correction(fabs(sSettings.sSNTP.timeZone) - fabs(newUtc));
  1196. else
  1197. TM_RTC_Correction(newUtc - sSettings.sSNTP.timeZone);
  1198. }
  1199. }
  1200. else if (sSettings.sSNTP.timeZone == 0)
  1201. {
  1202. TM_RTC_Correction(newUtc);
  1203. }
  1204. sSettings.sSNTP.timeZone = newUtc; // atof(str);
  1205. //TM_RTC_Correction(sSettings.sSNTP.timeZone);
  1206. }
  1207. #ifndef HARDWARE_BT6708
  1208. // ************************************************************************** //
  1209. // Параметры реле/сухих контактов
  1210. /**
  1211. * @brief Тип действий при срабатывание сухих контактов
  1212. */
  1213. void SetDINTypeActStr(char *str, uint8_t num)
  1214. {
  1215. sSettings.sInOuts.din_type_act[num] = atoi(str);
  1216. }
  1217. /**
  1218. * @brief Источник срабатывания реле
  1219. */
  1220. void SetROTypeActStr(char *str, uint8_t num)
  1221. {
  1222. static uint8_t OldROtype_Sourse[2] = {0};
  1223. OldROtype_Sourse[num] = sSettings.sInOuts.ro_type_source[num];
  1224. sSettings.sInOuts.ro_type_source[num] = atoi(str);
  1225. if(OldROtype_Sourse[num] != sSettings.sInOuts.ro_type_source[num])
  1226. SetROInt(0, num);
  1227. }
  1228. /**
  1229. * @brief
  1230. */
  1231. void SetROStr(char *str, uint8_t num)
  1232. {
  1233. set_state_douts((DOUT1+num), atoi(str));
  1234. }
  1235. /**
  1236. * @brief
  1237. */
  1238. void SetROInt(uint8_t val, uint8_t num)
  1239. {
  1240. set_state_douts((DOUT1+num), val);
  1241. }
  1242. #endif
  1243. // ************************************************************************** //
  1244. // Параметры настройки ИБП
  1245. /**
  1246. * @brief Минимальное напряжение на ячейках АКБ
  1247. */
  1248. void SetUPSVoltCellMinStr(char *str)
  1249. {
  1250. sSettings.UPS_Setting.Ucellmin = atof(str);
  1251. }
  1252. /**
  1253. * @brief Максимальное напряжение на ячейках АКБ
  1254. */
  1255. void SetUPSVoltCellMaxStr(char *str)
  1256. {
  1257. sSettings.UPS_Setting.Ucellmax = atof(str);
  1258. }
  1259. /********************************* (C) РОТЕК **********************************/