Commit 13ef8c4d authored by whmaizmy's avatar whmaizmy Committed by 黄振令

【修改内容】调试接口以及编译错误

【提交人】黄振令
parent c8ddb8c4
......@@ -4,7 +4,7 @@
#define ADDRESS "tcp://106.13.117.117:1883"
#define CLIENTID "1234"
#define TOPIC "cwctest"
#define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/thing/service/property/set"
#define PAYLOAD "Hello cwc World!"
#define QOS 2
......
......@@ -3,14 +3,30 @@
#include <string.h>
#include "mqtt_api.h"
#include "com_api.h"
#include "cJSON.h"
static char * data_create(const char *topic,const char *data)
{
cJSON *root;
char *out;
root=cJSON_CreateObject();
cJSON_AddStringToObject(root,"topic",topic);
cJSON_AddStringToObject(root,"payload",data);
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_CloudData(void *data)
{
KK_MQTT_SendMsg(TOPIC,(const char*)data,QOS);
KK_MQTT_SendMsg(TOPIC,(const char*)data);
}
void KK_Sendto_DevData(char *data)
void KK_Sendto_DevData(const char *topic,const char *data)
{
kk_ipc_send(IPC_APP2MID, data, strlen(data)+1);
}
\ No newline at end of file
char *send_data = data_create(topic,data);
kk_ipc_send(IPC_APP2MID, send_data, strlen(send_data)+1);
}
......@@ -62,6 +62,8 @@ static int mqtt_start(void)
int main(int argc, char* argv[])
{
int rc = 0;
//KK_Data_Hdl_Init();
/*set the callback to get the device date to cloud*/
kk_ipc_init(IPC_APP2MID,KK_Sendto_CloudData);
......
......@@ -106,7 +106,7 @@ int messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_messa
/* not expecting any messages */
INFO_PRINT("onMessageArrived topic:%s,message length:%d.\n",topicName,message->payloadlen);
INFO_PRINT("payload:%s,\n",message->payload);
KK_MQTT_RecvMsg((MQTTAsync)context,topicName,message->payload);
KK_MQTT_RecvMsg(topicName,message->payload);
MQTTAsync_freeMessage(&message);
MQTTAsync_free(topicName);
return 1;
......@@ -124,7 +124,7 @@ static void onConnectBuild(void *context, char *cause)
{
int rc = 0;
INFO_PRINT("onConnectBuild:%s \n",cause);
rc = KK_MQTT_SubTopic(s_Client,TOPIC,QOS,2000);
rc = KK_MQTT_SubTopic(TOPIC);
if(rc != 0)
{
ERROR_PRINT("KK_MQTT_SubTopic ERROR rc = %d\n",rc);
......@@ -219,7 +219,7 @@ MQTTAsync KK_MQTT_Connect(void)
return s_Client;
}
int KK_MQTT_SubTopic(MQTTAsync handle,char *topicName,int qos,int waitTimeout)
int KK_MQTT_SubTopic(char *topicName)
{
INFO_PRINT("to subtopic:%s \n",topicName);
......@@ -230,7 +230,7 @@ int KK_MQTT_SubTopic(MQTTAsync handle,char *topicName,int qos,int waitTimeout)
opts.onFailure = onOptFail;
opts.context = (void*)OPT_SUB;
if ((rc = MQTTAsync_subscribe(handle,topicName, qos, &opts)) != MQTTASYNC_SUCCESS)
if ((rc = MQTTAsync_subscribe(s_Client,topicName, QOS, &opts)) != MQTTASYNC_SUCCESS)
{
ERROR_PRINT("Failed to start subscribe, return code:%d.\n", rc);
return -1;
......@@ -238,7 +238,7 @@ int KK_MQTT_SubTopic(MQTTAsync handle,char *topicName,int qos,int waitTimeout)
return 0;
}
int KK_MQTT_SendMsg(char *topicName,const char *payload,int qos)
int KK_MQTT_SendMsg(char *topicName,const char *payload)
{
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
......@@ -250,10 +250,10 @@ int KK_MQTT_SendMsg(char *topicName,const char *payload,int qos)
pubmsg.payload = (void*)payload;
pubmsg.payloadlen = strlen(payload);
pubmsg.qos = qos;
pubmsg.qos = QOS;
pubmsg.retained = 0;
INFO_PRINT("mqtt send payload len:%d,qos:%d.\n",pubmsg.payloadlen,qos);
INFO_PRINT("mqtt send payload len:%d.\n",pubmsg.payloadlen);
if ((rc = MQTTAsync_sendMessage(s_Client, topicName, &pubmsg, &opts)) != MQTTASYNC_SUCCESS)
{
......@@ -262,18 +262,18 @@ int KK_MQTT_SendMsg(char *topicName,const char *payload,int qos)
}
return rc;
}
int KK_MQTT_RecvMsg(MQTTAsync handle,const char *topicName,const char *payload)
int KK_MQTT_RecvMsg(const char *topicName,const char *payload)
{
if(topicName == NULL || payload ==NULL)
{
ERROR_PRINT("PARAM ERROR\n");
return -1;
}
KK_Sendto_DevData(payload);
KK_Sendto_DevData(topicName,payload);
return 0;
}
int KK_MQTT_UnsubTopic(MQTTAsync handle,const char *topicName)
int KK_MQTT_UnsubTopic(const char *topicName)
{
INFO_PRINT("to unsubtopic:%s \n",topicName);
......@@ -284,7 +284,7 @@ int KK_MQTT_UnsubTopic(MQTTAsync handle,const char *topicName)
opts.onFailure = onOptFail;
opts.context = (void*)OPT_UNSUB;
if ((rc = MQTTAsync_unsubscribe(handle,topicName,&opts)) != MQTTASYNC_SUCCESS)
if ((rc = MQTTAsync_unsubscribe(s_Client,topicName,&opts)) != MQTTASYNC_SUCCESS)
{
ERROR_PRINT("Failed to start unubscribe, return code:%d.\n", rc);
return -1;
......
......@@ -6,13 +6,13 @@
extern void KK_Sendto_CloudData(void *data);
extern int KK_MQTT_SubTopic(MQTTAsync handle,char *topicName,int qos,int waitTimeout);
extern int KK_MQTT_SubTopic(char *topicName);
extern int KK_MQTT_SendMsg(char *topicName,const char *payload,int qos);
extern int KK_MQTT_SendMsg(char *topicName,const char *payload);
extern int KK_MQTT_RecvMsg(MQTTAsync handle,const char *topicName,const char *payload);
extern int KK_MQTT_RecvMsg(const char *topicName,const char *payload);
extern int KK_MQTT_UnsubTopic(MQTTAsync handle,const char *topicName);
extern int KK_MQTT_UnsubTopic(const char *topicName);
extern MQTTAsync KK_MQTT_Connect(void);
......
......@@ -3,6 +3,8 @@
#include "kk_tsl_api.h"
#include "lite-cjson.h"
#include "cJSON.h"
#include "com_api.h"
const char DM_URI_SYS_PREFIX[] DM_READ_ONLY = "/sys/%s/%s/";
......@@ -12,6 +14,19 @@ const char DM_URI_THING_SERVICE_PROPERTY_SET_REPLY[] DM_READ_ONLY = "thing/serv
const char DM_MSG_REQUEST[] DM_READ_ONLY = "{\"id\":\"%d\",\"version\":\"%s\",\"params\":%.*s,\"method\":\"%s\"}";
void kk_sendData2app(void *uri, void *payload){
cJSON *root=cJSON_CreateObject();
cJSON_AddStringToObject(root, "topic", uri);
cJSON_AddStringToObject(root, "payload", payload);
void *buf = cJSON_Print(root);
kk_ipc_send(IPC_MID2APP, buf, strlen(buf) + 1);
free(buf);
cJSON_Delete(root);
}
int dm_msg_request (_IN_ dm_msg_request_t *request)
{
int res = 0, payload_len = 0;
......@@ -52,13 +67,15 @@ int dm_msg_request (_IN_ dm_msg_request_t *request)
printf("DM Send Message, URI: %s, Payload: %s", uri, payload);
//if (type & DM_MSG_DEST_CLOUD) {
//dm_client_publish(uri, (unsigned char *)payload, strlen(payload), request->callback);
// dm_client_publish(uri, (unsigned char *)payload, strlen(payload), request->callback);
kk_sendData2app(uri, payload);
//}
free(uri);
free(payload);
return SUCCESS_RETURN;
}
const char DM_MSG_RESPONSE_WITH_DATA[] DM_READ_ONLY = "{\"id\":\"%.*s\",\"code\":%d,\"data\":%.*s}";
int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response_t *response,
_IN_ char *data, _IN_ int data_len, _IN_ void *user_data)
......@@ -101,6 +118,7 @@ int dm_msg_response(_IN_ kk_msg_request_payload_t *request, _IN_ kk_msg_response
printf("Send URI: %s, Payload: %s", uri, payload);
//dm_client_publish(uri, (unsigned char *)payload, strlen(payload), NULL);
kk_sendData2app(uri, payload);
free(uri);
free(payload);
......
......@@ -7,7 +7,7 @@ $(call Append_Conditional, TARGET, midware)
CFLAGS += -I$(TOP_DIR)/common/nanomsg/include
CFLAGS += -I$(TOP_DIR)/common/ev/include
CFLAGS += -I$(TOP_DIR)/common/api
LDFLAGS += -lapi_com
LDFLAGS += -lsqlite -ldl
LDFLAGS += -lapi_com -liot_cjson
LDFLAGS += -lsqlite -ldl -lm
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -static -lnanomsg -lanl
LDFLAGS += -L$(TOP_DIR)/common/ev -static -lev
\ No newline at end of file
......@@ -11,12 +11,25 @@
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>
#include "cJSON.h"
void mid_cb(void* data, int len){
if (data != NULL){
printf("app2mid_cb: %s RECEIVED \r\n", data);
char *out;cJSON *json, *topic, *payload;
json=cJSON_Parse(data);
if (!json) {
printf("Error before: [%s]\n","cJSON_Parse");
}
else
{
topic = cJSON_GetObjectItem(json, "topic");
payload = cJSON_GetObjectItem(json, "payload");
kk_tsl_service_property_set(topic->valuestring, payload->valuestring);
}
kk_ipc_send(IPC_MID2PLAT, data, len);
}
}
......
......@@ -877,7 +877,7 @@ int kk_tsl_post_property_end(_IN_ void **handle)
if (payload == NULL) {
lite_cjson_delete(dapi_property->lite);
if (dapi_property->mutex) {
HAL_MutexDestroy(dapi_property->mutex);
kk_MutexDestroy(dapi_property->mutex);
}
free(dapi_property);
return MEMORY_NOT_ENOUGH;
......
......@@ -990,7 +990,7 @@ static int _kk_tsl_data_array_search(_IN_ kk_tsl_data_t *input, _IN_ int input_i
return FAIL_RETURN;
}
static int _kk_tsl_property_search(_IN_ kk_tsl_t *shadow, _IN_ char *key, _IN_ int key_len,
int _kk_tsl_property_search(_IN_ kk_tsl_t *shadow, _IN_ char *key, _IN_ int key_len,
_OU_ kk_tsl_data_t **property, _OU_ int *index)
{
int res = 0, item_index = 0;
......
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