1 Star 0 Fork 10

冰雅轩/libiec10x

forked from MageeLow/libiec10x 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

libiec10x 协议栈使用说明

概述

功能简述 : 支持 104 / 平衡101 /非平衡101 的主从站的基本功能
程序语言 : C 语言
语言版本 : C99 标准
应用平台 : linux / 嵌入式
字符编码 : UTF-8
应用概述 : 协议栈基于事件回调,有无操作系统下皆可运行,且为面向对象架构, 一个连接为一条总线,适用于中小型场合(连接数小于250)。协议栈支持 101/104 主从连接并存, 并且每个连接可带不同的链路参数。协议栈对硬件抽象,需要用户提供硬件发送相关函数。协议用标准 C99 编写,理论上可以移植到任何支持 C99 的嵌入式平台(尚未验证)。

基本使用流程

下面以 101 规约总线使用为例:

0> 假设已实现硬件层相关的初始化,并编写硬件发送函数 void iec10x_puts(uint8_t * data, int len) ;

1> 初始化一次协议栈 iec10x_protocol_init();并提供 100ms 一次的 iec10x_periodic_handle() 轮询 ;

2> 新建全局/静态总线 iec10x_t bus ; 编写对应的初始化结构体 struct iec101cfg buscfg ;

3> iec10x_bus_init(&bus,101,&cfg,usrinit); 初始化总线,其中 usrinit 为用户层初始化函数

4> bus 接收到一包数据后,无论是否断包,交由 iec10x_recv(&bus,data,len) 处理

文件架构

其中,60870-5 为 iec10x 协议栈的具体实现,内容大致如下

./60870-5/
|-- 10x
|-- type
|-- iec
|-- iec_file.c
|-- iec_file.h
|-- iec_list.h
|-- iec_sys.h
`-- iec10x.h

其中,
10x 文件夹是协议栈具体的流程实现;
iec 文件夹是协议栈组件,如内存管理等;
type 文件夹定义了规约中常用的数据结构,如 SIQ.h 即单点遥信相关头文件;
iec_list.h 为协议栈中链表的实现;
iec10x.h 是唯一对外提供的 api 头文件,所有供用户使用的接口都在此头文件; 在协议栈的使用上可不去改动以上的内容,除非是需要进行协议栈的拓展。具体的软件设计流程后文详述。

主要移植项为以下文件:
iec_file.c,iec_file.h 是规约文件传输所需要进行移植的相关接口;此处提供了在 linux 下的文件接口。
iec_sys.h 为协议栈基本的配置条目,如配置协议栈是否打印调试信息等;

另外,lesson 中存放了 linux 平台的协议栈具体示例,工程基于 CMake 构建,在对应的文件夹执行 ./build.sh 脚本进行编译。工程文件夹后缀序号代表示例应用程度由简至繁,可作为入门参考。还在更新...

API 简述

目前 libiec10x 协议栈的所有应用 API 都集成在 iec10x.h 头文件中,在应用上只需要 include 这个头文件即可。
协议栈使用面向对象的设计方法,每一个主从站链接用一个 struct iec10x 表示,此处记为总线,一个 struct iec10x 包含了通讯过程中的中间参数、状态机和通讯参数等信息,在使用时可不关心里面的内容,只需知道协议栈所有的 api 主体 都为此结构体。

/**
  * @brief    定时轮询,此函数需要用户实现周期调用一次,建议 100ms / 50ms / 25ms
  * @note     此函数的轮询周期也决定了总线的发送频率,即每包的间隔
  * @param    localtime  : 毫秒精度的系统时间戳
  * @return   don't care
*/
void iec10x_periodic_handle(size_t localtime);


/**
  * @brief    总线接收数据并解析
  * @param    bus   : 需要解析的总线结构体 
  * @param    data  : 包数据 
  * @param    len   : 包数据长度
  * @return   don't care
*/
void iec10x_recv(iec10x_t * bus , uint8_t * data , int len);


/**
  * @brief    用户设备接口管理注册
  * @param    bus      : 目标总线
  * @param    type     : 当前数据接口的类型
  * @param    statfn   : 信息结构体状态获取接口
  * @param    getfn    : 信息体结构体内容获取接口
  * @param    profn    : 信息体结构体内容处理接口
  * @return   成功返回 0 ,否则返回其他
*/
int iec10x_devif_register(
	iec10x_t *         bus       ,
	unsigned char      type      ,
	dev_statfn_t       statfn    ,
	dev_getfn_t        getfn     ,
	dev_profn_t        profn   ) ;

/// 下次更,下次一定

软件设计框架及功能拓展

/// 有空再更,下次,下次一定

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

iec101/iec104 协议栈 C 语言实现 展开 收起
C
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/ice_elegant/libiec10x.git
git@gitee.com:ice_elegant/libiec10x.git
ice_elegant
libiec10x
libiec10x
master

搜索帮助

246c6175 1850385 950819b3 1850385