|
|
|
|
@ -59,7 +59,7 @@ InterfaceZ21::~InterfaceZ21() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InterfaceZ21::Connect () {
|
|
|
|
|
debug (DEBUG_INFO | DEBUG_IFACE, "InterfaceZ21: Connect to: %s", host);
|
|
|
|
|
debug (DEBUG_INFO | DEBUG_IFACE, "InterfaceZ21: Connect %s to: %s", name, host);
|
|
|
|
|
|
|
|
|
|
if (status_connected) Disconnect();
|
|
|
|
|
|
|
|
|
|
@ -99,12 +99,11 @@ void InterfaceZ21::Disconnect() {
|
|
|
|
|
//
|
|
|
|
|
// check if we are connected and for timeouts.
|
|
|
|
|
// read and go through incoming data
|
|
|
|
|
int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
int InterfaceZ21::Loop() {
|
|
|
|
|
time_t curtime = time(NULL);
|
|
|
|
|
string source;
|
|
|
|
|
int inlen;
|
|
|
|
|
int i;
|
|
|
|
|
int needs_update = false;
|
|
|
|
|
|
|
|
|
|
// debug (DEBUG_INFO | DEBUG_IFACE, "* InterfaceZ21 (%s) Loop", name);
|
|
|
|
|
|
|
|
|
|
@ -145,7 +144,7 @@ int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
if ((inlen = udp.ReadTimeout(&source, inbuffer, INTF_Z21_INBUFFER, 10)) > 0) {
|
|
|
|
|
//
|
|
|
|
|
// got some data
|
|
|
|
|
|
|
|
|
|
debug (DEBUG_INFO | DEBUG_IFACE, "%s:%d [%s] got some data.", __FILE__, __LINE__, name);
|
|
|
|
|
//
|
|
|
|
|
// check for LAN_SYSTEMSTATE_DATACHANGED
|
|
|
|
|
if (memcmp (inbuffer, RX_GET_SERIAL_NUMBER, sizeof(RX_GET_SERIAL_NUMBER)) == 0) {
|
|
|
|
|
@ -162,9 +161,9 @@ int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
debug (0, "%s:%d Interface-Z21: TurnoutInformation Addr:%d", __FILE__, __LINE__, addr);
|
|
|
|
|
|
|
|
|
|
if (inbuffer[Z21_IDX_SETTURNOUT_MODE] == 2)
|
|
|
|
|
server->TurnoutAddrMode(interfacename, addr, 1);
|
|
|
|
|
server->TurnoutAddrMode(name, addr, 1);
|
|
|
|
|
else if (inbuffer[Z21_IDX_SETTURNOUT_MODE] == 1)
|
|
|
|
|
server->TurnoutAddrMode(interfacename, addr, 0);
|
|
|
|
|
server->TurnoutAddrMode(name, addr, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -180,7 +179,7 @@ int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
status_shortcircuit = (cs & INTF_Z21_CS_ShortCircuit);
|
|
|
|
|
status_programmingmode = (cs & INTF_Z21_CS_ProgModeActive);
|
|
|
|
|
|
|
|
|
|
debug (0, "%s:%d cs:%d csex:%d", __FILE__, __LINE__, cs, csex);
|
|
|
|
|
debug (0, "%s:%d Name:%s cs:%d csex:%d", __FILE__, __LINE__, name, cs, csex);
|
|
|
|
|
|
|
|
|
|
needs_update = true;
|
|
|
|
|
//if ( old_poweron != status_poweron ||
|
|
|
|
|
@ -219,7 +218,7 @@ int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
debug (0, "%s:%d Loc:%d Speed:%d", __FILE__, __LINE__, loconet_map[inloc].addr, inspeed);
|
|
|
|
|
if (loconet_map[inloc].addr > 0) {
|
|
|
|
|
int speed = inspeed;
|
|
|
|
|
server->LocomotiveAddrSpeed(interfacename, loconet_map[inloc].addr, speed);
|
|
|
|
|
server->LocomotiveAddrSpeed(name, loconet_map[inloc].addr, speed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
loconet_last.addr = 0;
|
|
|
|
|
@ -238,7 +237,7 @@ int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
|
|
|
|
|
debug (0, "%s:%d Loc:%d Function:%d", __FILE__, __LINE__, loconet_map[inloc].addr, infunc);
|
|
|
|
|
if (loconet_map[inloc].addr > 0) {
|
|
|
|
|
server->LocomotiveAddrFunction(interfacename, loconet_map[inloc].addr, infunc);
|
|
|
|
|
server->LocomotiveAddrFunction(name, loconet_map[inloc].addr, infunc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loconet_last.addr = 0;
|
|
|
|
|
@ -251,7 +250,7 @@ int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
int group = (unsigned char)inbuffer[4];
|
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
|
|
printf ("LAN_RMBUS_DATA_CHANGE[%s] ", interfacename.c_str());
|
|
|
|
|
printf ("LAN_RMBUS_DATA_CHANGE[%s] ", name);
|
|
|
|
|
for (idx = 0; idx < INTF_Z21_RMSENSOR_BYTES * INTF_Z21_RMSENSOR_GROUPS; idx++) {
|
|
|
|
|
printf ("%x ", (unsigned char) inbuffer[4+idx]);
|
|
|
|
|
}
|
|
|
|
|
@ -268,9 +267,9 @@ int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
for (idx = 0; idx < INTF_Z21_RMSENSOR_GROUPS*INTF_Z21_RMSENSOR_BYTES; idx++) {
|
|
|
|
|
if (rmsold[idx]^rmsensors[idx]) {
|
|
|
|
|
for (i = 0; i < 8; i++) if (rmsensorinit || (rmsold[idx] & 1 << i) != (rmsensors[idx] & 1 << i)) {
|
|
|
|
|
debug (0, "Sendor Data Changed: %s[%d]", interfacename.c_str(), idx*8+i);
|
|
|
|
|
if (rmsensors[idx] & 1 << i) server->SensorAddrChange(interfacename, idx*8+i, 1);
|
|
|
|
|
else server->SensorAddrChange(interfacename, idx*8+i, 0);
|
|
|
|
|
debug (0, "Sendor Data Changed: %s[%d]", name, idx*8+i);
|
|
|
|
|
if (rmsensors[idx] & 1 << i) server->SensorAddrChange(name, idx*8+i, 1);
|
|
|
|
|
else server->SensorAddrChange(name, idx*8+i, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -279,7 +278,7 @@ int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
printf ("InterfaceZ21(%s) Got some Data:", interfacename.c_str());
|
|
|
|
|
printf ("InterfaceZ21(%s) Got some Data:", name);
|
|
|
|
|
for (i = 0; i < inlen; i++) {
|
|
|
|
|
int z = (unsigned char) inbuffer[i];
|
|
|
|
|
printf ("%02x:", z);
|
|
|
|
|
@ -295,6 +294,11 @@ int InterfaceZ21::Loop(string interfacename) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsConnected()) flags |= INTF_F_CONNECTED;
|
|
|
|
|
if (IsPoweron()) flags |= INTF_F_POWER;
|
|
|
|
|
if (IsEmergencyStop()) flags |= INTF_F_STOP;
|
|
|
|
|
if (IsSortCircuit()) flags |= INTF_F_SHORT_CIRCUIT;
|
|
|
|
|
|
|
|
|
|
return needs_update;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -456,7 +460,7 @@ void InterfaceZ21::SetTurnout(Turnout *t, int activate, int outputactive) {
|
|
|
|
|
// send_X_SET_TRACK_POWER_ON(); send_X_SET_TRACK_POWER_ON();
|
|
|
|
|
void InterfaceZ21::PowerOnOff(int onoff) {
|
|
|
|
|
if (status_connected == false) return;
|
|
|
|
|
|
|
|
|
|
debug (DEBUG_INFO | DEBUG_IFACE, "InterfaceZ21::PowerOnOff onoff:%d", onoff);
|
|
|
|
|
if (onoff) {
|
|
|
|
|
udp.Write(host, (char*)TX_X_SET_TRACK_POWER_ON, sizeof (TX_X_SET_TRACK_POWER_ON));
|
|
|
|
|
}
|
|
|
|
|
|