CLI_Commands.c 145 KB

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