CLI_Commands.c 137 KB

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