ソースを参照

add telnet server

balbekova 7 年 前
コミット
f02a58c0af

+ 3 - 0
modules/Ethernet/lwipopts.h

@@ -106,6 +106,9 @@ a lot of data that needs to be copied, this should be set high. */
 #define MEMP_NUM_NETBUF                 7
 
 
+#define TCP_LISTEN_BACKLOG              1
+
+
 /* ---------- TCP options ---------- */
 #define LWIP_TCP                1
 #define TCP_TTL                 255

+ 25 - 4
modules/HTTP_Server/http_server.c

@@ -909,6 +909,9 @@ void HTTP_SetSettings(char *buf, uint16_t lenBuf)
   /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
   if (GetStateWebReinit() == true)
   {	
+#ifdef HARDWARE_BT6706
+  telnet_act = false;
+#endif
 	SetWebReinitFlag(true);
 	HTTP_SaveSettings();
     /* Блокируем управление ключем на тау секунд*/
@@ -916,7 +919,9 @@ void HTTP_SetSettings(char *buf, uint16_t lenBuf)
     vTaskDelay(1010);
     Reboot();
   }	
-  
+#ifdef HARDWARE_BT6706
+  telnet_act = false;
+#endif
   HTTP_SaveSettings();
 }
 
@@ -952,7 +957,10 @@ void HTTP_SetInfo(char *buf, uint16_t lenBuf)
   url_decode(str, sizeof(str), value);
   SetComment(str);
   memset(value, 0, len);
- 
+
+#ifdef HARDWARE_BT6706
+  telnet_act = false;
+#endif
   HTTP_SaveSettings();
 }
 
