CLI_Commands.c 90 KB

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