Commit 66fdf9b9 authored by 尹佳钦's avatar 尹佳钦

代码整理

parent 5bd87730
...@@ -294,15 +294,13 @@ APPLICATION_FILES= \ ...@@ -294,15 +294,13 @@ APPLICATION_FILES= \
./ZB/kk_color_space.c\ ./ZB/kk_color_space.c\
./ZB/sub_device_manage.c\ ./ZB/sub_device_manage.c\
./ZB/kk_ncp_queue.c\ ./ZB/kk_ncp_queue.c\
./ZB/kk_ncp_common.c\
./ZB/kk_ncp_rpc.c\
./ZB/kk_ncp_msg.c\
./ZB/kk_ncp_thread.c\
./ZB/kk_topo_batch_handle.c\ ./ZB/kk_topo_batch_handle.c\
./ZB/kk_wlist_mng.c\ ./ZB/kk_wlist_mng.c\
./kk_test.c\
./rpc_api/src/rpc_common.c\ ./rpc_api/src/rpc_common.c\
./rpc_api/src/rpc_onoff.c\
./rpc_api/src/rpc_global_cmd.c\
./rpc_api/src/rpc_interface_parse.c\
./rpc_api/src/color_control/rpc_colorControl.c\
./rpc_api/src/rpc_network_operate.c\
LIBRARIES = \ LIBRARIES = \
\ \
......
...@@ -3,7 +3,13 @@ ...@@ -3,7 +3,13 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "kk_product_code.h" #include "kk_product_code.h"
#include "kk_zb_com.h" #include "kk_device_table_db.h"
#include "kk_ncp_msg.h"
#include "kk_zigbee_api.h"
#include "zb_device_id.h"
//#include "sub_device_manage.h"
...@@ -515,6 +521,7 @@ void kk_device_config_item_report(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId c ...@@ -515,6 +521,7 @@ void kk_device_config_item_report(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId c
break; break;
} }
} }
item = item->next;
} }
} }
......
#ifndef __KK_DEVICE_MANAGER_H #ifndef __KK_DEVICE_MANAGER_H
#define __KK_DEVICE_MANAGER_H #define __KK_DEVICE_MANAGER_H
#include "kk_test.h" #include "kk_ncp_common.h"
/****************** ****************************************************************** /****************** ******************************************************************
...@@ -74,6 +74,30 @@ typedef struct kk_dev_config_map{ ...@@ -74,6 +74,30 @@ typedef struct kk_dev_config_map{
struct kk_dev_config_map *next; struct kk_dev_config_map *next;
}kk_dev_config_map; }kk_dev_config_map;
typedef struct
{
unsigned char CloorModeFlag;
unsigned char CapabilitiesFlag;
unsigned char CloorMode;
unsigned char Capabilities;
unsigned int time;
unsigned char CloorSetFlag;
union{
struct {
unsigned char HSL_flag;//bit 0:H; bit 1:S; bit 2:L
unsigned short H;
unsigned char S;
unsigned char L;
}HSL;
}color;
}ColorLighting_s;
typedef struct{
union{
ColorLighting_s ColorLighting;
}dev;
}SubDevManage_s;
kk_dev_config_item_extra_data * kk_find_extra_data(EmberNodeId node,const char * tag); kk_dev_config_item_extra_data * kk_find_extra_data(EmberNodeId node,const char * tag);
......
#include "kk_device_table_db.h" #include "kk_device_table_db.h"
#include "sqlite3.h" #include "sqlite3.h"
#include "kk_ncp_queue.h" #include "kk_ncp_queue.h"
#include "kk_device_manager.h"
void kk_mac_conver(EmberEUI64 mac,char* macString) void kk_mac_conver(EmberEUI64 mac,char* macString)
{ {
sprintf(macString, "%02X%02X%02X%02X%02X%02X%02X%02X", sprintf(macString, "%02X%02X%02X%02X%02X%02X%02X%02X",
......
#ifndef __KK_DEVICE_TABLE_DB_H #ifndef __KK_DEVICE_TABLE_DB_H
#define __KK_DEVICE_TABLE_DB_H #define __KK_DEVICE_TABLE_DB_H
#include "kk_zb_com.h" #include "kk_ncp_common.h"
#include "kk_test.h" #include "kk_device_manager.h"
#include "../device-table/device-table.h"
typedef struct kk_device_table_s{
EmberEUI64 mac;
EmberNodeId nodeId;
uint16_t deviceId;
uint16_t identifyCnt;
char productCode[33];
SubDevManage_s manage;
struct kk_device_table_s *next;
}kk_device_table_s;
#define KK_MAX_PRODUCT_CODE_SIZE 33 #define KK_MAX_PRODUCT_CODE_SIZE 33
......
#include "kk_msg_report.h" #include "kk_msg_report.h"
#include "kk_ncp_common.h"
#include "kk_device_manager.h"
#include "kk_device_table_db.h"
static void kk_msg_report(cJSON *data,char *msgtype,char *method,EmberEUI64 mac) static void kk_msg_report(cJSON *data,char *msgtype,char *method,EmberEUI64 mac)
{ {
cJSON *root;
cJSON *info,*payload;
static uint16_t msgid; static uint16_t msgid;
char msgIdString[10]= {0}; char msgIdString[10]= {0};
char macString[19] = {0}; char macString[19] = {0};
int res = 0;
kk_device_table_s *dev =NULL; kk_device_table_s *dev =NULL;
rpc_eui64ToString(mac,macString);
rpc_eui64ToString(mac,macString);
dev = kk_device_find_by_mac(mac); dev = kk_device_find_by_mac(mac);
if (dev == NULL) { if (dev == NULL) {
printf("[%s][%d]kk_msg_report error!!!\n",__FUNCTION__,__LINE__); emberAfDebugPrintln("[%s][%d]kk_msg_report error!!!\n",__FUNCTION__,__LINE__);
return; return;
} }
cJSON *info = rpc_cJSON_CreateObject(); info = rpc_cJSON_CreateObject();
if(info != NULL){ if(info != NULL){
rpc_cJSON_AddStringToObject(info, "msgType",msgtype); rpc_cJSON_AddStringToObject(info, "msgType",msgtype);
rpc_cJSON_AddStringToObject(info, "productCode",dev->productCode); rpc_cJSON_AddStringToObject(info, "productCode",dev->productCode);
rpc_cJSON_AddStringToObject(info, "deviceCode",macString); rpc_cJSON_AddStringToObject(info, "deviceCode",macString);
} }
cJSON *payload = rpc_cJSON_CreateObject(); payload = rpc_cJSON_CreateObject();
if(payload != NULL){ if(payload != NULL){
sprintf(msgIdString,"%d",++msgid); sprintf(msgIdString,"%d",++msgid);
rpc_cJSON_AddStringToObject(payload, "msgId",msgIdString); rpc_cJSON_AddStringToObject(payload, "msgId",msgIdString);
rpc_cJSON_AddStringToObject(payload, "version", KK_IPC_VERSION); rpc_cJSON_AddStringToObject(payload, "version", KK_IPC_VERSION);
rpc_cJSON_AddStringToObject(payload, "method",method); rpc_cJSON_AddStringToObject(payload, "method",method);
rpc_cJSON_AddItemToObject(payload, "params", data); rpc_cJSON_AddItemToObject(payload, "params", data);
} }
cJSON *root = rpc_cJSON_CreateObject(); root = rpc_cJSON_CreateObject();
if(root != NULL){ if(root != NULL){
rpc_cJSON_AddItemToObject(root, "info", info); rpc_cJSON_AddItemToObject(root, "info", info);
rpc_cJSON_AddItemToObject(root, "payload", payload); rpc_cJSON_AddItemToObject(root, "payload", payload);
} }
char* p = rpc_cJSON_Print(root); kk_tsl_send_msg(root);
emberAfAppPrintln("send json:\n%s\n",p);
free(p);
jrpc_send_msg(root);
rpc_cJSON_Delete(root); rpc_cJSON_Delete(root);
} }
static void kk_msg_report_joined(cJSON *data,EmberEUI64 mac)
{
kk_msg_report(data,KK_REPORT_DEVICE_JOINED_TYPE,KK_REPORT_DEVICE_JOINED_METHOD,mac);
}
static void kk_msg_report_leave(cJSON *data,EmberEUI64 mac)
{
kk_msg_report(data,KK_REPORT_DEVICE_LEFT_TYPE,KK_REPORT_DEVICE_LEAVE_METHOD,mac);
}
void kk_msg_report_batch_joined(cJSON *data,EmberEUI64 mac) void kk_msg_report_batch_joined(cJSON *data,EmberEUI64 mac)
{ {
...@@ -51,42 +60,23 @@ void kk_msg_report_batch_leave(cJSON *data,EmberEUI64 mac) ...@@ -51,42 +60,23 @@ void kk_msg_report_batch_leave(cJSON *data,EmberEUI64 mac)
kk_msg_report(data,KK_REPORT_DEVICE_BATCH_LEFT_TYPE,KK_REPORT_DEVICE_BATCH_LEAVE_METHOD,mac); kk_msg_report(data,KK_REPORT_DEVICE_BATCH_LEFT_TYPE,KK_REPORT_DEVICE_BATCH_LEAVE_METHOD,mac);
} }
static void kk_msg_report_joined(cJSON *data,EmberEUI64 mac)
{
kk_msg_report(data,KK_REPORT_DEVICE_JOINED_TYPE,KK_REPORT_DEVICE_JOINED_METHOD,mac);
}
static void kk_msg_report_leave(cJSON *data,EmberEUI64 mac)
{
kk_msg_report(data,KK_REPORT_DEVICE_LEFT_TYPE,KK_REPORT_DEVICE_LEAVE_METHOD,mac);
}
void kk_msg_report_property(cJSON *data,EmberEUI64 mac) void kk_msg_report_property(cJSON *data,EmberEUI64 mac)
{ {
kk_msg_report(data,KK_REPORT_ATTRIBUTE_TYPE,KK_REPORT_ATTRIBUTE_METHOD,mac); kk_msg_report(data,KK_REPORT_ATTRIBUTE_TYPE,KK_REPORT_ATTRIBUTE_METHOD,mac);
} }
void kk_msg_report_whiteListAddedNotification(cJSON *data,EmberEUI64 mac) void kk_msg_report_whiteListAddedNotification(cJSON *data,EmberEUI64 mac)
{ {
kk_msg_report(data,KK_REPORT_ADDWHITELIST_NOTIFY_METHOD,KK_REPORT_ADDWHITELIST_NOTIFY_TYPE,mac); kk_msg_report(data,KK_REPORT_ADDWHITELIST_NOTIFY_METHOD,KK_REPORT_ADDWHITELIST_NOTIFY_TYPE,mac);
} }
void kk_msg_report_whiteListDelNotification(cJSON *data,EmberEUI64 mac) void kk_msg_report_whiteListDelNotification(cJSON *data,EmberEUI64 mac)
{ {
kk_msg_report(data,KK_REPORT_DELWHITELIST_NOTIFY_METHOD,KK_REPORT_DELWHITELIST_NOTIFY_TYPE,mac); kk_msg_report(data,KK_REPORT_DELWHITELIST_NOTIFY_METHOD,KK_REPORT_DELWHITELIST_NOTIFY_TYPE,mac);
} }
void kk_msg_report_alarm(cJSON *data,EmberEUI64 mac) void kk_msg_report_alarm(cJSON *data,EmberEUI64 mac)
{ {
kk_msg_report(data,KK_REPORT_ALARM_TYPE,KK_REPORT_ALARM_METHOD,mac); kk_msg_report(data,KK_REPORT_ALARM_TYPE,KK_REPORT_ALARM_METHOD,mac);
} }
void kk_msg_get_property_reply(cJSON *data,EmberEUI64 mac)
{
kk_msg_report(data,KK_GET_PROPERTY_REPLY_MSG_TYPE,KK_GET_PROPERTY_REPLY_METHOD,mac);
}
void kk_msg_report_dev_joined(EmberEUI64 mac,const char* productCode) void kk_msg_report_dev_joined(EmberEUI64 mac,const char* productCode)
{ {
cJSON* devicesJson; cJSON* devicesJson;
...@@ -110,7 +100,6 @@ void kk_msg_report_dev_joined(EmberEUI64 mac,const char* productCode) ...@@ -110,7 +100,6 @@ void kk_msg_report_dev_joined(EmberEUI64 mac,const char* productCode)
void kk_msg_report_dev_leave(EmberEUI64 mac) void kk_msg_report_dev_leave(EmberEUI64 mac)
{ {
int res = 0;
cJSON* devicesJson; cJSON* devicesJson;
EmberEUI64 localEui64 = {0}; EmberEUI64 localEui64 = {0};
char macString[KK_EUI64_STRING_LENGTH]; char macString[KK_EUI64_STRING_LENGTH];
...@@ -119,7 +108,7 @@ void kk_msg_report_dev_leave(EmberEUI64 mac) ...@@ -119,7 +108,7 @@ void kk_msg_report_dev_leave(EmberEUI64 mac)
dev = kk_device_find_by_mac(mac); dev = kk_device_find_by_mac(mac);
if (dev == NULL) { if (dev == NULL) {
emberAfDebugPrintln("[%s][%d]kk_msg_report_dev_leave error!!!\n",__FUNCTION__,__LINE__); emberAfDebugPrintln("[%s][%d]kk_msg_report_dev_leave error!!!\n",__FUNCTION__,__LINE__);
return; return;
} }
devicesJson = rpc_cJSON_CreateObject(); devicesJson = rpc_cJSON_CreateObject();
rpc_cJSON_AddStringToObject(devicesJson, "productCode",dev->productCode); rpc_cJSON_AddStringToObject(devicesJson, "productCode",dev->productCode);
...@@ -131,12 +120,5 @@ void kk_msg_report_dev_leave(EmberEUI64 mac) ...@@ -131,12 +120,5 @@ void kk_msg_report_dev_leave(EmberEUI64 mac)
} }
int kk_sendData2CCU(char* data, int len)
{
if (strcmp(GW2CCU_PROTOCOL,"tcp") == 0 ){
kk_tcp_client_send(data, len);
}else{
kk_ipc_send(IPC_PLAT2MID, data, len + 1);
}
}
#ifndef __KK_MSG_REPORT_H #ifndef __KK_MSG_REPORT_H
#define __KK_MSG_REPORT_H #define __KK_MSG_REPORT_H
#include <stdio.h> #include "kk_ncp_msg.h"
#include "app/framework/include/af.h"
#include ".././jsonrpc/jsonrpc-c.h"
#include ".././jsonrpc/rpccJSON.h"
#include "com_api.h"
#include "kk_zb_com.h"
#define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_BATCH_JOINED_METHOD "thing.topo.batchAdd"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_REPORT_DEVICE_BATCH_LEAVE_METHOD "thing.topo.batchDelete"
#define KK_REPORT_ADDWHITELIST_NOTIFY_METHOD "thing.event.whiteListAddedNotification.post"
#define KK_REPORT_DELWHITELIST_NOTIFY_METHOD "thing.event.whiteListDeletedNotification.post"
#define KK_REPORT_PROPERTY_MSG_TYPE "/thing/event/property/post"
#define KK_SET_PROPERTY_REPLY_MSG_TYPE "/thing/service/property/set_reply"
#define KK_GET_PROPERTY_REPLY_MSG_TYPE "/thing/service/property/get_reply"
#define KK_GET_PROPERTY_MSG_TYPE "/thing/service/property/get"
#define KK_GET_PROPERTY_REPLY_METHOD "thing.service.property.get"
#define KK_REPORT_ALARM_METHOD "thing.event.alarm.post"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_REPORT_DEVICE_BATCH_JOINED_TYPE "/thing/topo/batch_add"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#define KK_REPORT_DEVICE_BATCH_LEFT_TYPE "/thing/topo/batch_delete"
#define KK_REPORT_ALARM_TYPE "/thing/event/alarm/post"
#define KK_REPORT_ADDWHITELIST_NOTIFY_TYPE "/thing/event/whiteListAddedNotification/post"
#define KK_REPORT_DELWHITELIST_NOTIFY_TYPE "/thing/event/whiteListDeletedNotification/post"
#define GW2CCU_PROTOCOL "tcp"
//#define GATEWAY_TYPE_NCP
#ifdef GATEWAY_TYPE_NCP
#undef GW2CCU_PROTOCOL
#define GW2CCU_PROTOCOL "nanomsg"
#endif
int kk_sendData2CCU(char* data, int len);
void kk_msg_report_dev_leave(EmberEUI64 mac);
void kk_msg_report_dev_joined(EmberEUI64 mac,const char* productCode); void kk_msg_report_dev_joined(EmberEUI64 mac,const char* productCode);
void kk_msg_report_dev_leave(EmberEUI64 mac);
void kk_msg_report_batch_joined(cJSON *data,EmberEUI64 mac);
void kk_msg_report_batch_leave(cJSON *data,EmberEUI64 mac);
void kk_msg_report_property(cJSON *data,EmberEUI64 mac); void kk_msg_report_property(cJSON *data,EmberEUI64 mac);
void kk_msg_report_whiteListAddedNotification(cJSON *data,EmberEUI64 mac);
void kk_msg_report_whiteListDelNotification(cJSON *data,EmberEUI64 mac);
void kk_msg_report_alarm(cJSON *data,EmberEUI64 mac); void kk_msg_report_alarm(cJSON *data,EmberEUI64 mac);
#endif #endif
#ifndef __KK_ZB_COM_H #ifndef __KK_NCP_COMMON_H
#define __KK_ZB_COM_H #define __KK_NCP_COMMON_H
#include "app/framework/include/af.h" #include "app/framework/include/af.h"
#include "zb_device_id.h"
typedef struct #include "./jsonrpc/rpccJSON.h"
{ #include "./jsonrpc/jsonrpc-c.h"
unsigned char CloorModeFlag;
unsigned char CapabilitiesFlag;
unsigned char CloorMode;
unsigned char Capabilities;
unsigned int time;
unsigned char CloorSetFlag;
union{
struct {
unsigned char HSL_flag;//bit 0:H; bit 1:S; bit 2:L
unsigned short H; #define GW2CCU_PROTOCOL "tcp"
unsigned char S; #define GW_PRODUCT_CODE "2"
unsigned char L;
}HSL; //#define GATEWAY_TYPE_NCP
}color;
}ColorLighting_s; #ifdef GATEWAY_TYPE_NCP
#undef GW2CCU_PROTOCOL
#define GW2CCU_PROTOCOL "nanomsg"
typedef struct{ #endif
union{
ColorLighting_s ColorLighting; void _cb(void* data, int len, char* chlmark);
}dev;
}SubDevManage_s; char* kk_get_gw_mac(void);
typedef struct kk_device_table_s{ cJSON* rpc_reportDeviceState(char *state,EmberEUI64 eui64);
EmberEUI64 mac;
EmberNodeId nodeId;
uint16_t deviceId;
uint16_t identifyCnt;
char productCode[33];
SubDevManage_s manage;
struct kk_device_table_s *next;
}kk_device_table_s;
#define RPC_APPVERSION_STRING_LENGTH 3 // #define RPC_APPVERSION_STRING_LENGTH 3 //
...@@ -49,11 +41,7 @@ typedef struct kk_device_table_s{ ...@@ -49,11 +41,7 @@ typedef struct kk_device_table_s{
#define RPC_LENGTH_STRING_LENGTH 4 //0-255 + NULL #define RPC_LENGTH_STRING_LENGTH 4 //0-255 + NULL
#define RPC_STATUS_STRING_LENGTH 4 //0-255 + NULL #define RPC_STATUS_STRING_LENGTH 4 //0-255 + NULL
enum {
WC_normal_dir = 0,//"正转"
WC_reversed_dir = 1,//"反转"
WC_calibration_mode = 2,//"校验"
}windowCoveringMode;
#define KK_EUI64_STRING_LENGTH 17 //16 characters + NULL #define KK_EUI64_STRING_LENGTH 17 //16 characters + NULL
...@@ -69,7 +57,6 @@ enum { ...@@ -69,7 +57,6 @@ enum {
#endif
...@@ -78,3 +65,7 @@ enum { ...@@ -78,3 +65,7 @@ enum {
#endif
#include <stdio.h>
#include "kk_ncp_common.h"
#include "kk_ncp_msg.h"
#include "com_api.h"
void* _msg_event_property_post(char ip[16], int port)
{
char msgFmt[] = "{\"info\":{\"msgtype\":\"/thing/event/property/post\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"},\
\"payload\":{\"msgId\":\"%d\",\"version\":\"1.0\",\"params\":{\"NetChannelState\":%d,\"WhiteListState\":%d,\
\"OnlineDetectionState\":%d,\"SN\":\"%s\",\"IPAddress\":\"%s\",\"MACAddress\":\"%s\",\"Port\":%d},\
\"time\":1524448722000,\"method\":\"thing.event.property.post\"}\
}";
char* msg = NULL;
char* macString = kk_get_gw_mac();
if (macString == NULL){
emberAfDebugPrintln("[%s] get mac fail\n",__FUNCTION__);
return NULL;
}
msg = malloc(620);
if (msg == NULL){
emberAfDebugPrintln("[%s] msg malloc fail\n",__FUNCTION__);
return NULL;
}
sprintf(msg, msgFmt, GW_PRODUCT_CODE, macString,
1, 0, 0, 0, "12345", ip,macString,port);
return msg;
}
void* _msg_topo_add(void)
{
char msgFmt[] = "{\"info\":{\"msgtype\":\"/thing/topo/add\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"},\
\"payload\":{\"msgId\":\"%d\",\"version\":\"1.0\",\"params\":{\"deviceCode\":\"%s\",\"productCode\":\"%s\",\"mac\":\"%s\"}}}";
char* msg = NULL;
char* macString = kk_get_gw_mac();
if (macString == NULL){
emberAfDebugPrintln("[%s] get mac fail\n",__FUNCTION__);
return NULL;
}
msg = malloc(520);
if (msg == NULL){
emberAfDebugPrintln("[%s] msg malloc fail\n",__FUNCTION__);
return NULL;
}
sprintf(msg, msgFmt, GW_PRODUCT_CODE, macString, 1, macString, GW_PRODUCT_CODE,macString);
return msg;
}
int kk_sendData2CCU(char* data, int len)
{
if (strcmp(GW2CCU_PROTOCOL,"tcp") == 0 ){
kk_tcp_client_send(data, len);
}else{
kk_ipc_send(IPC_PLAT2MID, data, len + 1);
}
}
int kk_tsl_send_msg(cJSON * msgJson)
{
int return_value = 0;
char * str_result = rpc_cJSON_Print(msgJson);
emberAfAppPrintln("send tsl msg:\n%s\n",str_result);
return_value = kk_sendData2CCU(str_result, strlen(str_result));
free(str_result);
return return_value;
}
void kk_tsl_msg_ack(const char * id,const char *ackMsgType,const char *productCode,const char *deviceCode)
{
char *p_msgType;
cJSON *root = rpc_cJSON_CreateObject();
cJSON *info = rpc_cJSON_CreateObject();
cJSON *payload = rpc_cJSON_CreateObject();
cJSON *data = rpc_cJSON_CreateObject();
rpc_cJSON_AddItemToObject(root,"info",info);
rpc_cJSON_AddItemToObject(root,"payload",payload);
int len = strlen(ackMsgType) + "_reply" + 1;
p_msgType = (char *)malloc(len);
memset(p_msgType,0,len);
strcpy(p_msgType,ackMsgType);
strcat(p_msgType,"_reply");
rpc_cJSON_AddStringToObject(info, "msgType", p_msgType);
rpc_cJSON_AddStringToObject(info, "productCode", productCode);
rpc_cJSON_AddStringToObject(info, "deviceCode", deviceCode);
rpc_cJSON_AddStringToObject(payload, "msgId", id);
rpc_cJSON_AddNullToObject(payload, "code");
rpc_cJSON_AddItemToObject(payload,"data", data);
free(p_msgType);
kk_tsl_send_msg(root);
rpc_cJSON_Delete(root);
}
#ifndef __KK_NCP_MSG_H
#define __KK_NCP_MSG_H
#include "kk_ncp_common.h"
#define MSG_PARSE_ERROR "Parse error"
#define MSG_INVALID_REQUEST "Invalid Request"
#define MSG_METHOD_NOT_FOUND "Method not found"
#define MSG_INVALID_PARAMS "Invalid params"
#define MSG_INTERNAL_ERROR "Internal error"
#define KK_THING_OTA_DEVICE_UPGRADE "/ota/device/upgrade"
#define KK_GET_PROPERTY_MSG_TYPE "/thing/service/property/get"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define KK_DEVICE_TOPO_CHANGE_TYPE "/thing/topo/change"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_REPORT_ALARM_TYPE "/thing/event/alarm/post"
#define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
/////////////
#define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_BATCH_JOINED_METHOD "thing.topo.batchAdd"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_REPORT_DEVICE_BATCH_LEAVE_METHOD "thing.topo.batchDelete"
#define KK_REPORT_ADDWHITELIST_NOTIFY_METHOD "thing.event.whiteListAddedNotification.post"
#define KK_REPORT_DELWHITELIST_NOTIFY_METHOD "thing.event.whiteListDeletedNotification.post"
#define KK_REPORT_PROPERTY_MSG_TYPE "/thing/event/property/post"
#define KK_SET_PROPERTY_REPLY_MSG_TYPE "/thing/service/property/set_reply"
#define KK_GET_PROPERTY_REPLY_MSG_TYPE "/thing/service/property/get_reply"
#define KK_GET_PROPERTY_REPLY_METHOD "thing.service.property.get"
#define KK_REPORT_ALARM_METHOD "thing.event.alarm.post"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_REPORT_DEVICE_BATCH_JOINED_TYPE "/thing/topo/batch_add"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#define KK_REPORT_DEVICE_BATCH_LEFT_TYPE "/thing/topo/batch_delete"
#define KK_REPORT_ALARM_TYPE "/thing/event/alarm/post"
#define KK_REPORT_ADDWHITELIST_NOTIFY_TYPE "/thing/event/whiteListAddedNotification/post"
#define KK_REPORT_DELWHITELIST_NOTIFY_TYPE "/thing/event/whiteListDeletedNotification/post"
void* _msg_event_property_post(char ip[16], int port);
void* _msg_topo_add(void);
int kk_sendData2CCU(char* data, int len);
int kk_tsl_send_msg(cJSON * msgJson);
void kk_tsl_msg_ack(const char * id,const char *ackMsgType,const char *productCode,const char *deviceCode);
#endif
#include "kk_ncp_queue.h"
#include <pthread.h> #include <pthread.h>
#include "kk_ncp_queue.h"
#include "app/framework/include/af.h"
#define NCP_QUEUE1_SIZE 50
#define NCP_QUEUE2_SIZE 20
#define NCP_QUEUE_SIZE(x) NCP_QUEUE##x##_SIZE
static ncp_queue_s g_ncp_queue[GET_PROPERTY]; static ncp_queue_s g_ncp_queue[GET_PROPERTY];
static ncp_queue_s *_ncp_queue_get_ctx(NCP_QUEUE_ENUM ix) static ncp_queue_s *_ncp_queue_get_ctx(NCP_QUEUE_ENUM ix)
...@@ -22,7 +17,7 @@ static void _ncp_queue_lock(NCP_QUEUE_ENUM ix) ...@@ -22,7 +17,7 @@ static void _ncp_queue_lock(NCP_QUEUE_ENUM ix)
ncp_queue_s *ctx = _ncp_queue_get_ctx(ix); ncp_queue_s *ctx = _ncp_queue_get_ctx(ix);
if (0 != (err_num = pthread_mutex_lock((pthread_mutex_t *)ctx->mutex))) { if (0 != (err_num = pthread_mutex_lock((pthread_mutex_t *)ctx->mutex))) {
printf("lock mutex failed: - '%s' (%d)", strerror(err_num), err_num); UTIL_LOG_WARNING("\nlock queue mutex[%d] failed: - '%s' (%d)\n",ix,strerror(err_num), err_num);
} }
} }
static void _ncp_queue_unlock(NCP_QUEUE_ENUM ix) static void _ncp_queue_unlock(NCP_QUEUE_ENUM ix)
...@@ -31,7 +26,7 @@ static void _ncp_queue_unlock(NCP_QUEUE_ENUM ix) ...@@ -31,7 +26,7 @@ static void _ncp_queue_unlock(NCP_QUEUE_ENUM ix)
ncp_queue_s *ctx = _ncp_queue_get_ctx(ix); ncp_queue_s *ctx = _ncp_queue_get_ctx(ix);
if (0 != (err_num = pthread_mutex_unlock((pthread_mutex_t *)ctx->mutex))) { if (0 != (err_num = pthread_mutex_unlock((pthread_mutex_t *)ctx->mutex))) {
printf("unlock mutex failed - '%s' (%d)", strerror(err_num), err_num); UTIL_LOG_WARNING("unlock queue mutex[%d] failed - '%s' (%d)\n",ix, strerror(err_num), err_num);
} }
} }
...@@ -45,19 +40,20 @@ static int _ncp_queue_init(NCP_QUEUE_ENUM ix,int max_size) ...@@ -45,19 +40,20 @@ static int _ncp_queue_init(NCP_QUEUE_ENUM ix,int max_size)
ctx->mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); ctx->mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
if (ctx->mutex == NULL) { if (ctx->mutex == NULL) {
UTIL_LOG_WARNING("\nmalloc queue mutex[%d] failed: - '%s' (%d)\n",ix, strerror(err_num), err_num);
return -1; return -1;
} }
if (0 != (err_num = pthread_mutex_init(ctx->mutex, NULL))) { if (0 != (err_num = pthread_mutex_init(ctx->mutex, NULL))) {
printf("create mutex failed"); UTIL_LOG_WARNING("\ninit queue mutex[%d] failed\n",ix);
free(ctx->mutex); free(ctx->mutex);
return -2; return -2;
} }
ctx->magic = KK_NCP_QUEUE_MAGIC; ctx->magic = KK_NCP_QUEUE_MAGIC;
ctx->max_size = max_size; ctx->max_size = max_size;
INIT_LIST_HEAD(&ctx->list); INIT_LIST_HEAD(&ctx->list);
UTIL_LOG_INFO("\nncp queue[%d] init success~~~\n",ix);
return 0; return 0;
} }
...@@ -71,7 +67,7 @@ int ncp_queue_init(void) ...@@ -71,7 +67,7 @@ int ncp_queue_init(void)
} }
void ncp_queue_deinit(void) void ncp_queue_deinit(void)
{ {
//do it;
} }
...@@ -81,26 +77,29 @@ int ncp_queue_enqueue(NCP_QUEUE_ENUM ix,void *data) ...@@ -81,26 +77,29 @@ int ncp_queue_enqueue(NCP_QUEUE_ENUM ix,void *data)
ncp_queue_msg_s *node = NULL; ncp_queue_msg_s *node = NULL;
if(ctx->magic!=KK_NCP_QUEUE_MAGIC){ if(ctx->magic!=KK_NCP_QUEUE_MAGIC){
UTIL_LOG_WARNING("\nenqueue-[%d] fail,queue-[%d] not init!!!\n",ix);
return -1; return -1;
} }
if (data == NULL) { if (data == NULL) {
return -1; UTIL_LOG_DBG("\nenqueue-[%d] fail,data is NULL!!!\n",ix);
return -2;
} }
_ncp_queue_lock(ix); _ncp_queue_lock(ix);
printf("list size: %d, max size: %d\n", ctx->size, ctx->max_size); UTIL_LOG_DBG("\nlist size: %d, max size: %d\n", ctx->size, ctx->max_size);
if (ctx->size >= ctx->max_size) { if (ctx->size >= ctx->max_size) {
printf("ncp queue list full"); UTIL_LOG_DBG("\nenqueue-[%d] fail,queue full!!!\n",ix);
_ncp_queue_unlock(ix); _ncp_queue_unlock(ix);
return -2; return -3;
} }
node = malloc(sizeof(ncp_queue_msg_s)); node = malloc(sizeof(ncp_queue_msg_s));
if (node == NULL) { if (node == NULL) {
UTIL_LOG_DBG("\nenqueue-[%d] fail,node is NULL!!!\n",ix);
_ncp_queue_unlock(ix); _ncp_queue_unlock(ix);
return -3; return -4;
} }
memset(node, 0, sizeof(ncp_queue_msg_s)); memset(node, 0, sizeof(ncp_queue_msg_s));
...@@ -113,7 +112,7 @@ int ncp_queue_enqueue(NCP_QUEUE_ENUM ix,void *data) ...@@ -113,7 +112,7 @@ int ncp_queue_enqueue(NCP_QUEUE_ENUM ix,void *data)
_ncp_queue_unlock(ix); _ncp_queue_unlock(ix);
printf("add queue \n"); UTIL_LOG_INFO("\nenqueue-[%d] success~~~\n",ix);
return 0; return 0;
} }
...@@ -128,14 +127,14 @@ int ncp_queue_dequeue(NCP_QUEUE_ENUM ix,void **data) ...@@ -128,14 +127,14 @@ int ncp_queue_dequeue(NCP_QUEUE_ENUM ix,void **data)
} }
if (data == NULL) { if (data == NULL) {
return -1; return -2;
} }
_ncp_queue_lock(ix); _ncp_queue_lock(ix);
if (list_empty(&ctx->list)) { if (list_empty(&ctx->list)) {
_ncp_queue_unlock(ix); _ncp_queue_unlock(ix);
return -2; return -3;
} }
node = list_first_entry(&ctx->list, ncp_queue_msg_s, list); node = list_first_entry(&ctx->list, ncp_queue_msg_s, list);
...@@ -148,7 +147,7 @@ int ncp_queue_dequeue(NCP_QUEUE_ENUM ix,void **data) ...@@ -148,7 +147,7 @@ int ncp_queue_dequeue(NCP_QUEUE_ENUM ix,void **data)
_ncp_queue_unlock(ix); _ncp_queue_unlock(ix);
printf("de queue \n"); UTIL_LOG_INFO("\ndequeue queue[%d] success~~~\n",ix);
return 0; return 0;
} }
......
...@@ -15,12 +15,14 @@ typedef struct { ...@@ -15,12 +15,14 @@ typedef struct {
struct list_head list; struct list_head list;
}ncp_queue_s; }ncp_queue_s;
typedef enum{ typedef enum{
REV_MSG = 0, REV_MSG = 0,
GET_PROPERTY, GET_PROPERTY,
NCP_QUEUE_ENUM_END NCP_QUEUE_ENUM_END
}NCP_QUEUE_ENUM; }NCP_QUEUE_ENUM;
#define NCP_QUEUE1_SIZE 50
#define NCP_QUEUE2_SIZE 20
#define NCP_QUEUE_SIZE(x) NCP_QUEUE##x##_SIZE
int ncp_queue_init(void); int ncp_queue_init(void);
int ncp_queue_dequeue(NCP_QUEUE_ENUM ix,void **data); int ncp_queue_dequeue(NCP_QUEUE_ENUM ix,void **data);
......
#include "kk_ncp_common.h"
#include "kk_ncp_msg.h"
#include "kk_ncp_rpc.h"
static struct jrpc_server my_server;
typedef cJSON(*rpc_function)(jrpc_context * ctx, cJSON * params, cJSON *id);
typedef struct{
rpc_function func;
char * name;
}rpc_table_s;
extern cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
extern cJSON *kk_topo_change_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac);
extern cJSON *kk_tsl_get_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac);
extern cJSON *kk_wlist_add(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac);
extern cJSON *kk_wlist_delete(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac);
static rpc_table_s rpc_table[]={
{(rpc_function*)kk_tsl_get_property_operation,KK_GET_PROPERTY_MSG_TYPE},\
{(rpc_function*)kk_tsl_property_operation,KK_READ_ATTRIBUTE_METHOD},\
{(rpc_function*)kk_topo_change_operation,KK_DEVICE_TOPO_CHANGE_TYPE},\
{(rpc_function*)kk_wlist_add,"/thing/service/addWhiteList"},\
{(rpc_function*)kk_wlist_delete,"/thing/service/deleteWhiteList"}, \
};
struct jrpc_server *kk_get_jrpc_server(void)
{
return &my_server;
}
void kk_jrpc_init(void)
{
my_server.debug_level = 1;
emberAfDebugPrintln("sizeof(rpc_table)=%d,sizeof(rpc_table_s)=%d,%d\n",sizeof(rpc_table),sizeof(rpc_table_s),sizeof(rpc_table)/sizeof(rpc_table_s));
for(int i=0;i<sizeof(rpc_table)/sizeof(rpc_table_s);i++){
emberAfDebugPrintln("i=%d,%s\r\n",i,rpc_table[i].name);
jrpc_register_procedure(&my_server, rpc_table[i].func, rpc_table[i].name, NULL );
}
}
static int invoke_procedure(struct jrpc_server *server,
char *name, cJSON *params, cJSON *id,cJSON *mac) {
cJSON *returned = NULL;
int procedure_found = 0;
jrpc_context ctx;
int i = server->procedure_count;
while (i--) {
if (!strcmp(server->procedures[i].name, name)) {
procedure_found = 1;
ctx.data = server->procedures[i].data;
returned = server->procedures[i].function(&ctx, params, id, mac);
break;
}
}
if (!procedure_found){
emberAfDebugPrintln("[rpc invoke] Method not found...\n");
return -1;
}else {
return 0;
}
}
int kk_jrpc_eval_request(cJSON *root)
{
cJSON *info,*payload;
cJSON *msgType,*deviceCode,*productCode;
cJSON *params,*id;
info = rpc_cJSON_GetObjectItem(root, "info");
payload = rpc_cJSON_GetObjectItem(root, "payload");
if(info != NULL){
msgType = rpc_cJSON_GetObjectItem(info, "msgType");
deviceCode = rpc_cJSON_GetObjectItem(info, "deviceCode");
productCode = rpc_cJSON_GetObjectItem(info, "productCode");
}
if(payload != NULL){
params = rpc_cJSON_GetObjectItem(payload, "params");
id = rpc_cJSON_GetObjectItem(payload, "msgId");
}
if(id != NULL && params != NULL && msgType != NULL &&
deviceCode != NULL && deviceCode!= NULL){
if(strcmp(msgType->valuestring,KK_GET_PROPERTY_MSG_TYPE)==0)
kk_tsl_msg_ack(id->valuestring,msgType->valuestring,productCode->valuestring,deviceCode->valuestring);
return invoke_procedure(&my_server, msgType->valuestring,
params, id,deviceCode);
}
return -1;
}
#ifndef __KK_NCP_RPC_H
#define __KK_NCP_RPC_H
#include <stdio.h>
#include "./jsonrpc/rpccJSON.h"
#include "./jsonrpc/jsonrpc-c.h"
void kk_jrpc_init(void);
int kk_jrpc_eval_request(cJSON *root);
#endif
#include <stdio.h>
#include "kk_ncp_common.h"
#include "kk_ncp_thread.h"
#include "kk_ncp_rpc.h"
#include "kk_ncp_queue.h"
#include "kk_zigbee_api.h"
#include "com_api.h"
#include "kk_tsl_property_get.h"
static void _msg_deal_from_mid(void)
{
cJSON *root = NULL;
char *cJsonStr;
if(ncp_queue_dequeue(REV_MSG,&root)==0){
cJsonStr = rpc_cJSON_Print(root);
emberAfDebugPrintln("[dequeue-msgRev] cJson:\n%s\n",cJsonStr);
free(cJsonStr);
kk_jrpc_eval_request(root);
rpc_cJSON_Delete(root);
}
}
static void _get_prey_from_dev(void)
{
int i;
EmberStatus status;
get_property_data_s *data;
if(ncp_queue_dequeue(GET_PROPERTY,&data)==0){
emberAfDebugPrintln("[dequeue-getPrey] data:");
emberAfDebugPrintln("node = 0x%04X,ep=%d,clu=0x%04X,attr len=%d",
data->node,data->ep,data->clu,data->len);
for(int i=0;i<data->len;i++){
emberAfDebugPrintln("attr[%d]:0x%04X\n",i,data->attr[i]);
}
status = zclGReadAttrs(data->node,1,data->ep,false,data->clu,data->len,data->attr,true);
emberAfDebugPrintln("func call status:0x%02X",status);
free(data->attr);
free(data);
}
}
static void ncp_queue_handle(void)
{
UTIL_LOG_INFO("\nncp_queue_handle start~~~~~~~~~~~~~~~~~~~~\n");
while(1){
_msg_deal_from_mid();
_get_prey_from_dev();
usleep(100000);
}
UTIL_LOG_ERR("\nncp_queue_handle end!!!!!!!!!!!!!!!!!!!\n");
}
void ipc_handle(void)
{
char* outbuf;
char* postmsg;
char* macString;
UTIL_LOG_INFO("\nipc_handle start~~~~~~~~~~~~~~~~~~~~\n");
#ifdef GATEWAY_TYPE_NCP
kk_jrpc_init();
macString = kk_get_gw_mac();
if (macString == NULL){
UTIL_LOG_ERR("\n[%s] get mac fail, exit pthread !!!\n",__FUNCTION__);
return;
}
kk_ipc_init(IPC_PLAT2MID, _cb, macString, "127.0.0.1");
//send add gw to ccu
outbuf = _msg_topo_add();
if (outbuf == NULL){
UTIL_LOG_ERR("\n[%s] topo add msg failed, exit\n",__FUNCTION__);
return;
}
emberAfDebugPrintln("check nanomsg is connect(%d)", kk_ipc_isconnect(IPC_PLAT2MID));
kk_ipc_send(IPC_PLAT2MID, outbuf, strlen(outbuf) + 1);
free(outbuf);
postmsg = _msg_event_property_post("127.0.0.1",0);
if (postmsg == NULL){
UTIL_LOG_ERR("\n[%s] property_post msg failed\n",__FUNCTION__);
return;
}
kk_ipc_send(IPC_PLAT2MID, postmsg, strlen(postmsg) + 1);
free(postmsg);
//handle procidure
while(1){
usleep(20000);
}
#else
char deviceCode[33] = {0};
char ip[16] = {0};
int port = 0;
int cnt = 0;
search_ccu(deviceCode, ip, &port);
kk_jrpc_init();
macString = kk_get_gw_mac();
if (macString == NULL){
UTIL_LOG_ERR("\n[%s] get mac fail, exit pthread !!!\n",__FUNCTION__);
return;
}
if(strcmp(GW2CCU_PROTOCOL, "tcp") == 0){
kk_tcp_client_init(ip, port, _cb);
}else{
kk_ipc_init(IPC_PLAT2MID, _cb, macString, ip);
}
//send add gw to ccu
outbuf = _msg_topo_add();
if (outbuf == NULL){
UTIL_LOG_ERR("\n[%s] topo add msg failed, exit\n",__FUNCTION__);
return;
}
if (strcmp(GW2CCU_PROTOCOL, "tcp") != 0){
emberAfDebugPrintln("check nanomsg is connect(%d)", kk_ipc_isconnect(IPC_PLAT2MID));
}
kk_sendData2CCU(outbuf, strlen(outbuf));
free(outbuf);
//handle procidure
while(1){
usleep(20000);
if (++cnt == 2){
sleep(1);
char gwIp[17] = {0};
HAL_Get_IP(gwIp,NULL);
postmsg = _msg_event_property_post(gwIp,port);
if (postmsg == NULL){
UTIL_LOG_ERR("\n[%s] property_post msg failed\n",__FUNCTION__);
continue;
}
kk_sendData2CCU(postmsg, strlen(postmsg));
free(postmsg);
}
if (kk_connect_check()){
//discover ccu
search_ccu(deviceCode, ip, &port);
if(strcmp(GW2CCU_PROTOCOL, "tcp") == 0){
kk_tcp_client_init(ip, port, _cb);
}else{
kk_ipc_deinit(IPC_PLAT2MID);
kk_ipc_init(IPC_PLAT2MID, _cb, macString/*GW_DEVICE_CODE*/, ip);
}
//send add gw to ccu
outbuf = _msg_topo_add();
if (outbuf == NULL){
UTIL_LOG_ERR("\n[%s] topo add msg failed, exit\n",__FUNCTION__);
return;
}
kk_sendData2CCU(outbuf, strlen(outbuf));
free(outbuf);
cnt = 0;
kk_reset_retry_num();
}
}
#endif
UTIL_LOG_ERR("\nipc_handle end!!!!!!!!!!!!!!!!!!!\n");
}
void kk_thread_init(void)
{
pthread_t ipc_tid;
pthread_t prey_tid;
pthread_create(&ipc_tid, NULL, ipc_handle, NULL);
pthread_create(&prey_tid, NULL, ncp_queue_handle, NULL);
}
#ifndef __KK_NCP_THREAD_H
#define __KK_NCP_THREAD_H
#include <pthread.h>
void kk_thread_init(void);
#endif
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "kk_tsl_common.h" #include "kk_tsl_common.h"
#include ".././jsonrpc/jsonrpc-c.h" #include ".././jsonrpc/jsonrpc-c.h"
#include ".././jsonrpc/rpccJSON.h" #include ".././jsonrpc/rpccJSON.h"
#include "kk_zb_com.h" #include "kk_ncp_common.h"
typedef struct { typedef struct {
char productCode[PRODUCT_CODE_MAXLEN]; char productCode[PRODUCT_CODE_MAXLEN];
......
#include "kk_test.h" #include "kk_ncp_common.h"
#include "kk_tsl_property_get.h" #include "kk_tsl_property_get.h"
#include "kk_ncp_queue.h" #include "kk_ncp_queue.h"
......
#include "kk_tsl_property_report.h" #include "kk_tsl_property_report.h"
#include "kk_device_manager.h" #include "kk_device_manager.h"
#include "kk_rgb_hsl_convert.h" #include "kk_rgb_hsl_convert.h"
#include "kk_device_table_db.h"
#include "kk_zigbee_api.h"
const char *kk_tsl_rpt_status_string[] = { const char *kk_tsl_rpt_status_string[] = {
"Success", "Success",
......
#ifndef __KK_TSL_PROPERTY_REPORT_H #ifndef __KK_TSL_PROPERTY_REPORT_H
#define __KK_TSL_PROPERTY_REPORT_H #define __KK_TSL_PROPERTY_REPORT_H
#include "kk_zb_com.h"
#include "kk_msg_report.h" #include "kk_msg_report.h"
......
#include "kk_tsl_property_set.h" #include "kk_tsl_property_set.h"
#include "kk_rgb_hsl_convert.h" #include "kk_rgb_hsl_convert.h"
#include "kk_tsl_property_get.h" #include "kk_tsl_property_get.h"
#include "kk_ncp_msg.h"
#include "kk_color_space.h"
#include "kk_device_table_db.h"
#include "com_api.h"
#include "kk_device_manager.h"
#include "kk_zigbee_api.h"
#include "../device-table/device-table.h"
static uint8_t kk_global_buffer[256]; static uint8_t kk_global_buffer[256];
static uint8_t kk_global_len; static uint8_t kk_global_len;
...@@ -16,7 +23,8 @@ cJSON *kk_tsl_get_property_operation(jrpc_context * ctx, cJSON *params, cJSON *i ...@@ -16,7 +23,8 @@ cJSON *kk_tsl_get_property_operation(jrpc_context * ctx, cJSON *params, cJSON *i
kk_dev_config_map *ptr; kk_dev_config_map *ptr;
kk_dev_config_map *dev_info = NULL; kk_dev_config_map *dev_info = NULL;
kk_dev_config_item *item = NULL; kk_dev_config_item *item = NULL;
EmberEUI64 localEui64;
char localEui64Str[17];
cJSON *array; cJSON *array;
cJSON *identifier = NULL; cJSON *identifier = NULL;
int num; int num;
...@@ -30,7 +38,17 @@ cJSON *kk_tsl_get_property_operation(jrpc_context * ctx, cJSON *params, cJSON *i ...@@ -30,7 +38,17 @@ cJSON *kk_tsl_get_property_operation(jrpc_context * ctx, cJSON *params, cJSON *i
goto error_return; goto error_return;
} }
rpc_get_mac(mac->valuestring,eui64); rpc_get_mac(mac->valuestring,eui64);
emberAfGetEui64(localEui64);
rpc_eui64ToString(localEui64,localEui64Str);
if(strcmp(localEui64Str,mac->valuestring)==0){
printf("&&&&&&&&&&&&&&&& ignore\n");
goto error_return;
}
nodeId = emberAfDeviceTableGetNodeIdFromEui64(eui64); nodeId = emberAfDeviceTableGetNodeIdFromEui64(eui64);
emberAfPrintBigEndianEui64(eui64); emberAfPrintBigEndianEui64(eui64);
......
#ifndef __KK_TSL_PROPERTY_SET_H #ifndef __KK_TSL_PROPERTY_SET_H
#define __KK_TSL_PROPERTY_SET_H #define __KK_TSL_PROPERTY_SET_H
#include "kk_test.h" #include "kk_ncp_common.h"
#include "kk_color_space.h"
cJSON *kk_topo_change_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac); cJSON *kk_topo_change_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac);
...@@ -22,11 +22,7 @@ int kk_tsl_set_colorlight_RGB_blue(jrpc_context * ctx,EmberNodeId node,unsigned ...@@ -22,11 +22,7 @@ int kk_tsl_set_colorlight_RGB_blue(jrpc_context * ctx,EmberNodeId node,unsigned
int kk_tsl_set_colorlight_Brightness(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data); int kk_tsl_set_colorlight_Brightness(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
int kk_tsl_set_colorlight_mode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data); int kk_tsl_set_colorlight_mode(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
#define RPC_KK_TEST_FUNCTION_TABLE \
{(rpc_function*)kk_tsl_property_operation,"/thing/service/property/set"},\
{(rpc_function*)kk_wlist_add,"/thing/service/addWhiteList"}, \
{(rpc_function*)kk_wlist_delete,"/thing/service/deleteWhiteList"}, \
{(rpc_function*)kk_topo_change_operation,"/thing/topo/change"}, \
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include ".././jsonrpc/jsonrpc-c.h" #include ".././jsonrpc/jsonrpc-c.h"
#include ".././jsonrpc/rpccJSON.h" #include ".././jsonrpc/rpccJSON.h"
#include "kk_ncp_common.h"
#include "kk_wlist_mng.h" #include "kk_wlist_mng.h"
#include "sqlite3.h" #include "sqlite3.h"
......
#ifndef __KK_WHITELIST_MNG_H__ #ifndef __KK_WHITELIST_MNG_H__
#define __KK_WHITELIST_MNG_H__ #define __KK_WHITELIST_MNG_H__
#include "kk_tsl_common.h" #include "kk_tsl_common.h"
#include "kk_zb_com.h"
int kk_wlist_init(void); int kk_wlist_init(void);
int kk_wlist_status_open(int isOpen); int kk_wlist_status_open(int isOpen);
int kk_delete_wlist_byMac(const char* device_mac); int kk_delete_wlist_byMac(const char* device_mac);
......
#include "kk_zigbee_api.h" #include "kk_zigbee_api.h"
#include "kk_device_manager.h"
#include "kk_tsl_property_set.h"
#include "kk_tsl_property_report.h"
#include "RPC_API.h"
#define KK_RPC_SET_FUNCTION_TABLE {\
{"kk_permit_join",kk_permit_join},\
{"kk_wlist_ctrl",kk_wlist_ctrl},\
{"zclOnOff",kk_tsl_set_gloabl_OnOff},\
{"zclOnOff_Off",zclOnOff_Off},\
{"kk_tsl_set_colorlight_RGB_red",kk_tsl_set_colorlight_RGB_red},\
{"kk_tsl_set_colorlight_RGB_green",kk_tsl_set_colorlight_RGB_green},\
{"kk_tsl_set_colorlight_RGB_blue",kk_tsl_set_colorlight_RGB_blue},\
{"kk_tsl_set_colorlight_Brightness",kk_tsl_set_colorlight_Brightness},\
{"kk_tsl_set_colorlight_mode",kk_tsl_set_colorlight_mode},\
}
#define KK_RPC_REPORT_FUNCTION_TABLE {\
{"kk_tsl_report_global_onoff",kk_tsl_report_global_onoff},\
{"kk_tsl_report_colorControl_Brightness",kk_tsl_report_colorControl_Brightness},\
{"kk_tsl_report_colorControl_RGB",kk_tsl_report_colorControl_RGB},\
{"kk_tsl_report_iasZoneStatus",kk_tsl_report_iasZoneStatus},\
{"kk_tsl_report_battery",kk_tsl_report_battery},\
}
kk_rpc_set_api_s kk_rpc_set_api[]=KK_RPC_SET_FUNCTION_TABLE; kk_rpc_set_api_s kk_rpc_set_api[]=KK_RPC_SET_FUNCTION_TABLE;
kk_rpc_report_api_s kk_rpc_report_api[]=KK_RPC_REPORT_FUNCTION_TABLE; kk_rpc_report_api_s kk_rpc_report_api[]=KK_RPC_REPORT_FUNCTION_TABLE;
...@@ -30,6 +56,19 @@ EmberAfStatus kk_private_protocol(uint16_t node,uint8_t dataLen,uint8_t *data) ...@@ -30,6 +56,19 @@ EmberAfStatus kk_private_protocol(uint16_t node,uint8_t dataLen,uint8_t *data)
EmberStatus nwkPermitJoinCMD(bool open)
{
EmberStatus status;
status = (open
? emberAfPluginNetworkCreatorSecurityOpenNetwork()
: emberAfPluginNetworkCreatorSecurityCloseNetwork());
emberAfCorePrintln("%p: %p network: 0x%X",
"NWK Creator Security",
(open ? "Open" : "Close"),
status);
return status;
}
// network leave // network leave
EmberStatus kk_network_leave(void) EmberStatus kk_network_leave(void)
......
#ifndef __KK_ZIGBEE_API_H #ifndef __KK_ZIGBEE_API_H
#define __KK_ZIGBEE_API_H #define __KK_ZIGBEE_API_H
#include "kk_test.h" #include "kk_ncp_common.h"
typedef int (*kk_rpc_set)(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data); typedef int (*kk_rpc_set)(jrpc_context * ctx,EmberNodeId node,unsigned char ep,void* data);
...@@ -18,26 +18,7 @@ typedef struct{ ...@@ -18,26 +18,7 @@ typedef struct{
void kk_rpc_test(void); void kk_rpc_test(void);
#define KK_RPC_SET_FUNCTION_TABLE {\
{"kk_permit_join",kk_permit_join},\
{"kk_wlist_ctrl",kk_wlist_ctrl},\
{"zclOnOff",kk_tsl_set_gloabl_OnOff},\
{"zclOnOff_Off",zclOnOff_Off},\
{"kk_tsl_set_colorlight_RGB_red",kk_tsl_set_colorlight_RGB_red},\
{"kk_tsl_set_colorlight_RGB_green",kk_tsl_set_colorlight_RGB_green},\
{"kk_tsl_set_colorlight_RGB_blue",kk_tsl_set_colorlight_RGB_blue},\
{"kk_tsl_set_colorlight_Brightness",kk_tsl_set_colorlight_Brightness},\
{"kk_tsl_set_colorlight_mode",kk_tsl_set_colorlight_mode},\
}
#define KK_RPC_REPORT_FUNCTION_TABLE {\
{"kk_tsl_report_global_onoff",kk_tsl_report_global_onoff},\
{"kk_tsl_report_colorControl_Brightness",kk_tsl_report_colorControl_Brightness},\
{"kk_tsl_report_colorControl_RGB",kk_tsl_report_colorControl_RGB},\
{"kk_tsl_report_iasZoneStatus",kk_tsl_report_iasZoneStatus},\
{"kk_tsl_report_battery",kk_tsl_report_battery},\
}
kk_rpc_set_api_s kk_rpc_set_api[]; kk_rpc_set_api_s kk_rpc_set_api[];
kk_rpc_report_api_s kk_rpc_report_api[]; kk_rpc_report_api_s kk_rpc_report_api[];
...@@ -46,6 +27,12 @@ kk_rpc_report_api_s kk_rpc_report_api[]; ...@@ -46,6 +27,12 @@ kk_rpc_report_api_s kk_rpc_report_api[];
uint8_t kk_get_rpc_set_api_size(void ); uint8_t kk_get_rpc_set_api_size(void );
uint8_t kk_get_rpc_report_api_size(void ); uint8_t kk_get_rpc_report_api_size(void );
enum {
WC_normal_dir = 0,//"正转"
WC_reversed_dir = 1,//"反转"
WC_calibration_mode = 2,//"校验"
}windowCoveringMode;
typedef enum{ typedef enum{
EnrollResponseCode_Success = 0x00, EnrollResponseCode_Success = 0x00,
EnrollResponseCode_NoSupported = 0x01, EnrollResponseCode_NoSupported = 0x01,
...@@ -144,6 +131,7 @@ typedef enum{ ...@@ -144,6 +131,7 @@ typedef enum{
EmberAfStatus kk_private_protocol(uint16_t node,uint8_t dataLen,uint8_t *data); EmberAfStatus kk_private_protocol(uint16_t node,uint8_t dataLen,uint8_t *data);
EmberStatus nwkPermitJoinCMD(bool open);
EmberStatus kk_network_leave(void); EmberStatus kk_network_leave(void);
EmberStatus kk_network_form(bool centralized,EmberPanId panId,int8_t radioTxPower,uint8_t channel); EmberStatus kk_network_form(bool centralized,EmberPanId panId,int8_t radioTxPower,uint8_t channel);
......
#include "sub_device_manage.h" #include "sub_device_manage.h"
#include "kk_device_manager.h" #include "zb_device_id.h"
#include "kk_zb_com.h"
#include "kk_tsl_property_report.h"
typedef void(*subDevManageFunc)(kk_device_table_s* dev); typedef void(*subDevManageFunc)(kk_device_table_s* dev);
typedef struct{ typedef struct{
......
#ifndef __SUB_DEVICE_MANAGE_H #ifndef __SUB_DEVICE_MANAGE_H
#define __SUB_DEVICE_MANAGE_H #define __SUB_DEVICE_MANAGE_H
#include "kk_zb_com.h"
#include "kk_device_manager.h"
#include "kk_device_table_db.h"
......
...@@ -91,20 +91,18 @@ void emAfZigbeeKeyEstablishment(EmberEUI64 partner, EmberKeyStatus status) ...@@ -91,20 +91,18 @@ void emAfZigbeeKeyEstablishment(EmberEUI64 partner, EmberKeyStatus status)
// ReportAttributes function declarations. // ReportAttributes function declarations.
bool emberAfReportAttributesCallback(EmberAfClusterId clusterId,uint8_t * buffer,uint16_t bufLen); bool emberAfReportAttributesCallback(EmberAfClusterId clusterId,uint8_t * buffer,uint16_t bufLen);
bool rpc_ReportAttributesCallback(EmberAfClusterId clusterId,uint8_t * buffer,uint16_t bufLen); bool kk_ReportAttributesCallback(EmberAfClusterId clusterId,uint8_t * buffer,uint16_t bufLen);
bool rpc_ReadAttributesResponseCallback(EmberAfClusterId clusterId,uint8_t *buffer,uint16_t bufLen); bool kk_ReadAttributesResponseCallback(EmberAfClusterId clusterId,uint8_t *buffer,uint16_t bufLen);
bool emAfReportAttributes(EmberAfClusterId clusterId,uint8_t * buffer,uint16_t bufLen) bool emAfReportAttributes(EmberAfClusterId clusterId,uint8_t * buffer,uint16_t bufLen)
{ {
return rpc_ReportAttributesCallback(clusterId, buffer, bufLen); return kk_ReportAttributesCallback(clusterId, buffer, bufLen);
//return emberAfReportAttributesCallback(clusterId, buffer, bufLen);
} }
bool emAfReadAttributesResponse(EmberAfClusterId clusterId,uint8_t* buffer,uint16_t bufLen) bool emAfReadAttributesResponse(EmberAfClusterId clusterId,uint8_t* buffer,uint16_t bufLen)
{ {
return rpc_ReadAttributesResponseCallback(clusterId, buffer, bufLen); return kk_ReadAttributesResponseCallback(clusterId, buffer, bufLen);
//return emberAfReadAttributesResponseCallback(clusterId, buffer, bufLen);
} }
......
...@@ -1482,7 +1482,7 @@ EmberAfStatus emberAfIasZoneClusterClientCommandParse(EmberAfClusterCommand *cmd ...@@ -1482,7 +1482,7 @@ EmberAfStatus emberAfIasZoneClusterClientCommandParse(EmberAfClusterCommand *cmd
extendedStatus, extendedStatus,
zoneId, zoneId,
delay); delay);
rpc_IasZoneClusterZoneStatusChangeNotificationCallback(zoneStatus, kk_IasZoneClusterZoneStatusChangeNotificationCallback(zoneStatus,
extendedStatus, extendedStatus,
zoneId, zoneId,
delay); delay);
......
...@@ -40,4 +40,8 @@ EmberAfStatus emberAfIasZoneClusterClientCommandParse(EmberAfClusterCommand *cmd ...@@ -40,4 +40,8 @@ EmberAfStatus emberAfIasZoneClusterClientCommandParse(EmberAfClusterCommand *cmd
// Cluster: Simple Metering, client // Cluster: Simple Metering, client
EmberAfStatus emberAfSimpleMeteringClusterClientCommandParse(EmberAfClusterCommand *cmd); EmberAfStatus emberAfSimpleMeteringClusterClientCommandParse(EmberAfClusterCommand *cmd);
void kk_IasZoneClusterZoneStatusChangeNotificationCallback(uint16_t zoneStatus,uint8_t extendedStatus,uint8_t zoneId,uint16_t delay);
#endif // SILABS_EMBER_AF_COMMAND_PARSE_HEADER #endif // SILABS_EMBER_AF_COMMAND_PARSE_HEADER
#include "kk_test.h"
#include "kk_ncp_queue.h"
static void kk_rpc_send_message(cJSON *data,char *msgtype,char *method,EmberEUI64 mac)
{
static uint16_t msgid;
char msgIdString[10]= {0};
char macString[19] = {0};
int res = 0;
kk_device_table_s *dev =NULL;
rpc_eui64ToString(mac,macString);
dev = kk_device_find_by_mac(mac);
if (dev == NULL) {
printf("[%s][%d]kk_rpc_send_message error!!!\n",__FUNCTION__,__LINE__);
return;
}
cJSON *info = rpc_cJSON_CreateObject();
if(info != NULL){
rpc_cJSON_AddStringToObject(info, "msgType",msgtype);
rpc_cJSON_AddStringToObject(info, "productCode",dev->productCode);
rpc_cJSON_AddStringToObject(info, "deviceCode",macString);
}
cJSON *payload = rpc_cJSON_CreateObject();
if(payload != NULL){
sprintf(msgIdString,"%d",++msgid);
rpc_cJSON_AddStringToObject(payload, "msgId",msgIdString);
rpc_cJSON_AddStringToObject(payload, "version", KK_IPC_VERSION);
rpc_cJSON_AddStringToObject(payload, "method",method);
rpc_cJSON_AddItemToObject(payload, "params", data);
}
cJSON *root = rpc_cJSON_CreateObject();
if(root != NULL){
rpc_cJSON_AddItemToObject(root, "info", info);
rpc_cJSON_AddItemToObject(root, "payload", payload);
}
char* p = rpc_cJSON_Print(root);
emberAfAppPrintln("send json:\n%s\n",p);
free(p);
jrpc_send_msg(root);
rpc_cJSON_Delete(root);
}
void kk_rpc_report_devices(cJSON *data,EmberEUI64 mac)
{
kk_rpc_send_message(data,KK_REPORT_DEVICE_JOINED_TYPE,KK_REPORT_DEVICE_JOINED_METHOD,mac);
}
void kk_rpc_report_left_devices(cJSON *data,EmberEUI64 mac)
{
kk_rpc_send_message(data,KK_REPORT_DEVICE_LEFT_TYPE,KK_REPORT_DEVICE_LEAVE_METHOD,mac);
}
void kk_rpc_report_status(cJSON *data,EmberEUI64 mac)
{
kk_rpc_send_message(data,KK_REPORT_ATTRIBUTE_TYPE,KK_REPORT_ATTRIBUTE_METHOD,mac);
}
typedef struct{
EmberEUI64 mac;
uint8_t AppVersion;
uint8_t deviceType;
uint8_t deviceCode;
uint8_t productType;
uint8_t productCode;
}kk_report_device_s;
void kk_rpc_reportLeftDevices(EmberEUI64 mac)
{
cJSON* devicesJson;
char macString[RPC_EUI64_STRING_LENGTH];
int res = 0;
EmberEUI64 gw_eui64 = {0};
kk_device_table_s *dev =NULL;
rpc_eui64ToString(mac,macString);
dev = kk_device_find_by_mac(mac);
if (dev == NULL) {
printf("[%s][%d]kk_rpc_reportLeftDevices error!!!\n",__FUNCTION__,__LINE__);
return;
}
devicesJson = rpc_cJSON_CreateObject();
rpc_cJSON_AddStringToObject(devicesJson, "productCode",dev->productCode);
rpc_cJSON_AddStringToObject(devicesJson, "deviceCode",macString);
emberAfGetEui64(gw_eui64);
kk_rpc_report_left_devices(devicesJson,gw_eui64);
kk_device_table_delete(mac);
}
void kk_rpc_reportDevices(EmberEUI64 mac,const char* productCode)
{
cJSON* devicesJson;
char macString[19] = {0};
EmberEUI64 eui64 = {0};
UTIL_LOG_WARNING("report tsl product code:%s\n",productCode);
emberAfPrintBigEndianEui64(mac);
emberAfDebugPrintln("");
devicesJson = rpc_cJSON_CreateObject();
rpc_eui64ToString(mac,macString);
rpc_cJSON_AddStringToObject(devicesJson, "productCode",productCode);
rpc_cJSON_AddStringToObject(devicesJson, "deviceCode",macString);
rpc_cJSON_AddStringToObject(devicesJson, "mac",macString);
//
emberAfGetEui64(eui64);
kk_rpc_report_devices(devicesJson,eui64);
}
int kk_zcl_onoff_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data)
{
uint8_t eui64[EUI64_SIZE];
uint8_t OnOffStatus = 0;
EmberStatus status = 0;
EmberNodeId node = 0xffff;
OnOffStatus = *(uint8_t*)data;
bool macMatch= rpc_get_mac(mac,eui64);
emberAfCorePrintBuffer(eui64,EUI64_SIZE,true);
for(int i=0;i<EUI64_SIZE;i++){
emberAfCorePrintln("i=%d,val=%02x",i,eui64[i]);
}
if(macMatch){
node = emberAfDeviceTableGetNodeIdFromEui64(eui64);
if(node==0xffff){
emberAfCorePrintln("\r\n not find device by node!\r\n" );
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
emberAfCorePrintln("\r\nnode=0x%02X,ep=%d,OnOffStatus=%d\r\n",node,ep,OnOffStatus);
if(OnOffStatus==1){
status = zclOnOff_On(node,ep);
emberAfCorePrintln("\r\nzclOnOff_On,status=0x%x\r\n",status);
}else if(OnOffStatus==0){
status = zclOnOff_Off(node,ep);
emberAfCorePrintln("\r\nzclOnOff_Off,status=0x%x\r\n",status);
}else{
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
}else{
emberAfCorePrintln("\r\n not find device by mac!\r\n" );
if(ctx)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
return status;
error_return:
return -1;
}
//EmberStatus WindowCover_UpOpen(uint16_t node,uint8_t ep);
//EmberStatus WindowCover_DownClose(uint16_t node,uint8_t ep);
//EmberStatus WindowCover_Stop(uint16_t node,uint8_t ep);
extern void ncp_queue_tick(void);
void emberAfMainTickCallback(void)
{
static unsigned int last_time;
unsigned int time = halCommonGetInt32uMillisecondTick();
kk_sub_dev_manage();
if((time-last_time)>=3000){
last_time = time;
kk_productCode_tick();
//printf("kk_productCode_tick!\n");
}
}
#ifndef _KK_TEST_H
#define _KK_TEST_H
#include "rpc_network_operate.h"
#include "network-creator.h"
#include "network-creator-security.h"
#include "RPC_API.h"
#include "com_api.h"
#include "zb_device_id.h"
#include "kk_device_manager.h"
#include "kk_zigbee_api.h"
#include "kk_tsl_property_report.h"
#include "kk_tsl_property_set.h"
#include "kk_msg_report.h"
#include "kk_device_table_db.h"
#include "sub_device_manage.h"
#define KK_REPORT_DEVICE_JOINED_TYPE "/thing/topo/add"
#define KK_REPORT_DEVICE_LEFT_TYPE "/thing/topo/delete"
#define KK_REPORT_ATTRIBUTE_TYPE "/thing/event/property/post"
#define KK_REPORT_ALARM_TYPE "/thing/event/alarm/post"
#define KK_DEVICE_TOPO_CHANGE_TYPE "/thing/topo/change"
#define KK_IPC_VERSION "1.0"
#define KK_REPORT_DEVICE_JOINED_METHOD "thing.topo.add"
#define KK_REPORT_DEVICE_LEAVE_METHOD "thing.topo.delete"
#define KK_REPORT_ATTRIBUTE_METHOD "thing.event.property.post"
#define KK_READ_ATTRIBUTE_METHOD "thing.service.property.get"
#define ZIGBEE_COO_PRODUCT_CODE "2"
#define TEST_PRODUCT_CODE "24"
#define MSG_TOPO_CHANGE_TYPE_STR "changeType"
#define MSG_TOPO_CHANGE_DEVICES_STR "devices"
int kk_zcl_onoff_set(jrpc_context * ctx,const char *mac,unsigned char ep,void* data);
extern cJSON *kk_tsl_get_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac);
#define RPC_KK_TEST_FUNCTION_TABLE \
{(rpc_function*)kk_tsl_property_operation,"/thing/service/property/set"},\
{(rpc_function*)kk_tsl_get_property_operation,KK_GET_PROPERTY_MSG_TYPE},\
{(rpc_function*)kk_tsl_property_operation,KK_READ_ATTRIBUTE_METHOD},\
{(rpc_function*)kk_topo_change_operation,KK_DEVICE_TOPO_CHANGE_TYPE}
#endif
...@@ -4,17 +4,13 @@ ...@@ -4,17 +4,13 @@
#include <stdio.h> #include <stdio.h>
#include <pthread.h> #include <pthread.h>
#include "../device-table/device-table.h"
#include "./jsonrpc/jsonrpc-c.h" #include "./jsonrpc/jsonrpc-c.h"
#include "./jsonrpc/rpccJSON.h" #include "./jsonrpc/rpccJSON.h"
#define MSG_PARSE_ERROR "Parse error"
#define MSG_INVALID_REQUEST "Invalid Request"
#define MSG_METHOD_NOT_FOUND "Method not found"
#define MSG_INVALID_PARAMS "Invalid params"
#define MSG_INTERNAL_ERROR "Internal error"
extern pthread_mutex_t g_mutex_lock; extern pthread_mutex_t g_mutex_lock;
extern pthread_mutex_t report_mutex_lock; extern pthread_mutex_t report_mutex_lock;
......
#ifndef __RPC_COLOR_CONTROL_H
#define __RPC_COLOR_CONTROL_H
#include "RPC_API.h"
cJSON *rpc_zclColorControlMovetohue(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlMovehue(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlStephue(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlMovetosat(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlMovesat(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlStepsat(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlMovetohueandsat(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlMovetocolor(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlMovecolor(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlStepcolor(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlMovetocolortemp(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlEmovetohue(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlEmovehue(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlEstephue(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlEmovetohueandsat(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlLoopSet(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlStopmovestep(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlMovecolortemp(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclColorControlStepcolortemp(jrpc_context * ctx, cJSON * params, cJSON *id);
#define RPC_COLOR_CONTROL_COMMAND_FUNCTION_TABLE \
{rpc_zclColorControlMovetohue,"zclColorControlMovetohue"},\
{rpc_zclColorControlMovehue,"zclColorControlMovehue"},\
{rpc_zclColorControlStephue,"zclColorControlStephue"},\
{rpc_zclColorControlMovetosat,"zclColorControlMovetosat"},\
{rpc_zclColorControlMovesat,"zclColorControlMovesat"},\
{rpc_zclColorControlStepsat,"zclColorControlStepsat"},\
{rpc_zclColorControlMovetohueandsat,"zclColorControlMovetohueandsat"},\
{rpc_zclColorControlMovetocolor,"zclColorControlMovetocolor"},\
{rpc_zclColorControlMovecolor,"zclColorControlMovecolor"},\
{rpc_zclColorControlStepcolor,"zclColorControlStepcolor"},\
{rpc_zclColorControlMovetocolortemp,"zclColorControlMovetocolortemp"},\
{rpc_zclColorControlEmovetohue,"zclColorControlEmovetohue"},\
{rpc_zclColorControlEmovehue,"zclColorControlEmovehue"},\
{rpc_zclColorControlEstephue,"zclColorControlEstephue"},\
{rpc_zclColorControlEmovetohueandsat,"zclColorControlEmovetohueandsat"},\
{rpc_zclColorControlLoopSet,"zclColorControlLoopSet"},\
{rpc_zclColorControlStopmovestep,"zclColorControlStopmovestep"},\
{rpc_zclColorControlMovecolortemp,"zclColorControlMovecolortemp"},\
{rpc_zclColorControlStepcolortemp,"zclColorControlStepcolortemp"}\
#endif
#ifndef __ZCL_GLOBAL_CMD_H
#define __ZCL_GLOBAL_CMD_H
#include "RPC_API.h"
cJSON *rpc_zclGRead(jrpc_context * ctx, cJSON * params, cJSON *id);
#define RPC_GLOBAL_COMMAND_FUNCTION_TABLE \
{rpc_zclGRead,"zclGRead"}\
#endif
#ifndef __PRC_INTERFACE_PARSE_H
#define __PRC_INTERFACE_PARSE_H
#include "Z3GatewayHost.h"
#include "yjq_ezsp.h"
#include "./jsonrpc/rpccJSON.h"
#define PORT 5555
void ipcHandle(void);
void ncp_queue_handle(void);
void rpc_reportDevices(void);
void rpc_control_devices(cJSON *data,char *method);
cJSON* rpc_reportDeviceState(char *state,EmberEUI64 eui64);
#endif
#ifndef __NETWORK_OPERATE_H
#define __NETWORK_OPERATE_H
#include "RPC_API.h"
typedef struct{
EmberNetworkStatus status;
EmberEUI64 eui64;
EmberNodeId nodeid;
EmberPanId panid;
uint8_t ch;
EmberKeyStruct nwkKey;
}rpc_nwk_info_s;
EmberStatus nwkLeave(void);
EmberStatus nwkLeaveRequest(EmberNodeId target,bool removeChildren,bool rejoin);
void nwkGetInfo(rpc_nwk_info_s *info);
EmberStatus nwkFormCMD(bool centralized,uint16_t panId,int8_t txPower,uint8_t channel);
void nwkStartCMD(bool centralized);
void nwkaddChMaskCMD(bool channelMaskIsPrimary,uint32_t channelOrNewMask);
void nwksubChMaskCMD(bool channelMaskIsPrimary,uint32_t channelOrNewMask);
void nwksetChMaskCMD(bool channelMaskIsPrimary,uint32_t channelOrNewMask);
void nwkgetChMaskCMD(void);
EmberStatus nwkPermitJoinCMD(bool open);
void nwkPermitJoinWithKeyCMD(EmberEUI64 eui64,EmberKeyData keyData);
void nwkSetJoiningLinkKeyCMD(EmberEUI64 eui64,EmberKeyData keyData);
void nwkClearJoiningLinkKeyCMD(void);
cJSON *rpc_nwkGetInfo(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_nwkFormCMD(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_nwkStar(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_nwkLeave(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_nwkLeaveRequest(jrpc_context * ctx, cJSON * params, cJSON *id);
#define RPC_NETWORK_FUNCTION_TABLE \
{(rpc_function*)rpc_nwkLeave,"nwkLeave"},\
{(rpc_function*)rpc_nwkLeaveRequest,"nwkLeaveRequest"},\
{(rpc_function*)rpc_nwkGetInfo,"nwkGetInfo"},\
{(rpc_function*)rpc_nwkFormCMD,"thing.topo.property.set"},\
{(rpc_function*)rpc_nwkStar,"nwkStar"}\
#endif
#ifndef __RPC_ONOFF_H
#define __RPC_ONOFF_H
#include "RPC_API.h"
EmberStatus WindowCover_UpOpen(uint16_t node,uint8_t ep);
EmberStatus WindowCover_DownClose(uint16_t node,uint8_t ep);
EmberStatus WindowCover_Stop(uint16_t node,uint8_t ep);
EmberStatus WindowCover_GotoLiftPercentage(uint16_t node,uint8_t ep,uint8_t position);
EmberStatus zclOnOff_On(uint16_t node,uint8_t ep);
EmberStatus zclOnOff_Off(uint16_t node,uint8_t ep);
EmberStatus zclOnOff_Toggle(uint16_t node,uint8_t ep);
EmberStatus zclOnOff_OffWithEffect(uint16_t node,uint8_t ep,uint8_t id,uint8_t var);
EmberStatus zclOnOff_OnWithRecallGlobalScene(uint16_t node,uint8_t ep);
EmberStatus zclOnOff_OnWithTimedOff(uint16_t node,uint8_t ep,uint8_t Control,uint16_t OnTime,uint16_t OffWaitTime);
cJSON *rpc_zclOnOff_On(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclOnOff_Off(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclOnOff_Toggle(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclOnOff_OffWithEffect(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclOnOff_OnWithRecallGlobalScene(jrpc_context * ctx, cJSON * params, cJSON *id);
cJSON *rpc_zclOnOff_OnWithTimedOff(jrpc_context * ctx, cJSON * params, cJSON *id);
#define RPC_OnOff_COMMAND_FUNCTION_TABLE \
{rpc_zclOnOff_On,"zclOnOff_On"},\
{rpc_zclOnOff_Off,"zclOnOff_Off"},\
{rpc_zclOnOff_Toggle,"zclOnOff_Toggle"},\
{rpc_zclOnOff_OffWithEffect,"zclOnOff_OffWithEffect"},\
{rpc_zclOnOff_OnWithRecallGlobalScene,"zclOnOff_OnWithRecallGlobalScene"},\
{rpc_zclOnOff_OnWithTimedOff,"zclOnOff_OnWithTimedOff"}\
#endif
#include "RPC_API.h" #include "RPC_API.h"
#include <pthread.h> #include <pthread.h>
#include "kk_ncp_msg.h"
pthread_mutex_t report_mutex_lock; pthread_mutex_t report_mutex_lock;
......
#include "rpc_global_cmd.h"
#include <stdio.h>
/*
void emAfCliSendCommand(uint16_t destination,uint8_t srcEndpoint,uint8_t dstEndpoint)
{
EmberStatus status;
// check that cmd is built
if (zclCmdIsBuilt == false) {
emberAfCorePrintln("no cmd");
return;
}
emAfApsFrameEndpointSetup(srcEndpoint, dstEndpoint);
status = emberAfSendUnicast(EMBER_OUTGOING_DIRECT,
destination,
&globalApsFrame,
appZclBufferLen,
appZclBuffer);
if (status != EMBER_SUCCESS) {
emberAfCorePrintln("Error: CLI Send failed, status: 0x%X", status);
}
emberAfDebugPrintln("T%4x:TX (%p) %ccast 0x%x%p",
emberAfGetCurrentTime(),
"CLI",
label,
status,
((globalApsFrame.options & EMBER_APS_OPTION_ENCRYPTION)
? " w/ link key" : ""));
emberAfDebugPrint("TX buffer: [");
emberAfDebugFlush();
emberAfDebugPrintBuffer(appZclBuffer, appZclBufferLen, true);
emberAfDebugPrintln("]");
emberAfDebugFlush();
zclCmdIsBuilt = false;
mfgSpecificId = EMBER_AF_NULL_MANUFACTURER_CODE;
disableDefaultResponse = 0;
useNextSequence = false;
}*/
cJSON *rpc_zclGRead(jrpc_context * ctx, cJSON * params, cJSON *id)
{
cJSON *item_node;
cJSON *item_srcEP;
cJSON *item_dstEP;
cJSON *item_multicast;
cJSON *item_clu;
cJSON *item_attr;
cJSON *item_svr;
EmberStatus status;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
item_node = cJSON_GetObjectItem(params, "node");
item_srcEP = cJSON_GetObjectItem(params, "srcEP");
item_dstEP = cJSON_GetObjectItem(params, "dstEP");
item_multicast = cJSON_GetObjectItem(params, "multicast");
item_clu = cJSON_GetObjectItem(params, "clu");
item_attr = cJSON_GetObjectItem(params, "attr");
item_svr = cJSON_GetObjectItem(params, "svr");
}
if(item_node==NULL ||
item_srcEP==NULL ||
item_dstEP==NULL ||
item_multicast==NULL ||
item_clu == NULL ||
item_attr == NULL ||
item_svr == NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug("1.....\n");
goto error_return;
}
if(item_node->type!=cJSON_String ||
item_srcEP->type!=cJSON_String ||
item_dstEP->type!=cJSON_String ||
item_clu->type!=cJSON_String ||
item_attr->type!=cJSON_String ||
(item_multicast->type!=cJSON_True &&
item_multicast->type!=cJSON_False)||
(item_svr->type!=cJSON_True &&
item_svr->type!=cJSON_False)){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug(".2....\n");
goto error_return;
}
if(strlen(item_node->valuestring)!=4 ||
strlen(item_srcEP->valuestring)!=2 ||
strlen(item_dstEP->valuestring)!=2 ||
strlen(item_clu->valuestring)!=4 ||
strlen(item_attr->valuestring)!=4){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug("3[%d,%d,%d,%d,%d]\n",strlen(item_node->valuestring),strlen(item_srcEP->valuestring),strlen(item_dstEP->valuestring),strlen(item_clu->valuestring),strlen(item_attr->valuestring));
goto error_return;
}
kk_print_debug("node=%s\n",item_node->valuestring);
kk_print_debug("srcEP=%s\n",item_srcEP->valuestring);
kk_print_debug("dstEP=%s\n",item_dstEP->valuestring);
kk_print_debug("%s multicast\n",(item_multicast->type==cJSON_True)?"":"not ");
kk_print_debug("clu=%s\n",item_clu->valuestring);
kk_print_debug("attr=%s\n",item_attr->valuestring);
kk_print_debug("dir:%s\n",(item_svr->type==cJSON_True)?"client->server":"server->client");
uint16_t node = rpc_get_u16(item_node->valuestring);
uint8_t srcEP = rpc_get_u8(item_srcEP->valuestring);
uint8_t dstEP = rpc_get_u8(item_dstEP->valuestring);
bool multicast = (item_multicast->type==cJSON_True)?true:false;
uint16_t clu = rpc_get_u16(item_clu->valuestring);
uint16_t attr = rpc_get_u16(item_attr->valuestring);
bool svr = (item_svr->type==cJSON_True)?true:false;
kk_print_debug("read clu:0x%04X,attr:0x%04X,type:%s\n",clu,attr,(svr==true)?"client->server":"server->client");
kk_print_debug("target:0x%04X,srcEP=%d,dstEP=%d,type:%s\n",node,srcEP,dstEP,(multicast==true)?"multicast":"not multicast");
status = zclGRead(node,srcEP,dstEP,multicast,clu,attr,svr);
if(status == EMBER_ZCL_STATUS_SUCCESS){
kk_print_debug("send read command suc.");
}else{
kk_print_debug("send read command fail!status=0x%02X\r\n",status);
}
rpc_cJSON_CreateNumber(status);
error_return:
return rpc_cJSON_CreateNull();
}
#include "RPC_API.h"
#include "rpc_onoff.h"
cJSON *rpc_zclOnOff_On(jrpc_context * ctx, cJSON * params, cJSON *id)
{
cJSON *item_node;
cJSON *item_ep;
EmberStatus status;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
item_node = cJSON_GetObjectItem(params, "node");
item_ep = cJSON_GetObjectItem(params, "dstEP");
}
if(item_node==NULL ||
item_ep==NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug("1.....\n");
goto error_return;
}
if(item_node->type!=cJSON_String ||
item_ep->type!=cJSON_String){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug(".2....\n");
goto error_return;
}
kk_print_debug("node=%s\n",item_node->valuestring);
kk_print_debug("dstEP=%s\n",item_ep->valuestring);
uint16_t node = rpc_get_u16(item_node->valuestring);
uint8_t ep = rpc_get_u8(item_ep->valuestring);
status = zclOnOff_On(node,ep);
if(status == EMBER_ZCL_STATUS_SUCCESS){
kk_print_debug("send suc.");
}else{
kk_print_debug("send fail!status=0x%02X\r\n",status);
}
return rpc_cJSON_CreateNumber(status);
error_return:
return rpc_cJSON_CreateNull();
}
cJSON *rpc_zclOnOff_Off(jrpc_context * ctx, cJSON * params, cJSON *id)
{
cJSON *item_node;
cJSON *item_ep;
EmberStatus status;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
item_node = cJSON_GetObjectItem(params, "node");
item_ep = cJSON_GetObjectItem(params, "dstEP");
}
if(item_node==NULL ||
item_ep==NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug("1.....\n");
goto error_return;
}
if(item_node->type!=cJSON_String ||
item_ep->type!=cJSON_String){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug(".2....\n");
goto error_return;
}
kk_print_debug("node=%s\n",item_node->valuestring);
kk_print_debug("dstEP=%s\n",item_ep->valuestring);
uint16_t node = rpc_get_u16(item_node->valuestring);
uint8_t ep = rpc_get_u8(item_ep->valuestring);
status = zclOnOff_Off(node,ep);
if(status == EMBER_ZCL_STATUS_SUCCESS){
kk_print_debug("send suc.");
}else{
kk_print_debug("send fail!status=0x%02X\r\n",status);
}
return rpc_cJSON_CreateNumber(status);
error_return:
return rpc_cJSON_CreateNull();
}
cJSON *rpc_zclOnOff_Toggle(jrpc_context * ctx, cJSON * params, cJSON *id)
{
cJSON *item_node;
cJSON *item_ep;
EmberStatus status;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
item_node = cJSON_GetObjectItem(params, "node");
item_ep = cJSON_GetObjectItem(params, "dstEP");
}
if(item_node==NULL ||
item_ep==NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug("1.....\n");
goto error_return;
}
if(item_node->type!=cJSON_String ||
item_ep->type!=cJSON_String){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug(".2....\n");
goto error_return;
}
kk_print_debug("node=%s\n",item_node->valuestring);
kk_print_debug("dstEP=%s\n",item_ep->valuestring);
uint16_t node = rpc_get_u16(item_node->valuestring);
uint8_t ep = rpc_get_u8(item_ep->valuestring);
status = zclOnOff_Toggle(node,ep);
if(status == EMBER_ZCL_STATUS_SUCCESS){
kk_print_debug("send suc.");
}else{
kk_print_debug("send fail!status=0x%02X\r\n",status);
}
return rpc_cJSON_CreateNumber(status);
error_return:
return rpc_cJSON_CreateNull();
}
cJSON *rpc_zclOnOff_OffWithEffect(jrpc_context * ctx, cJSON * params, cJSON *id)
{
cJSON *item_node;
cJSON *item_ep;
cJSON *item_id;
cJSON *item_var;
EmberStatus status;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
item_node = cJSON_GetObjectItem(params, "node");
item_ep = cJSON_GetObjectItem(params, "dstEP");
item_id = cJSON_GetObjectItem(params, "identifier");
item_var = cJSON_GetObjectItem(params, "variant");
}
if(item_node==NULL ||
item_ep==NULL ||
item_id ==NULL ||
item_var == NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug("1.....\n");
goto error_return;
}
if(item_node->type!=cJSON_String ||
item_ep->type!=cJSON_String||
item_id->type!=cJSON_String||
item_var->type!=cJSON_String){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug(".2....\n");
goto error_return;
}
kk_print_debug("node=%s\n",item_node->valuestring);
kk_print_debug("dstEP=%s\n",item_ep->valuestring);
kk_print_debug("identifier=%s\n",item_id->valuestring);
kk_print_debug("variant=%s\n",item_var->valuestring);
uint16_t node = rpc_get_u16(item_node->valuestring);
uint8_t ep = rpc_get_u8(item_ep->valuestring);
uint8_t identifier = rpc_get_u8(item_id->valuestring);
uint8_t var = rpc_get_u8(item_var->valuestring);
status = zclOnOff_OffWithEffect(node,ep,identifier,var);
if(status == EMBER_ZCL_STATUS_SUCCESS){
kk_print_debug("send suc.");
}else{
kk_print_debug("send fail!status=0x%02X\r\n",status);
}
return rpc_cJSON_CreateNumber(status);
error_return:
return rpc_cJSON_CreateNull();
}
cJSON *rpc_zclOnOff_OnWithRecallGlobalScene(jrpc_context * ctx, cJSON * params, cJSON *id)
{
cJSON *item_node;
cJSON *item_ep;
EmberStatus status;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
item_node = cJSON_GetObjectItem(params, "node");
item_ep = cJSON_GetObjectItem(params, "dstEP");
}
if(item_node==NULL ||
item_ep==NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug("1.....\n");
goto error_return;
}
if(item_node->type!=cJSON_String ||
item_ep->type!=cJSON_String){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug(".2....\n");
goto error_return;
}
kk_print_debug("node=%s\n",item_node->valuestring);
kk_print_debug("dstEP=%s\n",item_ep->valuestring);
uint16_t node = rpc_get_u16(item_node->valuestring);
uint8_t ep = rpc_get_u8(item_ep->valuestring);
status = zclOnOff_OnWithRecallGlobalScene(node,ep);
if(status == EMBER_ZCL_STATUS_SUCCESS){
kk_print_debug("send suc.");
}else{
kk_print_debug("send fail!status=0x%02X\r\n",status);
}
return rpc_cJSON_CreateNumber(status);
error_return:
return rpc_cJSON_CreateNull();
}
cJSON *rpc_zclOnOff_OnWithTimedOff(jrpc_context * ctx, cJSON * params, cJSON *id)
{
cJSON *item_node;
cJSON *item_ep;
cJSON *item_control;
cJSON *item_OnTime;
cJSON *item_OffWaitTime;
EmberStatus status;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
item_node = cJSON_GetObjectItem(params, "node");
item_ep = cJSON_GetObjectItem(params, "dstEP");
item_control = cJSON_GetObjectItem(params, "control");
item_OnTime = cJSON_GetObjectItem(params, "OnTime");
item_OffWaitTime = cJSON_GetObjectItem(params, "OffWaitTime");
}
if(item_node==NULL ||
item_ep==NULL ||
item_control ==NULL ||
item_OnTime == NULL||
item_OffWaitTime== NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug("1.....\n");
goto error_return;
}
if(item_node->type!=cJSON_String ||
item_ep->type!=cJSON_String||
item_control->type!=cJSON_String||
item_OnTime->type!=cJSON_String||
item_OffWaitTime->type!=cJSON_String){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
kk_print_debug(".2....\n");
goto error_return;
}
kk_print_debug("node=%s\n",item_node->valuestring);
kk_print_debug("dstEP=%s\n",item_ep->valuestring);
kk_print_debug("control=%s\n",item_control->valuestring);
kk_print_debug("OnTime=%s\n",item_OnTime->valuestring);
kk_print_debug("OffWaitTime=%s\n",item_OffWaitTime->valuestring);
uint16_t node = rpc_get_u16(item_node->valuestring);
uint8_t ep = rpc_get_u8(item_ep->valuestring);
uint8_t control = rpc_get_u8(item_control->valuestring);
uint16_t OnTime = rpc_get_u16(item_OnTime->valuestring);
uint16_t OffWaitTime = rpc_get_u16(item_OffWaitTime->valuestring);
status = zclOnOff_OnWithTimedOff(node,ep,control,OnTime,OffWaitTime);
if(status == EMBER_ZCL_STATUS_SUCCESS){
kk_print_debug("send suc.");
}else{
kk_print_debug("send fail!status=0x%02X\r\n",status);
}
return rpc_cJSON_CreateNumber(status);
error_return:
return rpc_cJSON_CreateNull();
}
...@@ -96,6 +96,104 @@ extern void kk_ota_test111(); ...@@ -96,6 +96,104 @@ extern void kk_ota_test111();
extern void kk_ota_test123123123(); extern void kk_ota_test123123123();
extern void aaaBBB(); extern void aaaBBB();
extern void kk_tsl_msg_ack(const char * id,const char *ackMsgType,const char *productCode,const char *deviceCode); extern void kk_tsl_msg_ack(const char * id,const char *ackMsgType,const char *productCode,const char *deviceCode);
extern void TEST2(void);
char aaaaaaaaaa[]="{\
\"info\": {\
\"msgtype\": \"/thing/service/property/get\",\
\"productCode\": \"3003\",\
\"deviceCode\": \"1122334455667788\"\
\},\
\"payload\": {\
\"msgId\": \"11\",\
\"version\": \"1.0\",\
\"params\": {\
\"identifier\": [\"PowerSwitch_1\", \"PowerSwitch_2\", \"PowerSwitch_3\"]\
},\
\"time\": \"1603359090\",\
\"method\": \"thing.service.property.get\"\
}\
}";
void TEST2(void)
{
_cb(aaaaaaaaaa,strlen(aaaaaaaaaa),NULL);
/*
char *ptr;
cJSON *root = rpc_cJSON_CreateObject();
cJSON *info = rpc_cJSON_CreateObject();
cJSON *payload = rpc_cJSON_CreateObject();
cJSON *params = rpc_cJSON_CreateObject();
cJSON *array = rpc_cJSON_CreateArray();
rpc_cJSON_AddItemToObject(root, "info", info);
rpc_cJSON_AddItemToObject(root, "payload", payload);
rpc_cJSON_AddStringToObject(info, "msgtype","/thing/service/property/get");
rpc_cJSON_AddStringToObject(info, "productCode","83");
rpc_cJSON_AddStringToObject(info, "deviceCode","1023");
rpc_cJSON_AddStringToObject(payload, "msgId","123");
rpc_cJSON_AddStringToObject(payload, "version","1.0");
rpc_cJSON_AddItemToObject(payload, "params", params);
rpc_cJSON_AddItemToObject(params, "identifier", array);
rpc_cJSON_AddItemToArray(array,rpc_cJSON_CreateString("PowerSwitch_1"));
rpc_cJSON_AddItemToArray(array,rpc_cJSON_CreateString("PowerSwitch_2"));
rpc_cJSON_AddItemToArray(array,rpc_cJSON_CreateString("PowerSwitch_3"));
rpc_cJSON_AddStringToObject(root, "method","thing.service.property.get");
ptr = rpc_cJSON_Print(root);
printf("--->%s\n",ptr);
free(ptr);
ncp_queue_enqueue(REV_MSG,(void *)root);
*/
}
extern struct jrpc_server *kk_get_jrpc_server(void);
void aaaBBB()
{
struct jrpc_server *server = kk_get_jrpc_server();
char *ptr;
const char *strings[3]={"PowerSwitch_1","PowerSwitch_2","PowerSwitch_3"};
cJSON *params = rpc_cJSON_CreateObject();
cJSON *id = rpc_cJSON_CreateObject();
cJSON *mac = rpc_cJSON_CreateObject();
cJSON *array = rpc_cJSON_CreateArray();
rpc_cJSON_AddItemToArray(array,rpc_cJSON_CreateString("PowerSwitch_1"));
rpc_cJSON_AddItemToArray(array,rpc_cJSON_CreateString("PowerSwitch_2"));
rpc_cJSON_AddItemToArray(array,rpc_cJSON_CreateString("PowerSwitch_3"));
rpc_cJSON_AddItemToObject(params, "identifier", array);
rpc_cJSON_AddStringToObject(id, "msgId","123");
rpc_cJSON_AddStringToObject(mac, "mac","1122334455667788");
ptr = rpc_cJSON_Print(params);
printf("params--->%s\n",ptr);
free(ptr);
ptr = rpc_cJSON_Print(id);
printf("id--->%s\n",ptr);
free(ptr);
ptr = rpc_cJSON_Print(mac);
mac = cJSON_GetObjectItem(mac, "mac");
printf("mac--->%s,%s\n",ptr,mac->valuestring);
free(ptr);
kk_tsl_get_property_operation(server, params,id,mac);
}
void kk_message_process(char *messageString) void kk_message_process(char *messageString)
{ {
...@@ -118,7 +216,7 @@ void kk_message_process(char *messageString) ...@@ -118,7 +216,7 @@ void kk_message_process(char *messageString)
} }
if(MEMCOMPARE(messageString,"AT+TEST1\r\n",len)==0){ if(MEMCOMPARE(messageString,"AT+TEST1\r\n",len)==0){
kk_ota_test123123123(); TEST2();
} }
if(MEMCOMPARE(messageString,"AT+TEST\r\n",len)==0){ if(MEMCOMPARE(messageString,"AT+TEST\r\n",len)==0){
aaaBBB(); aaaBBB();
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "app/util/serial/command-interpreter2.h" #include "app/util/serial/command-interpreter2.h"
#include "app/util/zigbee-framework/zigbee-device-common.h" #include "app/util/zigbee-framework/zigbee-device-common.h"
#include "network-cli.h" #include "network-cli.h"
#include "kk_zb_com.h" #include "kk_ncp_common.h"
#define emberAfAppPrint(...) emberAfPrint(EMBER_AF_PRINT_APP, __VA_ARGS__) #define emberAfAppPrint(...) emberAfPrint(EMBER_AF_PRINT_APP, __VA_ARGS__)
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "app/framework/plugin/device-table/device-table-internal.h" #include "app/framework/plugin/device-table/device-table-internal.h"
#include "app/framework/util/util.h" #include "app/framework/util/util.h"
#include <stdlib.h> #include <stdlib.h>
#include <kk_test.h>
void emAfDeviceTableSave(void); void emAfDeviceTableSave(void);
......
...@@ -46,11 +46,10 @@ ...@@ -46,11 +46,10 @@
#include "afv2-bookkeeping.h" #include "afv2-bookkeeping.h"
#include "yjq_ezsp.h" #include "yjq_ezsp.h"
#include "./rpc_api/inc/rpc_interface_parse.h"
#include <pthread.h> #include <pthread.h>
#include <fcntl.h> #include <fcntl.h>
#include "kk_ncp_common.h"
pthread_mutex_t g_mutex_lock; pthread_mutex_t g_mutex_lock;
...@@ -564,13 +563,6 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS) ...@@ -564,13 +563,6 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
return -1; return -1;
} }
/*int pid=fork();
if(pid==0){
rpcInterfaceParse();
}*/
emberAfCoreFlush(); emberAfCoreFlush();
...@@ -595,11 +587,9 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS) ...@@ -595,11 +587,9 @@ int emberAfMain(MAIN_FUNCTION_PARAMETERS)
kk_topo_batch_handle_init(); kk_topo_batch_handle_init();
kk_device_gateway_add(eui64); kk_device_gateway_add(eui64);
pthread_t tid;
pthread_t prey_tid;
//pthread_create(&tid, NULL, rpcInterfaceParse, NULL); kk_thread_init();
pthread_create(&tid, NULL, ipcHandle, NULL);
pthread_create(&prey_tid, NULL, ncp_queue_handle, NULL);
// initialize the ZCL framework ,(plug in) ,mqtt init is here // initialize the ZCL framework ,(plug in) ,mqtt init is here
emAfInit(); emAfInit();
......
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