43 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package device
 | |
| 
 | |
| import "git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
 | |
| 
 | |
| // 设备行为
 | |
| type DeviceAction string
 | |
| 
 | |
| var (
 | |
| 	DeviceActionStart DeviceAction = "start" // 启动
 | |
| 	DeviceActionStop  DeviceAction = "stop"  // 停止
 | |
| )
 | |
| 
 | |
| // 指令类型
 | |
| type Method string
 | |
| 
 | |
| var (
 | |
| 	MethodSwitch Method = "switch" // 启停指令
 | |
| )
 | |
| 
 | |
| // Service 抽象了一组方法用于控制设备行为
 | |
| type Service interface {
 | |
| 
 | |
| 	// Switch 用于切换指定设备的状态, 比如启动和停止
 | |
| 	Switch(device *models.Device, action DeviceAction) error
 | |
| 
 | |
| 	// Collect 用于发起对指定区域主控下的多个设备的批量采集请求。
 | |
| 	Collect(regionalControllerID uint, devicesToCollect []*models.Device) error
 | |
| }
 | |
| 
 | |
| // 设备操作指令通用结构(最外层)
 | |
| type DeviceRequest struct {
 | |
| 	MessageID int         // 消息ID, 用于后续匹配响应
 | |
| 	Method    string      // 这是什么指令
 | |
| 	Data      interface{} // 指令参数
 | |
| }
 | |
| 
 | |
| // 设备操作指令通用响应结构(最外层)
 | |
| type DeviceResponse struct {
 | |
| 	MessageID int // 消息ID, 用于匹配这是哪一个请求的响应
 | |
| 	Message   string
 | |
| 	Data      interface{} // 响应内容
 | |
| }
 |