Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Benjamin Ries committed Apr 14, 2021
1 parent cdb8d48 commit 98973b3
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 74 deletions.
2 changes: 1 addition & 1 deletion EcosApp/railessentials.min.js

Large diffs are not rendered by default.

34 changes: 0 additions & 34 deletions EcosApp/src/occ.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Occ {

this.__divRootClass = "locomotiveInfo";
this.__divFromClass = "locomotiveInfoFrom";
this.__divNextClass = "locomotiveInfoNext";
this.__divFinalClass = "locomotiveInfoFinal";
this.__dataOidName = "locoid";
this.__divBlockedClass = "isblocked";
Expand Down Expand Up @@ -66,10 +65,8 @@ class Occ {
const self = this;
return {
"root": "locomotiveInfo" + objectId,
"rootNext": "locomotiveInfoNext" + objectId,
"rootFinal": "locomotiveInfoFinal" + objectId,
"image": "locomotiveInfoImage" + objectId,
"imageNext": "locomotiveInfoImageNext" + objectId,
"imageFinal": "locomotiveInfoImageFinal" + objectId
};
}
Expand Down Expand Up @@ -164,24 +161,6 @@ class Occ {
.addClass("enterSide");
locEnterSideCtrl.appendTo(locomotiveInfo);

//
// next locomotive info
//
let locomotiveInfoNext = locomotiveInfo.clone();
locomotiveInfoNext.attr("id", ids.rootNext);
locomotiveInfoNext.removeClass(this.__divFromClass);
locomotiveInfoNext.addClass(this.__divNextClass);
const locImg2 = locomotiveInfoNext.find('img');
locImg2.attr("id", ids.imageNext);
locomotiveInfoNext.dblclick(function () {
self.__trigger("resetAssignment",
{
mode: 'resetAssignment',
submode: 'next',
oid: locData.objectId
});
});

//
// final locomotive info
//
Expand Down Expand Up @@ -338,7 +317,6 @@ class Occ {
} else if (err === "resetAssignment") {

locomotiveInfo.hide();
locomotiveInfoNext.hide();
locomotiveInfoFinal.hide();

self.__trigger("resetAssignment",
Expand Down Expand Up @@ -559,7 +537,6 @@ class Occ {
const bodyCtrl = $('body');
locControl.appendTo(bodyCtrl);
locomotiveInfo.appendTo(bodyCtrl);
locomotiveInfoNext.appendTo(bodyCtrl);
locomotiveInfoFinal.appendTo(bodyCtrl);

self.__updateStateVisualization(locData.objectId);
Expand Down Expand Up @@ -929,7 +906,6 @@ class Occ {
for (i = 0; i < iMax; ++i) {
const occDataItem = occData[i];
// FinalBlock
// NextBlock
// FromBlock
// Oid
// EnterSide
Expand All @@ -941,11 +917,9 @@ class Occ {

const ids = self.__generateLocomotiveInfoIdentifiers(occDataItem.Oid);
const infoInstance = $('div#' + ids.root);
const infoInstanceNext = $('div#' + ids.rootNext);
const infoInstanceFinal = $('div#' + ids.rootFinal);

const fromBlockId = occDataItem.FromBlock;
const nextBlockId = occDataItem.NextBlock;
const finalBlockId = occDataItem.FinalBlock;

if (typeof fromBlockId === "undefined" || fromBlockId == null || fromBlockId.length === 0) {
Expand All @@ -956,14 +930,6 @@ class Occ {
self.__applyInfoToBlock(infoInstance, fromBlock, occDataItem);
}

if (typeof nextBlockId === "undefined" || nextBlockId == null || nextBlockId.length === 0) {
infoInstanceNext.hide();
} else {
const nextBlock = self.__getBlock(nextBlockId);
infoInstanceNext.show();
self.__applyInfoToBlock(infoInstanceNext, nextBlock);
}

if (typeof finalBlockId === "undefined" || finalBlockId == null || finalBlockId.length === 0) {
infoInstanceFinal.hide();
} else {
Expand Down
12 changes: 0 additions & 12 deletions Workspaces/Basement/occ.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,35 @@
{
"Oid": 1010,
"FromBlock": "B01",
"NextBlock": "",
"FinalBlock": "",
"RouteToNext": "",
"RouteToFinal": "",
"NextEntered": false,
"FinalEntered": false,
"ReachedTime": "2021-04-06T21:20:14.7038655+02:00",
"SecondsToWait": 10
},
{
"Oid": 1002,
"FromBlock": "B04",
"NextBlock": "",
"FinalBlock": "",
"RouteToNext": "",
"RouteToFinal": "",
"NextEntered": false,
"FinalEntered": false,
"ReachedTime": "2021-04-06T21:20:16.791565+02:00",
"SecondsToWait": 10
},
{
"Oid": 1009,
"FromBlock": "B15",
"NextBlock": "",
"FinalBlock": "B09",
"RouteToNext": "",
"RouteToFinal": "B15[+]_B09[+]",
"NextEntered": false,
"FinalEntered": false,
"ReachedTime": "2021-04-07T21:08:23.6768015+02:00",
"SecondsToWait": 10
},
{
"Oid": 1012,
"FromBlock": "B03",
"NextBlock": "",
"FinalBlock": "",
"RouteToNext": null,
"RouteToFinal": null,
"NextEntered": false,
"FinalEntered": false,
"ReachedTime": "0001-01-01T00:00:00",
"SecondsToWait": 0
Expand Down
62 changes: 52 additions & 10 deletions railessentials/AutoMode/AutoMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ await Task.Run(() =>
{
var noOfWaitingTasks = iMax - listOfFinishedTasks.Count;
var allTasksStopped = iMax == 0;
for (var j = 0; j < iMax; ++j)
{
var task = _autoModeTasks[j];
Expand All @@ -232,7 +232,7 @@ await Task.Run(() =>
}
var m = $"Waiting for {noOfWaitingTasks} locomotives...";
if(!m.Equals(previousMessage, StringComparison.OrdinalIgnoreCase))
if (!m.Equals(previousMessage, StringComparison.OrdinalIgnoreCase))
{
_ctx?.Logger?.Log.Info(m);
SendAutoModeStateToClients(m);
Expand Down Expand Up @@ -300,7 +300,6 @@ public void ResetRouteFor(int locOid)
{
if (itOccBlock.Oid != locOid) continue;
routeFinalName = itOccBlock.RouteToFinal;
routeNextName = itOccBlock.RouteToNext;
CleanOccBlock(itOccBlock);
break;
}
Expand Down Expand Up @@ -341,7 +340,8 @@ public void SendAutoModeStateToClients(string additionalMessage = null)
["data"] = new JObject
{
["command"] = "state",
["state"] = new JObject {
["state"] = new JObject
{
["started"] = IsStarted(),
["stopping"] = IsStopping(),
["stopped"] = IsStopped(),
Expand Down Expand Up @@ -392,15 +392,38 @@ private NextRouteInformation CheckForRoutesAndAssign()
{
foreach (var itOccBlock in _metadata.Occ.Blocks)
{
Route.Route nextRoute = null;
var locomotiveObjectId = -1;

//
// has already a destination
// and is traveling
//
if (!string.IsNullOrEmpty(itOccBlock.FinalBlock)
&& itOccBlock.IsTraveling)
continue;

//
// has already a destination
if (!string.IsNullOrEmpty(itOccBlock.FinalBlock)) continue;
// but it is not traveling
//
if (!string.IsNullOrEmpty(itOccBlock.FinalBlock)
&& !itOccBlock.IsTraveling)
{
// find route for traveling
nextRoute = GetUserNextRoute(itOccBlock, out locomotiveObjectId);
}

//
// the most interesting call is `GetNextRoute(..)` which
// is responsible for selecting the best next journey path
// if not already set by user decision
//
var nextRoute = GetNextRoute(itOccBlock, out var locomotiveObjectId);
if (nextRoute == null) continue;
if (nextRoute == null)
{
nextRoute = GetNextRoute(itOccBlock, out locomotiveObjectId);
if (nextRoute == null) continue;
}

//
// query feedback sensors for the route
Expand All @@ -424,6 +447,11 @@ private NextRouteInformation CheckForRoutesAndAssign()
itOccBlock.FinalBlock = targetBlock.identifier;
itOccBlock.RouteToFinal = nextRoute.Name;

// used to signal that the occ is started
// relevant if the user has set any route
// by drag & drop of locomotives between blocks
itOccBlock.IsTraveling = true;

SaveOccAndPromote();
SaveRoutesAndPromote();

Expand Down Expand Up @@ -688,10 +716,7 @@ public void CleanOcc()
internal static OccBlock CleanOccBlock(OccBlock block)
{
block.FinalBlock = string.Empty;
block.NextBlock = string.Empty;
block.RouteToFinal = string.Empty;
block.RouteToNext = string.Empty;
block.NextEntered = false;
block.FinalEntered = false;
return block;
}
Expand Down Expand Up @@ -722,6 +747,23 @@ Feedbacks.Data fbData
return false;
}

public Route.Route GetUserNextRoute(
OccBlock occBlock,
out int locomotiveObjectId)
{
locomotiveObjectId = 0;

var occFromBlock = occBlock.FromBlock;
if (string.IsNullOrEmpty(occFromBlock)) return null;

var occFromFinal = occBlock.FinalBlock;
if (string.IsNullOrEmpty(occFromFinal)) return null;

// TODO

return null;
}

public Route.Route GetNextRoute(
OccBlock occBlock,
out int locomotiveObjectId)
Expand Down
3 changes: 0 additions & 3 deletions railessentials/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,8 @@ public bool LoadOccData(string pathToOccmodel, bool resetToInitState = false)
foreach (var it in Occ.Blocks)
{
if (it == null) continue;
it.NextBlock = string.Empty;
it.FinalBlock = string.Empty;
it.RouteToNext = string.Empty;
it.RouteToFinal = string.Empty;
it.NextEntered = false;
it.FinalEntered = false;
}
Save(SaveModelType.OccData);
Expand Down
8 changes: 1 addition & 7 deletions railessentials/Occ/OccBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ public class OccBlock
{
public int Oid { get; set; }
public string FromBlock { get; set; } = string.Empty;
public string NextBlock { get; set; } = string.Empty;
public string FinalBlock { get; set; } = string.Empty;

public string RouteToNext { get; set; }
public string RouteToFinal { get; set; }

/// <summary>
/// true:=when the fbEnter is reached
/// </summary>
public bool NextEntered { get; set; }
public bool IsTraveling { get; set; } = false;

/// <summary>
/// true:=when the fbEnter is reached
Expand Down
7 changes: 1 addition & 6 deletions railessentials/Occ/OccData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ public bool ResetAssignment(int oid, string submode = "all")
{
if (it == null) continue;
if (it.Oid != oid) continue;
if (submode.Equals("next", StringComparison.OrdinalIgnoreCase))
{
it.NextBlock = string.Empty;
it.NextEntered = false;
}
else if (submode.Equals("final", StringComparison.OrdinalIgnoreCase))
if (submode.Equals("final", StringComparison.OrdinalIgnoreCase))
{
it.FinalBlock = string.Empty;
it.FinalEntered = false;
Expand Down
1 change: 0 additions & 1 deletion railessentials/Route/RouterListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public static RouteList FilterNotOccupiedOrLocked(this RouteList routeList, Occ.
{
blockIsOccupied =
itt.FromBlock.Equals(fromBlock, StringComparison.OrdinalIgnoreCase)
|| itt.NextBlock.Equals(fromBlock, StringComparison.OrdinalIgnoreCase)
|| itt.FinalBlock.Equals(fromBlock, StringComparison.OrdinalIgnoreCase);
if (blockIsOccupied) break;
}
Expand Down

0 comments on commit 98973b3

Please sign in to comment.