import for backup

origin
steffen 6 years ago
parent 3009c38ac9
commit 3ffbeee7f0

@ -45,6 +45,11 @@ Server::Server() {
thread_running = 0; thread_running = 0;
railways.SetSize(200, 200); railways.SetSize(200, 200);
status_text = "init server"; status_text = "init server";
mode = SMODE_STARTUP;
data_reset.mr_idx = -1;
data_reset.mr_step = SMRESET_STEP_INIT;
gettimeofday(&data_reset.mr_timestamp, NULL);
Load (); Load ();
}; };
@ -59,6 +64,31 @@ void Server::ThreadProcess() {
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
if (mode == SMODE_STARTUP) {
SetModeReset();
}
//
// reset all internal data
else if (mode == SMODE_RESET) {
SetModeManual();
}
//
// mode manual
else if (mode == SMODE_MANUAL) {
}
//
// mode auto
else if (mode == SMODE_AUTO) {
}
usleep (25000); usleep (25000);
} }
debug (0, "Server::ThreadProcess Finished"); debug (0, "Server::ThreadProcess Finished");
@ -102,14 +132,14 @@ bool Server::IsChanged() {
// //
// Set Mode Auto // Set Mode Auto
void Server::ModeAuto() { void Server::SetModeAuto() {
debug (0, "%s:%d * Mode Auto", __FILE__, __LINE__); debug (0, "%s:%d * Mode Auto", __FILE__, __LINE__);
status_text = "Mode Auto"; status_text = "Mode Auto";
} }
// //
// Set Mode Manual // Set Mode Manual
void Server::ModeManual() { void Server::SetModeManual() {
debug (0, "%s:%d * Mode Manual", __FILE__, __LINE__); debug (0, "%s:%d * Mode Manual", __FILE__, __LINE__);
status_text = "Mode Manual"; status_text = "Mode Manual";
} }
@ -117,16 +147,21 @@ void Server::ModeManual() {
// //
// Set Mode Error // Set Mode Error
// FIXME: maybe adding error text as parameter? // FIXME: maybe adding error text as parameter?
void Server::ModeError(string text) { void Server::SetModeError(string text) {
debug (0, "%s:%d * Mode Error :'%s'", __FILE__, __LINE__, text.c_str()); debug (0, "%s:%d * Mode Error :'%s'", __FILE__, __LINE__, text.c_str());
status_text = "Error:'" + text + "'"; status_text = "Error:'" + text + "'";
} }
// //
// Set Mode Reset // Set Mode Reset
void Server::ModeReset() { void Server::SetModeReset() {
debug (0, "%s:%d * Reset Data", __FILE__, __LINE__); debug (0, "%s:%d * Reset Data", __FILE__, __LINE__);
status_text = "Mode Reset"; status_text = "Mode Reset";
mode = SMODE_RESET;
data_reset.mr_step = SMRESET_STEP_INIT;
data_reset.mr_idx = -1;
gettimeofday(&data_reset.mr_timestamp, NULL);
}; };

@ -29,27 +29,28 @@
#include "sensor.h" #include "sensor.h"
#include "interface.h" #include "interface.h"
enum SSTATUS { enum SMODE {
SSTATUS_STARTUP, SMODE_STARTUP,
SSTATUS_RESET, SMODE_RESET,
SSTATUS_MANUAL, SMODE_MANUAL,
SSTATUS_AUTO, SMODE_AUTO,
SSTATUS_MAX SMODE_MAX
}; };
enum MRESET { enum SMRESET {
MRESET_STEP_INTERFACES, SMRESET_STEP_INIT,
MRESET_STEP_LOCOMOTIVES, SMRESET_STEP_LOCOMOTIVES,
MRESET_STEP_TURNOUTS, SMRESET_STEP_TURNOUTS,
MRESET_STEP_SENSORS, SMRESET_STEP_SENSORS,
SMRESET_STEP_INTERFACES,
MRESET_STEP_MAX SMRESET_STEP_MAX
}; };
struct s_ModeResetData{ struct s_ModeResetData{
int mr_step; // current step int mr_step; // current step
int mr_timestamp; // timestamp ( needed for times ) struct timeval mr_timestamp; // timestamp ( needed for times )
int mr_idx; // mode index int mr_idx; // mode index
} typedef ModeResetData; } typedef ModeResetData;
@ -119,10 +120,10 @@ public:
// FIXME: // FIXME:
// FIXME: // FIXME:
JSONParse GetJSONServerStatus(); JSONParse GetJSONServerStatus();
void ModeReset(); // mode Reset if finished will go to Manual void SetModeReset(); // mode Reset if finished will go to Manual
void ModeManual(); // Manual Mode void SetModeManual(); // Manual Mode
void ModeAuto(); // only allowed if Manual was set void SetModeAuto(); // only allowed if Manual was set
void ModeError(string text); // will cut power and keep this mode, until reset or Mode Manual void SetModeError(string text); // will cut power and keep this mode, until reset or Mode Manual
string GetStatus(); // return status string GetStatus(); // return status
///////////////////////////////////////// /////////////////////////////////////////

@ -113,7 +113,7 @@ int Session::ProcessData(JSONParse *jin, JSONParse *jout) {
} }
else if (command.compare("resetdata") == 0) { else if (command.compare("resetdata") == 0) {
debug (0, "* Reset All Data"); debug (0, "* Reset All Data");
server->ModeReset(); server->SetModeReset();
} }
else if (command.compare("getall") == 0) { else if (command.compare("getall") == 0) {
json.Clear(); json.Clear();

Loading…
Cancel
Save