CLI_Commands.c 120 KB

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