Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: WNCInterface_M2Xdemo ATT_WNCInterface_Info WNCInterface_HTTP_example Public_IoT_M2X_Cellular_Demo
Fork of M2XStreamClient by
Diff: StreamParseFunctions.h
- Revision:
- 22:4d895e732765
- Parent:
- 21:6878944d2ce2
- Child:
- 23:f32837239193
--- a/StreamParseFunctions.h Sat Jan 02 02:29:43 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-#ifndef StreamParseFunctions_h
-#define StreamParseFunctions_h
-
-// Data structures and functions used to parse stream values
-
-#define STREAM_BUF_LEN 32
-
-typedef struct {
- uint8_t state;
- char at_str[STREAM_BUF_LEN + 1];
- char value_str[STREAM_BUF_LEN + 1];
- int index;
-
- stream_value_read_callback callback;
- void* context;
-} stream_parsing_context_state;
-
-#define WAITING_AT 0x1
-#define GOT_AT 0x2
-#define WAITING_VALUE 0x4
-#define GOT_VALUE 0x8
-
-#define GOT_STREAM (GOT_AT | GOT_VALUE)
-#define TEST_GOT_STREAM(state_) (((state_) & GOT_STREAM) == GOT_STREAM)
-
-#define TEST_IS_AT(state_) (((state_) & (WAITING_AT | GOT_AT)) == WAITING_AT)
-#define TEST_IS_VALUE(state_) (((state_) & (WAITING_VALUE | GOT_VALUE)) == \
- WAITING_VALUE)
-
-static void on_stream_key_found(jsonlite_callback_context* context,
- jsonlite_token* token)
-{
- stream_parsing_context_state* state =
- (stream_parsing_context_state*) context->client_state;
- if (strncmp((const char*) token->start, "timestamp", 2) == 0) {
- state->state |= WAITING_AT;
- } else if ((strncmp((const char*) token->start, "value", 5) == 0) &&
- (token->start[5] != 's')) { // get rid of "values"
- state->state |= WAITING_VALUE;
- }
-}
-
-static void on_stream_value_found(jsonlite_callback_context* context,
- jsonlite_token* token,
- int type)
-{
- 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));
- state->at_str[MIN(token->end - token->start, STREAM_BUF_LEN)] = '\0';
- state->state |= GOT_AT;
- } else if (TEST_IS_VALUE(state->state)) {
- strncpy(state->value_str, (const char*) token->start,
- MIN(token->end - token->start, STREAM_BUF_LEN));
- state->value_str[MIN(token->end - token->start, STREAM_BUF_LEN)] = '\0';
- state->state |= GOT_VALUE;
- }
-
- if (TEST_GOT_STREAM(state->state)) {
- state->callback(state->at_str, state->value_str,
- state->index++, state->context, type);
- state->state = 0;
- }
-}
-
-static void on_stream_string_found(jsonlite_callback_context* context,
- jsonlite_token* token)
-{
- on_stream_value_found(context, token, 1);
-}
-
-static void on_stream_number_found(jsonlite_callback_context* context,
- jsonlite_token* token)
-{
- on_stream_value_found(context, token, 2);
-}
-
-#endif /* StreamParseFunctions_h */
