定义 device service

This commit is contained in:
2025-09-15 21:28:22 +08:00
parent b183ad660f
commit 4980495f90
2 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
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
// Ping 用于检查设备是否正常
Ping() error
}
// 设备操作指令通用结构(最外层)
type DeviceRequest struct {
MessageID int // 消息ID, 用于后续匹配响应
Method string // 这是什么指令
Data interface{} // 指令参数
}
// 设备操作指令通用响应结构(最外层)
type DeviceResponse struct {
MessageID int // 消息ID, 用于匹配这是哪一个请求的响应
Message string
Data interface{} // 响应内容
}