CLI_Commands.c 74 KB

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