origin
steffen 5 years ago
parent 25a6b63541
commit 36a930c06d

@ -150,18 +150,36 @@ int Blocks::Delete(string name) {
return 1;
};
//
// thread will not be locked..
int Blocks::SetOff(string name) {
JSONParse jp;
int i;
// jp.AddObject("block", _GetJSON(i));
// if(network) network->ChangeListPushToAll(jp.ToString());
for (i = 0; i < max; i++) if (blocks[i].name[0] != 0) {
if (name.compare(blocks[i].name) == 0) {
changed = 1;
blocks[i].flags |= BLOCK_F_OFF;
printf ("%s:%d set block %s off", __FILE__, __LINE__, blocks[i].name);
break;
}
}
return 1;
};
int Blocks::Clear(string name) {
int i;
for (i = 0; i < max; i++) if (blocks[i].name[0] != 0) {
if (name.compare(blocks[i].name) == 0) {
changed = 1;
blocks[i].flags &= ~BLOCK_F_OFF;
printf ("%s:%d clear block %s off", __FILE__, __LINE__, blocks[i].name);
break;
}
}
return 1;
};

@ -5,9 +5,10 @@
#include "modelbahn.h"
#include "server.h"
#define BLOCK_F_SHORT 0x0001
#define BLOCK_F_LONG 0x0002
#define BLOCK_F_ENDSTATION 0x0010
#define BLOCK_F_OFF 0x0001
#define BLOCK_F_SHORT 0x0010
#define BLOCK_F_LONG 0x0020
#define BLOCK_F_ENDSTATION 0x0040
#define BLOCK_F_SPEEDLIMIT 0x0100

@ -435,10 +435,9 @@ void Session::DelJSONLocomotive(JSONParse *jp) {
JSONParse jout;
string s;
server->LockThread();
jp->GetObject("locomotive", &jloco);
loco = server->LocomotiveFromJSON(&jloco);
server->LockThread();
if (loco.name[0] != 0) {
debug (0, "%s:%d DelJSONLocomotive Element %s", __FILE__, __LINE__, loco.name);
// add element
@ -453,12 +452,32 @@ void Session::DelJSONLocomotive(JSONParse *jp) {
void Session::SetJSONLocoDest(JSONParse *jp) {
string loco;
string block;
int reverse;
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->UnLockThread();
};
void Session::SetJSONLocoAssign(JSONParse *jp) {
string loco;
string block;
int reverse;
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->UnLockThread();
};
@ -589,20 +608,32 @@ void Session::DelJSONBlock(JSONParse *jp) {
void Session::BlockJSONOff(JSONParse *jp) {
string s;
string name;
JSONParse jout;
jp->GetValue("block", &s);
jp->GetValue("block", &name);
server->LockThread();
server->BlockSetOff(s);
server->BlockSetOff(name);
jout.Clear();
jout.AddObject("block", server->BlockGetJSON(name));
if (network) network->_ChangeListPushToAll(jout.ToString());
server->UnLockThread();
};
void Session::BlockJSONClear(JSONParse *jp) {
string s;
string name;
JSONParse jout;
jp->GetValue("block", &s);
jp->GetValue("block", &name);
server->LockThread();
server->BlockClear(s);
server->BlockClear(name);
jout.Clear();
jout.AddObject("block", server->BlockGetJSON(name));
if (network) network->_ChangeListPushToAll(jout.ToString());
server->UnLockThread();
};

@ -3,6 +3,13 @@
//
var blocks = [];
const BLOCK_F_OFF = 0x0001;
const BLOCK_F_SHORT = 0x0010;
const BLOCK_F_LONG = 0x0020;
const BLOCK_F_ENDSTATION = 0x0040;
const BLOCK_F_SPEEDLIMIT = 0x0100;
//
// update or add a new element
@ -81,6 +88,7 @@ function block_ctxmenu_DestinationLD (element, value) {
if (loc) {
locomotive_server_Dest(loc.value, element.name, 1);
}
gContextmenuClose();
};

@ -177,7 +177,7 @@ function serverinout_defaultCallback(data) {
if (data.changes[i].sensordelete) {
sensor_Delete(data.changes[i].sensordelete);
}
//
// Block changes
if (data.changes[i].blocks) {
@ -186,6 +186,7 @@ function serverinout_defaultCallback(data) {
}
}
if (data.changes[i].block) {
debug ("update Block:"+ data.changes[i].block.name + " Flags:" + data.changes[i].block.flags);
block_Update(data.changes[i].block);
}
if (data.changes[i].blockdelete) {

@ -239,9 +239,15 @@ function trackDrawBlock(ctx, blockelm) {
if (blockelm.dir == 1 || blockelm.dir == 2) { // 1 .. | 2.. -
let x1, y1, x2, y2, a, b;
let text, color;
let block;
// select color depending on referecedBy
for (var i = 0; i < blocks.length; i++) {
if (blockelm.name == blocks[i].name) {
block = blocks[i];
break;
}
}
// Fill Box
x1 = 0 * track.scale + 2;
@ -259,7 +265,9 @@ function trackDrawBlock(ctx, blockelm) {
y1 = y1 + (blockelm.y) * track.scale;
y2 = y2 + (blockelm.y) * track.scale;
if (blockelm.lockedby && blockelm.lockedby != "") ctx.fillStyle = cssVar('--block-bg-locked');
// debug ("Flags:" + Number(blockelm.flags) + " Res:" + (Number(blockelm.flags) & BLOCK_F_OFF));
if (block && Number(block.flags) & BLOCK_F_OFF) ctx.fillStyle = cssVar('--block-bg-closed');
else if (blockelm.lockedby && blockelm.lockedby != "") ctx.fillStyle = cssVar('--block-bg-locked');
else ctx.fillStyle = cssVar('--block-bg');
ctx.fillRect (x1, y1, (x2-x1), (y2-y1));
@ -280,7 +288,8 @@ function trackDrawBlock(ctx, blockelm) {
ctx.font = "10px Arial";
ctx.textAlign = "center";
if (blockelm.lockedby && blockelm.lockedby != "") ctx.fillStyle = cssVar('--block-fg-locked');
if (block && Number(block.flags) & BLOCK_F_OFF) ctx.fillStyle = cssVar('--block-fg-closed');
else if (blockelm.lockedby && blockelm.lockedby != "") ctx.fillStyle = cssVar('--block-fg-locked');
else ctx.fillStyle = cssVar('--block-fg');
ctx.fillText(blockelm.name, x1, y1);
} else {
@ -292,7 +301,8 @@ function trackDrawBlock(ctx, blockelm) {
ctx.rotate(-Math.PI/2);
ctx.font = "10px Arial";
ctx.textAlign = "center";
if (blockelm.lockedby && blockelm.lockedby != "") ctx.fillStyle = cssVar('--block-fg-locked');
if (block && Number(block.flags) & BLOCK_F_OFF) ctx.fillStyle = cssVar('--block-fg-closed');
else if (blockelm.lockedby && blockelm.lockedby != "") ctx.fillStyle = cssVar('--block-fg-locked');
else ctx.fillStyle = cssVar('--block-fg');
ctx.fillText(blockelm.name, 0, 0);
ctx.restore();

Loading…
Cancel
Save