origin
steffen 5 years ago
parent e9070992d9
commit 25a6b63541

@ -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

@ -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;
};

@ -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

@ -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 {

@ -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);
}
//////////////////////////////////////////////////////////////////////

@ -63,6 +63,16 @@ void Network::ThreadProcess() {
list<UNIX*>::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;
};

@ -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);

@ -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;
};

@ -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;

@ -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());

@ -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);
}

@ -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);
/////////////////////////////////////////

@ -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) {

@ -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;
};

@ -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;

@ -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;
}
};

@ -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: <input id=\"locodet_flags\" style=\"width: 50\"> \
</div> <hr>\
<div> <table><tr><td> \
<table><tr><td> \
<label><input id=\"locodet_reverse\" type=\"checkbox\" value=\"\"> Reverse</label><br> \
<label><input id=\"locodet_cargo\" type=\"checkbox\" value=\"\"> Cargo</label> \
</td><td> \
<label><input id=\"locodet_auto\" type=\"checkbox\" value=\"\" disabled> Auto</label><br> \
<label><input id=\"locodet_random\" type=\"checkbox\" value=\"\" disabled> Random</label> \
</td></tr></table> \
\
<fieldset><legend>Speed</legend> <table>\
<tr><td></td><td>Stop</td><td><button id=\"locodet_btnvstop\" type=\"button\" value=\"vstop\">X</button> </td></tr>\
<tr><td>Vmin:</td><td><input id=\"locodet_vmin\" style=\"width: 50\"></td><td><button id=\"locodet_btnvmin\" type=\"button\" value=\"vmin\">X</button> </td></tr>\
@ -147,15 +161,23 @@ function locodetail_show(loconame) {
<tr><td>Vmid:</td><td><input id=\"locodet_vmid\" style=\"width: 50\"></td><td><button id=\"locodet_btnvmid\" type=\"button\" value=\"vmid\">X</button> </td></tr> \
<tr><td>Vfast:</td><td><input id=\"locodet_vfast\" style=\"width: 50\"></td><td><button id=\"locodet_btnvfast\" type=\"button\" value=\"vfast\">X</button> </td></tr> \
<tr><td>Vmax:</td><td><input id=\"locodet_vmax\" style=\"width: 50\"></td><td><button id=\"locodet_btnvmax\" type=\"button\" value=\"vmax\">X</button> </td></tr> \
</table></td></fieldset> \
<tr><td>Current:</td><td><input id=\"locodet_speed\" style=\"width: 50\"></td></tr></table> \
\
</fieldset></td> \
<td> \
<fieldset><legend>Code</legend> \
<label><input type=\"radio\" id=\"locodet_DCC14\" name=\"STEPCODE\" value=\"1\">DCC14</label><br> \
<label><input type=\"radio\" id=\"locodet_DCC28\" name=\"STEPCODE\" value=\"2\">DCC28</label><br> \
<label><input type=\"radio\" id=\"locodet_DCC128\" name=\"STEPCODE\" value=\"3\">DCC128</label><br> \
</fieldset> \
Speed: <input id=\"locodet_speed\" style=\"width: 50\"><br> \
<label><input id=\"locodet_reverse\" type=\"checkbox\" value=\"\"> Reverse</label> \
\
<fieldset><legend>Block</legend><table> \
<tr><td>Destination:</td><td><input id=\"locodet_blockdest\" style=\"width: 50\" disabled></td></tr> \
<tr><td>Assined:</td><td><input id=\"locodet_blockassign\" style=\"width: 50\" disabled></td></tr> \
<tr><td>Next:</td><td><input id=\"locodet_blocknext\" style=\"width: 50\" disabled></td></tr> \
<tr><td>Prev:</td><td><input id=\"locodet_blockprev\" style=\"width: 50\" disabled></td></tr> \
</table></fileset>\
\
</td></tr></table></div> <hr>\
<div align=right> \
<button id=\"locodet_SAVE\" type=\"button\">Save</button> \
@ -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-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-1);
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;
}

@ -32,11 +32,15 @@ function rwdetail_show(posx, posy) {
Position: <input id=\"rwdet_X\" style=\"width: 50\" value=\"" + posx +"\"> , <input id=\"rwdet_Y\" style=\"width: 50\" value=\"" + posy +"\"> \
</div> <br> <hr>\
<div> <table><tr><td><table> \
<tr><td>Ref.Name:</td><td><input id=\"rwdet_name\" style=\"width: 100\"></td></tr> \
<tr><td>Ref.Name:</td><td><input id=\"rwdet_name\" style=\"width: 100\"><button id=\"rwdet_gotoref\" type=\"button\">&nearr;</button></td></tr> \
<tr><td>Dir:</td><td><input id=\"rwdet_dir\" style=\"width: 25\"></td></tr> \
<tr><td>Alt Dir:</td><td><input id=\"rwdet_altdir\" style=\"width: 25\"></td></tr> \
</table><br> \
<center><canvas id=\"rwdet_canvas\" height=\""+track.scale+"\" width=\""+track.scale+"\" style=\"border:1px solid #000000;\"></center> <br>\
<tr><td></td><td> \
<center><canvas id=\"rwdet_canvas\" height=\""+track.scale+"\" width=\""+track.scale+"\" style=\"border:1px solid #000000;\"></center> \
</td></tr>\
<tr><td>Lockedby:</td><td><input id=\"rwdet_lockedby\" style=\"width: 100\" disabled></td></tr>\
</table><br>\
\
</td><td> \
<fieldset><legend>Type</legend> \
Type: <input id=\"rwdet_type\" style=\"width: 25\"><br> \
@ -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;
}
};

@ -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;
}
};

@ -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();
}

@ -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;

Loading…
Cancel
Save