Skip to content

Commit c466c51

Browse files
Catch errors in getting status as they might block the Switch Panel. Now there is just an empty button and a log message.
1 parent f5d692a commit c466c51

File tree

2 files changed

+84
-69
lines changed

2 files changed

+84
-69
lines changed

Source/RunActivity/Viewer3D/WebServices/SwitchPanel/SwitchOnPanelStatus.cs

Lines changed: 80 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@
2323
using Orts.Simulation.RollingStocks.SubSystems;
2424
using Orts.Simulation.RollingStocks;
2525
using ORTS.Common;
26+
using System;
27+
using System.Diagnostics;
2628

2729
namespace Orts.Viewer3D.WebServices.SwitchPanel
2830
{
2931
public class SwitchOnPanelStatus
3032
{
31-
private static Viewer Viewer;
32-
3333
public string Status = "";
3434
public string Color = "";
3535
public bool Blinking = false;
3636

37+
private static Viewer Viewer;
38+
private static List<UserCommand> ExceptionForCommand = new List<UserCommand>();
39+
3740
public SwitchOnPanelStatus(Viewer viewer)
3841
{
3942
Viewer = viewer;
@@ -436,68 +439,82 @@ public static void getStatus(UserCommand userCommand, ref SwitchOnPanelStatus sw
436439
switchOnPanelStatus.Color = "";
437440
switchOnPanelStatus.Blinking = false;
438441

439-
switch (userCommand)
442+
try
440443
{
441-
case UserCommand.ControlDoorLeft:
442-
case UserCommand.ControlDoorRight:
443-
getStatusDoors(userCommand, ref switchOnPanelStatus);
444-
break;
445-
case UserCommand.ControlPantograph1:
446-
case UserCommand.ControlPantograph2:
447-
case UserCommand.ControlPantograph3:
448-
case UserCommand.ControlPantograph4:
449-
getStatusControlPantograph(userCommand, ref switchOnPanelStatus);
450-
break;
451-
case UserCommand.ControlHeadlightIncrease:
452-
case UserCommand.ControlHeadlightDecrease:
453-
getStatusControlHeadlight(ref switchOnPanelStatus);
454-
break;
455-
case UserCommand.ControlLight:
456-
getStatusControlCablight(ref switchOnPanelStatus);
457-
break;
458-
case UserCommand.ControlBackwards:
459-
case UserCommand.ControlForwards:
460-
getStatusControlDirection(ref switchOnPanelStatus);
461-
break;
462-
case UserCommand.ControlSander:
463-
getStatusControlSander(ref switchOnPanelStatus);
464-
break;
465-
case UserCommand.ControlWiper:
466-
getStatusControlWiper(ref switchOnPanelStatus);
467-
break;
468-
case UserCommand.ControlEmergencyPushButton:
469-
getStatusControlEmergencyPushButton(ref switchOnPanelStatus);
470-
break;
471-
case UserCommand.GameSwitchManualMode:
472-
getStatusGameControlMode(ref switchOnPanelStatus);
473-
break;
474-
case UserCommand.GameAutopilotMode:
475-
getStatusGameAutopilotMode(ref switchOnPanelStatus);
476-
break;
477-
case UserCommand.ControlMasterKey:
478-
getStatusMasterKey(ref switchOnPanelStatus);
479-
break;
480-
case UserCommand.ControlBatterySwitchClose:
481-
getStatusBatterySwitch(ref switchOnPanelStatus);
482-
break;
483-
case UserCommand.ControlCircuitBreakerClosingOrder:
484-
getStatusCircuitBreaker(ref switchOnPanelStatus);
485-
break;
486-
case UserCommand.ControlDieselPlayer:
487-
getStatusDieselEngine(UserCommand.ControlDieselPlayer, ref switchOnPanelStatus);
488-
break;
489-
case UserCommand.ControlDieselHelper:
490-
getStatusDieselEngine(UserCommand.ControlDieselHelper, ref switchOnPanelStatus);
491-
break;
492-
case UserCommand.ControlTractionCutOffRelayClosingOrder:
493-
getStatusTractionCutOffRelay(ref switchOnPanelStatus);
494-
break;
495-
case UserCommand.ControlHandbrakeFull:
496-
getStatusHandbrake(ref switchOnPanelStatus);
497-
break;
498-
case UserCommand.ControlBrakeHoseConnect:
499-
getStatusBrakehose(ref switchOnPanelStatus);
500-
break;
444+
switch (userCommand)
445+
{
446+
case UserCommand.ControlDoorLeft:
447+
case UserCommand.ControlDoorRight:
448+
getStatusDoors(userCommand, ref switchOnPanelStatus);
449+
break;
450+
case UserCommand.ControlPantograph1:
451+
case UserCommand.ControlPantograph2:
452+
case UserCommand.ControlPantograph3:
453+
case UserCommand.ControlPantograph4:
454+
getStatusControlPantograph(userCommand, ref switchOnPanelStatus);
455+
break;
456+
case UserCommand.ControlHeadlightIncrease:
457+
case UserCommand.ControlHeadlightDecrease:
458+
getStatusControlHeadlight(ref switchOnPanelStatus);
459+
break;
460+
case UserCommand.ControlLight:
461+
getStatusControlCablight(ref switchOnPanelStatus);
462+
break;
463+
case UserCommand.ControlBackwards:
464+
case UserCommand.ControlForwards:
465+
getStatusControlDirection(ref switchOnPanelStatus);
466+
break;
467+
case UserCommand.ControlSander:
468+
getStatusControlSander(ref switchOnPanelStatus);
469+
break;
470+
case UserCommand.ControlWiper:
471+
getStatusControlWiper(ref switchOnPanelStatus);
472+
break;
473+
case UserCommand.ControlEmergencyPushButton:
474+
getStatusControlEmergencyPushButton(ref switchOnPanelStatus);
475+
break;
476+
case UserCommand.GameSwitchManualMode:
477+
getStatusGameControlMode(ref switchOnPanelStatus);
478+
break;
479+
case UserCommand.GameAutopilotMode:
480+
getStatusGameAutopilotMode(ref switchOnPanelStatus);
481+
break;
482+
case UserCommand.ControlMasterKey:
483+
getStatusMasterKey(ref switchOnPanelStatus);
484+
break;
485+
case UserCommand.ControlBatterySwitchClose:
486+
getStatusBatterySwitch(ref switchOnPanelStatus);
487+
break;
488+
case UserCommand.ControlCircuitBreakerClosingOrder:
489+
getStatusCircuitBreaker(ref switchOnPanelStatus);
490+
break;
491+
case UserCommand.ControlDieselPlayer:
492+
getStatusDieselEngine(UserCommand.ControlDieselPlayer, ref switchOnPanelStatus);
493+
break;
494+
case UserCommand.ControlDieselHelper:
495+
getStatusDieselEngine(UserCommand.ControlDieselHelper, ref switchOnPanelStatus);
496+
break;
497+
case UserCommand.ControlTractionCutOffRelayClosingOrder:
498+
getStatusTractionCutOffRelay(ref switchOnPanelStatus);
499+
break;
500+
case UserCommand.ControlHandbrakeFull:
501+
getStatusHandbrake(ref switchOnPanelStatus);
502+
break;
503+
case UserCommand.ControlBrakeHoseConnect:
504+
getStatusBrakehose(ref switchOnPanelStatus);
505+
break;
506+
}
507+
}
508+
catch (Exception ex)
509+
{
510+
if (!ExceptionForCommand.Contains(userCommand))
511+
{
512+
// exception not yet logged
513+
ExceptionForCommand.Add(userCommand);
514+
515+
Trace.Write("Error in Switch Panel function \"getStatus\" getting status for " + userCommand + ":");
516+
Trace.WriteLine(ex);
517+
}
501518
}
502519
}
503520

Source/RunActivity/Viewer3D/WebServices/SwitchPanel/SwitchPanelModule.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ protected override Task OnMessageReceivedAsync(IWebSocketContext context, byte[]
4646
{
4747
var text = Encoding.GetString(rxBuffer);
4848
var switchPanelEvent = JsonConvert.DeserializeObject<SwitchPanelEvent>(text);
49-
Trace.TraceInformation("Got message of type {0} {1}", switchPanelEvent.Type, switchPanelEvent.Data);
5049

5150
int value;
5251
switch (switchPanelEvent.Type)
@@ -96,15 +95,15 @@ public static void SendSwitchPanelIfChanged()
9695
/// <inheritdoc />
9796
protected override Task OnClientConnectedAsync(IWebSocketContext context)
9897
{
99-
Trace.TraceInformation("client connected");
98+
Trace.TraceInformation("SwitchPanel, client connected");
10099
Connections++;
101100
return Task.CompletedTask;
102101
}
103102

104103
/// <inheritdoc />
105104
protected override Task OnClientDisconnectedAsync(IWebSocketContext context)
106105
{
107-
Trace.TraceInformation("client disconnected");
106+
Trace.TraceInformation("SwitchPanel, client disconnected");
108107
Connections--;
109108
return Task.CompletedTask;
110109
}
@@ -123,9 +122,8 @@ public async Task BroadcastEvent(SwitchPanelEvent jsEvent)
123122
}
124123
catch (Exception e)
125124
{
126-
string error = e.ToString();
127-
Console.WriteLine("Json serialize error:" + error);
128-
throw;
125+
Trace.TraceInformation("SwitchPanel, Json serialize error:");
126+
Trace.WriteLine(e);
129127
}
130128
}
131129
}

0 commit comments

Comments
 (0)