CLI_Commands.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  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. #ifdef HARDWARE_BT6706
  1314. telnet_act = true;
  1315. #endif
  1316. SetWebReinitFlag(true);
  1317. HTTP_SaveSettings();
  1318. strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  1319. return pdTRUE;
  1320. }
  1321. }
  1322. else{
  1323. #ifdef HARDWARE_BT6706
  1324. telnet_act = true;
  1325. #endif
  1326. start = 0;
  1327. vTaskDelay(1010);
  1328. Reboot();
  1329. }
  1330. break;
  1331. case ARG_NETCONFIG_CONFIRM:
  1332. telnet_act = true;
  1333. SetWebReinitFlag(false);
  1334. SetConfirmWebParamsFlag();
  1335. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  1336. break;
  1337. default:
  1338. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1339. break;
  1340. }
  1341. return pdFALSE;
  1342. }
  1343. /*
  1344. * Implements the history command.
  1345. */
  1346. static portBASE_TYPE prvTaskHistoryCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1347. int8_t *pcParameterString;
  1348. signed portBASE_TYPE xParameterStringLength, xReturn;
  1349. portBASE_TYPE xParameterNumber = 1;
  1350. char str[110];
  1351. uint8_t i;
  1352. static int16_t num_page = 0;
  1353. static int16_t num_page_temp = 1;
  1354. static bool start = true;
  1355. const int8_t * const pcUPShistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий ИБП***********\r\n";
  1356. const int8_t * const pcControllerHistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий Контроллера***********\r\n";
  1357. ( void ) pcCommandString;
  1358. ( void ) xWriteBufferLen;
  1359. configASSERT( pcWriteBuffer );
  1360. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1361. /* Obtain the parameter string. */
  1362. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1363. (
  1364. pcCommandString, /* The command string itself. */
  1365. xParameterNumber, /* Return the next parameter. */
  1366. &xParameterStringLength /* Store the parameter string length. */
  1367. );
  1368. if(pcParameterString == NULL){
  1369. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1370. return pdFALSE;
  1371. }
  1372. if( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ){
  1373. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1374. return pdFALSE;
  1375. }
  1376. xParameterNumber ++;
  1377. /* Obtain the parameter string. */
  1378. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1379. (
  1380. pcCommandString, /* The command string itself. */
  1381. xParameterNumber, /* Return the next parameter. */
  1382. &xParameterStringLength /* Store the parameter string length. */
  1383. );
  1384. for(i = 0; i < ARG_HISTORY_ALL; i ++){
  1385. if( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0 ){
  1386. break;
  1387. }
  1388. }
  1389. xParameterNumber ++;
  1390. /* Obtain the parameter string. */
  1391. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1392. (
  1393. pcCommandString, /* The command string itself. */
  1394. xParameterNumber, /* Return the next parameter. */
  1395. &xParameterStringLength /* Store the parameter string length. */
  1396. );
  1397. memset(str, 0, sizeof(str));
  1398. if(xParameterStringLength > 5){
  1399. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1400. return pdFALSE;
  1401. }
  1402. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1403. if(num_page == 0){
  1404. num_page = atoi(str);
  1405. if(num_page <= 0){
  1406. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1407. return pdFALSE;
  1408. }
  1409. }
  1410. switch(i){
  1411. case ARG_HISTORY_EVENTS:
  1412. if(start){
  1413. start = false;
  1414. /* Return the next command help string, before moving the pointer on to
  1415. the next command in the list. */
  1416. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader, strlen( ( char * ) pcControllerHistoryTableHeader ) );
  1417. memset(str, 0, sizeof(str));
  1418. strcat(( char * ) pcWriteBuffer, "\r\n");
  1419. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  1420. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  1421. strcat(( char * ) pcWriteBuffer, "\r\n");
  1422. if(num_page > History_GetPageCount())
  1423. num_page = History_GetPageCount();
  1424. }
  1425. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  1426. num_page --;
  1427. num_page_temp ++;
  1428. if(num_page == 0){
  1429. num_page = 0;
  1430. num_page_temp = 1;
  1431. start = true;
  1432. xReturn = pdFALSE;
  1433. }
  1434. else{
  1435. xReturn = pdTRUE;
  1436. }
  1437. break;
  1438. case ARG_HISTORY_UPS:
  1439. if(start){
  1440. start = false;
  1441. /* Return the next command help string, before moving the pointer on to
  1442. the next command in the list. */
  1443. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader, strlen( ( char * ) pcUPShistoryTableHeader ) );
  1444. memset(str, 0, sizeof(str));
  1445. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  1446. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  1447. if(num_page > LOG_GetPageCount())
  1448. num_page = LOG_GetPageCount();
  1449. }
  1450. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  1451. num_page --;
  1452. num_page_temp ++;
  1453. if(num_page == 0){
  1454. num_page = 0;
  1455. num_page_temp = 1;
  1456. start = true;
  1457. xReturn = pdFALSE;
  1458. }
  1459. else{
  1460. xReturn = pdTRUE;
  1461. }
  1462. break;
  1463. default:
  1464. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1465. xReturn = pdFALSE;
  1466. break;
  1467. }
  1468. return xReturn;
  1469. }
  1470. /*
  1471. * Implements the sensor info command.
  1472. */
  1473. static portBASE_TYPE prvTaskSensorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1474. int8_t *pcParameterString;
  1475. signed portBASE_TYPE xParameterStringLength, xReturn;
  1476. portBASE_TYPE xParameterNumber = 1;
  1477. uint8_t i;
  1478. char str[10];
  1479. char temp_str[10];
  1480. int32_t val = 0, val2 = 0;
  1481. uint8_t fail = 0;
  1482. static uint8_t config_menu = 0;
  1483. const int8_t * const pcSensorTableHeader = ( int8_t * ) "\r\n*********Параметры Контроллера*********\r\n";
  1484. ( void ) pcCommandString;
  1485. ( void ) xWriteBufferLen;
  1486. configASSERT( pcWriteBuffer );
  1487. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1488. /* Obtain the parameter string. */
  1489. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1490. (
  1491. pcCommandString, /* The command string itself. */
  1492. xParameterNumber, /* Return the next parameter. */
  1493. &xParameterStringLength /* Store the parameter string length. */
  1494. );
  1495. if(pcParameterString == NULL){
  1496. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1497. return pdFALSE;
  1498. }
  1499. for(i = 0; i < ARG_SENSOR_ALL; i ++){
  1500. if( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0 ){
  1501. break;
  1502. }
  1503. }
  1504. xParameterNumber ++;
  1505. /* Obtain the parameter string. */
  1506. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1507. (
  1508. pcCommandString, /* The command string itself. */
  1509. xParameterNumber, /* Return the next parameter. */
  1510. &xParameterStringLength /* Store the parameter string length. */
  1511. );
  1512. if(pcParameterString == NULL){
  1513. if(i == ARG_SENSOR_INFO){
  1514. switch(config_menu){
  1515. case 0:
  1516. /* Return the next command help string, before moving the pointer on to
  1517. the next command in the list. */
  1518. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  1519. ups_sensor_param(pcWriteBuffer);
  1520. break;
  1521. case 1:
  1522. ups_sensor_akb_param(pcWriteBuffer);
  1523. break;
  1524. case 2:
  1525. inouts_sensor_param(pcWriteBuffer);
  1526. break;
  1527. }
  1528. config_menu ++;
  1529. if(config_menu == 3){
  1530. config_menu = 0;
  1531. return pdFALSE;
  1532. }
  1533. else{
  1534. return pdTRUE;
  1535. }
  1536. }
  1537. else{
  1538. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1539. }
  1540. }
  1541. else{
  1542. switch(i){
  1543. case ARG_SENSOR_SETUP:
  1544. if(telnet_code_auth != ADMIN){
  1545. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1546. return pdFALSE;
  1547. }
  1548. memset(str, 0, sizeof(str));
  1549. if(xParameterStringLength > (int32_t)sizeof(str))
  1550. xParameterStringLength = sizeof(str) - 1;
  1551. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1552. if(xParameterStringLength < 3){
  1553. xParameterNumber ++;
  1554. /* Obtain the parameter string. */
  1555. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1556. (
  1557. pcCommandString, /* The command string itself. */
  1558. xParameterNumber, /* Return the next parameter. */
  1559. &xParameterStringLength /* Store the parameter string length. */
  1560. );
  1561. memset(temp_str, 0, sizeof(str));
  1562. if(xParameterStringLength > 1){
  1563. fail = 1;
  1564. break;
  1565. }
  1566. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  1567. if(!isdigit_int(temp_str[0])){
  1568. fail = 1;
  1569. break;
  1570. }
  1571. val = atoi(temp_str);
  1572. xParameterNumber ++;
  1573. /* Obtain the parameter string. */
  1574. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1575. (
  1576. pcCommandString, /* The command string itself. */
  1577. xParameterNumber, /* Return the next parameter. */
  1578. &xParameterStringLength /* Store the parameter string length. */
  1579. );
  1580. memset(temp_str, 0, sizeof(str));
  1581. if(xParameterStringLength > 1){
  1582. fail = 1;
  1583. break;
  1584. }
  1585. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  1586. if(!isdigit_int(temp_str[0])){
  1587. fail = 1;
  1588. break;
  1589. }
  1590. if(strncmp(str, "DI", 2) == 0){
  1591. if(val != 1){
  1592. fail = 1;
  1593. break;
  1594. }
  1595. val2 = atoi(temp_str);
  1596. if(val2 < 0 || val2 > 1){
  1597. fail = 1;
  1598. break;
  1599. }
  1600. SetDINTypeActStr(temp_str, (val - 1));
  1601. SETTINGS_Save();
  1602. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1603. }
  1604. else if(strncmp(str, "DO", 2) == 0){
  1605. if(val < 1 || val > 3){
  1606. fail = 1;
  1607. break;
  1608. }
  1609. val2 = atoi(temp_str);
  1610. if(val2 < 1 || val2 > 5){
  1611. fail = 1;
  1612. break;
  1613. }
  1614. SetROTypeActStr(temp_str, (val - 1));
  1615. SETTINGS_Save();
  1616. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1617. }
  1618. }
  1619. else{
  1620. fail = 1;
  1621. }
  1622. break;
  1623. default:
  1624. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1625. break;
  1626. }
  1627. }
  1628. if(fail)
  1629. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1630. xReturn = pdFALSE;
  1631. return xReturn;
  1632. }
  1633. /*
  1634. * Implements the firmware download http command.
  1635. */
  1636. static portBASE_TYPE prvTaskUploadCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1637. static bool start_update = true;
  1638. const int8_t *const pcUploadHeader = ( int8_t * ) "Контроллер переводится в режим загрузчика\r\n";
  1639. ( void ) pcCommandString;
  1640. ( void ) xWriteBufferLen;
  1641. if(telnet_code_auth != ADMIN){
  1642. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1643. return pdFALSE;
  1644. }
  1645. if(start_update){
  1646. start_update = false;
  1647. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  1648. return pdTRUE;
  1649. }
  1650. else{
  1651. telnet_act = true;
  1652. HTTP_StartResetTask(true);
  1653. return pdFALSE;
  1654. }
  1655. }
  1656. /*
  1657. * Implements the ups command.
  1658. */
  1659. static portBASE_TYPE prvTaskUPSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1660. int8_t *pcParameterString;
  1661. signed portBASE_TYPE xParameterStringLength, xReturn;
  1662. portBASE_TYPE xParameterNumber = 1;
  1663. char str[110];
  1664. int32_t val = 0;
  1665. float val_float = 0;
  1666. int8_t res = 0;
  1667. uint8_t i;
  1668. ( void ) pcCommandString;
  1669. ( void ) xWriteBufferLen;
  1670. configASSERT( pcWriteBuffer );
  1671. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1672. if(telnet_code_auth != ADMIN && i !=ARG_CONFIG_INFO){
  1673. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1674. return pdFALSE;
  1675. }
  1676. /* Obtain the parameter string. */
  1677. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1678. (
  1679. pcCommandString, /* The command string itself. */
  1680. xParameterNumber, /* Return the next parameter. */
  1681. &xParameterStringLength /* Store the parameter string length. */
  1682. );
  1683. for(i = 0; i < ARG_UPS_ALL; i ++){
  1684. if( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0 ){
  1685. break;
  1686. }
  1687. }
  1688. xParameterNumber ++;
  1689. /* Obtain the parameter string. */
  1690. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1691. (
  1692. pcCommandString, /* The command string itself. */
  1693. xParameterNumber, /* Return the next parameter. */
  1694. &xParameterStringLength /* Store the parameter string length. */
  1695. );
  1696. memset(str, 0, sizeof(str));
  1697. if(xParameterStringLength > 3){
  1698. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1699. return pdFALSE;
  1700. }
  1701. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1702. switch(i){
  1703. case ARG_UPS_BATTEST:
  1704. for(uint8_t j = 0; j < xParameterStringLength; j++){
  1705. if(!isdigit_int(str[j])){
  1706. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1707. return pdFALSE;
  1708. }
  1709. }
  1710. val = atoi(str);
  1711. if(val == 0){
  1712. res = ups_metac_service_pdu(ups_cancel_test);
  1713. if(res == 1){
  1714. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  1715. strcpy( ( char * ) pcWriteBuffer, "\t\tТест остановлен!\r\n");
  1716. }
  1717. else{
  1718. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось остановить!\r\n");
  1719. }
  1720. }
  1721. else if(val > 0 && val < 100){
  1722. TimeParam = val;
  1723. res = ups_metac_service_pdu(ups_test_time);
  1724. if(res == 1){
  1725. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1726. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  1727. }
  1728. else{
  1729. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1730. }
  1731. }
  1732. else if(val == 100){
  1733. res = ups_metac_service_pdu(ups_test_10sec);
  1734. if(res == 1){
  1735. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1736. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  1737. }
  1738. else{
  1739. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1740. }
  1741. }
  1742. else if(val == 999){
  1743. res = ups_metac_service_pdu(ups_test_low_bat);
  1744. if(res == 1){
  1745. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1746. strcpy( ( char * ) pcWriteBuffer, "\t\ttТест запущен!\r\n");
  1747. }
  1748. else{
  1749. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1750. }
  1751. }
  1752. else{
  1753. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1754. }
  1755. break;
  1756. case ARG_UPS_SHUTDOWN:
  1757. for(uint8_t j = 0; j < xParameterStringLength; j++){
  1758. if(!isfloatdigit(str[j])){
  1759. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1760. return pdFALSE;
  1761. }
  1762. }
  1763. val_float = atof(str);
  1764. if(val_float == 0){
  1765. res = ups_metac_service_pdu(ups_cancel_shut_down);
  1766. if(res == 1){
  1767. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  1768. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  1769. }
  1770. else{
  1771. strcpy( ( char * ) pcWriteBuffer, "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  1772. }
  1773. }
  1774. else if(val_float > 0 && val_float <= 10){
  1775. TimeParamFloat = val_float;
  1776. res = ups_metac_service_pdu(ups_shutdown);
  1777. if(res == 1){
  1778. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  1779. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  1780. }
  1781. else{
  1782. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  1783. }
  1784. }
  1785. else{
  1786. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1787. }
  1788. break;
  1789. default:
  1790. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1791. break;
  1792. }
  1793. xReturn = pdFALSE;
  1794. return xReturn;
  1795. }
  1796. /*-----------------------------------------------------------*/