From 939fd8f37fdab0941ae8eb3125bab572a97a0b26 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 31 Mar 2018 00:02:48 +0100 Subject: strings everywhere --- src/Server.cpp | 10 +++++----- src/standalone.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Server.cpp b/src/Server.cpp index 0917523..7e7e0f8 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -300,15 +300,15 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam // Standard characteristic "ReadValue" method call .onReadValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { - int16_t temperature = self.getDataValue("room-1", 0); + const char *temperature = self.getDataPointer("room-1", ""); self.methodReturnValue(pInvocation, temperature, true); }) // Standard characteristic "WriteValue" method call .onWriteValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { - GVariant *pValue = g_variant_get_child_value(pParameters, 0); - self.setDataValue("room-1", g_variant_get_int16(pValue)); + GVariant *pValue = g_variant_get_child_value(pParameters, 0); + self.setDataPointer("room-1", Utils::stringFromGVariantByteArray(pValue).c_str()); }) // GATT Descriptor: Characteristic User Description (0x2901) @@ -333,7 +333,7 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam // Standard characteristic "ReadValue" method call .onReadValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { - int16_t temperature = self.getDataValue("room-2", 0); + const char *temperature = self.getDataPointer("room-2", ""); self.methodReturnValue(pInvocation, temperature, true); }) @@ -341,7 +341,7 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam .onWriteValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { GVariant *pValue = g_variant_get_child_value(pParameters, 0); - self.setDataValue("room-2", g_variant_get_int16(pValue)); + self.setDataPointer("room-2", Utils::stringFromGVariantByteArray(pValue).c_str()); }) // GATT Descriptor: Characteristic User Description (0x2901) diff --git a/src/standalone.cpp b/src/standalone.cpp index 57177cd..b86e64e 100644 --- a/src/standalone.cpp +++ b/src/standalone.cpp @@ -106,7 +106,7 @@ #include #include #include -#include +#include #include "../include/Gobbledegook.h" @@ -121,7 +121,7 @@ static const int kMaxAsyncInitTimeoutMS = 30 * 1000; // Server data values // -static int16_t temperatures[] = {0,0,0,0,0}; +static std::vector temperatures(5); // // Logging @@ -192,7 +192,7 @@ const void *dataGetter(const char *pName) LogInfo((std::string("reading: ")+strName).c_str()); char idx = strName.back(); - return &(temperatures[idx-'0']); + return temperatures[idx-'0'].c_str(); } // Called by the server when it wants to update a named value @@ -216,11 +216,11 @@ int dataSetter(const char *pName, const void *pData) std::string strName = pName; - int16_t temp = *static_cast(pData); + const char* temp = static_cast(pData); char idx = strName.back(); temperatures[idx-'0']=temp; - LogDebug((std::string("Server data: temperature of ")+strName+" set to " + std::to_string(temp)).c_str()); + LogDebug((std::string("Server data: temperature of ")+strName+" set to " + temp).c_str()); return 1; } -- cgit v1.2.3