From 0a446a26df12f94f1c425b8ad754ce665232560c Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Tue, 8 Mar 2022 21:14:14 +0100 Subject: [PATCH] fixing stuff. The child class did not work as expexted. --- server/interface-z21.cc | 34 +++++++++++++++++++--------------- server/interface-z21.h | 2 +- server/interface.cc | 20 ++++++++++++++++++++ server/interface.h | 5 ++++- webinterface/interface.js | 2 +- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/server/interface-z21.cc b/server/interface-z21.cc index fba3864..ef3fe96 100644 --- a/server/interface-z21.cc +++ b/server/interface-z21.cc @@ -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)); } diff --git a/server/interface-z21.h b/server/interface-z21.h index 75750ec..47eeef6 100644 --- a/server/interface-z21.h +++ b/server/interface-z21.h @@ -70,7 +70,7 @@ class InterfaceZ21: public Interface { bool IsProgramminnMode() { return status_programmingmode; }; bool IsEmergencyStop() { return status_emergencystop; }; - int Loop(string interfacename); + int Loop(); void PowerOnOff(int onoff); void SetLocoSpeed(Locomotive *l, int step); void SetLocoFunction(Locomotive *l, int func, int value); diff --git a/server/interface.cc b/server/interface.cc index e4bfead..b1f8dcc 100644 --- a/server/interface.cc +++ b/server/interface.cc @@ -93,3 +93,23 @@ bool Interface::IsPoweron() { return ret; } + +bool Interface::IsSortCircuit() { + bool ret = false; + debug (DEBUG_INFO | DEBUG_IFACE, "* Interface (%s) IsSortCircuit", name); + return ret; +} + +bool Interface::IsProgramminnMode() { + bool ret = false; + debug (DEBUG_INFO | DEBUG_IFACE, "* Interface (%s) IsProgramminnMode", name); + return ret; +} + +bool Interface::IsEmergencyStop() { + bool ret = false; + debug (DEBUG_INFO | DEBUG_IFACE, "* Interface (%s) IsEmergencyStop", name); + return ret; +} + + diff --git a/server/interface.h b/server/interface.h index 1576366..04dea12 100644 --- a/server/interface.h +++ b/server/interface.h @@ -17,8 +17,8 @@ class Interface { private: - bool needs_update; public: + bool needs_update; char name[REFERENCENAME_LEN]; char host[NET_HOSTLEN]; int flags; @@ -37,6 +37,9 @@ public: virtual bool IsConnected(); virtual bool IsPoweron(); + virtual bool IsSortCircuit(); + virtual bool IsProgramminnMode(); + virtual bool IsEmergencyStop(); virtual int Loop(); }; diff --git a/webinterface/interface.js b/webinterface/interface.js index c8caf6f..6ab9579 100644 --- a/webinterface/interface.js +++ b/webinterface/interface.js @@ -10,7 +10,7 @@ var interfaces = []; function interface_Update(intdata) { for (var i = 0; i < interfaces.length; i++) { if (intdata.name == interfaces[i].name) { - //debug ("Update Interface:" + interfaces[i].name + "(" + interfaces[i].host + ") with Interface:" + intdata.name + "(" + intdata.host + ")"); + debug ("Update Interface:" + interfaces[i].name + "(" + interfaces[i].host + ") with Interface:" + intdata.name + "(" + intdata.host + ") Flags:" + intdata.flags); if (!(intdata.flags & 0x0001)) sideBtnOnOffMode (3); // not connected else if ((intdata.flags & 0x0010)) sideBtnOnOffMode (3); // programming mode