From 25a6b63541a5b15e5bc1d9b36890f6d5837db358 Mon Sep 17 00:00:00 2001 From: steffen Date: Sat, 16 Jan 2021 22:49:58 +0000 Subject: [PATCH] updates --- ChangeLog | 4 ++ server/block.cc | 15 +++++ server/block.h | 13 +++- server/locomotive.h | 33 +++++---- server/main.cc | 4 +- server/network.cc | 26 +++++++- server/network.h | 8 +++ server/railway.cc | 4 +- server/railway.h | 2 +- server/server-loadsave.cc | 13 ++++ server/server.cc | 27 +++++++- server/server.h | 12 ++++ server/session.cc | 130 +++++++++++++++++++++++++++++++++--- server/turnout.cc | 1 + server/turnout.h | 2 + webinterface/block.js | 22 ++++-- webinterface/locomotive.js | 78 +++++++++++++++++++--- webinterface/railways.js | 37 ++++++++-- webinterface/sensor.js | 8 ++- webinterface/serverinout.js | 15 +++++ webinterface/track.js | 4 +- 21 files changed, 408 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f3e370..b9ebf11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-01-15: - web interface for block assignemt seems ready +- saving and loading data from a block. +:q +:q +:q! 2020-12-05: - locomotive fixed division by zero diff --git a/server/block.cc b/server/block.cc index 660dbb7..0663820 100644 --- a/server/block.cc +++ b/server/block.cc @@ -40,6 +40,7 @@ JSONParse Blocks::_GetJSON(int idx) { s = blocks[idx].name; json.AddObject("name", s); json.AddObject("flags", blocks[idx].flags); + json.AddObject("lockedby", blocks[idx].lockedby); return json; }; @@ -150,3 +151,17 @@ int Blocks::Delete(string name) { }; +int Blocks::SetOff(string name) { + JSONParse jp; + +// jp.AddObject("block", _GetJSON(i)); +// if(network) network->ChangeListPushToAll(jp.ToString()); + + return 1; +}; + + +int Blocks::Clear(string name) { + return 1; +}; + diff --git a/server/block.h b/server/block.h index 0638783..90936b4 100644 --- a/server/block.h +++ b/server/block.h @@ -5,11 +5,19 @@ #include "modelbahn.h" #include "server.h" -#define BLOCKF_SHORTTRAIN 0x0001 +#define BLOCK_F_SHORT 0x0001 +#define BLOCK_F_LONG 0x0002 +#define BLOCK_F_ENDSTATION 0x0010 +#define BLOCK_F_SPEEDLIMIT 0x0100 + struct s_Block { char name[REFERENCENAME_LEN]; + char s_pos_1[REFERENCENAME_LEN]; + char s_neg_1[REFERENCENAME_LEN]; int flags; + + char lockedby[REFERENCENAME_LEN]; // element locked by locreference (only set by server, not by JSON/Webinterface) } typedef Block; class Blocks { @@ -37,6 +45,9 @@ class Blocks { JSONParse GetJSON(string name); void GetJSONAll(JSONParse *json); Block GetBlockFromJSON(JSONParse *j); + + int SetOff(string name); + int Clear(string name); }; #endif diff --git a/server/locomotive.h b/server/locomotive.h index 792c6ae..096f09f 100644 --- a/server/locomotive.h +++ b/server/locomotive.h @@ -6,6 +6,9 @@ #include "server.h" #define LOCO_F_REVERSE 0x0001 +#define LOCO_F_CARGO 0x0002 +#define LOCO_F_AUTO 0x0100 +#define LOCO_F_RANDOM 0x0200 enum { LOCO_INT_UNDEF = 0, @@ -15,18 +18,24 @@ enum { }; struct s_Locomotive { - char name[REFERENCENAME_LEN]; - char ifname[REFERENCENAME_LEN]; - int stepcode; - int speed; - int64_t func; - int flags; - int addr; - int vmin; - int vslow; - int vmid; - int vfast; - int vmax; + char name[REFERENCENAME_LEN]; // name + char ifname[REFERENCENAME_LEN]; // ref. of interface + int addr; // address on bus + int stepcode; // stepcoding LOCO_INT_DCC... + int flags; // flags + int vmin; // speed - below this we always set 0 + int vslow; // speed - slow entry in trainstation + int vmid; // speed - for normal trains (max for cargo trains, on automode) + int vfast; // speed - for normal trains + int vmax; // speed - maximum speed + + // dynamic data + int speed; // current speed + int64_t func; // function enabled ... light... + char blockassign; // currently assigned block [+BLOCKREFNAME ... -BLOCKREFNAME] + char blocknext; // next block to go to + char blockprev; // prev block (mostly assigned block + char blockdestination; // destination block } typedef Locomotive; class Locomotives { diff --git a/server/main.cc b/server/main.cc index 4865256..eb472de 100644 --- a/server/main.cc +++ b/server/main.cc @@ -62,9 +62,11 @@ int main (int argc, char **argv) { // debug (0, "* application loop"); server->Start(); + debug (0, "* server thread started"); network->Start(); + debug (0, "* network thread started"); while (running) { - sleep (1); + usleep (1000000); } ////////////////////////////////////////////////////////////////////// diff --git a/server/network.cc b/server/network.cc index 1ebd98f..46da3a6 100644 --- a/server/network.cc +++ b/server/network.cc @@ -63,6 +63,16 @@ void Network::ThreadProcess() { list::iterator iteru; Session *s; UNIX *u; + int i = 0; + + int timeout10s; + int cycletime_max = 0; + int cyclelooptime_max = 0; + struct timeval tv_loop, tv; + + gettimeofday (&tv, NULL); + gettimeofday (&tv_loop, NULL); + timeout10s = tv.tv_sec + 10; while (running) { // @@ -83,7 +93,21 @@ void Network::ThreadProcess() { } } - usleep (100000); + gettimeofday (&tv, NULL); + i = (tv.tv_sec-tv_loop.tv_sec) * 1000 + (tv.tv_usec - tv_loop.tv_usec) / 1000; + if (i > cycletime_max) cycletime_max = i; + if (i < 1000 && i > 0) usleep (100000 - i*1000); + gettimeofday (&tv, NULL); + i = (tv.tv_sec-tv_loop.tv_sec) * 1000 + (tv.tv_usec - tv_loop.tv_usec) / 1000; + if (i > cyclelooptime_max) cyclelooptime_max = i; + + if (tv_loop.tv_sec > timeout10s) { + timeout10s = tv.tv_sec + 10; + debug (DEBUG_INFO, "Network::ThreadProcess max Cycletime: %dms Cyclelooptime:%dms", cycletime_max, cyclelooptime_max); + cycletime_max = 0; + cyclelooptime_max = 0; + } + tv_loop = tv; } thread_running = 0; }; diff --git a/server/network.h b/server/network.h index 1881a46..bb29eaa 100644 --- a/server/network.h +++ b/server/network.h @@ -55,6 +55,14 @@ private: void AddJSONLocomotive(JSONParse *jp); void DelJSONLocomotive(JSONParse *jp); void SetJSONLocomotive(JSONParse *jp); + void SetJSONLocoDest(JSONParse *jp); + void SetJSONLocoAssign(JSONParse *jp); + + void BlockJSONOff(JSONParse *jp); + void BlockJSONClear(JSONParse *jp); + void AddJSONBlock(JSONParse *jp); + void DelJSONBlock(JSONParse *jp); + public: Session(int rid); diff --git a/server/railway.cc b/server/railway.cc index baa7bb2..8764a8a 100644 --- a/server/railway.cc +++ b/server/railway.cc @@ -72,10 +72,10 @@ JSONParse Railways::_GetJSONRailway(int x, int y) { json.AddObject("type", railways[idx].type); json.AddObject("maxspeed", railways[idx].maxspeed); json.AddObject("flags", railways[idx].flags); - text = railways[idx].name; - json.AddObject("name", text); text = railways[idx].lockedby; json.AddObject("lockedby", text); + text = railways[idx].name; + json.AddObject("name", text); return json; }; diff --git a/server/railway.h b/server/railway.h index 432ed46..035e308 100644 --- a/server/railway.h +++ b/server/railway.h @@ -51,7 +51,7 @@ struct s_Railway { int maxspeed; int flags; // not defined yet char name[REFERENCENAME_LEN]; // reference name - char lockedby[REFERENCENAME_LEN]; // element locked by locreference + char lockedby[REFERENCENAME_LEN]; // element locked by locreference (only set by server, not by JSON/Webinterface) } typedef Railway; diff --git a/server/server-loadsave.cc b/server/server-loadsave.cc index bc21f0a..bd402fb 100644 --- a/server/server-loadsave.cc +++ b/server/server-loadsave.cc @@ -138,6 +138,15 @@ int Server::Load(string fn) { } + // + // read blocks + Block bl; + for (i = 0; json.GetObjectIdx("blocks", i, &jtmp); i++) { + bl = blocks.GetBlockFromJSON(&jtmp); + blocks.Change(&bl); + } + + railways.ClearChanged(); return 1; }; @@ -182,6 +191,10 @@ int Server::Save(string fn) { // write all turnouts turnouts.GetJSONAll(&json); + // + // write all turnouts + blocks.GetJSONAll(&json); + f = fopen (fn.c_str(), "w"); fprintf (f, "%s", json.ToString().c_str()); diff --git a/server/server.cc b/server/server.cc index f20fdd5..506660d 100644 --- a/server/server.cc +++ b/server/server.cc @@ -65,6 +65,16 @@ Server::~Server() { // most important in each cycle there will be void Server::ThreadProcess() { int i = 0; + + int timeout10s; + int cyclelooptime_max = 0; + int cycletime_max = 0; + struct timeval tv_loop, tv; + + gettimeofday (&tv, NULL); + gettimeofday (&tv_loop, NULL); + timeout10s = tv.tv_sec + 10; + while (running) { interfaces.Loop(); turnouts.Loop(); @@ -90,7 +100,21 @@ void Server::ThreadProcess() { else if (mode == SMODE_AUTO) { } - usleep (25000); + gettimeofday (&tv, NULL); + i = (tv.tv_sec-tv_loop.tv_sec) * 1000 + (tv.tv_usec - tv_loop.tv_usec) / 1000; + if (i > cycletime_max) cycletime_max = i; + if (i < 25000 && i > 0) usleep (25000 - i*1000); + gettimeofday (&tv, NULL); + i = (tv.tv_sec-tv_loop.tv_sec) * 1000 + (tv.tv_usec - tv_loop.tv_usec) / 1000; + if (i > cyclelooptime_max) cyclelooptime_max = i; + + if (tv_loop.tv_sec > timeout10s) { + timeout10s = tv.tv_sec + 10; + debug (DEBUG_INFO, "Server::ThreadProcess max Cycletime: %dms Cyclelooptime:%dms", cycletime_max, cyclelooptime_max); + cycletime_max = 0; + cyclelooptime_max = 0; + } + tv_loop = tv; } debug (0, "Server::ThreadProcess Finished"); thread_running = 0; @@ -118,6 +142,7 @@ void Server::GetJSONAll(JSONParse *json) { sensors.GetJSONAll(json); locomotives.GetJSONAll(json); turnouts.GetJSONAll(json); + blocks.GetJSONAll(json); } diff --git a/server/server.h b/server/server.h index 62dd65f..bd3a046 100644 --- a/server/server.h +++ b/server/server.h @@ -28,6 +28,7 @@ #include "locomotive.h" #include "sensor.h" #include "interface.h" +#include "block.h" enum SMODE { SMODE_STARTUP, @@ -74,6 +75,7 @@ private: Railways railways; Locomotives locomotives; Interfaces interfaces; + Blocks blocks; void ThreadProcess(); void LoopCheckChanges(); @@ -87,6 +89,7 @@ private: friend class Locomotives; friend class Sensors; friend class Turnouts; + friend class Blocks; public: ///////////////////////////////////////// // functions here are required to be thread save @@ -165,6 +168,15 @@ public: JSONParse SensorGetJSON(string name) { return sensors.GetJSON(name); }; int SensorDelete(string name) { return sensors.Delete(name); }; + ///////////////////////////////////////// + // Blocks + int BlockChange(Block *s) { return blocks.Change(s); }; + Block BlockFromJSON(JSONParse *j) { return blocks.GetBlockFromJSON(j); }; + JSONParse BlockGetJSON(string name) { return blocks.GetJSON(name); }; + int BlockDelete(string name) { return blocks.Delete(name); }; + int BlockSetOff(string name) { return blocks.SetOff(name); }; + int BlockClear(string name) { return blocks.Clear(name); }; + void GetJSONAll(JSONParse *json); ///////////////////////////////////////// diff --git a/server/session.cc b/server/session.cc index 81d4da1..3044577 100644 --- a/server/session.cc +++ b/server/session.cc @@ -43,6 +43,7 @@ int Session::ProcessData(JSONParse *jin, JSONParse *jout) { // editing elements // debug (0, "%s:%d JIN:%s", __FILE__, __LINE__, jin->ToString().c_str()); + if (command.compare("addrailway") == 0) { debug (0, "* Session Add Railways"); AddJSONRailway(jin); @@ -67,6 +68,10 @@ int Session::ProcessData(JSONParse *jin, JSONParse *jout) { debug (0, "* Session del Sensor"); DelJSONSensor(jin); } + + // + // turnouts + // else if (command.compare("addturnout") == 0) { debug (0, "* Session Add Turnout"); AddJSONTurnout(jin); @@ -75,6 +80,32 @@ int Session::ProcessData(JSONParse *jin, JSONParse *jout) { debug (0, "* Session Del Turnout"); DelJSONTurnout(jin); } + else if (command.compare("setturnout") == 0) { + SetJSONTurnout(jin); + } + + // + // Blocks + // + else if (command.compare("addblock") == 0) { + debug (0, "* Session Add Block"); + AddJSONBlock(jin); + } + else if (command.compare("delblock") == 0) { + debug (0, "* Session Del Block"); + DelJSONBlock(jin); + } + else if (command.compare("blockoff") == 0) { + BlockJSONOff(jin); + } + else if (command.compare("blockclear") == 0) { + BlockJSONClear(jin); + } + + + // + // Locomotive + // else if (command.compare("addlocomotive") == 0) { debug (0, "* Session Add Locomotive"); AddJSONLocomotive(jin); @@ -83,21 +114,18 @@ int Session::ProcessData(JSONParse *jin, JSONParse *jout) { debug (0, "* Session Del Locomotive"); DelJSONLocomotive(jin); } - - // - // locomotives - // else if (command.compare("setlocomotive") == 0) { SetJSONLocomotive(jin); } - // - // locomotives - // - else if (command.compare("setturnout") == 0) { - SetJSONTurnout(jin); + else if (command.compare("locomotivedestination") == 0) { + SetJSONLocoDest(jin); } + else if (command.compare("locomotiveassign") == 0) { + SetJSONLocoAssign(jin); + } + // - // poweron / poweroff + // poweron / poweroff / save and resetdata // else if (command.compare("poweron") == 0) { debug (0, "* Session Poweron"); @@ -320,7 +348,7 @@ void Session::DelJSONSensor(JSONParse *jp) { jp->GetObject("sensor", &jtmp); se = server->SensorFromJSON(&jtmp); if (se.name[0] != 0) { - debug (0, "%s:%d DelJSONTurnout Element %s", __FILE__, __LINE__, se.name); + debug (0, "%s:%d DelJSONSensor Element %s", __FILE__, __LINE__, se.name); // add element server->SensorDelete(se.name); jout.Clear(); @@ -424,6 +452,16 @@ void Session::DelJSONLocomotive(JSONParse *jp) { }; +void Session::SetJSONLocoDest(JSONParse *jp) { + +}; + + +void Session::SetJSONLocoAssign(JSONParse *jp) { + +}; + + // // add new Turnout // @@ -500,6 +538,76 @@ void Session::SetJSONTurnout(JSONParse *jp) { }; + +// +// add new block +// +void Session::AddJSONBlock(JSONParse *jp) { + Block bl; + JSONParse jtmp; + JSONParse jout; + + server->LockThread(); + jp->GetObject("block", &jtmp); + bl = server->BlockFromJSON(&jtmp); + if (bl.name[0] != 0) { + debug (0, "%s:%d AddJSONBlock Element %s", __FILE__, __LINE__, bl.name); + // add element + server->BlockChange(&bl); + jout.Clear(); + jout.AddObject("block", server->BlockGetJSON(bl.name)); + if (network) network->_ChangeListPushToAll(jout.ToString()); + } + server->UnLockThread(); +}; + + +// +// delete block +// +void Session::DelJSONBlock(JSONParse *jp) { + Block bl; + JSONParse jtmp; + JSONParse jout; + string s; + + server->LockThread(); + + jp->GetObject("block", &jtmp); + bl = server->BlockFromJSON(&jtmp); + if (bl.name[0] != 0) { + debug (0, "%s:%d DelJSONBlock Element %s", __FILE__, __LINE__, bl.name); + // add element + server->BlockDelete(bl.name); + jout.Clear(); + s = bl.name; + jout.AddObject("blockdelete", s); + if (network) network->_ChangeListPushToAll(jout.ToString()); + } + server->UnLockThread(); +}; + + +void Session::BlockJSONOff(JSONParse *jp) { + string s; + + jp->GetValue("block", &s); + server->LockThread(); + server->BlockSetOff(s); + server->UnLockThread(); +}; + +void Session::BlockJSONClear(JSONParse *jp) { + string s; + + jp->GetValue("block", &s); + server->LockThread(); + server->BlockClear(s); + server->UnLockThread(); +}; + + + /* res = json.GetValue("command", &value); if (res && value.compare("addelemens") == 0) { diff --git a/server/turnout.cc b/server/turnout.cc index 53038c5..0631670 100644 --- a/server/turnout.cc +++ b/server/turnout.cc @@ -39,6 +39,7 @@ JSONParse Turnouts::_GetJSON(int idx) { json.AddObject("addr", turnouts[idx].addr); json.AddObject("activetimeout", turnouts[idx].activetimeout); json.AddObject("flags", turnouts[idx].flags); + json.AddObject("lockedby", turnouts[idx].lockedby); return json; }; diff --git a/server/turnout.h b/server/turnout.h index 6afa663..5eda964 100644 --- a/server/turnout.h +++ b/server/turnout.h @@ -18,6 +18,8 @@ struct s_Turnout { int flags; // setup of some flags; int activetimeout; // time in ms // 0 will be set to DEFAULT struct timeval activatetime; // set both to 0 for inactive + + char lockedby[REFERENCENAME_LEN]; // element locked by locreference (only set by server, not by JSON/Webinterface) } typedef Turnout; diff --git a/webinterface/block.js b/webinterface/block.js index 36af14d..6e188f3 100644 --- a/webinterface/block.js +++ b/webinterface/block.js @@ -95,8 +95,9 @@ function block_ctxmenu_DestinationRU (element, value) { function block_ctxmenu_AssignLD (element, value) { let loc = document.getElementById("contextbox_loc"); + let name = document.getElementById("ConextMenuHead").innerHTML; if (loc) { - locomotive_server_Assign(loc.value, element.name, 1); + locomotive_server_Assign(loc.value, name, 1); } gContextmenuClose(); }; @@ -104,20 +105,23 @@ function block_ctxmenu_AssignLD (element, value) { function block_ctxmenu_AssignRU (element, value) { let loc = document.getElementById("contextbox_loc"); + let name = document.getElementById("ConextMenuHead").innerHTML; if (loc) { - locomotive_server_Assign(loc.value, element.name, 0); + locomotive_server_Assign(loc.value, name, 0); } gContextmenuClose(); }; function block_ctxmenu_Clear (element, value) { - block_server_Clear(element.name); + let name = document.getElementById("ConextMenuHead").innerHTML; + block_server_Clear(name); gContextmenuClose(); } function block_ctxmenu_Off (element, value) { - block_server_Off(element.name); + let name = document.getElementById("ConextMenuHead").innerHTML; + block_server_Off(name); gContextmenuClose(); } @@ -154,11 +158,14 @@ function block_server_Clear(blockname) { // function block_server_Off(blockname) { var request = { command: "blockoff", block: blockname }; + debug ("send BlockOff:" + blockname); serverinout (request, serverinout_defaultCallback); }; -function blockdetail_show(name) { +// +// if create is set the name should be filled in +function blockdetail_show(name, create) { var win = document.getElementById("blockdetail"); debug ("blockdetail_show"); @@ -196,6 +203,11 @@ function blockdetail_show(name) { if (name == blocks[i].name) blockdetail_setData(blocks[i]); } } + + if (create) { + let rname = document.getElementById("blockdet_name"); + if (rname.value != name) rname.value = name; + } }; diff --git a/webinterface/locomotive.js b/webinterface/locomotive.js index 7869b99..025605e 100644 --- a/webinterface/locomotive.js +++ b/webinterface/locomotive.js @@ -2,7 +2,10 @@ // // -const LOCO_F_REVERSE = 1; +const LOCO_F_REVERSE = 0x0001; +const LOCO_F_CARGO = 0x0002; +const LOCO_F_AUTO = 0x0100; +const LOCO_F_RANDOM = 0x0200; var locomotives = []; @@ -25,7 +28,10 @@ function locomotive_Update(data) { locomotives[i].vfast = data.vfast; locomotives[i].vmax = data.vmax; locomotives[i].flags = data.flags; - + locomotives[i].blockassign = data.blockassing; + locomotives[i].blockpref = data.blockpref; + locomotives[i].blocknext = data.blocknext; + locomotives[i].blockdestination = data.blockdestination; locodetail_setData(locomotives[i]); lococtrl_setData(data); return; @@ -140,6 +146,14 @@ function locodetail_show(loconame) { Flags: \
\
\ +
\ +
\ +
\ + \ +
\ +
\ + \ +
\ + \
Speed \ \ \ @@ -147,15 +161,23 @@ function locodetail_show(loconame) { \ \ \ -
Stop
Vmin:
Vmid:
Vfast:
Vmax:
Current:
\ + \ + \ \
Code \
\
\
\
\ - Speed:
\ - \ + \ +
Block \ + \ + \ + \ + \ +
Destination:
Assined:
Next:
Prev:
\ + \

\
\ \ @@ -172,6 +194,7 @@ function locodetail_show(loconame) { gAddEventListener("locodet_btnvfast", 'click', locodetail_cb_btnmove); gAddEventListener("locodet_btnvmax", 'click', locodetail_cb_btnmove); gAddEventListener("locodet_reverse", 'click', locodetail_cb_reverse); + gAddEventListener("locodet_cargo", 'click', locodetail_cb_cargo); // gAddEventListener("locodet_DCC14", 'click', locodetail_cb_stepcode); // gAddEventListener("locodet_DCC28", 'click', locodetail_cb_stepcode); @@ -206,11 +229,27 @@ function locodetail_cb_reverse () { var flags = document.getElementById("locodet_flags"); if (cbreverse.checked) { - flags.value = Number(flags.value) | 1; + flags.value = Number(flags.value) | LOCO_F_REVERSE; } else { - flags.value = Number(flags.value) & (0xFFFF-1); + flags.value = Number(flags.value) & (0xFFFF-LOCO_F_REVERSE); + } +}; + + +// +// cargo selected, setup flags +function locodetail_cb_cargo () { + var cbcargo = document.getElementById("locodet_cargo"); + var flags = document.getElementById("locodet_flags"); + + if (cbcargo .checked) { + flags.value = Number(flags.value) | LOCO_F_CARGO; + } + + else { + flags.value = Number(flags.value) & (0xFFFF-LOCO_F_CARGO); } }; @@ -334,6 +373,13 @@ function locodetail_setData(elm) { var loco_vfast = document.getElementById("locodet_vfast"); var loco_vmax = document.getElementById("locodet_vmax"); var loco_reverse = document.getElementById("locodet_reverse"); + var loco_cargo = document.getElementById("locodet_cargo"); + var loco_auto = document.getElementById("locodet_auto"); + var loco_random = document.getElementById("locodet_random"); + var loco_blockassign = document.getElementById("locodet_blockassign"); + var loco_blockdest = document.getElementById("locodet_blockdest"); + var loco_blocknext = document.getElementById("locodet_blocknext"); + var loco_blockprev = document.getElementById("locodet_blockpev"); if (elm) { if (loco_name) loco_name.value = elm.name; @@ -347,9 +393,25 @@ function locodetail_setData(elm) { if (loco_vfast) loco_vfast.value = elm.vfast; if (loco_vmax) loco_vmax.value = elm.vmax; if (loco_reverse) { - if (Number(elm.flags) & 1) loco_reverse.checked = true; + if (Number(elm.flags) & LOCO_F_REVERSE) loco_reverse.checked = true; else loco_reverse.checked = false; } + if (loco_cargo) { + if (Number(elm.flags) & LOCO_F_CARGO) loco_cargo.checked = true; + else loco_cargo.checked = false; + } + if (loco_auto) { + if (Number(elm.flags) & LOCO_F_AUTO) loco_auto.checked = true; + else loco_auto.checked = false; + } + if (loco_random) { + if (Number(elm.flags) & LOCO_F_RANDOM) loco_random.checked = true; + else loco_random.checked = false; + } + if (loco_blockassign) loco_blockassign = elm.blockassign; + if (loco_blockdest) loco_blockdest = elm.blockdest; + if (loco_blocknext) loco_blocknext= elm.blocknext; + if (loco_blockprev) loco_blockprev = elm.blockprev; } diff --git a/webinterface/railways.js b/webinterface/railways.js index e825211..df99f20 100644 --- a/webinterface/railways.js +++ b/webinterface/railways.js @@ -32,11 +32,15 @@ function rwdetail_show(posx, posy) { Position: , \


\
\ + \ +
\ - \ + \ \ \ -
Ref.Name:
Ref.Name:
Dir:
Alt Dir:

\ -

\ +
\ +
\ +
Lockedby:

\ + \ \
Type \ Type:
\ @@ -60,6 +64,7 @@ function rwdetail_show(posx, posy) { \ "); + gAddEventListener("rwdet_gotoref", 'click', rwdetail_cb_gotoref); gAddEventListener("rwdet_dir", 'change', rwdetail_cb_dirchange); gAddEventListener("rwdet_type", 'change', rwdetail_cb_typechange); gAddEventListener("rwdet_altdir", 'change', rwdetail_cb_dirchange); @@ -90,6 +95,22 @@ function rwdetail_show(posx, posy) { } }; + +function rwdetail_cb_gotoref () { + var type = document.getElementById("rwdet_type"); + var name = document.getElementById("rwdet_name"); + + debug ("Name:" + name.value + " Type:" + type.value); + + switch(Number(type.value)) { + case 3: turndetail_show(name.value, true); break; // turnout + case 4: sensordetail_show(name.value, true); break; // sensor + case 5: break; // connector + case 8: blockdetail_show(name.value, true); break; // block + default: break; + } +}; + function rwdetail_cb_dirchange () { rwdetail_DrawSample (); }; @@ -178,12 +199,14 @@ function rwdetail_setData(rw) { var type = document.getElementById("rwdet_type"); var dir = document.getElementById("rwdet_dir"); var altdir = document.getElementById("rwdet_altdir"); + var lockedby = document.getElementById("rwdet_lockedby"); if (rw) { name.value = rw.name; type.value = rw.type; dir.value = rw.dir; altdir.value = rw.altdir; + lockedby.value = rw.lockedby; } rwdetail_cb_typechange(); @@ -341,7 +364,7 @@ function turnout_server_Activate(name, onoff) { -function turndetail_show(turnname) { +function turndetail_show(turnname, create) { var win = document.getElementById("turndetail"); debug ("turndetail_show"); @@ -389,6 +412,12 @@ function turndetail_show(turnname) { if (turnname == turnouts[i].name) turndetail_setData(turnouts[i]); } } + + + if (create) { + let rname = document.getElementById("turndet_name"); + if (rname.value != turnname && rname.value == "") rname.value = turnname; + } }; diff --git a/webinterface/sensor.js b/webinterface/sensor.js index 252449f..41789e5 100644 --- a/webinterface/sensor.js +++ b/webinterface/sensor.js @@ -89,7 +89,7 @@ function sensor_IsActive(name) { -function sensordetail_show(name) { +function sensordetail_show(name, create) { var win = document.getElementById("sensordetail"); debug ("sensordetail_show"); @@ -129,6 +129,12 @@ function sensordetail_show(name) { if (name == sensors[i].name) sensordetail_setData(sensors[i]); } } + + if (create) { + let rname = document.getElementById("sensor_name"); + if (rname.value != name && rname.value == "") rname.value = name; + } + }; diff --git a/webinterface/serverinout.js b/webinterface/serverinout.js index c0e196d..5beec1a 100644 --- a/webinterface/serverinout.js +++ b/webinterface/serverinout.js @@ -177,6 +177,21 @@ function serverinout_defaultCallback(data) { if (data.changes[i].sensordelete) { sensor_Delete(data.changes[i].sensordelete); } + + // + // Block changes + if (data.changes[i].blocks) { + for (var j = 0; j < data.changes[i].blocks.length; j++) { + block_Update(data.changes[i].blocks[j]); + } + } + if (data.changes[i].block) { + block_Update(data.changes[i].block); + } + if (data.changes[i].blockdelete) { + block_Delete(data.changes[i].blockdelete); + } + } trackDraw(); } diff --git a/webinterface/track.js b/webinterface/track.js index 6741e78..a68f2ab 100644 --- a/webinterface/track.js +++ b/webinterface/track.js @@ -207,7 +207,7 @@ function trackDrawElement(ctx, element, mode) { // // draw ref. name - if (element.name && sideBtnModeGet() == "mode-turn") { + if (element.name && sideBtnModeGet() == "mode-detail") { if (element.type != RAILWAY_TEXT && element.type != RAILWAY_CONNECTOR && element.type != RAILWAY_BLOCK) { ctx.font = "10px Arial"; @@ -563,7 +563,7 @@ function trackMouseup(event) { // add/or delete element // fill in element function trackAddElement(elm) { - //debug ("trackAddElement: pos:" + elm.x + "," + elm.y + " d: " + elm.dir + " name:" + elm.name + " type:" + elm.type); + // debug ("trackAddElement: pos:" + elm.x + "," + elm.y + " d: " + elm.dir + " name:" + elm.name + " type:" + elm.type); if (track.size.x > 0 && track.size.y > 0) { track.elements[elm.x + track.size.y * elm.y] = elm;