CLI_Commands.c 68 KB

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