Commit 86e4b066 authored by chen.weican's avatar chen.weican

【修改内容】修改CCUID获取方式

【提交人】陈伟灿
parent 5336a238
......@@ -27,7 +27,32 @@
#include "com_api.h"
#include "kk_product.h"
//#include "kcloud_log.h"
static char s_ccuid[DEVICE_CODE_LEN] = {0};
int KK_Get_ccuid(_OU_ char *device_code)
{
strncpy(device_code, s_ccuid, strlen(s_ccuid));
printf("HAL_Get_ccuid:%s\n",s_ccuid);
return strlen(s_ccuid);
}
static int _setDevice_Code(_IN_ char *device_code,int len)
{
memset(s_ccuid, 0x0, DEVICE_CODE_LEN);
printf("_setDevice_Code:%s\n",device_code);
strncpy(s_ccuid, device_code, len);
return len;
}
static void KK_Ccuid_init(void)
{
uint8_t ccuid[DEVICE_CODE_LEN] = {0};
int ccuid_len = 0;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len);
printf("GET_CCUID_CMD:%s\n",ccuid);
if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){
_setDevice_Code(ccuid,ccuid_len-1);
}else{
_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
}
}
static int mqtt_start(void)
{
int count = 0;
......@@ -63,6 +88,7 @@ int main(int argc, char* argv[])
int rc = 0;
open("kcloud",LOG_PID,LOG_USER);
/*set the callback to get the device date to cloud*/
KK_Ccuid_init();
kk_ipc_init(IPC_APP2MID,(ipc_cb*)KK_Data_FromDev,NULL,NULL);
kk_info_report_start();
again:
......
......@@ -46,7 +46,7 @@ static int kk_info_get(char *str)
}
HAL_GetVersion(version);
memcpy(ccuid,KK_CCU_ID,strlen(KK_CCU_ID));
KK_Get_ccuid(ccuid);
cJSON *root = cJSON_CreateObject();
if (root)
{
......
......@@ -20,27 +20,7 @@
#define BUFSIZE 1024
#define PRODUCTSECRET "123456"
int kk_execel_cmd(char * cmd,char * buf,int buf_len,int* ret_len)
{
if(cmd == NULL || buf == NULL || buf_len == 0)
{
printf("arg error\n");
return -1;
}
memset(buf,0,buf_len);
FILE *fp = NULL;
fp = popen(cmd,"r");
while(fgets(buf,buf_len,fp)!=NULL){
printf("%s return %s",cmd,buf);
}
pclose (fp);
*ret_len = strlen(buf);
return 0;
}
int kk_parse_deviceSecret(char *info){
FILE *fp;
if(info == NULL){
......@@ -205,14 +185,16 @@ static char * kk_create_register_info()
unsigned char sign_hex[32] = {0};
char sign_hex_str[65] = {0};
uint8_t productSecret[64] = {0};
char ccuid[32] = {0};
int productSecret_len = 0;
root=cJSON_CreateObject();
HAL_Get_mac(mac);
HAL_GetTime_s(ramdonId);
cJSON_AddStringToObject(root, "deviceCode", KK_CCU_ID);
KK_Get_ccuid(ccuid);
cJSON_AddStringToObject(root, "deviceCode", ccuid);
cJSON_AddStringToObject(root, "productCode",productCode);
signSource = kk_dictionary_order(KK_CCU_ID,productCode,KK_CCU_RANDOM);
kk_execel_cmd(GET_KEY_CMD,(char *)productSecret,sizeof(productSecret),&productSecret_len);
signSource = kk_dictionary_order(ccuid,productCode,KK_CCU_RANDOM);
HAL_Execel_cmd(GET_KEY_CMD,(char *)productSecret,sizeof(productSecret),&productSecret_len);
if(productSecret_len == 0){
utils_hmac_sha256((const uint8_t *)signSource, strlen(signSource), (const uint8_t *)PRODUCTSECRET, strlen(PRODUCTSECRET), sign_hex);
}else{
......@@ -247,10 +229,12 @@ static char * kk_create_get_jwt_info()
char *out = NULL;
char timestamp[16] = {0};
char deviceSecret[64] = {0};
char ccuid[32] = {0};
HAL_GetTime_s(timestamp);
sprintf(g_clientId, CLIENTID, KK_CCU_ID,timestamp);
KK_Get_ccuid(ccuid);
sprintf(g_clientId, CLIENTID, ccuid,timestamp);
root=cJSON_CreateObject();
cJSON_AddStringToObject(root, "deviceCode", KK_CCU_ID);
cJSON_AddStringToObject(root, "deviceCode", ccuid);
cJSON_AddStringToObject(root, "productCode",KK_CCU_PRODUCTID);
cJSON_AddStringToObject(root, "clientId",g_clientId);
fp = fopen("/usr/kk/kk_deviceSecret.txt", "r");
......
......@@ -115,10 +115,12 @@ int KK_CCU_TOPIC_Subscribe(void)
INFO_PRINT("[%s][%d] already Subscribe\n",__FUNCTION__,__LINE__);
return -1;
}
char ccuid[32] = {0};
KK_Get_ccuid(ccuid);
s_ccu_topic_sub = 1;
HAL_GetProduct_Code(productCode);
HAL_Get_mac(deviceCode);
return _kk_ccu_topic_subscribe(productCode,KK_CCU_ID);
return _kk_ccu_topic_subscribe(productCode,ccuid);
}
static int _kk_utils_topic(_IN_ const char *name, _IN_ char *product_code,
......
......@@ -206,7 +206,9 @@ MQTTAsync KK_MQTT_Connect(void)
fclose(fp);
}
HAL_Get_mac(mac);
sprintf(usrname, "%s.%s", KK_CCU_ID,KK_CCU_PRODUCTID);
char ccuid[32] = {0};
KK_Get_ccuid(ccuid);
sprintf(usrname, "%s.%s", ccuid,KK_CCU_PRODUCTID);
printf("cliendid:%s,usrname:%s\n",g_clientId,usrname);
printf("------------>token:%s\n",token);
if ((rc = MQTTAsync_createWithOptions(&s_Client, ADDRESS, g_clientId, MQTTCLIENT_PERSISTENCE_NONE, NULL,&opts)) != MQTTASYNC_SUCCESS)
......
......@@ -176,9 +176,11 @@ static int kk_loginccu_ack(cJSON *arg,int sockfd)
if(arg == NULL){
return -1;
}
char ccuid[32] = {0};
kk_lan_get_ccuid(ccuid);
zkid = cJSON_GetObjectItem(arg, ZKID_STRING);
if(zkid != NULL){
if(strstr(KK_CCU_ID,zkid->valuestring) != NULL){
if(strstr(ccuid,zkid->valuestring) != NULL){
root=cJSON_CreateObject();
if(root){
args = cJSON_CreateObject();
......
......@@ -26,12 +26,14 @@ static int kk_findccu_ack(int sockfd,struct sockaddr_in *addr){
if(addr == NULL || sockfd < 0){
return -1;
}
char ccuid[32] = {0};
kk_lan_get_ccuid(ccuid);
json=cJSON_CreateObject();
if(json){
args = cJSON_CreateObject();
if(args){
cJSON_AddItemToObject(json, "arg", args);
cJSON_AddStringToObject(args, "zkid", KK_CCU_ID);
cJSON_AddStringToObject(args, "zkid", ccuid);
cJSON_AddStringToObject(args, "zk", KK_CCU_NAME);
HAL_Get_IP(s_IP,NULL);
cJSON_AddStringToObject(args, "ip", s_IP);
......
......@@ -28,7 +28,32 @@
//#include "kk_lan_queue.h"
#include "kk_lan_node_db.h"
static char s_ccuid[DEVICE_CODE_LEN] = {0};
int kk_lan_get_ccuid(_OU_ char *device_code)
{
strncpy(device_code, s_ccuid, strlen(s_ccuid));
printf("kk_lan_get_ccuid:%s\n",s_ccuid);
return strlen(s_ccuid);
}
static int _setDevice_Code(_IN_ char *device_code,int len)
{
memset(s_ccuid, 0x0, DEVICE_CODE_LEN);
printf("_setDevice_Code:%s\n",device_code);
strncpy(s_ccuid, device_code, len);
return len;
}
static void kk_lan_ccuid_init(void)
{
uint8_t ccuid[DEVICE_CODE_LEN] = {0};
int ccuid_len = 0;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len);
printf("GET_CCUID_CMD:%s\n",ccuid);
if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){
_setDevice_Code(ccuid,ccuid_len-1);
}else{
_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
}
}
static void sig_handler(int sig)
{
printf("Received signal: %d\n", sig);
......@@ -44,6 +69,7 @@ int main(int argc, char* argv[])
int rc = 0;
char *ppp;
open("kk_lan",LOG_PID,LOG_USER);
kk_lan_ccuid_init();
ttttt_test();
kk_scene_build_test();
/*set the callback to get the device date to cloud*/
......
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