ARM mbed M2X API Client: The ARM mbed client library is used to send/receive data to/from AT&T's M2X service from mbed LPC1768 microcontrollers.

Dependents:   m2x-demo-all M2X_MTS_ACCEL_DEMO M2X_MTS_Accel M2X_K64F_ACCEL ... more

Files at this revision

API Documentation at this revision

Comitter:
NetArc
Date:
Sun Sep 07 05:28:55 2014 +0000
Parent:
0:f479e4f4db0e
Child:
3:2b527486e864
Commit message:
fix for parsing numeric stream values

Changed in this revision

M2XStreamClient.cpp Show annotated file Show diff for this revision Revisions of this file
M2XStreamClient.h Show annotated file Show diff for this revision Revisions of this file
StreamParseFunctions.h Show annotated file Show diff for this revision Revisions of this file
--- a/M2XStreamClient.cpp	Wed Feb 12 19:43:34 2014 +0000
+++ b/M2XStreamClient.cpp	Sun Sep 07 05:28:55 2014 +0000
@@ -7,6 +7,25 @@
 
 const char* M2XStreamClient::kDefaultM2XHost = "api-m2x.att.com";
 
+// import from jsonlite.c
+typedef uint8_t parse_state;
+struct jsonlite_parser_struct {
+    const uint8_t *cursor;
+    const uint8_t *limit;
+    const uint8_t *token_start;
+    const uint8_t *buffer;
+    
+    uint8_t *buffer_own;
+    uint8_t *rest;
+    size_t rest_size;
+    
+    parse_state *current;
+    const parse_state *last;
+    
+    jsonlite_result result;
+    jsonlite_parser_callbacks callbacks;
+};
+
 int print_encoded_string(Print* print, const char* str);
 int tolower(int ch);
 
@@ -287,7 +306,7 @@
 
 int M2XStreamClient::readStreamValue(stream_value_read_callback callback,
                                      void* context) {
-  const int BUF_LEN = 32;
+  const int BUF_LEN = 64;
   char buf[BUF_LEN];
 
   int length = readContentLength();
@@ -311,6 +330,7 @@
   jsonlite_parser_callbacks cbs = jsonlite_default_callbacks;
   cbs.key_found = on_stream_key_found;
   cbs.string_found = on_stream_string_found;
+  cbs.number_found = on_stream_string_found;
   cbs.context.client_state = &state;
 
   jsonlite_parser p = jsonlite_parser_init(jsonlite_parser_estimate_size(5));
@@ -319,7 +339,6 @@
   jsonlite_result result = jsonlite_result_unknown;
   while (index < length) {
     int i = 0;
-
     DBG("%s", "Received Data: ");
     while ((i < BUF_LEN) && _client->available()) {
       buf[i++] = _client->read();
@@ -342,8 +361,8 @@
       close();
       return E_JSON_INVALID;
     }
-
-    index += i;
+    
+    index += i - p->rest_size;
   }
 
   jsonlite_parser_release(p);
--- a/M2XStreamClient.h	Wed Feb 12 19:43:34 2014 +0000
+++ b/M2XStreamClient.h	Sun Sep 07 05:28:55 2014 +0000
@@ -3,6 +3,7 @@
 
 #define MIN(a, b) (((a) > (b))?(b):(a))
 
+#define DEBUG
 #define MBED_PLATFORM
 
 #ifdef ARDUINO_PLATFORM
--- a/StreamParseFunctions.h	Wed Feb 12 19:43:34 2014 +0000
+++ b/StreamParseFunctions.h	Sun Sep 07 05:28:55 2014 +0000
@@ -3,7 +3,7 @@
 
 // Data structures and functions used to parse stream values
 
-#define STREAM_BUF_LEN 20
+#define STREAM_BUF_LEN 64
 
 typedef struct {
   uint8_t state;
@@ -45,7 +45,6 @@
 {
   stream_parsing_context_state* state =
       (stream_parsing_context_state*) context->client_state;
-
   if (TEST_IS_AT(state->state)) {
     strncpy(state->at_str, (const char*) token->start,
             MIN(token->end - token->start, STREAM_BUF_LEN));