fixed AUTO->MAN stop mode is working on trains.

master
Steffen Pohle 4 years ago
parent 0a446a26df
commit 67c73836f8

@ -1,3 +1,9 @@
2022-04-17:
- added "-simulation" parmeter for debugging purpose.
needed to simulate turnout manipulation
- fixed: locomotive AUTO->MAN mode is working if searching for a new way.
2022-02-13:
- Interfaces are now virtual classes.

@ -419,7 +419,6 @@ void InterfaceZ21::SetTurnout(Turnout *t, int activate, int outputactive) {
debug (DEBUG_INFO | DEBUG_IFACE, "InterfaceZ21 (%s) SetTurnout Addr:%d Acitve:%d Output:%d", name,
t->addr, activate, outputactive);
//
//
if (outputactive == 1 && timer_get(&turnouttimeout) < 100) {

@ -749,7 +749,7 @@ int Locomotives::Loop() {
// only in automate do anything alone
//
if (loco->blockassign[0] == 0) {
debug (0, "%s:%d Locomotive not assigned to any block. Set Mode to Man", __FILE__, __LINE__);
debug (0, "%s:%d Locomotive [%s] not assigned to any block. Set Mode to Man", __FILE__, __LINE__, loco->name);
SetModeMan(loco->name);
continue;
}
@ -768,6 +768,13 @@ int Locomotives::Loop() {
}
else if (loco->auto_onroute == LOCO_OR_SEARCH) {
//
// check if the loco mode is set to autostop
if (loco->flags & LOCO_F_AUTOSTOP) {
SetModeMan(loco->name);
continue;
}
//
// try to find and prepare(lock) a new way.
// nothing found check if we can reverse direction, this will be done only
@ -893,14 +900,20 @@ int Locomotives::Loop() {
strncpy (loco->auto_wayold, loco->auto_way, WAYDATA_LEN);
loco->auto_way[0] = 0;
loco->blocknext[0] = 0;
if (strncmp(loco->blockassign, loco->blockdest, REFERENCENAME_LEN) == 0) {
printf ("%s:%d LOCO_OR_ONTHEWAY enter assign == dest stop\n", __FILE__, __LINE__);
//
// if destination reached or AUTO-MAN mode: stop train.
if ((strncmp(loco->blockassign, loco->blockdest, REFERENCENAME_LEN) == 0)
|| (loco->flags & LOCO_F_AUTOSTOP)) {
printf ("%s:%d LOCO_OR_ONTHEWAY enter assign == dest stop train\n", __FILE__, __LINE__);
loco->blockdest[0] = 0;
loco->auto_onroute = LOCO_OR_ENTERBLOCKSTOP;
SetSpeed(loco->name, reverse * loco->vslow);
}
//
// if not try to find next block.
else {
// try to find new way
printf ("%s:%d LOCO_OR_ONTHEWAY try to find new way\n", __FILE__, __LINE__);
if (loco->blockdest[0] == 0) {
if ((loco->flags & LOCO_F_RANDOM) && ((loco->flags & LOCO_F_CARGO) || !(server->blocks.GetFlags(block) & BLOCK_F_STATION)))

@ -18,8 +18,11 @@ int running = 1;
Server *server = NULL;
Network *network = NULL;
int simulation = 0;
int main (int argc, char **argv) {
int i;
//
// setup signals
//
@ -47,6 +50,14 @@ int main (int argc, char **argv) {
debug (0, "* *");
debug (0, "***************************************************");
debug (0, "");
for (i = 1; i < argc; i++) {
if (strcmp (argv[i], "-simulation") == 0) {
simulation = 1;
debug (0, "WARINING SIMULATION MODE ACTIVE. ALL COMMANDS WILL BE SEND");
debug (0, "TO THE INTERFACES. TURNOUT AND SENSORDATA WILL BE FORCED.");
sleep (5);
}
}
//////////////////////////////////////////////////////////////////////
//

@ -27,7 +27,7 @@ extern int running;
extern Server *server;
extern Network *network;
extern int simulation;
//
// to measure the time in ms (used for debugging)

@ -74,6 +74,17 @@ int Server::TurnoutSet(string name, int active) {
}
}
if (simulation) {
int flags;
debug (0, "%s:%d WARNING SIMULATION MODE", __FILE__, __LINE__);
flags = turnouts.GetFlags(turnouts.GetIdx(name));
if (flags & TURNOUT_F_TURNOUT) flags &= ~TURNOUT_F_TURNOUT;
else flags |= TURNOUT_F_TURNOUT;
turnouts.SetFlags(turnouts.GetIdx(name), flags);
turnouts.Set(name, active);
}
if (locked == 0) return turnouts.Set(name, active);
else {
debug (0, "%s:%d SetJSONTurnout Element %s is locked by %s", __FILE__, __LINE__, name.c_str(), lockedby.c_str());

@ -337,3 +337,34 @@ int Turnouts::GetFlags(int idx) {
};
void Turnouts::SetFlags(int idx, int flags) {
JSONParse jp;
Lock();
if (idx <= max && idx >= 0) {
turnouts[idx].flags = flags;
jp.Clear();
jp.AddObject("turnout", _GetJSON(idx));
if (network) network->ChangeListPushToAll(jp.ToString());
}
UnLock();
};
int Turnouts::GetIdx(string name) {
int i;
int res = -1;
//
Lock();
for (i = 0; i < max; i++) if (turnouts[i].name[0] != 0) {
if (name.compare(turnouts[i].name) == 0) {
res = i;
break;
}
}
UnLock();
return res;
}

@ -55,7 +55,9 @@ class Turnouts {
Turnout GetTurnoutFromJSON(JSONParse *j);
string GetName(int idx);
int GetIdx(string name);
int GetFlags(int idx);
void SetFlags(int idx, int flags);
void SetFromBus(string name, int addr, int active);
};

Loading…
Cancel
Save