aboutsummaryrefslogtreecommitdiff
path: root/src/standalone.cpp
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2018-03-31 17:08:42 +0100
committerdakkar <dakkar@thenautilus.net>2019-03-20 12:44:52 +0000
commitf3c110e8c370c8e64ac767b912fceaff97d66e7d (patch)
tree86ed940114a9cc580a7759daf453cc54659109f4 /src/standalone.cpp
parentgeneral autotools bump (diff)
downloadgobbledegook-f3c110e8c370c8e64ac767b912fceaff97d66e7d.tar.gz
gobbledegook-f3c110e8c370c8e64ac767b912fceaff97d66e7d.tar.bz2
gobbledegook-f3c110e8c370c8e64ac767b912fceaff97d66e7d.zip
closer to what I want
* setting the temperature just prints it out * asking for the next time to sample returns a constant (later, it will read from stdin) with this, I can wrap this program with `IPC::Run` or similar, and write all the logic in Perl! the esp32 will send its own device id with the temperature, and we can safely assume that the request for "next time" will come from the same device
Diffstat (limited to 'src/standalone.cpp')
-rw-r--r--src/standalone.cpp39
1 files changed, 17 insertions, 22 deletions
diff --git a/src/standalone.cpp b/src/standalone.cpp
index b86e64e..19b2f51 100644
--- a/src/standalone.cpp
+++ b/src/standalone.cpp
@@ -118,12 +118,6 @@
static const int kMaxAsyncInitTimeoutMS = 30 * 1000;
//
-// Server data values
-//
-
-static std::vector<std::string> temperatures(5);
-
-//
// Logging
//
@@ -141,14 +135,14 @@ LogLevel logLevel = Normal;
// Our full set of logging methods (we just log to stdout)
//
// NOTE: Some methods will only log if the appropriate `logLevel` is set
-void LogDebug(const char *pText) { if (logLevel <= Debug) { std::cout << " DEBUG: " << pText << std::endl; } }
-void LogInfo(const char *pText) { if (logLevel <= Verbose) { std::cout << " INFO: " << pText << std::endl; } }
-void LogStatus(const char *pText) { if (logLevel <= Normal) { std::cout << " STATUS: " << pText << std::endl; } }
-void LogWarn(const char *pText) { std::cout << "WARNING: " << pText << std::endl; }
-void LogError(const char *pText) { std::cout << "!!ERROR: " << pText << std::endl; }
-void LogFatal(const char *pText) { std::cout << "**FATAL: " << pText << std::endl; }
-void LogAlways(const char *pText) { std::cout << "..Log..: " << pText << std::endl; }
-void LogTrace(const char *pText) { std::cout << "-Trace-: " << pText << std::endl; }
+void LogDebug(const char *pText) { if (logLevel <= Debug) { std::cerr << " DEBUG: " << pText << std::endl; } }
+void LogInfo(const char *pText) { if (logLevel <= Verbose) { std::cerr << " INFO: " << pText << std::endl; } }
+void LogStatus(const char *pText) { if (logLevel <= Normal) { std::cerr << " STATUS: " << pText << std::endl; } }
+void LogWarn(const char *pText) { std::cerr << "WARNING: " << pText << std::endl; }
+void LogError(const char *pText) { std::cerr << "!!ERROR: " << pText << std::endl; }
+void LogFatal(const char *pText) { std::cerr << "**FATAL: " << pText << std::endl; }
+void LogAlways(const char *pText) { std::cerr << "..Log..: " << pText << std::endl; }
+void LogTrace(const char *pText) { std::cerr << "-Trace-: " << pText << std::endl; }
//
// Signal handling
@@ -190,9 +184,11 @@ const void *dataGetter(const char *pName)
std::string strName = pName;
LogInfo((std::string("reading: ")+strName).c_str());
-
- char idx = strName.back();
- return temperatures[idx-'0'].c_str();
+ // the only value the server can ask for is the "time to next
+ // sample"; this should be read from stdin, when we integrate
+ // with the rest of the thermostat
+ static const char *next_time = "30";
+ return next_time;
}
// Called by the server when it wants to update a named value
@@ -215,12 +211,11 @@ int dataSetter(const char *pName, const void *pData)
}
std::string strName = pName;
+ LogDebug((std::string("Server data: setting ")+strName).c_str());
+ // the server can only receive a temperature reading, let's print it
+ const char* strData = static_cast<const char *>(pData);
+ std::cout << strData << std::endl;
- const char* temp = static_cast<const char *>(pData);
- char idx = strName.back();
- temperatures[idx-'0']=temp;
-
- LogDebug((std::string("Server data: temperature of ")+strName+" set to " + temp).c_str());
return 1;
}