|
|
|
@ -39,6 +39,7 @@
|
|
|
|
|
#include "math.h"
|
|
|
|
|
|
|
|
|
|
#include "usart.h"
|
|
|
|
|
#include "rtc.h"
|
|
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "dev_config.h"
|
|
|
|
@ -94,7 +95,8 @@ typedef struct
|
|
|
|
|
uint16_t defect_thr; // 隐患阈值, 单位: mA.
|
|
|
|
|
uint16_t fault_thr; // 故障阈值, 单位: A.
|
|
|
|
|
uint8_t APN[DEV_APN_LEN]; // APN 名字.
|
|
|
|
|
uint8_t reserve[20];
|
|
|
|
|
uint16_t fault_inr; // 故障间隔, 单位: s.
|
|
|
|
|
uint8_t reserve[18];
|
|
|
|
|
} debug_config_t;
|
|
|
|
|
|
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
|
|
@ -113,6 +115,10 @@ static dev_adj_defect_zero_t debug_adj_defect;
|
|
|
|
|
dev_adj_fault_zero_t debug_adj_fault;
|
|
|
|
|
dev_adj_power_t debug_adj_power;
|
|
|
|
|
|
|
|
|
|
static RTC_DateTypeDef debug_date;
|
|
|
|
|
static RTC_TimeTypeDef debug_time;
|
|
|
|
|
static struct tm debug_tm;
|
|
|
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
|
/* Internal functions --------------------------------------------------------*/
|
|
|
|
|
/* 报文头校验. */
|
|
|
|
@ -469,9 +475,7 @@ static void _debug_pkt_update_fpga(void)
|
|
|
|
|
mul_head_t *m_head = (mul_head_t*)(debug_buf.buf + sizeof(proto_head_t));
|
|
|
|
|
uint8_t *data = (uint8_t*)(debug_buf.buf + sizeof(proto_head_t) + sizeof(mul_head_t));
|
|
|
|
|
uint32_t addr = TFTP_APP_ADDRESS;
|
|
|
|
|
uint32_t app_len = 0;
|
|
|
|
|
uint32_t *crc = NULL;
|
|
|
|
|
HAL_GPIO_WritePin(LED_RUN_GPIO_Port, LED_RUN_Pin, GPIO_PIN_SET);
|
|
|
|
|
|
|
|
|
|
/* index 为 0 表示是首保, 需要擦除 FLASH. */
|
|
|
|
|
if (0 == m_head->index)
|
|
|
|
@ -510,10 +514,9 @@ static void _debug_pkt_update_fpga(void)
|
|
|
|
|
if(m_head->len < DEBUG_FLASH_BUF_SIZE)
|
|
|
|
|
{
|
|
|
|
|
/* 校验数据. */
|
|
|
|
|
app_len = addr - TFTP_APP_ADDRESS + m_head->len;
|
|
|
|
|
dau_ctrl.update_flag = TRUE;
|
|
|
|
|
dau_ctrl.update_len = app_len;
|
|
|
|
|
dau_ctrl.update_rt = DAU_UPD_NONE;
|
|
|
|
|
dau_ctrl.update_len = addr - TFTP_APP_ADDRESS + m_head->len;
|
|
|
|
|
dau_ctrl.update_rt_dbg = DAU_UPD_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 封装报文头. */
|
|
|
|
@ -1274,6 +1277,20 @@ static void _debug_pkt_data_get(void)
|
|
|
|
|
data->temperature = ADC_ctrl.ADCi_temp;
|
|
|
|
|
data->vbat = ADC_ctrl.ADCi_vbat;
|
|
|
|
|
data->vin = ADC_ctrl.ADCi_vin;
|
|
|
|
|
HAL_RTC_GetTime(&hrtc, &debug_time, RTC_FORMAT_BIN);
|
|
|
|
|
HAL_RTC_GetDate(&hrtc, &debug_date, RTC_FORMAT_BIN);
|
|
|
|
|
debug_tm.tm_year = debug_date.Year + 100;
|
|
|
|
|
debug_tm.tm_mon = debug_date.Month - 1;
|
|
|
|
|
debug_tm.tm_mday = debug_date.Date;
|
|
|
|
|
debug_tm.tm_hour = debug_time.Hours;
|
|
|
|
|
debug_tm.tm_min = debug_time.Minutes;
|
|
|
|
|
debug_tm.tm_sec = debug_time.Seconds;
|
|
|
|
|
data->time = mktime(&debug_tm);
|
|
|
|
|
data->run = HAL_GetTick() / 1000;
|
|
|
|
|
data->state_wir = wl_ctrl.state;
|
|
|
|
|
data->is_bat_charge = st_data.is_bat_charge;
|
|
|
|
|
data->is_utc_valid = dau_ctrl.is_utc_valid;
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < DAU_PORT_POWER_CNT; i++)
|
|
|
|
|
{
|
|
|
|
|
data->elec[i] = dau_ctrl.reg_elec[i];
|
|
|
|
@ -1494,7 +1511,7 @@ static void _debug_pkt_adj_defect(void)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
temp = dau_ctrl.reg_port_state.DAVR[i] - dev_config.defect_base[i];
|
|
|
|
|
temp = 3276;
|
|
|
|
|
//temp = 3276;
|
|
|
|
|
dev_config.defect_adj[i] = debug_adj_defect.defect_elec * 32768 / temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1834,7 +1851,7 @@ static void _debug_pkt_update_fpga_result()
|
|
|
|
|
_debug_pkt_head_init(sizeof(proto_head_t) + sizeof(int32_t), DEBUG_CT_PRV_REPLY);
|
|
|
|
|
head->cmd_type = DEBUG_CT_PRV_REPLY;
|
|
|
|
|
head->cmd = DEBUG_PRV_UPDATE_RT;
|
|
|
|
|
*res = (dau_ctrl.update_rt != DAU_UPD_OK);
|
|
|
|
|
*res = (dau_ctrl.update_rt_dbg != DAU_UPD_OK);
|
|
|
|
|
|
|
|
|
|
/* 计算校验和. */
|
|
|
|
|
crc = (uint32_t*)(debug_buf.buf + head->len);
|
|
|
|
@ -2045,10 +2062,10 @@ void debug_start(void)
|
|
|
|
|
{
|
|
|
|
|
common_watchdog_set(COM_WDG_CLI);
|
|
|
|
|
|
|
|
|
|
if (dau_ctrl.update_rt == DAU_UPD_OK)
|
|
|
|
|
if (dau_ctrl.update_rt_dbg != DAU_UPD_NONE)
|
|
|
|
|
{
|
|
|
|
|
_debug_pkt_update_fpga_result();
|
|
|
|
|
dau_ctrl.update_rt = DAU_UPD_NONE;
|
|
|
|
|
dau_ctrl.update_rt_dbg = DAU_UPD_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 开启串口空闲中断 DMA 收包. 注意这里会收到空闲中断, DMA 收一半中断, 全收中断, 注意中断处理. */
|
|
|
|
|