|
@@ -7,38 +7,34 @@ import (
|
|
|
"lc-smartX/util"
|
|
|
)
|
|
|
|
|
|
-type Notifier interface {
|
|
|
- Notify()
|
|
|
-}
|
|
|
-
|
|
|
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
|
|
|
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)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func RegisterCallback(branch byte, notifier Notifier) {
|
|
|
- for _, radio := range S.Radios {
|
|
|
+ for _, radio := range RadioEventServer.Radios {
|
|
|
//关联主路led屏和支路雷达;关联支路led屏和主路雷达
|
|
|
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]
|
|
|
if !ok {
|
|
|
logrus.Errorf("回调函数注册表没有该ip:%s", port)
|
|
@@ -80,7 +76,7 @@ func OpenSerial(portName string) {
|
|
|
result = true
|
|
|
}
|
|
|
if result {
|
|
|
- S.Callback(portName)
|
|
|
+ RadioEventServer.Callback(portName)
|
|
|
}
|
|
|
}
|
|
|
}
|