Commit ef9e834f authored by 陈伟灿's avatar 陈伟灿

Merge branch 'yjq' into 'master'

Yjq

See merge request chenweican/k-sdk!109
parents 52797464 a8d1c966
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include "Serial.h"
#define DBG_SERIAL 0
extern int verbosity;
extern volatile sig_atomic_t bRunning;
int serial_fd = 0;
//static struct termios options; //place for settings for serial port
char buf[255]; //buffer for where data is put
/**************serial open *******************/
/***********************************************************
* 名 称:int set_Parity(int fd,int databits,int stopbits,int parity)
* 功 能:串口属性
* 入口参数:无
* 出口参数:无
* 说 明:
**********************************************************/
/**
*@brief 设置串口数据位,停止位和效验位
*@param fd 类型 int 打开的串口文件句柄*
*@param databits 类型 int 数据位 取值 为 7 或者8*
*@param stopbits 类型 int 停止位 取值为 1 或者2*
*@param parity 类型 int 效验类型 取值为N,E,O,,S
*/
int set_Parity(int fd,int databits,int stopbits,int parity)
{
struct termios options;
if ( tcgetattr( fd,&options) != 0)
{
perror("SetupSerial 1");
return(0);
}
options.c_cflag &= ~CSIZE;
switch (databits) /*设置数据位数*/
{
case 7:
options.c_cflag |= CS7;
break;
case 8:
options.c_cflag |= CS8;
break;
default:
fprintf(stderr,"Unsupported data size\n");
return (0);
}
switch (parity)
{
case 'n':
case 'N':
options.c_cflag &= ~PARENB; /* Clear parity enable */
options.c_iflag &= ~INPCK; /* Enable parity checking */
break;
case 'o':
case 'O':
options.c_cflag |= (PARODD | PARENB); /* 设置为奇效验*/
options.c_iflag |= INPCK; /* Disnable parity checking */
break;
case 'e':
case 'E':
options.c_cflag |= PARENB; /* Enable parity */
options.c_cflag &= ~PARODD; /* 转换为偶效验*/
options.c_iflag |= INPCK; /* Disnable parity checking */
break;
case 'S':
case 's': /*as no parity*/
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
break;
default:
fprintf(stderr,"Unsupported parity\n");
return (0);
}
/* 设置停止位*/
switch (stopbits)
{
case 1:
options.c_cflag &= ~CSTOPB;
break;
case 2:
options.c_cflag |= CSTOPB;
break;
default:
fprintf(stderr,"Unsupported stop bits\n");
return (0);
}
/* Set input parity option */
if ((parity != 'n') && (parity != 'N'))
{
options.c_iflag |= INPCK;
}
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_oflag &= ~OPOST;
options.c_cflag |= (CLOCAL | CREAD);
options.c_oflag &= ~(ONLCR | OCRNL);
options.c_iflag &= ~(ICRNL | INLCR);
options.c_iflag &= ~(IXON | IXOFF | IXANY);
options.c_cc[VTIME] = 30; // 30 seconds
options.c_cc[VMIN] = 0;//15
tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */
if (tcsetattr(fd,TCSANOW,&options) != 0)
{
perror("SetupSerial 3");
return (0);
}
return (1);
}
/***********************************************************
* 名 称:set_speed(int fd, int speed)
* 功 能:串口波特率设置
* 入口参数:
* 出口参数:
* 说 明:
**********************************************************/
int speed_arr[] = { B115200,B38400, B19200, B9600, B4800, B2400, B1200, B300,\
B38400, B19200, B9600, B4800, B2400, B1200, B300, };
int name_arr[] = {115200,38400, 19200, 9600, 4800, 2400, 1200, 300,\
38400, 19200, 9600, 4800, 2400, 1200, 300, };
teSerial_Status set_speed(int fd, int speed)
{
printf("set_speed\n");
int i;
int status;
struct termios Opt;
tcgetattr(fd, &Opt);
for ( i= 0; i < sizeof(speed_arr) / sizeof(int); i++)
{
printf("input:%d,speed:%d,i = %d\n",speed,name_arr[i],i);
if (speed == name_arr[i])
{
SERIAL_LOG_ERR("speed:%d,i = %d\n",name_arr[i],i);
printf("speed:%d,i = %d\n",name_arr[i],i);
tcflush(fd, TCIOFLUSH);
cfsetispeed(&Opt, speed_arr[i]);
cfsetospeed(&Opt, speed_arr[i]);
status = tcsetattr(fd, TCSANOW, &Opt);
if (status != 0)
{
perror("tcsetattr fd1");
return E_ERROR;
}
tcflush(fd,TCIOFLUSH);
return E_SERIAL_OK;
}
}
return E_ERROR;
}
/***********************************************************
* 名 称:int devOpen(char *dev)
* 功 能:打开串口设备
* 入口参数:
* 出口参数:
* 说 明:
**********************************************************/
int devOpen(char *dev)
{
int fd;
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY);
if(fd == -1)
{
SERIAL_LOG_ERR("devOpen %s\n ",dev);
perror("devOpen");
return -1;
}
if (fd>0)
{
set_speed(fd,SERIAL_BAUD);
}
else
{
SERIAL_LOG_ERR("Can't Open Serial Port!\n");
return -1;
}
if (set_Parity(fd,8,1,'N')== 0)
{
SERIAL_LOG_ERR("Set Parity Error\n");
return -1;
}
return fd;
}
/***********************************/
/***********************************************************
* 名 称:eSerial_start()
* 功 能:打开串口
* 入口参数:
* 出口参数:
* 说 明:
**********************************************************/
void eSerial_start()
{
#if 0
int ret = eSerial_Init(SERIAL_NAME, SERIAL_BAUD, &serial_fd);
if(E_SERIAL_OK != ret)
{
SERIAL_LOG_ERR("Open serial faild\n");
}
#endif
serial_fd = devOpen(SERIAL_NAME);
}
/***********************************************************
* 名 称:eSerial_stop()
* 功 能:停止串口
* 入口参数:
* 出口参数:
* 说 明:
**********************************************************/
void eSerial_stop()
{
if(serial_fd>0)
{
close(serial_fd);
serial_fd = 0;
SERIAL_LOG_DBG("close serial_fd ok\n");
}
}
/***********************************************************
* 名 称:eSerial_Read(unsigned char *data)
* 功 能:读串口(单个字节)
* 入口参数:
* 出口参数:
* 说 明:
**********************************************************/
teSerial_Status eSerial_Read(unsigned char *data)
{
signed char res;
if(serial_fd <= 0)
{
return E_SERIAL_FD_ERROR;
}
res = read(serial_fd,data,1);
if (res > 0)
{
//SERIAL_LOG_DBG("RX 0x%02x\n", *data);
return E_SERIAL_OK;
}
else
{
printf("Serial read: %d\n", res);
if (res == 0)
{
}
return E_SERIAL_NODATA;
}
}
/***********************************************************
* 名 称:eSerial_Write(const unsigned char data)
* 功 能:读串口(单个字节)
* 入口参数:
* 出口参数:
* 说 明:
**********************************************************/
teSerial_Status eSerial_Write(const unsigned char data)
{
int err, attempts = 0;
if(serial_fd <= 0)
{
return E_SERIAL_FD_ERROR;
}
SERIAL_LOG_DBG("TX 0x%02x\n", data);
err = write(serial_fd,&data,1);
if (err < 0)
{
if (errno == EAGAIN)
{
for (attempts = 0; attempts <= 5; attempts++)
{
usleep(1000);
err = write(serial_fd,&data,1);
if (err < 0)
{
if ((errno == EAGAIN) && (attempts == 5))
{
SERIAL_LOG_ERR("Error writing to module after %d attempts(%s)", attempts, strerror(errno));
exit(-1);
}
}
else
{
break;
}
}
}
else
{
SERIAL_LOG_ERR("Error writing to module(%s)", strerror(errno));
exit(-1);
}
}
return E_SERIAL_OK;
}
/***********************************************************
* 名 称:eSerial_ReadBuffer(unsigned char *data, int *count)
* 功 能:读串口(多个字节)
* 入口参数:
* 出口参数:
* 说 明:
**********************************************************/
teSerial_Status eSerial_ReadBuffer(unsigned char *data, int *count)
{
int res;
if(serial_fd <= 0)
{
return E_SERIAL_FD_ERROR;
}
res = read(serial_fd, data, *count);
SERIAL_LOG_DBG("uart recv res:%d\n",res);
if (res > 0)
{
*count = res;
SERIAL_LOG_DBG("uart recv:%d\n",res);
return E_SERIAL_OK;
}
else
{
#if DEBUG
if (verbosity >= LOG_DEBUG) daemon_log(LOG_DEBUG, "Serial read: %d\n", res);
#endif /* DEBUG */
if(res < 0)
{
SERIAL_LOG_ERR("readbuff error\n");
return E_SERIAL_FD_ERROR;
}
if (res == 0)
{
//SERIAL_LOG_ERR("Serial connection to module interrupted");
//bRunning = 0;
}
res = *count = 0;
return E_SERIAL_NODATA;
}
}
/***********************************************************
* 名 称:eSerial_WriteBuffer(unsigned char *data, int *count)
* 功 能:写串口(多个字节)
* 入口参数:
* 出口参数:
* 说 明:
**********************************************************/
teSerial_Status eSerial_WriteBuffer(unsigned char *data, uint32_t count)
{
int attempts = 0;
//printf("send char %d\n", data);
int total_sent_bytes = 0, sent_bytes = 0;
while (total_sent_bytes < count)
{
sent_bytes = write(serial_fd, &data[total_sent_bytes], count - total_sent_bytes);
if (sent_bytes <= 0)
{
if (errno == EAGAIN)
{
if (++attempts >= 5)
{
SERIAL_LOG_ERR("Error writing to module(%s)", strerror(errno));
return E_SERIAL_ERROR;
}
usleep(1000);
}
else
{
SERIAL_LOG_ERR("Error writing to module(%s)", strerror(errno));
return -1;
}
}
else
{
attempts = 0;
total_sent_bytes += sent_bytes;
}
}
return E_SERIAL_OK;
}
#include <stdint.h>
#ifndef __SERIAL_H__
#define __SERIAL_H__
#include <syslog.h>
#if defined __cplusplus
extern "C" {
#endif
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
#define _SERIAL_LOG(level, fmt, args...) \
do \
{ \
syslog(level, fmt, ##args); \
printf("\n["__FILE__":%d] "fmt,__LINE__, ##args); \
} while(0)
#define SERIAL_LOG_DBG(fmt, args...) _SERIAL_LOG(LOG_DEBUG, fmt, ##args)
#define SERIAL_LOG_ERR(fmt, args...) _SERIAL_LOG(LOG_ERR, fmt, ##args)
#define SERIAL_NAME "/dev/ttyUSB0"//"/dev/ttyS0"
#define SERIAL_BAUD 115200
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
typedef enum
{
E_ERROR = -1,
E_SERIAL_OK = 0,
E_SERIAL_ERROR,
E_SERIAL_NODATA,
E_SERIAL_FD_ERROR,
} teSerial_Status;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
extern int serial_fd;
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
void eSerial_start();
void eSerial_stop();
teSerial_Status eSerial_Init(char *name, uint32_t baud, int *piserial_fd);
teSerial_Status eSerial_Read(unsigned char *data);
teSerial_Status eSerial_Write(const unsigned char data);
teSerial_Status eSerial_ReadBuffer(unsigned char *data, int *count);
teSerial_Status eSerial_WriteBuffer(unsigned char *data, uint32_t count);
/****************************************************************************/
/*** Local Functions ***/
/****************************************************************************/
/****************************************************************************/
/*** END OF FILE ***/
/****************************************************************************/
#if defined __cplusplus
}
#endif
#endif /* __SERIAL_H__ */
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
#include "kk_lan_ctrl.h" #include "kk_lan_ctrl.h"
#include "kk_lan_sync.h" #include "kk_lan_sync.h"
#include "kk_voice_panel_handle.h"
const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}"; const char DM_MSG_TO_MIDDWARE[] = "{\"msgtype\":\"%s\",\"productCode\":\"%s\",\"deviceCode\":\"%s\"}";
char *strrpl(char *in, char *out, int outlen, char *src, char *dst) char *strrpl(char *in, char *out, int outlen, char *src, char *dst)
{ {
...@@ -450,6 +453,7 @@ int is_arming_status_notify(cJSON *payload) ...@@ -450,6 +453,7 @@ int is_arming_status_notify(cJSON *payload)
return -1; return -1;
} }
extern int vp_syncinfo(cJSON *payload);
void KK_Data_FromMid(void* str,int len) void KK_Data_FromMid(void* str,int len)
{ {
...@@ -486,6 +490,7 @@ void KK_Data_FromMid(void* str,int len) ...@@ -486,6 +490,7 @@ void KK_Data_FromMid(void* str,int len)
if (strstr(msgtype->valuestring,SYNC_MSG_TYPE_REPLY) != NULL){ if (strstr(msgtype->valuestring,SYNC_MSG_TYPE_REPLY) != NULL){
kk_parse_syncinfo(payload); kk_parse_syncinfo(payload);
kk_create_syncinfo_to_sdk(payload); kk_create_syncinfo_to_sdk(payload);
kk_vp_syncinfo_handle(payload);
} }
else if(strstr(msgtype->valuestring,"/thing/event/property/post")!= NULL){ else if(strstr(msgtype->valuestring,"/thing/event/property/post")!= NULL){
...@@ -496,7 +501,7 @@ void KK_Data_FromMid(void* str,int len) ...@@ -496,7 +501,7 @@ void KK_Data_FromMid(void* str,int len)
arming_status_notify(type); arming_status_notify(type);
} }
}else{ }else{
//property_post_deal(deviceCode->valuestring,payload); property_post_deal(deviceCode->valuestring,payload);
} }
}else if(strstr(msgtype->valuestring,"/thing/topo/delete")!= NULL){ }else if(strstr(msgtype->valuestring,"/thing/topo/delete")!= NULL){
device_delete_sync(payload); device_delete_sync(payload);
......
...@@ -193,7 +193,7 @@ static char *kk_open_lan_cfg_file(char *deviceCode) ...@@ -193,7 +193,7 @@ static char *kk_open_lan_cfg_file(char *deviceCode)
return buf; return buf;
} }
//todo: //todo:
int kk_creater_nodeid(char *deviceCode,int channel,char *nodeId) int kk_creater_nodeid(char *deviceCode,int channel,char *nodeId,int operate_type)
{ {
static int next = 1; static int next = 1;
int node=-1; int node=-1;
...@@ -212,7 +212,7 @@ int kk_creater_nodeid(char *deviceCode,int channel,char *nodeId) ...@@ -212,7 +212,7 @@ int kk_creater_nodeid(char *deviceCode,int channel,char *nodeId)
while(kk_check_lan_node(next)){ while(kk_check_lan_node(next)){
++next; ++next;
} }
if(0==kk_lan_db_node_insert(deviceCode,channel,next)){ if(0==kk_lan_db_node_insert(deviceCode,channel,next,operate_type)){
node=next; node=next;
} }
} }
......
...@@ -34,6 +34,7 @@ int kk_create_devices_to_sdk(cJSON *root); ...@@ -34,6 +34,7 @@ int kk_create_devices_to_sdk(cJSON *root);
int _deviceCode_switchto_mac(char * deviceCode,char *mac); int _deviceCode_switchto_mac(char * deviceCode,char *mac);
int mac_switchto_deviceCode(char *mac,char * deviceCode); int mac_switchto_deviceCode(char *mac,char * deviceCode);
int kk_map_dev_search_by_deviceCode(char *deviceCode, kk_map_dev_node_t **node);
kk_map_dev_ctx *_kk_map_dev_ctx(void); kk_map_dev_ctx *_kk_map_dev_ctx(void);
int kk_map_dev_init(void); int kk_map_dev_init(void);
#endif #endif
\ No newline at end of file
...@@ -151,10 +151,14 @@ int kk_ccu_opcode_handle(cJSON *root) ...@@ -151,10 +151,14 @@ int kk_ccu_opcode_handle(cJSON *root)
kk_lan_db_deviceCode_get(atoi(nodeId->valuestring),deviceCode); kk_lan_db_deviceCode_get(atoi(nodeId->valuestring),deviceCode);
//execute scene
if((requester!=NULL) &&(strcmp(requester->valuestring,HJ_PROFILE)==0) && if((requester!=NULL) &&(strcmp(requester->valuestring,HJ_PROFILE)==0) &&
(strcmp(opcode->valuestring,"SWITCH")==0)){ (strcmp(opcode->valuestring,"SWITCH")==0)){
msg=scene_execute(nodeId->valuestring); msg=scene_execute(nodeId->valuestring);
kk_ipc_send_json(msg); kk_ipc_send_json(msg);
return 0; return 0;
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "com_api.h" #include "com_api.h"
#include "kk_product.h" #include "kk_product.h"
#include "kk_findccu_handle.h" #include "kk_findccu_handle.h"
...@@ -27,32 +31,35 @@ ...@@ -27,32 +31,35 @@
//#include "kk_lan_queue.h" //#include "kk_lan_queue.h"
#include "kk_lan_node_db.h" #include "kk_lan_node_db.h"
#include "kk_lan_voice_panel.h"
#include "kk_data_mng.h"
static char s_ccuid[DEVICE_CODE_LEN] = {0}; static char s_ccuid[DEVICE_CODE_LEN] = {0};
int kk_lan_get_ccuid(_OU_ char *device_code) int kk_lan_get_ccuid(_OU_ char *device_code)
{ {
strncpy(device_code, s_ccuid, strlen(s_ccuid)); strncpy(device_code, s_ccuid, strlen(s_ccuid));
printf("kk_lan_get_ccuid:%s\n",s_ccuid); printf("kk_lan_get_ccuid:%s\n",s_ccuid);
return strlen(s_ccuid); return strlen(s_ccuid);
} }
static int _setDevice_Code(_IN_ char *device_code,int len) static int _setDevice_Code(_IN_ char *device_code,int len)
{ {
memset(s_ccuid, 0x0, DEVICE_CODE_LEN); memset(s_ccuid, 0x0, DEVICE_CODE_LEN);
printf("_setDevice_Code:%s\n",device_code); printf("_setDevice_Code:%s\n",device_code);
strncpy(s_ccuid, device_code, len); strncpy(s_ccuid, device_code, len);
return len; return len;
} }
extern int HAL_Execel_cmd(char * cmd,char * buf,int buf_len,int* ret_len);
static void kk_lan_ccuid_init(void) static void kk_lan_ccuid_init(void)
{ {
uint8_t ccuid[DEVICE_CODE_LEN] = {0}; uint8_t ccuid[DEVICE_CODE_LEN] = {0};
int ccuid_len = 0; int ccuid_len = 0;
HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len); HAL_Execel_cmd(GET_CCUID_CMD,(char *)ccuid,sizeof(ccuid),&ccuid_len);
printf("GET_CCUID_CMD:%s\n",ccuid); printf("GET_CCUID_CMD:%s\n",ccuid);
if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){ if(ccuid_len > 0 && ccuid_len <= DEVICE_CODE_LEN){
_setDevice_Code(ccuid,ccuid_len-1); _setDevice_Code((char *)ccuid,ccuid_len-1);
}else{ }else{
_setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID)); _setDevice_Code(KK_CCU_ID,strlen(KK_CCU_ID));
} }
} }
...@@ -71,6 +78,7 @@ int main(int argc, char* argv[]) ...@@ -71,6 +78,7 @@ int main(int argc, char* argv[])
kk_findccu_handle_init(); kk_findccu_handle_init();
kk_map_dev_init(); kk_map_dev_init();
kk_login_init(); kk_login_init();
kk_voice_panel_init();
//lan_queue_init(); //lan_queue_init();
kk_lan_db_node_init(); kk_lan_db_node_init();
......
...@@ -46,7 +46,8 @@ static int _kk_lan_node_db_Init(void) ...@@ -46,7 +46,8 @@ static int _kk_lan_node_db_Init(void)
idx INTEGER PRIMARY KEY, \ idx INTEGER PRIMARY KEY, \
deviceCode varchar(33), \ deviceCode varchar(33), \
channel INTEGER, \ channel INTEGER, \
nodeId INTEGER)"; nodeId INTEGER, \
operate_type INTEGER)";
char *pcErr; char *pcErr;
...@@ -233,10 +234,10 @@ static int kk_lan_db_node_update(const char *deviceCode,int channel,int node) ...@@ -233,10 +234,10 @@ static int kk_lan_db_node_update(const char *deviceCode,int channel,int node)
*返 回 值: 0:成功;其他:失败 *返 回 值: 0:成功;其他:失败
*其他说明:属性的值插入的时候先置空,后续再update *其他说明:属性的值插入的时候先置空,后续再update
*************************************************************/ *************************************************************/
int kk_lan_db_node_insert(const char *deviceCode,int channel,int node) int kk_lan_db_node_insert(const char *deviceCode,int channel,int node,int operate_type)
{ {
const char *insertCmd = "insert into Map2Node (deviceCode,channel,nodeId) \ const char *insertCmd = "insert into Map2Node (deviceCode,channel,nodeId,operate_type) \
values ('%s','%d','%d');"; values ('%s','%d','%d','%d');";
char *sqlCmd = NULL; char *sqlCmd = NULL;
int rc = 0; int rc = 0;
char *zErrMsg = 0; char *zErrMsg = 0;
...@@ -250,7 +251,7 @@ int kk_lan_db_node_insert(const char *deviceCode,int channel,int node) ...@@ -250,7 +251,7 @@ int kk_lan_db_node_insert(const char *deviceCode,int channel,int node)
} }
_kk_lan_node_db_lock(); _kk_lan_node_db_lock();
sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,channel,node); sqlCmd = sqlite3_mprintf(insertCmd,deviceCode,channel,node,operate_type);
rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg); rc = sqlite3_exec(ctx->pDb, sqlCmd, NULL, NULL, &zErrMsg);
if( rc != SQLITE_OK ){ if( rc != SQLITE_OK ){
......
...@@ -18,7 +18,7 @@ enum{ ...@@ -18,7 +18,7 @@ enum{
}; };
int kk_lan_db_node_init(void); int kk_lan_db_node_init(void);
int kk_lan_db_node_insert(const char *deviceCode,int channel,int node); int kk_lan_db_node_insert(const char *deviceCode,int channel,int node,int operate_type);
int kk_lan_db_node_get(const char *deviceCode,int channel); int kk_lan_db_node_get(const char *deviceCode,int channel);
int kk_lan_db_node_get_all(const char *deviceCode,int *nodes); int kk_lan_db_node_get_all(const char *deviceCode,int *nodes);
......
...@@ -226,10 +226,9 @@ static int kk_sync_scene_condition(cJSON *condition,SYN_SCENE_ITEM **build) ...@@ -226,10 +226,9 @@ static int kk_sync_scene_condition(cJSON *condition,SYN_SCENE_ITEM **build)
int get_flag = 0; int get_flag = 0;
SYN_SCENE_ITEM *ptr=*build; SYN_SCENE_ITEM *ptr=*build;
printf("kk_sync_scene_condition,num=%d\n",num);
for(i=0;i<num;i++){ for(i=0;i<num;i++){
cJSON *item; cJSON *item;
printf("i=%d\n",i);
item = cJSON_GetArrayItem(condition,i); item = cJSON_GetArrayItem(condition,i);
startTime = cJSON_GetObjectItem(item,"startTime"); startTime = cJSON_GetObjectItem(item,"startTime");
...@@ -293,20 +292,18 @@ cJSON *kk_sync_scence_to_sdk(cJSON *root,cJSON *data) ...@@ -293,20 +292,18 @@ cJSON *kk_sync_scence_to_sdk(cJSON *root,cJSON *data)
if(strcmp(sceneType->valuestring,"")==){ if(strcmp(sceneType->valuestring,"")==){
}*/ }*/
//printf("--------------------------->[%s][%d]\n",__FUNCTION__,__LINE__);
pScene->act_num = kk_sync_actions(actions,&pScene->act,&pScene->room_id); pScene->act_num = kk_sync_actions(actions,&pScene->act,&pScene->room_id);
//printf("--------------------------->[%s][%d]\n",__FUNCTION__,__LINE__);
kk_sync_scene_condition(condition,&pScene); kk_sync_scene_condition(condition,&pScene);
//printf("--------------------------->[%s][%d]\n",__FUNCTION__,__LINE__);
pScene->scene_id = sceneId->valuestring; pScene->scene_id = sceneId->valuestring;
pScene->name = name->valuestring; pScene->name = name->valuestring;
pScene->pannel_id = NULL; pScene->pannel_id = NULL;
sceneItem = kk_scene_build(&pScene); sceneItem = kk_scene_build(&pScene);
//printf("--------------------------->[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddItemToArray(scenesAry,sceneItem); cJSON_AddItemToArray(scenesAry,sceneItem);
// printf("[%s][%d]%s\n",__FUNCTION__,__LINE__,cJSON_Print(sceneItem));
} }
...@@ -332,10 +329,8 @@ int _kk_sync_device_item(cJSON *deviceCode,cJSON *epNum,cJSON *name,cJSON *roomI ...@@ -332,10 +329,8 @@ int _kk_sync_device_item(cJSON *deviceCode,cJSON *epNum,cJSON *name,cJSON *roomI
list_for_each_entry(node, &ctx->dev_list, linked_list, kk_map_dev_node_t) { list_for_each_entry(node, &ctx->dev_list, linked_list, kk_map_dev_node_t) {
if (node != NULL) { if (node != NULL) {
printf("node->deviceCode=%s,%s\n",node->deviceCode,deviceCode->valuestring);
if(strlen(node->deviceCode)==strlen(deviceCode->valuestring) && if(strlen(node->deviceCode)==strlen(deviceCode->valuestring) &&
!strcmp(node->deviceCode,deviceCode->valuestring)){ !strcmp(node->deviceCode,deviceCode->valuestring)){
cJSON *subdevicesItem = cJSON_CreateObject(); cJSON *subdevicesItem = cJSON_CreateObject();
if(epNum==NULL ||epNum->type!=cJSON_String){ if(epNum==NULL ||epNum->type!=cJSON_String){
......
#include <stdio.h>
#include <syslog.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "kk_log.h"
#include "kk_lan_voice_panel.h"
#include "kk_voice_panel_cfg.h"
#include "kk_voice_panel_handle.h"
#include "Serial.h"
#include "uart_proto.h"
static pthread_mutex_t v_mux;
extern int serial_fd;
static void *kk_vp_uart_thread(void *arg)
{
fd_set rd;
int nFlag;
struct timeval tval = {2,0};
int count = 0;
unsigned char data_buf[512];
teSerial_Status ret = E_SERIAL_ERROR;
INFO_PRINT("[%s] start...\n",__FUNCTION__);
eSerial_start();
while (1)
{
FD_ZERO(&rd);
FD_SET(serial_fd,&rd);
nFlag = select(serial_fd + 1, &rd, NULL, NULL, &tval);
if(0 > nFlag)
{
ERROR_PRINT("uartRecv():select error !\n");
ERROR_PRINT("uartRecv errno = %d", errno);
usleep( 100000 );
}
else if(0 == nFlag)
{
usleep( 100000 );
}
else
{
if(FD_ISSET(serial_fd, &rd))
{
ret = eSerial_Read(&data_buf[count]);
if(ret == E_SERIAL_OK)
{
if(get_uart_frame((uint8_t *)data_buf,1))
{
uart_frame_handle();
}
}
else if(ret == E_SERIAL_FD_ERROR)
{
eSerial_start();
}
}
}
}
ERROR_PRINT("[%s]thread end...\n",__FUNCTION__);
}
typedef struct {
int next_ver;
int f_ver;
int f_size;
int crc32;
}vpCFGInfo;
typedef struct{
int state;
vpCFGInfo cfg_info;
int updateFlag;
}VP_MANAGE;
VP_MANAGE vp_mag;
char *vp_file_load(const char *path)
{
char *buff = NULL;
char *pRead = NULL;
int t_len = 0;
int remain = 0;
int r_len = 0;
FILE *fp = NULL;
int size = 0;
INFO_PRINT("[%s]vp load file(%s)\n",__FUNCTION__,path);
fp = fopen (path,"r");
if(fp==NULL){
printf("open err.\n");
return NULL;
}
fseek (fp, 0, SEEK_END);
size=ftell(fp);
printf("size=%d\n",size);
fseek (fp, 0, SEEK_SET);
buff = malloc(size+1);
memset(buff,0,size+1);
pRead = buff;
remain = size;
while(remain>0){
r_len = fread(pRead, 1, size, fp);
if(remain>=r_len){
remain -= r_len;
pRead+=r_len;
}else{
remain = 0;
pRead[size] = '\0';
}
}
fclose(fp);
return buff;
}
static int _vp_config_file_version_load(void)
{
cJSON *json = NULL;
cJSON *version = NULL;
char *pFile = vp_file_load(VP_CONFIG_FILE);
if(pFile==NULL){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 0;
}
if((json = cJSON_Parse(pFile))==NULL){
free(pFile);
return 0;
}
version = cJSON_GetObjectItem(json,"version");
if(version!=NULL &&version->type==cJSON_Number){
vp_mag.cfg_info.f_ver = version->valueint;
vp_mag.cfg_info.next_ver = version->valueint;
printf("[vp load config version]%d\n",vp_mag.cfg_info.f_ver);
}
cJSON_Delete(json);
free(pFile);
}
void kk_vp_set_updateFlag(int flag)
{
vp_mag.updateFlag = (flag!=0)?1:0;
}
void kk_vp_config_file_update(void)
{
if(vp_mag.updateFlag==0){
return ;
}
if(vp_mag.state == UPDATING_8009_CONFIG_FILE_INFO||
vp_mag.state == START_8009_CONFIG_FILE_UPDATE){
kk_vp_set_state_machine(STOP_8009_CONFIG_FILE_UPDATE);
}else{
kk_vp_set_state_machine(START_8009_CONFIG_FILE_UPDATE);
}
kk_vp_set_updateFlag(0);
}
void kk_vp_set_state_machine(int state)
{
if(vp_mag.state!=state){
INFO_PRINT("[vp state machine]%d->%d\n",vp_mag.state,state);
vp_mag.state = state;
}
}
void kk_vp_get_config_file_version(int ver)
{
return vp_mag.cfg_info.next_ver;
}
void kk_vp_set_config_file_version(int ver)
{
vp_mag.cfg_info.f_ver = (vp_mag.cfg_info.f_ver>ver)?vp_mag.cfg_info.f_ver:ver;
printf("[cfg ver]File Version=%08x\n",vp_mag.cfg_info.f_ver);
}
void kk_vp_cfg_info_set(uint32_t f_ver,uint32_t f_size,uint32_t crc32)
{
vp_mag.cfg_info.next_ver = f_ver;
vp_mag.cfg_info.f_ver = f_ver;
vp_mag.cfg_info.f_size = f_size;
vp_mag.cfg_info.crc32 = crc32;
printf("[set cfg info]File Version=%08x,File Size=%08x,CRC32=%08x\n",f_ver,f_size,crc32);
}
void kk_vp_cfg_info_check(uint32_t f_ver,uint32_t f_size,uint32_t crc32)
{
if(vp_mag.cfg_info.f_ver!=f_ver ||
vp_mag.cfg_info.crc32!=crc32){
printf("[VP]File Version=%08x,File Size=%08x,CRC32=%08x\n",f_ver,f_size,crc32);
printf("[LAN]File Version=%08x,File Size=%08x,CRC32=%08x\n",vp_mag.cfg_info.f_ver,vp_mag.cfg_info.f_size,vp_mag.cfg_info.crc32);
kk_vp_set_updateFlag(1);
printf("[%s][%d]update config file.\n",__FUNCTION__,__LINE__);
}
}
void kk_vp_update_result_check(uint8_t status,uint32_t f_ver)
{
if(status==0 && (vp_mag.cfg_info.f_ver==f_ver) ){
vp_mag.cfg_info.next_ver=vp_mag.cfg_info.f_ver+1;
printf("[cfg ver]File Version=%08x\n",vp_mag.cfg_info.f_ver);
kk_vp_set_state_machine(GET_8009_CONFIG_FILE_INFO);
}else{
kk_vp_set_updateFlag(1);
printf("[%s][%d]update config file.\n",__FUNCTION__,__LINE__);
}
}
int kk_vp_config_file_info_check(int f_ver,int f_size,int crc32)
{
kk_vp_set_state_machine(UPDATING_8009_CONFIG_FILE_INFO);
if(vp_mag.cfg_info.f_ver==f_ver &&
vp_mag.cfg_info.f_size==f_size &&
vp_mag.cfg_info.crc32==crc32){
kk_vp_set_state_machine(UPDATING_8009_CONFIG_FILE_INFO);
return 1;
}
return 0;
}
void kk_vp_manage_init(void)
{
vp_scene_id_map_load();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
_vp_config_file_version_load();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
vp_mag.cfg_info.f_size = _vp_get_cfg_file_size();
vp_mag.cfg_info.crc32 = _vp_get_cfg_file_crc32();
}
void *kk_vp_manage_thread(void *arg)
{
INFO_PRINT("[%s] start...\n",__FUNCTION__);
kk_vp_manage_init();
while (1)
{
kk_vp_config_file_update();
switch(vp_mag.state){
case GET_8009_SNAPSHOOT_STATE:
kk_vp_get_8009_snapshoot();
sleep(5);
break;
case SET_8009_SYSTEM:
kk_vp_set_8009_system_time();
sleep(5);
break;
case START_8009_CONFIG_FILE_UPDATE:
kk_vp_config_file_update_start(vp_mag.cfg_info.next_ver);
kk_vp_set_state_machine(UPDATING_8009_CONFIG_FILE_INFO);
break;
case UPDATING_8009_CONFIG_FILE_INFO:
//todo :超时取消
break;
case STOP_8009_CONFIG_FILE_UPDATE:
kk_vp_config_file_update_stop(vp_mag.cfg_info.f_ver);
if(vp_mag.updateFlag==1){
kk_vp_set_state_machine(UPDATING_8009_CONFIG_FILE_INFO);
}else{
kk_vp_set_state_machine(GET_8009_CONFIG_FILE_INFO);
}
sleep(3);
break;
case GET_8009_CONFIG_FILE_INFO:
kk_vp_get_config_file_info();
sleep(15);
break;
default:
break;
}
usleep(50*1000);
}
ERROR_PRINT("[%s]thread end...\n",__FUNCTION__);
}
int kk_voice_panel_init(void)
{
size_t s = 1500;
pthread_t uart_tid = 0;
pthread_t mag_tid = 0;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, s);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (pthread_mutex_init(&v_mux, NULL) != 0) {
pthread_attr_destroy(&attr);
ERROR_PRINT("pthread_mutex_init v_mux fail.\n");
return -1;
}
if((pthread_create(&uart_tid, &attr, kk_vp_uart_thread, NULL))!= 0 ) {
pthread_attr_destroy(&attr);
ERROR_PRINT("pthread_create kk_voice_panel fail\n");
return -2;
}
if((pthread_create(&mag_tid, NULL, kk_vp_manage_thread, NULL))!= 0 ) {
ERROR_PRINT("pthread_create kk_voice_panel fail\n");
return -3;
}
/*if((pthread_create(&tid3, NULL, kk_voice_panel_333, NULL))!= 0 ) {
ERROR_PRINT("pthread_create kk_voice_panel fail\n");
return -4;
}*/
return 0;
}
#ifndef _KK_LAN_VOICE_PANEL_H
#define _KK_LAN_VOICE_PANEL_H
int kk_voice_panel_init(void);
#define GET_8009_SNAPSHOOT_STATE 0
#define SET_8009_SYSTEM 1
#define START_8009_CONFIG_FILE_UPDATE 2
#define UPDATING_8009_CONFIG_FILE_INFO 3
#define STOP_8009_CONFIG_FILE_UPDATE 4
#define GET_8009_CONFIG_FILE_INFO 5
void kk_vp_set_state_machine(int state);
void kk_vp_set_config_file_version(int ver);
int kk_vp_config_file_info_check(int f_ver,int f_size,int crc32);
void kk_vp_update_result_check(uint8_t status,uint32_t f_ver);
void kk_vp_set_config_file_version(int ver);
void kk_vp_cfg_info_check(uint32_t f_ver,uint32_t f_size,uint32_t crc32);
void kk_vp_cfg_info_set(uint32_t f_ver,uint32_t f_size,uint32_t crc32);
void kk_vp_set_updateFlag(int flag);
#endif
#include "kk_data_mng.h"
#include "kk_lan_vp_ctrl.h"
#include "cJSON.h"
cJSON *PowerSwitch_msg_build(int ep,int onoff)
{
char epNum[12] = {0};
cJSON *params = cJSON_CreateObject();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
memset(epNum,0,sizeof(epNum));
snprintf(epNum,sizeof(epNum),"%d",ep);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddStringToObject(params,"epNum",epNum);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddNumberToObject(params,"PowerSwitch",onoff);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return params;
}
static int is_light_dev(int pid);
static cJSON *light_dev(int ep,int onoff);
static cJSON *light_dev_handle(int ep,uint8_t *arg);
static int is_curtain_dev(int pid);
static cJSON *curtain_dev_msg_build(int ep,int OperationMode);
static cJSON *curtain_dev_handle(int ep,uint8_t *arg);
static int is_outlet_dev(int pid);
static cJSON *outlet_msg_build(int ep,int onoff);
static cJSON *outlet_dev_handle(int ep,uint8_t *arg);
typedef int (*pid_mth_func)(int pid);
typedef cJSON *(*dev_handle)(int ep,uint8_t *arg);
typedef struct{
pid_mth_func mth;
dev_handle handle;
}KK_VP_CTRL;
static KK_VP_CTRL vp_ctrl_table[]={
{is_light_dev,light_dev_handle},
{is_curtain_dev,curtain_dev_handle},
{is_outlet_dev,outlet_dev_handle}
};
static int light_dev_pid[]={
3023,3024
};
static int curtain_dev_pid[]={
3067
};
static int outlet_dev_pid[]={
3020
};
static int is_light_dev(int pid)
{
int i;
for(i=0;i<sizeof(light_dev_pid)/sizeof(int);i++){
if(pid==light_dev_pid[i]){
return 1;
}
}
return 0;
}
static int is_curtain_dev(int pid)
{
int i;
for(i=0;i<sizeof(curtain_dev_pid)/sizeof(int);i++){
if(pid==curtain_dev_pid[i]){
return 1;
}
}
return 0;
}
static int is_outlet_dev(int pid)
{
int i;
for(i=0;i<sizeof(outlet_dev_pid)/sizeof(int);i++){
if(pid==outlet_dev_pid[i]){
return 1;
}
}
return 0;
}
static cJSON *light_msg_build(int ep,int onoff)
{
return PowerSwitch_msg_build(ep,onoff);
}
static cJSON *light_dev_handle(int ep,uint8_t *arg)
{
uint8_t skill_type = arg[0];
printf("[%s][%d]skill_type=%d,ep=%d\n",__FUNCTION__,__LINE__,skill_type,ep);
switch(skill_type){
case VP_CTRL_OPEN://
return light_msg_build(ep,1);
case VP_CTRL_CLOSE:
return light_msg_build(ep,0);
default:break;
}
return NULL;
}
static cJSON *curtain_dev_msg_build(int ep,int OperationMode)
{
char epNum[12] = {0};
cJSON *params = cJSON_CreateObject();
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
memset(epNum,0,sizeof(epNum));
snprintf(epNum,sizeof(epNum),"%d",ep);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddStringToObject(params,"epNum",epNum);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
cJSON_AddNumberToObject(params,"OperationMode",OperationMode);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return params;
}
static cJSON *curtain_dev_handle(int ep,uint8_t *arg)
{
uint8_t skill_type = arg[0];
printf("[%s][%d]skill_type=%d,ep=%d\n",__FUNCTION__,__LINE__,skill_type,ep);
switch(skill_type){
case VP_CTRL_OPEN://
return curtain_dev_msg_build(ep,1);
case VP_CTRL_CLOSE:
return curtain_dev_msg_build(ep,0);
case VP_CTRL_STOP:
return curtain_dev_msg_build(ep,2);
default:break;
}
return NULL;
}
static cJSON *outlet_msg_build(int ep,int onoff)
{
return PowerSwitch_msg_build(ep,onoff);
}
static cJSON *outlet_dev_handle(int ep,uint8_t *arg)
{
uint8_t skill_type = arg[0];
printf("[%s][%d]skill_type=%d,ep=%d\n",__FUNCTION__,__LINE__,skill_type,ep);
switch(skill_type){
case VP_CTRL_OPEN://
return outlet_msg_build(ep,1);
case VP_CTRL_CLOSE:
return outlet_msg_build(ep,0);
default:break;
}
return NULL;
}
void kk_lan_vp_control(uint8_t num,uint32_t nodeIdAry[],uint8_t *arg)
{
uint8_t i,j;
int ep;
int pid = 0;
char productCode[32] = {0};
char deviceCode[32] = {0};
cJSON *msg = NULL;
cJSON *params = NULL;
kk_map_dev_node_t *node = NULL;
KK_VP_CTRL *pVpCtr = vp_ctrl_table;
for(i=0;i<num;i++){
memset(deviceCode,0,sizeof(deviceCode));
memset(productCode,0,sizeof(productCode));
kk_lan_db_deviceCode_get(nodeIdAry[i],deviceCode);
kk_lan_db_channel_get(nodeIdAry[i],&ep);
if(kk_map_dev_search_by_deviceCode(deviceCode,&node) != 0){
continue ;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
snprintf(productCode,sizeof(productCode),"%s",node->productCode);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
pid = atoi(productCode);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
params = NULL;
for(j=0;j<sizeof(vp_ctrl_table)/sizeof(KK_VP_CTRL);j++,pVpCtr++){
if(pVpCtr->mth!=NULL && pVpCtr->handle!=NULL){
if(pVpCtr->mth(pid)){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
params = pVpCtr->handle(ep,arg);
break;
}
}
}
if(params!=NULL){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
msg=property_set(productCode,deviceCode,"*","*",params);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_ipc_send_json(msg);
}
}
}
#ifndef _KK_LAN_VP_CTRL_H
#define _KK_LAN_VP_CTRL_H
#include "kk_newccu_msg.h"
#include "kk_lan_node_db.h"
#define VP_CTRL_OPEN 0X01
#define VP_CTRL_CLOSE 0X02
#define VP_CTRL_STOP 0X03
#define VP_CTRL_GO_ON 0X04
#define VP_CTRL_QUERY_ONOFF_STATUS 0X05
#define VP_CTRL_QUERY_AIR_QUALITY 0X06
#define VP_CTRL_QUERY_HUMIDITY 0X07
#define VP_CTRL_QUERY_WATER_TMP 0X08
#define VP_CTRL_QUERY_TMP 0X09
#define VP_CTRL_QUERY_WEATHER 0X0A
#define VP_CTRL_PLAY 0X0C
#define VP_CTRL_LEAVE_UP 0X0D
#define VP_CTRL_LEAVE_DOWN 0X0E
#define VP_CTRL_LEAVE_SET 0X0F
#define VP_CTRL_WINDSPEE_UP 0X10
#define VP_CTRL_WINDSPEE_DOWN 0X11
#define VP_CTRL_WINDSPEE_SET 0X12
#define VP_CTRL_OPEN_LITTLE 0X16
#define VP_CTRL_UP 0X17
#define VP_CTRL_DOWN 0X18
#define VP_CTRL_BRIGHTNESS_DOWN 0X19
#define VP_CTRL_BRIGHTNESS_UP 0X1A
#define VP_CTRL_BRIGHTNESS_SET 0X1B
#define VP_CTRL_MODE 0X1C
#define VP_CTRL_PREVIOUS 0X1E
#define VP_CTRL_NEXT 0X1F
#define VP_CTRL_WIND_DIR 0x20
#define VP_CTRL_TMP_UP 0X23
#define VP_CTRL_TMP_DOWN 0x24
#define VP_CTRL_TMP_SET 0x25
#define VP_CTRL_SET_COLOR 0x26
#define VP_CTRL_SET_COLOR_TMP 0x27
#define VP_CTRL_ALTITUDE 0x28
void kk_lan_vp_control(uint8_t num,uint32_t nodeIdAry[],uint8_t *arg);
#endif
...@@ -199,7 +199,7 @@ void *TCPServer() ...@@ -199,7 +199,7 @@ void *TCPServer()
struct timeval timeout = {1, 0}; struct timeval timeout = {1, 0};
ret = select(Listenfd + 1, &fds,NULL, NULL, &timeout ); ret = select(Listenfd + 1, &fds,NULL, NULL, &timeout );
if(ret <= 0){ if(ret <= 0){
DEBUG_PRINT("TCPServer:TCP receiving nothing......\n"); //DEBUG_PRINT("TCPServer:TCP receiving nothing......\n");
//break; //break;
}else{ }else{
printf("[%s][%d]\n",__FUNCTION__,__LINE__); printf("[%s][%d]\n",__FUNCTION__,__LINE__);
......
...@@ -12,6 +12,25 @@ ...@@ -12,6 +12,25 @@
#include "kk_newccu_msg.h" #include "kk_newccu_msg.h"
#include "kk_product.h" #include "kk_product.h"
static pthread_mutex_t *mutex = NULL;
int kk_new_msg_init(void)
{
int err = 0;
mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
if (0 != (err = pthread_mutex_init(mutex, NULL))) {
free(mutex);
mutex = NULL;
printf("mutex init fail.");
}
return err;
}
cJSON *property_info_build(const char *msgtype,const char *productCode,const char *deviceCode) cJSON *property_info_build(const char *msgtype,const char *productCode,const char *deviceCode)
...@@ -113,13 +132,22 @@ int kk_ipc_send_json(cJSON *root) ...@@ -113,13 +132,22 @@ int kk_ipc_send_json(cJSON *root)
if(root==NULL){ if(root==NULL){
return -1; return -1;
} }
if(mutex==NULL){
kk_new_msg_init();
}
msg=cJSON_Print(root); msg=cJSON_Print(root);
printf("[lan->midware]json:\n%s\n",msg); printf("[lan->midware]json:\n%s\n",msg);
cJSON_Minify(msg); cJSON_Minify(msg);
pthread_mutex_lock(mutex);
kk_ipc_send(IPC_APP2MID, msg, strlen(msg)+1); kk_ipc_send(IPC_APP2MID, msg, strlen(msg)+1);
pthread_mutex_unlock(mutex);
free(msg); free(msg);
cJSON_Delete(root); cJSON_Delete(root);
return 0; return 0;
} }
......
...@@ -13,6 +13,9 @@ cJSON * property_report(const char *productCode,const char *deviceCode,const cha ...@@ -13,6 +13,9 @@ cJSON * property_report(const char *productCode,const char *deviceCode,const cha
int kk_ipc_send_json(cJSON *root); int kk_ipc_send_json(cJSON *root);
cJSON * scene_execute(const char *sceneId);
......
...@@ -171,7 +171,7 @@ cJSON *kk_devicestatus_build(kk_map_dev_node_t *node) ...@@ -171,7 +171,7 @@ cJSON *kk_devicestatus_build(kk_map_dev_node_t *node)
status = cJSON_CreateObject(); status = cJSON_CreateObject();
kk_creater_nodeid(node->deviceCode,1,nodeid); kk_creater_nodeid(node->deviceCode,1,nodeid,atoi(node->opearteType));
cJSON_AddStringToObject(status, OPCODE_STRING, node->syn_opcode); cJSON_AddStringToObject(status, OPCODE_STRING, node->syn_opcode);
cJSON_AddNumberToObject(status, NODEID_STRING, atoi(nodeid)); cJSON_AddNumberToObject(status, NODEID_STRING, atoi(nodeid));
......
#include <stdio.h>
#include <syslog.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "kk_voice_panel_cfg.h"
#include "kk_ccu_msg.h"
_OUT cJSON *scenes_ary_build(_IN int num,_IN VP_SCENE_ITEM list[]);
_OUT cJSON *rooms_ary_build(_IN int num,_IN VP_ROOM_ITEM list[]);
_OUT cJSON *ac_indoors_ary_build(_IN int num,_IN VP_AC_INDOOR_ITEM list[]);
_OUT cJSON *gws_ary_build(_IN int num,_IN VP_GW_ITEM list[]);
static pthread_mutex_t *mutex;
int kk_vp_cfg_init(void)
{
int err = 0;
mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
if (0 != (err = pthread_mutex_init(mutex, NULL))) {
free(mutex);
}
pthread_mutex_init(&mutex, NULL);
return err;
}
static _OUT cJSON *zigbee_devices_item_build(_IN VP_ZB_DEV_ITEM *item);
static _OUT int kk_vp_get_room_id_by_scene_id(_IN cJSON *data,_IN const char *scene_id,_IN int size,_OUT char *buf)
{
cJSON *roomsAry = NULL;
cJSON *roomObj = NULL;
cJSON *roomId = NULL,*scenes = NULL;
cJSON *sceneItem = NULL,*sceneId = NULL;
int i,j;
int roomNum = 0;
int sceneNum = 0;
if(scene_id==NULL ){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 0;
}
if((roomsAry = cJSON_GetObjectItem(data,ROOMS_STR))==NULL||
roomsAry->type!=cJSON_Array){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 0;
}
roomNum = cJSON_GetArraySize(roomsAry);
printf("[%s][%d]roomNum=%d,scene_id=%s\n",__FUNCTION__,__LINE__,roomNum,scene_id);
for(i=0;i<roomNum;i++){
roomObj = cJSON_GetArrayItem(roomsAry,i);
if(roomObj->type!=cJSON_Object){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
continue ;
}
roomId = cJSON_GetObjectItem(roomObj,ROOMS_ID_STR);
scenes= cJSON_GetObjectItem(roomObj,SCENES_STR);
if(roomId==NULL||roomId->type!=cJSON_String||
scenes==NULL||scenes->type!=cJSON_Array){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
continue ;
}
sceneNum = cJSON_GetArraySize(scenes);
printf("[%s][%d]sceneNum=%d\n",__FUNCTION__,__LINE__,sceneNum);
for(j=0;j<sceneNum;j++){
sceneItem = cJSON_GetArrayItem(scenes,j);
if((sceneId = cJSON_GetObjectItem(sceneItem,"sceneId"))==NULL ||
sceneId->type!=cJSON_String){
printf("[%s][%d]sceneId->type=%d\n",__FUNCTION__,__LINE__,sceneId->type);
continue ;
}
printf("[%s][%d]%d,%d,%s,%s\n",__FUNCTION__,__LINE__,strlen(sceneId->valuestring),strlen(scene_id),
scene_id,sceneId->valuestring);
if(strlen(sceneId->valuestring)==strlen(scene_id) &&
!strcmp(sceneId->valuestring,scene_id)) {
memset(buf,0,size);
snprintf(buf,size,"%s",roomId->valuestring);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 1;
}
}
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 0;
}
static _OUT cJSON *kk_vp_sync_rooms(_IN cJSON *data)
{
cJSON *roomsAry = NULL;
cJSON *roomObj = NULL;
cJSON *roomId = NULL,*name = NULL;
VP_ROOM_ITEM *roomsItems = NULL;
VP_ROOM_ITEM* pRoomItem = NULL;
int i,roomNum = 0;
if((roomsAry = cJSON_GetObjectItem(data,ROOMS_STR))==NULL||
roomsAry->type!=cJSON_Array){
return rooms_ary_build(0,NULL);
}
if((roomNum = cJSON_GetArraySize(roomsAry))==0){
return rooms_ary_build(0,NULL);
}
roomsItems = (VP_ROOM_ITEM*)malloc(sizeof(VP_ROOM_ITEM)*roomNum);
memset(roomsItems,0,(sizeof(VP_ROOM_ITEM)*roomNum));
pRoomItem = roomsItems;
for(i=0;i<roomNum;i++,pRoomItem++){
if((roomObj = cJSON_GetArrayItem(roomsAry,i))==NULL||
roomObj->type!=cJSON_Object){
continue ;
}
roomId = cJSON_GetObjectItem(roomObj,ROOMS_ID_STR);
name = cJSON_GetObjectItem(roomObj,NAME_STR);
if(roomId==NULL||roomId->type!=cJSON_String||
name==NULL||name->type!=cJSON_String){
continue ;
}
snprintf(pRoomItem->id,sizeof(pRoomItem->id)-1,"%s",roomId->valuestring);
snprintf(pRoomItem->name,sizeof(pRoomItem->name)-1,"%s",name->valuestring);
}
roomsAry = rooms_ary_build(roomNum,roomsItems);
free(roomsItems);
return roomsAry;
}
static _OUT cJSON *kk_vp_sync_scences(_IN cJSON *data)
{
int i,sceneNum = 0;
cJSON *scenesAry = NULL;
cJSON *scenes = NULL;
cJSON *sceneName = NULL,*sceneId = NULL,*sceneType = NULL;
cJSON *item = NULL;
char roomId[32] = {0};
VP_SCENE_ITEM *pSceneList = NULL;
VP_SCENE_ITEM *pScene = NULL;
if((scenes = cJSON_GetObjectItem(data,SCENES_STR))==NULL||
scenes->type!=cJSON_Array){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return scenes_ary_build(0,NULL);
}
if((sceneNum = cJSON_GetArraySize(scenes))==0){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return scenes_ary_build(0,NULL);
}
pSceneList = (VP_SCENE_ITEM *)malloc(sizeof(VP_SCENE_ITEM)*sceneNum);
memset(pSceneList,0,sizeof(VP_SCENE_ITEM)*sceneNum);
pScene = pSceneList;
vp_scene_id_map_deinit();
for(i=0;i<sceneNum;i++,pScene++){
item = cJSON_GetArrayItem(scenes,i);
sceneId= cJSON_GetObjectItem(item,SCENE_ID_STR);
sceneType= cJSON_GetObjectItem(item,SCENE_TYPE_STR);
sceneName = cJSON_GetObjectItem(item,NAME_STR);
if(sceneId==NULL||sceneId->type!=cJSON_String||
sceneType==NULL||sceneType->type!=cJSON_Number||
sceneName==NULL||sceneName->type!=cJSON_String){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
continue ;
}
if(kk_vp_get_room_id_by_scene_id(data,sceneId->valuestring,sizeof(roomId),roomId)!=0){
int map_id = vp_scene_id_item_add(atoi(sceneId->valuestring));
snprintf(pScene->room,sizeof(pScene->room)-1,"%s",roomId);
snprintf(pScene->id,sizeof(pScene->id)-1,"%d",map_id);
snprintf(pScene->type,sizeof(pScene->type)-1,"%d",sceneType->valueint);
snprintf(pScene->name,sizeof(pScene->name)-1,"%s",sceneName->valuestring);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
}
}
vp_scene_id_map_save();
scenesAry = scenes_ary_build(sceneNum,pSceneList);
free(pSceneList);
return scenesAry;
}
static int kk_vp_get_device_name(_IN cJSON *devices,_IN const char*epNum,_IN const char*deviceCode,_IN int size,_OUT char *buf)
{
int i = 0,devNum = 0;
cJSON *name = NULL;
cJSON *deviceItem = NULL,*devCodeObj = NULL;
devNum = cJSON_GetArraySize(devices);
printf("[%s][%d]devNum=%d\n",__FUNCTION__,__LINE__,devNum);
for(i=0;i<devNum;i++){
deviceItem = cJSON_GetArrayItem(devices,i);
if(deviceItem->type!=cJSON_Object){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
continue ;
}
devCodeObj = cJSON_GetObjectItem(deviceItem,"deviceCode");
if(devCodeObj==NULL||devCodeObj->type!=cJSON_String){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
continue ;
}
printf("[%s][%d]%d,%d,%s,%s\n",__FUNCTION__,__LINE__,strlen(devCodeObj->valuestring),
strlen(deviceCode),devCodeObj->valuestring,deviceCode);
if((strlen(devCodeObj->valuestring)==strlen(deviceCode)) &&
!strcmp(devCodeObj->valuestring,deviceCode)){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if((name = cJSON_GetObjectItem(deviceItem,"name"))!=NULL &&
name->type==cJSON_String){
printf("[%s][%d]name=%s\n",__FUNCTION__,__LINE__,name->valuestring);
snprintf(buf,size,"%s",name->valuestring);
return 1;
}
}
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 0;
}
static int kk_vp_get_device_info(_IN cJSON *rooms,_IN VP_ZB_DEV_ITEM *pDevs)
{
cJSON *roomItem = NULL;
cJSON *roomId = NULL,*devices = NULL;
int i = 0,roomNum = 0,isFind = 0;
roomNum = cJSON_GetArraySize(rooms);
printf("[%s][%d]roomNum=%d\n",__FUNCTION__,__LINE__,roomNum);
for(i=0;i<roomNum;i++){
roomItem = cJSON_GetArrayItem(rooms,i);
if((roomId = cJSON_GetObjectItem(roomItem,ROOMS_ID_STR))==NULL||
roomId->type!=cJSON_String){
printf("[prase fail]roomId...\n");
continue ;
}
if((devices= cJSON_GetObjectItem(roomItem,DEVICES_STR))==NULL ||
devices->type!=cJSON_Array){
printf("[prase fail]devices...\n");
continue ;
}
isFind = kk_vp_get_device_name(devices,pDevs->ch,pDevs->mac,sizeof(pDevs->name),pDevs->name);
if(isFind!=0){
snprintf(pDevs->room,sizeof(pDevs->room),"%s",roomId->valuestring);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return isFind;
}
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 0;
}
static int kk_vp_sync_device_multi_eps(_IN cJSON *zbDevsAry,_IN cJSON *dev,_IN cJSON *rooms,_IN cJSON *eps)
{
int nodeId;
kk_map_dev_node_t *node = NULL;
VP_ZB_DEV_ITEM *pDevs = NULL;
cJSON *zbDevObj = NULL;
cJSON *mac = NULL,*onlineStatus = NULL,*productCode = NULL;
cJSON *epItem = NULL,*epNum = NULL;
int i = 0,num = 0,isFind = 0;
pDevs = (VP_ZB_DEV_ITEM *)malloc(sizeof(VP_ZB_DEV_ITEM));
memset(pDevs,0,sizeof(VP_ZB_DEV_ITEM));
mac = cJSON_GetObjectItem(dev,"mac");
onlineStatus = cJSON_GetObjectItem(dev,"onlineStatus");
productCode = cJSON_GetObjectItem(dev,"productCode");
if(mac==NULL||mac->type!=cJSON_String){
snprintf(pDevs->mac,sizeof(pDevs->mac)-1,"%s","0000000000000000");
}else{
snprintf(pDevs->mac,sizeof(pDevs->mac)-1,"%s",mac->valuestring);
}
if(onlineStatus==NULL||onlineStatus->type!=cJSON_Number){
snprintf(pDevs->online,sizeof(pDevs->online)-1,"%d",0);
}else{
snprintf(pDevs->online,sizeof(pDevs->online)-1,"%d",onlineStatus->valueint);
}
if(productCode==NULL||productCode->type!=cJSON_String){
snprintf(pDevs->pid,sizeof(pDevs->pid)-1,"%d",-1);
}else{
snprintf(pDevs->pid,sizeof(pDevs->pid)-1,"%s",productCode->valuestring);
}
num = cJSON_GetArraySize(eps);
printf("[%s][%d]num=%d\n",__FUNCTION__,__LINE__,num);
for(i=0;i<num;i++){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
memset(pDevs->ch,0,sizeof(pDevs->ch));
memset(pDevs->name,0,sizeof(pDevs->name));
memset(pDevs->room,0,sizeof(pDevs->room));
epItem = cJSON_GetArrayItem(eps,i);
if((epNum = cJSON_GetObjectItem(epItem,"epNum"))==NULL ||
epNum->type!=cJSON_String){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
continue ;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
snprintf(pDevs->ch,sizeof(pDevs->ch)-1,"%s",epNum->valuestring);
nodeId = kk_lan_db_node_get(pDevs->mac,atoi(pDevs->ch));
snprintf(pDevs->nodeId,sizeof(pDevs->nodeId)-1,"%d",nodeId);
if(kk_map_dev_search_by_deviceCode(pDevs->mac,&node) != 0){
snprintf(pDevs->operateType,sizeof(pDevs->operateType)-1,"%s",node->opearteType);
}else{
snprintf(pDevs->operateType,sizeof(pDevs->operateType)-1,"%s","1");
}
printf("pDevs->mac=%s,pDevs->ch=%s,pDevs->nodeId=%s\n",pDevs->mac,pDevs->ch,pDevs->nodeId);
if(kk_vp_get_device_info(rooms,pDevs)!=0){
if((zbDevObj = zigbee_devices_item_build(pDevs))!=NULL){
cJSON_AddItemToArray(zbDevsAry,zbDevObj);
isFind = 1;
}
}
}
free(pDevs);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return isFind;
}
static int kk_vp_sync_device_single_ep(_IN cJSON *zbDevsAry,_IN cJSON *dev,_IN cJSON *rooms)
{
int nodeId;
kk_map_dev_node_t *node = NULL;
VP_ZB_DEV_ITEM *pDevs = NULL;
cJSON *zbDevObj = NULL;
cJSON *mac = NULL,*onlineStatus = NULL,*productCode = NULL;
pDevs = (VP_ZB_DEV_ITEM *)malloc(sizeof(VP_ZB_DEV_ITEM));
memset(pDevs,0,sizeof(VP_ZB_DEV_ITEM));
mac = cJSON_GetObjectItem(dev,"mac");
onlineStatus = cJSON_GetObjectItem(dev,"onlineStatus");
productCode = cJSON_GetObjectItem(dev,"productCode");
snprintf(pDevs->ch,sizeof(pDevs->ch)-1,"%d",1);
if(mac==NULL||mac->type!=cJSON_String){
snprintf(pDevs->mac,sizeof(pDevs->mac)-1,"%s","0000000000000000");
}else{
snprintf(pDevs->mac,sizeof(pDevs->mac)-1,"%s",mac->valuestring);
}
if(onlineStatus==NULL||onlineStatus->type!=cJSON_Number){
snprintf(pDevs->online,sizeof(pDevs->online)-1,"%d",0);
}else{
snprintf(pDevs->online,sizeof(pDevs->online)-1,"%d",onlineStatus->valueint);
}
if(productCode==NULL||productCode->type!=cJSON_String){
snprintf(pDevs->pid,sizeof(pDevs->pid)-1,"%d",-1);
}else{
snprintf(pDevs->pid,sizeof(pDevs->pid)-1,"%s",productCode->valuestring);
}
nodeId = kk_lan_db_node_get(pDevs->mac,atoi(pDevs->ch));
snprintf(pDevs->nodeId,sizeof(pDevs->nodeId)-1,"%d",nodeId);
if(kk_map_dev_search_by_deviceCode(pDevs->mac,&node) != 0){
snprintf(pDevs->operateType,sizeof(pDevs->operateType)-1,"%s",node->opearteType);
}else{
snprintf(pDevs->operateType,sizeof(pDevs->operateType)-1,"%s","1");
}
if(kk_vp_get_device_info(rooms,pDevs)!=0){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
if((zbDevObj = zigbee_devices_item_build(pDevs))!=NULL){
cJSON_AddItemToArray(zbDevsAry,zbDevObj);
free(pDevs);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 1;
}
}
free(pDevs);
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 0;
}
static _OUT cJSON *kk_vp_sync_device(_IN cJSON *data)
{
int i,j;
cJSON *zbDevsAry = NULL;
int devicesAryNum = 0;
int subDevAryNum = 0;
cJSON *devicesAry = NULL;
cJSON *devicesAryItem = NULL;
cJSON *subDevAry = NULL;
cJSON *roomsAry = NULL;
cJSON *dev = NULL;
cJSON *properties = NULL;
cJSON *eps = NULL;
if((zbDevsAry = cJSON_CreateArray())==NULL){
printf("[cJSON_CreateArray err]zbDevsAry...\n");
return NULL;
}
devicesAry = cJSON_GetObjectItem(data,DEVICES_STR);
if(devicesAry==NULL ||
devicesAry->type!=cJSON_Array){
return zbDevsAry;
}
devicesAryNum = cJSON_GetArraySize(devicesAry);
for(i=0;i<devicesAryNum;i++){
devicesAryItem = cJSON_GetArrayItem(devicesAry,i);
if(devicesAryItem==NULL||devicesAryItem->type!=cJSON_Object){
printf("[prase fail]devicesAryItem...\n");
continue;
}
subDevAry = cJSON_GetObjectItem(devicesAryItem,DEVICES_STR);
if(subDevAry==NULL||subDevAry->type!=cJSON_Array){
printf("[prase fail]subDevAry...\n");
continue;
}
subDevAryNum = cJSON_GetArraySize(subDevAry);
for(j=0;j<subDevAryNum;j++){
if((dev = cJSON_GetArrayItem(subDevAry,j))==NULL||
dev->type!=cJSON_Object){
printf("[prase fail]dev...\n");
continue ;
}
if((properties = cJSON_GetObjectItem(dev,"properties"))==NULL||
properties->type!=cJSON_Object){
printf("[prase fail]properties...\n");
continue ;
}
eps = cJSON_GetObjectItem(properties,"eps");
roomsAry = cJSON_GetObjectItem(data,ROOMS_STR);
if(roomsAry==NULL||roomsAry->type!=cJSON_Array){
printf("[prase fail]roomsAry...\n");
continue ;
}
if(eps==NULL){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_vp_sync_device_single_ep(zbDevsAry,dev,roomsAry);
}else if(eps->type==cJSON_Array){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
kk_vp_sync_device_multi_eps(zbDevsAry,dev,roomsAry,eps);
}
}
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return zbDevsAry;
}
static _OUT cJSON *kk_vp_sync_gws(_IN cJSON *data)
{
int i,gw_num = 0;
cJSON *gwAry = NULL;
cJSON *devicesAry = NULL;
cJSON *item = NULL,*gw_mac = NULL,*gw_name = NULL;
VP_GW_ITEM *gws = NULL;
if((devicesAry = cJSON_GetObjectItem(data,DEVICES_STR)) == NULL
||devicesAry->type!=cJSON_Array){
return gws_ary_build(0,NULL);
}
if((gw_num = cJSON_GetArraySize(devicesAry))==0){
return gws_ary_build(0,NULL);
}
gws = (VP_GW_ITEM *)malloc(sizeof(VP_GW_ITEM)*gw_num);
memset(gws,0,sizeof(VP_GW_ITEM)*gw_num);
for(i=0;i<gw_num;i++){
if((item = cJSON_GetArrayItem(devicesAry,i))==NULL||
item->type!=cJSON_Object){
continue ;
}
gw_mac = cJSON_GetObjectItem(item,"mac");
gw_name = cJSON_GetObjectItem(item,"name");
if(gw_mac==NULL||gw_mac->type!=cJSON_String){
snprintf(gws->mac,sizeof(gws->mac)-1,"%016d",i);
}else {
snprintf(gws->mac,sizeof(gws->mac)-1,"%s",gw_mac->valuestring);
}
if(gw_name==NULL||gw_name->type!=cJSON_String){
snprintf(gws->name,sizeof(gws->name)-1,"gw%d",i);
}else {
snprintf(gws->name,sizeof(gws->name)-1,"%s",gw_name->valuestring);
}
snprintf(gws->nodeId,sizeof(gws->nodeId)-1,"%d",0);
}
gwAry = gws_ary_build(gw_num,gws);
free(gws);
return gwAry;
}
static _OUT cJSON *kk_vp_sync_ac_indoors(_IN cJSON *data)
{
//todo:
return ac_indoors_ary_build(0,NULL);
}
//保留
static _OUT cJSON *infrared_codelib_info_ary_build(_IN cJSON *data)
{
cJSON *resAry = cJSON_CreateArray();
return resAry;
}
//保留
static _OUT cJSON *controller_buttons_config_build(_IN cJSON *data)
{
return cJSON_CreateNull();
}
_OUT cJSON * kk_voice_panel_cfg_build(_IN VP_CFG_JSON *arg,int ver)
{
cJSON *root = NULL;
cJSON *params = NULL;
if(arg == NULL || arg->controller_buttons_config == NULL ||
arg->gws == NULL ||arg->infrared_codelib_info == NULL ||
arg->other_devices == NULL ||arg->rooms == NULL ||
arg->scenes == NULL ||arg->zigbee_devices == NULL){
return root;
}
if((root = cJSON_CreateObject())!=NULL){
if((params = cJSON_CreateObject())!=NULL) {
cJSON_AddItemToObject(params,"controller_buttons_config",arg->controller_buttons_config);
cJSON_AddItemToObject(params,"gws",arg->gws);
cJSON_AddItemToObject(params,"infrared_codelib_info",arg->infrared_codelib_info);
cJSON_AddItemToObject(params,"other_devices",arg->other_devices);
cJSON_AddItemToObject(params,"rooms",arg->rooms);
cJSON_AddItemToObject(params,"scenes",arg->scenes);
cJSON_AddItemToObject(params,"zigbee_devices",arg->zigbee_devices);
cJSON_AddItemToObject(root, "params",params);
}
cJSON_AddNumberToObject(root, "version",ver);
}
return root;
}
static _OUT cJSON *zigbee_devices_item_build(_IN VP_ZB_DEV_ITEM *item)
{
cJSON *devItemObj = NULL;
cJSON *chansAry = NULL;
if(item == NULL ||item->operateType==NULL||item->nodeId==NULL||
item->name==NULL||item->room == NULL||item->mac == NULL||
item->online == NULL||item->pid == NULL){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return NULL;
}
if((devItemObj = cJSON_CreateObject())!=NULL) {
if((chansAry = cJSON_CreateArray())!=NULL){
cJSON *chansItem = cJSON_CreateObject();
cJSON_AddStringToObject(chansItem, "oid",item->operateType);
cJSON_AddStringToObject(chansItem, "id",item->nodeId);
cJSON_AddStringToObject(chansItem, "name",item->name);
cJSON_AddStringToObject(chansItem, "room",item->room);
cJSON_AddStringToObject(chansItem, "chan",item->ch);
cJSON_AddItemToArray(chansAry,chansItem);
cJSON_AddItemToObject(devItemObj, "chans", chansAry);
}
cJSON_AddStringToObject(devItemObj, "mac",item->mac);
cJSON_AddStringToObject(devItemObj, "online",item->online);
cJSON_AddStringToObject(devItemObj, "pid",item->pid);
cJSON_AddStringToObject(devItemObj, "gw","1");
cJSON_AddStringToObject(devItemObj, "zaddr","0000");
cJSON_AddStringToObject(devItemObj, "mid","00000000");
}
return devItemObj;
}
_OUT cJSON *zigbee_devices_ary_build(_IN int num,_IN VP_ZB_DEV_ITEM list[])
{
int i = 0;
cJSON *zbDevsAry = NULL;
cJSON *zbDevObj = NULL;
VP_ZB_DEV_ITEM *pItem = NULL;
zbDevsAry = cJSON_CreateArray();
if(list==NULL || num==0){
return zbDevsAry;
}
pItem = (VP_ZB_DEV_ITEM *)list;
for(i=0;i<num;i++,pItem++){
if((zbDevObj = zigbee_devices_item_build(pItem))!=NULL){
cJSON_AddItemToArray(zbDevsAry,zbDevObj);
}
}
return zbDevsAry;
}
static _OUT cJSON *scenes_item_build(_IN VP_SCENE_ITEM *item)
{
cJSON *sceItemObj = NULL;
if(item == NULL ||item->id==NULL||item->name==NULL ||
item->room==NULL||item->type==NULL){
return NULL;
}
if((sceItemObj = cJSON_CreateObject())!=NULL) {
cJSON_AddStringToObject(sceItemObj, "id",item->id);
cJSON_AddStringToObject(sceItemObj, "name",item->name);
cJSON_AddStringToObject(sceItemObj, "room",item->room);
cJSON_AddStringToObject(sceItemObj, "type",item->type);
}
return sceItemObj;
}
_OUT cJSON *scenes_ary_build(_IN int num,_IN VP_SCENE_ITEM list[])
{
int i = 0;
cJSON *scenesAry = NULL;
cJSON *sceneObj = NULL;
VP_SCENE_ITEM *pItem = NULL;
scenesAry = cJSON_CreateArray();
if(list==NULL || num==0){
return scenesAry;
}
pItem = (VP_SCENE_ITEM *)list;
for(i=0;i<num;i++,pItem++){
if((sceneObj = scenes_item_build(pItem))!=NULL){
cJSON_AddItemToArray(scenesAry,sceneObj);
}
}
return scenesAry;
}
static _OUT cJSON *room_item_build(_IN VP_ROOM_ITEM *item)
{
cJSON *roomObj = NULL;
if(item == NULL ||item->id==NULL||item->name==NULL){
return NULL;
}
if((roomObj = cJSON_CreateObject())!=NULL) {
cJSON_AddStringToObject(roomObj, "id",item->id);
cJSON_AddStringToObject(roomObj, "name",item->name);
}
return roomObj;
}
_OUT cJSON *rooms_ary_build(_IN int num,_IN VP_ROOM_ITEM list[])
{
int i = 0;
cJSON *roomsAry = NULL;
cJSON *roomObj = NULL;
VP_ROOM_ITEM *pItem = NULL;
roomsAry = cJSON_CreateArray();
if(list==NULL || num==0){
return roomsAry;
}
pItem = (VP_ROOM_ITEM *)list;
for(i=0;i<num;i++,pItem++){
if((roomObj = room_item_build(pItem))!=NULL){
cJSON_AddItemToArray(roomsAry,roomObj);
}
}
return roomsAry;
}
static _OUT cJSON *ac_indoor_item_build(_IN VP_AC_INDOOR_ITEM *item)
{
cJSON *indoorObj = NULL;
if(item == NULL ||item->ac_gw_nodeId==NULL||item->addr==NULL ||
item->nodeId==NULL ||item->name==NULL||item->operateType==NULL||item->room==NULL){
return NULL;
}
if((indoorObj = cJSON_CreateObject())!=NULL) {
cJSON_AddStringToObject(indoorObj, "ac_gw_id",item->ac_gw_nodeId);
cJSON_AddStringToObject(indoorObj, "addr",item->addr);
cJSON_AddStringToObject(indoorObj, "id",item->nodeId);
cJSON_AddStringToObject(indoorObj, "name",item->name);
cJSON_AddStringToObject(indoorObj, "oid",item->operateType);
cJSON_AddStringToObject(indoorObj, "room",item->room);
cJSON_AddNumberToObject(indoorObj, "online",item->online);
}
return indoorObj;
}
_OUT cJSON *ac_indoors_ary_build(_IN int num,_IN VP_AC_INDOOR_ITEM list[])
{
int i = 0;
cJSON *acIndoorsAry = NULL;
cJSON *acIndoorObj = NULL;
VP_AC_INDOOR_ITEM *pItem = NULL;
acIndoorsAry = cJSON_CreateArray();
if(list==NULL || num==0){
return acIndoorsAry;
}
pItem = (VP_AC_INDOOR_ITEM *)list;
for(i=0;i<num;i++,pItem++){
if((acIndoorObj = ac_indoor_item_build(pItem))!=NULL){
cJSON_AddItemToArray(acIndoorsAry,acIndoorObj);
}
}
return acIndoorsAry;
}
static _OUT cJSON *gw_item_build(_IN VP_GW_ITEM *item)
{
cJSON *gwObj = NULL;
if(item == NULL || item->nodeId==NULL||
item->mac==NULL || item->name==NULL ){
return NULL;
}
if((gwObj = cJSON_CreateObject())!=NULL) {
cJSON_AddStringToObject(gwObj, "id",item->nodeId);
cJSON_AddStringToObject(gwObj, "mac",item->mac);
cJSON_AddStringToObject(gwObj, "name",item->name);
}
return gwObj;
}
_OUT cJSON *gws_ary_build(_IN int num,_IN VP_GW_ITEM list[])
{
int i = 0;
cJSON *gwsAry = NULL;
cJSON *gwObj = NULL;
VP_GW_ITEM *pItem = NULL;
gwsAry = cJSON_CreateArray();
if(list==NULL || num==0){
return gwsAry;
}
pItem = (VP_GW_ITEM *)list;
for(i=0;i<num;i++,pItem++){
if((gwObj = gw_item_build(pItem))!=NULL){
cJSON_AddItemToArray(gwsAry,gwObj);
}
}
return gwsAry;
}
_OUT int kk_vp_syncinfo(_IN cJSON *payload,_IN int ver,_OUT cJSON **root)
{
VP_CFG_JSON json = {0};
cJSON *data = NULL;
if(payload==NULL ||payload->type!=cJSON_Object){
return -2;
}
if((data = cJSON_GetObjectItem(payload,DATA_STR))==NULL ||
data->type!=cJSON_Object){
return -1;
}
json.controller_buttons_config = infrared_codelib_info_ary_build(data);
json.infrared_codelib_info = infrared_codelib_info_ary_build(data);
json.rooms = kk_vp_sync_rooms(data);
json.scenes = kk_vp_sync_scences(data);
json.gws = kk_vp_sync_gws(data);
json.zigbee_devices = kk_vp_sync_device(data);
json.other_devices = kk_vp_sync_ac_indoors(data);
if((*root = kk_voice_panel_cfg_build(&json,ver))!=NULL){
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return 0;
}
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
return -1;
}
#ifndef _KK_VOICE_PANEL_CFG_H
#define _KK_VOICE_PANEL_CFG_H
#include "cJSON.h"
#define _OUT
#define _IN
typedef struct{
char nodeId[17];
char name[32];
char ch[8];
char operateType[12];
char room[24];
char mac[24];
char online[6];
char pid[17];
}VP_ZB_DEV_ITEM;
typedef struct{
char id[24];
char name[32];
char room[24];
char type[12];
}VP_SCENE_ITEM;
typedef struct{
char id[24];
char name[32];
}VP_ROOM_ITEM;
typedef struct{
char *ac_gw_nodeId;
char *addr;
char *nodeId;
char *name;
char *operateType;
char *room;
int online;
}VP_AC_INDOOR_ITEM;
typedef struct{
char nodeId[12];
char mac[24];
char name[32];
}VP_GW_ITEM;
typedef struct{
cJSON *controller_buttons_config;
cJSON *gws;
cJSON *infrared_codelib_info;
cJSON *other_devices;
cJSON *rooms;
cJSON *scenes;
cJSON *zigbee_devices;
}VP_CFG_JSON;
int kk_vp_cfg_init(void);
_OUT int kk_vp_syncinfo(_IN cJSON *payload,_IN int ver,_OUT cJSON **root);
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include "kk_newccu_msg.h"
#include "kk_voice_panel_cfg.h"
#include "kk_voice_panel_handle.h"
#include "uart_proto.h"
#include "kk_lan_vp_ctrl.h"
#define MK_VERSION(x) ((*x<<24) | (*(x+1)<<16) | (*(x+2)<<8) | *(x+3))
#define MK_UINT32(x) ((*x<<24) | (*(x+1)<<16) | (*(x+2)<<8) | *(x+3))
#define MK_UINT24(x) ((*x<<16) | (*(x+1)<<8) | *(x+2))
#define MK_UINT16(x) ((*(x)<<8) | *(x+1))
static uint16_t _g_seq;
static FILE *update_fp = NULL;
#define VP_CH 0
#define VP_RES 0
static void kk_vp_get_8009_snapshoot_handle(pro_data_t *pro_data);
static void kk_vp_get_snapshoot_handle(pro_data_t *pro_data);
static void kk_vp_scene_trigger_handle(pro_data_t *pro_data);
static void kk_vp_set_8009_system_time_handle(pro_data_t *pro_data);
static void kk_vp_get_system_time_handle(pro_data_t *pro_data);
static void kk_vp_action_handle(pro_data_t *pro_data);
static void kk_vp_config_file_update_notify_handle(pro_data_t *pro_data);
static void kk_vp_config_file_update_data_req_handle(pro_data_t *pro_data);
static void kk_vp_config_file_update_stop_handle(pro_data_t *pro_data);
static void kk_vp_config_file_info_query_handle(pro_data_t *pro_data);
static void kk_vp_config_file_update_status_handle(pro_data_t *pro_data);
static VP_OPCODE_HANDLE vp_opcode_table[] = {
{OPCODE_8009_SNAPSHOOT,kk_vp_get_8009_snapshoot_handle},
{OPCODE_SNAPSHOOT,kk_vp_get_snapshoot_handle},
{OPCODE_SCENE_ID_NOTIFY,kk_vp_scene_trigger_handle},
{OPCODE_SYSTEM_TIME_SET,kk_vp_set_8009_system_time_handle},
{OPCODE_SYSTEM_TIME_GET,kk_vp_get_system_time_handle},
{OPCODE_ACTION_NOTIFY,kk_vp_action_handle},
{OPCODE_CONFIG_FILE_UPDATE_NOTIFY,kk_vp_config_file_update_notify_handle},
{OPCODE_CONFIG_DATA_REQUEST,kk_vp_config_file_update_data_req_handle},
{OPCODE_CONFIG_FILE_UPDATE_STOP,kk_vp_config_file_update_stop_handle},
{OPCODE_CONFIG_FILE_INFO_GET,kk_vp_config_file_info_query_handle},
{OPCODE_CONFIG_FILE_UPDATE_STATUS,kk_vp_config_file_update_status_handle}
};
uint32_t ms_uiCrc32Tab[256] = { /* CRC polynomial 0xedb88320 */
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
uint32_t CreateCrc32(const uint8_t* s, uint32_t len) {
uint32_t i;
uint32_t crc32val;
crc32val = ~0;
for (i = 0; i < len; i++) {
crc32val = ms_uiCrc32Tab[(crc32val ^ s[i]) & 0xff] ^ (crc32val >> 8);
}
return ~crc32val;
}
typedef struct
{
int raw_id;
uint16_t map_id;
struct VP_SCENE_MAP *next;
}VP_SCENE_MAP;
static VP_SCENE_MAP *vp_scene_map;
static uint16_t vp_map_id = 1;
static int vp_scene_id_get_scene_id(uint16_t map_id)
{
VP_SCENE_MAP *pScene = vp_scene_map;
while(pScene!=NULL){
if(pScene->map_id==map_id){
return pScene->raw_id;
}
pScene = pScene->next;
}
return -1;
}
void vp_scene_id_map_deinit(void)
{
VP_SCENE_MAP *pNext = NULL;
VP_SCENE_MAP *pScene = vp_scene_map;
while(pScene!=NULL){
pNext = pScene->next;
if(pScene!=NULL){
free(pScene);
}
pScene = pNext;
}
vp_map_id = 1;
vp_scene_map = NULL;
}
int vp_scene_id_item_add(int scene_id)
{
VP_SCENE_MAP *ptr = NULL;
VP_SCENE_MAP *pScene = NULL;
pScene = malloc(sizeof(VP_SCENE_MAP));
memset(pScene,0,sizeof(VP_SCENE_MAP));
pScene->raw_id = scene_id;
pScene->map_id = vp_map_id++;
printf("[vp scene map]%d->%d\n",pScene->raw_id,pScene->map_id);
if(vp_scene_map == NULL){
vp_scene_map = pScene;
}else{
vp_scene_map->next = pScene;
}
return pScene->map_id;
}
int vp_scene_id_item_load(int scene_id,uint16_t map_id)
{
VP_SCENE_MAP *ptr = NULL;
VP_SCENE_MAP *pScene = NULL;
pScene = malloc(sizeof(VP_SCENE_MAP));
memset(pScene,0,sizeof(VP_SCENE_MAP));
pScene->raw_id = scene_id;
pScene->map_id = map_id;
printf("[vp scene map load]%d->%d\n",pScene->raw_id,pScene->map_id);
if(vp_scene_map == NULL){
vp_scene_map = pScene;
}else{
vp_scene_map->next = pScene;
}
return pScene->map_id;
}
#define VP_SCENE_ID_STRING "scene_id"
#define VP_SCENE_ID_RAW_STRING "CCU"
#define VP_SCENE_ID_MAP_STRING "VP"
#define VP_SCENE_ID_FILE "scene_id_map.json"
cJSON *vp_scene_id_map_file_build(void)
{
VP_SCENE_MAP *pScene = vp_scene_map;
cJSON *json = cJSON_CreateObject();
cJSON *SceMapAry = cJSON_CreateArray();
while(pScene!=NULL){
cJSON * mapItem = cJSON_CreateObject();
cJSON_AddNumberToObject(mapItem,VP_SCENE_ID_MAP_STRING,pScene->map_id);
cJSON_AddNumberToObject(mapItem,VP_SCENE_ID_RAW_STRING,pScene->raw_id);
cJSON_AddItemToArray(SceMapAry,mapItem);
pScene = pScene->next;
}
cJSON_AddItemToObject(json,VP_SCENE_ID_STRING,SceMapAry);
return json;
}
int vp_scene_id_map_file_prase(char *data)
{
VP_SCENE_MAP *pScene = vp_scene_map;
cJSON *map_id = NULL,*raw_id = NULL;
cJSON *json = cJSON_Parse(data);
cJSON *SceMapAry = NULL;
int i,SceMapNum = 0;
if(json==NULL){
return 0;
}
SceMapAry = cJSON_GetObjectItem(json,VP_SCENE_ID_STRING);
SceMapNum = cJSON_GetArraySize(SceMapAry);
vp_scene_id_map_deinit();
for(i=0;i<SceMapNum;i++){
cJSON *mapItem = cJSON_GetArrayItem(SceMapAry,i);
map_id = cJSON_GetObjectItem(mapItem,VP_SCENE_ID_MAP_STRING);
raw_id = cJSON_GetObjectItem(mapItem,VP_SCENE_ID_RAW_STRING);
vp_scene_id_item_load(raw_id->valueint,map_id->valueint);
}
cJSON_Delete(json);
return 1;
}
int vp_scene_id_map_save(void)
{
char *pStr = NULL;
char *pWrite = NULL;
FILE *fp = NULL;
int w_len = 0,length = 0;
cJSON *json = vp_scene_id_map_file_build();
pStr = cJSON_Print(json);
printf("[%s][%d][vp scene id file]%s\n",__FUNCTION__,__LINE__,pStr);
cJSON_Minify(pStr);
length = strlen(pStr);
pWrite = pStr;
if((fp= fopen(VP_SCENE_ID_FILE, "w"))==NULL) {
return 0;
}
while(length>0){
w_len = fwrite(pWrite, 1, length, fp);
pWrite+=w_len;
length -= w_len;
}
cJSON_Delete(json);
free(pStr);
fclose(fp);
system("sync");
return 1;
}
int vp_scene_id_map_load(void)
{
char *buff = NULL;
char *pRead = NULL;
int t_len = 0;
int remain = 0;
int r_len = 0;
FILE *fp = NULL;
int size = 0;
fp = fopen (VP_SCENE_ID_FILE,"r");
if(fp==NULL){
printf("open err.\n");
return ;
}
printf("vp_scene_id_map_load\n");
fseek (fp, 0, SEEK_END);
size=ftell(fp);
printf("size=%d\n",size);
fseek (fp, 0, SEEK_SET);
buff = malloc(size+1);
memset(buff,0,size+1);
pRead = buff;
remain = size;
while(remain>0){
r_len = fread(pRead, 1, size, fp);
if(remain>=r_len){
remain -= r_len;
pRead+=r_len;
}else{
remain = 0;
pRead[size] = '\0';
}
}
vp_scene_id_map_file_prase(buff);
free(buff);
fclose(fp);
return 1;
}
uint16_t vp_get_seq(void)
{
return _g_seq++;
}
void vp_send_data_build(uint16_t opCode,uint8_t len,uint8_t *data)
{
uint8_t data_buf[256] = {0};
uint8_t data_len = 0;
pro_data_t pro_data;
memset(&pro_data,0,sizeof(pro_data_t));
pro_data.seq = vp_get_seq();
pro_data.ch = VP_CH;
pro_data.opcode = opCode;
pro_data.cf.ack = 0;
pro_data.cf.dir = 1;
pro_data.cf.sof_flag = 1;
pro_data.args_len = len;
memcpy(pro_data.arg,data,len);
data_len = proto_frame_to_uart(&pro_data,data_buf);
printf("\n*********************************\n");
printf("[send] len=%d\n",data_len);
for(int i=0;i<data_len;i++){
printf("%02X ",data_buf[i]);
}
printf("\n");
eSerial_WriteBuffer(data_buf, data_len);
}
void vp_reply_data_build(uint16_t seq,uint8_t ch,uint16_t opCode,uint8_t len,uint8_t *data)
{
uint8_t data_buf[256] = {0};
uint8_t data_len = 0;
pro_data_t pro_data;
memset(&pro_data,0,sizeof(pro_data_t));
pro_data.seq = seq;
pro_data.ch = ch;
pro_data.opcode = opCode;
pro_data.cf.ack = 0;
pro_data.cf.dir = 1;
pro_data.cf.sof_flag = 0;
pro_data.args_len = len;
memcpy(pro_data.arg,data,len);
data_len = proto_frame_to_uart(&pro_data,data_buf);
printf("\n*********************************\n");
printf("[reply] len=%d\n",data_len);
for(int i=0;i<data_len;i++){
printf("%02X ",data_buf[i]);
}
printf("\n\n");
eSerial_WriteBuffer(data_buf, data_len);
}
int _vp_get_cfg_file_size(void)
{
int size = 0;
FILE *fp = NULL;
fp = fopen (VP_CONFIG_FILE_TAR_GZ,"r");
if(fp==NULL){
perror ("open err");
return 0;
}
fseek (fp, 0, SEEK_END);
size=ftell(fp);
printf("size=%d\n",size);
fclose(fp);
return size;
}
int _vp_get_cfg_file_crc32(void)
{
char *buff = NULL;
char *pRead = NULL;
int t_len = 0;
int remain = 0;
int r_len = 0;
uint32_t crc32 = 0;
FILE *fp = NULL;
int size = 0;
fp = fopen (VP_CONFIG_FILE,"r");
if(fp==NULL){
printf("open err.\n");
return ;
}
fseek (fp, 0, SEEK_END);
size=ftell(fp);
printf("size=%d\n",size);
fseek (fp, 0, SEEK_SET);
buff = malloc(size+1);
memset(buff,0,size+1);
pRead = buff;
remain = size;
while(remain>0){
r_len = fread(pRead, 1, size, fp);
if(remain>=r_len){
remain -= r_len;
pRead+=r_len;
printf("[remain]r_len=%d,remain=%d\n",r_len,remain);
}else{
remain = 0;
printf("[remain] 0 \n",remain);
pRead[size] = '\0';
}
}
crc32 = CreateCrc32(buff, size);
printf("crc32=%x\n",crc32);
free(buff);
fclose(fp);
return crc32;
}
static void vp_open_fd()
{
update_fp = fopen (VP_CONFIG_FILE_TAR_GZ,"rb");
if(update_fp==NULL){
printf("update_fp open err.\n");
}
}
static void vp_close_fd()
{
if(update_fp!=NULL){
fclose (update_fp);
}
}
static void kk_vp_get_8009_snapshoot_handle(pro_data_t *pro_data)
{
uint8_t err;
uint32_t sv,hv,f_ver;
uint16_t year;
uint8_t month,day;
uint8_t hour,minute,second;
uint8_t volume;
if(pro_data->args_len==0){
return ;
}
if((err = pro_data->arg[0])==0){
if(pro_data->args_len!=19){
return ;
}
sv = MK_UINT24(&pro_data->arg[1]);
hv = MK_UINT24(&pro_data->arg[4]);
year = MK_UINT16(&pro_data->arg[7]);
month = pro_data->arg[9];
day = pro_data->arg[10];
hour = pro_data->arg[11];
minute = pro_data->arg[12];
second = pro_data->arg[13];
volume = pro_data->arg[14];
f_ver = MK_UINT32(&pro_data->arg[15]);
kk_vp_set_state_machine(SET_8009_SYSTEM);
kk_vp_set_config_file_version(f_ver);
VP_RECV_PRINT("\n[VP->LAN]sv=%06X,hv=%06X,%d-%d-%d %d:%d:%d,volume=%d,f_ver=%08X\n",
sv,hv,year,month,day,hour,minute,second,volume,f_ver);
}
}
static void kk_vp_get_snapshoot_handle(pro_data_t *pro_data)
{
uint8_t data[12]={0};
uint8_t i;
uint8_t err = 0;
uint8_t mac[8] ={0};
uint16_t nodeId = 0;
uint8_t netStatus = 0x02;
if(pro_data->args_len!=1){
return ;
}
//todo:
data[0] = err;
for(i=0;i<8;i++){
data[1+i] = mac[i];
}
data[9] = (nodeId>>8)&0xff;
data[10] = nodeId&0xff;
data[11] = netStatus;
VP_RECV_PRINT("\n[vp snapshoot get]\n");
vp_reply_data_build(pro_data->seq,pro_data->ch,OPCODE_SNAPSHOOT,sizeof(data),data);
}
static void kk_vp_scene_trigger_handle(pro_data_t *pro_data)
{
cJSON *msg = NULL;
uint8_t data[256]={0};
uint8_t off = 0;
uint16_t *sceneAry;
uint8_t sceneNum = 0;
uint8_t i;
int sceneId = 0;
if(pro_data->args_len<3 &&
pro_data->args_len%2!=0){
return ;
}
sceneNum = pro_data->arg[0];
sceneAry = malloc(sizeof(uint16_t)*sceneNum);
VP_RECV_PRINT("[VP]execute scene!",sceneNum);
printf("sceneNum=%d\n",sceneNum);
for(i=0;i<sceneNum;i++){
sceneAry[i] = MK_UINT16(&pro_data->arg[1+2*i]);
printf("scene %d:%d\n",i,sceneAry[i]);
}
VP_RECV_PRINT("\n[vp call scene]\n");
for(i=0;i<sceneNum;i++){
if((sceneId = vp_scene_id_get_scene_id(sceneAry[i]))!=-1){
printf("1...\n");
char buff[32] = {0};
memset(buff,0,32);
snprintf(buff,32,"%d",sceneId);
msg=scene_execute(buff);
kk_ipc_send_json(msg);
data[1+2*off] = (sceneAry[i]>>8)&0xff;
data[2+2*off] = sceneAry[i]&0xff;
off+=1;
}
}
printf("2...\n");
if(off!=0){
data[0] = 0x00;
}else{
data[0] = 1;
}
printf("3...\n");
vp_reply_data_build(pro_data->seq,pro_data->ch,OPCODE_SCENE_ID_NOTIFY,1+2*off+1,data);
free(sceneAry);
}
static void kk_vp_set_8009_system_time_handle(pro_data_t *pro_data)
{
uint8_t data[8]={0};
uint8_t err;
uint16_t year;
uint8_t month,day,hour,minute,sec;
if(pro_data->args_len==0){
return ;
}
if((err = pro_data->arg[0])==0){
if(pro_data->args_len!=8){
return ;
}
}
year = MK_UINT16(&pro_data->arg[1]);
month = pro_data->arg[3];
day = pro_data->arg[4];
hour= pro_data->arg[5];
minute = pro_data->arg[6];
sec = pro_data->arg[7];
kk_vp_set_state_machine(GET_8009_CONFIG_FILE_INFO);
VP_RECV_PRINT("\n[VP->LAN]%d-%d-%d %d:%d:%d\n",year,month,day,hour,minute,sec);
}
static void kk_vp_get_system_time_handle(pro_data_t *pro_data)
{
uint8_t data[8]={0};
uint8_t err;
uint16_t year;
uint8_t month,day,hour,minute,sec;
if(pro_data->args_len!=1){
return ;
}
time_t curTime = time(NULL);
struct tm *c = gmtime(&curTime);
data[0] = 0;
data[1] = ((c->tm_year+1900)>>8)&0Xff;
data[2] =(c->tm_year+1900)&0Xff;
data[3] = (c->tm_mon+1);
data[4] = c->tm_mday;
data[5] = c->tm_hour;
data[6] = c->tm_min;
data[7] = c->tm_sec;
VP_RECV_PRINT("\n[vp system time get reply]%d-%d-%d %d:%d:%d\n",(c->tm_year+1900),(c->tm_mon+1),c->tm_mday,c->tm_hour,c->tm_min,c->tm_sec);
vp_reply_data_build(pro_data->seq,pro_data->ch,OPCODE_SYSTEM_TIME_GET,sizeof(data),data);
}
static void kk_vp_action_handle(pro_data_t *pro_data)
{
uint8_t i=0;
uint8_t devNum = 0;
uint32_t *nodeIdAry = NULL;
uint32_t *OperatorIdAry = NULL;
uint8_t skillType;
VP_RECV_PRINT("\n\n******************0x010B***********************\n\n");
if((devNum = pro_data->arg[0])!=0){
nodeIdAry = malloc(sizeof(uint32_t)*devNum);
OperatorIdAry = malloc(sizeof(uint32_t)*devNum);
printf("devNum=%d",devNum);
for(i=0;i<devNum;i++){
nodeIdAry[i] =(pro_data->arg[1+8*i]<<24) | (pro_data->arg[2+8*i]<<16) | (pro_data->arg[3+8*i]<<8) | pro_data->arg[4+8*i];
OperatorIdAry[i] = (pro_data->arg[5+8*i]<<24) | (pro_data->arg[6+8*i]<<16) | (pro_data->arg[7+8*i]<<8) | pro_data->arg[8+8*i];
VP_RECV_PRINT("[Node Id %d] %08x",i,nodeIdAry[i]);
VP_RECV_PRINT("[Operator Id %d] %08x",i,OperatorIdAry[i]);
}
skillType = pro_data->arg[1+8*i];
VP_RECV_PRINT("[skillType] %02x",skillType);
kk_lan_vp_control(devNum,nodeIdAry,&pro_data->arg[1+8*i]);
uint8_t data[256]={0};
memset(data,0,sizeof(data));
data[0] = 0x00;
data[1] = devNum;
//todo:根据实际的执行
for(i=0;i<devNum;i++){
data[2+8*i] = (nodeIdAry[i]>>24)&0xff;
data[3+8*i] = (nodeIdAry[i]>>16)&0xff;
data[4+8*i] = (nodeIdAry[i]>>8)&0xff;
data[5+8*i] = nodeIdAry[i]&0xff;
data[6+8*i] = (OperatorIdAry[i]>>24)&0xff;
data[7+8*i] = (OperatorIdAry[i]>>16)&0xff;
data[8+8*i] = (OperatorIdAry[i]>>8)&0xff;
data[9+8*i] = OperatorIdAry[i]&0xff;
}
data[2+8*i] = skillType;
data[3+8*i] = 0x20;
data[4+8*i] = devNum;
int off =5+8*i;
for(i=0;i<devNum;i++){
data[off+i] = 0;
}
vp_reply_data_build(pro_data->seq,pro_data->ch,OPCODE_ACTION_NOTIFY,off+i,data);
free(nodeIdAry);
free(OperatorIdAry);
}
//OPCODE_ACTION_NOTIFY
}
static void kk_vp_config_file_update_notify_handle(pro_data_t *pro_data)
{
uint8_t err;
uint32_t f_ver,f_size,crc32;
if(pro_data->args_len==0){
return ;
}
if((err = pro_data->arg[0])==0){
if(pro_data->args_len!=13){
return ;
}
f_ver = MK_UINT32(&pro_data->arg[1]);
f_size = MK_UINT32(&pro_data->arg[5]);
crc32 = MK_UINT32(&pro_data->arg[9]);
kk_vp_config_file_info_check(f_ver,f_size,crc32);
VP_RECV_PRINT("\n[cfg file update notify ack]File Version=%08x,File Size=%d,CRC32 Value=%08X\n",
f_ver,f_size,crc32);
}else {
printf("\n");
}
}
static void kk_vp_config_file_update_data_req_handle(pro_data_t *pro_data)
{
uint8_t err = 0;
uint32_t f_ver,offset;
uint16_t req_size;
uint8_t data[256] = {0};
uint8_t len = 0;
uint8_t r_len = 0;
uint8_t t_len = 0;
uint8_t *pCrc = NULL;
uint32_t crc;
if(pro_data->args_len!=10){
return ;
}
f_ver = MK_UINT32(&pro_data->arg[0]);
offset = MK_UINT32(&pro_data->arg[4]);
req_size = MK_UINT16(&pro_data->arg[8]);
VP_RECV_PRINT("\n[vp config file req]f_ver=%d,offset=%d,req_size=%d\n",f_ver,offset,req_size);
if(update_fp==NULL){
printf("[update_fp] NULL!\n");
err = 1;
}
/*
if(f_ver!=kk_vp_get_config_file_version()){
printf("[file version] not match!%d,%d\n",f_ver,kk_vp_get_config_file_version());
err = 2;
}*/
data[len++] = err;
data[len++] = (offset>>24)&0xff;
data[len++] = (offset>>16)&0xff;
data[len++] = (offset>>8)&0xff;
data[len++] = offset&0xff;
data[len++] = (req_size>>8)&0xff;
data[len++] = req_size&0xff;
pCrc = &data[len];
printf("-------->=%d\n",len);
if(err==0){
int err = fseek(update_fp, offset, SEEK_SET);
if(err==0){
while(req_size>t_len){
r_len = fread(&data[len], 1, req_size, update_fp);
printf("r_len=%d\n",r_len);
if(r_len>=0){
t_len+=r_len;
len += r_len;
}else{
break;
}
}
}else{
printf("[fseek fail]offset=%d\n",offset);
}
}
crc = CreateCrc32(pCrc, req_size);
data[len++] = (crc>>24)&0xff;
data[len++] = (crc>>16)&0xff;
data[len++] = (crc>>8)&0xff;
data[len++] = crc&0xff;
printf("crc32=%x\n",crc);
vp_reply_data_build(pro_data->seq,pro_data->ch,OPCODE_CONFIG_DATA_REQUEST,len,data);
usleep(100*1000);
}
static void kk_vp_config_file_update_stop_handle(pro_data_t *pro_data)
{
uint8_t err,status;
uint32_t ver;
if(pro_data->args_len==0){
return ;
}
if((err = pro_data->arg[0])==0){
if(pro_data->args_len!=5){
return ;
}
ver = MK_VERSION(&pro_data->arg[1]);
VP_RECV_PRINT("\n[vp config file update stop ack] version=%d\n",ver);
}else{
printf("err=%d\n",ver);
}
ver = (pro_data->arg[0]<<24) | (pro_data->arg[1]<<16) | (pro_data->arg[2]<<8) | pro_data->arg[3];
status = pro_data->arg[4];
}
static void kk_vp_config_file_update_status_handle(pro_data_t *pro_data)
{
int err = 0;
int ver;
unsigned char status;
if(pro_data->args_len!=5){
return ;
}
ver = MK_UINT32(&pro_data->arg[0]);
status = pro_data->arg[4];
VP_RECV_PRINT("\n[config file update status]ver=%d,status=%d\n",ver,status);
uint8_t data[6] = {0};
data[0] = err;
data[1] = (ver>>24)&0xff;
data[2] = (ver>>16)&0xff;
data[3] = (ver>>8)&0xff;
data[4] = ver&0xff;
data[5] = status;
vp_reply_data_build(pro_data->seq,pro_data->ch,OPCODE_CONFIG_FILE_UPDATE_STATUS,sizeof(data),data);
kk_vp_update_result_check(status,ver);
}
static void kk_vp_config_file_info_query_handle(pro_data_t *pro_data)
{
uint8_t err;
uint32_t f_ver,f_size,crc32;
if(pro_data->args_len==0) {
return ;
}
if((err = pro_data->arg[0])==0) {
if(pro_data->args_len!=13){
return ;
}
f_ver = MK_UINT32(&pro_data->arg[1]);
f_size = MK_UINT32(&pro_data->arg[5]);
crc32 = MK_UINT32(&pro_data->arg[9]);
VP_RECV_PRINT("[VP->LAN]File Version=%08x,File Size=%08x,CRC32=%08x\n",f_ver,f_size,crc32);
kk_vp_cfg_info_check(f_ver,f_size,crc32);
}else{
printf("");
}
}
///////////////////////////////////////////
void kk_vp_get_8009_snapshoot(void)
{
uint8_t res[1] = {0};
VP_SEND_PRINT("[LAN->VP]get snapshoot\n");
vp_send_data_build(OPCODE_8009_SNAPSHOOT,sizeof(res),res);
}
void kk_vp_set_8009_system_time(void)
{
uint8_t data[7] = {0};
time_t curTime = time(NULL);
struct tm *c = gmtime(&curTime);
data[0] = ((c->tm_year+1900)>>8)&0Xff;
data[1] =(c->tm_year+1900)&0Xff;
data[2] = (c->tm_mon+1);
data[3] = c->tm_mday;
data[4] = c->tm_hour;
data[5] = c->tm_min;
data[6] = c->tm_sec;
VP_SEND_PRINT("[LAN->VP]set system (%d-%d-%d %d:%d:%d)\n",(c->tm_year+1900),(c->tm_mon+1),c->tm_mday,c->tm_hour,c->tm_min,c->tm_sec);
vp_send_data_build(OPCODE_SYSTEM_TIME_SET,sizeof(data),data);
}
void kk_vp_config_file_update_start(uint32_t ver)
{
uint8_t data[12] = {0};
uint32_t f_ver,f_size,crc32;
f_ver = ver;
f_size = _vp_get_cfg_file_size();
printf("f_size=%d\n",f_size);
crc32 = _vp_get_cfg_file_crc32();
data[0] = (f_ver>>24)&0xff;
data[1] = (f_ver>>16)&0xff;
data[2] = (f_ver>>8)&0xff;
data[3] = f_ver&0xff;
data[4] = (f_size>>24)&0xff;
data[5] = (f_size>>16)&0xff;
data[6] = (f_size>>8)&0xff;
data[7] = f_size&0xff;
data[8] = (crc32>>24)&0xff;
data[9] = (crc32>>16)&0xff;
data[10] = (crc32>>8)&0xff;
data[11] = crc32&0xff;
kk_vp_cfg_info_set(f_ver,f_size,crc32);
VP_SEND_PRINT("[cfg file update notify]File Version=%08x,File Size=%d,CRC32 Value=%08X\n",
f_ver,f_size,crc32);
vp_send_data_build(OPCODE_CONFIG_FILE_UPDATE_NOTIFY,sizeof(data),data);
vp_open_fd();
}
void kk_vp_config_file_update_stop(uint32_t ver)
{
uint8_t f_ver[4];
f_ver[0] = (ver>>24)&0xff;
f_ver[1] = (ver>>16)&0xff;
f_ver[2] = (ver>>8)&0xff;
f_ver[3] = ver&0xff;
VP_SEND_PRINT("[vp config file update stop] version=%d\n",ver);
vp_send_data_build(OPCODE_CONFIG_FILE_UPDATE_STOP,sizeof(f_ver),f_ver);
}
void kk_vp_get_config_file_info(void)
{
uint8_t res[1] = {0};
VP_SEND_PRINT("[config file info get]\n");
vp_send_data_build(OPCODE_CONFIG_FILE_INFO_GET,sizeof(res),res);
}
/////////////////////////////////////////////////////
int kk_vp_opcode_handle(_IN pro_data_t *pro_data)
{
int i;
VP_OPCODE_HANDLE *pFunc;
if(pro_data==NULL){
return 0;
}
pFunc = vp_opcode_table;
for(i=0;i<sizeof(vp_opcode_table)/sizeof(VP_OPCODE_HANDLE);i++,pFunc++){
if(pFunc->opcode==pro_data->opcode){
if(pFunc->func!=NULL){
printf("[%s][%d][vp handle opcode]%04X\n",__FUNCTION__,__LINE__,pro_data->opcode);
pFunc->func(pro_data);
return 1;
}
}
}
printf("[%s][%d][vp unknow opcode]%04X\n",__FUNCTION__,__LINE__,pro_data->opcode);
return 0;
}
static int kk_vp_config_file_save(_IN cJSON *json)
{
char *pStr = NULL;
char *pWrite = NULL;
FILE *fp = NULL;
int w_len = 0,length = 0;
pStr = cJSON_Print(json);
printf("[%s][%d][vp config file]%s\n",__FUNCTION__,__LINE__,pStr);
cJSON_Minify(pStr);
length = strlen(pStr);
pWrite = pStr;
if((fp= fopen(VP_CONFIG_FILE, "w"))==NULL) {
return 0;
}
while(length>0){
w_len = fwrite(pWrite, 1, length, fp);
pWrite+=w_len;
length -= w_len;
}
free(pStr);
fclose(fp);
system("sync");
return 1;
}
static _OUT int kk_vp_config_file_update_check(void)
{
const char *md5_create = "md5sum %s > %s";
const char *md5_check = "md5sum -c %s";
const char *tar_cmd = "tar -Pzcvf %s %s";
char cmd[256] = {0};
FILE *fp = NULL;
int ret = 0;
int updateFlag = 0;
char buf[64] = {0};
if(access(VP_CONFIG_FILE_MD5,F_OK)!=0){
memset(cmd,0,sizeof(cmd));
snprintf(cmd,sizeof(cmd),md5_create,VP_CONFIG_FILE,VP_CONFIG_FILE_MD5);
EXECUTE_CMD(cmd);
system(cmd);
updateFlag = 1;
}else{
memset(cmd,0,sizeof(cmd));
snprintf(cmd,sizeof(cmd),md5_check,VP_CONFIG_FILE_MD5);
EXECUTE_CMD(cmd);
fp = popen(cmd, "r");
fread(buf, 1, sizeof(buf), fp);
printf("execte result:%s",buf);
pclose(fp);
if(strstr(buf,"OK")==NULL){
printf("buf:%s\n",buf);
updateFlag = 1;
memset(cmd,0,sizeof(cmd));
snprintf(cmd,sizeof(cmd),md5_create,VP_CONFIG_FILE,VP_CONFIG_FILE_MD5);
EXECUTE_CMD(cmd);
system(cmd);
}
}
if(updateFlag!=0){
memset(cmd,0,sizeof(cmd));
snprintf(cmd,sizeof(cmd),tar_cmd,VP_CONFIG_FILE_TAR_GZ,VP_CONFIG_FILE);
EXECUTE_CMD(cmd);
system(cmd);
}
return updateFlag;
}
void kk_vp_syncinfo_handle(_IN cJSON *payload)
{
cJSON *root = NULL;
int err = 0;
if((err = kk_vp_syncinfo(payload,kk_vp_get_config_file_version(),&root))!=0){
printf("[%s][%d]SYNC fail,err=%d\n",__FUNCTION__,__LINE__,err);
}
if(kk_vp_config_file_save(root)!=0){
printf("[%s][%d][vp config file] save.\n",__FUNCTION__,__LINE__);
}
if(kk_vp_config_file_update_check()!=0){
printf("[%s][%d][vp config file] update.\n",__FUNCTION__,__LINE__);
kk_vp_set_updateFlag(1);
}
if(root!=NULL){
cJSON_Delete(root);
}
}
#ifndef _KK_VOICE_PANEL_HANDLE_H
#define _KK_VOICE_PANEL_HANDLE_H
#include "uart_proto.h"
#include "kk_lan_voice_panel.h"
#include "kk_voice_panel_cfg.h"
#define VP_CONFIG_FILE_MD5 "voice_data.MD5"
#define VP_CONFIG_FILE "/etc/smarthome/voice_data.json"
#define VP_CONFIG_FILE_TAR_GZ "voice_data.tar.gz"
#define OPCODE_8009_SNAPSHOOT 0x1000
#define OPCODE_SNAPSHOOT 0x1001
#define OPCODE_SCENE_ID_NOTIFY 0x1003
#define OPCODE_SYSTEM_TIME_SET 0x1009
#define OPCODE_SYSTEM_TIME_GET 0x100A
#define OPCODE_ACTION_NOTIFY 0x100B
#define OPCODE_CONFIG_FILE_UPDATE_NOTIFY 0x100C
#define OPCODE_CONFIG_DATA_REQUEST 0x100D
#define OPCODE_CONFIG_FILE_UPDATE_STOP 0x100E
#define OPCODE_CONFIG_FILE_INFO_GET 0x100F
#define OPCODE_CONFIG_FILE_UPDATE_STATUS 0x1010
#define EXECUTE_CMD(cmd) do {\
printf("\n[%s][%d]------------------execte cmd------------------\n",__FUNCTION__,__LINE__);\
printf("%s\n",cmd);\
}while(0)
#define VP_SEND_PRINT(format,...) printf("\n\033[33;32m"format"\033[0m\n",##__VA_ARGS__)
#define VP_RECV_PRINT(format,...) printf("\n\033[33;34m"format"\033[0m\n",##__VA_ARGS__)
typedef void (*vp_handle_func)(pro_data_t *pro_data);
typedef struct
{
uint16_t opcode;
vp_handle_func func;
}VP_OPCODE_HANDLE;
int vp_scene_id_map_load(void);
void vp_scene_id_map_deinit(void);
int vp_scene_id_item_add(int scene_id);
//主机快照请求
void vp_8009_snapshoot_get(void);
void kk_vp_set_8009_system_time(void);
void kk_vp_config_file_update_start(uint32_t ver);
void kk_vp_config_file_update_stop(uint32_t ver);
void kk_vp_get_config_file_info(void);
void kk_vp_get_8009_snapshoot(void);
void kk_vp_syncinfo_handle(_IN cJSON *payload);
int kk_vp_opcode_handle(_IN pro_data_t *pro_data);
int _vp_get_cfg_file_crc32(void);
int _vp_get_cfg_file_size(void);
#endif
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <unistd.h>
#include "Serial.h"
#include "main.h"
//#include "common.h"
//#include "thread.h"
//#include "app_queue.h"
//#include "dev_arp.h"
//#include "net_handle.h"
#include "uart_proto.h"
uart_data_t g_uart_data;
static uint16_t g_temp_data_len = 0;
static uint16_t g_data_len = 0;
static uint16_t g_recv_crc16 = 0;
static uint8_t state = SOP_STATE1;
uint16_t make_crc16(uint8_t *msg, uint16_t len)
{
uint16_t crc16 = 0xFFFF;
uint16_t i, j = 0;
uint8_t c15, bit;
for (i = 0; i < len ; i++)
{
for (j = 0; j < 8; j++)
{
c15 = ((crc16 >> 15 & 1) == 1);
bit = ((msg[i] >> (7 - j) & 1) == 1);
crc16 <<= 1;
if (c15 ^ bit)
{
crc16 ^= 0x1021;
}
}
}
// GW_LOG_DBG("crc16 caculate:0x%04x\n",crc16);
return crc16;
}
uint32_t make_crc32(uint8_t *msg, uint16_t len)
{
uint32_t crc32 = 0xFFFFFFFF;
uint16_t i, j = 0;
uint16_t c15, bit;
for (i = 0; i < len ; i++)
{
for (j = 0; j < 8; j++)
{
c15 = ((crc32 >> 31 & 1) == 1);
bit = ((msg[i] >> (7 - j) & 1) == 1);
crc32 <<= 1;
if (c15 ^ bit)
{
crc32 ^= 0x10211021;
}
}
}
return crc32;
}
int kk_execel_cmd(char * cmd,char * buf,int buf_len,int* ret_len)
{
if(cmd == NULL || buf == NULL || buf_len == 0)
{
GW_LOG_ERR("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;
}
void uart_frame_send(uint8_t *buf, uint32_t len)
{
int ret = eSerial_WriteBuffer(buf, len);
if (ret == E_SERIAL_FD_ERROR)
{
//eSerial_Init();
}
}
uint8_t pro_check_uart_frame(uint8_t *data, uint16_t data_len)
{
uint16_t i;
uint16_t tmp_len;
uint16_t tmp_crc;
//uint8_t gw_mac_flag = 0;
//uint16_t crc;
if (data_len < PRO_LINK_PAKCET_SIZE)
{
GW_LOG_ERR("PRO: data_len(%d) < (%d)\n", data_len, PRO_APP_PACKET_MIN_SIZE);
return 0;
}
//check header
i = 0;
if (data[0] != PRO_SOF_1 || data[1] != PRO_SOF_2)
{
GW_LOG_ERR("PRO: sof err (0x%02X 0x%02X)\n", data[0], data[1]);
return 0;
}
i += PRO_SOF_SIZE;
#if 0
//check control-field
if (data[i] < 0x08 && data[i + 1] == 0x30)
{
if (gw_mac_flag == 1)
{
//gw link ack, don't care
GW_LOG_DBG("gw link ack\n");
return 0;
}
//forward link ack to ccu
#if 0
if (!dev_arp_query_mac_by_ip(data + PRO_SOF_SIZE, dev_mac))
{
return 0;
}
#endif
crc = make_crc16(data, data_len - 2);
data[data_len - 2] = crc >> 8;
data[data_len - 1] = crc;
GW_LOG_DBG("link ack\n");
// dev_send_net(NET_SEND_NOT_BC, UDP_MSG_LOCAL, &g_ccu_net_addr, data, data_len);
//net_handle_send_tcp_data(data, data_len, 0, TCP_FRAME_NORMAL);
return 0;
}
#endif
//i += PRO_CONTORL_FIELD_SIZE; //jump over control-field
//check data_size
tmp_len = ((uint16_t)(data[i]) << 8) + data[i + 1] + PRO_SOF_SIZE + PRO_LEN_SIZE + PRO_CRC_SIZE;
if (tmp_len != data_len)
{
GW_LOG_ERR("PRO: data_len(%d) != (%d)\n", data_len, tmp_len);
return 0;
}
//check crc
i = data_len - PRO_CRC_SIZE - PRO_SOF_SIZE - PRO_LEN_SIZE;
tmp_crc = make_crc16(&data[4], i);
if (tmp_crc != ((((uint16_t)(data[data_len-2])) << 8) + data[data_len - 1]))
{
GW_LOG_ERR("PRO: crc err(0x%04X) != (0x%02X%02X)\n", tmp_crc, data[i], data[i + 1]);
return 0;
}
return 1;
}
int get_uart_frame(uint8_t * buf,int len)
{
uint8_t ch;
int i = 0;
//GW_LOG_DBG("uart fram len:%d state:%d\n",len,state);
for (i = 0 ; i < len ; i++)
{
ch = buf[i];
switch (state)
{
case SOP_STATE1:
if (ch == PRO_SOF_1)
{
state = SOP_STATE2;
}
g_temp_data_len = 0;
g_uart_data.data[g_temp_data_len++] = ch;
break;
case SOP_STATE2:
if (ch == PRO_SOF_2)
{
state = LENGTH_STATE1;
g_uart_data.data[g_temp_data_len++] = ch;
}
else
{
GW_LOG_ERR("uart data err: SOF2");
if (ch == PRO_SOF_1)
{
state = SOP_STATE2;
}
else
{
state = SOP_STATE1;
}
}
break;
/* Length 2 bytes */
case LENGTH_STATE1:
g_uart_data.data[g_temp_data_len++] = ch;
state = LENGTH_STATE2;
g_data_len = ((uint16_t)ch) << 8;
break;
case LENGTH_STATE2:
g_uart_data.data[g_temp_data_len++] = ch;
g_data_len += ch;
if (g_data_len < 2 || g_data_len > (DEV_UART_RECV_BUFFER_SIZE - (PRO_LINK_PAKCET_SIZE - 2)))
{
GW_LOG_ERR("uart data err: LEN err, len = %d", g_data_len);
if (ch == PRO_SOF_1)
{
state = SOP_STATE2;
}
else
{
state = SOP_STATE1;
}
break;
}
state = CONTROL_FIELD_STATE1;
g_data_len -= 3;
if (g_data_len == 0)
{
state = CRC16_STATE1;
}
break;
case CONTROL_FIELD_STATE1:
g_uart_data.data[g_temp_data_len++] = ch;
state = SEQ_STATE1;
break;
case SEQ_STATE1:
g_uart_data.data[g_temp_data_len++] = ch;
state = SEQ_STATE2;
break;
case SEQ_STATE2:
g_uart_data.data[g_temp_data_len++] = ch;
state = DATA_STATE;
break;
case DATA_STATE:
if (g_data_len--)
{
g_uart_data.data[g_temp_data_len++] = ch;
state = DATA_STATE;
if (g_data_len == 0)
{
state = CRC16_STATE1;
}
break;
}
break;
case CRC16_STATE1:
g_recv_crc16 = ((uint16_t)ch) << 8;
g_uart_data.data[g_temp_data_len++] = ch;
state = CRC16_STATE2;
break;
case CRC16_STATE2:
state = SOP_STATE1;
g_uart_data.data[g_temp_data_len++] = ch;
g_uart_data.data_len = g_temp_data_len;
g_recv_crc16 += ch;
if (make_crc16(&g_uart_data.data[4], g_temp_data_len - 6) == g_recv_crc16)
{
return true;
}
else
{
GW_LOG_ERR("uart data err: CRC err:0x%04x\n",g_recv_crc16);
state = SOP_STATE1;
}
break;
default:
GW_LOG_ERR("uart data err: INNER err");
if (ch == PRO_SOF_1)
{
state = SOP_STATE2;
}
else
{
state = SOP_STATE1;
}
break;
}
}
return false;
}
int get_proto_frame(uint8_t *data, uint16_t data_len, pro_data_t *pro_data)
{
if (pro_check_uart_frame(data, data_len))
{
pro_data->cf.ack = data[PRO_CF_INDEX] & 0x03;
pro_data->cf.dir = (data[PRO_CF_INDEX] >> 5) & 0x01;
pro_data->cf.sof_flag = (data[PRO_CF_INDEX] >> 4) & 0x01;
pro_data->cf.mf_flag = (data[PRO_CF_INDEX] >> 3) & 0x01;
pro_data->seq = (((uint16_t)(data[PRO_SEQ_INDEX])) << 8) + data[PRO_SEQ_INDEX + 1];
pro_data->ch = data[PRO_DATA_INDEX+1];
pro_data->opcode = (((uint16_t)(data[PRO_DATA_INDEX + 2])) << 8) + data[PRO_DATA_INDEX + 3];
//pro_data->args_len = data_len - PRO_APP_PACKET_MIN_SIZE + 1;
pro_data->args_len = data[PRO_DATA_INDEX] -3 ;
memcpy(pro_data->arg, data + PRO_DATA_INDEX + 4, pro_data->args_len);
return true;
}
return false;
}
uint8_t cf_to_uint8_t(control_field_t *cf)
{
return ((((uint8_t)(cf->ack))) + ((cf->dir) << 5) + ((cf->sof_flag) << 4) + ((cf->mf_flag) << 3));
}
uint8_t proto_frame_to_uart(pro_data_t *pro_data, uint8_t *uart_data)
{
uint8_t i = 0;
uint16_t cf;
uint8_t len;
uint16_t crc;
uart_data[i++] = PRO_SOF_1;
uart_data[i++] = PRO_SOF_2;
len = pro_data->args_len + 4 + 3;
uart_data[i++] = len>>8;
uart_data[i++] = len;
cf = cf_to_uint8_t(&(pro_data->cf));
//cf = 0x20;
uart_data[i++] = cf;
uart_data[i++] = pro_data->seq>>8;
uart_data[i++] = pro_data->seq;
uart_data[i++] = pro_data->args_len + 3;
uart_data[i++] = pro_data->ch;
uart_data[i++] = (pro_data->opcode) >> 8;
uart_data[i++] = (pro_data->opcode);
memcpy(uart_data + i, pro_data->arg, pro_data->args_len);
i += pro_data->args_len;
crc = make_crc16(&uart_data[4], i-4);
uart_data[i++] = crc >> 8;
uart_data[i++] = crc;
return i;
}
void pro_send_link_ack(pro_data_t *pro_data)
{
uint8_t buf[PRO_LINK_PAKCET_SIZE];
uint16_t len = 2;
uint16_t crc;
uint8_t i = 0;
buf[i++] = PRO_SOF_1;
buf[i++] = PRO_SOF_2;
buf[i++] = 0x00;
buf[i++] = 0x30;
len = 2;
buf[i++] = len >> 8;
buf[i++] = len;
crc = make_crc16(buf, i);
buf[i++] = crc >> 8;
buf[i++] = crc;
dev_send_uart(buf,i);
}
void dev_send_uart(uint8_t *data, uint16_t data_len)
{
#if 1 // debug
{
static char data_print_buf[512] = {0};
int i = 0;
memset(data_print_buf, 0, sizeof(data_print_buf));
for (i = 0; i < data_len; i ++)
{
snprintf(data_print_buf + strlen(data_print_buf), sizeof(data_print_buf), "%02X ", data[i]);
}
GW_LOG_DBG("uart send data %s\n", data_print_buf);
}
#endif
uart_frame_send(data, data_len);
}
static void uart_protocol_print(pro_data_t *pro_data)
{
printf("seq %02X\n", pro_data->seq);
printf("channel %02X\n", pro_data->ch);
printf("opcode %04X\n", pro_data->opcode);
printf("args_len: %d\n", pro_data->args_len);
char print_buf[512] = {0};
int i = 0;
snprintf(print_buf, sizeof(print_buf), "args: ");
for (i = 0; i < pro_data->args_len; i ++)
{
snprintf(print_buf + strlen(print_buf), sizeof(print_buf), "%02X ", pro_data->arg[i]);
}
printf("%s\n", print_buf);
}
/********proto app func************/
void connect_status_ack(pro_data_t pro_data)
{
pro_data_t pro_data_tmp;
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
pro_data_tmp.args_len = 0;
pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
}
void system_restart_ack(pro_data_t pro_data)
{
pro_data_t pro_data_tmp;
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
pro_data_tmp.args_len = 0;
pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
sleep(2);
my_system("reboot -f\n");
}
void read_mac_ack(pro_data_t pro_data)
{
#if 0
pro_data_t pro_data_tmp;
char eth0_mac_str[32] = "";
unsigned int eth0_mac[6] = {0};
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
//get mac
if (get_mac(ETH0_MAC_NAME, eth0_mac_str, sizeof(eth0_mac_str)) == 0)
{
OLED_LOG_DBG("get eth0 mac error\n");
return ;
}
sscanf(eth0_mac_str, "%x:%x:%x:%x:%x:%x", &eth0_mac[0], \
&eth0_mac[1],&eth0_mac[2],&eth0_mac[3],&eth0_mac[4],&eth0_mac[5]);
pro_data_tmp.args_len = 0;
pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
pro_data_tmp.arg[pro_data_tmp.args_len++] = 6; // mac len
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[0]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[1]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[2]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[3]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[4]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[5]&0xff; // mac
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
#endif
}
int my_system(const char * cmd)
{
FILE * fp;
int res;
char buf[1024];
if (cmd == NULL){
GW_LOG_DBG("my_system cmd is NULL!\n");
return -1;
}
if ((fp = popen(cmd, "r") ) == NULL){
perror("popen");
GW_LOG_DBG("popen error: %s/n", strerror(errno));
return -1;
}
else{
while(fgets(buf, sizeof(buf), fp)){
GW_LOG_DBG("%s", buf);
}
if ( (res = pclose(fp)) == -1){
GW_LOG_DBG("close popen file pointer fp error!\n");
return res;
}
else if (res == 0){
return res;
}
else{
GW_LOG_DBG("popen res is :%d\n", res);
return res;
}
}
}
int get_art_bin()
{
my_system("dd if=/dev/mtd5 of=/tmp/art.bin");
if(access("/tmp/art.bin",F_OK) == -1){
GW_LOG_DBG(" file not exist: /tmp/art.bin\n");
return 0;
}
return 1;
}
int write_art_bin()
{
GW_LOG_DBG("write art and restart!!!\n");
my_system("mtd write /tmp/art-modify.bin art");
// my_system("reboot -f");
return 1;
}
long get_file_len(FILE * fp)
{
long offset;
fseek(fp,0,SEEK_END); //�Ƶ��ļ���β
offset = ftell(fp);
fseek(fp,0,SEEK_SET); //�Ƶ��ļ���ͷ
return offset;
}
int mac_modify(unsigned char mac[6])
{
FILE *fp;
long offset = 0,fileLen = 0;
char *file_content;
if(!((mac[0]&0xff) == 0x28 && (mac[1]&0xff) == 0xd9 && (mac[2]&0xff) == 0x8a))
return 0;
if(get_art_bin() == 0){
GW_LOG_DBG("get uboot bin error \n");
return 0;
}
if(!(fp = fopen("/tmp/art.bin","r"))){
GW_LOG_DBG("can't open the file: /tmp/art.bin\n");
return 0;
}
offset = get_file_len(fp);
GW_LOG_DBG("offset:%ld ",offset);
file_content = (char *)malloc(offset);
memset(file_content,0,offset);
fileLen = fread(file_content,1,offset,fp);
GW_LOG_DBG("fileLen:%ld \n",fileLen);
fclose(fp);
GW_LOG_DBG("mac:%02x-%02x-%02x-%02x-%02x-%02x\n",file_content[MAC_ADDR]&0xff,file_content[MAC_ADDR+1]&0xff,file_content[MAC_ADDR+2]&0xff,file_content[MAC_ADDR+3]&0xff,file_content[MAC_ADDR+4]&0xff,file_content[MAC_ADDR+5]&0xff);
GW_LOG_DBG("mac-input:%02x-%02x-%02x-%02x-%02x-%02x\n",mac[0]&0xff,mac[1]&0xff,mac[2]&0xff,mac[3]&0xff,mac[4]&0xff,mac[5]&0xff);
if((file_content[MAC_ADDR]&0xff) == 0x28 && (file_content[MAC_ADDR+1]&0xff) == 0xd9 && (file_content[MAC_ADDR+2]&0xff) == 0x8a) {
GW_LOG_DBG("modifying\n");
file_content[MAC_ADDR] = mac[0];
file_content[MAC_ADDR+1] = mac[1];
file_content[MAC_ADDR+2] = mac[2];
file_content[MAC_ADDR+3] = mac[3];
file_content[MAC_ADDR+4] = mac[4];
file_content[MAC_ADDR+5] = mac[5];
}
GW_LOG_DBG("mac-modify:%02x-%02x-%02x-%02x-%02x-%02x\n",file_content[MAC_ADDR]&0xff,file_content[MAC_ADDR+1]&0xff,file_content[MAC_ADDR+2]&0xff,file_content[MAC_ADDR+3]&0xff,file_content[MAC_ADDR+4]&0xff,file_content[MAC_ADDR+5]&0xff);
if(!(fp = fopen("/tmp/art-modify.bin","w+"))){
GW_LOG_DBG("can't open the file: /tmp/art-modify.bin\n");
free(file_content);
return 0;
}
fwrite(file_content,1,offset,fp);
fclose(fp);
free(file_content);
return 1;
}
int get_art_mac(unsigned char mac[6])
{
FILE *fp;
long offset = 0,fileLen = 0;
char *file_content;
if(get_art_bin() == 0){
GW_LOG_DBG("get uboot bin error \n");
return 0;
}
if(!(fp = fopen("/tmp/art.bin","r"))){
GW_LOG_DBG("can't open the file: /tmp/wifi_scan\n");
return 0;
}
offset = get_file_len(fp);
GW_LOG_DBG("offset:%ld ",offset);
file_content = (char *)malloc(offset);
memset(file_content,0,offset);
fileLen = fread(file_content,1,offset,fp);
GW_LOG_DBG("fileLen:%ld \n",fileLen);
fclose(fp);
mac[0] = file_content[MAC_ADDR];
mac[1] = file_content[MAC_ADDR+1];
mac[2] = file_content[MAC_ADDR+2];
mac[3] = file_content[MAC_ADDR+3];
mac[4] = file_content[MAC_ADDR+4];
mac[5] = file_content[MAC_ADDR+5];
GW_LOG_DBG("mac-output:%02x-%02x-%02x-%02x-%02x-%02x\n",mac[0]&0xff,mac[1]&0xff,mac[2]&0xff,mac[3]&0xff,mac[4]&0xff,mac[5]&0xff);
free(file_content);
return 1;
}
void set_mac_ack(pro_data_t pro_data)
{
unsigned char mac_iput[6] = {0};
pro_data_t pro_data_tmp;
//uint8_t arg_buf[256];
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
//pro_data_tmp.arg = arg_buf;
memcpy(pro_data_tmp.arg,pro_data.arg,pro_data.args_len);
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
//pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
uint8_t mac_len = pro_data_tmp.arg[0];
int i = 0;
for(i = 0; i < mac_len; i++)
{
mac_iput[i] = pro_data_tmp.arg[i+1];
}
printf("mac input:%02x-%02x-%02x-%02x-%02x-%02x\n",mac_iput[0],\
mac_iput[1],mac_iput[2],mac_iput[3],mac_iput[4],mac_iput[5]);
// ack handle
if(mac_modify(mac_iput) == 0)
{
pro_data_tmp.arg[0] = E_Proto_ERROR;
}
write_art_bin();
pro_data_tmp.arg[0] = E_Proto_OK; // err status
memset(&pro_data_tmp.arg[1],0,pro_data_tmp.args_len);
memcpy(&pro_data_tmp.arg[1],&pro_data.arg[0],pro_data.args_len);
pro_data_tmp.args_len++;
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
}
void read_flash_mac_ack(pro_data_t pro_data)
{
pro_data_t pro_data_tmp;
unsigned char eth0_mac[6] = {0};
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
//get mac
get_art_mac(eth0_mac);
pro_data_tmp.args_len = 0;
pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
pro_data_tmp.arg[pro_data_tmp.args_len++] = 6; // mac len
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[0]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[1]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[2]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[3]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[4]&0xff; // mac
pro_data_tmp.arg[pro_data_tmp.args_len++] = eth0_mac[5]&0xff; // mac
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
}
void read_version_ack(pro_data_t pro_data)
{
#if 0
pro_data_t pro_data_tmp;
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
int version_len = strlen(g_oled_config.version_str);
pro_data_tmp.args_len = 0;
pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
pro_data_tmp.arg[pro_data_tmp.args_len++] = version_len; // version len
memcpy(&pro_data_tmp.arg[pro_data_tmp.args_len],g_oled_config.version_str,version_len);
pro_data_tmp.args_len += version_len;
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
printf("---->%s\n",g_oled_config.version_str);
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
#endif
}
void exit_subboard_test_ack(pro_data_t pro_data)
{
#if 0
pro_data_t pro_data_tmp;
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
//pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
//��־λд��
memset(run_flag,0,sizeof(run_flag));
strcpy(run_flag ,RUN_FLAG_AGING);
save_cfg_str_to_file(run_flag_file_name, run_flag);
pro_data_tmp.args_len = 0;
pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
#endif
}
void set_sn_ack(pro_data_t pro_data)
{
unsigned char sn_str[128] = {0};
pro_data_t pro_data_tmp;
//uint8_t arg_buf[256];
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
//pro_data_tmp.arg = arg_buf;
memcpy(pro_data_tmp.arg,pro_data.arg,pro_data.args_len);
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
//pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
uint8_t sn_len = pro_data_tmp.arg[0];
int i = 0;
for(i = 0; i < sn_len; i++)
{
sn_str[i] = pro_data_tmp.arg[i+1];
}
sn_str[i]='\0';
printf("sn_str:%s\n",sn_str);
pro_data_tmp.arg[0] = 0; // err status
memset(&pro_data_tmp.arg[1],0,pro_data_tmp.args_len);
memcpy(&pro_data_tmp.arg[1],&pro_data.arg[0],pro_data.args_len);
pro_data_tmp.args_len++;
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
char buf[64] = {0};
int ret_len = 0;
char cmd[128] = {0};
sprintf(cmd,"%s%s",SET_SN_CMD,sn_str);
kk_execel_cmd(cmd,buf,64,&ret_len);
//save_cfg_str_to_file(SN_CFG_FILE,(char *)sn_str);
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
}
void get_sn_ack(pro_data_t pro_data)
{
pro_data_t pro_data_tmp;
memset((char*)&pro_data_tmp,0,sizeof(pro_data_t));
memcpy(&pro_data_tmp,&pro_data,sizeof(pro_data_t));
pro_data_tmp.cf.dir = 1;
pro_data_tmp.cf.sof_flag = 0;
//pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
//��־λд��
uint8_t sn[128] = {0};
int sn_len = 0;
kk_execel_cmd(GET_SN_CMD,(char *)sn,128,&sn_len);
//int sn_len = strlen((char *)sn);
pro_data_tmp.args_len = 0;
if(sn_len == 0)
{
pro_data_tmp.arg[pro_data_tmp.args_len++] = 1; // err status
}
else
{
pro_data_tmp.arg[pro_data_tmp.args_len++] = 0; // err status
}
sn_len--;//ȥ�����з�
pro_data_tmp.arg[pro_data_tmp.args_len++] = sn_len; // version len
memcpy(&pro_data_tmp.arg[pro_data_tmp.args_len],(char *)sn,sn_len);
pro_data_tmp.args_len += sn_len;
uint8_t data_buf[255] = {0};
uint8_t data_len = 0;
data_len = proto_frame_to_uart(&pro_data_tmp,data_buf);
dev_send_uart(data_buf, data_len);
}
/********************/
extern void kk_vp_opcode_handle(pro_data_t *pro_data);
void uart_frame_handle()
{
GW_LOG_DBG("uart_frame_handle\n");
uint8_t *data = g_uart_data.data;
uint8_t data_len = g_uart_data.data_len;
pro_data_t pro_data;
//uint8_t pro_data_buf[256];
//pro_data.arg = pro_data_buf;
if (get_proto_frame(data, data_len, &pro_data) == false)
{
return;
}
uart_protocol_print(&pro_data);
kk_vp_opcode_handle(&pro_data);
// handle msg
switch (pro_data.opcode)
{
case OPCODE_CONNECT_STATUS_QUERY:
{
connect_status_ack(pro_data);
break;
}
case OPCODE_BURN_MAC:
{
//��ʱ��֧��
set_mac_ack(pro_data);
break;
}
case OPCODE_READ_MAC:
{
read_mac_ack(pro_data);
break;
}
case OPCODE_SET_SN:
{
set_sn_ack(pro_data);
break;
}
case OPCODE_GET_SN:
{
get_sn_ack(pro_data);
break;
}
case OPCODE_READ_VERSION:
{
read_version_ack(pro_data);
break;
}
case OPCODE_EXIT_SUBBOARD_TEST:
{
exit_subboard_test_ack(pro_data);
break;
}
case OPCODE_READ_MAC_FROM_FLASH:
{
read_flash_mac_ack(pro_data);
break;
}
case OPCODE_SYSTEM_RESTART:
{
system_restart_ack(pro_data);
break;
}
default:
{
//GW_LOG_DBG("gw others opcode %04X ack\n", pro_data.opcode);
break;
}
}
return;
}
#ifndef __UART_PROTO_H__
#define __UART_PROTO_H__
#include <syslog.h>
#include "infra_types.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define GW_LOG(level, fmt, args...) \
do \
{ \
syslog(level, fmt, ##args); \
printf("\n["__FILE__":%d] "fmt,__LINE__, ##args); \
} while(0)
#define GW_LOG_DBG(fmt, args...) GW_LOG(LOG_DEBUG, fmt, ##args)
#define GW_LOG_ERR(fmt, args...) GW_LOG(LOG_ERR, fmt, ##args)
//define protocal field size
#define PRO_SOF_SIZE 2
#define PRO_CONTORL_FIELD_SIZE 1
#define PRO_LEN_SIZE 2
#define PRO_CRC_SIZE 2
#define PRO_SEQ_SIZE 2
#define PRO_MIN_DATA_SIZE 4 // channel(1) + opcode(2) + args(1)
#define PRO_LINK_PAKCET_SIZE 13
#define PRO_APP_PACKET_MIN_SIZE 13
//define field index
#define PRO_SOF_INDEX 0
#define PRO_LEN_INDEX (PRO_SOF_INDEX + PRO_SOF_SIZE)
#define PRO_CF_INDEX (PRO_LEN_INDEX + PRO_LEN_SIZE)
#define PRO_SEQ_INDEX (PRO_CF_INDEX + PRO_CONTORL_FIELD_SIZE)
#define PRO_DATA_INDEX (PRO_SEQ_INDEX + PRO_SEQ_SIZE)
//define SOF
#define PRO_SOF_1 0xAA
#define PRO_SOF_2 0x55
#define DEV_UART_RECV_BUFFER_SIZE 255
#define MAC_ADDR 0x00000
/***************OPCODE*******************/
#define OPCODE_CONNECT_STATUS_QUERY 0x0000 //ͨѶ״̬ѯ
#define OPCODE_BURN_MAC 0x0001
#define OPCODE_READ_MAC 0x0002
#define OPCODE_SET_SN 0x0003
#define OPCODE_GET_SN 0x0004
#define OPCODE_READ_VERSION 0x0005
#define OPCODE_EXIT_SUBBOARD_TEST 0x0006
#define OPCODE_READ_MAC_FROM_FLASH 0x0007
#define OPCODE_SYSTEM_RESTART 0x0008
/*********************************/
typedef enum
{
E_Proto_OK = 0,
E_Proto_ERROR,
} teProto_Status;
typedef struct
{
uint8_t data_len;
uint8_t data[DEV_UART_RECV_BUFFER_SIZE];
} uart_data_t;
typedef enum
{
SOP_STATE1 = 0,
SOP_STATE2,
LENGTH_STATE1,
LENGTH_STATE2,
CONTROL_FIELD_STATE1,
SEQ_STATE1,
SEQ_STATE2,
DATA_STATE,
CRC16_STATE1,
CRC16_STATE2,
} utp_state_t;
typedef struct
{
uint8_t ack;
uint8_t dir;
uint8_t sof_flag;
uint8_t mf_flag;
} control_field_t;
typedef struct
{
uint16_t length;
control_field_t cf;
uint16_t seq;
uint8_t ch;
uint16_t opcode;
uint16_t args_len;
uint8_t arg[256];
} pro_data_t;
int my_system(const char * cmd);
uint32_t make_crc32(uint8_t *msg, uint16_t len);
uint16_t make_crc16(uint8_t *msg, uint16_t len);
uint8_t cf_to_uint8_t(control_field_t *cf);
uint8_t pro_check_uart_frame(uint8_t *data, uint16_t data_len);
void dev_send_uart(uint8_t *data, uint16_t data_len);
int get_proto_frame(uint8_t *data, uint16_t data_len, pro_data_t *pro_data);
void pro_send_link_ack(pro_data_t *pro_data);
uint8_t proto_frame_to_uart(pro_data_t *pro_data, uint8_t *uart_data);
int get_uart_frame(uint8_t * buf,int len);
void uart_frame_handle();
#ifdef __cplusplus
}
#endif
#endif /* __DEV_PROTO_H__ */
...@@ -60,7 +60,7 @@ int HAL_Execel_cmd(char * cmd,char * buf,int buf_len,int* ret_len) ...@@ -60,7 +60,7 @@ int HAL_Execel_cmd(char * cmd,char * buf,int buf_len,int* ret_len)
} }
void *HAL_Malloc(_IN_ uint32_t size) void *HAL_Malloc(_IN_ uint32_t size)
{ {
return malloc(size); return malloc(size);
} }
void *HAL_Realloc(_IN_ void *ptr, _IN_ uint32_t size) void *HAL_Realloc(_IN_ void *ptr, _IN_ uint32_t size)
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#define PRODUCT_TPYE "kk" #define PRODUCT_TPYE "kk"
#define CCU_LAN "eth1" #define CCU_LAN "eth1"
#define KK_CCU_ID "CCU_77770" #define KK_CCU_ID "CCU_77771"
#define KK_CCU_PRODUCTID "ccu_n12" #define KK_CCU_PRODUCTID "ccu_n12"
#define KK_GW_PRODUCTID "gateway_2" #define KK_GW_PRODUCTID "gateway_2"
#define KK_CCU_RANDOM "0000000000" #define KK_CCU_RANDOM "0000000000"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "cJSON.h" #include "cJSON.h"
#include "kk_dm_api.h" #include "kk_dm_api.h"
#include "kk_dm_msg.h" #include "kk_dm_msg.h"
#include <curl/curl.h> //#include <curl.h>
#include "com_api.h" #include "com_api.h"
#include "kk_log.h" #include "kk_log.h"
...@@ -237,6 +237,7 @@ int progress_callback(void *clientp, double dltotal, double dlnow, double ultota ...@@ -237,6 +237,7 @@ int progress_callback(void *clientp, double dltotal, double dlnow, double ultota
} }
void dm_ota_start(char *url) void dm_ota_start(char *url)
{ {
#if 0
int res = 0; int res = 0;
char *progress_data = "* "; char *progress_data = "* ";
CURL* curl = curl_easy_init(); CURL* curl = curl_easy_init();
...@@ -265,9 +266,11 @@ void dm_ota_start(char *url) ...@@ -265,9 +266,11 @@ void dm_ota_start(char *url)
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
fclose(file); fclose(file);
#endif
} }
void dm_ota_start_MD5(char *url) void dm_ota_start_MD5(char *url)
{ {
#if 0
int res = 0; int res = 0;
char *md5_url = malloc(strlen(url)+10); char *md5_url = malloc(strlen(url)+10);
if(md5_url == NULL){ if(md5_url == NULL){
...@@ -304,6 +307,7 @@ void dm_ota_start_MD5(char *url) ...@@ -304,6 +307,7 @@ void dm_ota_start_MD5(char *url)
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
fclose(file); fclose(file);
free(md5_url); free(md5_url);
#endif
} }
void dm_ota_handle(void *data){ void dm_ota_handle(void *data){
printf("dm_ota_handle ================== [%s]\n",(char*)data); printf("dm_ota_handle ================== [%s]\n",(char*)data);
......
...@@ -19,6 +19,7 @@ void kk_sendData2app(void *info, void *payload,int isAsync){ ...@@ -19,6 +19,7 @@ void kk_sendData2app(void *info, void *payload,int isAsync){
cJSON_AddItemToObject(root, "info", infoObj); cJSON_AddItemToObject(root, "info", infoObj);
cJSON_AddItemToObject(root, "payload",payloadObj); cJSON_AddItemToObject(root, "payload",payloadObj);
buf = cJSON_Print(root); buf = cJSON_Print(root);
cJSON_Minify(buf);
if(isAsync){ if(isAsync){
dm_queue_msg_insert4(buf); dm_queue_msg_insert4(buf);
......
...@@ -11,7 +11,7 @@ CFLAGS += -I$(TOP_DIR)/common/sqlite ...@@ -11,7 +11,7 @@ CFLAGS += -I$(TOP_DIR)/common/sqlite
CFLAGS += -I$(TOP_DIR)/src/tsl/tsl_handle CFLAGS += -I$(TOP_DIR)/src/tsl/tsl_handle
LDFLAGS += -lapi_com -liot_cjson -lkk_tsl LDFLAGS += -lapi_com -liot_cjson -lkk_tsl
LDFLAGS += -lm -lkk_hal LDFLAGS += -lm -lkk_hal
LDFLAGS += -lsqlite -ldl -lcurl LDFLAGS += -lsqlite -ldl
ifeq ($(CONFIG_MODEL),x86) ifeq ($(CONFIG_MODEL),x86)
LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg_ubuntu -lanl LDFLAGS += -L$(TOP_DIR)/common/nanomsg -lnanomsg_ubuntu -lanl
......
{ {
"productCode":"3020", "productCode":"3020",
"operateType":"2001", "operateType":"2001",
"channel":1, "channel":1,
"syn_type":1, "syn_type":1,
"syn_opcode":"STATUS", "syn_opcode":"STATUS",
"newccu":[ "newccu":[
{ {
"identifier":"PowerSwitch", "identifier":"PowerSwitch",
"opcodemap":"SWITCH", "opcodemap":"SWITCH",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1], "valueRange":[0,1],
"value": 0 "value": 0
}, },
{ {
"identifier":"Power", "identifier":"Power",
"opcodemap":"GET_DEV_POWER", "opcodemap":"GET_DEV_POWER",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
}, },
{ {
"identifier":"Electric", "identifier":"Electric",
"opcodemap":"GET_ELECTRICAL", "opcodemap":"GET_ELECTRICAL",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
}, },
{ {
"identifier":"", "identifier":"",
"opcodemap":"STATUS", "opcodemap":"STATUS",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 1 "value": 1
} }
], ],
"oldccu":[ "oldccu":[
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"PowerSwitch", "identifiermap":"PowerSwitch",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["OFF","ON"], "valueRange":["OFF","ON"],
"syn":"switch", "syn":"switch",
"synType":"map" "synType":"map"
}, },
{ {
"opcode":"GET_DEV_POWER", "opcode":"GET_DEV_POWER",
"identifiermap":"Power", "identifiermap":"Power",
"dataType":"string_double", "dataType":"string_double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"", "syn":"",
"synType":"dummy" "synType":"dummy"
}, },
{ {
"opcode":"GET_ELECTRICAL", "opcode":"GET_ELECTRICAL",
"identifiermap":"Electric", "identifiermap":"Electric",
"dataType":"string_double", "dataType":"string_double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"", "syn":"",
"synType":"dummy" "synType":"dummy"
}, },
{ {
"opcode":"STATUS", "opcode":"STATUS",
"identifiermap":"", "identifiermap":"",
"dataType":"dummy", "dataType":"dummy",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"light_switch", "syn":"light_switch",
"synType":"bool" "synType":"bool"
} }
] ]
} }
\ No newline at end of file
{ {
"productCode":"3023", "productCode":"3023",
"operateType":"3", "operateType":"3",
"channel":2, "channel":2,
"newccu":[ "newccu":[
{ {
"identifier":"PowerSwitch", "identifier":"PowerSwitch",
"opcodemap":"SWITCH", "opcodemap":"SWITCH",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1], "valueRange":[0,1],
"value": 0 "value": 0
}, },
{ {
"identifier":"PowerSwitch", "identifier":"PowerSwitch",
"opcodemap":"SWITCH", "opcodemap":"SWITCH",
"dataType":"int", "dataType":"int",
"channel":"2", "channel":"2",
"valueRange":[0,1], "valueRange":[0,1],
"value": 0 "value": 0
} }
], ],
"oldccu":[ "oldccu":[
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"PowerSwitch", "identifiermap":"PowerSwitch",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["OFF","ON"] "valueRange":["OFF","ON"]
}, },
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"PowerSwitch", "identifiermap":"PowerSwitch",
"dataType":"map", "dataType":"map",
"channel":"2", "channel":"2",
"valueRange":["OFF","ON"] "valueRange":["OFF","ON"]
} }
] ]
} }
\ No newline at end of file
{ {
"productCode":"3027", "productCode":"3027",
"operateType":"1003", "operateType":"1003",
"channel":2, "channel":2,
"newccu":[ "newccu":[
{ {
"identifier":"OperationMode", "identifier":"OperationMode",
"opcodemap":"SWITCH", "opcodemap":"SWITCH",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1,2], "valueRange":[0,1,2],
"value": 2 "value": 2
}, },
{ {
"identifier":"OperationMode", "identifier":"OperationMode",
"opcodemap":"SWITCH", "opcodemap":"SWITCH",
"dataType":"int", "dataType":"int",
"channel":"2", "channel":"2",
"valueRange":[0,1,2], "valueRange":[0,1,2],
"value": 2 "value": 2
} }
], ],
"oldccu":[ "oldccu":[
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"OperationMode", "identifiermap":"OperationMode",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["CLOSE","OPEN","STOP"] "valueRange":["CLOSE","OPEN","STOP"]
}, },
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"OperationMode", "identifiermap":"OperationMode",
"dataType":"map", "dataType":"map",
"channel":"2", "channel":"2",
"valueRange":["CLOSE","OPEN","STOP"] "valueRange":["CLOSE","OPEN","STOP"]
} }
] ]
} }
\ No newline at end of file
{ {
"productCode":"3032", "productCode":"3032",
"operateType":"14002", "operateType":"14002",
"channel":1, "channel":1,
"syn_type":1, "syn_type":1,
"syn_opcode":"CHOPIN_FRESH_AIR_STATUS", "syn_opcode":"CHOPIN_FRESH_AIR_STATUS",
"newccu":[ "newccu":[
{ {
"identifier":"PowerSwitch", "identifier":"PowerSwitch",
"opcodemap":"FRESH_AIR_SWITCH", "opcodemap":"FRESH_AIR_SWITCH",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1], "valueRange":[0,1],
"value": 0 "value": 0
},{ },{
"identifier":"WorkMode", "identifier":"WorkMode",
"opcodemap":"FRESH_AIR_RUN_MODEL", "opcodemap":"FRESH_AIR_RUN_MODEL",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1], "valueRange":[0,1],
"value": 1 "value": 1
},{ },{
"identifier":"WindSpeed", "identifier":"WindSpeed",
"opcodemap":"FRESH_AIR_SPEED_SET", "opcodemap":"FRESH_AIR_SPEED_SET",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1,2,3], "valueRange":[0,1,2,3],
"value": 1 "value": 1
},{ },{
"identifier":"ChildLockState", "identifier":"ChildLockState",
"opcodemap":"FRESH_AIR_SET_LOCK_STATUS", "opcodemap":"FRESH_AIR_SET_LOCK_STATUS",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1], "valueRange":[0,1],
"value": 0 "value": 0
},{ },{
"identifier":"TimingOffTime", "identifier":"TimingOffTime",
"opcodemap":"FRESH_AIR_SET_TIME_OFF", "opcodemap":"FRESH_AIR_SET_TIME_OFF",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
},{ },{
"identifier":"StrainerUsageTime", "identifier":"StrainerUsageTime",
"opcodemap":"CHOPIN_FRESH_AIR_STATUS", "opcodemap":"CHOPIN_FRESH_AIR_STATUS",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
},{ },{
"identifier":"StrainerAlarmTime", "identifier":"StrainerAlarmTime",
"opcodemap":"CHOPIN_FRESH_AIR_STATUS", "opcodemap":"CHOPIN_FRESH_AIR_STATUS",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
},{ },{
"identifier":"CurrentTemperature", "identifier":"CurrentTemperature",
"opcodemap":"CHOPIN_FRESH_AIR_STATUS", "opcodemap":"CHOPIN_FRESH_AIR_STATUS",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
} }
], ],
"oldccu":[ "oldccu":[
{ {
"opcode":"FRESH_AIR_SWITCH", "opcode":"FRESH_AIR_SWITCH",
"identifiermap":"PowerSwitch", "identifiermap":"PowerSwitch",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["OFF","ON"], "valueRange":["OFF","ON"],
"syn":"on", "syn":"on",
"synType":"bool" "synType":"bool"
},{ },{
"opcode":"FRESH_AIR_RUN_MODEL", "opcode":"FRESH_AIR_RUN_MODEL",
"identifiermap":"WorkMode", "identifiermap":"WorkMode",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["AUTO","MANUAL"], "valueRange":["AUTO","MANUAL"],
"syn":"runModel", "syn":"runModel",
"synType":"map" "synType":"map"
},{ },{
"opcode":"FRESH_AIR_SPEED_SET", "opcode":"FRESH_AIR_SPEED_SET",
"identifiermap":"WindSpeed", "identifiermap":"WindSpeed",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["STOP","LOW","MID","HIGH"], "valueRange":["STOP","LOW","MID","HIGH"],
"syn":"speed", "syn":"speed",
"synType":"int" "synType":"int"
},{ },{
"opcode":"FRESH_AIR_SET_LOCK_STATUS", "opcode":"FRESH_AIR_SET_LOCK_STATUS",
"identifiermap":"ChildLockState", "identifiermap":"ChildLockState",
"dataType":"bool", "dataType":"bool",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"ChildLockState", "syn":"ChildLockState",
"synType":"double" "synType":"double"
},{ },{
"opcode":"FRESH_AIR_SET_TIME_OFF", "opcode":"FRESH_AIR_SET_TIME_OFF",
"identifiermap":"TimingOffTime", "identifiermap":"TimingOffTime",
"dataType":"string_time", "dataType":"string_time",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"time_off", "syn":"time_off",
"synType":"string_time" "synType":"string_time"
},{ },{
"opcode":"CHOPIN_FRESH_AIR_STATUS ", "opcode":"CHOPIN_FRESH_AIR_STATUS ",
"identifiermap":"StrainerUsageTime", "identifiermap":"StrainerUsageTime",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"filterScreenWorkTime", "syn":"filterScreenWorkTime",
"synType":"int" "synType":"int"
},{ },{
"opcode":"CHOPIN_FRESH_AIR_STATUS", "opcode":"CHOPIN_FRESH_AIR_STATUS",
"identifiermap":"StrainerAlarmTime", "identifiermap":"StrainerAlarmTime",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"filterScreenAlarmTime", "syn":"filterScreenAlarmTime",
"synType":"int" "synType":"int"
},{ },{
"opcode":"CHOPIN_FRESH_AIR_STATUS", "opcode":"CHOPIN_FRESH_AIR_STATUS",
"identifiermap":"CurrentTemperature", "identifiermap":"CurrentTemperature",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"cur_temperature", "syn":"cur_temperature",
"synType":"double" "synType":"double"
} }
] ]
} }
{ {
"productCode":"3034", "productCode":"3034",
"operateType":"15003", "operateType":"15003",
"channel":1, "channel":1,
"syn_type":1, "syn_type":1,
"syn_opcode":"FAN_COIL_STATUS", "syn_opcode":"FAN_COIL_STATUS",
"newccu":[ "newccu":[
{ {
"identifier":"PowerSwitch", "identifier":"PowerSwitch",
"opcodemap":"SWITCH", "opcodemap":"SWITCH",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1], "valueRange":[0,1],
"value": 0 "value": 0
},{ },{
"identifier":"WorkMode", "identifier":"WorkMode",
"opcodemap":"FAN_COIL_SET_RUN_MODEL", "opcodemap":"FAN_COIL_SET_RUN_MODEL",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[1,2,3,4], "valueRange":[1,2,3,4],
"value": 1 "value": 1
},{ },{
"identifier":"WindSpeed", "identifier":"WindSpeed",
"opcodemap":"FAN_COIL_SET_FUN_SPEED", "opcodemap":"FAN_COIL_SET_FUN_SPEED",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[1,2,3,4], "valueRange":[1,2,3,4],
"value": 1 "value": 1
},{ },{
"identifier":"TargetTemperature", "identifier":"TargetTemperature",
"opcodemap":"FAN_COIL_SET_TEMPERATURE", "opcodemap":"FAN_COIL_SET_TEMPERATURE",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 16 "value": 16
},{ },{
"identifier":"TimingOffTime", "identifier":"TimingOffTime",
"opcodemap":"FAN_COIL_SET_DELAY_SWITCH_TASK", "opcodemap":"FAN_COIL_SET_DELAY_SWITCH_TASK",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
},{ },{
"identifier":"ChildLockState", "identifier":"ChildLockState",
"opcodemap":"FAN_COIL_SET_LOCK_STATUS", "opcodemap":"FAN_COIL_SET_LOCK_STATUS",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1], "valueRange":[0,1],
"value": 0 "value": 0
},{ },{
"identifier":"CurrentTemperature", "identifier":"CurrentTemperature",
"opcodemap":"room_temperature", "opcodemap":"room_temperature",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 22 "value": 22
},{ },{
"identifier":"smart_model_id", "identifier":"smart_model_id",
"opcodemap":"FAN_COIL_STATUS", "opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy", "dataType":"dummy",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
},{ },{
"identifier":"smart_model_time_index", "identifier":"smart_model_time_index",
"opcodemap":"FAN_COIL_STATUS", "opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy", "dataType":"dummy",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
},{ },{
"identifier":"system_time", "identifier":"system_time",
"opcodemap":"FAN_COIL_STATUS", "opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy", "dataType":"dummy",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": "1970-01-01 00:00:00" "value": "1970-01-01 00:00:00"
},{ },{
"identifier":"week_day", "identifier":"week_day",
"opcodemap":"FAN_COIL_STATUS", "opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy", "dataType":"dummy",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
},{ },{
"identifier":"total_work_time", "identifier":"total_work_time",
"opcodemap":"FAN_COIL_STATUS", "opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy", "dataType":"dummy",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
},{ },{
"identifier":"timing_boot", "identifier":"timing_boot",
"opcodemap":"FAN_COIL_STATUS", "opcodemap":"FAN_COIL_STATUS",
"dataType":"dummy", "dataType":"dummy",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": { "value": {
"enable ": false, "enable ": false,
"time": "00:00" "time": "00:00"
} }
} }
], ],
"oldccu":[ "oldccu":[
{ {
"opcode":"SWITCH", "opcode":"SWITCH",
"identifiermap":"PowerSwitch", "identifiermap":"PowerSwitch",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["OFF","ON"], "valueRange":["OFF","ON"],
"syn":"on", "syn":"on",
"synType":"bool" "synType":"bool"
},{ },{
"opcode":"FAN_COIL_SET_RUN_MODEL", "opcode":"FAN_COIL_SET_RUN_MODEL",
"identifiermap":"WorkMode", "identifiermap":"WorkMode",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["COLD","HOT","WIND","DEHUMIDIFICATION"], "valueRange":["COLD","HOT","WIND","DEHUMIDIFICATION"],
"syn":"run_model", "syn":"run_model",
"synType":"map" "synType":"map"
},{ },{
"opcode":"FAN_COIL_SET_FUN_SPEED", "opcode":"FAN_COIL_SET_FUN_SPEED",
"identifiermap":"WindSpeed", "identifiermap":"WindSpeed",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["AUTO","HIGH","MID","LOW"], "valueRange":["AUTO","HIGH","MID","LOW"],
"syn":"fan_speed", "syn":"fan_speed",
"synType":"map" "synType":"map"
},{ },{
"opcode":"FAN_COIL_SET_TEMPERATURE", "opcode":"FAN_COIL_SET_TEMPERATURE",
"identifiermap":"TargetTemperature", "identifiermap":"TargetTemperature",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"setting_temperature", "syn":"setting_temperature",
"synType":"double" "synType":"double"
},{ },{
"opcode":"FAN_COIL_SET_DELAY_SWITCH_TASK", "opcode":"FAN_COIL_SET_DELAY_SWITCH_TASK",
"identifiermap":"TimingOffTime", "identifiermap":"TimingOffTime",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"timing_shutdown", "syn":"timing_shutdown",
"synType":"timing_shutdown" "synType":"timing_shutdown"
},{ },{
"opcode":"FAN_COIL_SET_LOCK_STATUS", "opcode":"FAN_COIL_SET_LOCK_STATUS",
"identifiermap":"ChildLockState", "identifiermap":"ChildLockState",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"", "syn":"",
"synType":"dummy" "synType":"dummy"
},{ },{
"opcode":"room_temperature", "opcode":"room_temperature",
"identifiermap":"CurrentTemperature", "identifiermap":"CurrentTemperature",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"room_temperature", "syn":"room_temperature",
"synType":"double" "synType":"double"
},{ },{
"opcode":"FAN_COIL_STATUS", "opcode":"FAN_COIL_STATUS",
"identifiermap":"smart_model_id", "identifiermap":"smart_model_id",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"smart_model_id", "syn":"smart_model_id",
"synType":"double" "synType":"double"
},{ },{
"opcode":"FAN_COIL_STATUS", "opcode":"FAN_COIL_STATUS",
"identifiermap":"smart_model_time_index", "identifiermap":"smart_model_time_index",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"smart_model_time_index", "syn":"smart_model_time_index",
"synType":"double" "synType":"double"
},{ },{
"opcode":"FAN_COIL_STATUS", "opcode":"FAN_COIL_STATUS",
"identifiermap":"system_time", "identifiermap":"system_time",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"system_time", "syn":"system_time",
"synType":"map" "synType":"map"
},{ },{
"opcode":"FAN_COIL_STATUS", "opcode":"FAN_COIL_STATUS",
"identifiermap":"week_day", "identifiermap":"week_day",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"week_day", "syn":"week_day",
"synType":"int" "synType":"int"
},{ },{
"opcode":"FAN_COIL_STATUS", "opcode":"FAN_COIL_STATUS",
"identifiermap":"total_work_time", "identifiermap":"total_work_time",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"total_work_time", "syn":"total_work_time",
"synType":"int" "synType":"int"
},{ },{
"opcode":"FAN_COIL_STATUS", "opcode":"FAN_COIL_STATUS",
"identifiermap":"timing_boot", "identifiermap":"timing_boot",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"timing_boot", "syn":"timing_boot",
"synType":"def" "synType":"def"
} }
] ]
} }
{ {
"productCode":"3051", "productCode":"3051",
"operateType":"3499", "operateType":"3499",
"channel":1, "channel":1,
"syn_type":1, "syn_type":1,
"syn_opcode":"DOOR_CONTACT_STATUS", "syn_opcode":"DOOR_CONTACT_STATUS",
"newccu":[ "newccu":[
{ {
"identifier":"ContactState", "identifier":"ContactState",
"opcodemap":"DOOR_CONTACT_NOTIFY", "opcodemap":"DOOR_CONTACT_NOTIFY",
"dataType":"int", "dataType":"int",
"channel":"1", "channel":"1",
"valueRange":[0,1], "valueRange":[0,1],
"value": 0 "value": 0
}, },
{ {
"identifier":"Battery", "identifier":"Battery",
"opcodemap":"POWER_NOTIFY", "opcodemap":"POWER_NOTIFY",
"dataType":"double", "dataType":"double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"value": 0 "value": 0
} }
], ],
"oldccu":[ "oldccu":[
{ {
"opcode":"DOOR_CONTACT_NOTIFY", "opcode":"DOOR_CONTACT_NOTIFY",
"identifiermap":"ContactState", "identifiermap":"ContactState",
"dataType":"map", "dataType":"map",
"channel":"1", "channel":"1",
"valueRange":["CLOSE","OPEN"], "valueRange":["CLOSE","OPEN"],
"syn":"status", "syn":"status",
"synType":"map" "synType":"map"
}, },
{ {
"opcode":"POWER_NOTIFY", "opcode":"POWER_NOTIFY",
"identifiermap":"Battery", "identifiermap":"Battery",
"dataType":"string_double", "dataType":"string_double",
"channel":"1", "channel":"1",
"valueRange":[], "valueRange":[],
"syn":"power", "syn":"power",
"synType":"string_double" "synType":"string_double"
} }
] ]
} }
\ No newline at end of file
File added
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