12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package lc
- type Notifier interface {
- Notify(id string)
- }
- // CorrectTimer 校时器接口
- type CorrectTimer interface {
- Correct()
- }
- func DoCorrectTime(a any) {
- if c, ok := a.(CorrectTimer); ok {
- c.Correct()
- }
- }
- // ReConnector 重连器接口
- type ReConnector interface {
- Reconnect()
- }
- func DoReconnect(a any) {
- if c, ok := a.(ReConnector); ok {
- c.Reconnect()
- }
- }
- // IDevice 抽象设备,包含屏和扬声器
- type IDevice interface {
- // Call 通知输出设备,输出信息。屏显示来车警告信息,扬声器语音提示
- Call()
- // Rollback 屏回滚到初始状态
- Rollback()
- ReConnector
- CorrectTimer
- }
- type OutputDeviceInfo struct {
- Name string
- Ip string
- Port string
- Branch byte
- Audio string
- }
- type IntersectionDevice struct {
- Info OutputDeviceInfo
- Screen Screener
- Speaker Loudspeaker
- }
- func (id *IntersectionDevice) Call() {
- if id.Screen != nil {
- id.Screen.Display(1)
- }
- if id.Speaker != nil {
- id.Speaker.Speak("支路来车")
- }
- }
- func (id *IntersectionDevice) Rollback() {
- if id.Screen != nil {
- id.Screen.Display(0)
- }
- }
- func (id *IntersectionDevice) Reconnect() {
- DoReconnect(id.Screen)
- }
- func (id *IntersectionDevice) Correct() {
- DoCorrectTime(id.Screen)
- }
|