2023-10-19 09:33:40 +08:00
|
|
|
package third_party
|
|
|
|
|
2024-01-22 13:10:10 +08:00
|
|
|
import (
|
2024-10-09 17:38:52 +08:00
|
|
|
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"
|
2024-04-13 09:40:25 +08:00
|
|
|
"joylink.club/bj-rtsts-server/third_party/train_pc_sim"
|
2024-01-23 09:37:31 +08:00
|
|
|
"log/slog"
|
|
|
|
|
2024-01-22 13:10:10 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/dynamics"
|
2024-01-23 09:37:31 +08:00
|
|
|
"joylink.club/bj-rtsts-server/third_party/semi_physical_train"
|
2024-01-22 13:10:10 +08:00
|
|
|
"joylink.club/bj-rtsts-server/third_party/tpapi"
|
|
|
|
)
|
2023-10-26 15:06:26 +08:00
|
|
|
|
2024-01-23 09:37:31 +08:00
|
|
|
var tpapiService []tpapi.ThirdPartyApiService
|
|
|
|
|
|
|
|
func Init() {
|
|
|
|
tpapiService = append(
|
|
|
|
tpapiService, dynamics.Default(),
|
|
|
|
semi_physical_train.Default(),
|
2024-04-13 09:40:25 +08:00
|
|
|
train_pc_sim.Default(),
|
2024-01-23 09:37:31 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetAllServices() []tpapi.ThirdPartyApiService {
|
2024-10-09 17:38:52 +08:00
|
|
|
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
|
2024-01-23 09:37:31 +08:00
|
|
|
}
|
|
|
|
|
2024-10-09 17:38:52 +08:00
|
|
|
//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
|
|
|
|
// }
|
|
|
|
//}
|
2024-01-23 09:37:31 +08:00
|
|
|
|
|
|
|
func GetRunningServiceStates() *state_proto.SimulationThirdPartyApiService {
|
2024-01-22 13:10:10 +08:00
|
|
|
ss := &state_proto.SimulationThirdPartyApiService{}
|
2024-10-09 17:38:52 +08:00
|
|
|
for _, tpas := range GetAllServices() {
|
2024-07-19 15:24:28 +08:00
|
|
|
if tpas.TrueService() {
|
|
|
|
collectServiceState(ss, tpas)
|
|
|
|
} else {
|
|
|
|
trueServices := tpas.FindAppendApiService()
|
|
|
|
if trueServices != nil && len(trueServices) > 0 {
|
|
|
|
for _, trueService := range trueServices {
|
2024-09-10 15:37:40 +08:00
|
|
|
if trueService != nil {
|
|
|
|
collectServiceState(ss, trueService)
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
}
|
|
|
|
}
|
2024-04-13 09:40:25 +08:00
|
|
|
|
2024-01-23 09:37:31 +08:00
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
2024-01-22 13:10:10 +08:00
|
|
|
}
|
|
|
|
return ss
|
2023-10-19 09:33:40 +08:00
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
func collectServiceState(ss *state_proto.SimulationThirdPartyApiService, service tpapi.ThirdPartyApiService) {
|
2024-10-09 17:38:52 +08:00
|
|
|
t := service.Type()
|
2024-07-19 15:24:28 +08:00
|
|
|
if t == state_proto.SimulationThirdPartyApiService_Undefined {
|
2024-10-09 17:38:52 +08:00
|
|
|
slog.Error("未知的第三方接口服务类型", "name", service.Type())
|
2024-07-19 15:24:28 +08:00
|
|
|
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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|