|  | @@ -43,6 +43,10 @@ int test_time = 0;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  static bool flag_buzzer_on = false;
 |  |  static bool flag_buzzer_on = false;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +static float Ubat_sum = 0;
 | 
											
												
													
														|  | 
 |  | +static float Pload_sum = 0;
 | 
											
												
													
														|  | 
 |  | +uint32_t Period_testing = 0;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  enum {
 |  |  enum {
 | 
											
												
													
														|  |      NORMAL = 0x00,
 |  |      NORMAL = 0x00,
 | 
											
												
													
														|  |      VER_ERROR = 0x01,
 |  |      VER_ERROR = 0x01,
 | 
											
										
											
												
													
														|  | @@ -97,7 +101,6 @@ void init_UPS_value(void)
 | 
											
												
													
														|  |      UPS.Temp = 0;
 |  |      UPS.Temp = 0;
 | 
											
												
													
														|  |      UPS.Load = 0;
 |  |      UPS.Load = 0;
 | 
											
												
													
														|  |      UPS.SOC = 0;
 |  |      UPS.SOC = 0;
 | 
											
												
													
														|  | -    UPS.SOC_test = 0;
 |  | 
 | 
											
												
													
														|  |      UPS.work_time = 0;
 |  |      UPS.work_time = 0;
 | 
											
												
													
														|  |      UPS.akb_work_time = 0;
 |  |      UPS.akb_work_time = 0;
 | 
											
												
													
														|  |      UPS.Status = 0;
 |  |      UPS.Status = 0;
 | 
											
										
											
												
													
														|  | @@ -113,6 +116,24 @@ void init_UPS_value(void)
 | 
											
												
													
														|  |      memset(UPS.serial, 0, sizeof(UPS.serial));
 |  |      memset(UPS.serial, 0, sizeof(UPS.serial));
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +void init_var_for_testing(void)
 | 
											
												
													
														|  | 
 |  | +{
 | 
											
												
													
														|  | 
 |  | +    Ubat_sum = 0;
 | 
											
												
													
														|  | 
 |  | +    Pload_sum = 0;
 | 
											
												
													
														|  | 
 |  | +    Period_testing = 0;
 | 
											
												
													
														|  | 
 |  | +}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +float voltage_bat_average(void)
 | 
											
												
													
														|  | 
 |  | +{
 | 
											
												
													
														|  | 
 |  | +    return (Ubat_sum / Period_testing);
 | 
											
												
													
														|  | 
 |  | +}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +float power_load_average(void)
 | 
											
												
													
														|  | 
 |  | +{
 | 
											
												
													
														|  | 
 |  | +    return (Pload_sum / Period_testing);
 | 
											
												
													
														|  | 
 |  | +}
 | 
											
												
													
														|  | 
 |  | + 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  void send_MegaTec_cmd(cmdMegaTecEnums_t command)
 |  |  void send_MegaTec_cmd(cmdMegaTecEnums_t command)
 | 
											
												
													
														|  |  {
 |  |  {
 | 
											
												
													
														|  |      DBG printf("MegaTecCMD: %s\r\n", MegaTecCMD[command]);
 |  |      DBG printf("MegaTecCMD: %s\r\n", MegaTecCMD[command]);
 | 
											
										
											
												
													
														|  | @@ -287,14 +308,14 @@ void ups_status_response(char *data)
 | 
											
												
													
														|  |      len = get_ups_param(data, " ", value);
 |  |      len = get_ups_param(data, " ", value);
 | 
											
												
													
														|  |      data += (len + 1);
 |  |      data += (len + 1);
 | 
											
												
													
														|  |      if (len > 0) {
 |  |      if (len > 0) {
 | 
											
												
													
														|  | -        UPS.Vakb_curr = atof(value);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        UPS.Vcell_curr = atof(value);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |      if (sSettings.UPS_Setting.type_ups == ups_kestar || sSettings.UPS_Setting.type_ups == ups_offline) {
 |  |      if (sSettings.UPS_Setting.type_ups == ups_kestar || sSettings.UPS_Setting.type_ups == ups_offline) {
 | 
											
												
													
														|  | -        if (UPS.Vakb_curr < 7) {
 |  | 
 | 
											
												
													
														|  | -            UPS.SOC = round(100 * (UPS.Vakb_curr - sSettings.UPS_Setting.Ucellmin) / (sSettings.UPS_Setting.Ucellmax -
 |  | 
 | 
											
												
													
														|  | 
 |  | +        if (UPS.Vcell_curr < 7) {
 | 
											
												
													
														|  | 
 |  | +            UPS.SOC = round(100 * (UPS.Vcell_curr - sSettings.UPS_Setting.Ucellmin) / (sSettings.UPS_Setting.Ucellmax -
 | 
											
												
													
														|  |                          sSettings.UPS_Setting.Ucellmin));
 |  |                          sSettings.UPS_Setting.Ucellmin));
 | 
											
												
													
														|  |          } else {
 |  |          } else {
 | 
											
												
													
														|  | -            UPS.SOC = round(100 * (UPS.Vakb_curr / AKB_NUM_CELL - sSettings.UPS_Setting.Ucellmin) /
 |  | 
 | 
											
												
													
														|  | 
 |  | +            UPS.SOC = round(100 * (UPS.Vcell_curr / AKB_NUM_CELL - sSettings.UPS_Setting.Ucellmin) /
 | 
											
												
													
														|  |                      (sSettings.UPS_Setting.Ucellmax - sSettings.UPS_Setting.Ucellmin));
 |  |                      (sSettings.UPS_Setting.Ucellmax - sSettings.UPS_Setting.Ucellmin));
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
										
											
												
													
														|  | @@ -314,12 +335,6 @@ void ups_status_response(char *data)
 | 
											
												
													
														|  |          UPS.Status = stat;
 |  |          UPS.Status = stat;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -#ifdef RELAY_ALARM_AKB
 |  | 
 | 
											
												
													
														|  | -    if (sSettings.UPS_Setting.type_ups == ups_kestar || sSettings.UPS_Setting.type_ups == ups_offline) {
 |  | 
 | 
											
												
													
														|  | -      UPS_TestSOCMonitor();
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -#endif
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  void ups_general_status_response(char *data)
 |  |  void ups_general_status_response(char *data)
 | 
											
										
											
												
													
														|  | @@ -422,7 +437,7 @@ void ups_general_status_response(char *data)
 | 
											
												
													
														|  |      if (flUpdateLog) {
 |  |      if (flUpdateLog) {
 | 
											
												
													
														|  |          flUpdateLog = false;
 |  |          flUpdateLog = false;
 | 
											
												
													
														|  |          memset(data, 0, UPS_PDU_MAX_LEN);
 |  |          memset(data, 0, UPS_PDU_MAX_LEN);
 | 
											
												
													
														|  | -        sprintf(data, "(%0.1f n/a %0.1f %d %0.1f %0.2f %0.1f %s", UPS.VAC_in, UPS.VAC_out, UPS.Load, UPS.Freq_in, UPS.Vakb_curr, UPS.Temp, &value[2]);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        sprintf(data, "(%0.1f n/a %0.1f %d %0.1f %0.2f %0.1f %s", UPS.VAC_in, UPS.VAC_out, UPS.Load, UPS.Freq_in, UPS.Vcell_curr, UPS.Temp, &value[2]);
 | 
											
												
													
														|  |          log_add(data);
 |  |          log_add(data);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  */
 |  |  */
 | 
											
										
											
												
													
														|  | @@ -522,10 +537,18 @@ void ups_akb_info_response(char *data)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      DBG printf("UPS ups_akb_info_parser_start: %s\r\n", data);
 |  |      DBG printf("UPS ups_akb_info_parser_start: %s\r\n", data);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    //TODO
 |  | 
 | 
											
												
													
														|  |      len = get_ups_param(data, " ", value);
 |  |      len = get_ups_param(data, " ", value);
 | 
											
												
													
														|  |      data += (len + 1);
 |  |      data += (len + 1);
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | 
 |  | +    if(len > 0) {
 | 
											
												
													
														|  | 
 |  | +        UPS.Vakb_curr = atof(value);
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +#ifdef HARDWARE_BT6703_RT
 | 
											
												
													
														|  | 
 |  | +    if((UPS.Status >> 2) & 0x01) {
 | 
											
												
													
														|  | 
 |  | +        Ubat_sum +=  UPS.Vakb_curr;
 | 
											
												
													
														|  | 
 |  | +        Pload_sum += UPS.Load;
 | 
											
												
													
														|  | 
 |  | +        Period_testing ++;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +#endif
 | 
											
												
													
														|  |      //TODO
 |  |      //TODO
 | 
											
												
													
														|  |      len = get_ups_param(data, " ", value);
 |  |      len = get_ups_param(data, " ", value);
 | 
											
												
													
														|  |      data += (len + 1);
 |  |      data += (len + 1);
 | 
											
										
											
												
													
														|  | @@ -540,10 +563,6 @@ void ups_akb_info_response(char *data)
 | 
											
												
													
														|  |          UPS.SOC = atoi(value);
 |  |          UPS.SOC = atoi(value);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -#ifdef RELAY_ALARM_AKB
 |  | 
 | 
											
												
													
														|  | -      UPS_TestSOCMonitor();
 |  | 
 | 
											
												
													
														|  | -#endif
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |      len = get_ups_param(data, "\r", value);
 |  |      len = get_ups_param(data, "\r", value);
 | 
											
												
													
														|  |      data += (len + 1);
 |  |      data += (len + 1);
 | 
											
												
													
														|  |      if (len > 0) {
 |  |      if (len > 0) {
 | 
											
										
											
												
													
														|  | @@ -584,6 +603,20 @@ void ups_model_response(char *data)
 | 
											
												
													
														|  |              strncpy(UPS.model, value, len);
 |  |              strncpy(UPS.model, value, len);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          SNMP_SetObjDescr();
 |  |          SNMP_SetObjDescr();
 | 
											
												
													
														|  | 
 |  | +        data += (VOLTRONIC_MODEL_LENGTH + 1);
 | 
											
												
													
														|  | 
 |  | +        memset(value, 0, sizeof(value));
 | 
											
												
													
														|  | 
 |  | +        j = 0;
 | 
											
												
													
														|  | 
 |  | +        for (uint8_t i = 0; i < VOLTRONIC_OUTPUT_RATED_LENGTH; i ++) {
 | 
											
												
													
														|  | 
 |  | +            if (data[i] != '#') {
 | 
											
												
													
														|  | 
 |  | +                value[j] = data[i];
 | 
											
												
													
														|  | 
 |  | +                j ++;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        float temp_value = atof(value);
 | 
											
												
													
														|  | 
 |  | +        if (sSettings.UPS_Setting.ups_power != temp_value) {
 | 
											
												
													
														|  | 
 |  | +            sSettings.UPS_Setting.ups_power = temp_value;
 | 
											
												
													
														|  | 
 |  | +            SETTINGS_Save();
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |      } else {
 |  |      } else {
 | 
											
												
													
														|  |          return;
 |  |          return;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
										
											
												
													
														|  | @@ -803,11 +836,16 @@ int ups_metac_service_pdu(cmdMegaTecEnums_t command)
 | 
											
												
													
														|  |              TimeParam2 = 1;
 |  |              TimeParam2 = 1;
 | 
											
												
													
														|  |              send_MegaTec_cmd(ups_shutdown_restore);
 |  |              send_MegaTec_cmd(ups_shutdown_restore);
 | 
											
												
													
														|  |          } else {
 |  |          } else {
 | 
											
												
													
														|  | -            UPS.SOC_test = UPS.SOC;
 |  | 
 | 
											
												
													
														|  | -            if (command == ups_test_low_bat) { 
 |  | 
 | 
											
												
													
														|  | -                test_time = 0;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if((UPS.Status >> 2) & 0x01) {
 | 
											
												
													
														|  | 
 |  | +                if (command == ups_cancel_test) { 
 | 
											
												
													
														|  | 
 |  | +                    test_time = 100;
 | 
											
												
													
														|  | 
 |  | +                } 
 | 
											
												
													
														|  |              } else {
 |  |              } else {
 | 
											
												
													
														|  | -                test_time = (int)TimeParam;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                if (command == ups_test_low_bat) { 
 | 
											
												
													
														|  | 
 |  | +                    test_time = 100;
 | 
											
												
													
														|  | 
 |  | +                } else {
 | 
											
												
													
														|  | 
 |  | +                    test_time = (int)TimeParam;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |              send_MegaTec_cmd(command);
 |  |              send_MegaTec_cmd(command);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
										
											
												
													
														|  | @@ -819,6 +857,8 @@ int ups_metac_service_pdu(cmdMegaTecEnums_t command)
 | 
											
												
													
														|  |                      xTimerStart(UPSRestoreTimer, 0);
 |  |                      xTimerStart(UPSRestoreTimer, 0);
 | 
											
												
													
														|  |                  } else if(command == ups_cancel_shut_down) {
 |  |                  } else if(command == ups_cancel_shut_down) {
 | 
											
												
													
														|  |                      xTimerStop(UPSRestoreTimer, 0);
 |  |                      xTimerStop(UPSRestoreTimer, 0);
 | 
											
												
													
														|  | 
 |  | +                } else if (command == ups_test_time) {
 | 
											
												
													
														|  | 
 |  | +                    init_var_for_testing();
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  |                  return 1;
 |  |                  return 1;
 | 
											
												
													
														|  |              } else if (strncmp(ups_pdu.data, "NAK", 3) == 0 || strncmp(ups_pdu.data, "(NAK", 4) == 0) {
 |  |              } else if (strncmp(ups_pdu.data, "NAK", 3) == 0 || strncmp(ups_pdu.data, "(NAK", 4) == 0) {
 | 
											
										
											
												
													
														|  | @@ -851,6 +891,7 @@ int ups_metac_service_pdu(cmdMegaTecEnums_t command)
 | 
											
												
													
														|  |          } else {
 |  |          } else {
 | 
											
												
													
														|  |              if  ((((UPS.Status >> 2) & 0x01) != ((UPS_Status_prev >> 2) & 0x01))
 |  |              if  ((((UPS.Status >> 2) & 0x01) != ((UPS_Status_prev >> 2) & 0x01))
 | 
											
												
													
														|  |               && ((UPS.Status >> 2) & 0x01)) {
 |  |               && ((UPS.Status >> 2) & 0x01)) {
 | 
											
												
													
														|  | 
 |  | +                init_var_for_testing();
 | 
											
												
													
														|  |                  return 1;
 |  |                  return 1;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |          }
 |  |          }
 |