You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
819 lines
24 KiB
C
819 lines
24 KiB
C
/******************************************************************************
|
|
* file lib/process/pd_hf.c
|
|
* author YuLiang
|
|
* version 1.0.0
|
|
* date 05-March-2025
|
|
* brief This file provides all the HF operation functions.
|
|
*
|
|
******************************************************************************
|
|
* Attention
|
|
*
|
|
* <h2><center>© COPYRIGHT(c) 2025 LandPower</center></h2>
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
* are permitted provided that the following conditions are met:
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
* 3. Neither the name of LandPower nor the names of its contributors may be used to
|
|
* endorse or promote products derived from this software without specific
|
|
* prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
******************************************************************************/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#ifdef CFG_DEV_TYPE_LAND_PD
|
|
/* 标准C库头文件. */
|
|
#include <math.h>
|
|
|
|
/* 用户代码头文件. */
|
|
#include "pd_main.h"
|
|
#include "pd_csg.h"
|
|
#include "pd_dau.h"
|
|
#include "pd_hf.h"
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* Internal functions --------------------------------------------------------*/
|
|
/* 重启发送 */
|
|
void _hf_send_reset(uint8_t slot, void *data)
|
|
{
|
|
dau_head_init_t head_data;
|
|
dau_t *dau = &daus[slot];
|
|
|
|
/* 回复报文 */
|
|
head_data.cmd_type = DAU_REQUEST;
|
|
head_data.cmd = DAU_C_RESET;
|
|
head_data.pkt_id = dau->pkt_id++;
|
|
head_data.pkt = dau->buf_send;
|
|
head_data.len = sizeof(dau_pkt_head_t);
|
|
|
|
dau_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备信息配置发送 */
|
|
void _hf_send_info_set(uint8_t slot, void *data)
|
|
{
|
|
dau_head_init_t head_data;
|
|
dau_t *dau = &daus[slot];
|
|
hf_dev_info_t *param = (hf_dev_info_t*)(dau->buf_send + sizeof(dau_pkt_head_t));
|
|
|
|
/* 回复报文 */
|
|
head_data.cmd_type = DAU_REQUEST;
|
|
head_data.cmd = DAU_C_DEV_INFO_SET;
|
|
head_data.pkt_id = dau->pkt_id++;
|
|
head_data.pkt = dau->buf_send;
|
|
head_data.len = sizeof(dau_pkt_head_t) + sizeof(hf_dev_info_t);
|
|
|
|
memcpy(param, data, sizeof(hf_dev_info_t));
|
|
|
|
dau_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备信息获取发送 */
|
|
void _hf_send_info_get(uint8_t slot, void *data)
|
|
{
|
|
dau_head_init_t head_data;
|
|
dau_t *dau = &daus[slot];
|
|
|
|
/* 回复报文 */
|
|
head_data.cmd_type = DAU_REQUEST;
|
|
head_data.cmd = DAU_C_DEV_INFO_GET;
|
|
head_data.pkt_id = dau->pkt_id++;
|
|
head_data.pkt = dau->buf_send;
|
|
head_data.len = sizeof(dau_pkt_head_t);
|
|
|
|
dau_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备配置发送 */
|
|
void _hf_send_cfg_set(uint8_t slot, void *data)
|
|
{
|
|
dau_head_init_t head_data;
|
|
dau_t *dau = &daus[slot];
|
|
hf_cfg_t *param = (hf_cfg_t*)(dau->buf_send + sizeof(dau_pkt_head_t));
|
|
|
|
/* 回复报文 */
|
|
head_data.cmd_type = DAU_PRV_REQUEST;
|
|
head_data.cmd = DAU_P_CONFIG_SET;
|
|
head_data.pkt_id = dau->pkt_id++;
|
|
head_data.pkt = dau->buf_send;
|
|
head_data.len = sizeof(dau_pkt_head_t) + sizeof(hf_cfg_t);
|
|
|
|
memcpy(param, data, sizeof(hf_cfg_t));
|
|
|
|
dau_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备配置获取发送 */
|
|
void _hf_send_cfg_get(uint8_t slot, void *data)
|
|
{
|
|
dau_head_init_t head_data;
|
|
dau_t *dau = &daus[slot];
|
|
|
|
/* 回复报文 */
|
|
head_data.cmd_type = DAU_PRV_REQUEST;
|
|
head_data.cmd = DAU_P_CONFIG_GET;
|
|
head_data.pkt_id = dau->pkt_id++;
|
|
head_data.pkt = dau->buf_send;
|
|
head_data.len = sizeof(dau_pkt_head_t);
|
|
|
|
dau_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备端口配置发送 */
|
|
void _hf_send_cfg_set_port(uint8_t slot, void *data)
|
|
{
|
|
dau_head_init_t head_data;
|
|
dau_t *dau = &daus[slot];
|
|
hf_cfg_port_t *param = (hf_cfg_port_t*)(dau->buf_send + sizeof(dau_pkt_head_t));
|
|
|
|
/* 回复报文 */
|
|
head_data.cmd_type = DAU_PRV_REQUEST;
|
|
head_data.cmd = DAU_P_CONFIG_PORT_SET;
|
|
head_data.pkt_id = dau->pkt_id++;
|
|
head_data.pkt = dau->buf_send;
|
|
head_data.len = sizeof(dau_pkt_head_t) + sizeof(hf_cfg_port_t);
|
|
|
|
memcpy(param, data, sizeof(hf_cfg_port_t));
|
|
|
|
dau_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备端口配置获取发送 */
|
|
void _hf_send_cfg_get_port(uint8_t slot, void *data)
|
|
{
|
|
dau_head_init_t head_data;
|
|
dau_t *dau = &daus[slot];
|
|
|
|
/* 回复报文 */
|
|
head_data.cmd_type = DAU_PRV_REQUEST;
|
|
head_data.cmd = DAU_P_CONFIG_PORT_GET;
|
|
head_data.pkt_id = dau->pkt_id++;
|
|
head_data.pkt = dau->buf_send;
|
|
head_data.len = sizeof(dau_pkt_head_t);
|
|
|
|
dau_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* PRPS 关注报文发送 */
|
|
void _hf_send_prps_get(uint8_t slot, void *data)
|
|
{
|
|
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_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* 重启报文接收 */
|
|
void _hf_recv_reset(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
hf_ack_t *ack = (hf_ack_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
hf_ack_t *data = NULL;
|
|
|
|
/* 申请内存 */
|
|
data = XMALLOC(MTYPE_CSG, sizeof(hf_ack_t));
|
|
if (!data)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
/* 装填数据 */
|
|
data->result = ack->result;
|
|
data->slot = slot;
|
|
|
|
/* 发送给后台 */
|
|
if (dau_msg_send_cmd(DAU_SEND_RESET, slot, data) != E_NONE)
|
|
{
|
|
XFREE(MTYPE_CSG, data);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备信息配置报文接收 */
|
|
void _hf_recv_info_set(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
hf_ack_t *ack = (hf_ack_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
hf_ack_t *data = NULL;
|
|
|
|
/* 申请内存 */
|
|
data = XMALLOC(MTYPE_CSG, sizeof(hf_ack_t));
|
|
if (!data)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
/* 装填数据 */
|
|
data->result = ack->result;
|
|
data->slot = slot;
|
|
|
|
/* 发送给后台 */
|
|
if (dau_msg_send_cmd(DAU_SEND_INFO_SET, slot, data) != E_NONE)
|
|
{
|
|
XFREE(MTYPE_CSG, data);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备信息配置报文接收 */
|
|
void _hf_recv_info_get(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
hf_dev_info_t *param = (hf_dev_info_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
hf_dev_info_t *data = NULL;
|
|
|
|
/* 申请内存 */
|
|
data = XMALLOC(MTYPE_CSG, sizeof(hf_dev_info_t));
|
|
if (!data)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
/* 装填数据 */
|
|
memcpy(data, param, sizeof(hf_dev_info_t));
|
|
|
|
/* 发送给后台 */
|
|
if (dau_msg_send_cmd(DAU_SEND_INFO_GET, slot, data) != E_NONE)
|
|
{
|
|
XFREE(MTYPE_CSG, data);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/* 心跳报文接收 */
|
|
void _hf_recv_heartbeat(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;
|
|
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));
|
|
hf_heartbeat_t *param = NULL;
|
|
|
|
memcpy(&hf_data->run_status, data, sizeof(hf_heartbeat_t));
|
|
|
|
/* 回复报文 */
|
|
head_data.cmd_type = DAU_REQUEST;
|
|
head_data.cmd = DAU_C_HEARTBEAT;
|
|
head_data.pkt_id = head->pkt_id;
|
|
head_data.pkt = pkt;
|
|
head_data.len = sizeof(dau_pkt_head_t) + 4;
|
|
*timestamp = time(NULL);
|
|
dau_data_send(dau, &head_data);
|
|
|
|
/* 将心跳计数归零 */
|
|
dau->state.beat_cnt = 0;
|
|
|
|
/* 申请内存 */
|
|
param = XMALLOC(MTYPE_CSG, sizeof(hf_heartbeat_t));
|
|
if (!param)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
/* 装填数据 */
|
|
memcpy(param, &hf_data->run_status, sizeof(hf_heartbeat_t));
|
|
|
|
/* 发送给后台 */
|
|
if (dau_msg_send_cmd(DAU_SEND_HEARTBEAT, slot, data) != E_NONE)
|
|
{
|
|
XFREE(MTYPE_CSG, data);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备配置报文接收 */
|
|
void _hf_recv_cfg_set(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
hf_ack_t *ack = (hf_ack_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
hf_ack_t *data = NULL;
|
|
|
|
/* 申请内存 */
|
|
data = XMALLOC(MTYPE_CSG, sizeof(hf_ack_t));
|
|
if (!data)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
/* 装填数据 */
|
|
data->result = ack->result;
|
|
data->slot = slot;
|
|
|
|
/* 发送给后台 */
|
|
if (dau_msg_send_cmd(DAU_SEND_CFG_SET, slot, data) != E_NONE)
|
|
{
|
|
XFREE(MTYPE_CSG, data);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备配置报文接收 */
|
|
void _hf_recv_cfg_get(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
dau_t *dau = &daus[slot];
|
|
hf_data_t *hf_data = (hf_data_t*)dau->private_data;
|
|
hf_cfg_t *param = (hf_cfg_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
hf_cfg_t *data = NULL;
|
|
|
|
memcpy(&hf_data->cfg, param, sizeof(hf_cfg_t));
|
|
|
|
/* 申请内存 */
|
|
data = XMALLOC(MTYPE_CSG, sizeof(hf_cfg_t));
|
|
if (!data)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
/* 装填数据 */
|
|
memcpy(data, &hf_data->cfg, sizeof(hf_cfg_t));
|
|
|
|
/* 发送给后台 */
|
|
if (dau_msg_send_cmd(DAU_SEND_CFG_GET, slot, data) != E_NONE)
|
|
{
|
|
XFREE(MTYPE_CSG, data);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备端口配置报文接收 */
|
|
void _hf_recv_cfg_set_port(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
hf_cfg_port_ack_t *ack = (hf_cfg_port_ack_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
hf_cfg_port_ack_t *data = NULL;
|
|
|
|
/* 申请内存 */
|
|
data = XMALLOC(MTYPE_CSG, sizeof(hf_cfg_port_ack_t));
|
|
if (!data)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
/* 装填数据 */
|
|
data->vport = ack->vport;
|
|
data->result = ack->result;
|
|
data->slot = slot;
|
|
|
|
/* 发送给后台 */
|
|
if (dau_msg_send_cmd(DAU_SEND_PORT_SET, slot, data) != E_NONE)
|
|
{
|
|
XFREE(MTYPE_CSG, data);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/* 设备端口配置报文接收 */
|
|
void _hf_recv_cfg_get_port(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
dau_t *dau = &daus[slot];
|
|
hf_data_t *hf_data = (hf_data_t*)dau->private_data;
|
|
hf_cfg_port_t *param = (hf_cfg_port_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
hf_cfg_port_t *data = NULL;
|
|
uint8_t port = 0;
|
|
|
|
port = param->vport - 1;
|
|
memcpy(&hf_data->port[port], param, sizeof(hf_cfg_port_t));
|
|
|
|
/* 申请内存 */
|
|
data = XMALLOC(MTYPE_CSG, sizeof(hf_cfg_port_t));
|
|
if (!data)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
/* 装填数据 */
|
|
memcpy(data, &hf_data->port[port], sizeof(hf_cfg_port_t));
|
|
|
|
/* 发送给后台 */
|
|
if (dau_msg_send_cmd(DAU_SEND_PORT_GET, slot, data) != E_NONE)
|
|
{
|
|
XFREE(MTYPE_CSG, data);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/* PRPS 关注报文接收 */
|
|
void _hf_recv_prps_get(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
hf_ack_t *ack = (hf_ack_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
hf_ack_t *data = NULL;
|
|
|
|
/* 申请内存 */
|
|
data = XMALLOC(MTYPE_CSG, sizeof(hf_ack_t));
|
|
if (!data)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
/* 装填数据 */
|
|
data->result = ack->result;
|
|
data->slot = slot;
|
|
|
|
/* 发送给后台 */
|
|
if (dau_msg_send_cmd(DAU_SEND_PRPS_GET, slot, data) != E_NONE)
|
|
{
|
|
XFREE(MTYPE_CSG, data);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/* 趋势报文接收 */
|
|
void _hf_recv_trend(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_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* PRPS 图谱接收 */
|
|
void _hf_recv_prps(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
dau_t *dau = &daus[slot];
|
|
hf_data_t *hf_data = (hf_data_t*)dau->private_data;
|
|
hf_prps_t prps = hf_data->prps;
|
|
hf_prps_t *prps_send = NULL;
|
|
hf_prps_head_t *head_prps = (hf_prps_head_t*)(pkt + sizeof(dau_pkt_head_t));
|
|
char *data = (char*)(pkt + sizeof(dau_pkt_head_t) + sizeof(hf_prps_head_t));
|
|
char *point = NULL;
|
|
|
|
/* 第一个报文 */
|
|
if (0 == head_prps->pkt_index)
|
|
{
|
|
memcpy(&prps.head, head_prps, sizeof(hf_prps_head_t));
|
|
}
|
|
|
|
point = (char*)prps.prps;
|
|
point += head_prps->pkt_index * HF_DATA_LEN;
|
|
memcpy(point, data, head_prps->len);
|
|
|
|
if ((head_prps->pkt_index + 1) == head_prps->pkt_sum)
|
|
{
|
|
/* 申请内存 */
|
|
prps_send = XMALLOC_Q(MTYPE_CSG, sizeof(hf_prps_t));
|
|
if (!prps_send)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return;
|
|
}
|
|
|
|
memcpy(prps_send, &prps, sizeof(hf_prps_t));
|
|
|
|
/* 发送给后台, 内存由后台释放 */
|
|
if (dau_msg_send(DAU_SEND_PRPS, slot, prps_send) != E_NONE)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
/* 事件报文接收 */
|
|
void _hf_recv_event(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_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;
|
|
}
|
|
|
|
point = (char*)event->point;
|
|
point += head_event->index * HF_DATA_LEN;
|
|
memcpy(point, data, head_event->len);
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
/* 回复报文 */
|
|
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_data_send(dau, &head_data);
|
|
|
|
return;
|
|
}
|
|
|
|
/* 校验收到包的包头, 长度, 校验码. */
|
|
int32_t _hf_pkt_check(uint8_t slot, char *pkt)
|
|
{
|
|
dau_t *dau = &daus[slot];
|
|
dau_pkt_head_t *head = (dau_pkt_head_t*)pkt;
|
|
|
|
/* 对主次设备号进行识别, 次设备号可以是广播. */
|
|
if (head->dev_type_m != dau->info.type_m || head->dev_type_s != dau->info.type_s)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "Device type %d:%d ERROR\r\n", head->dev_type_m, head->dev_type_s);
|
|
return E_ERROR;
|
|
}
|
|
|
|
if (head->dev_id != dau->info.dev_id)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "Device id %08x ERROR\r\n", head->dev_id);
|
|
return E_ERROR;
|
|
}
|
|
|
|
if (head->len > DAU_BUF_SIZE)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "Packet len %d ERROR\r\n", head->len);
|
|
return E_ERROR;
|
|
}
|
|
|
|
if ((DAU_REPLY == head->cmd_type && head->cmd >= DAU_C_MAX)
|
|
|| (DAU_PRV_REPLY == head->cmd_type && head->cmd >= DAU_P_MAX))
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "Cmd %d:%d ERROR\r\n", head->cmd_type, head->cmd);
|
|
return E_ERROR;
|
|
}
|
|
|
|
return E_NONE;
|
|
}
|
|
|
|
/* 命令映射表 */
|
|
static hf_recv_fun_cb _hf_command[] =
|
|
{
|
|
NULL, // 0
|
|
NULL, // DAU_C_CONTACT 1
|
|
NULL, // DAU_C_ADD_DAU 2
|
|
_hf_recv_reset, // DAU_C_RESET 3
|
|
NULL, // 4
|
|
NULL, // DAU_C_UPDATE 5
|
|
_hf_recv_info_set, // DAU_C_DEV_INFO_SET 6
|
|
_hf_recv_info_get, // DAU_C_DEV_INFO_GET 7
|
|
NULL, // 8
|
|
NULL, // DAU_C_UPDATE_RESULT 9
|
|
_hf_recv_heartbeat, // DAU_C_HEARTBEAT 10
|
|
};
|
|
|
|
/* 命令映射表 */
|
|
static hf_recv_fun_cb _hf_prv_command[] =
|
|
{
|
|
NULL, // 0
|
|
_hf_recv_cfg_set, // DAU_P_CONFIG_SET 1
|
|
_hf_recv_cfg_get, // DAU_P_CONFIG_GET 2
|
|
_hf_recv_cfg_set_port, // DAU_P_CONFIG_PORT_SET 3
|
|
_hf_recv_cfg_get_port, // DAU_P_CONFIG_PORT_GET 4
|
|
_hf_recv_prps_get, // DAU_P_CONFIG_REAL_WAVE 5
|
|
NULL, // 6
|
|
NULL, // 7
|
|
NULL, // 8
|
|
NULL, // 9
|
|
_hf_recv_trend, // DAU_P_TREND 10
|
|
_hf_recv_prps, // DAU_P_REAL_PRPS 11
|
|
_hf_recv_event, // DAU_P_EVENT 12
|
|
};
|
|
|
|
/* 命令映射表 */
|
|
static hf_send_fun_cb _hf_send_command[] =
|
|
{
|
|
NULL, // 0
|
|
NULL, // DAU_SEND_ADD 1
|
|
_hf_send_reset, // DAU_SEND_RESET 2
|
|
NULL, // 3
|
|
_hf_send_info_set, // DAU_SEND_INFO_SET 4
|
|
_hf_send_info_get, // DAU_SEND_INFO_GET 5
|
|
NULL, // 6
|
|
NULL, // DAU_SEND_HEARTBEAT 7
|
|
_hf_send_cfg_set, // DAU_SEND_CFG_SET 8
|
|
_hf_send_cfg_get, // DAU_SEND_CFG_GET 9
|
|
_hf_send_cfg_set_port, // DAU_SEND_PORT_SET 10
|
|
_hf_send_cfg_get_port, // DAU_SEND_PORT_GET 11
|
|
_hf_send_prps_get, // DAU_SEND_PRPS_GET 12
|
|
NULL, // 13
|
|
NULL, // DAU_SEND_PRPS 14
|
|
NULL, // 15
|
|
};
|
|
|
|
/* Interface functions -------------------------------------------------------*/
|
|
/* 高频收包处理函数 */
|
|
int32_t hf_recv_process(uint8_t slot, char *pkt, uint16_t len)
|
|
{
|
|
dau_pkt_head_t *head = (dau_pkt_head_t*)pkt;
|
|
|
|
/* 报文头和 CRC 校验. */
|
|
LD_E_RETURN_N(_hf_pkt_check(slot, pkt));
|
|
|
|
if (DAU_REPLY == head->cmd_type)
|
|
{
|
|
if (_hf_command[head->cmd])
|
|
{
|
|
_hf_command[head->cmd](slot, pkt, len);
|
|
}
|
|
}
|
|
else if (CSG_PRV_REPLY == head->cmd_type)
|
|
{
|
|
if (_hf_prv_command[head->cmd])
|
|
{
|
|
_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)
|
|
{
|
|
hf_data_t *p = XMALLOC_Q(MTYPE_HF, sizeof(hf_data_t));
|
|
if (!p)
|
|
{
|
|
DBG(DBG_M_PD_HF_ERR, "XMALLOC ERROR!\r\n");
|
|
return NULL;
|
|
}
|
|
|
|
return p;
|
|
}
|
|
|
|
/* 高频私有数据释放 */
|
|
void hf_data_free(uint8_t slot)
|
|
{
|
|
dau_t *dau = &daus[slot];
|
|
hf_data_t *hf_data = (hf_data_t*)dau->private_data;
|
|
|
|
XFREE(MTYPE_HF, hf_data);
|
|
|
|
return;
|
|
}
|
|
|
|
#endif
|
|
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****************/
|