CLI_Commands.c 74 KB

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