Commit 3e8e06e3 authored by 杨熙's avatar 杨熙

OTA升級部分功能實現

parent 5e4b9687
/*
* KK_OTA.cpp
*
* Created on: Dec 27, 2018
* Author: sds
*/
#include "KK_OTA.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "LSC_Logger.h"
using namespace std;
KK_OTA* KK_OTA::ms_pInstance = NULL;
KK_OTA* KK_OTA::GetInstance() {
if (ms_pInstance == NULL) {
ms_pInstance = new KK_OTA();
}
return ms_pInstance;
}
KK_OTA::KK_OTA() {
taskInRunning = false;
}
bool KK_OTA::init(string url){
if (!taskInRunning) {
taskInRunning = true;
target_version_url = url;
// int ret = EH_ActiveObjectCallManager::GetInstance()->getScheduler().enqueue(new EH_KKEnhanceUpgraderMethodReq(*this,url));
// if (ret == -1) {
// EH_WARNING("kk enhance upgrader enqueue req failed.\n");
// SendUpgradeReqResp(false);
// taskInRunning = false;
// }
} else {
LOGE("konkeyunzhiyi OTA upgrader task in running.ignore current req.\n");
}
pthread_t tid;
pthread_create(&tid, NULL, run0, this);
return true;
}
void* KK_OTA::run0(void* opt) {
KK_OTA* client = (KK_OTA*) opt;
client->run(opt);
return NULL ;
}
int KK_OTA::run(void* opt){
LOGD("konkeyunzhiyi OTA in...\n");
string Software_url = "wget "+ target_version_url + "-O /home/hj/konkeyunzhiyi/konkeyunzhiyi.bin";
int down_int = system(Software_url.c_str());
LOGD("下载完成:%d \n",down_int);
system("chmod 755 /home/hj/konkeyunzhiyi/*");
system("rm -rf /tmp/konkeyunzhiyi");
system("tar xzvf /home/hj/konkeyunzhiyi/konkeyunzhiyi.bin -C /tmp/");
pid_t pid;
if ((pid = fork()) < 0){
return -1; /* errno set by fork() */
}else if (pid == 0) { /* child */
int fd =0;
for (; fd < sysconf(_SC_OPEN_MAX); fd++){
if (fd!= STDIN_FILENO && fd!= STDOUT_FILENO && fd!= STDERR_FILENO){
close(fd);
}
}
LOGD("OTA开始替换适配程序\n");
system("cd /tmp/konkeyunzhiyi/;sh update.sh");
system("rm -rf /tmp/konkeyunzhiyi");
LOGD("OTA适配程序开始重启\n");
system("killall konkeyunzhiyi");
exit(0);
}
LOGD("适配程序打印konkeyunzhiyi OTA fork child:%d.\n",pid);
LOGD("适配程序打印konkeyunzhiyi OTA out...\n");
return 1;
}
/*
* KK_OTA.h
*
* Created on: Dec 27, 2018
* Author: sds
*/
#ifndef KK_OTA_H_
#define KK_OTA_H_
#include <string>
using namespace std;
class KK_OTA{
public:
static KK_OTA* GetInstance();
static void* run0(void* opt);
bool init(string url);
private:
int run(void* opt);
bool taskInRunning;
string target_version_url;
private:
KK_OTA();
private:
static KK_OTA* ms_pInstance;
};
#endif /* KK_OTA_H_ */
......@@ -26,6 +26,8 @@
#include "EH_ToolKit.h"
#include "EH_Exception.h"
// #include "KK_CcuConfig.h"
#include "KK_OTA.h"
#include "kk_PTPO.h"
#define CCU_REQ_TIMEOUT 3
......@@ -151,6 +153,8 @@ int MQ_CCU_Adapter::open() {
//连接Roma平台,绑定就进行启动
oninitmqttsdk();
//升级检测
kk_PTPO::GetInstance()->init(gw_id);
return 0;
}
......@@ -267,50 +271,32 @@ void MQ_CCU_Adapter::onCloudMsgRecv(string payload,string topicName){
Split(topicName,"/",chanMac);
string Sub_Topic = chanMac[3];
if(Sub_Topic == "devices_public"){ //13. 获取设备列表信息
if(Sub_Topic == "devices_public"){ //功能Topic 13. 获取设备列表信息
kk_handleDeviceInfo::GetInstance()->onGetDevService(hwSubDevs,controllerModel,pushTopic);
}else if(Sub_Topic == "device"){ //子设备
if(chanMac[4] == "delete"){ //3. 删除子设备
if(chanMac[4] == "delete"){ //功能Topic 3. 删除子设备
string sn = jsonObject["mac"].asString();
onDeviceRequestDelete(sn);
}else if(chanMac[4] == "search"){ //2. 搜索子设备
}else if(chanMac[4] == "search"){ //功能Topic 2. 搜索子设备
on_Query_GateWay_Infomation();
onDeviceRequestJoin(true);
}else if(chanMac[4] == "stopsearch"){ //20. 停止搜索子设备
}else if(chanMac[4] == "stopsearch"){ //功能Topic 20. 停止搜索子设备
onDeviceRequestJoin(false);
}else if(chanMac[4] == "set"){ //6. 改变子设备状态
}else if(chanMac[4] == "set"){ //功能Topic 6. 改变子设备状态
string sn = jsonObject["mac"].asString();
EH::Json::Value cmd = jsonObject["datapoints"];
kk_handleDeviceInfo::GetInstance()->onSetDevService(hwSubDevs,sn,cmd); //下发控制命令
}
}else if(Sub_Topic == "cg_custom_msg"){ //16. XCG发送自定义数据到PTP
}else if(Sub_Topic == "firmware"){ //18. 查询最新的升级任务结果 "/firmware/check/result";
}else if(Sub_Topic == "cg_custom_msg"){ //功能Topic 16. XCG发送自定义数据到PTP
}else if(Sub_Topic == "firmware"){ //功能Topic 18. 查询最新的升级任务结果 "/firmware/check/result";
kk_PTPO::GetInstance()->handle_check_result(payload);
}else if(Sub_Topic == "switch"){ //运维Topic 21. 网关地址切换
}else if(Sub_Topic == "optcall"){ //运维Topic 25. 运维功能调用
kk_PTPO::GetInstance()->handle_Ptpo_optcall(payload,pushTopic);
}else if(Sub_Topic == "gwevent"){ //运维Topic 27. 网关事件通知
}else{
LOGW("recv unknown Topic:%s.\n",Sub_Topic.c_str());
}
// else if(Sub_Topic == "commands"){ //下发控制指令
// //判别控制指令
// if(jsonObject["method"] =="prepare_join_gw"){ //添加设备的界面下准备命令
// on_Query_GateWay_Infomation();
// }else if(jsonObject["method"] =="disable_join_gw"){ //关闭网关允许加网模式
// onDeviceRequestJoin(false);
// }else if(jsonObject["method"] =="unbind_gateway"){ //解绑网关-删除所有子设备
// string device_name = jsonObject["device_name"].asString();
// string client_id = jsonObject["client_id"].asString();
// string method = jsonObject["method"].asString();
// on_unbind_gateway(device_name,client_id,method);
// }else if(jsonObject["method"] =="unbind_gateway.keep"){ //解绑网关-不删除所有子设备
// string device_name = jsonObject["device_name"].asString();
// string client_id = jsonObject["client_id"].asString();
// string method = jsonObject["method"].asString();
// on_unbind_gateway(device_name,client_id,method);
// }
// }
} catch (exception &e) {
LOGW("%s.\n", e.what());
}
......@@ -749,17 +735,14 @@ void MQ_CCU_Adapter::oninitmqttsdk() {
try {
//goto跳转,谨慎使用。
// loop:
// EH::Json::Value connectStateInfo = KK_HwDevManager::GetInstance()->loadConnectState();//获取绑定信息
// if(connectStateInfo["result"] == "1"){
string heartbeat_Topic;
// clientId = connectStateInfo["client_id"].asString();
// username = connectStateInfo["device_name"].asString();
clientId = "123456";
username = "123456";
//订阅的 Topic
pushTopic = string("$xlink/ptp/")+gw_id; //ptpo运维
pushTopic = string("$xlink/ptp/")+gw_id; //ptp
subTopic = string("$xlink/ptp/")+gw_id; //ptp交互
PTPO_Topic = string("$xlink/ptpo/")+gw_id; //ptpo运维
willTopic = string("xChfVJ501599/out/")+username+"/heartbeat"; //遗嘱信息
heartbeat_Topic = string("$xlink/ptp/")+gw_id+"/ptp_keepalive"; //心跳
LOGD("pushTopic is: %s subTopic is: %s willTopic is: %s\n",pushTopic.c_str(),subTopic.c_str(),willTopic.c_str());
......@@ -767,7 +750,7 @@ void MQ_CCU_Adapter::oninitmqttsdk() {
// int ret = mqttSdk->init("172.25.240.31:1983", //临时调试环境
// clientId,"SmartMonitor","k9CCGgJZlkKhVottLvN0EVBOMc1sCC",willTopic,heartbeat_Topic,gw_id); //与云智易的XCG建立连接除了IP以外都不需要。
int ret = mqttSdk->init("127.0.0.1:23883", //正式环境
clientId,"2CEDC38940644E439649389C08329B09","}A12a#RM^r)iXy/?|sHW:z3!",willTopic,heartbeat_Topic,gw_id); //与云智易的XCG建立连接除了IP以外都不需要。
clientId,"2CEDC38940644E439649389C08329B09","}A12a#RM^r)iXy/?|sHW:z3!",willTopic,heartbeat_Topic,PTPO_Topic,gw_id); //与云智易的XCG建立连接除了IP以外都不需要。
mqttOnline = false;
if(ret == 0){
mqttSdk->con(1,3);
......@@ -775,12 +758,9 @@ void MQ_CCU_Adapter::oninitmqttsdk() {
LOGE("init mqtt sdk failed.\n");
return;
}
// }else{
// LOGI("与APP未绑定 Not bound to app\n");
// sleep(1);
// goto loop;
// }
}catch (exception &e) {
LOGW("%s.\n", e.what());
}
......@@ -815,110 +795,6 @@ void MQ_CCU_Adapter::onCloudDisConnect(){
LOGW("onCloudDisConnect,reconnect in seconds.\n")
}
//解绑网关
int MQ_CCU_Adapter::on_unbind_gateway(string device_name,string client_id,string method){
LOGD("on_unbind_gateway: device_name:%s, client_id:%s\n",device_name.c_str(),client_id.c_str());
EH::Json::Value connectStateInfo = KK_HwDevManager::GetInstance()->loadConnectState();//获取绑定信息
// 不对解绑信息进行校验,先默认解绑信息正确
try{
if(connectStateInfo["client_id"] == clientId && connectStateInfo["device_name"] == username){
//关闭UDP线程
//关闭TCP服务器
//去除缓存文件里的信息
EH::Json::Value newconnectInfo;
newconnectInfo["result"] = "0";
newconnectInfo["client_id"] = "";
newconnectInfo["device_name"] = "";
int saveok = KK_HwDevManager::GetInstance()->saveConnectState(newconnectInfo);
LOGD(" 去除缓存文件里的信息 :%d.\n",saveok);
//解绑网关推送
string respTopic;
respTopic = pushTopic+string("/gwstate");//解绑网关
EH::Json::Value payload;
payload["client_id"] = clientId; //请求发起者
payload["device_name"] = username;
payload["action"] = method;
int SendOk = sendtoRoma(payload,respTopic); //推送新设备到Roma
LOGD(" 解绑网关 unbind_gateway SendOk :%d.\n",SendOk);
//删除主机内所有设备
if(method == "unbind_gateway"){
// int Del_Devs = deleteCCuDevices();
// LOGD("删除主机内所有设备 :%d.\n",Del_Devs);
}
if(SendOk == 0){
//程序重启
LOGD("reboot Software now.\n");
sleep(5);
system("sync;sync;sync;sync;");
system("killall Konkexinghai");
exit(0);
}else{
LOGW("发送退网信息失败 :%d.\n",SendOk);
}
}else{
}
} catch (exception &e) {
LOGW("%s.\n", e.what());
}
return -1;
}
// //删除所有设备
// int MQ_CCU_Adapter::deleteCCuDevices(){
// LOGD("删除所有设备\n");
// try{
// map<string,kk_handleDeviceInfo::HwSubDev*>::iterator it = hwSubDevs.begin();
// for (; it != hwSubDevs.end(); it++) {
// string DevDodeId;
// string devMac = it->second->mac;
// string devProdId = it->second->dev_model_id;
// // LOGD("临时注释删除所有所有设备mac %s\n",arg.c_str());
// unsigned long nowReqTime = getSystemTimeInMs();
// if( (nowReqTime - lastCcuReqTime) > 100){
// if (devProdId == DAIKINCentralACgw_PID) {
// // string gwNodeId = KK_CcuConfig::GetInstance()->getCentralAcGwNodeId(it->second->mac);
// // client->sendRequest(gwNodeId, "DEL_CENTRAL_AC_GW", "*", "HJ_CentralAC");
// map<string,string>::iterator gwIt = NodeId2gwId.find(it->second->channelDevs["1"]->nodeId); //NodeId2gwId gwId2NodeId
// if(gwIt == NodeId2gwId.end()){
// LOGW("centralACnodeId:%s not in gwId2NodeId.\n",it->second->channelDevs["1"]->nodeId.c_str());
// } else {
// DevDodeId = gwIt->second;
// }
// client->sendRequest(DevDodeId, "DEL_CENTRAL_AC_GW", "*", "HJ_CentralAC");
// } else {
// string arg = "{\"mac\":\""+devMac+"\"}";
// client->sendRequest("*", "DEL_DEVICE", arg, "HJ_Server");
// }
// lastCcuReqTime = nowReqTime;
// }else{
// LOGI("delete Devicessend req to ccu too fast,wait 100ms.\n");
// usleep(200*1000);
// if (devProdId == DAIKINCentralACgw_PID) {
// // string gwNodeId = KK_CcuConfig::GetInstance()->getCentralAcGwNodeId(it->second->mac);
// // client->sendRequest(gwNodeId, "DEL_CENTRAL_AC_GW", "*", "HJ_CentralAC");
// map<string,string>::iterator gwIt = NodeId2gwId.find(it->second->channelDevs["1"]->nodeId); //NodeId2gwId gwId2NodeId
// if(gwIt == NodeId2gwId.end()){
// LOGW("centralACnodeId:%s not in gwId2NodeId.\n",it->second->channelDevs["1"]->nodeId.c_str());
// } else {
// DevDodeId = gwIt->second;
// }
// client->sendRequest(DevDodeId, "DEL_CENTRAL_AC_GW", "*", "HJ_CentralAC");
// } else {
// string arg = "{\"mac\":\""+devMac+"\"}";
// client->sendRequest("*", "DEL_DEVICE", arg, "HJ_Server");
// }
// lastCcuReqTime = getSystemTimeInMs();
// }
// }
// } catch (exception &e) {
// LOGW("%s.\n", e.what());
// }
// return 0;
// }
//删除请求
int MQ_CCU_Adapter::onDeviceRequestDelete(string devSn){
......
......@@ -16,16 +16,14 @@
#include "json/value.h"
#include "json/reader.h"
// #include "KK_CcuConfig.h"
#include "EH_Client.h"
#include "KK_MqttSdk.h"
// #include "kk_connect.h"
#include "lib/EH_SDKDef.h"
#include "kk_handleDeviceInfo.h"
#include "KK_HwDevManager.h"
#define CENTRALAC_INDOORUNIT_NUM_MAX 64
#define MQ_VERSION "1.0.5.3"
#define MQ_VERSION 5 //整数(云智易平台有对应关系)
using namespace std;
......@@ -78,7 +76,7 @@ private:
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 handleACindoorDevNolinePush(string mac);
//处理已加入房间的设备报文
......@@ -95,13 +93,9 @@ private:
int onDeviceRequestJoin(bool enableJoinSubdev);
//删除子设备
int onDeviceRequestDelete(string devSn);
//删除所有设备
// int deleteCCuDevices();
//删除网关时,也删除其下的内机。
//删除空调网关时,也删除其下的内机。
int onACindoorDelete(string devMac);
//解绑网关
int on_unbind_gateway(string device_name,string client_id,string method);
//获取网关的nodeID
void handlegwNodeId(EH::Json::Value arg);
//Zigbee 设备入网推送的信息
......@@ -138,6 +132,7 @@ private:
string pushTopic ;
string subTopic;
string willTopic;
string PTPO_Topic; //ptpo运维
bool KKdiscover;
bool ccuSyncOK;
......
......@@ -20,7 +20,7 @@ int ACE_TMAIN(int argc, ACE_TCHAR* argv[]) { //主函数
if(argc == 2) {
string flag = argv[1];
if (flag == "-v") {
cout<<"konkeyunzhiyi:"<< MQ_VERSION << endl;
// cout<<"konkeyunzhiyi:"<< MQ_VERSION << endl;
exit(0);
}
}
......@@ -47,7 +47,7 @@ int ACE_TMAIN(int argc, ACE_TCHAR* argv[]) { //主函数
LOGE("The same process is running.current process will abort.\n");
return -1;
} else {
LOGI("konke yunzhiyi Starting...Version:%s \n",MQ_VERSION);
LOGI("konke yunzhiyi Starting...Version:%d \n",MQ_VERSION);
LOGI("konke yunzhiyi Starting...Version 编译时间:%s %s \n",__DATE__,__TIME__);
LOGI("konkeyunzhiyi acquired.\n");
}
......
......@@ -29,7 +29,7 @@ public:
public:
static KK_MQTTSDK* GetInstance();
int init(string brokerAddr,string clientId,string username,string password,string willTopic,string heartbeat_Topic,string gw_id);
int init(string brokerAddr,string clientId,string username,string password,string willTopic,string heartbeat_Topic,string PTPO_Topic,string gw_id);
int subTopic(string topic,int qos = 0,int waitTimeout = 0);
int unsubTopic(string topic,int waitTimeout = 0);
......@@ -60,8 +60,9 @@ private:
string username;
string password;
string willTopic;
string PTPO_Topic; //ptpo运维
string heartbeat_Topic;
string topic1 ,topic2,topic3,topic4,topic5,topic6,topic7; //订阅的主题
string topic1 ,topic2,topic3,topic4,topic5,topic6,topic7,topic8,topic9,topic10; //订阅的主题
long reconTimerId;
EH_SDKCallbackHandler* callbackHandler;
......
/*
* kk_PTPO.cpp
*
* Created on: Dec 27, 2018
* Author: sds
*/
#include "kk_PTPO.h"
using namespace std;
kk_PTPO* kk_PTPO::ms_pInstance = NULL;
kk_PTPO* kk_PTPO::GetInstance() {
if (ms_pInstance == NULL) {
ms_pInstance = new kk_PTPO();
}
return ms_pInstance;
}
kk_PTPO::kk_PTPO() {
}
bool kk_PTPO::init(string gw_id){
this->gw_id= gw_id;
pthread_t tid;
pthread_create(&tid, NULL, run0, this);
return true;
}
void* kk_PTPO::run0(void* opt) {
kk_PTPO* client = (kk_PTPO*) opt;
client->run(opt);
return NULL ;
}
int kk_PTPO::run(void* opt){
LOGD("konkeyunzhiyi OTA 升级检测\n");
while (true) {
time_t t = time(0); \
struct tm ptm; \
memset(&ptm, 0, sizeof(ptm)); \
localtime_r(&t, &ptm);
LOGD("当前时间小时点:%d \n",ptm.tm_hour);
if(ptm.tm_hour == 2){ //是否是两点 //
string respTopic = string("$xlink/ptp/")+gw_id+string("/firmware/check");
EH::Json::Value Panel_2;
Panel_2["msg_id"] = 15;
Panel_2["mac"] = gw_id;
Panel_2["product_id"] = "1603bcc0b2ca03e91603bcc0b2cab201";
Panel_2["type"] = 1 ; // type 为 wifi,mcu,子设备三个类型(1,2,3)
Panel_2["current_version"] = MQ_VERSION;
Panel_2["identify"] = 120; //识别码
MQ_CCU_Adapter::GetInstance()->sendtoRoma(Panel_2,respTopic); //17. 查询最新的升级任务
}
sleep(3602); //一个小时多2秒检测一次,
}
return 1;
}
//处理运维Topic 25. 运维功能调用
int kk_PTPO::handle_Ptpo_optcall(string payload,string Topic){
try{
LOGI("payload is: %s \n",payload.c_str());
string respTopic = Topic+"/firmware/check";
EH::Json::Value jsonObject;
EH::Json::Reader reader;
if (!reader.parse(payload, jsonObject) || !jsonObject.isObject()) {
LOGW("Message format is wrong.primary msg is: %s\n",payload.c_str());
return -1;
}
if(jsonObject["callcode"].asInt() == 1){ //1 执行升级
LOGI("payload is:111111111111111111111111111111 \n");
EH::Json::Value Panel_2;
Panel_2["msg_id"] = jsonObject["callcode"].asInt()+ 1;
Panel_2["mac"] = jsonObject["mac"];
Panel_2["product_id"] = jsonObject["product_id"];
Panel_2["type"] = 1 ; // type 为 wifi,mcu,子设备三个类型(1,2,3)
Panel_2["current_version"] = MQ_VERSION;
Panel_2["identify"] = 120; //待更改
MQ_CCU_Adapter::GetInstance()->sendtoRoma(Panel_2,respTopic); //17. 查询最新的升级任务
}else if(jsonObject["callcode"].asInt() == 2){ //2 :更新升级参数,其中param1是pkey,param2是deviceid和当前固件版本
LOGI("payload is:22222222222222222222222222222 \n");
}else{
// LOGW("recv unknown Topic:%s.\n",Sub_Topic.c_str());
}
} catch (exception &e) {
LOGW("%s.\n", e.what());
}
return 0;
}
//判定处理是否进行升级
int kk_PTPO::handle_check_result(string payload){
try{
LOGI("payload is: %s \n",payload.c_str());
EH::Json::Value jsonObject;
EH::Json::Reader reader;
if (!reader.parse(payload, jsonObject) || !jsonObject.isObject()) {
LOGW("Message format is wrong.primary msg is: %s\n",payload.c_str());
return -1;
}
if(jsonObject["from_version"].asInt() != jsonObject["target_version"].asInt()
&& jsonObject["from_version_md5"].asString() != jsonObject["target_version_md5"].asString() ){ //版本与MD5都不一样才可以进行升级否则就不升级
LOGI("payload is:可以进行升级 \n");
KK_OTA::GetInstance()->init(jsonObject["target_version_url"].asString());
}else{
LOGW("信息不对,不进行升级.\n");
}
} catch (exception &e) {
LOGW("%s.\n", e.what());
}
return 0;
}
\ No newline at end of file
/*
* kk_PTPO.h
*
* Created on: Dec 27, 2018
* Author: sds
*/
#ifndef kk_PTPO_H_
#define kk_PTPO_H_
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <memory.h>
#include "json/writer.h"
#include "json/reader.h"
#include "json/value.h"
#include "KK_OTA.h"
#include "LSC_Logger.h"
#include "MQ_CCU_Adapter.h"
using namespace std;
//运维Topic的相关处理
class kk_PTPO{
public:
static kk_PTPO* GetInstance();
//处理运维Topic 25. 运维功能调用
int handle_Ptpo_optcall(string payload,string Topic);
//判定处理是否进行升级
int handle_check_result(string payload);
//不断检测升级
static void* run0(void* opt);
bool init(string gw_id);
int run(void* opt);
string gw_id;
private:
kk_PTPO();
private:
static kk_PTPO* ms_pInstance;
};
#endif /* kk_PTPO_H_ */
......@@ -21,23 +21,23 @@ using namespace std;
#define ZeroFire2ChanChopinSwitch_PID "1603bec0b8a203e91603bec0b8a28001" //肖邦-二路灯控
#define ZeroFire3ChanChopinSwitch_PID "1603bec0b8a303e91603bec0b8a32a01" //肖邦-三路灯控
//第2期接入设备 //临时定义 2020.11.18
#define Chopin1CurtainSwitch_PID "410100" //肖邦-一路窗帘
#define Chopin2CurtainSwitch_PID "410200" //肖邦-二路窗帘
#define ZeroFire2ChanModularSwitch_PID "400201" //两路智能开关模块Z3S(KONKE)
#define Chopin1ChanScenePanel_PID "420100" //肖邦-零火一路情景面板
#define WaterSensor_PID "440500" //邦德-水浸传感器
#define BodyMotionSensor_PID "440200" //KIT-人体传感器
#define DoorContact_PID "440100" //邦德-门磁传感器
#define SOSButton_PID "440400" //邦德-sos紧急呼叫
#define SoundLightAlarm_PID "440300" //邦德-声光报警器
#define DimmerLightPanel_PID "430100" //肖邦-调光面板
#define WaterHeating_PID "450300" //肖邦-水地暖
#define ElectricHeating_PID "450301" //肖邦-电地暖
#define FanCoilPanel_PID "450100" //肖邦-风机盘管面板
#define AirConditioner_PID "450101" //肖邦-中央空调线控器(大金)
#define ChopinFreshAir_PID "450200" //肖邦-新风控制面板
#define DAIKINCentralACgw_PID "450400" //中央空调网关
#define DAIKINCentralACindoor_PID "450401" //中央空调内机(等待调整)
// #define Chopin1CurtainSwitch_PID "410100" //肖邦-一路窗帘
// #define Chopin2CurtainSwitch_PID "410200" //肖邦-二路窗帘
// #define ZeroFire2ChanModularSwitch_PID "400201" //两路智能开关模块Z3S(KONKE)
// #define Chopin1ChanScenePanel_PID "420100" //肖邦-零火一路情景面板
// #define WaterSensor_PID "440500" //邦德-水浸传感器
// #define BodyMotionSensor_PID "440200" //KIT-人体传感器
// #define DoorContact_PID "440100" //邦德-门磁传感器
// #define SOSButton_PID "440400" //邦德-sos紧急呼叫
// #define SoundLightAlarm_PID "440300" //邦德-声光报警器
// #define DimmerLightPanel_PID "430100" //肖邦-调光面板
// #define WaterHeating_PID "450300" //肖邦-水地暖
// #define ElectricHeating_PID "450301" //肖邦-电地暖
// #define FanCoilPanel_PID "450100" //肖邦-风机盘管面板
// #define AirConditioner_PID "450101" //肖邦-中央空调线控器(大金)
// #define ChopinFreshAir_PID "450200" //肖邦-新风控制面板
// #define DAIKINCentralACgw_PID "450400" //中央空调网关
// #define DAIKINCentralACindoor_PID "450401" //中央空调内机(等待调整)
class kk_handleDeviceInfo{
public: ////////先建立
......
......@@ -149,7 +149,7 @@ void KK_MQTTSDK::recon(int delayInSec){
}
}
int KK_MQTTSDK::init(string brokerAddr,string clientId,string username,string password,string willTopic,string heartbeat_Topic,string gw_id) {
int KK_MQTTSDK::init(string brokerAddr,string clientId,string username,string password,string willTopic,string heartbeat_Topic,string PTPO_Topic,string gw_id) {
LOGD("MQTT 初始化.\n");
if(this->callbackHandler == NULL){
LOGE("callbackHandler not set.\n");
......@@ -160,6 +160,7 @@ int KK_MQTTSDK::init(string brokerAddr,string clientId,string username,string pa
this->username = username;
this->password = password;
this->willTopic = willTopic;
this->PTPO_Topic = PTPO_Topic;
this->heartbeat_Topic = heartbeat_Topic;
this->gw_id = gw_id;
......@@ -213,8 +214,9 @@ int KK_MQTTSDK::subTopic(string topic,int qos,int waitTimeout){
// Init list of topics to subscribe
char** topicsPath = (char**)calloc(7, sizeof(char*));
int* topicsQoS = (int*)calloc(7, sizeof(int));
char** topicsPath = (char**)calloc(10, sizeof(char*));
int* topicsQoS = (int*)calloc(10, sizeof(int));
//ptp应用接口订阅的Topic
topic1 = topic+"/device/delete"; //删除子设备
topicsPath[0] = const_cast<char*>(topic1.c_str());
topicsQoS[0] = 0;
......@@ -236,20 +238,30 @@ int KK_MQTTSDK::subTopic(string topic,int qos,int waitTimeout){
topic7 = topic+"/device/stopsearch"; //20. 停止搜索子设备
topicsPath[6] = const_cast<char*>(topic7.c_str());
topicsQoS[6] = 0;
//ptpo运维订阅的Topic
topic8 = PTPO_Topic+"/switch"; //21. 网关地址切换
topicsPath[7] = const_cast<char*>(topic8.c_str());
topicsQoS[7] = 0;
topic9 = PTPO_Topic+"/optcall"; //25. 运维功能调用
topicsPath[8] = const_cast<char*>(topic9.c_str());
topicsQoS[8] = 0;
topic10 = PTPO_Topic+"/gwevent"; //27. 网关事件通知
topicsPath[9] = const_cast<char*>(topic10.c_str());
topicsQoS[9] = 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 < 7 ; i++)
for(int i = 0; i < 10 ; i++)
{
LOGI("topicsPath:%s topicsQoS: %d\n",topicsPath[i], topicsQoS[i]);
}
// Subscribe and disconnect if error
if ((rc = MQTTAsync_subscribeMany(S_client,7,topicsPath,topicsQoS, &opts)) != MQTTASYNC_SUCCESS){//订阅多个主题
if ((rc = MQTTAsync_subscribeMany(S_client,10,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;
......@@ -410,16 +422,24 @@ void* KK_MQTTSDK::run0(void* opt) {
//MQTT心跳
void* KK_MQTTSDK::run(void* opt){
while (true) {
EH::Json::FastWriter writer;
EH::Json::Value Payload;
Payload["interval"] = 30;
string sendPayload = writer.write(Payload);
EH::Json::FastWriter writer;
EH::Json::Value Payload;
string ptpo_heartbeat_Topic = PTPO_Topic+"/ptpo_keepalive";
Payload["interval"] = 30;
string sendPayload = writer.write(Payload);
LOGD("Topic:%s Payload:%s\n",heartbeat_Topic.c_str(),sendPayload.c_str());
sendMsg(heartbeat_Topic,sendPayload,0);
LOGD("ptpo_heartbeat_Topic:%s Payload:%s\n",ptpo_heartbeat_Topic.c_str(),sendPayload.c_str());
sendMsg(ptpo_heartbeat_Topic,sendPayload,0);
while (true) {
//与Roma平台30秒心跳
sleep(30);
LOGD("Topic:%s Payload:%s\n",heartbeat_Topic.c_str(),sendPayload.c_str());
sendMsg(heartbeat_Topic,sendPayload,0);
LOGD("ptpo_heartbeat_Topic:%s Payload:%s\n",ptpo_heartbeat_Topic.c_str(),sendPayload.c_str());
sendMsg(ptpo_heartbeat_Topic,sendPayload,0);
}
//delete this;
return NULL;
......
#!/bin/bash
cd /home/hj/konkeyunzhiyi/bin/
nohup /home/hj/konkeyunzhiyi/bin/konkeyunzhiyi >> /dev/null 2>&1 &
nohup ./konkeyunzhiyi >> /dev/null 2>&1 &
#nohup ./Konkexinghai 2>&1|logger -i -t "Konkexinghai" &
......@@ -10,7 +10,8 @@ do
echo "try to start xlink-gw-core-cpp"
killall xlink-gw-core-cpp
sleep 1
sh /home/hj/konkeyunzhiyi/xlink-gw/start.sh &
cd /home/hj/konkeyunzhiyi/xlink-gw/
sh start.sh
fi
stillRunning_1=$(ps -e |grep xsepproject |grep -v "grep")
......@@ -20,7 +21,8 @@ do
echo "try to start xsepproject"
killall xsepproject
sleep 1
sh /home/hj/konkeyunzhiyi/xlink-gw/start.sh &
cd /home/hj/konkeyunzhiyi/xlink-gw/
sh start.sh
fi
sleep 10
......@@ -31,7 +33,8 @@ do
echo "try to start konkeyunzhiyi"
killall konkeyunzhiyi
sleep 1
sh /home/hj/konkeyunzhiyi/bin/start.sh &
cd /home/hj/konkeyunzhiyi/bin/
sh start.sh
fi
sleep 50
......
......@@ -4,6 +4,7 @@
#2:konkeyunzhiyi config
mkdir /home/hj/konkeyunzhiyi/
mkdir /home/hj/download/konkeyunzhiyi/
mv bin/ /home/hj/konkeyunzhiyi/
mv config/ /home/hj/konkeyunzhiyi/
mv xlink-gw/ /home/hj/konkeyunzhiyi/
......
......@@ -9,7 +9,7 @@ mv xlink-gw/xlink-gw-core-cpp /home/hj/konkeyunzhiyi/xlink-gw/
#3:重启程序
killall konkeyunzhiyi
killall xsepproject
killall xlink-gw-core-cpp
killall xsepproject
echo "update konkeyunzhiyi ok"
#!/bin/sh
nohup /home/hj/konkeyunzhiyi/xlink-gw/xlink-gw-core-cpp > /home/hj/konkeyunzhiyi/xlink-gw/1.txt 2>&1 &
nohup /home/hj/konkeyunzhiyi/xlink-gw/xsepproject -c xsep.conf > /home/hj/konkeyunzhiyi/xlink-gw/1.txt 2>&1 &
nohup ./xlink-gw-core-cpp > /home/hj/konkeyunzhiyi/xlink-gw/1.txt 2>&1 &
nohup ./xsepproject -c xsep.conf > /home/hj/konkeyunzhiyi/xlink-gw/1.txt 2>&1 &
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