Cumulocity Official / Mbed 2 deprecated MbedSmartRestMain Featured

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Vincent Wochnik

Revision:
93:0acd11870c6a
Parent:
92:48069375dffa
Child:
96:5dfdc8568e9f
--- a/config/ConfigurationSynchronization.cpp	Fri Mar 20 14:27:10 2015 +0000
+++ b/config/ConfigurationSynchronization.cpp	Mon Apr 13 14:24:58 2015 +0000
@@ -58,8 +58,10 @@
 
 bool ConfigurationSynchronization::updateConfiguration(const char *cfg)
 {
-    if (!_deviceConfiguration.read(cfg))
+    if (!_deviceConfiguration.read(cfg)) {
+        aError("updateConfiguration: Unable to read device configuration!\r\n");
         return false;
+    }
     
     if (!_configurationProperties.validateProperties()) {
         loadConfiguration();
@@ -74,8 +76,10 @@
 {
     char buf[256];
     
-    if (!_deviceConfiguration.write(buf, sizeof(buf)))
+    if (!_deviceConfiguration.write(buf, sizeof(buf))) {
+        aError("updateDeviceObject: Unable to write device configuration!\r\n");
         return false;
+    }
 
     ComposedRecord record;
     ParsedRecord received;
@@ -84,29 +88,29 @@
     IntegerValue deviceId(_deviceId);
     CharValue config(buf);
     IntegerValue responsibility(_configurationProperties.readInterval());
-    if ((!record.add(msgId)) || (!record.add(deviceId)) || (!record.add(config)) || (!record.add(responsibility)))
+    if (!record.add(msgId) || !record.add(deviceId) || !record.add(config) || !record.add(responsibility)) {
+        aWarning("updateDeviceObject: Adding record failed!\r\n");
         return false;
-
+    }
+    
     if (_client.send(record) != SMARTREST_SUCCESS) {
-        aError("Sending configuration failed.\r\n");
+        aWarning("Sending configuration failed.\r\n");
         _client.stop();
         return false;
     }
-
+    
     if (_client.receive(received) != SMARTREST_SUCCESS) {
-        aError("Connection failure or invalid configuration.\r\n");
+        aWarning("Receiving configuration failed.\r\n");
         _client.stop();
         return false;
     }
     _client.stop();
 
     if (received.values() != 3) {
-        aError("Unmatching configuration data received, expected 3, but %d received.\r\n", received.values());
+        aError("Invalid configuration received, expected 3 values, but %d received.\r\n", received.values());
         return false;
-    }
-    
-    if (received.value(0).integerValue() != 201) {
-        aError("Bad configuration data received.\r\n");
+    } else if (received.value(0).integerValue() != 201) {
+        aError("updateDeviceObject: Unexpected message ID %ld received.\r\n", received.value(0).integerValue());
         return false;
     }
     return true;
@@ -116,12 +120,14 @@
 {
     char buf[256];
     
-    if (!_deviceMemory.loadConfiguration(buf, sizeof(buf)))
+    if (!_deviceMemory.loadConfiguration(buf, sizeof(buf))) {
+        aError("loadConfiguration: Unable to load device configuration!\r\n");
         return false;
-    
-    if (!_deviceConfiguration.read(buf))
+    }
+    if (!_deviceConfiguration.read(buf)) {
+        aError("loadConfiguration: Unable to read device configuration!\r\n");
         return false;
-
+    }
     return true;
 }
 
@@ -129,11 +135,13 @@
 {
     char buf[256];
     
-    if (!_deviceConfiguration.write(buf, sizeof(buf)))
+    if (!_deviceConfiguration.write(buf, sizeof(buf))) {
+        aError("saveConfiguration: Unable to write device configuration!\r\n");
         return false;
-    
-    if (!_deviceMemory.saveConfiguration(buf))
+    }
+    if (!_deviceMemory.saveConfiguration(buf)) {
+        aError("saveConfiguration: Unable to save device configuration!\r\n");
         return false;
-    
+    }
     return true;
 }