Commit b074f244 authored by 尹佳钦's avatar 尹佳钦

【20210827】 局域网增加串口选项参数,修改部分bug,

parent c811884f
......@@ -22,6 +22,8 @@ int serial_fd = 0;
//static struct termios options; //place for settings for serial port
char buf[255]; //buffer for where data is put
char serialDev[64];
/**************serial open *******************/
/***********************************************************
......@@ -242,7 +244,7 @@ void eSerial_start()
}
#endif
serial_fd = devOpen(SERIAL_NAME);
serial_fd = devOpen(serialDev);
}
/***********************************************************
......@@ -407,7 +409,13 @@ 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;
if(serial_fd <= 0)
{
return E_SERIAL_FD_ERROR;
}
while (total_sent_bytes < count)
{
sent_bytes = write(serial_fd, &data[total_sent_bytes], count - total_sent_bytes);
......
......@@ -31,6 +31,9 @@ extern "C" {
#define SERIAL_NAME "/dev/ttyUSB0"//"/dev/ttyS0"
#define SERIAL_BAUD 115200
extern char serialDev[64];
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
......
......@@ -236,7 +236,7 @@ static cJSON *kk_zb_dev_hw_info_build(const char *deviceCode,cJSON * productCode
cJSON_AddNumberToObject(item, "online_status",online_status);
cJSON_AddNumberToObject(item, "product_id", pid);
if(hw_ver!=NULL){
if(sw_ver!=NULL){
cJSON_AddStringToObject(item, "version", sw_ver);
}else{
cJSON_AddStringToObject(item, "version", "");
......@@ -326,7 +326,7 @@ static void kk_zb_devs_hw_ack(int sockfd,cJSON *conditions)
cJSON *item;
cJSON *array = cJSON_CreateArray();
for(i=0;i<size;i++){
qMac=cJSON_GetArrayItem(arg,1);
qMac=cJSON_GetArrayItem(arg,i);
if(mac_switchto_deviceCode(qMac->valuestring,devCode)==0){
if((item=kk_zb_dev_hw_info_build_by_deviceCode(sockfd,devCode,-1))!=NULL){
cJSON_AddItemToArray(array,item);
......@@ -351,8 +351,8 @@ static void kk_handle_del_history_info(char *key)
int kk_data_handle(cJSON *json,int sockfd)
{
cJSON *opcode;
cJSON *arg;
cJSON *opcode = NULL;
cJSON *arg = NULL;
opcode = cJSON_GetObjectItem(json, OPCODE_STRING);
......@@ -741,11 +741,11 @@ static int kk_lan_scene_handle(cJSON *payload,int isAdd)
void KK_Data_FromMid(void* str,int len)
{
cJSON *json;
cJSON *info,*payload;
cJSON *msgtype,*deviceCode,*productCode;
cJSON *json = NULL;
cJSON *info = NULL,*payload = NULL;
cJSON *msgtype = NULL,*deviceCode = NULL,*productCode = NULL;
printf("[midware->lan] len=%d,data=%s\n",len,str);
debug_log(LOG_FOCUS,"[midware->lan] len=%d,data=%s\n",len,str);
if((json= cJSON_Parse(str)) == NULL) {
return;
......
......@@ -51,7 +51,7 @@ void kk_map_dev_deinit(void)
kk_map_dev_node_t *node = NULL;
kk_map_dev_node_t *n = NULL;
printf("[%s][%d]\n",__FUNCTION__,__LINE__);
//printf("[%s][%d]\n",__FUNCTION__,__LINE__);
_kk_map_dev_mutex_lock();
list_for_each_entry_safe(node,n,&ctx->dev_list, linked_list, kk_map_dev_node_t) {
......@@ -59,15 +59,15 @@ void kk_map_dev_deinit(void)
if (node != NULL) {
if(node->json){
printf("[delete cjson] node->json.\n");
//printf("[delete cjson] node->json.\n");
cJSON_Delete(node->json);
}
if(node->syn_opcode) {
printf("[free] node->syn_opcode.\n");
//printf("[free] node->syn_opcode.\n");
free(node->syn_opcode);
}
printf("[remove list] node->linked_list\n");
//printf("[remove list] node->linked_list\n");
dlist_del(&node->linked_list);
memset(node,0,sizeof(kk_map_dev_node_t));
......
......@@ -80,7 +80,7 @@ int main(int argc, char* argv[])
kk_findccu_handle_init();
kk_map_dev_init();
kk_login_init();
//kk_voice_panel_init();
kk_voice_panel_init(argc,argv);
//lan_queue_init();
kk_lan_db_node_init();
......
......@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include<getopt.h>
#include "kk_log.h"
#include "kk_lan_voice_panel.h"
......@@ -39,6 +40,11 @@ static void *kk_vp_uart_thread(void *arg)
while (1)
{
while(serial_fd<0){
eSerial_start();
sleep(1);
}
FD_ZERO(&rd);
FD_SET(serial_fd,&rd);
......@@ -337,7 +343,39 @@ void *kk_vp_manage_thread(void *arg)
ERROR_PRINT("[%s]thread end...\n",__FUNCTION__);
}
int kk_voice_panel_init(void)
void kk_voice_panel_uart_dev_chose(int argc, char* argv[])
{
int flag = 0;
int opt;
int option_index = 0;
char *string = "";
static struct option long_options[] =
{
{"uart", optional_argument,NULL, 0xAA5555AA},
{NULL, 0, NULL, 0},
};
debug_log(LOG_FOCUS,"kk_voice_panel_uart_dev_chose\n");
while((opt =getopt_long_only(argc,argv,string,long_options,&option_index))!= -1)
{
if(opt==0xAA5555AA){
memset(serialDev,0,sizeof(serialDev));
snprintf(serialDev,sizeof(serialDev),"%s",optarg);
flag =1;
break;
}
}
if(flag==0){
memset(serialDev,0,sizeof(serialDev));
snprintf(serialDev,sizeof(serialDev),"%s",SERIAL_NAME);
}
debug_log(LOG_FOCUS,"serialDev=%s\n",serialDev);
}
int kk_voice_panel_init(int argc, char* argv[])
{
size_t s = 1500;
......@@ -347,6 +385,7 @@ int kk_voice_panel_init(void)
pthread_attr_t attr;
pthread_attr_init(&attr);
kk_voice_panel_uart_dev_chose(argc,argv);
pthread_attr_setstacksize(&attr, s);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
......
......@@ -6,7 +6,7 @@
int kk_voice_panel_init(void);
int kk_voice_panel_init(int argc, char* argv[]);
#define GET_8009_SNAPSHOOT_STATE 0
#define SET_8009_SYSTEM 1
......
......@@ -224,8 +224,8 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
cJSON *item_size = NULL;
cJSON *epsAry = NULL,*epAryItem = NULL,*epAryEpNumObj = NULL;
int j,mFlag=0,epsArySize = 0;
......@@ -255,11 +255,8 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
continue;
}
if((valObj=cJSON_GetObjectItem(params,n_id->valuestring))==NULL){
debug_log(LOG_NORMAL,"[match] next.\n");
continue ;
}
n_dataType = cJSON_GetObjectItem(n_item,"dataType");
n_valueRange = cJSON_GetObjectItem(n_item,"valueRange");
......@@ -275,9 +272,40 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
channelObj = cJSON_GetObjectItem(o_item,"channel");
epNumObj = cJSON_GetObjectItem(params,"epNum");
if((channel = _kk_lan_check_channel(channelObj,epNumObj))==-1){
debug_log(LOG_DEBUG,"[channel] %d.\n",channel);
continue;
}
if((epsAry = cJSON_GetObjectItem(params,"eps"))!=NULL&&epsAry->type==cJSON_Array){
epsArySize = cJSON_GetArraySize(epsAry);
for(j=0;j<epsArySize;j++){
epAryItem = cJSON_GetArrayItem(epsAry,j);
epAryEpNumObj = cJSON_GetObjectItem(epAryItem,"epNum");
if(epAryEpNumObj==NULL||epAryEpNumObj->type!=cJSON_String ||channel!=atoi(epAryEpNumObj->valuestring)){
debug_log(LOG_NORMAL,"[epsAry match] next.\n");
continue ;
}
if((valObj=cJSON_GetObjectItem(epAryItem,n_id->valuestring))==NULL){
debug_log(LOG_NORMAL,"[epsAry match] next.\n");
continue ;
}else{
mFlag = 1;
break;
}
}
if(mFlag!=1){
continue ;
}
}else{
if((valObj=cJSON_GetObjectItem(params,n_id->valuestring))==NULL){
debug_log(LOG_NORMAL,"[match] next.\n");
continue ;
}
}
if((nodeId = kk_lan_db_node_get(deviceCode,channel))==-1){
debug_log(LOG_DEBUG,"[err] not find node.\n");
continue;
......@@ -298,7 +326,6 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
_kk_lan_update_device_status(nodeId,opcode,args);
//todo :
//cJSON_Delete(args);
}
}
......@@ -308,6 +335,8 @@ static int kk_lan_property_convert(const char *deviceCode,kk_map_dev_node_t *dev
return 0;
}
static int attr_indoorAir_report(cJSON *params)
{
int k = 0;
......
{
"productCode":"3022",
"operateType":"3",
"channel":1,
"newccu":[
{
"identifier":"PowerSwitch",
"opcodemap":"SWITCH",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 0
}
],
"oldccu":[
{
"opcode":"SWITCH",
"identifiermap":"PowerSwitch",
"dataType":"map",
"channel":"1",
"valueRange":["OFF","ON"]
}
]
}
\ No newline at end of file
{
"productCode":"3026",
"operateType":"1003",
"channel":1,
"newccu":[
{
"identifier":"OperationMode",
"opcodemap":"SWITCH",
"dataType":"int",
"channel":"1",
"valueRange":[0,1,2],
"value": 2
}
],
"oldccu":[
{
"opcode":"SWITCH",
"identifiermap":"OperationMode",
"dataType":"map",
"channel":"1",
"valueRange":["CLOSE","OPEN","STOP"]
}
]
}
\ No newline at end of file
{
"productCode":"3029",
"operateType":"12501",
"channel":1,
"syn_type":1,
"syn_opcode":"FLOOR_HEATING_DEV_STATUS",
"newccu":[
{
"identifier":"PowerSwitch",
"opcodemap":"SWITCH",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 0
},{
"identifier":"WorkMode",
"opcodemap":"SET_WORK_MODEL",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 1
},{
"identifier":"Temperature",
"opcodemap":"SET_WORK_TEMPERATURE",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 16
},{
"identifier":"TimingOffTime",
"opcodemap":"FLOOR_HEATING_SET_TIME_OFF",
"dataType":"string_time",
"channel":"1",
"valueRange":[],
"value": 0
},{
"identifier":"ChildLockState",
"opcodemap":"FLOOR_HEATING_SET_LOCK_STATUS",
"dataType":"int",
"channel":"1",
"valueRange":[0,1],
"value": 0
},{
"identifier":"CurrentTemperature",
"opcodemap":"current_real_temperature",
"dataType":"double",
"channel":"1",
"valueRange":[],
"value": 22
},{
"identifier":"time_off",
"opcodemap":"FLOOR_HEATING_DEV_STATUS",
"dataType":"dummy",
"channel":"1",
"valueRange":[],
"value": 0
}
],
"oldccu":[
{
"opcode":"SWITCH",
"identifiermap":"PowerSwitch",
"dataType":"map",
"channel":"1",
"valueRange":["OFF","ON"],
"syn":"on",
"synType":"bool"
},{
"opcode":"SET_WORK_MODEL",
"identifiermap":"WorkMode",
"dataType":"map",
"channel":"1",
"valueRange":["AUTO","MANUAL"],
"syn":"run_model",
"synType":"map"
},{
"opcode":"SET_WORK_TEMPERATURE",
"identifiermap":"Temperature",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"work_temperature",
"synType":"double"
},{
"opcode":"FLOOR_HEATING_SET_TIME_OFF",
"identifiermap":"TimingOffTime",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"time_off",
"synType":"fit"
},{
"opcode":"FLOOR_HEATING_SET_LOCK_STATUS",
"identifiermap":"ChildLockState",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"",
"synType":"dummy"
},{
"opcode":"current_real_temperature",
"identifiermap":"CurrentTemperature",
"dataType":"double",
"channel":"1",
"valueRange":[],
"syn":"current_real_temperature",
"synType":"double"
}
]
}
{
"productCode":"3062",
"operateType":"12001",
"channel":1,
"newccu":[
],
"oldccu":[
]
}
{
"productCode":"3067",
"operateType":"1003",
"channel":1,
"newccu":[
{
"identifier":"OperationMode",
"opcodemap":"SWITCH",
"dataType":"int",
"channel":"1",
"valueRange":[0,1,2],
"value": 2
}
],
"oldccu":[
{
"opcode":"SWITCH",
"identifiermap":"OperationMode",
"dataType":"map",
"channel":"1",
"valueRange":["CLOSE","OPEN","STOP"]
}
]
}
\ No newline at end of file
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