|
|
@ -59,25 +59,26 @@ Server::~Server() {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// server thread will cycle as long as running is set to true
|
|
|
|
|
|
|
|
// most important in each cycle there will be
|
|
|
|
void Server::ThreadProcess() {
|
|
|
|
void Server::ThreadProcess() {
|
|
|
|
int i = 0;
|
|
|
|
int i = 0;
|
|
|
|
while (running) {
|
|
|
|
while (running) {
|
|
|
|
interfaces.Loop();
|
|
|
|
interfaces.Loop();
|
|
|
|
turnouts.Loop();
|
|
|
|
turnouts.Loop();
|
|
|
|
|
|
|
|
|
|
|
|
debug (0, "%s:%d mode:%d data_reset.step:%d data_reset.idx:%d", __FILE__, __LINE__, mode, data_reset.mr_step, data_reset.mr_idx);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// startup process
|
|
|
|
// startup process
|
|
|
|
if (mode == SMODE_STARTUP) {
|
|
|
|
if (mode == SMODE_STARTUP) {
|
|
|
|
SetModeReset();
|
|
|
|
SetModeReset(); // currently there is not much to do.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// reset all internal data
|
|
|
|
// reset all internal data
|
|
|
|
else if (mode == SMODE_RESET) {
|
|
|
|
else if (mode == SMODE_RESET)
|
|
|
|
SetModeManual();
|
|
|
|
CycleModeReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// mode manual
|
|
|
|
// mode manual
|
|
|
@ -133,34 +134,101 @@ bool Server::IsChanged() {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Set Mode Auto
|
|
|
|
// Set Mode Auto
|
|
|
|
void Server::SetModeAuto() {
|
|
|
|
void Server::SetModeAuto() {
|
|
|
|
debug (0, "%s:%d * Mode Auto", __FILE__, __LINE__);
|
|
|
|
debug (0, "%s:%d * Set Mode Auto", __FILE__, __LINE__);
|
|
|
|
status_text = "Mode Auto";
|
|
|
|
status_text = "Mode Auto";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Set Mode Manual
|
|
|
|
// Set Mode Manual
|
|
|
|
void Server::SetModeManual() {
|
|
|
|
void Server::SetModeManual() {
|
|
|
|
debug (0, "%s:%d * Mode Manual", __FILE__, __LINE__);
|
|
|
|
debug (0, "%s:%d * Set Mode Manual", __FILE__, __LINE__);
|
|
|
|
|
|
|
|
mode = SMODE_MANUAL;
|
|
|
|
status_text = "Mode Manual";
|
|
|
|
status_text = "Mode Manual";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// run a single cycle in reset mode
|
|
|
|
|
|
|
|
// each step will only reset one single step.
|
|
|
|
|
|
|
|
void Server::CycleModeReset() {
|
|
|
|
|
|
|
|
JSONParse json;
|
|
|
|
|
|
|
|
list<JSONElement> elements;
|
|
|
|
|
|
|
|
list<JSONElement>::iterator iter;
|
|
|
|
|
|
|
|
json.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug (0, "* CycleModeReset Step:%d", data_reset.mr_step);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data_reset.mr_step == SMRESET_STEP_INIT) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// init reset
|
|
|
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_INTERFACES) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// reset interfaces
|
|
|
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_LOCOMOTIVES) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// reset locomotives
|
|
|
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_SENSORS) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// reset sensors
|
|
|
|
|
|
|
|
// all can be done in one single cycle.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
int i; // index of sensor
|
|
|
|
|
|
|
|
int oldflags; // old flags
|
|
|
|
|
|
|
|
Sensor sensor; // sensor data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; sensors.Get(i, &sensor) == 1; i++) {
|
|
|
|
|
|
|
|
oldflags = sensor.flags;
|
|
|
|
|
|
|
|
sensor.flags &= ~(SENSOR_F_ACTIVE);
|
|
|
|
|
|
|
|
debug (0, "* Reset Sensor: '%s' (%d -> %d)", sensor.name, oldflags, sensor.flags);
|
|
|
|
|
|
|
|
if (oldflags != sensor.flags) // only update if needed
|
|
|
|
|
|
|
|
sensors.Change(&sensor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sensors.GetJSONAll(&json);
|
|
|
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_TURNOUTS) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// reset turnouts
|
|
|
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
SetModeManual();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// adding update data
|
|
|
|
|
|
|
|
elements = json.GetElements();
|
|
|
|
|
|
|
|
for (iter = elements.begin(); iter != elements.end(); iter++) {
|
|
|
|
|
|
|
|
if (network) network->ChangeListPushToAll("{"+(*iter).GetString()+"}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Set Mode Error
|
|
|
|
// Set Mode Error
|
|
|
|
// FIXME: maybe adding error text as parameter?
|
|
|
|
// FIXME: maybe adding error text as parameter?
|
|
|
|
void Server::SetModeError(string text) {
|
|
|
|
void Server::SetModeError(string text) {
|
|
|
|
debug (0, "%s:%d * Mode Error :'%s'", __FILE__, __LINE__, text.c_str());
|
|
|
|
debug (0, "%s:%d * Set Mode Error :'%s'", __FILE__, __LINE__, text.c_str());
|
|
|
|
status_text = "Error:'" + text + "'";
|
|
|
|
status_text = "Error:'" + text + "'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Set Mode Reset
|
|
|
|
// Set Mode Reset
|
|
|
|
void Server::SetModeReset() {
|
|
|
|
void Server::SetModeReset() {
|
|
|
|
debug (0, "%s:%d * Reset Data", __FILE__, __LINE__);
|
|
|
|
debug (0, "%s:%d * Set Reset Data", __FILE__, __LINE__);
|
|
|
|
status_text = "Mode Reset";
|
|
|
|
status_text = "Mode Reset";
|
|
|
|
|
|
|
|
|
|
|
|
mode = SMODE_RESET;
|
|
|
|
mode = SMODE_RESET;
|
|
|
|
data_reset.mr_step = SMRESET_STEP_INIT;
|
|
|
|
data_reset.mr_step = SMRESET_STEP_INIT;
|
|
|
|
data_reset.mr_idx = -1;
|
|
|
|
data_reset.mr_idx = -1;
|
|
|
|
|
|
|
|
data_reset.mr_lastelm = "";
|
|
|
|
gettimeofday(&data_reset.mr_timestamp, NULL);
|
|
|
|
gettimeofday(&data_reset.mr_timestamp, NULL);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|