remove test cmd, introduce resources to cmdServer

This commit is contained in:
hg
2014-03-05 15:59:49 +01:00
parent 5375925f34
commit 5d86d6c2bd
6 changed files with 17 additions and 29 deletions

View File

@ -55,6 +55,11 @@ const uint8_t STATE_20_MSG_2_KEY = 39;
const uint8_t STATE_20_MSG_3_KEY = 40; const uint8_t STATE_20_MSG_3_KEY = 40;
const uint8_t STATE_20_MSG_4_KEY = 41; const uint8_t STATE_20_MSG_4_KEY = 41;
const uint8_t COLON_SPACE_KEY = 42; const uint8_t COLON_SPACE_KEY = 42;
const uint8_t CMDSERVER_HELP_KEY = 43;
const uint8_t CMDSERVER_CMD_NOT_FOUND_KEY = 44;
const uint8_t THERMCONFIG_HELP_KEY = 45;
const uint8_t THERMVALUES_HELP_KEY = 46;
const uint8_t THERMCALIBRATE_HELP_KEY = 47;
/* /*
@ -102,6 +107,11 @@ const String TEXT_RESOURCES[] = {
"Calibration stopped", "Calibration stopped",
"Save calibration factor for channel ", "Save calibration factor for channel ",
": ", ": ",
"HELP List this help for all commands",
"command not found",
"Thermometer configuration operations",
"Show thermometer measurement values",
"Thermometer calibration operations",
}; };
*/ */

View File

@ -1,14 +1,12 @@
#include "ThermometerPro.h" #include "ThermometerPro.h"
#include "cmd.h" #include "cmd.h"
#include "test.h"
#include "uptime.h" #include "uptime.h"
#include "thermometer.h" #include "thermometer.h"
#include "Config.h" #include "Config.h"
static CmdServer cmdServer(&Serial); static CmdServer cmdServer(&Serial);
static TestCmd testCmd;
static ConfigInvalidateCmd configInvalidateCmd; static ConfigInvalidateCmd configInvalidateCmd;
static Uptime uptime; static Uptime uptime;
static Thermometer thermometer; static Thermometer thermometer;
@ -16,7 +14,6 @@ static Thermometer thermometer;
void setup() { void setup() {
cmdServer.begin(); cmdServer.begin();
testCmd.registerYourself(&cmdServer);
configInvalidateCmd.registerYourself(&cmdServer); configInvalidateCmd.registerYourself(&cmdServer);
uptime.begin(&cmdServer); uptime.begin(&cmdServer);
thermometer.begin(&cmdServer); thermometer.begin(&cmdServer);

View File

@ -2,6 +2,7 @@
#include "cmd.h" #include "cmd.h"
#include "fatal.h" #include "fatal.h"
#include "Resources.h"
void Cmd::registerYourself(CmdServer *cmdServer) { void Cmd::registerYourself(CmdServer *cmdServer) {
@ -73,7 +74,7 @@ void CmdServer::parseCommand() {
Cmd *c = cmdList[i]; Cmd *c = cmdList[i];
m_stream->println(c->getCmdName() + " " + c->getHelp()); m_stream->println(c->getCmdName() + " " + c->getHelp());
} }
m_stream->println("HELP List this help for all commands"); m_stream->println(getResource(CMDSERVER_HELP_KEY));
} else { } else {
bool found = false; bool found = false;
for (uint8_t i = 0; i < cmdListIdx; i++) { for (uint8_t i = 0; i < cmdListIdx; i++) {
@ -88,7 +89,7 @@ void CmdServer::parseCommand() {
} }
} }
if (! found) if (! found)
m_stream->println("command not found"); m_stream->println(getResource(CMDSERVER_CMD_NOT_FOUND_KEY));
} }
} }

View File

@ -1,7 +0,0 @@
#include <WString.h>
#include "test.h"
String TestCmd::exec(String params) {
return "Result of testCmd";
}

14
test.h
View File

@ -1,14 +0,0 @@
#ifndef TEST_H_
#define TEST_H_
#include "cmd.h"
class TestCmd : public Cmd {
public:
virtual String getCmdName() { return "TEST"; }
virtual String getHelp() { return "Just a test command"; }
virtual String exec(String params);
};
#endif /* TEST_H_ */

View File

@ -10,6 +10,7 @@
#include <Metro.h> #include <Metro.h>
#include "cmd.h" #include "cmd.h"
#include "Resources.h"
const bool DEBUG = true; const bool DEBUG = true;
const bool INFO = true; const bool INFO = true;
@ -30,7 +31,7 @@ class ThermConfig : public Cmd {
public: public:
ThermConfig(Thermometer *thermometer) : m_thermometer(thermometer) {}; ThermConfig(Thermometer *thermometer) : m_thermometer(thermometer) {};
virtual String getCmdName() { return "TCFG"; } virtual String getCmdName() { return "TCFG"; }
virtual String getHelp() { return "Thermometer configuration operations"; } virtual String getHelp() { return getResource(THERMCONFIG_HELP_KEY); }
virtual String exec(String params); virtual String exec(String params);
private: private:
Thermometer *m_thermometer; Thermometer *m_thermometer;
@ -40,7 +41,7 @@ class ThermValues : public Cmd {
public: public:
ThermValues(Thermometer *thermometer) : m_thermometer(thermometer) {}; ThermValues(Thermometer *thermometer) : m_thermometer(thermometer) {};
virtual String getCmdName() { return "TVAL"; } virtual String getCmdName() { return "TVAL"; }
virtual String getHelp() { return "Show thermometer measurement values"; } virtual String getHelp() { return getResource(THERMVALUES_HELP_KEY); }
virtual String exec(String params); virtual String exec(String params);
private: private:
Thermometer *m_thermometer; Thermometer *m_thermometer;
@ -50,7 +51,7 @@ class ThermCalibrate : public Cmd {
public: public:
ThermCalibrate(Thermometer *thermometer); ThermCalibrate(Thermometer *thermometer);
virtual String getCmdName() { return "TCALIBR"; } virtual String getCmdName() { return "TCALIBR"; }
virtual String getHelp() { return "Thermometer calibration operations"; } virtual String getHelp() { return getResource(THERMCALIBRATE_HELP_KEY); }
virtual String exec(String params); virtual String exec(String params);
friend class Thermometer; friend class Thermometer;
private: private: