aboutsummaryrefslogtreecommitdiff
path: root/src/standalone.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/standalone.cpp')
-rw-r--r--src/standalone.cpp45
1 files changed, 9 insertions, 36 deletions
diff --git a/src/standalone.cpp b/src/standalone.cpp
index 20e4ade..16225f0 100644
--- a/src/standalone.cpp
+++ b/src/standalone.cpp
@@ -106,6 +106,7 @@
#include <iostream>
#include <thread>
#include <sstream>
+#include <map>
#include "../include/Gobbledegook.h"
@@ -120,11 +121,8 @@ static const int kMaxAsyncInitTimeoutMS = 30 * 1000;
// Server data values
//
-// The battery level ("battery/level") reported by the server (see Server.cpp)
-static uint8_t serverDataBatteryLevel = 78;
-
// The text string ("text/string") used by our custom text string service (see Server.cpp)
-static std::string serverDataTextString = "Hello, world!";
+static std::map<std::string,int> temperatures;
//
// Logging
@@ -192,17 +190,9 @@ const void *dataGetter(const char *pName)
}
std::string strName = pName;
+ auto it = temperatures.find(strName);
+ if (it != temperatures.end()) return &(*it);
- if (strName == "battery/level")
- {
- return &serverDataBatteryLevel;
- }
- else if (strName == "text/string")
- {
- return serverDataTextString.c_str();
- }
-
- LogWarn((std::string("Unknown name for server data getter request: '") + pName + "'").c_str());
return nullptr;
}
@@ -227,22 +217,10 @@ int dataSetter(const char *pName, const void *pData)
std::string strName = pName;
- if (strName == "battery/level")
- {
- serverDataBatteryLevel = *static_cast<const uint8_t *>(pData);
- LogDebug((std::string("Server data: battery level set to ") + std::to_string(serverDataBatteryLevel)).c_str());
- return 1;
- }
- else if (strName == "text/string")
- {
- serverDataTextString = static_cast<const char *>(pData);
- LogDebug((std::string("Server data: text string set to '") + serverDataTextString + "'").c_str());
- return 1;
- }
-
- LogWarn((std::string("Unknown name for server data setter request: '") + pName + "'").c_str());
-
- return 0;
+ int16_t temp = *static_cast<const int16_t *>(pData);
+ temperatures[strName]=temp;
+ LogDebug((std::string("Server data: temperature of ")+strName+" set to " + std::to_string(temp)).c_str());
+ return 1;
}
//
@@ -299,20 +277,15 @@ int main(int argc, char **ppArgv)
// This first parameter (the service name) must match tha name configured in the D-Bus permissions. See the Readme.md file
// for more information.
//
- if (!ggkStart("gobbledegook", "Gobbledegook", "Gobbledegook", dataGetter, dataSetter, kMaxAsyncInitTimeoutMS))
+ if (!ggkStart("termostore", "termostore", "thermo", dataGetter, dataSetter, kMaxAsyncInitTimeoutMS))
{
return -1;
}
// Wait for the server to start the shutdown process
- //
- // While we wait, every 15 ticks, drop the battery level by one percent until we reach 0
while (ggkGetServerRunState() < EStopping)
{
std::this_thread::sleep_for(std::chrono::seconds(15));
-
- serverDataBatteryLevel = std::max(serverDataBatteryLevel - 1, 0);
- ggkNofifyUpdatedCharacteristic("/com/gobbledegook/battery/level");
}
// Wait for the server to come to a complete stop (CTRL-C from the command line)