package third_party import ( beijing12axle "joylink.club/bj-rtsts-server/third_party/axle_device/beijing12" "joylink.club/bj-rtsts-server/third_party/interlock/beijing11" "joylink.club/bj-rtsts-server/third_party/interlock/beijing12" "joylink.club/bj-rtsts-server/third_party/train_pc_sim" "log/slog" "joylink.club/bj-rtsts-server/dto/state_proto" "joylink.club/bj-rtsts-server/third_party/dynamics" "joylink.club/bj-rtsts-server/third_party/semi_physical_train" "joylink.club/bj-rtsts-server/third_party/tpapi" ) var tpapiService []tpapi.ThirdPartyApiService func Init() { tpapiService = append( tpapiService, dynamics.Default(), semi_physical_train.Default(), train_pc_sim.Default(), ) } func GetAllServices() []tpapi.ThirdPartyApiService { services := make([]tpapi.ThirdPartyApiService, 0, 8) services = append(services, tpapiService...) services = append(services, beijing11.CollectAllServices()...) services = append(services, beijing12.CollectAllServices()...) services = append(services, beijing12axle.CollectAllServices()...) return services } //func convertServiceName(name string) state_proto.SimulationThirdPartyApiService_Type { // switch name { // case dynamics.Name: // return state_proto.SimulationThirdPartyApiService_Dynamics // case semi_physical_train.Name: // return state_proto.SimulationThirdPartyApiService_SemiPhysicalTrain // case train_pc_sim.Name: // return state_proto.SimulationThirdPartyApiService_Train_pc_sim // default: // return state_proto.SimulationThirdPartyApiService_Undefined // } //} func GetRunningServiceStates() *state_proto.SimulationThirdPartyApiService { ss := &state_proto.SimulationThirdPartyApiService{} for _, tpas := range GetAllServices() { if tpas.TrueService() { collectServiceState(ss, tpas) } else { trueServices := tpas.FindAppendApiService() if trueServices != nil && len(trueServices) > 0 { for _, trueService := range trueServices { if trueService != nil { collectServiceState(ss, trueService) } } } } } return ss } func collectServiceState(ss *state_proto.SimulationThirdPartyApiService, service tpapi.ThirdPartyApiService) { t := service.Type() if t == state_proto.SimulationThirdPartyApiService_Undefined { slog.Error("未知的第三方接口服务类型", "name", service.Type()) return } switch service.State() { case tpapi.ThirdPartyState_Normal: ss.States = append(ss.States, &state_proto.SimulationThirdPartyApiServiceState{ Type: t, ServiceName: service.ServiceDesc(), State: state_proto.SimulationThirdPartyApiService_Normal, }) case tpapi.ThirdPartyState_Broken: ss.States = append(ss.States, &state_proto.SimulationThirdPartyApiServiceState{ Type: t, ServiceName: service.ServiceDesc(), State: state_proto.SimulationThirdPartyApiService_Error, }) } }