|
|
@ -45,6 +45,7 @@ JSONParse Locomotives::_GetJSON(int idx) {
|
|
|
|
s = locomotives[idx].blockprev; json.AddObject("blockprev", s);
|
|
|
|
s = locomotives[idx].blockprev; json.AddObject("blockprev", s);
|
|
|
|
s = locomotives[idx].auto_way; json.AddObject("auto_way", s);
|
|
|
|
s = locomotives[idx].auto_way; json.AddObject("auto_way", s);
|
|
|
|
s = locomotives[idx].auto_wayold; json.AddObject("auto_wayold", s);
|
|
|
|
s = locomotives[idx].auto_wayold; json.AddObject("auto_wayold", s);
|
|
|
|
|
|
|
|
s = locomotives[idx].schedway; json.AddObject("schedway", s);
|
|
|
|
json.AddObject("addr", locomotives[idx].addr);
|
|
|
|
json.AddObject("addr", locomotives[idx].addr);
|
|
|
|
json.AddObject("stepcode", locomotives[idx].stepcode);
|
|
|
|
json.AddObject("stepcode", locomotives[idx].stepcode);
|
|
|
|
json.AddObject("speed", locomotives[idx].speed);
|
|
|
|
json.AddObject("speed", locomotives[idx].speed);
|
|
|
@ -118,6 +119,7 @@ Locomotive Locomotives::GetLocomotiveFromJSON(JSONParse *j) {
|
|
|
|
l.flags = 0;
|
|
|
|
l.flags = 0;
|
|
|
|
l.speed = 0;
|
|
|
|
l.speed = 0;
|
|
|
|
l.func = 0;
|
|
|
|
l.func = 0;
|
|
|
|
|
|
|
|
l.schedway[0] = 0;
|
|
|
|
l.blockassign[0] = 0;
|
|
|
|
l.blockassign[0] = 0;
|
|
|
|
l.blockdest[0] = 0;
|
|
|
|
l.blockdest[0] = 0;
|
|
|
|
l.blocknext[0] = 0;
|
|
|
|
l.blocknext[0] = 0;
|
|
|
@ -140,6 +142,9 @@ Locomotive Locomotives::GetLocomotiveFromJSON(JSONParse *j) {
|
|
|
|
strncpy (l.blockprev, s.c_str(), REFERENCENAME_LEN);
|
|
|
|
strncpy (l.blockprev, s.c_str(), REFERENCENAME_LEN);
|
|
|
|
j->GetValue("blocknext", &s);
|
|
|
|
j->GetValue("blocknext", &s);
|
|
|
|
strncpy (l.blocknext, s.c_str(), REFERENCENAME_LEN);
|
|
|
|
strncpy (l.blocknext, s.c_str(), REFERENCENAME_LEN);
|
|
|
|
|
|
|
|
j->GetValue("schedway", &s);
|
|
|
|
|
|
|
|
strncpy (l.schedway, s.c_str(), WAYDATA_LEN);
|
|
|
|
|
|
|
|
|
|
|
|
j->GetValueInt("addr", &l.addr);
|
|
|
|
j->GetValueInt("addr", &l.addr);
|
|
|
|
j->GetValueInt("stepcode", &l.stepcode);
|
|
|
|
j->GetValueInt("stepcode", &l.stepcode);
|
|
|
|
j->GetValueInt("speed", &l.speed);
|
|
|
|
j->GetValueInt("speed", &l.speed);
|
|
|
@ -155,6 +160,11 @@ Locomotive Locomotives::GetLocomotiveFromJSON(JSONParse *j) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* this function gets called if some configuration data has changed.
|
|
|
|
|
|
|
|
* We will ignore the functions and speed settings. This has to be set with the SetFunction
|
|
|
|
|
|
|
|
* and SetSpeed calls.
|
|
|
|
|
|
|
|
*/
|
|
|
|
int Locomotives::Change(Locomotive *loco) {
|
|
|
|
int Locomotives::Change(Locomotive *loco) {
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
int ifree = -1;
|
|
|
|
int ifree = -1;
|
|
|
@ -174,8 +184,7 @@ int Locomotives::Change(Locomotive *loco) {
|
|
|
|
locomotives[i].vfast = loco->vfast;
|
|
|
|
locomotives[i].vfast = loco->vfast;
|
|
|
|
locomotives[i].vmax = loco->vmax;
|
|
|
|
locomotives[i].vmax = loco->vmax;
|
|
|
|
locomotives[i].flags = loco->flags;
|
|
|
|
locomotives[i].flags = loco->flags;
|
|
|
|
// locomotives[i].speed = 0;
|
|
|
|
strncpy (locomotives[i].schedway, loco->schedway, WAYDATA_LEN);
|
|
|
|
// locomotives[i].func = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ifree = i;
|
|
|
|
ifree = i;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -189,6 +198,7 @@ int Locomotives::Change(Locomotive *loco) {
|
|
|
|
locomotives[ifree] = *loco;
|
|
|
|
locomotives[ifree] = *loco;
|
|
|
|
strncpy (locomotives[ifree].name, loco->name, REFERENCENAME_LEN);
|
|
|
|
strncpy (locomotives[ifree].name, loco->name, REFERENCENAME_LEN);
|
|
|
|
strncpy (locomotives[ifree].ifname, loco->ifname, REFERENCENAME_LEN);
|
|
|
|
strncpy (locomotives[ifree].ifname, loco->ifname, REFERENCENAME_LEN);
|
|
|
|
|
|
|
|
strncpy (locomotives[ifree].schedway, loco->schedway, WAYDATA_LEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
changed = 1;
|
|
|
|
changed = 1;
|
|
|
@ -206,6 +216,7 @@ int Locomotives::Delete(string name) {
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
locomotives[i].name[0] = 0;
|
|
|
|
locomotives[i].name[0] = 0;
|
|
|
|
locomotives[i].ifname[0] = 0;
|
|
|
|
locomotives[i].ifname[0] = 0;
|
|
|
|
|
|
|
|
locomotives[i].schedway[0] = 0;
|
|
|
|
locomotives[i].addr = 0;
|
|
|
|
locomotives[i].addr = 0;
|
|
|
|
locomotives[i].stepcode = 0;
|
|
|
|
locomotives[i].stepcode = 0;
|
|
|
|
locomotives[i].vmin = 0;
|
|
|
|
locomotives[i].vmin = 0;
|
|
|
@ -384,7 +395,10 @@ int Locomotives::Reset(string name) {
|
|
|
|
locomotives[i].blocknext[0] = 0;
|
|
|
|
locomotives[i].blocknext[0] = 0;
|
|
|
|
locomotives[i].auto_way[0] = 0;
|
|
|
|
locomotives[i].auto_way[0] = 0;
|
|
|
|
locomotives[i].auto_wayold[0] = 0;
|
|
|
|
locomotives[i].auto_wayold[0] = 0;
|
|
|
|
locomotives[i].auto_onroute = -1;
|
|
|
|
locomotives[i].auto_onroute = 0;
|
|
|
|
|
|
|
|
locomotives[i].auto_data = 0;
|
|
|
|
|
|
|
|
locomotives[i].auto_timenext = { 0 };
|
|
|
|
|
|
|
|
locomotives[i].sched_step = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -408,6 +422,7 @@ int Locomotives::SetMan(string name) {
|
|
|
|
locomotives[i].auto_onroute = 0;
|
|
|
|
locomotives[i].auto_onroute = 0;
|
|
|
|
locomotives[i].auto_way[0] = 0;
|
|
|
|
locomotives[i].auto_way[0] = 0;
|
|
|
|
locomotives[i].auto_wayold[0] = 0;
|
|
|
|
locomotives[i].auto_wayold[0] = 0;
|
|
|
|
|
|
|
|
locomotives[i].sched_step = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UnLock();
|
|
|
|
UnLock();
|
|
|
@ -534,6 +549,87 @@ string Locomotives::GetName(int idx) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Locomotive is on auto, do the scheduled steps
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int Locomotives::SchedulerNextStep(Locomotive *loc) {
|
|
|
|
|
|
|
|
int stepsmax = 0; // number of found steps
|
|
|
|
|
|
|
|
int stepcurpos = 0; // current pos in way string
|
|
|
|
|
|
|
|
int stepnextpos = -1; // next pos;
|
|
|
|
|
|
|
|
int schedwaylen = 0;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
string name;
|
|
|
|
|
|
|
|
string next;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loc == NULL) return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug (0, "Locomotives::SchedulerNextStep loc:%s Step:%d", loc->name, loc->sched_step);
|
|
|
|
|
|
|
|
name = loc->name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// find number of scheduled steps, current pos and next pos
|
|
|
|
|
|
|
|
for (i = 0; i < WAYDATA_LEN && loc->schedway[i] != 0; i++)
|
|
|
|
|
|
|
|
if (loc->schedway[i] == ',') {
|
|
|
|
|
|
|
|
stepsmax++;
|
|
|
|
|
|
|
|
if (stepsmax == loc->sched_step) stepcurpos = i;
|
|
|
|
|
|
|
|
else if (loc->sched_step == 0 || (stepcurpos > 0 && stepnextpos == -1)) stepnextpos = i+1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
schedwaylen = i;
|
|
|
|
|
|
|
|
if (stepnextpos == -1) stepnextpos = 0; // no next step found point to first
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// set next way
|
|
|
|
|
|
|
|
if (stepnextpos == 0) loc->sched_step = 0;
|
|
|
|
|
|
|
|
else loc->sched_step++;
|
|
|
|
|
|
|
|
if (loc->sched_step > stepsmax) {
|
|
|
|
|
|
|
|
loc->sched_step = 0;
|
|
|
|
|
|
|
|
stepnextpos = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// read parameter of step
|
|
|
|
|
|
|
|
for (next = "", i = stepnextpos; i < WAYDATA_LEN && loc->schedway[i] != ',' && loc->schedway[i] != 0; i++) {
|
|
|
|
|
|
|
|
if (i > stepnextpos+1) next += loc->schedway[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
debug (0, "Locomotives::SchedulerNextStep loc:%s Next Pos: '%s'", loc->name, loc->schedway+stepnextpos);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loc->schedway[stepnextpos] && stepnextpos < schedwaylen-2) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (loc->schedway[stepnextpos]) {
|
|
|
|
|
|
|
|
case ('W'):
|
|
|
|
|
|
|
|
case ('w'):
|
|
|
|
|
|
|
|
gettimeofday (&loc->auto_timenext, NULL);
|
|
|
|
|
|
|
|
loc->auto_timenext.tv_sec += atoi (next.c_str());
|
|
|
|
|
|
|
|
loc->auto_data = 0;
|
|
|
|
|
|
|
|
loc->auto_onroute = LOCO_OR_STOPWAIT;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ('B'):
|
|
|
|
|
|
|
|
case ('b'):
|
|
|
|
|
|
|
|
gettimeofday (&loc->auto_timenext, NULL);
|
|
|
|
|
|
|
|
snprintf (loc->blockdest, REFERENCENAME_LEN, "%s", next.c_str());
|
|
|
|
|
|
|
|
loc->auto_timenext.tv_sec += atoi (next.c_str());
|
|
|
|
|
|
|
|
loc->auto_data = 0;
|
|
|
|
|
|
|
|
loc->auto_onroute = LOCO_OR_SEARCH;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ('R'):
|
|
|
|
|
|
|
|
case ('r'):
|
|
|
|
|
|
|
|
if (loc->blockassign[0] == '-') loc->blockassign[0] = '+';
|
|
|
|
|
|
|
|
else if (loc->blockassign[0] == '+') loc->blockassign[0] = '-';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loc->flags & LOCO_F_REVERSE) loc->flags &= ~LOCO_F_REVERSE;
|
|
|
|
|
|
|
|
else loc->flags |= LOCO_F_REVERSE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
debug (0, "Locomotives::SchedulerNextStep Unknown Command: '%c' loc:%s way:'%s'", loc->name,
|
|
|
|
|
|
|
|
loc->schedway[stepnextpos], loc->schedway);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SendUpdate(loc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// with each call only check one single step of the way, if we have to
|
|
|
|
// with each call only check one single step of the way, if we have to
|
|
|
@ -589,6 +685,24 @@ int Locomotives::AutoCheckWaySingleStep(string way, string locname, int *data) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void::Locomotives::SendUpdate (Locomotive *loc) {
|
|
|
|
|
|
|
|
int lnum;
|
|
|
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (locomotives == NULL) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (lnum = 0; lnum < max; lnum++) {
|
|
|
|
|
|
|
|
if (loc == &locomotives[lnum]) {
|
|
|
|
|
|
|
|
jp.Clear();
|
|
|
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(lnum));
|
|
|
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Locomotives::Loop() {
|
|
|
|
int Locomotives::Loop() {
|
|
|
|
int lnum, i;
|
|
|
|
int lnum, i;
|
|
|
|
string way;
|
|
|
|
string way;
|
|
|
@ -669,8 +783,7 @@ int Locomotives::Loop() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
// in here we need to put code for scheduled ways. ?
|
|
|
|
SchedulerNextStep(loco);
|
|
|
|
printf ("%s:%d scheduled ways: not even started to work on this.\n", __FILE__, __LINE__);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|