|
|
|
@ -206,6 +206,28 @@ int Locomotives::SetSpeed(string name, int speed) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Locomotives::SetReverse(string name, int reverse) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
Lock();
|
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0) {
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0) {
|
|
|
|
|
if (reverse)
|
|
|
|
|
locomotives[i].flags |= LOCO_F_REVERSE;
|
|
|
|
|
else
|
|
|
|
|
locomotives[i].flags &= ~LOCO_F_REVERSE;
|
|
|
|
|
|
|
|
|
|
server->interfaces.SetLocoSpeed(&locomotives[i], locomotives[i].speed);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UnLock();
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Locomotives::SetFunction(string name, int func, int value) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
@ -227,13 +249,21 @@ int Locomotives::SetFunction(string name, int func, int value) {
|
|
|
|
|
//
|
|
|
|
|
// set values from bus...
|
|
|
|
|
//
|
|
|
|
|
int Locomotives::SetSpeedFromBus(string name, int addr, int speed) {
|
|
|
|
|
int Locomotives::SetSpeedFromBus(string ifname, int addr, int speed) {
|
|
|
|
|
int i;
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
|
|
|
|
|
debug (0, "%s:%d SetSpeedFromBus IfName:%s Addr:%d Speed:%d", __FILE__, __LINE__, ifname.c_str(), addr, speed);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0) {
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0 && locomotives[i].addr == addr) {
|
|
|
|
|
locomotives[i].speed = speed;
|
|
|
|
|
if (ifname.compare(locomotives[i].ifname) == 0 && locomotives[i].addr == addr) {
|
|
|
|
|
if (speed == 0) locomotives[i].speed = 0;
|
|
|
|
|
if (speed >= (127-((127/locomotives[i].steps)+1))) locomotives[i].speed = locomotives[i].vmax;
|
|
|
|
|
else {
|
|
|
|
|
printf ("\n\n Speed:%d test:%d", speed, (127-((127/locomotives[i].steps)+1)));
|
|
|
|
|
locomotives[i].speed = (1+speed) * locomotives[i].vmax / 127;
|
|
|
|
|
if (locomotives[i].speed > locomotives[i].vmax) locomotives[i].speed = locomotives[i].vmax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(i));
|
|
|
|
|
if(network) network->ChangeListPushToAll(jp.ToString());
|
|
|
|
@ -245,13 +275,14 @@ int Locomotives::SetSpeedFromBus(string name, int addr, int speed) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Locomotives::SetDirectionFromBus(string name, int addr, int reverse) {
|
|
|
|
|
int Locomotives::SetFunctionFromBus(string ifname, int addr, int func) {
|
|
|
|
|
int i;
|
|
|
|
|
JSONParse jp;
|
|
|
|
|
|
|
|
|
|
debug (0, "%s:%d SetDirectionFromBus IfName:%s Addr:%d function:%d", __FILE__, __LINE__, ifname.c_str(), addr, func);
|
|
|
|
|
for (i = 0; i < max; i++) if (locomotives[i].name[0] != 0) {
|
|
|
|
|
if (name.compare(locomotives[i].name) == 0 && locomotives[i].addr == addr) {
|
|
|
|
|
if (reverse) locomotives[i].flags |= LOCO_F_REVERSE;
|
|
|
|
|
if (ifname.compare(locomotives[i].ifname) == 0 && locomotives[i].addr == addr) {
|
|
|
|
|
if (func & 32) locomotives[i].flags |= LOCO_F_REVERSE;
|
|
|
|
|
else locomotives[i].flags &= ~LOCO_F_REVERSE;
|
|
|
|
|
|
|
|
|
|
jp.AddObject("locomotive",_GetJSON(i));
|
|
|
|
|