changes reset and gui

origin
steffen 5 years ago
parent 976a1fc281
commit ddb0e30e01

4041
Bugs.txt

File diff suppressed because it is too large Load Diff

@ -1,3 +1,6 @@
2020-04-25:
- reset seems to work fine now.
2020-03-22:
- adding server status messages
@ -10,4 +13,3 @@
2020-02-09:
- Initial CVS Import

@ -303,6 +303,15 @@ int Locomotives::SetFunctionFromBus(string ifname, int addr, int func) {
};
string Locomotives::GetName(int idx) {
string result = "";
Lock();
if (idx <= max && idx >= 0)
result = locomotives[idx].name;
UnLock();
return result;
};

@ -6,6 +6,7 @@
#include "server.h"
#define LOCO_F_REVERSE 0x0001
enum {
LOCO_INT_UNDEF = 0,
LOCO_INT_DCC14,
@ -57,6 +58,8 @@ class Locomotives {
int SetSpeedFromBus (string ifname, int addr, int speed);
int SetFunctionFromBus (string ifname, int addr, int func);
string GetName(int idx);
JSONParse GetJSON(string name);
void GetJSONAll(JSONParse *json);
Locomotive GetLocomotiveFromJSON(JSONParse *j);

@ -111,10 +111,16 @@ void timer_start(struct timeval *tv) {
};
int timer_end(struct timeval *tv) {
int timer_get(struct timeval *tv) {
struct timeval tvnow;
gettimeofday(&tvnow, NULL);
return ((tvnow.tv_sec - tv->tv_sec)*1000 + (tvnow.tv_usec - tv->tv_usec)/1000);
};
int timevaldiff (struct timeval *tv1, struct timeval *tv2) {
return ((tv1->tv_sec - tv2->tv_sec)*1000 + (tv1->tv_usec - tv2->tv_usec)/1000);
};

@ -33,8 +33,9 @@ extern Network *network;
// to measure the time in ms (used for debugging)
//
void timer_start(struct timeval *tv);
int timer_end(struct timeval *tv);
int timer_get(struct timeval *tv);
int timevaldiff (struct timeval *tv1, struct timeval *tv2);
#endif // _MODELBAHN_H_

@ -150,28 +150,68 @@ void Server::SetModeManual() {
//
// run a single cycle in reset mode
// each step will only reset one single step.
#define INTERFACE_LOCO_TIME 250
#define INTERFACE_TURN_TIME 750
void Server::CycleModeReset() {
JSONParse json;
list<JSONElement> elements;
list<JSONElement>::iterator iter;
json.Clear();
debug (0, "* CycleModeReset Step:%d", data_reset.mr_step);
// debug (0, "* CycleModeReset Step:%d", data_reset.mr_step);
if (data_reset.mr_step == SMRESET_STEP_INIT) {
//
// init reset
data_reset.mr_idx = -1;
data_reset.mr_step++;
}
else if (data_reset.mr_step == SMRESET_STEP_INTERFACES) {
else if (data_reset.mr_step == SMRESET_STEP_LOCOMOTIVES) {
//
// reset interfaces
data_reset.mr_step++;
// reset locomotives, cycle 30ms per locomotive
if (data_reset.mr_idx < 0 || timer_get(&data_reset.mr_timestamp) > INTERFACE_LOCO_TIME) {
if (data_reset.mr_idx < -1) data_reset.mr_idx = -1;
data_reset.mr_idx++;
data_reset.mr_lastelm = locomotives.GetName(data_reset.mr_idx);
timer_start (&data_reset.mr_timestamp);
if (data_reset.mr_lastelm.length() > 0) {
debug (0, "* Reset Locomotive %s", data_reset.mr_lastelm.c_str());
LocomotiveSetReverse(data_reset.mr_lastelm, 0);
LocomotiveSetSpeed(data_reset.mr_lastelm, 0);
}
else {
data_reset.mr_idx = -1;
data_reset.mr_step++;
data_reset.mr_lastelm;
}
}
}
else if (data_reset.mr_step == SMRESET_STEP_LOCOMOTIVES) {
else if (data_reset.mr_step == SMRESET_STEP_TURNOUTS) {
//
// reset locomotives
data_reset.mr_step++;
// reset turnouts
if (data_reset.mr_idx < 0 || timer_get(&data_reset.mr_timestamp) > INTERFACE_TURN_TIME) {
int flags, active;
if (data_reset.mr_idx < -1) data_reset.mr_idx = -1;
data_reset.mr_idx++;
data_reset.mr_lastelm = turnouts.GetName(data_reset.mr_idx);
flags = turnouts.GetFlags(data_reset.mr_idx);
if (flags & TURNOUT_F_TURNOUT) active = 1;
else active = 0;
timer_start (&data_reset.mr_timestamp);
if (data_reset.mr_lastelm.length() > 0) {
debug (0, "* Reset Turnout %s", data_reset.mr_lastelm.c_str());
TurnoutSet(data_reset.mr_lastelm, active);
}
else {
data_reset.mr_idx = -1;
data_reset.mr_step++;
data_reset.mr_lastelm;
}
}
}
else if (data_reset.mr_step == SMRESET_STEP_SENSORS) {
//
@ -191,11 +231,13 @@ void Server::CycleModeReset() {
}
sensors.GetJSONAll(&json);
data_reset.mr_idx = -1;
data_reset.mr_step++;
}
else if (data_reset.mr_step == SMRESET_STEP_TURNOUTS) {
else if (data_reset.mr_step == SMRESET_STEP_INTERFACES) {
//
// reset turnouts
// reset interfaces
data_reset.mr_idx = -1;
data_reset.mr_step++;
}
else {

@ -260,3 +260,29 @@ void Turnouts::Loop() {
}
UnLock();
};
string Turnouts::GetName(int idx) {
string result = "";
Lock();
if (idx <= max && idx >= 0)
result = turnouts[idx].name;
UnLock();
return result;
};
int Turnouts::GetFlags(int idx) {
int result = 0;
Lock();
if (idx <= max && idx >= 0)
result = turnouts[idx].flags;
UnLock();
return result;
};

@ -50,6 +50,9 @@ class Turnouts {
void GetJSONAll(JSONParse *json);
Turnout GetTurnoutFromJSON(JSONParse *j);
string GetName(int idx);
int GetFlags(int idx);
void SetFromBus(string name, int addr, int active);
};

@ -1,4 +1,9 @@
:root {
--bg-color: darkslategrey;
--input-bg-color: #121;
--input-fg-color: lightgray;
}
.GUIwindow {
float:left;
@ -10,7 +15,7 @@
.GUIwindowHead {
border: 1px solid black;
background: blue;
background: darkgreen;
color: white;
margin: 0px;
padding: 5px;
@ -21,10 +26,27 @@
.GUIwindowClient {
overflow: auto;
padding: 5px;
background-color: white;
background-color: var(--bg-color);
color: lightgray;
}
.GUIbutton {
}
button {
background-color: var(--input-bg-color);
color: var(--input-fg-color);
}
input {
border: 1px solid var(--input-bg-color);
background-color: var(--input-bg-color);
color: var(--input-fg-color);
}
td {
color: var(--input-fg-color);
}

Loading…
Cancel
Save