Demo application for using the AT&T IoT Starter Kit Powered by AWS.

Dependencies:   SDFileSystem

Fork of ATT_AWS_IoT_demo by Anthony Phillips

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers aws_iot_json_utils.h Source File

aws_iot_json_utils.h

00001 /*
00002  * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License").
00005  * You may not use this file except in compliance with the License.
00006  * A copy of the License is located at
00007  *
00008  *  http://aws.amazon.com/apache2.0
00009  *
00010  * or in the "license" file accompanying this file. This file is distributed
00011  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
00012  * express or implied. See the License for the specific language governing
00013  * permissions and limitations under the License.
00014  */
00015 
00016 /**
00017  * @file aws_json_utils.h
00018  * @brief Utilities for manipulating JSON
00019  *
00020  * json_utils provides JSON parsing utilities for use with the IoT SDK.
00021  * Underlying JSON parsing relies on the Jasmine JSON parser.
00022  *
00023  */
00024 
00025 #ifndef AWS_IOT_SDK_SRC_JSON_UTILS_H_
00026 #define AWS_IOT_SDK_SRC_JSON_UTILS_H_
00027 
00028 #include <stdbool.h>
00029 #include <stdint.h>
00030 
00031 #include "aws_iot_error.h"
00032 #include "jsmn.h"
00033 
00034 // utility functions
00035 /**
00036  * @brief          JSON Equality Check
00037  *
00038  * Given a token pointing to a particular JSON node and an
00039  * input string, check to see if the key is equal to the string.
00040  *
00041  * @param json      json string
00042  * @param tok       json token - pointer to key to test for equality
00043  * @param s         input string for key to test equality
00044  *
00045  * @return          0 if equal, 1 otherwise
00046  */
00047 int8_t jsoneq(const char *json, jsmntok_t *tok, const char *s);
00048 
00049 /**
00050  * @brief          Parse a signed 32-bit integer value from a JSON node.
00051  *
00052  * Given a JSON node parse the integer value from the value.
00053  *
00054  * @param jsonString    json string
00055  * @param tok           json token - pointer to JSON node
00056  * @param i             address of int32_t to be updated
00057  *
00058  * @return              NONE_ERROR - success
00059  * @return              JSON_PARSE_ERROR - error parsing value
00060  */
00061 IoT_Error_t parseInteger32Value(int32_t *i, const char *jsonString, jsmntok_t *token);
00062 
00063 /**
00064  * @brief          Parse a signed 16-bit integer value from a JSON node.
00065  *
00066  * Given a JSON node parse the integer value from the value.
00067  *
00068  * @param jsonString    json string
00069  * @param tok           json token - pointer to JSON node
00070  * @param i             address of int16_t to be updated
00071  *
00072  * @return              NONE_ERROR - success
00073  * @return              JSON_PARSE_ERROR - error parsing value
00074  */
00075 IoT_Error_t parseInteger16Value(int16_t *i, const char *jsonString, jsmntok_t *token);
00076 
00077 /**
00078  * @brief          Parse a signed 8-bit integer value from a JSON node.
00079  *
00080  * Given a JSON node parse the integer value from the value.
00081  *
00082  * @param jsonString    json string
00083  * @param tok           json token - pointer to JSON node
00084  * @param i             address of int8_t to be updated
00085  *
00086  * @return              NONE_ERROR - success
00087  * @return              JSON_PARSE_ERROR - error parsing value
00088  */
00089 IoT_Error_t parseInteger8Value(int8_t *i, const char *jsonString, jsmntok_t *token);
00090 
00091 /**
00092  * @brief          Parse an unsigned 32-bit integer value from a JSON node.
00093  *
00094  * Given a JSON node parse the integer value from the value.
00095  *
00096  * @param jsonString    json string
00097  * @param tok           json token - pointer to JSON node
00098  * @param i             address of uint32_t to be updated
00099  *
00100  * @return              NONE_ERROR - success
00101  * @return              JSON_PARSE_ERROR - error parsing value
00102  */
00103 IoT_Error_t parseUnsignedInteger32Value(uint32_t *i, const char *jsonString, jsmntok_t *token);
00104 
00105 /**
00106  * @brief          Parse an unsigned 16-bit integer value from a JSON node.
00107  *
00108  * Given a JSON node parse the integer value from the value.
00109  *
00110  * @param jsonString    json string
00111  * @param tok           json token - pointer to JSON node
00112  * @param i             address of uint16_t to be updated
00113  *
00114  * @return              NONE_ERROR - success
00115  * @return              JSON_PARSE_ERROR - error parsing value
00116  */
00117 IoT_Error_t parseUnsignedInteger16Value(uint16_t *i, const char *jsonString, jsmntok_t *token);
00118 
00119 /**
00120  * @brief          Parse an unsigned 8-bit integer value from a JSON node.
00121  *
00122  * Given a JSON node parse the integer value from the value.
00123  *
00124  * @param jsonString    json string
00125  * @param tok           json token - pointer to JSON node
00126  * @param i             address of uint8_t to be updated
00127  *
00128  * @return              NONE_ERROR - success
00129  * @return              JSON_PARSE_ERROR - error parsing value
00130  */
00131 IoT_Error_t parseUnsignedInteger8Value(uint8_t *i, const char *jsonString, jsmntok_t *token);
00132 
00133 /**
00134  * @brief          Parse a float value from a JSON node.
00135  *
00136  * Given a JSON node parse the float value from the value.
00137  *
00138  * @param jsonString    json string
00139  * @param tok           json token - pointer to JSON node
00140  * @param f             address of float to be updated
00141  *
00142  * @return              NONE_ERROR - success
00143  * @return              JSON_PARSE_ERROR - error parsing value
00144  */
00145 IoT_Error_t parseFloatValue(float *f, const char *jsonString, jsmntok_t *token);
00146 
00147 /**
00148  * @brief          Parse a double value from a JSON node.
00149  *
00150  * Given a JSON node parse the double value from the value.
00151  *
00152  * @param jsonString    json string
00153  * @param tok           json token - pointer to JSON node
00154  * @param d             address of double to be updated
00155  *
00156  * @return              NONE_ERROR - success
00157  * @return              JSON_PARSE_ERROR - error parsing value
00158  */
00159 IoT_Error_t parseDoubleValue(double *d, const char *jsonString, jsmntok_t *token);
00160 
00161 /**
00162  * @brief          Parse a boolean value from a JSON node.
00163  *
00164  * Given a JSON node parse the boolean value from the value.
00165  *
00166  * @param jsonString    json string
00167  * @param tok           json token - pointer to JSON node
00168  * @param b             address of boolean to be updated
00169  *
00170  * @return              NONE_ERROR - success
00171  * @return              JSON_PARSE_ERROR - error parsing value
00172  */
00173 IoT_Error_t parseBooleanValue(bool *b, const char *jsonString, jsmntok_t *token);
00174 
00175 /**
00176  * @brief          Parse a string value from a JSON node.
00177  *
00178  * Given a JSON node parse the string value from the value.
00179  *
00180  * @param jsonString    json string
00181  * @param tok           json token - pointer to JSON node
00182  * @param s             address of string to be updated
00183  *
00184  * @return              NONE_ERROR - success
00185  * @return              JSON_PARSE_ERROR - error parsing value
00186  */
00187 IoT_Error_t parseStringValue(char *buf, const char *jsonString, jsmntok_t *token);
00188 
00189 #endif /* AWS_IOT_SDK_SRC_JSON_UTILS_H_ */
00190