CLI_Commands.c 112 KB

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