package device import "git.huangwc.com/pig/pig-farm-controller/internal/infra/models" // 设备行为 type DeviceAction string var ( DeviceActionStart = "start" // 启动 DeviceActionStop = "stop" // 停止 ) // 指令类型 type Method string var ( MethodPing = "ping" // ping指令 ) // Service 抽象了一组方法用于控制设备行为 type Service interface { // Switch 用于切换指定设备的状态, 比如启动和停止 Switch(device models.Device, action DeviceAction) error } // 设备操作指令通用结构(最外层) type DeviceRequest struct { MessageID int // 消息ID, 用于后续匹配响应 Method string // 这是什么指令 Data interface{} // 指令参数 } // 设备操作指令通用响应结构(最外层) type DeviceResponse struct { MessageID int // 消息ID, 用于匹配这是哪一个请求的响应 Message string Data interface{} // 响应内容 }