IDevice.go 674 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package lc
  2. import (
  3. "fmt"
  4. "github.com/sirupsen/logrus"
  5. "lc-smartX/util"
  6. "net"
  7. )
  8. // IDevice 抽象设备,包含屏和喇叭
  9. type IDevice interface {
  10. Call()
  11. ReConnect()
  12. }
  13. type IntersectionDevice struct {
  14. Info util.OutputDevice
  15. S Screen
  16. L IpCast
  17. }
  18. func (id *IntersectionDevice) Call() {
  19. id.L.Speak()
  20. id.S.Display()
  21. }
  22. func (id *IntersectionDevice) ReConnect() {
  23. conn, err := net.Dial("tcp", id.Info.ScreenIp+":5000")
  24. if err != nil {
  25. logrus.Error("连接", id.Info.ScreenIp, "失败!error:", err)
  26. return
  27. }
  28. logrus.Info("连接", id.Info.ScreenIp, "成功!")
  29. fmt.Println("连接", id.Info.ScreenIp, "成功!")
  30. id.S.Conn = conn
  31. id.S.IsLive = true
  32. }