|
|
@ -123,6 +123,7 @@ Locomotive Locomotives::GetLocomotiveFromJSON(JSONParse *j) {
|
|
|
|
l.blockprev[0] = 0;
|
|
|
|
l.blockprev[0] = 0;
|
|
|
|
l.auto_way[0] = 0;
|
|
|
|
l.auto_way[0] = 0;
|
|
|
|
l.auto_onroute = 0;
|
|
|
|
l.auto_onroute = 0;
|
|
|
|
|
|
|
|
l.auto_timenext = {0};
|
|
|
|
|
|
|
|
|
|
|
|
j->GetValue("name", &s);
|
|
|
|
j->GetValue("name", &s);
|
|
|
|
strncpy (l.name, s.c_str(), REFERENCENAME_LEN);
|
|
|
|
strncpy (l.name, s.c_str(), REFERENCENAME_LEN);
|
|
|
@ -213,6 +214,7 @@ int Locomotives::Delete(string name) {
|
|
|
|
locomotives[i].flags = 0;
|
|
|
|
locomotives[i].flags = 0;
|
|
|
|
locomotives[i].auto_way[0] = 0;
|
|
|
|
locomotives[i].auto_way[0] = 0;
|
|
|
|
locomotives[i].auto_onroute = -1;
|
|
|
|
locomotives[i].auto_onroute = -1;
|
|
|
|
|
|
|
|
locomotives[i].auto_timenext = {0};
|
|
|
|
changed = 1;
|
|
|
|
changed = 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -290,16 +292,6 @@ int Locomotives::SetDestination (string name, string block, int direction) {
|
|
|
|
if (direction) snprintf (locomotives[i].blockdest, REFERENCENAME_LEN, "-:%s", block.c_str());
|
|
|
|
if (direction) snprintf (locomotives[i].blockdest, REFERENCENAME_LEN, "-:%s", block.c_str());
|
|
|
|
else snprintf (locomotives[i].blockdest, REFERENCENAME_LEN, "+:%s", block.c_str());
|
|
|
|
else snprintf (locomotives[i].blockdest, REFERENCENAME_LEN, "+:%s", block.c_str());
|
|
|
|
printf ("%s:%d Locomotive '%s' blockdest:%s\n", __FILE__, __LINE__, locomotives[i].name, locomotives[i].blockdest);
|
|
|
|
printf ("%s:%d Locomotive '%s' blockdest:%s\n", __FILE__, __LINE__, locomotives[i].name, locomotives[i].blockdest);
|
|
|
|
if (server->railways.FindWay(locomotives[i].blockassign, locomotives[i].blockdest, locomotives[i].name, &way)) {
|
|
|
|
|
|
|
|
size_t pos;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
|
|
|
|
strncpy (locomotives[i].blocknext, way.substr(pos+3,string::npos).c_str(), REFERENCENAME_LEN);
|
|
|
|
|
|
|
|
strncpy (locomotives[i].auto_way, way.c_str(), WAYDATA_LEN);
|
|
|
|
|
|
|
|
server->railways.LockWay(way, locomotives[i].name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("%s:%d Locomotive '%s' blockdest:%s\n", __FILE__, __LINE__, locomotives[i].name, locomotives[i].blockdest);
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UnLock();
|
|
|
|
UnLock();
|
|
|
@ -379,6 +371,8 @@ int Locomotives::SetMan(string name) {
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
debug (0, "Locomotives::SetMan (Name:%s)\n", name.c_str());
|
|
|
|
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_RANDOM);
|
|
|
|
|
|
|
|
locomotives[i].auto_onroute = 0;
|
|
|
|
|
|
|
|
locomotives[i].auto_way[0] = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UnLock();
|
|
|
|
UnLock();
|
|
|
@ -411,6 +405,7 @@ int Locomotives::SetAuto(string name) {
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
debug (0, "Locomotives::SetAuto (Name:%s)\n", name.c_str());
|
|
|
|
debug (0, "Locomotives::SetAuto (Name:%s)\n", name.c_str());
|
|
|
|
locomotives[i].flags |= LOCO_F_AUTO;
|
|
|
|
locomotives[i].flags |= LOCO_F_AUTO;
|
|
|
|
|
|
|
|
locomotives[i].auto_onroute = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UnLock();
|
|
|
|
UnLock();
|
|
|
@ -551,6 +546,106 @@ int Locomotives::AutoCheckWaySingleStep(string way, string locname) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Locomotives::Loop() {
|
|
|
|
|
|
|
|
int lnum;
|
|
|
|
|
|
|
|
string way;
|
|
|
|
|
|
|
|
Locomotive *loco = NULL;
|
|
|
|
|
|
|
|
string block;
|
|
|
|
|
|
|
|
string sensor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (lnum = 0; lnum < max; lnum++) if (locomotives[lnum].name[0] != 0) {
|
|
|
|
|
|
|
|
loco = &locomotives[lnum];
|
|
|
|
|
|
|
|
if (loco->flags & LOCO_F_AUTO) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// only in automate do anything alone
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
if (loco->blockassign[0] == 0 || loco->blockdest[0] == 0) continue;
|
|
|
|
|
|
|
|
if (loco->auto_onroute == LOCO_OR_NOTHING) {
|
|
|
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
|
|
|
loco->auto_onroute = LOCO_OR_SEARCH;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loco->auto_onroute == LOCO_OR_SEARCH) {
|
|
|
|
|
|
|
|
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > 1000) {
|
|
|
|
|
|
|
|
printf ("%s:%d Locomotive::Loop '%s' auto_onroute:%d\n", __FILE__, __LINE__,
|
|
|
|
|
|
|
|
loco->name, loco->auto_onroute);
|
|
|
|
|
|
|
|
if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) {
|
|
|
|
|
|
|
|
size_t pos;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
|
|
|
|
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_onroute = LOCO_OR_PREPARE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else timer_start(&loco->auto_timenext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else timer_start(&loco->auto_timenext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (loco->auto_onroute == LOCO_OR_PREPARE) {
|
|
|
|
|
|
|
|
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > 1000) {
|
|
|
|
|
|
|
|
if (AutoCheckWaySingleStep(loco->auto_way, loco->name) == 1)
|
|
|
|
|
|
|
|
loco->auto_onroute = LOCO_OR_ONTHEWAY;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
// check enter block
|
|
|
|
|
|
|
|
block = loco->blocknext+2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loco->blocknext[0] == '-')
|
|
|
|
|
|
|
|
sensor = server->blocks.GetSensorMinus(block);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
server->blocks.SetLockedby((string)(loco->blockassign+2), loco->name, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (loco->auto_onroute == LOCO_OR_ENTERBLOCK) {
|
|
|
|
|
|
|
|
// check enter block
|
|
|
|
|
|
|
|
block = loco->blocknext+2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loco->blocknext[0] == '-')
|
|
|
|
|
|
|
|
sensor = server->blocks.GetSensorPlus(block);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
sensor = server->blocks.GetSensorMinus(block);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (server->sensors.GetActive(sensor) == 1) {
|
|
|
|
|
|
|
|
debug (0, "Locomotives::Loop '%s' UnLockWay\n", loco->name);
|
|
|
|
|
|
|
|
SetSpeed(loco->name, 0);
|
|
|
|
|
|
|
|
loco->auto_onroute = LOCO_OR_STOPWAIT;
|
|
|
|
|
|
|
|
server->railways.UnLockWay(loco->auto_way, loco->name);
|
|
|
|
|
|
|
|
strncpy (loco->blockassign, loco->blocknext, REFERENCENAME_LEN);
|
|
|
|
|
|
|
|
loco->blocknext[0] = 0;
|
|
|
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (loco->auto_onroute == LOCO_OR_STOPWAIT) {
|
|
|
|
|
|
|
|
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > 5000) {
|
|
|
|
|
|
|
|
loco->auto_onroute = LOCO_OR_SEARCH;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Locomotives::Test(string loco) {
|
|
|
|
int Locomotives::Test(string loco) {
|
|
|
|
int res = 0;
|
|
|
|
int res = 0;
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|