ESP8266 Centre + NB
函数 | 变量
user_json.c 文件参考
#include "ets_sys.h"
#include "osapi.h"
#include "os_type.h"
#include "mem.h"
#include "user_json.h"
user_json.c 的引用(Include)关系图:

函数

struct jsontree_value
*ICACHE_FLASH_ATTR 
find_json_path (struct jsontree_context *json, const char *path)
 
int ICACHE_FLASH_ATTR json_putchar (int c)
 
void ICACHE_FLASH_ATTR json_ws_send (struct jsontree_value *tree, const char *path, char *pbuf)
 
void ICACHE_FLASH_ATTR json_parse (struct jsontree_context *json, char *ptrJSONMessage)
 
int ICACHE_FLASH_ATTR jsonArray_set (struct jsontree_context *js_ctx, struct jsonparse_state *parser)
 

变量

LOCAL char * json_buf
 
LOCAL int pos
 
LOCAL int size
 

函数说明

struct jsontree_value* ICACHE_FLASH_ATTR find_json_path ( struct jsontree_context json,
const char *  path 
)
44  {
45  struct jsontree_value *v;
46  const char *start;
47  const char *end;
48  int len;
49 
50  v = json->values[0];
51  start = path;
52 
53  do {
54  end = (const char *) os_strstr(start, "/");
55 
56  if (end == start) {
57  break;
58  }
59 
60  if (end != NULL) {
61  len = end - start;
62  end++;
63  } else {
64  len = os_strlen(start);
65  }
66 
67  if (v->type != JSON_TYPE_OBJECT) {
68  v = NULL;
69  } else {
70  struct jsontree_object *o;
71  int i;
72 
73  o = (struct jsontree_object *) v;
74  v = NULL;
75 
76  for (i = 0; i < o->count; i++) {
77  if (os_strncmp(start, o->pairs[i].name, len) == 0) {
78  v = o->pairs[i].value;
79  json->index[json->depth] = i;
80  json->depth++;
81  json->values[json->depth] = v;
82  json->index[json->depth] = 0;
83  break;
84  }
85  }
86  }
87 
88  start = end;
89  } while (end != NULL && *end != '\0' && v != NULL);
90 
91  json->callback_state = 0;
92  return v;
93 }
#define os_strncmp
Definition: osapi.h:44
#define JSON_TYPE_OBJECT
Definition: esp8266_centre_NB/include/include/json/json.h:44
struct jsontree_value * values[JSONTREE_MAX_DEPTH]
Definition: esp8266_centre_NB/include/include/json/jsontree.h:53
int callback_state
Definition: esp8266_centre_NB/include/include/json/jsontree.h:58
struct jsontree_value * value
Definition: esp8266_centre_NB/include/include/json/jsontree.h:86
uint8_t type
Definition: esp8266_centre_NB/include/include/json/jsontree.h:62
#define os_strlen
Definition: osapi.h:43
Definition: esp8266_centre_NB/include/include/json/jsontree.h:61
Definition: esp8266_centre_NB/include/include/json/jsontree.h:89
uint16_t index[JSONTREE_MAX_DEPTH]
Definition: esp8266_centre_NB/include/include/json/jsontree.h:54
#define os_strstr
Definition: osapi.h:46
uint8_t depth
Definition: esp8266_centre_NB/include/include/json/jsontree.h:56
#define NULL
Definition: c_types.h:73
struct jsontree_pair * pairs
Definition: esp8266_centre_NB/include/include/json/jsontree.h:92
uint8_t count
Definition: esp8266_centre_NB/include/include/json/jsontree.h:91
const char * name
Definition: esp8266_centre_NB/include/include/json/jsontree.h:85

这是这个函数的调用关系图:

int ICACHE_FLASH_ATTR json_putchar ( int  c)
102  {
103  if (json_buf != NULL && pos <= size) {
104  json_buf[pos++] = c;
105  return c;
106  }
107 
108  return 0;
109 }
LOCAL char * json_buf
Definition: user_json.c:32
#define NULL
Definition: c_types.h:73
LOCAL int pos
Definition: user_json.c:33
LOCAL int size
Definition: user_json.c:34

这是这个函数的调用关系图:

