定义 device service
This commit is contained in:
42
internal/app/service/device/device_service.go
Normal file
42
internal/app/service/device/device_service.go
Normal 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{} // 响应内容
|
||||||
|
}
|
||||||
18
internal/app/service/device/general_device_service.go
Normal file
18
internal/app/service/device/general_device_service.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package device
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GeneralDeviceService struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GeneralDeviceService) Switch(device models.Device, action DeviceAction) error {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GeneralDeviceService) Ping() error {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user