Official reference client implementation for Cumulocity SmartREST on u-blox C027.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: operation/OperationExecutor.cpp
- Revision:
- 66:31c754c36ed7
- Parent:
- 65:a62dbef2f924
- Child:
- 68:0dc778a16d0d
--- a/operation/OperationExecutor.cpp Thu Oct 30 13:38:20 2014 +0000 +++ b/operation/OperationExecutor.cpp Thu Oct 30 14:46:22 2014 +0000 @@ -5,6 +5,9 @@ #include <string.h> #include <stdio.h> +#define FOUND_RELAY 1 +#define FOUND_MESSAGE 2 + OperationExecutor::OperationExecutor(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId, DeviceIO& io) : _client(client), _tpl(tpl), @@ -25,17 +28,22 @@ return false; // Relay operation response - // Response: 211,<OPERATION/ID>,<STATUS> + // Response: 220,<OPERATION/ID>,<STATUS> if (!_tpl.add("11,220,,\"$.c8y_Relay\",\"$.id\",\"$.c8y_Relay.relayState\"\r\n")) return false; + // Message operation response + // Response: 221,<OPERATION/ID>,<MESSAGE> + if (!_tpl.add("11,221,,\"$.c8y_Message\",\"$.id\",\"$.c8y_Message.text\"\r\n")) + return false; + _init = true; return true; } bool OperationExecutor::executeOperation(OperationStore::Operation& op) { - uint8_t ret; bool found, relayState; + uint8_t ret; uint8_t found; bool relayState; char message[128]; ComposedRecord record; ParsedRecord received; @@ -49,7 +57,7 @@ return false; } - found = false; + found = 0; while ((ret = _client.receive(received)) == SMARTREST_SUCCESS) { if ((received.values() == 4) && (received.value(0).valueType() == VALUE_INTEGER) && @@ -58,16 +66,32 @@ (received.value(2).integerValue() == op.identifier) && (received.value(3).valueType() == VALUE_CHARACTER)) { relayState = (strcmp("CLOSED", received.value(3).characterValue()) == 0); - found = true; + found = FOUND_RELAY; + break; + } + + if ((received.values() == 4) && + (received.value(0).valueType() == VALUE_INTEGER) && + (received.value(0).integerValue() == 221) && + (received.value(2).valueType() == VALUE_INTEGER) && + (received.value(2).integerValue() == op.identifier) && + (received.value(3).valueType() == VALUE_CHARACTER)) { + strncpy(message, received.value(3).characterValue(), 128); + message[127] = '\0'; + found = FOUND_MESSAGE; break; } } _client.stop(); - if (!found) + switch (found) { + case FOUND_RELAY: + return executeRelayStateUpdate(relayState); + case FOUND_MESSAGE: + return executeMessageDisplay(message); + default: return false; - - return executeRelayStateUpdate(relayState); + } } bool OperationExecutor::executeRelayStateUpdate(bool relayState) @@ -78,3 +102,9 @@ _io.deviceFeedback().openRelay(); return true; } + +bool OperationExecutor::executeMessageDisplay(const char *message) +{ + _io.lcdPrint(message); + return true; +}