CLI_Commands.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178
  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 "telnet_server.h"
  35. #include "netconf.h"
  36. #include "control_symbol.h"
  37. #define in_range_digit(c, lo, up) ((uint8_t)c >= lo && (uint8_t)c <= up)
  38. #define isdigit_int(c) in_range_digit(c, '0', '9')
  39. #define isfloatdigit(c) (isdigit_int(c) || in_range_digit(c, '.', '.'))
  40. extern state_telnet_server_t telnetState;
  41. extern uint8_t id_change_pwd;
  42. const int8_t * const pcInvalidCommand = ( int8_t * ) "Неправильно введены параметры команды. Введите \"help\" для просмотра списка поддерживаемых команд.\r\n\r\n";
  43. const int8_t * const pcPermissionDenied = ( int8_t * ) "Отказ в доступе!\r\n\r\n";
  44. const int8_t * const pcSystymeDenied = ( int8_t * ) "Ручной ввод времени не доступен!\r\n\r\n";
  45. const char* info_args_list[] =
  46. {
  47. "address",
  48. "owner",
  49. "comments",
  50. };
  51. const char* ups_args_list[] =
  52. {
  53. "battest",
  54. "shutdown",
  55. };
  56. const char* systime_args_list[] =
  57. {
  58. "date",
  59. "time",
  60. };
  61. const char* network_args_list[] =
  62. {
  63. "info",
  64. "dhcp",
  65. "ip",
  66. "gw",
  67. "mask",
  68. };
  69. const char* snmp_args_list[] =
  70. {
  71. "info",
  72. "server",
  73. "community",
  74. };
  75. const char* whitelist_args_list[] =
  76. {
  77. "info",
  78. "range",
  79. };
  80. const char* ntp_args_list[] =
  81. {
  82. "ENA",
  83. "DIS",
  84. "info",
  85. "set",
  86. };
  87. const char* config_args_list[] =
  88. {
  89. "info",
  90. "load",
  91. };
  92. const char* netconfig_args_list[] =
  93. {
  94. "apply",
  95. "confirm",
  96. };
  97. const char* history_args_list[] =
  98. {
  99. "EVENTS",
  100. "UPS",
  101. };
  102. const char* sensor_args_list[] =
  103. {
  104. "info",
  105. "setup",
  106. };
  107. const char* user_args_list[] =
  108. {
  109. "passwd",
  110. };
  111. /**
  112. * @brief Общая структура настроек
  113. */
  114. extern SETTINGS_t sSettings;
  115. extern user_level_t telnet_code_auth;
  116. /*
  117. * Implements the controller's information command.
  118. */
  119. static portBASE_TYPE prvTaskInfoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  120. /*
  121. * Implements the reboot command.
  122. */
  123. static portBASE_TYPE prvTaskRebootCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  124. /*
  125. * Implements the systime command.
  126. */
  127. static portBASE_TYPE prvTaskSystimeCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  128. /*
  129. * Implements the ntp command.
  130. */
  131. static portBASE_TYPE prvTaskNTPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  132. /*
  133. * Implements the network command.
  134. */
  135. static portBASE_TYPE prvTaskNetworkCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  136. /*
  137. * Implements the snmp command.
  138. */
  139. static portBASE_TYPE prvTaskSNMPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  140. #ifdef HARDWARE_BT6708
  141. /*
  142. * Implements the whitelist command.
  143. */
  144. static portBASE_TYPE prvTaskWhiteListCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  145. #endif
  146. /*
  147. * Implements the change password command.
  148. */
  149. static portBASE_TYPE prvTaskUserCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  150. /*
  151. * Implements the config command.
  152. */
  153. static portBASE_TYPE prvTaskConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  154. /*
  155. * Implements the netconfig command.
  156. */
  157. static portBASE_TYPE prvTaskNetConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  158. /*
  159. * Implements the history command.
  160. */
  161. static portBASE_TYPE prvTaskHistoryCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  162. /*
  163. * Implements the sensor info command.
  164. */
  165. static portBASE_TYPE prvTaskSensorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  166. /*
  167. * Implements the firmware download http command.
  168. */
  169. static portBASE_TYPE prvTaskUploadCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  170. /*
  171. * Implements the ups command.
  172. */
  173. static portBASE_TYPE prvTaskUPSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
  174. /* Structure that defines the "info" command line command. This
  175. generates a table that shows how much run time each task has */
  176. static const CLI_Command_Definition_t prvInfoCommandDefinition =
  177. {
  178. ( const int8_t * const ) "info", /* The command string to type. */
  179. ( const int8_t * const ) "\tinfo: вывод информации о контроллере\r\n"
  180. "\tinfo address <adrr>: установка поля \"адрес расположения контролируемого объекта\"\r\n"
  181. "\tinfo owner <owner>: установка поля \"организация (собственник)\"\r\n"
  182. "\tinfo comments <comment>: установка поля \"комментарии\"\r\n",
  183. prvTaskInfoCommand, /* The function to run. */
  184. -1 /* The user can enter any number of commands. */
  185. };
  186. /* Structure that defines the "reboot" command line command. This
  187. generates a table that shows how much run time each task has */
  188. static const CLI_Command_Definition_t prvRebootCommandDefinition =
  189. {
  190. ( const int8_t * const ) "reboot", /* The command string to type. */
  191. ( const int8_t * const ) "\treboot: перезагрузка Контроллера\r\n",
  192. prvTaskRebootCommand, /* The function to run. */
  193. 0 /* No parameters are expected. */
  194. };
  195. /* Structure that defines the "systime" command line command. This
  196. generates a table that shows how much run time each task has */
  197. static const CLI_Command_Definition_t prvSystimeCommandDefinition =
  198. {
  199. ( const int8_t * const ) "systime", /* The command string to type. */
  200. ( const int8_t * const ) "\tsystime: вывод системного времени\r\n"
  201. "\tsystime date <YYYY-MM-DD>: установка даты\r\n"
  202. "\tsystime time <HH:MM>: установка времени\r\n",
  203. prvTaskSystimeCommand, /* The function to run. */
  204. -1 /* The user can enter any number of commands. */
  205. };
  206. /* Structure that defines the "ntp" command line command. This
  207. generates a table that shows how much run time each task has */
  208. static const CLI_Command_Definition_t prvNTPCommandDefinition =
  209. {
  210. ( const int8_t * const ) "ntp", /* The command string to type. */
  211. ( const int8_t * const ) "\tntp ENA|DIS: разрешение/запрет синхронизации времени\r\n"
  212. "\tntp set IP <A.B.C.D>: установка сервера NTP\r\n"
  213. "\tntp info: вывод информации о сервере NTP\r\n"
  214. "\tntp set gmt <SIGN><NUM>: установка часового пояса\r\n",
  215. prvTaskNTPCommand, /* The function to run. */
  216. -1 /* The user can enter any number of commands. */
  217. };
  218. /* Structure that defines the "network" command line command. This
  219. generates a table that shows how much run time each task has */
  220. static const CLI_Command_Definition_t prvNetworkCommandDefinition =
  221. {
  222. ( const int8_t * const ) "network", /* The command string to type. */
  223. ( const int8_t * const ) "\tnetwork info вывод информации о текущих сетевых настройках:\r\n"
  224. "\tnetwork dhcp ENA|DIS: разрешение/запрет получения IP по DHCP\r\n"
  225. "\tnetwork ip <A.B.C.D>: установка статического IP\r\n"
  226. "\tnetwork gw <A.B.C.D>: установка шлюза\r\n"
  227. "\tnetwork mask <A.B.C.D>: установка маски подсети\r\n",
  228. prvTaskNetworkCommand, /* The function to run. */
  229. -1 /* The user can enter any number of commands. */
  230. };
  231. /* Structure that defines the "snmp" command line command. This
  232. generates a table that shows how much run time each task has */
  233. static const CLI_Command_Definition_t prvSNMPCommandDefinition =
  234. {
  235. ( const int8_t * const ) "snmp", /* The command string to type. */
  236. ( const int8_t * const ) "\tsnmp info: вывод информации о текущих SNMP настройках\r\n"
  237. "\tsnmp server <NUM> <A.B.C.D>: установка сервера SNMP\r\n"
  238. "\tsnmp community read <read>: установка Read community\r\n"
  239. "\tsnmp community write <write>: установка Write community\r\n",
  240. prvTaskSNMPCommand, /* The function to run. */
  241. -1 /* The user can enter any number of commands. */
  242. };
  243. #ifdef HARDWARE_BT6708
  244. /* Structure that defines the "whitelist" command line command. This
  245. generates a table that shows how much run time each task has */
  246. static const CLI_Command_Definition_t prvWhiteListCommandDefinition =
  247. {
  248. ( const int8_t * const ) "whitelist", /* The command string to type. */
  249. ( const int8_t * const ) "\twhitelist info: вывод информации о текущем белом списке IP адресов контроллера\r\n"
  250. "\twhitelist range <NUM> <A.B.C.D/E>: установка диапазона IP адресов\r\n",
  251. prvTaskWhiteListCommand, /* The function to run. */
  252. -1 /* The user can enter any number of commands. */
  253. };
  254. #endif
  255. /* Structure that defines the "user" command line command. This
  256. generates a table that shows how much run time each task has */
  257. static const CLI_Command_Definition_t prvUserCommandDefinition =
  258. {
  259. ( const int8_t * const ) "user", /* The command string to type. */
  260. ( const int8_t * const ) "\tuser passwd <name>: установка пароля для пользователя <name>\r\n",
  261. prvTaskUserCommand, /* The function to run. */
  262. 2 /* Two parameters are expected, which can take any value. */
  263. };
  264. /* Structure that defines the "config" command line command. This
  265. generates a table that shows how much run time each task has */
  266. static const CLI_Command_Definition_t prvConfigCommandDefinition =
  267. {
  268. ( const int8_t * const ) "config", /* The command string to type. */
  269. ( const int8_t * const ) "\tconfig info: вывод информации о состоянии конфигураций\r\n"
  270. "\tconfig load default: загрузка конфигурации по умолчанию\r\n",
  271. prvTaskConfigCommand, /* The function to run. */
  272. -1 /* Two parameters are expected, which can take any value. */
  273. };
  274. /* Structure that defines the "config" command line command. This
  275. generates a table that shows how much run time each task has */
  276. static const CLI_Command_Definition_t prvNetConfigCommandDefinition =
  277. {
  278. ( const int8_t * const ) "netconfig", /* The command string to type. */
  279. ( const int8_t * const ) "\tnetconfig apply: применение конфигурации сетевых настроек\r\n"
  280. "\tnetconfig confirm: подтверждение конфигурации сетевых настроек\r\n",
  281. prvTaskNetConfigCommand, /* The function to run. */
  282. 1 /* Two parameters are expected, which can take any value. */
  283. };
  284. /* Structure that defines the "history" command line command. This
  285. generates a table that shows how much run time each task has */
  286. static const CLI_Command_Definition_t prvHistoryCommandDefinition =
  287. {
  288. ( const int8_t * const ) "history", /* The command string to type. */
  289. ( const int8_t * const ) "\thistory show EVENTS|UPS <num_page>: вывод журнала\r\n",
  290. prvTaskHistoryCommand, /* The function to run. */
  291. 3 /* Two parameters are expected, which can take any value. */
  292. };
  293. /* Structure that defines the "sensor info" command line command. This
  294. generates a table that shows how much run time each task has */
  295. static const CLI_Command_Definition_t prvSensorCommandDefinition =
  296. {
  297. ( const int8_t * const ) "sensor", /* The command string to type. */
  298. ( const int8_t * const ) "\tsensor info: вывод параметров системы\r\n"
  299. #ifdef HARDWARE_BT6706
  300. "\tsensor setup DI <num> <state>: установка нормального состояния сухого контакта:\r\n"
  301. "\t\t\t\t0 - разомкнутое состояние\r\n"
  302. "\t\t\t\t1 - замкнутое состояние\r\n"
  303. "\tsensor setup DO <num> <issue>: установка источника срабатывания реле:\r\n"
  304. "\t\t\t\t1 - Наличие сети\r\n"
  305. "\t\t\t\t2 - Наличие выходного напряжения\r\n"
  306. "\t\t\t\t3 - Разряд АКБ\r\n"
  307. "\t\t\t\t4 - Отключение АКБ\r\n"
  308. "\t\t\t\t5 - SNMP SET\r\n"
  309. #endif
  310. ,
  311. prvTaskSensorCommand, /* The function to run. */
  312. -1 /* No parameters are expected. */
  313. };
  314. /* Structure that defines the "firmware dowmload http" command line command. This
  315. generates a table that shows how much run time each task has */
  316. static const CLI_Command_Definition_t prvUploadCommandDefinition =
  317. {
  318. ( const int8_t * const ) "firmware download http", /* The command string to type. */
  319. ( const int8_t * const ) "\tfirmware download http: переход в режим обновления через Web-сервер\r\n",
  320. prvTaskUploadCommand, /* The function to run. */
  321. 2 /* No parameters are expected. */
  322. };
  323. /* Structure that defines the "ups" command line command. This
  324. generates a table that shows how much run time each task has */
  325. static const CLI_Command_Definition_t prvUPSCommandDefinition =
  326. {
  327. ( const int8_t * const ) "ups", /* The command string to type. */
  328. ( const int8_t * const ) "\tups battest <num>: управление процедурой тестирония АКБ:\r\n"
  329. "\t\t\t\t0 - Остановить тестирование\r\n"
  330. "\t\t\t\t1-99 - Запустить тест на x минут\r\n"
  331. "\t\t\t\t100 - Тестирование в течение 10 секунд\r\n"
  332. "\t\t\t\t999 - Тестирование до разряда\r\n"
  333. "\tups shutdown <num>: управление отключением нагрузки ИБП:\r\n"
  334. "\t\t\t\t0 - Остановить процедуру отключения нагрузки\r\n"
  335. "\t\t\t\tn - Отключить нагрузку через n минут\r\n"
  336. "\t\t\t\tn: 0.2, 0.3, ..., 1, 2, ..., 10\r\n",
  337. prvTaskUPSCommand, /* The function to run. */
  338. 2 /* Two parameters are expected, which can take any value. */
  339. };
  340. /* Structure that defines the "quit" command line command. This
  341. generates a table that shows how much run time each task has */
  342. static const CLI_Command_Definition_t prvQuitCommandDefinition =
  343. {
  344. ( const int8_t * const ) "quit", /* The command string to type. */
  345. ( const int8_t * const ) "\tquit: завершение сессии\r\n",
  346. NULL, /* The function to run. */
  347. -1 /* The user can enter any number of commands. */
  348. };
  349. /*-----------------------------------------------------------*/
  350. void vRegisterCLICommands( void )
  351. {
  352. /* Register all the command line commands defined immediately above. */
  353. FreeRTOS_CLIRegisterCommand( &prvInfoCommandDefinition );
  354. FreeRTOS_CLIRegisterCommand( &prvRebootCommandDefinition );
  355. FreeRTOS_CLIRegisterCommand( &prvSystimeCommandDefinition );
  356. FreeRTOS_CLIRegisterCommand( &prvNTPCommandDefinition );
  357. FreeRTOS_CLIRegisterCommand( &prvNetworkCommandDefinition );
  358. FreeRTOS_CLIRegisterCommand( &prvSNMPCommandDefinition );
  359. #ifdef HARDWARE_BT6708
  360. FreeRTOS_CLIRegisterCommand( &prvWhiteListCommandDefinition );
  361. #endif
  362. FreeRTOS_CLIRegisterCommand( &prvUserCommandDefinition );
  363. FreeRTOS_CLIRegisterCommand( &prvConfigCommandDefinition );
  364. FreeRTOS_CLIRegisterCommand( &prvNetConfigCommandDefinition );
  365. FreeRTOS_CLIRegisterCommand( &prvHistoryCommandDefinition );
  366. FreeRTOS_CLIRegisterCommand( &prvSensorCommandDefinition );
  367. FreeRTOS_CLIRegisterCommand( &prvUploadCommandDefinition );
  368. FreeRTOS_CLIRegisterCommand( &prvUPSCommandDefinition );
  369. FreeRTOS_CLIRegisterCommand( &prvQuitCommandDefinition );
  370. }
  371. /*-----------------------------------------------------------*/
  372. static portBASE_TYPE prvTaskInfoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
  373. {
  374. int8_t *pcParameterString;
  375. signed portBASE_TYPE xParameterStringLength, xReturn;
  376. portBASE_TYPE xParameterNumber = 1;
  377. char str[110];
  378. uint8_t len;
  379. int8_t num_arg = 0;
  380. uint8_t i;
  381. static uint8_t page = 0;
  382. ( void ) pcCommandString;
  383. ( void ) xWriteBufferLen;
  384. configASSERT( pcWriteBuffer );
  385. num_arg = prvGetNumberOfParameters(pcCommandString);
  386. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  387. if(num_arg == 0){
  388. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n**************Информация о Контроллере**************\r\n";
  389. const int8_t * const pcUPSInfoTableHeader = ( int8_t * ) "\r\n*****************Информация об ИБП******************\r\n";
  390. if(!page){
  391. /* Return the next command help string, before moving the pointer on to
  392. the next command in the list. */
  393. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  394. GetWorkTimeStr(str, &len);
  395. strcat(( char * ) pcWriteBuffer, "Время работы:\t\t\t");
  396. strncat(( char * ) pcWriteBuffer, str, len);
  397. strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
  398. GetModelStr(str, &len);
  399. strncat(( char * ) pcWriteBuffer, str, len);
  400. strcat(( char * ) pcWriteBuffer, "\r\nДата производства:\t\t");
  401. GetProductionDataStr(str, &len);
  402. strncat(( char * ) pcWriteBuffer, str, len);
  403. strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
  404. GetVersionStr(str, &len);
  405. strncat(( char * ) pcWriteBuffer, str, len);
  406. strcat(( char * ) pcWriteBuffer, "\r\nMAC адрес:\t\t\t");
  407. GetMacStr(str, &len);
  408. strncat(( char * ) pcWriteBuffer, str, len);
  409. strcat(( char * ) pcWriteBuffer, "\r\nСерийный номер:\t\t\t");
  410. GetSerialNumberStr(str, &len);
  411. strncat(( char * ) pcWriteBuffer, str, len);
  412. strcat(( char * ) pcWriteBuffer, "\r\nВладелец:\t\t\t");
  413. GetOwnerStr(str, &len);
  414. strncat(( char * ) pcWriteBuffer, str, len);
  415. strcat(( char * ) pcWriteBuffer, "\r\nМестоположение:\t\t\t");
  416. GetLocationStr(str, &len);
  417. strncat(( char * ) pcWriteBuffer, str, len);
  418. strcat(( char * ) pcWriteBuffer, "\r\nКомментарии:\t\t\t");
  419. GetCommentsStr(str, &len);
  420. strncat(( char * ) pcWriteBuffer, str, len);
  421. page = 1;
  422. xReturn = pdTRUE;
  423. }
  424. else{
  425. strncat( ( char * ) pcWriteBuffer, ( const char * ) pcUPSInfoTableHeader, strlen( ( char * ) pcUPSInfoTableHeader ) );
  426. strcat(( char * ) pcWriteBuffer, "\r\nКомпания:\t\t\tАО\"НПК РоТеК\"");
  427. strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
  428. GetUPSModelStr(str, &len);
  429. strncat(( char * ) pcWriteBuffer, str, len);
  430. strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
  431. GetUPSVersionStr(str, &len);
  432. strncat(( char * ) pcWriteBuffer, str, len);
  433. strcat(( char * ) pcWriteBuffer, "\r\n");
  434. page = 0;
  435. /* There are no more commands in the list, so there will be no more
  436. strings to return after this one and pdFALSE should be returned. */
  437. xReturn = pdFALSE;
  438. }
  439. }
  440. else if(num_arg == 1)
  441. {
  442. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  443. xReturn = pdFALSE;
  444. }
  445. else{
  446. /* Obtain the parameter string. */
  447. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  448. (
  449. pcCommandString, /* The command string itself. */
  450. xParameterNumber, /* Return the next parameter. */
  451. &xParameterStringLength /* Store the parameter string length. */
  452. );
  453. for(i = 0; i < INFO_ALL_ARGS; i ++){
  454. if( strncmp( ( const char * ) pcParameterString, info_args_list[i], strlen(info_args_list[i]) ) == 0 ){
  455. break;
  456. }
  457. }
  458. xParameterNumber ++;
  459. // xParameterNumber ++;
  460. /* Obtain the parameter string. */
  461. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  462. (
  463. pcCommandString, /* The command string itself. */
  464. xParameterNumber, /* Return the next parameter. */
  465. &xParameterStringLength /* Store the parameter string length. */
  466. );
  467. memset(str, 0, sizeof(str));
  468. xParameterStringLength = strlen(( const char * ) pcParameterString);
  469. if(xParameterStringLength > (int32_t)sizeof(str))
  470. xParameterStringLength = sizeof(str) - 1;
  471. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  472. if(control_string_en_digit(str, strlen(str))){
  473. switch(i){
  474. case INFO_ADDRESS:
  475. if(telnet_code_auth == ADMIN)
  476. SetLocation(str);
  477. else
  478. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  479. break;
  480. case INFO_OWNER:
  481. if(telnet_code_auth == ADMIN)
  482. SetOwner(str);
  483. else
  484. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  485. break;
  486. case INFO_COMMENTS:
  487. if(telnet_code_auth == ADMIN)
  488. SetComment(str);
  489. else
  490. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  491. break;
  492. default:
  493. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  494. break;
  495. }
  496. if(i >= INFO_ADDRESS && i <= INFO_COMMENTS){
  497. SETTINGS_Save();
  498. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  499. }
  500. }
  501. else{
  502. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  503. }
  504. xReturn = pdFALSE;
  505. }
  506. return xReturn;
  507. }
  508. static portBASE_TYPE prvTaskRebootCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  509. static bool start_reboot = true;
  510. const int8_t *const pcRebootHeader = ( int8_t * ) "Контроллер будет перезагружен через 1 секунду\r\n";
  511. ( void ) pcCommandString;
  512. ( void ) xWriteBufferLen;
  513. if(telnet_code_auth != ADMIN){
  514. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  515. return pdFALSE;
  516. }
  517. if(start_reboot){
  518. start_reboot = false;
  519. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcRebootHeader );
  520. return pdTRUE;
  521. }
  522. else{
  523. telnet_act = true;
  524. Reboot();
  525. return pdFALSE;
  526. }
  527. }
  528. static portBASE_TYPE prvTaskSystimeCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  529. int8_t *pcParameterString;
  530. signed portBASE_TYPE xParameterStringLength, xReturn;
  531. portBASE_TYPE xParameterNumber = 1;
  532. char str[110];
  533. uint8_t len;
  534. uint8_t i;
  535. uint8_t fail = 0;
  536. uint16_t temp = 0;
  537. ( void ) pcCommandString;
  538. ( void ) xWriteBufferLen;
  539. configASSERT( pcWriteBuffer );
  540. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  541. /* Obtain the parameter string. */
  542. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  543. (
  544. pcCommandString, /* The command string itself. */
  545. xParameterNumber, /* Return the next parameter. */
  546. &xParameterStringLength /* Store the parameter string length. */
  547. );
  548. if(pcParameterString == NULL){
  549. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n******Системное время Контроллера******\r\n";
  550. /* Return the next command help string, before moving the pointer on to
  551. the next command in the list. */
  552. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  553. GetDateStr(str, &len);
  554. strcat(( char * ) pcWriteBuffer, "Дата:\t\t\t");
  555. strncat(( char * ) pcWriteBuffer, str, len);
  556. strcat(( char * ) pcWriteBuffer, "\r\nВремя:\t\t\t");
  557. GetTimeStr(str, &len);
  558. strncat(( char * ) pcWriteBuffer, str, len);
  559. strcat(( char * ) pcWriteBuffer, "\r\n");
  560. /* There are no more commands in the list, so there will be no more
  561. strings to return after this one and pdFALSE should be returned. */
  562. xReturn = pdFALSE;
  563. }
  564. else{
  565. if(telnet_code_auth != ADMIN){
  566. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  567. return pdFALSE;
  568. }
  569. for(i = 0; i < ARG_SYSTIME_ALL; i ++){
  570. if( strncmp( ( const char * ) pcParameterString, systime_args_list[i], strlen(systime_args_list[i]) ) == 0 ){
  571. break;
  572. }
  573. }
  574. if(i != ARG_SYSTIME_ALL){
  575. if(sSettings.sSNTP.sntpEnable){
  576. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSystymeDenied, strlen( ( char * ) pcSystymeDenied ) );
  577. return pdFALSE;
  578. }
  579. }
  580. xParameterNumber ++;
  581. /* Obtain the parameter string. */
  582. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  583. (
  584. pcCommandString, /* The command string itself. */
  585. xParameterNumber, /* Return the next parameter. */
  586. &xParameterStringLength /* Store the parameter string length. */
  587. );
  588. if(pcParameterString == NULL){
  589. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  590. return pdFALSE;
  591. }
  592. memset(str, 0, sizeof(str));
  593. xParameterStringLength = strlen(( const char * ) pcParameterString);
  594. if(xParameterStringLength > (int32_t)sizeof(str))
  595. xParameterStringLength = sizeof(str) - 1;
  596. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  597. switch(i){
  598. case ARG_SYSTIME_DATA:
  599. if(xParameterStringLength == 10){
  600. for(uint8_t j = 0; j < xParameterStringLength; j++)
  601. {
  602. if(j != 4 && j != 7)
  603. {
  604. if(str[j] > 0x39 || str[j] < 0x30){
  605. fail = 1;
  606. }
  607. }
  608. else if(j == 4 || j == 7){
  609. if(str[j] != '-')
  610. fail = 1;
  611. }
  612. }
  613. if(!fail)
  614. {
  615. temp = 1000*(str[0] - 0x30) + 100*(str[1] - 0x30) + 10*(str[2] - 0x30) + str[3] - 0x30;
  616. if(temp > 2099 || temp < 2000)
  617. fail = 1;
  618. temp = 0;
  619. temp = 10*(str[5] - 0x30) + (str[6] - 0x30);
  620. if(temp > 12)
  621. fail = 1;
  622. temp = 0;
  623. temp = 10*(str[8] - 0x30) + (str[9] - 0x30);
  624. if(temp > 31)
  625. fail = 1;
  626. }
  627. }
  628. else{
  629. fail = 1;
  630. }
  631. if(!fail){
  632. SetDateStr(str);
  633. SETTINGS_Save();
  634. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  635. }
  636. else
  637. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  638. break;
  639. case ARG_SYSTIME_TIME:
  640. if(xParameterStringLength == 5){
  641. for(uint8_t j = 0; j < xParameterStringLength; j++)
  642. {
  643. if(j != 2)
  644. {
  645. if(str[j] > 0x39 || str[j] < 0x30)
  646. fail = 1;
  647. }
  648. else if(j == 2){
  649. if(str[j] != ':')
  650. fail = 1;
  651. }
  652. }
  653. if(!fail)
  654. {
  655. temp = 10*(str[0] - 0x30) + (str[1] - 0x30);
  656. if(temp > 23)
  657. fail = 1;
  658. temp = 0;
  659. temp = 10*(str[3] - 0x30) + (str[4] - 0x30);
  660. if(temp > 59)
  661. fail = 1;
  662. }
  663. }
  664. else{
  665. fail = 1;
  666. }
  667. if(!fail){
  668. SetTimeStr(str);
  669. SETTINGS_Save();
  670. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  671. }
  672. else
  673. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  674. break;
  675. default:
  676. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  677. break;
  678. }
  679. xReturn = pdFALSE;
  680. }
  681. return xReturn;
  682. }
  683. /*
  684. * Implements the ntp command.
  685. */
  686. static portBASE_TYPE prvTaskNTPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  687. int8_t *pcParameterString;
  688. signed portBASE_TYPE xParameterStringLength, xReturn;
  689. portBASE_TYPE xParameterNumber = 1;
  690. char str[110];
  691. char str_temp[110];
  692. uint8_t len;
  693. uint8_t i;
  694. bool enable_old_sntp;
  695. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n************NTP настройки Контроллера************\r\n";
  696. ( void ) pcCommandString;
  697. ( void ) xWriteBufferLen;
  698. configASSERT( pcWriteBuffer );
  699. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  700. /* Obtain the parameter string. */
  701. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  702. (
  703. pcCommandString, /* The command string itself. */
  704. xParameterNumber, /* Return the next parameter. */
  705. &xParameterStringLength /* Store the parameter string length. */
  706. );
  707. if(pcParameterString == NULL){
  708. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  709. return pdFALSE;
  710. }
  711. for(i = 0; i < ARG_NTP_ALL; i ++){
  712. if( strncmp( ( const char * ) pcParameterString, ntp_args_list[i], strlen(ntp_args_list[i]) ) == 0 ){
  713. break;
  714. }
  715. }
  716. if(telnet_code_auth != ADMIN && i !=ARG_NTP_INFO){
  717. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  718. return pdFALSE;
  719. }
  720. xParameterNumber ++;
  721. /* Obtain the parameter string. */
  722. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  723. (
  724. pcCommandString, /* The command string itself. */
  725. xParameterNumber, /* Return the next parameter. */
  726. &xParameterStringLength /* Store the parameter string length. */
  727. );
  728. xParameterNumber ++;
  729. if(pcParameterString == NULL){
  730. switch(i){
  731. case ARG_NTP_ENABLE:
  732. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  733. SetSntpStateStr("1");
  734. if(sSettings.sSNTP.sntpEnable != enable_old_sntp){
  735. SETTINGS_Save();
  736. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  737. SNTP_Init();
  738. //vTaskDelay(7000);
  739. SNTP_Poll();
  740. }
  741. break;
  742. case ARG_NTP_DISABLE:
  743. enable_old_sntp = sSettings.sSNTP.sntpEnable;
  744. SetSntpStateStr("0");
  745. if(sSettings.sSNTP.sntpEnable != enable_old_sntp){
  746. SETTINGS_Save();
  747. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  748. SNTP_Init();
  749. //vTaskDelay(7000);
  750. SNTP_Poll();
  751. }
  752. break;
  753. case ARG_NTP_INFO:
  754. /* Return the next command help string, before moving the pointer on to
  755. the next command in the list. */
  756. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  757. GetSntpStateStrRU(str, &len);
  758. strcat(( char * ) pcWriteBuffer, "Режим установки времени:\t");
  759. strncat(( char * ) pcWriteBuffer, str, len);
  760. strcat(( char * ) pcWriteBuffer, "\r\nIP адрес NTP сервера:\t\t");
  761. GetSntpServerIpStr(str, &len);
  762. strncat(( char * ) pcWriteBuffer, str, len);
  763. strcat(( char * ) pcWriteBuffer, "\r\nЧасовой пояс:\t\t\t");
  764. GetSntpTimeZoneStr(str, &len);
  765. strncat(( char * ) pcWriteBuffer, str, len);
  766. strcat(( char * ) pcWriteBuffer, "\r\nПоследняя дата синхронизации:\t");
  767. GetSntpLastDataStr(str, &len);
  768. strncat(( char * ) pcWriteBuffer, str, len);
  769. strcat(( char * ) pcWriteBuffer, "\r\n");
  770. break;
  771. default:
  772. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  773. break;
  774. }
  775. return pdFALSE;
  776. }
  777. if(i == ARG_NTP_SET){
  778. memset(str, 0, sizeof(str));
  779. if(xParameterStringLength > (int32_t)sizeof(str))
  780. xParameterStringLength = sizeof(str) - 1;
  781. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  782. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  783. (
  784. pcCommandString, /* The command string itself. */
  785. xParameterNumber, /* Return the next parameter. */
  786. &xParameterStringLength /* Store the parameter string length. */
  787. );
  788. if(pcParameterString != NULL){
  789. memset(str_temp, 0, sizeof(str_temp));
  790. if(xParameterStringLength > (int32_t)sizeof(str_temp))
  791. xParameterStringLength = sizeof(str_temp) - 1;
  792. strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
  793. if(strncmp(str, "IP", 2) == 0){
  794. if(xParameterStringLength <= 15){
  795. if(ipaddr_addr(str_temp) != IPADDR_NONE){
  796. if(strncmp(str_temp, sSettings.sSNTP.ip, strlen(str_temp)) != 0){
  797. SetSntpServerIpStr(str_temp);
  798. SETTINGS_Save();
  799. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  800. SNTP_Init();
  801. //vTaskDelay(7000);
  802. SNTP_Poll();
  803. }
  804. }
  805. else{
  806. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  807. }
  808. }
  809. else{
  810. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  811. }
  812. }
  813. else if(strncmp(str, "gmt", 3) == 0){
  814. if(xParameterStringLength > 1 && xParameterStringLength < 5){
  815. bool fail = false;
  816. if(str_temp[0] != '-' && str_temp[0] != '+')
  817. fail = true;
  818. if(!isdigit_int(str_temp[1]) && (!isdigit_int(str_temp[2]) && str_temp[2] != '.') && (!isdigit_int(str_temp[3]) && str_temp[3] != '.'))
  819. fail = true;
  820. if(xParameterStringLength == 5){
  821. if(!isdigit_int(str_temp[4]))
  822. fail = true;
  823. }
  824. if(!fail){
  825. float value = atof(str_temp);
  826. if(value > -12.0 && value < 12.0){
  827. SetSntpTimeZoneStr(str_temp);
  828. SETTINGS_Save();
  829. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  830. }
  831. else
  832. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  833. }
  834. else{
  835. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  836. }
  837. }
  838. else{
  839. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  840. }
  841. }
  842. else{
  843. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  844. }
  845. }
  846. else{
  847. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  848. }
  849. }
  850. else{
  851. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  852. }
  853. xReturn = pdFALSE;
  854. return xReturn;
  855. }
  856. /*
  857. * Implements the network command.
  858. */
  859. static portBASE_TYPE prvTaskNetworkCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  860. int8_t *pcParameterString;
  861. signed portBASE_TYPE xParameterStringLength, xReturn;
  862. portBASE_TYPE xParameterNumber = 1;
  863. char str[110];
  864. uint8_t i;
  865. ( void ) pcCommandString;
  866. ( void ) xWriteBufferLen;
  867. configASSERT( pcWriteBuffer );
  868. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  869. /* Obtain the parameter string. */
  870. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  871. (
  872. pcCommandString, /* The command string itself. */
  873. xParameterNumber, /* Return the next parameter. */
  874. &xParameterStringLength /* Store the parameter string length. */
  875. );
  876. if(pcParameterString == NULL){
  877. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  878. return pdFALSE;
  879. }
  880. for(i = 0; i < ARG_NETWORK_ALL; i ++){
  881. if( strncmp( ( const char * ) pcParameterString, network_args_list[i], strlen(network_args_list[i]) ) == 0 ){
  882. break;
  883. }
  884. }
  885. if(telnet_code_auth != ADMIN && i !=ARG_NETWORK_INFO){
  886. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  887. return pdFALSE;
  888. }
  889. if(i != ARG_NETWORK_ALL && i != ARG_NETWORK_DHCP && i != ARG_NETWORK_INFO){
  890. if(sSettings.sWebTempParams.dhcpEnable){
  891. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  892. return pdFALSE;
  893. }
  894. }
  895. xParameterNumber ++;
  896. /* Obtain the parameter string. */
  897. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  898. (
  899. pcCommandString, /* The command string itself. */
  900. xParameterNumber, /* Return the next parameter. */
  901. &xParameterStringLength /* Store the parameter string length. */
  902. );
  903. if(pcParameterString == NULL){
  904. if(i == ARG_NETWORK_INFO){
  905. net_config_param(pcWriteBuffer);
  906. }
  907. else{
  908. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  909. }
  910. return pdFALSE;
  911. }
  912. memset(str, 0, sizeof(str));
  913. xParameterStringLength = strlen(( const char * ) pcParameterString);
  914. if(xParameterStringLength > (int32_t)sizeof(str))
  915. xParameterStringLength = sizeof(str) - 1;
  916. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  917. switch(i){
  918. case ARG_NETWORK_DHCP:
  919. if(strncmp(str, "ENA", 3) == 0){
  920. SetUDPDhcpStateStr("True");
  921. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  922. }
  923. else if(strncmp(str, "DIS", 3) == 0){
  924. SetUDPDhcpStateStr("False");
  925. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  926. }
  927. else
  928. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  929. break;
  930. case ARG_NETWORK_IP:
  931. if(xParameterStringLength <= 15){
  932. if(ipaddr_addr(str) != IPADDR_NONE){
  933. SetIPStr(str);
  934. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  935. }
  936. else
  937. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  938. }
  939. else{
  940. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  941. }
  942. break;
  943. case ARG_NETWORK_GW:
  944. if(xParameterStringLength <= 15){
  945. if(ipaddr_addr(str) != IPADDR_NONE){
  946. SetGatewayStr(str);
  947. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  948. }
  949. else
  950. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  951. }
  952. else{
  953. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  954. }
  955. break;
  956. case ARG_NETWORK_MASK:
  957. if(xParameterStringLength <= 15){
  958. if(ipaddr_addr(str) != IPADDR_NONE){
  959. SetMaskStr(str);
  960. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  961. }
  962. else
  963. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  964. }
  965. else{
  966. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  967. }
  968. break;
  969. default:
  970. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  971. break;
  972. }
  973. xReturn = pdFALSE;
  974. return xReturn;
  975. }
  976. /*
  977. * Implements the snmp command.
  978. */
  979. static portBASE_TYPE prvTaskSNMPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  980. int8_t *pcParameterString;
  981. signed portBASE_TYPE xParameterStringLength, xReturn;
  982. portBASE_TYPE xParameterNumber = 1;
  983. char str[20];
  984. char temp_str[20];
  985. uint8_t i;
  986. ( void ) pcCommandString;
  987. ( void ) xWriteBufferLen;
  988. configASSERT( pcWriteBuffer );
  989. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  990. /* Obtain the parameter string. */
  991. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  992. (
  993. pcCommandString, /* The command string itself. */
  994. xParameterNumber, /* Return the next parameter. */
  995. &xParameterStringLength /* Store the parameter string length. */
  996. );
  997. if(pcParameterString == NULL){
  998. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  999. return pdFALSE;
  1000. }
  1001. for(i = 0; i < ARG_SNMP_ALL; i ++){
  1002. if( strncmp( ( const char * ) pcParameterString, snmp_args_list[i], strlen(snmp_args_list[i]) ) == 0 ){
  1003. break;
  1004. }
  1005. }
  1006. if(telnet_code_auth != ADMIN && i !=ARG_SNMP_INFO){
  1007. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1008. return pdFALSE;
  1009. }
  1010. xParameterNumber ++;
  1011. /* Obtain the parameter string. */
  1012. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1013. (
  1014. pcCommandString, /* The command string itself. */
  1015. xParameterNumber, /* Return the next parameter. */
  1016. &xParameterStringLength /* Store the parameter string length. */
  1017. );
  1018. xParameterNumber ++;
  1019. if(pcParameterString == NULL){
  1020. if(i == ARG_SNMP_INFO){
  1021. snmp_config_param(pcWriteBuffer);
  1022. }
  1023. else{
  1024. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1025. }
  1026. return pdFALSE;
  1027. }
  1028. memset(str, 0, sizeof(str));
  1029. if(xParameterStringLength > (int32_t)sizeof(str))
  1030. xParameterStringLength = sizeof(str) - 1;
  1031. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1032. switch(i){
  1033. case ARG_SNMP_SERVER:
  1034. if(xParameterStringLength == 1 && isdigit_int(str[0])){
  1035. int32_t temp = atoi(str);
  1036. if(temp > 0 && temp < 6){
  1037. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1038. (
  1039. pcCommandString, /* The command string itself. */
  1040. xParameterNumber, /* Return the next parameter. */
  1041. &xParameterStringLength /* Store the parameter string length. */
  1042. );
  1043. if(pcParameterString != NULL){
  1044. memset(str, 0, sizeof(str));
  1045. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1046. if(xParameterStringLength > (int32_t)sizeof(str))
  1047. xParameterStringLength = sizeof(str) - 1;
  1048. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1049. if(xParameterStringLength <= 15){
  1050. if(ipaddr_addr(str) != IPADDR_NONE){
  1051. switch(temp){
  1052. case 1:
  1053. SetManagerIp(str);
  1054. break;
  1055. case 2:
  1056. SetManagerIp2(str);
  1057. break;
  1058. case 3:
  1059. SetManagerIp3(str);
  1060. break;
  1061. case 4:
  1062. SetManagerIp4(str);
  1063. break;
  1064. case 5:
  1065. SetManagerIp5(str);
  1066. break;
  1067. }
  1068. if(temp > 0 && temp < 6){
  1069. SETTINGS_Save();
  1070. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1071. }
  1072. }
  1073. else{
  1074. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1075. }
  1076. }
  1077. else{
  1078. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1079. }
  1080. }
  1081. else{
  1082. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1083. }
  1084. }
  1085. else{
  1086. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1087. }
  1088. }
  1089. else{
  1090. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1091. }
  1092. break;
  1093. case ARG_SNMP_COMMUNITY:
  1094. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1095. (
  1096. pcCommandString, /* The command string itself. */
  1097. xParameterNumber, /* Return the next parameter. */
  1098. &xParameterStringLength /* Store the parameter string length. */
  1099. );
  1100. if(pcParameterString != NULL){
  1101. memset(temp_str, 0, sizeof(temp_str));
  1102. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1103. if(xParameterStringLength > (int32_t)sizeof(temp_str))
  1104. xParameterStringLength = sizeof(temp_str) - 1;
  1105. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1106. if(control_string_en_digit(temp_str, strlen(temp_str))){
  1107. if(strncmp(str, "read", 4) == 0){
  1108. SetReadCommunity(temp_str);
  1109. SETTINGS_Save();
  1110. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1111. }
  1112. else if(strncmp(str, "write", 5) == 0){
  1113. SetWriteCommunity(temp_str);
  1114. SETTINGS_Save();
  1115. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1116. }
  1117. else
  1118. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1119. }
  1120. else{
  1121. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1122. }
  1123. }
  1124. else{
  1125. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1126. }
  1127. break;
  1128. default:
  1129. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1130. break;
  1131. }
  1132. xReturn = pdFALSE;
  1133. return xReturn;
  1134. }
  1135. #ifdef HARDWARE_BT6708
  1136. /*
  1137. * Implements the whitelist command.
  1138. */
  1139. static portBASE_TYPE prvTaskWhiteListCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1140. int8_t *pcParameterString;
  1141. signed portBASE_TYPE xParameterStringLength, xReturn;
  1142. portBASE_TYPE xParameterNumber = 1;
  1143. char str[20];
  1144. char temp_str[20];
  1145. uint8_t i;
  1146. char *beginValue;
  1147. uint8_t len;
  1148. ( void ) pcCommandString;
  1149. ( void ) xWriteBufferLen;
  1150. configASSERT( pcWriteBuffer );
  1151. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1152. /* Obtain the parameter string. */
  1153. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1154. (
  1155. pcCommandString, /* The command string itself. */
  1156. xParameterNumber, /* Return the next parameter. */
  1157. &xParameterStringLength /* Store the parameter string length. */
  1158. );
  1159. if(pcParameterString == NULL){
  1160. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1161. return pdFALSE;
  1162. }
  1163. for(i = 0; i < ARG_WHITELIST_ALL; i ++){
  1164. if( strncmp( ( const char * ) pcParameterString, whitelist_args_list[i], strlen(whitelist_args_list[i]) ) == 0 ){
  1165. break;
  1166. }
  1167. }
  1168. if(telnet_code_auth != ADMIN && i !=ARG_WHITELIST_INFO){
  1169. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1170. return pdFALSE;
  1171. }
  1172. xParameterNumber ++;
  1173. /* Obtain the parameter string. */
  1174. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1175. (
  1176. pcCommandString, /* The command string itself. */
  1177. xParameterNumber, /* Return the next parameter. */
  1178. &xParameterStringLength /* Store the parameter string length. */
  1179. );
  1180. xParameterNumber ++;
  1181. if(pcParameterString == NULL){
  1182. if(i == ARG_WHITELIST_INFO){
  1183. whitelist_config_param(pcWriteBuffer);
  1184. }
  1185. else{
  1186. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1187. }
  1188. return pdFALSE;
  1189. }
  1190. memset(str, 0, sizeof(str));
  1191. if(xParameterStringLength > (int32_t)sizeof(str))
  1192. xParameterStringLength = sizeof(str) - 1;
  1193. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1194. switch(i){
  1195. case ARG_WHITELIST_RANGE:
  1196. if(xParameterStringLength == 1 && isdigit_int(str[0])){
  1197. int32_t temp = atoi(str);
  1198. if(temp > 0 && temp < 6){
  1199. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1200. (
  1201. pcCommandString, /* The command string itself. */
  1202. xParameterNumber, /* Return the next parameter. */
  1203. &xParameterStringLength /* Store the parameter string length. */
  1204. );
  1205. if(pcParameterString != NULL){
  1206. memset(str, 0, sizeof(str));
  1207. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1208. if(xParameterStringLength > (int32_t)sizeof(str))
  1209. xParameterStringLength = sizeof(str) - 1;
  1210. strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1211. if(xParameterStringLength <= 19){
  1212. beginValue = strpbrk(str,"/");
  1213. if(beginValue == NULL){
  1214. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1215. return pdFALSE;
  1216. }
  1217. len = beginValue - str;
  1218. memset(temp_str, 0, sizeof(temp_str));
  1219. strncpy(temp_str, str, len);
  1220. for(uint8_t j = (len + 1); j < xParameterStringLength; j++){
  1221. if(!isdigit_int(str[j])){
  1222. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1223. return pdFALSE;
  1224. }
  1225. }
  1226. if(ipaddr_addr(temp_str) != IPADDR_NONE){
  1227. SetWhiteListSTR(str, (temp - 1));
  1228. strcpy( ( char * ) pcWriteBuffer, "\t\tСохраните конфигурацию сетевых настроек\r\n" );
  1229. }
  1230. else{
  1231. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1232. }
  1233. }
  1234. else{
  1235. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1236. }
  1237. }
  1238. else{
  1239. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1240. }
  1241. }
  1242. else{
  1243. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1244. }
  1245. }
  1246. else{
  1247. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1248. }
  1249. break;
  1250. default:
  1251. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1252. break;
  1253. }
  1254. xReturn = pdFALSE;
  1255. return xReturn;
  1256. }
  1257. #endif
  1258. /*
  1259. * Implements the change password command.
  1260. */
  1261. static portBASE_TYPE prvTaskUserCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1262. int8_t *pcParameterString;
  1263. signed portBASE_TYPE xParameterStringLength, xReturn;
  1264. portBASE_TYPE xParameterNumber = 1;
  1265. uint8_t i;
  1266. char temp_str[MAX_WEB_LOGIN_LEN];
  1267. char WebLogin[MAX_WEB_LOGIN_LEN];
  1268. uint8_t valueLen, user_id;
  1269. const int8_t * const pcChangePWDHeader = ( int8_t * ) "\r\nВведите новый пароль:";
  1270. ( void ) pcCommandString;
  1271. ( void ) xWriteBufferLen;
  1272. configASSERT( pcWriteBuffer );
  1273. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1274. if(telnet_code_auth != ADMIN){
  1275. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1276. return pdFALSE;
  1277. }
  1278. /* Obtain the parameter string. */
  1279. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1280. (
  1281. pcCommandString, /* The command string itself. */
  1282. xParameterNumber, /* Return the next parameter. */
  1283. &xParameterStringLength /* Store the parameter string length. */
  1284. );
  1285. if(pcParameterString == NULL){
  1286. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1287. return pdFALSE;
  1288. }
  1289. for(i = 0; i < ARG_USER_ALL; i ++){
  1290. if( strncmp( ( const char * ) pcParameterString, user_args_list[i], strlen(user_args_list[i]) ) == 0 ){
  1291. break;
  1292. }
  1293. }
  1294. xParameterNumber ++;
  1295. /* Obtain the parameter string. */
  1296. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1297. (
  1298. pcCommandString, /* The command string itself. */
  1299. xParameterNumber, /* Return the next parameter. */
  1300. &xParameterStringLength /* Store the parameter string length. */
  1301. );
  1302. if(i == ARG_USER_PWD){
  1303. memset(temp_str, 0, sizeof(temp_str));
  1304. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1305. if(xParameterStringLength > (int32_t)sizeof(temp_str)){
  1306. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1307. }
  1308. else{
  1309. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1310. for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
  1311. GetUserLogin(user_id, WebLogin, &valueLen);
  1312. /* Check login and password */
  1313. if (strncmp(WebLogin, temp_str, MAX_WEB_LOGIN_LEN) == 0) {
  1314. /* Login and pass are valid */
  1315. id_change_pwd = user_id;
  1316. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcChangePWDHeader, strlen( ( char * ) pcChangePWDHeader ) );
  1317. telnetState = TELNET_CHANGE_PWD;
  1318. break;
  1319. }
  1320. }
  1321. if(telnetState != TELNET_CHANGE_PWD){
  1322. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1323. }
  1324. }
  1325. }
  1326. else{
  1327. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1328. }
  1329. xReturn = pdFALSE;
  1330. return xReturn;
  1331. }
  1332. /*
  1333. * Implements the config command.
  1334. */
  1335. static portBASE_TYPE prvTaskConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1336. int8_t *pcParameterString;
  1337. signed portBASE_TYPE xParameterStringLength, xReturn;
  1338. portBASE_TYPE xParameterNumber = 1;
  1339. char str[110];
  1340. uint8_t i;
  1341. static uint8_t config_menu = 0;
  1342. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n*********Конфигурация Контроллера*********\r\n";
  1343. ( void ) pcCommandString;
  1344. ( void ) xWriteBufferLen;
  1345. configASSERT( pcWriteBuffer );
  1346. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1347. /* Obtain the parameter string. */
  1348. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1349. (
  1350. pcCommandString, /* The command string itself. */
  1351. xParameterNumber, /* Return the next parameter. */
  1352. &xParameterStringLength /* Store the parameter string length. */
  1353. );
  1354. if(pcParameterString == NULL){
  1355. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1356. return pdFALSE;
  1357. }
  1358. for(i = 0; i < ARG_CONFIG_ALL; i ++){
  1359. if( strncmp( ( const char * ) pcParameterString, config_args_list[i], strlen(config_args_list[i]) ) == 0 ){
  1360. break;
  1361. }
  1362. }
  1363. if(telnet_code_auth != ADMIN && i !=ARG_CONFIG_INFO){
  1364. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1365. return pdFALSE;
  1366. }
  1367. xParameterNumber ++;
  1368. /* Obtain the parameter string. */
  1369. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1370. (
  1371. pcCommandString, /* The command string itself. */
  1372. xParameterNumber, /* Return the next parameter. */
  1373. &xParameterStringLength /* Store the parameter string length. */
  1374. );
  1375. if(pcParameterString == NULL){
  1376. switch(i){
  1377. case ARG_CONFIG_INFO:
  1378. switch(config_menu){
  1379. case PARAM_CONFIG_SNMP:
  1380. /* Return the next command help string, before moving the pointer on to
  1381. the next command in the list. */
  1382. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  1383. snmp_config_param(pcWriteBuffer);
  1384. break;
  1385. #ifdef HARDWARE_BT6706
  1386. case PARAM_CONFIG_INOUTS:
  1387. inouts_config_param(pcWriteBuffer);
  1388. break;
  1389. #endif
  1390. #ifdef HARDWARE_BT6708
  1391. case PARAM_CONFIG_WHITELIST:
  1392. whitelist_config_param(pcWriteBuffer);
  1393. break;
  1394. #endif
  1395. case PARAM_CONFIG_NET:
  1396. net_config_param(pcWriteBuffer);
  1397. break;
  1398. case PARAM_CONFIG_TIME:
  1399. time_config_param(pcWriteBuffer);
  1400. break;
  1401. }
  1402. config_menu ++;
  1403. if(config_menu == PARAM_CONFIG_ALL){
  1404. config_menu = 0;
  1405. return pdFALSE;
  1406. }
  1407. else{
  1408. return pdTRUE;
  1409. }
  1410. break;
  1411. default:
  1412. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1413. break;
  1414. }
  1415. return pdFALSE;
  1416. }
  1417. if(i == ARG_CONFIG_LOAD){
  1418. memset(str, 0, sizeof(str));
  1419. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1420. if(xParameterStringLength > (int32_t)sizeof(str))
  1421. xParameterStringLength = sizeof(str) - 1;
  1422. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1423. if(xParameterStringLength < 13){
  1424. if(strncmp(str, "default", 7) == 0){
  1425. SNMP_SendUserTrap(DEVICE_RESTORED);
  1426. log_event_data(LOG_SYSTEM_DEFCONFIG, name_login_telnet);
  1427. vTaskDelay(500);
  1428. SETTINGS_SetPartDefault();
  1429. SETTINGS_Save();
  1430. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1431. strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
  1432. }
  1433. else{
  1434. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1435. }
  1436. }
  1437. else{
  1438. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1439. }
  1440. }
  1441. else{
  1442. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1443. }
  1444. xReturn = pdFALSE;
  1445. return xReturn;
  1446. }
  1447. /*
  1448. * Implements the config command.
  1449. */
  1450. static portBASE_TYPE prvTaskNetConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1451. int8_t *pcParameterString;
  1452. portBASE_TYPE xParameterNumber = 1;
  1453. signed portBASE_TYPE xParameterStringLength;
  1454. uint8_t i;
  1455. static start = 0;
  1456. ( void ) pcCommandString;
  1457. ( void ) xWriteBufferLen;
  1458. configASSERT( pcWriteBuffer );
  1459. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1460. /* Obtain the parameter string. */
  1461. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1462. (
  1463. pcCommandString, /* The command string itself. */
  1464. xParameterNumber, /* Return the next parameter. */
  1465. &xParameterStringLength /* Store the parameter string length. */
  1466. );
  1467. for(i = 0; i < ARG_NETCONFIG_ALL; i ++){
  1468. if( strncmp( ( const char * ) pcParameterString, netconfig_args_list[i], strlen(netconfig_args_list[i]) ) == 0 ){
  1469. break;
  1470. }
  1471. }
  1472. if(telnet_code_auth != ADMIN){
  1473. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1474. return pdFALSE;
  1475. }
  1476. switch(i){
  1477. case ARG_NETCONFIG_APPLY:
  1478. if(!start){
  1479. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  1480. if (GetStateWebReinit() == true)
  1481. {
  1482. start = 1;
  1483. telnet_act = true;
  1484. SetWebReinitFlag(true);
  1485. HTTP_SaveSettings();
  1486. strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  1487. return pdTRUE;
  1488. }
  1489. }
  1490. else{
  1491. telnet_act = true;
  1492. start = 0;
  1493. vTaskDelay(1010);
  1494. Reboot();
  1495. }
  1496. break;
  1497. case ARG_NETCONFIG_CONFIRM:
  1498. telnet_act = true;
  1499. SetWebReinitFlag(false);
  1500. SetConfirmWebParamsFlag();
  1501. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  1502. break;
  1503. default:
  1504. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1505. break;
  1506. }
  1507. return pdFALSE;
  1508. }
  1509. /*
  1510. * Implements the history command.
  1511. */
  1512. static portBASE_TYPE prvTaskHistoryCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1513. int8_t *pcParameterString;
  1514. signed portBASE_TYPE xParameterStringLength, xReturn;
  1515. portBASE_TYPE xParameterNumber = 1;
  1516. char str[110];
  1517. uint8_t i;
  1518. static int16_t num_page = 0;
  1519. static int16_t num_page_temp = 1;
  1520. static bool start = true;
  1521. const int8_t * const pcUPShistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий ИБП***********\r\n";
  1522. const int8_t * const pcControllerHistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий Контроллера***********\r\n";
  1523. ( void ) pcCommandString;
  1524. ( void ) xWriteBufferLen;
  1525. configASSERT( pcWriteBuffer );
  1526. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1527. /* Obtain the parameter string. */
  1528. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1529. (
  1530. pcCommandString, /* The command string itself. */
  1531. xParameterNumber, /* Return the next parameter. */
  1532. &xParameterStringLength /* Store the parameter string length. */
  1533. );
  1534. if(pcParameterString == NULL){
  1535. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1536. return pdFALSE;
  1537. }
  1538. if( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ){
  1539. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1540. return pdFALSE;
  1541. }
  1542. xParameterNumber ++;
  1543. /* Obtain the parameter string. */
  1544. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1545. (
  1546. pcCommandString, /* The command string itself. */
  1547. xParameterNumber, /* Return the next parameter. */
  1548. &xParameterStringLength /* Store the parameter string length. */
  1549. );
  1550. for(i = 0; i < ARG_HISTORY_ALL; i ++){
  1551. if( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0 ){
  1552. break;
  1553. }
  1554. }
  1555. xParameterNumber ++;
  1556. /* Obtain the parameter string. */
  1557. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1558. (
  1559. pcCommandString, /* The command string itself. */
  1560. xParameterNumber, /* Return the next parameter. */
  1561. &xParameterStringLength /* Store the parameter string length. */
  1562. );
  1563. memset(str, 0, sizeof(str));
  1564. if(xParameterStringLength > 5){
  1565. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1566. return pdFALSE;
  1567. }
  1568. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1569. if(num_page == 0){
  1570. num_page = atoi(str);
  1571. if(num_page <= 0){
  1572. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1573. return pdFALSE;
  1574. }
  1575. }
  1576. switch(i){
  1577. case ARG_HISTORY_EVENTS:
  1578. if(start){
  1579. start = false;
  1580. /* Return the next command help string, before moving the pointer on to
  1581. the next command in the list. */
  1582. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader, strlen( ( char * ) pcControllerHistoryTableHeader ) );
  1583. memset(str, 0, sizeof(str));
  1584. strcat(( char * ) pcWriteBuffer, "\r\n");
  1585. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  1586. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  1587. strcat(( char * ) pcWriteBuffer, "\r\n");
  1588. if(num_page > History_GetPageCount())
  1589. num_page = History_GetPageCount();
  1590. }
  1591. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  1592. num_page --;
  1593. num_page_temp ++;
  1594. if(num_page == 0){
  1595. num_page = 0;
  1596. num_page_temp = 1;
  1597. start = true;
  1598. xReturn = pdFALSE;
  1599. }
  1600. else{
  1601. xReturn = pdTRUE;
  1602. }
  1603. break;
  1604. case ARG_HISTORY_UPS:
  1605. if(start){
  1606. start = false;
  1607. /* Return the next command help string, before moving the pointer on to
  1608. the next command in the list. */
  1609. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader, strlen( ( char * ) pcUPShistoryTableHeader ) );
  1610. memset(str, 0, sizeof(str));
  1611. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  1612. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  1613. if(num_page > LOG_GetPageCount())
  1614. num_page = LOG_GetPageCount();
  1615. }
  1616. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  1617. num_page --;
  1618. num_page_temp ++;
  1619. if(num_page == 0){
  1620. num_page = 0;
  1621. num_page_temp = 1;
  1622. start = true;
  1623. xReturn = pdFALSE;
  1624. }
  1625. else{
  1626. xReturn = pdTRUE;
  1627. }
  1628. break;
  1629. default:
  1630. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1631. xReturn = pdFALSE;
  1632. break;
  1633. }
  1634. return xReturn;
  1635. }
  1636. /*
  1637. * Implements the sensor info command.
  1638. */
  1639. static portBASE_TYPE prvTaskSensorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1640. int8_t *pcParameterString;
  1641. signed portBASE_TYPE xParameterStringLength, xReturn;
  1642. portBASE_TYPE xParameterNumber = 1;
  1643. uint8_t i;
  1644. char str[10];
  1645. char temp_str[10];
  1646. int32_t val = 0, val2 = 0;
  1647. uint8_t fail = 0;
  1648. static uint8_t config_menu = 0;
  1649. uint8_t MAX_CONFIG_PARAM = 0;
  1650. #ifdef HARDWARE_BT6706
  1651. MAX_CONFIG_PARAM = 3;
  1652. #else
  1653. MAX_CONFIG_PARAM = 2;
  1654. #endif
  1655. const int8_t * const pcSensorTableHeader = ( int8_t * ) "\r\n*********Параметры Контроллера*********\r\n";
  1656. ( void ) pcCommandString;
  1657. ( void ) xWriteBufferLen;
  1658. configASSERT( pcWriteBuffer );
  1659. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1660. /* Obtain the parameter string. */
  1661. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1662. (
  1663. pcCommandString, /* The command string itself. */
  1664. xParameterNumber, /* Return the next parameter. */
  1665. &xParameterStringLength /* Store the parameter string length. */
  1666. );
  1667. if(pcParameterString == NULL){
  1668. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1669. return pdFALSE;
  1670. }
  1671. for(i = 0; i < ARG_SENSOR_ALL; i ++){
  1672. if( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0 ){
  1673. break;
  1674. }
  1675. }
  1676. xParameterNumber ++;
  1677. /* Obtain the parameter string. */
  1678. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1679. (
  1680. pcCommandString, /* The command string itself. */
  1681. xParameterNumber, /* Return the next parameter. */
  1682. &xParameterStringLength /* Store the parameter string length. */
  1683. );
  1684. if(pcParameterString == NULL){
  1685. if(i == ARG_SENSOR_INFO){
  1686. switch(config_menu){
  1687. case 0:
  1688. /* Return the next command help string, before moving the pointer on to
  1689. the next command in the list. */
  1690. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  1691. ups_sensor_param(pcWriteBuffer);
  1692. break;
  1693. case 1:
  1694. ups_sensor_akb_param(pcWriteBuffer);
  1695. break;
  1696. #ifdef HARDWARE_BT6706
  1697. case 2:
  1698. inouts_sensor_param(pcWriteBuffer);
  1699. break;
  1700. #endif
  1701. }
  1702. config_menu ++;
  1703. if(config_menu == MAX_CONFIG_PARAM){
  1704. config_menu = 0;
  1705. return pdFALSE;
  1706. }
  1707. else{
  1708. return pdTRUE;
  1709. }
  1710. }
  1711. else{
  1712. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1713. }
  1714. }
  1715. else{
  1716. switch(i){
  1717. #ifdef HARDWARE_BT6706
  1718. case ARG_SENSOR_SETUP:
  1719. if(telnet_code_auth != ADMIN){
  1720. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1721. return pdFALSE;
  1722. }
  1723. memset(str, 0, sizeof(str));
  1724. if(xParameterStringLength > (int32_t)sizeof(str))
  1725. xParameterStringLength = sizeof(str) - 1;
  1726. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1727. if(xParameterStringLength < 3){
  1728. xParameterNumber ++;
  1729. /* Obtain the parameter string. */
  1730. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1731. (
  1732. pcCommandString, /* The command string itself. */
  1733. xParameterNumber, /* Return the next parameter. */
  1734. &xParameterStringLength /* Store the parameter string length. */
  1735. );
  1736. memset(temp_str, 0, sizeof(str));
  1737. if(xParameterStringLength > 1){
  1738. fail = 1;
  1739. break;
  1740. }
  1741. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  1742. if(!isdigit_int(temp_str[0])){
  1743. fail = 1;
  1744. break;
  1745. }
  1746. val = atoi(temp_str);
  1747. xParameterNumber ++;
  1748. /* Obtain the parameter string. */
  1749. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1750. (
  1751. pcCommandString, /* The command string itself. */
  1752. xParameterNumber, /* Return the next parameter. */
  1753. &xParameterStringLength /* Store the parameter string length. */
  1754. );
  1755. memset(temp_str, 0, sizeof(str));
  1756. if(xParameterStringLength > 1){
  1757. fail = 1;
  1758. break;
  1759. }
  1760. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  1761. if(!isdigit_int(temp_str[0])){
  1762. fail = 1;
  1763. break;
  1764. }
  1765. if(strncmp(str, "DI", 2) == 0){
  1766. if(val != 1){
  1767. fail = 1;
  1768. break;
  1769. }
  1770. val2 = atoi(temp_str);
  1771. if(val2 < 0 || val2 > 1){
  1772. fail = 1;
  1773. break;
  1774. }
  1775. SetDINTypeActStr(temp_str, (val - 1));
  1776. SETTINGS_Save();
  1777. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1778. }
  1779. else if(strncmp(str, "DO", 2) == 0){
  1780. if(val < 1 || val > 3){
  1781. fail = 1;
  1782. break;
  1783. }
  1784. val2 = atoi(temp_str);
  1785. if(val2 < 1 || val2 > 5){
  1786. fail = 1;
  1787. break;
  1788. }
  1789. SetROTypeActStr(temp_str, (val - 1));
  1790. SETTINGS_Save();
  1791. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1792. }
  1793. }
  1794. else{
  1795. fail = 1;
  1796. }
  1797. break;
  1798. #endif
  1799. default:
  1800. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1801. break;
  1802. }
  1803. }
  1804. if(fail)
  1805. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1806. xReturn = pdFALSE;
  1807. return xReturn;
  1808. }
  1809. /*
  1810. * Implements the firmware download http command.
  1811. */
  1812. static portBASE_TYPE prvTaskUploadCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1813. static bool start_update = true;
  1814. const int8_t *const pcUploadHeader = ( int8_t * ) "Контроллер переводится в режим загрузчика\r\n";
  1815. ( void ) pcCommandString;
  1816. ( void ) xWriteBufferLen;
  1817. if(telnet_code_auth != ADMIN){
  1818. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1819. return pdFALSE;
  1820. }
  1821. if(start_update){
  1822. start_update = false;
  1823. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  1824. return pdTRUE;
  1825. }
  1826. else{
  1827. telnet_act = true;
  1828. HTTP_StartResetTask(true);
  1829. return pdFALSE;
  1830. }
  1831. }
  1832. /*
  1833. * Implements the ups command.
  1834. */
  1835. static portBASE_TYPE prvTaskUPSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1836. int8_t *pcParameterString;
  1837. signed portBASE_TYPE xParameterStringLength, xReturn;
  1838. portBASE_TYPE xParameterNumber = 1;
  1839. char str[110];
  1840. int32_t val = 0;
  1841. float val_float = 0;
  1842. int8_t res = 0;
  1843. uint8_t i;
  1844. ( void ) pcCommandString;
  1845. ( void ) xWriteBufferLen;
  1846. configASSERT( pcWriteBuffer );
  1847. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1848. if(telnet_code_auth != ADMIN && i !=ARG_CONFIG_INFO){
  1849. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1850. return pdFALSE;
  1851. }
  1852. /* Obtain the parameter string. */
  1853. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1854. (
  1855. pcCommandString, /* The command string itself. */
  1856. xParameterNumber, /* Return the next parameter. */
  1857. &xParameterStringLength /* Store the parameter string length. */
  1858. );
  1859. for(i = 0; i < ARG_UPS_ALL; i ++){
  1860. if( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0 ){
  1861. break;
  1862. }
  1863. }
  1864. xParameterNumber ++;
  1865. /* Obtain the parameter string. */
  1866. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1867. (
  1868. pcCommandString, /* The command string itself. */
  1869. xParameterNumber, /* Return the next parameter. */
  1870. &xParameterStringLength /* Store the parameter string length. */
  1871. );
  1872. memset(str, 0, sizeof(str));
  1873. if(xParameterStringLength > 3){
  1874. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1875. return pdFALSE;
  1876. }
  1877. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1878. switch(i){
  1879. case ARG_UPS_BATTEST:
  1880. for(uint8_t j = 0; j < xParameterStringLength; j++){
  1881. if(!isdigit_int(str[j])){
  1882. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1883. return pdFALSE;
  1884. }
  1885. }
  1886. val = atoi(str);
  1887. if(val == 0){
  1888. res = ups_metac_service_pdu(ups_cancel_test);
  1889. if(res == 1){
  1890. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  1891. strcpy( ( char * ) pcWriteBuffer, "\t\tТест остановлен!\r\n");
  1892. }
  1893. else{
  1894. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось остановить!\r\n");
  1895. }
  1896. }
  1897. else if(val > 0 && val < 100){
  1898. TimeParam = val;
  1899. res = ups_metac_service_pdu(ups_test_time);
  1900. if(res == 1){
  1901. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1902. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  1903. }
  1904. else{
  1905. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1906. }
  1907. }
  1908. else if(val == 100){
  1909. res = ups_metac_service_pdu(ups_test_10sec);
  1910. if(res == 1){
  1911. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1912. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  1913. }
  1914. else{
  1915. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1916. }
  1917. }
  1918. else if(val == 999){
  1919. res = ups_metac_service_pdu(ups_test_low_bat);
  1920. if(res == 1){
  1921. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1922. strcpy( ( char * ) pcWriteBuffer, "\t\ttТест запущен!\r\n");
  1923. }
  1924. else{
  1925. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1926. }
  1927. }
  1928. else{
  1929. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1930. }
  1931. break;
  1932. case ARG_UPS_SHUTDOWN:
  1933. for(uint8_t j = 0; j < xParameterStringLength; j++){
  1934. if(!isfloatdigit(str[j])){
  1935. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1936. return pdFALSE;
  1937. }
  1938. }
  1939. val_float = atof(str);
  1940. if(val_float == 0){
  1941. res = ups_metac_service_pdu(ups_cancel_shut_down);
  1942. if(res == 1){
  1943. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  1944. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  1945. }
  1946. else{
  1947. strcpy( ( char * ) pcWriteBuffer, "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  1948. }
  1949. }
  1950. else if(val_float > 0 && val_float <= 10){
  1951. TimeParamFloat = val_float;
  1952. res = ups_metac_service_pdu(ups_shutdown);
  1953. if(res == 1){
  1954. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  1955. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  1956. }
  1957. else{
  1958. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  1959. }
  1960. }
  1961. else{
  1962. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1963. }
  1964. break;
  1965. default:
  1966. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1967. break;
  1968. }
  1969. xReturn = pdFALSE;
  1970. return xReturn;
  1971. }
  1972. /*-----------------------------------------------------------*/