[修改]北京12号线连锁rsd、sse、ssr编解码算法及交互流程

This commit is contained in:
thesai 2024-07-29 13:53:46 +08:00
parent ef7e469175
commit 8c6bfb2aee
8 changed files with 680 additions and 569 deletions

View File

@ -9,6 +9,9 @@ var (
BaliseVB = ecs.NewTag() // 主信号应答器
BaliseIB = ecs.NewTag() // 预告应答器
)
var ForceVariableTelegram = ecs.NewTag() //表示可变报文为强制设置并锁定
var BaliseFixedTelegramType = ecs.NewComponentType[BaliseTelegram]() //应答器固定报文
var BaliseVariableTelegramType = ecs.NewComponentType[BaliseTelegram]() //应答器可变报文
type BaliseTelegram struct {

View File

@ -12,7 +12,7 @@ func GetBitOfBytes(bs []byte, bitIndex int) bool {
panic(fmt.Errorf("从字节数组获取位值错误,位索引超出字节数组范围: 数组len=%d,位索引=%d", len(bs), bitIndex))
}
by := bs[bi]
v := byte(1 << (7 - i))
v := byte(1 << i)
return (by & v) == v
}

65
fi/balise.go Normal file
View File

@ -0,0 +1,65 @@
package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
// BaliseUpdateFixedTelegram 更新固定报文
func BaliseUpdateFixedTelegram(w ecs.World, id string, telegram []byte, userTelegram []byte) error {
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
baliseFixedTelegram := component.BaliseFixedTelegramType.Get(entry)
baliseFixedTelegram.Telegram = telegram
baliseFixedTelegram.UserTelegram = userTelegram
} else {
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的应答器", id))
}
return ecs.NewOkEmptyResult()
})
return result.Err
}
// BaliseUpdateVariableTelegram 更新可变报文
func BaliseUpdateVariableTelegram(w ecs.World, id string, telegram []byte, force bool) error {
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
if entry.HasComponent(component.BaliseVariableTelegramType) {
if force {
entry.AddComponent(component.ForceVariableTelegram)
} else if entry.HasComponent(component.ForceVariableTelegram) {
return ecs.NewOkEmptyResult()
}
baliseVariableTelegram := component.BaliseVariableTelegramType.Get(entry)
baliseVariableTelegram.Telegram = telegram
} else {
ecs.NewErrResult(fmt.Errorf("应答器[%s]无可变报文组件", id))
}
} else {
return ecs.NewErrResult(fmt.Errorf("未找到应答器[%s]", id))
}
return ecs.NewOkEmptyResult()
})
return result.Err
}
// BaliseCancelForceVariableTelegram 取消强制可变报文
func BaliseCancelForceVariableTelegram(w ecs.World, id string) error {
request := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
if entry.HasComponent(component.ForceVariableTelegram) {
entry.RemoveComponent(component.ForceVariableTelegram)
}
}
return ecs.NewOkEmptyResult()
})
return request.Err
}

View File

@ -164,6 +164,8 @@ message Transponder {
bytes fixedTelegram = 5;//
Type type = 6;//
bytes fixedUserTelegram = 7; //
uint32 leuIndex = 8; //LEU的索引
uint32 indexInLeu = 9; //LEU内部的索引
enum Type {
FB = 0; //
WB = 1; //

File diff suppressed because it is too large Load Diff

View File

@ -370,6 +370,14 @@ func (repo *Repository) CentralizedStationRefList() []*proto.CentralizedStationR
return list
}
func (repo *Repository) TransponderList() []*Transponder {
var list []*Transponder
for _, model := range repo.responderMap {
list = append(list, model)
}
return list
}
func (repo *Repository) GetCentralizedStationRef(centralizedStationId string) *proto.CentralizedStationRef {
return repo.centralizedMap[centralizedStationId]
}

View File

@ -80,7 +80,8 @@ func buildModels(source *proto.Repository, repository *Repository) error {
repository.signalMap[m.Id()] = m
}
for _, protoData := range source.Transponders {
m := NewTransponder(protoData.Id, protoData.Km, protoData.FixedTelegram, protoData.FixedUserTelegram, protoData.Type)
m := NewTransponder(protoData.Id, protoData.Km, protoData.FixedTelegram, protoData.FixedUserTelegram,
protoData.Type, protoData.LeuIndex, protoData.IndexInLeu)
repository.responderMap[m.Id()] = m
}
for _, protoData := range source.Slopes {

View File

@ -12,17 +12,23 @@ type Transponder struct {
fixedTelegram []byte //应答器固定报文
fixedUserTelegram []byte //应答器固定用户报文
baliseType proto.Transponder_Type //应答器类型
leuIndex uint32 //应答器所属LEU的索引
indexInLeu uint32 //应答器在LEU内的索引
}
func NewTransponder(id string, km *proto.Kilometer, fixedTelegram []byte, fixedUserTelegram []byte, baliseType proto.Transponder_Type) *Transponder {
func NewTransponder(id string, km *proto.Kilometer, fixedTelegram []byte, fixedUserTelegram []byte,
baliseType proto.Transponder_Type, leuIndex uint32, indexInLeu uint32) *Transponder {
return &Transponder{
Identity: identity{id, proto.DeviceType_DeviceType_Transponder},
km: km,
fixedTelegram: fixedTelegram,
fixedUserTelegram: fixedUserTelegram,
baliseType: baliseType,
leuIndex: leuIndex,
indexInLeu: indexInLeu,
}
}
func (t *Transponder) TransponderType() proto.Transponder_Type {
return t.baliseType
}
@ -35,7 +41,6 @@ func (t *Transponder) FixedUserTelegram() []byte {
func (t *Transponder) bindLinkPosition(position *LinkPosition) {
t.linkPosition = position
}
func (t *Transponder) LinkPosition() *LinkPosition {
return t.linkPosition
}
@ -47,3 +52,11 @@ func (t *Transponder) Km() *proto.Kilometer {
func (t *Transponder) BaliseType() proto.Transponder_Type {
return t.baliseType
}
func (t *Transponder) LeuIndex() uint32 {
return t.leuIndex
}
func (t *Transponder) IndexInLeu() uint32 {
return t.indexInLeu
}