|
@@ -0,0 +1,1714 @@
|
|
|
+/*
|
|
|
+ * 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 "telnet_server.h"
|
|
|
+
|
|
|
+
|
|
|
+#define in_range_digit(c, lo, up) ((uint8_t)c >= lo && (uint8_t)c <= up)
|
|
|
+#define isdigit_int(c) in_range_digit(c, '0', '9')
|
|
|
+#define isfloatdigit(c) (isdigit_int(c) || in_range_digit(c, '.', '.'))
|
|
|
+
|
|
|
+extern state_telnet_server_t telnetState;
|
|
|
+extern uint8_t id_change_pwd;
|
|
|
+
|
|
|
+
|
|
|
+const int8_t * const pcInvalidCommand = ( int8_t * ) "Command invalid. Enter \"help\" to view a list of available commands.\r\n\r\n";
|
|
|
+const int8_t * const pcPermissionDenied = ( int8_t * ) "Permission denied!\r\n\r\n";
|
|
|
+
|
|
|
+const char* info_args_list[] =
|
|
|
+{
|
|
|
+ "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* ntp_args_list[] =
|
|
|
+{
|
|
|
+ "ENA",
|
|
|
+ "DIS",
|
|
|
+ "info",
|
|
|
+ "set",
|
|
|
+};
|
|
|
+
|
|
|
+const char* config_args_list[] =
|
|
|
+{
|
|
|
+ "info",
|
|
|
+ "load",
|
|
|
+ "apply",
|
|
|
+ "confirm",
|
|
|
+};
|
|
|
+
|
|
|
+const char* history_args_list[] =
|
|
|
+{
|
|
|
+ "EVENTS",
|
|
|
+ "UPS",
|
|
|
+};
|
|
|
+
|
|
|
+const char* sensor_args_list[] =
|
|
|
+{
|
|
|
+ "info",
|
|
|
+};
|
|
|
+
|
|
|
+const char* user_args_list[] =
|
|
|
+{
|
|
|
+ "passwd",
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Общая структура настроек
|
|
|
+ */
|
|
|
+extern SETTINGS_t sSettings;
|
|
|
+
|
|
|
+extern user_level_t telnet_code_auth;
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the controller's information command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskInfoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the reboot command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskRebootCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the systime command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskSystimeCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the ntp command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskNTPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the network command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskNetworkCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the snmp command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskSNMPCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the change password command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskUserCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the config command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskConfigCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the history command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskHistoryCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the sensor info command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskSensorCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the firmware download http command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskUploadCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
|
|
+
|
|
|
+/*
|
|
|
+ * Implements the ups command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskUPSCommand( 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 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 "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"
|
|
|
+ "\tconfig apply: применение конфигурации\r\n"
|
|
|
+ "\tconfig confirm: подтверждение конфигурации\r\n",
|
|
|
+ prvTaskConfigCommand, /* 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. */
|
|
|
+ 2 /* 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 info", /* The command string to type. */
|
|
|
+ ( const int8_t * const ) "\tsensor info: вывод параметров системы\r\n",
|
|
|
+ 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 dowmload http", /* The command string to type. */
|
|
|
+ ( const int8_t * const ) "\tfirmware dowmload 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. */
|
|
|
+};
|
|
|
+
|
|
|
+/*-----------------------------------------------------------*/
|
|
|
+
|
|
|
+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( &prvUserCommandDefinition );
|
|
|
+ FreeRTOS_CLIRegisterCommand( &prvConfigCommandDefinition );
|
|
|
+ FreeRTOS_CLIRegisterCommand( &prvHistoryCommandDefinition );
|
|
|
+ FreeRTOS_CLIRegisterCommand( &prvSensorCommandDefinition );
|
|
|
+ FreeRTOS_CLIRegisterCommand( &prvUploadCommandDefinition );
|
|
|
+ FreeRTOS_CLIRegisterCommand( &prvUPSCommandDefinition );
|
|
|
+}
|
|
|
+/*-----------------------------------------------------------*/
|
|
|
+
|
|
|
+static portBASE_TYPE prvTaskInfoCommand( 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;
|
|
|
+
|
|
|
+ ( 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";
|
|
|
+ /* 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\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);
|
|
|
+
|
|
|
+ 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(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], xParameterStringLength ) == 0 ){
|
|
|
+ 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));
|
|
|
+ switch(i){
|
|
|
+ case INFO_ADDRESS:
|
|
|
+ if(telnet_code_auth == ADMIN)
|
|
|
+ SetLocation(str);
|
|
|
+ else
|
|
|
+ strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
|
|
|
+ break;
|
|
|
+ case INFO_OWNER:
|
|
|
+ if(telnet_code_auth == ADMIN)
|
|
|
+ SetOwner(str);
|
|
|
+ else
|
|
|
+ strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
|
|
|
+ break;
|
|
|
+ case INFO_COMMENTS:
|
|
|
+ if(telnet_code_auth == ADMIN)
|
|
|
+ SetComment(str);
|
|
|
+ else
|
|
|
+ strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPermissionDenied, strlen( ( char * ) pcPermissionDenied ) );
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ xReturn = pdFALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ return xReturn;
|
|
|
+}
|
|
|
+
|
|
|
+static portBASE_TYPE prvTaskRebootCommand( 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(telnet_code_auth != 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();
|
|
|
+ return pdFALSE;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static portBASE_TYPE prvTaskSystimeCommand( 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(telnet_code_auth != 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], xParameterStringLength ) == 0 ){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(i != ARG_SYSTIME_ALL){
|
|
|
+ if(sSettings.sSNTP.sntpEnable){
|
|
|
+ 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){
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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( 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], xParameterStringLength ) == 0 ){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(telnet_code_auth != 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){
|
|
|
+ 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){
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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( 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], xParameterStringLength ) == 0 ){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(telnet_code_auth != 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");
|
|
|
+ else if(strncmp(str, "DIS", 3) == 0)
|
|
|
+ SetUDPDhcpStateStr("False");
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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( 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], xParameterStringLength ) == 0 ){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(telnet_code_auth != 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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(strncmp(str, "read", 4) == 0){
|
|
|
+ SetReadCommunity(temp_str);
|
|
|
+ }
|
|
|
+ else if(strncmp(str, "write", 5) == 0)
|
|
|
+ SetWriteCommunity(temp_str);
|
|
|
+ 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 change password command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskUserCommand( 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(telnet_code_auth != 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], xParameterStringLength ) == 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));
|
|
|
+ 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 = TELNET_CHANGE_PWD;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(telnetState != TELNET_CHANGE_PWD){
|
|
|
+ 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( 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], xParameterStringLength ) == 0 ){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(telnet_code_auth != 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 0:
|
|
|
+ /* 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;
|
|
|
+ case 1:
|
|
|
+ inouts_config_param(pcWriteBuffer);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ net_config_param(pcWriteBuffer);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ time_config_param(pcWriteBuffer);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ config_menu ++;
|
|
|
+ if(config_menu == 4){
|
|
|
+ config_menu = 0;
|
|
|
+ return pdFALSE;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return pdTRUE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ARG_CONFIG_APPLY:
|
|
|
+ SETTINGS_Save();
|
|
|
+ log_event_data(LOG_SETTING_SAVE, name_login_telnet);
|
|
|
+ strcpy( ( char * ) pcWriteBuffer, "\t\tНастройки сохранены!\r\n");
|
|
|
+ break;
|
|
|
+ case ARG_CONFIG_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;
|
|
|
+ }
|
|
|
+ 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 history command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskHistoryCommand( 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i = 0; i < ARG_HISTORY_ALL; i ++){
|
|
|
+ if( strncmp( ( const char * ) pcParameterString, history_args_list[i], xParameterStringLength ) == 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. */
|
|
|
+ );
|
|
|
+ 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( 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;
|
|
|
+ static uint8_t config_menu = 0;
|
|
|
+
|
|
|
+ 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], xParameterStringLength ) == 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){
|
|
|
+ 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;
|
|
|
+ case 2:
|
|
|
+ inouts_sensor_param(pcWriteBuffer);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ config_menu ++;
|
|
|
+ if(config_menu == 3){
|
|
|
+ config_menu = 0;
|
|
|
+ return pdFALSE;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return pdTRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 firmware download http command.
|
|
|
+ */
|
|
|
+static portBASE_TYPE prvTaskUploadCommand( 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(telnet_code_auth != 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( 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(telnet_code_auth != 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], xParameterStringLength ) == 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. */
|
|
|
+ );
|
|
|
+ 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);
|
|
|
+ if(res == 1){
|
|
|
+ log_event_data(LOG_TEST_UPS, "Администратор (Останов)");
|
|
|
+ strcpy( ( char * ) pcWriteBuffer, "\t\ttТест остановлен!\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){
|
|
|
+ log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
|
|
|
+ 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){
|
|
|
+ log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
|
|
|
+ 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){
|
|
|
+ log_event_data(LOG_TEST_UPS, "Администратор (Запущен)");
|
|
|
+ strcpy( ( char * ) pcWriteBuffer, "\t\ttТест запущен!\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\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;
|
|
|
+}
|
|
|
+
|
|
|
+/*-----------------------------------------------------------*/
|
|
|
+
|