|
@@ -10,18 +10,29 @@ type SmartXServer interface {
|
|
|
Serve()
|
|
|
}
|
|
|
|
|
|
-func StartSmartXServer(s SmartXServer) {
|
|
|
- s.Serve()
|
|
|
+type IntersectionServer struct {
|
|
|
+ RadioEventServer *RadioServer
|
|
|
+ CameraEventServer *CameraServer
|
|
|
+ MainState byte
|
|
|
+ SubState byte
|
|
|
+ MainDevices []IDevice
|
|
|
+ SubDevices []IDevice
|
|
|
+ ReTicker *time.Ticker
|
|
|
+ Main *time.Ticker
|
|
|
+ Sub *time.Ticker
|
|
|
}
|
|
|
|
|
|
-type IntersectionServer struct {
|
|
|
- MainState byte
|
|
|
- SubState byte
|
|
|
- MainDevices []IDevice
|
|
|
- SubDevices []IDevice
|
|
|
- ReTicker *time.Ticker
|
|
|
- Main *time.Ticker
|
|
|
- Sub *time.Ticker
|
|
|
+func StartIntersectionServer() {
|
|
|
+ is := &IntersectionServer{
|
|
|
+ Main: time.NewTicker(5 * time.Second), //主路状态回滚
|
|
|
+ Sub: time.NewTicker(5 * time.Second), //支路状态回滚
|
|
|
+ ReTicker: time.NewTicker(30 * time.Second), //重连
|
|
|
+ }
|
|
|
+ is.RadioEventServer = StartRadioEventServer()
|
|
|
+ is.CameraEventServer = StartCameraEventServer()
|
|
|
+ //等事件服务先启动
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+ is.Serve()
|
|
|
}
|
|
|
|
|
|
type MainNotifier struct{ s *IntersectionServer }
|
|
@@ -51,20 +62,39 @@ func (sub SubNotifier) Notify() {
|
|
|
}
|
|
|
|
|
|
func (is *IntersectionServer) Serve() {
|
|
|
- RegisterCallback(1, &SubNotifier{is})
|
|
|
- RegisterCallback(0, &MainNotifier{is})
|
|
|
+ if util.Config.Server.SupportCamera {
|
|
|
+ is.CameraEventServer.RegisterCallback(1, &SubNotifier{is})
|
|
|
+ is.CameraEventServer.RegisterCallback(0, &MainNotifier{is})
|
|
|
+ }
|
|
|
+ if util.Config.Server.SupportRadio {
|
|
|
+ is.RadioEventServer.RegisterCallback(1, &SubNotifier{is})
|
|
|
+ is.RadioEventServer.RegisterCallback(0, &MainNotifier{is})
|
|
|
+ }
|
|
|
+
|
|
|
//先创建响应设备
|
|
|
- for _, v := range util.Config.OutputDevices {
|
|
|
+ for _, c := range util.Config.Screens {
|
|
|
+ iDevice := &IntersectionDevice{
|
|
|
+ Info: c,
|
|
|
+ Screen: NewScreen(c.Name, c.Ip, c.Port),
|
|
|
+ }
|
|
|
+ if c.Branch == 1 {
|
|
|
+ is.MainDevices = append(is.MainDevices, iDevice)
|
|
|
+ } else {
|
|
|
+ is.SubDevices = append(is.SubDevices, iDevice)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, c := range util.Config.Speakers {
|
|
|
iDevice := &IntersectionDevice{
|
|
|
- Info: v,
|
|
|
- Screen: NewScreen(v.Name, v.ScreenIp, v.ScreenPort),
|
|
|
+ Info: c,
|
|
|
+ Speaker: NewIpCast(c.Name, c.Ip),
|
|
|
}
|
|
|
- if iDevice.Info.Branch == 1 {
|
|
|
+ if c.Branch == 1 {
|
|
|
is.MainDevices = append(is.MainDevices, iDevice)
|
|
|
} else {
|
|
|
is.SubDevices = append(is.SubDevices, iDevice)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
for {
|
|
|
select {
|
|
|
case <-is.Main.C: //检查主路状态->支路输出设备回到初始状态
|