123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853 |
- /*
- * CLI_Commands.c
- *
- * Created on: 28.11.2017
- * Author: balbekova
- */
- /* FreeRTOS includes. */
- #include "FreeRTOS.h"
- #include "task.h"
- /* Standard includes. */
- #include <stdint.h>
- #ifdef PRINTF_STDLIB
- #include <stdio.h>
- #endif
- #ifdef PRINTF_CUSTOM
- #include "tinystdio.h"
- #endif
- #include <string.h>
- #include <stdlib.h>
- /* FreeRTOS+CLI includes. */
- #include "FreeRTOS_CLI.h"
- #include "snmp_api.h"
- #include "trap_api.h"
- #include "sntp_api.h"
- #include "lwip/ip_addr.h"
- #include "settings_api.h"
- #include "log.h"
- #include "megatec.h"
- #include "web_params_api.h"
- #include "hal.h"
- #include "parameters.h"
- #include "CLI_Commands.h"
- #include "CLI_Parameters.h"
- #include "cli.h"
- #include "netconf.h"
- #include "control_symbol.h"
- const int8_t *const pcInvalidCommand = ( int8_t * )
- "Неправильно введены параметры команды. Введите \"help\" для просмотра списка поддерживаемых команд.\r\n\r\n";
- const int8_t *const pcPermissionDenied = ( int8_t * ) "Отказ в доступе!\r\n\r\n";
- const int8_t *const pcSystymeDenied = ( int8_t * )
- "Ручной ввод времени не доступен!\r\n\r\n";
- const char *info_args_list[] = {
- "name",
- "address",
- "owner",
- "comments",
- };
- const char *ups_args_list[] = {
- "battest",
- "shutdown",
- };
- const char *systime_args_list[] = {
- "date",
- "time",
- };
- const char *network_args_list[] = {
- "info",
- "dhcp",
- "ip",
- "gw",
- "mask",
- };
- const char *snmp_args_list[] = {
- "info",
- "server",
- "community",
- };
- const char *akb_args_list[] = {
- "info",
- "voltcellmin",
- "voltcellmax",
- #ifdef HARDWARE_BT6709
- "capacity",
- "voltakb",
- "lifetime",
- "dataset",
- "upspower",
- #endif
- };
- const char *type_alarm_args_list[] = {
- "info",
- "temp",
- "load",
- "vout",
- };
- const char *alarm_args_list[] = {
- "low",
- "high",
- "hist",
- };
- const char *notification_args_list[] = {
- "info",
- "set",
- };
- const char *whitelist_args_list[] = {
- "info",
- "range",
- "reset",
- };
- const char *ntp_args_list[] = {
- "ENA",
- "DIS",
- "info",
- "set",
- };
- const char *config_args_list[] = {
- "info",
- "load",
- };
- const char *netconfig_args_list[] = {
- "apply",
- "confirm",
- };
- const char *history_args_list[] = {
- "EVENTS",
- "UPS",
- };
- const char *sensor_args_list[] = {
- "info",
- "setup",
- };
- const char *user_args_list[] = {
- "passwd",
- };
- /**
- * @brief Общая структура настроек
- */
- extern SETTINGS_t sSettings;
- /*
- * Implements the controller's information command.
- */
- static portBASE_TYPE prvTaskInfoCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
- /*
- * Implements the reboot command.
- */
- static portBASE_TYPE prvTaskRebootCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- /*
- * Implements the systime command.
- */
- static portBASE_TYPE prvTaskSystimeCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- /*
- * Implements the ntp command.
- */
- static portBASE_TYPE prvTaskNTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
- /*
- * Implements the network command.
- */
- static portBASE_TYPE prvTaskNetworkCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- /*
- * Implements the snmp command.
- */
- static portBASE_TYPE prvTaskSNMPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
- /*
- * Implements the AKB command.
- */
- static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
- /*
- * Implements the alarm command.
- */
- static portBASE_TYPE prvTaskAlarmCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- #ifdef HARDWARE_BT6709
- /*
- * Implements the notification command.
- */
- static portBASE_TYPE prvTaskNotificationCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- /*
- * Implements the whitelist command.
- */
- static portBASE_TYPE prvTaskWhiteListCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- #endif
- /*
- * Implements the change password command.
- */
- static portBASE_TYPE prvTaskUserCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
- /*
- * Implements the config command.
- */
- static portBASE_TYPE prvTaskConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- /*
- * Implements the netconfig command.
- */
- static portBASE_TYPE prvTaskNetConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- /*
- * Implements the history command.
- */
- static portBASE_TYPE prvTaskHistoryCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- /*
- * Implements the sensor info command.
- */
- static portBASE_TYPE prvTaskSensorCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- /*
- * Implements the firmware download http command.
- */
- static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString );
- /*
- * Implements the ups command.
- */
- static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
- /* Structure that defines the "info" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvInfoCommandDefinition = {
- ( const int8_t *const ) "info", /* The command string to type. */
- ( const int8_t *const ) "\tinfo: вывод информации о контроллере\r\n"
- "\tinfo name <name>: установка поля \"название устройства\"\r\n"
- "\tinfo address <adrr>: установка поля \"адрес расположения контролируемого объекта\"\r\n"
- "\tinfo owner <owner>: установка поля \"организация (собственник)\"\r\n"
- "\tinfo comments <comment>: установка поля \"комментарии\"\r\n",
- prvTaskInfoCommand, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- /* Structure that defines the "reboot" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvRebootCommandDefinition = {
- ( const int8_t *const ) "reboot", /* The command string to type. */
- ( const int8_t *const ) "\treboot: перезагрузка Контроллера\r\n",
- prvTaskRebootCommand, /* The function to run. */
- 0 /* No parameters are expected. */
- };
- /* Structure that defines the "systime" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvSystimeCommandDefinition = {
- ( const int8_t *const ) "systime", /* The command string to type. */
- ( const int8_t *const ) "\tsystime: вывод системного времени\r\n"
- "\tsystime date <YYYY-MM-DD>: установка даты\r\n"
- "\tsystime time <HH:MM>: установка времени\r\n",
- prvTaskSystimeCommand, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- /* Structure that defines the "ntp" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvNTPCommandDefinition = {
- ( const int8_t *const ) "ntp", /* The command string to type. */
- ( const int8_t *const ) "\tntp ENA|DIS: разрешение/запрет синхронизации времени\r\n"
- "\tntp set IP <A.B.C.D>: установка сервера NTP\r\n"
- "\tntp info: вывод информации о сервере NTP\r\n"
- "\tntp set gmt <SIGN><NUM>: установка часового пояса\r\n",
- prvTaskNTPCommand, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- /* Structure that defines the "network" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvNetworkCommandDefinition = {
- ( const int8_t *const ) "network", /* The command string to type. */
- ( const int8_t *const ) "\tnetwork info вывод информации о текущих сетевых настройках:\r\n"
- "\tnetwork dhcp ENA|DIS: разрешение/запрет получения IP по DHCP\r\n"
- "\tnetwork ip <A.B.C.D>: установка статического IP\r\n"
- "\tnetwork gw <A.B.C.D>: установка шлюза\r\n"
- "\tnetwork mask <A.B.C.D>: установка маски подсети\r\n",
- prvTaskNetworkCommand, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- /* Structure that defines the "snmp" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvSNMPCommandDefinition = {
- ( const int8_t *const ) "snmp", /* The command string to type. */
- ( const int8_t *const ) "\tsnmp info: вывод информации о текущих SNMP настройках\r\n"
- "\tsnmp server <NUM> <A.B.C.D>: установка сервера SNMP\r\n"
- "\tsnmp community read <read>: установка Read community\r\n"
- "\tsnmp community write <write>: установка Write community\r\n",
- prvTaskSNMPCommand, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- /* Structure that defines the "akb" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvAKBCommandDefinition = {
- ( const int8_t *const ) "akb", /* The command string to type. */
- ( const int8_t *const ) "\takb info: вывод информации о параметрах АКБ\r\n"
- "\takb voltcellmin <value>: ввод минимального напряжения на ячейки АКБ (В)\r\n"
- "\takb voltcellmax <value>: ввод максимального напряжения на ячейки АКБ (В)\r\n"
- #ifdef HARDWARE_BT6709
- "\takb capacity <value>: ввод ёмкости АКБ (Ач)\r\n"
- "\takb voltakb <value>: ввод номинального напряжения АКБ (В)\r\n"
- "\takb lifetime <value>: ввод срока службы АКБ (лет)\r\n"
- "\takb dataset <YYYY-MM-DD>: ввод даты установки АКБ\r\n"
- "\takb upspower <value>: ввод полной мощности ИБП (ВА)\r\n"
- #endif
- ,
- prvTaskAKBCommand, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- /* Structure that defines the "alarm" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvAlarmCommandDefinition = {
- ( const int8_t *const ) "alarm", /* The command string to type. */
- ( const int8_t *const ) "\talarm info: вывод информации о параметрах АКБ\r\n"
- "\talarm temp low <value>: ввод нижней границы аварии по температуре (С)\r\n"
- "\talarm temp high <value>: ввод верxней границы аварии по температуре (С)\r\n"
- "\talarm temp hist <value>: ввод гистерезиса аварии по температуре (С)\r\n"
- "\talarm load high <value>: ввод верхней границы аварии по нагрузке (%)\r\n"
- "\talarm load hist <value>: ввод гистерезиса аварии по нагрузке (%)\r\n"
- "\talarm vout low <value>: ввод нижней границы аварии по вых. напряжению (В)\r\n"
- "\talarm vout high <value>: ввод верxней границы аварии по вых. напряжению (В)\r\n"
- "\talarm vout hist <value>: ввод гистерезиса аварии по вых. напряжению (В)\r\n",
- prvTaskAlarmCommand, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- #ifdef HARDWARE_BT6709
- /* Structure that defines the "notification" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvNotificationCommandDefinition = {
- ( const int8_t *const ) "notification", /* The command string to type. */
- ( const int8_t *const ) "\tnotification info: вывод списка уведомлений\r\n"
- "\tnotification set <NUM> ENA|DIS: вкл/выкл уведомления\r\n",
- prvTaskNotificationCommand, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- /* Structure that defines the "whitelist" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvWhiteListCommandDefinition = {
- ( const int8_t *const ) "whitelist", /* The command string to type. */
- ( const int8_t *const ) "\twhitelist info: вывод информации о текущем белом списке IP адресов контроллера\r\n"
- "\twhitelist range <NUM> <A.B.C.D/E>: установка диапазона IP адресов\r\n"
- "\twhitelist reset <NUM>: сброс диапазона IP адресов\r\n",
- prvTaskWhiteListCommand, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- #endif
- /* Structure that defines the "user" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvUserCommandDefinition = {
- ( const int8_t *const ) "user", /* The command string to type. */
- ( const int8_t *const ) "\tuser passwd <name>: установка пароля для пользователя <name>\r\n",
- prvTaskUserCommand, /* The function to run. */
- 2 /* Two parameters are expected, which can take any value. */
- };
- /* Structure that defines the "config" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvConfigCommandDefinition = {
- ( const int8_t *const ) "config", /* The command string to type. */
- ( const int8_t *const ) "\tconfig info: вывод информации о состоянии конфигураций\r\n"
- "\tconfig load default: загрузка конфигурации по умолчанию\r\n",
- prvTaskConfigCommand, /* The function to run. */
- -1 /* Two parameters are expected, which can take any value. */
- };
- /* Structure that defines the "config" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvNetConfigCommandDefinition = {
- ( const int8_t *const ) "netconfig", /* The command string to type. */
- ( const int8_t *const ) "\tnetconfig apply: применение конфигурации сетевых настроек\r\n"
- "\tnetconfig confirm: подтверждение конфигурации сетевых настроек\r\n",
- prvTaskNetConfigCommand, /* The function to run. */
- 1 /* Two parameters are expected, which can take any value. */
- };
- /* Structure that defines the "history" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvHistoryCommandDefinition = {
- ( const int8_t *const ) "history", /* The command string to type. */
- ( const int8_t *const ) "\thistory show EVENTS|UPS <num_page>: вывод журнала\r\n",
- prvTaskHistoryCommand, /* The function to run. */
- 3 /* Two parameters are expected, which can take any value. */
- };
- /* Structure that defines the "sensor info" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvSensorCommandDefinition = {
- ( const int8_t *const ) "sensor", /* The command string to type. */
- ( const int8_t *const ) "\tsensor info: вывод параметров системы (выход из режима Ctrl+C далее Enter)\r\n"
- #ifdef HARDWARE_BT6707
- "\tsensor setup DI <num> <state>: установка нормального состояния сухого контакта:\r\n"
- "\t\t\t\t0 - разомкнутое состояние\r\n"
- "\t\t\t\t1 - замкнутое состояние\r\n"
- "\tsensor setup DO <num> <issue>: установка источника срабатывания реле:\r\n"
- "\t\t\t\t1 - Наличие сети\r\n"
- "\t\t\t\t2 - Наличие выходного напряжения\r\n"
- "\t\t\t\t3 - Разряд АКБ\r\n"
- "\t\t\t\t4 - Отключение АКБ\r\n"
- "\t\t\t\t5 - SNMP SET\r\n"
- #endif
- ,
- prvTaskSensorCommand, /* The function to run. */
- -1 /* No parameters are expected. */
- };
- /* Structure that defines the "firmware dowmload http" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvUploadCommandDefinition = {
- ( const int8_t *const ) "firmware download http", /* The command string to type. */
- ( const int8_t *const ) "\tfirmware download http: переход в режим обновления через Web-сервер\r\n",
- prvTaskUploadCommand, /* The function to run. */
- 2 /* No parameters are expected. */
- };
- /* Structure that defines the "ups" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvUPSCommandDefinition = {
- ( const int8_t *const ) "ups", /* The command string to type. */
- ( const int8_t *const ) "\tups battest <num>: управление процедурой тестирования АКБ:\r\n"
- "\t\t\t\t0 - Остановить тестирование\r\n"
- "\t\t\t\t1-99 - Запустить тест на x минут\r\n"
- "\t\t\t\t100 - Тестирование в течение 10 секунд\r\n"
- "\t\t\t\t999 - Тестирование до разряда\r\n"
- "\tups shutdown <num>: управление отключением нагрузки ИБП:\r\n"
- "\t\t\t\t0 - Остановить процедуру отключения нагрузки\r\n"
- "\t\t\t\tn - Отключить нагрузку через n минут\r\n"
- "\t\t\t\tn: 0.2, 0.3, ..., 1, 2, ..., 10\r\n",
- prvTaskUPSCommand, /* The function to run. */
- 2 /* Two parameters are expected, which can take any value. */
- };
- /* Structure that defines the "quit" command line command. This
- generates a table that shows how much run time each task has */
- static const CLI_Command_Definition_t prvQuitCommandDefinition = {
- ( const int8_t *const ) "quit", /* The command string to type. */
- ( const int8_t *const ) "\tquit: завершение сессии\r\n",
- NULL, /* The function to run. */
- -1 /* The user can enter any number of commands. */
- };
- /*-----------------------------------------------------------*/
- void vRegisterCLICommands( void )
- {
- /* Register all the command line commands defined immediately above. */
- FreeRTOS_CLIRegisterCommand( &prvInfoCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvRebootCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvSystimeCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvNTPCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvNetworkCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvSNMPCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvAKBCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvAlarmCommandDefinition );
- #ifdef HARDWARE_BT6709
- FreeRTOS_CLIRegisterCommand( &prvNotificationCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvWhiteListCommandDefinition );
- #endif
- FreeRTOS_CLIRegisterCommand( &prvUserCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvConfigCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvNetConfigCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvHistoryCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvSensorCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvUploadCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvUPSCommandDefinition );
- FreeRTOS_CLIRegisterCommand( &prvQuitCommandDefinition );
- }
- /*-----------------------------------------------------------*/
- static portBASE_TYPE prvTaskInfoCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[110];
- uint8_t len;
- int8_t num_arg = 0;
- uint8_t i;
- static uint8_t page = 0;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- num_arg = prvGetNumberOfParameters(pcCommandString);
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- if (num_arg == 0) {
- const int8_t *const pcInfoTableHeader = ( int8_t * )
- "\r\n**************Информация о Контроллере**************\r\n";
- const int8_t *const pcUPSInfoTableHeader = ( int8_t * )
- "\r\n*****************Информация об ИБП******************\r\n";
- if (!page) {
- /* Return the next command help string, before moving the pointer on to
- the next command in the list. */
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
- GetWorkTimeStr(str, &len);
- strcat(( char * ) pcWriteBuffer, "Время работы:\t\t\t");
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
- GetModelStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nДата производства:\t\t");
- GetProductionDataStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
- GetVersionStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nMAC адрес:\t\t\t");
- GetMacStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nСерийный номер:\t\t\t");
- GetSerialNumberStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nНазвание устройства:\t\t");
- GetNameDeviceStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nВладелец:\t\t\t");
- GetOwnerStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nМестоположение:\t\t\t");
- GetLocationStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nКомментарии:\t\t\t");
- GetCommentsStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- page = 1;
- xReturn = pdTRUE;
- } else {
- strncat( ( char * ) pcWriteBuffer, ( const char * ) pcUPSInfoTableHeader, strlen( ( char * ) pcUPSInfoTableHeader ) );
- strcat(( char * ) pcWriteBuffer, "\r\nКомпания:\t\t\tАО\"НПК РоТеК\"");
- strcat(( char * ) pcWriteBuffer, "\r\nМодель:\t\t\t\t");
- GetUPSModelStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nВерсия ПО:\t\t\t");
- GetUPSVersionStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\n");
- page = 0;
- /* There are no more commands in the list, so there will be no more
- strings to return after this one and pdFALSE should be returned. */
- xReturn = pdFALSE;
- }
- } else if (num_arg == 1) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- xReturn = pdFALSE;
- } else {
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- for (i = 0; i < INFO_ALL_ARGS; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, info_args_list[i], strlen(info_args_list[i]) ) == 0
- && xParameterStringLength == strlen(info_args_list[i])) {
- break;
- }
- }
- xParameterNumber ++;
- // xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- memset(str, 0, sizeof(str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
- if (control_string_en_digit(str, strlen(str))) {
- switch (i) {
- case INFO_DEV_NAME:
- if (cli_state->user_id == ADMIN) {
- str[19] = 0;
- SetNameDeviceStr(str);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- }
- break;
- case INFO_ADDRESS:
- if (cli_state->user_id == ADMIN) {
- str[109] = 0;
- SetLocation(str);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- }
- break;
- case INFO_OWNER:
- if (cli_state->user_id == ADMIN) {
- str[49] = 0;
- SetOwner(str);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- }
- break;
- case INFO_COMMENTS:
- if (cli_state->user_id == ADMIN) {
- str[109] = 0;
- SetComment(str);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- if (i >= INFO_ADDRESS && i <= INFO_COMMENTS) {
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- xReturn = pdFALSE;
- }
- return xReturn;
- }
- static portBASE_TYPE prvTaskRebootCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- static bool start_reboot = true;
- const int8_t *const pcRebootHeader = ( int8_t * )
- "Контроллер будет перезагружен через 1 секунду\r\n";
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- if (cli_state->user_id != ADMIN) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- if (start_reboot) {
- start_reboot = false;
- strcpy( ( char * ) pcWriteBuffer, ( char * ) pcRebootHeader );
- return pdTRUE;
- } else {
- telnet_act = true;
- Reboot(TELNET_ACT);
- return pdFALSE;
- }
- }
- static portBASE_TYPE prvTaskSystimeCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[110];
- uint8_t len;
- uint8_t i;
- uint8_t fail = 0;
- uint16_t temp = 0;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- const int8_t *const pcInfoTableHeader = ( int8_t * )
- "\r\n******Системное время Контроллера******\r\n";
- /* Return the next command help string, before moving the pointer on to
- the next command in the list. */
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
- GetDateStr(str, &len);
- strcat(( char * ) pcWriteBuffer, "Дата:\t\t\t");
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nВремя:\t\t\t");
- GetTimeStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\n");
- /* There are no more commands in the list, so there will be no more
- strings to return after this one and pdFALSE should be returned. */
- xReturn = pdFALSE;
- } else {
- if (cli_state->user_id != ADMIN) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_SYSTIME_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, systime_args_list[i], strlen(systime_args_list[i]) ) == 0
- && xParameterStringLength == strlen(systime_args_list[i])) {
- break;
- }
- }
- if (i != ARG_SYSTIME_ALL) {
- if (sSettings.sSNTP.sntpEnable) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSystymeDenied, strlen( ( char * ) pcSystymeDenied ) );
- return pdFALSE;
- }
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- memset(str, 0, sizeof(str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
- switch (i) {
- case ARG_SYSTIME_DATA:
- if (xParameterStringLength == 10) {
- for (uint8_t j = 0; j < xParameterStringLength; j++) {
- if (j != 4 && j != 7) {
- if (str[j] > 0x39 || str[j] < 0x30) {
- fail = 1;
- }
- } else if (j == 4 || j == 7) {
- if (str[j] != '-') {
- fail = 1;
- }
- }
- }
- if (!fail) {
- temp = 1000 * (str[0] - 0x30) + 100 * (str[1] - 0x30) + 10 * (str[2] - 0x30) + str[3] - 0x30;
- if (temp > 2099 || temp < 2000) {
- fail = 1;
- }
- temp = 0;
- temp = 10 * (str[5] - 0x30) + (str[6] - 0x30);
- if (temp > 12) {
- fail = 1;
- }
- temp = 0;
- temp = 10 * (str[8] - 0x30) + (str[9] - 0x30);
- if (temp > 31) {
- fail = 1;
- }
- }
- } else {
- fail = 1;
- }
- if (!fail) {
- SetDateStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_SYSTIME_TIME:
- if (xParameterStringLength == 5) {
- for (uint8_t j = 0; j < xParameterStringLength; j++) {
- if (j != 2) {
- if (str[j] > 0x39 || str[j] < 0x30) {
- fail = 1;
- }
- } else if (j == 2) {
- if (str[j] != ':') {
- fail = 1;
- }
- }
- }
- if (!fail) {
- temp = 10 * (str[0] - 0x30) + (str[1] - 0x30);
- if (temp > 23) {
- fail = 1;
- }
- temp = 0;
- temp = 10 * (str[3] - 0x30) + (str[4] - 0x30);
- if (temp > 59) {
- fail = 1;
- }
- }
- } else {
- fail = 1;
- }
- if (!fail) {
- SetTimeStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- xReturn = pdFALSE;
- }
- return xReturn;
- }
- /*
- * Implements the ntp command.
- */
- static portBASE_TYPE prvTaskNTPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[110];
- char str_temp[110];
- uint8_t len;
- uint8_t i;
- bool enable_old_sntp;
- const int8_t *const pcInfoTableHeader = ( int8_t * )
- "\r\n************NTP настройки Контроллера************\r\n";
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_NTP_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, ntp_args_list[i], strlen(ntp_args_list[i]) ) == 0
- && xParameterStringLength == strlen(ntp_args_list[i])) {
- break;
- }
- }
- if (cli_state->user_id != ADMIN && i != ARG_NTP_INFO) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- xParameterNumber ++;
- if (pcParameterString == NULL) {
- switch (i) {
- case ARG_NTP_ENABLE:
- enable_old_sntp = sSettings.sSNTP.sntpEnable;
- SetSntpStateStr("1");
- if (sSettings.sSNTP.sntpEnable != enable_old_sntp) {
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- SNTP_Init();
- //vTaskDelay(7000);
- SNTP_Poll();
- }
- break;
- case ARG_NTP_DISABLE:
- enable_old_sntp = sSettings.sSNTP.sntpEnable;
- SetSntpStateStr("0");
- if (sSettings.sSNTP.sntpEnable != enable_old_sntp) {
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- SNTP_Init();
- //vTaskDelay(7000);
- SNTP_Poll();
- }
- break;
- case ARG_NTP_INFO:
- /* Return the next command help string, before moving the pointer on to
- the next command in the list. */
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
- GetSntpStateStrRU(str, &len);
- strcat(( char * ) pcWriteBuffer, "Режим установки времени:\t");
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nIP адрес NTP сервера:\t\t");
- GetSntpServerIpStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nЧасовой пояс:\t\t\t");
- GetSntpTimeZoneStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\nПоследняя дата синхронизации:\t");
- GetSntpLastDataStr(str, &len);
- strncat(( char * ) pcWriteBuffer, str, len);
- strcat(( char * ) pcWriteBuffer, "\r\n");
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- return pdFALSE;
- }
- if (i == ARG_NTP_SET) {
- memset(str, 0, sizeof(str));
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString != NULL) {
- memset(str_temp, 0, sizeof(str_temp));
- if (xParameterStringLength > (int32_t)sizeof(str_temp)) {
- xParameterStringLength = sizeof(str_temp) - 1;
- }
- strncat(str_temp, ( const char * ) pcParameterString, xParameterStringLength);
- if (strncmp(str, "IP", 2) == 0) {
- if (xParameterStringLength <= 15) {
- if (ipaddr_addr(str_temp) != IPADDR_NONE) {
- if (strncmp(str_temp, sSettings.sSNTP.ip, strlen(str_temp)) != 0) {
- SetSntpServerIpStr(str_temp);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- SNTP_Init();
- //vTaskDelay(7000);
- SNTP_Poll();
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else if (strncmp(str, "gmt", 3) == 0) {
- if (xParameterStringLength > 1 && xParameterStringLength < 5) {
- bool fail = false;
- if (str_temp[0] != '-' && str_temp[0] != '+') {
- fail = true;
- }
- if (!isdigit_int(str_temp[1]) && (!isdigit_int(str_temp[2]) && str_temp[2] != '.') && (!isdigit_int(str_temp[3]) &&
- str_temp[3] != '.')) {
- fail = true;
- }
- if (xParameterStringLength == 5) {
- if (!isdigit_int(str_temp[4])) {
- fail = true;
- }
- }
- if (!fail) {
- float value = atof(str_temp);
- if (value >= -12.0 && value <= 12.0) {
- SetSntpTimeZoneStr(str_temp);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- /*
- * Implements the network command.
- */
- static portBASE_TYPE prvTaskNetworkCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[110];
- uint8_t i;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_NETWORK_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, network_args_list[i], strlen(network_args_list[i]) ) == 0
- && xParameterStringLength == strlen(network_args_list[i])) {
- break;
- }
- }
- if (cli_state->user_id != ADMIN && i != ARG_NETWORK_INFO) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- if (i != ARG_NETWORK_ALL && i != ARG_NETWORK_DHCP && i != ARG_NETWORK_INFO) {
- if (sSettings.sWebTempParams.dhcpEnable) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- if (i == ARG_NETWORK_INFO) {
- net_config_param(pcWriteBuffer);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- return pdFALSE;
- }
- memset(str, 0, sizeof(str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
- switch (i) {
- case ARG_NETWORK_DHCP:
- if (strncmp(str, "ENA", 3) == 0) {
- SetUDPDhcpStateStr("True");
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tСохраните конфигурацию сетевых настроек\r\n" );
- } else if (strncmp(str, "DIS", 3) == 0) {
- SetUDPDhcpStateStr("False");
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tСохраните конфигурацию сетевых настроек\r\n" );
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_NETWORK_IP:
- if (xParameterStringLength <= 15) {
- if (ipaddr_addr(str) != IPADDR_NONE) {
- SetIPStr(str);
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tСохраните конфигурацию сетевых настроек\r\n" );
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_NETWORK_GW:
- if (xParameterStringLength <= 15) {
- if (ipaddr_addr(str) != IPADDR_NONE) {
- SetGatewayStr(str);
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tСохраните конфигурацию сетевых настроек\r\n" );
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_NETWORK_MASK:
- if (xParameterStringLength <= 15) {
- if (ipaddr_addr(str) != IPADDR_NONE) {
- SetMaskStr(str);
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tСохраните конфигурацию сетевых настроек\r\n" );
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- /*
- * Implements the snmp command.
- */
- static portBASE_TYPE prvTaskSNMPCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[20];
- char temp_str[20];
- uint8_t i;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_SNMP_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, snmp_args_list[i], strlen(snmp_args_list[i]) ) == 0
- && xParameterStringLength == strlen(snmp_args_list[i])) {
- break;
- }
- }
- if (cli_state->user_id != ADMIN && i != ARG_SNMP_INFO) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- xParameterNumber ++;
- if (pcParameterString == NULL) {
- if (i == ARG_SNMP_INFO) {
- snmp_config_param(pcWriteBuffer);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- return pdFALSE;
- }
- memset(str, 0, sizeof(str));
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
- switch (i) {
- case ARG_SNMP_SERVER:
- if (xParameterStringLength == 1 && isdigit_int(str[0])) {
- int32_t temp = atoi(str);
- if (temp > 0 && temp < 6) {
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString != NULL) {
- memset(str, 0, sizeof(str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
- if (xParameterStringLength <= 15) {
- if (ipaddr_addr(str) != IPADDR_NONE) {
- switch (temp) {
- case 1:
- SetManagerIp(str);
- break;
- case 2:
- SetManagerIp2(str);
- break;
- case 3:
- SetManagerIp3(str);
- break;
- case 4:
- SetManagerIp4(str);
- break;
- case 5:
- SetManagerIp5(str);
- break;
- }
- if (temp > 0 && temp < 6) {
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_SNMP_COMMUNITY:
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString != NULL) {
- memset(temp_str, 0, sizeof(temp_str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
- xParameterStringLength = sizeof(temp_str) - 1;
- }
- strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
- if (control_string_en_digit(temp_str, strlen(temp_str))) {
- if (strncmp(str, "read", 4) == 0) {
- SetReadCommunity(temp_str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else if (strncmp(str, "write", 5) == 0) {
- SetWriteCommunity(temp_str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- /*
- * Implements the akb command.
- */
- static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[110];
- uint8_t i;
- uint8_t fail = 0;
- uint16_t temp = 0;
- float value = 0;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_AKB_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, akb_args_list[i], strlen(akb_args_list[i]) ) == 0
- && xParameterStringLength == strlen(akb_args_list[i])) {
- break;
- }
- }
- if (cli_state->user_id != ADMIN && i != ARG_AKB_INFO) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- if (i == ARG_AKB_INFO) {
- akb_config_param(pcWriteBuffer);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- return pdFALSE;
- }
- memset(str, 0, sizeof(str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 2;
- }
- strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
- #ifdef HARDWARE_BT6709
- if (i != ARG_AKB_DATASET)
- #endif
- {
- for (uint8_t j = 0; j < xParameterStringLength; j ++) {
- if (!isfloatdigit(str[j])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- value = atof(str);
- }
- switch (i) {
- case ARG_AKB_VOLT_CELL_MIN:
- if (value < sSettings.UPS_Setting.Ucellmax && value > MIN_VOLT_CELL_RANGE) {
- SetUPSVoltCellMinStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_AKB_VOLT_CELL_MAX:
- if (value > sSettings.UPS_Setting.Ucellmin && value <= MAX_VOLT_CELL_RANGE) {
- SetUPSVoltCellMaxStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- #ifdef HARDWARE_BT6709
- case ARG_AKB_CAPACITY:
- if (value >= CAPACITY_MIN_RANGE && value <= CAPACITY_MAX_RANGE && (value - (int32_t)value) == 0) {
- SetCapacityNominalAKBStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_AKB_VOLT:
- if (value >= AKB_VOLTAGE_MIN_RANGE && value <= AKB_VOLTAGE_MAX_RANGE && ((int32_t)value % 12) == 0 && (value - (int32_t)value) == 0) {
- SetVoltageAKBNominalStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_AKB_LIFETIME:
- if (value >= LIFETIME_MIN_RANGE && value <= LIFETIME_MAX_RANGE && (value - (int32_t)value) == 0) {
- SetLifeTimeAKBStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_AKB_DATASET:
- if (xParameterStringLength == 10) {
- if (strncmp( str, "0000-00-00", 10) == 0) {
- memset(str, 0, sizeof(str));
- SetDataSetAKBStr(str);
- SETTINGS_Save();
- xReturn = pdFALSE;
- return xReturn;
- }
- for (uint8_t j = 0; j < xParameterStringLength; j++) {
- if (j != 4 && j != 7) {
- if (str[j] > 0x39 || str[j] < 0x30) {
- fail = 1;
- }
- } else if (j == 4 || j == 7) {
- if (str[j] != '-') {
- fail = 1;
- }
- }
- }
- if (!fail) {
- temp = 1000 * (str[0] - 0x30) + 100 * (str[1] - 0x30) + 10 * (str[2] - 0x30) + str[3] - 0x30;
- if (temp > 2099 || temp < 2000) {
- fail = 1;
- }
- temp = 0;
- temp = 10 * (str[5] - 0x30) + (str[6] - 0x30);
- if (temp > 12) {
- fail = 1;
- }
- temp = 0;
- temp = 10 * (str[8] - 0x30) + (str[9] - 0x30);
- if (temp > 31) {
- fail = 1;
- }
- }
- } else {
- fail = 1;
- }
- if (!fail) {
- SetDataSetAKBStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_AKB_UPS_POWER:
- if (value >= UPS_POWER_MIN_RANGE && value <= UPS_POWER_MAX_RANGE && ((int32_t)value % 50) == 0 && (value - (int32_t)value) == 0) {
- SetUPSPowerStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- #endif
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- /*
- * Implements the alarm command.
- */
- static portBASE_TYPE prvTaskAlarmCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[110];
- uint8_t i, j;
- float value = 0;
- uint8_t k;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_ALARM_TYPE_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, type_alarm_args_list[i], strlen(type_alarm_args_list[i]) ) == 0
- && xParameterStringLength == strlen(type_alarm_args_list[i])) {
- break;
- }
- }
- if (cli_state->user_id != ADMIN && i != ARG_ALARM_INFO) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- if (i == ARG_ALARM_INFO) {
- alarm_config_param(pcWriteBuffer);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- return pdFALSE;
- }
- for (j = 0; j < ARG_ALARM_ALL; j ++) {
- if ( strncmp( ( const char * ) pcParameterString, alarm_args_list[j], strlen(alarm_args_list[j]) ) == 0 ) {
- break;
- }
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- memset(str, 0, sizeof(str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 2;
- }
- strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
- switch (i) {
- case ARG_ALARM_TEMP:
- switch (j) {
- case ARG_ALARM_LINE_LOW:
- for (k = 0; k < xParameterStringLength; k ++) {
- if (!isdigit_int(str[k])) {
- if (k == 0 && str[k] == '-') {
- continue;
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- }
- value = atof(str);
- if (value >= MIN_TEMP_MIN_RANGE && value <= MIN_TEMP_MAX_RANGE) {
- SetTemperatureAlarmLowRangeStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_ALARM_LINE_HIGH:
- for (k = 0; k < xParameterStringLength; k ++) {
- if (!isdigit_int(str[k])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- value = atof(str);
- if (value >= MAX_TEMP_MIN_RANGE && value <= MAX_TEMP_MAX_RANGE) {
- SetTemperatureAlarmHighRangeStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_ALARM_LINE_HIST:
- for (k = 0; k < xParameterStringLength; k ++) {
- if (!isfloatdigit(str[k])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- value = atof(str);
- if (value >= HIST_TEMP_MIN_RANGE && value <= HIST_TEMP_MAX_RANGE) {
- SetTemperatureAlarmHisteStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- break;
- case ARG_ALARM_LOAD:
- switch (j) {
- case ARG_ALARM_LINE_LOW:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- case ARG_ALARM_LINE_HIGH:
- for (k = 0; k < xParameterStringLength; k ++) {
- if (!isdigit_int(str[k])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- value = atof(str);
- if (value >= MAX_LOAD_MIN_RANGE && value <= MAX_LOAD_MAX_RANGE) {
- SetLoadAlarmHighRangeStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_ALARM_LINE_HIST:
- for (k = 0; k < xParameterStringLength; k ++) {
- if (!isfloatdigit(str[k])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- value = atof(str);
- if (value >= HIST_LOAD_MIN_RANGE && value <= HIST_LOAD_MAX_RANGE) {
- SetLoadAlarmHistStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- break;
- case ARG_ALARM_VOUT:
- switch (j) {
- case ARG_ALARM_LINE_LOW:
- for (k = 0; k < xParameterStringLength; k ++) {
- if (!isdigit_int(str[k])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- value = atof(str);
- if (value >= MIN_VAC_MIN_RANGE && value <= MIN_VAC_MAX_RANGE) {
- SetVACAlarmLowRangeStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_ALARM_LINE_HIGH:
- for (k = 0; k < xParameterStringLength; k ++) {
- if (!isdigit_int(str[k])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- value = atof(str);
- if (value >= MAX_VAC_MIN_RANGE && value <= MAX_VAC_MAX_RANGE) {
- SetVACAlarmHighRangeStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_ALARM_LINE_HIST:
- for (k = 0; k < xParameterStringLength; k ++) {
- if (!isdigit_int(str[k])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- value = atof(str);
- if (value >= HIST_VAC_MIN_RANGE && value <= HIST_VAC_MAX_RANGE) {
- SetVACAlarmHisteStr(str);
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- #ifdef HARDWARE_BT6709
- /*
- * Implements the notification command.
- */
- static portBASE_TYPE prvTaskNotificationCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[20];
- char temp_str[20];
- uint8_t i;
- char *beginValue;
- uint8_t len;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_NOTIFICATION_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, notification_args_list[i], strlen(notification_args_list[i]) ) == 0
- && xParameterStringLength == strlen(notification_args_list[i])) {
- break;
- }
- }
- if (cli_state->user_id != ADMIN && i != ARG_NOTIFICATION_INFO) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- xParameterNumber ++;
- if (pcParameterString == NULL) {
- if (i == ARG_NOTIFICATION_INFO) {
- notification_param(pcWriteBuffer);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- return pdFALSE;
- }
- memset(str, 0, sizeof(str));
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
- switch (i) {
- case ARG_NOTIFICATION_SET:
- if (xParameterStringLength >= 1) {
- for(uint32_t k = 0; k < xParameterStringLength; k ++) {
- if (!isdigit_int(str[k])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- int32_t temp = atoi(str);
- uint8_t value_notification = 0;
- if (temp > 0 && temp < ALL_TRAPS) {
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString != NULL && xParameterStringLength == 3) {
- if (strncmp(pcParameterString, "ENA", 3) == 0) {
- value_notification = 1;
- SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
- SETTINGS_Save();
- } else if (strncmp(pcParameterString, "DIS", 3) == 0) {
- SetNotificationFlagsStr(&value_notification, (uint8_t)temp);
- SETTINGS_Save();
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- /*
- * Implements the whitelist command.
- */
- static portBASE_TYPE prvTaskWhiteListCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[20];
- char temp_str[20];
- uint8_t i;
- char *beginValue;
- uint8_t len;
- int32_t temp;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_WHITELIST_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, whitelist_args_list[i], strlen(whitelist_args_list[i]) ) == 0
- && xParameterStringLength == strlen(whitelist_args_list[i])) {
- break;
- }
- }
- if (cli_state->user_id != ADMIN && i != ARG_WHITELIST_INFO) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- xParameterNumber ++;
- if (pcParameterString == NULL) {
- if (i == ARG_WHITELIST_INFO) {
- whitelist_config_param(pcWriteBuffer);
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- return pdFALSE;
- }
- memset(str, 0, sizeof(str));
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
- switch (i) {
- case ARG_WHITELIST_RANGE:
- if (xParameterStringLength == 1 && isdigit_int(str[0])) {
- temp = atoi(str);
- if (temp > 0 && temp < 6) {
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString != NULL) {
- memset(str, 0, sizeof(str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
- if (xParameterStringLength <= 19) {
- beginValue = strpbrk(str, "/");
- if (beginValue == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- int32_t mask = atoi(&beginValue[1]);
- len = beginValue - str;
- memset(temp_str, 0, sizeof(temp_str));
- strncpy(temp_str, str, len);
- for (uint8_t j = (len + 1); j < xParameterStringLength; j++) {
- if (!isdigit_int(str[j])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- if (ipaddr_addr(temp_str) != IPADDR_NONE && (mask <= 32 && mask >= 0)) {
- SetWhiteListSTR(str, (temp - 1));
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tСохраните конфигурацию сетевых настроек\r\n" );
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_WHITELIST_RESET:
- if (xParameterStringLength == 1 && isdigit_int(str[0])) {
- temp = atoi(str);
- if (temp > 0 && temp < 6) {
- memset(str, 0, sizeof(str));
- SetWhiteListSTR(str, (temp - 1));
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tСохраните конфигурацию сетевых настроек\r\n" );
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- #endif
- /*
- * Implements the change password command.
- */
- static portBASE_TYPE prvTaskUserCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- uint8_t i;
- char temp_str[MAX_WEB_LOGIN_LEN];
- char WebLogin[MAX_WEB_LOGIN_LEN];
- uint8_t valueLen, user_id;
- const int8_t *const pcChangePWDHeader = ( int8_t * ) "\r\nВведите новый пароль:";
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- if (cli_state->user_id != ADMIN) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_USER_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, user_args_list[i], strlen(user_args_list[i]) ) == 0 ) {
- break;
- }
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (i == ARG_USER_PWD) {
- memset(temp_str, 0, sizeof(temp_str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(temp_str)) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- } else {
- strncat(temp_str, ( const char * ) pcParameterString, strlen(( const char * ) pcParameterString));
- // FIXME proper context
- #if 0
- for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
- GetUserLogin(user_id, WebLogin, &valueLen);
- /* Check login and password */
- if (strncmp(WebLogin, temp_str, MAX_WEB_LOGIN_LEN) == 0) {
- /* Login and pass are valid */
- id_change_pwd = user_id;
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcChangePWDHeader, strlen( ( char * ) pcChangePWDHeader ) );
- telnetState = CLI_CHANGE_PWD;
- break;
- }
- }
- if (telnetState != CLI_CHANGE_PWD) {
- #endif
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- //}
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- /*
- * Implements the config command.
- */
- static portBASE_TYPE prvTaskConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[110];
- uint8_t i;
- static uint8_t config_menu = 0;
- const int8_t *const pcInfoTableHeader = ( int8_t * )
- "\r\n*********Конфигурация Контроллера*********\r\n";
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_CONFIG_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, config_args_list[i], strlen(config_args_list[i]) ) == 0
- && xParameterStringLength == strlen(config_args_list[i])) {
- break;
- }
- }
- if (cli_state->user_id != ADMIN && i != ARG_CONFIG_INFO) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- switch (i) {
- case ARG_CONFIG_INFO:
- switch (config_menu) {
- case PARAM_CONFIG_SNMP:
- /* Return the next command help string, before moving the pointer on to
- the next command in the list. */
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
- snmp_config_param(pcWriteBuffer);
- break;
- #ifdef HARDWARE_BT6707
- case PARAM_CONFIG_INOUTS:
- inouts_config_param(pcWriteBuffer);
- break;
- #endif
- case PARAM_CONFIG_AKB:
- akb_config_param(pcWriteBuffer);
- break;
- case PARAM_CONFIG_ALARM:
- alarm_config_param(pcWriteBuffer);
- break;
- #ifdef HARDWARE_BT6709
- case PARAM_CONFIG_WHITELIST:
- whitelist_config_param(pcWriteBuffer);
- break;
- #endif
- case PARAM_CONFIG_NET:
- net_config_param(pcWriteBuffer);
- break;
- case PARAM_CONFIG_TIME:
- time_config_param(pcWriteBuffer);
- break;
- }
- config_menu ++;
- if (config_menu == PARAM_CONFIG_ALL) {
- config_menu = 0;
- return pdFALSE;
- } else {
- return pdTRUE;
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- return pdFALSE;
- }
- if (i == ARG_CONFIG_LOAD) {
- memset(str, 0, sizeof(str));
- xParameterStringLength = strlen(( const char * ) pcParameterString);
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
- if (xParameterStringLength < 13) {
- if (strncmp(str, "default", 7) == 0) {
- SNMP_SendUserTrap(DEVICE_RESTORED);
- log_event_data(LOG_SYSTEM_DEFCONFIG, name_login_telnet);
- vTaskDelay(500);
- SETTINGS_SetPartDefault();
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tНастройки сброшены к настройкам по умолчанию!\r\n");
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- /*
- * Implements the config command.
- */
- static portBASE_TYPE prvTaskNetConfigCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- portBASE_TYPE xParameterNumber = 1;
- signed portBASE_TYPE xParameterStringLength;
- uint8_t i;
- static start = 0;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- for (i = 0; i < ARG_NETCONFIG_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, netconfig_args_list[i], strlen(netconfig_args_list[i]) ) == 0
- && xParameterStringLength == strlen(netconfig_args_list[i])) {
- break;
- }
- }
- if (cli_state->user_id != ADMIN) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- switch (i) {
- case ARG_NETCONFIG_APPLY:
- if (!start) {
- /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
- if (GetStateWebReinit() == true) {
- start = 1;
- telnet_act = true;
- SetWebReinitFlag(true);
- HTTP_SaveSettings();
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tНастройки сохранены! Контроллер будет перезагружен\r\n\tПосле перезагрузки подтвердите изменения сетевых настроек\r\n");
- return pdTRUE;
- }
- } else {
- telnet_act = true;
- start = 0;
- vTaskDelay(1010);
- Reboot(TELNET_ACT);
- }
- break;
- case ARG_NETCONFIG_CONFIRM:
- telnet_act = true;
- SetWebReinitFlag(false);
- SetConfirmWebParamsFlag();
- strcpy( ( char * ) pcWriteBuffer, "\t\tСетевые настройки подтверждены!\r\n");
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- return pdFALSE;
- }
- /*
- * Implements the history command.
- */
- static portBASE_TYPE prvTaskHistoryCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[110];
- uint8_t i;
- static int16_t num_page = 0;
- static int16_t num_page_temp = 1;
- static bool start = true;
- const int8_t *const pcUPShistoryTableHeader = ( int8_t * )
- "\r\n***********Журнал событий ИБП***********\r\n";
- const int8_t *const pcControllerHistoryTableHeader = ( int8_t * )
- "\r\n***********Журнал событий Контроллера***********\r\n";
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- if ( strncmp( ( const char * ) pcParameterString, "show", xParameterStringLength ) != 0 ) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- for (i = 0; i < ARG_HISTORY_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, history_args_list[i], strlen(history_args_list[i]) ) == 0
- && xParameterStringLength == strlen(history_args_list[i])) {
- break;
- }
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- memset(str, 0, sizeof(str));
- if (xParameterStringLength > 5) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
- if (num_page == 0) {
- num_page = atoi(str);
- if (num_page <= 0) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- switch (i) {
- case ARG_HISTORY_EVENTS:
- if (start) {
- start = false;
- /* Return the next command help string, before moving the pointer on to
- the next command in the list. */
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcControllerHistoryTableHeader,
- strlen( ( char * ) pcControllerHistoryTableHeader ) );
- memset(str, 0, sizeof(str));
- strcat(( char * ) pcWriteBuffer, "\r\n");
- sprintf(str, "Количество страниц журнала: %d\r\n", History_GetPageCount());
- strncat(( char * ) pcWriteBuffer, str, strlen(str));
- strcat(( char * ) pcWriteBuffer, "\r\n");
- if (num_page > History_GetPageCount()) {
- num_page = History_GetPageCount();
- }
- }
- History_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
- num_page --;
- num_page_temp ++;
- if (num_page == 0) {
- num_page = 0;
- num_page_temp = 1;
- start = true;
- xReturn = pdFALSE;
- } else {
- xReturn = pdTRUE;
- }
- break;
- case ARG_HISTORY_UPS:
- if (start) {
- start = false;
- /* Return the next command help string, before moving the pointer on to
- the next command in the list. */
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcUPShistoryTableHeader,
- strlen( ( char * ) pcUPShistoryTableHeader ) );
- memset(str, 0, sizeof(str));
- sprintf(str, "Количество страниц журнала: %d\r\n", LOG_GetPageCount());
- strncat(( char * ) pcWriteBuffer, str, strlen(str));
- if (num_page > LOG_GetPageCount()) {
- num_page = LOG_GetPageCount();
- }
- }
- LOG_GetPage_tabs(( char * ) pcWriteBuffer, num_page_temp);
- num_page --;
- num_page_temp ++;
- if (num_page == 0) {
- num_page = 0;
- num_page_temp = 1;
- start = true;
- xReturn = pdFALSE;
- } else {
- xReturn = pdTRUE;
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- xReturn = pdFALSE;
- break;
- }
- return xReturn;
- }
- /*
- * Implements the sensor info command.
- */
- static portBASE_TYPE prvTaskSensorCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- uint8_t i;
- char str[10];
- char temp_str[10];
- int32_t val = 0, val2 = 0;
- uint8_t fail = 0;
- static uint8_t config_menu = 0;
- uint8_t MAX_CONFIG_PARAM = 0;
- #ifdef HARDWARE_BT6707
- MAX_CONFIG_PARAM = 3;
- #else
- MAX_CONFIG_PARAM = 2;
- #endif
- const int8_t *const pcSensorTableHeader = ( int8_t * )
- "\r\n*********Параметры Контроллера*********\r\n";
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- for (i = 0; i < ARG_SENSOR_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, sensor_args_list[i], strlen(sensor_args_list[i]) ) == 0
- && xParameterStringLength == strlen(sensor_args_list[i])) {
- break;
- }
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- if (pcParameterString == NULL) {
- if (i == ARG_SENSOR_INFO) {
- switch (config_menu) {
- case 0:
- /* Return the next command help string, before moving the pointer on to
- the next command in the list. */
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcSensorTableHeader, strlen( ( char * ) pcSensorTableHeader ) );
- ups_sensor_param(pcWriteBuffer);
- break;
- case 1:
- ups_sensor_akb_param(pcWriteBuffer);
- break;
- #ifdef HARDWARE_BT6707
- case 2:
- inouts_sensor_param(pcWriteBuffer);
- break;
- #endif
- }
- config_menu ++;
- if (config_menu == MAX_CONFIG_PARAM) {
- config_menu = 0;
- return pdFALSE;
- } else {
- return pdTRUE;
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- } else {
- switch (i) {
- #ifdef HARDWARE_BT6707
- case ARG_SENSOR_SETUP:
- if (cli_state->user_id != ADMIN) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- memset(str, 0, sizeof(str));
- if (xParameterStringLength > (int32_t)sizeof(str)) {
- xParameterStringLength = sizeof(str) - 1;
- }
- strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
- if (xParameterStringLength < 3) {
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- memset(temp_str, 0, sizeof(str));
- if (xParameterStringLength > 1) {
- fail = 1;
- break;
- }
- strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
- if (!isdigit_int(temp_str[0])) {
- fail = 1;
- break;
- }
- val = atoi(temp_str);
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- memset(temp_str, 0, sizeof(str));
- if (xParameterStringLength > 1) {
- fail = 1;
- break;
- }
- strncat(temp_str, ( const char * ) pcParameterString, xParameterStringLength);
- if (!isdigit_int(temp_str[0])) {
- fail = 1;
- break;
- }
- if (strncmp(str, "DI", 2) == 0) {
- if (val != 1) {
- fail = 1;
- break;
- }
- val2 = atoi(temp_str);
- if (val2 < 0 || val2 > 1) {
- fail = 1;
- break;
- }
- SetDINTypeActStr(temp_str, (val - 1));
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- } else if (strncmp(str, "DO", 2) == 0) {
- if (val < 1 || val > 3) {
- fail = 1;
- break;
- }
- val2 = atoi(temp_str);
- if (val2 < 1 || val2 > 5) {
- fail = 1;
- break;
- }
- SetROTypeActStr(temp_str, (val - 1));
- SETTINGS_Save();
- log_event_data(LOG_SETTING_SAVE, name_login_telnet);
- }
- } else {
- fail = 1;
- }
- break;
- #endif
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- }
- if (fail) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- /*
- * Implements the firmware download http command.
- */
- static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen,
- const int8_t *pcCommandString )
- {
- static bool start_update = true;
- const int8_t *const pcUploadHeader = ( int8_t * )
- "Контроллер переводится в режим загрузчика\r\n";
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- if (cli_state->user_id != ADMIN) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- if (start_update) {
- start_update = false;
- strcpy( ( char * ) pcWriteBuffer, ( char * ) pcUploadHeader );
- return pdTRUE;
- } else {
- telnet_act = true;
- HTTP_StartResetTask(true);
- return pdFALSE;
- }
- }
- /*
- * Implements the ups command.
- */
- static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
- {
- int8_t *pcParameterString;
- signed portBASE_TYPE xParameterStringLength, xReturn;
- portBASE_TYPE xParameterNumber = 1;
- char str[110];
- int32_t val = 0;
- float val_float = 0;
- int8_t res = 0;
- uint8_t i;
- ( void ) pcCommandString;
- ( void ) xWriteBufferLen;
- configASSERT( pcWriteBuffer );
- memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
- if (cli_state->user_id != ADMIN && i != ARG_CONFIG_INFO) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
- return pdFALSE;
- }
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- for (i = 0; i < ARG_UPS_ALL; i ++) {
- if ( strncmp( ( const char * ) pcParameterString, ups_args_list[i], strlen(ups_args_list[i]) ) == 0
- && xParameterStringLength == strlen(ups_args_list[i])) {
- break;
- }
- }
- xParameterNumber ++;
- /* Obtain the parameter string. */
- pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
- (
- pcCommandString, /* The command string itself. */
- xParameterNumber, /* Return the next parameter. */
- &xParameterStringLength /* Store the parameter string length. */
- );
- memset(str, 0, sizeof(str));
- if (xParameterStringLength > 3) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
- switch (i) {
- case ARG_UPS_BATTEST:
- for (uint8_t j = 0; j < xParameterStringLength; j++) {
- if (!isdigit_int(str[j])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- val = atoi(str);
- if (val == 0) {
- res = ups_metac_service_pdu(ups_cancel_test);
- set_act_source(TELNET_ACT);
- if (res == 1) {
- log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
- strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" принята ИБП!\r\n");
- } else {
- strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Останов теста\" отклонена ИБП!\r\n");
- }
- } else if (val > 0 && val < 100) {
- TimeParam = val;
- res = ups_metac_service_pdu(ups_test_time);
- if (res == 1) {
- strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
- } else {
- strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
- }
- } else if (val == 100) {
- res = ups_metac_service_pdu(ups_test_10sec);
- if (res == 1) {
- strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
- } else {
- strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
- }
- } else if (val == 999) {
- res = ups_metac_service_pdu(ups_test_low_bat);
- if (res == 1) {
- strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" принята ИБП!\r\n");
- } else {
- strcpy( ( char * ) pcWriteBuffer, "\t\tКоманда \"Запуск теста\" отклонена ИБП!\r\n");
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- case ARG_UPS_SHUTDOWN:
- for (uint8_t j = 0; j < xParameterStringLength; j++) {
- if (!isfloatdigit(str[j])) {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- return pdFALSE;
- }
- }
- val_float = atof(str);
- if (val_float == 0) {
- res = ups_metac_service_pdu(ups_cancel_shut_down);
- if (res == 1) {
- log_event_data(LOG_SHUTDOWN_UPS, "Администратор (Останов)");
- strcpy( ( char * ) pcWriteBuffer, "\t\t\tВыключение нагрузки ИБП отменено!\r\n");
- } else {
- strcpy( ( char * ) pcWriteBuffer,
- "\t\tВыключение нагрузки ИБП не удалось отменить!\r\n");
- }
- } else if (val_float > 0 && val_float <= 10) {
- TimeParamFloat = val_float;
- res = ups_metac_service_pdu(ups_shutdown);
- if (res == 1) {
- log_event_data(LOG_SHUTDOWN_UPS, "Администратор");
- strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП!\r\n");
- } else {
- strcpy( ( char * ) pcWriteBuffer, "\t\tОтключение нагрузки ИБП не удалось!\r\n");
- }
- } else {
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- }
- break;
- default:
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
- break;
- }
- xReturn = pdFALSE;
- return xReturn;
- }
- /*-----------------------------------------------------------*/
|