|
|
|
|
@ -74,7 +74,7 @@
|
|
|
|
|
debug_ctrl_t debug_ctrl;
|
|
|
|
|
dbg_device_info_t dbg_base_config;
|
|
|
|
|
dbg_global_config_t dbg_global_config;
|
|
|
|
|
dbg_port_config_t dbg_port_config;
|
|
|
|
|
dbg_config_port_t dbg_port_config;
|
|
|
|
|
|
|
|
|
|
static char buf_cmd[DEBUG_CMD_LEN];
|
|
|
|
|
|
|
|
|
|
@ -114,14 +114,13 @@ int32_t _debug_pkt_common_send(char *buf, uint16_t cmd, uint32_t data_len)
|
|
|
|
|
/* 获取配置报文处理. */
|
|
|
|
|
int32_t _debug_pkt_factory_cfg_get(char *buf, int len)
|
|
|
|
|
{
|
|
|
|
|
uint16_t len_pkt = 0;
|
|
|
|
|
dbg_device_info_t *info = (dbg_device_info_t *)(buf+sizeof(dbg_pkt_head_t));
|
|
|
|
|
|
|
|
|
|
memset(info, 0, sizeof(dbg_device_info_t));
|
|
|
|
|
info->type_m = device_info.type_m;
|
|
|
|
|
info->type_s = device_info.type_s;
|
|
|
|
|
info->dev_id = device_info.dev_id;
|
|
|
|
|
snprintf((char*)info->hostname, PD_DEV_NUM_LEN, "%s", device_info.hostname);
|
|
|
|
|
snprintf((char*)info->hostname, FILE_NAME_LEN, "%s", device_info.hostname);
|
|
|
|
|
info->factory_date = device_info.factory_date;
|
|
|
|
|
info->deployment_date = device_info.deployment_date;
|
|
|
|
|
info->ip = device_info.ip;
|
|
|
|
|
@ -138,10 +137,8 @@ int32_t _debug_pkt_factory_cfg_get(char *buf, int len)
|
|
|
|
|
info->csg_port = csg.server_port;
|
|
|
|
|
info->csg_ipv4 = csg.server_ip;
|
|
|
|
|
info->running_time = start_time;
|
|
|
|
|
len_pkt += sizeof(dbg_device_info_t);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t ret = _debug_pkt_common_send(buf, DEBUG_CONFIG_FACTORY_GET, len_pkt);
|
|
|
|
|
int32_t ret = _debug_pkt_common_send(buf, DEBUG_CONFIG_FACTORY_GET, sizeof(dbg_device_info_t));
|
|
|
|
|
/* 发送数据. */
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
@ -161,7 +158,7 @@ int32_t _debug_pkt_factory_cfg_set(char *buf, int len)
|
|
|
|
|
device_info.dev_id = info->dev_id;
|
|
|
|
|
boottype = REBOOT_LOCAL_HOST_NAME_CHANGE;
|
|
|
|
|
}
|
|
|
|
|
snprintf(device_info.hostname, PD_DEV_NUM_LEN, "%s", (const char*)info->hostname);
|
|
|
|
|
snprintf(device_info.hostname, FILE_NAME_LEN, "%s", (const char*)info->hostname);
|
|
|
|
|
device_info.factory_date = info->factory_date;
|
|
|
|
|
device_info.deployment_date = info->deployment_date;
|
|
|
|
|
|
|
|
|
|
@ -227,19 +224,24 @@ int32_t _debug_pkt_factory_cfg_set(char *buf, int len)
|
|
|
|
|
/* 设置报文处理. */
|
|
|
|
|
int32_t _debug_pkt_global_cfg_set(char *pkt, int len)
|
|
|
|
|
{
|
|
|
|
|
dbg_global_config_t *pnet = (dbg_global_config_t *)(pkt + sizeof(dbg_pkt_head_t));
|
|
|
|
|
|
|
|
|
|
//pd_config.config.power_frequency = pnet->power_frequency * 10;
|
|
|
|
|
//pd_config.config.trend_period = pnet->trend_period * 60;
|
|
|
|
|
//pd_config.config.sync_mode = pnet->sync_mode;
|
|
|
|
|
//pd_config.config.heartbeat_period = pnet->heartbeat_period;
|
|
|
|
|
//pd_config.config.pps_mode = pnet->pps_mode;
|
|
|
|
|
//pd_config.config.trend_storage = pnet->trend_storage;
|
|
|
|
|
//pd_config.config.event_storage = pnet->event_storage;
|
|
|
|
|
//pd_config.config.is_4G_enable = pnet->is_4G_enable;
|
|
|
|
|
|
|
|
|
|
dbg_global_config_t *config = (dbg_global_config_t *)(pkt + sizeof(csg_pkt_head_t));
|
|
|
|
|
pd_config.config.sample_frequency = config->sample_frequency;
|
|
|
|
|
pd_config.config.trigger_sample_nums = config->trigger_sample_numbers;
|
|
|
|
|
pd_config.config.trig_location = (config->pre_trigger_percent << 4) / 100.00;
|
|
|
|
|
pd_config.config.trig_threshold = config->trigLevel;
|
|
|
|
|
pd_config.config.trend_up_period = config->trend_up_period;
|
|
|
|
|
pd_config.config.heartbeat_period = config->heartbeat_period;
|
|
|
|
|
pd_config.config.ch_en_mask = config->ch_en_mask;
|
|
|
|
|
if (config->sync_mode == 0)
|
|
|
|
|
{
|
|
|
|
|
BITMAP_RESET(pd_config.config.pt_B_sync_mode, PD_BIT_PT);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BITMAP_SET(pd_config.config.pt_B_sync_mode, PD_BIT_PT);
|
|
|
|
|
}
|
|
|
|
|
pd_config.config.pt_internal_period = 1000000000UL / config->pt_internal_period;
|
|
|
|
|
vtysh_config_save();
|
|
|
|
|
|
|
|
|
|
return _debug_pkt_common_send(pkt, DEBUG_CONFIG_GLOBAL_SET, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -248,11 +250,24 @@ int32_t _debug_pkt_global_cfg_set(char *pkt, int len)
|
|
|
|
|
/* 查询用户参数查询报文处理. */
|
|
|
|
|
int32_t _debug_pkt_global_cfg_get(char *pkt, int len)
|
|
|
|
|
{
|
|
|
|
|
uint16_t len_pkt = 0;
|
|
|
|
|
dbg_global_config_t *pnet = (dbg_global_config_t *)(pkt + sizeof(dbg_pkt_head_t));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_debug_pkt_common_send(pkt, DEBUG_CONFIG_GLOBAL_GET, len_pkt);
|
|
|
|
|
dbg_global_config_t *pconfig = (dbg_global_config_t *)(pkt + sizeof(dbg_pkt_head_t));
|
|
|
|
|
pconfig->sample_frequency = pd_config.config.sample_frequency;
|
|
|
|
|
pconfig->trigger_sample_numbers = pd_config.config.trigger_sample_nums;
|
|
|
|
|
pconfig->pre_trigger_percent = (uint32_t)(pd_config.config.trig_location * 100 / 16.00 + 0.5);
|
|
|
|
|
pconfig->trigLevel = pd_config.config.trig_threshold;
|
|
|
|
|
pconfig->trend_up_period = pd_config.config.trend_up_period;
|
|
|
|
|
pconfig->heartbeat_period = pd_config.config.heartbeat_period;
|
|
|
|
|
pconfig->ch_en_mask = pd_config.config.ch_en_mask;
|
|
|
|
|
if (IS_BITMAP_SET(pd_config.config.pt_B_sync_mode, PD_BIT_PT))
|
|
|
|
|
{
|
|
|
|
|
pconfig->sync_mode = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pconfig->sync_mode = 0;
|
|
|
|
|
}
|
|
|
|
|
pconfig->pt_internal_period = 1000000000UL / pd_config.config.pt_internal_period;
|
|
|
|
|
_debug_pkt_common_send(pkt, DEBUG_CONFIG_GLOBAL_GET, sizeof(dbg_global_config_t));
|
|
|
|
|
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
@ -260,15 +275,75 @@ int32_t _debug_pkt_global_cfg_get(char *pkt, int len)
|
|
|
|
|
/* 设置报文处理. */
|
|
|
|
|
int32_t _debug_pkt_port_cfg_set(char *pkt, int len)
|
|
|
|
|
{
|
|
|
|
|
uint8_t unit = 0;
|
|
|
|
|
uint8_t port = 0;
|
|
|
|
|
dbg_config_port_t *pnet = (dbg_config_port_t *)(pkt + sizeof(dbg_pkt_head_t));
|
|
|
|
|
|
|
|
|
|
if (dau_vport_to_port(pnet->vport, &unit, &port) != E_NONE)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_DEBUG, "Pkt port %d error!\r\n", pnet->vport);
|
|
|
|
|
return E_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pd_config.config_port[unit][port].vport = pnet->vport;
|
|
|
|
|
pd_config.config_port[unit][port].type = pnet->channel_type;
|
|
|
|
|
pd_config.config_port[unit][port].filter_frequency = pnet->filter_frequency;
|
|
|
|
|
pd_config.config_port[unit][port].rise_time = pnet->rise_time;
|
|
|
|
|
pd_config.config_port[unit][port].peak_time = pnet->peak_time;
|
|
|
|
|
pd_config.config_port[unit][port].fall_time = pnet->fall_time;
|
|
|
|
|
pd_config.config_port[unit][port].pulse_width = pnet->pulse_width;
|
|
|
|
|
pd_config.config_port[unit][port].peak_count = pnet->peak_count;
|
|
|
|
|
pd_config.config_port[unit][port].signal_envelope = pnet->signal_envelope;
|
|
|
|
|
pd_config.config_port[unit][port].signal_mean = pnet->signal_mean;
|
|
|
|
|
pd_config.config_port[unit][port].signal_variance = pnet->signal_variance;
|
|
|
|
|
pd_config.config_port[unit][port].primary_frequency = pnet->primary_frequency;
|
|
|
|
|
pd_config.config_port[unit][port].primary_freq_peak = pnet->primary_freq_peak;
|
|
|
|
|
pd_config.config_port[unit][port].spectral_peak_count = pnet->spectral_peak_count;
|
|
|
|
|
pd_config.config_port[unit][port].spectrum_mean = pnet->spectrum_mean;
|
|
|
|
|
pd_config.config_port[unit][port].spectrum_variance = pnet->spectrum_variance;
|
|
|
|
|
|
|
|
|
|
vtysh_config_save();
|
|
|
|
|
_debug_pkt_common_send(pkt, DEBUG_CONFIG_PORT_SET, 0);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 查询用户参数查询报文处理. */
|
|
|
|
|
int32_t _debug_pkt_port_cfg_get(char *pkt, int len)
|
|
|
|
|
{
|
|
|
|
|
dbg_config_port_t *pnet = (dbg_config_port_t *)(pkt + sizeof(dbg_pkt_head_t));
|
|
|
|
|
uint8_t unit = 0;
|
|
|
|
|
uint8_t port = 0;
|
|
|
|
|
|
|
|
|
|
if (dau_vport_to_port(pnet->vport, &unit, &port) != E_NONE)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_DEBUG, "Pkt port %d error!\r\n", pnet->vport);
|
|
|
|
|
return E_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pnet->vport = pd_config.config_port[unit][port].vport;
|
|
|
|
|
pnet->channel_type = pd_config.config_port[unit][port].type;
|
|
|
|
|
pnet->vport = pd_config.config_port[unit][port].vport;
|
|
|
|
|
pnet->channel_type = pd_config.config_port[unit][port].type;
|
|
|
|
|
pnet->filter_frequency = pd_config.config_port[unit][port].filter_frequency;
|
|
|
|
|
pnet->rise_time = pd_config.config_port[unit][port].rise_time;
|
|
|
|
|
pnet->peak_time = pd_config.config_port[unit][port].peak_time;
|
|
|
|
|
pnet->fall_time = pd_config.config_port[unit][port].fall_time;
|
|
|
|
|
pnet->pulse_width = pd_config.config_port[unit][port].pulse_width;
|
|
|
|
|
pnet->peak_count = pd_config.config_port[unit][port].peak_count;
|
|
|
|
|
pnet->signal_envelope = pd_config.config_port[unit][port].signal_envelope;
|
|
|
|
|
pnet->signal_mean = pd_config.config_port[unit][port].signal_mean;
|
|
|
|
|
pnet->signal_variance = pd_config.config_port[unit][port].signal_variance;
|
|
|
|
|
pnet->primary_frequency = pd_config.config_port[unit][port].primary_frequency;
|
|
|
|
|
pnet->primary_freq_peak = pd_config.config_port[unit][port].primary_freq_peak;
|
|
|
|
|
pnet->spectral_peak_count = pd_config.config_port[unit][port].spectral_peak_count;
|
|
|
|
|
pnet->spectrum_mean = pd_config.config_port[unit][port].spectrum_mean;
|
|
|
|
|
pnet->spectrum_variance = pd_config.config_port[unit][port].spectrum_variance;
|
|
|
|
|
_debug_pkt_common_send(pkt, DEBUG_CONFIG_PORT_GET, sizeof(dbg_config_port_t));
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 重启报文处理. */
|
|
|
|
|
int32_t _debug_pkt_reboot(char *buf, int len)
|
|
|
|
|
{
|
|
|
|
|
@ -295,198 +370,98 @@ int32_t _debug_pkt_time_set(char *buf, int len)
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 数据手动设置报文处理. */
|
|
|
|
|
int32_t _debug_pkt_manual_col(char *buf, int len)
|
|
|
|
|
{
|
|
|
|
|
char *flag = buf + sizeof(dbg_pkt_head_t);
|
|
|
|
|
DBG(DBG_M_DEBUG, " 手动采集 flag : %d\r\n", (*flag) ? TRUE : FALSE);
|
|
|
|
|
|
|
|
|
|
/* 修改标志位. */
|
|
|
|
|
debug_ctrl.is_manual_col = (*flag) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
|
|
/* 发送数据. */
|
|
|
|
|
return _debug_pkt_common_send(buf, DEBUG_NOISE_CAREFOR, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 获取校准系数报文处理. */
|
|
|
|
|
int32_t _debug_pkt_adj_get(char *buf, int len)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/* 获取校准系数报文处理. */
|
|
|
|
|
int32_t _debug_pkt_adj_set(char *buf, int len)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/* 获取运行状态报文处理. */
|
|
|
|
|
int32_t _debug_pkt_status_get(char *buf, int len)
|
|
|
|
|
{
|
|
|
|
|
debug_pkt_status_t *status = (debug_pkt_status_t*)(buf + sizeof(debug_pkt_head_t));
|
|
|
|
|
|
|
|
|
|
status->idx = 0;
|
|
|
|
|
status->UTC_TimeScale = time(NULL);
|
|
|
|
|
//status->F50Hz_Frequency = dau_power_frequency_get();
|
|
|
|
|
status->F50Hz_SynStatus = pd_state.sync;
|
|
|
|
|
status->dau_status = dau_connect_get();
|
|
|
|
|
status->sensor_status = 0;
|
|
|
|
|
status->is_server_link = csg.is_connect;
|
|
|
|
|
status->version = version_hex;
|
|
|
|
|
status->communication_time = csg.communication_time;
|
|
|
|
|
debug_pkt_status_t *status = (debug_pkt_status_t*)(buf + sizeof(dbg_pkt_head_t));
|
|
|
|
|
status->utc = time(NULL);
|
|
|
|
|
status->run_time = start_time;
|
|
|
|
|
status->is_server_link = csg.is_connect;
|
|
|
|
|
_debug_pkt_common_send(buf, DEBUG_DEVICE_STATUS, sizeof(debug_pkt_status_t));
|
|
|
|
|
|
|
|
|
|
/* 发送数据. */
|
|
|
|
|
//return _debug_pkt_common_send(buf, DEBUG_RUN_STATUS_GET, sizeof(debug_pkt_status_t));
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 获取运行状态报文处理. */
|
|
|
|
|
int32_t _debug_pkt_dev_connect_status_get(char *buf, int len)
|
|
|
|
|
{
|
|
|
|
|
debug_pkt_dev_connect_status_t *status = (debug_pkt_dev_connect_status_t*)(buf + sizeof(dbg_pkt_head_t));
|
|
|
|
|
|
|
|
|
|
status->csg_connect_status = csg.is_connect;
|
|
|
|
|
|
|
|
|
|
DBG(DBG_M_DEBUG, " ec20_connect_status %d\r\n", status->ec20_connect_status);
|
|
|
|
|
DBG(DBG_M_DEBUG, " csg_connect_status %d\r\n", status->csg_connect_status);
|
|
|
|
|
/* 发送数据. */
|
|
|
|
|
return _debug_pkt_common_send(buf, DEBUG_DEVICE_STATUS, sizeof(debug_pkt_dev_connect_status_t));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* CMU 升级报文处理. */
|
|
|
|
|
int32_t _debug_pkt_mcu_upgrade(char *buf, int len)
|
|
|
|
|
int32_t _debug_pkt_upgrade(char *pkt, int len)
|
|
|
|
|
{
|
|
|
|
|
dbg_pkt_head_t *head = (dbg_pkt_head_t*)buf;
|
|
|
|
|
char *type = buf + sizeof(dbg_pkt_head_t);
|
|
|
|
|
DBG(DBG_M_DEBUG, "upgrade type is %d\r\n", type[0]);
|
|
|
|
|
char *data = buf + sizeof(dbg_pkt_head_t) + 1;
|
|
|
|
|
|
|
|
|
|
static int fd = -1;
|
|
|
|
|
static uint32_t fix_len = 0;
|
|
|
|
|
dbg_upgrade_data_t *head_msg = (dbg_upgrade_data_t*)(pkt + sizeof(dbg_pkt_head_t));
|
|
|
|
|
char *pdata = pkt + sizeof(dbg_pkt_head_t) + sizeof(dbg_upgrade_data_t);
|
|
|
|
|
dbg_upgrade_ack_t *pack = (dbg_upgrade_ack_t*)(pkt + sizeof(dbg_pkt_head_t));
|
|
|
|
|
int32_t size = 0;
|
|
|
|
|
int32_t len_wr = 0;
|
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
|
|
csg.is_connect = FALSE; //关闭主动上传
|
|
|
|
|
/* 首保处理, 打开文件描述符, 初始化变量 */
|
|
|
|
|
if (head_msg->index == 0)
|
|
|
|
|
{
|
|
|
|
|
if (fd > 0)
|
|
|
|
|
{
|
|
|
|
|
close(fd);
|
|
|
|
|
fd = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int fd = 0;
|
|
|
|
|
fd = open(PD_UPG_SOFTWARE, O_WRONLY | O_CREAT | O_TRUNC, 0777);
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_DEBUG, "Open file " PD_UPG_SOFTWARE " error!\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
}
|
|
|
|
|
fix_len = head_msg->len;
|
|
|
|
|
|
|
|
|
|
/* 保存文件. */
|
|
|
|
|
fd = open(DEBUG_CMU_FILE_UPGRADE, O_WRONLY | O_CREAT | O_TRUNC, 0777);
|
|
|
|
|
if (fd <= 0)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_ERR, "Open " DEBUG_CMU_FILE_UPGRADE " ERROR\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
DBG(DBG_M_DEBUG, "Receive upgrade file start.\r\n");
|
|
|
|
|
}
|
|
|
|
|
DBG(DBG_M_DEBUG,"type=%d,sum=%d,index=%d,len=%d,fix_len=%d\r\n", head_msg->type, head_msg->sum, head_msg->index, head_msg->len, fix_len);
|
|
|
|
|
|
|
|
|
|
if (write(fd, data, head->len) != head->len)
|
|
|
|
|
/* 收包流程 */
|
|
|
|
|
size = head_msg->len;
|
|
|
|
|
offset = head_msg->index * fix_len;
|
|
|
|
|
if (lseek(fd, offset, SEEK_SET) < 0)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_ERR, "Write " DEBUG_CMU_FILE_UPGRADE " ERROR\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
}
|
|
|
|
|
close(fd);
|
|
|
|
|
int error = errno;
|
|
|
|
|
DBG(DBG_M_PD_CSG_ERR, "lseek file " PD_UPG_SOFTWARE " error: %s, fd=%d, offset=%ld\r\n",
|
|
|
|
|
strerror(error), fd, offset);
|
|
|
|
|
|
|
|
|
|
//保存旧文件
|
|
|
|
|
if (rename(DEBUG_CMU_FILE, DEBUG_CMU_FILE_BAK) < 0)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_ERR, "Rename " DEBUG_CMU_FILE_BAK " ERROR\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
}
|
|
|
|
|
// 升级新文件
|
|
|
|
|
if (rename(DEBUG_CMU_FILE_UPGRADE, DEBUG_CMU_FILE) < 0)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_ERR, "Rename " DEBUG_CMU_FILE_UPGRADE " ERROR\r\n");
|
|
|
|
|
// 检查具体错误类型
|
|
|
|
|
switch(error) {
|
|
|
|
|
case EBADF: // 无效文件描述符
|
|
|
|
|
DBG(DBG_M_DEBUG, "Invalid file descriptor\r\n");
|
|
|
|
|
break;
|
|
|
|
|
case EINVAL: // 无效的 whence 或 offset
|
|
|
|
|
DBG(DBG_M_DEBUG, "Invalid offset or whence\r\n");
|
|
|
|
|
break;
|
|
|
|
|
case EOVERFLOW: // offset 过大
|
|
|
|
|
DBG(DBG_M_DEBUG, "Offset overflow\r\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 发送回复. */
|
|
|
|
|
_debug_pkt_common_send(buf, DEBUG_ARM_UPGRADE, 0);
|
|
|
|
|
|
|
|
|
|
DBG(DBG_M_DEBUG, "reboot_system arm upgrade\r\n");
|
|
|
|
|
|
|
|
|
|
reboot_system(LOG_DEBUG, REBOOT_LOCAL_ARM_UPGRADE);
|
|
|
|
|
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* DAU 升级报文处理. */
|
|
|
|
|
int32_t _debug_pkt_dau_upgrade(char *buf, int len, uint8_t bitmap)
|
|
|
|
|
{
|
|
|
|
|
dbg_pkt_head_t *head = (dbg_pkt_head_t*)buf;
|
|
|
|
|
char *type = buf + sizeof(dbg_pkt_head_t);
|
|
|
|
|
DBG(DBG_M_DEBUG, "upgrade type is %d\r\n", type[0]);
|
|
|
|
|
char *data = buf + sizeof(dbg_pkt_head_t) + 1;
|
|
|
|
|
int fd = 0;
|
|
|
|
|
|
|
|
|
|
fd = open(DEBUG_DAU_FILE_UPGRADE, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
|
|
|
|
if (fd <= 0)
|
|
|
|
|
len_wr = write(fd, pdata, size);
|
|
|
|
|
if (len_wr != size)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_DEBUG, "Open " DEBUG_DAU_FILE_UPGRADE " ERROR\r\n");
|
|
|
|
|
DBG(DBG_M_DEBUG, "Write file " PD_UPG_SOFTWARE " error!\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (write(fd, data, head->len) != head->len)
|
|
|
|
|
/* 最后一个报文处理 */
|
|
|
|
|
if (head_msg->sum - 1 == head_msg->index)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_DEBUG, "Write " DEBUG_DAU_FILE_UPGRADE " ERROR\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
}
|
|
|
|
|
close(fd);
|
|
|
|
|
//保存旧文件
|
|
|
|
|
if (rename(DEBUG_DAU_FILE, DEBUG_DAU_FILE_BAK) < 0)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_ERR, "Rename " DEBUG_CMU_FILE_BAK " ERROR\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
}
|
|
|
|
|
// 升级新文件
|
|
|
|
|
if (rename(DEBUG_DAU_FILE_UPGRADE, DEBUG_DAU_FILE) < 0)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_ERR, "Rename " DEBUG_CMU_FILE_UPGRADE " ERROR\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
close(fd);
|
|
|
|
|
fd = -1;
|
|
|
|
|
DBG(DBG_M_DEBUG, "Receive upgrade file end.\r\n");
|
|
|
|
|
pd_upg_start(PD_UPG_FROM_CSG, head_msg->type);
|
|
|
|
|
}
|
|
|
|
|
pack->index = head_msg->index;
|
|
|
|
|
|
|
|
|
|
DBG(DBG_M_DEBUG, "reboot_system dau upgrade\r\n");
|
|
|
|
|
_debug_pkt_common_send(buf, head->cmd, 1);
|
|
|
|
|
|
|
|
|
|
reboot_system(LOG_DEBUG, REBOOT_LOCAL_ARM_UPGRADE);
|
|
|
|
|
/* 发送应答 */
|
|
|
|
|
_debug_pkt_common_send(pkt, DEBUG_UPGRADE_DATA, sizeof(dbg_upgrade_ack_t));
|
|
|
|
|
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t _debug_all_upgrade(char *buf, int len)
|
|
|
|
|
{
|
|
|
|
|
dbg_pkt_head_t *head = (dbg_pkt_head_t*)buf;
|
|
|
|
|
char *data = buf + sizeof(dbg_pkt_head_t);
|
|
|
|
|
uint8_t type = 0;
|
|
|
|
|
int32_t *rt = (int32_t*)data;
|
|
|
|
|
int fd = 0;
|
|
|
|
|
int32_t rv = 0;
|
|
|
|
|
|
|
|
|
|
if (buf == NULL)
|
|
|
|
|
{
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 获取升级类型, 更新数据指针 */
|
|
|
|
|
type = *data;
|
|
|
|
|
data++;
|
|
|
|
|
|
|
|
|
|
/* 保存文件 */
|
|
|
|
|
fd = open(PD_UPG_SOFTWARE, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
|
|
|
|
if (fd <= 0)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_DEBUG, "Open " PD_UPG_SOFTWARE " ERROR\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (write(fd, data, head->len - 1) != (head->len - 1))
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_DEBUG, "Write " PD_UPG_SOFTWARE " ERROR\r\n");
|
|
|
|
|
return E_SYS_CALL;
|
|
|
|
|
}
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
/* 升级 */
|
|
|
|
|
rv = pd_upg_start(PD_UPG_FROM_DBG, type);
|
|
|
|
|
if (rv != E_NONE)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_DEBUG, "Write " PD_UPG_SOFTWARE " ERROR\r\n");
|
|
|
|
|
*rt = 1;
|
|
|
|
|
_debug_pkt_common_send(buf, head->cmd, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 报文校验. */
|
|
|
|
|
@ -546,10 +521,6 @@ int32_t _debug_pkt_process(char *buf, int32_t len)
|
|
|
|
|
_debug_pkt_port_cfg_set(buf, len);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DEBUG_NOISE_CAREFOR:
|
|
|
|
|
_debug_pkt_manual_col(buf, len);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DEBUG_REBOOT:
|
|
|
|
|
_debug_pkt_reboot(buf, len);
|
|
|
|
|
break;
|
|
|
|
|
@ -557,26 +528,12 @@ int32_t _debug_pkt_process(char *buf, int32_t len)
|
|
|
|
|
_debug_pkt_time_set(buf, len);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DEBUG_ADJSUT_COEFFICIENT_GET:
|
|
|
|
|
_debug_pkt_adj_get(buf, len);
|
|
|
|
|
break;
|
|
|
|
|
case DEBUG_ADJSUT_COEFFICIENT_SET:
|
|
|
|
|
_debug_pkt_adj_set(buf, len);
|
|
|
|
|
break;
|
|
|
|
|
case DEBUG_DEVICE_STATUS:
|
|
|
|
|
_debug_pkt_dev_connect_status_get(buf, len);
|
|
|
|
|
break;
|
|
|
|
|
case DEBUG_ARM_UPGRADE:
|
|
|
|
|
_debug_pkt_mcu_upgrade(buf, len);
|
|
|
|
|
_debug_pkt_status_get(buf, len);
|
|
|
|
|
break;
|
|
|
|
|
case DEBUG_FPGA1_UPGRADE:
|
|
|
|
|
_debug_pkt_dau_upgrade(buf, len, 0x01);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DEBUG_UPGRADE_ALL:
|
|
|
|
|
_debug_all_upgrade(buf, len);
|
|
|
|
|
case DEBUG_UPGRADE_DATA:
|
|
|
|
|
_debug_pkt_upgrade(buf, len);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
DBG(DBG_M_DEBUG, "Debug not support cmd:%x\n", head->cmd);
|
|
|
|
|
break;
|
|
|
|
|
@ -611,7 +568,7 @@ int32_t _debug_pkt_recv_adhesion(char *buf, int len, int *len_recv)
|
|
|
|
|
state = 1;
|
|
|
|
|
|
|
|
|
|
/* 计算剩余报文长度, 复制数据, 并计算收包总长度. */
|
|
|
|
|
len_pkt = head->len + 10 - len;
|
|
|
|
|
len_pkt = head->len + 32 - len;
|
|
|
|
|
memcpy(buf_cmd + bytes_cnt, buf, len);
|
|
|
|
|
bytes_cnt += len;
|
|
|
|
|
|
|
|
|
|
@ -648,6 +605,7 @@ int32_t _debug_pkt_recv_adhesion(char *buf, int len, int *len_recv)
|
|
|
|
|
{
|
|
|
|
|
*len_recv = len_pkt;
|
|
|
|
|
}
|
|
|
|
|
printf("@2len_pkt=%d\n", len_pkt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 报文没有收全, 继续等待数据. */
|
|
|
|
|
@ -711,7 +669,6 @@ void *_debug_pkt_recv_handle(void *arg)
|
|
|
|
|
{
|
|
|
|
|
/* 连接中断, 关闭 socket 和手动采样. */
|
|
|
|
|
DBG(DBG_M_DEBUG, "Read len %d, close fd!\r\n", len);
|
|
|
|
|
debug_ctrl.is_manual_col = FALSE;
|
|
|
|
|
close(debug_ctrl.fd_client);
|
|
|
|
|
debug_ctrl.fd_client = -1;
|
|
|
|
|
break;
|
|
|
|
|
@ -791,9 +748,9 @@ void *_debug_accept_connect_handle()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char buf[20] = {0};
|
|
|
|
|
DBG(DBG_M_DEBUG, "new client: %s, port: %d\n",
|
|
|
|
|
DBG(DBG_M_DEBUG, "new client: %s, port: %d fd_client=%d\n",
|
|
|
|
|
inet_ntop(AF_INET, &cliaddr.sin_addr, buf, sizeof(buf)),
|
|
|
|
|
ntohs(cliaddr.sin_port));
|
|
|
|
|
ntohs(cliaddr.sin_port), debug_ctrl.fd_client);
|
|
|
|
|
|
|
|
|
|
if (debug_ctrl.fd_client < 0)
|
|
|
|
|
{
|
|
|
|
|
@ -811,20 +768,6 @@ void *_debug_accept_connect_handle()
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 用于定时将端口的状态发送给调试软件. */
|
|
|
|
|
void* _debug_port_state_get(void *arg)
|
|
|
|
|
{
|
|
|
|
|
/* 如果手动采样开启, 则发送数据. */
|
|
|
|
|
if (debug_ctrl.is_manual_col)
|
|
|
|
|
{
|
|
|
|
|
debug_pkt_port_state_post();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 重新加入定时器. */
|
|
|
|
|
mtimer_add(_debug_port_state_get, NULL, 1, "DEBUG_PORT_STATE_GET");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Interface functions -------------------------------------------------------*/
|
|
|
|
|
/* 调试工具初始化. */
|
|
|
|
|
int32_t debug_handle_init(void)
|
|
|
|
|
@ -886,25 +829,17 @@ int32_t debug_handle_init_after(void)
|
|
|
|
|
thread_m_add("PD_DEBUG_ACCEPT", pid);
|
|
|
|
|
}
|
|
|
|
|
pthread_attr_destroy(&attr);
|
|
|
|
|
|
|
|
|
|
/* 每秒上传 DAU 状态寄存器. */
|
|
|
|
|
mtimer_add(_debug_port_state_get, NULL, 1, "DEBUG_PORT_STATE_GET");
|
|
|
|
|
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 数据手动上传报文处理. */
|
|
|
|
|
int32_t debug_pkt_port_state_post(void)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/* 升级结果回复处理 */
|
|
|
|
|
void debug_upgrade_result_send(int32_t rv, char *buf)
|
|
|
|
|
{
|
|
|
|
|
char buffer[32] = {0};
|
|
|
|
|
int32_t *rt = (int32_t*)(buffer + sizeof(debug_pkt_head_t));
|
|
|
|
|
int32_t *rt = (int32_t*)(buffer + sizeof(dbg_pkt_head_t));
|
|
|
|
|
|
|
|
|
|
*rt = rv;
|
|
|
|
|
_debug_pkt_common_send(buffer, DEBUG_UPGRADE_ALL, 4);
|
|
|
|
|
_debug_pkt_common_send(buffer, 0, 4);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****************/
|
|
|
|
|
|