FIX 1.升级优化;

main
wangbo 1 month ago
parent 12dc851e46
commit 74c69befe9

@ -38,6 +38,7 @@
#define _DBG_H_
/* Includes ------------------------------------------------------------------*/
#include "common.h"
/* Define --------------------------------------------------------------------*/
#define DBG_HELP_STR_MAX 32
@ -102,9 +103,16 @@ typedef struct
do { \
if (_dbg_module[_MODULE_].stat) printh(_format_, ##_msg_); \
} while(0)
#define DBG_ARRAY(_MODULE_, _msg_...) \
do { \
if (dbg_stat_get(_MODULE_)) { \
buf_print(_msg_); \
}\
} while(0)
#else
#define DBG(_MODULE_, _msg_...)
#define DBG(_MODULE_, _format_, _msg_...)
#define DBG_ARRAY(_MODULE_, _msg_...)
#endif
/* Extern global variables ---------------------------------------------------*/

@ -145,6 +145,18 @@ CMD(csg_show,
return CMD_SUCCESS;
}
CMD(csg_upgrade_test,
csg_upgrade_test_cmd,
"upgrade test",
"Upgrade\n"
"Test\n")
{
pd_upg_start(PD_UPG_FROM_CSG, 1);
return CMD_SUCCESS;
}
void _print_sockaddr_in(const struct sockaddr_in *addr)
{
@ -379,9 +391,8 @@ void _csg_add_dau_recv(char *pkt)
return;
}
slot--;
log_out(LOG_CSG, LOG_LVL_WARN, "_csg_add_dau_recv slot = %d\n", slot);
daus[slot].state.is_insert = TRUE;
daus[slot-1].state.is_insert = TRUE;
}
void _csg_remove_dau_recv(char *pkt)
@ -394,10 +405,9 @@ void _csg_remove_dau_recv(char *pkt)
return;
}
slot--;
log_out(LOG_CSG, LOG_LVL_WARN, "_csg_remove_dau_recv slot = %d\n", slot);
daus[slot].state.is_insert = FALSE;
daus[slot].state.is_connect = FALSE;
daus[slot-1].state.is_insert = FALSE;
daus[slot-1].state.is_connect = FALSE;
}
@ -406,7 +416,7 @@ void _csg_heartbeat_recv(char *pkt)
{
uint32_t server_time = *(uint32_t*)(pkt + sizeof(csg_pkt_head_t));
//printf("server_time:%d now:%ld\n", server_time, time(NULL));
DBG(DBG_M_PD_CSG, "server_time:%d now:%ld\n", server_time, time(NULL));
if (abs(server_time - time(NULL)) > 3)
{
time_set(server_time); //北京时间
@ -421,7 +431,7 @@ int32_t _csg_reboot_recv(char *pkt)
uint8_t slot = head->slot;
if (slot > PD_SLOTS_MAX)
{
DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot);
DBG(DBG_M_PD_CSG_ERR, "slot:%d error\r\n", head->slot);
return E_BAD_PARAM;
}
@ -463,7 +473,7 @@ int32_t _csg_dev_info_set_recv(char *pkt)
uint8_t slot = head->slot;
if (slot > PD_SLOTS_MAX)
{
DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot);
DBG(DBG_M_PD_CSG_ERR, "slot:%d error\r\n", head->slot);
return E_BAD_PARAM;
}
@ -527,7 +537,7 @@ int32_t _csg_dev_info_get_recv(char *pkt)
uint8_t slot = head->slot;
if (slot > PD_SLOTS_MAX)
{
DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot);
DBG(DBG_M_PD_CSG_ERR, "slot:%d error\r\n", head->slot);
return E_BAD_PARAM;
}
@ -580,7 +590,7 @@ int32_t _csg_config_set_recv(char *pkt)
uint8_t slot = head->slot;
if (slot > PD_SLOTS_MAX)
{
DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot);
DBG(DBG_M_PD_CSG_ERR, "slot:%d error\r\n", head->slot);
return E_BAD_PARAM;
}
@ -630,10 +640,10 @@ int32_t _csg_config_get_recv(char *pkt)
{
csg_pkt_head_t *head = (csg_pkt_head_t*)pkt;
int *data = NULL;
uint8_t slot = head->slot - 1;
uint8_t slot = head->slot;
if (slot > PD_SLOTS_MAX)
{
DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot);
DBG(DBG_M_PD_CSG_ERR, "slot:%d error\r\n", head->slot);
return E_BAD_PARAM;
}
@ -678,7 +688,7 @@ int32_t _csg_port_config_set_recv(char *pkt)
uint8_t slot = head->slot;
if (slot > PD_SLOTS_MAX && slot != 0)
{
DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot);
DBG(DBG_M_PD_CSG_ERR, "slot:%d error\r\n", head->slot);
return E_BAD_PARAM;
}
DBG(DBG_M_PD_CSG, "_csg_port_config_set_recv slot:%d \r\n", head->slot);
@ -707,7 +717,7 @@ int32_t _csg_port_config_get_recv(char *pkt)
uint8_t slot = head->slot;
if (slot > PD_SLOTS_MAX && slot != 0)
{
DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot);
DBG(DBG_M_PD_CSG_ERR, "slot:%d error\r\n", head->slot);
return E_BAD_PARAM;
}
@ -735,9 +745,10 @@ int32_t _csg_real_image_recv(char *pkt)
uint8_t slot = head->slot;
if (slot > PD_SLOTS_MAX && slot != 0)
{
DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot);
DBG(DBG_M_PD_CSG_ERR, "slot:%d error\r\n", head->slot);
return E_BAD_PARAM;
}
DBG(DBG_M_PD_CSG, "_csg_real_image_recv slot:%d \r\n", head->slot);
data = XMALLOC(MTYPE_CSG, sizeof(csg_real_image_get_t));
if (!data)
@ -745,7 +756,8 @@ int32_t _csg_real_image_recv(char *pkt)
DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n");
return E_MEM;
}
param->vport = param->vport % 8;
memcpy(data, param, sizeof(csg_real_image_get_t));
if (_csg_msg_send_dau(slot - 1, DAU_SEND_PRPS_GET, data) != E_NONE)
{
@ -803,8 +815,8 @@ int32_t _csg_update_slot(uint8_t type)
{
dau = &daus[slot];
if (dau->info.type_m == 0x03 && (dau->info.type_s == 0x01
|| dau->info.type_s == 0x02
|| dau->info.type_s == 0x03))
|| dau->info.type_s == 0x02
|| dau->info.type_s == 0x03))
{
data = XMALLOC(MTYPE_CSG, sizeof(csg_upate_msg_t));
if (!data)
@ -823,14 +835,15 @@ int32_t _csg_update_slot(uint8_t type)
return E_ERROR;
}
snprintf(data->name, 128, "%s/%s", buff, PD_UPG_SOFTWARE);
DBG(DBG_M_PD_CSG_ERR, "upgrade name:%s slot=%d\r\n", data->name, slot);
if (_csg_msg_send_dau(slot, DAU_SEND_UPDATE, data) != E_NONE)
{
XFREE(MTYPE_CSG, data);
}
}
}
return ENABLE_NODE;
return E_NONE;
}
/* 升级文件接收 */
@ -915,6 +928,30 @@ int32_t _csg_slot_match(uint8_t slot, uint8_t *type_m, uint8_t *type_s)
*type_s = types;
return E_NONE;
}
int32_t _csg_slot_is_valid(char *pkt, uint8_t *type_m, uint8_t *type_s)
{
csg_pkt_head_t *head = (csg_pkt_head_t *)pkt;
uint8_t slot = head->slot - 1;
uint8_t cmd = head->cmd;
dau_t *dau = &daus[slot];
// 如果相应卡槽不存在,暂时先不回复平台
if ( dau->state.is_insert == FALSE && cmd != CSG_C_ADD_DAU)
{
//char *pkt = csg.buf_send;
//csg_ack_t ack = {0};
//ack.result = FALSE;
//memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t));
//_csg_send_data(head->cmd_type, head->cmd, pkt, sizeof(csg_ack_t), slot + 1);
return E_ERROR;
}
*type_m = dau->info.type_m;
*type_s = dau->info.type_s;
return E_NONE;
}
int32_t _csg_recv_process(char *pkt, uint32_t len)
{
@ -925,10 +962,13 @@ int32_t _csg_recv_process(char *pkt, uint32_t len)
LD_E_RETURN(DBG_M_PD_CSG_ERR, _csg_pkt_check(pkt));
csg.heartbeat_timeout_cnt = 0;
if (_csg_slot_match(head->slot - 1, &typem, &types) != E_NONE)
if (head->slot > 0)
{
DBG(DBG_M_PD_CSG_ERR, "Invalid slot=%d typem=%d types=%d\n", head->slot, typem, types);
return E_ERROR;
if (_csg_slot_is_valid(pkt, &typem, &types) != E_NONE)
{
DBG(DBG_M_PD_CSG_ERR, "Invalid slot=%d\n", head->slot);
return E_ERROR;
}
}
if (DEVICE_M_TYPE == typem && DEVICE_IR_TYPE == types
@ -2296,7 +2336,8 @@ void *_csg_heartbeat_handle(void *arg)
if (dau->state.is_connect == TRUE
&& dau->state.is_insert != TRUE)
{
if (dau->info.type_m == 0x03 && dau->info.type_m == 0x04)
if (dau->info.type_m == 0x03 && (dau->info.type_s == 0x04
|| dau->info.type_s == 0x05))
{
csg_contact_t info = {0};
info.type_m = dau->info.type_m;
@ -2365,6 +2406,7 @@ int32_t csg_handle_init(void)
cmd_install_element(CONFIG_NODE, &csg_server_set_cmd);
cmd_install_element(COMMON_NODE, &csg_show_cmd);
cmd_install_element(COMMON_NODE, &csg_upgrade_test_cmd);
/* 注册配置保存函数 */
rv = cmd_config_node_config_register(CONFIG_PRI_CSG, _csg_config_save);

@ -492,7 +492,7 @@ void *_dau_state_handle(void *arg)
state->beat_cnt++;
if (state->beat_cnt > pd_config.config_slot[i].timeout * 60)
{
log_warn(LOG_DAU, "Slot %d remove!", i);
log_warn(LOG_DAU, "Slot %d remove!", i + 1);
_dau_remove(&daus[i]);
}
}

@ -19,11 +19,11 @@ modbus_t modbus;
void _modbus_show(void)
{
card_t *pcard = NULL;
printh("ID ST \r\n");
printh("UNIT STATUS CURRENT ALARM\r\n");
for (int slot = 0; slot < PD_SLOTS_MAX; slot++)
{
pcard = &modbus.card[slot];
printh("%-02d %-02d \r\n", pcard->unit_id, pcard->status);
printh("%-04d %3d %8d %6d\r\n", pcard->unit_id, pcard->status, pcard->current, pcard->alarm);
}
}
@ -71,8 +71,8 @@ int32_t _modbus_tcp_transaction(uint8_t unit_id, uint16_t start_addr, uint16_t d
return E_ERROR;
}
//DBG(DBG_M_PD_MODBUS, "Modbus write len = %d\r\n", txlen);
//buf_print((char *)modbus.txbuf, txlen);
DBG(DBG_M_PD_MODBUS, "Modbus write len = %d\r\n", txlen);
DBG_ARRAY(DBG_M_PD_MODBUS, (char *)modbus.txbuf, txlen);
// 等待传输完成
usleep(13000); // 13000
@ -83,8 +83,8 @@ int32_t _modbus_tcp_transaction(uint8_t unit_id, uint16_t start_addr, uint16_t d
{
uint16_t length;
//DBG(DBG_M_PD_MODBUS, "Modbus read len = %d\r\n", rxlen);
//buf_print((char *)modbus.rxbuf, rxlen);
DBG(DBG_M_PD_MODBUS, "Modbus read len = %d\r\n", rxlen);
DBG_ARRAY(DBG_M_PD_MODBUS, (char *)modbus.rxbuf, rxlen);
length = modbus.rxbuf[POS_DATA_LEN] << 8;
length += modbus.rxbuf[POS_DATA_LEN + 1];
@ -142,8 +142,9 @@ int32_t _modbus_get_device_type(uint8_t unit, uint8_t *typem, uint8_t *types)
{
*typem = modbus.rxbuf[9];
*types = modbus.rxbuf[10];
return E_NONE;
}
return E_NONE;
return E_ERROR;
}
int32_t _modbus_get_current(uint8_t unit, uint16_t addr, uint16_t len, uint32_t *current)
@ -184,18 +185,27 @@ void _modbus_read_slot_stat(card_t *pcard)
ptmp = pcard;
gpio_val_get(gpio_dau1_idx, &ptmp->status);
ptmp++;
gpio_val_get(gpio_dau2_idx, &ptmp->status);
ptmp++;
gpio_val_get(gpio_dau3_idx, &ptmp->status);
ptmp++;
gpio_val_get(gpio_dau4_idx, &ptmp->status);
ptmp++;
gpio_val_get(gpio_dau5_idx, &ptmp->status);
ptmp++;
gpio_val_get(gpio_dau6_idx, &ptmp->status);
}
void crash() {
int *ptr = NULL;
*ptr = 42; // 故意触发段错误
}
void *_modbus_send_handle()
{
@ -207,12 +217,16 @@ void *_modbus_send_handle()
for (int slot = 0; slot < PD_SLOTS_MAX; slot++)
{
pcard = &modbus.card[slot];
dau = &daus[slot];
//DBG(DBG_M_PD_MODBUS, "slot%d unit_id:%d status:%d\n", slot, pcard->unit_id, pcard->status);
if (pcard->status)
{
_modbus_get_device_type(pcard->unit_id, &dau->info.type_m, &dau->info.type_s);
//DBG(DBG_M_PD_MODBUS, "typem:%d types:%d\n", dau->info.type_m, dau->info.type_s);
sleep(1);
if (_modbus_get_device_type(pcard->unit_id, &dau->info.type_m, &dau->info.type_s) != E_NONE)
continue;
//DBG(DBG_M_PD_MODBUS, "slot%d typem:%d types:%d\n", slot, dau->info.type_m, dau->info.type_s);
if (DEVICE_IR_TYPE == dau->info.type_s && DEVICE_M_TYPE == dau->info.type_m)
{
@ -221,11 +235,9 @@ void *_modbus_send_handle()
sleep(1);
_modbus_get_current(pcard->unit_id,
MODBUS_IR_CURRENT_ADDR, MODBUS_IR_CURRENT_LEN, &pcard->current);
//DBG(DBG_M_PD_MODBUS, "current:%d\n", pcard->current);
_modbus_get_alarm(pcard->unit_id,
MODBUS_IR_ALARM_ADDR, MODBUS_IR_ALARM_LEN, &pcard->alarm);
//DBG(DBG_M_PD_MODBUS, "alarm:%d\n", pcard->alarm);
}
else if (DEVICE_DC_TYPE == dau->info.type_s && DEVICE_M_TYPE == dau->info.type_m)
{
@ -234,7 +246,16 @@ void *_modbus_send_handle()
sleep(1);
_modbus_get_current(pcard->unit_id,
MODBUS_DC_CURRENT_ADDR, MODBUS_DC_CURRENT_LEN, &pcard->current);
//DBG(DBG_M_PD_MODBUS, "current:%d\n", pcard->current);
}
}
else
{
if (DEVICE_M_TYPE == dau->info.type_m &&
(DEVICE_IR_TYPE == dau->info.type_s || DEVICE_DC_TYPE == dau->info.type_s))
{
dau->state.beat_cnt = 0;
dau->state.is_connect = FALSE;
dau->state.is_insert = FALSE;
}
}
}

@ -59,7 +59,8 @@
/* Private define ------------------------------------------------------------*/
#define PD_UPG_READ_SIZE (1024*1024)
#define PD_UPG_HARDWARE_VERSON "GIS-cmu"
#define PD_UPG_HARDWARE_CMU_VERSON "GIScmu"
#define PD_UPG_HARDWARE_GIS_VERSON "GIS7.0"
#define PD_UPG_DAU_FILE "/lib/firmware/system_wrapper.bin"
/* Private macro -------------------------------------------------------------*/
@ -309,16 +310,18 @@ int32_t _pd_upg_upgrade(void)
return: E_NONE - , E_XXXX - */
int32_t _pd_upg_hardware_check(void)
{
if (strncmp(pd_upg_ctrl.head.hard_ver, PD_UPG_HARDWARE_VERSON, strlen(PD_UPG_HARDWARE_VERSON)))
if (strncmp(pd_upg_ctrl.head.hard_ver, PD_UPG_HARDWARE_CMU_VERSON, strlen(PD_UPG_HARDWARE_CMU_VERSON)) == 0)
{
DBG(DBG_M_PD_UPGRADE, "Hardware version(%s) not match\n", pd_upg_ctrl.head.hard_ver);
return E_ERROR;
}
else
else if (strncmp(pd_upg_ctrl.head.hard_ver, PD_UPG_HARDWARE_GIS_VERSON, strlen(PD_UPG_HARDWARE_GIS_VERSON)) == 0)
{
pd_upg_ctrl.upgrade_slot = _csg_update_slot;
}
else
{
DBG(DBG_M_PD_UPGRADE, "Hardware version(%s) not match\n", pd_upg_ctrl.head.hard_ver);
return E_ERROR;
}
return E_NONE;
}
@ -426,6 +429,7 @@ void *_pd_upg_handle(void *parm)
{
char cmd[128] = {0};
int32_t rv = E_ERROR;
int32_t upgrade_flag = 0;
while(1)
{
@ -439,18 +443,27 @@ void *_pd_upg_handle(void *parm)
if (pd_upg_ctrl.upgrade_slot)
{
pd_upg_ctrl.upgrade_slot(pd_upg_ctrl.upg_type);
upgrade_flag = 1;
}
/* 升级系统 */
rv = _pd_upg_upgrade();
if (rv != E_NONE)
else
{
break;
/* 升级系统 */
rv = _pd_upg_upgrade();
if (rv != E_NONE)
{
break;
}
}
break;
}
if (upgrade_flag)
{
pd_upg_ctrl.is_start = FALSE;
pthread_exit(NULL);
return NULL;
}
/* 保存升级原始文件 */
snprintf(cmd, 128, "mv " PD_UPG_SOFTWARE " bak");
_pd_upg_system(cmd);

@ -73,8 +73,8 @@ dbg_module_t _dbg_module[DBG_M_COUNT] =
{DBG_M_PD_HF, FALSE, "pd_hf"},
{DBG_M_PD_HF_ERR, TRUE, "pd_hf_err"},
{DBG_M_SERIAL, FALSE, "serial"},
{DBG_M_PD_MODBUS, TRUE, "pd_modbus"},
{DBG_M_PD_MODBUS_ERR, TRUE, "pd_modbus_err"},
{DBG_M_PD_MODBUS, FALSE, "modbus"},
{DBG_M_PD_MODBUS_ERR, FALSE, "modbus_err"},
{DBG_M_FILE_FIFO, TRUE, "file_fifo"},
{DBG_M_FILE_FIFO_ERR, TRUE, "file_fifo_err"},
};

Loading…
Cancel
Save