|
|
|
@ -164,20 +164,33 @@ int Turnouts::Delete(string name) {
|
|
|
|
|
|
|
|
|
|
int Turnouts::Set(string name, int value) {
|
|
|
|
|
int i;
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
Lock();
|
|
|
|
|
for (i = 0; i < max; i++) if (turnouts[i].name[0] != 0) {
|
|
|
|
|
if (name.compare(turnouts[i].name) == 0) {
|
|
|
|
|
debug (0, "Turnout::Set: Name:%s Flags:%d[%c%c%c] Value:%d", name.c_str(), turnouts[i].flags,
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_INVERSE) ? 'I' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_ACTIVE) ? 'A' : '-',
|
|
|
|
|
debug (0, "%s:%d Turnout::Set: Name:%s Flags:%d[%c%c%c%c] Value:%d", __FILE__, __LINE__, name.c_str(), turnouts[i].flags,
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_ISRELAIS) ? 'R' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_TURNOUT) ? 'T' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_ACTIVE) ? 'A' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_INVERSE) ? 'I' : '-',
|
|
|
|
|
value);
|
|
|
|
|
if (turnouts[i].flags & TURNOUT_F_INVERSE)
|
|
|
|
|
server->interfaces.SetTurnout(&turnouts[i], !value, 1); // motor on
|
|
|
|
|
else
|
|
|
|
|
server->interfaces.SetTurnout(&turnouts[i], value, 1); // motor on
|
|
|
|
|
if (turnouts[i].flags & TURNOUT_F_ISRELAIS) {
|
|
|
|
|
printf ("%s:%d is relais.... %d\n", __FILE__, __LINE__, value);
|
|
|
|
|
server->interfaces.SetTurnout(&turnouts[i], value, value);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (turnouts[i].flags & TURNOUT_F_INVERSE)
|
|
|
|
|
server->interfaces.SetTurnout(&turnouts[i], !value, 1); // motor on
|
|
|
|
|
else
|
|
|
|
|
server->interfaces.SetTurnout(&turnouts[i], value, 1); // motor on
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("turnout", _GetJSON(i));
|
|
|
|
|
if (network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
|
|
|
|
|
gettimeofday (&turnouts[i].activatetime, NULL);
|
|
|
|
|
changed = 1;
|
|
|
|
|
|
|
|
|
@ -215,14 +228,15 @@ void Turnouts::SetFromBus(string ifname, int addr, int value) {
|
|
|
|
|
int i;
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
|
|
|
|
|
debug (0, "Turnouts::SetFromBus Interface:%s, addr: %d, value:%d", ifname.c_str(), addr, value);
|
|
|
|
|
debug (0, "%s:%d Turnouts::SetFromBus Interface:%s, addr: %d, value:%d", __FILE__, __LINE__, ifname.c_str(), addr, value);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < max; i++) if (turnouts[i].name[0] != 0) {
|
|
|
|
|
if (ifname.compare(turnouts[i].ifname) == 0 && turnouts[i].addr == addr) {
|
|
|
|
|
debug (0, "Turnout::SetFromBus Name:%s Flags:%d[%c%c%c]", turnouts[i].name, turnouts[i].flags,
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_INVERSE) ? 'I' : '-',
|
|
|
|
|
debug (0, "%s:%d Turnout::SetFromBus Name:%s Flags:%d[%c%c%c%c]", __FILE__, __LINE__, turnouts[i].name, turnouts[i].flags,
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_ISRELAIS) ? 'R' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_TURNOUT) ? 'T' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_ACTIVE) ? 'A' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_TURNOUT) ? 'T' : '-');
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_INVERSE) ? 'I' : '-');
|
|
|
|
|
|
|
|
|
|
// if (value) turnouts[i].flags |= TURNOUT_F_ACTIVE;
|
|
|
|
|
// else turnouts[i].flags &= ~TURNOUT_F_ACTIVE;
|
|
|
|
@ -235,10 +249,11 @@ void Turnouts::SetFromBus(string ifname, int addr, int value) {
|
|
|
|
|
if (value) turnouts[i].flags |= TURNOUT_F_TURNOUT;
|
|
|
|
|
else turnouts[i].flags &= ~TURNOUT_F_TURNOUT;
|
|
|
|
|
}
|
|
|
|
|
debug (0, "Turnout::SetFromBus Name:%s Flags:%d[%c%c%c]", turnouts[i].name, turnouts[i].flags,
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_INVERSE) ? 'I' : '-',
|
|
|
|
|
debug (0, "%s:%d Turnout::SetFromBus Name:%s Flags:%d[%c%c%c%c]", __FILE__, __LINE__, turnouts[i].name, turnouts[i].flags,
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_ISRELAIS) ? 'R' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_TURNOUT) ? 'T' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_ACTIVE) ? 'A' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_TURNOUT) ? 'T' : '-');
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_INVERSE) ? 'I' : '-');
|
|
|
|
|
|
|
|
|
|
jp.AddObject("turnout", _GetJSON(i));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
@ -248,11 +263,13 @@ void Turnouts::SetFromBus(string ifname, int addr, int value) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// this loop is important: Turnout motors needs to be deactivated after a short time
|
|
|
|
|
//
|
|
|
|
|
/*
|
|
|
|
|
* this loop is important: some outputs especially motors needs to be deactivated
|
|
|
|
|
* after a short period of time.
|
|
|
|
|
*/
|
|
|
|
|
void Turnouts::Loop() {
|
|
|
|
|
int i;
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
struct timeval curtime;
|
|
|
|
|
|
|
|
|
|
gettimeofday(&curtime, NULL);
|
|
|
|
@ -260,9 +277,9 @@ void Turnouts::Loop() {
|
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < max; i++) if (turnouts[i].name[0] != 0) {
|
|
|
|
|
if (turnouts[i].flags & TURNOUT_F_ACTIVE) {
|
|
|
|
|
if ((turnouts[i].flags & TURNOUT_F_ACTIVE) && ((turnouts[i].flags & TURNOUT_F_ISRELAIS) == 0)) {
|
|
|
|
|
//
|
|
|
|
|
// motor still active check timeout and deactivate
|
|
|
|
|
// motor/output still active check timeout and deactivate
|
|
|
|
|
int timediff = (1000 * (curtime.tv_sec - turnouts[i].activatetime.tv_sec)) +
|
|
|
|
|
((curtime.tv_usec - turnouts[i].activatetime.tv_usec) / 1000);
|
|
|
|
|
if (timediff < 0) gettimeofday (&turnouts[i].activatetime, NULL);
|
|
|
|
@ -270,12 +287,25 @@ void Turnouts::Loop() {
|
|
|
|
|
// debug (0, "%s:%d timediff: %d", __FILE__, __LINE__, timediff);
|
|
|
|
|
|
|
|
|
|
if (timediff > turnouts[i].activetimeout) {
|
|
|
|
|
int active = turnouts[i].flags & TURNOUT_F_TURNOUT;
|
|
|
|
|
int turnout = (turnouts[i].flags & TURNOUT_F_TURNOUT) != 0 ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
debug (0, "%s:%d Turnout::Loop Name:%s Flags:%d[%c%c%c%c] Turnout:%d", __FILE__, __LINE__, turnouts[i].name, turnouts[i].flags,
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_ISRELAIS) ? 'R' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_TURNOUT) ? 'T' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_ACTIVE) ? 'A' : '-',
|
|
|
|
|
(turnouts[i].flags & TURNOUT_F_INVERSE) ? 'I' : '-',
|
|
|
|
|
turnout);
|
|
|
|
|
|
|
|
|
|
if (turnouts[i].flags & TURNOUT_F_INVERSE)
|
|
|
|
|
server->interfaces.SetTurnout(&turnouts[i], !active, 0); // motor on
|
|
|
|
|
server->interfaces.SetTurnout(&turnouts[i], !turnout, 0); // motor on
|
|
|
|
|
else
|
|
|
|
|
server->interfaces.SetTurnout(&turnouts[i], active, 0); // motor on
|
|
|
|
|
server->interfaces.SetTurnout(&turnouts[i], turnout, 0); // motor on
|
|
|
|
|
|
|
|
|
|
turnouts[i].flags &= ~TURNOUT_F_ACTIVE;
|
|
|
|
|
|
|
|
|
|
jp.Clear();
|
|
|
|
|
jp.AddObject("turnout", _GetJSON(i));
|
|
|
|
|
if (network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|