auto mode optimized..

origin
steffen 5 years ago
parent 3970afd8c8
commit 0585a8c367

@ -569,7 +569,7 @@ int Locomotives::Loop() {
// //
// only in automate do anything alone // only in automate do anything alone
// //
if (loco->blockassign[0] == 0 || loco->blockdest[0] == 0) continue; if (loco->blockassign[0] == 0) continue;
if (loco->auto_onroute == LOCO_OR_NOTHING) { if (loco->auto_onroute == LOCO_OR_NOTHING) {
timer_start(&loco->auto_timenext); timer_start(&loco->auto_timenext);
@ -577,7 +577,7 @@ int Locomotives::Loop() {
} }
else if (loco->auto_onroute == LOCO_OR_SEARCH) { else if (loco->auto_onroute == LOCO_OR_SEARCH) {
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > 1000) { if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > LOCO_TO_TRYAGAIN) {
if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) { if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) {
size_t pos; size_t pos;
@ -596,20 +596,17 @@ int Locomotives::Loop() {
} }
else if (loco->auto_onroute == LOCO_OR_PREPARE) { else if (loco->auto_onroute == LOCO_OR_PREPARE) {
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > 1000) { if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > LOCO_TO_TURNOUT) {
if (AutoCheckWaySingleStep(loco->auto_way, loco->name, &loco->auto_data) == 1) if (AutoCheckWaySingleStep(loco->auto_way, loco->name, &loco->auto_data) == 1) {
if (loco->flags & LOCO_F_CARGO) SetSpeed(loco->name, loco->vmid);
else SetSpeed(loco->name, loco->vfast);
loco->auto_onroute = LOCO_OR_ONTHEWAY; loco->auto_onroute = LOCO_OR_ONTHEWAY;
else timer_start(&loco->auto_timenext);
} }
else timer_start(&loco->auto_timenext);
} }
else if (loco->auto_onroute == LOCO_OR_ONTHEWAY) {
if (loco->flags & LOCO_F_CARGO) SetSpeed(loco->name, loco->vmid);
else SetSpeed(loco->name, loco->vfast);
loco->auto_onroute = LOCO_OR_ONTHEWAYPREPARE;
} }
else if (loco->auto_onroute == LOCO_OR_ONTHEWAYPREPARE) { else if (loco->auto_onroute == LOCO_OR_ONTHEWAY) {
// check enter block // check enter block
block = loco->blocknext+2; block = loco->blocknext+2;
@ -617,20 +614,38 @@ int Locomotives::Loop() {
sensor = server->blocks.GetSensorMinus(block); sensor = server->blocks.GetSensorMinus(block);
else else
sensor = server->blocks.GetSensorPlus(block); sensor = server->blocks.GetSensorPlus(block);
if (server->sensors.GetActive(sensor) == 1) {
SetSpeed(loco->name, loco->vslow);
loco->auto_onroute = LOCO_OR_ENTERBLOCK;
if (loco->blockassign != 0) { if (server->sensors.GetActive(sensor) == 1) { // entering block?
debug (0, "* Locomotive '%s' Enter Block '%s'", loco->name, loco->blocknext);
// unlock old assigned block
if (loco->blockassign[0] != 0) {
server->blocks.SetLockedby((string)(loco->blockassign+2), loco->name, 0); server->blocks.SetLockedby((string)(loco->blockassign+2), loco->name, 0);
} }
// assignment <-- next
// check if we need to clear dest
strncpy (loco->blockprev, loco->blockassign, REFERENCENAME_LEN);
strncpy (loco->blockassign, loco->blocknext, REFERENCENAME_LEN);
loco->blocknext[0] = 0;
if (strncmp(loco->blockassign, loco->blockdest, REFERENCENAME_LEN) == 0) {
loco->blockdest[0] = 0;
}
// slow down
SetSpeed(loco->name, loco->vslow);
jp.Clear();
jp.AddObject("locomotive",_GetJSON(lnum));
if(network) network->ChangeListPushToAll(jp.ToString());
loco->auto_onroute = LOCO_OR_ENTERBLOCK;
} }
} }
else if (loco->auto_onroute == LOCO_OR_ENTERBLOCK) { else if (loco->auto_onroute == LOCO_OR_ENTERBLOCK) {
// check enter block // check enter block
block = loco->blocknext+2; block = loco->blockassign+2;
if (loco->blockassign[0] == '-')
if (loco->blocknext[0] == '-')
sensor = server->blocks.GetSensorPlus(block); sensor = server->blocks.GetSensorPlus(block);
else else
sensor = server->blocks.GetSensorMinus(block); sensor = server->blocks.GetSensorMinus(block);
@ -640,21 +655,16 @@ int Locomotives::Loop() {
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_way, loco->name); server->railways.UnLockWay(loco->auto_way, loco->name);
strncpy (loco->blockassign, loco->blocknext, REFERENCENAME_LEN);
if (strncmp (loco->blockassign, loco->blockdest, REFERENCENAME_LEN) == 0) {
loco->blockdest[0] = 0;
jp.Clear(); jp.Clear();
jp.AddObject("locomotive",_GetJSON(lnum)); jp.AddObject("locomotive",_GetJSON(lnum));
if(network) network->ChangeListPushToAll(jp.ToString()); if(network) network->ChangeListPushToAll(jp.ToString());
}
loco->blocknext[0] = 0;
timer_start(&loco->auto_timenext); timer_start(&loco->auto_timenext);
} }
} }
else if (loco->auto_onroute == LOCO_OR_STOPWAIT) { else if (loco->auto_onroute == LOCO_OR_STOPWAIT) {
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > 5000) { if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > 5000) {
loco->auto_onroute = LOCO_OR_SEARCH; if (loco->blockdest[0] != 0) loco->auto_onroute = LOCO_OR_SEARCH;
else loco->auto_onroute = LOCO_OR_NOTHING;
} }
} }
} }