@@ -1071,7 +1079,9 @@ void HTTP_ConfirmBootPwd(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t
   uint8_t valueLen;
   
   memset(value, 0, 20);
-  
+#ifdef HARDWARE_BT6706
+  telnet_act = false;
+#endif
   /* Запускаем задачу отложенной перезагрузки. Контроллер должен успеть
      отправить ответ серверу о статусе пароля */
   HTTP_StartResetTask(true); 
@@ -1448,7 +1458,9 @@ int HTTP_ChangeUserPwd(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *l
 				 {
 
 					 memcpy(sSettings.sAuth[user_id].password, password, 11);
-
+#ifdef HARDWARE_BT6706
+  telnet_act = false;
+#endif
 					 HTTP_SaveSettings();
 					 log_event_data(LOG_PSW_CHANGE, name_login);
 					 strcat(bufOut, "Пароль успешно изменён");
@@ -1839,6 +1851,9 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen)
     /* Сброс настроек и сохранине */
     else if (strncmp(receiveBuf, "GET /reset.cgi", 14) == 0)
     {
+#ifdef HARDWARE_BT6706
+  telnet_act = false;
+#endif
         HTTP_ResetSettings();
         HTTP_SaveSettings();
     
@@ -1849,11 +1864,17 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen)
     /* Перезагрузка контроллера */
     else if (strncmp(receiveBuf, "GET /reboot.cgi", 15) == 0)
     {
+#ifdef HARDWARE_BT6706
+    	telnet_act = false;
+#endif
         HTTP_Reboot();
     }
     /* Подтверждение новых сетевых настроек */
     else if (strncmp(receiveBuf, "GET /confirm.cgi", 16) == 0)
     {
+#ifdef HARDWARE_BT6706
+    	  telnet_act = false;
+#endif
         SetWebReinitFlag(false);
         SetConfirmWebParamsFlag();
     

+ 12 - 2
modules/HTTP_Server/web_params_api.c

@@ -463,7 +463,12 @@ void HTTP_SaveSettings(void)
 //  taskENTER_CRITICAL();
   
   SETTINGS_Save();
-  
+
+#ifdef HARDWARE_BT6706
+	  if(telnet_act)
+		  log_event_data(LOG_SETTING_SAVE, name_login_telnet);
+	  else
+#endif
   log_event_data(LOG_SETTING_SAVE, name_login);
 
 //  taskEXIT_CRITICAL();
@@ -510,7 +515,12 @@ void vTaskReboot(void * pvParameters)
 	if (mode)
 	{
 	  SNMP_SendUserTrap(FW_VERSION_UPDATE);
-	  log_event_data(LOG_UPDATE_SOFT, name_login);
+#ifdef HARDWARE_BT6706
+	  if(telnet_act)
+		  log_event_data(LOG_UPDATE_SOFT, name_login_telnet);
+	  else
+#endif
+		  log_event_data(LOG_UPDATE_SOFT, name_login);
 	  SetLoadMode();
 	  HTTP_SaveSettings();
       vTaskDelay(2000);

+ 3 - 1
modules/Makefile

@@ -97,8 +97,10 @@ CSRC += $(wildcard ../thirdparty/FreeRTOS/portable/MemMang/heap_4.c)
 ifeq ($(HARDWARE), bt6702) 	
    CSRC += $(wildcard HTTP_Server/my_ssl_server.c)
 endif
-ifeq ($(HARDWARE), bt6706)   
+ifeq ($(HARDWARE), bt6706)  
+      INCLUDES += -ITelnet_Server 
       CSRC += $(wildcard HTTP_Server/http_server.c)
+      CSRC += $(wildcard Telnet_Server/*.c)
 endif
     CSRC += $(wildcard HTTP_Server/trap_params.c)
     CSRC += $(wildcard HTTP_Server/web_params_api.c)

+ 1714 - 0
modules/Telnet_Server/CLI_Commands.c

@@ -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;
+}
+
+/*-----------------------------------------------------------*/
+

+ 81 - 0
modules/Telnet_Server/CLI_Commands.h

@@ -0,0 +1,81 @@
+/*
+ * CLI_Commands.h
+ *
+ *  Created on: 29.11.2017
+ *      Author: balbekova
+ */
+
+#ifndef CLI_COMMANDS_H_
+#define CLI_COMMANDS_H_
+
+
+typedef enum{
+	INFO_ADDRESS = 0,
+	INFO_OWNER,
+	INFO_COMMENTS,
+	INFO_ALL_ARGS
+}info_args_t;
+
+typedef enum{
+	ARG_UPS_BATTEST = 0,
+	ARG_UPS_SHUTDOWN,
+	ARG_UPS_ALL
+}ups_args_t;
+
+typedef enum{
+	ARG_SYSTIME_DATA = 0,
+	ARG_SYSTIME_TIME,
+	ARG_SYSTIME_ALL
+}systime_args_t;
+
+typedef enum{
+	ARG_NETWORK_INFO = 0,
+	ARG_NETWORK_DHCP,
+	ARG_NETWORK_IP,
+	ARG_NETWORK_GW,
+	ARG_NETWORK_MASK,
+	ARG_NETWORK_ALL
+}network_args_t;
+
+typedef enum{
+	ARG_SNMP_INFO = 0,
+	ARG_SNMP_SERVER,
+	ARG_SNMP_COMMUNITY,
+	ARG_SNMP_ALL
+}snmp_args_t;
+
+typedef enum{
+	ARG_NTP_ENABLE = 0,
+	ARG_NTP_DISABLE,
+	ARG_NTP_INFO,
+	ARG_NTP_SET,
+	ARG_NTP_ALL
+}ntp_args_t;
+
+typedef enum{
+	ARG_CONFIG_INFO = 0,
+	ARG_CONFIG_LOAD,
+	ARG_CONFIG_APPLY,
+	ARG_CONFIG_CONFIRM,
+	ARG_CONFIG_ALL
+}config_args_t;
+
+typedef enum{
+	ARG_HISTORY_EVENTS = 0,
+	ARG_HISTORY_UPS,
+	ARG_HISTORY_ALL
+}history_args_t;
+
+typedef enum{
+	ARG_SENSOR_INFO = 0,
+	ARG_SENSOR_ALL
+}sensor_args_t;
+
+typedef enum{
+	ARG_USER_PWD = 0,
+	ARG_USER_ALL
+}user_args_t;
+
+void vRegisterCLICommands(void);
+
+#endif /* CLI_COMMANDS_H_ */

+ 300 - 0
modules/Telnet_Server/CLI_Parameters.c

@@ -0,0 +1,300 @@
+/*
+ * CLI_Parameters.c
+ *
+ *  Created on: 04.12.2017
+ *      Author: balbekova
+ */
+
+#include <stdint.h>
+#include <string.h>
+#ifdef PRINTF_STDLIB
+#include <stdio.h>
+#endif
+#ifdef PRINTF_CUSTOM
+#include "tinystdio.h"
+#endif
+
+#include "CLI_Parameters.h"
+#include "parameters.h"
+#include "settings_api.h"
+
+
+/**
+  * @brief  Общая структура настроек
+  */
+extern SETTINGS_t sSettings;
+
+
+//Настройки SNMP
+void snmp_config_param(int8_t *buf)
+{
+	char str[20];
+	uint8_t len = 0;
+
+
+	const int8_t * const pcInfoTableHeader = ( int8_t * ) "\r\n***********SNMP настройки Контроллера***********\r\n";
+	/* Return the next command help string, before moving the pointer on to
+	the next command in the list. */
+	strncpy( ( char * ) buf, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
+
+	GetManagerIp(str, &len);
+	strcat(( char * ) buf, "Ceрвер 1:\t\t\t");
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nСервер 2:\t\t\t");
+	GetManagerIp2(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nСервер 3:\t\t\t");
+	GetManagerIp3(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nСервер 4:\t\t\t");
+	GetManagerIp4(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nСервер 5:\t\t\t");
+	GetManagerIp5(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nRead community:\t\t\t");
+	GetReadCommunity(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nWrite community:\t\t");
+	GetWriteCommunity(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\n");
+}
+
+//Настройки сухих контактов
+void inouts_config_param(int8_t *buf)
+{
+	char str[20];
+	char str_temp[20];
+	uint8_t len = 0;
+
+	const int8_t * const pcInOutsTableHeader = ( int8_t * ) "\r\n*********Настройки сухих контактов Контроллера*********\r\n";
+	const int8_t * const pcDryInsTableHeader = ( int8_t * ) "Дискретные входы\r\n";
+	const int8_t * const pcDryInsTableHeader2 = ( int8_t * ) "\r\nКонтакт\t\tНормальное состояние\r\n";
+	const int8_t * const pcRelaysTableHeader = ( int8_t * ) "Релейные выходы\r\n";
+	const int8_t * const pcRelaysTableHeader2 = ( int8_t * ) "\r\nКонтакт\t\tИсточник\r\n";
+	const int8_t * const pcSharedTableHeader = ( int8_t * ) "------------+--------------------------------------------\r\n";
+
+
+	/* Return the next command help string, before moving the pointer on to
+	the next command in the list. */
+	strncpy( ( char * ) buf, ( const char * ) pcInOutsTableHeader, strlen( ( char * ) pcInOutsTableHeader ) );
+
+	strncat( ( char * ) buf, ( const char * ) pcDryInsTableHeader, strlen( ( char * ) pcDryInsTableHeader ) );
+	strncat( ( char * ) buf, ( const char * ) pcDryInsTableHeader2, strlen( ( char * ) pcDryInsTableHeader2 ) );
+	strncat( ( char * ) buf, ( const char * ) pcSharedTableHeader, strlen( ( char * ) pcSharedTableHeader ) );
+
+	GetDINTypeActStr(str, &len, 0);
+	strcat(( char * ) buf, "1:\t\t");
+	switch(str[0]){
+	case '0':
+		strcat(( char * ) buf, "Разомкнут\r\n");
+		break;
+	case '1':
+		strcat(( char * ) buf, "Замкнут\r\n");
+		break;
+	}
+	strncat( ( char * ) buf, ( const char * ) pcSharedTableHeader, strlen( ( char * ) pcSharedTableHeader ) );
+	strcat(( char * ) buf, "\r\n");
+
+	strncat( ( char * ) buf, ( const char * ) pcRelaysTableHeader, strlen( ( char * ) pcRelaysTableHeader ) );
+	strncat( ( char * ) buf, ( const char * ) pcRelaysTableHeader2, strlen( ( char * ) pcRelaysTableHeader2 ) );
+	strncat( ( char * ) buf, ( const char * ) pcSharedTableHeader, strlen( ( char * ) pcSharedTableHeader ) );
+
+	for(uint8_t i = 0; i < OUTPUTS_TOTAL_COUNT; i++){
+		GetROTypeActStr(str, &len, i);
+		memset(str_temp, 0, strlen(str_temp));
+		sprintf(str_temp, "%d:\t\t", i);
+		strncat(( char * ) buf, str_temp, strlen(str_temp));
+		switch(str[0]){
+		case '0':
+			strcat(( char * ) buf, "Наличие сети\r\n");
+			break;
+		case '1':
+			strcat(( char * ) buf, "Наличие выходного напряжения\r\n");
+			break;
+		case '2':
+			strcat(( char * ) buf, "Разряд АКБ\r\n");
+			break;
+		case '3':
+			strcat(( char * ) buf, "Отключение АКБ\r\n");
+			break;
+		case '4':
+			strcat(( char * ) buf, "SNMP SET\r\n");
+			break;
+		}
+		strcat(( char * ) buf, "\r\n");
+	}
+	strncat( ( char * ) buf, ( const char * ) pcSharedTableHeader, strlen( ( char * ) pcSharedTableHeader ) );
+}
+
+//Сетевые настройки
+void net_config_param(int8_t *buf)
+{
+	char str[20];
+	uint8_t len = 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 * ) buf, ( const char * ) pcInfoTableHeader, strlen( ( char * ) pcInfoTableHeader ) );
+
+	GetDhcpStateStrRu(str, &len);
+	strcat(( char * ) buf, "DHCP:\t\t\t\t");
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nIP адрес:\t\t\t");
+	GetIpStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nАдрес шлюза:\t\t\t");
+	GetGatewayStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nАдрес маски подсети:\t\t");
+	GetMaskStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+
+	strcat(( char * ) buf, "\r\n");
+}
+
+//Настройки времени
+void time_config_param(int8_t *buf)
+{
+	char str[20];
+	uint8_t len = 0;
+
+	const int8_t * const pcTimeTableHeader = ( 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 * ) buf, ( const char * ) pcTimeTableHeader, strlen( ( char * ) pcTimeTableHeader ) );
+
+	GetSntpStateStrRU(str, &len);
+	strcat(( char * ) buf, "Режим установки времени:\t");
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nЧасовой пояс:\t\t\t");
+	GetSntpTimeZoneStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	if(sSettings.sSNTP.sntpEnable){
+		strcat(( char * ) buf, "\r\nIP адрес NTP сервера:\t\t");
+		GetSntpServerIpStr(str, &len);
+		strncat(( char * ) buf, str, len);
+
+		strcat(( char * ) buf, "\r\nПоследняя дата синхронизации:\t");
+		GetSntpLastDataStr(str, &len);
+		strncat(( char * ) buf, str, len);
+
+	}
+	else{
+		GetDateStr(str, &len);
+		strcat(( char * ) buf, "Дата:\t\t\t");
+		strncat(( char * ) buf, str, len);
+
+		strcat(( char * ) buf, "\r\nВремя:\t\t\t");
+		GetTimeStr(str, &len);
+		strncat(( char * ) buf, str, len);
+	}
+
+	strcat(( char * ) buf, "\r\n");
+}
+
+//Параметры ИБП
+void ups_sensor_param(int8_t *buf)
+{
+	char str[20];
+	uint8_t len = 0;
+
+
+	const int8_t * const pcUPSInfoTableHeader = ( int8_t * ) "\r\n***********Параметры источника питания***********\r\n";
+	/* Return the next command help string, before moving the pointer on to
+	the next command in the list. */
+	strncat( ( char * ) buf, ( const char * ) pcUPSInfoTableHeader, strlen( ( char * ) pcUPSInfoTableHeader ) );
+
+	GetInputVoltageStr(str, &len);
+	strcat(( char * ) buf, "Входное напряжение (VAC):\t\t");
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nВыходное напряжение (VAC):\t\t");
+	GetOutputVoltageStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nВходная частота:\t\t\t");
+	GetInputFreqStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nНагрузка:\t\t\t\t");
+	GetPowerStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nТекущий режим:\t\t\t\t");
+	GetUPSModeStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\n");
+}
+
+//Параметры аккумуляторных батарей
+void ups_sensor_akb_param(int8_t *buf)
+{
+	char str[20];
+	uint8_t len = 0;
+
+	const int8_t * const pcAKBInfoTableHeader = ( 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 * ) buf, ( const char * ) pcAKBInfoTableHeader, strlen( ( char * ) pcAKBInfoTableHeader ) );
+
+	GetBatCapacityStr(str, &len);
+	strcat(( char * ) buf, "Емкость батареи:\t\t\t");
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nВнутренняя температура:\t\t\t");
+	GetInternalTempStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nОставшееся время работы:\t\t");
+	GetRuntimeStr(str, &len);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\n");
+}
+
+//Параметры сухих контактов
+void inouts_sensor_param(int8_t *buf)
+{
+	char str[20];
+	uint8_t len = 0;
+
+	const int8_t * const pcInOutsInfoTableHeader = ( 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 * ) buf, ( const char * ) pcInOutsInfoTableHeader, strlen( ( char * ) pcInOutsInfoTableHeader ) );
+
+	GetDIN0StatusStrRU(str, &len);
+	strcat(( char * ) buf, "Дискретный вход:\t\t\t");
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nРелейный выход 1:\t\t\t");
+	GetDOUTStatusStrRU(str, &len, 0);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nРелейный выход 2:\t\t\t");
+	GetDOUTStatusStrRU(str, &len, 1);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\nРелейный выход 3:\t\t\t");
+	GetDOUTStatusStrRU(str, &len, 2);
+	strncat(( char * ) buf, str, len);
+
+	strcat(( char * ) buf, "\r\n");
+}

+ 33 - 0
modules/Telnet_Server/CLI_Parameters.h

@@ -0,0 +1,33 @@
+/*
+ * CLI_Parameters.h
+ *
+ *  Created on: 04.12.2017
+ *      Author: balbekova
+ */
+
+#ifndef CLI_PARAMETERS_H_
+#define CLI_PARAMETERS_H_
+
+
+//Настройки SNMP
+void snmp_config_param(int8_t *buf);
+
+//Настройки сухих контактов
+void inouts_config_param(int8_t *buf);
+
+//Сетевые настройки
+void net_config_param(int8_t *buf);
+
+//Настройки времени
+void time_config_param(int8_t *buf);
+
+//Параметры ИБП
+void ups_sensor_param(int8_t *buf);
+
+//Параметры аккумуляторных батарей
+void ups_sensor_akb_param(int8_t *buf);
+
+//Параметры сухих контактов
+void inouts_sensor_param(int8_t *buf);
+
+#endif /* CLI_PARAMETERS_H_ */

+ 340 - 0
modules/Telnet_Server/FreeRTOS_CLI.c

@@ -0,0 +1,340 @@
+/*
+ * FreeRTOS+CLI V1.0.1 (C) 2012 Real Time Engineers ltd.
+ *
+ * FreeRTOS+CLI is an add-on component to FreeRTOS.  It is not, in itself, part
+ * of the FreeRTOS kernel.  FreeRTOS+CLI is licensed separately from FreeRTOS,
+ * and uses a different license to FreeRTOS.  FreeRTOS+CLI uses a dual license
+ * model, information on which is provided below:
+ *
+ * - Open source licensing -
+ * FreeRTOS+CLI is a free download and may be used, modified and distributed
+ * without charge provided the user adheres to version two of the GNU General
+ * Public license (GPL) and does not remove the copyright notice or this text.
+ * The GPL V2 text is available on the gnu.org web site, and on the following
+ * URL: http://www.FreeRTOS.org/gpl-2.0.txt
+ *
+ * - Commercial licensing -
+ * Businesses and individuals who wish to incorporate FreeRTOS+CLI into
+ * proprietary software for redistribution in any form must first obtain a
+ * (very) low cost commercial license - and in-so-doing support the maintenance,
+ * support and further development of the FreeRTOS+CLI product.  Commercial
+ * licenses can be obtained from http://shop.freertos.org and do not require any
+ * source files to be changed.
+ *
+ * FreeRTOS+CLI is distributed in the hope that it will be useful.  You cannot
+ * use FreeRTOS+CLI unless you agree that you use the software 'as is'.
+ * FreeRTOS+CLI is provided WITHOUT ANY WARRANTY; without even the implied
+ * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they
+ * implied, expressed, or statutory.
+ *
+ * 1 tab == 4 spaces!
+ *
+ * http://www.FreeRTOS.org
+ * http://www.FreeRTOS.org/FreeRTOS-Plus
+ *
+ */
+
+/* Standard includes. */
+#include <string.h>
+#include <stdint.h>
+
+/* FreeRTOS includes. */
+#include "FreeRTOS.h"
+#include "task.h"
+
+/* Utils includes. */
+#include "FreeRTOS_CLI.h"
+
+
+typedef struct xCOMMAND_INPUT_LIST
+{
+	const CLI_Command_Definition_t *pxCommandLineDefinition;
+	struct xCOMMAND_INPUT_LIST *pxNext;
+} CLI_Definition_List_Item_t;
+
+/*
+ * The callback function that is executed when "help" is entered.  This is the
+ * only default command that is always present.
+ */
+static portBASE_TYPE prvHelpCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
+
+/* The definition of the "help" command.  This command is always at the front
+of the list of registered commands. */
+static const CLI_Command_Definition_t xHelpCommand =
+{
+	( const int8_t * const ) "help",
+	( const int8_t * const ) "\r\n\thelp: вывод краткого описания поддерживаемых команд\r\n",
+	prvHelpCommand,
+	0
+};
+
+/* The definition of the list of commands.  Commands that are registered are
+added to this list. */
+static CLI_Definition_List_Item_t xRegisteredCommands =
+{
+	&xHelpCommand,	/* The first command in the list is always the help command, defined in this file. */
+	NULL,
+};
+
+/* A buffer into which command outputs can be written is declared here, rather
+than in the command console implementation, to allow multiple command consoles
+to share the same buffer.  For example, an application may allow access to the
+command interpreter by UART and by Ethernet.  Sharing a buffer is done purely
+to save RAM.  Note, however, that the command console itself is not re-entrant,
+so only one command interpreter interface can be used at any one time.  For that
+reason, no attempt at providing mutual exclusion to the cOutputBuffer array is
+attempted. */
+static int8_t cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
+
+/*-----------------------------------------------------------*/
+
+portBASE_TYPE FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
+{
+static CLI_Definition_List_Item_t *pxLastCommandInList = &xRegisteredCommands;
+CLI_Definition_List_Item_t *pxNewListItem;
+portBASE_TYPE xReturn = pdFAIL;
+
+	/* Check the parameter is not NULL. */
+	configASSERT( pxCommandToRegister );
+
+	/* Create a new list item that will reference the command being registered. */
+	pxNewListItem = ( CLI_Definition_List_Item_t * ) pvPortMalloc( sizeof( CLI_Definition_List_Item_t ) );
+	configASSERT( pxNewListItem );
+
+	if( pxNewListItem != NULL )
+	{
+		taskENTER_CRITICAL();
+		{
+			/* Reference the command being registered from the newly created
+			list item. */
+			pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;
+
+			/* The new list item will get added to the end of the list, so
+			pxNext has nowhere to point. */
+			pxNewListItem->pxNext = NULL;
+
+			/* Add the newly created list item to the end of the already existing
+			list. */
+			pxLastCommandInList->pxNext = pxNewListItem;
+
+			/* Set the end of list marker to the new list item. */
+			pxLastCommandInList = pxNewListItem;
+		}
+		taskEXIT_CRITICAL();
+
+		xReturn = pdPASS;
+	}
+
+	return xReturn;
+}
+/*-----------------------------------------------------------*/
+
+portBASE_TYPE FreeRTOS_CLIProcessCommand( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer, size_t xWriteBufferLen  )
+{
+	static const CLI_Definition_List_Item_t *pxCommand = NULL;
+	portBASE_TYPE xReturn = pdTRUE;
+	const int8_t *pcRegisteredCommandString;
+	size_t xCommandStringLength;
+
+	/* Note:  This function is not re-entrant.  It must not be called from more
+	thank one task. */
+
+	if( pxCommand == NULL )
+	{
+		/* Search for the command string in the list of registered commands. */
+		for( pxCommand = &xRegisteredCommands; pxCommand != NULL; pxCommand = pxCommand->pxNext )
+		{
+			pcRegisteredCommandString = pxCommand->pxCommandLineDefinition->pcCommand;
+			xCommandStringLength = strlen( ( const char * ) pcRegisteredCommandString );
+
+			/* To ensure the string lengths match exactly, so as not to pick up
+			a sub-string of a longer command, check the byte after the expected
+			end of the string is either the end of the string or a space before
+			a parameter. */
+			if( ( pcCommandInput[ xCommandStringLength ] == ' ' ) || ( pcCommandInput[ xCommandStringLength ] == 0x00 ) )
+			{
+				if( strncmp( ( const char * ) pcCommandInput, ( const char * ) pcRegisteredCommandString, xCommandStringLength ) == 0 )
+				{
+					/* The command has been found.  Check it has the expected
+					number of parameters.  If cExpectedNumberOfParameters is -1,
+					then there could be a variable number of parameters and no
+					check is made. */
+					if( pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters >= 0 )
+					{
+						if( prvGetNumberOfParameters( pcCommandInput ) != pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters )
+						{
+							xReturn = pdFALSE;
+						}
+					}
+
+					break;
+				}
+			}
+		}
+	}
+
+	if( ( pxCommand != NULL ) && ( xReturn == pdFALSE ) )
+	{
+		/* The command was found, but the number of parameters with the command
+		was incorrect. */
+		strncpy( ( char * ) pcWriteBuffer, "Incorrect command parameter(s).  Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );
+		pxCommand = NULL;
+	}
+	else if( pxCommand != NULL )
+	{
+		/* Call the callback function that is registered to this command. */
+		xReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter( pcWriteBuffer, xWriteBufferLen, pcCommandInput );
+
+		/* If xReturn is pdFALSE, then no further strings will be returned
+		after this one, and	pxCommand can be reset to NULL ready to search
+		for the next entered command. */
+		if( xReturn == pdFALSE )
+		{
+			pxCommand = NULL;
+		}
+	}
+	else
+	{
+		/* pxCommand was NULL, the command was not found. */
+		strncpy( ( char * ) pcWriteBuffer, ( const char * const ) "Command not recognised.  Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );
+		xReturn = pdFALSE;
+	}
+
+	return xReturn;
+}
+/*-----------------------------------------------------------*/
+
+int8_t *FreeRTOS_CLIGetOutputBuffer( void )
+{
+	return cOutputBuffer;
+}
+/*-----------------------------------------------------------*/
+
+const int8_t *FreeRTOS_CLIGetParameter( const int8_t *pcCommandString, unsigned portBASE_TYPE uxWantedParameter, portBASE_TYPE *pxParameterStringLength )
+{
+unsigned portBASE_TYPE uxParametersFound = 0;
+const int8_t *pcReturn = NULL;
+
+	*pxParameterStringLength = 0;
+
+	while( uxParametersFound < uxWantedParameter )
+	{
+		/* Index the character pointer past the current word.  If this is the start
+		of the command string then the first word is the command itself. */
+		while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )
+		{
+			pcCommandString++;
+		}
+
+		/* Find the start of the next string. */
+		while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) == ' ' ) )
+		{
+			pcCommandString++;
+		}
+
+		/* Was a string found? */
+		if( *pcCommandString != 0x00 )
+		{
+			/* Is this the start of the required parameter? */
+			uxParametersFound++;
+
+			if( uxParametersFound == uxWantedParameter )
+			{
+				/* How long is the parameter? */
+				pcReturn = pcCommandString;
+				while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )
+				{
+					( *pxParameterStringLength )++;
+					pcCommandString++;
+				}
+
+				if( *pxParameterStringLength == 0 )
+				{
+					pcReturn = NULL;
+				}
+
+				break;
+			}
+		}
+		else
+		{
+			break;
+		}
+	}
+
+	return pcReturn;
+}
+/*-----------------------------------------------------------*/
+
+static portBASE_TYPE prvHelpCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
+{
+	static const CLI_Definition_List_Item_t * pxCommand = NULL;
+	signed portBASE_TYPE xReturn;
+
+	( void ) pcCommandString;
+	//configASSERT( pcWriteBuffer );
+
+	if( pxCommand == NULL )
+	{
+		/* Reset the pxCommand pointer back to the start of the list. */
+		pxCommand = &xRegisteredCommands;
+	}
+	memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
+
+	/* Return the next command help string, before moving the pointer on to
+	the next command in the list. */
+	strncpy( ( char * ) pcWriteBuffer, ( const char * ) pxCommand->pxCommandLineDefinition->pcHelpString, xWriteBufferLen );
+	pxCommand = pxCommand->pxNext;
+
+	if( pxCommand == NULL )
+	{
+		/* 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
+	{
+		xReturn = pdTRUE;
+	}
+
+	return xReturn;
+}
+/*-----------------------------------------------------------*/
+
+int8_t prvGetNumberOfParameters( const int8_t * pcCommandString )
+{
+int8_t cParameters = 0;
+portBASE_TYPE xLastCharacterWasSpace = pdFALSE;
+
+	/* Count the number of space delimited words in pcCommandString. */
+	while( *pcCommandString != 0x00 )
+	{
+		if( ( *pcCommandString ) == ' ' )
+		{
+			if( xLastCharacterWasSpace != pdTRUE )
+			{
+				cParameters++;
+				xLastCharacterWasSpace = pdTRUE;
+			}
+		}
+		else
+		{
+			xLastCharacterWasSpace = pdFALSE;
+		}
+
+		pcCommandString++;
+	}
+
+	/* If the command string ended with spaces, then there will have been too
+	many parameters counted. */
+	if( xLastCharacterWasSpace == pdTRUE )
+	{
+		cParameters--;
+	}
+
+	/* The value returned is one less than the number of space delimited words,
+	as the first word should be the command itself. */
+	return cParameters;
+}
+

+ 120 - 0
modules/Telnet_Server/FreeRTOS_CLI.h

@@ -0,0 +1,120 @@
+/*
+ * FreeRTOS+CLI V1.0.1 (C) 2012 Real Time Engineers ltd.
+ *
+ * FreeRTOS+CLI is an add-on component to FreeRTOS.  It is not, in itself, part 
+ * of the FreeRTOS kernel.  FreeRTOS+CLI is licensed separately from FreeRTOS, 
+ * and uses a different license to FreeRTOS.  FreeRTOS+CLI uses a dual license 
+ * model, information on which is provided below:
+ *
+ * - Open source licensing -
+ * FreeRTOS+CLI is a free download and may be used, modified and distributed
+ * without charge provided the user adheres to version two of the GNU General
+ * Public license (GPL) and does not remove the copyright notice or this text.
+ * The GPL V2 text is available on the gnu.org web site, and on the following
+ * URL: http://www.FreeRTOS.org/gpl-2.0.txt
+ *
+ * - Commercial licensing -
+ * Businesses and individuals who wish to incorporate FreeRTOS+CLI into
+ * proprietary software for redistribution in any form must first obtain a 
+ * (very) low cost commercial license - and in-so-doing support the maintenance, 
+ * support and further development of the FreeRTOS+CLI product.  Commercial 
+ * licenses can be obtained from http://shop.freertos.org and do not require any 
+ * source files to be changed.
+ *
+ * FreeRTOS+CLI is distributed in the hope that it will be useful.  You cannot
+ * use FreeRTOS+CLI unless you agree that you use the software 'as is'.
+ * FreeRTOS+CLI is provided WITHOUT ANY WARRANTY; without even the implied
+ * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they
+ * implied, expressed, or statutory.
+ *
+ * 1 tab == 4 spaces!
+ *
+ * http://www.FreeRTOS.org
+ * http://www.FreeRTOS.org/FreeRTOS-Plus
+ *
+ */
+
+#ifndef COMMAND_INTERPRETER_H
+#define COMMAND_INTERPRETER_H
+
+/* The prototype to which callback functions used to process command line
+commands must comply.  pcWriteBuffer is a buffer into which the output from 
+executing the command can be written, xWriteBufferLen is the length, in bytes of 
+the pcWriteBuffer buffer, and pcCommandString is the entire string as input by
+the user (from which parameters can be extracted).*/
+typedef portBASE_TYPE (*pdCOMMAND_LINE_CALLBACK)( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t * pcCommandString );
+
+/* The structure that defines command line commands.  A command line command
+should be defined by declaring a const structure of this type. */
+typedef struct xCOMMAND_LINE_INPUT
+{
+	const int8_t * const pcCommand;				/* The command that causes pxCommandInterpreter to be executed.  For example "help".  Must be all lower case. */
+	const int8_t * const pcHelpString;			/* String that describes how to use the command.  Should start with the command itself, and end with "\r\n".  For example "help: Returns a list of all the commands\r\n". */
+	const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter;	/* A pointer to the callback function that will return the output generated by the command. */
+	int8_t cExpectedNumberOfParameters;			/* Commands expect a fixed number of parameters, which may be zero. */
+} CLI_Command_Definition_t;
+
+/* For backward compatibility. */
+#define xCommandLineInput CLI_Command_Definition_t
+
+/*
+ * Register the command passed in using the pxCommandToRegister parameter.
+ * Registering a command adds the command to the list of commands that are
+ * handled by the command interpreter.  Once a command has been registered it
+ * can be executed from the command line.
+ */
+portBASE_TYPE FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister );
+
+/*
+ * Runs the command interpreter for the command string "pcCommandInput".  Any
+ * output generated by running the command will be placed into pcWriteBuffer.
+ * xWriteBufferLen must indicate the size, in bytes, of the buffer pointed to
+ * by pcWriteBuffer.
+ *
+ * FreeRTOS_CLIProcessCommand should be called repeatedly until it returns pdFALSE.
+ *
+ * pcCmdIntProcessCommand is not reentrant.  It must not be called from more
+ * than one task - or at least - by more than one task at a time.
+ */
+portBASE_TYPE FreeRTOS_CLIProcessCommand( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer, size_t xWriteBufferLen  );
+
+/*-----------------------------------------------------------*/
+
+/*
+ * A buffer into which command outputs can be written is declared in the
+ * main command interpreter, rather than in the command console implementation,
+ * to allow application that provide access to the command console via multiple
+ * interfaces to share a buffer, and therefore save RAM.  Note, however, that
+ * the command interpreter itself is not re-entrant, so only one command
+ * console interface can be used at any one time.  For that reason, no attempt
+ * is made to provide any mutual exclusion mechanism on the output buffer.
+ *
+ * FreeRTOS_CLIGetOutputBuffer() returns the address of the output buffer.
+ */
+int8_t *FreeRTOS_CLIGetOutputBuffer( void );
+
+/*
+ * Return a pointer to the xParameterNumber'th word in pcCommandString.
+ */
+const int8_t *FreeRTOS_CLIGetParameter( const int8_t *pcCommandString, unsigned portBASE_TYPE uxWantedParameter, portBASE_TYPE *pxParameterStringLength );
+
+/*
+ * Return the number of parameters that follow the command name.
+ */
+int8_t prvGetNumberOfParameters( const int8_t * pcCommandString );
+
+#endif /* COMMAND_INTERPRETER_H */
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 418 - 0
modules/Telnet_Server/telnet_server.c

@@ -0,0 +1,418 @@
+/*
+ * telnet_server.c
+ *
+ *  Created on: 24.11.2017
+ *      Author: balbekova
+ */
+
+/* Standard includes. */
+#include <string.h>
+
+/* lwIP core includes */
+#include "lwip/opt.h"
+#include "lwip/sockets.h"
+
+/* FreeRTOS includes. */
+#include "FreeRTOS.h"
+#include "task.h"
+#include "fr_timers.h"
+
+/* Utils includes. */
+#include "FreeRTOS_CLI.h"
+#include "CLI_Commands.h"
+#include "telnet_server.h"
+#include "settings_api.h"
+#include "parameters.h"
+#include "control_symbol.h"
+#include "log.h"
+#include "web_params_api.h"
+
+
+
+/* Dimensions the buffer into which input characters are placed. */
+#define cmdMAX_INPUT_SIZE	144
+/* Repeat Login timeout, 1 seconds */
+#define REPEAT_SENSOR_INFO_TIME		configTICK_RATE_HZ*1*1
+
+static portBASE_TYPE FreeRTOS_CLIAuthProcess( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer  );
+static portBASE_TYPE FreeRTOS_ChangePWDProcess( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer  );
+void SensorInfoTimerCallback(TimerHandle_t pxTimer);
+
+TimerHandle_t RepeatSensorInfoTimer;
+
+state_telnet_server_t telnetState = TELNET_AUTH;
+uint8_t id_change_pwd = 0;
+user_level_t telnet_code_auth = USER;
+
+static int32_t lClientFd;
+static int8_t *pcOutputString;
+
+/**
+  * @brief  Общая структура настроек
+  */
+extern SETTINGS_t sSettings;
+
+/*-----------------------------------------------------------*/
+
+void vBasicSocketsCommandInterpreterTask( void *pvParameters )
+{
+int32_t lSocket, lBytes, lAddrLen = sizeof( struct sockaddr_in );
+struct sockaddr_in sLocalAddr;
+struct sockaddr_in client_addr;
+const int8_t * const pcWelcomeMessage = ( const int8_t * ) "BT6706 command server - connection accepted.\r\nlogin:";
+static const int8_t * const pcEndOfCommandOutputString = ( int8_t * ) "\r\n[Press ENTER to execute the previous command again]\r\n>";
+int8_t cInChar, cInputIndex;
+static int8_t cInputString[ cmdMAX_INPUT_SIZE ] = { 0 }, cLastInputString[ cmdMAX_INPUT_SIZE ] = { 0 };
+portBASE_TYPE xReturned;
+
+	( void ) pvParameters;
+
+	lSocket = lwip_socket( AF_INET, SOCK_STREAM, 0 );
+
+	if( lSocket >= 0 )
+	{
+		/* Obtain the address of the output buffer.  Note there is no mutual
+		exclusion on this buffer as it is assumed only one command console
+		interface will be used at any one time. */
+		pcOutputString = FreeRTOS_CLIGetOutputBuffer();
+
+		memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
+		sLocalAddr.sin_family = AF_INET;
+		sLocalAddr.sin_len = sizeof(sLocalAddr);
+		sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+		sLocalAddr.sin_port = ntohs( ( ( uint16_t ) 23 ) );
+
+		if( lwip_bind( lSocket, ( struct sockaddr *) &sLocalAddr, sizeof( sLocalAddr ) ) < 0 )
+		{
+			lwip_close( lSocket );
+			vTaskDelete( NULL );
+		}
+
+		if( lwip_listen( lSocket, 20 ) != 0 )
+		{
+			lwip_close( lSocket );
+			vTaskDelete( NULL );
+		}
+
+		/* Ensure the input string starts clear. */
+		cInputString[ 0 ] = 0;
+		cLastInputString[ 0 ] = 0;
+
+		for( ;; )
+		{
+			lClientFd = lwip_accept( lSocket, ( struct sockaddr * ) &client_addr, ( u32_t * ) &lAddrLen );
+
+			if( lClientFd > 0L )
+			{
+				lBytes = lwip_recv( lClientFd, cInputString, 27, 0 );
+				telnetState = TELNET_AUTH;
+				lwip_send( lClientFd, pcWelcomeMessage, strlen( ( const char * ) pcWelcomeMessage ), 0 );
+
+				cInputIndex = 0;
+				memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
+
+				do
+				{
+					lBytes = lwip_recv( lClientFd, &cInChar, sizeof( cInChar ), 0 );
+
+					if( lBytes > 0L )
+					{
+						if( cInChar == '\n' )
+						{
+							switch(telnetState){
+							case TELNET_AUTH:
+								if(FreeRTOS_CLIAuthProcess(cInputString, pcOutputString)){
+									lwip_send( lClientFd, pcOutputString, strlen( ( const char * ) pcOutputString ), 0 );
+									cInputIndex = 0;
+									memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
+								}
+								else{
+									/* Set lBytes to 0 to close the connection. */
+									lBytes = 0L;
+								}
+								break;
+							case TELNET_CMD:
+								/* The input string has been terminated.  Was the
+								input a quit command? */
+								if( strcmp( "quit", ( const char * ) cInputString ) == 0 )
+								{
+									/* Set lBytes to 0 to close the connection. */
+									lBytes = 0L;
+								}
+								else
+								{
+									/* The input string was not a quit command.
+									Pass the string to the command interpreter. */
+
+									/* See if the command is empty, indicating that the last command is
+									to be executed again. */
+									if( cInputIndex == 0 )
+									{
+										strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
+									}
+
+									/* Transmit a line separator, just to make the
+									output easier to read. */
+									lwip_send( lClientFd, "\r\n", strlen( "\r\n" ), 0 );
+
+									do
+									{
+										/* Ensure there is not a string lingering in
+										the output buffer. */
+										pcOutputString[ 0 ] = 0x00;
+										xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
+										lwip_send( lClientFd, pcOutputString, strlen( ( const char * ) pcOutputString ), 0 );
+
+									} while( xReturned != pdFALSE );
+
+									if( strcmp( "sensor info", ( const char * ) cInputString ) == 0 ){
+										strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
+										cInputIndex = 0;
+										memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
+										xTimerStart(RepeatSensorInfoTimer, 0);
+									}
+									else{
+
+										/* All the strings generated by the input
+										command have been sent.  Clear the input
+										string ready to receive the next command.
+										Remember the command that was just processed
+										first in case it is to be processed again. */
+										strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
+										cInputIndex = 0;
+										memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
+										if(telnetState != TELNET_CHANGE_PWD)
+										lwip_send( lClientFd, pcEndOfCommandOutputString, strlen( ( const char * ) pcEndOfCommandOutputString ), 0 );
+									}
+								}
+								break;
+							case TELNET_CHANGE_PWD:
+								FreeRTOS_ChangePWDProcess(cInputString, pcOutputString);
+								lwip_send( lClientFd, pcOutputString, strlen( ( const char * ) pcOutputString ), 0 );
+								cInputIndex = 0;
+								memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
+								break;
+
+							}
+
+						}
+						else
+						{
+							if( cInChar == '\r' )
+							{
+								/* Ignore the character. */
+							}
+							else if( cInChar == '\b' )
+							{
+								/* Backspace was pressed.  Erase the last
+								character in the string - if any. */
+								if( cInputIndex > 0 )
+								{
+									cInputIndex--;
+									cInputString[ cInputIndex ] = '\0';
+								}
+							}
+							else
+							{
+								/* A character was entered.  Add it to the string
+								entered so far.  When a \n is entered the complete
+								string will be passed to the command interpreter. */
+								if( cInputIndex < cmdMAX_INPUT_SIZE )
+								{
+									cInputString[ cInputIndex ] = cInChar;
+									cInputIndex++;
+								}
+								if( strcmp( "\377\364\377\375\006", ( const char * ) cInputString ) == 0 ){
+									xTimerStop(RepeatSensorInfoTimer, 0);
+									cInputIndex = 0;
+									memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
+									cInputString[0] = 255;
+									cInputString[1] = 251;
+									cInputString[2] = 6;
+									cInputString[3] = 255;
+									cInputString[4] = 242;
+									//if(telnetState != TELNET_CHANGE_PWD)
+										//lwip_send( lClientFd, pcEndOfCommandOutputString, strlen( ( const char * ) pcEndOfCommandOutputString ), 0 );
+									lwip_send( lClientFd, cInputString, strlen( ( const char * ) cInputString ), 0 );
+									memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
+									if(telnetState != TELNET_CHANGE_PWD)
+										lwip_send( lClientFd, pcEndOfCommandOutputString, strlen( ( const char * ) pcEndOfCommandOutputString ), 0 );
+								}
+							}
+						}
+					}
+
+				} while( lBytes > 0L );
+
+				 lwip_close( lClientFd );
+			}
+		}
+	}
+
+	/* Will only get here if a listening socket could not be created. */
+	vTaskDelete( NULL );
+}
+
+void telnet_server_init(void) {
+	vRegisterCLICommands();
+	xTaskCreate(vBasicSocketsCommandInterpreterTask, ( char * ) "vBasicSocketsCommandInterpreterTask", 8*configMINIMAL_STACK_SIZE , NULL, tskIDLE_PRIORITY, NULL);
+	 RepeatSensorInfoTimer = xTimerCreate("SensorInfoTmr", REPEAT_SENSOR_INFO_TIME, pdFALSE, ( void * ) 0, SensorInfoTimerCallback);
+}
+
+void SensorInfoTimerCallback(TimerHandle_t pxTimer) {
+	portBASE_TYPE xReturned = pdTRUE;
+
+	do
+	{
+		/* Ensure there is not a string lingering in
+		the output buffer. */
+		pcOutputString[ 0 ] = 0x00;
+		xReturned = FreeRTOS_CLIProcessCommand( "sensor info", pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
+		lwip_send( lClientFd, pcOutputString, strlen( ( const char * ) pcOutputString ), 0 );
+
+	} while( xReturned != pdFALSE );
+	xTimerStart(RepeatSensorInfoTimer, 0);
+}
+
+static portBASE_TYPE FreeRTOS_CLIAuthProcess( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer  )
+{
+	portBASE_TYPE xReturn = pdTRUE;
+	uint32_t len;
+	uint8_t valueLen, user_id;
+	char WebPassword[MAX_WEB_PASSWD_LEN];
+	char WebLogin[MAX_WEB_LOGIN_LEN];
+	static uint8_t login_err = 0;
+	static uint8_t telnet_state_auth = 0;
+	static char login[ cmdMAX_INPUT_SIZE ] = { 0 };
+	char password[ cmdMAX_INPUT_SIZE ] = { 0 };
+	const int8_t * const pcPSWHeader = ( int8_t * ) "\r\npassword:";
+	const int8_t * const pcLoginHeader = ( int8_t * ) "\r\nlogin:";
+
+	memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
+
+	if(telnet_state_auth == 0){
+		telnet_state_auth = 1;
+		memset(login, 0, cmdMAX_INPUT_SIZE);
+		len = strlen((char *)pcCommandInput);
+		strncpy(login, (char *)pcCommandInput, len);
+		strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPSWHeader, strlen( ( char * ) pcPSWHeader ) );
+		xReturn = pdTRUE;
+	}
+	else{
+		memset(name_login_telnet, 0, 50);
+		telnet_state_auth = 0;
+		memset(password, 0, cmdMAX_INPUT_SIZE);
+		len = strlen((char *)pcCommandInput);
+		strncpy(password, (char *)pcCommandInput, len);
+		for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
+
+			GetUserLogin(user_id, WebLogin, &valueLen);
+			GetUserPassword(user_id, WebPassword, &valueLen);
+
+			/* Check login and password */
+			if ((strncmp(WebLogin, login, MAX_WEB_LOGIN_LEN) == 0) &&
+				(strncmp(WebPassword, password, MAX_WEB_PASSWD_LEN) == 0)) {
+
+				/* Login and pass are valid */
+				telnet_code_auth = user_id;
+				login_err = 0;
+				strcpy( ( char * ) pcWriteBuffer, "\r\nАвторизация успешно пройдена\r\n>" );
+				telnetState = TELNET_CMD;
+				xReturn = pdTRUE;
+				break;
+			}
+			else{
+				xReturn = pdFALSE;
+			}
+		}
+		if(xReturn == pdFALSE){
+			if(login_err < 4){
+				login_err ++;
+				strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка авторизации\r\n" );
+				strncat( ( char * ) pcWriteBuffer, ( const char * ) pcLoginHeader, strlen( ( char * ) pcLoginHeader ) );
+				xReturn = pdTRUE;
+			}
+			else{
+				login_err = 0;
+				xReturn = pdFALSE;
+			}
+		}
+		switch (user_id) {
+			  case 0:
+				  snprintf(name_login_telnet, sizeof(name_login_telnet), "Администратор");
+				  break;
+			  case 1:
+				  snprintf(name_login_telnet, sizeof(name_login_telnet), "Пользователь");
+				  break;
+			  default:
+				  break;
+		  }
+
+			log_event_data(LOG_LOGIN_TELNET, name_login_telnet);
+	}
+
+
+	return xReturn;
+}
+
+static portBASE_TYPE FreeRTOS_ChangePWDProcess( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer  )
+{
+	portBASE_TYPE xReturn = pdTRUE;
+	uint32_t len;
+	static uint8_t telnet_state_change_pwd = 0;
+	static char password[ MAX_WEB_LOGIN_LEN ] = { 0 };
+	char password2[ MAX_WEB_LOGIN_LEN ] = { 0 };
+	const int8_t * const pcNewPSWHeader = ( int8_t * ) "\r\nВведите повторно новый пароль:";
+
+	memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
+
+	if(telnet_state_change_pwd == 0){
+		telnet_state_change_pwd = 1;
+		memset(password, 0, MAX_WEB_LOGIN_LEN);
+		len = strlen((char *)pcCommandInput);
+		if(len >= MAX_WEB_LOGIN_LEN){
+			strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка при вводе нового пароля\r\n>" );
+			telnetState = TELNET_CMD;
+		}
+		else{
+			if(!control_string_en_digit((char *)pcCommandInput, len)){
+				strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка при вводе нового пароля\r\n>" );
+				telnetState = TELNET_CMD;
+			}
+			else{
+				strncpy(password, (char *)pcCommandInput, len);
+				strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcNewPSWHeader, strlen( ( char * ) pcNewPSWHeader ) );
+			}
+		}
+	}
+	else{
+		telnet_state_change_pwd = 0;
+		memset(password2, 0, cmdMAX_INPUT_SIZE);
+		len = strlen((char *)pcCommandInput);
+		if(len >= MAX_WEB_LOGIN_LEN){
+			strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка при вводе нового пароля\r\n>" );
+			telnetState = TELNET_CMD;
+		}
+		else{
+			strncpy(password2, (char *)pcCommandInput, len);
+
+			if (strncmp(password, password2, MAX_WEB_PASSWD_LEN) == 0) {
+				memcpy(sSettings.sAuth[id_change_pwd].password, password, 11);
+				telnet_act = true;
+				 HTTP_SaveSettings();
+				 log_event_data(LOG_PSW_CHANGE, name_login_telnet);
+				strcpy( ( char * ) pcWriteBuffer, "\r\nПароль успешно изменен\r\n>" );
+				telnetState = TELNET_CMD;
+				xReturn = pdTRUE;
+			}
+			else{
+				strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка при вводе нового пароля\r\n>" );
+				telnetState = TELNET_CMD;
+			}
+		}
+	}
+
+
+	return xReturn;
+}
+

+ 20 - 0
modules/Telnet_Server/telnet_server.h

@@ -0,0 +1,20 @@
+/*
+ * telnet_server.h
+ *
+ *  Created on: 24.11.2017
+ *      Author: balbekova
+ */
+
+#ifndef TELNET_SERVER_H_
+#define TELNET_SERVER_H_
+
+typedef enum{
+	TELNET_AUTH = 0,
+	TELNET_CMD,
+	TELNET_CHANGE_PWD
+}state_telnet_server_t;
+
+
+void telnet_server_init(void);
+
+#endif /* TELNET_SERVER_H_ */

+ 24 - 0
modules/common/control_symbol.c

@@ -0,0 +1,24 @@
+/*
+ * control_symbol.c
+ *
+ *  Created on: 06.12.2017
+ *      Author: balbekova
+ */
+#include <stdint.h>
+#include <stdbool.h>
+
+
+bool control_string_en_digit(char *str, uint8_t len)
+{
+	uint8_t i;
+	bool fail = true;
+
+	for(i = 0; i < len; i++){
+		if(str[i] < 0x21 || str[i] > 0x7e){
+			fail = false;
+			break;
+		}
+	}
+	return fail;
+}
+

+ 14 - 0
modules/common/control_symbol.h

@@ -0,0 +1,14 @@
+/*
+ * control_symbol.h
+ *
+ *  Created on: 06.12.2017
+ *      Author: balbekova
+ */
+
+#ifndef CONTROL_SYMBOL_H_
+#define CONTROL_SYMBOL_H_
+
+bool control_string_en_digit(char *str, uint8_t len);
+
+
+#endif /* CONTROL_SYMBOL_H_ */

+ 6 - 1
modules/common/hal.c

@@ -19,7 +19,12 @@
 void Reboot(void) {
 #ifndef BT6702_SERVICE
 	SNMP_SendUserTrap(DEVICE_REBOOTED);
-	log_event_data(LOG_SYSTEM_BOOT, name_login);
+#ifdef HARDWARE_BT6706
+	  if(telnet_act)
+		  log_event_data(LOG_SYSTEM_BOOT, name_login_telnet);
+	  else
+#endif
+		  log_event_data(LOG_SYSTEM_BOOT, name_login);
 
 	vTaskDelay(1010);
 	LOG_Disable();

+ 79 - 0
modules/log/log.c

@@ -12,6 +12,9 @@
 char logFileBuf[FILE_BUF_MAX_LEN];
 
 char name_login[50];
+char name_login_telnet[50];
+
+bool telnet_act = false;
 
 const char* logsStrShortRu[] =
 {
@@ -21,6 +24,9 @@ const char* logsStrShortRu[] =
     "Включение",
     "Смена пароля",
     "Сохранение настроек",
+#ifdef HARDWARE_BT6706
+    "Авторизация (Telnet)",
+#endif
     "Авторизация",
     "Тест ИБП",
     "Откл. нагрузки ИБП",
@@ -328,6 +334,36 @@ uint32_t LOG_GetTotalSTRCount(void)
 	return ringfs_count_estimate(&fs);
 }
 
+void LOG_GetPage_tabs(char *str, uint32_t page)
+{
+	TM_RTC_t rtc_data;
+	log_entry_t entry;
+	char buf[20];
+	uint8_t i;
+	int start =LOG_GetTotalSTRCount();//(fs.write.sector*fs.slots_per_sector + fs.write.slot);
+
+	memset(buf, 0, 20);
+	for(i=0; i < 10; i++){
+		fs.cursor_position =  start - 10*(page-1) - 1 - i;
+		if(fs.cursor_position < 0)
+			break;
+		else{
+			fs.cursor.sector = (fs.read.sector + fs.cursor_position/fs.slots_per_sector)%fs.flash->sector_count;
+			fs.cursor.slot = fs.cursor_position%fs.slots_per_sector;
+		}
+		entry.type = LOG_VALUE;
+		log_fetch(&entry, portMAX_DELAY);
+		entry.data[49] = 0;
+		strncat(str, entry.data, strlen(entry.data));
+		TM_RTC_GetDateTimeFromUnix(&rtc_data, entry.timestamp);
+		sprintf(buf, "%02i.%02i.%02i %02i:%02i:%02i",  rtc_data.date, rtc_data.month,
+		rtc_data.year, rtc_data.hours, rtc_data.minutes, rtc_data.seconds);
+		strcat(str, buf);
+		strcat(str, "\",");
+		strcat(str, "\r\n");
+	}
+}
+
 void LOG_GetPage(char *str, uint32_t page)
 {
 	TM_RTC_t rtc_data;
@@ -433,6 +469,49 @@ void History_GetPage(char *str, uint32_t page)
 	}
 }
 
+void History_GetPage_tabs(char *str, uint32_t page)
+{
+	TM_RTC_t rtc_data;
+	log_entry_t entry;
+	char buf[50];
+	uint8_t i;
+	int start =History_GetTotalSTRCount();//(fs.write.sector*fs.slots_per_sector + fs.write.slot);
+
+	memset(buf, 0, 50);
+	for(i=0; i < 10; i++){
+		fs2.cursor_position =  start - 10*(page-1) - 1 - i;
+		if(fs2.cursor_position < 0)
+			break;
+		else{
+			fs2.cursor.sector = (fs2.read.sector + fs2.cursor_position/fs.slots_per_sector)%fs2.flash->sector_count;
+			fs2.cursor.slot = fs2.cursor_position%fs2.slots_per_sector;
+		}
+		entry.type = LOG_LOGIN;
+		log_fetch(&entry, portMAX_DELAY);
+		//sprintf(buf, "%-50s", logsStrShortRu[entry.type]);
+		strncat(str, logsStrShortRu[entry.type], (strlen(logsStrShortRu[entry.type]) ));
+		for(uint8_t j = 0; j < (25 - strlen(logsStrShortRu[entry.type])/2); j ++)
+			strcat(str, " ");
+
+		strcat(str, "\t");
+
+		memset(buf, 0, 50);
+		entry.data[49] = 0;
+		strncat(str, entry.data, (strlen(entry.data) ));
+		for(uint8_t j = 0; j < (25 - strlen(entry.data)/2); j ++)
+			strcat(str, " ");
+
+		strcat(str, "\t");
+
+		memset(buf, 0, 50);
+		TM_RTC_GetDateTimeFromUnix(&rtc_data, entry.timestamp);
+		sprintf(buf, "%02i.%02i.%02i %02i:%02i:%02i",  rtc_data.date, rtc_data.month,
+		rtc_data.year, rtc_data.hours, rtc_data.minutes, rtc_data.seconds);
+		strcat(str, buf);
+		strcat(str, "\r\n");
+	}
+}
+
 uint32_t History_GetData(int ptr, char *str, uint32_t size, bool start)
 {
 	TM_RTC_t rtc_data;

+ 8 - 0
modules/log/log.h

@@ -11,6 +11,9 @@
 extern char logFileBuf[FILE_BUF_MAX_LEN];
 
 extern char name_login[50];
+extern char name_login_telnet[50];
+
+extern bool telnet_act;
 
 typedef __packed enum {
 	LOG_SYSTEM_BOOT = 0x00,			// device booted
@@ -19,6 +22,9 @@ typedef __packed enum {
 	LOG_TURN_ON,		//
 	LOG_PSW_CHANGE,		//
 	LOG_SETTING_SAVE,		//
+#ifdef HARDWARE_BT6706
+	LOG_LOGIN_TELNET,		//
+#endif
 	LOG_LOGIN,		//
 	LOG_TEST_UPS,		//
 	LOG_SHUTDOWN_UPS,
@@ -73,12 +79,14 @@ bool LOG_Disable(void);
 uint32_t LOG_GetPageCount(void);
 uint32_t LOG_GetTotalSTRCount(void);
 void LOG_GetPage(char *str, uint32_t page);
+void LOG_GetPage_tabs(char *str, uint32_t page);
 uint32_t LOG_GetData(int ptr, char *str, uint32_t size, bool start);
 
 uint32_t History_GetPageCount(void);
 uint32_t History_GetTotalSTRCount(void);
 void History_GetPage(char *str, uint32_t page);
 uint32_t History_GetData(int ptr, char *str, uint32_t size, bool start);
+void History_GetPage_tabs(char *str, uint32_t page);
 
 
 #endif /* LOG_H */

+ 86 - 1
modules/parameters.c

@@ -24,7 +24,6 @@
 #include "lwip/snmp.h"
 #include "lwip/sys.h"
 #include "common_config.h"
-#include "settings_api.h"
 //#include "d_inouts.h"
 #include "gpio.h"
 //#if defined HARDWARE_BT6702
@@ -167,6 +166,19 @@ void GetAlarmStr(char *str, uint8_t *len)
 	*len = strlen(str);
 
 }
+
+/**
+  * @brief  Индикация аварийных ситуаций
+  */
+void GetUPSModeStr(char *str, uint8_t *len)
+{
+	if((UPS.Status>>5)&0x01)
+		sprintf(str, "Bypass");
+	else
+		sprintf(str, "Boost or Buck");
+
+	*len = strlen(str);
+}
 #endif
 // ************************************************************************** //
 //                             Параметры даты и времени
@@ -232,6 +244,23 @@ void GetSntpStateStr(char *str, uint8_t *len)
   }
 }
 
+/**
+  * @brief  Состояние SNTP (Ready for PRS!)
+  */
+void GetSntpStateStrRU(char *str, uint8_t *len)
+{
+  if (sSettings.sSNTP.sntpEnable)
+  {
+    sprintf(str, "%s", "авто"); //авто
+    *len = strlen(str);
+  }
+  else
+  {
+    sprintf(str, "%s", "ручной"); //ручной
+    *len = strlen(str);
+  }
+}
+
 /**
   * @brief  IP адрес SNTP сервера (Ready for PRS!)
   */
@@ -289,6 +318,18 @@ void GetDIN0StatusStr(char *str, uint8_t *len)
 	*len = strlen(str);
 }
 
+/**
+  * @brief  Состояние сухого контакта
+  */
+void GetDIN0StatusStrRU(char *str, uint8_t *len)
+{
+	if(get_state_din_outs(DIN1)^1)
+		sprintf(str, "Разомкнут" );
+	else
+		sprintf(str, "Замкнут" );
+	*len = strlen(str);
+}
+
 /**
   * @brief  Источник срабатывания реле
   */
@@ -312,6 +353,26 @@ void GetDOUTStatusStr(char *str, uint8_t *len, uint8_t num)
 	*len = strlen(str);
 }
 
+/**
+  * @brief  Состояние релейного выхода
+  */
+void GetDOUTStatusStrRU(char *str, uint8_t *len, uint8_t num)
+{
+#ifdef HARDWARE_BT6706
+	if (get_state_din_outs(DOUT1+num)^1)
+		sprintf(str, "Замкнут");
+	else
+		sprintf(str, "Разомкнут");
+#elif HARDWARE_BT6702
+	if(get_state_din_outs(DOUT1+num))
+		sprintf(str, "Замкнут");
+	else
+		sprintf(str, "Разомкнут");
+#endif
+
+	*len = strlen(str);
+}
+
 /**
   * @brief  Состояние релейного выхода
   */
@@ -590,6 +651,30 @@ void GetDhcpStateUDP(char *str, uint8_t *len)
 	  *len = strlen(str);
 }
 
