modify timer by wangweigen

This commit is contained in:
Yan_yan 2020-12-03 10:55:41 +08:00
parent 27a4e38b1e
commit 2f0273094d
7 changed files with 80 additions and 101 deletions

View File

@ -15,9 +15,9 @@ XiUOS的传感器框架以用户为中心采用了以物理量为中心的抽
* struct xs_SensorQuantity结构
```c
struct xs_SensorQuantity {
const char name[XS_NAME_MAX]; /* name of the sensor quantity instance */
enum xs_SensorQuantityType type; /* type of data the sensor collects, such as CO2 concentration */
struct xs_SensorDevice *sdev; /* corresponding sensor device */
const char name[XS_NAME_MAX]; /* name of the sensor quantity instance */
enum xs_SensorQuantityType type; /* type of data the sensor collects, such as CO2 concentration */
struct xs_SensorDevice *sdev; /* corresponding sensor device */
struct XS_DOUBLE_LINKLIST_NODE link; /* link list node */
};
```
@ -27,8 +27,8 @@ type成员表示该xs_SensorQuantity可测量的物理量用一个枚举变
```c
enum xs_SensorQuantityType {
XS_SENSOR_QUANTITY_CO2 = 0, /* CO2 concentration */
XS_SENSOR_QUANTITY_TEMP, /* temperature */
XS_SENSOR_QUANTITY_HUMI, /* humidity */
XS_SENSOR_QUANTITY_TEMP, /* temperature */
XS_SENSOR_QUANTITY_HUMI, /* humidity */
/* ...... */
XS_SENSOR_QUANTITY_END,
};
@ -41,11 +41,11 @@ sdev成员表示该xs_SensorQuantity所属的xs_SensorDevice结构其具体
* struct xs_SensorDevice结构
```c
struct xs_SensorDevice {
const char name[XS_NAME_MAX]; /* name of the sensor device */
struct xs_SensorProductInfo info; /* sensor model info, such as vendor name and model name */
struct xs_SensorOps ops; /* filesystem-like APIs for data transferring */
struct xs_SensorInterface interface; /* physical interface for transferring data */
struct XS_DOUBLE_LINKLIST_NODE link; /* link list node */
const char name[XS_NAME_MAX]; /* name of the sensor device */
struct xs_SensorProductInfo info; /* sensor model info, such as vendor name and model name */
struct xs_SensorOps ops; /* filesystem-like APIs for data transferring */
struct xs_SensorInterface interface; /* physical interface for transferring data */
struct XS_DOUBLE_LINKLIST_NODE link; /* link list node */
};
```
name成员记录传感器设备在系统中的名字用于唯一标识一个xs_SensorDevice结构
@ -58,7 +58,7 @@ info成员记录传感器设备的一些属性信息包括传感器的能力a
/* ...... */
struct xs_SensorProductInfo {
uint32_t ability; /* bitwise OR of XS_SENSOR_ABILITY_XXX */
uint32_t ability; /* bitwise OR of XS_SENSOR_ABILITY_XXX */
const char *vendor;
const char *product_model;
};
@ -112,9 +112,7 @@ struct xs_SensorOps co2_example_ops = {
};
```
实现xs_SensorQuantityCo2中的read_concentration接口该接口用于读取当前空气中的二氧化碳浓度。在实现过程中可以使用xs_SensorOps中的接口与传感器进行通信。
最后将传感器设备添加到传感器框架。分别填充xs_SensorDevice与对应物理量的xs_SensorQuantity结构二氧化碳即为xs_SensorQuantityCo2)并依次使用xs_SensorDeviceRegister和xs_SensorQuantityRegister函数将其注册到传感器框架
实现xs_SensorQuantityCo2中的read_concentration接口该接口用于读取当前空气中的二氧化碳浓度。在实现过程中可以使用xs_SensorOps中的接口与传感器进行通信。最后将传感器设备添加到传感器框架。分别填充xs_SensorDevice与对应物理量的xs_SensorQuantity结构二氧化碳即为xs_SensorQuantityCo2)并依次使用xs_SensorDeviceRegister和xs_SensorQuantityRegister函数将其注册到传感器框架
```c
int xs_SensorDeviceRegister(struct xs_SensorDevice *sdev);
int xs_SensorQuantityRegister(struct xs_SensorQuantity *quant);
@ -168,7 +166,7 @@ void xs_SensorQuantityClose(struct xs_SensorQuantity *quant);
uint32_t xs_SensorCo2Read(struct xs_SensorQuantityCo2 *quant);
```
在获取数据前,需要先获取并打开要使用的传感器;传感器打开后可以随时对传感器数据进行读取;使用完毕后,须关闭传感器。完整的使用过程示例如下:
在获取数据前需要先获取并打开要使用的传感器,传感器打开后可以随时对传感器数据进行读取,使用完毕必须关闭传感器。完整的使用过程示例如下:
```c
int main(int argc, char *argv[])
{

View File

@ -8,10 +8,10 @@ XiUOS 应用程序框架中的“控”子框架从“控制需求”本身出
```c
struct xs_PlcAbility {
const char name[XS_NAME_MAX]; /* name of the PLC ability instance */
enum xs_PlcCtlType type; /* type of control the plcable to excute, such as HSC or PID control */
char address[XS_PLC_ADDRESS_MAX]; /* The address for this function in the PLC*/
struct xs_PlcDevice *pdev;/* corresponding PLC device */
const char name[XS_NAME_MAX]; /* name of the PLC ability instance */
enum xs_PlcCtlType type; /* type of control the plcable to excute, such as HSC or PID control */
char address[XS_PLC_ADDRESS_MAX]; /* The address for this function in the PLC*/
struct xs_PlcDevice *pdev; /* corresponding PLC device */
struct XS_DOUBLE_LINKLIST_NODE link;/* link list node */
};
```
@ -20,36 +20,32 @@ name成员是一个可读的名字用于唯一标识一个xs_PlcAbility结构
type成员表示该xs_PlcAbility可控制的类型用一个枚举变量表示
```c
enum xs_PLcCtlType {
XS_PLC_CONTROL_TYPE_HSC = 0, /* high-speed counter */
XS_PLC_CONTROL_TYPE_PID , /* proportional,integral,derivative */
XS_PLC_CONTROL_TYPE_PHASING , /* phasing control*/
enum xs_PlcCtlType {
XS_PLC_CONTROL_TYPE_HSC = 0, /* high-speed counter */
XS_PLC_CONTROL_TYPE_PID , /* proportional,integral,derivative */
XS_PLC_CONTROL_TYPE_PHASING , /* phasing control*/
/* ...... */
XS_PLC_CONTROL_TYPE_END,
};
```
由于 PLC 里控制指令执行都是向数据模块DB写数据,需要知道该函数功能对应的数据块地址这个用address标识。
pdev成员表示该xs_PlcAbility所属的xs_PlcDevice结构其具体定义在下文给出。
最后在系统中不同控制类型的xs_PlcAbility被分别组织成不同的双链表如高速计数器xs_PlcAbility链表、PID控制xs_PlcAbility链表等使用的链表节点即为link成员。
由于 PLC 里控制指令执行都是向数据模块DB写数据,需要知道该函数功能对应的数据块地址这个用address标识。pdev成员表示该xs_PlcAbility所属的xs_PlcDevice结构其具体定义在下文给出。 最后在系统中不同控制类型的xs_PlcAbility被分别组织成不同的双链表如高速计数器xs_PlcAbility链表、PID控制xs_PlcAbility链表等使用的链表节点即为link成员。
```c
struct xs_PlcDevice {
const char name[XS_NAME_MAX]; /* name of the device */
struct xs_PlcInfo info;/* PLC info, such as vendor name and model name */
struct xs_PlcOps ops;/* filesystem-like APIs for data transferring */
struct xs_PlcInterface interface;/* protocls used for transferring data from program to PLC */
structXS_DOUBLE_LINKLIST_NODE link;/* link list node */
const char name[XS_NAME_MAX]; /* name of the device */
struct xs_PlcInfo info; /* PLC info, such as vendor name and model name */
struct xs_PlcOps ops; /* filesystem-like APIs for data transferring */
struct xs_PlcInterface interface; /* protocls used for transferring data from program to PLC */
structXS_DOUBLE_LINKLIST_NODE link; /* link list node */
};
```
name成员记录 PLC 设备在系统中的名字用于唯一标识一个xs_PlcDevice结构。
```c
structxs_PlcInfo {
struct xs_PlcInfo {
uint32_t ability;
const char *vendor;
const char *product_model;
@ -65,7 +61,7 @@ info成员记录 PLC 设备的一些属性信息,包括 PLC 的能力ability
/* ...... */
```
ps成员包含统一的、类似文件系统的API用于和 PLC 设备通信,进行实际的数据读写和对 PLC 设备实现控制功能。在使用一个 PLC 设备前后需要打开open/关闭close该 PLC实际为建立和关闭连接read、write分别用与从 PLC 接收数据与向 PLC 发送数据ioctl用于向 PLC 设备发送控制指令:
ops成员包含统一的、类似文件系统的API用于和 PLC 设备通信,进行实际的数据读写和对 PLC 设备实现控制功能。在使用一个 PLC 设备前后需要打开open/关闭close该 PLC实际为建立和关闭连接read、write分别用与从 PLC 接收数据与向 PLC 发送数据ioctl用于向 PLC 设备发送控制指令:
```c
structxs_PlcOps {
@ -90,16 +86,16 @@ xs_plc_protocol和xs_plc_transport是两个枚举类型标识 PLC 设备和
```c
enum xs_plc_protocol{
AB-ETH = 0,
ADS/AMS,
BACnet/IP,
AB_ETH = 0,
ADS_AMS,
BACnet_IP,
DeltaV,
DF1,
EtherNet/IP,
EtherNet_IP,
Firmata,
KNXnet/IP,
KNXnet_IP,
Modbus,
OPC UA,
OPC_UA,
S7,
Simulated,
};
@ -107,8 +103,8 @@ enum xs_plc_transport{
TCP = 0,
UDP,
Serial,
Raw Socket,
PCAP Replay,
Raw_Socket,
PCAP_Replay,
};
```
@ -151,20 +147,19 @@ structxs_PlcOpshsc_example_ops = {
```c
struct hsc_write{
char id[id_max]; /* id_max is to identify the max HSC ctrl instruction of HSC */
int cmd; /* HSC control type *
int cmd; /* HSC control type */
};
```
其中id用来标识HSC, cmd表示要发送的具体指令具体的指令可以用一个枚举类型来表示
其中id用来标识HSCcmd表示要发送的具体指令具体的指令可以用一个枚举类型来表示
```c
enum HscCmdSubType{
EnHsc = 0; /* enable HSC */
EnCapture; /* enable the function of capturing the inputs */
EnSync; /* enable the function of synchronous inputs */
EnHSCRESET
En_CTRL_UPTODOWN
EnHsc = 0, /* enable HSC */
EnCapture, /* enable the function of capturing the inputs */
EnSync, /* enable the function of synchronous inputs */
EnHSCRESET,
En_CTRL_UPTODOWN ,
... ...
};
@ -174,15 +169,15 @@ enum HscCmdSubType{
```c
enum PIDcmdSubType{
ENHsc = 0
EN_XS_PLC_CONTROL_TYPE_PID_COMPACT
XS_PLC_CONTROL_TYPE_PID_3STEP /* valve of motor-driven */
ENHsc = 0,
EN_XS_PLC_CONTROL_TYPE_PID_COMPACT,
XS_PLC_CONTROL_TYPE_PID_3STEP , /* valve of motor-driven */
... ...
};
enum PHASEcmdSubType{
ENPhase = 0
XS_PLC_CONTROL_TYPE_PHASING_MC_HALT
XS_PLC_CONTROL_TYPE_PHASING_MC_HALT_MOVE_ABSOLUTE
ENPhase = 0,
XS_PLC_CONTROL_TYPE_PHASING_MC_HALT,
XS_PLC_CONTROL_TYPE_PHASING_MC_HALT_MOVE_ABSOLUTE,
... ...
}
```
@ -192,9 +187,9 @@ enum PHASEcmdSubType{
```c
struct hsc_read{
uint32_t value; /* the main value you want to get, depends on the cmd */
bool done; /* indicate whether the SFB has been done */
bool busy; /* indicate whether the function is busy */
bool error; /* indicate whether there is error */
bool done; /* indicate whether the SFB has been done */
bool busy; /* indicate whether the function is busy */
bool error; /* indicate whether there is error */
};
```

View File

@ -19,22 +19,22 @@ xs_Adapter可以被设计为采用类似面向对象的方法针对不同的
```c
struct xs_Adapter
{
    const char name[XS_NAME_MAX]; /* name of the adapter instance */
    enum xs_AdapterType type;      /* type of adapter, such as lora adapter */
    xs_AdapterInfo info;   /* adapter model info, such as vendor name and model name */
    struct xs_AdapterOps ops; /* socket-like APIs for data transferring */
    struct xs_AdapterInterface interface; /* physical interface for transferring data */
    struct XS_DOUBLE_LINKLIST_NODE link; /* link list node */
    const char name[XS_NAME_MAX];  /* name of the adapter instance */
    enum xs_AdapterType type;       /* type of adapter, such as lora adapter */
    xs_AdapterInfo info;    /* adapter model info, such as vendor name and model name */
    struct xs_AdapterOps ops;  /* socket-like APIs for data transferring */
    struct xs_AdapterInterface interface;  /* physical interface for transferring data */
    struct XS_DOUBLE_LINKLIST_NODE link;  /* link list node */
};
```
name成员是一个可读的名字用于唯一标识一个xs_Adapter结构。type成员表示该xs_Adapter所使用的网络协议用一个枚举变量表示
```c
enum xs_AdapterType {
    XS_ADAPTER_LORA = 0, /* Lora */
    XS_ADAPTER_4G ,      /* 4G */
    XS_ADAPTER_LORA = 0,  /* Lora */
    XS_ADAPTER_4G ,       /* 4G */
    /* ...... */
    XS_ADAPTER_WIFI ,    /* Wifi */
    XS_ADAPTER_WIFI ,     /* Wifi */
};
```
@ -84,9 +84,8 @@ net_type代表的含义是使用传统的中心化网络或者自组网络。
```c
struct xs_AdapterLora {
    struct xs_Adapter parent; /* inherit from xs_Adapter */
    const char *deve_ui; /* Lora specific value */
    const char *app_key; /* Lora specific value */
    const char *deve_ui;  /* Lora specific value */
    const char *app_key;  /* Lora specific value */
};
```

View File

@ -3,7 +3,7 @@
## 1. 背景及动机
印刷和包装行业中大量使用油墨,润版液,废定影液,油性上光材料等不可避免地会对生产环境造成危害,会对工人的健康造成威胁,会对产品的质量造成损害。浙江大胜达包装股份有限公司非常重视生产环境保护,以工人健康为己任,积极提高产品质量。基于此背景,大胜达智能环境智能感知系统应运而生。
大胜达智能环境智能感知系统主要采集PM1.0PM2.5PM10AQSTVOC甲醛乙醇二氧化碳噪音甲烷温度湿度气压风速风向等环境因子此外还包括部分机器电能消耗的监测。当印刷机高速运转时墨膜分裂产生断片进而形成细小球状墨滴散落在空气中形成飞墨所以对PM1.0PM2.5PM10三种参数的监测可以有效反映飞墨现象在印刷过程的严重程度从而对高精度印刷产品质量的保障提供精准控制的参数支持。印刷过程中油墨溶剂包含了芳香烃类酯类酮类醚类等有机化合物这些化合物或多或少具有一定毒性。同时在印刷原材料中对甲醛和乙醇使用也较为广泛所以对TVOC和AQS的监测可以有效监测空气中这些有机化合物的浓度对工人的健康保护起到提示和预警作用对甲醛和乙醇这些挥发性较大的有机物的监测可以反映出原材料使用和管控的精细程度为企业节约原材料成本提供参数支持。大量的印刷机同时运转时会产生大强度的机器噪音和消耗大量的电能所以对噪音和电能的监测不仅可以帮助工人排查噪音干扰提高工作效率而且更为企业合理安排印刷机器的开机数量和节能减排提供依据。甲烷温度湿度气压和空气流动性等指标是印刷产品质量保证和安全生产必须参考的参数。
大胜达智能环境智能感知系统主要采集PM1.0、PM2.5、PM10、AQS、TVOC、甲醛、乙醇、二氧化碳、噪音、甲烷、温度、湿度、气压、风速、风向等环境因子此外还包括部分机器电能消耗的监测。当印刷机高速运转时墨膜分裂产生断片进而形成细小球状墨滴散落在空气中形成飞墨所以对PM1.0PM2.5PM10三种参数的监测可以有效反映飞墨现象在印刷过程的严重程度从而对高精度印刷产品质量的保障提供精准控制的参数支持。印刷过程中油墨溶剂包含了芳香烃类酯类酮类醚类等有机化合物这些化合物或多或少具有一定毒性。同时在印刷原材料中对甲醛和乙醇使用也较为广泛所以对TVOC和AQS的监测可以有效监测空气中这些有机化合物的浓度对工人的健康保护起到提示和预警作用对甲醛和乙醇这些挥发性较大的有机物的监测可以反映出原材料使用和管控的精细程度为企业节约原材料成本提供参数支持。大量的印刷机同时运转时会产生大强度的机器噪音和消耗大量的电能所以对噪音和电能的监测不仅可以帮助工人排查噪音干扰提高工作效率而且更为企业合理安排印刷机器的开机数量和节能减排提供依据。甲烷温度湿度气压和空气流动性等指标是印刷产品质量保证和安全生产必须参考的参数。
## 2. 基于XiUOS的环境智能感知系统
丰富的环境参数需要多种类型的传感器设备支持然而丰富的传感器类型涉及很多异构接口和不同的驱动程序。XiUOS提供的操作系统方案能够以统一设备驱动模型管理各种异构传感设备降低管理众多传感设备的复杂性。进一步地各种不同的传感器将实时的采集到大量的物理环境参数有效的传输和管理这些数据也颇为复杂。XiUOS提供的“感”子框架以用户需求为主旨采用了以物理环境参数为中心的抽象方式在应用开发时只需要考虑用户需要感知的物理量种类无需把重点放在实际采集物理量的传感器设备。这种“感”子框架有效地隐藏了底层传感器设备的硬件细节以操作系统的视角对外提供统一的数据采集接口有效地简化了传感器应用与驱动的开发。

View File

@ -504,7 +504,7 @@ td
### Quectel BC28
<div style="display: flex;justify-content: center;align-items: center;">
<img src = "./imagesrc/bc26.png" alt="bc26" width =50% max-width= 50% >
<img src = "./imagesrc/bc28.jpg" alt="bc28" width =50% max-width= 50% >
</br>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -53,14 +53,14 @@ xs_uint32 xs_CurrentTicksGain(void);
<span id="tmr_mechanism"></span>
## 定时器机制
软件定时器模块根据系统的节拍心跳tick提供软件定时服务用户可以设定固定的超时时间
## 内核定时器机制
内核软件定时器模块根据系统的节拍心跳tick提供软件定时服务用户可以设定固定的超时时间
当系统运行的节拍数到达用户设定的超时时间时,便执行用户定义的超时回调函数进行业务处理。
软件定时器的存在可以解决硬件定时器数量不足的问题。
<span id="structure"></span>
### 软件定时器结构定义
### 内核软件定时器结构定义
```c
#define TRIGGE_WAY_ONCE (1 << 0)
#define TRIGGE_WAY_PERIODIC (1 << 1)
@ -74,7 +74,7 @@ struct xs_Timer
xs_tick_x origin_timeslice; ///< 超时时间
xs_tick_x deadline_timeslice; ///< 截止时间
XS_DOUBLE_LINKLIST link; ///< 管理链表
XS_DOUBLE_LINKLIST Sortlist; ///< 查询链表
XS_DOUBLE_LINKLIST Sortlist; ///< 查询链表
};
typedef struct xs_Timer *xs_timer_x;
```
@ -91,23 +91,19 @@ typedef struct xs_Timer *xs_timer_x;
<span id="timer_api"></span>
### 软件定时器接口
### 内核软件定时器接口
定时器用户操作结构体定义如下:
```c
#define TRIGGE_WAY_ONCE (1 << 0)
#define TRIGGE_WAY_PERIODIC (1 << 1)
struct xs_utimer
{
xs_uint8 trigge_way; ///< 触发方式包括单次触发和周期触发方式
void (*func_callback)(void *param); ///< 超时回调函数
void *func_param; ///< 回调函数的参数
xs_tick_x ticks; ///< 定时时间,单位为 tick
};
typedef struct xs_utimer xs_utimer_x;
```c
xs_int32 xs_KTimerCreate(xs_uint8 trigge_wayvoid (*func_callback)(void *param)void *func_param xs_tick_x ticks);
```
| 成员 | 描述 |
该函数用于创建一个内核软件定时器并返回创建成功的软件定时器的IDID默认范围0-255可配置。
| 参数 | 描述 |
| --- | --- |
| trigge_way | 触发方式可以配置为宏TRIGGE_WAY_ONCE和TRIGGE_WAY_PERIODIC |
| func_callback | 软件定时器回调函数 |
@ -115,16 +111,7 @@ typedef struct xs_utimer xs_utimer_x;
| ticks | 配置需要等待的超时时间 |
```c
xs_int32 xs_UserTimerCreate(xs_utimer_x* timer);
```
该函数用于创建一个软件定时器并返回创建成功的软件定时器的IDID默认范围0-255可配置。
| 参数 | 描述 |
| --- | --- |
| timer | 软件定时器初始化结构体 |
```c
void xs_UserTimerDelete(xs_uint16 id);
void xs_KTimerDelete(xs_uint16 id);
```
该函数用于删除一个软件定时器。
@ -133,7 +120,7 @@ void xs_UserTimerDelete(xs_uint16 id);
| id | 待删除的软件定时器ID |
```c
xs_int32 xs_UserTimerStartRun(xs_uint16 id);
xs_int32 xs_KTimerStartRun(xs_uint16 id);
```
该函数用于启动一个软件定时器。
@ -142,7 +129,7 @@ xs_int32 xs_UserTimerStartRun(xs_uint16 id);
| id | 已创建且待运行的软件定时器ID |
```c
xs_int32 xs_UserTimerQuitRun(xs_uint16 id);
xs_int32 xs_KTimerQuitRun(xs_uint16 id);
```
该函数用于停止一个软件定时器。
@ -151,7 +138,7 @@ xs_int32 xs_UserTimerQuitRun(xs_uint16 id);
| id | 待停止运行的软件定时器ID |
```c
xs_int32 xs_UserTimerModify(xs_uint16 id, xs_tick_x ticks);
xs_int32 xs_KTimerModify(xs_uint16 id, xs_tick_x ticks);
```
该函数用于修改一个软件定时器的超时时间。