CLI_Commands.c 133 KB

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