Commit f368c9f1 authored by chen.weican's avatar chen.weican

【修改内容】去warning处理

parent b9b502dd
//=========kk============= //=========kk=============
#include <pthread.h>
#include "com_api.h" #include "com_api.h"
#include "kk_log.h" #include "kk_log.h"
...@@ -32,10 +33,10 @@ static Bloop_ctrl_t Bloop_ctrl; ...@@ -32,10 +33,10 @@ static Bloop_ctrl_t Bloop_ctrl;
static Bloop_ctrl_t Mloop_ctrl; static Bloop_ctrl_t Mloop_ctrl;
static struct ev_loop* gloop = NULL; static struct ev_loop* gloop = NULL;
static pthread_t g_pTh = NULL; static pthread_t g_pTh = 0;
static char* _parse_data_by_subscribe(char* data, int len, int *outLen, void** chlMark){ static char* _parse_data_by_subscribe(char* data, int len, uint32_t *outLen, void** chlMark){
char* foundStr = NULL; char* foundStr = NULL;
if (data == NULL|| len <= 0 ){ if (data == NULL|| len <= 0 ){
return data; return data;
...@@ -90,14 +91,14 @@ static void watcher_cb (struct ev_loop *loop ,struct ev_io *w, int revents) ...@@ -90,14 +91,14 @@ static void watcher_cb (struct ev_loop *loop ,struct ev_io *w, int revents)
loop_ctrl->isconnect = 1; loop_ctrl->isconnect = 1;
//if sub, need filter sbuscribe str //if sub, need filter sbuscribe str
if (IPC_PLAT2MID == loop_ctrl->type || IPC_MID2PLAT == loop_ctrl->type){ if (IPC_PLAT2MID == loop_ctrl->type || IPC_MID2PLAT == loop_ctrl->type){
validDat = _parse_data_by_subscribe(dat, bytes, &validLen, &chlMark); validDat = _parse_data_by_subscribe((char*)dat, bytes, &validLen, &chlMark);
}else{ }else{
validDat = dat; validDat = dat;
validLen = bytes; validLen = bytes;
} }
if (strncmp(validDat,MAGIC, strlen(MAGIC)) == 0){ if (strncmp((char*)validDat,MAGIC, strlen(MAGIC)) == 0){
if (strncmp(validDat,MAGIC_ACK, strlen(MAGIC_ACK)) == 0){ if (strncmp((char*)validDat,MAGIC_ACK, strlen(MAGIC_ACK)) == 0){
}else{ }else{
kk_ipc_send_ex(loop_ctrl->type, MAGIC_ACK, strlen(MAGIC_ACK)+1, chlMark); kk_ipc_send_ex(loop_ctrl->type, MAGIC_ACK, strlen(MAGIC_ACK)+1, chlMark);
...@@ -316,24 +317,24 @@ int kk_ipc_init(ipc_type type, ipc_cb cb, char* chlMark, char* ip) ...@@ -316,24 +317,24 @@ int kk_ipc_init(ipc_type type, ipc_cb cb, char* chlMark, char* ip)
}else { }else {
loop_ctrl = &Bloop_ctrl; loop_ctrl = &Bloop_ctrl;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if (type == IPC_PLAT2MID && (chlMark == NULL || ip == NULL)){ if (type == IPC_PLAT2MID && (chlMark == NULL || ip == NULL)){
ERROR_PRINT("parameter is error \r\n"); ERROR_PRINT("parameter is error \r\n");
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if(loop_ctrl->cb != NULL){ if(loop_ctrl->cb != NULL){
WARNING_PRINT("middleware to platform ipc has been inited!\r\n"); WARNING_PRINT("middleware to platform ipc has been inited!\r\n");
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if (__nanomsg_init(loop_ctrl, type, chlMark, ip) < 0) { if (__nanomsg_init(loop_ctrl, type, chlMark, ip) < 0) {
ERROR_PRINT("nanomsg init failed\r\n"); ERROR_PRINT("nanomsg init failed\r\n");
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if (gloop == NULL){ if (gloop == NULL){
gloop = ev_loop_new(EVBACKEND_EPOLL); gloop = ev_loop_new(EVBACKEND_EPOLL);
if (NULL == gloop) { if (NULL == gloop) {
...@@ -342,15 +343,15 @@ int kk_ipc_init(ipc_type type, ipc_cb cb, char* chlMark, char* ip) ...@@ -342,15 +343,15 @@ int kk_ipc_init(ipc_type type, ipc_cb cb, char* chlMark, char* ip)
} }
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
loop_ctrl->type = type; loop_ctrl->type = type;
__loop_init(loop_ctrl, gloop); __loop_init(loop_ctrl, gloop);
if (g_pTh ==NULL && 0 != pthread_create(&g_pTh, NULL, loop_thread, NULL)) { if (g_pTh == 0 && 0 != pthread_create(&g_pTh, NULL, loop_thread, NULL)) {
ERROR_PRINT("create pthread failed\r\n"); ERROR_PRINT("create pthread failed\r\n");
return -1; return -1;
} }
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
loop_ctrl->cb = cb; loop_ctrl->cb = cb;
loop_ctrl->type = type; loop_ctrl->type = type;
return 0; return 0;
...@@ -382,10 +383,10 @@ int kk_ipc_deinit(ipc_type type) ...@@ -382,10 +383,10 @@ int kk_ipc_deinit(ipc_type type)
if (Bloop_ctrl.cb ==NULL && Mloop_ctrl.cb ==NULL){ if (Bloop_ctrl.cb ==NULL && Mloop_ctrl.cb ==NULL){
ev_break(gloop,EVBREAK_ALL); ev_break(gloop,EVBREAK_ALL);
pthread_exit(g_pTh); pthread_exit(0);
ev_loop_destroy(gloop); ev_loop_destroy(gloop);
gloop = NULL; gloop = NULL;
g_pTh = NULL; g_pTh = 0;
} }
return 0; return 0;
...@@ -403,7 +404,7 @@ int kk_ipc_send(ipc_type type, void* data, int len) ...@@ -403,7 +404,7 @@ int kk_ipc_send(ipc_type type, void* data, int len)
chalMark = Bloop_ctrl.subscrStr; chalMark = Bloop_ctrl.subscrStr;
} }
} }
printf("kk_ipc_send data:%s\n",data);
return kk_ipc_send_ex(type, data, len, chalMark); return kk_ipc_send_ex(type, data, len, chalMark);
} }
......
...@@ -18,6 +18,7 @@ extern "C" { ...@@ -18,6 +18,7 @@ extern "C" {
#include "pubsub.h" #include "pubsub.h"
#include "pipeline.h" #include "pipeline.h"
#include "kk_product.h" #include "kk_product.h"
#include "cJSON.h"
//=====kk====================== //=====kk======================
typedef enum { typedef enum {
......
...@@ -26,7 +26,7 @@ typedef struct{ ...@@ -26,7 +26,7 @@ typedef struct{
static kk_tcp_ctrl_t g_tcp_ctrl[MAX_LISTEN_NUM]; static kk_tcp_ctrl_t g_tcp_ctrl[MAX_LISTEN_NUM];
static struct ev_loop *g_loop = NULL; static struct ev_loop *g_loop = NULL;
static pthread_t g_pTh = NULL; static pthread_t g_pTh = 0;
static int g_init = 0; static int g_init = 0;
static ipc_cb* g_cb = NULL; static ipc_cb* g_cb = NULL;
static struct ev_io w_accept; static struct ev_io w_accept;
...@@ -193,13 +193,11 @@ static char* __do_spilt(char* buf, int buflen,ipc_cb* cb, char* deviceCode){ ...@@ -193,13 +193,11 @@ static char* __do_spilt(char* buf, int buflen,ipc_cb* cb, char* deviceCode){
return NULL; return NULL;
} }
#if 0
// Save/Load the gateway list // Save/Load the gateway list
static void kk_gw_list_save(void) static void kk_gw_list_save(void)
{ {
FILE *fp; FILE *fp;
uint8_t i;
uint8_t j;
int len = MAX_LISTEN_NUM * sizeof(kk_tcp_ctrl_t); int len = MAX_LISTEN_NUM * sizeof(kk_tcp_ctrl_t);
// Save device table // Save device table
...@@ -216,7 +214,7 @@ static void kk_gw_list_load(void) ...@@ -216,7 +214,7 @@ static void kk_gw_list_load(void)
FILE *fp; FILE *fp;
int readLen = MAX_LISTEN_NUM * sizeof(kk_tcp_ctrl_t); int readLen = MAX_LISTEN_NUM * sizeof(kk_tcp_ctrl_t);
int retLen = 0; int retLen = 0;
char buf[1024] = {0}; //char buf[1024] = {0};
fp = fopen("gwlist.txt", "r"); fp = fopen("gwlist.txt", "r");
if (!fp) { if (!fp) {
INFO_PRINT("open gatewaylist.txt failed! \n"); INFO_PRINT("open gatewaylist.txt failed! \n");
...@@ -256,7 +254,7 @@ static int get_idx_by_ip(char ip[MAX_IP_LEN]){ ...@@ -256,7 +254,7 @@ static int get_idx_by_ip(char ip[MAX_IP_LEN]){
return -1; return -1;
} }
#endif
static kk_tcp_ctrl_t* get_channel_by_deviceCode(char deviceCode[DEVICE_CODE_LEN]){ static kk_tcp_ctrl_t* get_channel_by_deviceCode(char deviceCode[DEVICE_CODE_LEN]){
int i = 0; int i = 0;
...@@ -290,7 +288,7 @@ static kk_tcp_ctrl_t* get_channel_by_ip(char ip[MAX_IP_LEN]){ ...@@ -290,7 +288,7 @@ static kk_tcp_ctrl_t* get_channel_by_ip(char ip[MAX_IP_LEN]){
} }
#if 0
static int set_status_by_ip(char ip[MAX_IP_LEN], int status){ static int set_status_by_ip(char ip[MAX_IP_LEN], int status){
int i = 0; int i = 0;
...@@ -306,6 +304,7 @@ static int set_status_by_ip(char ip[MAX_IP_LEN], int status){ ...@@ -306,6 +304,7 @@ static int set_status_by_ip(char ip[MAX_IP_LEN], int status){
return -1; return -1;
} }
#endif
static int reset_by_sock(int sock){ static int reset_by_sock(int sock){
int i = 0; int i = 0;
...@@ -371,11 +370,8 @@ int kk_is_tcp_channel(char devCode[DEVICE_CODE_LEN]){ ...@@ -371,11 +370,8 @@ int kk_is_tcp_channel(char devCode[DEVICE_CODE_LEN]){
} }
int kk_set_tcp_channel_by_idx(int idx, char devCode[DEVICE_CODE_LEN], char ip[MAX_IP_LEN]){ 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){ if(idx >= MAX_LISTEN_NUM){
INFO_PRINT("kk_set_tcp_channel_by_idx idx[] need less than %d \n", idx, MAX_LISTEN_NUM); INFO_PRINT("kk_set_tcp_channel_by_idx idx[%d] need less than %d \n", idx, MAX_LISTEN_NUM);
return - 1; return - 1;
} }
...@@ -636,18 +632,17 @@ static void loop_tcp_thread(void *arg){ ...@@ -636,18 +632,17 @@ static void loop_tcp_thread(void *arg){
g_loop = ev_loop_new(EVBACKEND_EPOLL); g_loop = ev_loop_new(EVBACKEND_EPOLL);
if (NULL == g_loop) { if (NULL == g_loop) {
INFO_PRINT("loop create failed\r\n"); INFO_PRINT("loop create failed\r\n");
return -1; return;
} }
if (server_socket_init(&sd, NULL, CCU_TCP_PORT) < 0) { if (server_socket_init(&sd, NULL, CCU_TCP_PORT) < 0) {
INFO_PRINT("server init failed\r\n"); INFO_PRINT("server init failed\r\n");
return -1; return;
} }
ev_io_init(&w_accept, accept_cb, sd, EV_READ); ev_io_init(&w_accept, accept_cb, sd, EV_READ);
ev_io_start(g_loop, &w_accept); ev_io_start(g_loop, &w_accept);
ev_run (g_loop, 0); ev_run (g_loop, 0);
close(sd); close(sd);
INFO_PRINT("loop_tcp_thread================== end \n"); INFO_PRINT("loop_tcp_thread================== end \n");
} }
...@@ -726,7 +721,7 @@ int kk_TCP_channel_init(ipc_cb cb) ...@@ -726,7 +721,7 @@ int kk_TCP_channel_init(ipc_cb cb)
g_tcp_ctrl[i].sock = -1; g_tcp_ctrl[i].sock = -1;
} }
if (g_pTh ==NULL && 0 != pthread_create(&g_pTh, NULL, loop_tcp_thread, NULL)) { if (g_pTh == 0 && 0 != pthread_create(&g_pTh, NULL, loop_tcp_thread, NULL)) {
INFO_PRINT("create pthread failed\r\n"); INFO_PRINT("create pthread failed\r\n");
return -1; return -1;
}; };
...@@ -754,10 +749,10 @@ int kk_TCP_channel_deinit(ipc_type type) ...@@ -754,10 +749,10 @@ int kk_TCP_channel_deinit(ipc_type type)
ev_io_stop(g_loop, &w_accept); ev_io_stop(g_loop, &w_accept);
ev_break(g_loop,EVBREAK_ALL); ev_break(g_loop,EVBREAK_ALL);
pthread_exit(g_pTh); pthread_exit(0);
ev_loop_destroy(g_loop); ev_loop_destroy(g_loop);
g_loop = NULL; g_loop = NULL;
g_pTh = NULL; g_pTh = 0;
g_init = 0; g_init = 0;
...@@ -789,7 +784,7 @@ static int _init_client(){ ...@@ -789,7 +784,7 @@ static int _init_client(){
return -1; return -1;
} }
g_client_ctrl.sd = -1; g_client_ctrl.sd = -1;
return 0;
} }
...@@ -1001,11 +996,12 @@ int kk_tcp_client_init(char ip[MAX_IP_LEN], int port, ipc_cb cb) ...@@ -1001,11 +996,12 @@ int kk_tcp_client_init(char ip[MAX_IP_LEN], int port, ipc_cb cb)
_init_client(); _init_client();
g_client_ctrl.port = port; g_client_ctrl.port = port;
memcpy(g_client_ctrl.ip, ip, strlen(ip)); memcpy(g_client_ctrl.ip, ip, strlen(ip));
if (g_pTh ==NULL && 0 != pthread_create(&g_pTh, NULL, loop_tcp_client_thread, NULL)) { if (g_pTh ==0 && 0 != pthread_create(&g_pTh, NULL, loop_tcp_client_thread, NULL)) {
INFO_PRINT("create pthread failed\r\n"); INFO_PRINT("create pthread failed\r\n");
return -1; return -1;
}; };
g_client_ctrl.cb = cb; g_client_ctrl.cb = cb;
return 0;
} }
void kk_tcp_client_deinit(void){ void kk_tcp_client_deinit(void){
......
...@@ -263,7 +263,7 @@ int HAL_SetDevice_Code(_IN_ char *device_code) ...@@ -263,7 +263,7 @@ int HAL_SetDevice_Code(_IN_ char *device_code)
return -1; return -1;
} }
memset(g_device_code, 0x0, DEVICE_CODE_LEN); memset(g_device_code, 0x0, DEVICE_CODE_LEN);
strncpy(g_device_code, DEVICE_CODE_LEN, len); strncpy(g_device_code, device_code, len);
return len; return len;
} }
......
...@@ -15,9 +15,26 @@ ...@@ -15,9 +15,26 @@
uint64_t HAL_UptimeMs(void); uint64_t HAL_UptimeMs(void);
time_t HAL_Uptimes(void); time_t HAL_Uptimes(void);
void HAL_SleepMs(_IN_ uint32_t ms);
uint32_t HAL_Get_IP(char ip_str[NETWORK_ADDR_LEN], const char *ifname); uint32_t HAL_Get_IP(char ip_str[NETWORK_ADDR_LEN], const char *ifname);
time_t HAL_GetTime(void); time_t HAL_GetTime(void);
time_t HAL_GetTime_s(char *outStr); time_t HAL_GetTime_s(char *outStr);
int HAL_Snprintf(_IN_ char *str, const int len, const char *fmt, ...); int HAL_Snprintf(_IN_ char *str, const int len, const char *fmt, ...);
int HAL_Vsnprintf(_IN_ char *str, _IN_ const int len, _IN_ const char *format, va_list ap); int HAL_Vsnprintf(_IN_ char *str, _IN_ const int len, _IN_ const char *format, va_list ap);
void *HAL_MutexCreate(void);
void HAL_MutexLock(_IN_ void *mutex);
void HAL_MutexUnlock(_IN_ void *mutex);
void HAL_SemaphoreDestroy(_IN_ void *sem);
void *HAL_SemaphoreCreate(void);
int HAL_SemaphoreWait(_IN_ void *sem, _IN_ uint32_t timeout_ms);
void HAL_SemaphorePost(_IN_ void *sem);
int HAL_ThreadCreate(
_OU_ void **thread_handle,
_IN_ void *(*work_routine)(void *),
_IN_ void *arg,
_OU_ int *stack_used);
void HAL_MutexDestroy(_IN_ void *mutex);
int HAL_GetVersion(_OU_ char *version);
int HAL_Get_mac(char* mac);
int HAL_Get_SN(char sn[SN_ADDR_LEN]);
#endif #endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "cJSON.h"
/* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */
CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *pointer);
CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointerCaseSensitive(cJSON * const object, const char *pointer);
/* Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec. */
/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */
CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON * const from, cJSON * const to);
CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatchesCaseSensitive(cJSON * const from, cJSON * const to);
/* Utility for generating patch array entries. */
CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON * const array, const char * const operation, const char * const path, const cJSON * const value);
/* Returns 0 for success. */
CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches);
CJSON_PUBLIC(int) cJSONUtils_ApplyPatchesCaseSensitive(cJSON * const object, const cJSON * const patches);
/*
// Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use:
//int cJSONUtils_AtomicApplyPatches(cJSON **object, cJSON *patches)
//{
// cJSON *modme = cJSON_Duplicate(*object, 1);
// int error = cJSONUtils_ApplyPatches(modme, patches);
// if (!error)
// {
// cJSON_Delete(*object);
// *object = modme;
// }
// else
// {
// cJSON_Delete(modme);
// }
//
// return error;
//}
// Code not added to library since this strategy is a LOT slower.
*/
/* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */
/* target will be modified by patch. return value is new ptr for target. */
CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatch(cJSON *target, const cJSON * const patch);
CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON * const patch);
/* generates a patch to move from -> to */
/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */
CJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatch(cJSON * const from, cJSON * const to);
CJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatchCaseSensitive(cJSON * const from, cJSON * const to);
/* Given a root object and a target object, construct a pointer from one to the other. */
CJSON_PUBLIC(char *) cJSONUtils_FindPointerFromObjectTo(const cJSON * const object, const cJSON * const target);
/* Sorts the members of the object into alphabetical order. */
CJSON_PUBLIC(void) cJSONUtils_SortObject(cJSON * const object);
CJSON_PUBLIC(void) cJSONUtils_SortObjectCaseSensitive(cJSON * const object);
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