+/**
+  * @brief  Настройка DHCP
+  */
+void GetDhcpStateStrRu(char *str, uint8_t *len)
+{
+	  /* Если сейчас временные настройки или был загружен файл конфигурации */
+	  if (sSettings.sFlags.netsettingsChanged)
+	  {
+	    if (sSettings.sWebTempParams.dhcpEnable)
+	      sprintf(str, "%s", "Вкл");
+	    else
+	      sprintf(str, "%s", "Откл");
+	  }
+	  else
+	  {
+	    if (sSettings.sWebParams.dhcpEnable)
+	      sprintf(str, "%s", "Вкл");
+	    else
+	      sprintf(str, "%s", "Откл");
+	  }
+
+	  *len = strlen(str);
+}
+
 // ************************************************************************** //
 //                             Параметры SNMP
 

+ 25 - 0
modules/parameters.h

@@ -49,6 +49,11 @@ void GetModeEn(char *str, uint8_t *len);
   */
 void GetAlarmStr(char *str, uint8_t *len);
 
+/**
+  * @brief  Индикация аварийных ситуаций
+  */
+void GetUPSModeStr(char *str, uint8_t *len);
+
 /**
   * @brief  Текущее время ч/м/с
   */
@@ -81,6 +86,11 @@ void GetUnixTimeStr(char *str, uint8_t *len);
   */
 void GetSntpStateStr(char *str, uint8_t *len);
 
