/****************************************************************************** * 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 * *

© COPYRIGHT(c) 2025 LandPower

* * 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 /* 用户代码头文件. */ #include "pd_main.h" #include "pd_csg.h" #include "pd_dau.h" /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* 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_event_recv(uint8_t slot, char *pkt, uint16_t len); // 命令映射表 static dau_recv_fun_cb _hf_command[] = { NULL, // 0 NULL, // DAU_C_CONTACT 1 NULL, // DAU_C_ADD_DAU 2 NULL, // DAU_C_RESET 3 NULL, // 4 NULL, // DAU_C_UPDATE 5 NULL, // DAU_C_DEV_INFO_SET 6 NULL, // DAU_C_DEV_INFO_GET 7 NULL, // 8 NULL, // DAU_C_UPDATE_RESULT 9 _hf_heartbeat_recv, // DAU_C_HEARTBEAT 10 }; // 命令映射表 static dau_recv_fun_cb _hf_prv_command[] = { NULL, // 0 NULL, // DAU_P_CONFIG_SET 1 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 NULL, // 6 NULL, // 7 NULL, // 8 NULL, // 9 NULL, // DAU_P_TREND 10 NULL, // DAU_P_REAL_PRPS 11 NULL, // DAU_P_EVENT 12 }; /* Interface functions -------------------------------------------------------*/ void _hf_real_image_recv(int slot, char *pkt) { 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)); } void _hf_trend_recv(int slot, char *pkt) { 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)); } /* 心跳报文接收 */ 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)); uint32_t *timestamp = (uint32_t*)(pkt + sizeof(dau_pkt_head_t)); memcpy(&dau->run_status, data, sizeof(dau_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_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)); /* 第一个报文 */ //if (0 == head_event->index) //{ //} 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; } /* 高频收包处理函数 */ 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_command[head->cmd](slot, pkt, len); } } return E_NONE; } #endif /************************ (C) COPYRIGHT LandPower ***** END OF FILE ****************/