Lock and Unlock fixed: in case of an error the train is stopped and put on manual mode.

master
Steffen Pohle 2 years ago
parent b370dbf930
commit d6c4907557

@ -851,11 +851,11 @@ int Locomotives::Loco_SearchAndLock(Locomotive *loco) {
} }
else strncpy (loco->blocknext, way.substr(pos+3,string::npos).c_str(), REFERENCENAME_LEN); else strncpy (loco->blocknext, way.substr(pos+3,string::npos).c_str(), REFERENCENAME_LEN);
strncpy (loco->auto_way, way.c_str(), WAYDATA_LEN); strncpy (loco->auto_way, way.c_str(), WAYDATA_LEN);
if (server->railways.LockWay(way, loco->name) == 1) { if (server->railways.LockWay(way, loco->name, 1, 0) == 1) {
loco->auto_data = -1; loco->auto_data = -1;
return 1; return 1;
} }
server->railways.UnLockWay(way, loco->name); server->railways.LockWay(way, loco->name, 0, RAILWAYS_LOCKF_KEEPSTART);
} }
} }
} }
@ -876,11 +876,20 @@ int Locomotives::Loco_SearchAndLock(Locomotive *loco) {
} }
else strncpy (loco->blocknext, way.substr(pos+3,string::npos).c_str(), REFERENCENAME_LEN); else strncpy (loco->blocknext, way.substr(pos+3,string::npos).c_str(), REFERENCENAME_LEN);
strncpy (loco->auto_way, way.c_str(), WAYDATA_LEN); strncpy (loco->auto_way, way.c_str(), WAYDATA_LEN);
if (server->railways.LockWay(way, loco->name) == 1) { if (server->railways.LockWay(way, loco->name, 1, 0) == 1) {
loco->auto_data = -1; loco->auto_data = -1;
return 1; return 1;
} }
server->railways.UnLockWay(way, loco->name); if (server->railways.LockWay(way, loco->name, 0, RAILWAYS_LOCKF_KEEPSTART) == 0) {
SetSpeed(loco->name, 0);
SetModeMan(loco->name);
server->LocomotiveSetMan(loco->name);
server->LocomotiveSetSpeed(loco->name, 0);
debug (DEBUG_ERROR, "*** ERROR *** %s:%d locomotive %s error occured. Could not undo the locking of the way.",
__FILE__, __LINE__, loco->name);
return 0;
}
} }
} }
@ -980,15 +989,19 @@ int Locomotives::Loco_OnRoute(Locomotive *loco) {
// //
if (Loco_SearchAndLock(loco) == 1) { if (Loco_SearchAndLock(loco) == 1) {
loco->auto_onroute = LOCO_OR_ENTERBLOCKNEXT; loco->auto_onroute = LOCO_OR_ENTERBLOCKNEXT;
debug (0, "Locomotives::Loco_OnRoute Found Way Prepare '%s'\n", loco->name); debug (0, "Locomotives::Loco_OnRoute Found Way Prepare '%s'", loco->name);
SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vslow : loco->vslow); SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vslow : loco->vslow);
timer_start(&loco->auto_timenext); timer_start(&loco->auto_timenext);
} }
else { else if (loco->flags && LOCO_F_AUTO) {
loco->auto_onroute = LOCO_OR_ENTERBLOCKSTOP; loco->auto_onroute = LOCO_OR_ENTERBLOCKSTOP;
debug (0, "Locomotives::Loco_OnRoute Slow Down '%s'\n", loco->name); debug (0, "Locomotives::Loco_OnRoute Slow Down '%s'", loco->name);
SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vslow : loco->vslow); SetSpeed(loco->name, loco->flags & LOCO_F_REVERSE ? -loco->vslow : loco->vslow);
} }
else {
debug (0, "Locomotives::Loco_OnRoute '%s' some error occured.", loco->name);
SetSpeed(loco->name, 0);
}
return 1; return 1;
} }
@ -1027,7 +1040,7 @@ int Locomotives::Loco_BlockEnterStop(Locomotive *loco) {
SetSpeed(loco->name, 0); SetSpeed(loco->name, 0);
loco->auto_onroute = LOCO_OR_STOPWAIT; loco->auto_onroute = LOCO_OR_STOPWAIT;
server->railways.UnLockWay(loco->auto_wayold, loco->name); server->railways.LockWay(loco->auto_wayold, loco->name, 0, 0);
server->blocks.SetLockedby(loco->blockprev+2, loco->name, 0); server->blocks.SetLockedby(loco->blockprev+2, loco->name, 0);
loco->auto_wayold[0] = 0; loco->auto_wayold[0] = 0;
timer_start(&loco->auto_timenext); timer_start(&loco->auto_timenext);
@ -1069,7 +1082,7 @@ int Locomotives::Loco_BlockEnterNext(Locomotive *loco) {
debug (0, "Locomotives::Loco_BlockEnterNext could not prepare way in time '%s'\n", loco->name); debug (0, "Locomotives::Loco_BlockEnterNext could not prepare way in time '%s'\n", loco->name);
SetSpeed(loco->name, 0); SetSpeed(loco->name, 0);
loco->auto_onroute = LOCO_OR_STOPWAIT; loco->auto_onroute = LOCO_OR_STOPWAIT;
server->railways.UnLockWay(loco->auto_wayold, loco->name); server->railways.LockWay(loco->auto_wayold, loco->name, 0, 0);
server->blocks.SetLockedby(loco->blockprev+2, loco->name, 0); server->blocks.SetLockedby(loco->blockprev+2, loco->name, 0);
loco->auto_wayold[0] = 0; loco->auto_wayold[0] = 0;
timer_start(&loco->auto_timenext); timer_start(&loco->auto_timenext);
@ -1079,7 +1092,7 @@ int Locomotives::Loco_BlockEnterNext(Locomotive *loco) {
else { else {
debug (0, "* Locomotives::Loco_BlockEnterNext endblock reached %s", loco->name); debug (0, "* Locomotives::Loco_BlockEnterNext endblock reached %s", loco->name);
server->railways.UnLockWay(loco->auto_wayold, loco->name); server->railways.LockWay(loco->auto_wayold, loco->name, 0, 0);
server->blocks.SetLockedby(loco->blockprev+2, loco->name, 0); server->blocks.SetLockedby(loco->blockprev+2, loco->name, 0);
loco->auto_wayold[0] = 0; loco->auto_wayold[0] = 0;

@ -965,8 +965,10 @@ int Railways::FindRandomWay(string blockstart, string lockedfor, string *next) {
* try to lock or unlock the way for the loco(lockedby) * try to lock or unlock the way for the loco(lockedby)
* this lock will only go from one to the next block. * this lock will only go from one to the next block.
* Will also do the check for long trains and split blocks. * Will also do the check for long trains and split blocks.
*
* flags: RAILWAYS_LOCKF_* see definition
*/ */
int Railways::LockWay (string way, string lockedby, int lockonoff) { int Railways::LockWay (string way, string lockedby, int lockonoff, int flags) {
int res = 0; int res = 0;
size_t pos1, pos2; size_t pos1, pos2;
size_t curwaypos; size_t curwaypos;
@ -1115,8 +1117,10 @@ int Railways::LockWay (string way, string lockedby, int lockonoff) {
return 0; return 0;
} }
//
// lock start and endpoint... unlock only start // lock start and endpoint... unlock only start
if (r->type == RAILWAY_BLOCK) { if (r->type == RAILWAY_BLOCK) {
// endblock
if ((strcmp(endblock.c_str()+2,r->name) == 0) || (endblock2.length() > 0 && (endblock2.compare(r->name) == 0))) { if ((strcmp(endblock.c_str()+2,r->name) == 0) || (endblock2.length() > 0 && (endblock2.compare(r->name) == 0))) {
UnLock(); UnLock();
if (lockonoff) { if (lockonoff) {
@ -1125,11 +1129,12 @@ int Railways::LockWay (string way, string lockedby, int lockonoff) {
} }
Lock(); Lock();
} }
// startblock
else if ((strcmp(startblock.c_str()+2, r->name) == 0) || (startblock2.length() > 0 && (startblock2.compare(r->name) == 0))) { else if ((strcmp(startblock.c_str()+2, r->name) == 0) || (startblock2.length() > 0 && (startblock2.compare(r->name) == 0))) {
UnLock(); UnLock();
server->blocks.SetLockedby(r->name, lockedby, lockonoff); if ((!flags & RAILWAYS_LOCKF_KEEPSTART) || lockonoff) server->blocks.SetLockedby(r->name, lockedby, lockonoff);
if (lockonoff) strncpy (r->lockedby, lockedby.c_str(), REFERENCENAME_LEN); if (lockonoff) strncpy (r->lockedby, lockedby.c_str(), REFERENCENAME_LEN);
else r->lockedby[0] = 0; else if (!flags & RAILWAYS_LOCKF_KEEPSTART) r->lockedby[0] = 0;
Lock(); Lock();
} }
else { else {
@ -1210,13 +1215,12 @@ int Railways::LockWay (string way, string lockedby, int lockonoff) {
else if (r->type == RAILWAY_CONNECTOR) { else if (r->type == RAILWAY_CONNECTOR) {
int found = 0; int found = 0;
int x, y, cnt; int x = -1, y = -1, cnt = 0;
printf ("%s:%d connector found Reference:'%s'\n", __FILE__, __LINE__, r->name);
x = -1; debug (0, "LockWay connector found Reference:'%s'", r->name);
y = -1;
while (found == 0 && _FindReference(&x, &y, r->name, (cnt++)) == 1) { while (found == 0 && _FindReference(&x, &y, r->name, (cnt++)) == 1) {
if (pos.x != x || pos.y != y) { if (pos.x != x || pos.y != y) {
printf ("%s:%d found %d,%d\n", __FILE__, __LINE__, x, y); debug (0, "%s:%d found %d,%d", __FILE__, __LINE__, x, y);
pos.oldx = pos.x; pos.oldx = pos.x;
pos.oldy = pos.y; pos.oldy = pos.y;
pos.oldenterfrom = pos.enterfrom; pos.oldenterfrom = pos.enterfrom;

@ -25,6 +25,7 @@ enum {
#define RAILWAYS_MAX_WIDTH 500 #define RAILWAYS_MAX_WIDTH 500
#define RAILWAYS_MAX_HEIGHT 500 #define RAILWAYS_MAX_HEIGHT 500
#define RAILWAYS_LOCKF_KEEPSTART 0x0001 // keep start
// direktion // direktion
// //
@ -132,9 +133,7 @@ class Railways {
int FindWay(string blockstart, string blockend, string lockedfor, string *next); int FindWay(string blockstart, string blockend, string lockedfor, string *next);
int FindWayCheckIfNoDoubleTurnouts (string *next); int FindWayCheckIfNoDoubleTurnouts (string *next);
int FindRandomWay(string blockstart, string lockedfor, string *next); int FindRandomWay(string blockstart, string lockedfor, string *next);
int LockWay (string way, string lockedby, int lockonoff); int LockWay (string way, string lockedby, int lockonoff, int flags);
int LockWay (string way, string lockedby) { return LockWay(way, lockedby, 1); };
int UnLockWay (string way, string lockedby) { return LockWay(way, lockedby, 0); };
int SetLockedby (int x, int y, string name, int locked); int SetLockedby (int x, int y, string name, int locked);
struct s_findway_data NextPos(struct s_findway_data pos, int dirtype); struct s_findway_data NextPos(struct s_findway_data pos, int dirtype);

Loading…
Cancel
Save