IDevice.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. }
  43. func (id *IntersectionDevice) Call() {
  44. if id.Screen != nil {
  45. id.Screen.Display(1)
  46. }
  47. }
  48. func (id *IntersectionDevice) Rollback() {
  49. if id.Screen != nil {
  50. id.Screen.Display(0)
  51. }
  52. }
  53. func (id *IntersectionDevice) Reconnect() {
  54. DoReconnect(id.Screen)
  55. }
  56. func (id *IntersectionDevice) Correct() {
  57. DoCorrectTime(id.Screen)
  58. }