@ -13,6 +13,9 @@
#define LOCO_F_RANDOM 0x0200 #define LOCO_F_RANDOM 0x0200
#define LOCO_F_AUTOSTOP 0x0400 #define LOCO_F_AUTOSTOP 0x0400
#define LOCO_TO_TURNOUT (50+TURNOUT_DEFAULT_ACTIVETIMEOUT)
#define LOCO_TO_TRYAGAIN (1000)
#define WAYDATA_LEN (16*REFERENCENAME_LEN) #define WAYDATA_LEN (16*REFERENCENAME_LEN)
enum { enum {
@ -30,7 +33,6 @@ enum {
LOCO_OR_ONTHEWAY, // locomotive is on the way // maybe prepare next block? LOCO_OR_ONTHEWAY, // locomotive is on the way // maybe prepare next block?
// ASSIGN -> PREV, NEXT -> ASSIGN, NEXT <- (empty) // ASSIGN -> PREV, NEXT -> ASSIGN, NEXT <- (empty)
// propabely searching next block (if DEST is set)? // propabely searching next block (if DEST is set)?
LOCO_OR_ONTHEWAYPREPARE, // prepare way as long as on the way
LOCO_OR_ENTERBLOCK, // got new block ready? LOCO_OR_ENTERBLOCK, // got new block ready?
// if NEXT is empty and way not AutoPrepareWay not finished... slow down // if NEXT is empty and way not AutoPrepareWay not finished... slow down
LOCO_OR_STOPWAIT // stopping LOCO_OR_STOPWAIT // stopping

@ -404,8 +404,6 @@ int Railways::_FindReference(int *x, int *y, string name) {
*y = 0; *y = 0;
} }
printf ("%s:%d find reference (%d,%d,%s)\n", __FILE__, __LINE__, *x, *y, name.c_str());
for (; found == 0 && *y < height; (*y)++) { for (; found == 0 && *y < height; (*y)++) {
if (*x >= width) *x = 0; if (*x >= width) *x = 0;
else (*x)++; else (*x)++;
@ -419,8 +417,6 @@ int Railways::_FindReference(int *x, int *y, string name) {
if (found) break; if (found) break;
} }
printf ("%s:%d found (%d,%d)\n", __FILE__, __LINE__, *x, *y);
if (*x < width && *y < height) return 1; if (*x < width && *y < height) return 1;
else return 0; else return 0;
}; };

@ -574,7 +574,7 @@ function locolist_show() {
// //
// clear list // clear list
ul.innerHTML = "";
// //
// append all locomotives // append all locomotives

Loading…
Cancel
Save