diff --git a/server/interface-z21.cc b/server/interface-z21.cc
index 8145a7b..df46ac0 100644
--- a/server/interface-z21.cc
+++ b/server/interface-z21.cc
@@ -410,8 +410,6 @@ void InterfaceZ21::SetLocoFunction(Locomotive *l, int func, int value) {
void InterfaceZ21::SetTurnout(Turnout *t, int activate, int motoractive) {
unsigned char buffer[] = { 0x09, 0x00, 0x40, 0x00, 0x53, 0x00, 0x00, 0x00, 0x00 };
- debug (0, "%s:%d InterfaceZ21::SetTurnout (a:%d, m:%d)", __FILE__, __LINE__, activate, motoractive);
-
//
// setup turnout addr
buffer[Z21_IDX_SETTURNOUT_ADRL] = (unsigned char) (t->addr & 0xFF);
diff --git a/server/interface-z21.h b/server/interface-z21.h
index 589afea..a589988 100644
--- a/server/interface-z21.h
+++ b/server/interface-z21.h
@@ -15,10 +15,10 @@
#define INTF_Z21_CS_ShortCircuit 0x04
#define INTF_Z21_CS_ProgModeActive 0x20
-#define INTF_Z21_LOCONET_MAXADDR 255
+#define INTF_Z21_LOCONET_MAXADDR 255
#define INTF_Z21_RMSENSOR_GROUPS 2
-#define INTF_Z21_RMSENSOR_BYTES 10
-#define INTF_Z21_RMGETDATA_TIMEOUT 30
+#define INTF_Z21_RMSENSOR_BYTES 10
+#define INTF_Z21_RMGETDATA_TIMEOUT 30
struct s_loconet_map{
int addr;
diff --git a/server/interface.cc b/server/interface.cc
index 0be242e..601b1a7 100644
--- a/server/interface.cc
+++ b/server/interface.cc
@@ -15,6 +15,7 @@ Interface::Interface() {
flags = 0;
type = INTF_T_OFF_UNKNOWN;
needs_update = true;
+ timer_start(&turnouttimeout);
};
Interface::~Interface() {
@@ -57,6 +58,12 @@ void Interface::SetTurnout(Turnout *t, int active, int motoractive) {
debug (DEBUG_INFO | DEBUG_IFACE, "* Interface (%s) SetTurnout Addr:%d FinalAcitve:%d Motor:%d", name,
t->addr, active, motoractive);
+ if (motoractive == 1 && timer_get(&turnouttimeout) < 100) {
+ debug (0, "* Interface need to wait between two turnout commands");
+ return;
+ }
+ timer_start(&turnouttimeout);
+
switch (type) {
case INTF_T_Z21: intz21.SetTurnout(t, active, motoractive); break;
default: break;
diff --git a/server/interface.h b/server/interface.h
index 3ded1c6..b259310 100644
--- a/server/interface.h
+++ b/server/interface.h
@@ -23,6 +23,7 @@ class Interface {
private:
InterfaceZ21 intz21;
bool needs_update;
+ struct timeval turnouttimeout;
public:
char name[REFERENCENAME_LEN];
char host[NET_HOSTLEN];
diff --git a/server/locomotive.cc b/server/locomotive.cc
index 462af97..b41c730 100644
--- a/server/locomotive.cc
+++ b/server/locomotive.cc
@@ -614,7 +614,8 @@ int Locomotives::Loop() {
// find way, if nothing found check if we can reverse direction
//
if (loco->auto_timenext.tv_sec == 0 || timer_get(&loco->auto_timenext) > LOCO_TO_TRYAGAIN) {
- debug (0, "* Loco Loop Search '%s' Reverse:%d", loco->name, reverse);;
+ debug (0, "* Loco Loop Search '%s' Reverse:%d", loco->name, reverse);
+ timer_start(&loco->auto_timenext);
if (loco->blockdest[0] == 0) {
if (loco->flags & LOCO_F_RANDOM)
if (server->railways.FindRandomWay(loco->blockassign, loco->name, &way)) {
@@ -628,7 +629,6 @@ int Locomotives::Loop() {
}
else {
server->railways.UnLockWay(way, loco->name);
- timer_start(&loco->auto_timenext);
}
}
}
@@ -641,7 +641,6 @@ int Locomotives::Loop() {
if (loco->flags & LOCO_F_REVERSE) loco->flags &= ~LOCO_F_REVERSE;
else loco->flags |= LOCO_F_REVERSE;
}
- timer_start(&loco->auto_timenext);
}
}
else if (server->railways.FindWay(loco->blockassign, loco->blockdest, loco->name, &way)) {
diff --git a/server/railway.cc b/server/railway.cc
index b1a407d..d73e97c 100644
--- a/server/railway.cc
+++ b/server/railway.cc
@@ -1064,7 +1064,7 @@ int Railways::LockWay (string way, string lockedby, int lockonoff) {
printf ("LockWay Position [%d,%d] Name:%s LockedBy:'%s'\n", pos.x, pos.y, r->name, r->lockedby);
// check if railway is free or locked by me
- if (r->lockedby[0] != 0 && lockedby.compare(r->lockedby) != 0) {
+ if (r->lockedby[0] != 0 && lockedby.compare(r->lockedby) != 0 && !(lockonoff == 0 && pos.x == start.x && pos.y == start.y && r->type == RAILWAY_BLOCK)) {
debug (0, "LockWay: Railway currently locked by '%s'.", r->lockedby);
UnLock();
return 0;
diff --git a/server/server.cc b/server/server.cc
index f362b85..bfc7b38 100644
--- a/server/server.cc
+++ b/server/server.cc
@@ -117,12 +117,12 @@ void Server::ThreadProcess() {
//
// mode manual
else if (mode == SMODE_MANUAL) {
- server->locomotives.Loop();
}
//
// mode auto
else if (mode == SMODE_AUTO) {
+ server->locomotives.Loop();
}
gettimeofday (&tv, NULL);
@@ -185,7 +185,10 @@ bool Server::IsChanged() {
// Set Mode Auto
void Server::SetModeAuto() {
debug (0, "%s:%d * Set Mode Auto", __FILE__, __LINE__);
- status_text = "Mode Auto";
+ if (mode == SMODE_MANUAL) {
+ mode = SMODE_MANUAL;
+ status_text = "Mode Auto";
+ }
}
//
diff --git a/server/session.cc b/server/session.cc
index 35a885b..9cbe213 100644
--- a/server/session.cc
+++ b/server/session.cc
@@ -160,10 +160,18 @@ int Session::ProcessData(JSONParse *jin, JSONParse *jout) {
debug (0, "* Save All");
server->Save();
}
- else if (command.compare("resetdata") == 0) {
- debug (0, "* Reset All Data");
+ else if (command.compare("serverreset") == 0) {
+ debug (0, "* Server Set to Reset");
server->SetModeReset();
}
+ else if (command.compare("servermanual") == 0) {
+ debug (0, "* Server Set to Manual");
+ server->SetModeManual();
+ }
+ else if (command.compare("serverauto") == 0) {
+ debug (0, "* Server Set to Auto");
+ server->SetModeAuto();
+ }
else if (command.compare("getall") == 0) {
json.Clear();
server->GetJSONAll(&json);
diff --git a/webinterface/images/btnauto.png b/webinterface/images/btnauto.png
new file mode 100644
index 0000000..6d7ca6f
Binary files /dev/null and b/webinterface/images/btnauto.png differ
diff --git a/webinterface/images/btnmanual.png b/webinterface/images/btnmanual.png
new file mode 100644
index 0000000..7181cb7
Binary files /dev/null and b/webinterface/images/btnmanual.png differ
diff --git a/webinterface/index.html b/webinterface/index.html
index 8645ee3..22ab410 100644
--- a/webinterface/index.html
+++ b/webinterface/index.html
@@ -52,26 +52,32 @@
-
+
+
+
+
+