ISSDK  1.7
IoT Sensing Software Development Kit
data_format_json.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 /**
35 * @file data_format_json.h
36 * @brief The format_json.h file describes the structures and definitions for the data-format standard JSON.
37 */
38 
39 #ifndef DATA_FORMAT_JSON_H_
40 #define DATA_FORMAT_JSON_H_
41 #include <stddef.h>
42 #include <stdint.h>
43 #include <stdbool.h>
44 #define HOST_INTERFACE 1
45 #if HOST_INTERFACE
46 #include "host_interface_service.h"
47 #include "host_io_uart.h"
48 #endif
49 #define DATA_FORMAT_JSON_OK 0
50 /*******************************************************************************
51  * Definitions
52  ******************************************************************************/
53 
54 typedef enum _json_format_
55 {
56  JSON_TYPE_OBJECT, /* String value pair, Note: Value will be primitive data type*/
57  JSON_TYPE_ARRAY /* Array of Values*/
59 /******************************************************************************/
60 /*! @brief The function to serialize the data,
61  * @details it applys the serialization in single data element,
62  Once user finishes the data stream with different data tag, set end flag to TRUE.
63 
64  * @param[in] pStr - pointer to the data stream - formated data put into this buffer
65  * @param[in] pDataTagStr - Data tag name for a data
66  * @param[in] pDataValue - Data value
67  * @param[in] type - Json data type
68  * @param[in] end - flag determine the end of data stream serialization.
69  * @return ::JSON_Serialize() returns the status .
70  *
71  * @Constraints None
72  *
73  * @Reentrant Yes
74  */
75 int32_t JSON_Serialize(char *pStr, char *pDataTagStr, char *pDataValue, json_format_t type, bool end);
76 
77 /*! @brief The function to deserialize the data,
78  * @details it applys the deserialization in a single data element,
79 
80  * @param[in] pStr - pointer to a formated data stream
81  * @param[out] pDataTagStr - Data tag name for a data
82  * @param[out] pDataValue - Data value
83  * @param[in] type - Json data type
84  * @return ::JSON_Deserialize() returns the status .
85  *
86  * @Constraints None
87  *
88  * @Reentrant Yes
89  */
90 // Note: Signature of this function may change based on the implementation and usability.
91 int32_t JSON_Deserialize(void *pInData, void *pDataTag, char *pDataValue, json_format_t type);
92 
93 #if HOST_INTERFACE
94 
95 /*! @brief The function provides block data read for the JSON stream, This is for Blocking receive call
96  * @details This can be the argument to host interface
97 
98  * @param[in] pHandle - pointer to a formated data stream
99  * @param[out] pRecvData - Pointer to RecvBuffer;
100  * @return None.
101  *
102  * @Constraints None
103  *
104  * @Reentrant Yes
105  */
106 // Note: Signature of this function may change based on the implementation and usability.
107 void JSON_BlockDataRead_BlockingCall(host_interface_handle_t *pHandle, void *pRecvData);
108 
109 /*! @brief This function is a helper function to get json stream where the data length is unknown
110  * @details Basically look for start and end packets and form a packet
111 
112  * @param[out] pRecvData - Pointer to RecvBuffer;
113  * @param[out] data - one byte of data received.
114  * @parma[in] event - status event for send complete and receive complete
115  * @return DATA_FORMAT_JSON_OK, if data read is completed. else still get more data.
116  *
117  * @Constraints None
118  *
119  * @Reentrant Yes
120  */
121 // Note: Signature of this function may change based on the implementation and usability.
122 
123 int32_t JSON_Get_Stream_NonBlockingCall(void *pRecvData, uint8_t data, uint8_t *state, uint8_t *buffIndex);
124 
125 /*! @brief Function to handle incomming JSON encoded bytes form the Host over UART.
126  * @details This function will be called on receipt of every UART Byte
127  * and will do the JSON combination to create a Host Message.
128  * @param[in] uint8_t c The character in the UART payload.
129  * @param[in] host_rx_packet_t *pHostRxPkt The Host Packet context structure.
130  * @return bool Success/Failure.
131  * @constraints This should be the called only after DEBUG/UART has been initialized.
132  * @reeentrant No
133  */
134 bool JSON_Process_Rx_Byte(uint8_t c, host_rx_packet_t *pHostRxPkt);
135 
136 /* @brief Function to format bytes for JSON to be sent to Host over UART.
137  * @details This function will encode a Host Protocol formatted Message to be sent to Host over UART.
138  * @param[in] uint8_t *pbuffer The handle to the input buffer containing the Host message.
139  * @param[in] uint8_t *pMsg The handle to the output buffer containing the formatted Host message.
140  * @param[in] size_t size The number of bytes to be sent starting form the buffer.
141  * @return size_t Length of the encoded message.
142  * @constraints This should be the called only after DEBUG/UART has been initialized.
143  * @reeentrant No
144  */
145 size_t JSON_Process_Tx_Msg(const uint8_t *pBuffer, uint8_t *pMsg, size_t size);
146 
147 #endif
148 
149 #endif // DATA_FORMAT_JSON_H_
bool JSON_Process_Rx_Byte(uint8_t c, host_rx_packet_t *pHostRxPkt)
Function to handle incomming JSON encoded bytes form the Host over UART.
uint8_t data[FXLS8962_DATA_SIZE]
The host_interface_service.h file describes the structures and definitions for the host...
_json_format_
int32_t JSON_Get_Stream_NonBlockingCall(void *pRecvData, uint8_t data, uint8_t *state, uint8_t *buffIndex)
This function is a helper function to get json stream where the data length is unknown.
void JSON_BlockDataRead_BlockingCall(host_interface_handle_t *pHandle, void *pRecvData)
The function provides block data read for the JSON stream, This is for Blocking receive call...
size_t JSON_Process_Tx_Msg(const uint8_t *pBuffer, uint8_t *pMsg, size_t size)
This structure holds information to receive a packet of data to the host.
Definition: host_io_uart.h:75
int32_t JSON_Serialize(char *pStr, char *pDataTagStr, char *pDataValue, json_format_t type, bool end)
The function to serialize the data,.
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
uint32_t size
int32_t JSON_Deserialize(void *pInData, void *pDataTag, char *pDataValue, json_format_t type)
The function to deserialize the data,.
The host_io_uart.h file contains the Host Protocol interface definitions and configuration.
enum _json_format_ json_format_t