|
@@ -7,38 +7,34 @@ import (
|
|
"lc-smartX/util"
|
|
"lc-smartX/util"
|
|
)
|
|
)
|
|
|
|
|
|
-type Notifier interface {
|
|
|
|
- Notify()
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func StartEventServer() {
|
|
func StartEventServer() {
|
|
- S = &Server{Radios: util.Config.Radios, Notifiers: make(map[string]Notifier, 4)}
|
|
|
|
- S.start()
|
|
|
|
|
|
+ RadioEventServer = &RadioServer{Radios: util.Config.Radios, Notifiers: make(map[string]Notifier, 4)}
|
|
|
|
+ RadioEventServer.start()
|
|
}
|
|
}
|
|
|
|
|
|
-var S *Server
|
|
|
|
|
|
+var RadioEventServer *RadioServer
|
|
|
|
|
|
-type Server struct {
|
|
|
|
|
|
+type RadioServer struct {
|
|
Radios []model.RadioInfo
|
|
Radios []model.RadioInfo
|
|
Notifiers map[string]Notifier //485通道名
|
|
Notifiers map[string]Notifier //485通道名
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) start() {
|
|
|
|
- for _, radio := range S.Radios {
|
|
|
|
|
|
+func (s *RadioServer) start() {
|
|
|
|
+ for _, radio := range RadioEventServer.Radios {
|
|
go OpenSerial(radio.Port)
|
|
go OpenSerial(radio.Port)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
func RegisterCallback(branch byte, notifier Notifier) {
|
|
func RegisterCallback(branch byte, notifier Notifier) {
|
|
- for _, radio := range S.Radios {
|
|
|
|
|
|
+ for _, radio := range RadioEventServer.Radios {
|
|
//关联主路led屏和支路雷达;关联支路led屏和主路雷达
|
|
//关联主路led屏和支路雷达;关联支路led屏和主路雷达
|
|
if branch == 0 && radio.Branch == 1 || branch == 1 && radio.Branch == 0 {
|
|
if branch == 0 && radio.Branch == 1 || branch == 1 && radio.Branch == 0 {
|
|
- S.Notifiers[radio.Port] = notifier
|
|
|
|
|
|
+ RadioEventServer.Notifiers[radio.Port] = notifier
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Server) Callback(port string) {
|
|
|
|
|
|
+func (s *RadioServer) Callback(port string) {
|
|
notifier, ok := s.Notifiers[port]
|
|
notifier, ok := s.Notifiers[port]
|
|
if !ok {
|
|
if !ok {
|
|
logrus.Errorf("回调函数注册表没有该ip:%s", port)
|
|
logrus.Errorf("回调函数注册表没有该ip:%s", port)
|
|
@@ -80,7 +76,7 @@ func OpenSerial(portName string) {
|
|
result = true
|
|
result = true
|
|
}
|
|
}
|
|
if result {
|
|
if result {
|
|
- S.Callback(portName)
|
|
|
|
|
|
+ RadioEventServer.Callback(portName)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|