|
|
|
@ -288,11 +288,20 @@ int Locomotives::SetFunction(string name, int func, int value) {
|
|
|
|
int Locomotives::SetDestination (string name, string block, int direction) {
|
|
|
|
int Locomotives::SetDestination (string name, string block, int direction) {
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
string way;
|
|
|
|
string way;
|
|
|
|
|
|
|
|
int blflags;
|
|
|
|
|
|
|
|
|
|
|
|
Lock();
|
|
|
|
Lock();
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
|
|
|
|
|
|
|
|
debug (0, "Locomotives::SetDestination (Name:%s Block:%s Direction:%d)\n", name.c_str(), block.c_str(), direction);
|
|
|
|
debug (0, "Locomotives::SetDestination (Name:%s Block:%s Direction:%d)\n", name.c_str(), block.c_str(), direction);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blflags = server->blocks.GetFlags(block);
|
|
|
|
|
|
|
|
if ((blflags & BLOCK_F_SHORT) && !(locomotives[i].flags & LOCO_F_SHORTTRAIN)) break;
|
|
|
|
|
|
|
|
if ((blflags & BLOCK_F_ENDSTATION) && !(locomotives[i].flags & LOCO_F_CANREVERSE)) break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf ("%s:%d blflags:%d locoflags:%d\n", __FILE__, __LINE__, blflags, locomotives[i].flags);
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@ -313,7 +322,7 @@ int Locomotives::SetAssign (string name, string block, int direction) {
|
|
|
|
debug (0, "Locomotives::SetAssign (Name:%s Block:%s Direction:%d)\n", name.c_str(), block.c_str(), direction);
|
|
|
|
debug (0, "Locomotives::SetAssign (Name:%s Block:%s Direction:%d)\n", name.c_str(), block.c_str(), direction);
|
|
|
|
|
|
|
|
|
|
|
|
if (locomotives[i].blockassign[0] != 0) // still locked unlock
|
|
|
|
if (locomotives[i].blockassign[0] != 0) // still locked unlock
|
|
|
|
server->blocks.SetLockedby(locomotives[i].blockassign, name, 0);
|
|
|
|
server->blocks.SetLockedby(locomotives[i].blockassign+2, name, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (direction) snprintf (locomotives[i].blockassign, REFERENCENAME_LEN, "-:%s", block.c_str());
|
|
|
|
if (direction) snprintf (locomotives[i].blockassign, REFERENCENAME_LEN, "-:%s", block.c_str());
|
|
|
|
else snprintf (locomotives[i].blockassign, REFERENCENAME_LEN, "+:%s", block.c_str());
|
|
|
|
else snprintf (locomotives[i].blockassign, REFERENCENAME_LEN, "+:%s", block.c_str());
|
|
|
|
@ -339,6 +348,21 @@ int Locomotives::SetAssign (string name, string block, int direction) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Locomotives::GetFlags(string name) {
|
|
|
|
|
|
|
|
int flags = -1;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
|
|
|
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
|
|
|
|
flags = locomotives[i].flags;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UnLock();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Locomotives::Reset(string name) {
|
|
|
|
int Locomotives::Reset(string name) {
|
|
|
|
Railway rw;
|
|
|
|
Railway rw;
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
@ -410,7 +434,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;
|
|
|
|
locomotives[i].flags &= ~LOCO_F_RANDOM;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UnLock();
|
|
|
|
UnLock();
|
|
|
|
@ -573,6 +597,7 @@ int Locomotives::Loop() {
|
|
|
|
if (loco->flags & LOCO_F_REVERSE) reverse = -1;
|
|
|
|
if (loco->flags & LOCO_F_REVERSE) reverse = -1;
|
|
|
|
else reverse = 1;
|
|
|
|
else reverse = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loco->flags & LOCO_F_AUTO) {
|
|
|
|
if (loco->flags & LOCO_F_AUTO) {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// only in automate do anything alone
|
|
|
|
// only in automate do anything alone
|
|
|
|
@ -589,7 +614,37 @@ int Locomotives::Loop() {
|
|
|
|
// find way, if nothing found check if we can reverse direction
|
|
|
|
// find way, if nothing found check if we can reverse direction
|
|
|
|
//
|
|
|
|
//
|
|
|
|
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > LOCO_TO_TRYAGAIN) {
|
|
|
|
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)) {
|
|
|
|
debug (0, "* Loco Loop Search '%s' Reverse:%d", loco->name, reverse);;
|
|
|
|
|
|
|
|
if (loco->blockdest[0] == 0) {
|
|
|
|
|
|
|
|
if (loco->flags & LOCO_F_RANDOM)
|
|
|
|
|
|
|
|
if (server->railways.FindRandomWay(loco->blockassign, 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_data = -1;
|
|
|
|
|
|
|
|
loco->auto_onroute = LOCO_OR_PREPARE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
server->railways.UnLockWay(way, loco->name);
|
|
|
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (loco->blockassign[0] != 0 && (loco->flags & LOCO_F_CANREVERSE)) {
|
|
|
|
|
|
|
|
debug (0, "* 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) {
|
|
|
|
size_t pos;
|
|
|
|
size_t pos;
|
|
|
|
|
|
|
|
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
@ -599,11 +654,16 @@ int Locomotives::Loop() {
|
|
|
|
loco->auto_data = -1;
|
|
|
|
loco->auto_data = -1;
|
|
|
|
loco->auto_onroute = LOCO_OR_PREPARE;
|
|
|
|
loco->auto_onroute = LOCO_OR_PREPARE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else timer_start(&loco->auto_timenext);
|
|
|
|
else {
|
|
|
|
|
|
|
|
server->railways.UnLockWay(way, loco->name);
|
|
|
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
if (loco->blockassign[0] != 0 && (loco->flags & LOCO_F_CANREVERSE)) {
|
|
|
|
if (loco->blockassign[0] != 0 && (loco->flags & LOCO_F_CANREVERSE)) {
|
|
|
|
|
|
|
|
debug (0, "* Reverse Loco %s", loco->name);
|
|
|
|
|
|
|
|
|
|
|
|
if (loco->blockassign[0] == '-') loco->blockassign[0] = '+';
|
|
|
|
if (loco->blockassign[0] == '-') loco->blockassign[0] = '+';
|
|
|
|
else if (loco->blockassign[0] == '+') loco->blockassign[0] = '-';
|
|
|
|
else if (loco->blockassign[0] == '+') loco->blockassign[0] = '-';
|
|
|
|
|
|
|
|
|
|
|
|
@ -662,7 +722,25 @@ int Locomotives::Loop() {
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
// try to find new way
|
|
|
|
// try to find new way
|
|
|
|
printf ("%s:%d LOCO_OR_ONTHEWAY try to find new way\n", __FILE__, __LINE__);
|
|
|
|
printf ("%s:%d LOCO_OR_ONTHEWAY try to find new way\n", __FILE__, __LINE__);
|
|
|
|
if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) {
|
|
|
|
if (loco->blockdest[0] == 0) {
|
|
|
|
|
|
|
|
if (loco->flags & LOCO_F_RANDOM)
|
|
|
|
|
|
|
|
if (server->railways.FindRandomWay(loco->blockassign, 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_data = -1;
|
|
|
|
|
|
|
|
loco->auto_onroute = LOCO_OR_ENTERBLOCKNEXT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
server->railways.UnLockWay(way, loco->name);
|
|
|
|
|
|
|
|
timer_start(&loco->auto_timenext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) {
|
|
|
|
size_t pos;
|
|
|
|
size_t pos;
|
|
|
|
|
|
|
|
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
if ((pos = way.find(",b:", 1)) != string::npos) {
|
|
|
|
@ -688,7 +766,6 @@ int Locomotives::Loop() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
@ -710,10 +787,11 @@ int Locomotives::Loop() {
|
|
|
|
sensor = server->blocks.GetSensorMinus(block);
|
|
|
|
sensor = server->blocks.GetSensorMinus(block);
|
|
|
|
|
|
|
|
|
|
|
|
if (server->sensors.GetActive(sensor) == 1) {
|
|
|
|
if (server->sensors.GetActive(sensor) == 1) {
|
|
|
|
debug (0, "Locomotives::Loop '%s' UnLockWay\n", loco->name);
|
|
|
|
debug (0, "Locomotives::Loop EnterBlockStop '%s' UnLockWay\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.UnLockWay(loco->auto_wayold, loco->name);
|
|
|
|
|
|
|
|
server->blocks.SetLockedby(loco->blockprev+2, loco->name, 0);
|
|
|
|
loco->auto_wayold[0] = 0;
|
|
|
|
loco->auto_wayold[0] = 0;
|
|
|
|
jp.Clear();
|
|
|
|
jp.Clear();
|
|
|
|
jp.AddObject("locomotive",_GetJSON(lnum));
|
|
|
|
jp.AddObject("locomotive",_GetJSON(lnum));
|
|
|
|
@ -740,7 +818,10 @@ int Locomotives::Loop() {
|
|
|
|
sensor = server->blocks.GetSensorMinus(block);
|
|
|
|
sensor = server->blocks.GetSensorMinus(block);
|
|
|
|
|
|
|
|
|
|
|
|
if (server->sensors.GetActive(sensor) == 1) {
|
|
|
|
if (server->sensors.GetActive(sensor) == 1) {
|
|
|
|
|
|
|
|
debug (0, "Locomotives::Loop EnterBlockNext '%s' UnLockWay\n", loco->name);
|
|
|
|
|
|
|
|
|
|
|
|
server->railways.UnLockWay(loco->auto_wayold, loco->name);
|
|
|
|
server->railways.UnLockWay(loco->auto_wayold, loco->name);
|
|
|
|
|
|
|
|
server->blocks.SetLockedby(loco->blockprev+2, loco->name, 0);
|
|
|
|
loco->auto_wayold[0] = 0;
|
|
|
|
loco->auto_wayold[0] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (finish == 0) { // stop train if not finished
|
|
|
|
if (finish == 0) { // stop train if not finished
|
|
|
|
|