CLI_Commands.c 119 KB

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