diff options
-rw-r--r-- | src/Server.cpp | 25 | ||||
-rw-r--r-- | src/standalone.cpp | 39 |
2 files changed, 26 insertions, 38 deletions
diff --git a/src/Server.cpp b/src/Server.cpp index f3464c6..bdc98a9 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -294,20 +294,20 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam .gattServiceBegin("thermo", "11111111-2222-3333-4444-000000000000") // Characteristic: String value - .gattCharacteristicBegin("room1", "11111111-2222-3333-4444-000000000001", {"read", "write"}) + .gattCharacteristicBegin("temperature", "11111111-2222-3333-4444-000000000001", {"read","write"}) // Standard characteristic "ReadValue" method call .onReadValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { - const char *temperature = self.getDataPointer<const char*>("room-1", ""); - self.methodReturnValue(pInvocation, temperature, true); + const char *fake_temp = "0"; + self.methodReturnValue(pInvocation, fake_temp, true); }) // Standard characteristic "WriteValue" method call .onWriteValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { GVariant *pValue = g_variant_get_child_value(pParameters, 0); - self.setDataPointer("room-1", Utils::stringFromGVariantByteArray(pValue).c_str()); + self.setDataPointer("temperature", Utils::stringFromGVariantByteArray(pValue).c_str()); }) // GATT Descriptor: Characteristic User Description (0x2901) @@ -318,7 +318,7 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam // Standard descriptor "ReadValue" method call .onReadValue(DESCRIPTOR_METHOD_CALLBACK_LAMBDA { - const char *pDescription = "temperature in room 1"; + const char *pDescription = "temperature in a room"; self.methodReturnValue(pInvocation, pDescription, true); }) @@ -327,20 +327,13 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam .gattCharacteristicEnd() // Characteristic: String value - .gattCharacteristicBegin("room2", "11111111-2222-3333-4444-000000000002", {"read", "write"}) + .gattCharacteristicBegin("time_to_next_reading", "11111111-2222-3333-4444-000000000002", {"read"}) // Standard characteristic "ReadValue" method call .onReadValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { - const char *temperature = self.getDataPointer<const char*>("room-2", ""); - 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.setDataPointer("room-2", Utils::stringFromGVariantByteArray(pValue).c_str()); + const char *time = self.getDataPointer<const char*>("time-to-next-sample", ""); + self.methodReturnValue(pInvocation, time, true); }) // GATT Descriptor: Characteristic User Description (0x2901) @@ -351,7 +344,7 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam // Standard descriptor "ReadValue" method call .onReadValue(DESCRIPTOR_METHOD_CALLBACK_LAMBDA { - const char *pDescription = "temperature in room 2"; + const char *pDescription = "time (in seconds) to wait before sending the next temperature reading"; self.methodReturnValue(pInvocation, pDescription, true); }) diff --git a/src/standalone.cpp b/src/standalone.cpp index 9b32043..9ab2ceb 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; } |