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.

117 lines
3.2 KiB
C

/* Includes ------------------------------------------------------------------*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef CFG_DEV_TYPE_LAND_PD
/* 标准C库头文件. */
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>
/* 用户代码头文件. */
#include "pd_csgiron.h"
#include "pd_csg.h"
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Internal functions --------------------------------------------------------*/
int32_t _csgiron_config_port_get(uint8_t slot, char* pkt, uint16_t len)
{
csg_pkt_head_t *head = (csg_pkt_head_t*)pkt;
iron_config_t *pdata = (iron_config_t*)(pkt + sizeof(csg_pkt_head_t));
pdata->vport = slot + 1;
pdata->report_period = pd_config.config_slot[slot].report_period;
_csg_send_data(CSG_PRV_REPLY, head->cmd, pkt, sizeof(iron_config_t), slot + 1);
return E_NONE;
}
int32_t _csgiron_config_port_set(uint8_t slot, char* pkt, uint16_t len)
{
csg_pkt_head_t *head = (csg_pkt_head_t*)pkt;
iron_config_t *pdata = (iron_config_t*)(pkt + sizeof(csg_pkt_head_t));
pd_config.config_slot[slot].report_period = pdata->report_period;
vtysh_config_save();
iron_ack_t ack = {0};
ack.vport = slot + 1;
ack.result = TRUE;
memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(iron_ack_t));
_csg_send_data(CSG_PRV_REPLY, head->cmd, pkt, sizeof(iron_ack_t), slot + 1);
return E_NONE;
}
int32_t _csgiron_modbus_reply(uint8_t slot, char* pkt, uint16_t len)
{
//csg_pkt_head_t *head = (csg_pkt_head_t*)pkt;
//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, head->cmd, pkt, sizeof(csg_ack_t), slot + 1);
return E_NONE;
}
/* 命令映射表 */
static csgiron_recv_fun_cb _csgiron_command[] =
{
NULL, // 0
};
/* 命令映射表 */
static csgiron_recv_fun_cb _csgiron_prv_command[] =
{
NULL, // 0
NULL, // CSG_PRV_CONFIG_GLOBAL_SET
NULL, // CSG_PRV_CONFIG_GLOBAL_GET
_csgiron_config_port_set, // CSG_PRV_CONFIG_PORT_SET
_csgiron_config_port_get, // CSG_PRV_CONFIG_PORT_GET
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL, // CSG_PRV_MODBUS
NULL
};
int32_t _csgiron_recv_process(uint8_t slot, char *pkt, uint16_t len)
{
dau_pkt_head_t *head = (dau_pkt_head_t*)pkt;
if (CSG_REQUEST == head->cmd_type)
{
if (_csgiron_command[head->cmd])
{
_csgiron_command[head->cmd](slot, pkt, len);
}
}
else if (CSG_PRV_REQUEST == head->cmd_type)
{
if (_csgiron_prv_command[head->cmd])
{
_csgiron_prv_command[head->cmd](slot, pkt, len);
}
}
return E_NONE;
}
#endif