sensors are working again, split blocks should finally work

master
Steffen Pohle 2 years ago
parent 2df7d6e032
commit f0bf67f740

@ -380,59 +380,126 @@ int Blocks::GetFlags (string blname) {
}; };
string Blocks::GetSensorEnter (int direction, string blname) {
string res = ""; /*
* return a pointer to the blockdata in case of split blocks also return the second block
*/
int Blocks::GetBlocksPtr (string blname, Block **b1, Block **b2) {
int i; int i;
JSONParse jp;
Lock(); (*b1) = NULL;
(*b2) = NULL;
for (i = 0; i < max; i++) if (blname.compare(blocks[i].name) == 0) { for (i = 0; i < max; i++) if (blname.compare(blocks[i].name) == 0) {
res = blocks[i].s_enter[direction]; (*b1) = &blocks[i];
} }
UnLock();
return res;
};
if ((*b1) == NULL) {
debug (0, "Blocks::%s Could not find block: %s", __FUNCTION__, blname.c_str());
return 0;
}
string Blocks::GetSensorSlow (int direction, string blname) { if ((*b1)->flags & BLOCK_F_SPLIT) {
std::string res = ""; for (i = 0; i < max; i++) if (strcmp ((*b1)->secondblock, blocks[i].name) == 0) {
int i; (*b2) = &blocks[i];
}
if ((*b2) == NULL) {
debug (0, "Blocks::%s Could not find second block: %s", __FUNCTION__, (*b1)->secondblock);
return 0;
}
}
return 1;
}
string Blocks::GetSensorEnter (int direction, string blname, int locoflags) {
string res = "";
JSONParse jp; JSONParse jp;
Block *b1 = NULL;
Block *b2 = NULL;
Lock(); Lock();
for (i = 0; i < max; i++) if (blname.compare(blocks[i].name) == 0) { if (!GetBlocksPtr(blname, &b1, &b2)) return res;
res = blocks[i].s_slow[direction];
if (!(locoflags & LOCO_F_SHORTTRAIN) && (b1->flags & BLOCK_F_SPLIT)) {
if (direction == 0) {
if (b1->flags & BLOCK_F_SPLITPOS) res = b1->s_enter[direction];
else res = b2->s_enter[direction];
}
else {
if (b1->flags & BLOCK_F_SPLITPOS) res = b2->s_enter[direction];
else res = b1->s_enter[direction];
}
} }
if (res.length() == 0) {
res = b1->s_enter[direction];
}
UnLock(); UnLock();
return res; return res;
}; };
string Blocks::GetSensorStop (int direction, string blname) { string Blocks::GetSensorSlow (int direction, string blname, int locoflags) {
string res = ""; string res = "";
int i;
JSONParse jp; JSONParse jp;
Block *b1 = NULL;
Block *b2 = NULL;
Lock(); Lock();
for (i = 0; i < max; i++) if (blname.compare(blocks[i].name) == 0) { if (!GetBlocksPtr(blname, &b1, &b2)) return res;
res = blocks[i].s_stop[direction];
if (!(locoflags & LOCO_F_SHORTTRAIN) && (b1->flags & BLOCK_F_SPLIT)) {
if (direction == 0) {
if (b1->flags & BLOCK_F_SPLITPOS) res = b2->s_slow[direction];
else res = b1->s_slow[direction];
}
else {
if (b1->flags & BLOCK_F_SPLITPOS) res = b1->s_slow[direction];
else res = b2->s_slow[direction];
}
}
if (res.length() == 0) {
res = b1->s_slow[direction];
}
if (res.length() == 0) {
res = b1->s_enter[direction];
} }
UnLock(); UnLock();
return res; return res;
}; };
string Blocks::GetSensorShortStop (int direction, string blname) { string Blocks::GetSensorStop (int direction, string blname, int locoflags) {
string res = ""; string res = "";
int i;
JSONParse jp; JSONParse jp;
Block *b1 = NULL;
Block *b2 = NULL;
Lock(); Lock();
for (i = 0; i < max; i++) if (blname.compare(blocks[i].name) == 0) { if (!GetBlocksPtr(blname, &b1, &b2)) return res;
res = blocks[i].s_shortstop[direction];
if ((locoflags & LOCO_F_SHORTTRAIN) && b1->s_shortstop[direction][0] != 0)
res = b1->s_shortstop[direction];
if (!(locoflags & LOCO_F_SHORTTRAIN) && (b1->flags & BLOCK_F_SPLIT)) {
if (direction == 0) {
if (b1->flags & BLOCK_F_SPLITPOS) res = b2->s_stop[direction];
else res = b1->s_stop[direction];
}
else {
if (b1->flags & BLOCK_F_SPLITPOS) res = b1->s_stop[direction];
else res = b2->s_stop[direction];
}
}
if (res.length() == 0) {
res = b1->s_stop[direction];
} }
UnLock(); UnLock();
return res; return res;
}; };

