Pārlūkot izejas kodu

[BT-6709]add func for inputting UPS S/N

balbekova 3 gadi atpakaļ
vecāks
revīzija
abff4de3d5

+ 83 - 7
modules/cli/CLI_Commands.c

@@ -88,7 +88,7 @@ const char *akb_args_list[] = {
     "lifetime",
     "dataset",
     "upspower",
-#else if HARDWARE_BT6711
+#else if HARDWARE_BT6711 || HARDWARE_BT6711_V1
     "capacity",
     "voltakb",
     "upspower",
@@ -258,6 +258,10 @@ static portBASE_TYPE prvTaskUploadCommand(cli_state_t *cli_state, int8_t *pcWrit
  */
 static portBASE_TYPE prvTaskUPSCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
 
+/*
+ * Implements the гзs serial command.
+ */
+static portBASE_TYPE prvSetUPSserialCommand(cli_state_t *cli_state, int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
 
 /* Structure that defines the "info" command line command.   This
 generates a table that shows how much run time each task has */
@@ -342,7 +346,7 @@ static const CLI_Command_Definition_t prvAKBCommandDefinition = {
 							"\takb lifetime <value>: ввод срока службы АКБ (лет)\r\n"
 							"\takb dataset <YYYY-MM-DD>: ввод даты установки АКБ\r\n"
 							"\takb upspower <value>: ввод полной мощности ИБП (ВА)\r\n"
-#else if HARDWARE_BT6711
+#else if HARDWARE_BT6711 || HARDWARE_BT6711_V1
 							"\takb capacity <value>: ввод ёмкости АКБ (Ач)\r\n"
 							"\takb voltakb <value>:  ввод номинального напряжения АКБ (В)\r\n"
 							"\takb upspower <value>: ввод полной мощности ИБП (ВА)\r\n"
@@ -591,6 +595,14 @@ static const CLI_Command_Definition_t prvRADIUSCommandDefinition = {
 };
 #endif
 
+static const CLI_Command_Definition_t prvSetUPSserialCommandDefinition =
+{
+	( const int8_t * const ) "setupsid", /* The command string to type. */
+	( const int8_t * const ) "\tsetupsid <password> <SN>: установка серийного номера ИБП\r\n",
+	prvSetUPSserialCommand, /* The function to run. */
+	2 /* Two parameters are expected, which can take any value. */
+};
+
 /* Structure that defines the "quit" command line command.   This
 generates a table that shows how much run time each task has */
 static const CLI_Command_Definition_t prvQuitCommandDefinition = {
@@ -635,6 +647,7 @@ void vRegisterCLICommands( void )
 #ifdef RADIUS_SERVER_ENABLE
     FreeRTOS_CLIRegisterCommand( &prvRADIUSCommandDefinition );
 #endif
+    FreeRTOS_CLIRegisterCommand( &prvSetUPSserialCommandDefinition );
     FreeRTOS_CLIRegisterCommand( &prvQuitCommandDefinition );
 }
 /*-----------------------------------------------------------*/
@@ -1290,10 +1303,15 @@ static portBASE_TYPE prvTaskNetworkCommand(cli_state_t *cli_state, int8_t *pcWri
             break;
         case ARG_NETWORK_MASK:
             if (xParameterStringLength <= 15) {
-                if (ipaddr_addr(str) != IPADDR_NONE) {
-                    SetMaskStr(str);
-                    strcpy( ( char * ) pcWriteBuffer,
+                uint32_t mask = ipaddr_addr(str);
+                if (mask != IPADDR_NONE) {
+                    if(ip4_addr_netmask_valid(mask)) {
+                        SetMaskStr(str);
+                        strcpy( ( char * ) pcWriteBuffer,
                         "\t\tСохраните конфигурацию сетевых настроек\r\n" );
+                    }  else {
+                        strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
+                    } 
                 } else {
                     strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
                 }
@@ -1563,7 +1581,7 @@ static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBu
                 strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
             }
             break;
-#if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6711
+#if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6711 || HARDWARE_BT6711_V1
         case ARG_AKB_CAPACITY:
             if (value >= CAPACITY_MIN_RANGE && value <= CAPACITY_MAX_RANGE && (value - (int32_t)value) == 0) {
                 SetCapacityNominalAKBStr(str);
@@ -1580,7 +1598,7 @@ static portBASE_TYPE prvTaskAKBCommand(cli_state_t *cli_state, int8_t *pcWriteBu
                 strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
             }
             break;
-#ifndef HARDWARE_BT6711
+#if HARDWARE_BT6709 || HARDWARE_BT6709_MTS
         case ARG_AKB_LIFETIME:
             if (value >= LIFETIME_MIN_RANGE && value <= LIFETIME_MAX_RANGE  && (value - (int32_t)value) == 0) {
                 SetLifeTimeAKBStr(str);
@@ -3440,5 +3458,63 @@ static portBASE_TYPE prvTaskFTPCommand(cli_state_t *cli_state, int8_t *pcWriteBu
     return xReturn;
 }
 #endif // FTP_ENABLE
+
+
+/*
+ * Implements the ups serial command.
+ */
+static portBASE_TYPE prvSetUPSserialCommand(cli_state_t *cli_state,  int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString ){
+	int8_t *pcParameterString;
+	signed portBASE_TYPE xParameterStringLength;
+	portBASE_TYPE xParameterNumber = 1;
+	char str[10];
+
+	( void ) pcCommandString;
+	( void ) xWriteBufferLen;
+	configASSERT( pcWriteBuffer );
+
+	memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
+	/* Obtain the parameter string. */
+	pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
+															(
+																pcCommandString,		/* The command string itself. */
+																xParameterNumber,		/* Return the next parameter. */
+																&xParameterStringLength	/* Store the parameter string length. */
+															);
+	if(pcParameterString == NULL){
+		strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
+		return pdFALSE;
+	}
+
+	if( strncmp( ( const char * ) pcParameterString, "SvUsn", xParameterStringLength ) != 0 ){
+		strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
+			return pdFALSE;
+	}
+
+	xParameterNumber ++;
+	/* Obtain the parameter string. */
+	pcParameterString = ( int8_t * ) FreeRTOS_CLIGetParameter
+															(
+																pcCommandString,		/* The command string itself. */
+																xParameterNumber,		/* Return the next parameter. */
+																&xParameterStringLength	/* Store the parameter string length. */
+															);
+	memset(str, 0, sizeof(str));
+	if(xParameterStringLength != 8){
+		strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
+		return pdFALSE;
+	}
+	strncat(str, ( const char * ) pcParameterString, xParameterStringLength);
+	for(uint8_t j = 0; j < xParameterStringLength; j++){
+		if(!isdigit_int(str[j])){
+			strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcInvalidCommand, strlen( ( char * ) pcInvalidCommand ) );
+			return pdFALSE;
+		}
+	}
+	SetUPSSerialStr(str);
+    cli_save_config(cli_state);
+
+	return pdFALSE;
+}
 /*-----------------------------------------------------------*/
 

+ 1 - 1
modules/cli/CLI_Commands.h

@@ -55,7 +55,7 @@ typedef enum{
 	ARG_AKB_LIFETIME,
 	ARG_AKB_DATASET,
 	ARG_AKB_UPS_POWER,
-#else if HARDWARE_BT6711
+#else if HARDWARE_BT6711 || HARDWARE_BT6711_V1
 	ARG_AKB_CAPACITY,
 	ARG_AKB_VOLT,
 	ARG_AKB_UPS_POWER,

+ 3 - 3
modules/cli/CLI_Parameters.c

@@ -294,7 +294,7 @@ void akb_config_param(int8_t *buf)
     GetUPSVoltCellMaxStr(str, &len);
     strncat(( char * ) buf, str, len);
 
-#if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6711
+#if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6711 || HARDWARE_BT6711_V1
 
     GetVoltageAKBNominalStr(str, &len);
     strcat(( char * ) buf, "\r\nНоминальное напряжение (В):\t\t");
@@ -511,7 +511,7 @@ void ups_sensor_param(int8_t *buf)
     GetOutputVoltageStr(str, &len);
     strncat(( char * ) buf, str, len);
 
-#if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6711
+#if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6711 || HARDWARE_BT6711_V1
     GetInputCurrentStr(str, &len);
     strcat(( char * ) buf, "\r\nВходная сила тока (A):\t\t\t");
     strncat(( char * ) buf, str, len);
@@ -565,7 +565,7 @@ void ups_sensor_akb_param(int8_t *buf)
     GetRuntimeStr(str, &len);
     strncat(( char * ) buf, str, len);
 
-#if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6711
+#if HARDWARE_BT6709 || HARDWARE_BT6709_MTS || HARDWARE_BT6711 || HARDWARE_BT6711_V1
     GetCapacityNominalAKBStr(str, &len);
     strcat(( char * ) buf, "\r\nЕмкость батареи (Ач):\t\t\t");
     strncat(( char * ) buf, str, len);

+ 22 - 4
modules/parameters.c

@@ -1035,13 +1035,31 @@ void GetUPSSerialStr(char *str, uint8_t *len)
 
     if (sSettings.UPS_Setting.serial == 0) {
       *len = strlen(UPS.serial);
-      strncpy(str, UPS.serial, *len);
+      if(*len == 0){
+        strcpy(str, "00000000000000");
+      } else {
+        strcpy(str, UPS.serial);
+      }
     } else {
       memset(tempStr, 0, sizeof(tempStr));
-      sprintf(tempStr, "%d", sSettings.UPS_Setting.serial);
-      strcpy(str, tempStr);
+      memset(str, 0, 14);
+      sprintf(str, "%lu", sSettings.UPS_Setting.serial);
       *len = strlen(str);
+      strcpy(tempStr, UPS.serial);
+      
+      if (*len < 8) {
+        for(uint8_t i = 0; i < (8-*len); i ++) {
+          tempStr[6+i] = '0';
+        }
+        tempStr[6+(8-*len)] = 0;
+      }  else  {
+        tempStr[6] = 0;
+      }
+      
+       strncat(tempStr, str, strlen(str));
+       strcpy(str, tempStr);
     }
+    *len = strlen(str);
 }
 
 /**
@@ -3016,7 +3034,7 @@ void SetCapacityNominalAKBStr(char *str)
   */
 void SetUPSSerialStr(char *str)
 {
-	sSettings.UPS_Setting.serial = atoi(str);
+	sSettings.UPS_Setting.serial = atol(str);
 }
 
 // ************************************************************************** //