test

Committer:
peyo
Date:
Wed Apr 12 14:09:46 2017 +0200
Revision:
1:3f75eb8d46f4
Parent:
0:cd5404401c2f
add main

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peyo 0:cd5404401c2f 1 /*
peyo 0:cd5404401c2f 2 * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
peyo 0:cd5404401c2f 3 *
peyo 0:cd5404401c2f 4 * Licensed under the Apache License, Version 2.0 (the "License").
peyo 0:cd5404401c2f 5 * You may not use this file except in compliance with the License.
peyo 0:cd5404401c2f 6 * A copy of the License is located at
peyo 0:cd5404401c2f 7 *
peyo 0:cd5404401c2f 8 * http://aws.amazon.com/apache2.0
peyo 0:cd5404401c2f 9 *
peyo 0:cd5404401c2f 10 * or in the "license" file accompanying this file. This file is distributed
peyo 0:cd5404401c2f 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
peyo 0:cd5404401c2f 12 * express or implied. See the License for the specific language governing
peyo 0:cd5404401c2f 13 * permissions and limitations under the License.
peyo 0:cd5404401c2f 14 */
peyo 0:cd5404401c2f 15
peyo 0:cd5404401c2f 16 #ifndef SRC_SHADOW_AWS_IOT_SHADOW_JSON_DATA_H_
peyo 0:cd5404401c2f 17 #define SRC_SHADOW_AWS_IOT_SHADOW_JSON_DATA_H_
peyo 0:cd5404401c2f 18
peyo 0:cd5404401c2f 19 #ifdef __cplusplus
peyo 0:cd5404401c2f 20 extern "C" {
peyo 0:cd5404401c2f 21 #endif
peyo 0:cd5404401c2f 22
peyo 0:cd5404401c2f 23 /**
peyo 0:cd5404401c2f 24 * @file aws_iot_shadow_json_data.h
peyo 0:cd5404401c2f 25 * @brief This file is the interface for all the Shadow related JSON functions.
peyo 0:cd5404401c2f 26 */
peyo 0:cd5404401c2f 27
peyo 0:cd5404401c2f 28 #include <stddef.h>
peyo 0:cd5404401c2f 29
peyo 0:cd5404401c2f 30 /**
peyo 0:cd5404401c2f 31 * @brief This is a static JSON object that could be used in code
peyo 0:cd5404401c2f 32 *
peyo 0:cd5404401c2f 33 */
peyo 0:cd5404401c2f 34 typedef struct jsonStruct jsonStruct_t;
peyo 0:cd5404401c2f 35
peyo 0:cd5404401c2f 36 /**
peyo 0:cd5404401c2f 37 * @brief Every JSON name value can have a callback. The callback should follow this signature
peyo 0:cd5404401c2f 38 */
peyo 0:cd5404401c2f 39 typedef void (*jsonStructCallback_t)(const char *pJsonValueBuffer, uint32_t valueLength, jsonStruct_t *pJsonStruct_t);
peyo 0:cd5404401c2f 40
peyo 0:cd5404401c2f 41 /**
peyo 0:cd5404401c2f 42 * @brief All the JSON object types enum
peyo 0:cd5404401c2f 43 *
peyo 0:cd5404401c2f 44 * JSON number types need to be split into proper integer / floating point data types and sizes on embedded platforms.
peyo 0:cd5404401c2f 45 */
peyo 0:cd5404401c2f 46 typedef enum {
peyo 0:cd5404401c2f 47 SHADOW_JSON_INT32,
peyo 0:cd5404401c2f 48 SHADOW_JSON_INT16,
peyo 0:cd5404401c2f 49 SHADOW_JSON_INT8,
peyo 0:cd5404401c2f 50 SHADOW_JSON_UINT32,
peyo 0:cd5404401c2f 51 SHADOW_JSON_UINT16,
peyo 0:cd5404401c2f 52 SHADOW_JSON_UINT8,
peyo 0:cd5404401c2f 53 SHADOW_JSON_FLOAT,
peyo 0:cd5404401c2f 54 SHADOW_JSON_DOUBLE,
peyo 0:cd5404401c2f 55 SHADOW_JSON_BOOL,
peyo 0:cd5404401c2f 56 SHADOW_JSON_STRING,
peyo 0:cd5404401c2f 57 SHADOW_JSON_OBJECT
peyo 0:cd5404401c2f 58 } JsonPrimitiveType;
peyo 0:cd5404401c2f 59
peyo 0:cd5404401c2f 60 /**
peyo 0:cd5404401c2f 61 * @brief This is the struct form of a JSON Key value pair
peyo 0:cd5404401c2f 62 */
peyo 0:cd5404401c2f 63 struct jsonStruct {
peyo 0:cd5404401c2f 64 const char *pKey; ///< JSON key
peyo 0:cd5404401c2f 65 void *pData; ///< pointer to the data (JSON value)
peyo 0:cd5404401c2f 66 JsonPrimitiveType type; ///< type of JSON
peyo 0:cd5404401c2f 67 jsonStructCallback_t cb; ///< callback to be executed on receiving the Key value pair
peyo 0:cd5404401c2f 68 };
peyo 0:cd5404401c2f 69
peyo 0:cd5404401c2f 70 /**
peyo 0:cd5404401c2f 71 * @brief Initialize the JSON document with Shadow expected name/value
peyo 0:cd5404401c2f 72 *
peyo 0:cd5404401c2f 73 * This Function will fill the JSON Buffer with a null terminated string. Internally it uses snprintf
peyo 0:cd5404401c2f 74 * This function should always be used First, followed by iot_shadow_add_reported and/or iot_shadow_add_desired.
peyo 0:cd5404401c2f 75 * Always finish the call sequence with iot_finalize_json_document
peyo 0:cd5404401c2f 76 *
peyo 0:cd5404401c2f 77 * @note Ensure the size of the Buffer is enough to hold the entire JSON Document.
peyo 0:cd5404401c2f 78 *
peyo 0:cd5404401c2f 79 *
peyo 0:cd5404401c2f 80 * @param pJsonDocument The JSON Document filled in this char buffer
peyo 0:cd5404401c2f 81 * @param maxSizeOfJsonDocument maximum size of the pJsonDocument that can be used to fill the JSON document
peyo 0:cd5404401c2f 82 * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up
peyo 0:cd5404401c2f 83 */
peyo 0:cd5404401c2f 84 IoT_Error_t aws_iot_shadow_init_json_document(char *pJsonDocument, size_t maxSizeOfJsonDocument);
peyo 0:cd5404401c2f 85
peyo 0:cd5404401c2f 86 /**
peyo 0:cd5404401c2f 87 * @brief Add the reported section of the JSON document of jsonStruct_t
peyo 0:cd5404401c2f 88 *
peyo 0:cd5404401c2f 89 * This is a variadic function and please be careful with the usage. count is the number of jsonStruct_t types that you would like to add in the reported section
peyo 0:cd5404401c2f 90 * This function will add "reported":{<all the values that needs to be added>}
peyo 0:cd5404401c2f 91 *
peyo 0:cd5404401c2f 92 * @note Ensure the size of the Buffer is enough to hold the reported section + the init section. Always use the same JSON document buffer used in the iot_shadow_init_json_document function. This function will accommodate the size of previous null terminated string, so pass teh max size of the buffer
peyo 0:cd5404401c2f 93 *
peyo 0:cd5404401c2f 94 *
peyo 0:cd5404401c2f 95 * @param pJsonDocument The JSON Document filled in this char buffer
peyo 0:cd5404401c2f 96 * @param maxSizeOfJsonDocument maximum size of the pJsonDocument that can be used to fill the JSON document
peyo 0:cd5404401c2f 97 * @param count total number of arguments(jsonStruct_t object) passed in the arguments
peyo 0:cd5404401c2f 98 * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up
peyo 0:cd5404401c2f 99 */
peyo 0:cd5404401c2f 100 IoT_Error_t aws_iot_shadow_add_reported(char *pJsonDocument, size_t maxSizeOfJsonDocument, uint8_t count, ...);
peyo 0:cd5404401c2f 101
peyo 0:cd5404401c2f 102 /**
peyo 0:cd5404401c2f 103 * @brief Add the desired section of the JSON document of jsonStruct_t
peyo 0:cd5404401c2f 104 *
peyo 0:cd5404401c2f 105 * This is a variadic function and please be careful with the usage. count is the number of jsonStruct_t types that you would like to add in the reported section
peyo 0:cd5404401c2f 106 * This function will add "desired":{<all the values that needs to be added>}
peyo 0:cd5404401c2f 107 *
peyo 0:cd5404401c2f 108 * @note Ensure the size of the Buffer is enough to hold the reported section + the init section. Always use the same JSON document buffer used in the iot_shadow_init_json_document function. This function will accommodate the size of previous null terminated string, so pass the max size of the buffer
peyo 0:cd5404401c2f 109 *
peyo 0:cd5404401c2f 110 *
peyo 0:cd5404401c2f 111 * @param pJsonDocument The JSON Document filled in this char buffer
peyo 0:cd5404401c2f 112 * @param maxSizeOfJsonDocument maximum size of the pJsonDocument that can be used to fill the JSON document
peyo 0:cd5404401c2f 113 * @param count total number of arguments(jsonStruct_t object) passed in the arguments
peyo 0:cd5404401c2f 114 * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up
peyo 0:cd5404401c2f 115 */
peyo 0:cd5404401c2f 116 IoT_Error_t aws_iot_shadow_add_desired(char *pJsonDocument, size_t maxSizeOfJsonDocument, uint8_t count, ...);
peyo 0:cd5404401c2f 117
peyo 0:cd5404401c2f 118 /**
peyo 0:cd5404401c2f 119 * @brief Finalize the JSON document with Shadow expected client Token.
peyo 0:cd5404401c2f 120 *
peyo 0:cd5404401c2f 121 * This function will automatically increment the client token every time this function is called.
peyo 0:cd5404401c2f 122 *
peyo 0:cd5404401c2f 123 * @note Ensure the size of the Buffer is enough to hold the entire JSON Document. If the finalized section is not invoked then the JSON doucment will not be valid
peyo 0:cd5404401c2f 124 *
peyo 0:cd5404401c2f 125 *
peyo 0:cd5404401c2f 126 * @param pJsonDocument The JSON Document filled in this char buffer
peyo 0:cd5404401c2f 127 * @param maxSizeOfJsonDocument maximum size of the pJsonDocument that can be used to fill the JSON document
peyo 0:cd5404401c2f 128 * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up
peyo 0:cd5404401c2f 129 */
peyo 0:cd5404401c2f 130 IoT_Error_t aws_iot_finalize_json_document(char *pJsonDocument, size_t maxSizeOfJsonDocument);
peyo 0:cd5404401c2f 131
peyo 0:cd5404401c2f 132 /**
peyo 0:cd5404401c2f 133 * @brief Fill the given buffer with client token for tracking the Repsonse.
peyo 0:cd5404401c2f 134 *
peyo 0:cd5404401c2f 135 * This function will add the AWS_IOT_MQTT_CLIENT_ID with a sequence number. Every time this function is used the sequence number gets incremented
peyo 0:cd5404401c2f 136 *
peyo 0:cd5404401c2f 137 *
peyo 0:cd5404401c2f 138 * @param pBufferToBeUpdatedWithClientToken buffer to be updated with the client token string
peyo 0:cd5404401c2f 139 * @param maxSizeOfJsonDocument maximum size of the pBufferToBeUpdatedWithClientToken that can be used
peyo 0:cd5404401c2f 140 * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up
peyo 0:cd5404401c2f 141 */
peyo 0:cd5404401c2f 142
peyo 0:cd5404401c2f 143 IoT_Error_t aws_iot_fill_with_client_token(char *pBufferToBeUpdatedWithClientToken, size_t maxSizeOfJsonDocument);
peyo 0:cd5404401c2f 144
peyo 0:cd5404401c2f 145 #ifdef __cplusplus
peyo 0:cd5404401c2f 146 }
peyo 0:cd5404401c2f 147 #endif
peyo 0:cd5404401c2f 148
peyo 0:cd5404401c2f 149 #endif /* SRC_SHADOW_AWS_IOT_SHADOW_JSON_DATA_H_ */