@ -72,6 +72,7 @@ class Blocks {
int last_blockidx; // to speed up things int last_blockidx; // to speed up things
Block* FindBlock(string name); Block* FindBlock(string name);
int GetBlocksPtr(string blname, Block **b1, Block **b2);
public: public:
Blocks(); Blocks();
~Blocks(); ~Blocks();
@ -89,10 +90,9 @@ class Blocks {
int SetOff(string blname); int SetOff(string blname);
int IsOff(string blname); int IsOff(string blname);
string GetSensorEnter (int direction, string blname); string GetSensorEnter (int direction, string blname, int locoflags);
string GetSensorSlow (int direction, string blname); string GetSensorSlow (int direction, string blname, int locoflags);
string GetSensorStop (int direction, string blname); string GetSensorStop (int direction, string blname, int locoflags);
string GetSensorShortStop (int direction, string blname);
int GetFlags (string blname); int GetFlags (string blname);
string GetSecondBlock(string block); string GetSecondBlock(string block);

@ -859,7 +859,6 @@ int Locomotives::Loco_OnRoute(Locomotive *loco) {
string s_enter; string s_enter;
string s_slow; string s_slow;
string s_stop; string s_stop;
string s_shortstop;
int dir_reverse = 0; int dir_reverse = 0;
char *tmpc = NULL; char *tmpc = NULL;
string way; string way;
@ -874,18 +873,16 @@ int Locomotives::Loco_OnRoute(Locomotive *loco) {
if (loco->blocknext[0] == '-') dir_reverse = 1; if (loco->blocknext[0] == '-') dir_reverse = 1;
else dir_reverse = 0; else dir_reverse = 0;
s_shortstop = server->blocks.GetSensorShortStop(dir_reverse, block); s_stop = server->blocks.GetSensorStop(dir_reverse, block, loco->flags);
s_stop = server->blocks.GetSensorStop(dir_reverse, block); s_slow = server->blocks.GetSensorSlow(dir_reverse, block, loco->flags);
s_slow = server->blocks.GetSensorSlow(dir_reverse, block); s_enter = server->blocks.GetSensorEnter(dir_reverse, block, loco->flags);
s_enter = server->blocks.GetSensorEnter(dir_reverse, block);
if ( server->sensors.GetActive(s_enter) == 1 || server->sensors.GetActive(s_stop) == 1 || if ( server->sensors.GetActive(s_enter) == 1 || server->sensors.GetActive(s_stop) == 1 ||
server->sensors.GetActive(s_slow) == 1 || server->sensors.GetActive(s_shortstop) == 1) { // entering block? server->sensors.GetActive(s_slow) == 1) { // entering block?
debug (0, "* Locomotive '%s' EnterBlock '%s'", loco->name, loco->blocknext); debug (0, "* Locomotive '%s' EnterBlock '%s'", loco->name, loco->blocknext);
debug (0, "* %s,%d Sensor Enter '%s' = %d", __FILE__, __LINE__, s_enter.c_str(), server->sensors.GetActive(s_enter)); 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 Slow '%s' = %d", __FILE__, __LINE__, s_slow.c_str(), server->sensors.GetActive(s_slow));
debug (0, "* %s,%d Sensor Sh.Stop '%s' = %d", __FILE__, __LINE__, s_shortstop.c_str(), server->sensors.GetActive(s_shortstop));
debug (0, "* %s,%d Sensor Stop '%s' = %d", __FILE__, __LINE__, s_stop.c_str(), server->sensors.GetActive(s_stop)); debug (0, "* %s,%d Sensor Stop '%s' = %d", __FILE__, __LINE__, s_stop.c_str(), server->sensors.GetActive(s_stop));
// assignment <-- next, the assignment has to be checked // assignment <-- next, the assignment has to be checked
@ -943,7 +940,6 @@ int Locomotives::Loco_BlockEnterStop(Locomotive *loco) {
string s_enter; string s_enter;
string s_slow; string s_slow;
string s_stop; string s_stop;
string s_shortstop;
int dir_reverse = 0; int dir_reverse = 0;
string way; string way;
@ -955,14 +951,11 @@ int Locomotives::Loco_BlockEnterStop(Locomotive *loco) {
if (loco->blockassign[0] == '-') dir_reverse = 1; if (loco->blockassign[0] == '-') dir_reverse = 1;
else dir_reverse = 0; else dir_reverse = 0;
s_shortstop = server->blocks.GetSensorShortStop(dir_reverse, block); s_stop = server->blocks.GetSensorStop(dir_reverse, block, loco->flags);
s_stop = server->blocks.GetSensorStop(dir_reverse, block); s_slow = server->blocks.GetSensorSlow(dir_reverse, block, loco->flags);
s_slow = server->blocks.GetSensorSlow(dir_reverse, block); s_enter = server->blocks.GetSensorEnter(dir_reverse, block, loco->flags);
s_enter = server->blocks.GetSensorEnter(dir_reverse, block);
if ( server->sensors.GetActive(s_stop) == 1 ||
((loco->flags & LOCO_F_SHORTTRAIN) && server->sensors.GetActive(s_shortstop) == 1)) {
if (server->sensors.GetActive(s_stop) == 1) {
debug (0, "Locomotives::Loop EnterBlockStop '%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;
@ -996,13 +989,11 @@ int Locomotives::Loco_BlockEnterNext(Locomotive *loco) {
if (loco->blockassign[0] == '-') dir_reverse = 1; if (loco->blockassign[0] == '-') dir_reverse = 1;
else dir_reverse = 0; else dir_reverse = 0;
s_shortstop = server->blocks.GetSensorShortStop(dir_reverse, block); s_stop = server->blocks.GetSensorStop(dir_reverse, block, loco->flags);
s_stop = server->blocks.GetSensorStop(dir_reverse, block); s_slow = server->blocks.GetSensorSlow(dir_reverse, block, loco->flags);
s_slow = server->blocks.GetSensorSlow(dir_reverse, block); s_enter = server->blocks.GetSensorEnter(dir_reverse, block, loco->flags);
s_enter = server->blocks.GetSensorEnter(dir_reverse, block);
if ( server->sensors.GetActive(s_stop) == 1 || if (server->sensors.GetActive(s_stop) == 1) {
((loco->flags & LOCO_F_SHORTTRAIN) && server->sensors.GetActive(s_shortstop) == 1)) {
if (loco->auto_timenext.tv_sec > 0) { if (loco->auto_timenext.tv_sec > 0) {
// //

Loading…
Cancel
Save