add command, argument evaluation

This commit is contained in:
hg
2015-05-13 17:37:05 +02:00
parent fe3f5d4b84
commit b27f964e20
2 changed files with 40 additions and 4 deletions

View File

@ -68,9 +68,42 @@ String MqttConfig::exec(String params) {
}
} else if (params.startsWith("add ")) {
// add an mbus client, params: token address period
char paramBuf[64];
char *paramPtr;
strncpy(paramBuf, params.c_str(), sizeof(paramBuf));
paramPtr = paramBuf;
char *tokenStr = 0;
char *addressStr = 0;
char *periodStr = 0;
if ((paramPtr != 0) && (*paramPtr != 0)){
// command
strsep(&paramPtr, " ");
}
if ((paramPtr != 0) && (*paramPtr != 0)){
tokenStr = strsep(&paramPtr, " ");
}
if ((paramPtr != 0) && (*paramPtr != 0)){
addressStr = strsep(&paramPtr, " ");
}
if ((paramPtr != 0) && (*paramPtr != 0)){
periodStr = strsep(&paramPtr, " ");
}
configWrite(CONFIG_DEVICES, sizeof(mc->m_mbusDevTuple), (char*)mc->m_mbusDevTuple);
res = "done";
if ((tokenStr != 0) && (*tokenStr != 0) &&
(addressStr != 0) && (*addressStr != 0) &&
(periodStr != 0) && (*periodStr != 0)) {
*out << "Token: " << tokenStr << endl;
*out << "Address: " << addressStr << endl;
*out << "Period: " << periodStr << endl;
res = "done";
} else {
*out << "not enough arguments" << endl;
res = "failure";
}
// configWrite(CONFIG_DEVICES, sizeof(mc->m_mbusDevTuple), (char*)mc->m_mbusDevTuple);
} else if (params.startsWith("del ")) {
// delete an mbus client, params: index
int space = params.indexOf(' ');