一起养成写作习惯!这是我参与「掘金日新计划 · 4 月更文挑战」的第21天,点击查看活动详情。
简介
mapper功能:
- 扫描连接设备
- 上报设备的 twin-attribute数据
- 将设备-twin的期望状态映射到设备-twin的实际状态。
- 手机设备数据
- 将读取到的设备数据转换成Kubeedge接受的格式
- 调度设备行为
- 设备健康监测
动机
所有的设备都可以通过厂商的驱动进行连接和控制,但是从设备拿到的信息需要转换成Kubeedge所理解的格式,并且需要提供一个方法是平台可以控制设备。Mapper就是Kubeedge和devices之间相互联系的应用程序。KubeEdge支持的映射器应该有一个标准的设计,以保持它们的通用性和易于使用。
目标
- 通过KubeEdge提供的映射器标准设计,支持不同协议的多个设备的通用方法。
- 易于使用的映射器设计
- 开放的可能性,在未来有mapper SDK,可以生成基于可配置的输入mapper。
组件
- Action-Manager:可以通过在设备的物理寄存器中设置特定的值来控制设备,并且可以通过从特定寄存器中获取值来获取读数。我们把一组操作定义成一个行为,来控制设备
// Operation is structure to define device operation
type Operation struct {
// Action can be one of read/write corresponding to get/set respectively
Action string
// AttributeName is the name of the attribute where action is to be performed.
// for eg uuid in BLE, holding register in modbus
AttributeName string
// AttributeValue is the value of the Attribute.
AttributeValue string
// Value is the value to be written in case of write action
Value string
}
Action:
// Operation is structure to define device operation
type Operation struct {
// Action can be one of read/write corresponding to get/set respectively
Action string
// AttributeName is the name of the attribute where action is to be performed.
// for eg uuid in BLE, holding register in modbus
AttributeName string
// AttributeValue is the value of the Attribute.
AttributeValue string
// Value is the value to be written in case of write action
Value string
}
- Scheduler:周期性执行Action,Scheduler可以按照如下结构定义:
// Operation is structure to define device operation
type Operation struct {
// Action can be one of read/write corresponding to get/set respectively
Action string
// AttributeName is the name of the attribute where action is to be performed.
// for eg uuid in BLE, holding register in modbus
AttributeName string
// AttributeValue is the value of the Attribute.
AttributeValue string
// Value is the value to be written in case of write action
Value string
}
- Watcher:观察者,观察者具备3中功能:
- 扫描并等待设备开机,当其可用时进行接入。可以使用MAC地址或者设备提供的其他唯一地址来标识,在设备写入操作时,可以使用GPIO
- 监视设备的twin属性的期望状态,并执行操作使实际状态等于期望状态。
- 向twin上传设备真实状态
- Data-Converter:数据转换。从设备接收到的数据结构可能比较复杂,Kubeedge不能直接解析这种结构,data-converter主要功能就是将设备信息转换成kubeedge课时表的信息
- Health-Checker 向kubeedge上报设备状态,
- Controller:控制器应该提供用于管理Actions, Schedules, Watchers, Data-Converters, Health-Checkers的CRUD操作的API
- Driver Interface:用于设备驱动
示例
1.Bluetooth Mapper github.com/kubeedge/ku…2.Modbus Mapper github.com/kubeedge/ku…github.com/kubeedge/ku…