CLI_Commands.c 59 KB

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