CLI_Commands.c 119 KB

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