automatic mode prepraring data handling

origin
steffen 5 years ago
parent 277e8934b2
commit 22d750a63a

@ -39,6 +39,10 @@ JSONParse Locomotives::_GetJSON(int idx) {
s = locomotives[idx].name; json.AddObject("name", s);
s = locomotives[idx].ifname; json.AddObject("ifname", s);
s = locomotives[idx].blockdest; json.AddObject("blockdest", s);
s = locomotives[idx].blocknext; json.AddObject("blocknext", s);
s = locomotives[idx].blockassign; json.AddObject("blockassign", s);
s = locomotives[idx].blockprev; json.AddObject("blockprev", s);
json.AddObject("addr", locomotives[idx].addr);
json.AddObject("stepcode", locomotives[idx].stepcode);
json.AddObject("speed", locomotives[idx].speed);
@ -112,11 +116,23 @@ Locomotive Locomotives::GetLocomotiveFromJSON(JSONParse *j) {
l.flags = 0;
l.speed = 0;
l.func = 0;
l.blockassign[0] = 0;
l.blockdest[0] = 0;
l.blocknext[0] = 0;
l.blockprev[0] = 0;
j->GetValue("name", &s);
strncpy (l.name, s.c_str(), REFERENCENAME_LEN);
j->GetValue("ifname", &s);
strncpy (l.ifname, s.c_str(), REFERENCENAME_LEN);
j->GetValue("blockassign", &s);
strncpy (l.blockassign, s.c_str(), REFERENCENAME_LEN);
j->GetValue("blockdest", &s);
strncpy (l.blockdest, s.c_str(), REFERENCENAME_LEN);
j->GetValue("blockprev", &s);
strncpy (l.blockprev, s.c_str(), REFERENCENAME_LEN);
j->GetValue("blocknext", &s);
strncpy (l.blocknext, s.c_str(), REFERENCENAME_LEN);
j->GetValueInt("addr", &l.addr);
j->GetValueInt("stepcode", &l.stepcode);
j->GetValueInt("speed", &l.speed);
@ -238,12 +254,94 @@ int Locomotives::SetFunction(string name, int func, int value) {
break;
}
}
UnLock();
return 1;
};
int Locomotives::SetDestination (string name, string block, int direction) {
int i;
Lock();
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
if (name.compare(locomotives[i].name) == 0) {
debug (0, "Locomotives::SetDestination (Name:%s Block:%s Direction:%d)\n", name.c_str(), block.c_str(), direction);
if (direction) snprintf (locomotives[i].blockdest, REFERENCENAME_LEN, "-:%s", block.c_str());
else snprintf (locomotives[i].blockdest, REFERENCENAME_LEN, "+:%s", block.c_str());
break;
}
UnLock();
printf ("%s:%d %s ************** finish me **************\n", __FILE__, __LINE__, __FUNCTION__);
return 1;
}
int Locomotives::SetAssign (string name, string block, int direction) {
int i;
Lock();
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
if (name.compare(locomotives[i].name) == 0) {
debug (0, "Locomotives::SetAssign (Name:%s Block:%s Direction:%d)\n", name.c_str(), block.c_str(), direction);
if (direction) snprintf (locomotives[i].blockassign, REFERENCENAME_LEN, "-:%s", block.c_str());
else snprintf (locomotives[i].blockassign, REFERENCENAME_LEN, "+:%s", block.c_str());
break;
}
UnLock();
printf ("%s:%d %s ************** finish me **************\n", __FILE__, __LINE__, __FUNCTION__);
return 1;
}
int Locomotives::Reset(string name) {
int i;
Lock();
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0)
if (name.compare(locomotives[i].name) == 0) {
debug (0, "Locomotives::Reset (Name:%s)\n", name.c_str());
locomotives[i].blockassign[0] = 0;
locomotives[i].blockdest[0] = 0;
locomotives[i].blockprev[0] = 0;
locomotives[i].blocknext[0] = 0;
break;
}
UnLock();
printf ("%s:%d %s ************** finish me **************\n", __FILE__, __LINE__, __FUNCTION__);
return 1;
};
int Locomotives::SetMan(string name) {
int i;
printf ("%s:%d %s ************** finish me **************\n", __FILE__, __LINE__, __FUNCTION__);
return 1;
};
int Locomotives::SetAutoMan(string name) {
int i;
printf ("%s:%d %s ************** finish me **************\n", __FILE__, __LINE__, __FUNCTION__);
return 1;
};
int Locomotives::SetAuto(string name) {
int i;
printf ("%s:%d %s ************** finish me **************\n", __FILE__, __LINE__, __FUNCTION__);
return 1;
};
int Locomotives::SetAutoRand(string name) {
int i;
printf ("%s:%d %s ************** finish me **************\n", __FILE__, __LINE__, __FUNCTION__);
return 1;
};
//

