Erick / Mbed 2 deprecated ICE-F412

Dependencies:   mbed-rtos mbed

Committer:
jmarkel44
Date:
Tue Jan 24 19:05:33 2017 +0000
Revision:
0:61364762ee0e
Port from IAR to Nucleo-F412 board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmarkel44 0:61364762ee0e 1 /*
jmarkel44 0:61364762ee0e 2 Copyright (c) 2009 Dave Gamble
jmarkel44 0:61364762ee0e 3
jmarkel44 0:61364762ee0e 4 Permission is hereby granted, free of charge, to any person obtaining a copy
jmarkel44 0:61364762ee0e 5 of this software and associated documentation files (the "Software"), to deal
jmarkel44 0:61364762ee0e 6 in the Software without restriction, including without limitation the rights
jmarkel44 0:61364762ee0e 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jmarkel44 0:61364762ee0e 8 copies of the Software, and to permit persons to whom the Software is
jmarkel44 0:61364762ee0e 9 furnished to do so, subject to the following conditions:
jmarkel44 0:61364762ee0e 10
jmarkel44 0:61364762ee0e 11 The above copyright notice and this permission notice shall be included in
jmarkel44 0:61364762ee0e 12 all copies or substantial portions of the Software.
jmarkel44 0:61364762ee0e 13
jmarkel44 0:61364762ee0e 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jmarkel44 0:61364762ee0e 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jmarkel44 0:61364762ee0e 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jmarkel44 0:61364762ee0e 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jmarkel44 0:61364762ee0e 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jmarkel44 0:61364762ee0e 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jmarkel44 0:61364762ee0e 20 THE SOFTWARE.
jmarkel44 0:61364762ee0e 21 */
jmarkel44 0:61364762ee0e 22
jmarkel44 0:61364762ee0e 23 #ifndef cJSON__h
jmarkel44 0:61364762ee0e 24 #define cJSON__h
jmarkel44 0:61364762ee0e 25
jmarkel44 0:61364762ee0e 26 #ifdef __cplusplus
jmarkel44 0:61364762ee0e 27 extern "C"
jmarkel44 0:61364762ee0e 28 {
jmarkel44 0:61364762ee0e 29 #endif
jmarkel44 0:61364762ee0e 30
jmarkel44 0:61364762ee0e 31 /* cJSON Types: */
jmarkel44 0:61364762ee0e 32 #define cJSON_False (1 << 0)
jmarkel44 0:61364762ee0e 33 #define cJSON_True (1 << 1)
jmarkel44 0:61364762ee0e 34 #define cJSON_NULL (1 << 2)
jmarkel44 0:61364762ee0e 35 #define cJSON_Number (1 << 3)
jmarkel44 0:61364762ee0e 36 #define cJSON_String (1 << 4)
jmarkel44 0:61364762ee0e 37 #define cJSON_Array (1 << 5)
jmarkel44 0:61364762ee0e 38 #define cJSON_Object (1 << 6)
jmarkel44 0:61364762ee0e 39
jmarkel44 0:61364762ee0e 40 #define cJSON_IsReference 256
jmarkel44 0:61364762ee0e 41 #define cJSON_StringIsConst 512
jmarkel44 0:61364762ee0e 42
jmarkel44 0:61364762ee0e 43 /* The cJSON structure: */
jmarkel44 0:61364762ee0e 44 typedef struct cJSON {
jmarkel44 0:61364762ee0e 45 struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
jmarkel44 0:61364762ee0e 46 struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
jmarkel44 0:61364762ee0e 47
jmarkel44 0:61364762ee0e 48 int type; /* The type of the item, as above. */
jmarkel44 0:61364762ee0e 49
jmarkel44 0:61364762ee0e 50 char *valuestring; /* The item's string, if type==cJSON_String */
jmarkel44 0:61364762ee0e 51 int valueint; /* The item's number, if type==cJSON_Number */
jmarkel44 0:61364762ee0e 52 double valuedouble; /* The item's number, if type==cJSON_Number */
jmarkel44 0:61364762ee0e 53
jmarkel44 0:61364762ee0e 54 char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
jmarkel44 0:61364762ee0e 55 } cJSON;
jmarkel44 0:61364762ee0e 56
jmarkel44 0:61364762ee0e 57 typedef struct cJSON_Hooks {
jmarkel44 0:61364762ee0e 58 void *(*malloc_fn)(size_t sz);
jmarkel44 0:61364762ee0e 59 void (*free_fn)(void *ptr);
jmarkel44 0:61364762ee0e 60 } cJSON_Hooks;
jmarkel44 0:61364762ee0e 61
jmarkel44 0:61364762ee0e 62 /* Supply malloc, realloc and free functions to cJSON */
jmarkel44 0:61364762ee0e 63 extern void cJSON_InitHooks(cJSON_Hooks* hooks);
jmarkel44 0:61364762ee0e 64
jmarkel44 0:61364762ee0e 65
jmarkel44 0:61364762ee0e 66 /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
jmarkel44 0:61364762ee0e 67 extern cJSON *cJSON_Parse(const char *value);
jmarkel44 0:61364762ee0e 68 /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
jmarkel44 0:61364762ee0e 69 extern char *cJSON_Print(cJSON *item);
jmarkel44 0:61364762ee0e 70 /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
jmarkel44 0:61364762ee0e 71 extern char *cJSON_PrintUnformatted(cJSON *item);
jmarkel44 0:61364762ee0e 72 /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
jmarkel44 0:61364762ee0e 73 extern char *cJSON_PrintBuffered(cJSON *item,int prebuffer,int fmt);
jmarkel44 0:61364762ee0e 74 /* Delete a cJSON entity and all subentities. */
jmarkel44 0:61364762ee0e 75 extern void cJSON_Delete(cJSON *c);
jmarkel44 0:61364762ee0e 76
jmarkel44 0:61364762ee0e 77 /* Returns the number of items in an array (or object). */
jmarkel44 0:61364762ee0e 78 extern int cJSON_GetArraySize(cJSON *array);
jmarkel44 0:61364762ee0e 79 /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
jmarkel44 0:61364762ee0e 80 extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
jmarkel44 0:61364762ee0e 81 /* Get item "string" from object. Case insensitive. */
jmarkel44 0:61364762ee0e 82 extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
jmarkel44 0:61364762ee0e 83 extern int cJSON_HasObjectItem(cJSON *object,const char *string);
jmarkel44 0:61364762ee0e 84 /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
jmarkel44 0:61364762ee0e 85 extern const char *cJSON_GetErrorPtr(void);
jmarkel44 0:61364762ee0e 86
jmarkel44 0:61364762ee0e 87 /* These calls create a cJSON item of the appropriate type. */
jmarkel44 0:61364762ee0e 88 extern cJSON *cJSON_CreateNull(void);
jmarkel44 0:61364762ee0e 89 extern cJSON *cJSON_CreateTrue(void);
jmarkel44 0:61364762ee0e 90 extern cJSON *cJSON_CreateFalse(void);
jmarkel44 0:61364762ee0e 91 extern cJSON *cJSON_CreateBool(int b);
jmarkel44 0:61364762ee0e 92 extern cJSON *cJSON_CreateNumber(double num);
jmarkel44 0:61364762ee0e 93 extern cJSON *cJSON_CreateString(const char *string);
jmarkel44 0:61364762ee0e 94 extern cJSON *cJSON_CreateArray(void);
jmarkel44 0:61364762ee0e 95 extern cJSON *cJSON_CreateObject(void);
jmarkel44 0:61364762ee0e 96
jmarkel44 0:61364762ee0e 97 /* These utilities create an Array of count items. */
jmarkel44 0:61364762ee0e 98 extern cJSON *cJSON_CreateIntArray(const int *numbers,int count);
jmarkel44 0:61364762ee0e 99 extern cJSON *cJSON_CreateFloatArray(const float *numbers,int count);
jmarkel44 0:61364762ee0e 100 extern cJSON *cJSON_CreateDoubleArray(const double *numbers,int count);
jmarkel44 0:61364762ee0e 101 extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
jmarkel44 0:61364762ee0e 102
jmarkel44 0:61364762ee0e 103 /* Append item to the specified array/object. */
jmarkel44 0:61364762ee0e 104 extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
jmarkel44 0:61364762ee0e 105 extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
jmarkel44 0:61364762ee0e 106 extern void cJSON_AddItemToObjectCS(cJSON *object,const char *string,cJSON *item); /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object */
jmarkel44 0:61364762ee0e 107 /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
jmarkel44 0:61364762ee0e 108 extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
jmarkel44 0:61364762ee0e 109 extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
jmarkel44 0:61364762ee0e 110
jmarkel44 0:61364762ee0e 111 /* Remove/Detatch items from Arrays/Objects. */
jmarkel44 0:61364762ee0e 112 extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
jmarkel44 0:61364762ee0e 113 extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
jmarkel44 0:61364762ee0e 114 extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
jmarkel44 0:61364762ee0e 115 extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
jmarkel44 0:61364762ee0e 116
jmarkel44 0:61364762ee0e 117 /* Update array items. */
jmarkel44 0:61364762ee0e 118 extern void cJSON_InsertItemInArray(cJSON *array,int which,cJSON *newitem); /* Shifts pre-existing items to the right. */
jmarkel44 0:61364762ee0e 119 extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
jmarkel44 0:61364762ee0e 120 extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
jmarkel44 0:61364762ee0e 121
jmarkel44 0:61364762ee0e 122 /* Duplicate a cJSON item */
jmarkel44 0:61364762ee0e 123 extern cJSON *cJSON_Duplicate(cJSON *item,int recurse);
jmarkel44 0:61364762ee0e 124 /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
jmarkel44 0:61364762ee0e 125 need to be released. With recurse!=0, it will duplicate any children connected to the item.
jmarkel44 0:61364762ee0e 126 The item->next and ->prev pointers are always zero on return from Duplicate. */
jmarkel44 0:61364762ee0e 127
jmarkel44 0:61364762ee0e 128 /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
jmarkel44 0:61364762ee0e 129 /* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error. If not, then cJSON_GetErrorPtr() does the job. */
jmarkel44 0:61364762ee0e 130 extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated);
jmarkel44 0:61364762ee0e 131
jmarkel44 0:61364762ee0e 132 extern void cJSON_Minify(char *json);
jmarkel44 0:61364762ee0e 133
jmarkel44 0:61364762ee0e 134 /* Macros for creating things quickly. */
jmarkel44 0:61364762ee0e 135 #define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
jmarkel44 0:61364762ee0e 136 #define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
jmarkel44 0:61364762ee0e 137 #define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
jmarkel44 0:61364762ee0e 138 #define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
jmarkel44 0:61364762ee0e 139 #define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
jmarkel44 0:61364762ee0e 140 #define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
jmarkel44 0:61364762ee0e 141
jmarkel44 0:61364762ee0e 142 /* When assigning an integer value, it needs to be propagated to valuedouble too. */
jmarkel44 0:61364762ee0e 143 #define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
jmarkel44 0:61364762ee0e 144 #define cJSON_SetNumberValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
jmarkel44 0:61364762ee0e 145
jmarkel44 0:61364762ee0e 146 /* Macro for iterating over an array */
jmarkel44 0:61364762ee0e 147 #define cJSON_ArrayForEach(pos, head) for(pos = (head)->child; pos != NULL; pos = pos->next)
jmarkel44 0:61364762ee0e 148
jmarkel44 0:61364762ee0e 149 #ifdef __cplusplus
jmarkel44 0:61364762ee0e 150 }
jmarkel44 0:61364762ee0e 151 #endif
jmarkel44 0:61364762ee0e 152
jmarkel44 0:61364762ee0e 153 #endif