Commit 2fd1e197 authored by chen.weican's avatar chen.weican

【修改内容】1,增加oled的应用

【提交人】陈伟灿
parent 344cd961
LIBA_TARGET := libiot_kcloud.a LIBA_TARGET := libiot_kcloud.a
$(call Append_Conditional, LIB_SRCS_EXCLUDE, kcloud_main.c) $(call Append_Conditional, LIB_SRCS_EXCLUDE, kcloud_main.c)
$(call Append_Conditional, SRCS_kcloud, kcloud_main.c) $(call Append_Conditional, SRCS_kk_cloud, kcloud_main.c)
$(call Append_Conditional, TARGET, kcloud) $(call Append_Conditional, TARGET, kk_cloud)
CFLAGS += -I$(TOP_DIR)/common/api CFLAGS += -I$(TOP_DIR)/common/api
CFLAGS += -I$(TOP_DIR)/common/json CFLAGS += -I$(TOP_DIR)/common/json
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#ifndef MQTT_CONF_H_ #ifndef MQTT_CONF_H_
#define MQTT_CONF_H_ #define MQTT_CONF_H_
#define ADDRESS "tcp://172.25.240.31:1983" #define ADDRESS "tcp://172.25.240.199:1883"//"tcp://172.25.240.31:1983"////
#define CLIENTID "kk_%s" #define CLIENTID "CCU.%s.%s"
#define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/thing/service/property/set" #define TOPIC "/sys/a1OYuSBt23u/aIqEbWno8yDdsjCX15iq/thing/service/property/set"
#define PAYLOAD "Hello cwc World!" #define PAYLOAD "Hello cwc World!"
......
...@@ -55,10 +55,12 @@ const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\" ...@@ -55,10 +55,12 @@ const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"
static char *s_split_product[] = { static char *s_split_product[] = {
"85", //三路面板 "3002", //星辰系列双路面板
"97", //双路面板 "3003", //星辰系列三路面板
"98" //三路面板 "3010", //铂金系列双路面板
"3011", //铂金系列三路面板
"3023", //肖邦系列双路面板
"3024" //肖邦系列三路面板
}; };
/************************************************************ /************************************************************
*功能描述:灯控面板需要分开上报属性 *功能描述:灯控面板需要分开上报属性
...@@ -75,7 +77,6 @@ static int kk_check_need_split(cJSON * info) ...@@ -75,7 +77,6 @@ static int kk_check_need_split(cJSON * info)
int i = 0; int i = 0;
int num = sizeof(s_split_product)/sizeof(char*); int num = sizeof(s_split_product)/sizeof(char*);
if(info == NULL){ if(info == NULL){
return 0; return 0;
} }
...@@ -215,7 +216,6 @@ int _kk_sendto_cloud(cJSON *root) ...@@ -215,7 +216,6 @@ int _kk_sendto_cloud(cJSON *root)
KK_Send_CloudState(kk_get_cloud_status()); KK_Send_CloudState(kk_get_cloud_status());
free(topic); free(topic);
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
if(kk_check_need_split(info)){ if(kk_check_need_split(info)){
kk_split_send_data(pData,topic); kk_split_send_data(pData,topic);
...@@ -432,6 +432,10 @@ static char * _kk_data_create(const char *topic,const char *data) ...@@ -432,6 +432,10 @@ static char * _kk_data_create(const char *topic,const char *data)
char * msgStr = NULL; char * msgStr = NULL;
res =_kk_topic_parse_pkdn((char *)topic,3,productCode,deviceCode); res =_kk_topic_parse_pkdn((char *)topic,3,productCode,deviceCode);
//if(!strcmp("gateway_2",productCode)){
//memset(productCode,0x0,sizeof(productCode));
//memcpy(productCode,"2",strlen("2"));
//}
res|=_kk_topic_parse_msgType((char *)topic,5,&msgStr); res|=_kk_topic_parse_msgType((char *)topic,5,&msgStr);
infoStr_len = strlen(DM_MSG_TO_MIDDWARE)+strlen(productCode)+strlen(deviceCode)+strlen(msgStr)+10; infoStr_len = strlen(DM_MSG_TO_MIDDWARE)+strlen(productCode)+strlen(deviceCode)+strlen(msgStr)+10;
infoStr = malloc(infoStr_len); infoStr = malloc(infoStr_len);
...@@ -520,7 +524,6 @@ int KK_Send_CloudState(int state) ...@@ -520,7 +524,6 @@ int KK_Send_CloudState(int state)
*返 回 值: 无 *返 回 值: 无
*其他说明: *其他说明:
*************************************************************/ *************************************************************/
void KK_Sendto_DevData(const char *topic,const char *data) void KK_Sendto_DevData(const char *topic,const char *data)
{ {
if(_check_invalid_topic(topic)) if(_check_invalid_topic(topic))
......
...@@ -34,12 +34,6 @@ static int mqtt_start(void) ...@@ -34,12 +34,6 @@ static int mqtt_start(void)
{ {
WARNING_PRINT("KK_MQTT_Connect FAIL!!!\n"); WARNING_PRINT("KK_MQTT_Connect FAIL!!!\n");
} }
else
{
INFO_PRINT("Waiting for publication of %s\n"
"on topic %s for client with ClientID: %s\n",
PAYLOAD, TOPIC, CLIENTID);
}
while(1) while(1)
{ {
usleep(100000L); usleep(100000L);
...@@ -58,7 +52,7 @@ static int mqtt_start(void) ...@@ -58,7 +52,7 @@ static int mqtt_start(void)
return rc; return rc;
} }
extern int kk_info_report_start(void);
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int rc = 0; int rc = 0;
...@@ -66,8 +60,14 @@ int main(int argc, char* argv[]) ...@@ -66,8 +60,14 @@ int main(int argc, char* argv[])
open("kcloud",LOG_PID,LOG_USER); open("kcloud",LOG_PID,LOG_USER);
/*set the callback to get the device date to cloud*/ /*set the callback to get the device date to cloud*/
kk_ipc_init(IPC_APP2MID,KK_Data_FromDev,NULL,NULL); kk_ipc_init(IPC_APP2MID,KK_Data_FromDev,NULL,NULL);
kk_info_report_start();
again:
rc = kk_start_ccu_register();
if(rc == 0){
rc = mqtt_start(); rc = mqtt_start();
}else{
goto again;
}
return rc; return rc;
} }
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include "cJSON.h"
#include "com_api.h"
#include "kk_product.h"
#include "kk_log.h"
static pthread_mutex_t s_data_mutex;
#define TO_OLED_NANOMSG_SOCKET_ADDR "ipc:///tmp/oled_pair.ipc"
static int kk_info_nanomsg_init(void)
{
int socketfd = 0;
socketfd = nn_socket(AF_SP, NN_PAIR);
if(socketfd < 0){
return -1;
}
if(nn_connect(socketfd, TO_OLED_NANOMSG_SOCKET_ADDR) < 0){
WARNING_PRINT("[%s][%d]connect fail!!!\n",__FUNCTION__,__LINE__);
return -1;
}
return socketfd;
}
static int kk_info_get(char *str)
{
int ret = 0;
char version[VERSION_MAXLEN] = {0};
char *str_tmp = NULL;
if(str == NULL){
return -1;
}
HAL_GetVersion(version);
cJSON *root = cJSON_CreateObject();
if (root)
{
cJSON *args = cJSON_CreateObject();
if (args)
{
cJSON_AddItemToObject(root, "args", args);
cJSON *ccu = cJSON_CreateObject();
if (ccu)
{
char status[4] = {0};
cJSON_AddItemToObject(args, "ccu", ccu);
cJSON_AddStringToObject(ccu, "id", "12345");
cJSON_AddStringToObject(ccu, "version", version);
cJSON_AddStringToObject(ccu, "name", "kk_new_ccu");
if(kk_get_gw_status() == DEVICE_OFFLINE){
strcpy(status,"2");
}
else if(kk_get_cloud_status() == DEVICE_OFFLINE){
//cJSON_AddStringToObject(ccu, "status", "1");
strcpy(status,"1");
}else{
strcpy(status,"0");
}
cJSON_AddStringToObject(ccu, "status", status);
}
cJSON *net = cJSON_CreateObject();
if (net)
{
char s_IP[NETWORK_ADDR_LEN] = {0};
HAL_Get_IP(s_IP,NULL);
cJSON_AddItemToObject(args, "net", net);
cJSON_AddStringToObject(net, "interface", CCU_LAN);
cJSON_AddStringToObject(net, "ip", s_IP);
}
cJSON *lsc_status = cJSON_CreateObject();
if (lsc_status)
{
cJSON_AddStringToObject(args, "lsc_status", "1");
}
cJSON *qr_code = cJSON_CreateObject();
if (qr_code)
{
cJSON_AddItemToObject(args, "qr_code", qr_code);
cJSON_AddStringToObject(qr_code, "string", "KONKE-CCU:15:95972:E53AC78A40C4EBD4ABFFA1009794641B");
cJSON_AddBoolToObject(qr_code, "show", 1);
}
cJSON *service = cJSON_CreateObject();
if (service)
{
cJSON_AddStringToObject(args, "service", "1");
}
}
str_tmp = cJSON_PrintUnformatted(root);
INFO_PRINT("JSON %s\r\n", str_tmp);
strcpy(str, str_tmp);
free(str_tmp);
cJSON_Delete(root);
}
else
{
ret = -1;
}
return ret;
}
//static int
void *kk_info_nanomsg_send(void *data)
{
int ret = 0;
char str[1024] = {0};
int socketfd = kk_info_nanomsg_init();
if(socketfd < 0){
return NULL;
}
while(1){
memset(str,0x0,sizeof(str));
ret = kk_info_get(str);
if(ret == 0){
printf("*********nn_send***********\n");
ret = nn_send(socketfd, str, strlen(str), 1);
if(ret < 0) {
WARNING_PRINT("[%s][%d]nn_send fail!!!\n",__FUNCTION__,__LINE__);
}
}
sleep(10);
}
}
int kk_info_report_start(void)
{
void *status;
int rc;
pthread_t info_report_thread;
pthread_attr_t info_report_attr;
pthread_mutex_init(&s_data_mutex, NULL);
/*创建线程*/
pthread_attr_init(&info_report_attr);
size_t s = 1500;
pthread_attr_setstacksize(&info_report_attr, s);
pthread_attr_setdetachstate(&info_report_attr, PTHREAD_CREATE_JOINABLE);
rc = pthread_create(&info_report_thread, &info_report_attr, kk_info_nanomsg_send, (void *)NULL); //收数据
if (rc)
{
WARNING_PRINT("Error : unable to create thread udp_recv \r\n");
return -1;
}
pthread_attr_destroy(&info_report_attr);
return 0;
}
\ No newline at end of file
This diff is collapsed.
...@@ -8,14 +8,23 @@ ...@@ -8,14 +8,23 @@
#include "kk_log.h" #include "kk_log.h"
const char KK_URI_SYS_PREFIX[] = "/sys/kk/%s/%s/#"; const char KK_URI_SYS_PREFIX[] = "/sys/kk/%s/%s/thing/service/property/set";
const char KK_URI_SYS_PREFIX_SERVICE[] = "/sys/kk/%s/%s/thing/service/+";
const char KK_URI_SYS_PREFIX_TOPO_CHANGE[] = "/sys/kk/%s/%s/thing/topo/change";
const char KK_URI_SYS_PREFIX_EX[] = "/sys/kk/%s/%s"; const char KK_URI_SYS_PREFIX_EX[] = "/sys/kk/%s/%s";
const char KK_URI_OTA_PREFIX[] = "/ota/device/upgrade/kk/%s/%s/#"; const char KK_URI_OTA_PREFIX[] = "/ota/device/upgrade/kk/%s/%s/#";
const char KK_URI_OTA_PROCESS[] = "/ota/device/progress/%s/%s"; const char KK_URI_OTA_PROCESS[] = "/ota/device/progress/%s/%s";
const char KK_URI_OTA_INFORM[] = "/ota/device/inform/%s/%s"; const char KK_URI_OTA_INFORM[] = "/ota/device/inform/%s/%s";
static int s_gw_status = DEVICE_OFFLINE;
int kk_set_gw_status(int status)
{
s_gw_status = status;
}
int kk_get_gw_status(void)
{
return s_gw_status;
}
int KK_Subdev_Subscribe(const cJSON *root) int KK_Subdev_Subscribe(const cJSON *root)
{ {
int res = 0; int res = 0;
...@@ -37,7 +46,7 @@ int KK_Subdev_Subscribe(const cJSON *root) ...@@ -37,7 +46,7 @@ int KK_Subdev_Subscribe(const cJSON *root)
if(productCode == NULL){ if(productCode == NULL){
return -1; return -1;
} }
url_len = strlen(KK_URI_OTA_PREFIX) + strlen(productCode->valuestring) + strlen(deviceCode->valuestring) + 1; url_len = strlen(KK_URI_SYS_PREFIX) + strlen(productCode->valuestring) + strlen(deviceCode->valuestring) + 1;
char *url = malloc(url_len); char *url = malloc(url_len);
if (url == NULL) { if (url == NULL) {
return -1; return -1;
...@@ -52,6 +61,14 @@ int KK_Subdev_Subscribe(const cJSON *root) ...@@ -52,6 +61,14 @@ int KK_Subdev_Subscribe(const cJSON *root)
snprintf(url, url_len, KK_URI_SYS_PREFIX, productCode->valuestring, deviceCode->valuestring); snprintf(url, url_len, KK_URI_SYS_PREFIX, productCode->valuestring, deviceCode->valuestring);
INFO_PRINT("sys [%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url); INFO_PRINT("sys [%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url);
res = KK_MQTT_SubTopic(url); res = KK_MQTT_SubTopic(url);
memset(url, 0, url_len);
snprintf(url, url_len, KK_URI_SYS_PREFIX_SERVICE, productCode->valuestring, deviceCode->valuestring);
INFO_PRINT("sys [%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url);
res = KK_MQTT_SubTopic(url);
memset(url, 0, url_len);
snprintf(url, url_len, KK_URI_SYS_PREFIX_TOPO_CHANGE, productCode->valuestring, deviceCode->valuestring);
INFO_PRINT("sys [%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url);
res = KK_MQTT_SubTopic(url);
free(url); free(url);
return res; return res;
...@@ -62,20 +79,20 @@ static int _kk_client_subscribe(char productCode[PRODUCT_CODE_LEN],char deviceCo ...@@ -62,20 +79,20 @@ static int _kk_client_subscribe(char productCode[PRODUCT_CODE_LEN],char deviceCo
int res = 0, index = 0, fail_count = 0; int res = 0, index = 0, fail_count = 0;
int url_len = 0; int url_len = 0;
url_len = strlen(KK_URI_OTA_PREFIX) + strlen(productCode)+strlen(deviceCode) + 1; url_len = strlen(KK_URI_SYS_PREFIX_SERVICE) + strlen(productCode)+strlen(deviceCode) + 1;
char *url = malloc(url_len); char *url = malloc(url_len);
if (url == NULL) { if (url == NULL) {
return -1; return -1;
} }
memset(url, 0, url_len); //memset(url, 0, url_len);
snprintf(url, url_len, KK_URI_OTA_PREFIX, productCode,deviceCode); //snprintf(url, url_len, KK_URI_OTA_PREFIX, productCode,deviceCode);
INFO_PRINT("ota [%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url); //INFO_PRINT("ota [%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url);
res = KK_MQTT_SubTopic(url); //res = KK_MQTT_SubTopic(url);
memset(url, 0, url_len); memset(url, 0, url_len);
snprintf(url, url_len, KK_URI_SYS_PREFIX, productCode,deviceCode); snprintf(url, url_len, KK_URI_SYS_PREFIX_SERVICE, productCode,deviceCode);
INFO_PRINT("sys [%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url); INFO_PRINT("sys [%s][%d] URL:%s\n",__FUNCTION__,__LINE__,url);
res = KK_MQTT_SubTopic(url); res = KK_MQTT_SubTopic(url);
...@@ -91,7 +108,7 @@ int KK_Client_Gateway_Subscribe(void) ...@@ -91,7 +108,7 @@ int KK_Client_Gateway_Subscribe(void)
HAL_GetProduct_Code(productCode); HAL_GetProduct_Code(productCode);
HAL_Get_mac(deviceCode); HAL_Get_mac(deviceCode);
return _kk_client_subscribe(productCode,"CCU_66666"); return _kk_client_subscribe(productCode,KK_CCU_ID);
} }
static int _kk_utils_topic(_IN_ const char *name, _IN_ char *product_code, static int _kk_utils_topic(_IN_ const char *name, _IN_ char *product_code,
...@@ -150,6 +167,13 @@ int KK_Subdev_UnSubscribe_By_DeviceCode(const char *deviceCode,const char *produ ...@@ -150,6 +167,13 @@ int KK_Subdev_UnSubscribe_By_DeviceCode(const char *deviceCode,const char *produ
snprintf(topic, topic_len, KK_URI_SYS_PREFIX, productCode,deviceCode); snprintf(topic, topic_len, KK_URI_SYS_PREFIX, productCode,deviceCode);
INFO_PRINT("[%s][%d] TOPIC:%s\n",__FUNCTION__,__LINE__,topic); INFO_PRINT("[%s][%d] TOPIC:%s\n",__FUNCTION__,__LINE__,topic);
KK_MQTT_UnsubTopic(topic); KK_MQTT_UnsubTopic(topic);
memset(topic,0,topic_len);
snprintf(topic, topic_len, KK_URI_SYS_PREFIX_SERVICE, productCode,deviceCode);
INFO_PRINT("[%s][%d] TOPIC:%s\n",__FUNCTION__,__LINE__,topic);
KK_MQTT_UnsubTopic(topic);
snprintf(topic, topic_len, KK_URI_SYS_PREFIX_TOPO_CHANGE, productCode,deviceCode);
INFO_PRINT("[%s][%d] TOPIC:%s\n",__FUNCTION__,__LINE__,topic);
KK_MQTT_UnsubTopic(topic);
free(topic); free(topic);
return 0; return 0;
...@@ -199,6 +223,17 @@ char* KK_Make_Topic(cJSON *info) ...@@ -199,6 +223,17 @@ char* KK_Make_Topic(cJSON *info)
if(device_code == NULL){ if(device_code == NULL){
goto errorreturn; goto errorreturn;
} }
if((!strcmp(product_code->valuestring,"15") || !strcmp(product_code->valuestring,"ccu_n12")) && \
(strstr(type->valuestring,"thing/status/online") != NULL)){
KK_Client_Gateway_Subscribe();
}
if(!strcmp(product_code->valuestring,KK_GW_PRODUCTID)){
if(strstr(type->valuestring,"/thing/status/offline") != NULL){
kk_set_gw_status(DEVICE_OFFLINE);
}else if(strstr(type->valuestring,"/thing/status/online") != NULL){
kk_set_gw_status(DEVICE_ONLINE);
}
}
if(strstr(type->valuestring,"/ota/device/inform") ||strstr(type->valuestring,"/ota/device/progress")){ if(strstr(type->valuestring,"/ota/device/inform") ||strstr(type->valuestring,"/ota/device/progress")){
_kk_utils_topic_ota(type->valuestring,&topic); _kk_utils_topic_ota(type->valuestring,&topic);
} }
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "mqtt_api.h" #include "mqtt_api.h"
#include "com_api.h"
#include "kk_product.h"
static const char* OPT_SEND = "MQTTAsync_sendMessage"; static const char* OPT_SEND = "MQTTAsync_sendMessage";
static const char* OPT_SUB = "MQTTAsync_subscribe"; static const char* OPT_SUB = "MQTTAsync_subscribe";
static const char* OPT_UNSUB = "MQTTAsync_unsubscribe"; static const char* OPT_UNSUB = "MQTTAsync_unsubscribe";
static MQTTAsync s_Client; static MQTTAsync s_Client;
static int s_mqttStop = 0; static int s_mqttStop = 0;
static int s_cloudStatus = 0; static int s_cloudStatus = DEVICE_OFFLINE;
int kk_get_cloud_status(void){ int kk_get_cloud_status(void){
return s_cloudStatus; return s_cloudStatus;
...@@ -30,7 +30,7 @@ static void connlost(void *context, char *cause) ...@@ -30,7 +30,7 @@ static void connlost(void *context, char *cause)
INFO_PRINT("\nConnection lost\n"); INFO_PRINT("\nConnection lost\n");
INFO_PRINT("cause: %s\n", cause); INFO_PRINT("cause: %s\n", cause);
s_cloudStatus = 0; s_cloudStatus = DEVICE_OFFLINE;
KK_Send_CloudState(s_cloudStatus); KK_Send_CloudState(s_cloudStatus);
conn_opts.keepAliveInterval = 20; conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1; conn_opts.cleansession = 1;
...@@ -103,7 +103,7 @@ void onConnectFailure(void* context, MQTTAsync_failureData* response) ...@@ -103,7 +103,7 @@ void onConnectFailure(void* context, MQTTAsync_failureData* response)
void onConnect(void* context, MQTTAsync_successData* response) void onConnect(void* context, MQTTAsync_successData* response)
{ {
INFO_PRINT("Successful connection\n"); INFO_PRINT("Successful connection\n");
s_cloudStatus = 1; s_cloudStatus = DEVICE_ONLINE;
KK_Send_CloudState(s_cloudStatus); KK_Send_CloudState(s_cloudStatus);
} }
...@@ -131,11 +131,11 @@ static void onConnectBuild(void *context, char *cause) ...@@ -131,11 +131,11 @@ static void onConnectBuild(void *context, char *cause)
{ {
int rc = 0; int rc = 0;
INFO_PRINT("onConnectBuild:%s \n",cause); INFO_PRINT("onConnectBuild:%s \n",cause);
rc = KK_Client_Gateway_Subscribe(); //rc = KK_Client_Gateway_Subscribe();
if(rc != 0) //if(rc != 0)
{ //{
ERROR_PRINT("KK_MQTT_SubTopic ERROR rc = %d\n",rc); //ERROR_PRINT("KK_MQTT_SubTopic ERROR rc = %d\n",rc);
} //}
} }
static void onDisConnected(void *context, MQTTProperties* properties,enum MQTTReasonCodes reasonCode) static void onDisConnected(void *context, MQTTProperties* properties,enum MQTTReasonCodes reasonCode)
{ {
...@@ -195,14 +195,27 @@ void KK_Get_MqttClient(MQTTAsync *pClient) ...@@ -195,14 +195,27 @@ void KK_Get_MqttClient(MQTTAsync *pClient)
MQTTAsync KK_MQTT_Connect(void) MQTTAsync KK_MQTT_Connect(void)
{ {
int rc = 0; int rc = 0;
FILE *fp;
MQTTAsync_createOptions opts = MQTTAsync_createOptions_initializer; MQTTAsync_createOptions opts = MQTTAsync_createOptions_initializer;
MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer; MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
MQTTAsync_setTraceCallback(mqttTraceCallback); MQTTAsync_setTraceCallback(mqttTraceCallback);
opts.MQTTVersion = MQTTVERSION_3_1_1; opts.MQTTVersion = MQTTVERSION_3_1_1;
char mac[16]={0}; char mac[16]={0};
char clientBuf[20] = {0}; char clientBuf[64] = {0};
char timestamp[16] = {0};
char token[512] = {0};
char usrname[128] = {0};
fp = fopen("/usr/kk/kk_token.txt", "r");
if(fp != NULL){
fread(token,1,sizeof(token),fp);
fclose(fp);
}
HAL_Get_mac(mac); HAL_Get_mac(mac);
sprintf(clientBuf, CLIENTID, mac); HAL_GetTime_s(timestamp);
sprintf(clientBuf, CLIENTID, KK_CCU_ID,timestamp);
sprintf(usrname, "%s&%s", KK_CCU_ID,KK_CCU_PRODUCTID);
printf("cliendid:%s,usrname:%s\n",clientBuf,usrname);
printf("------------>token:%s\n",token);
if ((rc = MQTTAsync_createWithOptions(&s_Client, ADDRESS, clientBuf, MQTTCLIENT_PERSISTENCE_NONE, NULL,&opts)) != MQTTASYNC_SUCCESS) if ((rc = MQTTAsync_createWithOptions(&s_Client, ADDRESS, clientBuf, MQTTCLIENT_PERSISTENCE_NONE, NULL,&opts)) != MQTTASYNC_SUCCESS)
{ {
ERROR_PRINT("Failed to create client object, return code %d\n", rc); ERROR_PRINT("Failed to create client object, return code %d\n", rc);
...@@ -216,8 +229,10 @@ MQTTAsync KK_MQTT_Connect(void) ...@@ -216,8 +229,10 @@ MQTTAsync KK_MQTT_Connect(void)
conn_opts.automaticReconnect = AUTO_CONN; conn_opts.automaticReconnect = AUTO_CONN;
conn_opts.minRetryInterval = 1; conn_opts.minRetryInterval = 1;
conn_opts.maxRetryInterval = 32; conn_opts.maxRetryInterval = 32;
conn_opts.username = USRNAME; //conn_opts.username = USRNAME;
conn_opts.password = PASSWORD; //conn_opts.password = PASSWORD;
conn_opts.username = usrname;
conn_opts.password = token;
conn_opts.cleansession = 1; conn_opts.cleansession = 1;
conn_opts.onSuccess = onConnect; conn_opts.onSuccess = onConnect;
conn_opts.onFailure = onConnectFailure; conn_opts.onFailure = onConnectFailure;
......
LIBA_TARGET := libiot_luoma.a
$(call Append_Conditional, LIB_SRCS_EXCLUDE, kk_luoma_main.c)
$(call Append_Conditional, SRCS_kk_luoma, kk_luoma_main.c)
$(call Append_Conditional, TARGET, kk_luoma)
CFLAGS += -I$(TOP_DIR)/common/api
CFLAGS += -I$(TOP_DIR)/common/json
CFLAGS += -I$(TOP_DIR)/common/nanomsg/include
CFLAGS += -I$(TOP_DIR)/common/ev/include
LDFLAGS += -lkk_tsl
LDFLAGS += -lapi_com
ifeq ($(CONFIG_VENDOR),ubuntu)
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg_ubuntu
LDFLAGS += -L$(TOP_DIR)/common/ev -lev_ubuntu
else
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg
LDFLAGS += -L$(TOP_DIR)/common/ev -lev
endif
LDFLAGS += -liot_cjson -liot_mqtt -ldl -lm -lanl -lkk_hal
/*******************************************************************************
* Copyright (c) 2012, 2020 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* https://www.eclipse.org/legal/epl-2.0/
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial contribution
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "MQTTAsync.h"
#include "mqtt_api.h"
#include "com_api.h"
#include "kk_product.h"
//#include "kcloud_log.h"
int main(int argc, char* argv[])
{
int rc = 0;
adasd
return rc;
}
This diff is collapsed.
#ifndef __QRENCODE_H
#define __QRENCODE_H
typedef unsigned char BYTE;
typedef unsigned int WORD;
//typedef enum {FALSE = 0, TRUE = !FALSE} bool;
#define min(a,b) (((a) < (b)) ? (a) : (b))
//4种纠错等级,可恢复的码字比例为:
#define QR_LEVEL_L 0 //7%的字码可被修正
#define QR_LEVEL_M 1 //15%的字码可被修正
#define QR_LEVEL_Q 2 //25%的字码可被修正
#define QR_LEVEL_H 3 //30%的字码可被修正
//编码形式
#define QR_MODE_NUMERAL 0
#define QR_MODE_ALPHABET 1
#define QR_MODE_8BIT 2
#define QR_MODE_KANJI 3
#define QR_MODE_CHINESE 4
//Number of bits per length field
//Encoding Ver.1–9 10–26 27–40
//Numeric 10 12 14
//Alphanumeric 9 11 13
//Byte 8 16 16
//Kanji 8 10 12
//Chinese
//P17 字符计数指示的位数
#define QR_VRESION_S 0
#define QR_VRESION_M 1
#define QR_VRESION_L 2
#define QR_MARGIN 4
#define QR_VER1_SIZE 21// 版本的行列数
#define MAX_ALLCODEWORD 3706//400// //P14,P35 数据容量[码字]* (E) (VER:40), 所有码字为8位
#define MAX_DATACODEWORD 2956//400// //P27 最大信息码子(Ver:40-L),所有码字为8位
#define MAX_CODEBLOCK 153 //最大纠错码字 Ver:36.37.38_L_第二块
#define MAX_MODULESIZE 177 // 21:Version=1,最大字符=17(8.5个汉字)
// 25:Version=2,最大字符=32(16个汉字)
// 29:Version=3,最大字符=49(24.5个汉字)
// 33:Version=4,最大字符=78(39个汉字)
// 37:Version=5,最大字符=106(53个汉字)
// 41:Version=6,最大字符=134(67个汉字)
// 45:Version=7,最大字符=154(77个汉字)
// 49:Version=8,最大字符=192(96个汉字)
// 53:
//#define MAX_MODULESIZE 177//P14 每边的模块数(A) (VER:40 ) Ver:40 = 21+(Ver-1)*4
extern int m_nSymbleSize;
extern BYTE m_byModuleData[MAX_MODULESIZE][MAX_MODULESIZE];
/////////////////////////////////////////////////////////////////////////////
//
typedef struct
{
uint16_t ncRSBlock; //纠错的块数
uint16_t ncAllCodeWord; //码字总数
uint16_t ncDataCodeWord; //指定纠错等级下的数据码字数
} RS_BLOCKINFO;
typedef struct
{
uint16_t nVersionNo; //ver 1~40
uint16_t ncAllCodeWord; //码字总数=数据码字+纠错码字
uint16_t ncDataCodeWord[4]; //指定纠错等级下的数据码字(0=L,1=M,2=Q,3=H)
uint16_t ncAlignPoint; //P61 表E1 校正图形 个数
uint16_t nAlignPoint[6]; //P61 表E1 校正图形 行列坐标
//(0=L,1=M,2=Q,3=H)
RS_BLOCKINFO RS_BlockInfo1[4]; //纠错块1
RS_BLOCKINFO RS_BlockInfo2[4]; //纠错块2
} QR_VERSIONINFO;
bool EncodeData(char *lpsSource);
int GetEncodeVersion(int nVersion, char *lpsSource, int ncLength);
// bool EncodeSourceData(char *lpsSource, int ncLength, int nVerGroup);
int EncodeSourceData(char *lpsSource, int ncLength, int nVerGroup);
int GetBitLength(BYTE nMode, int ncData, int nVerGroup);
int SetBitStream(int nIndex, WORD wData, int ncData);
bool IsNumeralData(unsigned char c);
bool IsAlphabetData(unsigned char c);
bool IsKanjiData(unsigned char c1, unsigned char c2);
bool IsChineseData(unsigned char c1, unsigned char c2);
BYTE AlphabetToBinaly(unsigned char c);
WORD KanjiToBinaly(WORD wc);
WORD ChineseToBinaly(WORD wc);
void GetRSCodeWord(BYTE *lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord);
void FormatModule(void);
void SetFunctionModule(void);
void SetFinderPattern(int x, int y);
void SetAlignmentPattern(int x, int y);
void SetVersionPattern(void);
void SetCodeWordPattern(void);
void SetMaskingPattern(int nPatternNo);
void SetFormatInfoPattern(int nPatternNo);
int CountPenalty(void);
void Print_2DCode(void);
#endif
/*
* qrencode - QR Code encoder
*
* Binary sequence class.
* Copyright (C) 2006-2011 Kentaro Fukuchi <kentaro@fukuchi.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bitstream.h"
BitStream *BitStream_new(void)
{
BitStream *bstream;
bstream = (BitStream *)malloc(sizeof(BitStream));
if(bstream == NULL) return NULL;
bstream->length = 0;
bstream->data = NULL;
return bstream;
}
static int BitStream_allocate(BitStream *bstream, int length)
{
unsigned char *data;
if(bstream == NULL) {
return -1;
}
data = (unsigned char *)malloc(length);
if(data == NULL) {
return -1;
}
if(bstream->data) {
free(bstream->data);
}
bstream->length = length;
bstream->data = data;
return 0;
}
static BitStream *BitStream_newFromNum(int bits, unsigned int num)
{
unsigned int mask;
int i;
unsigned char *p;
BitStream *bstream;
bstream = BitStream_new();
if(bstream == NULL) return NULL;
if(BitStream_allocate(bstream, bits)) {
BitStream_free(bstream);
return NULL;
}
p = bstream->data;
mask = 1 << (bits - 1);
for(i=0; i<bits; i++) {
if(num & mask) {
*p = 1;
} else {
*p = 0;
}
p++;
mask = mask >> 1;
}
return bstream;
}
static BitStream *BitStream_newFromBytes(int size, unsigned char *data)
{
unsigned char mask;
int i, j;
unsigned char *p;
BitStream *bstream;
bstream = BitStream_new();
if(bstream == NULL) return NULL;
if(BitStream_allocate(bstream, size * 8)) {
BitStream_free(bstream);
return NULL;
}
p = bstream->data;
for(i=0; i<size; i++) {
mask = 0x80;
for(j=0; j<8; j++) {
if(data[i] & mask) {
*p = 1;
} else {
*p = 0;
}
p++;
mask = mask >> 1;
}
}
return bstream;
}
int BitStream_append(BitStream *bstream, BitStream *arg)
{
unsigned char *data;
if(arg == NULL) {
return -1;
}
if(arg->length == 0) {
return 0;
}
if(bstream->length == 0) {
if(BitStream_allocate(bstream, arg->length)) {
return -1;
}
memcpy(bstream->data, arg->data, arg->length);
return 0;
}
data = (unsigned char *)malloc(bstream->length + arg->length);
if(data == NULL) {
return -1;
}
memcpy(data, bstream->data, bstream->length);
memcpy(data + bstream->length, arg->data, arg->length);
free(bstream->data);
bstream->length += arg->length;
bstream->data = data;
return 0;
}
int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num)
{
BitStream *b;
int ret;
if(bits == 0) return 0;
b = BitStream_newFromNum(bits, num);
if(b == NULL) return -1;
ret = BitStream_append(bstream, b);
BitStream_free(b);
return ret;
}
int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data)
{
BitStream *b;
int ret;
if(size == 0) return 0;
b = BitStream_newFromBytes(size, data);
if(b == NULL) return -1;
ret = BitStream_append(bstream, b);
BitStream_free(b);
return ret;
}
unsigned char *BitStream_toByte(BitStream *bstream)
{
int i, j, size, bytes;
unsigned char *data, v;
unsigned char *p;
size = BitStream_size(bstream);
if(size == 0) {
return NULL;
}
data = (unsigned char *)malloc((size + 7) / 8);
if(data == NULL) {
return NULL;
}
bytes = size / 8;
p = bstream->data;
for(i=0; i<bytes; i++) {
v = 0;
for(j=0; j<8; j++) {
v = v << 1;
v |= *p;
p++;
}
data[i] = v;
}
if(size & 7) {
v = 0;
for(j=0; j<(size & 7); j++) {
v = v << 1;
v |= *p;
p++;
}
data[bytes] = v;
}
return data;
}
void BitStream_free(BitStream *bstream)
{
if(bstream != NULL) {
free(bstream->data);
free(bstream);
}
}
/*
* qrencode - QR Code encoder
*
* Binary sequence class.
* Copyright (C) 2006-2011 Kentaro Fukuchi <kentaro@fukuchi.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __BITSTREAM_H__
#define __BITSTREAM_H__
typedef struct {
int length;
unsigned char *data;
} BitStream;
extern BitStream *BitStream_new(void);
extern int BitStream_append(BitStream *bstream, BitStream *arg);
extern int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num);
extern int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data);
#define BitStream_size(__bstream__) (__bstream__->length)
extern unsigned char *BitStream_toByte(BitStream *bstream);
extern void BitStream_free(BitStream *bstream);
#endif /* __BITSTREAM_H__ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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