Browse Source

优化架构

terry 8 months ago
parent
commit
fb90d7e897
6 changed files with 40 additions and 25 deletions
  1. 11 3
      config.yaml
  2. 9 2
      lc/IDevice.go
  3. 0 1
      lc/model/speaker.go
  4. 18 4
      lc/server.go
  5. 2 2
      lc/speaker.go
  6. 0 13
      main.go

+ 11 - 3
config.yaml

@@ -6,15 +6,23 @@ service:
 hikServer:
   addr: ":8850"
   path: "/event"
+cameras:
+  - name: "主路1"
+    ip: "192.168.1.64"
+    branch: 1
 radios:
   - port: "/dev/ttymxc4"
     name: "对向"
     branch: 1
   - port: "/dev/ttymxc6"
     name: "同向"
+    branch: 1
+screens:
+  - name: "主路1输出设备"
+    ip: "192.168.1.200"
+    port: "5005"
     branch: 0
-outputDevices:
+speakers:
   - name: "主路1输出设备"
-    screen_ip: "192.168.1.200"
-    screen_port: "5005"
+    ip: "192.168.1.160"
     branch: 0

+ 9 - 2
lc/IDevice.go

@@ -36,15 +36,22 @@ type IDevice interface {
 	CorrectTimer
 }
 
+type OutputDeviceInfo struct {
+	Name   string
+	Ip     string
+	Port   string
+	Branch byte
+}
+
 type IntersectionDevice struct {
-	Info    interface{}
+	Info    OutputDeviceInfo
 	Screen  Screener
 	Speaker Loudspeaker
 }
 
 func (id *IntersectionDevice) Call() {
 	id.Screen.Display(1)
-	id.Speaker.Speak()
+	id.Speaker.Speak("支路来车")
 }
 func (id *IntersectionDevice) Rollback() {
 	id.Screen.Display(0)

+ 0 - 1
lc/model/speaker.go

@@ -3,7 +3,6 @@ package model
 type SpeakerInfo struct {
 	Name   string `yaml:"name"`
 	Ip     string `yaml:"ip"`
-	Port   string `yaml:"port"`
 	Branch byte   `yaml:"branch"`
 }
 

+ 18 - 4
lc/server.go

@@ -28,8 +28,13 @@ func StartIntersectionServer() {
 		Sub:      time.NewTicker(5 * time.Second),  //支路状态回滚
 		ReTicker: time.NewTicker(30 * time.Second), //重连
 	}
-	is.RadioEventServer = StartRadioEventServer()
-	is.CameraEventServer = StartCameraEventServer()
+	if util.Config.Server.SupportCamera {
+		is.CameraEventServer = StartCameraEventServer()
+
+	}
+	if util.Config.Server.SupportRadio {
+		is.RadioEventServer = StartRadioEventServer()
+	}
 	//等事件服务先启动
 	time.Sleep(1 * time.Second)
 	is.Serve()
@@ -74,7 +79,12 @@ func (is *IntersectionServer) Serve() {
 	//先创建响应设备
 	for _, c := range util.Config.Screens {
 		iDevice := &IntersectionDevice{
-			Info:   c,
+			Info: OutputDeviceInfo{
+				Name:   c.Name,
+				Ip:     c.Ip,
+				Port:   c.Port,
+				Branch: c.Branch,
+			},
 			Screen: NewScreen(c.Name, c.Ip, c.Port),
 		}
 		if c.Branch == 1 {
@@ -85,7 +95,11 @@ func (is *IntersectionServer) Serve() {
 	}
 	for _, c := range util.Config.Speakers {
 		iDevice := &IntersectionDevice{
-			Info:    c,
+			Info: OutputDeviceInfo{
+				Name:   c.Name,
+				Ip:     c.Ip,
+				Branch: c.Branch,
+			},
 			Speaker: NewIpCast(c.Name, c.Ip),
 		}
 		if c.Branch == 1 {

+ 2 - 2
lc/speaker.go

@@ -52,9 +52,9 @@ func (ip *IpCast) Speak(txt string) {
 
 	c := http.DefaultClient
 	req, _ := http.NewRequest("POST", fmt.Sprintf("http://%s/v1/speech", ip.Ip), bytes.NewReader(body))
-	rsp, err := c.Do(req)
+	_, err = c.Do(req)
 	if err != nil {
-		logrus.Errorf("IpCast Speak err : %s", err.Error())
+		logrus.Errorf("IpCast Speak Do err : %s", err.Error())
 		return
 	}
 }

+ 0 - 13
main.go

@@ -1,21 +1,8 @@
 package main
 
 import (
-	//"github.com/sirupsen/logrus"
 	"lc-smartX/lc"
 	"lc-smartX/util/gopool"
-
-	//"lc-smartX/util/gopool"
-	//"net"
-	//"time"
-	//
-	//"lc-smartX/util/gopool"
-	"time"
-	//
-	//"lc-smartX/util/gopool"
-	//"net"
-	//"os"
-	//"time"
 )
 
 func main() {