Commit 2e5a7b62 authored by 杨熙's avatar 杨熙

设备基本功能完成,待完善升级,自定义topic,PIPO的topic

parent 9523bf65
This diff is collapsed.
......@@ -25,7 +25,7 @@
#include "KK_HwDevManager.h"
#define CENTRALAC_INDOORUNIT_NUM_MAX 64
#define MQ_VERSION "1.0.1"
#define MQ_VERSION "1.0.5.2"
using namespace std;
......@@ -77,13 +77,13 @@ private:
void handleNewDevice(EH::Json::Value devices, EH::Json::Value centralACdevices, EH::Json::Value newCentralAcGwsDevices);
void handleCcuDeviceToHwSubDev(string operateType,string nodeid,string mac,
string channel,string sn,EH::Json::Value status,string devroomid,string devname);
void handleACindoor(string devroomid,string devname,int indoorunitsdevCount,EH::Json::Value centralACdevices,int infocome);
// void handleACindoor(string devroomid,string devname,int indoorunitsdevCount,EH::Json::Value centralACdevices,int infocome);
//当网关离线,其下内机也推送离线
void handleACindoorDevNolinePush(string mac);
// void handleACindoorDevNolinePush(string mac);
//处理已加入房间的设备报文
void handleSyncInfo(EH::Json::Value arg,string opcode);\
void SYNC_handle_AcGw_Devices(EH::Json::Value CentralAcGwsDevices);
// void SYNC_handle_AcGw_Devices(EH::Json::Value CentralAcGwsDevices);
//添加设备到云
void addCCuDevicesToCloud(map<string,kk_handleDeviceInfo::HwSubDev*> toAddSubDevs);
......@@ -96,7 +96,7 @@ private:
//删除子设备
int onDeviceRequestDelete(string devSn);
//删除所有设备
int deleteCCuDevices();
// int deleteCCuDevices();
//删除网关时,也删除其下的内机。
int onACindoorDelete(string devMac);
......
......@@ -77,6 +77,7 @@ int ACE_TMAIN(int argc, ACE_TCHAR* argv[]) { //主函数
}
if(argc == 2 && string(argv[1]) == "-d") {
LOGI("000000000000000000000000000000000000000000\n");
oepnDebug();
}
......@@ -130,6 +131,7 @@ static void* run0(void* opt){
static void oepnDebug(){
LOGI("333333333333333333333333\n");
struct sockaddr_in addr; /*描述Internet套接字地址的结构。*/
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=htonl(INADDR_ANY);
......@@ -160,5 +162,6 @@ static void oepnDebug(){
正在传递ARG。创造属性来自属性。新的
句柄存储在*NEWTHREAD中。*/
pthread_t tid;
LOGI("444444444444444444444444444\n");
pthread_create(&tid, NULL, run0, NULL);
}
/*
* EH_DB.h
* Copyright by AirDream Co., Ltd. 2010-2011 All right reserved
*
* Description:
* Created on:2011-12-22
* Modified on:2011-12-22
*
*/
//#define NOT_X86
#ifndef NOT_X86
#ifndef EH_DB_H_
#define EH_DB_H_
#include <iostream>
#include <string>
#include <pqxx/pqxx>
#include "ace/Recursive_Thread_Mutex.h"
using namespace std;
using namespace pqxx;
typedef vector<map<string, string>*> DBRESVEC;
typedef vector<map<string, string>*>* DBRES;
typedef map<string, string> DBROWMAP;
typedef map<string, string>* DBROW;
class EH_DB {
public:
EH_DB(string username,string passwd,string addr,string port,string dbname);
~EH_DB();
void OpenConnection();
void CloseConnection();
void ResetConnection();
void StartTransaction();
void CommitTransaction();
void AbortTransaction();
void ExceptionInTransaction();
DBRES ExecuteQuery(string sql);
int ExecuteUpdate(string sql);
static void ReleaseResultSet(DBRES& res);
private:
connection* m_pConn;
transaction<>* m_pAction;
string m_strConnectionInfo;
ACE_Recursive_Thread_Mutex m_Lock;
};
#endif /* EH_DB_H_ */
#else
#include "EH_DB_Sqlite.h"
#endif
/*
* EH_DB.h
*
* Created on: 2013-9-10
* Author: sj
usage:
try {
StartTransaction();
ExecuteQuery
ExecuteUpdate
.....
CommitTransaction();
} catch (...) {
ExceptionInTransaction();//NOTE!!
....//custom process code
}
modify by zgm at 2016-5-6
*/
#ifdef NOT_X86
#ifndef EH_DB_H_
#define EH_DB_H_
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include "ace/Recursive_Thread_Mutex.h"
#include "ace/Process_Mutex.h"
#include "EH_Sqlite3.h"
using namespace std;
typedef vector<map<string, string>*> DBRESVEC;
typedef vector<map<string, string>*>* DBRES;
typedef map<string, string> DBROWMAP;
typedef map<string, string>* DBROW;
class EH_DB {
public:
EH_DB(string username,string passwd,string addr,string port,string dbname);
~EH_DB();
/*
* If already have a connection,don't get a new connection.
* if success return 0, else are other values.
*/
int OpenConnection();
/*
* close the db connection
*/
void CloseConnection();
/*
* if success return 0, else are other values.
*/
int ResetConnection();
/*
* if success return 0, else are other values.
*/
int StartTransaction();
/*
* if success return 0, else are other values.
*/
int CommitTransaction();
/*
* if success return 0, else are other values.
*/
int AbortTransaction();
/* must be called when exception occur when in executing a transaction.
* if success return 0, else are other values.
*/
int ExceptionInTransaction();
/*
* release the DBRES is the application's responsibility
*/
DBRES ExecuteQuery(string sql);
void ExecuteUpdate(string sql);
static void ReleaseResultSet(DBRES& res);
private:
private:
void* m_pConn;
string m_strConnectionInfo;
int m_iTransactionFlag;
int m_iErrCode;
};
#endif /* EH_DB_H_ */
#endif
This diff is collapsed.
......@@ -61,7 +61,7 @@ private:
string password;
string willTopic;
string heartbeat_Topic;
string topic1 ,topic2; //订阅的主题
string topic1 ,topic2,topic3,topic4,topic5,topic6,topic7; //订阅的主题
long reconTimerId;
EH_SDKCallbackHandler* callbackHandler;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -16,10 +16,10 @@
using namespace std;
//第1期接入设备 //临时定义 2020.10.14
#define ZeroFire1ChanChopinSwitch_PID "400100" //肖邦-一路灯控
#define ZeroFire2ChanChopinSwitch_PID "400200" //肖邦-二路灯控
#define ZeroFire3ChanChopinSwitch_PID "400300" //肖邦-三路灯控
//第1期接入设备 //产品ID 2021.3.35
#define ZeroFire1ChanChopinSwitch_PID "1603bcc0b8a103e91603bcc0b8a16001" //肖邦-一路灯控
#define ZeroFire2ChanChopinSwitch_PID "1603bec0b8a203e91603bec0b8a28001" //肖邦-二路灯控
#define ZeroFire3ChanChopinSwitch_PID "1603bec0b8a303e91603bec0b8a32a01" //肖邦-三路灯控
//第2期接入设备 //临时定义 2020.11.18
#define Chopin1CurtainSwitch_PID "410100" //肖邦-一路窗帘
#define Chopin2CurtainSwitch_PID "410200" //肖邦-二路窗帘
......@@ -44,7 +44,7 @@ public: ////////先建立
class KKDevmapinfo {
public:
string dev_model_id;
string dev_type;
// string dev_type;
string sn;
string mac;
};
......@@ -61,7 +61,7 @@ public:
class HwSubDev {
public:
string dev_model_id; //产品ID ProdID
string dev_type; //产品类型
// string dev_type; //产品类型
string operatetype; //设备的operate_type类型
string devTypeId;
string model;
......@@ -160,15 +160,15 @@ public:
//更改设备状态信息
void handleDeviceStatusChanged(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,string>&nodeId2channelMap,
string nodeId,string opcode,EH::Json::Value arg,string pushTopic,string gw_id);
//空调内机更改设备状态信息
void handleCentralACStatusPush(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,string>&indoorunitsId2AddrMap,string pushTopic,
string nodeId,EH::Json::Value arg,string opcode);
// //空调内机更改设备状态信息
// void handleCentralACStatusPush(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,string>&indoorunitsId2AddrMap,string pushTopic,
// string nodeId,EH::Json::Value arg,string opcode);
//允许加入的设备类型
bool isValidJoinDeviceType(string kkDevOperateId,string kkDevProductId,string mac);
//获取全部设备信息
int onGetDevService(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,vector<string> >& controllerModel,string pushTopic,string gw_id);
int onGetDevService(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,vector<string> >& controllerModel,string pushTopic);
//控制设备
int onSetDevService(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,string sn,string channel,string svcId,EH::Json::Value cmd);
int onSetDevService(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,string sn,EH::Json::Value cmd);
//建立通道设备模型
kk_handleDeviceInfo::KKChannelDev* buildChannelDevice(string operateId,string nodeId,string channel,EH::Json::Value status,string devroomid,string devname);
......
/*
* EH_DB.cpp
* Copyright by AirDream Co., Ltd. 2010-2011 All right reserved
*
* Description:
* Created on:2011-12-22
* Modified on:2011-12-22
*
*/
#ifndef NOT_X86
#include "EH_DB.h"
#include "EH_DEBUG.h"
EH_DB::EH_DB(string username, string passwd,
string addr, string port,string dbname) {
string conn = "";
conn.append("dbname=");
conn.append(dbname);
conn.append(" ");
conn.append("host=");
conn.append(addr);
conn.append(" ");
conn.append("port=");
conn.append(port);
conn.append(" ");
conn.append("user=");
conn.append(username);
conn.append(" ");
conn.append("password=");
conn.append(passwd);
m_strConnectionInfo = conn;
m_pConn = NULL;
m_pAction = NULL;
}
/*
*If already have a connection,don't get a
*new connection.
*/
void EH_DB::OpenConnection() {
m_Lock.acquire();
if (m_pConn == NULL) {
m_pConn = new connection(m_strConnectionInfo);
}
m_Lock.release();
}
void EH_DB::ResetConnection() {
m_Lock.acquire();
CloseConnection();
OpenConnection();
m_Lock.release();
}
void EH_DB::CloseConnection() {
m_Lock.acquire();
if (m_pConn) {
m_pConn->disconnect();
delete m_pConn;
m_pConn = NULL;
}
m_Lock.release();
}
void EH_DB::StartTransaction() {
m_Lock.acquire();
if (m_pAction) {
delete m_pAction;
m_pAction = NULL;
}
m_pAction = new transaction<>(*m_pConn, "EH_DB");
}
void EH_DB::CommitTransaction() {
if (m_pAction) {
m_pAction->commit();
delete m_pAction;
m_pAction = NULL;
m_Lock.release();
}
}
void EH_DB::AbortTransaction() {
if (m_pAction) {
m_pAction->abort();
delete m_pAction;
m_pAction = NULL;
m_Lock.release();
}
}
/*must be called when exception occur when in executing a transaction.
usage:
try {
StartTransaction();
ExecuteQuery
ExecuteUpdate
.....
CommitTransaction();
} catch (...) {
ExceptionInTransaction();//NOTE!!
....//custom process code
}
*/
void EH_DB::ExceptionInTransaction() {
if (m_pAction) {
delete m_pAction;
m_pAction = NULL;
}
m_Lock.release();
}
DBRES EH_DB::ExecuteQuery(string sql) {
if (m_pConn == NULL) {
throw runtime_error("EXCEPTION:connection instance is NULL");
}
if (m_pAction == NULL) {
throw runtime_error("EXCEPTION:transaction instance is NULL");
}
result R = m_pAction->exec(sql);
DBRES result = new DBRESVEC();
DBROW row = NULL;
for (uint i = 0; i < R.size(); i++) {
row = new DBROWMAP();
for (uint j = 0; j < R.columns(); j++) {
string colName = R.column_name(j);
string vlaue(R[i][colName].c_str());
row->insert(DBROWMAP::value_type(colName, vlaue));
}
result->push_back(DBRESVEC::value_type(row));
row = NULL;
}
return result;
}
int EH_DB::ExecuteUpdate(string sql) {
if (m_pConn == NULL) {
throw runtime_error("EXCEPTION:connection instance is NULL");
}
if (m_pAction == NULL) {
throw runtime_error("EXCEPTION:transaction instance is NULL");
}
result ret = m_pAction->exec(sql);
return ret.affected_rows();
}
void EH_DB::ReleaseResultSet(DBRES& res) {
if (!res) {
return;
}
DBRESVEC::const_iterator it = res->begin();
while (it != res->end()) {
DBROW row = *it;
if (row) {
delete row;
row = NULL;
}
++it;
}
delete res;
res = NULL;
}
EH_DB::~EH_DB() {
CloseConnection();
}
#endif
This diff is collapsed.
......@@ -187,7 +187,7 @@ int KK_MQTTSDK::init(string brokerAddr,string clientId,string username,string pa
MQTTAsync_setMessageArrivedCallback(S_client,NULL,onMessageArrived);
//此函数用于为特定客户端的传递完成事件设置回调函数
MQTTAsync_setDeliveryCompleteCallback(S_client,NULL,onDeliveryComplete);
//为客户端设置MQTTAsync_connected()回调函数
// 为客户端设置MQTTAsync_connected()回调函数
MQTTAsync_setConnected(S_client,NULL,onConnectBuild);
//为客户端设置MQTTAsync_disconnected()回调函数
MQTTAsync_setDisconnected(S_client,NULL,onDisConnected);
......@@ -213,28 +213,43 @@ int KK_MQTTSDK::subTopic(string topic,int qos,int waitTimeout){
// Init list of topics to subscribe
char** topicsPath = (char**)calloc(2, sizeof(char*));
int* topicsQoS = (int*)calloc(2, sizeof(int));
topic1 = topic+"/publishstate";
char** topicsPath = (char**)calloc(7, sizeof(char*));
int* topicsQoS = (int*)calloc(7, sizeof(int));
topic1 = topic+"/device/delete"; //删除子设备
topicsPath[0] = const_cast<char*>(topic1.c_str());
topicsQoS[0] = 0;
topic2 = topic+"/commands";
topic2 = topic+"/device/set"; //6. 改变子设备状态
topicsPath[1] = const_cast<char*>(topic2.c_str());
topicsQoS[1] = 0;
topic3 = topic+"/devices_public"; //13. 获取设备列表信息
topicsPath[2] = const_cast<char*>(topic3.c_str());
topicsQoS[2] = 0;
topic4 = topic+"/cg_custom_msg"; //16. XCG发送自定义数据到PTP
topicsPath[3] = const_cast<char*>(topic4.c_str());
topicsQoS[3] = 0;
topic5 = topic+"/firmware/check/result"; //18. 查询最新的升级任务结果
topicsPath[4] = const_cast<char*>(topic5.c_str());
topicsQoS[4] = 0;
topic6 = topic+"/device/search"; //2. 搜索子设备
topicsPath[5] = const_cast<char*>(topic6.c_str());
topicsQoS[5] = 0;
topic7 = topic+"/device/stopsearch"; //20. 停止搜索子设备
topicsPath[6] = const_cast<char*>(topic7.c_str());
topicsQoS[6] = 0;
// Create subcribe parameters
MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
int rc ;
opts.onSuccess = onOptSuccess;
opts.onFailure = onOptFail;
opts.context = (void*)OPT_SUB;
for(int i = 0; i < 2; i++)
for(int i = 0; i < 7 ; i++)
{
LOGI("test:%s %d\n",topicsPath[i], topicsQoS[i]);
LOGI("topicsPath:%s topicsQoS: %d\n",topicsPath[i], topicsQoS[i]);
}
// Subscribe and disconnect if error
if ((rc = MQTTAsync_subscribeMany(S_client,2,topicsPath,topicsQoS, &opts)) != MQTTASYNC_SUCCESS){//订阅多个主题
if ((rc = MQTTAsync_subscribeMany(S_client,7,topicsPath,topicsQoS, &opts)) != MQTTASYNC_SUCCESS){//订阅多个主题
// if ((rc = MQTTAsync_subscribe(S_client,topic.c_str(), qos, &opts)) != MQTTASYNC_SUCCESS){//订阅单个主题
LOGW("Failed to start subscribe Many, return code:%d.\n", rc);
return -1;
......@@ -392,6 +407,8 @@ void* KK_MQTTSDK::run0(void* opt) {
KK_MQTTSDK* mqttheartbeat_pthread = (KK_MQTTSDK*) opt; //这个的含义是什么?
return mqttheartbeat_pthread->run(opt);
}
//MQTT心跳
void* KK_MQTTSDK::run(void* opt){
while (true) {
EH::Json::FastWriter writer;
......
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