|
|
|
|
@ -401,7 +401,7 @@ int Locomotives::Reset(string name) {
|
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
|
debug (0, "Locomotives::Reset (Name:%s)", name.c_str());
|
|
|
|
|
locomotives[i].flags &= ~(LOCO_F_AUTO | LOCO_F_AUTOSTOP | LOCO_F_RANDOM);
|
|
|
|
|
locomotives[i].flags &= ~(LOCO_F_AUTO | LOCO_F_AUTOSTOP | LOCO_F_AUTORANDOM | LOCO_F_AUTOSHED);
|
|
|
|
|
locomotives[i].blockassign[0] = 0;
|
|
|
|
|
locomotives[i].blockdest[0] = 0;
|
|
|
|
|
locomotives[i].blockprev[0] = 0;
|
|
|
|
|
@ -435,7 +435,7 @@ int Locomotives::SetModeMan(string name) {
|
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
|
debug (0, "Locomotives::SetMan (Name:%s)\n", name.c_str());
|
|
|
|
|
locomotives[i].flags &= ~(LOCO_F_AUTO | LOCO_F_AUTOSTOP | LOCO_F_RANDOM);
|
|
|
|
|
locomotives[i].flags &= ~(LOCO_F_AUTO | LOCO_F_AUTOSTOP | LOCO_F_AUTORANDOM | LOCO_F_AUTOSHED);
|
|
|
|
|
locomotives[i].auto_onroute = 0;
|
|
|
|
|
locomotives[i].auto_way[0] = 0;
|
|
|
|
|
locomotives[i].auto_wayold[0] = 0;
|
|
|
|
|
@ -462,7 +462,8 @@ int Locomotives::SetModeAutoMan(string name) {
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0 && (locomotives[i].flags & LOCO_F_AUTO)) {
|
|
|
|
|
debug (0, "Locomotives::SetAutoMan (Name:%s)\n", name.c_str());
|
|
|
|
|
locomotives[i].flags |= LOCO_F_AUTOSTOP;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_RANDOM;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_AUTORANDOM;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_AUTOSHED;
|
|
|
|
|
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(i));
|
|
|
|
|
@ -484,7 +485,8 @@ int Locomotives::SetModeAuto(string name) {
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
|
debug (0, "Locomotives::SetAuto (Name:%s)\n", name.c_str());
|
|
|
|
|
locomotives[i].flags |= LOCO_F_AUTO;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_RANDOM;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_AUTORANDOM;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_AUTOSHED;
|
|
|
|
|
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(i));
|
|
|
|
|
@ -504,8 +506,33 @@ int Locomotives::SetModeAutoRand(string name) {
|
|
|
|
|
Lock();
|
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0 && (locomotives[i].flags & LOCO_F_AUTO)) {
|
|
|
|
|
debug (0, "Locomotives::SetRandom (Name:%s)\n", name.c_str());
|
|
|
|
|
locomotives[i].flags |= LOCO_F_RANDOM;
|
|
|
|
|
debug (0, "Locomotives::SetAutoRandom (Name:%s)\n", name.c_str());
|
|
|
|
|
locomotives[i].flags |= LOCO_F_AUTORANDOM;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_AUTOSHED;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_AUTOSTOP;
|
|
|
|
|
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(i));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
UnLock();
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Locomotives::SetModeAutoShed(string name) {
|
|
|
|
|
int i;
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
|
|
|
|
|
Lock();
|
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0 && (locomotives[i].flags & LOCO_F_AUTO)) {
|
|
|
|
|
debug (0, "Locomotives::SetAutoShed (Name:%s)\n", name.c_str());
|
|
|
|
|
locomotives[i].flags |= LOCO_F_AUTOSHED;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_AUTORANDOM;
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_AUTOSTOP;
|
|
|
|
|
|
|
|
|
|
jp.Clear();
|
|
|
|
|
@ -758,65 +785,50 @@ int Locomotives::Loco_SearchAndLock(Locomotive *loco) {
|
|
|
|
|
//
|
|
|
|
|
// destination empty? true -> random
|
|
|
|
|
// false -> find way to destination
|
|
|
|
|
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > LOCO_TO_TRYAGAIN) {
|
|
|
|
|
debug (0, "Locomotives::Loop Search '%s' Reverse:%d", loco->name, loco->flags && LOCO_F_REVERSE ? 1 : 0);
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
debug (0, "Locomotives::Loop Search '%s' Reverse:%d", loco->name, (loco->flags & LOCO_F_REVERSE) ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// destination set? - need to find a random block?
|
|
|
|
|
if (loco->blockdest[0] == 0) {
|
|
|
|
|
if (loco->flags & LOCO_F_RANDOM) {
|
|
|
|
|
if (server->railways.FindRandomWay(loco->blockassign, loco->name, &way)) {
|
|
|
|
|
size_t pos, pos1;
|
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
|
if ((pos1 = way.find(",", pos+3)) != string::npos) {
|
|
|
|
|
strncpy (loco->blocknext, way.substr(pos+3, pos1-(pos+3)).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);
|
|
|
|
|
if (server->railways.LockWay(way, loco->name) == 1) {
|
|
|
|
|
loco->auto_data = -1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
server->railways.UnLockWay(way, loco->name);
|
|
|
|
|
//
|
|
|
|
|
// destination set? - need to find a random block?
|
|
|
|
|
if (loco->blockdest[0] == 0) {
|
|
|
|
|
if (loco->flags & LOCO_F_AUTORANDOM) {
|
|
|
|
|
if (server->railways.FindRandomWay(loco->blockassign, loco->name, &way)) {
|
|
|
|
|
size_t pos, pos1;
|
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
|
if ((pos1 = way.find(",", pos+3)) != string::npos) {
|
|
|
|
|
strncpy (loco->blocknext, way.substr(pos+3, pos1-(pos+3)).c_str(), REFERENCENAME_LEN);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// nothing found -> try reverse
|
|
|
|
|
if (loco->blockassign[0] != 0 && (loco->flags & LOCO_F_CANREVERSE)) {
|
|
|
|
|
debug (0, "* Loco_SearchAndLock Reverse Loco %s", loco->name);
|
|
|
|
|
if (loco->blockassign[0] == '-') loco->blockassign[0] = '+';
|
|
|
|
|
else if (loco->blockassign[0] == '+') loco->blockassign[0] = '-';
|
|
|
|
|
|
|
|
|
|
if (loco->flags & LOCO_F_REVERSE) loco->flags &= ~LOCO_F_REVERSE;
|
|
|
|
|
else loco->flags |= LOCO_F_REVERSE;
|
|
|
|
|
else strncpy (loco->blocknext, way.substr(pos+3,string::npos).c_str(), REFERENCENAME_LEN);
|
|
|
|
|
strncpy (loco->auto_way, way.c_str(), WAYDATA_LEN);
|
|
|
|
|
if (server->railways.LockWay(way, loco->name) == 1) {
|
|
|
|
|
loco->auto_data = -1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
server->railways.UnLockWay(way, loco->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
SchedulerNextStep(loco);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (loco->flags & LOCO_F_AUTOSHED) {
|
|
|
|
|
SchedulerNextStep(loco);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// we assume a destination is set, and try to find a new way to the destination
|
|
|
|
|
else if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) {
|
|
|
|
|
// try to lock way.
|
|
|
|
|
size_t pos, pos1;
|
|
|
|
|
debug (0, "Locomotives::Loop %s:%d Found Way:%s", __FILE__, __LINE__, way.c_str());
|
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
|
if ((pos1 = way.find(",", pos+3)) != string::npos) {
|
|
|
|
|
strncpy (loco->blocknext, way.substr(pos+3, pos1-(pos+3)).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);
|
|
|
|
|
if (server->railways.LockWay(way, loco->name) == 1) {
|
|
|
|
|
loco->auto_data = -1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
server->railways.UnLockWay(way, loco->name);
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
//
|
|
|
|
|
// we assume a destination is set, and try to find a new way to the destination
|
|
|
|
|
else if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) {
|
|
|
|
|
// try to lock way.
|
|
|
|
|
size_t pos, pos1;
|
|
|
|
|
debug (0, "Locomotives::Loop %s:%d Found Way:%s", __FILE__, __LINE__, way.c_str());
|
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
|
if ((pos1 = way.find(",", pos+3)) != string::npos) {
|
|
|
|
|
strncpy (loco->blocknext, way.substr(pos+3, pos1-(pos+3)).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);
|
|
|
|
|
if (server->railways.LockWay(way, loco->name) == 1) {
|
|
|
|
|
loco->auto_data = -1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
server->railways.UnLockWay(way, loco->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -954,9 +966,12 @@ int Locomotives::Loco_BlockEnterStop(Locomotive *loco) {
|
|
|
|
|
s_stop = server->blocks.GetSensorStop(dir_reverse, block, loco->flags);
|
|
|
|
|
s_slow = server->blocks.GetSensorSlow(dir_reverse, block, loco->flags);
|
|
|
|
|
s_enter = server->blocks.GetSensorEnter(dir_reverse, block, loco->flags);
|
|
|
|
|
|
|
|
|
|
if (server->sensors.GetActive(s_stop) == 1) {
|
|
|
|
|
debug (0, "Locomotives::Loop EnterBlockStop '%s' UnLockWay\n", loco->name);
|
|
|
|
|
debug (0, "Locomotives::Loop BlockEnterStop '%s' UnLockWay\n", loco->name);
|
|
|
|
|
debug (0, "* %s,%d Sensor Enter '%s' = %d", __FILE__, __LINE__, s_enter.c_str(), server->sensors.GetActive(s_enter));
|
|
|
|
|
debug (0, "* %s,%d Sensor Slow '%s' = %d", __FILE__, __LINE__, s_slow.c_str(), server->sensors.GetActive(s_slow));
|
|
|
|
|
debug (0, "* %s,%d Sensor Stop '%s' = %d", __FILE__, __LINE__, s_stop.c_str(), server->sensors.GetActive(s_stop));
|
|
|
|
|
|
|
|
|
|
SetSpeed(loco->name, 0);
|
|
|
|
|
loco->auto_onroute = LOCO_OR_STOPWAIT;
|
|
|
|
|
server->railways.UnLockWay(loco->auto_wayold, loco->name);
|
|
|
|
|
@ -1075,7 +1090,7 @@ int Locomotives::Loop() {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
debug (0, "%s:%d Locomotive [%s] is doing NOTHING", __FILE__, __LINE__, loco->name);
|
|
|
|
|
debug (0, "%s:%d Locomotive [%s] is doing NOTHING", __FILE__, __LINE__, loco->name);
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
loco->auto_onroute = LOCO_OR_SEARCH;
|
|
|
|
|
}
|
|
|
|
|
@ -1089,17 +1104,37 @@ int Locomotives::Loop() {
|
|
|
|
|
SetModeMan(loco->name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (strcmp(loco->blockassign, loco->blockdest) == 0) {
|
|
|
|
|
loco->blockdest[0] = 0;
|
|
|
|
|
debug (0, "* Locomotive '%s' DEST == ASSING", loco->name);
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(lnum));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// try to find and lock a way
|
|
|
|
|
if (Loco_SearchAndLock(loco)) {
|
|
|
|
|
loco->auto_onroute = LOCO_OR_PREPARE;
|
|
|
|
|
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > LOCO_TO_TRYAGAIN) {
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
|
|
|
|
|
if (strcmp(loco->blockassign, loco->blockdest) == 0) {
|
|
|
|
|
loco->blockdest[0] = 0;
|
|
|
|
|
debug (0, "* Locomotive '%s' DEST == ASSING", loco->name);
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(lnum));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// try to find and lock a way
|
|
|
|
|
if (Loco_SearchAndLock(loco)) {
|
|
|
|
|
loco->auto_onroute = LOCO_OR_PREPARE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// nothing found -> try reverse
|
|
|
|
|
if (loco->blockassign[0] != 0 && (loco->flags & LOCO_F_CANREVERSE)) {
|
|
|
|
|
debug (0, "* Loco_SearchAndLock Reverse Loco %s", loco->name);
|
|
|
|
|
if (loco->blockassign[0] == '-') loco->blockassign[0] = '+';
|
|
|
|
|
else if (loco->blockassign[0] == '+') loco->blockassign[0] = '-';
|
|
|
|
|
|
|
|
|
|
if (loco->flags & LOCO_F_REVERSE) loco->flags &= ~LOCO_F_REVERSE;
|
|
|
|
|
else loco->flags |= LOCO_F_REVERSE;
|
|
|
|
|
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(lnum));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|