CLI_Commands.c 137 KB

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