CLI_Commands.c 119 KB

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