CLI_Commands.c 75 KB

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