Skip to content

Commit

Permalink
Merge pull request #6 from winup-zhou/develop
Browse files Browse the repository at this point in the history
测试版 v0.3
  • Loading branch information
winup-zhou authored Oct 27, 2024
2 parents b51158f + 10abbcf commit 97ba229
Show file tree
Hide file tree
Showing 17 changed files with 420 additions and 191 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -361,5 +361,3 @@ MigrationBackup/

# Fody - auto-generated XML schema
FodyWeavers.xsd

*.csproj
3 changes: 2 additions & 1 deletion TGMT-CBTC-EX/Ato.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public static bool IsAvailable() {
&& (StationManager.NextStation.StopPosition - TGMTAts.location > Config.StationStartDistance
|| StationManager.Arrived)
// 离移动授权终点太近不能接通ATO (这是现实情况吗?)
&& (TGMTAts.movementEndpoint.Location - TGMTAts.location > 50 || TGMTAts.releaseSpeed)
&& ((TGMTAts.signalMode == 1 && TGMTAts.movementEndpoint.Location - TGMTAts.location > 50) ||
(TGMTAts.signalMode == 2 && StationManager.CTCEndpoint().Location - TGMTAts.location > 50) || TGMTAts.releaseSpeed)
// CTC下离前车太近不能接通ATO (这是现实情况吗?)
&& (TGMTAts.signalMode == 1 || PreTrainManager.GetEndpoint().Location - TGMTAts.location > 50);
}
Expand Down
4 changes: 2 additions & 2 deletions TGMT-CBTC-EX/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TGMTAts.OBCU {

public static class Config {

public const double LessInf = 100000000;
public const double LessInf = 0x7fffffff;
public static string PluginDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

public static bool Debug = false;
Expand All @@ -30,7 +30,7 @@ public static class Config {
public static double StationEndDistance = 5;
public static double StationMotionEndpoint = 3;
public static double CTCSafetyDistance = 30;
public static double CloseRequestShowTime = 1000;
public static double CloseRequestShowTime = 10;
public static double ITCSafetyDistance = 20;

public static double TrainLength = 0;
Expand Down
11 changes: 11 additions & 0 deletions TGMT-CBTC-EX/DoorControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TGMTAts.OBCU {
internal class DoorControl {

}
}
55 changes: 26 additions & 29 deletions TGMT-CBTC-EX/Inputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.InteropServices;
using AtsEx.PluginHost.Plugins;

namespace TGMTAts.OBCU{
namespace TGMTAts.OBCU {
public partial class TGMTAts : AssemblyPluginBase {

private static bool a1Down, b1Down;
Expand All @@ -19,7 +19,7 @@ private void OnA1Pressed(object sender, EventArgs e) {

private void OnB1Pressed(object sender, EventArgs e) {
b1Down = true;
if (a1Down && b1Down && Ato.IsAvailable()) {
if (a1Down && b1Down && Ato.IsAvailable()) {
driveMode = 2;
}
}
Expand All @@ -36,12 +36,6 @@ private void OnB2Pressed(object sender, EventArgs e) {
selectedMode = selectingMode;
selectModeStartTime = 0;
FixIncompatibleModes();
if (signalMode < lastSigMode) {
// CTC->ITC 降级到RM
// 有说实际运行中这么操作不会到RM的,不过移动授权终点不知道好没好?
signalMode = 0;
FixIncompatibleModes();
}
break;
case 6:
// 切换到RM
Expand Down Expand Up @@ -75,20 +69,23 @@ private void SetBeaconData(AtsEx.PluginHost.Native.BeaconPassedEventArgs e) {
trackLimit.SetBeacon(e);
break;
case 96811:
deviceCapability = e.Optional;
FixIncompatibleModes();
var lastRadioAvailable = RadioAvailable;
RadioAvailable = e.Optional > 0;
if (lastRadioAvailable && !RadioAvailable)
RadioFailed = true;
break;
case 96812:
doorMode = e.Optional;
break;
case 96813:
signalMode = e.Optional / 10 % 10;
if (signalMode != 0) {
Localized = true;
BaliseCount = 0;
}
selectedMode = e.Optional / 100 % 10;
driveMode = 1;
FixIncompatibleModes();
if(signalMode != 0&& driveMode != 0) {
VBCount = FBCount = 1;
}
if (!RadioFailed) FixIncompatibleModes();
break;
case 96810:
trackLimit.SetBeacon(e);
Expand All @@ -111,10 +108,11 @@ private void SetBeaconData(AtsEx.PluginHost.Native.BeaconPassedEventArgs e) {
break;
case 96801:
case 96802:
if (!Localized) BaliseCount += 1;
// TGMT 主
// TGMT 填充
signalMode = 2;
FixIncompatibleModes();
if (signalMode < 1) signalMode = 1;
if (!RadioFailed) FixIncompatibleModes();
if (signalMode == 1) {
if (e.SignalIndex > 0) {
ITCNextSectionPos = e.Optional;
Expand All @@ -123,16 +121,15 @@ private void SetBeaconData(AtsEx.PluginHost.Native.BeaconPassedEventArgs e) {
movementEndpoint = new SpeedLimit(0, e.Optional - Config.ITCSafetyDistance);
releaseSpeed = false;
} else {
ITCNextSectionPos = location + e.Distance;
ITCNextSectionPos = e.Type == 96801 ? location : location + e.Distance;
Log("红灯 移动授权终点是 " + location + e.Distance);
movementEndpoint = new SpeedLimit(0, location + e.Distance - Config.ITCSafetyDistance);
}
}
break;
case 96803:
if (!Localized) BaliseCount += 1;
// TGMT 定位
signalMode = 2;
FixIncompatibleModes();
break;
}
}
Expand All @@ -141,7 +138,7 @@ private void Initialize(AtsEx.PluginHost.Native.StartedEventArgs e) {
driveMode = 1;
FixIncompatibleModes();

ITCNextSectionPos = 0;
ITCNextSectionPos = -114514;
movementEndpoint = SpeedLimit.inf;
nextLimit = null;
selectingMode = -1;
Expand All @@ -160,23 +157,23 @@ private void Initialize(AtsEx.PluginHost.Native.StartedEventArgs e) {

public static double time;
public static double doorOpenTime, doorCloseTime;


private void DoorOpen(AtsEx.PluginHost.Native.DoorEventArgs e) {
doorOpen = true;
doorOpenTime = time;
}


private void DoorClose(AtsEx.PluginHost.Native.DoorEventArgs e) {
doorOpen = false;
doorCloseTime = time;
}


private void HornBlow(int type){

}

}
private void HornBlow(int type) {

}

}
}
74 changes: 58 additions & 16 deletions TGMT-CBTC-EX/Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public partial class TGMTAts : AssemblyPluginBase {
public static int signalMode = 2;
// 1: MM; 2: AM; 3: AA
public static int doorMode = 1;
// 0: 没有CTC,ITC; 1: 没有CTC; 2: 正常
public static int deviceCapability = 2;
// 无线电
public static bool RadioAvailable = false;
public static bool RadioFailed = false;
// WCU可用性
public static bool WCUAvailable = false;

// 暂时的预选速度,-1表示没有在预选
public static int selectingMode = -1;
Expand All @@ -40,12 +43,14 @@ public partial class TGMTAts : AssemblyPluginBase {
public static bool releaseSpeed = false;
public static int ackMessage = 0;

public static int TrainNumber = 0;
public static int DestinationNumber = 0;
public static double ITCNextSectionPos = 0;
public static int TrainNumber = -114514;
public static int DestinationNumber = -114514;
public static double ITCNextSectionPos = -114514;

public static int VBCount = 0;
public static int FBCount = 0;
//定位策略
public static int BaliseCount = 0;
public static double SigUpgradePosition = Config.LessInf;
public static bool Localized = false;

public static double reverseStartLocation = Config.LessInf;

Expand Down Expand Up @@ -90,16 +95,24 @@ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEven
return null;
}

private static void CTCUpgrade() {
signalMode = 2;
FixIncompatibleModes();
}
static void FixIncompatibleModes() {
if (selectedMode == 0) signalMode = 0; // 预选了IXL
if (selectedMode == 1 && signalMode > 1) signalMode = 1; // 预选了ITC
if (selectedMode == 3 && signalMode > 1) signalMode = 1; // 预选了ITC

if (deviceCapability == 0) signalMode = 0; // 没有TGMT设备
if (deviceCapability == 1 && signalMode > 1) signalMode = 1; // 没有无线电信号

if (signalMode > 0 && driveMode == 0) driveMode = 1; // 有信号就至少是SM
if (signalMode == 0 && driveMode > 0) driveMode = 0; // 没信号就得是RM
if (BaliseCount >= 2) { Localized = true; BaliseCount = 0; }
if (WCUAvailable) {
if (selectedMode == 0 || !Localized) signalMode = 0; // 预选了IXL
if (signalMode == 0 && driveMode > 0) driveMode = 0; // 没信号就得是RM
if (Localized) {
if (selectedMode == 1 && signalMode > 1) signalMode = 1; // 预选了ITC
if (selectedMode == 3 && signalMode > 1) signalMode = 1; // 预选了ITC
if (!RadioAvailable && signalMode > 1) signalMode = 1; // 没有无线电信号
if (signalMode > 0 && driveMode == 0) driveMode = 1; // 有信号就至少是SM
}
} else {
signalMode = 0;
}
}

public static int ConvertTime(int human) {
Expand All @@ -118,6 +131,35 @@ public override void Dispose() {
hHMITex.Dispose();
hTDTTex.Dispose();

ITCNextSectionPos = -114514;
movementEndpoint = SpeedLimit.inf;
nextLimit = null;
selectingMode = -1;
selectModeStartTime = 0;
pluginReady = false;
reverseStartLocation = Config.LessInf;
releaseSpeed = false;
ebState = 0;
ackMessage = 0;

DestinationNumber = TrainNumber = -114514;

Ato.ResetCache();
PreTrainManager.ResetCache();

RadioAvailable = false;
RadioFailed = false;
WCUAvailable = false;
doorMode = 1;
signalMode = 2;
driveMode = 1;
selectedMode = 4;
debugMessages.Clear();
trackLimit = new TrackLimit();

BaliseCount = 0;
Localized = false;

Native.NativeKeys.AtsKeys[NativeAtsKeyName.A1].Pressed -= OnA1Pressed;
Native.NativeKeys.AtsKeys[NativeAtsKeyName.B1].Pressed -= OnB1Pressed;
Native.NativeKeys.AtsKeys[NativeAtsKeyName.B2].Pressed -= OnB2Pressed;
Expand Down
2 changes: 1 addition & 1 deletion TGMT-CBTC-EX/Patterns/CalculatedLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static CalculatedLimit Calculate(double location, double idealdecel, doub
Array.Sort(limits, (a, b) => a.Location.CompareTo(b.Location));
int pointer = 0;
double currentTarget = Config.LessInf, nextTarget = Config.LessInf;
while (limits[pointer].Location < location - 10) pointer++;
while (limits[pointer].Location < location - 1) pointer++;
for (int i = 0; i < limits.Length; i++) {
currentTarget = Math.Min(currentTarget, limits[i].AtLocation(location, idealdecel, voffset));
}
Expand Down
2 changes: 1 addition & 1 deletion TGMT-CBTC-EX/Patterns/PreTrainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void SetBeacon(AtsEx.PluginHost.Native.BeaconPassedEventArgs data)
}

public static SpeedLimit GetEndpoint() {
if (Commands.Count == 0) return new SpeedLimit(0, TGMTAts.mapPlugin.MovementAuthority - Config.CTCSafetyDistance);
if (Commands.Count == 0 && TGMTAts.WCUAvailable) return new SpeedLimit(0, TGMTAts.mapPlugin.MovementAuthority - Config.CTCSafetyDistance);
int pointer = 0;
var time = TGMTAts.time;
while (pointer < Commands.Count && Commands[pointer].Time < time) pointer++;
Expand Down
Loading

0 comments on commit 97ba229

Please sign in to comment.