CLI_Commands.c 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626
  1. /*
  2. * CLI_Commands.c
  3. *
  4. * Created on: 28.11.2017
  5. * Author: balbekova
  6. */
  7. /* FreeRTOS includes. */
  8. #include "FreeRTOS.h"
  9. #include "task.h"
  10. /* Standard includes. */
  11. #include <stdint.h>
  12. #ifdef PRINTF_STDLIB
  13. #include <stdio.h>
  14. #endif
  15. #ifdef PRINTF_CUSTOM
  16. #include "tinystdio.h"
  17. #endif
  18. #include <string.h>
  19. #include <stdlib.h>
  20. /* FreeRTOS+CLI includes. */
  21. #include "FreeRTOS_CLI.h"
  22. #include "snmp_api.h"
  23. #include "trap_api.h"
  24. #include "sntp_api.h"
  25. #include "lwip/ip_addr.h"
  26. #include "settings_api.h"
  27. #include "log.h"
  28. #include "megatec.h"
  29. #include "web_params_api.h"
  30. #include "hal.h"
  31. #include "parameters.h"
  32. #include "CLI_Commands.h"
  33. #include "CLI_Parameters.h"
  34. #include "telnet_server.h"
  35. #include "netconf.h"
  36. #include "control_symbol.h"
  37. #define in_range_digit(c, lo, up) ((uint8_t)c >= lo && (uint8_t)c <= up)
  38. #define isdigit_int(c) in_range_digit(c, '0', '9')
  39. #define isfloatdigit(c) (isdigit_int(c) || in_range_digit(c, '.', '.'))
  40. extern state_telnet_server_t telnetState;
  41. extern uint8_t id_change_pwd;
  42. const int8_t * const pcInvalidCommand = ( int8_t * ) "Неправильно введены параметры команды. Введите \"help\" для просмотра списка поддерживаемых команд.\r\n\r\n";
  43. const int8_t * const pcPermissionDenied = ( int8_t * ) "Отказ в доступе!\r\n\r\n";
  44. const int8_t * const pcSystymeDenied = ( int8_t * ) "Ручной ввод времени не доступен!\r\n\r\n";
  45. const char* info_args_list[] =
  46. {
  47. "name",
  48. "address",
  49. "owner",
  50. "comments",
  51. };
  52. const char* ups_args_list[] =
  53. {
  54. "battest",
  55. "shutdown",
  56. };
  57. const char* systime_args_list[] =
  58. {
  59. "date",
  60. "time",
  61. };
  62. const char* network_args_list[] =
  63. {
  64. "info",
  65. "dhcp",
  66. "ip",
  67. "gw",
  68. "mask",
  69. };
  70. const char* snmp_args_list[] =
  71. {
  72. "info",
  73. "server",
  74. "community",
  75. };
  76. const char* akb_args_list[] =
  77. {
  78. "info",
  79. "voltcellmin",
  80. "voltcellmax",
  81. };
  82. const char* type_alarm_args_list[] =
  83. {
  84. "info",
  85. "temp",
  86. "load",
  87. "vout",
  88. };
  89. const char* alarm_args_list[] =
  90. {
  91. "low",
  92. "high",
  93. "hist",
  94. };
  95. const char* whitelist_args_list[] =
  96. {
  97. "info",
  98. "range",
  99. };
  100. const char* ntp_args_list[] =
  101. {
  102. "ENA",
  103. "DIS",
  104. "info",
  105. "set",
  106. };
  107. const char* config_args_list[] =
  108. {
  109. "info",
  110. "load",
  111. };
  112. const char* netconfig_args_list[] =
  113. {
  114. "apply",
  115. "confirm",
  116. };
  117. const char* history_args_list[] =
  118. {
  119. "EVENTS",
  120. "UPS",
  121. };
  122. const char* sensor_args_list[] =
  123. {
  124. "info",
  125. "setup",
  126. };
  127. const char* user_args_list[] =
  128. {
  129. "passwd",
  130. };
  131. /**
  132. * @brief Общая структура настроек
  133. */
  134. extern SETTINGS_t sSettings;
  135. extern user_level_t telnet_code_auth;
  136. /*
  137. * Implements the controller's information command.
  138. */
  139. static portBASE_TYPE prvTaskInfoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  140. /*
  141. * Implements the reboot command.
  142. */
  143. static portBASE_TYPE prvTaskRebootCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  144. /*
  145. * Implements the systime command.
  146. */
  147. static portBASE_TYPE prvTaskSystimeCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  148. /*
  149. * Implements the ntp command.
  150. */
  151. static portBASE_TYPE prvTaskNTPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  152. /*
  153. * Implements the network command.
  154. */
  155. static portBASE_TYPE prvTaskNetworkCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  156. /*
  157. * Implements the snmp command.
  158. */
  159. static portBASE_TYPE prvTaskSNMPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  160. /*
  161. * Implements the AKB command.
  162. */
  163. static portBASE_TYPE prvTaskAKBCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  164. /*
  165. * Implements the alarm command.
  166. */
  167. static portBASE_TYPE prvTaskAlarmCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  168. #ifdef HARDWARE_BT6708
  169. /*
  170. * Implements the whitelist command.
  171. */
  172. static portBASE_TYPE prvTaskWhiteListCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  173. #endif
  174. /*
  175. * Implements the change password command.
  176. */
  177. static portBASE_TYPE prvTaskUserCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  178. /*
  179. * Implements the config command.
  180. */
  181. static portBASE_TYPE prvTaskConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  182. /*
  183. * Implements the netconfig command.
  184. */
  185. static portBASE_TYPE prvTaskNetConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  186. /*
  187. * Implements the history command.
  188. */
  189. static portBASE_TYPE prvTaskHistoryCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  190. /*
  191. * Implements the sensor info command.
  192. */
  193. static portBASE_TYPE prvTaskSensorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  194. /*
  195. * Implements the firmware download http command.
  196. */
  197. static portBASE_TYPE prvTaskUploadCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  198. /*
  199. * Implements the ups command.
  200. */
  201. static portBASE_TYPE prvTaskUPSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  202. /* Structure that defines the "info" command line command. This
  203. generates a table that shows how much run time each task has */
  204. static const CLI_Command_Definition_t prvInfoCommandDefinition =
  205. {
  206. ( const int8_t * const ) "info", /* The command string to type. */
  207. ( const int8_t * const ) "\tinfo: вывод информации о контроллере\r\n"
  208. "\tinfo name <name>: установка поля \"название устройства\"\r\n"
  209. "\tinfo address <adrr>: установка поля \"адрес расположения контролируемого объекта\"\r\n"
  210. "\tinfo owner <owner>: установка поля \"организация (собственник)\"\r\n"
  211. "\tinfo comments <comment>: установка поля \"комментарии\"\r\n",
  212. prvTaskInfoCommand, /* The function to run. */
  213. -1 /* The user can enter any number of commands. */
  214. };
  215. /* Structure that defines the "reboot" command line command. This
  216. generates a table that shows how much run time each task has */
  217. static const CLI_Command_Definition_t prvRebootCommandDefinition =
  218. {
  219. ( const int8_t * const ) "reboot", /* The command string to type. */
  220. ( const int8_t * const ) "\treboot: перезагрузка Контроллера\r\n",
  221. prvTaskRebootCommand, /* The function to run. */
  222. 0 /* No parameters are expected. */
  223. };
  224. /* Structure that defines the "systime" command line command. This
  225. generates a table that shows how much run time each task has */
  226. static const CLI_Command_Definition_t prvSystimeCommandDefinition =
  227. {
  228. ( const int8_t * const ) "systime", /* The command string to type. */
  229. ( const int8_t * const ) "\tsystime: вывод системного времени\r\n"
  230. "\tsystime date <YYYY-MM-DD>: установка даты\r\n"
  231. "\tsystime time <HH:MM>: установка времени\r\n",
  232. prvTaskSystimeCommand, /* The function to run. */
  233. -1 /* The user can enter any number of commands. */
  234. };
  235. /* Structure that defines the "ntp" command line command. This
  236. generates a table that shows how much run time each task has */
  237. static const CLI_Command_Definition_t prvNTPCommandDefinition =
  238. {
  239. ( const int8_t * const ) "ntp", /* The command string to type. */
  240. ( const int8_t * const ) "\tntp ENA|DIS: разрешение/запрет синхронизации времени\r\n"
  241. "\tntp set IP <A.B.C.D>: установка сервера NTP\r\n"
  242. "\tntp info: вывод информации о сервере NTP\r\n"
  243. "\tntp set gmt <SIGN><NUM>: установка часового пояса\r\n",
  244. prvTaskNTPCommand, /* The function to run. */
  245. -1 /* The user can enter any number of commands. */
  246. };
  247. /* Structure that defines the "network" command line command. This
  248. generates a table that shows how much run time each task has */
  249. static const CLI_Command_Definition_t prvNetworkCommandDefinition =
  250. {
  251. ( const int8_t * const ) "network", /* The command string to type. */
  252. ( const int8_t * const ) "\tnetwork info вывод информации о текущих сетевых настройках:\r\n"
  253. "\tnetwork dhcp ENA|DIS: разрешение/запрет получения IP по DHCP\r\n"
  254. "\tnetwork ip <A.B.C.D>: установка статического IP\r\n"
  255. "\tnetwork gw <A.B.C.D>: установка шлюза\r\n"
  256. "\tnetwork mask <A.B.C.D>: установка маски подсети\r\n",
  257. prvTaskNetworkCommand, /* The function to run. */
  258. -1 /* The user can enter any number of commands. */
  259. };
  260. /* Structure that defines the "snmp" command line command. This
  261. generates a table that shows how much run time each task has */
  262. static const CLI_Command_Definition_t prvSNMPCommandDefinition =
  263. {
  264. ( const int8_t * const ) "snmp", /* The command string to type. */
  265. ( const int8_t * const ) "\tsnmp info: вывод информации о текущих SNMP настройках\r\n"
  266. "\tsnmp server <NUM> <A.B.C.D>: установка сервера SNMP\r\n"
  267. "\tsnmp community read <read>: установка Read community\r\n"
  268. "\tsnmp community write <write>: установка Write community\r\n",
  269. prvTaskSNMPCommand, /* The function to run. */
  270. -1 /* The user can enter any number of commands. */
  271. };
  272. /* Structure that defines the "akb" command line command. This
  273. generates a table that shows how much run time each task has */
  274. static const CLI_Command_Definition_t prvAKBCommandDefinition =
  275. {
  276. ( const int8_t * const ) "akb", /* The command string to type. */
  277. ( const int8_t * const ) "\takb info: вывод информации о параметрах АКБ\r\n"
  278. "\takb voltcellmin <value>: ввод минимального напряжения на ячейки АКБ (В)\r\n"
  279. "\takb voltcellmax <value>: ввод максимального напряжения на ячейки АКБ (В)\r\n",
  280. prvTaskAKBCommand, /* The function to run. */
  281. -1 /* The user can enter any number of commands. */
  282. };
  283. /* Structure that defines the "alarm" command line command. This
  284. generates a table that shows how much run time each task has */
  285. static const CLI_Command_Definition_t prvAlarmCommandDefinition =
  286. {
  287. ( const int8_t * const ) "alarm", /* The command string to type. */
  288. ( const int8_t * const ) "\talarm info: вывод информации о параметрах АКБ\r\n"
  289. "\talarm temp low <value>: ввод нижней границы аварии по температуре (С)\r\n"
  290. "\talarm temp high <value>: ввод верxней границы аварии по температуре (С)\r\n"
  291. "\talarm temp hist <value>: ввод гистерезиса аварии по температуре (С)\r\n"
  292. "\talarm load high <value>: ввод верхней границы аварии по нагрузке (%)\r\n"
  293. "\talarm load hist <value>: ввод гистерезиса аварии по нагрузке (%)\r\n"
  294. "\talarm vout low <value>: ввод нижней границы аварии по вых. напряжению (В)\r\n"
  295. "\talarm vout high <value>: ввод верxней границы аварии по вых. напряжению (В)\r\n"
  296. "\talarm vout hist <value>: ввод гистерезиса аварии по вых. напряжению (В)\r\n",
  297. prvTaskAlarmCommand, /* The function to run. */
  298. -1 /* The user can enter any number of commands. */
  299. };
  300. #ifdef HARDWARE_BT6708
  301. /* Structure that defines the "whitelist" command line command. This
  302. generates a table that shows how much run time each task has */
  303. static const CLI_Command_Definition_t prvWhiteListCommandDefinition =
  304. {
  305. ( const int8_t * const ) "whitelist", /* The command string to type. */
  306. ( const int8_t * const ) "\twhitelist info: вывод информации о текущем белом списке IP адресов контроллера\r\n"
  307. "\twhitelist range <NUM> <A.B.C.D/E>: установка диапазона IP адресов\r\n",
  308. prvTaskWhiteListCommand, /* The function to run. */
  309. -1 /* The user can enter any number of commands. */
  310. };
  311. #endif
  312. /* Structure that defines the "user" command line command. This
  313. generates a table that shows how much run time each task has */
  314. static const CLI_Command_Definition_t prvUserCommandDefinition =
  315. {
  316. ( const int8_t * const ) "user", /* The command string to type. */
  317. ( const int8_t * const ) "\tuser passwd <name>: установка пароля для пользователя <name>\r\n",
  318. prvTaskUserCommand, /* The function to run. */
  319. 2 /* Two parameters are expected, which can take any value. */
  320. };
  321. /* Structure that defines the "config" command line command. This
  322. generates a table that shows how much run time each task has */
  323. static const CLI_Command_Definition_t prvConfigCommandDefinition =
  324. {
  325. ( const int8_t * const ) "config", /* The command string to type. */
  326. ( const int8_t * const ) "\tconfig info: вывод информации о состоянии конфигураций\r\n"
  327. "\tconfig load default: загрузка конфигурации по умолчанию\r\n",
  328. prvTaskConfigCommand, /* The function to run. */
  329. -1 /* Two parameters are expected, which can take any value. */
  330. };
  331. /* Structure that defines the "config" command line command. This
  332. generates a table that shows how much run time each task has */
  333. static const CLI_Command_Definition_t prvNetConfigCommandDefinition =
  334. {
  335. ( const int8_t * const ) "netconfig", /* The command string to type. */
  336. ( const int8_t * const ) "\tnetconfig apply: применение конфигурации сетевых настроек\r\n"
  337. "\tnetconfig confirm: подтверждение конфигурации сетевых настроек\r\n",
  338. prvTaskNetConfigCommand, /* The function to run. */
  339. 1 /* Two parameters are expected, which can take any value. */
  340. };
  341. /* Structure that defines the "history" command line command. This
  342. generates a table that shows how much run time each task has */
  343. static const CLI_Command_Definition_t prvHistoryCommandDefinition =
  344. {
  345. ( const int8_t * const ) "history", /* The command string to type. */
  346. ( const int8_t * const ) "\thistory show EVENTS|UPS <num_page>: вывод журнала\r\n",
  347. prvTaskHistoryCommand, /* The function to run. */
  348. 3 /* Two parameters are expected, which can take any value. */
  349. };
  350. /* Structure that defines the "sensor info" command line command. This
  351. generates a table that shows how much run time each task has */
  352. static const CLI_Command_Definition_t prvSensorCommandDefinition =
  353. {
  354. ( const int8_t * const ) "sensor", /* The command string to type. */
  355. ( const int8_t * const ) "\tsensor info: вывод параметров системы\r\n"
  356. #ifdef HARDWARE_BT6706
  357. "\tsensor setup DI <num> <state>: установка нормального состояния сухого контакта:\r\n"
  358. "\t\t\t\t0 - разомкнутое состояние\r\n"
  359. "\t\t\t\t1 - замкнутое состояние\r\n"
  360. "\tsensor setup DO <num> <issue>: установка источника срабатывания реле:\r\n"
  361. "\t\t\t\t1 - Наличие сети\r\n"
  362. "\t\t\t\t2 - Наличие выходного напряжения\r\n"
  363. "\t\t\t\t3 - Разряд АКБ\r\n"
  364. "\t\t\t\t4 - Отключение АКБ\r\n"
  365. "\t\t\t\t5 - SNMP SET\r\n"
  366. #endif
  367. ,
  368. prvTaskSensorCommand, /* The function to run. */
  369. -1 /* No parameters are expected. */
  370. };
  371. /* Structure that defines the "firmware dowmload http" command line command. This
  372. generates a table that shows how much run time each task has */
  373. static const CLI_Command_Definition_t prvUploadCommandDefinition =
  374. {
  375. ( const int8_t * const ) "firmware download http", /* The command string to type. */
  376. ( const int8_t * const ) "\tfirmware download http: переход в режим обновления через Web-сервер\r\n",
  377. prvTaskUploadCommand, /* The function to run. */
  378. 2 /* No parameters are expected. */
  379. };
  380. /* Structure that defines the "ups" command line command. This
  381. generates a table that shows how much run time each task has */
  382. static const CLI_Command_Definition_t prvUPSCommandDefinition =
  383. {
  384. ( const int8_t * const ) "ups", /* The command string to type. */
  385. ( const int8_t * const ) "\tups battest <num>: управление процедурой тестирования АКБ:\r\n"
  386. "\t\t\t\t0 - Остановить тестирование\r\n"
  387. "\t\t\t\t1-99 - Запустить тест на x минут\r\n"
  388. "\t\t\t\t100 - Тестирование в течение 10 секунд\r\n"
  389. "\t\t\t\t999 - Тестирование до разряда\r\n"
  390. "\tups shutdown <num>: управление отключением нагрузки ИБП:\r\n"
  391. "\t\t\t\t0 - Остановить процедуру отключения нагрузки\r\n"
  392. "\t\t\t\tn - Отключить нагрузку через n минут\r\n"
  393. "\t\t\t\tn: 0.2, 0.3, ..., 1, 2, ..., 10\r\n",
  394. prvTaskUPSCommand, /* The function to run. */
  395. 2 /* Two parameters are expected, which can take any value. */
  396. };
  397. /* Structure that defines the "quit" command line command. This
  398. generates a table that shows how much run time each task has */
  399. static const CLI_Command_Definition_t prvQuitCommandDefinition =
  400. {
  401. ( const int8_t * const ) "quit", /* The command string to type. */
  402. ( const int8_t * const ) "\tquit: завершение сессии\r\n",
  403. NULL, /* The function to run. */
  404. -1 /* The user can enter any number of commands. */
  405. };
  406. /*-----------------------------------------------------------*/
  407. void vRegisterCLICommands( void )
  408. {
  409. /* Register all the command line commands defined immediately above. */
  410. FreeRTOS_CLIRegisterCommand( &prvInfoCommandDefinition );
  411. FreeRTOS_CLIRegisterCommand( &prvRebootCommandDefinition );
  412. FreeRTOS_CLIRegisterCommand( &prvSystimeCommandDefinition );
  413. FreeRTOS_CLIRegisterCommand( &prvNTPCommandDefinition );
  414. FreeRTOS_CLIRegisterCommand( &prvNetworkCommandDefinition );
  415. FreeRTOS_CLIRegisterCommand( &prvSNMPCommandDefinition );
  416. FreeRTOS_CLIRegisterCommand( &prvAKBCommandDefinition );
  417. FreeRTOS_CLIRegisterCommand( &prvAlarmCommandDefinition );
  418. #ifdef HARDWARE_BT6708
  419. FreeRTOS_CLIRegisterCommand( &prvWhiteListCommandDefinition );
  420. #endif
  421. FreeRTOS_CLIRegisterCommand( &prvUserCommandDefinition );
  422. FreeRTOS_CLIRegisterCommand( &prvConfigCommandDefinition );
  423. FreeRTOS_CLIRegisterCommand( &prvNetConfigCommandDefinition );
  424. FreeRTOS_CLIRegisterCommand( &prvHistoryCommandDefinition );
  425. FreeRTOS_CLIRegisterCommand( &prvSensorCommandDefinition );
  426. FreeRTOS_CLIRegisterCommand( &prvUploadCommandDefinition );
  427. FreeRTOS_CLIRegisterCommand( &prvUPSCommandDefinition );
  428. FreeRTOS_CLIRegisterCommand( &prvQuitCommandDefinition );
  429. }
  430. /*-----------------------------------------------------------*/
  431. static portBASE_TYPE prvTaskInfoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  432. {
  433. int8_t *pcParameterString;
  434. signed portBASE_TYPE xParameterStringLength, xReturn;
  435. portBASE_TYPE xParameterNumber = 1;
  436. char str[110];
  437. uint8_t len;
  438. int8_t num_arg = 0;
  439. uint8_t i;
  440. static uint8_t page = 0;
  441. ( void ) pcCommandString;
  442. ( void ) xWriteBufferLen;
  443. configASSERT( pcWriteBuffer );
  444. num_arg = prvGetNumberOfParameters(pcCommandString);
  445. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  446. if(num_arg == 0){
  447. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n**************Информация о Контроллере**************\r\n";
  448. const int8_t * const pcUPSInfoTableHeader = ( int8_t * ) "\r\n*****************Информация об ИБП******************\r\n";
  449. if(!page){
  450. /* Return the next command help string, before moving the pointer on to
  451. the next command in the list. */
  452. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  453. GetWorkTimeStr(str, &len);
  454. strcat(( char * ) pcWriteBuffer, "Время работы:\t\t\t");
  455. strncat(( char * ) pcWriteBuffer, str, len);
  456. strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
  457. GetModelStr(str, &len);
  458. strncat(( char * ) pcWriteBuffer, str, len);
  459. strcat(( char * ) pcWriteBuffer, "\r\nДата производства:\t\t");
  460. GetProductionDataStr(str, &len);
  461. strncat(( char * ) pcWriteBuffer, str, len);
  462. strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
  463. GetVersionStr(str, &len);
  464. strncat(( char * ) pcWriteBuffer, str, len);
  465. strcat(( char * ) pcWriteBuffer, "\r\nMAC адрес:\t\t\t");
  466. GetMacStr(str, &len);
  467. strncat(( char * ) pcWriteBuffer, str, len);
  468. strcat(( char * ) pcWriteBuffer, "\r\nСерийный номер:\t\t\t");
  469. GetSerialNumberStr(str, &len);
  470. strncat(( char * ) pcWriteBuffer, str, len);
  471. strcat(( char * ) pcWriteBuffer, "\r\nНазвание устройства:\t\t");
  472. GetNameDeviceStr(str, &len);
  473. strncat(( char * ) pcWriteBuffer, str, len);
  474. strcat(( char * ) pcWriteBuffer, "\r\nВладелец:\t\t\t");
  475. GetOwnerStr(str, &len);
  476. strncat(( char * ) pcWriteBuffer, str, len);
  477. strcat(( char * ) pcWriteBuffer, "\r\nМестоположение:\t\t\t");
  478. GetLocationStr(str, &len);
  479. strncat(( char * ) pcWriteBuffer, str, len);
  480. strcat(( char * ) pcWriteBuffer, "\r\nКомментарии:\t\t\t");
  481. GetCommentsStr(str, &len);
  482. strncat(( char * ) pcWriteBuffer, str, len);
  483. page = 1;
  484. xReturn = pdTRUE;
  485. }
  486. else{
  487. strncat( ( char * ) pcWriteBuffer, ( const char * ) pcUPSInfoTableHeader, strlen( ( char * ) pcUPSInfoTableHeader ) );
  488. strcat(( char * ) pcWriteBuffer, "\r\nКомпания:\t\t\tАО\"НПК РоТеК\"");
  489. strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
  490. GetUPSModelStr(str, &len);
  491. strncat(( char * ) pcWriteBuffer, str, len);
  492. strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
  493. GetUPSVersionStr(str, &len);
  494. strncat(( char * ) pcWriteBuffer, str, len);
  495. strcat(( char * ) pcWriteBuffer, "\r\n");
  496. page = 0;
  497. /* There are no more commands in the list, so there will be no more
  498. strings to return after this one and pdFALSE should be returned. */
  499. xReturn = pdFALSE;
  500. }
  501. }
  502. else if(num_arg == 1)
  503. {
  504. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  505. xReturn = pdFALSE;
  506. }
  507. else{
  508. /* Obtain the parameter string. */
  509. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  510. (
  511. pcCommandString, /* The command string itself. */
  512. xParameterNumber, /* Return the next parameter. */
  513. &xParameterStringLength /* Store the parameter string length. */
  514. );
  515. for(i = 0; i < INFO_ALL_ARGS; i ++){
  516. if( strncmp( ( const char * ) pcParameterString, info_args_list[i], strlen(info_args_list[i]) ) == 0 ){
  517. break;
  518. }
  519. }
  520. xParameterNumber ++;
  521. // xParameterNumber ++;
  522. /* Obtain the parameter string. */
  523. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  524. (
  525. pcCommandString, /* The command string itself. */
  526. xParameterNumber, /* Return the next parameter. */
  527. &xParameterStringLength /* Store the parameter string length. */
  528. );
  529. memset(str, 0, sizeof(str));
  530. xParameterStringLength = strlen(( const char * ) pcParameterString);
  531. if(xParameterStringLength > (int32_t)sizeof(str))
  532. xParameterStringLength = sizeof(str) - 1;
  533. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  534. if(control_string_en_digit(str, strlen(str))){
  535. switch(i){
  536. case INFO_DEV_NAME:
  537. if(telnet_code_auth == ADMIN){
  538. str[19] = 0;
  539. SetNameDeviceStr(str);
  540. }
  541. else
  542. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  543. break;
  544. case INFO_ADDRESS:
  545. if(telnet_code_auth == ADMIN)
  546. {
  547. str[109] = 0;
  548. SetLocation(str);
  549. }
  550. else
  551. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  552. break;
  553. case INFO_OWNER:
  554. if(telnet_code_auth == ADMIN){
  555. str[49] = 0;
  556. SetOwner(str);
  557. }
  558. else
  559. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  560. break;
  561. case INFO_COMMENTS:
  562. if(telnet_code_auth == ADMIN){
  563. str[109] = 0;
  564. SetComment(str);
  565. }
  566. else
  567. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  568. break;
  569. default:
  570. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  571. break;
  572. }
  573. if(i >= INFO_ADDRESS && i <= INFO_COMMENTS){
  574. SETTINGS_Save();
  575. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  576. }
  577. }
  578. else{
  579. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  580. }
  581. xReturn = pdFALSE;
  582. }
  583. return xReturn;
  584. }
  585. static portBASE_TYPE prvTaskRebootCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  586. static bool start_reboot = true;
  587. const int8_t *const pcRebootHeader = ( int8_t * ) "Контроллер будет перезагружен через 1 секунду\r\n";
  588. ( void ) pcCommandString;
  589. ( void ) xWriteBufferLen;
  590. if(telnet_code_auth != ADMIN){
  591. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  592. return pdFALSE;
  593. }
  594. if(start_reboot){
  595. start_reboot = false;
  596. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcRebootHeader );
  597. return pdTRUE;
  598. }
  599. else{
  600. telnet_act = true;
  601. Reboot();
  602. return pdFALSE;
  603. }
  604. }
  605. static portBASE_TYPE prvTaskSystimeCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  606. int8_t *pcParameterString;
  607. signed portBASE_TYPE xParameterStringLength, xReturn;
  608. portBASE_TYPE xParameterNumber = 1;
  609. char str[110];
  610. uint8_t len;
  611. uint8_t i;
  612. uint8_t fail = 0;
  613. uint16_t temp = 0;
  614. ( void ) pcCommandString;
  615. ( void ) xWriteBufferLen;
  616. configASSERT( pcWriteBuffer );
  617. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  618. /* Obtain the parameter string. */
  619. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  620. (
  621. pcCommandString, /* The command string itself. */
  622. xParameterNumber, /* Return the next parameter. */
  623. &xParameterStringLength /* Store the parameter string length. */
  624. );
  625. if(pcParameterString == NULL){
  626. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n******Системное время Контроллера******\r\n";
  627. /* Return the next command help string, before moving the pointer on to
  628. the next command in the list. */
  629. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  630. GetDateStr(str, &len);
  631. strcat(( char * ) pcWriteBuffer, "Дата:\t\t\t");
  632. strncat(( char * ) pcWriteBuffer, str, len);
  633. strcat(( char * ) pcWriteBuffer, "\r\nВремя:\t\t\t");
  634. GetTimeStr(str, &len);
  635. strncat(( char * ) pcWriteBuffer, str, len);
  636. strcat(( char * ) pcWriteBuffer, "\r\n");
  637. /* There are no more commands in the list, so there will be no more
  638. strings to return after this one and pdFALSE should be returned. */
  639. xReturn = pdFALSE;
  640. }
  641. else{
  642. if(telnet_code_auth != ADMIN){
  643. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  644. return pdFALSE;
  645. }
  646. for(i = 0; i < ARG_SYSTIME_ALL; i ++){
  647. if( strncmp( ( const char * ) pcParameterString, systime_args_list[i], strlen(systime_args_list[i]) ) == 0 ){
  648. break;
  649. }
  650. }
  651. if(i != ARG_SYSTIME_ALL){
  652. if(sSettings.sSNTP.sntpEnable){
  653. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSystymeDenied, strlen( ( char * ) pcSystymeDenied ) );
  654. return pdFALSE;
  655. }
  656. }
  657. xParameterNumber ++;
  658. /* Obtain the parameter string. */
  659. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  660. (
  661. pcCommandString, /* The command string itself. */
  662. xParameterNumber, /* Return the next parameter. */
  663. &xParameterStringLength /* Store the parameter string length. */
  664. );
  665. if(pcParameterString == NULL){
  666. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  667. return pdFALSE;
  668. }
  669. memset(str, 0, sizeof(str));
  670. xParameterStringLength = strlen(( const char * ) pcParameterString);
  671. if(xParameterStringLength > (int32_t)sizeof(str))
  672. xParameterStringLength = sizeof(str) - 1;
  673. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  674. switch(i){
  675. case ARG_SYSTIME_DATA:
  676. if(xParameterStringLength == 10){
  677. for(uint8_t j = 0; j < xParameterStringLength; j++)
  678. {
  679. if(j != 4 && j != 7)
  680. {
  681. if(str[j] > 0x39 || str[j] < 0x30){
  682. fail = 1;
  683. }
  684. }
  685. else if(j == 4 || j == 7){
  686. if(str[j] != '-')
  687. fail = 1;
  688. }
  689. }
  690. if(!fail)
  691. {
  692. temp = 1000*(str[0] - 0x30) + 100*(str[1] - 0x30) + 10*(str[2] - 0x30) + str[3] - 0x30;
  693. if(temp > 2099 || temp < 2000)
  694. fail = 1;
  695. temp = 0;
  696. temp = 10*(str[5] - 0x30) + (str[6] - 0x30);
  697. if(temp > 12)
  698. fail = 1;
  699. temp = 0;
  700. temp = 10*(str[8] - 0x30) + (str[9] - 0x30);
  701. if(temp > 31)
  702. fail = 1;
  703. }
  704. }
  705. else{
  706. fail = 1;
  707. }
  708. if(!fail){
  709. SetDateStr(str);
  710. SETTINGS_Save();
  711. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  712. }
  713. else
  714. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  715. break;
  716. case ARG_SYSTIME_TIME:
  717. if(xParameterStringLength == 5){
  718. for(uint8_t j = 0; j < xParameterStringLength; j++)
  719. {
  720. if(j != 2)
  721. {
  722. if(str[j] > 0x39 || str[j] < 0x30)
  723. fail = 1;
  724. }
  725. else if(j == 2){
  726. if(str[j] != ':')
  727. fail = 1;
  728. }
  729. }
  730. if(!fail)
  731. {
  732. temp = 10*(str[0] - 0x30) + (str[1] - 0x30);
  733. if(temp > 23)
  734. fail = 1;
  735. temp = 0;
  736. temp = 10*(str[3] - 0x30) + (str[4] - 0x30);
  737. if(temp > 59)
  738. fail = 1;
  739. }
  740. }
  741. else{
  742. fail = 1;
  743. }
  744. if(!fail){
  745. SetTimeStr(str);
  746. SETTINGS_Save();
  747. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  748. }
  749. else
  750. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  751. break;
  752. default:
  753. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  754. break;
  755. }
  756. xReturn = pdFALSE;
  757. }
  758. return xReturn;
  759. }
  760. /*
  761. * Implements the ntp command.
  762. */
  763. static portBASE_TYPE prvTaskNTPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  764. int8_t *pcParameterString;
  765. signed portBASE_TYPE xParameterStringLength, xReturn;
  766. portBASE_TYPE xParameterNumber = 1;
  767. char str[110];
  768. char str_temp[110];
  769. uint8_t len;
  770. uint8_t i;
  771. bool enable_old_sntp;
  772. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n************NTP настройки Контроллера************\r\n";
  773. ( void ) pcCommandString;
  774. ( void ) xWriteBufferLen;
  775. configASSERT( pcWriteBuffer );
  776. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  777. /* Obtain the parameter string. */
  778. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  779. (
  780. pcCommandString, /* The command string itself. */
  781. xParameterNumber, /* Return the next parameter. */
  782. &xParameterStringLength /* Store the parameter string length. */
  783. );
  784. if(pcParameterString == NULL){
  785. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  786. return pdFALSE;
  787. }
  788. for(i = 0; i < ARG_NTP_ALL; i ++){
  789. if( strncmp( ( const char * ) pcParameterString, ntp_args_list[i], strlen(ntp_args_list[i]) ) == 0 ){
  790. break;
  791. }
  792. }
  793. if(telnet_code_auth != ADMIN && i !=ARG_NTP_INFO){
  794. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  795. return pdFALSE;
  796. }
  797. xParameterNumber ++;
  798. /* Obtain the parameter string. */
  799. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  800. (
  801. pcCommandString, /* The command string itself. */
  802. xParameterNumber, /* Return the next parameter. */
  803. &xParameterStringLength /* Store the parameter string length. */
  804. );
  805. xParameterNumber ++;
  806. if(pcParameterString == NULL){
  807. switch(i){
  808. case ARG_NTP_ENABLE:
  809. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  810. SetSntpStateStr("1");
  811. if(sSettings.sSNTP.sntpEnable != enable_old_sntp){
  812. SETTINGS_Save();
  813. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  814. SNTP_Init();
  815. //vTaskDelay(7000);
  816. SNTP_Poll();
  817. }
  818. break;
  819. case ARG_NTP_DISABLE:
  820. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  821. SetSntpStateStr("0");
  822. if(sSettings.sSNTP.sntpEnable != enable_old_sntp){
  823. SETTINGS_Save();
  824. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  825. SNTP_Init();
  826. //vTaskDelay(7000);
  827. SNTP_Poll();
  828. }
  829. break;
  830. case ARG_NTP_INFO:
  831. /* Return the next command help string, before moving the pointer on to
  832. the next command in the list. */
  833. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  834. GetSntpStateStrRU(str, &len);
  835. strcat(( char * ) pcWriteBuffer, "Режим установки времени:\t");
  836. strncat(( char * ) pcWriteBuffer, str, len);
  837. strcat(( char * ) pcWriteBuffer, "\r\nIP адрес NTP сервера:\t\t");
  838. GetSntpServerIpStr(str, &len);
  839. strncat(( char * ) pcWriteBuffer, str, len);
  840. strcat(( char * ) pcWriteBuffer, "\r\nЧасовой пояс:\t\t\t");
  841. GetSntpTimeZoneStr(str, &len);
  842. strncat(( char * ) pcWriteBuffer, str, len);
  843. strcat(( char * ) pcWriteBuffer, "\r\nПоследняя дата синхронизации:\t");
  844. GetSntpLastDataStr(str, &len);
  845. strncat(( char * ) pcWriteBuffer, str, len);
  846. strcat(( char * ) pcWriteBuffer, "\r\n");
  847. break;
  848. default:
  849. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  850. break;
  851. }
  852. return pdFALSE;
  853. }
  854. if(i == ARG_NTP_SET){
  855. memset(str, 0, sizeof(str));
  856. if(xParameterStringLength > (int32_t)sizeof(str))
  857. xParameterStringLength = sizeof(str) - 1;
  858. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  859. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  860. (
  861. pcCommandString, /* The command string itself. */
  862. xParameterNumber, /* Return the next parameter. */
  863. &xParameterStringLength /* Store the parameter string length. */
  864. );
  865. if(pcParameterString != NULL){
  866. memset(str_temp, 0, sizeof(str_temp));
  867. if(xParameterStringLength > (int32_t)sizeof(str_temp))
  868. xParameterStringLength = sizeof(str_temp) - 1;
  869. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  870. if(strncmp(str, "IP", 2) == 0){
  871. if(xParameterStringLength <= 15){
  872. if(ipaddr_addr(str_temp) != IPADDR_NONE){
  873. if(strncmp(str_temp, sSettings.sSNTP.ip, strlen(str_temp)) != 0){
  874. SetSntpServerIpStr(str_temp);
  875. SETTINGS_Save();
  876. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  877. SNTP_Init();
  878. //vTaskDelay(7000);
  879. SNTP_Poll();
  880. }
  881. }
  882. else{
  883. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  884. }
  885. }
  886. else{
  887. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  888. }
  889. }
  890. else if(strncmp(str, "gmt", 3) == 0){
  891. if(xParameterStringLength > 1 && xParameterStringLength < 5){
  892. bool fail = false;
  893. if(str_temp[0] != '-' && str_temp[0] != '+')
  894. fail = true;
  895. if(!isdigit_int(str_temp[1]) && (!isdigit_int(str_temp[2]) && str_temp[2] != '.') && (!isdigit_int(str_temp[3]) && str_temp[3] != '.'))
  896. fail = true;
  897. if(xParameterStringLength == 5){
  898. if(!isdigit_int(str_temp[4]))
  899. fail = true;
  900. }
  901. if(!fail){
  902. float value = atof(str_temp);
  903. if(value > -12.0 && value < 12.0){
  904. SetSntpTimeZoneStr(str_temp);
  905. SETTINGS_Save();
  906. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  907. }
  908. else
  909. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  910. }
  911. else{
  912. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  913. }
  914. }
  915. else{
  916. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  917. }
  918. }
  919. else{
  920. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  921. }
  922. }
  923. else{
  924. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  925. }
  926. }
  927. else{
  928. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  929. }
  930. xReturn = pdFALSE;
  931. return xReturn;
  932. }
  933. /*
  934. * Implements the network command.
  935. */
  936. static portBASE_TYPE prvTaskNetworkCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  937. int8_t *pcParameterString;
  938. signed portBASE_TYPE xParameterStringLength, xReturn;
  939. portBASE_TYPE xParameterNumber = 1;
  940. char str[110];
  941. uint8_t i;
  942. ( void ) pcCommandString;
  943. ( void ) xWriteBufferLen;
  944. configASSERT( pcWriteBuffer );
  945. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  946. /* Obtain the parameter string. */
  947. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  948. (
  949. pcCommandString, /* The command string itself. */
  950. xParameterNumber, /* Return the next parameter. */
  951. &xParameterStringLength /* Store the parameter string length. */
  952. );
  953. if(pcParameterString == NULL){
  954. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  955. return pdFALSE;
  956. }
  957. for(i = 0; i < ARG_NETWORK_ALL; i ++){
  958. if( strncmp( ( const char * ) pcParameterString, network_args_list[i], strlen(network_args_list[i]) ) == 0 ){
  959. break;
  960. }
  961. }
  962. if(telnet_code_auth != ADMIN && i !=ARG_NETWORK_INFO){
  963. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  964. return pdFALSE;
  965. }
  966. if(i != ARG_NETWORK_ALL && i != ARG_NETWORK_DHCP && i != ARG_NETWORK_INFO){
  967. if(sSettings.sWebTempParams.dhcpEnable){
  968. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  969. return pdFALSE;
  970. }
  971. }
  972. xParameterNumber ++;
  973. /* Obtain the parameter string. */
  974. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  975. (
  976. pcCommandString, /* The command string itself. */
  977. xParameterNumber, /* Return the next parameter. */
  978. &xParameterStringLength /* Store the parameter string length. */
  979. );
  980. if(pcParameterString == NULL){
  981. if(i == ARG_NETWORK_INFO){
  982. net_config_param(pcWriteBuffer);
  983. }
  984. else{
  985. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  986. }
  987. return pdFALSE;
  988. }
  989. memset(str, 0, sizeof(str));
  990. xParameterStringLength = strlen(( const char * ) pcParameterString);
  991. if(xParameterStringLength > (int32_t)sizeof(str))
  992. xParameterStringLength = sizeof(str) - 1;
  993. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  994. switch(i){
  995. case ARG_NETWORK_DHCP:
  996. if(strncmp(str, "ENA", 3) == 0){
  997. SetUDPDhcpStateStr("True");
  998. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  999. }
  1000. else if(strncmp(str, "DIS", 3) == 0){
  1001. SetUDPDhcpStateStr("False");
  1002. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1003. }
  1004. else
  1005. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1006. break;
  1007. case ARG_NETWORK_IP:
  1008. if(xParameterStringLength <= 15){
  1009. if(ipaddr_addr(str) != IPADDR_NONE){
  1010. SetIPStr(str);
  1011. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1012. }
  1013. else
  1014. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1015. }
  1016. else{
  1017. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1018. }
  1019. break;
  1020. case ARG_NETWORK_GW:
  1021. if(xParameterStringLength <= 15){
  1022. if(ipaddr_addr(str) != IPADDR_NONE){
  1023. SetGatewayStr(str);
  1024. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1025. }
  1026. else
  1027. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1028. }
  1029. else{
  1030. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1031. }
  1032. break;
  1033. case ARG_NETWORK_MASK:
  1034. if(xParameterStringLength <= 15){
  1035. if(ipaddr_addr(str) != IPADDR_NONE){
  1036. SetMaskStr(str);
  1037. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1038. }
  1039. else
  1040. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1041. }
  1042. else{
  1043. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1044. }
  1045. break;
  1046. default:
  1047. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1048. break;
  1049. }
  1050. xReturn = pdFALSE;
  1051. return xReturn;
  1052. }
  1053. /*
  1054. * Implements the snmp command.
  1055. */
  1056. static portBASE_TYPE prvTaskSNMPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1057. int8_t *pcParameterString;
  1058. signed portBASE_TYPE xParameterStringLength, xReturn;
  1059. portBASE_TYPE xParameterNumber = 1;
  1060. char str[20];
  1061. char temp_str[20];
  1062. uint8_t i;
  1063. ( void ) pcCommandString;
  1064. ( void ) xWriteBufferLen;
  1065. configASSERT( pcWriteBuffer );
  1066. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1067. /* Obtain the parameter string. */
  1068. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1069. (
  1070. pcCommandString, /* The command string itself. */
  1071. xParameterNumber, /* Return the next parameter. */
  1072. &xParameterStringLength /* Store the parameter string length. */
  1073. );
  1074. if(pcParameterString == NULL){
  1075. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1076. return pdFALSE;
  1077. }
  1078. for(i = 0; i < ARG_SNMP_ALL; i ++){
  1079. if( strncmp( ( const char * ) pcParameterString, snmp_args_list[i], strlen(snmp_args_list[i]) ) == 0 ){
  1080. break;
  1081. }
  1082. }
  1083. if(telnet_code_auth != ADMIN && i !=ARG_SNMP_INFO){
  1084. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1085. return pdFALSE;
  1086. }
  1087. xParameterNumber ++;
  1088. /* Obtain the parameter string. */
  1089. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1090. (
  1091. pcCommandString, /* The command string itself. */
  1092. xParameterNumber, /* Return the next parameter. */
  1093. &xParameterStringLength /* Store the parameter string length. */
  1094. );
  1095. xParameterNumber ++;
  1096. if(pcParameterString == NULL){
  1097. if(i == ARG_SNMP_INFO){
  1098. snmp_config_param(pcWriteBuffer);
  1099. }
  1100. else{
  1101. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1102. }
  1103. return pdFALSE;
  1104. }
  1105. memset(str, 0, sizeof(str));
  1106. if(xParameterStringLength > (int32_t)sizeof(str))
  1107. xParameterStringLength = sizeof(str) - 1;
  1108. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1109. switch(i){
  1110. case ARG_SNMP_SERVER:
  1111. if(xParameterStringLength == 1 && isdigit_int(str[0])){
  1112. int32_t temp = atoi(str);
  1113. if(temp > 0 && temp < 6){
  1114. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1115. (
  1116. pcCommandString, /* The command string itself. */
  1117. xParameterNumber, /* Return the next parameter. */
  1118. &xParameterStringLength /* Store the parameter string length. */
  1119. );
  1120. if(pcParameterString != NULL){
  1121. memset(str, 0, sizeof(str));
  1122. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1123. if(xParameterStringLength > (int32_t)sizeof(str))
  1124. xParameterStringLength = sizeof(str) - 1;
  1125. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1126. if(xParameterStringLength <= 15){
  1127. if(ipaddr_addr(str) != IPADDR_NONE){
  1128. switch(temp){
  1129. case 1:
  1130. SetManagerIp(str);
  1131. break;
  1132. case 2:
  1133. SetManagerIp2(str);
  1134. break;
  1135. case 3:
  1136. SetManagerIp3(str);
  1137. break;
  1138. case 4:
  1139. SetManagerIp4(str);
  1140. break;
  1141. case 5:
  1142. SetManagerIp5(str);
  1143. break;
  1144. }
  1145. if(temp > 0 && temp < 6){
  1146. SETTINGS_Save();
  1147. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1148. }
  1149. }
  1150. else{
  1151. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1152. }
  1153. }
  1154. else{
  1155. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1156. }
  1157. }
  1158. else{
  1159. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1160. }
  1161. }
  1162. else{
  1163. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1164. }
  1165. }
  1166. else{
  1167. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1168. }
  1169. break;
  1170. case ARG_SNMP_COMMUNITY:
  1171. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1172. (
  1173. pcCommandString, /* The command string itself. */
  1174. xParameterNumber, /* Return the next parameter. */
  1175. &xParameterStringLength /* Store the parameter string length. */
  1176. );
  1177. if(pcParameterString != NULL){
  1178. memset(temp_str, 0, sizeof(temp_str));
  1179. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1180. if(xParameterStringLength > (int32_t)sizeof(temp_str))
  1181. xParameterStringLength = sizeof(temp_str) - 1;
  1182. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1183. if(control_string_en_digit(temp_str, strlen(temp_str))){
  1184. if(strncmp(str, "read", 4) == 0){
  1185. SetReadCommunity(temp_str);
  1186. SETTINGS_Save();
  1187. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1188. }
  1189. else if(strncmp(str, "write", 5) == 0){
  1190. SetWriteCommunity(temp_str);
  1191. SETTINGS_Save();
  1192. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1193. }
  1194. else
  1195. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1196. }
  1197. else{
  1198. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1199. }
  1200. }
  1201. else{
  1202. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1203. }
  1204. break;
  1205. default:
  1206. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1207. break;
  1208. }
  1209. xReturn = pdFALSE;
  1210. return xReturn;
  1211. }
  1212. /*
  1213. * Implements the akb command.
  1214. */
  1215. static portBASE_TYPE prvTaskAKBCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1216. int8_t *pcParameterString;
  1217. signed portBASE_TYPE xParameterStringLength, xReturn;
  1218. portBASE_TYPE xParameterNumber = 1;
  1219. char str[110];
  1220. uint8_t i;
  1221. float value = 0;
  1222. ( void ) pcCommandString;
  1223. ( void ) xWriteBufferLen;
  1224. configASSERT( pcWriteBuffer );
  1225. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1226. /* Obtain the parameter string. */
  1227. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1228. (
  1229. pcCommandString, /* The command string itself. */
  1230. xParameterNumber, /* Return the next parameter. */
  1231. &xParameterStringLength /* Store the parameter string length. */
  1232. );
  1233. if(pcParameterString == NULL){
  1234. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1235. return pdFALSE;
  1236. }
  1237. for(i = 0; i < ARG_AKB_ALL; i ++){
  1238. if( strncmp( ( const char * ) pcParameterString, akb_args_list[i], strlen(akb_args_list[i]) ) == 0 ){
  1239. break;
  1240. }
  1241. }
  1242. if(telnet_code_auth != ADMIN && i !=ARG_AKB_INFO){
  1243. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1244. return pdFALSE;
  1245. }
  1246. xParameterNumber ++;
  1247. /* Obtain the parameter string. */
  1248. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1249. (
  1250. pcCommandString, /* The command string itself. */
  1251. xParameterNumber, /* Return the next parameter. */
  1252. &xParameterStringLength /* Store the parameter string length. */
  1253. );
  1254. if(pcParameterString == NULL){
  1255. if(i == ARG_AKB_INFO){
  1256. akb_config_param(pcWriteBuffer);
  1257. }
  1258. else{
  1259. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1260. }
  1261. return pdFALSE;
  1262. }
  1263. memset(str, 0, sizeof(str));
  1264. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1265. if(xParameterStringLength > (int32_t)sizeof(str))
  1266. xParameterStringLength = sizeof(str) - 2;
  1267. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1268. for(uint8_t j = 0; j < xParameterStringLength; j ++){
  1269. if(!isfloatdigit(str[j])){
  1270. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1271. return pdFALSE;
  1272. }
  1273. }
  1274. value = atof(str);
  1275. switch(i){
  1276. case ARG_AKB_VOLT_CELL_MIN:
  1277. if(value < sSettings.UPS_Setting.Ucellmax && value > 0){
  1278. SetUPSVoltCellMinStr(str);
  1279. SETTINGS_Save();
  1280. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1281. }
  1282. else
  1283. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1284. break;
  1285. case ARG_AKB_VOLT_CELL_MAX:
  1286. if(value > sSettings.UPS_Setting.Ucellmin && value <= 3.0){
  1287. SetUPSVoltCellMaxStr(str);
  1288. SETTINGS_Save();
  1289. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1290. }
  1291. else
  1292. {
  1293. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1294. }
  1295. break;
  1296. default:
  1297. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1298. break;
  1299. }
  1300. xReturn = pdFALSE;
  1301. return xReturn;
  1302. }
  1303. /*
  1304. * Implements the alarm command.
  1305. */
  1306. static portBASE_TYPE prvTaskAlarmCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1307. int8_t *pcParameterString;
  1308. signed portBASE_TYPE xParameterStringLength, xReturn;
  1309. portBASE_TYPE xParameterNumber = 1;
  1310. char str[110];
  1311. uint8_t i, j;
  1312. float value = 0;
  1313. uint8_t k;
  1314. ( void ) pcCommandString;
  1315. ( void ) xWriteBufferLen;
  1316. configASSERT( pcWriteBuffer );
  1317. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1318. /* Obtain the parameter string. */
  1319. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1320. (
  1321. pcCommandString, /* The command string itself. */
  1322. xParameterNumber, /* Return the next parameter. */
  1323. &xParameterStringLength /* Store the parameter string length. */
  1324. );
  1325. if(pcParameterString == NULL){
  1326. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1327. return pdFALSE;
  1328. }
  1329. for(i = 0; i < ARG_ALARM_TYPE_ALL; i ++){
  1330. if( strncmp( ( const char * ) pcParameterString, type_alarm_args_list[i], strlen(type_alarm_args_list[i]) ) == 0 ){
  1331. break;
  1332. }
  1333. }
  1334. if(telnet_code_auth != ADMIN && i != ARG_ALARM_INFO){
  1335. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1336. return pdFALSE;
  1337. }
  1338. xParameterNumber ++;
  1339. /* Obtain the parameter string. */
  1340. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1341. (
  1342. pcCommandString, /* The command string itself. */
  1343. xParameterNumber, /* Return the next parameter. */
  1344. &xParameterStringLength /* Store the parameter string length. */
  1345. );
  1346. if(pcParameterString == NULL){
  1347. if(i == ARG_ALARM_INFO){
  1348. alarm_config_param(pcWriteBuffer);
  1349. }
  1350. else{
  1351. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1352. }
  1353. return pdFALSE;
  1354. }
  1355. for(j = 0; j < ARG_ALARM_ALL; j ++){
  1356. if( strncmp( ( const char * ) pcParameterString, alarm_args_list[j], strlen(alarm_args_list[j]) ) == 0 ){
  1357. break;
  1358. }
  1359. }
  1360. xParameterNumber ++;
  1361. /* Obtain the parameter string. */
  1362. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1363. (
  1364. pcCommandString, /* The command string itself. */
  1365. xParameterNumber, /* Return the next parameter. */
  1366. &xParameterStringLength /* Store the parameter string length. */
  1367. );
  1368. if(pcParameterString == NULL){
  1369. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1370. return pdFALSE;
  1371. }
  1372. memset(str, 0, sizeof(str));
  1373. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1374. if(xParameterStringLength > (int32_t)sizeof(str))
  1375. xParameterStringLength = sizeof(str) - 2;
  1376. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1377. switch(i){
  1378. case ARG_ALARM_TEMP:
  1379. switch(j){
  1380. case ARG_ALARM_LINE_LOW:
  1381. for(k = 0; k < xParameterStringLength; k ++){
  1382. if(!isdigit_int(str[k])){
  1383. if(k == 0 && str[k] == '-'){
  1384. continue;
  1385. }
  1386. else{
  1387. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1388. return pdFALSE;
  1389. }
  1390. }
  1391. }
  1392. value = atof(str);
  1393. if(value >= -40 && value <= 0){
  1394. SetTemperatureAlarmLowRangeStr(str);
  1395. SETTINGS_Save();
  1396. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1397. }
  1398. else{
  1399. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1400. }
  1401. break;
  1402. case ARG_ALARM_LINE_HIGH:
  1403. for(k = 0; k < xParameterStringLength; k ++){
  1404. if(!isdigit_int(str[k])){
  1405. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1406. return pdFALSE;
  1407. }
  1408. }
  1409. value = atof(str);
  1410. if(value >= 40 && value <= 80){
  1411. SetTemperatureAlarmHighRangeStr(str);
  1412. SETTINGS_Save();
  1413. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1414. }
  1415. else{
  1416. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1417. }
  1418. break;
  1419. case ARG_ALARM_LINE_HIST:
  1420. for(k = 0; k < xParameterStringLength; k ++){
  1421. if(!isfloatdigit(str[k])){
  1422. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1423. return pdFALSE;
  1424. }
  1425. }
  1426. value = atof(str);
  1427. if(value >= 0.5 && value <= 2){
  1428. SetTemperatureAlarmHisteStr(str);
  1429. SETTINGS_Save();
  1430. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1431. }
  1432. else{
  1433. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1434. }
  1435. break;
  1436. default:
  1437. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1438. break;
  1439. }
  1440. break;
  1441. case ARG_ALARM_LOAD:
  1442. switch(j){
  1443. case ARG_ALARM_LINE_LOW:
  1444. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1445. break;
  1446. case ARG_ALARM_LINE_HIGH:
  1447. for(k = 0; k < xParameterStringLength; k ++){
  1448. if(!isdigit_int(str[k])){
  1449. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1450. return pdFALSE;
  1451. }
  1452. }
  1453. value = atof(str);
  1454. if(value >= 60 && value <= 120){
  1455. SetLoadAlarmHighRangeStr(str);
  1456. SETTINGS_Save();
  1457. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1458. }
  1459. else{
  1460. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1461. }
  1462. break;
  1463. case ARG_ALARM_LINE_HIST:
  1464. for(k = 0; k < xParameterStringLength; k ++){
  1465. if(!isfloatdigit(str[k])){
  1466. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1467. return pdFALSE;
  1468. }
  1469. }
  1470. value = atof(str);
  1471. if(value >= 0.5 && value <= 2){
  1472. SetLoadAlarmHistStr(str);
  1473. SETTINGS_Save();
  1474. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1475. }
  1476. else{
  1477. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1478. }
  1479. break;
  1480. default:
  1481. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1482. break;
  1483. }
  1484. break;
  1485. case ARG_ALARM_VOUT:
  1486. switch(j){
  1487. case ARG_ALARM_LINE_LOW:
  1488. for(k = 0; k < xParameterStringLength; k ++){
  1489. if(!isdigit_int(str[k])){
  1490. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1491. return pdFALSE;
  1492. }
  1493. }
  1494. value = atof(str);
  1495. if(value >= 110 && value <= 200){
  1496. SetVACAlarmLowRangeStr(str);
  1497. SETTINGS_Save();
  1498. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1499. }
  1500. else{
  1501. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1502. }
  1503. break;
  1504. case ARG_ALARM_LINE_HIGH:
  1505. for(k = 0; k < xParameterStringLength; k ++){
  1506. if(!isdigit_int(str[k])){
  1507. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1508. return pdFALSE;
  1509. }
  1510. }
  1511. value = atof(str);
  1512. if(value >= 220 && value <= 250){
  1513. SetVACAlarmHighRangeStr(str);
  1514. SETTINGS_Save();
  1515. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1516. }
  1517. else{
  1518. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1519. }
  1520. break;
  1521. case ARG_ALARM_LINE_HIST:
  1522. for(k = 0; k < xParameterStringLength; k ++){
  1523. if(!isdigit_int(str[k])){
  1524. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1525. return pdFALSE;
  1526. }
  1527. }
  1528. value = atof(str);
  1529. if(value >= 10 && value <= 30){
  1530. SetVACAlarmHisteStr(str);
  1531. SETTINGS_Save();
  1532. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1533. }
  1534. else{
  1535. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1536. }
  1537. break;
  1538. default:
  1539. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1540. break;
  1541. }
  1542. break;
  1543. default:
  1544. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1545. break;
  1546. }
  1547. xReturn = pdFALSE;
  1548. return xReturn;
  1549. }
  1550. #ifdef HARDWARE_BT6708
  1551. /*
  1552. * Implements the whitelist command.
  1553. */
  1554. static portBASE_TYPE prvTaskWhiteListCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1555. int8_t *pcParameterString;
  1556. signed portBASE_TYPE xParameterStringLength, xReturn;
  1557. portBASE_TYPE xParameterNumber = 1;
  1558. char str[20];
  1559. char temp_str[20];
  1560. uint8_t i;
  1561. char *beginValue;
  1562. uint8_t len;
  1563. ( void ) pcCommandString;
  1564. ( void ) xWriteBufferLen;
  1565. configASSERT( pcWriteBuffer );
  1566. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1567. /* Obtain the parameter string. */
  1568. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1569. (
  1570. pcCommandString, /* The command string itself. */
  1571. xParameterNumber, /* Return the next parameter. */
  1572. &xParameterStringLength /* Store the parameter string length. */
  1573. );
  1574. if(pcParameterString == NULL){
  1575. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1576. return pdFALSE;
  1577. }
  1578. for(i = 0; i < ARG_WHITELIST_ALL; i ++){
  1579. if( strncmp( ( const char * ) pcParameterString, whitelist_args_list[i], strlen(whitelist_args_list[i]) ) == 0 ){
  1580. break;
  1581. }
  1582. }
  1583. if(telnet_code_auth != ADMIN && i !=ARG_WHITELIST_INFO){
  1584. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1585. return pdFALSE;
  1586. }
  1587. xParameterNumber ++;
  1588. /* Obtain the parameter string. */
  1589. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1590. (
  1591. pcCommandString, /* The command string itself. */
  1592. xParameterNumber, /* Return the next parameter. */
  1593. &xParameterStringLength /* Store the parameter string length. */
  1594. );
  1595. xParameterNumber ++;
  1596. if(pcParameterString == NULL){
  1597. if(i == ARG_WHITELIST_INFO){
  1598. whitelist_config_param(pcWriteBuffer);
  1599. }
  1600. else{
  1601. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1602. }
  1603. return pdFALSE;
  1604. }
  1605. memset(str, 0, sizeof(str));
  1606. if(xParameterStringLength > (int32_t)sizeof(str))
  1607. xParameterStringLength = sizeof(str) - 1;
  1608. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1609. switch(i){
  1610. case ARG_WHITELIST_RANGE:
  1611. if(xParameterStringLength == 1 && isdigit_int(str[0])){
  1612. int32_t temp = atoi(str);
  1613. if(temp > 0 && temp < 6){
  1614. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1615. (
  1616. pcCommandString, /* The command string itself. */
  1617. xParameterNumber, /* Return the next parameter. */
  1618. &xParameterStringLength /* Store the parameter string length. */
  1619. );
  1620. if(pcParameterString != NULL){
  1621. memset(str, 0, sizeof(str));
  1622. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1623. if(xParameterStringLength > (int32_t)sizeof(str))
  1624. xParameterStringLength = sizeof(str) - 1;
  1625. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1626. if(xParameterStringLength <= 19){
  1627. beginValue = strpbrk(str,"/");
  1628. if(beginValue == NULL){
  1629. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1630. return pdFALSE;
  1631. }
  1632. len = beginValue - str;
  1633. memset(temp_str, 0, sizeof(temp_str));
  1634. strncpy(temp_str, str, len);
  1635. for(uint8_t j = (len + 1); j < xParameterStringLength; j++){
  1636. if(!isdigit_int(str[j])){
  1637. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1638. return pdFALSE;
  1639. }
  1640. }
  1641. if(ipaddr_addr(temp_str) != IPADDR_NONE){
  1642. SetWhiteListSTR(str, (temp - 1));
  1643. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1644. }
  1645. else{
  1646. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1647. }
  1648. }
  1649. else{
  1650. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1651. }
  1652. }
  1653. else{
  1654. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1655. }
  1656. }
  1657. else{
  1658. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1659. }
  1660. }
  1661. else{
  1662. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1663. }
  1664. break;
  1665. default:
  1666. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1667. break;
  1668. }
  1669. xReturn = pdFALSE;
  1670. return xReturn;
  1671. }
  1672. #endif
  1673. /*
  1674. * Implements the change password command.
  1675. */
  1676. static portBASE_TYPE prvTaskUserCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1677. int8_t *pcParameterString;
  1678. signed portBASE_TYPE xParameterStringLength, xReturn;
  1679. portBASE_TYPE xParameterNumber = 1;
  1680. uint8_t i;
  1681. char temp_str[MAX_WEB_LOGIN_LEN];
  1682. char WebLogin[MAX_WEB_LOGIN_LEN];
  1683. uint8_t valueLen, user_id;
  1684. const int8_t * const pcChangePWDHeader = ( int8_t * ) "\r\nВведите новый пароль:";
  1685. ( void ) pcCommandString;
  1686. ( void ) xWriteBufferLen;
  1687. configASSERT( pcWriteBuffer );
  1688. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1689. if(telnet_code_auth != ADMIN){
  1690. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1691. return pdFALSE;
  1692. }
  1693. /* Obtain the parameter string. */
  1694. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1695. (
  1696. pcCommandString, /* The command string itself. */
  1697. xParameterNumber, /* Return the next parameter. */
  1698. &xParameterStringLength /* Store the parameter string length. */
  1699. );
  1700. if(pcParameterString == NULL){
  1701. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1702. return pdFALSE;
  1703. }
  1704. for(i = 0; i < ARG_USER_ALL; i ++){
  1705. if( strncmp( ( const char * ) pcParameterString, user_args_list[i], strlen(user_args_list[i]) ) == 0 ){
  1706. break;
  1707. }
  1708. }
  1709. xParameterNumber ++;
  1710. /* Obtain the parameter string. */
  1711. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1712. (
  1713. pcCommandString, /* The command string itself. */
  1714. xParameterNumber, /* Return the next parameter. */
  1715. &xParameterStringLength /* Store the parameter string length. */
  1716. );
  1717. if(i == ARG_USER_PWD){
  1718. memset(temp_str, 0, sizeof(temp_str));
  1719. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1720. if(xParameterStringLength > (int32_t)sizeof(temp_str)){
  1721. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1722. }
  1723. else{
  1724. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1725. for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
  1726. GetUserLogin(user_id, WebLogin, &valueLen);
  1727. /* Check login and password */
  1728. if (strncmp(WebLogin, temp_str, MAX_WEB_LOGIN_LEN) == 0) {
  1729. /* Login and pass are valid */
  1730. id_change_pwd = user_id;
  1731. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcChangePWDHeader, strlen( ( char * ) pcChangePWDHeader ) );
  1732. telnetState = TELNET_CHANGE_PWD;
  1733. break;
  1734. }
  1735. }
  1736. if(telnetState != TELNET_CHANGE_PWD){
  1737. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1738. }
  1739. }
  1740. }
  1741. else{
  1742. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1743. }
  1744. xReturn = pdFALSE;
  1745. return xReturn;
  1746. }
  1747. /*
  1748. * Implements the config command.
  1749. */
  1750. static portBASE_TYPE prvTaskConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1751. int8_t *pcParameterString;
  1752. signed portBASE_TYPE xParameterStringLength, xReturn;
  1753. portBASE_TYPE xParameterNumber = 1;
  1754. char str[110];
  1755. uint8_t i;
  1756. static uint8_t config_menu = 0;
  1757. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n*********Конфигурация Контроллера*********\r\n";
  1758. ( void ) pcCommandString;
  1759. ( void ) xWriteBufferLen;
  1760. configASSERT( pcWriteBuffer );
  1761. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1762. /* Obtain the parameter string. */
  1763. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1764. (
  1765. pcCommandString, /* The command string itself. */
  1766. xParameterNumber, /* Return the next parameter. */
  1767. &xParameterStringLength /* Store the parameter string length. */
  1768. );
  1769. if(pcParameterString == NULL){
  1770. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1771. return pdFALSE;
  1772. }
  1773. for(i = 0; i < ARG_CONFIG_ALL; i ++){
  1774. if( strncmp( ( const char * ) pcParameterString, config_args_list[i], strlen(config_args_list[i]) ) == 0 ){
  1775. break;
  1776. }
  1777. }
  1778. if(telnet_code_auth != ADMIN && i !=ARG_CONFIG_INFO){
  1779. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1780. return pdFALSE;
  1781. }
  1782. xParameterNumber ++;
  1783. /* Obtain the parameter string. */
  1784. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1785. (
  1786. pcCommandString, /* The command string itself. */
  1787. xParameterNumber, /* Return the next parameter. */
  1788. &xParameterStringLength /* Store the parameter string length. */
  1789. );
  1790. if(pcParameterString == NULL){
  1791. switch(i){
  1792. case ARG_CONFIG_INFO:
  1793. switch(config_menu){
  1794. case PARAM_CONFIG_SNMP:
  1795. /* Return the next command help string, before moving the pointer on to
  1796. the next command in the list. */
  1797. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  1798. snmp_config_param(pcWriteBuffer);
  1799. break;
  1800. #ifdef HARDWARE_BT6706
  1801. case PARAM_CONFIG_INOUTS:
  1802. inouts_config_param(pcWriteBuffer);
  1803. break;
  1804. #endif
  1805. case PARAM_CONFIG_AKB:
  1806. akb_config_param(pcWriteBuffer);
  1807. break;
  1808. case PARAM_CONFIG_ALARM:
  1809. alarm_config_param(pcWriteBuffer);
  1810. break;
  1811. #ifdef HARDWARE_BT6708
  1812. case PARAM_CONFIG_WHITELIST:
  1813. whitelist_config_param(pcWriteBuffer);
  1814. break;
  1815. #endif
  1816. case PARAM_CONFIG_NET:
  1817. net_config_param(pcWriteBuffer);
  1818. break;
  1819. case PARAM_CONFIG_TIME:
  1820. time_config_param(pcWriteBuffer);
  1821. break;
  1822. }
  1823. config_menu ++;
  1824. if(config_menu == PARAM_CONFIG_ALL){
  1825. config_menu = 0;
  1826. return pdFALSE;
  1827. }
  1828. else{
  1829. return pdTRUE;
  1830. }
  1831. break;
  1832. default:
  1833. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1834. break;
  1835. }
  1836. return pdFALSE;
  1837. }
  1838. if(i == ARG_CONFIG_LOAD){
  1839. memset(str, 0, sizeof(str));
  1840. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1841. if(xParameterStringLength > (int32_t)sizeof(str))
  1842. xParameterStringLength = sizeof(str) - 1;
  1843. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1844. if(xParameterStringLength < 13){
  1845. if(strncmp(str, "default", 7) == 0){
  1846. SNMP_SendUserTrap(DEVICE_RESTORED);
  1847. log_event_data(LOG_SYSTEM_DEFCONFIG, name_login_telnet);
  1848. vTaskDelay(500);
  1849. SETTINGS_SetPartDefault();
  1850. SETTINGS_Save();
  1851. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1852. strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
  1853. }
  1854. else{
  1855. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1856. }
  1857. }
  1858. else{
  1859. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1860. }
  1861. }
  1862. else{
  1863. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1864. }
  1865. xReturn = pdFALSE;
  1866. return xReturn;
  1867. }
  1868. /*
  1869. * Implements the config command.
  1870. */
  1871. static portBASE_TYPE prvTaskNetConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1872. int8_t *pcParameterString;
  1873. portBASE_TYPE xParameterNumber = 1;
  1874. signed portBASE_TYPE xParameterStringLength;
  1875. uint8_t i;
  1876. static start = 0;
  1877. ( void ) pcCommandString;
  1878. ( void ) xWriteBufferLen;
  1879. configASSERT( pcWriteBuffer );
  1880. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1881. /* Obtain the parameter string. */
  1882. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1883. (
  1884. pcCommandString, /* The command string itself. */
  1885. xParameterNumber, /* Return the next parameter. */
  1886. &xParameterStringLength /* Store the parameter string length. */
  1887. );
  1888. for(i = 0; i < ARG_NETCONFIG_ALL; i ++){
  1889. if( strncmp( ( const char * ) pcParameterString, netconfig_args_list[i], strlen(netconfig_args_list[i]) ) == 0 ){
  1890. break;
  1891. }
  1892. }
  1893. if(telnet_code_auth != ADMIN){
  1894. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1895. return pdFALSE;
  1896. }
  1897. switch(i){
  1898. case ARG_NETCONFIG_APPLY:
  1899. if(!start){
  1900. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  1901. if (GetStateWebReinit() == true)
  1902. {
  1903. start = 1;
  1904. telnet_act = true;
  1905. SetWebReinitFlag(true);
  1906. HTTP_SaveSettings();
  1907. strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  1908. return pdTRUE;
  1909. }
  1910. }
  1911. else{
  1912. telnet_act = true;
  1913. start = 0;
  1914. vTaskDelay(1010);
  1915. Reboot();
  1916. }
  1917. break;
  1918. case ARG_NETCONFIG_CONFIRM:
  1919. telnet_act = true;
  1920. SetWebReinitFlag(false);
  1921. SetConfirmWebParamsFlag();
  1922. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  1923. break;
  1924. default:
  1925. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1926. break;
  1927. }
  1928. return pdFALSE;
  1929. }
  1930. /*
  1931. * Implements the history command.
  1932. */
  1933. static portBASE_TYPE prvTaskHistoryCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1934. int8_t *pcParameterString;
  1935. signed portBASE_TYPE xParameterStringLength, xReturn;
  1936. portBASE_TYPE xParameterNumber = 1;
  1937. char str[110];
  1938. uint8_t i;
  1939. static int16_t num_page = 0;
  1940. static int16_t num_page_temp = 1;
  1941. static bool start = true;
  1942. const int8_t * const pcUPShistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий ИБП***********\r\n";
  1943. const int8_t * const pcControllerHistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий Контроллера***********\r\n";
  1944. ( void ) pcCommandString;
  1945. ( void ) xWriteBufferLen;
  1946. configASSERT( pcWriteBuffer );
  1947. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1948. /* Obtain the parameter string. */
  1949. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1950. (
  1951. pcCommandString, /* The command string itself. */
  1952. xParameterNumber, /* Return the next parameter. */
  1953. &xParameterStringLength /* Store the parameter string length. */
  1954. );
  1955. if(pcParameterString == NULL){
  1956. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1957. return pdFALSE;
  1958. }
  1959. if( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ){
  1960. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1961. return pdFALSE;
  1962. }
  1963. xParameterNumber ++;
  1964. /* Obtain the parameter string. */
  1965. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1966. (
  1967. pcCommandString, /* The command string itself. */
  1968. xParameterNumber, /* Return the next parameter. */
  1969. &xParameterStringLength /* Store the parameter string length. */
  1970. );
  1971. for(i = 0; i < ARG_HISTORY_ALL; i ++){
  1972. if( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0 ){
  1973. break;
  1974. }
  1975. }
  1976. xParameterNumber ++;
  1977. /* Obtain the parameter string. */
  1978. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1979. (
  1980. pcCommandString, /* The command string itself. */
  1981. xParameterNumber, /* Return the next parameter. */
  1982. &xParameterStringLength /* Store the parameter string length. */
  1983. );
  1984. memset(str, 0, sizeof(str));
  1985. if(xParameterStringLength > 5){
  1986. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1987. return pdFALSE;
  1988. }
  1989. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1990. if(num_page == 0){
  1991. num_page = atoi(str);
  1992. if(num_page <= 0){
  1993. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1994. return pdFALSE;
  1995. }
  1996. }
  1997. switch(i){
  1998. case ARG_HISTORY_EVENTS:
  1999. if(start){
  2000. start = false;
  2001. /* Return the next command help string, before moving the pointer on to
  2002. the next command in the list. */
  2003. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader, strlen( ( char * ) pcControllerHistoryTableHeader ) );
  2004. memset(str, 0, sizeof(str));
  2005. strcat(( char * ) pcWriteBuffer, "\r\n");
  2006. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  2007. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2008. strcat(( char * ) pcWriteBuffer, "\r\n");
  2009. if(num_page > History_GetPageCount())
  2010. num_page = History_GetPageCount();
  2011. }
  2012. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2013. num_page --;
  2014. num_page_temp ++;
  2015. if(num_page == 0){
  2016. num_page = 0;
  2017. num_page_temp = 1;
  2018. start = true;
  2019. xReturn = pdFALSE;
  2020. }
  2021. else{
  2022. xReturn = pdTRUE;
  2023. }
  2024. break;
  2025. case ARG_HISTORY_UPS:
  2026. if(start){
  2027. start = false;
  2028. /* Return the next command help string, before moving the pointer on to
  2029. the next command in the list. */
  2030. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader, strlen( ( char * ) pcUPShistoryTableHeader ) );
  2031. memset(str, 0, sizeof(str));
  2032. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  2033. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2034. if(num_page > LOG_GetPageCount())
  2035. num_page = LOG_GetPageCount();
  2036. }
  2037. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2038. num_page --;
  2039. num_page_temp ++;
  2040. if(num_page == 0){
  2041. num_page = 0;
  2042. num_page_temp = 1;
  2043. start = true;
  2044. xReturn = pdFALSE;
  2045. }
  2046. else{
  2047. xReturn = pdTRUE;
  2048. }
  2049. break;
  2050. default:
  2051. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2052. xReturn = pdFALSE;
  2053. break;
  2054. }
  2055. return xReturn;
  2056. }
  2057. /*
  2058. * Implements the sensor info command.
  2059. */
  2060. static portBASE_TYPE prvTaskSensorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  2061. int8_t *pcParameterString;
  2062. signed portBASE_TYPE xParameterStringLength, xReturn;
  2063. portBASE_TYPE xParameterNumber = 1;
  2064. uint8_t i;
  2065. char str[10];
  2066. char temp_str[10];
  2067. int32_t val = 0, val2 = 0;
  2068. uint8_t fail = 0;
  2069. static uint8_t config_menu = 0;
  2070. uint8_t MAX_CONFIG_PARAM = 0;
  2071. #ifdef HARDWARE_BT6706
  2072. MAX_CONFIG_PARAM = 3;
  2073. #else
  2074. MAX_CONFIG_PARAM = 2;
  2075. #endif
  2076. const int8_t * const pcSensorTableHeader = ( int8_t * ) "\r\n*********Параметры Контроллера*********\r\n";
  2077. ( void ) pcCommandString;
  2078. ( void ) xWriteBufferLen;
  2079. configASSERT( pcWriteBuffer );
  2080. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2081. /* Obtain the parameter string. */
  2082. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2083. (
  2084. pcCommandString, /* The command string itself. */
  2085. xParameterNumber, /* Return the next parameter. */
  2086. &xParameterStringLength /* Store the parameter string length. */
  2087. );
  2088. if(pcParameterString == NULL){
  2089. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2090. return pdFALSE;
  2091. }
  2092. for(i = 0; i < ARG_SENSOR_ALL; i ++){
  2093. if( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0 ){
  2094. break;
  2095. }
  2096. }
  2097. xParameterNumber ++;
  2098. /* Obtain the parameter string. */
  2099. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2100. (
  2101. pcCommandString, /* The command string itself. */
  2102. xParameterNumber, /* Return the next parameter. */
  2103. &xParameterStringLength /* Store the parameter string length. */
  2104. );
  2105. if(pcParameterString == NULL){
  2106. if(i == ARG_SENSOR_INFO){
  2107. switch(config_menu){
  2108. case 0:
  2109. /* Return the next command help string, before moving the pointer on to
  2110. the next command in the list. */
  2111. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  2112. ups_sensor_param(pcWriteBuffer);
  2113. break;
  2114. case 1:
  2115. ups_sensor_akb_param(pcWriteBuffer);
  2116. break;
  2117. #ifdef HARDWARE_BT6706
  2118. case 2:
  2119. inouts_sensor_param(pcWriteBuffer);
  2120. break;
  2121. #endif
  2122. }
  2123. config_menu ++;
  2124. if(config_menu == MAX_CONFIG_PARAM){
  2125. config_menu = 0;
  2126. return pdFALSE;
  2127. }
  2128. else{
  2129. return pdTRUE;
  2130. }
  2131. }
  2132. else{
  2133. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2134. }
  2135. }
  2136. else{
  2137. switch(i){
  2138. #ifdef HARDWARE_BT6706
  2139. case ARG_SENSOR_SETUP:
  2140. if(telnet_code_auth != ADMIN){
  2141. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2142. return pdFALSE;
  2143. }
  2144. memset(str, 0, sizeof(str));
  2145. if(xParameterStringLength > (int32_t)sizeof(str))
  2146. xParameterStringLength = sizeof(str) - 1;
  2147. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2148. if(xParameterStringLength < 3){
  2149. xParameterNumber ++;
  2150. /* Obtain the parameter string. */
  2151. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2152. (
  2153. pcCommandString, /* The command string itself. */
  2154. xParameterNumber, /* Return the next parameter. */
  2155. &xParameterStringLength /* Store the parameter string length. */
  2156. );
  2157. memset(temp_str, 0, sizeof(str));
  2158. if(xParameterStringLength > 1){
  2159. fail = 1;
  2160. break;
  2161. }
  2162. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2163. if(!isdigit_int(temp_str[0])){
  2164. fail = 1;
  2165. break;
  2166. }
  2167. val = atoi(temp_str);
  2168. xParameterNumber ++;
  2169. /* Obtain the parameter string. */
  2170. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2171. (
  2172. pcCommandString, /* The command string itself. */
  2173. xParameterNumber, /* Return the next parameter. */
  2174. &xParameterStringLength /* Store the parameter string length. */
  2175. );
  2176. memset(temp_str, 0, sizeof(str));
  2177. if(xParameterStringLength > 1){
  2178. fail = 1;
  2179. break;
  2180. }
  2181. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2182. if(!isdigit_int(temp_str[0])){
  2183. fail = 1;
  2184. break;
  2185. }
  2186. if(strncmp(str, "DI", 2) == 0){
  2187. if(val != 1){
  2188. fail = 1;
  2189. break;
  2190. }
  2191. val2 = atoi(temp_str);
  2192. if(val2 < 0 || val2 > 1){
  2193. fail = 1;
  2194. break;
  2195. }
  2196. SetDINTypeActStr(temp_str, (val - 1));
  2197. SETTINGS_Save();
  2198. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  2199. }
  2200. else if(strncmp(str, "DO", 2) == 0){
  2201. if(val < 1 || val > 3){
  2202. fail = 1;
  2203. break;
  2204. }
  2205. val2 = atoi(temp_str);
  2206. if(val2 < 1 || val2 > 5){
  2207. fail = 1;
  2208. break;
  2209. }
  2210. SetROTypeActStr(temp_str, (val - 1));
  2211. SETTINGS_Save();
  2212. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  2213. }
  2214. }
  2215. else{
  2216. fail = 1;
  2217. }
  2218. break;
  2219. #endif
  2220. default:
  2221. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2222. break;
  2223. }
  2224. }
  2225. if(fail)
  2226. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2227. xReturn = pdFALSE;
  2228. return xReturn;
  2229. }
  2230. /*
  2231. * Implements the firmware download http command.
  2232. */
  2233. static portBASE_TYPE prvTaskUploadCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  2234. static bool start_update = true;
  2235. const int8_t *const pcUploadHeader = ( int8_t * ) "Контроллер переводится в режим загрузчика\r\n";
  2236. ( void ) pcCommandString;
  2237. ( void ) xWriteBufferLen;
  2238. if(telnet_code_auth != ADMIN){
  2239. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2240. return pdFALSE;
  2241. }
  2242. if(start_update){
  2243. start_update = false;
  2244. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  2245. return pdTRUE;
  2246. }
  2247. else{
  2248. telnet_act = true;
  2249. HTTP_StartResetTask(true);
  2250. return pdFALSE;
  2251. }
  2252. }
  2253. /*
  2254. * Implements the ups command.
  2255. */
  2256. static portBASE_TYPE prvTaskUPSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  2257. int8_t *pcParameterString;
  2258. signed portBASE_TYPE xParameterStringLength, xReturn;
  2259. portBASE_TYPE xParameterNumber = 1;
  2260. char str[110];
  2261. int32_t val = 0;
  2262. float val_float = 0;
  2263. int8_t res = 0;
  2264. uint8_t i;
  2265. ( void ) pcCommandString;
  2266. ( void ) xWriteBufferLen;
  2267. configASSERT( pcWriteBuffer );
  2268. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2269. if(telnet_code_auth != ADMIN && i !=ARG_CONFIG_INFO){
  2270. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2271. return pdFALSE;
  2272. }
  2273. /* Obtain the parameter string. */
  2274. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2275. (
  2276. pcCommandString, /* The command string itself. */
  2277. xParameterNumber, /* Return the next parameter. */
  2278. &xParameterStringLength /* Store the parameter string length. */
  2279. );
  2280. for(i = 0; i < ARG_UPS_ALL; i ++){
  2281. if( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0 ){
  2282. break;
  2283. }
  2284. }
  2285. xParameterNumber ++;
  2286. /* Obtain the parameter string. */
  2287. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2288. (
  2289. pcCommandString, /* The command string itself. */
  2290. xParameterNumber, /* Return the next parameter. */
  2291. &xParameterStringLength /* Store the parameter string length. */
  2292. );
  2293. memset(str, 0, sizeof(str));
  2294. if(xParameterStringLength > 3){
  2295. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2296. return pdFALSE;
  2297. }
  2298. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2299. switch(i){
  2300. case ARG_UPS_BATTEST:
  2301. for(uint8_t j = 0; j < xParameterStringLength; j++){
  2302. if(!isdigit_int(str[j])){
  2303. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2304. return pdFALSE;
  2305. }
  2306. }
  2307. val = atoi(str);
  2308. if(val == 0){
  2309. res = ups_metac_service_pdu(ups_cancel_test);
  2310. if(res == 1){
  2311. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  2312. strcpy( ( char * ) pcWriteBuffer, "\t\tТест остановлен!\r\n");
  2313. }
  2314. else{
  2315. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось остановить!\r\n");
  2316. }
  2317. }
  2318. else if(val > 0 && val < 100){
  2319. TimeParam = val;
  2320. res = ups_metac_service_pdu(ups_test_time);
  2321. if(res == 1){
  2322. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  2323. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  2324. }
  2325. else{
  2326. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  2327. }
  2328. }
  2329. else if(val == 100){
  2330. res = ups_metac_service_pdu(ups_test_10sec);
  2331. if(res == 1){
  2332. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  2333. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  2334. }
  2335. else{
  2336. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  2337. }
  2338. }
  2339. else if(val == 999){
  2340. res = ups_metac_service_pdu(ups_test_low_bat);
  2341. if(res == 1){
  2342. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  2343. strcpy( ( char * ) pcWriteBuffer, "\t\ttТест запущен!\r\n");
  2344. }
  2345. else{
  2346. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  2347. }
  2348. }
  2349. else{
  2350. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2351. }
  2352. break;
  2353. case ARG_UPS_SHUTDOWN:
  2354. for(uint8_t j = 0; j < xParameterStringLength; j++){
  2355. if(!isfloatdigit(str[j])){
  2356. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2357. return pdFALSE;
  2358. }
  2359. }
  2360. val_float = atof(str);
  2361. if(val_float == 0){
  2362. res = ups_metac_service_pdu(ups_cancel_shut_down);
  2363. if(res == 1){
  2364. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  2365. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  2366. }
  2367. else{
  2368. strcpy( ( char * ) pcWriteBuffer, "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  2369. }
  2370. }
  2371. else if(val_float > 0 && val_float <= 10){
  2372. TimeParamFloat = val_float;
  2373. res = ups_metac_service_pdu(ups_shutdown);
  2374. if(res == 1){
  2375. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  2376. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  2377. }
  2378. else{
  2379. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  2380. }
  2381. }
  2382. else{
  2383. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2384. }
  2385. break;
  2386. default:
  2387. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2388. break;
  2389. }
  2390. xReturn = pdFALSE;
  2391. return xReturn;
  2392. }
  2393. /*-----------------------------------------------------------*/