@ -11,6 +11,7 @@
#define LOCO_F_SHORTTRAIN 0x0040
#define LOCO_F_AUTO 0x0100
#define LOCO_F_RANDOM 0x0200
#define LOCO_F_AUTOSTOP 0x0400
enum {
LOCO_INT_UNDEF = 0,
@ -34,10 +35,10 @@ struct s_Locomotive {
// 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
char blockassign[REFERENCENAME_LEN]; // currently assigned block [+BLOCKREFNAME ... -BLOCKREFNAME]
char blocknext[REFERENCENAME_LEN]; // next block to go to
char blockprev[REFERENCENAME_LEN]; // prev block (mostly assigned block
char blockdest[REFERENCENAME_LEN]; // destination block
} typedef Locomotive;
class Locomotives {
@ -65,9 +66,15 @@ class Locomotives {
int SetSpeed(string name, int speed);
int SetReverse(string name, int reverse);
int SetFunction(string name, int func, int value);
int Reset(string name);
int SetMan(string name);
int SetAutoMan(string name);
int SetAuto(string name);
int SetAutoRand(string name);
int SetSpeedFromBus (string ifname, int addr, int speed);
int SetFunctionFromBus (string ifname, int addr, int func);
int SetDestination (string name, string block, int direction);
int SetAssign (string name, string block, int direction);
string GetName(int idx);

@ -57,6 +57,11 @@ private:
void SetJSONLocomotive(JSONParse *jp);
void SetJSONLocoDest(JSONParse *jp);
void SetJSONLocoAssign(JSONParse *jp);
void SetJSONLocoReset(JSONParse *jp);
void SetJSONLocoMan(JSONParse *jp);
void SetJSONLocoAutoMan(JSONParse *jp);
void SetJSONLocoAuto(JSONParse *jp);
void SetJSONLocoAutoRand(JSONParse *jp);
void BlockJSONOff(JSONParse *jp);
void BlockJSONClear(JSONParse *jp);

@ -82,7 +82,9 @@ void Server::ThreadProcess() {
//
// startup process
if (mode == SMODE_STARTUP) {
SetModeReset(); // currently there is not much to do.
mode = SMODE_MANUAL;
printf ("%s:%d ************************************************************ fix me\n", __FILE__, __LINE__);
// SetModeReset(); // currently there is not much to do.
}
//

@ -160,6 +160,13 @@ public:
int LocomotiveSetSpeed(string name, int speed) { return locomotives.SetSpeed(name, speed); };
int LocomotiveSetReverse(string name, int reverse) { return locomotives.SetReverse(name, reverse); };
int LocomotiveSetFunction(string name, int func, int value) { return locomotives.SetFunction(name, func, value); };
int LocomotiveSetDest(string name, string block, int direction) { return locomotives.SetDestination(name, block, direction); };
int LocomotiveSetAssign(string name, string block, int direction) { return locomotives.SetAssign(name, block, direction); };
int LocomotiveReset(string name) { return locomotives.Reset(name); };
int LocomotiveSetMan(string name) { return locomotives.SetMan(name); };
int LocomotiveSetAuto(string name) { return locomotives.SetAuto(name); };
int LocomotiveSetAutoMan(string name) { return locomotives.SetAutoMan(name); };
int LocomotiveSetAutoRand(string name) { return locomotives.SetAutoRand(name); };
/////////////////////////////////////////
// Sensor

@ -123,7 +123,21 @@ int Session::ProcessData(JSONParse *jin, JSONParse *jout) {
else if (command.compare("locomotiveassign") == 0) {
SetJSONLocoAssign(jin);
}
else if (command.compare("locomotivesetman") == 0) {
SetJSONLocoMan(jin);
}
else if (command.compare("locomotivesetauto") == 0) {
SetJSONLocoAuto(jin);
}
else if (command.compare("locomotivesetautoman") == 0) {
SetJSONLocoAutoMan(jin);
}
else if (command.compare("locomotivesetautorand") == 0) {
SetJSONLocoAutoRand(jin);
}
else if (command.compare("locomotivereset") == 0) {
SetJSONLocoReset(jin);
}
//
// poweron / poweroff / save and resetdata
//
@ -455,13 +469,17 @@ void Session::SetJSONLocoDest(JSONParse *jp) {
string loco;
string block;
int reverse;
JSONParse jout;
jp->GetValue("locomotive", &loco);
jp->GetValue("block", &block);
jp->GetValueInt("reverse", &reverse);
server->LockThread();
printf ("%s:%d ******************** finish me - SetJSONLocoDest * loco:%s block:%s rev:%d ******\n", __FILE__, __LINE__, loco.c_str(), block.c_str(), reverse);
server->LocomotiveSetDest(loco, block, reverse);
jout.Clear();
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
if (network) network->_ChangeListPushToAll(jout.ToString());
server->UnLockThread();
};
@ -470,16 +488,93 @@ void Session::SetJSONLocoAssign(JSONParse *jp) {
string loco;
string block;
int reverse;
JSONParse jout;
jp->GetValue("locomotive", &loco);
jp->GetValue("block", &block);
jp->GetValueInt("reverse", &reverse);
server->LockThread();
printf ("%s:%d ******************** finish me - SetJSONLocoAssign * loco:%s block:%s rev:%d ******\n", __FILE__, __LINE__, loco.c_str(), block.c_str(), reverse);
server->LocomotiveSetAssign(loco, block, reverse);
jout.Clear();
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
if (network) network->_ChangeListPushToAll(jout.ToString());
server->UnLockThread();
};
void Session::SetJSONLocoReset(JSONParse *jp) {
string loco;
JSONParse jout;
jp->GetValue("locomotive", &loco);
server->LockThread();
server->LocomotiveReset(loco);
jout.Clear();
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
if (network) network->_ChangeListPushToAll(jout.ToString());
server->UnLockThread();
};
void Session::SetJSONLocoMan(JSONParse *jp) {
string loco;
JSONParse jout;
jp->GetValue("locomotive", &loco);
server->LockThread();
server->LocomotiveSetMan(loco);
jout.Clear();
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
if (network) network->_ChangeListPushToAll(jout.ToString());
server->UnLockThread();
};
void Session::SetJSONLocoAutoMan(JSONParse *jp) {
string loco;
JSONParse jout;
jp->GetValue("locomotive", &loco);
server->LockThread();
server->LocomotiveSetAutoMan(loco);
jout.Clear();
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
if (network) network->_ChangeListPushToAll(jout.ToString());
server->UnLockThread();
};
void Session::SetJSONLocoAuto(JSONParse *jp) {
string loco;
JSONParse jout;
jp->GetValue("locomotive", &loco);
server->LockThread();
server->LocomotiveSetAuto(loco);
jout.Clear();
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
if (network) network->_ChangeListPushToAll(jout.ToString());
server->UnLockThread();
};
void Session::SetJSONLocoAutoRand(JSONParse *jp) {
string loco;
JSONParse jout;
jp->GetValue("locomotive", &loco);
server->LockThread();
server->LocomotiveSetAutoRand(loco);
jout.Clear();
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
if (network) network->_ChangeListPushToAll(jout.ToString());
server->UnLockThread();
};
//
// add new Turnout

@ -93,8 +93,9 @@ function block_contextmenu(name) {
function block_ctxmenu_DestinationLU (element, value) {
let loc = document.getElementById("contextbox_loc");
let name = document.getElementById("ConextMenuHead").innerHTML;
if (loc) {
locomotive_server_Dest(loc.value, element.name, 1);
locomotive_server_Dest(loc.value, name, 1);
}
gContextmenuClose();
};
@ -102,8 +103,9 @@ function block_ctxmenu_DestinationLU (element, value) {
function block_ctxmenu_DestinationRD (element, value) {
let loc = document.getElementById("contextbox_loc");
let name = document.getElementById("ConextMenuHead").innerHTML;
if (loc) {
locomotive_server_Dest(loc.value, element.name, 0);
locomotive_server_Dest(loc.value, name, 0);
}
gContextmenuClose();
};

@ -8,6 +8,7 @@ const LOCO_F_CANREVERSE = 0x0020;
const LOCO_F_SHORTTRAIN = 0x0040;
const LOCO_F_AUTO = 0x0100;
const LOCO_F_RANDOM = 0x0200;
const LOCO_F_AUTOSTOP = 0x0400;
var locomotives = [];
@ -30,10 +31,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].blockassign = data.blockassign;
locomotives[i].blockprev = data.blockprev;
locomotives[i].blocknext = data.blocknext;
locomotives[i].blockdestination = data.blockdestination;
locomotives[i].blockdest = data.blockdest;
locodetail_setData(locomotives[i]);
lococtrl_setData(data);
return;
@ -46,14 +47,19 @@ function locomotive_Update(data) {
name: data.name,
ifname: data.ifname,
addr: data.addr,
steps: data.steps,
stepcode: data.stepcode,
vmin: data.vmin,
vslow: data.vslow,
speed: data.speed,
vmid: data.vmid,
vfast: data.vfast,
vmax: data.vmax,
flags: data.flags
flags: data.flags,
blockassign: data.blockassign,
blockdest: data.blockdest,
blocknext: data.blocknext,
blockprev: data.blockprev
});
};
@ -173,8 +179,8 @@ function locodetail_show(loconame) {
</fieldset> \
\
<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>Destination:</td><td><input id=\"locodet_blockdest\" 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><button id=\"locodet_RESET\" type=\"button\">Reset</button></fileset>\
@ -428,7 +434,7 @@ function locodetail_setData(elm) {
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");
var loco_blockprev = document.getElementById("locodet_blockprev");
if (elm) {
if (loco_name) loco_name.value = elm.name;
@ -465,10 +471,10 @@ function locodetail_setData(elm) {
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;
if (loco_blockassign) loco_blockassign.value = elm.blockassign;
if (loco_blockdest) loco_blockdest.value = elm.blockdest;
if (loco_blocknext) loco_blocknext.value = elm.blocknext;
if (loco_blockprev) loco_blockprev.value = elm.blockprev;
}
@ -602,25 +608,40 @@ function lococtrl_show(name) {
if (!win) {
debug ("locolist_show create window");
win = gWindowCreate("lococtrl_"+name, "Loco:"+name, 200, 500, " \
<div> \
Speed: <div id=\"lococtrl_"+name+"_SPEED\"></div> \
<table><tr><td> \
win = gWindowCreate("lococtrl_"+name, "Loco:"+name, 270, 500, " \
<table><tr><td> \
<fieldset><legend>Speed</legend><table><tr><td align=center>\
\
<input id=\"lococtrl_"+name+"_RANGE\" name=\""+name+"\" type=\"range\" orient=\"vertical\" \
style=\"-webkit-appearance: slider-vertical; width: 10px; height: 100px;\"\
min=\"0\" value=\"0\" max=\"100\" > \
<br><button id=\"lococtrl_"+name+"_REVBTN\" type=\"button\">REV</button> \
</td><td> \
<fieldset><legend>Speed</legend> <table>\
\
</td><td><table>\
<tr><td><button id=\"lococtrl_"+name+"_btnvstop\" type=\"button\" value=\"vstop\">Stop</button> </td></tr>\
<tr><td><button id=\"lococtrl_"+name+"_btnvmin\" type=\"button\" value=\"vmin\">Min</button></td></tr>\
<tr><td><button id=\"lococtrl_"+name+"_btnvslow\" type=\"button\" value=\"vslow\">Slow</button></td></tr> \
<tr><td><button id=\"lococtrl_"+name+"_btnvmid\" type=\"button\" value=\"vmid\">Mid</button></td></tr> \
<tr><td><button id=\"lococtrl_"+name+"_btnvfast\" type=\"button\" value=\"vfast\">Fast</button></td></tr> \
<tr><td><button id=\"lococtrl_"+name+"_btnvmax\" type=\"button\" value=\"vmax\">Max</button></td></tr> \
</table></td></fieldset> \
</td></tr></table></div> \
<div align=right> \
</table></td></tr></table></fieldset> \
</td><td>\
<fieldset><legend>Control</legend><table>\
<tr> \
<td></td><td><button id=\"lococtrl_"+name+"_btnman\" type=\"button\" value=\"vstop\">MAN</button></td> \
</tr><tr> \
<td align=center><input id=\"lococtrl_"+name+"_cbstopman\" type=\"checkbox\" value=\"\" disabled></td>\
<td><button id=\"lococtrl_"+name+"_btnstopman\" type=\"button\" value=\"vstop\">A&lArr;M</button></td> \
</tr><tr> \
<td align=center><input id=\"lococtrl_"+name+"_cbauto\" type=\"checkbox\" value=\"\" disabled></td>\
<td><button id=\"lococtrl_"+name+"_btnauto\" type=\"button\" value=\"vstop\">AUTO</button></td> \
</tr><tr> \
<td align=center><input id=\"lococtrl_"+name+"_cbrand\" type=\"checkbox\" value=\"\" disabled></td>\
<td><button id=\"lococtrl_"+name+"_btnrand\" type=\"button\" value=\"vstop\">RAND</button></td> \
</tr> \
</table></fieldset> \
</td><tr></table>\
<br><div align=right> \
<button id=\"lococtrl_"+name+"_CLOSE\" type=\"button\" value=\""+name+"\">Close</button> \
</div> \
\
@ -633,6 +654,11 @@ function lococtrl_show(name) {
gAddEventListener("lococtrl_"+name+"_btnvfast", 'click', lococtrl_cb_btnmove);
gAddEventListener("lococtrl_"+name+"_btnvmax", 'click', lococtrl_cb_btnmove);
gAddEventListener("lococtrl_"+name+"_btnman", 'click', lococtrl_cb_btnman);
gAddEventListener("lococtrl_"+name+"_btnstopman", 'click', lococtrl_cb_btnstopman);
gAddEventListener("lococtrl_"+name+"_btnauto", 'click', lococtrl_cb_btnauto);
gAddEventListener("lococtrl_"+name+"_btnrand", 'click', lococtrl_cb_btnrand);
gAddEventListener("lococtrl_"+name+"_RANGE", 'click', lococtrl_speed);
gAddEventListener("lococtrl_"+name+"_REVBTN", 'click', lococtrl_reverse);
gAddEventListener("lococtrl_"+name+"_CLOSE", 'click', lococtrl_close);
@ -644,6 +670,35 @@ function lococtrl_show(name) {
};
function lococtrl_cb_btnman() {
var name = getTextBetween(this.id, "lococtrl_", "_btnman");
var request = { command: "locomotivesetman", locomotive: name };
serverinout (request, serverinout_defaultCallback);
};
function lococtrl_cb_btnstopman() {
var name = getTextBetween(this.id, "lococtrl_", "_btnstopman");
var request = { command: "locomotivesetautoman", locomotive: name };
serverinout (request, serverinout_defaultCallback);
};
function lococtrl_cb_btnauto() {
var name = getTextBetween(this.id, "lococtrl_", "_btnauto");
var request = { command: "locomotivesetauto", locomotive: name };
serverinout (request, serverinout_defaultCallback);
};
function lococtrl_cb_btnrand() {
var name = getTextBetween(this.id, "lococtrl_", "_btnauto");
var request = { command: "locomotivesetautorand", locomotive: name };
serverinout (request, serverinout_defaultCallback);
};
function lococtrl_reverse() {
var name = getTextBetween(this.id, "lococtrl_", "_REVBTN");
var reverse;
@ -707,6 +762,9 @@ function lococtrl_speed() {
function lococtrl_setData(data) {
var range = document.getElementById("lococtrl_"+data.name+"_RANGE");
var reverse = document.getElementById("lococtrl_"+data.name+"_REVBTN");
var cbauto = document.getElementById("lococtrl_"+data.name+"_cbauto");
var cbrand = document.getElementById("lococtrl_"+data.name+"_cbrand");
var cbmanstop = document.getElementById("lococtrl_"+data.name+"_cbstopman");
if (range && reverse) {
debug ("lococtrl: " + data.name + " speed:" + data.speed + " vmax:" +
@ -714,6 +772,10 @@ function lococtrl_setData(data) {
if (data.flags & LOCO_F_REVERSE) reverse.innerHTML = "REV";
else reverse.innerHTML = "FWD";
cbauto.checked = (data.flags & LOCO_F_AUTO);
cbrand.checked = (data.flags & LOCO_F_RANDOM);
cbmanstop.checked = (data.flags & LOCO_F_AUTOSTOP);
range.min = 0;
if (data.vmax) range.max = data.vmax;
range.value = Math.abs(Number(data.speed));

Loading…
Cancel
Save