Commit bc05e79b authored by whmaizmy's avatar whmaizmy Committed by 黄振令

【修改内容】1,子设备注册,添加topo,login 到云端

parent 0db490ba
......@@ -4,7 +4,7 @@
#define ADDRESS "tcp://172.25.240.31:1983"
#define CLIENTID "1234"
#define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/thing/service/property/set"
#define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/#"
#define PAYLOAD "Hello cwc World!"
#define QOS 2
......
......@@ -74,7 +74,7 @@ static int _check_invalid_topic(char* topic)
}
void KK_Sendto_DevData(const char *topic,const char *data)
{
if(_check_invalid_topic())
if(_check_invalid_topic(topic))
{
return;//ingore the message
}
......
......@@ -30,9 +30,9 @@
#include "kk_product.h"
//#include "iot_import.h"
char g_product_type[PRODUCT_TYPE_LEN];
char g_product_code[PRODUCT_CODE_LEN];
char g_device_code[DEVICE_CODE_LEN];
volatile char g_product_type[PRODUCT_TYPE_LEN]={"a1OYuSBt23u"};
volatile char g_product_code[PRODUCT_CODE_LEN] = {"aIqEbWno8yDdsjCX15iq"};
volatile char g_device_code[DEVICE_CODE_LEN];
#define PLATFORM_WAIT_INFINITE (~0)
......@@ -185,8 +185,10 @@ int HAL_SetProduct_Type(_IN_ char *product_type)
if (len > PRODUCT_TYPE_LEN) {
return -1;
}
printf("HAL_SetProduct_Type [%d] [%s] \n", len, g_product_type);
memset(g_product_type, 0x0, PRODUCT_TYPE_LEN);
strncpy(g_product_type, product_type, len);
printf("HAL_SetProduct_Type end [%d] [%s] \n", len, g_product_type);
return len;
}
......@@ -219,7 +221,9 @@ int HAL_GetProduct_Type(_OU_ char *product_type)
{
int len = strlen(g_product_type);
memset(product_type, 0x0, PRODUCT_TYPE_LEN);
printf("HAL_GetProduct_Type [%d] [%s] \n", len, g_product_type);
strncpy(product_type, g_product_type, len);
printf("HAL_GetProduct_Type product_type [%d] [%s] \n", len, product_type);
return len;
}
......
/*
* Copyright (C) 2020-2020 ikonke
*/
#ifndef _IOT_EXPORT_LINKKIT_H_
#define _IOT_EXPORT_LINKKIT_H_
#if defined(__cplusplus)
extern "C" {
#endif
/*#include "dm_wrapper.h"*/
typedef enum {
IOTX_LINKKIT_DEV_TYPE_MASTER,
IOTX_LINKKIT_DEV_TYPE_SLAVE,
IOTX_LINKKIT_DEV_TYPE_MAX
} iotx_linkkit_dev_type_t;
/*typedef struct {
char product_key[IOTX_PRODUCT_KEY_LEN + 1];
char product_secret[IOTX_PRODUCT_SECRET_LEN + 1];
char device_name[IOTX_DEVICE_NAME_LEN + 1];
char device_secret[IOTX_DEVICE_SECRET_LEN + 1];
} iotx_linkkit_dev_meta_info_t;*/
typedef enum {
/* post property value to cloud */
ITM_MSG_POST_PROPERTY,
/* post device info update message to cloud */
ITM_MSG_DEVICEINFO_UPDATE,
/* post device info delete message to cloud */
ITM_MSG_DEVICEINFO_DELETE,
/* post raw data to cloud */
ITM_MSG_POST_RAW_DATA,
/* only for slave device, send login request to cloud */
ITM_MSG_LOGIN,
/* only for slave device, send logout request to cloud */
ITM_MSG_LOGOUT,
/* only for slave device, send delete topo request to cloud */
ITM_MSG_DELETE_TOPO,
/* query ntp time from cloud */
ITM_MSG_QUERY_TIMESTAMP,
/* only for master device, query topo list */
ITM_MSG_QUERY_TOPOLIST,
/* only for master device, qurey firmware ota data */
ITM_MSG_QUERY_FOTA_DATA,
/* only for master device, qurey config ota data */
ITM_MSG_QUERY_COTA_DATA,
/* only for master device, request config ota data from cloud */
ITM_MSG_REQUEST_COTA,
/* only for master device, request fota image from cloud */
ITM_MSG_REQUEST_FOTA_IMAGE,
/* report subdev's firmware version */
ITM_MSG_REPORT_SUBDEV_FIRMWARE_VERSION,
/* get a device's desired property */
ITM_MSG_PROPERTY_DESIRED_GET,
/* delete a device's desired property */
ITM_MSG_PROPERTY_DESIRED_DELETE,
IOTX_LINKKIT_MSG_MAX
} iotx_linkkit_msg_type_t;
#if 0
/**
* @brief create a new device
*
* @param dev_type. type of device which will be created. see iotx_linkkit_dev_type_t
* @param meta_info. The product key, product secret, device name and device secret of new device.
*
* @return success: device id (>=0), fail: -1.
*
*/
int IOT_Linkkit_Open(iotx_linkkit_dev_type_t dev_type, iotx_linkkit_dev_meta_info_t *meta_info);
/**
* @brief start device network connection.
* for master device, start to connect aliyun server.
* for slave device, send message to cloud for register new device and add topo with master device
*
* @param devid. device identifier.
*
* @return success: device id (>=0), fail: -1.
*
*/
int IOT_Linkkit_Connect(int devid);
/**
* @brief try to receive message from cloud and dispatch these message to user event callback
*
* @param timeout_ms. timeout for waiting new message arrived
*
* @return void.
*
*/
void IOT_Linkkit_Yield(int timeout_ms);
/**
* @brief close device network connection and release resources.
* for master device, disconnect with aliyun server and release all local resources.
* for slave device, send message to cloud for delete topo with master device and unregister itself, then release device's resources.
*
* @param devid. device identifier.
*
* @return success: 0, fail: -1.
*
*/
int IOT_Linkkit_Close(int devid);
/**
* @brief Report message to cloud
*
* @param devid. device identifier.
* @param msg_type. message type. see iotx_linkkit_msg_type_t, as follows:
* ITM_MSG_POST_PROPERTY
* ITM_MSG_DEVICEINFO_UPDATE
* ITM_MSG_DEVICEINFO_DELETE
* ITM_MSG_POST_RAW_DATA
* ITM_MSG_LOGIN
* ITM_MSG_LOGOUT
*
* @param payload. message payload.
* @param payload_len. message payload length.
*
* @return success: 0 or message id (>=1), fail: -1.
*
*/
int IOT_Linkkit_Report(int devid, iotx_linkkit_msg_type_t msg_type, unsigned char *payload,
int payload_len);
/**
* @brief post message to cloud
*
* @param devid. device identifier.
* @param msg_type. message type. see iotx_linkkit_msg_type_t, as follows:
* ITM_MSG_QUERY_TIMESTAMP
* ITM_MSG_QUERY_TOPOLIST
* ITM_MSG_QUERY_FOTA_DATA
* ITM_MSG_QUERY_COTA_DATA
* ITM_MSG_REQUEST_COTA
* ITM_MSG_REQUEST_FOTA_IMAGE
*
* @param payload. message payload.
* @param payload_len. message payload length.
*
* @return success: 0 or message id (>=1), fail: -1.
*
*/
int IOT_Linkkit_Query(int devid, iotx_linkkit_msg_type_t msg_type, unsigned char *payload,
int payload_len);
/**
* @brief post event to cloud
*
* @param devid. device identifier.
* @param eventid. tsl event id.
* @param eventid_len. length of tsl event id.
* @param payload. event payload.
* @param payload_len. event payload length.
*
* @return success: message id (>=1), fail: -1.
*
*/
int IOT_Linkkit_TriggerEvent(int devid, char *eventid, int eventid_len, char *payload, int payload_len);
#endif
#if defined(__cplusplus)
}
#endif
#endif
This diff is collapsed.
/*
* Copyright (C) 2020-2020 ikonke
*/
#include "kk_dm_api.h"
#include "kk_tsl_common.h"
#include "kk_dm_mng.h"
static dm_api_ctx_t g_dm_api_ctx;
static dm_api_ctx_t *_dm_api_get_ctx(void)
{
return &g_dm_api_ctx;
}
static void _dm_api_lock(void)
{
dm_api_ctx_t *ctx = _dm_api_get_ctx();
if (ctx->mutex) {
HAL_MutexLock(ctx->mutex);
}
}
static void _dm_api_unlock(void)
{
dm_api_ctx_t *ctx = _dm_api_get_ctx();
if (ctx->mutex) {
HAL_MutexUnlock(ctx->mutex);
}
}
int iotx_dm_post_property(_IN_ int devid, _IN_ char *payload, _IN_ int payload_len)
{
int res = 0;
_dm_api_lock();
res = dm_mgr_upstream_thing_property_post(devid, payload, payload_len);
if (res < SUCCESS_RETURN) {
_dm_api_unlock();
return FAIL_RETURN;
}
_dm_api_unlock();
return res;
}
int iotx_dm_subdev_create(_IN_ char product_key[PRODUCT_KEY_MAXLEN],
_IN_ char device_name[DEVICE_NAME_MAXLEN],
_IN_ char device_secret[DEVICE_SECRET_MAXLEN], _OU_ int *devid)
{
int res = 0;
if (product_key == NULL || device_name == NULL ||
(strlen(product_key) >= PRODUCT_KEY_MAXLEN) ||
(strlen(device_name) >= DEVICE_NAME_MAXLEN) ||
devid == NULL) {
return INVALID_PARAMETER;
}
if (device_secret != NULL && strlen(device_secret) >= DEVICE_SECRET_MAXLEN) {
return INVALID_PARAMETER;
}
_dm_api_lock();
res = dm_mgr_device_create(IOTX_DM_DEVICE_SUBDEV, product_key, device_name, device_secret, devid);
if (res != SUCCESS_RETURN) {
_dm_api_unlock();
return FAIL_RETURN;
}
_dm_api_unlock();
return SUCCESS_RETURN;
}
int kk_dm_subdev_register(_IN_ int devid)
{
int res = 0;
dm_mgr_dev_node_t *search_node = NULL;
if (devid < 0) {
return INVALID_PARAMETER;
}
_dm_api_lock();
res = dm_mgr_search_dev_by_devid(devid, (void **)&search_node);
if (res != SUCCESS_RETURN) {
_dm_api_unlock();
return FAIL_RETURN;
}
if ((strlen(search_node->device_secret) > 0) && (strlen(search_node->device_secret) < DEVICE_SECRET_MAXLEN)) {
_dm_api_unlock();
return SUCCESS_RETURN;
}
res = dm_mgr_upstream_thing_sub_register(devid);
_dm_api_unlock();
return res;
}
int kk_dm_subdev_unregister(_IN_ int devid)
{
int res = 0;
if (devid < 0) {
return INVALID_PARAMETER;
}
_dm_api_lock();
res = dm_mgr_upstream_thing_sub_unregister(devid);
_dm_api_unlock();
return res;
}
int kk_dm_subdev_topo_add(_IN_ int devid)
{
int res = 0;
if (devid < 0) {
return INVALID_PARAMETER;
}
_dm_api_lock();
res = dm_mgr_upstream_thing_topo_add(devid);
_dm_api_unlock();
return res;
}
int iotx_dm_subdev_topo_del(_IN_ int devid)
{
int res = 0;
if (devid < 0) {
return DM_INVALID_PARAMETER;
}
_dm_api_lock();
res = dm_mgr_upstream_thing_topo_delete(devid);
_dm_api_unlock();
return res;
}
int iotx_dm_subdev_login(_IN_ int devid)
{
int res = 0;
if (devid < 0) {
return INVALID_PARAMETER;
}
_dm_api_lock();
res = dm_mgr_upstream_combine_login(devid);
_dm_api_unlock();
return res;
}
int iotx_dm_subdev_logout(_IN_ int devid)
{
int res = 0;
if (devid < 0) {
return DM_INVALID_PARAMETER;
}
_dm_api_lock();
res = dm_mgr_upstream_combine_logout(devid);
_dm_api_unlock();
return res;
}
void iotx_dm_dispatch(void)
{
int count = 0;
void *data = NULL;
dm_api_ctx_t *ctx = _dm_api_get_ctx();
#if defined(OTA_ENABLED) && !defined(BUILD_AOS)
dm_cota_status_check();
dm_fota_status_check();
#endif
while (CONFIG_DISPATCH_QUEUE_MAXLEN == 0 || count++ < CONFIG_DISPATCH_QUEUE_MAXLEN) {
//printf("iotx_dm_dispatch time=%d \n", HAL_UptimeMs());
if (dm_queue_msg_next(&data) == SUCCESS_RETURN) {
//dm_queue_msg_t *msg = (dm_queue_msg_t *)data;
printf("dm_queue_msg_next call \n");
if (ctx->event_callback) {
ctx->event_callback(1, data);
}
free(data);
data = NULL;
} else {
break;
}
}
}
int iotx_dm_connect(_IN_ iotx_dm_event_callback cb)
{
int res = 0;
dm_api_ctx_t *ctx = _dm_api_get_ctx();
if (cb == NULL) {
return INVALID_PARAMETER;
}
/* DM Event Callback */
ctx->event_callback = cb;
/*res = dm_client_connect(IOTX_DM_CLIENT_CONNECT_TIMEOUT_MS);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
#ifdef ALCS_ENABLED
res = dm_server_connect();
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
#endif*/
return SUCCESS_RETURN;
}
/*
* Copyright (C) 2015-2018 Alibaba Group Holding Limited
*/
#ifndef _KK_DM_API_H_
#define _KK_DM_API_H_
#include "iotx_dm.h"
#define CONFIG_DISPATCH_QUEUE_MAXLEN (50)
typedef struct {
void *mutex;
void *cloud_connectivity;
void *local_connectivity;
iotx_dm_event_callback event_callback;
} dm_api_ctx_t;
#if defined(DEPRECATED_LINKKIT)
typedef struct {
void *mutex;
int devid;
lite_cjson_item_t *lite;
} dm_api_property_t;
#endif
#endif
This diff is collapsed.
......@@ -3,9 +3,12 @@
#include "kk_tsl_common.h"
#include "klist.h"
#include "iotx_dm.h"
#define KK_DM_DEVICE_SINGLE (0x01)
#define KK_DM_DEVICE_SUBDEV (0x02)
#define KK_DM_DEVICE_GATEWAY (0x04)
#define KK_MID_SYNC_DEFAULT_TIMEOUT_MS (200)
typedef struct {
int devid;
......@@ -14,8 +17,8 @@ typedef struct {
char product_key[PRODUCT_KEY_MAXLEN];
char device_name[DEVICE_NAME_MAXLEN];
char device_secret[DEVICE_SECRET_MAXLEN];
//iotx_dm_dev_avail_t status;
//iotx_dm_dev_status_t dev_status;
iotx_dm_dev_avail_t status;
iotx_dm_dev_status_t dev_status;
struct list_head linked_list;
} dm_mgr_dev_node_t;
......
This diff is collapsed.
#ifndef __KK_DM_MSG__
#define __KK_DM_MSG__
#include "kk_tsl_common.h"
#include "../tsl_handle/lite-cjson.h"
typedef enum {
#define DM_MSG_KEY_ID "id"
#define DM_MSG_KEY_VERSION "version"
#define DM_MSG_KEY_METHOD "method"
#define DM_MSG_KEY_PARAMS "params"
#define DM_MSG_KEY_CODE "code"
#define DM_MSG_KEY_DATA "data"
#define DM_MSG_KEY_MESSAGE "message"
#define DM_MSG_VERSION "1.0"
#define DM_MSG_KEY_PRODUCT_KEY "productKey"
#define DM_MSG_KEY_DEVICE_NAME "deviceName"
#define DM_MSG_KEY_DEVICE_SECRET "deviceSecret"
#define DM_MSG_KEY_TIME "time"
#define DM_MSG_SIGN_METHOD_SHA256 "Sha256"
#define DM_MSG_SIGN_METHOD_HMACMD5 "hmacMd5"
#define DM_MSG_SIGN_METHOD_HMACSHA1 "hmacSha1"
#define DM_MSG_SIGN_METHOD_HMACSHA256 "hmacSha256"
/*typedef enum {
IOTX_DM_EVENT_CLOUD_CONNECTED = 0,
IOTX_DM_EVENT_CLOUD_DISCONNECT,
IOTX_DM_EVENT_CLOUD_RECONNECT,
......@@ -47,7 +71,15 @@ typedef enum {
IOTX_DM_EVENT_NTP_RESPONSE,
IOTX_DM_EVENT_RRPC_REQUEST,
IOTX_DM_EVENT_MAX
} iotx_dm_event_types_t;
} iotx_dm_event_types_t;*/
typedef struct {
lite_cjson_t id;
lite_cjson_t code;
lite_cjson_t data;
lite_cjson_t message;
} dm_msg_response_payload_t;
#ifndef DM_READ_ONLY
#define DM_READ_ONLY
......
/*
* Copyright (C) 2020-2020 ikonke
*/
#include "kk_dm_queue.h"
#include "kk_tsl_common.h"
dm_queue_t g_dm_queue;
static dm_queue_t *_dm_queue_get_ctx(void)
{
return &g_dm_queue;
}
static void _dm_queue_lock(void)
{
dm_queue_t *ctx = _dm_queue_get_ctx();
if (ctx->mutex) {
HAL_MutexLock(ctx->mutex);
}
}
static void _dm_queue_unlock(void)
{
dm_queue_t *ctx = _dm_queue_get_ctx();
if (ctx->mutex) {
HAL_MutexUnlock(ctx->mutex);
}
}
int dm_queue_init(int max_size)
{
dm_queue_t *ctx = _dm_queue_get_ctx();
memset(ctx, 0, sizeof(dm_queue_t));
/* Create Mutex */
ctx->mutex = HAL_MutexCreate();
if (ctx->mutex == NULL) {
return INVALID_PARAMETER;
}
/* Init List */
ctx->msg_list.max_size = max_size;
INIT_LIST_HEAD(&ctx->msg_list.message_list);
return SUCCESS_RETURN;
}
void dm_queue_deinit(void)
{
dm_queue_t *ctx = _dm_queue_get_ctx();
dm_queue_msg_node_t *del_node = NULL;
dm_queue_msg_node_t *next_node = NULL;
dm_queue_msg_t *del_msg = NULL;
if (ctx->mutex) {
HAL_MutexDestroy(ctx->mutex);
}
list_for_each_entry_safe(del_node, next_node, &ctx->msg_list.message_list, linked_list, dm_queue_msg_node_t) {
/* Free Message */
del_msg = (dm_queue_msg_t *)del_node->data;
if (del_msg->data) {
free(del_msg->data);
}
free(del_msg);
del_msg = NULL;
/* Free Node */
list_del(&del_node->linked_list);
free(del_node);
}
}
int dm_queue_msg_insert(void *data)
{
dm_queue_t *ctx = _dm_queue_get_ctx();
dm_queue_msg_node_t *node = NULL;
if (data == NULL) {
return INVALID_PARAMETER;
}
_dm_queue_lock();
printf("dm msg list size: %d, max size: %d", ctx->msg_list.size, ctx->msg_list.max_size);
if (ctx->msg_list.size >= ctx->msg_list.max_size) {
printf("dm queue list full");
_dm_queue_unlock();
return FAIL_RETURN;
}
node = malloc(sizeof(dm_queue_msg_node_t));
if (node == NULL) {
_dm_queue_unlock();
return DM_MEMORY_NOT_ENOUGH;
}
memset(node, 0, sizeof(dm_queue_msg_node_t));
node->data = data;
INIT_LIST_HEAD(&node->linked_list);
ctx->msg_list.size++;
list_add_tail(&node->linked_list, &ctx->msg_list.message_list);
_dm_queue_unlock();
return SUCCESS_RETURN;
}
int dm_queue_msg_next(void **data)
{
dm_queue_t *ctx = _dm_queue_get_ctx();
dm_queue_msg_node_t *node = NULL;
if (data == NULL || *data != NULL) {
return INVALID_PARAMETER;
}
_dm_queue_lock();
if (list_empty(&ctx->msg_list.message_list)) {
_dm_queue_unlock();
return FAIL_RETURN;
}
node = list_first_entry(&ctx->msg_list.message_list, dm_queue_msg_node_t, linked_list);
list_del(&node->linked_list);
ctx->msg_list.size--;
*data = node->data;
free(node);
_dm_queue_unlock();
return SUCCESS_RETURN;
}
/*
* Copyright (C) 2020-2020 ikonke
*/
#ifndef _DM_QUEUE_H_
#define _DM_QUEUE_H_
#include "iotx_dm.h"
#include "klist.h"
typedef struct {
iotx_dm_event_types_t type;
char *data;
} dm_queue_msg_t;
typedef struct {
void *data;
struct list_head linked_list;
} dm_queue_msg_node_t;
typedef struct {
int max_size;
int size;
struct list_head message_list;
} dm_queue_msg_list_t;
typedef struct {
void *mutex;
dm_queue_msg_list_t msg_list;
} dm_queue_t;
int dm_queue_init(int max_size);
void dm_queue_deinit(void);
int dm_queue_msg_insert(void *data);
int dm_queue_msg_next(void **data);
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -13,6 +13,7 @@
#include <sys/shm.h>
#include "cJSON.h"
#include "kk_product.h"
#include "kk_tsl_common.h"
......@@ -29,7 +30,21 @@ void mid_cb(void* data, int len){
{
topic = cJSON_GetObjectItem(json, "topic");
payload = cJSON_GetObjectItem(json, "payload");
kk_tsl_service_property_set(topic->valuestring, payload->valuestring,strlen(payload->valuestring),NULL);
printf("mid_cb topic: [%s] ,payload= %s \n",topic->valuestring,payload->valuestring );
if (strcmp(payload->valuestring, "addsub")==0){
kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","");
}else{
void* buf = malloc(len);
memcpy(buf, data, len);
int res = dm_queue_msg_insert((void *)buf);
if (res != SUCCESS_RETURN) {
free(buf);
return FAIL_RETURN;
}
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}
}
kk_ipc_send(IPC_MID2PLAT, data, len);
}
......@@ -94,6 +109,38 @@ time_t getSysTime(){
return t;
}
typedef struct {
int auto_add_subdev;
int master_devid;
int cloud_connected;
int master_initialized;
int subdev_index;
int permit_join;
void *g_mid_dispatch_thread;
int g_mid_dispatch_thread_running;
} mid_ctx_t;
#define MID_YIELD_TIMEOUT_MS (200)
static mid_ctx_t g_mid_ctx;
static mid_ctx_t *kk_mid_get_ctx(void)
{
return &g_mid_ctx;
}
extern void IOT_Linkkit_Yield(int timeout_ms);
void *mid_dispatch_yield(void *args)
{
mid_ctx_t *mid_ctx = kk_mid_get_ctx();
while (mid_ctx->g_mid_dispatch_thread_running) {
IOT_Linkkit_Yield(MID_YIELD_TIMEOUT_MS);
}
return NULL;
}
static int kk_set_product_info(void)
{
HAL_SetProduct_Type(PRODUCT_TPYE);
......@@ -104,6 +151,13 @@ static int kk_set_product_info(void)
int main(const int argc, const char **argv)
{
int res = 0;
mid_ctx_t *mid_ctx = kk_mid_get_ctx();
memset(mid_ctx, 0, sizeof(mid_ctx_t));
kk_set_product_info();
kk_tsl_api_init();
kk_ipc_init(IPC_MID2APP, mid_cb);
......@@ -113,9 +167,33 @@ int main(const int argc, const char **argv)
//DB_Init();
//test_tcp();
/* when Connect to app and platfrom */
/*do {
res = IOT_Linkkit_Connect(user_example_ctx->master_devid);
if (res < 0) {
EXAMPLE_TRACE("IOT_Linkkit_Connect failed, retry after 5s...\n");
HAL_SleepMs(5000);
}
} while (res < 0);*/
kk_init_dmproc();
mid_ctx->g_mid_dispatch_thread_running = 1;
res = pthread_create(&mid_ctx->g_mid_dispatch_thread, NULL, mid_dispatch_yield, NULL);
if (res < 0) {
printf("HAL_ThreadCreate Failed\n");
IOT_Linkkit_Close(mid_ctx->master_devid);
return -1;
}
char buf[100] = {0};
int ct = 0;
for (;;) {
sleep(5);
usleep(4000000);
if (ct == 0){
ct =1;
kk_set_tsl_by_productKey("a1OYuSallan","model.json");
kk_mid_subdev_add("a1OYuSallan","allanWno8yDdsjCX15iq","");
}
/*memset(buf, 0, 100);
sprintf(buf , "send data app time = %d\n", getSysTime());
printf("M2A: %s", buf);
......
......@@ -2,6 +2,7 @@
#define _TSL_API_H__
#include "lite-cjson.h"
#include "kk_tsl_common.h"
#include "../../midware/dm/iotx_dm.h"
......@@ -14,14 +15,14 @@
#define KK_MSG_KEY_MESSAGE "message"
typedef enum {
/*typedef enum {
IOTX_DM_ERR_CODE_SUCCESS = 200,
IOTX_DM_ERR_CODE_REQUEST_ERROR = 400,
IOTX_DM_ERR_CODE_REQUEST_PARAMS_ERROR = 460,
IOTX_DM_ERR_CODE_REQUEST_TOO_MANY = 429,
IOTX_DM_ERR_CODE_NO_ACTIVE_SESSION = 520,
IOTX_DM_ERR_CODE_TIMEOUT = 100000
} iotx_dm_error_code_t;
} iotx_dm_error_code_t;*/
typedef struct {
const char *uri;
......
#include "kk_utils.h"
#include "lite-cjson.h"
int kk_utils_copy(_IN_ void *input, _IN_ int input_len, _OU_ void **output, _IN_ int output_len)
{
......@@ -262,4 +264,55 @@ int kk_utils_ftoa_direct(_IN_ double input, _OU_ char **output)
return SUCCESS_RETURN;
}
int kk_utils_json_parse(_IN_ const char *payload, _IN_ int payload_len, _IN_ int type, _OU_ lite_cjson_t *lite)
{
int res = 0;
if (payload == NULL || payload_len <= 0 || type < 0 || lite == NULL) {
return INVALID_PARAMETER;
}
memset(lite, 0, sizeof(lite_cjson_t));
res = lite_cjson_parse(payload, payload_len, lite);
if (res != SUCCESS_RETURN) {
memset(lite, 0, sizeof(lite_cjson_t));
return FAIL_RETURN;
}
//printf (" lite->type= %d [%d] \n", lite->type, type);
if (type != cJSON_Invalid && lite->type != type) {
memset(lite, 0, sizeof(lite_cjson_t));
return FAIL_RETURN;
}
return SUCCESS_RETURN;
}
int kk_utils_json_object_item(_IN_ lite_cjson_t *lite, _IN_ const char *key, _IN_ int key_len, _IN_ int type,
_OU_ lite_cjson_t *lite_item)
{
int res = 0;
if (lite == NULL || lite->type != cJSON_Object || key == NULL || key_len <= 0 || type < 0 || lite_item == NULL) {
return INVALID_PARAMETER;
}
if (lite->type != cJSON_Object) {
dm_log_err("lite->type != cJSON_Object, %d", lite->type);
}
memset(lite_item, 0, sizeof(lite_cjson_t));
res = lite_cjson_object_item(lite, key, key_len, lite_item);
if (res != SUCCESS_RETURN) {
/* dm_log_err(DM_UTILS_LOG_JSON_PARSE_FAILED, lite->value_length, lite->value); */
memset(lite_item, 0, sizeof(lite_cjson_t));
return FAIL_RETURN;
}
if (type != cJSON_Invalid && lite_item->type != type) {
memset(lite_item, 0, sizeof(lite_cjson_t));
return FAIL_RETURN;
}
return SUCCESS_RETURN;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment