Commit b951d6a6 authored by 黄振令's avatar 黄振令

Merge branch 'master' of http://172.17.3.10:17001/chenweican/k-sdk

# Conflicts:
#	application/kcloud/kcloud_data_handle.c
parents b049cedc 36737fa0
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "mqtt_api.h" #include "mqtt_api.h"
#include "com_api.h" #include "com_api.h"
#include "cJSON.h" #include "cJSON.h"
static char * _kk_data_create(const char *topic,const char *data) #define KK_FILTER_ADD_TOPIC "/thing/topo/add"
{ #define KK_FILTER_ADD_TOPIC_REPLY "/thing/topo/add_reply"
cJSON *root; #define KK_FILTER_DELETE_TOPIC "/thing/topo/delete"
char *out; #define KK_FILTER_DELETE_TOPIC_REPLY "/thing/topo/delete_reply"
root=cJSON_CreateObject(); #define KK_FILTER_REGISTER_TOPIC "/thing/sub/register"
cJSON_AddStringToObject(root,"topic",topic); #define KK_FILTER_REGISTER_TOPIC_REPLY "/thing/sub/register_reply"
cJSON_AddStringToObject(root,"payload",data); #define KK_FILTER_LOGIN_TOPIC "/thing/combine/login"
out=cJSON_Print(root); #define KK_FILTER_LOGIN_TOPIC_REPLY "/thing/combine/login_reply"
cJSON_Delete(root); #define KK_FILTER_SET_TOPIC "/thing/service/property/set"
printf("[%s][%d]%s\n",__FUNCTION__,__LINE__,out); #define KK_FILTER_SET_TOPIC_REPLY "/thing/service/property/set_reply"
return out; #define KK_FILTER_EVENT_POST_TOPIC "/thing/event/property/post"
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */ #define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply"
}
void KK_Sendto_CloudData(void *data,int len) int _kk_sendto_cloud(cJSON *root)
{ {
cJSON *root,*pTopic,*pData; cJSON *pTopic,*pData;
char *topic = NULL; char *topic = NULL;
char *payload = NULL; char *payload = NULL;
root=cJSON_Parse((char*)data);
if(root == NULL) pTopic = cJSON_GetObjectItem(root, "topic");
{ if(pTopic == NULL){
return; return;
} }
pTopic = cJSON_GetObjectItem(root, "topic"); pData = cJSON_GetObjectItem(root, "payload");
if(pTopic == NULL) if(pData == NULL){
{ return;
return; }
} printf("[%s][%d] topic:%s\n",__FUNCTION__,__LINE__,pTopic->valuestring);
pData = cJSON_GetObjectItem(root, "payload"); printf("[%s][%d] payload:%s\n",__FUNCTION__,__LINE__,pData->valuestring);
if(pData == NULL) KK_MQTT_SendMsg(pTopic->valuestring,(const char*)pData->valuestring);
{ }
return;
} void KK_Data_FromDev(void* str,int len)
printf("[%s][%d] topic:%s\n",__FUNCTION__,__LINE__,pTopic->valuestring); {
printf("[%s][%d] payload:%s\n",__FUNCTION__,__LINE__,pData->valuestring); cJSON *root,*cmd;
KK_MQTT_SendMsg(pTopic->valuestring,(const char*)pData->valuestring); if(str == NULL){
} return;
#define KK_FILTER_ADD_TOPIC "/thing/topo/add" }
#define KK_FILTER_ADD_TOPIC_REPLY "/thing/topo/add_reply" root=cJSON_Parse((char*)str);
#define KK_FILTER_DELETE_TOPIC "/thing/topo/delete" if(root == NULL){
#define KK_FILTER_DELETE_TOPIC_REPLY "/thing/topo/delete_reply" return;
#define KK_FILTER_REGISTER_TOPIC "/thing/sub/register" }
#define KK_FILTER_REGISTER_TOPIC_REPLY "/thing/sub/register_reply" cmd = cJSON_GetObjectItem(root, "cmd");
#define KK_FILTER_LOGIN_TOPIC "/thing/combine/login" if(cmd == NULL){
#define KK_FILTER_LOGIN_TOPIC_REPLY "/thing/combine/login_reply" _kk_sendto_cloud(root);
#define KK_FILTER_SET_TOPIC "/thing/service/property/set" }
#define KK_FILTER_SET_TOPIC_REPLY "/thing/service/property/set_reply" else{
#define KK_FILTER_EVENT_POST_TOPIC "/thing/event/property/post" KK_Subdev_Subscribe(root);
#define KK_FILTER_EVENT_POST_REPLY "/thing/event/property/post_reply" }
cJSON_Delete(root);
free(root);
static int _check_invalid_topic(char* topic) }
{ static int _check_invalid_topic(const char* topic)
if(strstr(topic, KK_FILTER_ADD_TOPIC) != NULL && \ {
strstr(topic,KK_FILTER_ADD_TOPIC_REPLY) == NULL){ if(strstr(topic, KK_FILTER_ADD_TOPIC) != NULL && \
return 1; strstr(topic,KK_FILTER_ADD_TOPIC_REPLY) == NULL){
} return 1;
else if(strstr(topic, KK_FILTER_DELETE_TOPIC) != NULL && \ }
strstr(topic,KK_FILTER_DELETE_TOPIC_REPLY) == NULL){ else if(strstr(topic, KK_FILTER_DELETE_TOPIC) != NULL && \
return 1; strstr(topic,KK_FILTER_DELETE_TOPIC_REPLY) == NULL){
} return 1;
else if(strstr(topic, KK_FILTER_REGISTER_TOPIC) != NULL && \ }
strstr(topic,KK_FILTER_REGISTER_TOPIC_REPLY) == NULL){ else if(strstr(topic, KK_FILTER_REGISTER_TOPIC) != NULL && \
return 1; strstr(topic,KK_FILTER_REGISTER_TOPIC_REPLY) == NULL){
} return 1;
else if(strstr(topic, KK_FILTER_LOGIN_TOPIC) != NULL && \ }
strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){ else if(strstr(topic, KK_FILTER_LOGIN_TOPIC) != NULL && \
return 1; strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){
} return 1;
else if(strstr(topic, KK_FILTER_SET_TOPIC_REPLY) != NULL){ }
return 1; else if(strstr(topic, KK_FILTER_SET_TOPIC_REPLY) != NULL){
} return 1;
else if(strstr(topic, KK_FILTER_EVENT_POST_TOPIC) != NULL && \ }
strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){ else if(strstr(topic, KK_FILTER_EVENT_POST_TOPIC) != NULL && \
return 1; strstr(topic,KK_FILTER_LOGIN_TOPIC_REPLY) == NULL){
} return 1;
return 0; }
} return 0;
void KK_Sendto_DevData(const char *topic,const char *data) }
{ static char * _kk_data_create(const char *topic,const char *data)
if(_check_invalid_topic(topic)) {
{ cJSON *root;
return;//ingore the message char *out;
} root=cJSON_CreateObject();
char *send_data = _kk_data_create(topic,data); cJSON_AddStringToObject(root,"topic",topic);
cJSON_AddStringToObject(root,"payload",data);
kk_ipc_send(IPC_APP2MID, send_data, strlen(send_data)+1); out=cJSON_Print(root);
} cJSON_Delete(root);
printf("[%s][%d]%s\n",__FUNCTION__,__LINE__,out);
return out;
//free(out); /* Print to text, Delete the cJSON, print it, release the string. */
}
void KK_Sendto_DevData(const char *topic,const char *data)
{
if(_check_invalid_topic(topic))
{
return;//ingore the message
}
char *send_data = _kk_data_create(topic,data);
kk_ipc_send(IPC_APP2MID, send_data, strlen(send_data)+1);
}
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