From ec48b5f48ae9c262880c79e59baaeb4ab0d51065 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Wed, 24 Jan 2024 17:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=AD=94=E5=99=A8=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=AF=E5=8F=98=E6=8A=A5=E6=96=87=E7=8A=B6=E6=80=81=E5=8F=8A?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/simulation.go | 4 +- bj-rtss-message | 2 +- config/bj_local.yml | 2 +- dto/simulation.go | 12 ++-- dto/state_proto/device_state.pb.go | 32 ++++++++-- message_server/sfp_ms.go | 5 ++ rtss_simulation | 2 +- .../memory/wayside_memory_transponder.go | 64 +++++++++++++++---- 8 files changed, 94 insertions(+), 29 deletions(-) diff --git a/api/simulation.go b/api/simulation.go index 43b944a..b4de711 100644 --- a/api/simulation.go +++ b/api/simulation.go @@ -665,9 +665,9 @@ func baliseTelegramModify(c *gin.Context) { } simulation := checkDeviceDataAndReturn(req.SimulationId) slog.Info("传入状态参数", req) - err := memory.BaliseTelegramModify(simulation, req) + var err *sys_error.BusinessError = memory.BaliseTelegramModify(simulation, req) if err != nil { - panic(sys_error.New(fmt.Sprintf("应答器修改报文操作失败,%s", err.Error()), err)) + panic(err) } c.JSON(http.StatusOK, "ok") } diff --git a/bj-rtss-message b/bj-rtss-message index e800ded..1a75420 160000 --- a/bj-rtss-message +++ b/bj-rtss-message @@ -1 +1 @@ -Subproject commit e800ded2c3b80a73cab3efc07c7146b7ae48035a +Subproject commit 1a75420f049a7b5838d9024a3abb1b9c2e7b7074 diff --git a/config/bj_local.yml b/config/bj_local.yml index b39c8a9..ed80a64 100644 --- a/config/bj_local.yml +++ b/config/bj_local.yml @@ -39,7 +39,7 @@ logging: # 日志文件名 fileName: bjrtsts.log # 单个日志文件大小,单位mb,超过会自动滚动 - fileMaxSize: 5 + fileMaxSize: 50 # 日志文件最大备份数量 fileMaxBackups: 100 # 日志文件最大保留时间,单位 天 diff --git a/dto/simulation.go b/dto/simulation.go index 8a41d81..2854ec8 100644 --- a/dto/simulation.go +++ b/dto/simulation.go @@ -234,11 +234,13 @@ type BaliseMoveReqDto struct { // BaliseModifyTelegramReqDto 修改应答器报文 type BaliseModifyTelegramReqDto struct { - SimulationId string `json:"simulationId" form:"simulationId"` //仿真ID - MapId int32 `json:"mapId" form:"mapId"` //地图ID - BaliseId uint32 `json:"baliseId" form:"baliseId"` //应答器ID - FixedTelegram string `json:"fixedTelegram" from:"fixedTelegram"` //固定报文(16进制字符串) - FixedUserTelegram string `json:"fixedUserTelegram" from:"fixedUserTelegram"` //固定用户报文(16进制字符串) + SimulationId string `json:"simulationId" form:"simulationId"` //仿真ID + MapId int32 `json:"mapId" form:"mapId"` //地图ID + BaliseId uint32 `json:"baliseId" form:"baliseId"` //应答器ID + FixedTelegram string `json:"fixedTelegram" from:"fixedTelegram"` //固定报文(16进制字符串) + FixedUserTelegram string `json:"fixedUserTelegram" from:"fixedUserTelegram"` //固定用户报文(16进制字符串) + VariableTelegram string `json:"variableTelegram" from:"variableTelegram"` //可变报文 + VariableUserTelegram string `json:"variableUserTelegram" from:"variableUserTelegram"` //可变用户报文 } // BaliseReqDto 应答器请求 diff --git a/dto/state_proto/device_state.pb.go b/dto/state_proto/device_state.pb.go index 0cff91f..8bf5525 100644 --- a/dto/state_proto/device_state.pb.go +++ b/dto/state_proto/device_state.pb.go @@ -2952,10 +2952,12 @@ type BaliseState struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Km *data_proto.KilometerSystem `protobuf:"bytes,2,opt,name=km,proto3" json:"km,omitempty"` //当前公里标 - FixedTelegram string `protobuf:"bytes,3,opt,name=fixedTelegram,proto3" json:"fixedTelegram,omitempty"` //固定报文 - FixedUserTelegram string `protobuf:"bytes,4,opt,name=fixedUserTelegram,proto3" json:"fixedUserTelegram,omitempty"` //固定用户报文 + Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Km *data_proto.KilometerSystem `protobuf:"bytes,2,opt,name=km,proto3" json:"km,omitempty"` //当前公里标 + FixedTelegram string `protobuf:"bytes,3,opt,name=fixedTelegram,proto3" json:"fixedTelegram,omitempty"` //固定报文 + FixedUserTelegram string `protobuf:"bytes,4,opt,name=fixedUserTelegram,proto3" json:"fixedUserTelegram,omitempty"` //固定用户报文 + VariableTelegram string `protobuf:"bytes,5,opt,name=variableTelegram,proto3" json:"variableTelegram,omitempty"` //可变报文 + VariableUserTelegram string `protobuf:"bytes,6,opt,name=variableUserTelegram,proto3" json:"variableUserTelegram,omitempty"` //可变用户报文 } func (x *BaliseState) Reset() { @@ -3018,6 +3020,20 @@ func (x *BaliseState) GetFixedUserTelegram() string { return "" } +func (x *BaliseState) GetVariableTelegram() string { + if x != nil { + return x.VariableTelegram + } + return "" +} + +func (x *BaliseState) GetVariableUserTelegram() string { + if x != nil { + return x.VariableUserTelegram + } + return "" +} + // 仿真运行时状态变化量,当前时刻与上一时刻比较得到 type VariationStatus struct { state protoimpl.MessageState @@ -3962,7 +3978,7 @@ var file_device_state_proto_rawDesc = []byte{ 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x31, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x79, 0x53, 0x74, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x0a, 0x72, 0x65, - 0x70, 0x6c, 0x79, 0x53, 0x74, 0x61, 0x74, 0x65, 0x22, 0x9f, 0x01, 0x0a, 0x0b, 0x42, 0x61, 0x6c, + 0x70, 0x6c, 0x79, 0x53, 0x74, 0x61, 0x74, 0x65, 0x22, 0xff, 0x01, 0x0a, 0x0b, 0x42, 0x61, 0x6c, 0x69, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x2c, 0x0a, 0x02, 0x6b, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x44, 0x61, @@ -3972,6 +3988,12 @@ var file_device_state_proto_rawDesc = []byte{ 0x69, 0x78, 0x65, 0x64, 0x54, 0x65, 0x6c, 0x65, 0x67, 0x72, 0x61, 0x6d, 0x12, 0x2c, 0x0a, 0x11, 0x66, 0x69, 0x78, 0x65, 0x64, 0x55, 0x73, 0x65, 0x72, 0x54, 0x65, 0x6c, 0x65, 0x67, 0x72, 0x61, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x66, 0x69, 0x78, 0x65, 0x64, 0x55, 0x73, + 0x65, 0x72, 0x54, 0x65, 0x6c, 0x65, 0x67, 0x72, 0x61, 0x6d, 0x12, 0x2a, 0x0a, 0x10, 0x76, 0x61, + 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x54, 0x65, 0x6c, 0x65, 0x67, 0x72, 0x61, 0x6d, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x54, 0x65, + 0x6c, 0x65, 0x67, 0x72, 0x61, 0x6d, 0x12, 0x32, 0x0a, 0x14, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, + 0x6c, 0x65, 0x55, 0x73, 0x65, 0x72, 0x54, 0x65, 0x6c, 0x65, 0x67, 0x72, 0x61, 0x6d, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x55, 0x73, 0x65, 0x72, 0x54, 0x65, 0x6c, 0x65, 0x67, 0x72, 0x61, 0x6d, 0x22, 0xa1, 0x02, 0x0a, 0x0f, 0x56, 0x61, 0x72, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x38, 0x0a, 0x0c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x18, 0x01, diff --git a/message_server/sfp_ms.go b/message_server/sfp_ms.go index 377b757..c6a80c1 100644 --- a/message_server/sfp_ms.go +++ b/message_server/sfp_ms.go @@ -89,6 +89,11 @@ func collectBaliseStates(world ecs.World, mapId int32) ([]*state_proto.BaliseSta FixedTelegram: fmt.Sprintf("%X", baliseFixedTelegram.Telegram), FixedUserTelegram: fmt.Sprintf("%X", baliseFixedTelegram.UserTelegram), } + if entry.HasComponent(component.BaliseVariableTelegramType) { + baliseVariableTelegram := component.BaliseVariableTelegramType.Get(entry) + baliseState.VariableTelegram = fmt.Sprintf("%X", baliseVariableTelegram.Telegram) + baliseState.VariableUserTelegram = fmt.Sprintf("%X", baliseVariableTelegram.UserTelegram) + } transponderStates = append(transponderStates, baliseState) km := component.KmType.Get(entry) baliseState.Km = &data_proto.KilometerSystem{ diff --git a/rtss_simulation b/rtss_simulation index 247003d..7372a5f 160000 --- a/rtss_simulation +++ b/rtss_simulation @@ -1 +1 @@ -Subproject commit 247003d00b1d1c37e467242ac9b3c35e012b0eb8 +Subproject commit 7372a5fa72e0dbd55ecdcd3fb9161a7ef4af0998 diff --git a/ts/simulation/wayside/memory/wayside_memory_transponder.go b/ts/simulation/wayside/memory/wayside_memory_transponder.go index fa6ba65..c229824 100644 --- a/ts/simulation/wayside/memory/wayside_memory_transponder.go +++ b/ts/simulation/wayside/memory/wayside_memory_transponder.go @@ -3,6 +3,7 @@ package memory import ( "encoding/hex" "fmt" + "joylink.club/ecs" "strings" "joylink.club/bj-rtsts-server/dto" @@ -102,7 +103,7 @@ func BalisePositionModify(simulation *VerifySimulation, req *dto.BaliseMoveReqDt } // BalisePositionReset 应答器复位 -func BalisePositionReset(simulation *VerifySimulation, req *dto.BaliseReqDto) error { +func BalisePositionReset(simulation *VerifySimulation, req *dto.BaliseReqDto) *sys_error.BusinessError { uid := QueryMapUidMapByType(req.MapId, &data_proto.Transponder{})[req.BaliseId].Uid balise := simulation.Repo.FindTransponder(uid) if balise == nil { @@ -111,7 +112,7 @@ func BalisePositionReset(simulation *VerifySimulation, req *dto.BaliseReqDto) er return balisePositionReset(simulation, balise) } -func balisePositionReset(simulation *VerifySimulation, balise *repository.Transponder) error { +func balisePositionReset(simulation *VerifySimulation, balise *repository.Transponder) *sys_error.BusinessError { entry, _ := entity.GetEntityByUid(simulation.World, balise.Id()) component.KmType.Set(entry, balise.Km()) component.LinkPositionType.SetValue(entry, component_data.LinkPosition{ @@ -122,7 +123,7 @@ func balisePositionReset(simulation *VerifySimulation, balise *repository.Transp } // BaliseTelegramModify 修改应答器报文 -func BaliseTelegramModify(simulation *VerifySimulation, req *dto.BaliseModifyTelegramReqDto) error { +func BaliseTelegramModify(simulation *VerifySimulation, req *dto.BaliseModifyTelegramReqDto) *sys_error.BusinessError { uid := QueryMapUidMapByType(req.MapId, &data_proto.Transponder{})[req.BaliseId].Uid entry, ok := entity.GetEntityByUid(simulation.World, uid) if !ok { @@ -144,15 +145,31 @@ func BaliseTelegramModify(simulation *VerifySimulation, req *dto.BaliseModifyTel if err != nil { return sys_error.New("固定用户报文解析出错", err) } - component.BaliseFixedTelegramType.SetValue(entry, component.BaliseState{ - Telegram: ft, - UserTelegram: fut, + vt, err := hex.DecodeString(req.VariableTelegram) + if err != nil { + return sys_error.New("可变报文解析出错", err) + } + vut, err := hex.DecodeString(req.VariableUserTelegram) + if err != nil { + return sys_error.New("可变用户报文解析出错", err) + } + return sendEcsRequest(simulation.World, func() error { + component.BaliseFixedTelegramType.SetValue(entry, component.BaliseState{ + Telegram: ft, + UserTelegram: fut, + }) + if entry.HasComponent(component.BaliseVariableTelegramType) { + component.BaliseVariableTelegramType.SetValue(entry, component.BaliseState{ + Telegram: vt, + UserTelegram: vut, + }) + } + return nil }) - return nil } // BaliseTelegramReset 重置应答器报文 -func BaliseTelegramReset(simulation *VerifySimulation, req *dto.BaliseReqDto) error { +func BaliseTelegramReset(simulation *VerifySimulation, req *dto.BaliseReqDto) *sys_error.BusinessError { uid := QueryMapUidMapByType(req.MapId, &data_proto.Transponder{})[req.BaliseId].Uid worldData := entity.GetWorldData(simulation.World) balise := worldData.Repo.FindTransponder(uid) @@ -162,17 +179,22 @@ func BaliseTelegramReset(simulation *VerifySimulation, req *dto.BaliseReqDto) er return baliseTelegramReset(simulation, balise) } -func baliseTelegramReset(simulation *VerifySimulation, balise *repository.Transponder) error { +func baliseTelegramReset(simulation *VerifySimulation, balise *repository.Transponder) *sys_error.BusinessError { entry, _ := entity.GetEntityByUid(simulation.World, balise.Id()) - component.BaliseFixedTelegramType.SetValue(entry, component.BaliseState{ - Telegram: balise.FixedTelegram(), - UserTelegram: balise.FixedUserTelegram(), + return sendEcsRequest(simulation.World, func() error { + component.BaliseFixedTelegramType.SetValue(entry, component.BaliseState{ + Telegram: balise.FixedTelegram(), + UserTelegram: balise.FixedUserTelegram(), + }) + if entry.HasComponent(component.BaliseVariableTelegramType) { + component.BaliseVariableTelegramType.SetValue(entry, component.BaliseState{}) + } + return nil }) - return nil } // BaliseReset 重置应答器所有状态 -func BaliseReset(simulation *VerifySimulation) error { +func BaliseReset(simulation *VerifySimulation) *sys_error.BusinessError { var errs []error for _, balise := range simulation.Repo.ResponderList() { err := baliseTelegramReset(simulation, balise) @@ -196,3 +218,17 @@ func BaliseReset(simulation *VerifySimulation) error { } return nil } + +func sendEcsRequest(w ecs.World, handler func() error) *sys_error.BusinessError { + result := <-ecs.Request(w, func() ecs.Result[ecs.EmptyType] { + err := handler() + if err != nil { + return ecs.NewErrResult(err) + } + return ecs.NewOkEmptyResult() + }) + if result.Err != nil { + return sys_error.New("仿真世界请求执行失败", result.Err) + } + return nil +}