CLI_Commands.c 137 KB

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