[修改]11号线通信服务结束时,调用服务上下文中的cancelFunc以结束死循环协程

This commit is contained in:
thesai 2024-09-30 16:24:02 +08:00
parent 2463edd996
commit 735423ca67
4 changed files with 16 additions and 15 deletions

@ -1 +1 @@
Subproject commit ef7ff5459cde3eced121d1908b192ee586a47c97
Subproject commit 150aa24307c42916cde8f6fbe629c9d100be8737

View File

@ -9,7 +9,7 @@ import (
)
func TestFromInterlockFrame_Decode(t *testing.T) {
str := "58bea4c65e0e583f5bdedc310800450000c94eae0000801100003d0b0a0d3d0b7814413c40d800b5fcfd8200a63c0363010003000400000500000900000200040000080000020004aaaa0008aaaa0000000f000d06000e01000f060010060021060023060011060012060026060027010013060014010022060024060025060010001300001400001500001600001700001800001900001a00002c00002d00002e00002f00003000003100003200003300000000000004000daaaa000eaaaa000faaaa0010aaaa00000000000000000000000058f24545"
str := "58bea4c65e0e583f5bdedc310800450000c9d0770000801100003d0b0a0d3d0b7814413c40d800b5fcfd8200a63c0363010003000400000500000900000200040000080000020004aaaa0008aaaa0000000f000d06000e01000f060010060021060023060011060012060026060027010013060014010022060024060025060010001300001400001500001600001700001800001900001a00002c00002d00002e00002f00003000003100003200003300000000000004000daaaa000eaaaa000faaaa0010aaaa00000000000000000000000058f24545"
data, err := hex.DecodeString(str)
if err != nil {
t.Fatal(err)

View File

@ -84,6 +84,19 @@ func Start(interlockConfig config.InterlockConfig, simulation *memory.VerifySimu
serviceContextMap[interlockConfig.Code] = serviceCtx
}
func Stop(stationCode string) {
mu.Lock()
defer mu.Unlock()
serviceContext := serviceContextMap[stationCode]
if serviceContext != nil {
serviceContext.cancelFunc()
if serviceContext.server != nil {
serviceContext.server.Close()
}
delete(serviceContextMap, stationCode)
}
}
func (s *serviceContext) handleDriveMsg(data []byte) {
logger().Info(fmt.Sprintf("收到消息:%x", data))
frame := &FromInterlockFrame{}
@ -310,18 +323,6 @@ func (s *serviceContext) handleDriveMsg(data []byte) {
}
}
func Stop(stationCode string) {
mu.Lock()
defer mu.Unlock()
serviceContext := serviceContextMap[stationCode]
if serviceContext != nil {
if serviceContext.server != nil {
serviceContext.server.Close()
}
delete(serviceContextMap, stationCode)
}
}
func preprocessingData(sim *memory.VerifySimulation, stationCode string) (*StationDeviceIndexTable, []*ToInterlockFrame) {
for _, mapId := range sim.MapIds {
giType := memory.QueryGiType(mapId)

View File

@ -193,7 +193,7 @@ func stopThirdParty(s *memory.VerifySimulation) {
semi_physical_train.BtmDefault().Stop()
// 停止动力学接口功能
dynamics.Default().Stop()
// 联锁启动
// 联锁通信服务停止
for _, c := range s.GetRunConfig().Interlocks {
switch c.Line {
case "11":