void ICACHE_FLASH_ATTR json_ws_send ( struct jsontree_value tree,
const char *  path,
char *  pbuf 
)
120  {
121  struct jsontree_context json;
122  /* maxsize = 128 bytes */
123  json_buf = (char *) os_malloc(jsonSize);
124 
125  /* reset state and set max-size */
126  /* NOTE: packet will be truncated at 512 bytes */
127  pos = 0;
128  size = jsonSize;
129 
130  json.values[0] = (struct jsontree_value *) tree;
131  jsontree_reset(&json);
132  find_json_path(&json, path);
133  json.path = json.depth;
134  json.putchar = json_putchar;
135 
136  while (jsontree_print_next(&json) && json.path <= json.depth)
137  ;
138 
139  json_buf[pos] = 0;
140  os_memcpy(pbuf, json_buf, pos);
141  os_free(json_buf);
142 }
int ICACHE_FLASH_ATTR json_putchar(int c)
Definition: user_json.c:102
int jsontree_print_next(struct jsontree_context *js_ctx)
#define os_memcpy
Definition: osapi.h:36
#define jsonSize
Definition: user_json.h:31
LOCAL char * json_buf
Definition: user_json.c:32
Definition: esp8266_centre_NB/include/include/json/jsontree.h:61
struct jsontree_value *ICACHE_FLASH_ATTR find_json_path(struct jsontree_context *json, const char *path)
Definition: user_json.c:44
void jsontree_reset(struct jsontree_context *js_ctx)
#define os_malloc(s)
Definition: mem.h:41
#define os_free(s)
Definition: mem.h:40
LOCAL int pos
Definition: user_json.c:33
LOCAL int size
Definition: user_json.c:34
Definition: esp8266_centre_NB/include/include/json/jsontree.h:52

函数调用图:

void ICACHE_FLASH_ATTR json_parse ( struct jsontree_context json,
char *  ptrJSONMessage 
)
152  {
153  /* Set value */
154  struct jsontree_value *v;
155  struct jsontree_callback *c;
156  struct jsontree_callback *c_bak = NULL;
157 
158  while ((v = jsontree_find_next(json, JSON_TYPE_CALLBACK)) != NULL) {
159  c = (struct jsontree_callback *) v;
160 
161  if (c == c_bak) {
162  continue;
163  }
164 
165  c_bak = c;
166 
167  if (c->set != NULL) {
168  struct jsonparse_state js;
169 
170  jsonparse_setup(&js, ptrJSONMessage, os_strlen(ptrJSONMessage));
171  c->set(json, &js);
172  }
173  }
174 }
int(* set)(struct jsontree_context *js_ctx, struct jsonparse_state *parser)
Definition: esp8266_centre_NB/include/include/json/jsontree.h:81
Definition: esp8266_centre_NB/include/include/json/jsonparse.h:44
void jsonparse_setup(struct jsonparse_state *state, const char *json, int len)
Initialize a JSON parser state.
#define os_strlen
Definition: osapi.h:43
Definition: esp8266_centre_NB/include/include/json/jsontree.h:61
#define NULL
Definition: c_types.h:73
#define JSON_TYPE_CALLBACK
Definition: esp8266_centre_NB/include/include/json/json.h:57
Definition: esp8266_centre_NB/include/include/json/jsontree.h:78
struct jsontree_value * jsontree_find_next(struct jsontree_context *js_ctx, int type)

函数调用图:

int ICACHE_FLASH_ATTR jsonArray_set ( struct jsontree_context js_ctx,
struct jsonparse_state parser 
)
178  {
179  int type;
180 
181  while ((type = jsonparse_next(parser)) == 0) {
182  //如果是KEY类型
183  if (type == JSON_TYPE_PAIR_NAME) {
184  char buffer[64];
185  os_bzero(buffer, 64);
186 
187  if (jsonparse_strcmp_value(parser, "K1") == 0) {
188  if (JSON_TYPE_STRING == type) { //#define JSON_TYPE_STRING '"'
189  jsonparse_copy_value(parser, buffer, sizeof(buffer));
190  os_printf("K1 Value = %s\n", buffer);
191  }
192  } else if (jsonparse_strcmp_value(parser, "K2") == 0) {
193  if (JSON_TYPE_STRING == type) { //#define JSON_TYPE_STRING '"'
194  jsonparse_copy_value(parser, buffer, sizeof(buffer));
195  os_printf("K2 Value = %s\n", buffer);
196  }
197  } else if (jsonparse_strcmp_value(parser, "K3") == 0) {
198  if (JSON_TYPE_STRING == type) { //#define JSON_TYPE_STRING '"'
199  jsonparse_copy_value(parser, buffer, sizeof(buffer));
200  os_printf("K3 Value = %s\n", buffer);
201  }
202  }
203  }
204  }
205 
206  return 0;
207 }
#define JSON_TYPE_STRING
Definition: esp8266_centre_NB/include/include/json/json.h:47
int jsonparse_copy_value(struct jsonparse_state *state, char *buf, int buf_size)
#define os_printf
Definition: osapi.h:62
#define JSON_TYPE_PAIR_NAME
Definition: esp8266_centre_NB/include/include/json/json.h:46
int jsonparse_strcmp_value(struct jsonparse_state *state, const char *str)
#define os_bzero
Definition: osapi.h:31
int jsonparse_next(struct jsonparse_state *state)

函数调用图:

变量说明

LOCAL char* json_buf
LOCAL int pos
LOCAL int size