|
|
|
@ -79,19 +79,20 @@ csg_t csg;
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
|
void _csg_server_set(int32_t ip, uint16_t port);
|
|
|
|
|
void _csg_show();
|
|
|
|
|
void _csg_send_add_dau(uint8_t slot, void *data);
|
|
|
|
|
void _csg_send_reset(uint8_t, void *data);
|
|
|
|
|
void _csg_send_info_set(uint8_t, void *data);
|
|
|
|
|
void _csg_send_info_get(uint8_t, void *data);
|
|
|
|
|
void _csg_send_heartbeat(uint8_t slot, void *data);
|
|
|
|
|
void _csg_send_cfg_set(uint8_t, void *data);
|
|
|
|
|
void _csg_send_cfg_get(uint8_t, void *data);
|
|
|
|
|
void _csg_send_cfg_set_port(uint8_t, void *data);
|
|
|
|
|
void _csg_send_cfg_get_port(uint8_t, void *data);
|
|
|
|
|
void _csg_send_prps_get(uint8_t, void *data);
|
|
|
|
|
void _csg_send_trend_data(uint8_t, void *data);
|
|
|
|
|
void _csg_send_prps_data(uint8_t, void *data);
|
|
|
|
|
void _csg_send_event_data(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_add_dau(uint8_t slot, void *data);
|
|
|
|
|
int32_t _csg_send_reset(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_info_set(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_info_get(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_updata_rv(uint8_t slot, void *data);
|
|
|
|
|
int32_t _csg_send_heartbeat(uint8_t slot, void *data);
|
|
|
|
|
int32_t _csg_send_cfg_set(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_cfg_get(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_cfg_set_port(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_cfg_get_port(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_prps_get(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_trend_data(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_prps_data(uint8_t, void *data);
|
|
|
|
|
int32_t _csg_send_event_data(uint8_t, void *data);
|
|
|
|
|
|
|
|
|
|
// 命令映射表
|
|
|
|
|
static csg_send_fun_cb _csg_send_command[] =
|
|
|
|
@ -102,16 +103,17 @@ static csg_send_fun_cb _csg_send_command[] =
|
|
|
|
|
NULL, // 3
|
|
|
|
|
_csg_send_info_set, // DAU_SEND_INFO_SET 4
|
|
|
|
|
_csg_send_info_get, // DAU_SEND_INFO_GET 5
|
|
|
|
|
NULL, // 6
|
|
|
|
|
_csg_send_updata_rv, // DAU_SEND_UPDATE_RV 6
|
|
|
|
|
_csg_send_heartbeat, // DAU_SEND_HEARTBEAT 7
|
|
|
|
|
_csg_send_cfg_set, // DAU_SEND_CFG_SET 8
|
|
|
|
|
_csg_send_cfg_get, // DAU_SEND_CFG_GET 9
|
|
|
|
|
_csg_send_cfg_set_port, // DAU_SEND_PORT_SET 10
|
|
|
|
|
_csg_send_cfg_get_port, // DAU_SEND_PORT_GET 11
|
|
|
|
|
_csg_send_prps_get, // DAU_SEND_PRPS_GET 12
|
|
|
|
|
NULL, // 13
|
|
|
|
|
_csg_send_trend_data, // DAU_SEND_TREND 13
|
|
|
|
|
_csg_send_prps_data, // DAU_SEND_PRPS 14
|
|
|
|
|
NULL, // 15
|
|
|
|
|
_csg_send_event_data, // DAU_SEND_EVENT 15
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Internal functions --------------------------------------------------------*/
|
|
|
|
@ -597,6 +599,45 @@ int32_t _csg_real_image_recv(char *pkt)
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t _csg_trend_get_recv(char *pkt)
|
|
|
|
|
{
|
|
|
|
|
csg_trend_ack_t *ptrend = (csg_trend_ack_t*)(pkt + sizeof(csg_pkt_head_t));
|
|
|
|
|
if (ptrend->boosterpacke)
|
|
|
|
|
{
|
|
|
|
|
if (csg.trend_booster_id == ptrend->index)
|
|
|
|
|
{
|
|
|
|
|
sem_post(&csg.trend_booster_sem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (csg.trend_msg_id == ptrend->index)
|
|
|
|
|
{
|
|
|
|
|
sem_post(&csg.trend_sem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t _csg_event_get_recv(char *pkt)
|
|
|
|
|
{
|
|
|
|
|
csg_event_ack_t *pevent = (csg_event_ack_t*)(pkt + sizeof(csg_pkt_head_t));
|
|
|
|
|
if (pevent->boosterpacke)
|
|
|
|
|
{
|
|
|
|
|
if (csg.event_booster_id == pevent->index)
|
|
|
|
|
{
|
|
|
|
|
sem_post(&csg.event_booster_sem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (csg.event_msg_id == pevent->index)
|
|
|
|
|
{
|
|
|
|
|
sem_post(&csg.event_sem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 升级文件接收 */
|
|
|
|
|
int32_t _csg_upgrade_recv(char *pkt)
|
|
|
|
@ -611,6 +652,13 @@ int32_t _csg_upgrade_recv(char *pkt)
|
|
|
|
|
int32_t len_wr = 0;
|
|
|
|
|
int32_t rv = E_NONE;
|
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t slot = head->slot - 1;
|
|
|
|
|
if (slot > PD_SLOTS_MAX)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot);
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 首保处理, 打开文件描述符, 初始化变量 */
|
|
|
|
|
if (head_msg->index == 0)
|
|
|
|
@ -654,8 +702,35 @@ int32_t _csg_upgrade_recv(char *pkt)
|
|
|
|
|
close(fd);
|
|
|
|
|
fd = -1;
|
|
|
|
|
DBG(DBG_M_PD_CSG, "Receive upgrade file end.\n");
|
|
|
|
|
rv = pd_upg_start(PD_UPG_FROM_CSG, head_msg->type);
|
|
|
|
|
csg_upate_msg_t *data;
|
|
|
|
|
|
|
|
|
|
data = XMALLOC(MTYPE_CSG, sizeof(csg_upate_msg_t));
|
|
|
|
|
if (!data)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n");
|
|
|
|
|
rv = E_ERROR;
|
|
|
|
|
goto UP_ERR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data->type = head_msg->type;
|
|
|
|
|
|
|
|
|
|
char buff[64] = {0};
|
|
|
|
|
if (getcwd(buff, sizeof(buff)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_CSG_ERR, "getcwd error!\n");
|
|
|
|
|
rv = E_ERROR;
|
|
|
|
|
goto UP_ERR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snprintf(data->name, 128, "%s/%s", buff, PD_UPG_SOFTWARE);
|
|
|
|
|
|
|
|
|
|
if (_csg_msg_send_dau(slot, DAU_SEND_UPDATE, data) != E_NONE)
|
|
|
|
|
{
|
|
|
|
|
XFREE(MTYPE_CSG, data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UP_ERR:
|
|
|
|
|
ack.index = head_msg->index;
|
|
|
|
|
ack.result = TRUE;
|
|
|
|
|
|
|
|
|
@ -663,31 +738,17 @@ int32_t _csg_upgrade_recv(char *pkt)
|
|
|
|
|
|
|
|
|
|
/* 发送应答 */
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t));
|
|
|
|
|
_csg_send_data(CSG_REPLY, head->cmd, pkt, sizeof(ack), 0);
|
|
|
|
|
|
|
|
|
|
/* 如果升级线程开启失败返回错误信息. */
|
|
|
|
|
_csg_send_data(CSG_REPLY, head->cmd, pkt, sizeof(ack), 0);
|
|
|
|
|
|
|
|
|
|
/* 如果升级线程开启失败返回错误信息. */
|
|
|
|
|
if (rv != E_NONE)
|
|
|
|
|
{
|
|
|
|
|
printf("Upgrade start failed.\n");
|
|
|
|
|
csg_upgrade_result_send(0, "Upgrade start failed.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t _csg_event_recv(char *pkt)
|
|
|
|
|
{
|
|
|
|
|
csg_pkt_head_t *head = (csg_pkt_head_t*)pkt;
|
|
|
|
|
//int slot = head->slot;
|
|
|
|
|
|
|
|
|
|
printf("_csg_event_recv slot = %d\n", head->slot);
|
|
|
|
|
head->dev_id = head->sdev_id;
|
|
|
|
|
head->cmd = CSG_PRV_EVENT;
|
|
|
|
|
|
|
|
|
|
//_dau_response(slot, pkt, head->len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t _csg_recv_process(char *pkt, uint32_t len)
|
|
|
|
|
{
|
|
|
|
@ -746,11 +807,12 @@ int32_t _csg_recv_process(char *pkt, uint32_t len)
|
|
|
|
|
_csg_real_image_recv(pkt);
|
|
|
|
|
break;
|
|
|
|
|
case CSG_PRV_TREND:
|
|
|
|
|
_csg_trend_get_recv(pkt);
|
|
|
|
|
break;
|
|
|
|
|
case CSG_PRV_REAL_PRPS:
|
|
|
|
|
break;
|
|
|
|
|
case CSG_PRV_EVENT:
|
|
|
|
|
_csg_event_recv(pkt);
|
|
|
|
|
_csg_event_get_recv(pkt);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
@ -759,48 +821,65 @@ int32_t _csg_recv_process(char *pkt, uint32_t len)
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_add_dau(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_add_dau(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
if (NULL == data)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
}
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), data, sizeof(csg_contact_t));
|
|
|
|
|
_csg_send_data(CSG_REPLY, CSG_C_ADD_DAU, pkt, sizeof(csg_contact_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_reset(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_reset(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
csg_ack_t ack = {0};
|
|
|
|
|
ack.result = TRUE;
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t));
|
|
|
|
|
_csg_send_data(CSG_REPLY, CSG_C_RESET, pkt, sizeof(csg_ack_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_info_set(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_info_set(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
csg_ack_t ack = {0};
|
|
|
|
|
ack.result = TRUE;
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t));
|
|
|
|
|
_csg_send_data(CSG_REPLY, CSG_C_DEV_INFO_SET, pkt, sizeof(csg_ack_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_info_get(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_info_get(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
if (NULL == data)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), data, sizeof(csg_dev_info_t));
|
|
|
|
|
_csg_send_data(CSG_REPLY, CSG_C_DEV_INFO_GET, pkt, sizeof(csg_dev_info_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t _csg_send_updata_rv(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
if (NULL == data)
|
|
|
|
|
{
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), data, sizeof(upgrade_res_t));
|
|
|
|
|
_csg_send_data(CSG_REPLY, CSG_C_UPDATE_RESULT, pkt, sizeof(upgrade_res_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_heartbeat(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_heartbeat(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
csg_timestamp_t *param = NULL;
|
|
|
|
|
struct timespec t;
|
|
|
|
@ -809,7 +888,7 @@ void _csg_send_heartbeat(uint8_t slot, void *data)
|
|
|
|
|
if (!param)
|
|
|
|
|
{
|
|
|
|
|
DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n");
|
|
|
|
|
return;
|
|
|
|
|
return E_MEM;
|
|
|
|
|
}
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &t);
|
|
|
|
|
param->sec = time(NULL);
|
|
|
|
@ -820,30 +899,33 @@ void _csg_send_heartbeat(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
XFREE(MTYPE_CSG, param);
|
|
|
|
|
}
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_cfg_set(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_cfg_set(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
csg_ack_t ack = {0};
|
|
|
|
|
ack.result = TRUE;
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t));
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_CONFIG_GLOBAL_SET, pkt, sizeof(csg_ack_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_cfg_get(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_cfg_get(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
if (NULL == data)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), data, sizeof(csg_config_global_t));
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_CONFIG_GLOBAL_GET, pkt, sizeof(csg_config_global_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_cfg_set_port(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_cfg_set_port(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
csg_config_port_ack_t ack = {0};
|
|
|
|
@ -852,30 +934,33 @@ void _csg_send_cfg_set_port(uint8_t slot, void *data)
|
|
|
|
|
ack.vport = psrc->vport;
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_config_port_ack_t));
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_CONFIG_PORT_SET, pkt, sizeof(csg_config_port_ack_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_cfg_get_port(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_cfg_get_port(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
if (NULL == data)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), data, sizeof(csg_config_port_t));
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_CONFIG_PORT_GET, pkt, sizeof(csg_config_port_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_prps_get(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_prps_get(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
csg_ack_t ack = {0};
|
|
|
|
|
ack.result = TRUE;
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t));
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_CONFIG_REAL_WAVE, pkt, sizeof(csg_ack_t), slot + 1);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_prps_data(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_prps_data(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.real_buf;
|
|
|
|
|
csg_real_image_t *head = (csg_real_image_t *)(pkt + sizeof(csg_pkt_head_t));
|
|
|
|
@ -890,7 +975,7 @@ void _csg_send_prps_data(uint8_t slot, void *data)
|
|
|
|
|
|
|
|
|
|
if (NULL == data)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
head->index = real->head.index;
|
|
|
|
@ -924,30 +1009,304 @@ void _csg_send_prps_data(uint8_t slot, void *data)
|
|
|
|
|
usleep(500);
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_REAL_PRPS, pkt, sizeof(csg_real_image_t) + len, slot + 1);
|
|
|
|
|
}
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_trend(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_event_data(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
if (NULL != data)
|
|
|
|
|
char *pkt = csg.event_buf;
|
|
|
|
|
csg_event_t *head = (csg_event_t *)(pkt + sizeof(csg_pkt_head_t));
|
|
|
|
|
char *pdata = pkt + sizeof(csg_pkt_head_t) + sizeof(csg_event_t);
|
|
|
|
|
hf_event_t *event = (hf_event_t *)data;
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
uint8_t err_cnt = 0;
|
|
|
|
|
uint32_t index = 0;
|
|
|
|
|
uint32_t event_len = 0;
|
|
|
|
|
uint32_t sum = 0;
|
|
|
|
|
|
|
|
|
|
if (NULL == event)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PD_EVENT_TYPE_NONE == event->head.type)
|
|
|
|
|
{
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
|
event_len = event->head.point_cnt * sizeof(pd_data_point_t);
|
|
|
|
|
sum = event_len / CSG_PKT_LEN;
|
|
|
|
|
if (event_len % CSG_PKT_LEN)
|
|
|
|
|
{
|
|
|
|
|
sum += 1;
|
|
|
|
|
}
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), data, sizeof(csg_ack_t));
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_TREND, pkt, sizeof(csg_ack_t), slot + 1);
|
|
|
|
|
|
|
|
|
|
head->sum = sum;
|
|
|
|
|
head->vport = event->head.vport;
|
|
|
|
|
head->boosterpack = 0;
|
|
|
|
|
head->power_fre = event->head.power_fre;
|
|
|
|
|
head->type = event->head.type;
|
|
|
|
|
head->max = event->head.max;
|
|
|
|
|
head->identifier = event->head.index;
|
|
|
|
|
head->utc = event->head.utc;
|
|
|
|
|
head->cnt = event->head.cnt;
|
|
|
|
|
head->avg_o = event->head.avg_o;
|
|
|
|
|
head->avg = event->head.avg;
|
|
|
|
|
head->point_cnt = event->head.point_cnt;
|
|
|
|
|
|
|
|
|
|
while (index < sum)
|
|
|
|
|
{
|
|
|
|
|
csg.event_msg_id = index;
|
|
|
|
|
head->len = event_len > CSG_PKT_LEN ? CSG_PKT_LEN : event_len;
|
|
|
|
|
head->index = index;
|
|
|
|
|
|
|
|
|
|
memcpy(pdata, event->point + index * CSG_PKT_LEN, head->len);
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_EVENT, pkt, head->len + sizeof(csg_event_t), slot + 1);
|
|
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
|
|
ts.tv_sec += CSG_SEND_TIMEOUT; // 设置 3 秒超时
|
|
|
|
|
if (sem_timedwait(&csg.event_sem, &ts) != 0)
|
|
|
|
|
{
|
|
|
|
|
err_cnt++;
|
|
|
|
|
if (err_cnt >= CSG_SEND_ERR_CNT)
|
|
|
|
|
{
|
|
|
|
|
_csg_disconnect_set(__FUNCTION__);
|
|
|
|
|
return E_TIMEOUT;
|
|
|
|
|
}
|
|
|
|
|
DBG(DBG_M_PD_CSG_ERR, "event sem error:%s\r\n", strerror(errno));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event_len -= head->len;
|
|
|
|
|
index++;
|
|
|
|
|
err_cnt = 0;
|
|
|
|
|
}
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _csg_send_event(uint8_t slot, void *data)
|
|
|
|
|
int32_t _csg_send_trend_prps_data(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
char *pkt = csg.buf_send;
|
|
|
|
|
if (NULL != data)
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
char *pkt = csg.trend_buf;
|
|
|
|
|
csg_trend_t *head = (csg_trend_t *)(pkt + sizeof(csg_pkt_head_t));
|
|
|
|
|
char *pdata = pkt + sizeof(csg_pkt_head_t) + sizeof(csg_trend_t);
|
|
|
|
|
|
|
|
|
|
dau_t *dau = &daus[slot];
|
|
|
|
|
hf_data_t *hf_data = (hf_data_t*)dau->private_data;
|
|
|
|
|
hf_trend_prps_t *prps = &hf_data->trend.prps;
|
|
|
|
|
hf_trend_col_t *col = &hf_data->trend.col;
|
|
|
|
|
|
|
|
|
|
uint8_t err_cnt = 0;
|
|
|
|
|
uint32_t index = 0;
|
|
|
|
|
uint32_t prps_len = 0;
|
|
|
|
|
uint32_t sum = 0;
|
|
|
|
|
uint32_t len = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t port = *(uint32_t *)data;
|
|
|
|
|
if (port >= 8)
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
|
|
|
|
|
head->type = CSG_TREND_TYPE_PRPS;
|
|
|
|
|
head->identifier = col->index;
|
|
|
|
|
head->utc = col->utc;
|
|
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
|
prps_len = prps->port[port].point_cnt * sizeof(pd_data_point_t);
|
|
|
|
|
sum = prps_len / CSG_PKT_LEN;
|
|
|
|
|
if (prps_len % CSG_PKT_LEN)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
sum += 1;
|
|
|
|
|
}
|
|
|
|
|
memcpy(pkt + sizeof(csg_pkt_head_t), data, sizeof(csg_ack_t));
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_EVENT, pkt, sizeof(csg_ack_t), slot + 1);
|
|
|
|
|
|
|
|
|
|
head->vport = port + 1;
|
|
|
|
|
head->sum = sum;
|
|
|
|
|
|
|
|
|
|
while (index < sum)
|
|
|
|
|
{
|
|
|
|
|
csg.trend_msg_id = index;
|
|
|
|
|
len = prps_len > CSG_PKT_LEN ? CSG_PKT_LEN : prps_len;
|
|
|
|
|
|
|
|
|
|
head->len = len;
|
|
|
|
|
head->index = index;
|
|
|
|
|
|
|
|
|
|
memcpy(pdata, (char *)prps->port[port].point + index * CSG_PKT_LEN, len);
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_TREND, pkt, len + sizeof(csg_trend_t), slot + 1);
|
|
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
|
|
ts.tv_sec += CSG_SEND_TIMEOUT; // 设置 3 秒超时
|
|
|
|
|
if (sem_timedwait(&csg.trend_sem, &ts) != 0)
|
|
|
|
|
{
|
|
|
|
|
err_cnt++;
|
|
|
|
|
if (err_cnt >= CSG_SEND_ERR_CNT)
|
|
|
|
|
{
|
|
|
|
|
_csg_disconnect_set(__FUNCTION__);
|
|
|
|
|
return E_TIMEOUT;
|
|
|
|
|
}
|
|
|
|
|
DBG(DBG_M_PD_CSG_ERR, "trend sem error:%s\r\n", strerror(errno));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prps_len -= len;
|
|
|
|
|
index++;
|
|
|
|
|
err_cnt = 0;
|
|
|
|
|
}
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t _csg_send_trend_prpd_data(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
char *pkt = csg.trend_buf;
|
|
|
|
|
csg_trend_t *head = (csg_trend_t *)(pkt + sizeof(csg_pkt_head_t));
|
|
|
|
|
char *pdata = pkt + sizeof(csg_pkt_head_t) + sizeof(csg_trend_t);
|
|
|
|
|
|
|
|
|
|
dau_t *dau = &daus[slot];
|
|
|
|
|
hf_data_t *hf_data = (hf_data_t*)dau->private_data;
|
|
|
|
|
hf_trend_col_t *col = &hf_data->trend.col;
|
|
|
|
|
hf_trend_prpd_t *prpd = &hf_data->trend.prpd;
|
|
|
|
|
|
|
|
|
|
uint8_t err_cnt = 0;
|
|
|
|
|
uint32_t index = 0;
|
|
|
|
|
uint32_t prps_len = 0;
|
|
|
|
|
uint32_t sum = 0;
|
|
|
|
|
uint32_t len = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t port = *(uint32_t *)data;
|
|
|
|
|
if (port >= 8)
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
|
|
|
|
|
head->type = CSG_TREND_TYPE_PRPD;
|
|
|
|
|
head->identifier = col->index;
|
|
|
|
|
head->utc = col->utc;
|
|
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
|
prps_len = CSG_TREND_PRPD_PORT_LEN;
|
|
|
|
|
sum = prps_len / CSG_PKT_LEN;
|
|
|
|
|
if (prps_len % CSG_PKT_LEN)
|
|
|
|
|
{
|
|
|
|
|
sum += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
head->vport = port + 1;
|
|
|
|
|
head->sum = sum;
|
|
|
|
|
|
|
|
|
|
while (index < sum)
|
|
|
|
|
{
|
|
|
|
|
csg.trend_msg_id = index;
|
|
|
|
|
len = prps_len > CSG_PKT_LEN ? CSG_PKT_LEN : prps_len;
|
|
|
|
|
|
|
|
|
|
head->len = len;
|
|
|
|
|
head->index = index;
|
|
|
|
|
|
|
|
|
|
memcpy(pdata, (char *)prpd->port[port].data + index * CSG_PKT_LEN, len);
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_TREND, pkt, len + sizeof(csg_trend_t), slot + 1);
|
|
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
|
|
ts.tv_sec += CSG_SEND_TIMEOUT; // 设置 3 秒超时
|
|
|
|
|
if (sem_timedwait(&csg.trend_sem, &ts) != 0)
|
|
|
|
|
{
|
|
|
|
|
err_cnt++;
|
|
|
|
|
if (err_cnt >= CSG_SEND_ERR_CNT)
|
|
|
|
|
{
|
|
|
|
|
_csg_disconnect_set(__FUNCTION__);
|
|
|
|
|
return E_TIMEOUT;
|
|
|
|
|
}
|
|
|
|
|
DBG(DBG_M_PD_CSG_ERR, "trend sem error:%s\r\n", strerror(errno));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prps_len -= len;
|
|
|
|
|
index++;
|
|
|
|
|
err_cnt = 0;
|
|
|
|
|
}
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t _csg_send_trend_statistics_data(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
char *pkt = csg.trend_buf;
|
|
|
|
|
csg_trend_t *head = (csg_trend_t *)(pkt + sizeof(csg_pkt_head_t));
|
|
|
|
|
csg_trend_stat *pdata = (csg_trend_stat*)(pkt + sizeof(csg_pkt_head_t) + sizeof(csg_trend_t));
|
|
|
|
|
|
|
|
|
|
dau_t *dau = &daus[slot];
|
|
|
|
|
hf_data_t *hf_data = (hf_data_t*)dau->private_data;
|
|
|
|
|
hf_trend_col_t *col = &hf_data->trend.col;
|
|
|
|
|
|
|
|
|
|
uint8_t err_cnt = 0;
|
|
|
|
|
uint32_t index = 0;
|
|
|
|
|
uint32_t prps_len = 0;
|
|
|
|
|
uint32_t sum = 0;
|
|
|
|
|
uint32_t len = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t port = *(uint32_t *)data;
|
|
|
|
|
if (port >= 8)
|
|
|
|
|
return E_BAD_PARAM;
|
|
|
|
|
|
|
|
|
|
head->type = CSG_TREND_TYPE_STAT;
|
|
|
|
|
head->identifier = col->index;
|
|
|
|
|
head->utc = col->utc;
|
|
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
|
prps_len = sizeof(csg_trend_stat);
|
|
|
|
|
sum = prps_len / CSG_PKT_LEN;
|
|
|
|
|
if (prps_len % CSG_PKT_LEN)
|
|
|
|
|
{
|
|
|
|
|
sum += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
head->vport = port + 1;
|
|
|
|
|
head->sum = sum;
|
|
|
|
|
|
|
|
|
|
while (index < sum)
|
|
|
|
|
{
|
|
|
|
|
csg.trend_msg_id = index;
|
|
|
|
|
len = prps_len > CSG_PKT_LEN ? CSG_PKT_LEN : prps_len;
|
|
|
|
|
|
|
|
|
|
head->len = len;
|
|
|
|
|
head->index = index;
|
|
|
|
|
|
|
|
|
|
pdata->data_cnt = col->port[port].data_cnt;
|
|
|
|
|
pdata->max = col->port[port].max;
|
|
|
|
|
pdata->avg = col->port[port].avg;
|
|
|
|
|
pdata->cnt = col->port[port].cnt;
|
|
|
|
|
pdata->phase = col->port[port].phase;
|
|
|
|
|
pdata->noise = col->port[port].noise;
|
|
|
|
|
pdata->event_cnt = col->port[port].event_cnt;
|
|
|
|
|
|
|
|
|
|
_csg_send_data(CSG_PRV_REPLY, CSG_PRV_TREND, pkt, len + sizeof(csg_trend_t), slot + 1);
|
|
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
|
|
ts.tv_sec += CSG_SEND_TIMEOUT; // 设置 3 秒超时
|
|
|
|
|
if (sem_timedwait(&csg.trend_sem, &ts) != 0)
|
|
|
|
|
{
|
|
|
|
|
err_cnt++;
|
|
|
|
|
if (err_cnt >= CSG_SEND_ERR_CNT)
|
|
|
|
|
{
|
|
|
|
|
_csg_disconnect_set(__FUNCTION__);
|
|
|
|
|
return E_TIMEOUT;
|
|
|
|
|
}
|
|
|
|
|
DBG(DBG_M_PD_CSG_ERR, "trend sem error:%s\r\n", strerror(errno));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prps_len -= len;
|
|
|
|
|
index++;
|
|
|
|
|
err_cnt = 0;
|
|
|
|
|
}
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t _csg_send_trend_data(uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
|
_csg_send_trend_prps_data(slot, data);
|
|
|
|
|
_csg_send_trend_prpd_data(slot, data);
|
|
|
|
|
_csg_send_trend_statistics_data(slot, data);
|
|
|
|
|
return E_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* csg向后台发包处理函数 */
|
|
|
|
|
int32_t _csg_send_process(uint8_t type, uint8_t slot, void *data)
|
|
|
|
|
{
|
|
|
|
@ -1222,6 +1581,11 @@ int32_t csg_handle_init(void)
|
|
|
|
|
int32_t rv = 0;
|
|
|
|
|
|
|
|
|
|
memset(&csg, 0, sizeof(csg_t));
|
|
|
|
|
csg.trend_msg_id = -1;
|
|
|
|
|
csg.event_msg_id = -1;
|
|
|
|
|
csg.fifo_prps_id = E_MEM;
|
|
|
|
|
csg.fifo_event_id = E_MEM;
|
|
|
|
|
csg.fifo_trend_id = E_MEM;
|
|
|
|
|
|
|
|
|
|
/* 发送数据. */
|
|
|
|
|
csg.server_ip = inet_addr("192.168.1.161");
|
|
|
|
@ -1312,6 +1676,11 @@ int32_t csg_handle_init_after(void)
|
|
|
|
|
return E_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sem_init(&csg.event_sem, 0, 0);
|
|
|
|
|
sem_init(&csg.trend_sem, 0, 0);
|
|
|
|
|
sem_init(&csg.event_booster_sem, 0, 0);
|
|
|
|
|
sem_init(&csg.trend_booster_sem, 0, 0);
|
|
|
|
|
|
|
|
|
|
csg.send_cb = _csg_send_process;
|
|
|
|
|
|
|
|
|
|
param.arg = NULL;
|
|
|
|
|