diff --git a/server/locomotive.cc b/server/locomotive.cc index 940eac0..69ef8e2 100644 --- a/server/locomotive.cc +++ b/server/locomotive.cc @@ -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; +}; // diff --git a/server/locomotive.h b/server/locomotive.h index d192674..cfe1f13 100644 --- a/server/locomotive.h +++ b/server/locomotive.h @@ -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); diff --git a/server/network.h b/server/network.h index bb29eaa..5ff6c3c 100644 --- a/server/network.h +++ b/server/network.h @@ -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); diff --git a/server/server.cc b/server/server.cc index 506660d..c063171 100644 --- a/server/server.cc +++ b/server/server.cc @@ -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. } // diff --git a/server/server.h b/server/server.h index bd3a046..c1b1104 100644 --- a/server/server.h +++ b/server/server.h @@ -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 diff --git a/server/session.cc b/server/session.cc index a3bddd6..327386b 100644 --- a/server/session.cc +++ b/server/session.cc @@ -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 diff --git a/webinterface/block.js b/webinterface/block.js index 3169ccc..5043c26 100644 --- a/webinterface/block.js +++ b/webinterface/block.js @@ -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(); }; diff --git a/webinterface/locomotive.js b/webinterface/locomotive.js index 76f9cb8..e3d3958 100644 --- a/webinterface/locomotive.js +++ b/webinterface/locomotive.js @@ -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) { \ \
Block \ - \ \ + \ \ \
Destination:
Assined:
Destination:
Next:
Prev:
\ @@ -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, " \ -
\ - Speed:
\ -
\ + win = gWindowCreate("lococtrl_"+name, "Loco:"+name, 270, 500, " \ +
\ +
Speed
\ + \ \
\ -
\ -
Speed \ + \ + \ -
\ \ \ \ \ \ \ -
\ -
\ +
\ +
\ +
Control\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
\ +
\ +
\ \
\ \ @@ -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));