+/**
+  * @brief  Состояние SNTP (Ready for PRS!)
+  */
+void GetSntpStateStrRU(char *str, uint8_t *len);
+
 /**
   * @brief  IP адрес SNTP сервера (Ready for PRS!)
   */
@@ -192,6 +202,11 @@ void GetDhcpStateStr(char *str, uint8_t *len);
   */
 void GetDhcpStateUDP(char *str, uint8_t *len);
 
+/**
+  * @brief  Настройка DHCP
+  */
+void GetDhcpStateStrRu(char *str, uint8_t *len);
+
 // ************************************************************************** //
 //                             Параметры SNMP
 /**
@@ -272,6 +287,11 @@ void GetDINStatusStr(char *str, uint8_t *len, uint8_t num);
   */
 void GetDIN0StatusStr(char *str, uint8_t *len);
 
+/**
+  * @brief  Состояние сухого контакта
+  */
+void GetDIN0StatusStrRU(char *str, uint8_t *len);
+
 /**
   * @brief  Источник срабатывания реле
   */
@@ -281,6 +301,11 @@ void GetROTypeActStr(char *str, uint8_t *len, uint8_t num);
   */
 void GetDOUTStatusStr(char *str, uint8_t *len, uint8_t num);
 
+/**
+  * @brief  Состояние релейного выхода
+  */
+void GetDOUTStatusStrRU(char *str, uint8_t *len, uint8_t num);
+
 /**
   * @brief  Состояние релейного выхода
   */

