应答器增加可变报文状态及操作

This commit is contained in:
joylink_zhangsai 2024-01-24 17:45:16 +08:00
parent 5ee14ba52e
commit ec48b5f48a
8 changed files with 94 additions and 29 deletions

View File

@ -665,9 +665,9 @@ func baliseTelegramModify(c *gin.Context) {
} }
simulation := checkDeviceDataAndReturn(req.SimulationId) simulation := checkDeviceDataAndReturn(req.SimulationId)
slog.Info("传入状态参数", req) slog.Info("传入状态参数", req)
err := memory.BaliseTelegramModify(simulation, req) var err *sys_error.BusinessError = memory.BaliseTelegramModify(simulation, req)
if err != nil { if err != nil {
panic(sys_error.New(fmt.Sprintf("应答器修改报文操作失败,%s", err.Error()), err)) panic(err)
} }
c.JSON(http.StatusOK, "ok") c.JSON(http.StatusOK, "ok")
} }

@ -1 +1 @@
Subproject commit e800ded2c3b80a73cab3efc07c7146b7ae48035a Subproject commit 1a75420f049a7b5838d9024a3abb1b9c2e7b7074

View File

@ -39,7 +39,7 @@ logging:
# 日志文件名 # 日志文件名
fileName: bjrtsts.log fileName: bjrtsts.log
# 单个日志文件大小,单位mb,超过会自动滚动 # 单个日志文件大小,单位mb,超过会自动滚动
fileMaxSize: 5 fileMaxSize: 50
# 日志文件最大备份数量 # 日志文件最大备份数量
fileMaxBackups: 100 fileMaxBackups: 100
# 日志文件最大保留时间,单位 天 # 日志文件最大保留时间,单位 天

View File

@ -239,6 +239,8 @@ type BaliseModifyTelegramReqDto struct {
BaliseId uint32 `json:"baliseId" form:"baliseId"` //应答器ID BaliseId uint32 `json:"baliseId" form:"baliseId"` //应答器ID
FixedTelegram string `json:"fixedTelegram" from:"fixedTelegram"` //固定报文16进制字符串 FixedTelegram string `json:"fixedTelegram" from:"fixedTelegram"` //固定报文16进制字符串
FixedUserTelegram string `json:"fixedUserTelegram" from:"fixedUserTelegram"` //固定用户报文16进制字符串 FixedUserTelegram string `json:"fixedUserTelegram" from:"fixedUserTelegram"` //固定用户报文16进制字符串
VariableTelegram string `json:"variableTelegram" from:"variableTelegram"` //可变报文
VariableUserTelegram string `json:"variableUserTelegram" from:"variableUserTelegram"` //可变用户报文
} }
// BaliseReqDto 应答器请求 // BaliseReqDto 应答器请求

View File

