#include "aws_iot_shadow_json.h"
#include <string.h>
#include <stdbool.h>
#include <inttypes.h>
#include "AWS_SDK/aws_iot_src/utils/aws_iot_json_utils.h"
#include "AWS_SDK/aws_iot_src/utils/aws_iot_log.h"
#include "aws_iot_shadow_key.h"
#include "aws_iot_config.h"
Functions | |
IoT_Error_t | aws_iot_fill_with_client_token (char *pBufferToBeUpdatedWithClientToken, size_t maxSizeOfJsonDocument) |
Fill the given buffer with client token for tracking the Repsonse. More... | |
IoT_Error_t | aws_iot_finalize_json_document (char *pJsonDocument, size_t maxSizeOfJsonDocument) |
Finalize the JSON document with Shadow expected client Token. More... | |
IoT_Error_t | aws_iot_shadow_add_desired (char *pJsonDocument, size_t maxSizeOfJsonDocument, uint8_t count,...) |
Add the desired section of the JSON document of jsonStruct_t. More... | |
IoT_Error_t | aws_iot_shadow_add_reported (char *pJsonDocument, size_t maxSizeOfJsonDocument, uint8_t count,...) |
Add the reported section of the JSON document of jsonStruct_t. More... | |
IoT_Error_t | aws_iot_shadow_init_json_document (char *pJsonDocument, size_t maxSizeOfJsonDocument) |
Initialize the JSON document with Shadow expected name/value. More... | |
static IoT_Error_t | checkReturnValueOfSnPrintf (int32_t snPrintfReturn, size_t maxSizeOfJsonDocument) |
static IoT_Error_t | convertDataToString (char *pStringBuffer, size_t maxSizoStringBuffer, JsonPrimitiveType type, void *pData) |
static void | emptyJsonWithClientToken (char *pJsonDocument) |
bool | extractClientToken (const char *pJsonDocument, char *pExtractedClientToken) |
bool | extractVersionNumber (const char *pJsonDocument, void *pJsonHandler, int32_t tokenCount, uint32_t *pVersionNumber) |
void | FillWithClientToken (char *pBufferToBeUpdatedWithClientToken) |
int32_t | FillWithClientTokenSize (char *pBufferToBeUpdatedWithClientToken, size_t maxSizeOfJsonDocument) |
void | iot_shadow_delete_request_json (char *pJsonDocument) |
void | iot_shadow_get_request_json (char *pJsonDocument) |
bool | isJsonKeyMatchingAndUpdateValue (const char *pJsonDocument, void *pJsonHandler, int32_t tokenCount, jsonStruct_t *pDataStruct, uint32_t *pDataLength, int32_t *pDataPosition) |
bool | isJsonValidAndParse (const char *pJsonDocument, void *pJsonHandler, int32_t *pTokenCount) |
bool | isReceivedJsonValid (const char *pJsonDocument) |
void | resetClientTokenSequenceNum (void) |
static IoT_Error_t | UpdateValueIfNoObject (const char *pJsonString, jsonStruct_t *pDataStruct, jsmntok_t token) |
Variables | |
static uint32_t | clientTokenNum = 0 |
static jsmntok_t | jsonTokenStruct [MAX_JSON_TOKEN_EXPECTED] |
char | mqttClientID [MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES] |
static jsmn_parser | shadowJsonParser |
IoT_Error_t aws_iot_fill_with_client_token | ( | char * | pBufferToBeUpdatedWithClientToken, |
size_t | maxSizeOfJsonDocument | ||
) |
Fill the given buffer with client token for tracking the Repsonse.
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
pBufferToBeUpdatedWithClientToken | buffer to be updated with the client token string |
maxSizeOfJsonDocument | maximum size of the pBufferToBeUpdatedWithClientToken that can be used |
References checkReturnValueOfSnPrintf(), and FillWithClientTokenSize().
IoT_Error_t aws_iot_finalize_json_document | ( | char * | pJsonDocument, |
size_t | maxSizeOfJsonDocument | ||
) |
Finalize the JSON document with Shadow expected client Token.
This function will automatically increment the client token every time this function is called.
pJsonDocument | The JSON Document filled in this char buffer |
maxSizeOfJsonDocument | maximum size of the pJsonDocument that can be used to fill the JSON document |
References checkReturnValueOfSnPrintf(), FillWithClientTokenSize(), NONE_ERROR, NULL, NULL_VALUE_ERROR, SHADOW_CLIENT_TOKEN_STRING, and SHADOW_JSON_ERROR.
IoT_Error_t aws_iot_shadow_add_desired | ( | char * | pJsonDocument, |
size_t | maxSizeOfJsonDocument, | ||
uint8_t | count, | ||
... | |||
) |
Add the desired section of the JSON document of jsonStruct_t.
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 This function will add "desired":{<all the="" values="" that="" needs="" to="" be="" added>="">}
pJsonDocument | The JSON Document filled in this char buffer |
maxSizeOfJsonDocument | maximum size of the pJsonDocument that can be used to fill the JSON document |
count | total number of arguments(jsonStruct_t object) passed in the arguments |
References checkReturnValueOfSnPrintf(), convertDataToString(), count, i, NONE_ERROR, NULL, NULL_VALUE_ERROR, jsonStruct::pData, jsonStruct::pKey, SHADOW_JSON_ERROR, and jsonStruct::type.
IoT_Error_t aws_iot_shadow_add_reported | ( | char * | pJsonDocument, |
size_t | maxSizeOfJsonDocument, | ||
uint8_t | count, | ||
... | |||
) |
Add the reported section of the JSON document of jsonStruct_t.
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 This function will add "reported":{<all the="" values="" that="" needs="" to="" be="" added>="">}
pJsonDocument | The JSON Document filled in this char buffer |
maxSizeOfJsonDocument | maximum size of the pJsonDocument that can be used to fill the JSON document |
count | total number of arguments(jsonStruct_t object) passed in the arguments |
References checkReturnValueOfSnPrintf(), convertDataToString(), count, i, NONE_ERROR, NULL, NULL_VALUE_ERROR, jsonStruct::pData, jsonStruct::pKey, SHADOW_JSON_ERROR, and jsonStruct::type.
IoT_Error_t aws_iot_shadow_init_json_document | ( | char * | pJsonDocument, |
size_t | maxSizeOfJsonDocument | ||
) |
Initialize the JSON document with Shadow expected name/value.
This Function will fill the JSON Buffer with a null terminated string. Internally it uses snprintf This function should always be used First, followed by iot_shadow_add_reported and/or iot_shadow_add_desired. Always finish the call sequence with iot_finalize_json_document
pJsonDocument | The JSON Document filled in this char buffer |
maxSizeOfJsonDocument | maximum size of the pJsonDocument that can be used to fill the JSON document |
References checkReturnValueOfSnPrintf(), NONE_ERROR, NULL, and NULL_VALUE_ERROR.
|
inlinestatic |
|
static |
References checkReturnValueOfSnPrintf(), NONE_ERROR, SHADOW_JSON_BOOL, SHADOW_JSON_DOUBLE, SHADOW_JSON_ERROR, SHADOW_JSON_FLOAT, SHADOW_JSON_INT16, SHADOW_JSON_INT32, SHADOW_JSON_INT8, SHADOW_JSON_STRING, SHADOW_JSON_UINT16, SHADOW_JSON_UINT32, and SHADOW_JSON_UINT8.
Referenced by aws_iot_shadow_add_desired(), and aws_iot_shadow_add_reported().
|
static |
References FillWithClientToken().
Referenced by iot_shadow_delete_request_json(), and iot_shadow_get_request_json().
bool extractClientToken | ( | const char * | pJsonDocument, |
char * | pExtractedClientToken | ||
) |
References jsmntok_t::end, i, jsmn_init(), JSMN_OBJECT, jsmn_parse(), jsoneq(), length, SHADOW_CLIENT_TOKEN_STRING, jsmntok_t::start, strncpy(), and WARN.
Referenced by AckStatusCallback(), and iot_shadow_action().
bool extractVersionNumber | ( | const char * | pJsonDocument, |
void * | pJsonHandler, | ||
int32_t | tokenCount, | ||
uint32_t * | pVersionNumber | ||
) |
References jsmntok_t::end, i, jsoneq(), NONE_ERROR, parseUnsignedInteger32Value(), SHADOW_VERSION_STRING, and jsmntok_t::start.
Referenced by AckStatusCallback(), and shadow_delta_callback().
void FillWithClientToken | ( | char * | pBufferToBeUpdatedWithClientToken | ) |
References clientTokenNum, and mqttClientID.
Referenced by emptyJsonWithClientToken().
int32_t FillWithClientTokenSize | ( | char * | pBufferToBeUpdatedWithClientToken, |
size_t | maxSizeOfJsonDocument | ||
) |
References clientTokenNum, and mqttClientID.
Referenced by aws_iot_fill_with_client_token(), and aws_iot_finalize_json_document().
void iot_shadow_delete_request_json | ( | char * | pJsonDocument | ) |
References emptyJsonWithClientToken().
Referenced by aws_iot_shadow_delete().
void iot_shadow_get_request_json | ( | char * | pJsonDocument | ) |
References emptyJsonWithClientToken().
Referenced by aws_iot_shadow_get().
bool isJsonKeyMatchingAndUpdateValue | ( | const char * | pJsonDocument, |
void * | pJsonHandler, | ||
int32_t | tokenCount, | ||
jsonStruct_t * | pDataStruct, | ||
uint32_t * | pDataLength, | ||
int32_t * | pDataPosition | ||
) |
References jsmntok_t::end, i, jsoneq(), jsonStruct::pKey, jsmntok_t::start, and UpdateValueIfNoObject().
Referenced by shadow_delta_callback().
bool isJsonValidAndParse | ( | const char * | pJsonDocument, |
void * | pJsonHandler, | ||
int32_t * | pTokenCount | ||
) |
References jsmn_init(), JSMN_OBJECT, jsmn_parse(), and WARN.
Referenced by AckStatusCallback(), and shadow_delta_callback().
bool isReceivedJsonValid | ( | const char * | pJsonDocument | ) |
References jsmn_init(), JSMN_OBJECT, jsmn_parse(), and WARN.
void resetClientTokenSequenceNum | ( | void | ) |
References clientTokenNum.
Referenced by aws_iot_shadow_init().
|
static |
References NONE_ERROR, parseBooleanValue(), parseDoubleValue(), parseFloatValue(), parseInteger16Value(), parseInteger32Value(), parseInteger8Value(), parseUnsignedInteger16Value(), parseUnsignedInteger32Value(), parseUnsignedInteger8Value(), jsonStruct::pData, SHADOW_JSON_BOOL, SHADOW_JSON_DOUBLE, SHADOW_JSON_FLOAT, SHADOW_JSON_INT16, SHADOW_JSON_INT32, SHADOW_JSON_INT8, SHADOW_JSON_UINT16, SHADOW_JSON_UINT32, SHADOW_JSON_UINT8, and jsonStruct::type.
Referenced by isJsonKeyMatchingAndUpdateValue().
|
static |
Referenced by FillWithClientToken(), FillWithClientTokenSize(), and resetClientTokenSequenceNum().
|
static |
char mqttClientID[MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES] |
|
static |