CLI_Commands.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165
  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. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1228. }
  1229. }
  1230. else{
  1231. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1232. }
  1233. }
  1234. else{
  1235. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1236. }
  1237. break;
  1238. default:
  1239. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1240. break;
  1241. }
  1242. xReturn = pdFALSE;
  1243. return xReturn;
  1244. }
  1245. #endif
  1246. /*
  1247. * Implements the change password command.
  1248. */
  1249. static portBASE_TYPE prvTaskUserCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1250. int8_t *pcParameterString;
  1251. signed portBASE_TYPE xParameterStringLength, xReturn;
  1252. portBASE_TYPE xParameterNumber = 1;
  1253. uint8_t i;
  1254. char temp_str[MAX_WEB_LOGIN_LEN];
  1255. char WebLogin[MAX_WEB_LOGIN_LEN];
  1256. uint8_t valueLen, user_id;
  1257. const int8_t * const pcChangePWDHeader = ( int8_t * ) "\r\nВведите новый пароль:";
  1258. ( void ) pcCommandString;
  1259. ( void ) xWriteBufferLen;
  1260. configASSERT( pcWriteBuffer );
  1261. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1262. if(telnet_code_auth != ADMIN){
  1263. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1264. return pdFALSE;
  1265. }
  1266. /* Obtain the parameter string. */
  1267. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1268. (
  1269. pcCommandString, /* The command string itself. */
  1270. xParameterNumber, /* Return the next parameter. */
  1271. &xParameterStringLength /* Store the parameter string length. */
  1272. );
  1273. if(pcParameterString == NULL){
  1274. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1275. return pdFALSE;
  1276. }
  1277. for(i = 0; i < ARG_USER_ALL; i ++){
  1278. if( strncmp( ( const char * ) pcParameterString, user_args_list[i], strlen(user_args_list[i]) ) == 0 ){
  1279. break;
  1280. }
  1281. }
  1282. xParameterNumber ++;
  1283. /* Obtain the parameter string. */
  1284. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1285. (
  1286. pcCommandString, /* The command string itself. */
  1287. xParameterNumber, /* Return the next parameter. */
  1288. &xParameterStringLength /* Store the parameter string length. */
  1289. );
  1290. if(i == ARG_USER_PWD){
  1291. memset(temp_str, 0, sizeof(temp_str));
  1292. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1293. if(xParameterStringLength > (int32_t)sizeof(temp_str)){
  1294. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1295. }
  1296. else{
  1297. strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
  1298. for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
  1299. GetUserLogin(user_id, WebLogin, &valueLen);
  1300. /* Check login and password */
  1301. if (strncmp(WebLogin, temp_str, MAX_WEB_LOGIN_LEN) == 0) {
  1302. /* Login and pass are valid */
  1303. id_change_pwd = user_id;
  1304. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcChangePWDHeader, strlen( ( char * ) pcChangePWDHeader ) );
  1305. telnetState = TELNET_CHANGE_PWD;
  1306. break;
  1307. }
  1308. }
  1309. if(telnetState != TELNET_CHANGE_PWD){
  1310. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1311. }
  1312. }
  1313. }
  1314. else{
  1315. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1316. }
  1317. xReturn = pdFALSE;
  1318. return xReturn;
  1319. }
  1320. /*
  1321. * Implements the config command.
  1322. */
  1323. static portBASE_TYPE prvTaskConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1324. int8_t *pcParameterString;
  1325. signed portBASE_TYPE xParameterStringLength, xReturn;
  1326. portBASE_TYPE xParameterNumber = 1;
  1327. char str[110];
  1328. uint8_t i;
  1329. static uint8_t config_menu = 0;
  1330. const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n*********Конфигурация Контроллера*********\r\n";
  1331. ( void ) pcCommandString;
  1332. ( void ) xWriteBufferLen;
  1333. configASSERT( pcWriteBuffer );
  1334. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1335. /* Obtain the parameter string. */
  1336. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1337. (
  1338. pcCommandString, /* The command string itself. */
  1339. xParameterNumber, /* Return the next parameter. */
  1340. &xParameterStringLength /* Store the parameter string length. */
  1341. );
  1342. if(pcParameterString == NULL){
  1343. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1344. return pdFALSE;
  1345. }
  1346. for(i = 0; i < ARG_CONFIG_ALL; i ++){
  1347. if( strncmp( ( const char * ) pcParameterString, config_args_list[i], strlen(config_args_list[i]) ) == 0 ){
  1348. break;
  1349. }
  1350. }
  1351. if(telnet_code_auth != ADMIN && i !=ARG_CONFIG_INFO){
  1352. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1353. return pdFALSE;
  1354. }
  1355. xParameterNumber ++;
  1356. /* Obtain the parameter string. */
  1357. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1358. (
  1359. pcCommandString, /* The command string itself. */
  1360. xParameterNumber, /* Return the next parameter. */
  1361. &xParameterStringLength /* Store the parameter string length. */
  1362. );
  1363. if(pcParameterString == NULL){
  1364. switch(i){
  1365. case ARG_CONFIG_INFO:
  1366. switch(config_menu){
  1367. case PARAM_CONFIG_SNMP:
  1368. /* Return the next command help string, before moving the pointer on to
  1369. the next command in the list. */
  1370. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
  1371. snmp_config_param(pcWriteBuffer);
  1372. break;
  1373. #ifdef HARDWARE_BT6706
  1374. case PARAM_CONFIG_INOUTS:
  1375. inouts_config_param(pcWriteBuffer);
  1376. break;
  1377. #endif
  1378. #ifdef HARDWARE_BT6708
  1379. case PARAM_CONFIG_WHITELIST:
  1380. whitelist_config_param(pcWriteBuffer);
  1381. break;
  1382. #endif
  1383. case PARAM_CONFIG_NET:
  1384. net_config_param(pcWriteBuffer);
  1385. break;
  1386. case PARAM_CONFIG_TIME:
  1387. time_config_param(pcWriteBuffer);
  1388. break;
  1389. }
  1390. config_menu ++;
  1391. if(config_menu == PARAM_CONFIG_ALL){
  1392. config_menu = 0;
  1393. return pdFALSE;
  1394. }
  1395. else{
  1396. return pdTRUE;
  1397. }
  1398. break;
  1399. default:
  1400. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1401. break;
  1402. }
  1403. return pdFALSE;
  1404. }
  1405. if(i == ARG_CONFIG_LOAD){
  1406. memset(str, 0, sizeof(str));
  1407. xParameterStringLength = strlen(( const char * ) pcParameterString);
  1408. if(xParameterStringLength > (int32_t)sizeof(str))
  1409. xParameterStringLength = sizeof(str) - 1;
  1410. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1411. if(xParameterStringLength < 13){
  1412. if(strncmp(str, "default", 7) == 0){
  1413. SNMP_SendUserTrap(DEVICE_RESTORED);
  1414. log_event_data(LOG_SYSTEM_DEFCONFIG, name_login_telnet);
  1415. vTaskDelay(500);
  1416. SETTINGS_SetPartDefault();
  1417. SETTINGS_Save();
  1418. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1419. strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
  1420. }
  1421. else{
  1422. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1423. }
  1424. }
  1425. else{
  1426. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1427. }
  1428. }
  1429. else{
  1430. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1431. }
  1432. xReturn = pdFALSE;
  1433. return xReturn;
  1434. }
  1435. /*
  1436. * Implements the config command.
  1437. */
  1438. static portBASE_TYPE prvTaskNetConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1439. int8_t *pcParameterString;
  1440. portBASE_TYPE xParameterNumber = 1;
  1441. signed portBASE_TYPE xParameterStringLength;
  1442. uint8_t i;
  1443. static start = 0;
  1444. ( void ) pcCommandString;
  1445. ( void ) xWriteBufferLen;
  1446. configASSERT( pcWriteBuffer );
  1447. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1448. /* Obtain the parameter string. */
  1449. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1450. (
  1451. pcCommandString, /* The command string itself. */
  1452. xParameterNumber, /* Return the next parameter. */
  1453. &xParameterStringLength /* Store the parameter string length. */
  1454. );
  1455. for(i = 0; i < ARG_NETCONFIG_ALL; i ++){
  1456. if( strncmp( ( const char * ) pcParameterString, netconfig_args_list[i], strlen(netconfig_args_list[i]) ) == 0 ){
  1457. break;
  1458. }
  1459. }
  1460. if(telnet_code_auth != ADMIN){
  1461. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1462. return pdFALSE;
  1463. }
  1464. switch(i){
  1465. case ARG_NETCONFIG_APPLY:
  1466. if(!start){
  1467. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  1468. if (GetStateWebReinit() == true)
  1469. {
  1470. start = 1;
  1471. telnet_act = true;
  1472. SetWebReinitFlag(true);
  1473. HTTP_SaveSettings();
  1474. strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
  1475. return pdTRUE;
  1476. }
  1477. }
  1478. else{
  1479. telnet_act = true;
  1480. start = 0;
  1481. vTaskDelay(1010);
  1482. Reboot();
  1483. }
  1484. break;
  1485. case ARG_NETCONFIG_CONFIRM:
  1486. telnet_act = true;
  1487. SetWebReinitFlag(false);
  1488. SetConfirmWebParamsFlag();
  1489. strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
  1490. break;
  1491. default:
  1492. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1493. break;
  1494. }
  1495. return pdFALSE;
  1496. }
  1497. /*
  1498. * Implements the history command.
  1499. */
  1500. static portBASE_TYPE prvTaskHistoryCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1501. int8_t *pcParameterString;
  1502. signed portBASE_TYPE xParameterStringLength, xReturn;
  1503. portBASE_TYPE xParameterNumber = 1;
  1504. char str[110];
  1505. uint8_t i;
  1506. static int16_t num_page = 0;
  1507. static int16_t num_page_temp = 1;
  1508. static bool start = true;
  1509. const int8_t * const pcUPShistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий ИБП***********\r\n";
  1510. const int8_t * const pcControllerHistoryTableHeader = ( int8_t * ) "\r\n***********Журнал событий Контроллера***********\r\n";
  1511. ( void ) pcCommandString;
  1512. ( void ) xWriteBufferLen;
  1513. configASSERT( pcWriteBuffer );
  1514. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1515. /* Obtain the parameter string. */
  1516. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1517. (
  1518. pcCommandString, /* The command string itself. */
  1519. xParameterNumber, /* Return the next parameter. */
  1520. &xParameterStringLength /* Store the parameter string length. */
  1521. );
  1522. if(pcParameterString == NULL){
  1523. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1524. return pdFALSE;
  1525. }
  1526. if( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ){
  1527. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1528. return pdFALSE;
  1529. }
  1530. xParameterNumber ++;
  1531. /* Obtain the parameter string. */
  1532. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1533. (
  1534. pcCommandString, /* The command string itself. */
  1535. xParameterNumber, /* Return the next parameter. */
  1536. &xParameterStringLength /* Store the parameter string length. */
  1537. );
  1538. for(i = 0; i < ARG_HISTORY_ALL; i ++){
  1539. if( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0 ){
  1540. break;
  1541. }
  1542. }
  1543. xParameterNumber ++;
  1544. /* Obtain the parameter string. */
  1545. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1546. (
  1547. pcCommandString, /* The command string itself. */
  1548. xParameterNumber, /* Return the next parameter. */
  1549. &xParameterStringLength /* Store the parameter string length. */
  1550. );
  1551. memset(str, 0, sizeof(str));
  1552. if(xParameterStringLength > 5){
  1553. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1554. return pdFALSE;
  1555. }
  1556. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1557. if(num_page == 0){
  1558. num_page = atoi(str);
  1559. if(num_page <= 0){
  1560. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1561. return pdFALSE;
  1562. }
  1563. }
  1564. switch(i){
  1565. case ARG_HISTORY_EVENTS:
  1566. if(start){
  1567. start = false;
  1568. /* Return the next command help string, before moving the pointer on to
  1569. the next command in the list. */
  1570. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader, strlen( ( char * ) pcControllerHistoryTableHeader ) );
  1571. memset(str, 0, sizeof(str));
  1572. strcat(( char * ) pcWriteBuffer, "\r\n");
  1573. sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
  1574. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  1575. strcat(( char * ) pcWriteBuffer, "\r\n");
  1576. if(num_page > History_GetPageCount())
  1577. num_page = History_GetPageCount();
  1578. }
  1579. History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  1580. num_page --;
  1581. num_page_temp ++;
  1582. if(num_page == 0){
  1583. num_page = 0;
  1584. num_page_temp = 1;
  1585. start = true;
  1586. xReturn = pdFALSE;
  1587. }
  1588. else{
  1589. xReturn = pdTRUE;
  1590. }
  1591. break;
  1592. case ARG_HISTORY_UPS:
  1593. if(start){
  1594. start = false;
  1595. /* Return the next command help string, before moving the pointer on to
  1596. the next command in the list. */
  1597. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader, strlen( ( char * ) pcUPShistoryTableHeader ) );
  1598. memset(str, 0, sizeof(str));
  1599. sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
  1600. strncat(( char * ) pcWriteBuffer, str, strlen(str));
  1601. if(num_page > LOG_GetPageCount())
  1602. num_page = LOG_GetPageCount();
  1603. }
  1604. LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
  1605. num_page --;
  1606. num_page_temp ++;
  1607. if(num_page == 0){
  1608. num_page = 0;
  1609. num_page_temp = 1;
  1610. start = true;
  1611. xReturn = pdFALSE;
  1612. }
  1613. else{
  1614. xReturn = pdTRUE;
  1615. }
  1616. break;
  1617. default:
  1618. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1619. xReturn = pdFALSE;
  1620. break;
  1621. }
  1622. return xReturn;
  1623. }
  1624. /*
  1625. * Implements the sensor info command.
  1626. */
  1627. static portBASE_TYPE prvTaskSensorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1628. int8_t *pcParameterString;
  1629. signed portBASE_TYPE xParameterStringLength, xReturn;
  1630. portBASE_TYPE xParameterNumber = 1;
  1631. uint8_t i;
  1632. char str[10];
  1633. char temp_str[10];
  1634. int32_t val = 0, val2 = 0;
  1635. uint8_t fail = 0;
  1636. static uint8_t config_menu = 0;
  1637. uint8_t MAX_CONFIG_PARAM = 0;
  1638. #ifdef HARDWARE_BT6706
  1639. MAX_CONFIG_PARAM = 3;
  1640. #else
  1641. MAX_CONFIG_PARAM = 2;
  1642. #endif
  1643. const int8_t * const pcSensorTableHeader = ( int8_t * ) "\r\n*********Параметры Контроллера*********\r\n";
  1644. ( void ) pcCommandString;
  1645. ( void ) xWriteBufferLen;
  1646. configASSERT( pcWriteBuffer );
  1647. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1648. /* Obtain the parameter string. */
  1649. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1650. (
  1651. pcCommandString, /* The command string itself. */
  1652. xParameterNumber, /* Return the next parameter. */
  1653. &xParameterStringLength /* Store the parameter string length. */
  1654. );
  1655. if(pcParameterString == NULL){
  1656. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1657. return pdFALSE;
  1658. }
  1659. for(i = 0; i < ARG_SENSOR_ALL; i ++){
  1660. if( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0 ){
  1661. break;
  1662. }
  1663. }
  1664. xParameterNumber ++;
  1665. /* Obtain the parameter string. */
  1666. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1667. (
  1668. pcCommandString, /* The command string itself. */
  1669. xParameterNumber, /* Return the next parameter. */
  1670. &xParameterStringLength /* Store the parameter string length. */
  1671. );
  1672. if(pcParameterString == NULL){
  1673. if(i == ARG_SENSOR_INFO){
  1674. switch(config_menu){
  1675. case 0:
  1676. /* Return the next command help string, before moving the pointer on to
  1677. the next command in the list. */
  1678. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
  1679. ups_sensor_param(pcWriteBuffer);
  1680. break;
  1681. case 1:
  1682. ups_sensor_akb_param(pcWriteBuffer);
  1683. break;
  1684. #ifdef HARDWARE_BT6706
  1685. case 2:
  1686. inouts_sensor_param(pcWriteBuffer);
  1687. break;
  1688. #endif
  1689. }
  1690. config_menu ++;
  1691. if(config_menu == MAX_CONFIG_PARAM){
  1692. config_menu = 0;
  1693. return pdFALSE;
  1694. }
  1695. else{
  1696. return pdTRUE;
  1697. }
  1698. }
  1699. else{
  1700. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1701. }
  1702. }
  1703. else{
  1704. switch(i){
  1705. #ifdef HARDWARE_BT6706
  1706. case ARG_SENSOR_SETUP:
  1707. if(telnet_code_auth != ADMIN){
  1708. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1709. return pdFALSE;
  1710. }
  1711. memset(str, 0, sizeof(str));
  1712. if(xParameterStringLength > (int32_t)sizeof(str))
  1713. xParameterStringLength = sizeof(str) - 1;
  1714. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1715. if(xParameterStringLength < 3){
  1716. xParameterNumber ++;
  1717. /* Obtain the parameter string. */
  1718. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1719. (
  1720. pcCommandString, /* The command string itself. */
  1721. xParameterNumber, /* Return the next parameter. */
  1722. &xParameterStringLength /* Store the parameter string length. */
  1723. );
  1724. memset(temp_str, 0, sizeof(str));
  1725. if(xParameterStringLength > 1){
  1726. fail = 1;
  1727. break;
  1728. }
  1729. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  1730. if(!isdigit_int(temp_str[0])){
  1731. fail = 1;
  1732. break;
  1733. }
  1734. val = atoi(temp_str);
  1735. xParameterNumber ++;
  1736. /* Obtain the parameter string. */
  1737. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1738. (
  1739. pcCommandString, /* The command string itself. */
  1740. xParameterNumber, /* Return the next parameter. */
  1741. &xParameterStringLength /* Store the parameter string length. */
  1742. );
  1743. memset(temp_str, 0, sizeof(str));
  1744. if(xParameterStringLength > 1){
  1745. fail = 1;
  1746. break;
  1747. }
  1748. strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
  1749. if(!isdigit_int(temp_str[0])){
  1750. fail = 1;
  1751. break;
  1752. }
  1753. if(strncmp(str, "DI", 2) == 0){
  1754. if(val != 1){
  1755. fail = 1;
  1756. break;
  1757. }
  1758. val2 = atoi(temp_str);
  1759. if(val2 < 0 || val2 > 1){
  1760. fail = 1;
  1761. break;
  1762. }
  1763. SetDINTypeActStr(temp_str, (val - 1));
  1764. SETTINGS_Save();
  1765. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1766. }
  1767. else if(strncmp(str, "DO", 2) == 0){
  1768. if(val < 1 || val > 3){
  1769. fail = 1;
  1770. break;
  1771. }
  1772. val2 = atoi(temp_str);
  1773. if(val2 < 1 || val2 > 5){
  1774. fail = 1;
  1775. break;
  1776. }
  1777. SetROTypeActStr(temp_str, (val - 1));
  1778. SETTINGS_Save();
  1779. log_event_data(LOG_SETTING_SAVE, name_login_telnet);
  1780. }
  1781. }
  1782. else{
  1783. fail = 1;
  1784. }
  1785. break;
  1786. #endif
  1787. default:
  1788. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1789. break;
  1790. }
  1791. }
  1792. if(fail)
  1793. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1794. xReturn = pdFALSE;
  1795. return xReturn;
  1796. }
  1797. /*
  1798. * Implements the firmware download http command.
  1799. */
  1800. static portBASE_TYPE prvTaskUploadCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1801. static bool start_update = true;
  1802. const int8_t *const pcUploadHeader = ( int8_t * ) "Контроллер переводится в режим загрузчика\r\n";
  1803. ( void ) pcCommandString;
  1804. ( void ) xWriteBufferLen;
  1805. if(telnet_code_auth != ADMIN){
  1806. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1807. return pdFALSE;
  1808. }
  1809. if(start_update){
  1810. start_update = false;
  1811. strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
  1812. return pdTRUE;
  1813. }
  1814. else{
  1815. telnet_act = true;
  1816. HTTP_StartResetTask(true);
  1817. return pdFALSE;
  1818. }
  1819. }
  1820. /*
  1821. * Implements the ups command.
  1822. */
  1823. static portBASE_TYPE prvTaskUPSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
  1824. int8_t *pcParameterString;
  1825. signed portBASE_TYPE xParameterStringLength, xReturn;
  1826. portBASE_TYPE xParameterNumber = 1;
  1827. char str[110];
  1828. int32_t val = 0;
  1829. float val_float = 0;
  1830. int8_t res = 0;
  1831. uint8_t i;
  1832. ( void ) pcCommandString;
  1833. ( void ) xWriteBufferLen;
  1834. configASSERT( pcWriteBuffer );
  1835. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  1836. if(telnet_code_auth != ADMIN && i !=ARG_CONFIG_INFO){
  1837. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
  1838. return pdFALSE;
  1839. }
  1840. /* Obtain the parameter string. */
  1841. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1842. (
  1843. pcCommandString, /* The command string itself. */
  1844. xParameterNumber, /* Return the next parameter. */
  1845. &xParameterStringLength /* Store the parameter string length. */
  1846. );
  1847. for(i = 0; i < ARG_UPS_ALL; i ++){
  1848. if( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0 ){
  1849. break;
  1850. }
  1851. }
  1852. xParameterNumber ++;
  1853. /* Obtain the parameter string. */
  1854. pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
  1855. (
  1856. pcCommandString, /* The command string itself. */
  1857. xParameterNumber, /* Return the next parameter. */
  1858. &xParameterStringLength /* Store the parameter string length. */
  1859. );
  1860. memset(str, 0, sizeof(str));
  1861. if(xParameterStringLength > 3){
  1862. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1863. return pdFALSE;
  1864. }
  1865. strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
  1866. switch(i){
  1867. case ARG_UPS_BATTEST:
  1868. for(uint8_t j = 0; j < xParameterStringLength; j++){
  1869. if(!isdigit_int(str[j])){
  1870. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1871. return pdFALSE;
  1872. }
  1873. }
  1874. val = atoi(str);
  1875. if(val == 0){
  1876. res = ups_metac_service_pdu(ups_cancel_test);
  1877. if(res == 1){
  1878. log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
  1879. strcpy( ( char * ) pcWriteBuffer, "\t\tТест остановлен!\r\n");
  1880. }
  1881. else{
  1882. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось остановить!\r\n");
  1883. }
  1884. }
  1885. else if(val > 0 && val < 100){
  1886. TimeParam = val;
  1887. res = ups_metac_service_pdu(ups_test_time);
  1888. if(res == 1){
  1889. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1890. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  1891. }
  1892. else{
  1893. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1894. }
  1895. }
  1896. else if(val == 100){
  1897. res = ups_metac_service_pdu(ups_test_10sec);
  1898. if(res == 1){
  1899. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1900. strcpy( ( char * ) pcWriteBuffer, "\t\tТест запущен!\r\n");
  1901. }
  1902. else{
  1903. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1904. }
  1905. }
  1906. else if(val == 999){
  1907. res = ups_metac_service_pdu(ups_test_low_bat);
  1908. if(res == 1){
  1909. log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
  1910. strcpy( ( char * ) pcWriteBuffer, "\t\ttТест запущен!\r\n");
  1911. }
  1912. else{
  1913. strcpy( ( char * ) pcWriteBuffer, "\t\tТест не удалось запустить!\r\n");
  1914. }
  1915. }
  1916. else{
  1917. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1918. }
  1919. break;
  1920. case ARG_UPS_SHUTDOWN:
  1921. for(uint8_t j = 0; j < xParameterStringLength; j++){
  1922. if(!isfloatdigit(str[j])){
  1923. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1924. return pdFALSE;
  1925. }
  1926. }
  1927. val_float = atof(str);
  1928. if(val_float == 0){
  1929. res = ups_metac_service_pdu(ups_cancel_shut_down);
  1930. if(res == 1){
  1931. log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
  1932. strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
  1933. }
  1934. else{
  1935. strcpy( ( char * ) pcWriteBuffer, "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
  1936. }
  1937. }
  1938. else if(val_float > 0 && val_float <= 10){
  1939. TimeParamFloat = val_float;
  1940. res = ups_metac_service_pdu(ups_shutdown);
  1941. if(res == 1){
  1942. log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
  1943. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
  1944. }
  1945. else{
  1946. strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
  1947. }
  1948. }
  1949. else{
  1950. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1951. }
  1952. break;
  1953. default:
  1954. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
  1955. break;
  1956. }
  1957. xReturn = pdFALSE;
  1958. return xReturn;
  1959. }
  1960. /*-----------------------------------------------------------*/