CLI_Commands.c 148 KB

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