feat(libmodbus_m): 导入 Modbus 主站管理模块(原工程自研)
- 从原工程 src/system/libmodbus_m 复制 modbus_m.h + modbus_m.cpp (~1K行) - 新增 mySystem.h: stru_app 任务上下文 + 公用定义 - 新增 myModbusM.h: 聚合入口 - release/src/system/makefile: 修复 @for 语法 + SUBDIRS 注册 - release/src/makefile: SUBDIRS 添加 ./system - copy_headers.sh: 新增 copy_sys_module/copy_sys_header 函数 适配修改(原工程 API → 本项目 API): - SIGNAL_CTRL_STEP → dc_ctrl_step_t / SIGNAL_CTRL_TYPE → dc_ctrl_type_t - DIRECT_NORMAL → DC_CTRL_DIRECT / EV_TIMER1-3 → 0x01/0x02/0x04 - func_get_process_self_dir → func_proc_self_dir - dc_create_data_ptr_by_type → dc_create_data - 回调签名 std::string → const char*
This commit is contained in:
parent
7b1bbba325
commit
78d48e537e
|
|
@ -49,6 +49,37 @@ copy_proto_module()
|
|||
fi
|
||||
}
|
||||
|
||||
# --- system/ 模块下的头文件 ---
|
||||
copy_sys_module()
|
||||
{
|
||||
local module="$1"
|
||||
local header="$2"
|
||||
local src="$SRC_DIR/system/$module/inc/$header"
|
||||
|
||||
if [ -f "$src" ]
|
||||
then
|
||||
cp -f "$src" "$DST_DIR/"
|
||||
echo " [system/$module] $header"
|
||||
else
|
||||
echo " [WARN] $src not found, skip"
|
||||
fi
|
||||
}
|
||||
|
||||
# --- system/ 公共头文件 ---
|
||||
copy_sys_header()
|
||||
{
|
||||
local header="$1"
|
||||
local src="$SRC_DIR/system/inc/$header"
|
||||
|
||||
if [ -f "$src" ]
|
||||
then
|
||||
cp -f "$src" "$DST_DIR/"
|
||||
echo " [system/inc] $header"
|
||||
else
|
||||
echo " [WARN] $src not found, skip"
|
||||
fi
|
||||
}
|
||||
|
||||
# ================================================================
|
||||
# 公共库模块(按顺序添加)
|
||||
# ================================================================
|
||||
|
|
@ -71,4 +102,10 @@ copy_module "libcomm" "myComm.h"
|
|||
copy_proto_module "libmodbus" "myModbus.h"
|
||||
copy_proto_module "lib60870" "myIec60870.h"
|
||||
|
||||
# ================================================================
|
||||
# 系统模块(system/)
|
||||
# ================================================================
|
||||
copy_sys_header "mySystem.h"
|
||||
copy_sys_module "libmodbus_m" "myModbusM.h"
|
||||
|
||||
echo "=== done ==="
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS := ./public ./protocol
|
||||
SUBDIRS := ./public ./protocol ./system
|
||||
define make_subdir
|
||||
for d in $(SUBDIRS); do [ -f "$$d/makefile" ] && (cd "$$d" && make -f makefile $1) || true; done
|
||||
endef
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
include ./../../../linux.mk
|
||||
L := $(notdir $(realpath $(CURDIR)/..))
|
||||
M := libmodbus_m
|
||||
O := $(LIB_REL)/$(M).a
|
||||
S := $(SRC_ROOT_DIR)/$(L)/libmodbus_m/src
|
||||
I := -I$(SRC_ROOT_DIR)/$(L)/libmodbus_m/inc \
|
||||
-I$(SRC_ROOT_DIR)/$(L)/inc \
|
||||
-I$(SRC_ROOT_DIR)/protocol/libmodbus/inc \
|
||||
-I$(SRC_ROOT_DIR)/public/libxml/inc \
|
||||
-I$(SRC_ROOT_DIR)/public/libdatacenter/inc \
|
||||
-I$(SRC_ROOT_DIR)/public/liblog/inc \
|
||||
-I$(SRC_ROOT_DIR)/public/libfunc/inc \
|
||||
-I$(SRC_ROOT_DIR)/public/libcmd/inc \
|
||||
-I$(SRC_ROOT_DIR)/public/libtask/inc \
|
||||
-I$(SRC_ROOT_DIR)/public/libmy_xxhash/inc
|
||||
B := $(CURDIR)/$(M)/obj
|
||||
SRCS := $(wildcard $(S)/*.cpp)
|
||||
OBJS := $(patsubst $(S)/%.cpp, $(B)/%.o, $(SRCS))
|
||||
F := $(CXX_FLAGS) $(I)
|
||||
|
||||
.PHONY: all
|
||||
all:
|
||||
@mkdir -p $(ROOT_DIR)/release/inc
|
||||
@$(MAKE) $(O)
|
||||
|
||||
$(O): $(OBJS)
|
||||
@mkdir -p $(dir $@)
|
||||
$(AR) rcs $@ $^
|
||||
@echo "[$(M)] built"
|
||||
|
||||
$(B)/%.o: $(S)/%.cpp
|
||||
@mkdir -p $(dir $@)
|
||||
$(CXX) $(F) -c $< -o $@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(B) $(O)
|
||||
|
||||
.PHONY: rebuild
|
||||
rebuild: clean all
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
SUBDIRS :=
|
||||
SUBDIRS := ./libmodbus_m
|
||||
define make_subdir
|
||||
@for d in $(SUBDIRS); do [ -f "$$d/makefile" ] && (cd "$$d" && make -f makefile $1) || true; done
|
||||
for d in $(SUBDIRS); do [ -f "$$d/makefile" ] && (cd "$$d" && make -f makefile $1) || true; done
|
||||
endef
|
||||
.PHONY: all; all:; $(call make_subdir,all)
|
||||
.PHONY: clean; clean:; $(call make_subdir,clean)
|
||||
.PHONY: rebuild; rebuild: clean all
|
||||
.PHONY: all clean rebuild
|
||||
all:; @$(call make_subdir,all)
|
||||
clean:; @$(call make_subdir,clean)
|
||||
rebuild: clean all
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @file mySystem.h
|
||||
* @brief 系统管理模块公共定义
|
||||
* @details 供 libmodbus_m/libiec/libcom_decode/RTU 等系统模块共用。
|
||||
*/
|
||||
#ifndef _MY_SYSTEM_H_
|
||||
#define _MY_SYSTEM_H_
|
||||
|
||||
#include "myBase.h"
|
||||
#include "myTask.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** @brief 应用任务上下文(RTU 多任务运行时使用) */
|
||||
typedef struct
|
||||
{
|
||||
const char *name; /**< 任务名称 */
|
||||
stru_task_event_t p_event; /**< 事件句柄 */
|
||||
stru_task_msg_queue_t p_queue; /**< 消息队列句柄 */
|
||||
uint32_t run_cnt; /**< 运行计数 */
|
||||
} stru_app;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _MY_SYSTEM_H_ */
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
#pragma once
|
||||
|
||||
#include "myBase.h"
|
||||
#include "mySystem.h"
|
||||
#include "myModbus.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#define MODULE_MODBUS_M "modbus_m"
|
||||
|
||||
#define MODBUS_M_STR_LEN 64
|
||||
#define MODBUS_M_MAX_SLAVE_NUM 16
|
||||
|
||||
// 通讯通道配置
|
||||
typedef struct
|
||||
{
|
||||
uint32_t id; // 通道ID
|
||||
std::string mode; // "tcp" 或 "rtu"
|
||||
std::string host; // TCP 目标IP
|
||||
uint16_t port; // TCP 目标端口
|
||||
std::string device; // RTU 串口设备
|
||||
int baud; // RTU 波特率
|
||||
char parity; // RTU 校验位
|
||||
int data_bit; // RTU 数据位
|
||||
int stop_bit; // RTU 停止位
|
||||
int timeout_ms; // 请求超时
|
||||
int retry_cnt; // 失败重试次数
|
||||
modbus_t *ctx; // libmodbus 上下文
|
||||
bool connected; // 连接状态
|
||||
}stru_modbus_m_channel;
|
||||
|
||||
// 点表条目
|
||||
typedef struct
|
||||
{
|
||||
uint16_t no; // 序号
|
||||
uint8_t type; // 数据类型: 2=bit, 4=uint16, 6=float32, 7=uint32, 13=string
|
||||
uint32_t channel; // 归属通道ID
|
||||
uint8_t slave; // 从站地址
|
||||
uint8_t fc; // 功能码
|
||||
uint16_t addr; // 寄存器/线圈起始地址
|
||||
uint16_t count; // 连续读取数量
|
||||
uint8_t bit; // 位位置(0-15),type=2且fc=03/04时有效
|
||||
float factor; // 遥测系数
|
||||
float offset; // 遥测偏移
|
||||
std::string saddr; // 内部信号地址
|
||||
std::string desc; // 描述
|
||||
void *p_val; // 数据指针
|
||||
}stru_modbus_m_item;
|
||||
|
||||
// 点表页
|
||||
typedef struct
|
||||
{
|
||||
std::string desc;
|
||||
std::vector<stru_modbus_m_item> st_vec; // 遥信
|
||||
std::vector<stru_modbus_m_item> mx_vec; // 遥测
|
||||
std::vector<stru_modbus_m_item> co_vec; // 遥控
|
||||
std::vector<stru_modbus_m_item> ao_vec; // 参数
|
||||
}stru_modbus_m_point;
|
||||
|
||||
// 写请求(用于 Co/Ao 异步写入)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t channel;
|
||||
uint8_t slave;
|
||||
uint8_t fc;
|
||||
uint16_t addr;
|
||||
uint16_t value;
|
||||
bool is_coil; // true=写线圈, false=写寄存器
|
||||
}stru_modbus_m_write_req;
|
||||
|
||||
// 模块主配置
|
||||
typedef struct
|
||||
{
|
||||
std::vector<stru_modbus_m_channel> channels;
|
||||
stru_modbus_m_point point;
|
||||
}stru_modbus_m_cfg;
|
||||
|
||||
|
||||
// API 声明
|
||||
int modbus_m_init();
|
||||
int modbus_m_cfg_parse(const std::string &path);
|
||||
void modbus_m_show_info();
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* @file myModbusM.h
|
||||
* @brief Modbus 主站管理模块统一入口
|
||||
* @details 原工程自研模块,通过 XML 配置通道和点表,轮询读取 Modbus 从站数据,
|
||||
* 写入 libdatacenter,支持遥控/遥调异步写入。
|
||||
* 调用者只需 #include "myModbusM.h"。
|
||||
*/
|
||||
#ifndef _MY_MODBUS_M_H_
|
||||
#define _MY_MODBUS_M_H_
|
||||
|
||||
#include "modbus_m.h"
|
||||
|
||||
#endif /* _MY_MODBUS_M_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue