CLI_Commands.c 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853
  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_ADDRESS && i <= INFO_COMMENTS) {
  583. SETTINGS_Save();
  584. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  585. }
  586. } else {
  587. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  588. }
  589. xReturn = pdFALSE;
  590. }
  591. return xReturn;
  592. }
  593. static portBASE_TYPE prvTaskRebootCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  594. const int8_t *pcCommandString )
  595. {
  596. static bool start_reboot = true;
  597. const int8_t *const pcRebootHeader = ( int8_t * )
  598. "Контроллер будет перезагружен через 1 секунду\r\n";
  599. ( void ) pcCommandString;
  600. ( void ) xWriteBufferLen;
  601. if (cli_state->user_id != ADMIN) {
  602. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  603. return pdFALSE;
  604. }
  605. if (start_reboot) {
  606. start_reboot = false;
  607. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcRebootHeader );
  608. return pdTRUE;
  609. } else {
  610. telnet_act = true;
  611. Reboot(TELNET_ACT);
  612. return pdFALSE;
  613. }
  614. }
  615. static portBASE_TYPE prvTaskSystimeCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  616. const int8_t *pcCommandString )
  617. {
  618. int8_t *pcParameterString;
  619. signed portBASE_TYPE xParameterStringLength, xReturn;
  620. portBASE_TYPE xParameterNumber = 1;
  621. char str[110];
  622. uint8_t len;
  623. uint8_t i;
  624. uint8_t fail = 0;
  625. uint16_t temp = 0;
  626. ( void ) pcCommandString;
  627. ( void ) xWriteBufferLen;
  628. configASSERT( pcWriteBuffer );
  629. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  630. /* Obtain the parameter string. */
  631. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  632. (
  633. pcCommandString, /* The command string itself. */
  634. xParameterNumber, /* Return the next parameter. */
  635. &xParameterStringLength /* Store the parameter string length. */
  636. );
  637. if (pcParameterString == NULL) {
  638. const int8_t *const pcInfoTableHeader = ( int8_t * )
  639. "\r\n******Системное время Контроллера******\r\n";
  640. /* Return the next command help string, before moving the pointer on to
  641. the next command in the list. */
  642. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  643. GetDateStr(str, &len);
  644. strcat(( char * ) pcWriteBuffer, "Дата:\t\t\t");
  645. strncat(( char * ) pcWriteBuffer, str, len);
  646. strcat(( char * ) pcWriteBuffer, "\r\nВремя:\t\t\t");
  647. GetTimeStr(str, &len);
  648. strncat(( char * ) pcWriteBuffer, str, len);
  649. strcat(( char * ) pcWriteBuffer, "\r\n");
  650. /* There are no more commands in the list, so there will be no more
  651. strings to return after this one and pdFALSE should be returned. */
  652. xReturn = pdFALSE;
  653. } else {
  654. if (cli_state->user_id != ADMIN) {
  655. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  656. return pdFALSE;
  657. }
  658. for (i = 0; i < ARG_SYSTIME_ALL; i ++) {
  659. if ( strncmp( ( const char * ) pcParameterString, systime_args_list[i], strlen(systime_args_list[i]) ) == 0
  660. && xParameterStringLength == strlen(systime_args_list[i])) {
  661. break;
  662. }
  663. }
  664. if (i != ARG_SYSTIME_ALL) {
  665. if (sSettings.sSNTP.sntpEnable) {
  666. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSystymeDenied, strlen( ( char * ) pcSystymeDenied ) );
  667. return pdFALSE;
  668. }
  669. }
  670. xParameterNumber ++;
  671. /* Obtain the parameter string. */
  672. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  673. (
  674. pcCommandString, /* The command string itself. */
  675. xParameterNumber, /* Return the next parameter. */
  676. &xParameterStringLength /* Store the parameter string length. */
  677. );
  678. if (pcParameterString == NULL) {
  679. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  680. return pdFALSE;
  681. }
  682. memset(str, 0, sizeof(str));
  683. xParameterStringLength = strlen(( const char * ) pcParameterString);
  684. if (xParameterStringLength > (int32_t)sizeof(str)) {
  685. xParameterStringLength = sizeof(str) - 1;
  686. }
  687. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  688. switch (i) {
  689. case ARG_SYSTIME_DATA:
  690. if (xParameterStringLength == 10) {
  691. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  692. if (j != 4 && j != 7) {
  693. if (str[j] > 0x39 || str[j] < 0x30) {
  694. fail = 1;
  695. }
  696. } else if (j == 4 || j == 7) {
  697. if (str[j] != '-') {
  698. fail = 1;
  699. }
  700. }
  701. }
  702. if (!fail) {
  703. temp = 1000 * (str[0] - 0x30) + 100 * (str[1] - 0x30) + 10 * (str[2] - 0x30) + str[3] - 0x30;
  704. if (temp > 2099 || temp < 2000) {
  705. fail = 1;
  706. }
  707. temp = 0;
  708. temp = 10 * (str[5] - 0x30) + (str[6] - 0x30);
  709. if (temp > 12) {
  710. fail = 1;
  711. }
  712. temp = 0;
  713. temp = 10 * (str[8] - 0x30) + (str[9] - 0x30);
  714. if (temp > 31) {
  715. fail = 1;
  716. }
  717. }
  718. } else {
  719. fail = 1;
  720. }
  721. if (!fail) {
  722. SetDateStr(str);
  723. SETTINGS_Save();
  724. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  725. } else {
  726. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  727. }
  728. break;
  729. case ARG_SYSTIME_TIME:
  730. if (xParameterStringLength == 5) {
  731. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  732. if (j != 2) {
  733. if (str[j] > 0x39 || str[j] < 0x30) {
  734. fail = 1;
  735. }
  736. } else if (j == 2) {
  737. if (str[j] != ':') {
  738. fail = 1;
  739. }
  740. }
  741. }
  742. if (!fail) {
  743. temp = 10 * (str[0] - 0x30) + (str[1] - 0x30);
  744. if (temp > 23) {
  745. fail = 1;
  746. }
  747. temp = 0;
  748. temp = 10 * (str[3] - 0x30) + (str[4] - 0x30);
  749. if (temp > 59) {
  750. fail = 1;
  751. }
  752. }
  753. } else {
  754. fail = 1;
  755. }
  756. if (!fail) {
  757. SetTimeStr(str);
  758. SETTINGS_Save();
  759. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  760. } else {
  761. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  762. }
  763. break;
  764. default:
  765. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  766. break;
  767. }
  768. xReturn = pdFALSE;
  769. }
  770. return xReturn;
  771. }
  772. /*
  773. * Implements the ntp command.
  774. */
  775. static portBASE_TYPE prvTaskNTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  776. {
  777. int8_t *pcParameterString;
  778. signed portBASE_TYPE xParameterStringLength, xReturn;
  779. portBASE_TYPE xParameterNumber = 1;
  780. char str[110];
  781. char str_temp[110];
  782. uint8_t len;
  783. uint8_t i;
  784. bool enable_old_sntp;
  785. const int8_t *const pcInfoTableHeader = ( int8_t * )
  786. "\r\n************NTP настройки Контроллера************\r\n";
  787. ( void ) pcCommandString;
  788. ( void ) xWriteBufferLen;
  789. configASSERT( pcWriteBuffer );
  790. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  791. /* Obtain the parameter string. */
  792. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  793. (
  794. pcCommandString, /* The command string itself. */
  795. xParameterNumber, /* Return the next parameter. */
  796. &xParameterStringLength /* Store the parameter string length. */
  797. );
  798. if (pcParameterString == NULL) {
  799. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  800. return pdFALSE;
  801. }
  802. for (i = 0; i < ARG_NTP_ALL; i ++) {
  803. if ( strncmp( ( const char * ) pcParameterString, ntp_args_list[i], strlen(ntp_args_list[i]) ) == 0
  804. && xParameterStringLength == strlen(ntp_args_list[i])) {
  805. break;
  806. }
  807. }
  808. if (cli_state->user_id != ADMIN && i != ARG_NTP_INFO) {
  809. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  810. return pdFALSE;
  811. }
  812. xParameterNumber ++;
  813. /* Obtain the parameter string. */
  814. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  815. (
  816. pcCommandString, /* The command string itself. */
  817. xParameterNumber, /* Return the next parameter. */
  818. &xParameterStringLength /* Store the parameter string length. */
  819. );
  820. xParameterNumber ++;
  821. if (pcParameterString == NULL) {
  822. switch (i) {
  823. case ARG_NTP_ENABLE:
  824. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  825. SetSntpStateStr("1");
  826. if (sSettings.sSNTP.sntpEnable != enable_old_sntp) {
  827. SETTINGS_Save();
  828. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  829. SNTP_Init();
  830. //vTaskDelay(7000);
  831. SNTP_Poll();
  832. }
  833. break;
  834. case ARG_NTP_DISABLE:
  835. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  836. SetSntpStateStr("0");
  837. if (sSettings.sSNTP.sntpEnable != enable_old_sntp) {
  838. SETTINGS_Save();
  839. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  840. SNTP_Init();
  841. //vTaskDelay(7000);
  842. SNTP_Poll();
  843. }
  844. break;
  845. case ARG_NTP_INFO:
  846. /* Return the next command help string, before moving the pointer on to
  847. the next command in the list. */
  848. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  849. GetSntpStateStrRU(str, &len);
  850. strcat(( char * ) pcWriteBuffer, "Режим установки времени:\t");
  851. strncat(( char * ) pcWriteBuffer, str, len);
  852. strcat(( char * ) pcWriteBuffer, "\r\nIP адрес NTP сервера:\t\t");
  853. GetSntpServerIpStr(str, &len);
  854. strncat(( char * ) pcWriteBuffer, str, len);
  855. strcat(( char * ) pcWriteBuffer, "\r\nЧасовой пояс:\t\t\t");
  856. GetSntpTimeZoneStr(str, &len);
  857. strncat(( char * ) pcWriteBuffer, str, len);
  858. strcat(( char * ) pcWriteBuffer, "\r\nПоследняя дата синхронизации:\t");
  859. GetSntpLastDataStr(str, &len);
  860. strncat(( char * ) pcWriteBuffer, str, len);
  861. strcat(( char * ) pcWriteBuffer, "\r\n");
  862. break;
  863. default:
  864. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  865. break;
  866. }
  867. return pdFALSE;
  868. }
  869. if (i == ARG_NTP_SET) {
  870. memset(str, 0, sizeof(str));
  871. if (xParameterStringLength > (int32_t)sizeof(str)) {
  872. xParameterStringLength = sizeof(str) - 1;
  873. }
  874. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  875. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  876. (
  877. pcCommandString, /* The command string itself. */
  878. xParameterNumber, /* Return the next parameter. */
  879. &xParameterStringLength /* Store the parameter string length. */
  880. );
  881. if (pcParameterString != NULL) {
  882. memset(str_temp, 0, sizeof(str_temp));
  883. if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
  884. xParameterStringLength = sizeof(str_temp) - 1;
  885. }
  886. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  887. if (strncmp(str, "IP", 2) == 0) {
  888. if (xParameterStringLength <= 15) {
  889. if (ipaddr_addr(str_temp) != IPADDR_NONE) {
  890. if (strncmp(str_temp, sSettings.sSNTP.ip, strlen(str_temp)) != 0) {
  891. SetSntpServerIpStr(str_temp);
  892. SETTINGS_Save();
  893. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  894. SNTP_Init();
  895. //vTaskDelay(7000);
  896. SNTP_Poll();
  897. }
  898. } else {
  899. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  900. }
  901. } else {
  902. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  903. }
  904. } else if (strncmp(str, "gmt", 3) == 0) {
  905. if (xParameterStringLength > 1 && xParameterStringLength < 5) {
  906. bool fail = false;
  907. if (str_temp[0] != '-' && str_temp[0] != '+') {
  908. fail = true;
  909. }
  910. if (!isdigit_int(str_temp[1]) && (!isdigit_int(str_temp[2]) && str_temp[2] != '.') && (!isdigit_int(str_temp[3]) &&
  911. str_temp[3] != '.')) {
  912. fail = true;
  913. }
  914. if (xParameterStringLength == 5) {
  915. if (!isdigit_int(str_temp[4])) {
  916. fail = true;
  917. }
  918. }
  919. if (!fail) {
  920. float value = atof(str_temp);
  921. if (value >= -12.0 && value <= 12.0) {
  922. SetSntpTimeZoneStr(str_temp);
  923. SETTINGS_Save();
  924. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  925. } else {
  926. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  927. }
  928. } else {
  929. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  930. }
  931. } else {
  932. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  933. }
  934. } else {
  935. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  936. }
  937. } else {
  938. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  939. }
  940. } else {
  941. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  942. }
  943. xReturn = pdFALSE;
  944. return xReturn;
  945. }
  946. /*
  947. * Implements the network command.
  948. */
  949. static portBASE_TYPE prvTaskNetworkCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  950. const int8_t *pcCommandString )
  951. {
  952. int8_t *pcParameterString;
  953. signed portBASE_TYPE xParameterStringLength, xReturn;
  954. portBASE_TYPE xParameterNumber = 1;
  955. char str[110];
  956. uint8_t i;
  957. ( void ) pcCommandString;
  958. ( void ) xWriteBufferLen;
  959. configASSERT( pcWriteBuffer );
  960. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  961. /* Obtain the parameter string. */
  962. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  963. (
  964. pcCommandString, /* The command string itself. */
  965. xParameterNumber, /* Return the next parameter. */
  966. &xParameterStringLength /* Store the parameter string length. */
  967. );
  968. if (pcParameterString == NULL) {
  969. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  970. return pdFALSE;
  971. }
  972. for (i = 0; i < ARG_NETWORK_ALL; i ++) {
  973. if ( strncmp( ( const char * ) pcParameterString, network_args_list[i], strlen(network_args_list[i]) ) == 0
  974. && xParameterStringLength == strlen(network_args_list[i])) {
  975. break;
  976. }
  977. }
  978. if (cli_state->user_id != ADMIN && i != ARG_NETWORK_INFO) {
  979. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  980. return pdFALSE;
  981. }
  982. if (i != ARG_NETWORK_ALL && i != ARG_NETWORK_DHCP && i != ARG_NETWORK_INFO) {
  983. if (sSettings.sWebTempParams.dhcpEnable) {
  984. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  985. return pdFALSE;
  986. }
  987. }
  988. xParameterNumber ++;
  989. /* Obtain the parameter string. */
  990. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  991. (
  992. pcCommandString, /* The command string itself. */
  993. xParameterNumber, /* Return the next parameter. */
  994. &xParameterStringLength /* Store the parameter string length. */
  995. );
  996. if (pcParameterString == NULL) {
  997. if (i == ARG_NETWORK_INFO) {
  998. net_config_param(pcWriteBuffer);
  999. } else {
  1000. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1001. }
  1002. return pdFALSE;
  1003. }
  1004. memset(str, 0, sizeof(str));
  1005. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1006. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1007. xParameterStringLength = sizeof(str) - 1;
  1008. }
  1009. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1010. switch (i) {
  1011. case ARG_NETWORK_DHCP:
  1012. if (strncmp(str, "ENA", 3) == 0) {
  1013. SetUDPDhcpStateStr("True");
  1014. strcpy( ( char * ) pcWriteBuffer,
  1015. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1016. } else if (strncmp(str, "DIS", 3) == 0) {
  1017. SetUDPDhcpStateStr("False");
  1018. strcpy( ( char * ) pcWriteBuffer,
  1019. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1020. } else {
  1021. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1022. }
  1023. break;
  1024. case ARG_NETWORK_IP:
  1025. if (xParameterStringLength <= 15) {
  1026. if (ipaddr_addr(str) != IPADDR_NONE) {
  1027. SetIPStr(str);
  1028. strcpy( ( char * ) pcWriteBuffer,
  1029. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1030. } else {
  1031. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1032. }
  1033. } else {
  1034. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1035. }
  1036. break;
  1037. case ARG_NETWORK_GW:
  1038. if (xParameterStringLength <= 15) {
  1039. if (ipaddr_addr(str) != IPADDR_NONE) {
  1040. SetGatewayStr(str);
  1041. strcpy( ( char * ) pcWriteBuffer,
  1042. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1043. } else {
  1044. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1045. }
  1046. } else {
  1047. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1048. }
  1049. break;
  1050. case ARG_NETWORK_MASK:
  1051. if (xParameterStringLength <= 15) {
  1052. if (ipaddr_addr(str) != IPADDR_NONE) {
  1053. SetMaskStr(str);
  1054. strcpy( ( char * ) pcWriteBuffer,
  1055. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1056. } else {
  1057. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1058. }
  1059. } else {
  1060. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1061. }
  1062. break;
  1063. default:
  1064. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1065. break;
  1066. }
  1067. xReturn = pdFALSE;
  1068. return xReturn;
  1069. }
  1070. /*
  1071. * Implements the snmp command.
  1072. */
  1073. static portBASE_TYPE prvTaskSNMPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1074. {
  1075. int8_t *pcParameterString;
  1076. signed portBASE_TYPE xParameterStringLength, xReturn;
  1077. portBASE_TYPE xParameterNumber = 1;
  1078. char str[20];
  1079. char temp_str[20];
  1080. uint8_t i;
  1081. ( void ) pcCommandString;
  1082. ( void ) xWriteBufferLen;
  1083. configASSERT( pcWriteBuffer );
  1084. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1085. /* Obtain the parameter string. */
  1086. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1087. (
  1088. pcCommandString, /* The command string itself. */
  1089. xParameterNumber, /* Return the next parameter. */
  1090. &xParameterStringLength /* Store the parameter string length. */
  1091. );
  1092. if (pcParameterString == NULL) {
  1093. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1094. return pdFALSE;
  1095. }
  1096. for (i = 0; i < ARG_SNMP_ALL; i ++) {
  1097. if ( strncmp( ( const char * ) pcParameterString, snmp_args_list[i], strlen(snmp_args_list[i]) ) == 0
  1098. && xParameterStringLength == strlen(snmp_args_list[i])) {
  1099. break;
  1100. }
  1101. }
  1102. if (cli_state->user_id != ADMIN && i != ARG_SNMP_INFO) {
  1103. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1104. return pdFALSE;
  1105. }
  1106. xParameterNumber ++;
  1107. /* Obtain the parameter string. */
  1108. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1109. (
  1110. pcCommandString, /* The command string itself. */
  1111. xParameterNumber, /* Return the next parameter. */
  1112. &xParameterStringLength /* Store the parameter string length. */
  1113. );
  1114. xParameterNumber ++;
  1115. if (pcParameterString == NULL) {
  1116. if (i == ARG_SNMP_INFO) {
  1117. snmp_config_param(pcWriteBuffer);
  1118. } else {
  1119. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1120. }
  1121. return pdFALSE;
  1122. }
  1123. memset(str, 0, sizeof(str));
  1124. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1125. xParameterStringLength = sizeof(str) - 1;
  1126. }
  1127. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1128. switch (i) {
  1129. case ARG_SNMP_SERVER:
  1130. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1131. int32_t temp = atoi(str);
  1132. if (temp > 0 && temp < 6) {
  1133. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1134. (
  1135. pcCommandString, /* The command string itself. */
  1136. xParameterNumber, /* Return the next parameter. */
  1137. &xParameterStringLength /* Store the parameter string length. */
  1138. );
  1139. if (pcParameterString != NULL) {
  1140. memset(str, 0, sizeof(str));
  1141. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1142. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1143. xParameterStringLength = sizeof(str) - 1;
  1144. }
  1145. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1146. if (xParameterStringLength <= 15) {
  1147. if (ipaddr_addr(str) != IPADDR_NONE) {
  1148. switch (temp) {
  1149. case 1:
  1150. SetManagerIp(str);
  1151. break;
  1152. case 2:
  1153. SetManagerIp2(str);
  1154. break;
  1155. case 3:
  1156. SetManagerIp3(str);
  1157. break;
  1158. case 4:
  1159. SetManagerIp4(str);
  1160. break;
  1161. case 5:
  1162. SetManagerIp5(str);
  1163. break;
  1164. }
  1165. if (temp > 0 && temp < 6) {
  1166. SETTINGS_Save();
  1167. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  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. } else {
  1176. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1177. }
  1178. } else {
  1179. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1180. }
  1181. } else {
  1182. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1183. }
  1184. break;
  1185. case ARG_SNMP_COMMUNITY:
  1186. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1187. (
  1188. pcCommandString, /* The command string itself. */
  1189. xParameterNumber, /* Return the next parameter. */
  1190. &xParameterStringLength /* Store the parameter string length. */
  1191. );
  1192. if (pcParameterString != NULL) {
  1193. memset(temp_str, 0, sizeof(temp_str));
  1194. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1195. if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
  1196. xParameterStringLength = sizeof(temp_str) - 1;
  1197. }
  1198. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1199. if (control_string_en_digit(temp_str, strlen(temp_str))) {
  1200. if (strncmp(str, "read", 4) == 0) {
  1201. SetReadCommunity(temp_str);
  1202. SETTINGS_Save();
  1203. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1204. } else if (strncmp(str, "write", 5) == 0) {
  1205. SetWriteCommunity(temp_str);
  1206. SETTINGS_Save();
  1207. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1208. } else {
  1209. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1210. }
  1211. } else {
  1212. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1213. }
  1214. } else {
  1215. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1216. }
  1217. break;
  1218. default:
  1219. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1220. break;
  1221. }
  1222. xReturn = pdFALSE;
  1223. return xReturn;
  1224. }
  1225. /*
  1226. * Implements the akb command.
  1227. */
  1228. static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1229. {
  1230. int8_t *pcParameterString;
  1231. signed portBASE_TYPE xParameterStringLength, xReturn;
  1232. portBASE_TYPE xParameterNumber = 1;
  1233. char str[110];
  1234. uint8_t i;
  1235. uint8_t fail = 0;
  1236. uint16_t temp = 0;
  1237. float value = 0;
  1238. ( void ) pcCommandString;
  1239. ( void ) xWriteBufferLen;
  1240. configASSERT( pcWriteBuffer );
  1241. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1242. /* Obtain the parameter string. */
  1243. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1244. (
  1245. pcCommandString, /* The command string itself. */
  1246. xParameterNumber, /* Return the next parameter. */
  1247. &xParameterStringLength /* Store the parameter string length. */
  1248. );
  1249. if (pcParameterString == NULL) {
  1250. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1251. return pdFALSE;
  1252. }
  1253. for (i = 0; i < ARG_AKB_ALL; i ++) {
  1254. if ( strncmp( ( const char * ) pcParameterString, akb_args_list[i], strlen(akb_args_list[i]) ) == 0
  1255. && xParameterStringLength == strlen(akb_args_list[i])) {
  1256. break;
  1257. }
  1258. }
  1259. if (cli_state->user_id != ADMIN && i != ARG_AKB_INFO) {
  1260. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1261. return pdFALSE;
  1262. }
  1263. xParameterNumber ++;
  1264. /* Obtain the parameter string. */
  1265. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1266. (
  1267. pcCommandString, /* The command string itself. */
  1268. xParameterNumber, /* Return the next parameter. */
  1269. &xParameterStringLength /* Store the parameter string length. */
  1270. );
  1271. if (pcParameterString == NULL) {
  1272. if (i == ARG_AKB_INFO) {
  1273. akb_config_param(pcWriteBuffer);
  1274. } else {
  1275. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1276. }
  1277. return pdFALSE;
  1278. }
  1279. memset(str, 0, sizeof(str));
  1280. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1281. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1282. xParameterStringLength = sizeof(str) - 2;
  1283. }
  1284. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1285. #ifdef HARDWARE_BT6709
  1286. if (i != ARG_AKB_DATASET)
  1287. #endif
  1288. {
  1289. for (uint8_t j = 0; j < xParameterStringLength; j ++) {
  1290. if (!isfloatdigit(str[j])) {
  1291. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1292. return pdFALSE;
  1293. }
  1294. }
  1295. value = atof(str);
  1296. }
  1297. switch (i) {
  1298. case ARG_AKB_VOLT_CELL_MIN:
  1299. if (value < sSettings.UPS_Setting.Ucellmax && value > MIN_VOLT_CELL_RANGE) {
  1300. SetUPSVoltCellMinStr(str);
  1301. SETTINGS_Save();
  1302. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1303. } else {
  1304. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1305. }
  1306. break;
  1307. case ARG_AKB_VOLT_CELL_MAX:
  1308. if (value > sSettings.UPS_Setting.Ucellmin && value <= MAX_VOLT_CELL_RANGE) {
  1309. SetUPSVoltCellMaxStr(str);
  1310. SETTINGS_Save();
  1311. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1312. } else {
  1313. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1314. }
  1315. break;
  1316. #ifdef HARDWARE_BT6709
  1317. case ARG_AKB_CAPACITY:
  1318. if (value >= CAPACITY_MIN_RANGE && value <= CAPACITY_MAX_RANGE && (value - (int32_t)value) == 0) {
  1319. SetCapacityNominalAKBStr(str);
  1320. SETTINGS_Save();
  1321. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1322. } else {
  1323. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1324. }
  1325. break;
  1326. case ARG_AKB_VOLT:
  1327. if (value >= AKB_VOLTAGE_MIN_RANGE && value <= AKB_VOLTAGE_MAX_RANGE && ((int32_t)value % 12) == 0 && (value - (int32_t)value) == 0) {
  1328. SetVoltageAKBNominalStr(str);
  1329. SETTINGS_Save();
  1330. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1331. } else {
  1332. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1333. }
  1334. break;
  1335. case ARG_AKB_LIFETIME:
  1336. if (value >= LIFETIME_MIN_RANGE && value <= LIFETIME_MAX_RANGE && (value - (int32_t)value) == 0) {
  1337. SetLifeTimeAKBStr(str);
  1338. SETTINGS_Save();
  1339. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1340. } else {
  1341. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1342. }
  1343. break;
  1344. case ARG_AKB_DATASET:
  1345. if (xParameterStringLength == 10) {
  1346. if (strncmp( str, "0000-00-00", 10) == 0) {
  1347. memset(str, 0, sizeof(str));
  1348. SetDataSetAKBStr(str);
  1349. SETTINGS_Save();
  1350. xReturn = pdFALSE;
  1351. return xReturn;
  1352. }
  1353. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  1354. if (j != 4 && j != 7) {
  1355. if (str[j] > 0x39 || str[j] < 0x30) {
  1356. fail = 1;
  1357. }
  1358. } else if (j == 4 || j == 7) {
  1359. if (str[j] != '-') {
  1360. fail = 1;
  1361. }
  1362. }
  1363. }
  1364. if (!fail) {
  1365. temp = 1000 * (str[0] - 0x30) + 100 * (str[1] - 0x30) + 10 * (str[2] - 0x30) + str[3] - 0x30;
  1366. if (temp > 2099 || temp < 2000) {
  1367. fail = 1;
  1368. }
  1369. temp = 0;
  1370. temp = 10 * (str[5] - 0x30) + (str[6] - 0x30);
  1371. if (temp > 12) {
  1372. fail = 1;
  1373. }
  1374. temp = 0;
  1375. temp = 10 * (str[8] - 0x30) + (str[9] - 0x30);
  1376. if (temp > 31) {
  1377. fail = 1;
  1378. }
  1379. }
  1380. } else {
  1381. fail = 1;
  1382. }
  1383. if (!fail) {
  1384. SetDataSetAKBStr(str);
  1385. SETTINGS_Save();
  1386. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1387. } else {
  1388. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1389. }
  1390. break;
  1391. case ARG_AKB_UPS_POWER:
  1392. if (value >= UPS_POWER_MIN_RANGE && value <= UPS_POWER_MAX_RANGE && ((int32_t)value % 50) == 0 && (value - (int32_t)value) == 0) {
  1393. SetUPSPowerStr(str);
  1394. SETTINGS_Save();
  1395. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1396. } else {
  1397. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1398. }
  1399. break;
  1400. #endif
  1401. default:
  1402. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1403. break;
  1404. }
  1405. xReturn = pdFALSE;
  1406. return xReturn;
  1407. }
  1408. /*
  1409. * Implements the alarm command.
  1410. */
  1411. static portBASE_TYPE prvTaskAlarmCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1412. {
  1413. int8_t *pcParameterString;
  1414. signed portBASE_TYPE xParameterStringLength, xReturn;
  1415. portBASE_TYPE xParameterNumber = 1;
  1416. char str[110];
  1417. uint8_t i, j;
  1418. float value = 0;
  1419. uint8_t k;
  1420. ( void ) pcCommandString;
  1421. ( void ) xWriteBufferLen;
  1422. configASSERT( pcWriteBuffer );
  1423. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1424. /* Obtain the parameter string. */
  1425. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1426. (
  1427. pcCommandString, /* The command string itself. */
  1428. xParameterNumber, /* Return the next parameter. */
  1429. &xParameterStringLength /* Store the parameter string length. */
  1430. );
  1431. if (pcParameterString == NULL) {
  1432. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1433. return pdFALSE;
  1434. }
  1435. for (i = 0; i < ARG_ALARM_TYPE_ALL; i ++) {
  1436. if ( strncmp( ( const char * ) pcParameterString, type_alarm_args_list[i], strlen(type_alarm_args_list[i]) ) == 0
  1437. && xParameterStringLength == strlen(type_alarm_args_list[i])) {
  1438. break;
  1439. }
  1440. }
  1441. if (cli_state->user_id != ADMIN && i != ARG_ALARM_INFO) {
  1442. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1443. return pdFALSE;
  1444. }
  1445. xParameterNumber ++;
  1446. /* Obtain the parameter string. */
  1447. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1448. (
  1449. pcCommandString, /* The command string itself. */
  1450. xParameterNumber, /* Return the next parameter. */
  1451. &xParameterStringLength /* Store the parameter string length. */
  1452. );
  1453. if (pcParameterString == NULL) {
  1454. if (i == ARG_ALARM_INFO) {
  1455. alarm_config_param(pcWriteBuffer);
  1456. } else {
  1457. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1458. }
  1459. return pdFALSE;
  1460. }
  1461. for (j = 0; j < ARG_ALARM_ALL; j ++) {
  1462. if ( strncmp( ( const char * ) pcParameterString, alarm_args_list[j], strlen(alarm_args_list[j]) ) == 0 ) {
  1463. break;
  1464. }
  1465. }
  1466. xParameterNumber ++;
  1467. /* Obtain the parameter string. */
  1468. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1469. (
  1470. pcCommandString, /* The command string itself. */
  1471. xParameterNumber, /* Return the next parameter. */
  1472. &xParameterStringLength /* Store the parameter string length. */
  1473. );
  1474. if (pcParameterString == NULL) {
  1475. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1476. return pdFALSE;
  1477. }
  1478. memset(str, 0, sizeof(str));
  1479. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1480. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1481. xParameterStringLength = sizeof(str) - 2;
  1482. }
  1483. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1484. switch (i) {
  1485. case ARG_ALARM_TEMP:
  1486. switch (j) {
  1487. case ARG_ALARM_LINE_LOW:
  1488. for (k = 0; k < xParameterStringLength; k ++) {
  1489. if (!isdigit_int(str[k])) {
  1490. if (k == 0 && str[k] == '-') {
  1491. continue;
  1492. } else {
  1493. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1494. return pdFALSE;
  1495. }
  1496. }
  1497. }
  1498. value = atof(str);
  1499. if (value >= MIN_TEMP_MIN_RANGE && value <= MIN_TEMP_MAX_RANGE) {
  1500. SetTemperatureAlarmLowRangeStr(str);
  1501. SETTINGS_Save();
  1502. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1503. } else {
  1504. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1505. }
  1506. break;
  1507. case ARG_ALARM_LINE_HIGH:
  1508. for (k = 0; k < xParameterStringLength; k ++) {
  1509. if (!isdigit_int(str[k])) {
  1510. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1511. return pdFALSE;
  1512. }
  1513. }
  1514. value = atof(str);
  1515. if (value >= MAX_TEMP_MIN_RANGE && value <= MAX_TEMP_MAX_RANGE) {
  1516. SetTemperatureAlarmHighRangeStr(str);
  1517. SETTINGS_Save();
  1518. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1519. } else {
  1520. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1521. }
  1522. break;
  1523. case ARG_ALARM_LINE_HIST:
  1524. for (k = 0; k < xParameterStringLength; k ++) {
  1525. if (!isfloatdigit(str[k])) {
  1526. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1527. return pdFALSE;
  1528. }
  1529. }
  1530. value = atof(str);
  1531. if (value >= HIST_TEMP_MIN_RANGE && value <= HIST_TEMP_MAX_RANGE) {
  1532. SetTemperatureAlarmHisteStr(str);
  1533. SETTINGS_Save();
  1534. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1535. } else {
  1536. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1537. }
  1538. break;
  1539. default:
  1540. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1541. break;
  1542. }
  1543. break;
  1544. case ARG_ALARM_LOAD:
  1545. switch (j) {
  1546. case ARG_ALARM_LINE_LOW:
  1547. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1548. break;
  1549. case ARG_ALARM_LINE_HIGH:
  1550. for (k = 0; k < xParameterStringLength; k ++) {
  1551. if (!isdigit_int(str[k])) {
  1552. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1553. return pdFALSE;
  1554. }
  1555. }
  1556. value = atof(str);
  1557. if (value >= MAX_LOAD_MIN_RANGE && value <= MAX_LOAD_MAX_RANGE) {
  1558. SetLoadAlarmHighRangeStr(str);
  1559. SETTINGS_Save();
  1560. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1561. } else {
  1562. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1563. }
  1564. break;
  1565. case ARG_ALARM_LINE_HIST:
  1566. for (k = 0; k < xParameterStringLength; k ++) {
  1567. if (!isfloatdigit(str[k])) {
  1568. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1569. return pdFALSE;
  1570. }
  1571. }
  1572. value = atof(str);
  1573. if (value >= HIST_LOAD_MIN_RANGE && value <= HIST_LOAD_MAX_RANGE) {
  1574. SetLoadAlarmHistStr(str);
  1575. SETTINGS_Save();
  1576. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1577. } else {
  1578. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1579. }
  1580. break;
  1581. default:
  1582. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1583. break;
  1584. }
  1585. break;
  1586. case ARG_ALARM_VOUT:
  1587. switch (j) {
  1588. case ARG_ALARM_LINE_LOW:
  1589. for (k = 0; k < xParameterStringLength; k ++) {
  1590. if (!isdigit_int(str[k])) {
  1591. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1592. return pdFALSE;
  1593. }
  1594. }
  1595. value = atof(str);
  1596. if (value >= MIN_VAC_MIN_RANGE && value <= MIN_VAC_MAX_RANGE) {
  1597. SetVACAlarmLowRangeStr(str);
  1598. SETTINGS_Save();
  1599. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1600. } else {
  1601. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1602. }
  1603. break;
  1604. case ARG_ALARM_LINE_HIGH:
  1605. for (k = 0; k < xParameterStringLength; k ++) {
  1606. if (!isdigit_int(str[k])) {
  1607. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1608. return pdFALSE;
  1609. }
  1610. }
  1611. value = atof(str);
  1612. if (value >= MAX_VAC_MIN_RANGE && value <= MAX_VAC_MAX_RANGE) {
  1613. SetVACAlarmHighRangeStr(str);
  1614. SETTINGS_Save();
  1615. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1616. } else {
  1617. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1618. }
  1619. break;
  1620. case ARG_ALARM_LINE_HIST:
  1621. for (k = 0; k < xParameterStringLength; k ++) {
  1622. if (!isdigit_int(str[k])) {
  1623. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1624. return pdFALSE;
  1625. }
  1626. }
  1627. value = atof(str);
  1628. if (value >= HIST_VAC_MIN_RANGE && value <= HIST_VAC_MAX_RANGE) {
  1629. SetVACAlarmHisteStr(str);
  1630. SETTINGS_Save();
  1631. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1632. } else {
  1633. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1634. }
  1635. break;
  1636. default:
  1637. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1638. break;
  1639. }
  1640. break;
  1641. default:
  1642. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1643. break;
  1644. }
  1645. xReturn = pdFALSE;
  1646. return xReturn;
  1647. }
  1648. #ifdef HARDWARE_BT6709
  1649. /*
  1650. * Implements the notification command.
  1651. */
  1652. static portBASE_TYPE prvTaskNotificationCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1653. const int8_t *pcCommandString )
  1654. {
  1655. int8_t *pcParameterString;
  1656. signed portBASE_TYPE xParameterStringLength, xReturn;
  1657. portBASE_TYPE xParameterNumber = 1;
  1658. char str[20];
  1659. char temp_str[20];
  1660. uint8_t i;
  1661. char *beginValue;
  1662. uint8_t len;
  1663. ( void ) pcCommandString;
  1664. ( void ) xWriteBufferLen;
  1665. configASSERT( pcWriteBuffer );
  1666. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1667. /* Obtain the parameter string. */
  1668. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1669. (
  1670. pcCommandString, /* The command string itself. */
  1671. xParameterNumber, /* Return the next parameter. */
  1672. &xParameterStringLength /* Store the parameter string length. */
  1673. );
  1674. if (pcParameterString == NULL) {
  1675. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1676. return pdFALSE;
  1677. }
  1678. for (i = 0; i < ARG_NOTIFICATION_ALL; i ++) {
  1679. if ( strncmp( ( const char * ) pcParameterString, notification_args_list[i], strlen(notification_args_list[i]) ) == 0
  1680. && xParameterStringLength == strlen(notification_args_list[i])) {
  1681. break;
  1682. }
  1683. }
  1684. if (cli_state->user_id != ADMIN && i != ARG_NOTIFICATION_INFO) {
  1685. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1686. return pdFALSE;
  1687. }
  1688. xParameterNumber ++;
  1689. /* Obtain the parameter string. */
  1690. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1691. (
  1692. pcCommandString, /* The command string itself. */
  1693. xParameterNumber, /* Return the next parameter. */
  1694. &xParameterStringLength /* Store the parameter string length. */
  1695. );
  1696. xParameterNumber ++;
  1697. if (pcParameterString == NULL) {
  1698. if (i == ARG_NOTIFICATION_INFO) {
  1699. notification_param(pcWriteBuffer);
  1700. } else {
  1701. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1702. }
  1703. return pdFALSE;
  1704. }
  1705. memset(str, 0, sizeof(str));
  1706. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1707. xParameterStringLength = sizeof(str) - 1;
  1708. }
  1709. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1710. switch (i) {
  1711. case ARG_NOTIFICATION_SET:
  1712. if (xParameterStringLength >= 1) {
  1713. for(uint32_t k = 0; k < xParameterStringLength; k ++) {
  1714. if (!isdigit_int(str[k])) {
  1715. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1716. return pdFALSE;
  1717. }
  1718. }
  1719. int32_t temp = atoi(str);
  1720. uint8_t value_notification = 0;
  1721. if (temp > 0 && temp < ALL_TRAPS) {
  1722. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1723. (
  1724. pcCommandString, /* The command string itself. */
  1725. xParameterNumber, /* Return the next parameter. */
  1726. &xParameterStringLength /* Store the parameter string length. */
  1727. );
  1728. if (pcParameterString != NULL && xParameterStringLength == 3) {
  1729. if (strncmp(pcParameterString, "ENA", 3) == 0) {
  1730. value_notification = 1;
  1731. SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
  1732. SETTINGS_Save();
  1733. } else if (strncmp(pcParameterString, "DIS", 3) == 0) {
  1734. SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
  1735. SETTINGS_Save();
  1736. } else {
  1737. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1738. }
  1739. } else {
  1740. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1741. }
  1742. } else {
  1743. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1744. }
  1745. } else {
  1746. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1747. }
  1748. break;
  1749. default:
  1750. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1751. break;
  1752. }
  1753. xReturn = pdFALSE;
  1754. return xReturn;
  1755. }
  1756. /*
  1757. * Implements the whitelist command.
  1758. */
  1759. static portBASE_TYPE prvTaskWhiteListCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1760. const int8_t *pcCommandString )
  1761. {
  1762. int8_t *pcParameterString;
  1763. signed portBASE_TYPE xParameterStringLength, xReturn;
  1764. portBASE_TYPE xParameterNumber = 1;
  1765. char str[20];
  1766. char temp_str[20];
  1767. uint8_t i;
  1768. char *beginValue;
  1769. uint8_t len;
  1770. int32_t temp;
  1771. ( void ) pcCommandString;
  1772. ( void ) xWriteBufferLen;
  1773. configASSERT( pcWriteBuffer );
  1774. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1775. /* Obtain the parameter string. */
  1776. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1777. (
  1778. pcCommandString, /* The command string itself. */
  1779. xParameterNumber, /* Return the next parameter. */
  1780. &xParameterStringLength /* Store the parameter string length. */
  1781. );
  1782. if (pcParameterString == NULL) {
  1783. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1784. return pdFALSE;
  1785. }
  1786. for (i = 0; i < ARG_WHITELIST_ALL; i ++) {
  1787. if ( strncmp( ( const char * ) pcParameterString, whitelist_args_list[i], strlen(whitelist_args_list[i]) ) == 0
  1788. && xParameterStringLength == strlen(whitelist_args_list[i])) {
  1789. break;
  1790. }
  1791. }
  1792. if (cli_state->user_id != ADMIN && i != ARG_WHITELIST_INFO) {
  1793. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1794. return pdFALSE;
  1795. }
  1796. xParameterNumber ++;
  1797. /* Obtain the parameter string. */
  1798. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1799. (
  1800. pcCommandString, /* The command string itself. */
  1801. xParameterNumber, /* Return the next parameter. */
  1802. &xParameterStringLength /* Store the parameter string length. */
  1803. );
  1804. xParameterNumber ++;
  1805. if (pcParameterString == NULL) {
  1806. if (i == ARG_WHITELIST_INFO) {
  1807. whitelist_config_param(pcWriteBuffer);
  1808. } else {
  1809. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1810. }
  1811. return pdFALSE;
  1812. }
  1813. memset(str, 0, sizeof(str));
  1814. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1815. xParameterStringLength = sizeof(str) - 1;
  1816. }
  1817. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1818. switch (i) {
  1819. case ARG_WHITELIST_RANGE:
  1820. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1821. temp = atoi(str);
  1822. if (temp > 0 && temp < 6) {
  1823. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1824. (
  1825. pcCommandString, /* The command string itself. */
  1826. xParameterNumber, /* Return the next parameter. */
  1827. &xParameterStringLength /* Store the parameter string length. */
  1828. );
  1829. if (pcParameterString != NULL) {
  1830. memset(str, 0, sizeof(str));
  1831. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1832. if (xParameterStringLength > (int32_t)sizeof(str)) {
  1833. xParameterStringLength = sizeof(str) - 1;
  1834. }
  1835. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1836. if (xParameterStringLength <= 19) {
  1837. beginValue = strpbrk(str, "/");
  1838. if (beginValue == NULL) {
  1839. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1840. return pdFALSE;
  1841. }
  1842. int32_t mask = atoi(&beginValue[1]);
  1843. len = beginValue - str;
  1844. memset(temp_str, 0, sizeof(temp_str));
  1845. strncpy(temp_str, str, len);
  1846. for (uint8_t j = (len + 1); j < xParameterStringLength; j++) {
  1847. if (!isdigit_int(str[j])) {
  1848. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1849. return pdFALSE;
  1850. }
  1851. }
  1852. if (ipaddr_addr(temp_str) != IPADDR_NONE && (mask <= 32 && mask >= 0)) {
  1853. SetWhiteListSTR(str, (temp - 1));
  1854. strcpy( ( char * ) pcWriteBuffer,
  1855. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1856. } else {
  1857. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1858. }
  1859. } else {
  1860. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1861. }
  1862. } else {
  1863. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1864. }
  1865. } else {
  1866. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1867. }
  1868. } else {
  1869. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1870. }
  1871. break;
  1872. case ARG_WHITELIST_RESET:
  1873. if (xParameterStringLength == 1 && isdigit_int(str[0])) {
  1874. temp = atoi(str);
  1875. if (temp > 0 && temp < 6) {
  1876. memset(str, 0, sizeof(str));
  1877. SetWhiteListSTR(str, (temp - 1));
  1878. strcpy( ( char * ) pcWriteBuffer,
  1879. "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1880. } else {
  1881. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1882. }
  1883. } else {
  1884. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1885. }
  1886. break;
  1887. default:
  1888. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1889. break;
  1890. }
  1891. xReturn = pdFALSE;
  1892. return xReturn;
  1893. }
  1894. #endif
  1895. /*
  1896. * Implements the change password command.
  1897. */
  1898. static portBASE_TYPE prvTaskUserCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  1899. {
  1900. int8_t *pcParameterString;
  1901. signed portBASE_TYPE xParameterStringLength, xReturn;
  1902. portBASE_TYPE xParameterNumber = 1;
  1903. uint8_t i;
  1904. char temp_str[MAX_WEB_LOGIN_LEN];
  1905. char WebLogin[MAX_WEB_LOGIN_LEN];
  1906. uint8_t valueLen, user_id;
  1907. const int8_t *const pcChangePWDHeader = ( int8_t * ) "\r\nВведите новый пароль:";
  1908. ( void ) pcCommandString;
  1909. ( void ) xWriteBufferLen;
  1910. configASSERT( pcWriteBuffer );
  1911. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1912. if (cli_state->user_id != ADMIN) {
  1913. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1914. return pdFALSE;
  1915. }
  1916. /* Obtain the parameter string. */
  1917. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1918. (
  1919. pcCommandString, /* The command string itself. */
  1920. xParameterNumber, /* Return the next parameter. */
  1921. &xParameterStringLength /* Store the parameter string length. */
  1922. );
  1923. if (pcParameterString == NULL) {
  1924. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1925. return pdFALSE;
  1926. }
  1927. for (i = 0; i < ARG_USER_ALL; i ++) {
  1928. if ( strncmp( ( const char * ) pcParameterString, user_args_list[i], strlen(user_args_list[i]) ) == 0 ) {
  1929. break;
  1930. }
  1931. }
  1932. xParameterNumber ++;
  1933. /* Obtain the parameter string. */
  1934. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1935. (
  1936. pcCommandString, /* The command string itself. */
  1937. xParameterNumber, /* Return the next parameter. */
  1938. &xParameterStringLength /* Store the parameter string length. */
  1939. );
  1940. if (i == ARG_USER_PWD) {
  1941. memset(temp_str, 0, sizeof(temp_str));
  1942. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1943. if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
  1944. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1945. } else {
  1946. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1947. // FIXME proper context
  1948. #if 0
  1949. for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
  1950. GetUserLogin(user_id, WebLogin, &valueLen);
  1951. /* Check login and password */
  1952. if (strncmp(WebLogin, temp_str, MAX_WEB_LOGIN_LEN) == 0) {
  1953. /* Login and pass are valid */
  1954. id_change_pwd = user_id;
  1955. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcChangePWDHeader, strlen( ( char * ) pcChangePWDHeader ) );
  1956. telnetState = CLI_CHANGE_PWD;
  1957. break;
  1958. }
  1959. }
  1960. if (telnetState != CLI_CHANGE_PWD) {
  1961. #endif
  1962. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1963. //}
  1964. }
  1965. } else {
  1966. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1967. }
  1968. xReturn = pdFALSE;
  1969. return xReturn;
  1970. }
  1971. /*
  1972. * Implements the config command.
  1973. */
  1974. static portBASE_TYPE prvTaskConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  1975. const int8_t *pcCommandString )
  1976. {
  1977. int8_t *pcParameterString;
  1978. signed portBASE_TYPE xParameterStringLength, xReturn;
  1979. portBASE_TYPE xParameterNumber = 1;
  1980. char str[110];
  1981. uint8_t i;
  1982. static uint8_t config_menu = 0;
  1983. const int8_t *const pcInfoTableHeader = ( int8_t * )
  1984. "\r\n*********Конфигурация Контроллера*********\r\n";
  1985. ( void ) pcCommandString;
  1986. ( void ) xWriteBufferLen;
  1987. configASSERT( pcWriteBuffer );
  1988. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1989. /* Obtain the parameter string. */
  1990. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1991. (
  1992. pcCommandString, /* The command string itself. */
  1993. xParameterNumber, /* Return the next parameter. */
  1994. &xParameterStringLength /* Store the parameter string length. */
  1995. );
  1996. if (pcParameterString == NULL) {
  1997. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1998. return pdFALSE;
  1999. }
  2000. for (i = 0; i < ARG_CONFIG_ALL; i ++) {
  2001. if ( strncmp( ( const char * ) pcParameterString, config_args_list[i], strlen(config_args_list[i]) ) == 0
  2002. && xParameterStringLength == strlen(config_args_list[i])) {
  2003. break;
  2004. }
  2005. }
  2006. if (cli_state->user_id != ADMIN && i != ARG_CONFIG_INFO) {
  2007. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2008. return pdFALSE;
  2009. }
  2010. xParameterNumber ++;
  2011. /* Obtain the parameter string. */
  2012. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2013. (
  2014. pcCommandString, /* The command string itself. */
  2015. xParameterNumber, /* Return the next parameter. */
  2016. &xParameterStringLength /* Store the parameter string length. */
  2017. );
  2018. if (pcParameterString == NULL) {
  2019. switch (i) {
  2020. case ARG_CONFIG_INFO:
  2021. switch (config_menu) {
  2022. case PARAM_CONFIG_SNMP:
  2023. /* Return the next command help string, before moving the pointer on to
  2024. the next command in the list. */
  2025. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  2026. snmp_config_param(pcWriteBuffer);
  2027. break;
  2028. #ifdef HARDWARE_BT6707
  2029. case PARAM_CONFIG_INOUTS:
  2030. inouts_config_param(pcWriteBuffer);
  2031. break;
  2032. #endif
  2033. case PARAM_CONFIG_AKB:
  2034. akb_config_param(pcWriteBuffer);
  2035. break;
  2036. case PARAM_CONFIG_ALARM:
  2037. alarm_config_param(pcWriteBuffer);
  2038. break;
  2039. #ifdef HARDWARE_BT6709
  2040. case PARAM_CONFIG_WHITELIST:
  2041. whitelist_config_param(pcWriteBuffer);
  2042. break;
  2043. #endif
  2044. case PARAM_CONFIG_NET:
  2045. net_config_param(pcWriteBuffer);
  2046. break;
  2047. case PARAM_CONFIG_TIME:
  2048. time_config_param(pcWriteBuffer);
  2049. break;
  2050. }
  2051. config_menu ++;
  2052. if (config_menu == PARAM_CONFIG_ALL) {
  2053. config_menu = 0;
  2054. return pdFALSE;
  2055. } else {
  2056. return pdTRUE;
  2057. }
  2058. break;
  2059. default:
  2060. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2061. break;
  2062. }
  2063. return pdFALSE;
  2064. }
  2065. if (i == ARG_CONFIG_LOAD) {
  2066. memset(str, 0, sizeof(str));
  2067. xParameterStringLength = strlen(( const char * ) pcParameterString);
  2068. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2069. xParameterStringLength = sizeof(str) - 1;
  2070. }
  2071. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2072. if (xParameterStringLength < 13) {
  2073. if (strncmp(str, "default", 7) == 0) {
  2074. SNMP_SendUserTrap(DEVICE_RESTORED);
  2075. log_event_data(LOG_SYSTEM_DEFCONFIG, name_login_telnet);
  2076. vTaskDelay(500);
  2077. SETTINGS_SetPartDefault();
  2078. SETTINGS_Save();
  2079. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  2080. strcpy( ( char * ) pcWriteBuffer,
  2081. "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
  2082. } else {
  2083. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2084. }
  2085. } else {
  2086. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2087. }
  2088. } else {
  2089. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2090. }
  2091. xReturn = pdFALSE;
  2092. return xReturn;
  2093. }
  2094. /*
  2095. * Implements the config command.
  2096. */
  2097. static portBASE_TYPE prvTaskNetConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2098. const int8_t *pcCommandString )
  2099. {
  2100. int8_t *pcParameterString;
  2101. portBASE_TYPE xParameterNumber = 1;
  2102. signed portBASE_TYPE xParameterStringLength;
  2103. uint8_t i;
  2104. static start = 0;
  2105. ( void ) pcCommandString;
  2106. ( void ) xWriteBufferLen;
  2107. configASSERT( pcWriteBuffer );
  2108. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2109. /* Obtain the parameter string. */
  2110. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2111. (
  2112. pcCommandString, /* The command string itself. */
  2113. xParameterNumber, /* Return the next parameter. */
  2114. &xParameterStringLength /* Store the parameter string length. */
  2115. );
  2116. for (i = 0; i < ARG_NETCONFIG_ALL; i ++) {
  2117. if ( strncmp( ( const char * ) pcParameterString, netconfig_args_list[i], strlen(netconfig_args_list[i]) ) == 0
  2118. && xParameterStringLength == strlen(netconfig_args_list[i])) {
  2119. break;
  2120. }
  2121. }
  2122. if (cli_state->user_id != ADMIN) {
  2123. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2124. return pdFALSE;
  2125. }
  2126. switch (i) {
  2127. case ARG_NETCONFIG_APPLY:
  2128. if (!start) {
  2129. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  2130. if (GetStateWebReinit() == true) {
  2131. start = 1;
  2132. telnet_act = true;
  2133. SetWebReinitFlag(true);
  2134. HTTP_SaveSettings();
  2135. strcpy( ( char * ) pcWriteBuffer,
  2136. "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  2137. return pdTRUE;
  2138. }
  2139. } else {
  2140. telnet_act = true;
  2141. start = 0;
  2142. vTaskDelay(1010);
  2143. Reboot(TELNET_ACT);
  2144. }
  2145. break;
  2146. case ARG_NETCONFIG_CONFIRM:
  2147. telnet_act = true;
  2148. SetWebReinitFlag(false);
  2149. SetConfirmWebParamsFlag();
  2150. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  2151. break;
  2152. default:
  2153. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2154. break;
  2155. }
  2156. return pdFALSE;
  2157. }
  2158. /*
  2159. * Implements the history command.
  2160. */
  2161. static portBASE_TYPE prvTaskHistoryCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2162. const int8_t *pcCommandString )
  2163. {
  2164. int8_t *pcParameterString;
  2165. signed portBASE_TYPE xParameterStringLength, xReturn;
  2166. portBASE_TYPE xParameterNumber = 1;
  2167. char str[110];
  2168. uint8_t i;
  2169. static int16_t num_page = 0;
  2170. static int16_t num_page_temp = 1;
  2171. static bool start = true;
  2172. const int8_t *const pcUPShistoryTableHeader = ( int8_t * )
  2173. "\r\n***********Журнал событий ИБП***********\r\n";
  2174. const int8_t *const pcControllerHistoryTableHeader = ( int8_t * )
  2175. "\r\n***********Журнал событий Контроллера***********\r\n";
  2176. ( void ) pcCommandString;
  2177. ( void ) xWriteBufferLen;
  2178. configASSERT( pcWriteBuffer );
  2179. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  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. if (pcParameterString == NULL) {
  2188. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2189. return pdFALSE;
  2190. }
  2191. if ( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ) {
  2192. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2193. return pdFALSE;
  2194. }
  2195. xParameterNumber ++;
  2196. /* Obtain the parameter string. */
  2197. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2198. (
  2199. pcCommandString, /* The command string itself. */
  2200. xParameterNumber, /* Return the next parameter. */
  2201. &xParameterStringLength /* Store the parameter string length. */
  2202. );
  2203. for (i = 0; i < ARG_HISTORY_ALL; i ++) {
  2204. if ( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0
  2205. && xParameterStringLength == strlen(history_args_list[i])) {
  2206. break;
  2207. }
  2208. }
  2209. xParameterNumber ++;
  2210. /* Obtain the parameter string. */
  2211. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2212. (
  2213. pcCommandString, /* The command string itself. */
  2214. xParameterNumber, /* Return the next parameter. */
  2215. &xParameterStringLength /* Store the parameter string length. */
  2216. );
  2217. memset(str, 0, sizeof(str));
  2218. if (xParameterStringLength > 5) {
  2219. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2220. return pdFALSE;
  2221. }
  2222. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2223. if (num_page == 0) {
  2224. num_page = atoi(str);
  2225. if (num_page <= 0) {
  2226. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2227. return pdFALSE;
  2228. }
  2229. }
  2230. switch (i) {
  2231. case ARG_HISTORY_EVENTS:
  2232. if (start) {
  2233. start = false;
  2234. /* Return the next command help string, before moving the pointer on to
  2235. the next command in the list. */
  2236. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader,
  2237. strlen( ( char * ) pcControllerHistoryTableHeader ) );
  2238. memset(str, 0, sizeof(str));
  2239. strcat(( char * ) pcWriteBuffer, "\r\n");
  2240. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  2241. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2242. strcat(( char * ) pcWriteBuffer, "\r\n");
  2243. if (num_page > History_GetPageCount()) {
  2244. num_page = History_GetPageCount();
  2245. }
  2246. }
  2247. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2248. num_page --;
  2249. num_page_temp ++;
  2250. if (num_page == 0) {
  2251. num_page = 0;
  2252. num_page_temp = 1;
  2253. start = true;
  2254. xReturn = pdFALSE;
  2255. } else {
  2256. xReturn = pdTRUE;
  2257. }
  2258. break;
  2259. case ARG_HISTORY_UPS:
  2260. if (start) {
  2261. start = false;
  2262. /* Return the next command help string, before moving the pointer on to
  2263. the next command in the list. */
  2264. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader,
  2265. strlen( ( char * ) pcUPShistoryTableHeader ) );
  2266. memset(str, 0, sizeof(str));
  2267. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  2268. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  2269. if (num_page > LOG_GetPageCount()) {
  2270. num_page = LOG_GetPageCount();
  2271. }
  2272. }
  2273. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  2274. num_page --;
  2275. num_page_temp ++;
  2276. if (num_page == 0) {
  2277. num_page = 0;
  2278. num_page_temp = 1;
  2279. start = true;
  2280. xReturn = pdFALSE;
  2281. } else {
  2282. xReturn = pdTRUE;
  2283. }
  2284. break;
  2285. default:
  2286. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2287. xReturn = pdFALSE;
  2288. break;
  2289. }
  2290. return xReturn;
  2291. }
  2292. /*
  2293. * Implements the sensor info command.
  2294. */
  2295. static portBASE_TYPE prvTaskSensorCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2296. const int8_t *pcCommandString )
  2297. {
  2298. int8_t *pcParameterString;
  2299. signed portBASE_TYPE xParameterStringLength, xReturn;
  2300. portBASE_TYPE xParameterNumber = 1;
  2301. uint8_t i;
  2302. char str[10];
  2303. char temp_str[10];
  2304. int32_t val = 0, val2 = 0;
  2305. uint8_t fail = 0;
  2306. static uint8_t config_menu = 0;
  2307. uint8_t MAX_CONFIG_PARAM = 0;
  2308. #ifdef HARDWARE_BT6707
  2309. MAX_CONFIG_PARAM = 3;
  2310. #else
  2311. MAX_CONFIG_PARAM = 2;
  2312. #endif
  2313. const int8_t *const pcSensorTableHeader = ( int8_t * )
  2314. "\r\n*********Параметры Контроллера*********\r\n";
  2315. ( void ) pcCommandString;
  2316. ( void ) xWriteBufferLen;
  2317. configASSERT( pcWriteBuffer );
  2318. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2319. /* Obtain the parameter string. */
  2320. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2321. (
  2322. pcCommandString, /* The command string itself. */
  2323. xParameterNumber, /* Return the next parameter. */
  2324. &xParameterStringLength /* Store the parameter string length. */
  2325. );
  2326. if (pcParameterString == NULL) {
  2327. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2328. return pdFALSE;
  2329. }
  2330. for (i = 0; i < ARG_SENSOR_ALL; i ++) {
  2331. if ( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0
  2332. && xParameterStringLength == strlen(sensor_args_list[i])) {
  2333. break;
  2334. }
  2335. }
  2336. xParameterNumber ++;
  2337. /* Obtain the parameter string. */
  2338. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2339. (
  2340. pcCommandString, /* The command string itself. */
  2341. xParameterNumber, /* Return the next parameter. */
  2342. &xParameterStringLength /* Store the parameter string length. */
  2343. );
  2344. if (pcParameterString == NULL) {
  2345. if (i == ARG_SENSOR_INFO) {
  2346. switch (config_menu) {
  2347. case 0:
  2348. /* Return the next command help string, before moving the pointer on to
  2349. the next command in the list. */
  2350. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  2351. ups_sensor_param(pcWriteBuffer);
  2352. break;
  2353. case 1:
  2354. ups_sensor_akb_param(pcWriteBuffer);
  2355. break;
  2356. #ifdef HARDWARE_BT6707
  2357. case 2:
  2358. inouts_sensor_param(pcWriteBuffer);
  2359. break;
  2360. #endif
  2361. }
  2362. config_menu ++;
  2363. if (config_menu == MAX_CONFIG_PARAM) {
  2364. config_menu = 0;
  2365. return pdFALSE;
  2366. } else {
  2367. return pdTRUE;
  2368. }
  2369. } else {
  2370. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2371. }
  2372. } else {
  2373. switch (i) {
  2374. #ifdef HARDWARE_BT6707
  2375. case ARG_SENSOR_SETUP:
  2376. if (cli_state->user_id != ADMIN) {
  2377. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2378. return pdFALSE;
  2379. }
  2380. memset(str, 0, sizeof(str));
  2381. if (xParameterStringLength > (int32_t)sizeof(str)) {
  2382. xParameterStringLength = sizeof(str) - 1;
  2383. }
  2384. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2385. if (xParameterStringLength < 3) {
  2386. xParameterNumber ++;
  2387. /* Obtain the parameter string. */
  2388. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2389. (
  2390. pcCommandString, /* The command string itself. */
  2391. xParameterNumber, /* Return the next parameter. */
  2392. &xParameterStringLength /* Store the parameter string length. */
  2393. );
  2394. memset(temp_str, 0, sizeof(str));
  2395. if (xParameterStringLength > 1) {
  2396. fail = 1;
  2397. break;
  2398. }
  2399. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2400. if (!isdigit_int(temp_str[0])) {
  2401. fail = 1;
  2402. break;
  2403. }
  2404. val = atoi(temp_str);
  2405. xParameterNumber ++;
  2406. /* Obtain the parameter string. */
  2407. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2408. (
  2409. pcCommandString, /* The command string itself. */
  2410. xParameterNumber, /* Return the next parameter. */
  2411. &xParameterStringLength /* Store the parameter string length. */
  2412. );
  2413. memset(temp_str, 0, sizeof(str));
  2414. if (xParameterStringLength > 1) {
  2415. fail = 1;
  2416. break;
  2417. }
  2418. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  2419. if (!isdigit_int(temp_str[0])) {
  2420. fail = 1;
  2421. break;
  2422. }
  2423. if (strncmp(str, "DI", 2) == 0) {
  2424. if (val != 1) {
  2425. fail = 1;
  2426. break;
  2427. }
  2428. val2 = atoi(temp_str);
  2429. if (val2 < 0 || val2 > 1) {
  2430. fail = 1;
  2431. break;
  2432. }
  2433. SetDINTypeActStr(temp_str, (val - 1));
  2434. SETTINGS_Save();
  2435. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  2436. } else if (strncmp(str, "DO", 2) == 0) {
  2437. if (val < 1 || val > 3) {
  2438. fail = 1;
  2439. break;
  2440. }
  2441. val2 = atoi(temp_str);
  2442. if (val2 < 1 || val2 > 5) {
  2443. fail = 1;
  2444. break;
  2445. }
  2446. SetROTypeActStr(temp_str, (val - 1));
  2447. SETTINGS_Save();
  2448. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  2449. }
  2450. } else {
  2451. fail = 1;
  2452. }
  2453. break;
  2454. #endif
  2455. default:
  2456. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2457. break;
  2458. }
  2459. }
  2460. if (fail) {
  2461. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2462. }
  2463. xReturn = pdFALSE;
  2464. return xReturn;
  2465. }
  2466. /*
  2467. * Implements the firmware download http command.
  2468. */
  2469. static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
  2470. const int8_t *pcCommandString )
  2471. {
  2472. static bool start_update = true;
  2473. const int8_t *const pcUploadHeader = ( int8_t * )
  2474. "Контроллер переводится в режим загрузчика\r\n";
  2475. ( void ) pcCommandString;
  2476. ( void ) xWriteBufferLen;
  2477. if (cli_state->user_id != ADMIN) {
  2478. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2479. return pdFALSE;
  2480. }
  2481. if (start_update) {
  2482. start_update = false;
  2483. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  2484. return pdTRUE;
  2485. } else {
  2486. telnet_act = true;
  2487. HTTP_StartResetTask(true);
  2488. return pdFALSE;
  2489. }
  2490. }
  2491. /*
  2492. * Implements the ups command.
  2493. */
  2494. static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  2495. {
  2496. int8_t *pcParameterString;
  2497. signed portBASE_TYPE xParameterStringLength, xReturn;
  2498. portBASE_TYPE xParameterNumber = 1;
  2499. char str[110];
  2500. int32_t val = 0;
  2501. float val_float = 0;
  2502. int8_t res = 0;
  2503. uint8_t i;
  2504. ( void ) pcCommandString;
  2505. ( void ) xWriteBufferLen;
  2506. configASSERT( pcWriteBuffer );
  2507. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  2508. if (cli_state->user_id != ADMIN && i != ARG_CONFIG_INFO) {
  2509. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  2510. return pdFALSE;
  2511. }
  2512. /* Obtain the parameter string. */
  2513. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2514. (
  2515. pcCommandString, /* The command string itself. */
  2516. xParameterNumber, /* Return the next parameter. */
  2517. &xParameterStringLength /* Store the parameter string length. */
  2518. );
  2519. for (i = 0; i < ARG_UPS_ALL; i ++) {
  2520. if ( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0
  2521. && xParameterStringLength == strlen(ups_args_list[i])) {
  2522. break;
  2523. }
  2524. }
  2525. xParameterNumber ++;
  2526. /* Obtain the parameter string. */
  2527. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  2528. (
  2529. pcCommandString, /* The command string itself. */
  2530. xParameterNumber, /* Return the next parameter. */
  2531. &xParameterStringLength /* Store the parameter string length. */
  2532. );
  2533. memset(str, 0, sizeof(str));
  2534. if (xParameterStringLength > 3) {
  2535. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2536. return pdFALSE;
  2537. }
  2538. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  2539. switch (i) {
  2540. case ARG_UPS_BATTEST:
  2541. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2542. if (!isdigit_int(str[j])) {
  2543. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2544. return pdFALSE;
  2545. }
  2546. }
  2547. val = atoi(str);
  2548. if (val == 0) {
  2549. res = ups_metac_service_pdu(ups_cancel_test);
  2550. set_act_source(TELNET_ACT);
  2551. if (res == 1) {
  2552. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  2553. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" принята ИБП!\r\n");
  2554. } else {
  2555. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" отклонена ИБП!\r\n");
  2556. }
  2557. } else if (val > 0 && val < 100) {
  2558. TimeParam = val;
  2559. res = ups_metac_service_pdu(ups_test_time);
  2560. if (res == 1) {
  2561. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2562. } else {
  2563. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2564. }
  2565. } else if (val == 100) {
  2566. res = ups_metac_service_pdu(ups_test_10sec);
  2567. if (res == 1) {
  2568. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2569. } else {
  2570. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2571. }
  2572. } else if (val == 999) {
  2573. res = ups_metac_service_pdu(ups_test_low_bat);
  2574. if (res == 1) {
  2575. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
  2576. } else {
  2577. strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
  2578. }
  2579. } else {
  2580. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2581. }
  2582. break;
  2583. case ARG_UPS_SHUTDOWN:
  2584. for (uint8_t j = 0; j < xParameterStringLength; j++) {
  2585. if (!isfloatdigit(str[j])) {
  2586. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2587. return pdFALSE;
  2588. }
  2589. }
  2590. val_float = atof(str);
  2591. if (val_float == 0) {
  2592. res = ups_metac_service_pdu(ups_cancel_shut_down);
  2593. if (res == 1) {
  2594. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  2595. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  2596. } else {
  2597. strcpy( ( char * ) pcWriteBuffer,
  2598. "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  2599. }
  2600. } else if (val_float > 0 && val_float <= 10) {
  2601. TimeParamFloat = val_float;
  2602. res = ups_metac_service_pdu(ups_shutdown);
  2603. if (res == 1) {
  2604. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  2605. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  2606. } else {
  2607. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  2608. }
  2609. } else {
  2610. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2611. }
  2612. break;
  2613. default:
  2614. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  2615. break;
  2616. }
  2617. xReturn = pdFALSE;
  2618. return xReturn;
  2619. }
  2620. /*-----------------------------------------------------------*/