【动力学link转换】
This commit is contained in:
parent
9799ed41d1
commit
88c54e23b8
@ -166,7 +166,7 @@ func convert(info *dynamics.TrainInfo, sta *state.TrainState, simulation *memory
|
|||||||
zap.S().Debugf("原始消息:[%d-%d-%d]", info.Number, info.Link, info.LinkOffset)
|
zap.S().Debugf("原始消息:[%d-%d-%d]", info.Number, info.Link, info.LinkOffset)
|
||||||
id, port, offset, runDirection, pointTo, kilometer := memory.QueryDeviceByCalcLink(simulation.Repo, strconv.Itoa(int(info.Link)), int64(info.LinkOffset), info.Up)
|
id, port, offset, runDirection, pointTo, kilometer := memory.QueryDeviceByCalcLink(simulation.Repo, strconv.Itoa(int(info.Link)), int64(info.LinkOffset), info.Up)
|
||||||
zap.S().Debugf("转换后的消息:[%d-车头:%s-偏移:%d-上行:%v-是否ab:%v]", info.Number, id, offset, runDirection, pointTo)
|
zap.S().Debugf("转换后的消息:[%d-车头:%s-偏移:%d-上行:%v-是否ab:%v]", info.Number, id, offset, runDirection, pointTo)
|
||||||
sta.HeadDeviceId = id
|
sta.HeadDeviceId = strconv.Itoa(int(simulation.GetComIdByIndex(id)))
|
||||||
sta.DevicePort = port
|
sta.DevicePort = port
|
||||||
sta.HeadOffset = offset
|
sta.HeadOffset = offset
|
||||||
sta.PointTo = pointTo
|
sta.PointTo = pointTo
|
||||||
|
@ -181,43 +181,107 @@ func QueryDeviceByCalcLink(repo *repository.Repository, id string, offset int64,
|
|||||||
if offset > link.Length() {
|
if offset > link.Length() {
|
||||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("偏移【%d】超出link范围【%d】", offset, link.Length())})
|
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("偏移【%d】超出link范围【%d】", offset, link.Length())})
|
||||||
}
|
}
|
||||||
|
// 判断是否在道岔上
|
||||||
|
onTurnout, isA := isOnLinkTurnout(link, offset)
|
||||||
|
if onTurnout {
|
||||||
|
return ecsLinkMapToTurnout(isA, offset, up, link)
|
||||||
|
} else {
|
||||||
|
return ecsLinkMapToSection(offset, up, link)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否在link的道岔上
|
||||||
|
func isOnLinkTurnout(link *repository.Link, offset int64) (bool, bool) {
|
||||||
aTp := link.ARelation()
|
aTp := link.ARelation()
|
||||||
|
var turnoutOffset int64
|
||||||
|
if aTp != nil {
|
||||||
|
turnoutOffset = aTp.Turnout().FindLinkPositionByPort(aTp.Port()).Offset()
|
||||||
|
}
|
||||||
|
if offset <= turnoutOffset {
|
||||||
|
return true, true
|
||||||
|
}
|
||||||
bTp := link.BRelation()
|
bTp := link.BRelation()
|
||||||
aOffset := aTp.Turnout().FindLinkPositionByPort(aTp.Port()).Offset()
|
if bTp != nil {
|
||||||
bOffset := bTp.Turnout().FindLinkPositionByPort(bTp.Port()).Offset()
|
turnoutOffset = bTp.Turnout().FindLinkPositionByPort(bTp.Port()).Offset()
|
||||||
if offset <= aOffset {
|
return offset >= turnoutOffset, false
|
||||||
deviceId = aTp.Turnout().Id()
|
}
|
||||||
deviceOffset = aOffset - (aOffset - offset)
|
return false, false
|
||||||
if up {
|
}
|
||||||
pointTo = false
|
|
||||||
} else {
|
// 处理在道岔上link映射
|
||||||
pointTo = true
|
func ecsLinkMapToTurnout(isA bool, offset int64, up bool, link *repository.Link) (
|
||||||
}
|
deviceId, port string, deviceOffset int64, runDirection, pointTo bool, km int64) {
|
||||||
switch aTp.Port() {
|
tp := link.ARelation()
|
||||||
case proto2.Port_A:
|
if !isA {
|
||||||
port = "A"
|
tp = link.BRelation()
|
||||||
case proto2.Port_B:
|
}
|
||||||
port = "B"
|
deviceId = tp.Turnout().Id()
|
||||||
case proto2.Port_C:
|
tpOffset := tp.Turnout().FindLinkPositionByPort(tp.Port()).Offset()
|
||||||
port = "C"
|
crossKm, portKm := tp.Turnout().GetTurnoutKm(proto2.Port_None).Value, tp.Turnout().GetTurnoutKm(tp.Port()).Value
|
||||||
}
|
if isA {
|
||||||
} else if offset >= bOffset {
|
deviceOffset = tpOffset - (tpOffset - offset)
|
||||||
deviceId = bTp.Turnout().Id()
|
pointTo = !up
|
||||||
|
} else {
|
||||||
deviceOffset = link.Length() - offset
|
deviceOffset = link.Length() - offset
|
||||||
if up {
|
pointTo = up
|
||||||
pointTo = true
|
}
|
||||||
} else {
|
// 查询公里标大于端口公里标
|
||||||
pointTo = false
|
if crossKm > portKm {
|
||||||
}
|
km = crossKm - deviceOffset
|
||||||
switch bTp.Port() {
|
runDirection = pointTo
|
||||||
case proto2.Port_A:
|
} else {
|
||||||
port = "A"
|
km = crossKm + deviceOffset
|
||||||
case proto2.Port_B:
|
runDirection = !pointTo
|
||||||
port = "B"
|
}
|
||||||
case proto2.Port_C:
|
switch tp.Port() {
|
||||||
port = "C"
|
case proto2.Port_A:
|
||||||
|
port = "A"
|
||||||
|
case proto2.Port_B:
|
||||||
|
port = "B"
|
||||||
|
case proto2.Port_C:
|
||||||
|
port = "C"
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理在道岔上link映射
|
||||||
|
func ecsLinkMapToSection(offset int64, up bool, link *repository.Link) (
|
||||||
|
deviceId, port string, deviceOffset int64, runDirection, pointTo bool, km int64) {
|
||||||
|
var section *repository.PhysicalSection
|
||||||
|
for _, s := range link.PhysicalSections() {
|
||||||
|
ao, bo := s.ALinkPosition().Offset(), s.BLinkPosition().Offset()
|
||||||
|
if (ao <= offset && offset <= bo) || (bo <= offset && offset <= ao) {
|
||||||
|
section = s
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if section == nil {
|
||||||
|
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("未找到link设备偏移【%d】", offset)})
|
||||||
|
}
|
||||||
|
// 元素ID
|
||||||
|
deviceId = section.Id()
|
||||||
|
// link偏移变大方向
|
||||||
|
ao, bo := section.ALinkPosition().Offset(), section.BLinkPosition().Offset()
|
||||||
|
ak, bk := section.AKilometer().Value, section.BKilometer().Value
|
||||||
|
if up {
|
||||||
|
pointTo = ao < bo
|
||||||
|
runDirection = ((ak < bk) == (ao < bo))
|
||||||
|
} else {
|
||||||
|
pointTo = bo > ao
|
||||||
|
runDirection = ((ak > bk) == (ao > bo))
|
||||||
|
}
|
||||||
|
// a点偏移 大于 b点偏移
|
||||||
|
if ao > bo {
|
||||||
|
deviceOffset = ao - offset
|
||||||
|
} else {
|
||||||
|
deviceOffset = offset - ao
|
||||||
|
}
|
||||||
|
// a点公里标 大于 b点公里标
|
||||||
|
if ak > bk {
|
||||||
|
km = ak - deviceOffset
|
||||||
|
} else {
|
||||||
|
km = ak + deviceOffset
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +158,18 @@ func (s *VerifySimulation) GetComIdByUid(uid string) string {
|
|||||||
return es[uid].CommonId
|
return es[uid].CommonId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取仿真世界信息
|
||||||
|
func (s *VerifySimulation) GetComIdByIndex(uid string) int32 {
|
||||||
|
es := s.uidMap
|
||||||
|
if es == nil {
|
||||||
|
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无映射信息"})
|
||||||
|
}
|
||||||
|
if es[uid] == nil {
|
||||||
|
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无【uid】映射信息"})
|
||||||
|
}
|
||||||
|
return es[uid].Index
|
||||||
|
}
|
||||||
|
|
||||||
func buildProtoRepository(mapIds []int32) (*proto.Repository, error) {
|
func buildProtoRepository(mapIds []int32) (*proto.Repository, error) {
|
||||||
repo := &proto.Repository{}
|
repo := &proto.Repository{}
|
||||||
var exceptStationGiMapIds []int32
|
var exceptStationGiMapIds []int32
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 5833de36fbb1e153672aa1ddf049f7006eefca60
|
Subproject commit be88137f2ab670707c7bd80f708ad1379c62f141
|
Loading…
Reference in New Issue
Block a user