CLI_Commands.c 134 KB

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