CLI_Commands.c 125 KB

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