Commit fc3fe0ee authored by 黄振令's avatar 黄振令
parents dbaa62f2 4edd1128
......@@ -7,7 +7,7 @@
#define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/thing/service/property/set"
#define PAYLOAD "Hello cwc World!"
#define QOS 2
#define QOS 0
#define TIMEOUT 10000L
#define USRNAME "hangzhou_gateway "
#define PASSWORD "2ca1442865ff4cb99870f60f2c646190"
......
......@@ -88,7 +88,7 @@ static int _dm_mgr_next_devid(void)
return ctx->global_devid++;
}
static int _dm_init_tsl_params(int devId)
static int _dm_init_tsl_params(kk_tsl_t * dev_shadow)
{
int res = 0;
char version[VERSION_MAXLEN] = {0};
......@@ -99,7 +99,7 @@ static int _dm_init_tsl_params(int devId)
/*******set version***********/
HAL_GetVersion(version);
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,KK_TSL_VERSION_IDENTIFIER,NULL,version);
res = kk_tsl_set_value(kk_tsl_set_property_value,dev_shadow,KK_TSL_VERSION_IDENTIFIER,NULL,version);
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
......@@ -107,12 +107,12 @@ static int _dm_init_tsl_params(int devId)
/*******set IP*************/
//HAL_Get_IP(s_IP,NULL);
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,KK_TSL_CCU_LANIP_IDENTIFIER,NULL,"0.0.0.0");
res = kk_tsl_set_value(kk_tsl_set_property_value,dev_shadow,KK_TSL_CCU_LANIP_IDENTIFIER,NULL,"0.0.0.0");
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,KK_TSL_CCU_WANIP_IDENTIFIER,NULL,"0.0.0.0");
res = kk_tsl_set_value(kk_tsl_set_property_value,dev_shadow,KK_TSL_CCU_WANIP_IDENTIFIER,NULL,"0.0.0.0");
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
......@@ -120,28 +120,28 @@ static int _dm_init_tsl_params(int devId)
/*******set MAC*************/
HAL_Get_mac(s_mac);
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,KK_TSL_GATAWAY_MAC_IDENTIFIER,NULL,s_mac);
res = kk_tsl_set_value(kk_tsl_set_property_value,dev_shadow,KK_TSL_GATAWAY_MAC_IDENTIFIER,NULL,s_mac);
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
int wanState = 0;
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,KK_TSL_CCU_WANSTATE_IDENTIFIER,&wanState,NULL);
res = kk_tsl_set_value(kk_tsl_set_property_value,dev_shadow,KK_TSL_CCU_WANSTATE_IDENTIFIER,&wanState,NULL);
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
int IOTCloudState = 0;
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,KK_TSL_CCU_IOTCLOUD_IDENTIFIER,&IOTCloudState,NULL);
res = kk_tsl_set_value(kk_tsl_set_property_value,dev_shadow,KK_TSL_CCU_IOTCLOUD_IDENTIFIER,&IOTCloudState,NULL);
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
/*******set sn*************/
HAL_Get_SN(s_SN);
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,KK_TSL_GATAWAY_SN_IDENTIFIER,NULL,s_SN);
res = kk_tsl_set_value(kk_tsl_set_property_value,dev_shadow,KK_TSL_GATAWAY_SN_IDENTIFIER,NULL,s_SN);
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
......@@ -229,7 +229,7 @@ int dm_mgr_device_create(_IN_ int dev_type,_IN_ char productCode[PRODUCT_CODE_MA
list_add_tail(&node->linked_list, &ctx->dev_list);
if(dev_type == KK_DM_DEVICE_CCU){
//_dm_init_tsl_params(node->devid);
_dm_init_tsl_params(node->dev_shadow);
}
if (devid) {
......@@ -280,6 +280,25 @@ int dm_mgr_get_devicetype_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN]
ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode);
return FAIL_RETURN;
}
int dm_mgr_get_device_shadow_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ kk_tsl_t **shadow)
{
dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
dm_mgr_dev_node_t *search_node = NULL;
list_for_each_entry(search_node, &ctx->dev_list, linked_list, dm_mgr_dev_node_t) {
if ((strlen(search_node->deviceCode) == strlen(deviceCode)) &&
(memcmp(search_node->deviceCode, deviceCode, strlen(deviceCode)) == 0)) {
/* dm_log_debug("Device Found, Product Key: %s, Device Name: %s", product_key, device_name); */
if (shadow) {
*shadow = search_node->dev_shadow;
}
return SUCCESS_RETURN;
}
}
ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode);
return FAIL_RETURN;
}
int dm_mgr_get_device_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _OU_ dm_mgr_dev_node_t **node)
......@@ -301,6 +320,8 @@ int dm_mgr_get_device_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN], _O
ERROR_PRINT("Device Not Found, deviceCode: %s\n", deviceCode);
return FAIL_RETURN;
}
int dm_mgr_update_timestamp_by_devicecode(_IN_ char deviceCode[DEVICE_CODE_MAXLEN],uint64_t timestamp)
{
dm_mgr_ctx *ctx = _dm_mgr_get_ctx();
......@@ -421,7 +442,7 @@ int dm_mgr_init(void)
goto ERROR;
}
else{
_dm_init_tsl_params(devId);
kk_property_db_update("CCU_66666");
}
......
......@@ -738,11 +738,78 @@ int dm_msg_thing_property_set_reply(char deviceCode[DEVICE_CODE_MAXLEN],char *pa
dm_msg_response(&request, &response, "{}", strlen("{}"), NULL);
return SUCCESS_RETURN;
}
int dm_msg_thing_event_post(const char *deviceCode, const char *identifier)
{
int res = 0;
int nums = 0;
int idx = 0;
char *payload = NULL;
dm_mgr_dev_node_t *node = NULL;
void *event = NULL;
char *method = NULL;
if(deviceCode == NULL){
return FAIL_RETURN;
}
res = dm_mgr_get_device_by_devicecode(deviceCode, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
payload = kk_tsl_get_post_event_str(node->dev_shadow,identifier,strlen(identifier));
if(payload != NULL){
res = kk_tsl_get_event_by_identifier(node->dev_shadow, identifier, &event);
if (res != SUCCESS_RETURN) {
free(payload);
return FAIL_RETURN;
}
res = kk_tsl_get_event_method(event, &method);
if (res != SUCCESS_RETURN) {
free(payload);
return FAIL_RETURN;
}
dm_mgr_upstream_thing_event_post(node->devid, identifier, strlen(identifier), method, payload, strlen(payload));
free(method);
method = NULL;
free(payload);
payload = NULL;
}
return SUCCESS_RETURN;
}
int dm_msg_thing_service_post(const char *deviceCode, const char *identifier,int response_id,int code)
{
int res = 0;
int nums = 0;
int idx = 0;
char *payload = NULL;
dm_mgr_dev_node_t *node = NULL;
if(deviceCode == NULL){
return FAIL_RETURN;
}
res = dm_mgr_get_device_by_devicecode(deviceCode, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
payload = kk_tsl_get_post_service_str(node->dev_shadow,identifier);
if(payload != NULL){
dm_mgr_deprecated_upstream_thing_service_response(node->devid,response_id,code, identifier, strlen(identifier), payload, strlen(payload));
free(payload);
payload = NULL;
}
return SUCCESS_RETURN;
}
int dm_msg_thing_property_post_all(char *deviceCode)
{
int res = 0;
int nums = 0;
int idx = 0;
char *payload = NULL;
dm_mgr_dev_node_t *node = NULL;
if(deviceCode == NULL){
......@@ -753,7 +820,12 @@ int dm_msg_thing_property_post_all(char *deviceCode)
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
kk_tsl_post_property(node->devid,NULL,1);//here need async post
payload = kk_tsl_get_post_property_str(node->dev_shadow,NULL);//here need async post
if(payload != NULL){
dm_mgr_upstream_thing_property_post(node->devid, payload, strlen(payload),1);
free(payload);
payload = NULL;
}
return SUCCESS_RETURN;
}
......@@ -784,7 +856,6 @@ int dm_msg_thing_property_post_by_identify(char *deviceCode,cJSON *params)
}
propertyItem = cJSON_GetObjectItem(params, property->identifier);
if(propertyItem != NULL){
//kk_tsl_post_property(node->devid,property->identifier,0);
/*update the db data */
if(property->data_value.type == KK_TSL_DATA_TYPE_INT ||
......
......@@ -298,19 +298,20 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
INFO_PRINT("property set \n");
cJSON *deviceCode = cJSON_GetObjectItem(info_root, MSG_DEVICE_CODE_STR);
dm_msg_thing_property_set_reply(deviceCode->valuestring,payload_Str, strlen(payload_Str), NULL);
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}else if (strstr(typeJson->valuestring,KK_THING_CLOUDSTATE_MSG)){
INFO_PRINT("cloud state notify \n");
s_CloudStatusRecv = 1;
cJSON *paramStr = cJSON_GetObjectItem(payload, MSG_PARAMS_STR);
cJSON *state = cJSON_GetObjectItem(paramStr, MSG_IOTClOUDSTATE_STR);
s_CloudStatus = atoi(state->valuestring);
res = kk_tsl_set_value(kk_tsl_set_property_value,0,KK_TSL_CCU_WANSTATE_IDENTIFIER,&s_CloudStatus,NULL);
dm_mgr_dev_node_t *node = NULL;
dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID,&node);
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,KK_TSL_CCU_WANSTATE_IDENTIFIER,&s_CloudStatus,NULL);
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
}
res = kk_tsl_set_value(kk_tsl_set_property_value,0,KK_TSL_CCU_IOTCLOUD_IDENTIFIER,&s_CloudStatus,NULL);
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,KK_TSL_CCU_IOTCLOUD_IDENTIFIER,&s_CloudStatus,NULL);
if(res != SUCCESS_RETURN)
{
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
......@@ -319,7 +320,12 @@ static void _iotx_linkkit_event_callback(iotx_dm_event_types_t type, char *data)
if(s_CloudStatus){
iotx_dm_dev_online(KK_DM_DEVICE_CCU_DEVICEID);//first online,report the online status
usleep(200000);
kk_tsl_post_property(KK_DM_DEVICE_CCU_DEVICEID,NULL,0);
char *payload_property = kk_tsl_get_post_property_str(node->dev_shadow,NULL);
if(payload_property != NULL){
dm_mgr_upstream_thing_property_post(node->devid, payload_property, strlen(payload_property),0);
free(payload_property);
payload_property = NULL;
}
}
}else if (strstr(typeJson->valuestring,KK_THING_OTA_DEVICE_UPGRADE)){
INFO_PRINT("ota upgrade... \n");
......
......@@ -328,11 +328,12 @@ int kk_property_sync_values(const char *deviceCode)
char *pIdentifier = NULL;
char *valueStr = NULL;
int valueType = 0;
int devId = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
char *searchCmd = "select * from PropertiesInfo;";
dm_mgr_dev_node_t *node = NULL;
dm_mgr_get_devId_by_devicecode(deviceCode,&devId);
dm_mgr_get_device_by_devicecode(deviceCode,&node);
sqlCmd = sqlite3_mprintf(searchCmd,deviceCode);
......@@ -351,18 +352,18 @@ int kk_property_sync_values(const char *deviceCode)
valueType == KK_TSL_DATA_TYPE_ENUM||
valueType == KK_TSL_DATA_TYPE_BOOL){
int value_int = atoi(valueStr);
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,pIdentifier,&value_int,NULL);
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,pIdentifier,&value_int,NULL);
}
else if(valueType == KK_TSL_DATA_TYPE_FLOAT){
float value_float = atoi(valueStr);
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,pIdentifier,&value_float,NULL);
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,pIdentifier,&value_float,NULL);
}
else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
double value_double = atoi(valueStr);
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,pIdentifier,&value_double,NULL);
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,pIdentifier,&value_double,NULL);
}
else{
res = kk_tsl_set_value(kk_tsl_set_property_value,devId,pIdentifier,NULL,valueStr);
res = kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,pIdentifier,NULL,valueStr);
}
if(res != SUCCESS_RETURN)
{
......
#include <stdio.h>
#include "kk_tsl_api.h"
#include "kk_wlist_mng.h"
#include "sqlite3.h"
#include "kk_log.h"
#define KK_TSL_GATAWAY_ADDWHITELIST_IDENTIFIER "addWhiteList"
#define KK_TSL_GATAWAY_WHITELISTDEVICE_IDENTIFIER "Devices"
#define KK_TSL_GATAWAY_WHITELISTMAC_IDENTIFIER "getWhiteListNotification.Devices[%d].MACAddress"
#define KK_TSL_GATAWAY_WHITELISTPRODUCTID_IDENTIFIER "getWhiteListNotification.Devices[%d].ProductId"
#define KK_TSL_GATAWAY_WHITELISTSN_IDENTIFIER "getWhiteListNotification.Devices[%d].SN"
#define KK_TSL_GATAWAY_WHITELISTDEVICEID_IDENTIFIER "getWhiteListNotification.Devices[%d].deviceId"
#define KK_WLIST_DB_FILE "wlist.db"
typedef struct {
void *mutex;
int isOpened;
int isInited;
int wlistNum;
sqlite3 *pDb;
} kk_wlist_ctx_t;
static kk_wlist_ctx_t s_kk_wlist_ctx = {NULL,0,0,NULL};
static kk_wlist_ctx_t *_kk_wlist_get_ctx(void)
{
return &s_kk_wlist_ctx;
}
static void _kk_wlist_lock(void)
{
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
if (ctx->mutex) {
HAL_MutexLock(ctx->mutex);
}
}
static void _kk_wlist_unlock(void)
{
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
if (ctx->mutex) {
HAL_MutexUnlock(ctx->mutex);
}
}
static int kk_wlist_db_Init(void)
{
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
//eUtils_LockLock(&sLock);
_kk_wlist_lock();
if (sqlite3_open_v2(KK_WLIST_DB_FILE, &ctx->pDb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) != SQLITE_OK)
{
ERROR_PRINT("Error initialising linkage database (%s)", sqlite3_errmsg(ctx->pDb));
_kk_wlist_unlock();
return FAIL_RETURN;
}
INFO_PRINT("wlist Database opened\n");
{
const char *pwListTable = "CREATE TABLE IF NOT EXISTS WhiteList(idx INTEGER, deviceMac varchar(17),productId varchar(33), deviceSN varchar(33), deviceId varchar(33))";
char *pcErr;
// DBG_vPrintf(DBG_SQL, "Execute SQL: '%s'\n", pConditionTableDef);
if (sqlite3_exec(ctx->pDb, pwListTable, NULL, NULL, &pcErr) != SQLITE_OK)
{
ERROR_PRINT("Error creating table (%s)\n", pcErr);
sqlite3_free(pcErr);
//eUtils_LockUnlock(&sLock);
_kk_wlist_unlock();
return FAIL_RETURN;
}
}
//eUtils_LockUnlock(&sLock);
_kk_wlist_unlock();
return SUCCESS_RETURN;
}
static int _kk_check_exist(const char* device_mac)
{
int isExist = 0;
sqlite3_stmt *stmt;
char *pmac = NULL;
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
const char *searchCmd = "select * from WhiteList;";
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
INFO_PRINT("total_column = %d\n", sqlite3_column_count(stmt));
while(sqlite3_step(stmt) == SQLITE_ROW){
pmac = sqlite3_column_text(stmt, 1);
if(!strcmp(device_mac,pmac))
{
isExist = 1;
break;
}
}
INFO_PRINT("\n");
sqlite3_finalize(stmt);
return isExist;
}
static int kk_wlist_insert_db(int index,char device_mac[DEVICE_MAC_MAXLEN],char product_Id[PRODUCT_CODE_MAXLEN], \
char device_SN[DEVICE_SN_MAXLEN],char device_Id[DEVICE_CODE_MAXLEN])
{
const char *insertCmd = "insert into WhiteList (idx, deviceMac, productId,deviceSN,deviceId) values ('%d', '%s', '%s','%s','%s');";
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
_kk_wlist_lock();
sqlCmd = sqlite3_mprintf(insertCmd, index,device_mac,product_Id,device_SN,device_Id);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
INFO_PRINT("Table insert data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_wlist_unlock();
return SUCCESS_RETURN;
}
static int _kk_wlist_delete_db_byMac(char device_mac[DEVICE_MAC_MAXLEN])
{
const char *deleteCmd = "delete from WhiteList where deviceMac = %s;";
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
_kk_wlist_lock();
sqlCmd = sqlite3_mprintf( deleteCmd,device_mac);
INFO_PRINT("Table delete data sqlCmd:%s\n",sqlCmd);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){
ERROR_PRINT("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
INFO_PRINT("Table delete data successfully\n");
}
sqlite3_free(sqlCmd);
_kk_wlist_unlock();
return SUCCESS_RETURN;
}
int kk_wlist_status_open(int isOpen)
{
int res = 0;
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
if(ctx->isOpened)
{
printf("[%s][%d] ALREADY OPENED\n",__FUNCTION__,__LINE__,res);
return SUCCESS_RETURN;
}
res = kk_tsl_set_value(kk_tsl_set_property_value,0,KK_TSL_GATAWAY_WHITELIST_IDENTIFIER,&isOpen,NULL);
if(res != SUCCESS_RETURN){
ERROR_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
}
ctx->isOpened = isOpen;
if(ctx->isOpened){
kk_wlist_init();
}
return SUCCESS_RETURN;
}
int kk_load_wlist(void)
{
const char *searchCmd = "select * from WhiteList;";
sqlite3_stmt *stmt;
char *pmac = NULL,*pPID = NULL,*pSN = NULL,pDID = NULL;
kk_wlist_dev_t wlist = {0};
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
if(ctx->isOpened != 1){
return FAIL_RETURN;
}
sqlite3_prepare_v2(ctx->pDb, searchCmd, strlen(searchCmd), &stmt, NULL);
INFO_PRINT("kk_load_wlist total_column = %d\n", sqlite3_column_count(stmt));
while(sqlite3_step(stmt) == SQLITE_ROW){
memset(&wlist,0x0,sizeof(kk_wlist_dev_t));
strcpy(wlist.device_mac,sqlite3_column_text(stmt, 1));
strcpy(wlist.product_id,sqlite3_column_text(stmt, 2));
strcpy(wlist.device_sn,sqlite3_column_text(stmt, 3));
strcpy(wlist.device_id,sqlite3_column_text(stmt, 4));
// kk_add_wlist(&wlist);
kk_set_wlist_byIdx(ctx->wlistNum,&wlist);
ctx->wlistNum++;
}
sqlite3_finalize(stmt);
return SUCCESS_RETURN;
}
int kk_wlist_init(void)
{
int res = 0;
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
if(ctx->isInited)
{
return SUCCESS_RETURN;
}
/* Create Mutex */
ctx->mutex = HAL_MutexCreate();
if (ctx->mutex == NULL) {
return FAIL_RETURN;
}
res = kk_wlist_db_Init();
if(res != SUCCESS_RETURN){
ERROR_PRINT("[%s][%d]kk_wlist_db_Init FAIL!!!\n",__FUNCTION__,__LINE__);
}
kk_load_wlist();
ctx->isInited = 1;
return SUCCESS_RETURN;
}
int kk_set_wlist_byIdx(int idx,kk_wlist_dev_t * wlist_dev)
{
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
int res = 0;
char identifier_name[64] = {0};
if(wlist_dev == NULL)
{
ERROR_PRINT("[%s][%d] wlist_dev == NULL!!!\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
}
_kk_wlist_lock();
sprintf(identifier_name,KK_TSL_GATAWAY_WHITELISTMAC_IDENTIFIER,idx);
res = kk_tsl_set_value(kk_tsl_set_event_output_value,0,identifier_name,NULL,wlist_dev->device_mac);
if(res != SUCCESS_RETURN){
goto fail_return;
}
memset(identifier_name,0x0,sizeof(identifier_name));
sprintf(identifier_name,KK_TSL_GATAWAY_WHITELISTPRODUCTID_IDENTIFIER,idx);
res = kk_tsl_set_value(kk_tsl_set_event_output_value,0,identifier_name,NULL,wlist_dev->product_id);
if(res != SUCCESS_RETURN){
goto fail_return;
}
memset(identifier_name,0x0,sizeof(identifier_name));
sprintf(identifier_name,KK_TSL_GATAWAY_WHITELISTSN_IDENTIFIER,idx);
res = kk_tsl_set_value(kk_tsl_set_event_output_value,0,identifier_name,NULL,wlist_dev->device_sn);
if(res != SUCCESS_RETURN){
goto fail_return;
}
memset(identifier_name,0x0,sizeof(identifier_name));
sprintf(identifier_name,KK_TSL_GATAWAY_WHITELISTDEVICEID_IDENTIFIER,idx);
res = kk_tsl_set_value(kk_tsl_set_event_output_value,0,identifier_name,NULL,wlist_dev->device_id);
if(res != SUCCESS_RETURN){
goto fail_return;
}
_kk_wlist_unlock();
return SUCCESS_RETURN;
fail_return:
_kk_wlist_unlock();
INFO_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
}
int kk_add_wlist(kk_wlist_dev_t *wlist_dev)
{
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
int res = 0;
if(ctx->isOpened != 1){
ERROR_PRINT("[%s][%d] PLEASE OPNE THE WHITELIST FUNCTION FIRST!!!\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
}
if(ctx->wlistNum >= 512){
ERROR_PRINT("[%s][%d] WHITELIST FULL!!!\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
}
if(wlist_dev == NULL){
ERROR_PRINT("[%s][%d] wlist_dev == NULL!!!\n",__FUNCTION__,__LINE__);
return INVALID_PARAMETER;
}
if(_kk_check_exist(wlist_dev->device_mac) == 1)
{
ERROR_PRINT("[%s][%d] DATA ALREADY EXIST!!!\n",__FUNCTION__,__LINE__);
return SUCCESS_RETURN;
}
res = kk_wlist_insert_db(ctx->wlistNum,wlist_dev->device_mac,wlist_dev->product_id,wlist_dev->device_sn,wlist_dev->device_id);
res |= kk_set_wlist_byIdx(ctx->wlistNum,wlist_dev);
ctx->wlistNum++;
return res;
}
int kk_get_wlist_num(void)
{
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
if(ctx->isOpened != 1)
{
ERROR_PRINT("[%s][%d] PLEASE OPNE THE WHITELIST FUNCTION FIRST!!!\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
}
return ctx->wlistNum;
}
int kk_getwlist_ByIdx(int idx,kk_wlist_dev_t* wlist_dev)
{
char macs[DEVICE_MAC_MAXLEN] = {0};
char PID[PRODUCT_CODE_MAXLEN] = {0};
char DID[DEVICE_CODE_MAXLEN] = {0};
char SN[PRODUCT_CODE_MAXLEN] = {0};
char identifier_name[64] = {0};
int res = 0;
_kk_wlist_lock();
sprintf(identifier_name,KK_TSL_GATAWAY_WHITELISTMAC_IDENTIFIER,idx);
res = kk_tsl_get_value(kk_tsl_get_event_output_value,0,identifier_name,macs,NULL);
if(res != SUCCESS_RETURN){
goto fail_return;
}
strcpy(wlist_dev->device_mac,macs);
memset(identifier_name,0x0,sizeof(identifier_name));
sprintf(identifier_name,KK_TSL_GATAWAY_WHITELISTPRODUCTID_IDENTIFIER,idx);
res = kk_tsl_get_value(kk_tsl_get_event_output_value,0,identifier_name,PID,NULL);
if(res != SUCCESS_RETURN){
goto fail_return;
}
strcpy(wlist_dev->product_id,PID);
memset(identifier_name,0x0,sizeof(identifier_name));
sprintf(identifier_name,KK_TSL_GATAWAY_WHITELISTSN_IDENTIFIER,idx);
res = kk_tsl_get_value(kk_tsl_get_event_output_value,0,identifier_name,SN,NULL);
if(res != SUCCESS_RETURN){
goto fail_return;
}
strcpy(wlist_dev->device_sn,SN);
memset(identifier_name,0x0,sizeof(identifier_name));
sprintf(identifier_name,KK_TSL_GATAWAY_WHITELISTDEVICEID_IDENTIFIER,idx);
res = kk_tsl_get_value(kk_tsl_get_event_output_value,0,identifier_name,DID,NULL);
if(res != SUCCESS_RETURN){
goto fail_return;
}
strcpy(wlist_dev->device_id,DID);
_kk_wlist_unlock();
return SUCCESS_RETURN;
fail_return:
_kk_wlist_unlock();
INFO_PRINT("[%s][%d] res:%d\n",__FUNCTION__,__LINE__,res);
return FAIL_RETURN;
}
int kk_get_wlistIdx_byMac(const char* device_mac)
{
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
int res = 0;
char pmac[DEVICE_MAC_MAXLEN] = {0};
char identifier_name[64] = {0};
int idx = 0,findIdx = 0;
if(ctx->isOpened != 1)
{
ERROR_PRINT("[%s][%d] PLEASE OPNE THE WHITELIST FUNCTION FIRST!!!\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
}
if(idx >= 512)
{
ERROR_PRINT("[%s][%d]Invalid idx!!!\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
}
_kk_wlist_lock();
for(idx = 0; idx < ctx->wlistNum;idx++)
{
memset(identifier_name,0x0,sizeof(identifier_name));
sprintf(identifier_name,KK_TSL_GATAWAY_WHITELISTMAC_IDENTIFIER,idx);
res = kk_tsl_get_value(kk_tsl_get_event_output_value,0,identifier_name,pmac,NULL);
if(res != SUCCESS_RETURN){
continue;
}
if(!strcmp(device_mac,pmac))
{
findIdx = idx;
ERROR_PRINT("[%s][%d]find the delete index\n",__FUNCTION__,__LINE__);
_kk_wlist_unlock();
return findIdx;
}
}
if(idx == ctx->wlistNum)
{
_kk_wlist_unlock();
return TSL_EVENT_NOT_EXIST;
}
_kk_wlist_unlock();
return FAIL_RETURN;
}
static int _kk_delete_wlist_byIdx(int idx)
{
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
int res = 0;
kk_wlist_dev_t dWlist = {0};
if(idx >= 512)
{
ERROR_PRINT("[%s][%d]Invalid idx!!!\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
}
strcpy(dWlist.product_id,"");
strcpy(dWlist.device_mac,"");
strcpy(dWlist.device_sn,"");
strcpy(dWlist.device_id,"");
res = kk_set_wlist_byIdx(idx,&dWlist);
return res;
}
int kk_delete_wlist_byMac(const char* device_mac)
{
kk_wlist_ctx_t *ctx = _kk_wlist_get_ctx();
char identifier_name[64] = {0};
int res;
int idx = 0;
char *pmac = NULL;
int findIdx = 0;
if(ctx->isOpened != 1)
{
ERROR_PRINT("[%s][%d] PLEASE OPNE THE WHITELIST FUNCTION FIRST!!!\n",__FUNCTION__,__LINE__);
return FAIL_RETURN;
}
findIdx = kk_get_wlistIdx_byMac(device_mac);
if(findIdx < 0)
{
return FAIL_RETURN;
}
res = _kk_delete_wlist_byIdx(findIdx);
res |= _kk_wlist_delete_db_byMac(device_mac);
if(res != SUCCESS_RETURN)
{
return FAIL_RETURN;
}
ctx->wlistNum--;
return SUCCESS_RETURN;
}
#ifndef __KK_WHITELIST_MNG_H__
#define __KK_WHITELIST_MNG_H__
#include "kk_tsl_common.h"
typedef struct {
char device_mac[DEVICE_MAC_MAXLEN];
char product_id[PRODUCT_TYPE_MAXLEN];
char device_sn[DEVICE_SN_MAXLEN];
char device_id[DEVICE_CODE_MAXLEN];
int index;
} kk_wlist_dev_t;
int kk_wlist_init(void);
int kk_wlist_status_open(int isOpen);
int kk_add_wlist(kk_wlist_dev_t *wlist_dev);
int kk_get_wlist_num(void);
int kk_delete_wlist_byMac(const char* device_mac);
#endif
\ No newline at end of file
......@@ -223,7 +223,9 @@ void kk_platMsg_handle(void* data, char* chalMark){
}else if (strstr(msgType->valuestring, KK_THING_PROPERTY_POST) != NULL){
INFO_PRINT("save property and send to cloud \n");
char* outstr = cJSON_Print(payload);
kk_tsl_property_set_by_devicecode(info_dcode->valuestring, outstr, strlen(outstr)+1);
kk_tsl_t *dev_shadow = NULL;
dm_mgr_get_device_shadow_by_devicecode(info_dcode->valuestring,&dev_shadow);
kk_tsl_property_set_by_shadow(dev_shadow, outstr, strlen(outstr)+1);
dm_msg_thing_property_post_by_identify(info_dcode->valuestring,jsonPay);
free(outstr);
......@@ -236,7 +238,6 @@ void kk_platMsg_handle(void* data, char* chalMark){
}else{
INFO_PRINT("kk_platMsg_handle data: don't handle it [%s]\n",data);
//kk_tsl_service_property_set(topic->valuestring, payload->valuestring, strlen(payload->valuestring), NULL);
}
error:
cJSON_Delete(json);
......@@ -580,6 +581,8 @@ void *ccu_property_monitor(void *args)
int res = 0;
int needReport = 0;
int time_second = 60;
dm_mgr_dev_node_t *node = NULL;
dm_mgr_search_dev_by_devid(KK_DM_DEVICE_CCU_DEVICEID,&node);
while (mid_ctx->g_ccuProChg_dispatch_thread_running) {
if(kk_get_cloud_recv_status() == 0){
......@@ -587,15 +590,15 @@ void *ccu_property_monitor(void *args)
sleep(10);
continue;
}
//dm_ota_yield(MID_YIELD_TIMEOUT_MS);
HAL_Get_IP(s_IP,NULL);
res = kk_tsl_get_value(kk_tsl_get_property_value,0,KK_TSL_CCU_WANIP_IDENTIFIER,s_IP_TSL,NULL);
res = kk_tsl_get_value(kk_tsl_get_property_value,node->dev_shadow,KK_TSL_CCU_WANIP_IDENTIFIER,s_IP_TSL,NULL);
if(res != SUCCESS_RETURN){
ERROR_PRINT("kk_tsl_get_value Failed\n");
}
else{
if(strcmp(s_IP,s_IP_TSL)){
kk_tsl_set_value(kk_tsl_set_property_value,0,KK_TSL_CCU_WANIP_IDENTIFIER,NULL,s_IP);
kk_tsl_set_value(kk_tsl_set_property_value,node->dev_shadow,KK_TSL_CCU_WANIP_IDENTIFIER,NULL,s_IP);
INFO_PRINT("current ip:%s,before ip:%s\n",s_IP,s_IP_TSL);
kk_property_db_update("CCU_66666");
needReport = 1;
......@@ -604,7 +607,12 @@ void *ccu_property_monitor(void *args)
if(needReport&&(kk_get_cloudstatus() == 1)){
needReport = 0;
kk_tsl_post_property(KK_DM_DEVICE_CCU_DEVICEID,NULL,0);
char *postStr = kk_tsl_get_post_property_str(node->dev_shadow,NULL);
if(postStr != NULL){
dm_mgr_upstream_thing_property_post(node->devid, postStr, strlen(postStr),0);
free(postStr);
postStr = NULL;
}
}
sleep(time_second);
}
......
......@@ -5,32 +5,37 @@
#include "kk_dm_msg.h"
#include "kk_log.h"
#ifndef _ZLOG_
#undef INFO_PRINT
#undef WARNING_PRINT
#undef ERROR_PRINT
#define INFO_PRINT printf
#define WARNING_PRINT printf
#define ERROR_PRINT printf
#else
#include "kk_log.h"
#endif
typedef enum {
KK_MSG_PROPERTY_SET,
KK_MSG_SERVICE_SET
} kk_msg_set_type_t;
typedef int (*dm_get_shadow_data)(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _OU_ void **data);
typedef int (*dm_set_shadow_data)(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
typedef int (*dm_get_shadow_data)(_IN_ kk_tsl_t * dev_shadow, _IN_ char *key, _IN_ int key_len, _OU_ void **data);
typedef int (*dm_set_shadow_data)(_IN_ kk_tsl_t * dev_shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
_IN_ int value_len);
static int _kk_msg_set_object(kk_msg_set_type_t type, int devid, char *key, lite_cjson_t *root);
static int _kk_msg_get_property_data(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _OU_ void **data)
static int _kk_msg_set_object(kk_msg_set_type_t type, kk_tsl_t *dev_shadow, char *key, lite_cjson_t *root);
static int _kk_msg_get_property_data(_IN_ kk_tsl_t * dev_shadow, _IN_ char *key, _IN_ int key_len, _OU_ void **data)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = kk_tsl_get_property_data(node->dev_shadow, key, key_len, data);
res = kk_tsl_get_property_data(dev_shadow, key, key_len, data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -38,21 +43,15 @@ static int _kk_msg_get_property_data(_IN_ int devid, _IN_ char *key, _IN_ int ke
return SUCCESS_RETURN;
}
#if 1
int kk_msg_get_event_output_data(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _OU_ void **data)
int kk_msg_get_event_output_data(_IN_ kk_tsl_t * dev_shadow, _IN_ char *key, _IN_ int key_len, _OU_ void **data)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_tsl_get_event_output_data(node->dev_shadow, key, key_len, data);
res = dm_tsl_get_event_output_data(dev_shadow, key, key_len, data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -60,66 +59,34 @@ int kk_msg_get_event_output_data(_IN_ int devid, _IN_ char *key, _IN_ int key_le
return SUCCESS_RETURN;
}
int kk_msg_set_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
_IN_ int value_len)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0 || value == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_tls_set_event_output_value(node->dev_shadow, key, key_len, value, value_len);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
return SUCCESS_RETURN;
}
#endif
static int _kk_msg_get_service_input_data(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _OU_ void **data)
static int _kk_msg_get_service_input_data(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len, _OU_ void **data)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_tsl_get_service_input_output_data(KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA, node->dev_shadow, key, key_len, data);
res = dm_tsl_get_service_input_output_data(KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA,dev_shadow, key, key_len, data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
return SUCCESS_RETURN;
}
static int _kk_msg_get_service_output_data(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _OU_ void **data)
static int _kk_msg_get_service_output_data(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len, _OU_ void **data)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_tsl_get_service_input_output_data(KK_TSL_DATA_TARGET_SERVICE_OUTPUT_DATA, node->dev_shadow, key, key_len,
res = dm_tsl_get_service_input_output_data(KK_TSL_DATA_TARGET_SERVICE_OUTPUT_DATA,dev_shadow, key, key_len,
data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
......@@ -128,21 +95,16 @@ static int _kk_msg_get_service_output_data(_IN_ int devid, _IN_ char *key, _IN_
return SUCCESS_RETURN;
}
static int _kk_msg_set_service_input_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
static int _kk_msg_set_service_input_value(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
_IN_ int value_len)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0 || value == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_tsl_set_service_input_output_value(KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA, node->dev_shadow, key, key_len,
res = dm_tsl_set_service_input_output_value(KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA, dev_shadow, key, key_len,
value, value_len);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
......@@ -150,22 +112,16 @@ static int _kk_msg_set_service_input_value(_IN_ int devid, _IN_ char *key, _IN_
return SUCCESS_RETURN;
}
static int _kk_msg_set_service_output_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
static int _kk_msg_set_service_output_value(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
_IN_ int value_len)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0 || value == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_tsl_set_service_input_output_value(KK_TSL_DATA_TARGET_SERVICE_OUTPUT_DATA, node->dev_shadow, key, key_len,
res = dm_tsl_set_service_input_output_value(KK_TSL_DATA_TARGET_SERVICE_OUTPUT_DATA, dev_shadow, key, key_len,
value, value_len);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
......@@ -176,22 +132,16 @@ static int _kk_msg_set_service_output_value(_IN_ int devid, _IN_ char *key, _IN_
static int _kk_msg_set_property_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
static int _kk_msg_set_property_value(_IN_ kk_tsl_t *dev_shadow , _IN_ char *key, _IN_ int key_len, _IN_ void *value,
_IN_ int value_len)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0 || value == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = dm_tsl_set_property_value(node->dev_shadow, key, key_len, value, value_len);
res = dm_tsl_set_property_value(dev_shadow, key, key_len, value, value_len);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -199,18 +149,18 @@ static int _kk_msg_set_property_value(_IN_ int devid, _IN_ char *key, _IN_ int k
return SUCCESS_RETURN;
}
int _kk_tsl_set_property_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
int _kk_tsl_set_property_value(_IN_ kk_tsl_t * dev_shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
_IN_ char *value_str)
{
int res = 0;
void *data = NULL;
kk_tsl_data_type_e type;
if (devid < 0 || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
if (dev_shadow == NULL|| key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
return INVALID_PARAMETER;
}
res = _kk_msg_get_property_data(devid, key, key_len, &data);
res = _kk_msg_get_property_data(dev_shadow, key, key_len, &data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -225,23 +175,23 @@ int _kk_tsl_set_property_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len,
case KK_TSL_DATA_TYPE_ENUM:
case KK_TSL_DATA_TYPE_BOOL: {
int value_int = (value == NULL) ? (atoi(value_str)) : (*(int *)value);
res = _kk_msg_set_property_value(devid, key, key_len, &value_int, sizeof(int));
res = _kk_msg_set_property_value(dev_shadow, key, key_len, &value_int, sizeof(int));
}
break;
case KK_TSL_DATA_TYPE_FLOAT: {
float value_float = (value == NULL) ? (atof(value_str)) : (*(float *)value);
res = _kk_msg_set_property_value(devid, key, key_len, &value_float, sizeof(float));
res = _kk_msg_set_property_value(dev_shadow, key, key_len, &value_float, sizeof(float));
}
break;
case KK_TSL_DATA_TYPE_DOUBLE: {
double value_double = (value == NULL) ? (atof(value_str)) : (*(double *)value);
res = _kk_msg_set_property_value(devid, key, key_len, &value_double, sizeof(double));
res = _kk_msg_set_property_value(dev_shadow, key, key_len, &value_double, sizeof(double));
}
break;
case KK_TSL_DATA_TYPE_TEXT:
case KK_TSL_DATA_TYPE_DATE: {
char *value_string = (value == NULL) ? (value_str) : (value);
res = _kk_msg_set_property_value(devid, key, key_len, value_string, strlen(value_string));
res = _kk_msg_set_property_value(dev_shadow, key, key_len, value_string, strlen(value_string));
}
break;
default: {
......@@ -256,7 +206,7 @@ int _kk_tsl_set_property_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len,
return SUCCESS_RETURN;
}
static int _kk_msg_set_numberOrStr(kk_msg_set_type_t type, int devid, char *key, lite_cjson_t *root)
static int _kk_msg_set_numberOrStr(kk_msg_set_type_t type, kk_tsl_t *dev_shadow, char *key, lite_cjson_t *root)
{
int res = 0;
void *data = NULL;
......@@ -268,7 +218,7 @@ static int _kk_msg_set_numberOrStr(kk_msg_set_type_t type, int devid, char *key,
/* dm_log_debug("Current Key: %s", key); */
res = get_shadow_data_func(devid, key, strlen(key), &data);
res = get_shadow_data_func(dev_shadow, key, strlen(key), &data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -286,21 +236,21 @@ static int _kk_msg_set_numberOrStr(kk_msg_set_type_t type, int devid, char *key,
if (root->type == cJSON_String && root->value_length > 0){
root->value_int = atoi(root->value);
}
res = set_shadow_data_func(devid, key, strlen(key), &root->value_int, 0);
res = set_shadow_data_func(dev_shadow, key, strlen(key), &root->value_int, 0);
}
break;
case KK_TSL_DATA_TYPE_FLOAT: {
float value_float = (float)root->value_double;
res = set_shadow_data_func(devid, key, strlen(key), &value_float, 0);
res = set_shadow_data_func(dev_shadow, key, strlen(key), &value_float, 0);
}
break;
case KK_TSL_DATA_TYPE_DOUBLE: {
res = set_shadow_data_func(devid, key, strlen(key), &root->value_double, 0);
res = set_shadow_data_func(dev_shadow, key, strlen(key), &root->value_double, 0);
}
break;
case KK_TSL_DATA_TYPE_TEXT:
case KK_TSL_DATA_TYPE_DATE: {
res = set_shadow_data_func(devid, key, strlen(key), root->value, root->value_length);
res = set_shadow_data_func(dev_shadow, key, strlen(key), root->value, root->value_length);
}
break;
default:
......@@ -311,7 +261,7 @@ static int _kk_msg_set_numberOrStr(kk_msg_set_type_t type, int devid, char *key,
return res;
}
static int _kk_msg_set_array(kk_msg_set_type_t type, int devid, char *key, lite_cjson_t *root)
static int _kk_msg_set_array(kk_msg_set_type_t type, kk_tsl_t *dev_shadow, char *key, lite_cjson_t *root)
{
int res = 0, index = 0;
lite_cjson_t lite_item_value;
......@@ -351,16 +301,16 @@ static int _kk_msg_set_array(kk_msg_set_type_t type, int devid, char *key, lite_
free(ascii_index);
if (lite_cjson_is_object(&lite_item_value)) {
res = _kk_msg_set_object(type, devid, new_key, &lite_item_value);
res = _kk_msg_set_object(type, dev_shadow, new_key, &lite_item_value);
}
if (lite_cjson_is_array(&lite_item_value)) {
res = _kk_msg_set_array(type, devid, new_key, &lite_item_value);
res = _kk_msg_set_array(type, dev_shadow, new_key, &lite_item_value);
}
if (lite_cjson_is_number(&lite_item_value)) {
res = _kk_msg_set_numberOrStr(type, devid, new_key, &lite_item_value);
res = _kk_msg_set_numberOrStr(type, dev_shadow, new_key, &lite_item_value);
}
if (lite_cjson_is_string(&lite_item_value)) {
res = _kk_msg_set_numberOrStr(type, devid, new_key, &lite_item_value);
res = _kk_msg_set_numberOrStr(type, dev_shadow, new_key, &lite_item_value);
}
free(new_key);
......@@ -372,7 +322,7 @@ static int _kk_msg_set_array(kk_msg_set_type_t type, int devid, char *key, lite_
return SUCCESS_RETURN;
}
static int _kk_msg_set_object(kk_msg_set_type_t type, int devid, char *key, lite_cjson_t *root)
static int _kk_msg_set_object(kk_msg_set_type_t type, kk_tsl_t *dev_shadow, char *key, lite_cjson_t *root)
{
int res = 0, index = 0;
lite_cjson_t lite_item_key;
......@@ -405,16 +355,16 @@ static int _kk_msg_set_object(kk_msg_set_type_t type, int devid, char *key, lite
/* dm_log_debug("New Key: %s", new_key); */
if (lite_cjson_is_object(&lite_item_value)) {
res = _kk_msg_set_object(type, devid, new_key, &lite_item_value);
res = _kk_msg_set_object(type, dev_shadow, new_key, &lite_item_value);
}
if (lite_cjson_is_array(&lite_item_value)) {
res = _kk_msg_set_array(type, devid, new_key, &lite_item_value);
res = _kk_msg_set_array(type, dev_shadow, new_key, &lite_item_value);
}
if (lite_cjson_is_number(&lite_item_value)) {
res = _kk_msg_set_numberOrStr(type, devid, new_key, &lite_item_value);
res = _kk_msg_set_numberOrStr(type, dev_shadow, new_key, &lite_item_value);
}
if (lite_cjson_is_string(&lite_item_value)) {
res = _kk_msg_set_numberOrStr(type, devid, new_key, &lite_item_value);
res = _kk_msg_set_numberOrStr(type, dev_shadow, new_key, &lite_item_value);
}
free(new_key);
......@@ -425,7 +375,7 @@ static int _kk_msg_set_object(kk_msg_set_type_t type, int devid, char *key, lite
return SUCCESS_RETURN;
}
int _kk_msg_property_set(int devid, kk_msg_request_payload_t *request)
int _kk_msg_property_set(kk_tsl_t *dev_shadow, kk_msg_request_payload_t *request)
{
int res = 0, message_len = 0;
char *message = NULL;
......@@ -444,28 +394,12 @@ int _kk_msg_property_set(int devid, kk_msg_request_payload_t *request)
/* dm_log_info("Property Set, Size: %d", lite.size); */
if (lite_cjson_is_object(&lite)) {
res = _kk_msg_set_object(KK_MSG_PROPERTY_SET, devid, NULL, &lite);
res = _kk_msg_set_object(KK_MSG_PROPERTY_SET, dev_shadow, NULL, &lite);
}
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
#if 0
message_len = strlen(DM_MSG_PROPERTY_SET_FMT) + DM_UTILS_UINT32_STRLEN + request->params.value_length + 1;
message = DM_malloc(message_len);
if (message == NULL) {
return DM_MEMORY_NOT_ENOUGH;
}
memset(message, 0, message_len);
HAL_Snprintf(message, message_len, DM_MSG_PROPERTY_SET_FMT, devid, request->params.value_length, request->params.value);
res = _dm_msg_send_to_user(IOTX_DM_EVENT_PROPERTY_SET, message);
if (res != SUCCESS_RETURN) {
DM_free(message);
}
#endif
return SUCCESS_RETURN;
}
......@@ -496,24 +430,19 @@ static int _kk_msg_request_parse(_IN_ char *payload, _IN_ int payload_len, _OU_
return SUCCESS_RETURN;
}
static int _kk_set_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
static int _kk_set_event_output_value(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
_IN_ char *value_str)
{
int res = 0;
void *data = NULL;
kk_tsl_data_type_e type;
dm_mgr_dev_node_t *node = NULL;
if (devid < 0 || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
if (dev_shadow == NULL || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
return INVALID_PARAMETER;
}
res = dm_tsl_get_event_output_data(node->dev_shadow, key, key_len, &data);
res = dm_tsl_get_event_output_data(dev_shadow, key, key_len, &data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -528,23 +457,23 @@ static int _kk_set_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ int k
case KK_TSL_DATA_TYPE_ENUM:
case KK_TSL_DATA_TYPE_BOOL: {
int value_int = (value == NULL) ? (atoi(value_str)) : (*(int *)value);
res = dm_tls_set_event_output_value(node->dev_shadow, key, key_len, &value_int, sizeof(int));
res = dm_tls_set_event_output_value(dev_shadow, key, key_len, &value_int, sizeof(int));
}
break;
case KK_TSL_DATA_TYPE_FLOAT: {
float value_float = (value == NULL) ? (atof(value_str)) : (*(float *)value);
res = dm_tls_set_event_output_value(node->dev_shadow, key, key_len, &value_float, sizeof(float));
res = dm_tls_set_event_output_value(dev_shadow, key, key_len, &value_float, sizeof(float));
}
break;
case KK_TSL_DATA_TYPE_DOUBLE: {
double value_double = (value == NULL) ? (atof(value_str)) : (*(double *)value);
res = dm_tls_set_event_output_value(node->dev_shadow, key, key_len, &value_double, sizeof(double));
res = dm_tls_set_event_output_value(dev_shadow, key, key_len, &value_double, sizeof(double));
}
break;
case KK_TSL_DATA_TYPE_TEXT:
case KK_TSL_DATA_TYPE_DATE: {
char *value_string = (value == NULL) ? (value_str) : (value);
res = dm_tls_set_event_output_value(node->dev_shadow, key, key_len, value_string, strlen(value_string));
res = dm_tls_set_event_output_value(dev_shadow, key, key_len, value_string, strlen(value_string));
}
break;
default: {
......@@ -559,7 +488,7 @@ static int _kk_set_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ int k
return SUCCESS_RETURN;
}
static int _kk_set_service_output_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len,
static int _kk_set_service_output_value(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len,
_IN_ void *value,
_IN_ char *value_str)
{
......@@ -567,11 +496,11 @@ static int _kk_set_service_output_value(_IN_ int devid, _IN_ char *key, _IN_ int
void *data = NULL;
kk_tsl_data_type_e type;
if (devid < 0 || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
if (dev_shadow == 0 || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
return INVALID_PARAMETER;
}
res = _kk_msg_get_service_output_data(devid, key, key_len, &data);
res = _kk_msg_get_service_output_data(dev_shadow, key, key_len, &data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -586,23 +515,23 @@ static int _kk_set_service_output_value(_IN_ int devid, _IN_ char *key, _IN_ int
case KK_TSL_DATA_TYPE_ENUM:
case KK_TSL_DATA_TYPE_BOOL: {
int value_int = (value == NULL) ? (atoi(value_str)) : (*(int *)value);
res = _kk_msg_set_service_output_value(devid, key, key_len, &value_int, sizeof(int));
res = _kk_msg_set_service_output_value(dev_shadow, key, key_len, &value_int, sizeof(int));
}
break;
case KK_TSL_DATA_TYPE_FLOAT: {
float value_float = (value == NULL) ? (atof(value_str)) : (*(float *)value);
res = _kk_msg_set_service_output_value(devid, key, key_len, &value_float, sizeof(float));
res = _kk_msg_set_service_output_value(dev_shadow, key, key_len, &value_float, sizeof(float));
}
break;
case KK_TSL_DATA_TYPE_DOUBLE: {
double value_double = (value == NULL) ? (atof(value_str)) : (*(double *)value);
res = _kk_msg_set_service_output_value(devid, key, key_len, &value_double, sizeof(double));
res = _kk_msg_set_service_output_value(dev_shadow, key, key_len, &value_double, sizeof(double));
}
break;
case KK_TSL_DATA_TYPE_TEXT:
case KK_TSL_DATA_TYPE_DATE: {
char *value_string = (value == NULL) ? (value_str) : (value);
res = _kk_msg_set_service_output_value(devid, key, key_len, value_string, strlen(value_string));
res = _kk_msg_set_service_output_value(dev_shadow, key, key_len, value_string, strlen(value_string));
}
break;
default: {
......@@ -659,40 +588,18 @@ int kk_tsl_api_init(void)
return SUCCESS_RETURN;
}
static int _kk_tsl_get_property_value_byId(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0 || value == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = kk_tsl_get_property_value_ex(node->dev_shadow, key, key_len, value);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
return SUCCESS_RETURN;
}
static int _kk_tsl_get_property_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
static int _kk_tsl_get_property_value(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
_IN_ char **value_str)
{
int res = 0;
void *data = NULL;
kk_tsl_data_type_e type;
if (devid < 0 || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
if (dev_shadow == NULL || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
return INVALID_PARAMETER;
}
res = _kk_msg_get_property_data(devid, key, key_len, &data);
res = _kk_msg_get_property_data(dev_shadow, key, key_len, &data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -707,7 +614,7 @@ static int _kk_tsl_get_property_value(_IN_ int devid, _IN_ char *key, _IN_ int k
case KK_TSL_DATA_TYPE_ENUM:
case KK_TSL_DATA_TYPE_BOOL: {
int value_int = 0;
res = _kk_tsl_get_property_value_byId(devid, key, key_len, (void *)&value_int);
res = kk_tsl_get_property_value_ex(dev_shadow, key, key_len, (void *)&value_int);
if (res == SUCCESS_RETURN) {
if (value) {
*(int *)value = value_int;
......@@ -720,7 +627,7 @@ static int _kk_tsl_get_property_value(_IN_ int devid, _IN_ char *key, _IN_ int k
break;
case KK_TSL_DATA_TYPE_FLOAT: {
float value_float = 0;
res = _kk_tsl_get_property_value_byId(devid, key, key_len, (void *)&value_float);
res = kk_tsl_get_property_value_ex(dev_shadow, key, key_len, (void *)&value_float);
if (res == SUCCESS_RETURN) {
if (value) {
*(float *)value = value_float;
......@@ -733,7 +640,7 @@ static int _kk_tsl_get_property_value(_IN_ int devid, _IN_ char *key, _IN_ int k
break;
case KK_TSL_DATA_TYPE_DOUBLE: {
double value_double = 0;
res = _kk_tsl_get_property_value_byId(devid, key, key_len, (void *)&value_double);
res = kk_tsl_get_property_value_ex(dev_shadow, key, key_len, (void *)&value_double);
if (res == SUCCESS_RETURN) {
if (value) {
*(double *)value = value_double;
......@@ -747,7 +654,7 @@ static int _kk_tsl_get_property_value(_IN_ int devid, _IN_ char *key, _IN_ int k
case KK_TSL_DATA_TYPE_TEXT:
case KK_TSL_DATA_TYPE_DATE: {
char *value_string = NULL;
res = _kk_tsl_get_property_value_byId(devid, key, key_len, (void *)&value_string);
res = kk_tsl_get_property_value_ex(dev_shadow, key, key_len, (void *)&value_string);
if (res == SUCCESS_RETURN) {
if (value) {
memcpy(value, value_string, strlen(value_string));
......@@ -775,39 +682,18 @@ static int _kk_tsl_get_property_value(_IN_ int devid, _IN_ char *key, _IN_ int k
return SUCCESS_RETURN;
}
static int _kk_tsl_get_event_output_value_byId(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0 || value == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = kk_tsl_get_event_oput_value(node->dev_shadow, key, key_len, value);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
return SUCCESS_RETURN;
}
static int _kk_tsl_get_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
static int _kk_tsl_get_event_output_value(_IN_ kk_tsl_t * dev_shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
_IN_ char **value_str)
{
int res = 0;
void *data = NULL;
kk_tsl_data_type_e type;
if (devid < 0 || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
if (dev_shadow == NULL || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
return INVALID_PARAMETER;
}
res = kk_msg_get_event_output_data(devid, key, key_len, &data);
res = kk_msg_get_event_output_data(dev_shadow, key, key_len, &data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -822,7 +708,7 @@ static int _kk_tsl_get_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ i
case KK_TSL_DATA_TYPE_ENUM:
case KK_TSL_DATA_TYPE_BOOL: {
int value_int = 0;
res = _kk_tsl_get_event_output_value_byId(devid, key, key_len, (void *)&value_int);
res = kk_tsl_get_event_oput_value(dev_shadow, key, key_len, (void *)&value_int);
if (res == SUCCESS_RETURN) {
if (value) {
*(int *)value = value_int;
......@@ -835,7 +721,7 @@ static int _kk_tsl_get_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ i
break;
case KK_TSL_DATA_TYPE_FLOAT: {
float value_float = 0;
res = _kk_tsl_get_event_output_value_byId(devid, key, key_len, (void *)&value_float);
res = kk_tsl_get_event_oput_value(dev_shadow, key, key_len, (void *)&value_float);
if (res == SUCCESS_RETURN) {
if (value) {
*(float *)value = value_float;
......@@ -848,7 +734,7 @@ static int _kk_tsl_get_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ i
break;
case KK_TSL_DATA_TYPE_DOUBLE: {
double value_double = 0;
res = _kk_tsl_get_event_output_value_byId(devid, key, key_len, (void *)&value_double);
res = kk_tsl_get_event_oput_value(dev_shadow, key, key_len, (void *)&value_double);
if (res == SUCCESS_RETURN) {
if (value) {
*(double *)value = value_double;
......@@ -862,7 +748,7 @@ static int _kk_tsl_get_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ i
case KK_TSL_DATA_TYPE_TEXT:
case KK_TSL_DATA_TYPE_DATE: {
char *value_string = NULL;
res = _kk_tsl_get_event_output_value_byId(devid, key, key_len, (void *)&value_string);
res = kk_tsl_get_event_oput_value(dev_shadow, key, key_len, (void *)&value_string);
if (res == SUCCESS_RETURN) {
if (value) {
memcpy(value, value_string, strlen(value_string));
......@@ -887,21 +773,15 @@ static int _kk_tsl_get_event_output_value(_IN_ int devid, _IN_ char *key, _IN_ i
return SUCCESS_RETURN;
}
static int _kk_tsl_get_service_input_value_byId(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value)
static int _kk_tsl_get_service_input_value_byId(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (key == NULL || key_len <= 0 || value == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = kk_tsl_get_service_input_output_value(KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA, node->dev_shadow, key, key_len,
res = kk_tsl_get_service_input_output_value(KK_TSL_DATA_TARGET_SERVICE_INPUT_DATA, dev_shadow, key, key_len,
value);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
......@@ -909,7 +789,7 @@ static int _kk_tsl_get_service_input_value_byId(_IN_ int devid, _IN_ char *key,
return SUCCESS_RETURN;
}
static int _kk_tsl_get_service_input_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len,
static int _kk_tsl_get_service_input_value(_IN_ kk_tsl_t * dev_shadow, _IN_ char *key, _IN_ int key_len,
_IN_ void *value,
_IN_ char **value_str)
{
......@@ -917,11 +797,11 @@ static int _kk_tsl_get_service_input_value(_IN_ int devid, _IN_ char *key, _IN_
void *data = NULL;
kk_tsl_data_type_e type;
if (devid < 0 || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
if (dev_shadow == NULL || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
return INVALID_PARAMETER;
}
res = _kk_msg_get_service_input_data(devid, key, key_len, &data);
res = _kk_msg_get_service_input_data(dev_shadow, key, key_len, &data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -936,7 +816,7 @@ static int _kk_tsl_get_service_input_value(_IN_ int devid, _IN_ char *key, _IN_
case KK_TSL_DATA_TYPE_ENUM:
case KK_TSL_DATA_TYPE_BOOL: {
int value_int = 0;
res = _kk_tsl_get_service_input_value_byId(devid, key, key_len, (void *)&value_int);
res = _kk_tsl_get_service_input_value_byId(dev_shadow, key, key_len, (void *)&value_int);
if (res == SUCCESS_RETURN) {
if (value) {
*(int *)value = value_int;
......@@ -949,7 +829,7 @@ static int _kk_tsl_get_service_input_value(_IN_ int devid, _IN_ char *key, _IN_
break;
case KK_TSL_DATA_TYPE_FLOAT: {
float value_float = 0;
res = _kk_tsl_get_service_input_value_byId(devid, key, key_len, (void *)&value_float);
res = _kk_tsl_get_service_input_value_byId(dev_shadow, key, key_len, (void *)&value_float);
if (res == SUCCESS_RETURN) {
if (value) {
*(float *)value = value_float;
......@@ -962,7 +842,7 @@ static int _kk_tsl_get_service_input_value(_IN_ int devid, _IN_ char *key, _IN_
break;
case KK_TSL_DATA_TYPE_DOUBLE: {
double value_double = 0;
res = _kk_tsl_get_service_input_value_byId(devid, key, key_len, (void *)&value_double);
res = _kk_tsl_get_service_input_value_byId(dev_shadow, key, key_len, (void *)&value_double);
if (res == SUCCESS_RETURN) {
if (value) {
*(double *)value = value_double;
......@@ -976,7 +856,7 @@ static int _kk_tsl_get_service_input_value(_IN_ int devid, _IN_ char *key, _IN_
case KK_TSL_DATA_TYPE_TEXT:
case KK_TSL_DATA_TYPE_DATE: {
char *value_string = NULL;
res = _kk_tsl_get_service_input_value_byId(devid, key, key_len, (void *)&value_string);
res = _kk_tsl_get_service_input_value_byId(dev_shadow, key, key_len, (void *)&value_string);
if (res == SUCCESS_RETURN) {
if (value) {
memcpy(value, value_string, strlen(value_string));
......@@ -1000,21 +880,15 @@ static int _kk_tsl_get_service_input_value(_IN_ int devid, _IN_ char *key, _IN_
}
return SUCCESS_RETURN;
}
static int _kk_tsl_get_service_output_value_byId(_IN_ int devid, _IN_ char *key, _IN_ int key_len, _IN_ void *value)
static int _kk_tsl_get_service_output_value_byId(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (devid < 0 || key == NULL || key_len <= 0 || value == NULL) {
if (dev_shadow == NULL || key == NULL || key_len <= 0 || value == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = kk_tsl_get_service_input_output_value(KK_TSL_DATA_TARGET_SERVICE_OUTPUT_DATA, node->dev_shadow, key, key_len,
res = kk_tsl_get_service_input_output_value(KK_TSL_DATA_TARGET_SERVICE_OUTPUT_DATA, dev_shadow, key, key_len,
value);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
......@@ -1022,7 +896,7 @@ static int _kk_tsl_get_service_output_value_byId(_IN_ int devid, _IN_ char *key,
return SUCCESS_RETURN;
}
static int _kk_tsl_get_service_output_value(_IN_ int devid, _IN_ char *key, _IN_ int key_len,
static int _kk_tsl_get_service_output_value(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key, _IN_ int key_len,
_IN_ void *value,
_IN_ char **value_str)
{
......@@ -1030,11 +904,11 @@ static int _kk_tsl_get_service_output_value(_IN_ int devid, _IN_ char *key, _IN_
void *data = NULL;
kk_tsl_data_type_e type;
if (devid < 0 || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
if (dev_shadow == NULL || key == NULL || key_len <= 0 || ((value == NULL) && (value_str == NULL))) {
return INVALID_PARAMETER;
}
res = _kk_msg_get_service_output_data(devid, key, key_len, &data);
res = _kk_msg_get_service_output_data(dev_shadow, key, key_len, &data);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1049,7 +923,7 @@ static int _kk_tsl_get_service_output_value(_IN_ int devid, _IN_ char *key, _IN_
case KK_TSL_DATA_TYPE_ENUM:
case KK_TSL_DATA_TYPE_BOOL: {
int value_int = 0;
res = _kk_tsl_get_service_output_value_byId(devid, key, key_len, (void *)&value_int);
res = _kk_tsl_get_service_output_value_byId(dev_shadow, key, key_len, (void *)&value_int);
if (res == SUCCESS_RETURN) {
if (value) {
*(int *)value = value_int;
......@@ -1062,7 +936,7 @@ static int _kk_tsl_get_service_output_value(_IN_ int devid, _IN_ char *key, _IN_
break;
case KK_TSL_DATA_TYPE_FLOAT: {
float value_float = 0;
res = _kk_tsl_get_service_output_value_byId(devid, key, key_len, (void *)&value_float);
res = _kk_tsl_get_service_output_value_byId(dev_shadow, key, key_len, (void *)&value_float);
if (res == SUCCESS_RETURN) {
if (value) {
*(float *)value = value_float;
......@@ -1075,7 +949,7 @@ static int _kk_tsl_get_service_output_value(_IN_ int devid, _IN_ char *key, _IN_
break;
case KK_TSL_DATA_TYPE_DOUBLE: {
double value_double = 0;
res = _kk_tsl_get_service_output_value_byId(devid, key, key_len, (void *)&value_double);
res = _kk_tsl_get_service_output_value_byId(dev_shadow, key, key_len, (void *)&value_double);
if (res == SUCCESS_RETURN) {
if (value) {
*(double *)value = value_double;
......@@ -1089,7 +963,7 @@ static int _kk_tsl_get_service_output_value(_IN_ int devid, _IN_ char *key, _IN_
case KK_TSL_DATA_TYPE_TEXT:
case KK_TSL_DATA_TYPE_DATE: {
char *value_string = NULL;
res = _kk_tsl_get_service_output_value_byId(devid, key, key_len, (void *)&value_string);
res = _kk_tsl_get_service_output_value_byId(dev_shadow, key, key_len, (void *)&value_string);
if (res == SUCCESS_RETURN) {
if (value) {
memcpy(value, value_string, strlen(value_string));
......@@ -1114,7 +988,7 @@ static int _kk_tsl_get_service_output_value(_IN_ int devid, _IN_ char *key, _IN_
return SUCCESS_RETURN;
}
int kk_tsl_get_value(kk_tsl_get_t method_get, int devId, const char *identifier,
int kk_tsl_get_value(kk_tsl_get_t method_get, kk_tsl_t * dev_shadow, const char *identifier,
void *value,
char **value_str)
{
......@@ -1130,20 +1004,20 @@ int kk_tsl_get_value(kk_tsl_get_t method_get, int devId, const char *identifier,
switch (method_get) {
case kk_tsl_get_property_value: {
res = _kk_tsl_get_property_value(devId, (char *)identifier, strlen(identifier), value, value_str);
res = _kk_tsl_get_property_value(dev_shadow, (char *)identifier, strlen(identifier), value, value_str);
}
break;
case kk_tsl_get_event_output_value: {
res = _kk_tsl_get_event_output_value(devId, (char *)identifier, strlen(identifier), value, value_str);
res = _kk_tsl_get_event_output_value(dev_shadow, (char *)identifier, strlen(identifier), value, value_str);
}
break;
case kk_tsl_get_service_input_value: {
res = _kk_tsl_get_service_input_value(devId, (char *)identifier, strlen(identifier), value,
res = _kk_tsl_get_service_input_value(dev_shadow, (char *)identifier, strlen(identifier), value,
value_str);
}
break;
case kk_tsl_get_service_output_value: {
res = _kk_tsl_get_service_output_value(devId, (char *)identifier, strlen(identifier), value,
res = _kk_tsl_get_service_output_value(dev_shadow, (char *)identifier, strlen(identifier), value,
value_str);
}
break;
......@@ -1164,7 +1038,7 @@ int kk_tsl_get_value(kk_tsl_get_t method_get, int devId, const char *identifier,
return SUCCESS_RETURN;
}
int kk_tsl_set_value(kk_tsl_set_t set, int devId, const char *identifier,
int kk_tsl_set_value(kk_tsl_set_t set, kk_tsl_t * dev_shadow, const char *identifier,
const void *value,
const char *value_str)
{
......@@ -1179,17 +1053,17 @@ int kk_tsl_set_value(kk_tsl_set_t set, int devId, const char *identifier,
_kk_tsl_api_lock();
switch (set) {
case kk_tsl_set_property_value: {
res = _kk_tsl_set_property_value(devId, (char *)identifier, strlen(identifier), (void *)value,
res = _kk_tsl_set_property_value(dev_shadow, (char *)identifier, strlen(identifier), (void *)value,
(char*)value_str);
}
break;
case kk_tsl_set_event_output_value: {
res = _kk_set_event_output_value(devId, (char *)identifier, strlen(identifier), (void *)value,
res = _kk_set_event_output_value(dev_shadow, (char *)identifier, strlen(identifier), (void *)value,
(char *)value_str);
}
break;
case kk_tsl_set_service_output_value: {
res = _kk_set_service_output_value(devId, (char *)identifier, strlen(identifier), (void *)value,
res = _kk_set_service_output_value(dev_shadow, (char *)identifier, strlen(identifier), (void *)value,
(char *)value_str);
}
break;
......@@ -1243,47 +1117,24 @@ int kk_msg_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli,
return SUCCESS_RETURN;
}
int kk_tsl_property_set_by_devicecode(const char deviceCode[DEVICE_CODE_MAXLEN], const char *payload, unsigned int payload_len)
int kk_tsl_property_set_by_shadow(kk_tsl_t * dev_shadow, const char *payload, unsigned int payload_len)
{
kk_msg_request_payload_t request;
int res = 0, devid = 0;
memset(&request, 0, sizeof(kk_msg_request_payload_t));
res = dm_mgr_get_devId_by_devicecode(deviceCode, &devid);
if(res != SUCCESS_RETURN){
return FAIL_RETURN;
}
res = _kk_msg_request_parse((char *)payload, payload_len, &request);
if (res < SUCCESS_RETURN) {
return res ;
}
/* Operation */
res = _kk_msg_property_set(devid, &request);
res = _kk_msg_property_set(dev_shadow, &request);
/* Response */
//kk_tsl_post_property(devid,NULL);
#if 0
#define EVENT_ERROR_IDENTIFIER "Error"
#define EVENT_ERROR_OUTPUT_INFO_IDENTIFIER "ErrorCode"
//kk_tsl_post_property(devid,NULL);
char event_output_identifier[64];
snprintf(event_output_identifier, sizeof(event_output_identifier), "%s.%s",
EVENT_ERROR_IDENTIFIER, EVENT_ERROR_OUTPUT_INFO_IDENTIFIER);
int errorCode = 0;
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_tsl_set_value(kk_tsl_set_event_output_value, devid,
event_output_identifier, &errorCode, NULL);
kk_tsl_post_event(devid,EVENT_ERROR_IDENTIFIER);
#endif
return SUCCESS_RETURN;
}
#if 0
int kk_tsl_service_property_set(const char *topic, const char *payload, unsigned int payload_len,
void *context)
{
......@@ -1293,6 +1144,7 @@ int kk_tsl_service_property_set(const char *topic, const char *payload, unsigned
int res = 0, devid = 0;
char productType[PRODUCT_TYPE_MAXLEN] = {0};
char deviceCode[DEVICE_CODE_MAXLEN] = {0};
kk_tsl_t *dev_shadow = NULL;
memset(&request, 0, sizeof(kk_msg_request_payload_t));
......@@ -1308,7 +1160,7 @@ int kk_tsl_service_property_set(const char *topic, const char *payload, unsigned
deviceCode);
res = dm_mgr_search_device_by_pkdn(productType, deviceCode, &devid);
res = dm_mgr_get_device_shadow_by_devicecode(deviceCode, &dev_shadow);
if (res < SUCCESS_RETURN) {
return res;
}
......@@ -1318,34 +1170,19 @@ int kk_tsl_service_property_set(const char *topic, const char *payload, unsigned
}
/* Operation */
res = _kk_msg_property_set(devid, &request);
res = _kk_msg_property_set(dev_shadow, &request);
/* Response */
kk_tsl_post_property(devid,NULL,0);
kk_tsl_post_property(dev_shadow,NULL,0);
#if 0
#define EVENT_ERROR_IDENTIFIER "Error"
#define EVENT_ERROR_OUTPUT_INFO_IDENTIFIER "ErrorCode"
//kk_tsl_post_property(devid,NULL);
char event_output_identifier[64];
snprintf(event_output_identifier, sizeof(event_output_identifier), "%s.%s",
EVENT_ERROR_IDENTIFIER, EVENT_ERROR_OUTPUT_INFO_IDENTIFIER);
int errorCode = 0;
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_tsl_set_value(kk_tsl_set_event_output_value, devid,
event_output_identifier, &errorCode, NULL);
kk_tsl_post_event(devid,EVENT_ERROR_IDENTIFIER);
#endif
return SUCCESS_RETURN;
}
static int kk_tsl_post_property_start(_IN_ int devid, _OU_ void **handle)
#endif
static int kk_tsl_post_property_start(_IN_ kk_tsl_t * dev_shadow, _OU_ void **handle)
{
dm_api_property_t *dapi_property = NULL;
if (devid < 0 || handle == NULL || *handle != NULL) {
if (dev_shadow == NULL || handle == NULL || *handle != NULL) {
return INVALID_PARAMETER;
}
......@@ -1355,7 +1192,7 @@ static int kk_tsl_post_property_start(_IN_ int devid, _OU_ void **handle)
}
memset(dapi_property, 0, sizeof(dm_api_property_t));
/* Set Devid */
dapi_property->devid = devid;
dapi_property->shadow = dev_shadow;
/* Init Json Object */
dapi_property->lite = lite_cjson_create_object();
if (dapi_property->lite == NULL) {
......@@ -1365,41 +1202,26 @@ static int kk_tsl_post_property_start(_IN_ int devid, _OU_ void **handle)
*handle = (void *)dapi_property;
return SUCCESS_RETURN;
}
static int _kk_tsl_get_property_by_index(_IN_ int devid, _IN_ int index, _OU_ kk_tsl_data_t **property)
static int _kk_tsl_get_property_by_index(_IN_ kk_tsl_t *dev_shadow, _IN_ int index, _OU_ kk_tsl_data_t **property)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (devid < 0 || index < 0) {
if (dev_shadow == NULL || index < 0) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
*property = (kk_tsl_data_t *)(node->dev_shadow->properties + index);
*property = (kk_tsl_data_t *)(dev_shadow->properties + index);
return SUCCESS_RETURN;
}
int kk_tsl_get_property_number(_IN_ int devid, _OU_ int *number)
int kk_tsl_get_property_number(_IN_ kk_tsl_t *shadow, _OU_ int *number)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (devid < 0 || number == NULL) {
if (shadow == NULL || number == NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
if(node->dev_shadow == NULL)
{
return FAIL_RETURN;
}
*number = node->dev_shadow->property_number;
*number = shadow->property_number;
return SUCCESS_RETURN;
}
......@@ -1414,13 +1236,8 @@ static int _kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _
}
dapi_property = (dm_api_property_t *)handle;
/* Assemble Property Payload */
res = dm_mgr_search_dev_by_devid(dapi_property->devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = kk_tsl_assemble_property(node->dev_shadow, identifier, identifier_len, dapi_property->lite);
res = kk_tsl_assemble_property(dapi_property->shadow, identifier, identifier_len, dapi_property->lite);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1449,7 +1266,7 @@ int kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _IN_ int
return ret;
}
res = kk_tsl_get_property_number(dapi_property->devid, &number);
res = kk_tsl_get_property_number(dapi_property->shadow, &number);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1458,7 +1275,7 @@ int kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _IN_ int
property_refer = NULL;
identifier_refer = NULL;
res = _kk_tsl_get_property_by_index(dapi_property->devid, index, &property_refer);
res = _kk_tsl_get_property_by_index(dapi_property->shadow, index, &property_refer);
if (res != SUCCESS_RETURN) {
continue;
}
......@@ -1472,75 +1289,60 @@ int kk_tsl_post_property_add(_IN_ void *handle, _IN_ char *identifier, _IN_ int
}
return ret;
}
static int kk_tsl_post_property_end(_IN_ void *handle,_IN_ int isAsync)
static char* kk_tsl_post_property_end(_IN_ void *handle)
{
int res = 0;
char *payload = NULL;
dm_api_property_t *dapi_property = NULL;
if (handle == NULL) {
return INVALID_PARAMETER;
return NULL;
}
dapi_property = (dm_api_property_t *)handle;
payload = lite_cjson_print_unformatted(dapi_property->lite);
if (payload == NULL) {
lite_cjson_delete(dapi_property->lite);
free(dapi_property);
return MEMORY_NOT_ENOUGH;
return NULL;
}
INFO_PRINT("Post Payload, Length: %d, Payload: %s\n", strlen(payload), payload);
res = dm_mgr_upstream_thing_property_post(dapi_property->devid, payload, strlen(payload),isAsync);
//res = dm_mgr_upstream_thing_property_post(dapi_property->shadow, payload, strlen(payload),isAsync);
lite_cjson_delete(dapi_property->lite);
free(dapi_property);
free(payload);
//free(payload);
dapi_property = NULL;
return res;
return payload;
}
int kk_tsl_post_property(int devId, const char *property_identifier,int isAsync)
char* kk_tsl_get_post_property_str(kk_tsl_t *dev_shadow, const char *property_identifier)
{
int res = 0, msgid = 0, property_identifier_len = 0, post_property_reply = 0;
void *property_handle = NULL;
kk_tsl_api_ctx_t *kk_tsl_api_ctx = _kk_tsl_api_get_ctx();
_kk_tsl_api_lock();
res = kk_tsl_post_property_start(devId, &property_handle);
res = kk_tsl_post_property_start(dev_shadow, &property_handle);
if (res != SUCCESS_RETURN) {
_kk_tsl_api_unlock();
return FAIL_RETURN;
return NULL;
}
property_identifier_len = (property_identifier) ? (strlen((char *)property_identifier)) : (0);
res = kk_tsl_post_property_add(property_handle, (char *)property_identifier, property_identifier_len);
if (res != SUCCESS_RETURN) {
kk_tsl_post_property_end(property_handle,isAsync);
_kk_tsl_api_unlock();
return FAIL_RETURN;
}
res = kk_tsl_post_property_end(property_handle,isAsync);
if (res < SUCCESS_RETURN) {
_kk_tsl_api_unlock();
return FAIL_RETURN;
}
kk_tsl_post_property_add(property_handle, (char *)property_identifier, property_identifier_len);
_kk_tsl_api_unlock();
return SUCCESS_RETURN;
return kk_tsl_post_property_end(property_handle);
}
static int kk_tsl_event_output(_IN_ int devid, _IN_ char *identifier, _IN_ int identifier_len,
static int kk_tsl_event_output(_IN_ kk_tsl_t *dev_shadow, _IN_ char *identifier, _IN_ int identifier_len,
_IN_ lite_cjson_item_t *lite)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (devid < 0 || identifier == NULL || identifier_len <= 0 || lite == NULL || lite->type != cJSON_Object) {
if (dev_shadow == NULL || identifier == NULL || identifier_len <= 0 || lite == NULL || lite->type != cJSON_Object) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
res = kk_tsl_assemble_event_output(node->dev_shadow, identifier, identifier_len, lite);
res = kk_tsl_assemble_event_output(dev_shadow, identifier, identifier_len, lite);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
......@@ -1569,21 +1371,15 @@ static int _kk_tsl_get_event_by_identifier(_IN_ kk_tsl_t *shadow, _IN_ char *ide
return FAIL_RETURN;
}
int kk_tsl_get_event_by_identifier(_IN_ int devid, _IN_ char *identifier, _OU_ void **event)
int kk_tsl_get_event_by_identifier(_IN_ kk_tsl_t *dev_shadow, _IN_ char *identifier, _OU_ void **event)
{
int res = 0;
dm_mgr_dev_node_t *node = NULL;
if (devid < 0 || identifier == NULL || event == NULL || *event != NULL) {
if (dev_shadow == NULL || identifier == NULL || event == NULL || *event != NULL) {
return INVALID_PARAMETER;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
}
return _kk_tsl_get_event_by_identifier(node->dev_shadow, identifier, event);
return _kk_tsl_get_event_by_identifier(dev_shadow, identifier, event);
}
int kk_tsl_get_event_method(_IN_ void *event, _OU_ char **method)
{
......@@ -1617,143 +1413,97 @@ int kk_tsl_get_event_method(_IN_ void *event, _OU_ char **method)
return SUCCESS_RETURN;
}
static int _kk_tsl_post_event(_IN_ int devid, _IN_ char *identifier, _IN_ int identifier_len)
char* kk_tsl_get_post_event_str(_IN_ kk_tsl_t *dev_shadow, _IN_ char *identifier, _IN_ int identifier_len)
{
int res = 0;
void *event = NULL;
lite_cjson_item_t *lite = NULL;
char *method = NULL, *payload = NULL;
char *payload = NULL;
if (devid < 0 || identifier == NULL || identifier_len <= 0) {
return INVALID_PARAMETER;
if (dev_shadow == NULL || identifier == NULL || identifier_len <= 0) {
return NULL;
}
lite = lite_cjson_create_object();
if (lite == NULL) {
return MEMORY_NOT_ENOUGH;
return NULL;
}
_kk_tsl_api_lock();
res = kk_tsl_event_output(devid, identifier, identifier_len, lite);
res = kk_tsl_event_output(dev_shadow, identifier, identifier_len, lite);
if (res != SUCCESS_RETURN) {
lite_cjson_delete(lite);
return FAIL_RETURN;
_kk_tsl_api_unlock();
return NULL;
}
payload = lite_cjson_print_unformatted(lite);
lite_cjson_delete(lite);
if (payload == NULL) {
return MEMORY_NOT_ENOUGH;
}
INFO_PRINT("\nCurrent Event Post Payload, Length: %d, Payload: %s\n", strlen(payload), payload);
res = kk_tsl_get_event_by_identifier(devid, identifier, &event);
if (res != SUCCESS_RETURN) {
free(payload);
return FAIL_RETURN;
}
res = kk_tsl_get_event_method(event, &method);
if (res != SUCCESS_RETURN) {
free(payload);
return FAIL_RETURN;
_kk_tsl_api_unlock();
return NULL;
}
INFO_PRINT("Current Event Method: %s", method);
INFO_PRINT("\nCurrent Event Post Payload, Length: %d, Payload: %s\n", strlen(payload), payload);
_kk_tsl_api_unlock();
res = dm_mgr_upstream_thing_event_post(devid, identifier, identifier_len, method, payload, strlen(payload));
//res = dm_mgr_upstream_thing_event_post(devid, identifier, identifier_len, method, payload, strlen(payload));
free(payload);
free(method);
return res;
//free(payload);
return payload;
}
int kk_tsl_post_event(int devId, const char *event_identifier)
{
int res = 0, msgid = 0, post_event_reply = 0;
kk_tsl_api_ctx_t *kk_tsl_api_ctx = _kk_tsl_api_get_ctx();
if (event_identifier == NULL) {
return FAIL_RETURN;
}
_kk_tsl_api_lock();
res = _kk_tsl_post_event(devId, (char *)event_identifier, strlen((char *)event_identifier));
if (res < SUCCESS_RETURN) {
_kk_tsl_api_unlock();
return FAIL_RETURN;
}
_kk_tsl_api_unlock();
return SUCCESS_RETURN;
}
static int _kk_tsl_send_service_response(_IN_ int devid, _IN_ int msgid, _IN_ iotx_dm_error_code_t code,
static char* _kk_tsl_send_service_response(_IN_ kk_tsl_t *dev_shadow,
_IN_ char *identifier,
_IN_ int identifier_len)
{
int res = 0;
lite_cjson_item_t *lite = NULL;
char *payload = NULL;
dm_mgr_dev_node_t *node = NULL;
if (devid < 0 || msgid < 0 || identifier == NULL || identifier_len <= 0) {
return INVALID_PARAMETER;
if (dev_shadow == NULL || identifier == NULL || identifier_len <= 0) {
return NULL;
}
lite = lite_cjson_create_object();
if (lite == NULL) {
return MEMORY_NOT_ENOUGH;
}
res = dm_mgr_search_dev_by_devid(devid, &node);
if (res != SUCCESS_RETURN) {
return FAIL_RETURN;
return NULL;
}
_kk_tsl_api_lock();
res = kk_tsl_assemble_service_output(node->dev_shadow, identifier, identifier_len, lite);
res = kk_tsl_assemble_service_output(dev_shadow, identifier, identifier_len, lite);
if (res != SUCCESS_RETURN) {
lite_cjson_delete(lite);
return FAIL_RETURN;
_kk_tsl_api_unlock();
return NULL;
}
_kk_tsl_api_unlock();
payload = lite_cjson_print_unformatted(lite);
lite_cjson_delete(lite);
if (payload == NULL) {
return MEMORY_NOT_ENOUGH;
return NULL;
}
INFO_PRINT("Current Service Response Payload, Length: %d, Payload: %s", strlen(payload), payload);
res = dm_mgr_deprecated_upstream_thing_service_response(devid, msgid, code, identifier, identifier_len, payload,
strlen(payload));
// res = dm_mgr_deprecated_upstream_thing_service_response(devid, msgid, code, identifier, identifier_len, payload,
//strlen(payload));
free(payload);
return res;
//free(payload);
return payload;
}
int kk_tsl_post_service(int devId, const char *service_identifier, int response_id,
int code)
char * kk_tsl_get_post_service_str(kk_tsl_t *dev_shadow, const char *service_identifier)
{
int res = 0;
kk_tsl_api_ctx_t *kk_tsl_api_ctx = _kk_tsl_api_get_ctx();
if (service_identifier == NULL) {
ERROR_PRINT("Invalid Parameter");
return FAIL_RETURN;
}
_kk_tsl_api_lock();
res = _kk_tsl_send_service_response(devId, response_id, (iotx_dm_error_code_t)code,
(char *)service_identifier, strlen(service_identifier));
if (res < SUCCESS_RETURN) {
_kk_tsl_api_unlock();
return FAIL_RETURN;
return NULL;
}
_kk_tsl_api_unlock();
return SUCCESS_RETURN;
return _kk_tsl_send_service_response(dev_shadow,(char *)service_identifier, strlen(service_identifier));
}
......
......@@ -66,22 +66,22 @@ typedef enum {
} kk_tsl_get_t;
typedef struct {
int devid;
kk_tsl_t * shadow;
lite_cjson_item_t *lite;
} dm_api_property_t;
extern int kk_tsl_api_init(void);
extern int kk_tsl_set_value(kk_tsl_set_t set, int devId, const char *identifier, \
extern int kk_tsl_set_value(kk_tsl_set_t set, kk_tsl_t *dev_shadow, const char *identifier, \
const void *value, \
const char *value_str);
extern int kk_tsl_get_value(kk_tsl_get_t method_get, int devId, const char *identifier, \
extern int kk_tsl_get_value(kk_tsl_get_t method_get, kk_tsl_t * dev_shadow, const char *identifier, \
void *value, \
char **value_str);
extern int kk_msg_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli, _IN_ int end_deli, \
_OU_ char productType[PRODUCT_TYPE_MAXLEN], _OU_ char deviceCode[DEVICE_CODE_MAXLEN]);
extern int kk_tsl_service_property_set(const char *topic, const char *payload, unsigned int payload_len,
void *context);
extern int kk_tsl_post_property(int devId, const char *property_identifier,int isAsync);
extern int kk_tsl_post_event(int devId, const char *event_identifier);
extern int kk_tsl_post_service(int devId, const char *service_identifier, int response_id,int code);
extern char* kk_tsl_get_post_property_str(kk_tsl_t *dev_shadow, const char *property_identifier);
extern char* kk_tsl_get_post_event_str(_IN_ kk_tsl_t *dev_shadow, _IN_ char *identifier, _IN_ int identifier_len);
extern char * kk_tsl_get_post_service_str(kk_tsl_t *dev_shadow, const char *service_identifier);
#endif
......@@ -3,7 +3,18 @@
#include <stdio.h>
#include "kk_tsl_common.h"
#include "kk_dm_mng.h"
#ifndef _ZLOG_
#undef INFO_PRINT
#undef WARNING_PRINT
#undef ERROR_PRINT
#define INFO_PRINT printf
#define WARNING_PRINT printf
#define ERROR_PRINT printf
#else
#include "kk_log.h"
#endif
#define TSL_SUBDEVICE_PATH_FILE "/home/tsl/product_%s.json"
......
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