123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package lc
- import (
- "github.com/sirupsen/logrus"
- "lc-smartX/util"
- "net"
- "time"
- )
- type CorrectTimer interface {
- Correct()
- }
- func DoCorrectTime(a any) {
- if c, ok := a.(CorrectTimer); ok {
- c.Correct()
- }
- }
- // IDevice 抽象设备,包含屏和喇叭
- type IDevice interface {
- // Call 通知输出设备,输出信息。屏显示来车警告信息,扬声器语音提示
- Call()
- // Back 屏显示原来的无车提醒信息
- Back()
- ReConnect()
- // Correct time 校时
- CorrectTimer
- }
- type IntersectionDevice struct {
- Info util.OutputDevice
- S Screen
- L IpCast
- }
- func (id *IntersectionDevice) Call() {
- id.L.Speak()
- id.S.Display()
- }
- func (id *IntersectionDevice) Back() {
- id.S.Back()
- }
- func (id *IntersectionDevice) ReConnect() {
- //重连屏
- if !id.S.IsLive {
- conn, err := net.DialTimeout("tcp", id.Info.ScreenIp+":5000", 5*time.Second)
- if err != nil {
- logrus.WithFields(map[string]interface{}{"设备名": id.Info.Name, "IP": id.Info.ScreenIp, "error": err}).Error("屏重连接失败!")
- return
- }
- logrus.WithFields(map[string]interface{}{"设备名": id.Info.Name, "IP": id.Info.ScreenIp}).Info("屏重连接成功!")
- id.S.Conn = conn
- id.S.IsLive = true
- }
- //todo 重连loudspeaker
- }
- func (id *IntersectionDevice) Correct() {
- DoCorrectTime(id.S)
- DoCorrectTime(id.L)
- }
|