コード例 #1
0
ファイル: wifiscan.c プロジェクト: taiyuanfang/Espressif
/******************************************************************************
 * scan
*******************************************************************************/
static int ICACHE_FLASH_ATTR
scan_get(struct jsontree_context *js_ctx)
{
    const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1);

    if (os_strncmp(path, "id", 2) == 0)
    {
        jsontree_write_string(js_ctx, param.id);
    }
    else if (os_strncmp(path, "data", 4) == 0)
    {
        jsontree_write_string(js_ctx, ssOk == param.scan_status ? "OK" : "ERROR");
    }

    return 0;
}
コード例 #2
0
LOCAL int ICACHE_FLASH_ATTR
temp_json_get(struct jsontree_context *js_ctx) {
	const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1);
	if (os_strncmp(path, "temperature", 11) == 0) {
		jsontree_write_string(js_ctx, temperature);
	}
	return 0;
}
コード例 #3
0
LOCAL int ICACHE_FLASH_ATTR
json_get(struct jsontree_context *js_ctx) {
	const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1);
	if (os_strncmp(path, "humidity", 8) == 0) {
		jsontree_write_string(js_ctx, humidity);
	}
	return 0;
}
コード例 #4
0
LOCAL int ICACHE_FLASH_ATTR
json_get(struct jsontree_context *js_ctx)
{
    const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1);
    if (os_strncmp(path, "switch", 6) == 0) {
        jsontree_write_string(js_ctx, GPIO_REG_READ(BUTTON_GPIO) & BIT2 ? "on" : "off");
    }
    return 0;
}
コード例 #5
0
ファイル: user_main.c プロジェクト: hehao3344/mkit
LOCAL int ICACHE_FLASH_ATTR version_get(struct jsontree_context *js_ctx)
{
    const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1);
    char string[32];
    
    os_printf("got %s \n", path);
    if (os_strncmp(path, "hardware", 8) == 0) {
        os_sprintf(string, "0.1");
    }

    jsontree_write_string(js_ctx, string);

    return 0;
}
コード例 #6
0
ファイル: jsontree.c プロジェクト: cplusplus-study/fastjson
/*---------------------------------------------------------------------------*/
int
jsontree_print_next(struct jsontree_context *js_ctx)
{
  struct jsontree_value *v;
  int index;

  v = js_ctx->values[js_ctx->depth];

  /* Default operation after switch is to back up one level */
  switch(v->type) {
  case JSON_TYPE_OBJECT:
  case JSON_TYPE_ARRAY: {
    struct jsontree_array *o = (struct jsontree_array *)v;
    struct jsontree_value *ov;

    index = js_ctx->index[js_ctx->depth];
    if(index == 0) {
      js_ctx->putchar(v->type);
      js_ctx->putchar('\n');
    }
    if(index >= o->count) {
      js_ctx->putchar('\n');
      js_ctx->putchar(v->type + 2);
      /* Default operation: back up one level! */
      break;
    }

    if(index > 0) {
      js_ctx->putchar(',');
      js_ctx->putchar('\n');
    }
    if(v->type == JSON_TYPE_OBJECT) {
      jsontree_write_string(js_ctx,
                            ((struct jsontree_object *)o)->pairs[index].name);
      js_ctx->putchar(':');
      ov = ((struct jsontree_object *)o)->pairs[index].value;
    } else {
      ov = o->values[index];
    }
    /* TODO check max depth */
    js_ctx->depth++;          /* step down to value... */
    js_ctx->index[js_ctx->depth] = 0; /* and init index */
    js_ctx->values[js_ctx->depth] = ov;
    /* Continue on this new level */
    return 1;
  }
  case JSON_TYPE_STRING:
    jsontree_write_string(js_ctx, ((struct jsontree_string *)v)->value);
    /* Default operation: back up one level! */
    break;
  case JSON_TYPE_INT:
    jsontree_write_int(js_ctx, ((struct jsontree_int *)v)->value);
    /* Default operation: back up one level! */
    break;
  case JSON_TYPE_CALLBACK: {   /* pre-formatted json string currently */
    struct jsontree_callback *callback;

    callback = (struct jsontree_callback *)v;
    if(js_ctx->index[js_ctx->depth] == 0) {
      /* First call: reset the callback status */
      js_ctx->callback_state = 0;
    }
    if(callback->output == NULL) {
      jsontree_write_string(js_ctx, "");
    } else if(callback->output(js_ctx)) {
      /* The callback wants to output more */
      js_ctx->index[js_ctx->depth]++;
      return 1;
    }
    /* Default operation: back up one level! */
    break;
  }
  default:
    PRINTF("\nError: Illegal json type:'%c'\n", v->type);
    return 0;
  }
  /* Done => back up one level! */
  if(js_ctx->depth > 0) {
    js_ctx->depth--;
    js_ctx->index[js_ctx->depth]++;
    return 1;
  }
  return 0;
}
コード例 #7
0
LOCAL int ICACHE_FLASH_ATTR
card_info_json_get(struct jsontree_context *js_ctx) {
	const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1);
	jsontree_write_string(js_ctx, uidstr);
	return 0;
}
コード例 #8
0
ファイル: wifiscan.c プロジェクト: taiyuanfang/Espressif
/******************************************************************************
 * FunctionName : scan_get
 * Description  : set up the scan data as a JSON format
 * Parameters   : js_ctx -- A pointer to a JSON set up
 * Returns      : result
*******************************************************************************/
LOCAL int ICACHE_FLASH_ATTR
scanres_get(struct jsontree_context *js_ctx)
{
    const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1);
    struct user_wifi_scanresult *sr = NULL;
    
    if(param.le)
        sr = param.le->data;

    if (os_strncmp(path, "id", 2) == 0)
    {
        jsontree_write_string(js_ctx, param.id);
    }
    else if (os_strncmp(path, "totalpage", 9) == 0)
    {
        jsontree_write_int(js_ctx, param.totalpage);
    }
    else if (os_strncmp(path, "pagenum", 7) == 0)
    {
        jsontree_write_int(js_ctx, param.pagenum);
    }
    else if (os_strncmp(path, "bssid", 5) == 0)
    {
        jsontree_write_string(js_ctx, sr ? sr->bssid : "");
    }
    else if (os_strncmp(path, "ssid", 4) == 0)
    {
        jsontree_write_string(js_ctx, sr ? sr->ssid : "");
    }
    else if (os_strncmp(path, "rssi", 4) == 0)
    {
        jsontree_write_int(js_ctx, sr ? -(sr->rssi) : 0);
    }
    else if (os_strncmp(path, "authmode", 8) == 0)
    {
        if(sr)
        {
            struct le *cur = param.le;
            param.le = cur->next;

            switch(sr->authmode)
            {
            case AUTH_OPEN:
                jsontree_write_string(js_ctx, "OPEN");
                break;

            case AUTH_WEP:
                jsontree_write_string(js_ctx, "WEP");
                break;

            case AUTH_WPA_PSK:
                jsontree_write_string(js_ctx, "WPAPSK");
                break;

            case AUTH_WPA2_PSK:
                jsontree_write_string(js_ctx, "WPA2PSK");
                break;

            case AUTH_WPA_WPA2_PSK:
                jsontree_write_string(js_ctx, "WPAPSK/WPA2PSK");
                break;

            default :
                jsontree_write_int(js_ctx, sr->authmode);
                break;
            }
        }
        else
            jsontree_write_string(js_ctx, "");
    }
    return 0;
}