IDevice.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package lc
  2. type Notifier interface {
  3. Notify()
  4. }
  5. // CorrectTimer 校时器接口
  6. type CorrectTimer interface {
  7. Correct()
  8. }
  9. func DoCorrectTime(a any) {
  10. if c, ok := a.(CorrectTimer); ok {
  11. c.Correct()
  12. }
  13. }
  14. // ReConnector 重连器接口
  15. type ReConnector interface {
  16. Reconnect()
  17. }
  18. func DoReconnect(a any) {
  19. if c, ok := a.(ReConnector); ok {
  20. c.Reconnect()
  21. }
  22. }
  23. // IDevice 抽象设备,包含屏和扬声器
  24. type IDevice interface {
  25. // Call 通知输出设备,输出信息。屏显示来车警告信息,扬声器语音提示
  26. Call()
  27. // Rollback 屏回滚到初始状态
  28. Rollback()
  29. ReConnector
  30. CorrectTimer
  31. }
  32. type OutputDeviceInfo struct {
  33. Name string
  34. Ip string
  35. Port string
  36. Branch byte
  37. Audio string
  38. }
  39. type IntersectionDevice struct {
  40. Info OutputDeviceInfo
  41. Screen Screener
  42. Speaker Loudspeaker
  43. }
  44. func (id *IntersectionDevice) Call() {
  45. if id.Screen != nil {
  46. id.Screen.Display(1)
  47. }
  48. if id.Speaker != nil {
  49. id.Speaker.Speak("支路来车")
  50. }
  51. }
  52. func (id *IntersectionDevice) Rollback() {
  53. if id.Screen != nil {
  54. id.Screen.Display(0)
  55. }
  56. }
  57. func (id *IntersectionDevice) Reconnect() {
  58. DoReconnect(id.Screen)
  59. }
  60. func (id *IntersectionDevice) Correct() {
  61. DoCorrectTime(id.Screen)
  62. }