Edge-X 设备服务开发(转)

[复制链接]
533|1
 楼主| keer_zu 发表于 2020-10-16 16:34 | 显示全部楼层 |阅读模式
edge, ic, ce, vi, ev
Edge-X 设备服务开发一,设备驱动(device driver) 核心接口protocoldriver.go
  1. / ProtocolDriver is a low-level device-specific interface used by
  2. // by other components of an EdgeX Device Service to interact with
  3. // a specific class of devices.
  4. type ProtocolDriver interface {
  5.     // Initialize performs protocol-specific initialization for the device
  6.     // service. The given *AsyncValues channel can be used to push asynchronous
  7.     // events and readings to Core Data.
  8.     Initialize(lc logger.LoggingClient, asyncCh chan<- *AsyncValues) error

  9.     // HandleReadCommands passes a slice of CommandRequest struct each representing
  10.     // a ResourceOperation for a specific device resource.
  11.     HandleReadCommands(deviceName string, protocols map[string]contract.ProtocolProperties, reqs []CommandRequest) ([]*CommandValue, error)

  12.     // HandleWriteCommands passes a slice of CommandRequest struct each representing
  13.     // a ResourceOperation for a specific device resource.
  14.     // Since the commands are actuation commands, params provide parameters for the individual
  15.     // command.
  16.     HandleWriteCommands(deviceName string, protocols map[string]contract.ProtocolProperties, reqs []CommandRequest, params []*CommandValue) error

  17.     // Stop instructs the protocol-specific DS code to shutdown gracefully, or
  18.     // if the force parameter is 'true', immediately. The driver is responsible
  19.     // for closing any in-use channels, including the channel used to send async
  20.     // readings (if supported).
  21.     Stop(force bool) error

  22.     // AddDevice is a callback function that is invoked
  23.     // when a new Device associated with this Device Service is added
  24.     AddDevice(deviceName string, protocols map[string]contract.ProtocolProperties, adminState contract.AdminState) error

  25.     // UpdateDevice is a callback function that is invoked
  26.     // when a Device associated with this Device Service is updated
  27.     UpdateDevice(deviceName string, protocols map[string]contract.ProtocolProperties, adminState contract.AdminState) error

  28.     // RemoveDevice is a callback function that is invoked
  29.     // when a Device associated with this Device Service is removed
  30.     RemoveDevice(deviceName string, protocols map[string]contract.ProtocolProperties) error
  31. }

1、初始化函数:// AsyncValues : 异步通道,用来做异步事件发送
  1. Initialize(lc logger.LoggingClient, asyncCh chan<- *AsyncValues) error

2、写函数
  1. HandleWriteCommands(deviceName string, protocols map[string]contract.ProtocolProperties, reqs []CommandRequest, params []*CommandValue) error




入参:
948435f895b2d88dc8.png


 楼主| keer_zu 发表于 2020-10-16 16:39 | 显示全部楼层
在另外一个工程:github.com/edgexfoundry/go-mod-core-contracts/models/device.go
136605f895b6ae1bde.png


211315f895b9fcb776.png

3、读函数
  1. // HandleReadCommands passes a slice of CommandRequest struct each representing
  2.     // a ResourceOperation for a specific device resource.
  3.     HandleReadCommands(deviceName string, protocols map[string]contract.ProtocolProperties, reqs []CommandRequest) ([]*CommandValue, error)

4、停止函数
  1. // Stop instructs the protocol-specific DS code to shutdown gracefully, or
  2.     // if the force parameter is 'true', immediately. The driver is responsible
  3.     // for closing any in-use channels, including the channel used to send async
  4.     // readings (if supported).
  5.     Stop(force bool) error

5、添加设备回调函数
  1.     // AddDevice is a callback function that is invoked
  2.     // when a new Device associated with this Device Service is added
  3.     AddDevice(deviceName string, protocols map[string]contract.ProtocolProperties, adminState contract.AdminState) error

6、更新设备回调函数
  1. // UpdateDevice is a callback function that is invoked
  2.     // when a Device associated with this Device Service is updated
  3.     UpdateDevice(deviceName string, protocols map[string]contract.ProtocolProperties, adminState contract.AdminState) error


7、移除设备回调函数
  1. // RemoveDevice is a callback function that is invoked
  2.     // when a Device associated with this Device Service is removed
  3.     RemoveDevice(deviceName string, protocols map[string]contract.ProtocolProperties) error












您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:qq群:49734243 Email:zukeqiang@gmail.com

1488

主题

12953

帖子

55

粉丝
快速回复 在线客服 返回列表 返回顶部