@ -2956,6 +2956,8 @@ type BaliseState struct {
Km *data_proto.KilometerSystem `protobuf:"bytes,2,opt,name=km,proto3" json:"km,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"` //固定报文 FixedTelegram string `protobuf:"bytes,3,opt,name=fixedTelegram,proto3" json:"fixedTelegram,omitempty"` //固定报文
FixedUserTelegram string `protobuf:"bytes,4,opt,name=fixedUserTelegram,proto3" json:"fixedUserTelegram,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() { func (x *BaliseState) Reset() {
@ -3018,6 +3020,20 @@ func (x *BaliseState) GetFixedUserTelegram() string {
return "" 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 { type VariationStatus struct {
state protoimpl.MessageState 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 0x0a, 0x0c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x18, 0x01,

View File

@ -89,6 +89,11 @@ func collectBaliseStates(world ecs.World, mapId int32) ([]*state_proto.BaliseSta
FixedTelegram: fmt.Sprintf("%X", baliseFixedTelegram.Telegram), FixedTelegram: fmt.Sprintf("%X", baliseFixedTelegram.Telegram),
FixedUserTelegram: fmt.Sprintf("%X", baliseFixedTelegram.UserTelegram), 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) transponderStates = append(transponderStates, baliseState)
km := component.KmType.Get(entry) km := component.KmType.Get(entry)
baliseState.Km = &data_proto.KilometerSystem{ baliseState.Km = &data_proto.KilometerSystem{

@ -1 +1 @@
Subproject commit 247003d00b1d1c37e467242ac9b3c35e012b0eb8 Subproject commit 7372a5fa72e0dbd55ecdcd3fb9161a7ef4af0998

View File

@ -3,6 +3,7 @@ package memory
import ( import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"joylink.club/ecs"
"strings" "strings"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
@ -102,7 +103,7 @@ func BalisePositionModify(simulation *VerifySimulation, req *dto.BaliseMoveReqDt
} }
// BalisePositionReset 应答器复位 // 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 uid := QueryMapUidMapByType(req.MapId, &data_proto.Transponder{})[req.BaliseId].Uid
balise := simulation.Repo.FindTransponder(uid) balise := simulation.Repo.FindTransponder(uid)
if balise == nil { if balise == nil {
@ -111,7 +112,7 @@ func BalisePositionReset(simulation *VerifySimulation, req *dto.BaliseReqDto) er
return balisePositionReset(simulation, balise) 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()) entry, _ := entity.GetEntityByUid(simulation.World, balise.Id())
component.KmType.Set(entry, balise.Km()) component.KmType.Set(entry, balise.Km())
component.LinkPositionType.SetValue(entry, component_data.LinkPosition{ component.LinkPositionType.SetValue(entry, component_data.LinkPosition{
@ -122,7 +123,7 @@ func balisePositionReset(simulation *VerifySimulation, balise *repository.Transp
} }
// BaliseTelegramModify 修改应答器报文 // 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 uid := QueryMapUidMapByType(req.MapId, &data_proto.Transponder{})[req.BaliseId].Uid
entry, ok := entity.GetEntityByUid(simulation.World, uid) entry, ok := entity.GetEntityByUid(simulation.World, uid)
if !ok { if !ok {
@ -144,15 +145,31 @@ func BaliseTelegramModify(simulation *VerifySimulation, req *dto.BaliseModifyTel
if err != nil { if err != nil {
return sys_error.New("固定用户报文解析出错", err) return sys_error.New("固定用户报文解析出错", err)
} }
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{ component.BaliseFixedTelegramType.SetValue(entry, component.BaliseState{
Telegram: ft, Telegram: ft,
UserTelegram: fut, UserTelegram: fut,
}) })
if entry.HasComponent(component.BaliseVariableTelegramType) {
component.BaliseVariableTelegramType.SetValue(entry, component.BaliseState{
Telegram: vt,
UserTelegram: vut,
})
}
return nil return nil
})
} }
// BaliseTelegramReset 重置应答器报文 // 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 uid := QueryMapUidMapByType(req.MapId, &data_proto.Transponder{})[req.BaliseId].Uid
worldData := entity.GetWorldData(simulation.World) worldData := entity.GetWorldData(simulation.World)
balise := worldData.Repo.FindTransponder(uid) balise := worldData.Repo.FindTransponder(uid)
@ -162,17 +179,22 @@ func BaliseTelegramReset(simulation *VerifySimulation, req *dto.BaliseReqDto) er
return baliseTelegramReset(simulation, balise) 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()) entry, _ := entity.GetEntityByUid(simulation.World, balise.Id())
return sendEcsRequest(simulation.World, func() error {
component.BaliseFixedTelegramType.SetValue(entry, component.BaliseState{ component.BaliseFixedTelegramType.SetValue(entry, component.BaliseState{
Telegram: balise.FixedTelegram(), Telegram: balise.FixedTelegram(),
UserTelegram: balise.FixedUserTelegram(), UserTelegram: balise.FixedUserTelegram(),
}) })
if entry.HasComponent(component.BaliseVariableTelegramType) {
component.BaliseVariableTelegramType.SetValue(entry, component.BaliseState{})
}
return nil return nil
})
} }
// BaliseReset 重置应答器所有状态 // BaliseReset 重置应答器所有状态
func BaliseReset(simulation *VerifySimulation) error { func BaliseReset(simulation *VerifySimulation) *sys_error.BusinessError {
var errs []error var errs []error
for _, balise := range simulation.Repo.ResponderList() { for _, balise := range simulation.Repo.ResponderList() {
err := baliseTelegramReset(simulation, balise) err := baliseTelegramReset(simulation, balise)
@ -196,3 +218,17 @@ func BaliseReset(simulation *VerifySimulation) error {
} }
return nil 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
}