CLI_Commands.c 119 KB

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