rts-sim-testing-service/ats/verify/simulation/wayside/face/device_model.go

68 lines
1.1 KiB
Go
Raw Normal View History

2023-07-31 11:30:34 +08:00
package face
2023-07-28 18:12:50 +08:00
import (
"fmt"
"strings"
)
2023-07-28 18:12:50 +08:00
// 设备模型基类
2023-07-28 18:12:50 +08:00
type DeviceModel struct {
//图形id,即由前端作图时生成,且全局唯一
GraphicId string
//索引编号,同类设备唯一,不同类设备不唯一
Index string
}
// 判断是否同一个设备
2023-07-28 18:12:50 +08:00
func (dm *DeviceModel) IsSame(other *DeviceModel) bool {
return strings.EqualFold(dm.GraphicId, other.GraphicId)
}
// 模型图形id
2023-07-31 11:30:34 +08:00
func (dm *DeviceModel) GetGraphicId() string {
return dm.GraphicId
}
// 模型索引
2023-07-31 11:30:34 +08:00
func (dm *DeviceModel) GetIndex() string {
return dm.Index
}
2023-07-28 18:12:50 +08:00
//////////////////////////////////////////////////////////////
// 设备端口枚举定义
2023-07-28 18:12:50 +08:00
type PortEnum int8
func (pe PortEnum) Name() string {
switch pe {
case A:
return "A"
case B:
return "B"
case C:
return "C"
default:
panic(fmt.Sprintf("未知的PortEnum%d", pe))
}
}
// 设备端口枚举值
2023-07-28 18:12:50 +08:00
const (
A PortEnum = iota
B
C
)
func GetPortEnum(i int8) PortEnum {
switch i {
case int8(A):
return A
case int8(B):
return B
case int8(C):
return C
default:
panic(fmt.Sprintf("未知的PortEnum%d", i))
}
}