diff --git a/app/include/memory.h b/app/include/memory.h index be68704..90ddca7 100644 --- a/app/include/memory.h +++ b/app/include/memory.h @@ -69,6 +69,7 @@ enum MTYPE_ETH, MTYPE_GIS, MTYPE_DAU, + MTYPE_HF, MTYPE_CSG, MTYPE_STORAGE, MTYPE_DEBUG, diff --git a/app/include/pd_dau.h b/app/include/pd_dau.h index d888114..2f88baf 100755 --- a/app/include/pd_dau.h +++ b/app/include/pd_dau.h @@ -62,7 +62,9 @@ /* Exported types ------------------------------------------------------------*/ typedef int32_t (*dau_recv_cb)(uint8_t, char*, uint16_t); +typedef int32_t (*dau_send_cb)(uint8_t, uint8_t, void*); typedef void (*dau_recv_fun_cb)(uint8_t, char*, uint16_t); +typedef void (*dau_send_fun_cb)(uint8_t, void*); /* 命令类型. */ enum DAU_CMD_TYPE @@ -101,72 +103,19 @@ enum DAU_P_CMD DAU_P_MAX }; -// 板卡类型枚举 -typedef enum { - DAU_TYPE_UDP, - DAU_TYPE_RS485, - DAU_TYPE_NONE -} DauType; - -// 板卡状态枚举 -typedef enum { - DAU_STATE_DISCONNECTED, - DAU_STATE_CONNECTED, - DAU_STATE_REGISTERED -} DauState; - - -// 通信回调函数类型 -//typedef void (*data_recv_callback)(void* priv_data, const void* data, size_t len); -//typedef void (*data_send_callback)(void* priv_data, void* data, size_t len); - -// 板卡私有数据结构 -typedef struct +/* 命令类型. */ +enum DAU_SEND_TYPE { - DauType type; - union - { - struct - { - int sockfd; - struct sockaddr_in addr; - } udp; - struct - { - int fd; - char port[20]; - struct termios options; - } rs485; - } comm; - char board_id[32]; - void *rx_buffer; - size_t buffer_size; - uint8_t cmd_type; - uint8_t cmd; -} dau_private_data_t; - -// 板卡操作回调函数结构 -typedef struct + DAU_SEND_PRPS = 1, + DAU_SEND_MAX +}; + +/* 发送数据消息 */ +typedef struct { - int (*init)(dau_private_data_t *data, const char *config); - int (*receive)(dau_private_data_t *data, void *buf, size_t len); - int (*transmit)(dau_private_data_t *data, const void *buf, size_t len); - void (*cleanup)(dau_private_data_t *data); -} dau_operations_t; - -// UDP客户端信息 -typedef struct { - struct sockaddr_in addr; - char board_id[32]; -} udp_client_data; - - -// RS485设备信息 -typedef struct { - int fd; // 串口文件描述符 - char board_id[32]; - uint8_t address; // 从机地址 -} rs485_device_data; + uint32_t type; + void *data; +} dau_send_msg_t; /* 报文头初始化结构体 */ typedef struct @@ -226,65 +175,6 @@ typedef struct uint8_t port_type[PD_PORT_SUM]; } dau_contact_t; -/* 心跳报文. */ -typedef struct -{ - float freq; // 实测同步源工频频率. - uint8_t dau_state[4]; // 采集模块的状态. - uint8_t out_sync; // 外接调频同步 1: 有效 0: 无效. - uint8_t pt_sync; // PT同步 1: 有效 0: 无效. - uint8_t in_sync; // 内同步 1: 有效 0: 无效. - uint8_t reserved1; // 预留 字节对齐. - uint8_t port_link_alarm[PD_PORT_SUM]; // 通道传感器连接状态 断线告警. - uint8_t dau_port_num[4]; // 采集板端口数量. -} dau_heartbeat_t; - -/* 时间头 */ -typedef struct -{ - uint16_t index; // 包索引 - uint16_t sum; // 总包数 - uint8_t vport; // 通道号 - uint8_t boosterpack; // 是否补包 0:否 1:是 - int16_t max; // 通道的最大值. - uint32_t power_fre; // 工频周期. - uint8_t type; // 事件类型. - uint8_t reserved[3]; // 保留 - uint32_t identifier; // 数据编号: 0 - (2^32-1) 循环. - uint32_t utc; // UTC 时标. - uint32_t cnt; // 通道每秒脉冲计数值. - uint16_t avg_o; // 通道原始信号 (降噪前) 的平均值. - uint16_t avg; // 脉冲平均值. - uint32_t point_cnt; // 数据累计点数 - uint32_t len; // 当前包长度 -} dau_event_head_t; - -// 板卡管理器结构 -typedef struct -{ - //dau_private_data_t *private_data; - - dau_operations_t ops; - - // udp - int sockfd; - struct sockaddr_in addr; - // rs485 - int fd; - char port[20]; - struct termios options; - - char board_id[32]; - void *rx_buffer; - size_t buffer_size; - uint8_t cmd_type; - uint8_t cmd; - - pthread_t thread_id; - int slot; - bool occupied; // 槽位占用标志 -} dau_manager_t; - /* DAU 状态结构体 */ typedef struct { @@ -296,16 +186,17 @@ typedef struct typedef struct { uint8_t slot; // dau slot - DauType type; + uint16_t pkt_id; // 发送报文 id int fd; // dau socket fd struct sockaddr_in server; // dau client ip char buf_recv[DAU_BUF_SIZE]; // dau 收包 buf - DauState stat; - void *private_data; + char buf_send[DAU_BUF_SIZE]; // dau 发包 buf dau_contact_t info; // dau 信息 - dau_heartbeat_t run_status; // dau 运行状态 dau_state_t state; // dau 状态 dau_recv_cb recv_cb; // dau 收包处理函数 + dau_send_cb send_cb; // dau 收包处理函数 + int32_t fifo_send; // 发包 fifo + void *private_data; } dau_t; /* Exported macro ------------------------------------------------------------*/ diff --git a/app/include/pd_hf.h b/app/include/pd_hf.h index 7804a87..2c4528d 100755 --- a/app/include/pd_hf.h +++ b/app/include/pd_hf.h @@ -3,6 +3,33 @@ #ifdef CFG_DEV_TYPE_LAND_PD /* Includes ------------------------------------------------------------------*/ +#include "pd_dau.h" + +#define HF_DATA_LEN (1300) + +/*趋势上送数据报文头c语言定义*/ +enum HF_TREND_TYPE +{ + HF_TREND_TYPE_PRPD = 0, // 累计PRPD + HF_TREND_TYPE_ORIG, // 原始波形 + HF_TREND_TYPE_PRPS, // 后10秒PRPS + HF_TREND_TYPE_STAT, // 统计数据 + HF_TREND_TYPE_MAX, +}; + +/* 点位数据 */ +typedef struct +{ + uint16_t index; // 点位 + int16_t data; // 数据 +} hf_data_point_t; + +/* 一般应答 */ +typedef struct +{ + uint8_t result; // 应答结果. 0:失败 1:成功 + uint8_t reserved[3]; // 保留 +} hf_ack_t; typedef struct { @@ -28,7 +55,155 @@ typedef struct uint8_t port_type[8]; } hf_dev_info_t; +/* 心跳报文. */ +typedef struct +{ + float freq; // 实测同步源工频频率. + uint8_t dau_state[4]; // 采集模块的状态. + uint8_t out_sync; // 外接调频同步 1: 有效 0: 无效. + uint8_t pt_sync; // PT同步 1: 有效 0: 无效. + uint8_t in_sync; // 内同步 1: 有效 0: 无效. + uint8_t reserved1; // 预留 字节对齐. + uint8_t port_link_alarm[PD_PORT_SUM]; // 通道传感器连接状态 断线告警. + uint8_t dau_port_num[4]; // 采集板端口数量. +} hf_heartbeat_t; + +/* 实时图谱关注 */ +typedef struct +{ + uint8_t vport; // 通道编号 1 ~ 8 + uint8_t is_concern; // 关注 1: 关注 0: 取消关注 + uint8_t filter; // 滤波器类型 + uint8_t denoise_correlation; // 关联降噪 1: 关联噪声去噪 + uint8_t denoise_type; // 0-无配置 1-自动 2-手动降噪 + uint8_t reserved[1]; + uint16_t denoise_manual; // 手动降噪等级 +} hf_prps_get_t; + +/* 趋势头 */ +typedef struct +{ + uint16_t index; // 包索引 + uint16_t sum; // 总包数 + uint8_t type; // 数据类型 0:prpd 1:原始波形 2:10秒prps 3:统计数据 + uint8_t vport; // 通道号 + uint8_t boosterpack; // 是否补包 0:否 1:是 + uint8_t reserved[1]; // 保留 + uint32_t identifier; // 数据编号 + uint32_t utc; // 同步时间 + uint32_t len; // 当前包长度 +} hf_trend_head_t; + +/* 趋势应答 */ +typedef struct +{ + uint32_t index; + uint8_t result; + uint8_t boosterpack; // 是否补包 0:否 1:是 + uint8_t reserve[2]; +} hf_trend_ack_t; + +/* 趋势统计 */ +typedef struct +{ + uint16_t data_cnt; // 数据计数 + int16_t max; // 通道的最大值 + uint16_t reserved; // 保留 + uint16_t avg; // 通道的平均值 + uint32_t cnt; // 通道的计数值 + uint32_t phase; // 放电相位 + uint32_t noise; // 趋势数据中的底噪值: 单位 dBm + uint32_t event_cnt; // 趋势数据中的的事件数量记录 +} hf_trend_stat; + +/* 趋势统计结构体 */ +typedef struct +{ + uint32_t index; // 数据编号: 0 - (2^32-1) 循环. + uint32_t utc; // UTC 时标. + hf_trend_stat port[PD_DAU_PORT_SUM]; // 通道 0 - 15 的计算及测量数据. +} hf_trend_col_t; + +/* 趋势 PRPD 结构体 */ +typedef struct +{ + uint16_t data[PD_PHASE_NUM][PD_VAULE_NUM]; +} hf_trend_prpd_port_t; + +/* 趋势 PRPD 结构体 */ +typedef struct +{ + pd_trend_prpd_port_t port[PD_DAU_PORT_SUM]; +} hf_trend_prpd_t; + +/* 趋势 PRPS 结构体 */ +typedef struct +{ + uint32_t point_cnt; // 数据累计点数. + hf_data_point_t point[PD_TREND_POINT_MAX]; +} hf_trend_prps_port_t; + +/* 趋势 PRPS 结构体 */ +typedef struct +{ + hf_trend_prps_port_t port[PD_DAU_PORT_SUM]; +} hf_trend_prps_t; + +/* 高频趋势数据 */ +typedef struct +{ + hf_trend_col_t col; + hf_trend_prpd_t prpd; + hf_trend_prps_t prps; +} hf_trend_t; + +/* 事件头 */ +typedef struct +{ + uint16_t index; // 包索引 + uint16_t sum; // 总包数 + uint8_t vport; // 通道号 + uint8_t boosterpack; // 是否补包 0:否 1:是 + int16_t max; // 通道的最大值. + uint32_t power_fre; // 工频周期. + uint8_t type; // 事件类型. + uint8_t reserved[3]; // 保留 + uint32_t identifier; // 数据编号: 0 - (2^32-1) 循环. + uint32_t utc; // UTC 时标. + uint32_t cnt; // 通道每秒脉冲计数值. + uint16_t avg_o; // 通道原始信号 (降噪前) 的平均值. + uint16_t avg; // 脉冲平均值. + uint32_t point_cnt; // 数据累计点数 + uint32_t len; // 当前包长度 +} hf_event_head_t; + +/* 事件应答 */ +typedef struct +{ + uint32_t index; + uint8_t result; + uint8_t boosterpack; // 是否补包 0: 否 1: 是 + uint8_t reserve[2]; +} hf_event_ack_t; + +/* 高频事件数据 */ +typedef struct +{ + hf_event_head_t head; + hf_data_point_t point[PD_EVENT_POINT_MAX]; +} hf_event_t; + +/* 高频私有数据 */ +typedef struct +{ + hf_heartbeat_t run_status; + hf_event_t event; + hf_trend_t trend; +} hf_data_t; + extern int32_t hf_recv_process(uint8_t slot, char *pkt, uint16_t len); +extern int32_t hf_send_process(uint8_t slot, uint8_t type, void *data); +extern void* hf_data_malloc(void); #endif #endif diff --git a/app/include/pd_main.h b/app/include/pd_main.h index 054b22a..8ade6c8 100755 --- a/app/include/pd_main.h +++ b/app/include/pd_main.h @@ -55,9 +55,9 @@ #define PD_VAULE_NUM 256 #define PD_PRPS_NUM 12800 #define PD_PRPS_NUM_MAX 98304 -#define PD_EVENT_POINT_MAX 983040 +#define PD_EVENT_POINT_MAX 768000 #define PD_TREND_PHASE_POINT_CNT 256 -#define PD_TREND_POINT_MAX 983040 +#define PD_TREND_POINT_MAX 768000 #define PD_TREND_ORIGINAL_NUM 65536 #define PD_PORT_ORIGINAL_NUM 2560000 // 100M采样率, 最大40Hz diff --git a/app/lib/a_process/pd_dau.c b/app/lib/a_process/pd_dau.c index b6d1ef9..88d573b 100755 --- a/app/lib/a_process/pd_dau.c +++ b/app/lib/a_process/pd_dau.c @@ -21,21 +21,19 @@ /* 用户代码头文件. */ #include "main.h" -#include "cmd.h" +#include "cmd.h" +#include "fifo.h" #include "pd_dau.h" #include "pd_hf.h" #include "pd_csg.h" /* Define --------------------------------------------------------------------*/ #define DUA_UDP_PORT 23760 +#define DUA_SEND_FIFO_NUM (8) /* Private typedef -----------------------------------------------------------*/ -/* 上传平台回调函数类型 */ -typedef void (*UploadCallback)(int slot, const void *data, size_t len); /* Private variables ---------------------------------------------------------*/ -pthread_mutex_t board_mutex = PTHREAD_MUTEX_INITIALIZER; -int udp_socket; dau_t daus[PD_SLOTS_MAX]; /* Private function prototypes -----------------------------------------------*/ @@ -58,33 +56,14 @@ void _dau_head_init(dau_t *dau, dau_head_init_t *head_data) head->pkt_id = head_data->pkt_id; } -void _dau_response(int slot, char *buf, int len) -{ - printf("_dau_response: slot=%d len=%d\n", slot, len); - - - if (slot >= 0 && slot < PD_SLOTS_MAX) - { - if (daus[slot].type == DAU_TYPE_UDP) - { - udp_client_data *client = (udp_client_data*)daus[slot].private_data; - sendto(udp_socket, buf, len, 0, - (struct sockaddr*)&client->addr, sizeof(client->addr)); - } - else if (daus[slot].type == DAU_TYPE_RS485) - { - rs485_device_data *dev = (rs485_device_data*)daus[slot].private_data; - write(dev->fd, buf, len); - } - } -} - /* dau 插入处理 */ int _dau_insert(dau_t *dau) { if (3 == dau->info.type_m && 1 == dau->info.type_s) { dau->recv_cb = hf_recv_process; + dau->send_cb = hf_send_process; + dau->private_data = hf_data_malloc(); } else { @@ -194,6 +173,12 @@ void *_dau_recv_handle(void *arg) return NULL; } + /* 等待初始化完成 */ + while(!is_system_init) + { + sleep(1); + } + while(1) { /* 读取数据. */ @@ -210,6 +195,40 @@ void *_dau_recv_handle(void *arg) return NULL; } +/* dau 收包线程 */ +void *_dau_send_handle(void *arg) +{ + dau_t *dau = (dau_t*)arg; + dau_send_msg_t *recv_msg = NULL; + + /* 等待初始化完成 */ + while(!is_system_init) + { + sleep(1); + } + + while(1) + { + if (fifo_read(dau->fifo_send, (void**)&recv_msg) != 0) + { + DBG(DBG_M_PD_DAU_ERR, "ERROR at fifo %d read!\r\n", dau->fifo_send); + continue; + } + + /* 响应其他报文 */ + if (dau->send_cb) + { + dau->send_cb(dau->slot, recv_msg->type, recv_msg->data); + } + + /* 释放数据内存, 注意一定要在 fifo_push 之前调用, 因为 fifo_push 后 recv_msg 已被释放. */ + XFREE(MTYPE_CSG, recv_msg->data); + fifo_push(dau->fifo_send); + } + + return NULL; +} + /* dau 预初始化 */ int32_t dau_handle_init(void) { @@ -229,16 +248,26 @@ int32_t dau_handle_init(void) int32_t dau_handle_init_after(void) { thread_param_t param = {0}; + char fifo_name[THREAD_NAME_LEN]; uint8_t i = 0; /* 初始收包线程 */ for (i = 0; i < DAU_ETH_SLOTS_SUM; i++) { + snprintf(fifo_name, THREAD_NAME_LEN, "DAU_SEND_%d", i); + daus[i].fifo_send = fifo_create(fifo_name, DUA_SEND_FIFO_NUM); + param.arg = (void*)(&daus[i]); param.priority = 80; param.log_module = LOG_DAU; snprintf(param.thread_name, THREAD_NAME_LEN, "DAU_RECV_%d", i); create_thread(_dau_recv_handle, ¶m); + + param.arg = (void*)(&daus[i]); + param.priority = 50; + param.log_module = LOG_DAU; + snprintf(param.thread_name, THREAD_NAME_LEN, "DAU_SEND_%d", i); + create_thread(_dau_send_handle, ¶m); } return E_NONE; @@ -255,7 +284,7 @@ void dau_send_data(dau_t *dau, dau_head_init_t *head_data) rv = sendto(dau->fd, head_data->pkt, head_data->len, 0, (struct sockaddr*)&dau->server, sizeof(dau->server)); if (rv < 0) { - DBG(DBG_M_PD_CSG_ERR, "Sendto return %s!\r\n", safe_strerror(errno)); + DBG(DBG_M_PD_DAU_ERR, "Sendto return %s!\r\n", safe_strerror(errno)); } } diff --git a/app/lib/a_process/pd_hf.c b/app/lib/a_process/pd_hf.c index 91a08ad..18c7458 100755 --- a/app/lib/a_process/pd_hf.c +++ b/app/lib/a_process/pd_hf.c @@ -47,6 +47,7 @@ #include "pd_main.h" #include "pd_csg.h" #include "pd_dau.h" +#include "pd_hf.h" /* Private define ------------------------------------------------------------*/ @@ -58,12 +59,13 @@ /* Private function prototypes -----------------------------------------------*/ -extern void _hf_contact_recv(int slot, char *pkt); extern void _hf_heartbeat_recv(uint8_t slot, char *pkt, uint16_t len); -extern void _hf_real_image_recv(int slot, char *pkt); -extern void _hf_trend_recv(int slot, char *pkt); +extern void _hf_prps_get_recv(uint8_t slot, char *pkt, uint16_t len); +extern void _hf_trend_recv(uint8_t slot, char *pkt, uint16_t len); extern void _hf_event_recv(uint8_t slot, char *pkt, uint16_t len); +extern void _hf_prps_get_send(uint8_t slot, void *data); + // 命令映射表 static dau_recv_fun_cb _hf_command[] = { @@ -88,31 +90,43 @@ static dau_recv_fun_cb _hf_prv_command[] = NULL, // DAU_P_CONFIG_GET 2 NULL, // DAU_P_CONFIG_PORT_SET 3 NULL, // DAU_P_CONFIG_PORT_GET 4 - NULL, // DAU_P_CONFIG_REAL_WAVE 5 + _hf_prps_get_recv, // DAU_P_CONFIG_REAL_WAVE 5 NULL, // 6 NULL, // 7 NULL, // 8 NULL, // 9 - NULL, // DAU_P_TREND 10 + _hf_trend_recv, // DAU_P_TREND 10 NULL, // DAU_P_REAL_PRPS 11 - NULL, // DAU_P_EVENT 12 + _hf_event_recv, // DAU_P_EVENT 12 }; -/* Interface functions -------------------------------------------------------*/ -void _hf_real_image_recv(int slot, char *pkt) +// 命令映射表 +static dau_send_fun_cb _hf_send_command[] = { - csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; - head->slot = slot; - head->sdev_id = head->dev_id; - _csg_send_data(CSG_PRV_REPLY, CSG_PRV_REAL_PRPS, pkt, head->len - sizeof(csg_pkt_head_t)); -} + NULL, // 0 + _hf_prps_get_send, // DAU_SEND_PRPS 1 +}; -void _hf_trend_recv(int slot, char *pkt) +/* Interface functions -------------------------------------------------------*/ +/* PRPS 关注报文发送 */ +void _hf_prps_get_send(uint8_t slot, void *data) { - csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; - head->slot = slot; - head->sdev_id = head->dev_id; - _csg_send_data(CSG_PRV_REPLY, CSG_PRV_TREND, pkt, head->len - sizeof(csg_pkt_head_t)); + dau_head_init_t head_data; + dau_t *dau = &daus[slot]; + hf_prps_get_t *param = (hf_prps_get_t*)(dau->buf_send + sizeof(dau_pkt_head_t)); + + /* 回复报文 */ + head_data.cmd_type = DAU_PRV_REQUEST; + head_data.cmd = DAU_P_CONFIG_REAL_WAVE; + head_data.pkt_id = dau->pkt_id++; + head_data.pkt = dau->buf_send; + head_data.len = sizeof(dau_pkt_head_t) + sizeof(hf_prps_get_t); + + memcpy(param, data, sizeof(hf_prps_get_t)); + + dau_send_data(dau, &head_data); + + return; } /* 心跳报文接收 */ @@ -121,10 +135,11 @@ void _hf_heartbeat_recv(uint8_t slot, char *pkt, uint16_t len) dau_head_init_t head_data; dau_t *dau = &daus[slot]; dau_pkt_head_t *head = (dau_pkt_head_t*)pkt; - dau_heartbeat_t *data = (dau_heartbeat_t*)(pkt + sizeof(dau_pkt_head_t)); + hf_heartbeat_t *data = (hf_heartbeat_t*)(pkt + sizeof(dau_pkt_head_t)); + hf_data_t *hf_data = (hf_data_t*)dau->private_data; uint32_t *timestamp = (uint32_t*)(pkt + sizeof(dau_pkt_head_t)); - memcpy(&dau->run_status, data, sizeof(dau_heartbeat_t)); + memcpy(&hf_data->run_status, data, sizeof(hf_heartbeat_t)); /* 回复报文 */ head_data.cmd_type = DAU_REQUEST; @@ -138,19 +153,141 @@ void _hf_heartbeat_recv(uint8_t slot, char *pkt, uint16_t len) return; } +/* 心跳报文接收 */ +void _hf_prps_get_recv(uint8_t slot, char *pkt, uint16_t len) +{ + return; +} + +/* 趋势报文接收 */ +void _hf_trend_recv(uint8_t slot, char *pkt, uint16_t len) +{ + dau_head_init_t head_data; + dau_t *dau = &daus[slot]; + hf_data_t *hf_data = (hf_data_t*)dau->private_data; + hf_trend_t *trend = &hf_data->trend; + dau_pkt_head_t *head = (dau_pkt_head_t*)pkt; + hf_trend_head_t *head_trend = (hf_trend_head_t*)(pkt + sizeof(dau_pkt_head_t)); + char *data = (char*)(pkt + sizeof(dau_pkt_head_t) + sizeof(hf_trend_head_t)); + char *point = NULL; + uint8_t port = 0; + hf_trend_ack_t ack; + hf_trend_ack_t *ack_p = (hf_trend_ack_t*)(pkt + sizeof(dau_pkt_head_t)); + + /* 不处理补包数据 */ + if (!head_trend->boosterpack) + { + //printh("#1 %d %d %d %d\r\n", head_trend->vport, head_trend->sum, head_trend->index, head_trend->type); + //printh("#2 %d %d\r\n", head_trend->utc, head_trend->len); + + port = head_trend->vport - 1; + if (HF_TREND_TYPE_STAT == head_trend->type) + { + trend->col.index = head_trend->identifier; + trend->col.utc = head_trend->utc; + memcpy(&trend->col.port[port], data, sizeof(hf_trend_stat)); + + if ((head_trend->index + 1) == head_trend->sum) + { + //printh("vport %d index %d utc %d max %d\r\n", head_trend->vport, trend->col.index, trend->col.utc, trend->col.port[port].max); + //printh("avg %d cnt %d phase %d noise %d\r\n", trend->col.port[port].avg, trend->col.port[port].cnt, trend->col.port[port].phase, trend->col.port[port].noise); + //printh("event_cnt %d\r\n", trend->col.port[port].event_cnt); + } + } + else if (HF_TREND_TYPE_PRPD == head_trend->type) + { + point = (char*)trend->prpd.port[port].data; + point += head_trend->index * HF_DATA_LEN; + memcpy(point, data, head_trend->len); + } + else if (HF_TREND_TYPE_PRPS == head_trend->type) + { + if (0 == head_trend->index) + { + trend->prps.port[port].point_cnt = 0; + } + /* 这里左移 2 位是因为 sizeof(hf_data_point_t) 等于 4 */ + trend->prps.port[port].point_cnt += head_trend->len >> 2; + point = (char*)trend->prps.port[port].point; + point += head_trend->index * HF_DATA_LEN; + memcpy(point, data, head_trend->len); + } + } + + /* 回复报文 */ + head_data.cmd_type = DAU_PRV_REQUEST; + head_data.cmd = DAU_P_TREND; + head_data.pkt_id = head->pkt_id; + head_data.pkt = pkt; + head_data.len = sizeof(dau_pkt_head_t) + sizeof(hf_trend_ack_t); + ack.index = head_trend->index; + ack.result = 0; + ack.boosterpack = head_trend->boosterpack; + memcpy(ack_p, &ack, sizeof(hf_trend_ack_t)); + dau_send_data(dau, &head_data); + + return; +} + /* 事件报文接收 */ void _hf_event_recv(uint8_t slot, char *pkt, uint16_t len) { - //dau_head_init_t head_data; - //dau_t *dau = &daus[slot]; - //dau_pkt_head_t *head = (dau_pkt_head_t*)pkt; - //dau_event_head_t *head_event = (dau_event_head_t*)(pkt + sizeof(dau_pkt_head_t)); + dau_head_init_t head_data; + dau_t *dau = &daus[slot]; + hf_data_t *hf_data = (hf_data_t*)dau->private_data; + hf_event_t *event = &hf_data->event; + dau_pkt_head_t *head = (dau_pkt_head_t*)pkt; + hf_event_head_t *head_event = (hf_event_head_t*)(pkt + sizeof(dau_pkt_head_t)); + char *data = (char*)(pkt + sizeof(dau_pkt_head_t) + sizeof(hf_event_head_t)); + char *point = NULL; + hf_event_ack_t ack; + hf_event_ack_t *ack_p = (hf_event_ack_t*)(pkt + sizeof(dau_pkt_head_t)); + + /* 不处理补包数据 */ + if (!head_event->boosterpack) + { + //printh("#3 %d %d %d %d\r\n", head_event->vport, head_event->sum, head_event->index, head_event->type); + //printh("#4 %d %d\r\n\n", head_event->utc, head_event->len); + + /* 第一个报文 */ + if (0 == head_event->index) + { + event->head.vport = head_event->vport; + event->head.boosterpack = head_event->boosterpack; + event->head.power_fre = head_event->power_fre; + event->head.type = head_event->type; + event->head.max = head_event->max; + event->head.identifier = head_event->identifier; + event->head.utc = head_event->utc; + event->head.cnt = head_event->cnt; + event->head.avg_o = head_event->avg_o; + event->head.avg = head_event->avg; + event->head.point_cnt = head_event->point_cnt; + } + + if ((head_event->index + 1) == head_event->sum) + { + //printh("vport %d power_fre %d type %d max %d\r\n", event->head.vport, event->head.power_fre, event->head.type, event->head.max); + //printh("identifier %d utc %d cnt %d avg %d\r\n", event->head.identifier, event->head.utc, event->head.cnt, event->head.avg); + //printh("point_cnt %d\r\n\n", event->head.point_cnt); + } - /* 第一个报文 */ - //if (0 == head_event->index) - //{ - - //} + point = (char*)event->point; + point += head_event->index * HF_DATA_LEN; + memcpy(point, data, head_event->len); + } + + /* 回复报文 */ + head_data.cmd_type = DAU_PRV_REQUEST; + head_data.cmd = DAU_P_EVENT; + head_data.pkt_id = head->pkt_id; + head_data.pkt = pkt; + head_data.len = sizeof(dau_pkt_head_t) + sizeof(hf_event_ack_t); + ack.index = head_event->index; + ack.result = 0; + ack.boosterpack = head_event->boosterpack; + memcpy(ack_p, &ack, sizeof(hf_event_ack_t)); + dau_send_data(dau, &head_data); return; } @@ -195,7 +332,7 @@ int32_t hf_recv_process(uint8_t slot, char *pkt, uint16_t len) { dau_pkt_head_t *head = (dau_pkt_head_t*)pkt; - /* 报文头和 CRC 校验. */ + /* 报文头和 CRC 校验. */ LD_E_RETURN_N(_hf_pkt_check(slot, pkt)); if (DAU_REPLY == head->cmd_type) @@ -209,12 +346,29 @@ int32_t hf_recv_process(uint8_t slot, char *pkt, uint16_t len) { if (_hf_prv_command[head->cmd]) { - _hf_command[head->cmd](slot, pkt, len); + _hf_prv_command[head->cmd](slot, pkt, len); } } return E_NONE; } +/* 高频发包处理函数 */ +int32_t hf_send_process(uint8_t slot, uint8_t type, void *data) +{ + if (_hf_send_command[type]) + { + _hf_send_command[type](slot, data); + } + + return E_NONE; +} + +/* 高频私有数据 */ +void* hf_data_malloc(void) +{ + return XMALLOC_Q(MTYPE_HF, sizeof(hf_data_t)); +} + #endif /************************ (C) COPYRIGHT LandPower ***** END OF FILE ****************/ diff --git a/app/lib/m_management/memory.c b/app/lib/m_management/memory.c index ed2efa2..689d6c4 100644 --- a/app/lib/m_management/memory.c +++ b/app/lib/m_management/memory.c @@ -93,6 +93,7 @@ static mem_node_t mem_list_process[] = { {MTYPE_GIS, "GIS"}, {MTYPE_DAU, "DAU"}, + {MTYPE_HF, "HF"}, {MTYPE_CSG, "CSG"}, {MTYPE_STORAGE, "STORAGE"}, {MTYPE_DEBUG, "DEBUG"},