terry 7 mesiacov pred
rodič
commit
59e92868de
4 zmenil súbory, kde vykonal 26 pridanie a 12 odobranie
  1. 1 1
      lc/IDevice.go
  2. 6 4
      lc/camera_event.go
  3. 1 1
      lc/radar_event.go
  4. 18 6
      lc/server.go

+ 1 - 1
lc/IDevice.go

@@ -1,7 +1,7 @@
 package lc
 
 type Notifier interface {
-	Notify()
+	Notify(id string)
 }
 
 // CorrectTimer 校时器接口

+ 6 - 4
lc/camera_event.go

@@ -39,13 +39,13 @@ func (s *CameraServer) RegisterCallback(branch byte, notifier Notifier) {
 	}
 }
 
-func (s *CameraServer) Callback(ip string) {
+func (s *CameraServer) Callback(ip, id string) {
 	notifier, ok := s.Notifiers[ip]
 	if !ok {
 		logrus.Errorf("回调函数注册表没有该ip:%s", ip)
 		return
 	}
-	notifier.Notify()
+	notifier.Notify(id)
 	logrus.Debugf("camera [%s] Callback", ip)
 }
 
@@ -69,7 +69,9 @@ func (s *CameraServer) Handler(w http.ResponseWriter, r *http.Request) {
 			return
 		}
 		//发送事件通知
-		s.Callback(event.IpAddress)
+		for _, v := range event.DetectionRegionList.DetectionRegionEntry {
+			s.Callback(event.IpAddress, v.RegionID)
+		}
 	} else if strings.Contains(contentType, "multipart/form-data") {
 		s.HandleMultipart(r)
 	}
@@ -101,5 +103,5 @@ func (s *CameraServer) HandleMultipart(r *http.Request) {
 		}
 	}
 	//发送事件通知
-	s.Callback(event.IpAddress)
+	s.Callback(event.IpAddress, "")
 }

+ 1 - 1
lc/radar_event.go

@@ -38,7 +38,7 @@ func (s *RadarServer) Callback(port string) {
 		logrus.Errorf("回调函数注册表没有该ip:%s", port)
 		return
 	}
-	notifier.Notify()
+	notifier.Notify("")
 }
 
 func (s *RadarServer) OpenSerial(portName string) {

+ 18 - 6
lc/server.go

@@ -44,12 +44,18 @@ func StartIntersectionServer() {
 type MainNotifier struct{ s *IntersectionServer }
 
 // Notify 主路来车,通知支路设备
-func (m MainNotifier) Notify() {
+func (m MainNotifier) Notify(id string) {
 	m.s.Main.Reset(5 * time.Second)
 	if m.s.MainState != 1 {
 		m.s.MainState = 1
-		for _, v := range m.s.SubDevices {
-			gopool.Go(v.Call)
+		if id == "1" {
+			for _, v := range m.s.SubDevices {
+				gopool.Go(v.Call)
+			}
+		} else if id == "2" {
+			for _, v := range m.s.MainDevices {
+				gopool.Go(v.Call)
+			}
 		}
 	}
 }
@@ -57,12 +63,18 @@ func (m MainNotifier) Notify() {
 type SubNotifier struct{ s *IntersectionServer }
 
 // Notify 支路来车,通知主路设备
-func (sub SubNotifier) Notify() {
+func (sub SubNotifier) Notify(id string) {
 	sub.s.Sub.Reset(5 * time.Second)
 	if sub.s.SubState != 1 {
 		sub.s.SubState = 1
-		for _, v := range sub.s.MainDevices {
-			gopool.Go(v.Call)
+		if id == "1" {
+			for _, v := range sub.s.SubDevices {
+				gopool.Go(v.Call)
+			}
+		} else if id == "2" {
+			for _, v := range sub.s.MainDevices {
+				gopool.Go(v.Call)
+			}
 		}
 	}
 }