+ 6 - 0
thirdparty/FreeRTOS/include/FreeRTOSConfig.h

@@ -159,5 +159,11 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
 #define vPortSVCHandler SVC_Handler
 #define xPortSysTickHandler SysTick_Handler
 
+/* Dimensions a buffer that can be used by the FreeRTOS+CLI command
+interpreter.  Set this value to 1 to save RAM if FreeRTOS+CLI does not supply
+the output butter.  See the FreeRTOS+CLI documentation for more information:
+http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_CLI/ */
+#define configCOMMAND_INT_MAX_OUTPUT_SIZE			3*1024
+
 #endif /* FREERTOS_CONFIG_H */
 

+ 4 - 1
user/init_task.c

@@ -26,6 +26,7 @@
 #include "snmp_api.h"
 #ifdef HARDWARE_BT6706
 #include "http_server.h"
+#include "telnet_server.h"
 #elif HARDWARE_BT6702
 #include "my_ssl_server.h"
 #endif
@@ -156,7 +157,9 @@ void InitTask(void *params)
 	   else{
 		   UDP_netsetting_init();
 	   }
-
+#ifdef HARDWARE_BT6706
+	   telnet_server_init();
+#endif
  /* HTTPS_Init();
   xTaskCreate(ssl_server, "SSL", 10*configMINIMAL_STACK_SIZE, NULL, SSL_TASK_PRIO, NULL);  
   UDP_netsetting_init();*/