Commit 44036e7a authored by chen.weican's avatar chen.weican
parents c7a249a9 a0816f3c
...@@ -196,6 +196,26 @@ int kk_is_tcp_channel(char devCode[DEVICE_CODE_LEN]){ ...@@ -196,6 +196,26 @@ int kk_is_tcp_channel(char devCode[DEVICE_CODE_LEN]){
return -1; return -1;
} }
int kk_set_tcp_channel_by_idx(int idx, char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){
int i = 0;
if(idx >= MAX_LISTEN_NUM){
printf("kk_set_tcp_channel_by_idx idx[] need less than %d \n", idx, MAX_LISTEN_NUM);
return - 1;
}
if (devCode == NULL || strlen(devCode) == 0 || ip == NULL || strlen(ip) == 0){
return -1;
}
//printf("[%s] devCode=%s \n", __FUNCTION__,devCode);
memcpy(g_tcp_ctrl[idx].deviceCode, devCode, strlen(devCode));
memcpy(g_tcp_ctrl[idx].ip, ip, strlen(ip));
return 0;
}
int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){
int i = 0; int i = 0;
int isEmptyIdx = -1; int isEmptyIdx = -1;
...@@ -210,7 +230,7 @@ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){ ...@@ -210,7 +230,7 @@ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){
if(strcmp(devCode, g_tcp_ctrl[i].deviceCode) == 0){ if(strcmp(devCode, g_tcp_ctrl[i].deviceCode) == 0){
strncpy(g_tcp_ctrl[i].ip, ip, strlen(ip)); strncpy(g_tcp_ctrl[i].ip, ip, strlen(ip));
printf("find and replace it [%d][%s][%s] \n",i, g_tcp_ctrl[i].ip, devCode); printf("find and replace it [%d][%s][%s] \n",i, g_tcp_ctrl[i].ip, devCode);
kk_gw_list_save(); //kk_gw_list_save();
break; break;
} }
...@@ -228,7 +248,7 @@ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){ ...@@ -228,7 +248,7 @@ int kk_set_tcp_channel(char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){
strncpy(g_tcp_ctrl[isEmptyIdx].ip, ip, strlen(ip)); strncpy(g_tcp_ctrl[isEmptyIdx].ip, ip, strlen(ip));
strncpy(g_tcp_ctrl[isEmptyIdx].deviceCode, devCode, strlen(devCode)); strncpy(g_tcp_ctrl[isEmptyIdx].deviceCode, devCode, strlen(devCode));
printf("idx deviceCode ip[%d][%s][%s]",isEmptyIdx, g_tcp_ctrl[isEmptyIdx].deviceCode, g_tcp_ctrl[isEmptyIdx].ip); printf("idx deviceCode ip[%d][%s][%s]",isEmptyIdx, g_tcp_ctrl[isEmptyIdx].deviceCode, g_tcp_ctrl[isEmptyIdx].ip);
kk_gw_list_save(); //kk_gw_list_save();
return 0; return 0;
} }
...@@ -433,9 +453,11 @@ int kk_TCP_channel_init(ipc_cb cb) ...@@ -433,9 +453,11 @@ int kk_TCP_channel_init(ipc_cb cb)
return -1; return -1;
} }
g_init = 1; g_init = 1;
memset(g_tcp_ctrl, 0, sizeof(kk_tcp_ctrl_t)*MAX_LISTEN_NUM); //memset(g_tcp_ctrl, 0, sizeof(kk_tcp_ctrl_t)*MAX_LISTEN_NUM);
kk_gw_list_load(); //kk_gw_list_load();
for(i = 0; i < MAX_LISTEN_NUM; i++){
g_tcp_ctrl[i].sock = -1;
}
if (g_pTh ==NULL && 0 != pthread_create(&g_pTh, NULL, loop_tcp_thread, NULL)) { if (g_pTh ==NULL && 0 != pthread_create(&g_pTh, NULL, loop_tcp_thread, NULL)) {
printf("create pthread failed\r\n"); printf("create pthread failed\r\n");
......
LIBA_TARGET := libkk_hal.a LIBSO_TARGET := libkk_hal.so
\ No newline at end of file \ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "sqlite3.h" #include "sqlite3.h"
#include "kk_log.h" #include "kk_log.h"
#include "kk_dm_mng.h" #include "kk_dm_mng.h"
#include "kk_property_db.h"
#define KK_PROPERTIES_DB_FILE "kk_properties.db" #define KK_PROPERTIES_DB_FILE "kk_properties.db"
...@@ -185,6 +186,93 @@ int kk_property_db_update_value(const char *deviceCode,const char *identifier,co ...@@ -185,6 +186,93 @@ int kk_property_db_update_value(const char *deviceCode,const char *identifier,co
return SUCCESS_RETURN; return SUCCESS_RETURN;
} }
int kk_property_db_get_value(const char *deviceCode,const char *identifier,void* value)
{
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
sqlite3_stmt *stmt;
char *valueStr = NULL;
int valueType = 0;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
sqlCmd = sqlite3_mprintf("select * from PropertiesInfo WHERE deviceCode= '%s' and identifier = '%s'",deviceCode,identifier);
DEBUG_PRINT("kk_property_db_get_value sqlCmd:%s\n",sqlCmd);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
while(sqlite3_step(stmt) == SQLITE_ROW){
valueStr = sqlite3_column_text(stmt, DB_VALUE);
valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
if(valueType == KK_TSL_DATA_TYPE_INT||
valueType == KK_TSL_DATA_TYPE_ENUM||
valueType == KK_TSL_DATA_TYPE_BOOL){
int value_int = atoi(valueStr);
*(int*)value = value_int;
}
else if(valueType == KK_TSL_DATA_TYPE_FLOAT){
float value_float = atoi(valueStr);
*(float*)value = value_float;
}
else if(valueType == KK_TSL_DATA_TYPE_DOUBLE){
double value_double = atoi(valueStr);
*(double*)value = value_double;
}
else{
memcpy(value,valueStr, strlen(valueStr));
}
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
sqlite3_finalize(stmt);
return SUCCESS_RETURN;
}
int kk_property_db_get_rawdata(const char *identifier,const int dev_type, kk_prop_raw_struct_t* raw, int count)
{
char *sqlCmd = NULL;
int rc = 0;
char *zErrMsg = 0;
sqlite3_stmt *stmt;
char *valueStr = NULL;
char *devcode = NULL;
int valueType = 0;
int idx = 0;
kk_prop_raw_struct_t *curData = NULL;
kk_property_db_ctx_t *ctx = _kk_property_db_get_ctx();
_kk_property_db_lock();
sqlCmd = sqlite3_mprintf("select * from PropertiesInfo WHERE devType= '%d' and identifier = '%s'",dev_type,identifier);
DEBUG_PRINT("kk_property_db_get_gw_value sqlCmd:%s\n",sqlCmd);
sqlite3_prepare_v2(ctx->pDb, sqlCmd, strlen(sqlCmd), &stmt, NULL);
curData = raw;
while(sqlite3_step(stmt) == SQLITE_ROW && idx < count){
devcode = sqlite3_column_text(stmt, DB_DEVICECODE);
valueStr = sqlite3_column_text(stmt, DB_VALUE);
valueType = sqlite3_column_int(stmt, DB_VALUETYPE);
memcpy(curData->deviceCode,devcode, strlen(devcode));
memcpy(curData->raw,valueStr, strlen(valueStr));
curData->type = valueType;
curData++;
idx++;
}
sqlite3_free(sqlCmd);
_kk_property_db_unlock();
sqlite3_finalize(stmt);
return SUCCESS_RETURN;
}
int kk_property_db_update(const char *deviceCode) int kk_property_db_update(const char *deviceCode)
{ {
int res = 0; int res = 0;
...@@ -285,6 +373,7 @@ int kk_property_sync_values(const char *deviceCode) ...@@ -285,6 +373,7 @@ int kk_property_sync_values(const char *deviceCode)
} }
sqlite3_free(sqlCmd);
_kk_property_db_unlock(); _kk_property_db_unlock();
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
#define _KK_PROPERTY_DB_H_ #define _KK_PROPERTY_DB_H_
#include "kk_tsl_common.h" #include "kk_tsl_common.h"
typedef struct{
int type;
char deviceCode[DEVICE_CODE_MAXLEN];
char raw[60];
}kk_prop_raw_struct_t;
int kk_property_db_init(void); int kk_property_db_init(void);
#endif #endif
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "kk_dm_mng.h" #include "kk_dm_mng.h"
#include "kk_log.h" #include "kk_log.h"
#include "kk_dm_queue.h" #include "kk_dm_queue.h"
#include "kk_property_db.h"
char * g_filerToPlatTable[] = char * g_filerToPlatTable[] =
...@@ -323,6 +324,7 @@ void *ota_dispatch_yield(void *args) ...@@ -323,6 +324,7 @@ void *ota_dispatch_yield(void *args)
#define UDP_LAN_PORT 25556 #define UDP_LAN_PORT 25556
#define UDP_LAN_PORT_HOST 25555 #define UDP_LAN_PORT_HOST 25555
#define test_ #define test_
void *udp_dispatch_yield(void *args){ void *udp_dispatch_yield(void *args){
...@@ -381,7 +383,16 @@ void *udp_dispatch_yield(void *args){ ...@@ -381,7 +383,16 @@ void *udp_dispatch_yield(void *args){
char mac[32] = {0}; char mac[32] = {0};
char device_code[DEVICE_CODE_LEN] = {0}; char device_code[DEVICE_CODE_LEN] = {0};
int devId = 0; int devId = 0;
kk_prop_raw_struct_t ipList[10] = {0};
int idx = 0;
kk_property_db_get_rawdata("IPAddress",4, ipList, sizeof(ipList));
for(; idx < 10; idx++){
DEBUG_PRINT("ipList[%d][%s][%s] \n", idx, ipList[idx].deviceCode, ipList[idx].raw);
if (strlen(ipList[idx].deviceCode)>0 && strlen(ipList[idx].raw)>0){
kk_set_tcp_channel_by_idx(idx, ipList[idx].deviceCode, ipList[idx].raw);
}
}
kk_TCP_channel_init(gw2mid_cb); kk_TCP_channel_init(gw2mid_cb);
while(1) while(1)
......
...@@ -356,7 +356,7 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES) ...@@ -356,7 +356,7 @@ $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
@echo -e '\n$@ build success' @echo -e '\n$@ build success'
else else
$(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES) $(TARGET_FILE): $(APPLICATION_OBJECTS) $(LIBRARIES)
$(LD) $^ $(LINKER_FLAGS) -lm -L. -lapi_com -lnanomsg -lanl -pthread -lev -ltinfo -o $(TARGET_FILE) $(LD) $^ $(LINKER_FLAGS) -lm -L. -lapi_com -lnanomsg -lkk_hal -lanl -pthread -lev -ltinfo -o $(TARGET_FILE)
@echo -e '\n$@ build success' @echo -e '\n$@ build success'
endif endif
......
...@@ -534,7 +534,9 @@ void ipcHandle(void) ...@@ -534,7 +534,9 @@ void ipcHandle(void)
cnt++; cnt++;
if (cnt == 2){ if (cnt == 2){
sleep(1); sleep(1);
char* postmsg = _msg_event_property_post(ip,port); char gwIp[17] = {0};
HAL_Get_IP(gwIp,NULL);
char* postmsg = _msg_event_property_post(gwIp,port);
if (outbuf == NULL){ if (outbuf == NULL){
printf("[%s] property_post msg failed\n",__FUNCTION__); printf("[%s] property_post msg failed\n",__FUNCTION__);
......
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