CLI_Commands.c 68 KB

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