/*
 * kk_handleDeviceInfo.cpp
 *
 *  Created on: 2020年11月17日
 *      Author: hj
 */
#include "kk_handleDeviceInfo.h"

#include "json/writer.h"
#include "json/reader.h"
#include "json/value.h"
#include "EH_ToolKit.h"
#include "LSC_Logger.h"
#include <stdio.h>
#include "KK_Util.h"
#include "MQ_CCU_Adapter.h"
#include "EH_Client.h"

kk_handleDeviceInfo* kk_handleDeviceInfo::ms_pInstance = NULL;

kk_handleDeviceInfo* kk_handleDeviceInfo::GetInstance() {
	if (ms_pInstance == NULL) {
		ms_pInstance = new kk_handleDeviceInfo();
	}
	return ms_pInstance;
}

kk_handleDeviceInfo::kk_handleDeviceInfo() {

}

//小K组设备，自动补充设备对应的prodID。
EH::Json::Value  kk_handleDeviceInfo::XiaoK_Zu_Wang(string kkDevProductId){
	EH::Json::Value  devProductinfo;
	try {
		if (kkDevProductId == "3022"){
			devProductinfo["dev_model_id"] = ZeroFire1ChanChopinSwitch_PID;//肖邦一路灯控
		}else if (kkDevProductId == "3023"){
			devProductinfo["dev_model_id"] = ZeroFire2ChanChopinSwitch_PID;//肖邦二路灯控
		}else if (kkDevProductId == "3024"){
			devProductinfo["dev_model_id"] = ZeroFire3ChanChopinSwitch_PID;//肖邦三路灯控
		}else if (kkDevProductId == "3026"){
			devProductinfo["dev_model_id"] = Chopin1CurtainSwitch_PID;		//肖邦一路窗帘
		}else if (kkDevProductId == "3027"){
			devProductinfo["dev_model_id"] = Chopin2CurtainSwitch_PID;		//肖邦二路窗帘
		}else if (kkDevProductId == "3069"){
			devProductinfo["dev_model_id"] = ZeroFire2ChanModularSwitch_PID;//两路智能开关模块Z3S(KONKE)
		}else if (kkDevProductId == "3025"){
			devProductinfo["dev_model_id"] = Chopin1ChanScenePanel_PID;		//肖邦零火一路情景面板
		}else if (kkDevProductId == "3055"){
			devProductinfo["dev_model_id"] = WaterSensor_PID;				//邦德水浸传感器
		}else if (kkDevProductId == "3054"){
			devProductinfo["dev_model_id"] = SOSButton_PID;					//邦德紧急按钮
		}else if (kkDevProductId == "3057"){
			devProductinfo["dev_model_id"] = SoundLightAlarm_PID;			//邦德声光报警器
		}else if (kkDevProductId == "3049"){
			devProductinfo["dev_model_id"] = BodyMotionSensor_PID;			//KIT人体传感器
		}else if (kkDevProductId == "3051"){
			devProductinfo["dev_model_id"] = DoorContact_PID;				//邦德门磁传感器
		}else if (kkDevProductId == "3029"){
			devProductinfo["dev_model_id"] = WaterHeating_PID ;				//肖邦水地暖
		}else if (kkDevProductId == "3030"){
			devProductinfo["dev_model_id"] = ElectricHeating_PID;			//肖邦电地暖
		}else if (kkDevProductId == "3032"){
			devProductinfo["dev_model_id"] = ChopinFreshAir_PID;			//肖邦新风控制面板
		}else if (kkDevProductId == "3028"){
			devProductinfo["dev_model_id"] = DimmerLightPanel_PID;			//肖邦零火线调光面板
		}else if (kkDevProductId == "3031"){
			devProductinfo["dev_model_id"] = FanCoilPanel_PID;				//肖邦风机盘管面板
		}else if (kkDevProductId == "142"){
			devProductinfo["dev_model_id"] = AirConditioner_PID;			//肖邦中央空调线控器（大金）
		}else if (kkDevProductId == "3062"){
			devProductinfo["dev_model_id"] = DAIKINCentralACgw_PID;			//中央空调网关 /中央空调内机  400401	空调内机
		}else {
			devProductinfo["dev_model_id"] = "-1";
			LOGW("unknown dev_type Productid:%s \n",kkDevProductId.c_str());
		}   //当为-1时，这个设备未对接华为。
	//	LOGD("小K的Productid:%s  对应对接兴海的Productid:%s \n",kkDevProductId.c_str(),devProductid.c_str());
	}catch (exception &e) {
		LOGW("%s.\n", e.what());
	}
	return devProductinfo;
}

bool kk_handleDeviceInfo::isValidJoinDeviceType(string kkDevOperateId,string kkDevProductId,string mac){
	LOGD("isValidJoinDeviceType kkDevOperateId:%s, kkDevProductId:%s, mac:%s    \n",kkDevOperateId.c_str(),kkDevProductId.c_str(),mac.c_str());
	try {
			if (kkDevOperateId=="3") {
				return (kkDevProductId == "3022")||(kkDevProductId == "3023")||(kkDevProductId == "3024");
			} else if (kkDevOperateId=="510") {
				return (kkDevProductId == "3069");//肖邦-一路窗帘
			} else if (kkDevOperateId=="1006") {
				return (kkDevProductId == "3026");//肖邦-二路窗帘
			} else if (kkDevOperateId=="1007") {
				return (kkDevProductId == "3027");//两路智能开关模块Z3S(KONKE)
			} else if (kkDevOperateId=="11503") {
				return (kkDevProductId == "3025");//肖邦-零火一路情景面板
			} else if (kkDevOperateId=="3004") {
				return (kkDevProductId == "3055");//邦德-水浸传感器
			} else if (kkDevOperateId=="3504") {
				return (kkDevProductId == "3054");//邦德-紧急按钮
			} else if (kkDevOperateId=="11002") {
				return (kkDevProductId == "3057");//邦德-声光报警器
			} else if (kkDevOperateId=="3007") {
				return (kkDevProductId == "3049");//KIT-人体传感器
			} else if (kkDevOperateId=="3497") {
				return (kkDevProductId == "3051");//邦德-门磁传感器
			} else if (kkDevOperateId=="12504") {
				return (kkDevProductId == "3029");//肖邦-水地暖
			} else if (kkDevOperateId=="12503") {
				return (kkDevProductId == "3030");//肖邦-电地暖
			} else if (kkDevOperateId=="14002") {
				return (kkDevProductId == "3032");//肖邦-新风控制面板
			} else if (kkDevOperateId=="507") {
				return (kkDevProductId == "3028");//肖邦-零火线调光面板
			} else if (kkDevOperateId=="15002") {
				return (kkDevProductId == "3031");//肖邦-风机盘管面板
			}else if (kkDevOperateId=="15003") {
				return (kkDevProductId == "142");//肖邦-中央空调线控器（大金）
			}else if (kkDevOperateId=="12001") {
				return (kkDevProductId == "3062");//中央空调网关 /中央空调内机不做类型判断
			}
			LOGW("invalid join device type,kkDevOperateId:%s,kkDevProductId:%s,.\n",
				kkDevOperateId.c_str(),kkDevProductId.c_str());
	}catch (exception &e) {
			LOGW("%s.\n", e.what());
	}
	return false;
}

//建立通道设备模型
kk_handleDeviceInfo::KKChannelDev* kk_handleDeviceInfo::buildChannelDevice(string operateId,string nodeId,string channel,EH::Json::Value status,string devroomid,string devname){
	 LOGD("buildChannelDevice operateId:%s\n  nodeId:%s\n  channel:%s\n  status:%s\n",operateId.c_str(),nodeId.c_str(),channel.c_str(),EH_ToolKit::JsonToString(status).c_str());
	//刚上报的status设备信息里有的是没有参数，要做异常处理
	 kk_handleDeviceInfo::KKChannelDev* chanDev = NULL;
	int error;
	try {
		if(operateId=="1"||operateId=="3"||operateId=="510"){    //灯控 /灯控模块
			HwSwitch* light = new HwSwitch();
			if(status.isNull() == true){
				light->on = (status.asString() == "ON");
			}else{
				light->on = (status.asString() == "ON");
			}
			light->devroomid = devroomid;
			light->devname = devname;
			chanDev = light;
		} else if (operateId=="1001"||operateId=="1006"||operateId=="1007") {//窗帘面板
			HwCurtain* curtain = new HwCurtain();
			string sMode = status.asString();
			if (sMode == "OPEN") {
				curtain->mode = "1";
			} else if (sMode == "CLOSE") {
				curtain->mode = "0";
			} else if (sMode == "STOP"){
				curtain->mode = "2";
			}else {
				curtain->mode = "0";
				LOGW("not support:%s，默认为关.\n", sMode.c_str());
			}
			curtain->devroomid = devroomid;
			curtain->devname = devname;
			chanDev = curtain;
		} else if (operateId=="11502"||operateId=="11503") {//  //铂金情景面板3按键 肖邦情景面板4按键
			HwScenePanel* shortcutPanel = new HwScenePanel();
			shortcutPanel->num = "switch0";
			shortcutPanel->devroomid = devroomid;
			shortcutPanel->devname = devname;
			chanDev = shortcutPanel;
		} else if (operateId == "3004"||operateId == "3007"){//邦德-水浸传感器3004 //邦德-人体传感器3007 (待确认是否合并2020.11.25)
			HwSensor* Sensor = new HwSensor();
			if(status.isNull() == true){
				Sensor->alarm = "0";
				Sensor->leftbattery = "100";
			}else{
				Sensor->alarm =  status["alarm"]["normal"].asString();
				Sensor->leftbattery = status["battery"].asString();
			}			
			Sensor->devroomid = devroomid;
			Sensor->devname = devname;
			chanDev = Sensor;
		} else if (operateId == "11002"){//邦德-声光11002
			HwSensor* Sensor = new HwSensor();
			if(status.isNull() == true){
				Sensor->alarm =  "0";
				Sensor->leftbattery = "100";
				Sensor->sound = "0";
				Sensor->power_style = "1";
			}else{
				Sensor->alarm =  status["alarm"].asString();
				Sensor->leftbattery = status["battery"].asString();
				Sensor->sound = status["sound"].asString();
				Sensor->power_style = status["power"].asString();
			}
			Sensor->devroomid = devroomid;
			Sensor->devname = devname;
			chanDev = Sensor;
		} else if (operateId == "3504"){//邦德-sos紧急呼叫3504
			HwSensor* Sensor = new HwSensor();
			if(status.isNull() == true){
				Sensor->alarm =  "0";
				Sensor->leftbattery = "100";
			}else{
				Sensor->alarm =  status["alarm"].asString();
				Sensor->leftbattery = status["battery"].asString();
			}
			Sensor->devroomid = devroomid;
			Sensor->devname = devname;
			chanDev = Sensor;
		} else if (operateId == "3497") {////邦德-门磁传感器3497
			HwSensor* Sensor = new HwSensor();
			if(status.isNull() == true){
				Sensor->alarm =  "1";
			}else{
				Sensor->alarm =  status["status"].asString()=="OPEN" ? "1":"0";
			}
			Sensor->leftbattery =  "100";
			Sensor->devroomid = devroomid;
			Sensor->devname = devname;
			chanDev = Sensor;
		} else if (operateId == "507") {	//肖邦-零火线调光面板
			HwDimmerLightPanel* DimmerLightPanel = new HwDimmerLightPanel();
			if(status.isNull() == true){
				DimmerLightPanel->on = true;
				DimmerLightPanel->brightness = "100";
			}else{
				DimmerLightPanel->on = status["on"].asBool();
				DimmerLightPanel->brightness = IntToString(status["bri"].asInt());
			}
			DimmerLightPanel->devroomid = devroomid;
			DimmerLightPanel->devname = devname;
			chanDev = DimmerLightPanel;
		} else if (operateId == "12503"||operateId == "12504") {	//肖邦-水地暖 //肖邦-电地暖
			HwWaterElectricHeating* DiNuan = new HwWaterElectricHeating();
			if(status.isNull() == true){
				DiNuan->on = true;
				DiNuan->mode = "1";
				DiNuan->target = "100";
				DiNuan->current = "100";
			}else{
				DiNuan->on = status["on"].asBool();
				DiNuan->mode = status["run_model"].asString()=="AUTO"? "0":"1";
				DiNuan->target = DoubleToString(status["work_temperature"].asDouble()* 10,error);
				DiNuan->current = DoubleToString(status["current_real_temperature"].asDouble()* 10,error);
			}
			DiNuan->devroomid = devroomid;
			DiNuan->devname = devname;
			chanDev = DiNuan;
		} else if (operateId == "14002") {	//肖邦-新风控制面板
			HwChopinFreshAir* chopinFreshAir = new HwChopinFreshAir();
			if(status.isNull() == true){
				chopinFreshAir->fan = "1";
				chopinFreshAir->on = true ;
				chopinFreshAir->mode = 1;
				chopinFreshAir->current = "100";
				chopinFreshAir->downtime = 0;
				chopinFreshAir->totalTime = 4000;
				chopinFreshAir->leftTime = 4000;
			}else{
				chopinFreshAir->fan = IntToString(status["speed"].asInt());
				chopinFreshAir->on = status["on"].asBool();
				chopinFreshAir->mode = status["runModel"].asString()=="MANUAL" ? 0 : 1;
				chopinFreshAir->current = EH_ToolKit::DoubleToString(status["cur_temperature"].asDouble() * 10);
				string Stime = status["time_off"].asString();
				if(Stime!="00:00"){
					chopinFreshAir->downtime =  (StringToInt(Stime.substr(0.1), error))*6 + StringToInt(Stime.substr(3.4), error);
				}else{
					chopinFreshAir->downtime = 0;
				}
				chopinFreshAir->totalTime = status["filterScreenAlarmTime"].asInt();
				chopinFreshAir->leftTime = chopinFreshAir->totalTime - status["filterScreenWorkTime"].asInt();
				if (chopinFreshAir->leftTime < 0) {
					chopinFreshAir->leftTime = 0;
				}
			}			
			chopinFreshAir->devroomid = devroomid;
			chopinFreshAir->devname = devname;
			chanDev = chopinFreshAir;
		} else if (operateId == "15002"||operateId == "15003") {  	//肖邦-风机盘管面板 //肖邦-大金中央空调线控器（大金）
			HwConditionerPanel* FanCoilPanel = new HwConditionerPanel();
			if(status.isNull() == true){
				FanCoilPanel->on = true ;
				FanCoilPanel->fan = "0";
				FanCoilPanel->current=  "100"; //当前温度   参数注意！！！！！！
				FanCoilPanel->target = "100"; //目标温度
				FanCoilPanel->mode = "1";
				FanCoilPanel->downtime = 0;
				FanCoilPanel->enable=  true;
			}else{
				FanCoilPanel->on = status["on"].asBool();
				string sSpeed =status["fan_speed"].asString();
					if (sSpeed == "AUTO") {
						FanCoilPanel->fan = "0";
					} else if (sSpeed == "LOW") {
						FanCoilPanel->fan = "1";
					} else if (sSpeed == "MID") {
						FanCoilPanel->fan = "2";
					} else if (sSpeed == "HIGH") {
						FanCoilPanel->fan = "3";
					} else {
						LOGW("not support:%s.\n",sSpeed.c_str());
					}
				FanCoilPanel->current=  EH_ToolKit::DoubleToString(status["room_temperature"].asDouble()*10); //当前温度   参数注意！！！！！！
				FanCoilPanel->target = EH_ToolKit::DoubleToString(status["setting_temperature"].asDouble()*10); //目标温度
				string smode = status["run_model"].asString();
					if (smode == "COLD") {
						FanCoilPanel->mode = "1";
					} else if (smode == "HOT") {
						FanCoilPanel->mode = "2";
					} else if (smode == "WIND") {
						FanCoilPanel->mode = "3";
					} else if (smode == "DEHUMIDIFICATION") {
						FanCoilPanel->mode = "4";
					} else {
						LOGW("not support:%s.\n",smode.c_str());
					}
				string Stime = status["timing_shutdown"]["time"].asString();
					if(Stime!=""){
						FanCoilPanel->downtime =  (StringToInt(Stime.substr(0.1), error))*6 + StringToInt(Stime.substr(3.4), error);
						}else{
							FanCoilPanel->downtime = 0;
						}
				FanCoilPanel->enable= status["timing_shutdown"]["enable"].asBool();
			}			
			FanCoilPanel->devroomid = devroomid;
			FanCoilPanel->devname = devname;
			chanDev = FanCoilPanel;
		}  else if (operateId == "12001") { //中央空调网关
			HwCentralAcgw* centralAc = new HwCentralAcgw();
                centralAc->num = 0;
                centralAc->devroomid = devroomid;
                centralAc->devname = devname;
           chanDev = centralAc;
		} else if (operateId == "-13") { //情景模式里的内机operateId
			HwCentralAcindoor* centralAcindoor = new HwCentralAcindoor();
			if(status == ""){
				centralAcindoor->on = true ;
				centralAcindoor->current = 100;
				centralAcindoor->target = 100;
				centralAcindoor->fan = "1";
				centralAcindoor->mode = 1;
			}else{
				centralAcindoor->on = status["on"].asBool();
				centralAcindoor->current = (status["roomTemperature"].asDouble());
				centralAcindoor->target = (status["settingTemperature"].asDouble());
				
				string sSpeed = status["fanSpeed"].asString();
				if (sSpeed == "LOW") {
					centralAcindoor->fan = "1";
				} else if (sSpeed == "MID") {
					centralAcindoor->fan = "2";
				} else if (sSpeed == "HIGH") {
					centralAcindoor->fan = "3";
				} else {
					LOGW("UNKNOWN style speed");
				}

				string sModel = status["runModel"].asString();
				if (sModel == "AUTO") {
					centralAcindoor->mode = 5;
				} else if (sModel == "AIR_SUPPLY") {
					centralAcindoor->mode = 3;
				} else if (sModel == "COLD") {
					centralAcindoor->mode = 1;
				} else if (sModel == "HOT") {
					centralAcindoor->mode = 2;
				} else if (sModel == "DEHUMIDIFICATION") {
					centralAcindoor->mode = 4;
				} else {
					LOGW("UNKNOWN style model");
				}
			}
			centralAcindoor->devroomid = devroomid;
			centralAcindoor->devname = devname;
           chanDev = centralAcindoor;
		} else{
			LOGW("no device build operateId %s.\n",operateId.c_str());
		}
	}catch (exception &e) {
			LOGW("%s.\n", e.what());
	}

		if(chanDev!=NULL){
			chanDev->channel = channel;
			chanDev->nodeId = nodeId;
			chanDev->operateId = operateId;
		}else{
			LOGW("no device build.\n");
		}
	return chanDev;
}

//添加到房间里
void kk_handleDeviceInfo::addCCuDevicesToRoom(map<string,kk_handleDeviceInfo::HwSubDev*>::iterator&it,map<string,string> NodeId2gwId){
	LOGD(" addCCuDevicesToRoom 开始，自动添加到房间\n");
	int error;
	string roomid = KK_HwDevManager::GetInstance()->GetRoomId();//特定的房间
	string dev_model_id = it->second->dev_model_id;
	//map<string, KK_HwSdk::HwSubDev*>::iterator subDevIt = hwSubDevs.begin();
	try
	{
		if(dev_model_id == ZeroFire1ChanChopinSwitch_PID || dev_model_id == ZeroFire2ChanChopinSwitch_PID || dev_model_id == ZeroFire3ChanChopinSwitch_PID
				|| dev_model_id == ZeroFire2ChanModularSwitch_PID){ //灯控 /灯控模块
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwSwitch* device = (HwSwitch*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "灯控"+IntToString(StringToInt(subIt->second->channel,error));
					string DeviceIcon = "l_0";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("灯控设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == Chopin1CurtainSwitch_PID||dev_model_id == Chopin2CurtainSwitch_PID) { //肖邦一路二路窗帘面板
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwCurtain* device = (HwCurtain*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "窗帘面板"+IntToString(StringToInt(subIt->second->channel,error));
					string DeviceIcon = "m_0";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("窗帘面板设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == Chopin1ChanScenePanel_PID) { //肖邦-情景面板
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwScenePanel* device = (HwScenePanel*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "快捷按键设备";
					string DeviceIcon = "q_0";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("快捷按键设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == WaterSensor_PID) {		//邦德-水浸传感器
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwSensor* device = (HwSensor*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "水浸探测器";
					string DeviceIcon = "t_16";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("水浸探测器设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == BodyMotionSensor_PID) {		//KIT-人体传感器
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwSensor* device = (HwSensor*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "人体传感器";
					string DeviceIcon = "t_2";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("人体传感器设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == DoorContact_PID) {		//邦德-门窗传感器
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwSensor* device = (HwSensor*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "门窗传感器";
					string DeviceIcon = "t_3";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("门窗传感器设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == SOSButton_PID) {		//邦德-sos紧急呼叫
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwSensor* device = (HwSensor*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "SOS按钮";
					string DeviceIcon = "SOS";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("SOS按钮设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == SoundLightAlarm_PID) {		//邦德-声光报警器
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwSensor* device = (HwSensor*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "声光报警器";
					string DeviceIcon = "icon_edit_alarm_bangde";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("声光报警器 设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == DimmerLightPanel_PID) {		//肖邦-调光面板
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwDimmerLightPanel* device = (HwDimmerLightPanel*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "肖邦调光面板";
					string DeviceIcon = "l_0";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("肖邦调光面板设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == WaterHeating_PID||dev_model_id == ElectricHeating_PID) {	//肖邦-水地暖 肖邦-电地暖
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwWaterElectricHeating* device = (HwWaterElectricHeating*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "地暖设备";
					string DeviceIcon = "icon_xinf_s";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("地暖设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == ChopinFreshAir_PID) {	//肖邦-新风控制面板
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwChopinFreshAir* device = (HwChopinFreshAir*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "新风控制面板";
					string DeviceIcon = "icon_xinf_s";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("新风控制面板设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == FanCoilPanel_PID) {	//肖邦-风机盘管面板
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwConditionerPanel* device = (HwConditionerPanel*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "肖邦风机盘管面板";
					string DeviceIcon = "ac";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("肖邦风机盘管面板设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == AirConditioner_PID) {	//肖邦-中央空调线控器（大金）
			for (map<string,kk_handleDeviceInfo::KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
				HwConditionerPanel* device = (HwConditionerPanel*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				if(device->devroomid == "-1"){
					string name = "大金中央空调线控器";
					string DeviceIcon = "ac";
					string DevDodeId = subIt->second->nodeId;
					string opcode = "SETUP_NODE";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					LOGD("肖邦中央空调线控器nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}else{
					continue;
				}
			}
		} else if (dev_model_id == DAIKINCentralACindoor_PID) {  //四期  肖邦中央空调内机
			map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.find("1");
			HwCentralAcindoor* device = (HwCentralAcindoor*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			LOGD("空调内机devroomid:%s\n",device->devroomid.c_str());
				if(device->devroomid == "-1"){
					string DevDodeId = subIt->second->nodeId;
					string name = "中央空调内机";
					string DeviceIcon = "ac";
					string opcode = "SET_CENTRAL_AC_INDOOR_UNIT";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					subIt->second->devroomid = roomid;
					LOGD("中央空调内机设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}

		} else if (dev_model_id == DAIKINCentralACgw_PID) {  //四期  空调网关
			map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.find("1");
				HwCentralAcgw* device = (HwCentralAcgw*)it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
				LOGD("中央空调网关设备 devroomid:%s\n",device->devroomid.c_str());

				if(device->devroomid == "-1"){
					string DevDodeId;

					map<string,string>::iterator gwIt = NodeId2gwId.find(subIt->second->nodeId); //NodeId2gwId  gwId2NodeId
					if(gwIt == NodeId2gwId.end()){
						LOGW("centralACnodeId:%s not in gwId2NodeId.\n",subIt->second->nodeId.c_str());
					} else {
						DevDodeId = gwIt->second;
					}
					string name = "中央空调网关";
					string DeviceIcon = "ac"; //无效参数，补全格式
//					string DevDodeId = subIt->second->nodeId;
					string opcode = "SET_CENTRAL_AC_GW";
					MQ_CCU_Adapter::GetInstance()->SendSETUPToCcu( name,DeviceIcon,DevDodeId,roomid,opcode);
					subIt->second->devroomid = roomid;
					LOGD("中央空调网关设备nodeID:%s 自动添加到房间roomid:%s \n",device->nodeId.c_str(),roomid.c_str());
				}

		} else{
			LOGW("dev_model_id:%s not .\n",dev_model_id.c_str());
		}
	} catch (exception &e) {
		LOGW("%s.\n", e.what());
	}
}
//下发控制命令
int kk_handleDeviceInfo::onSetDevService(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,string sn,EH::Json::Value cmd){
	LOGD("onSetDevService sn:%s  cmd:%s . \n",sn.c_str(),cmd.toStyledString().c_str());
	map<string, HwSubDev*>::iterator subDevIt = hwSubDevs.find(sn);
	if(subDevIt == hwSubDevs.end()){
		LOGW("not found hw dev sn:%s in local cache.\n",sn.c_str());
		return -1;
	}
	int error;
	string jsonarg = "";
	string opcode = "";
	string nodeid = "*";
	string arg = "*";
	string dev_model_id = subDevIt->second->dev_model_id;
	// EH::Json::Value cmd_1 = cmd[0u]; //0容易出错，原因： 这里的value的参数同时包含string和int，识别不出来，改成cmd[0u]就能解决了!

	// EH::Json::Value::Members  members(cmd.getMemberNames());
	// for (EH::Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it)  {
	// 	jsonarg = *it;
	// }
	LOGD("prodId:%s . \n",dev_model_id.c_str());
	try {
		if(dev_model_id == ZeroFire1ChanChopinSwitch_PID|| dev_model_id == ZeroFire2ChanModularSwitch_PID){  //一路灯控 /灯控模块	
			KKChannelDev* chanDev = subDevIt->second->channelDevs["1"];
			bool on = true;
			on = cmd[0u]["value"].asBool() == true;
			if(chanDev!=NULL){
				opcode = "SWITCH";
				nodeid = chanDev->nodeId;
				arg = on?"ON":"OFF";
			}
			on_Send_Service(opcode,nodeid,arg,dev_model_id);
		}else if(dev_model_id == ZeroFire2ChanChopinSwitch_PID||dev_model_id == ZeroFire3ChanChopinSwitch_PID){  //多路灯控 /灯控模块
			for(int i = 0; i < cmd.size(); i++) {
				vector<string> chanMac;
				Split(cmd[i]["name"].asString(),"_",chanMac);
				string sn = Replace(chanMac[0],":","");
				string channel = chanMac[1];	
			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
			bool on = true;
			on = cmd[i]["value"].asBool() == true;
			if(chanDev!=NULL){
				opcode = "SWITCH";
				nodeid = chanDev->nodeId;
				arg = on?"ON":"OFF";
				}
				on_Send_Service(opcode,nodeid,arg,dev_model_id);
			}
		}
	// 	 else if (dev_model_id == Chopin1CurtainSwitch_PID|| dev_model_id == Chopin2CurtainSwitch_PID) { //肖邦一路二路窗帘面板
	// 		KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 		string mode;
	// 		string sMode;
	// 		mode = cmd["Operate"].asString();
	// 		if (mode == "1") {
	// 			sMode = "OPEN";
	// 		} else if (mode == "0"){
	// 			sMode = "CLOSE";
	// 		} else if (mode == "2"){
	// 			sMode = "STOP";
	// 		} else {
	// 			LOGW("not support type:%s.\n",mode.c_str());
	// 			return -1;
	// 		}
	// 		if(chanDev!=NULL){
	// 			opcode = "SWITCH";
	// 			nodeid = chanDev->nodeId;
	// 			arg = sMode;
	// 		}
	// 	} else if (dev_model_id == SoundLightAlarm_PID) { //邦德-声光报警器
	// 		KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 		string mode;
	// 		string sMode;
	// 		EH::Json::Value::Members  members(cmd.getMemberNames());
	// 		for (EH::Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it)  {
	// 			jsonarg = *it;
	// 		}
	// 		if(jsonarg == "Sound"){
	// 			if(chanDev!=NULL){
	// 				opcode = "ADJUST_VOLUME";
	// 				nodeid = chanDev->nodeId;
	// 				arg = cmd["Sound"].asString();
	// 				}
	// 		}else{}
	// 	} else if (dev_model_id == ChopinFreshAir_PID) { //肖邦-新风控制面板
	// 		string channel = "0";
	// 		if (jsonarg == "On") {
	// 			channel = "1";
	// 			bool on = cmd["On"].asString() == "1";
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FRESH_AIR_SWITCH";
	// 				nodeid = chanDev->nodeId;
	// 				arg = on?"ON":"OFF";
	// 			}
	// 		} else if (jsonarg == "Mode") {
	// 			channel = "1";
	// 			string mode = cmd["Mode"].asString();
	// 			if (mode == "0") {
	// 				arg = "MANUAL";
	// 			} else if (mode == "1") {
	// 				arg = "AUTO";
	// 			} else {
	// 				LOGW("not found svcId:%s.\n", mode.c_str());
	// 				return -1;
	// 			}
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FRESH_AIR_RUN_MODEL";
	// 				nodeid = chanDev->nodeId;
	// 			}
	// 		} else if (jsonarg == "Wind_num") {
	// 			channel = "1";
	// 			string fan = cmd["Wind_num"].asString();
	// 			if (fan == "1") {
	// 				arg = "LOW";
	// 			} else if (fan == "2") {
	// 				arg = "MID";
	// 			} else if (fan == "3") {
	// 				arg = "HIGH";
	// 			} else {
	// 				LOGW("not found svcId:%s.\n", fan.c_str());
	// 				return -1;
	// 			}
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FRESH_AIR_SPEED_SET";
	// 				nodeid = chanDev->nodeId;
	// 			}
	// 		} else if (jsonarg == "SwitchChildLock") {
	// 			channel = "1";
	// 			bool bChildLock = cmd["SwitchChildLock"].asString() == "1";
	// 			EH::Json::Value childLockArg;
	// 			if (bChildLock) {
	// 				childLockArg["model_lock"] = true;
	// 				childLockArg["child_lock"] = true;
	// 				childLockArg["time_lock"] = true;
	// 				childLockArg["switch_lock"] = true;
	// 				childLockArg["rotate_lock"] = true;
	// 			}else{
	// 				childLockArg["model_lock"] = false;
	// 				childLockArg["child_lock"] = false;
	// 				childLockArg["time_lock"] = false;
	// 				childLockArg["switch_lock"] = false;
	// 				childLockArg["rotate_lock"] = false;
	// 			}

	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FRESH_AIR_SET_LOCK_STATUS";
	// 				nodeid = chanDev->nodeId;
	// 				arg = childLockArg.toStyledString();
	// 			}
	// 		} else if (jsonarg == "Query_Action") { //查询状态动作
	// 			channel = "1";
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL ){
	// 				opcode = "FRESH_AIR_GET_CONFIG_ARGS";
	// 				nodeid = chanDev->nodeId;
	// 				arg = "*";
	// 			}
	// 		} else if (jsonarg == "TotalTime_FilterElement") {
	// 			channel = "1";
	// 			EH::Json::Value filter;
	// 			filter["resetWorktime"] = false;
	// 			filter["alarmTime"] = EH_ToolKit::StringToInt(cmd["TotalTime_FilterElement"].asString());
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FRESH_AIR_SET_FILTER_SCREEN_TIME";
	// 				nodeid = chanDev->nodeId;
	// 				arg = filter.toStyledString();
	// 			}
	// 		} else if (jsonarg == "Reset_FilterElement") {
	// 			channel = "1";
	// 			EH::Json::Value filter;
	// 			filter["resetWorktime"] = true;
	// 			filter["alarmTime"] = 65535;  //65535 表示不改变
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FRESH_AIR_SET_FILTER_SCREEN_TIME";
	// 				nodeid = chanDev->nodeId;
	// 				arg = filter.toStyledString();
	// 			}
	// 		} else if (jsonarg == "Time_AutoOff") {
	// 			channel = "1";
	// 			string bLight = "";
	// 			string timehour = EH_ToolKit::IntToString(EH_ToolKit::StringToInt(cmd["Time_AutoOff"].asString())/60);//( cmd["Time_AutoOff"].asInt())/60;
	// 			string timeminute = EH_ToolKit::IntToString(EH_ToolKit::StringToInt(cmd["Time_AutoOff"].asString())%60);//( cmd["Time_AutoOff"].asInt())%60;
	// 			LOGD("timehour:%s  timeminute:%s.\n",timehour.c_str(),timeminute.c_str());
	// 			EH::Json::Value timing_switch;
	// 			if (timeminute == "0"){
	// 				timing_switch = timehour + ":00";
	// 			}else{
	// 				timing_switch = timehour + ":30";
	// 			}
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FRESH_AIR_SET_TIME_OFF";
	// 				nodeid = chanDev->nodeId;
	// 				arg = timing_switch.toStyledString();
	// 			}
	// 		} else {
	// 			LOGW("not found svcId:%s.\n",jsonarg.c_str());
	// 			return -1;
	// 		}
	// 	} else if (dev_model_id == DimmerLightPanel_PID) { //肖邦-调光灯面板
	// 		string channel = "0";
	// 		if (jsonarg == "On") {
	// 			channel = "1";
	// 			bool on = cmd["On"].asString() == "1";
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "SWITCH";
	// 				nodeid = chanDev->nodeId;
	// 				arg = on?"ON":"OFF";
	// 			}
	// 		} else if (jsonarg == "Brightness") {
	// 			channel = "1";
	// 			string brightness = cmd["Brightness"].asString();
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "ADJUST_LUMINANCE";
	// 				nodeid = chanDev->nodeId;
	// 				arg = brightness;
	// 			}
	// 		} else if (jsonarg == "Query_Action") {
	// 			channel = "1";
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL ){
	// 				opcode = "GET_DIMMABLE_LIGHT_CONFIG";
	// 				nodeid = chanDev->nodeId;
	// 				arg = "*";
	// 				}
	// 		}  else if (jsonarg == "FadeTime") {
	// 			channel = "1";
	// 				HwDimmerLightPanel* device = (HwDimmerLightPanel*)subDevIt->second->channelDevs[channel];
	// 				device->time = cmd["FadeTime"].asString();
	// 				EH::Json::Value childLockArg;
	// 				childLockArg["ilumHighValue"] = 100;
	// 				childLockArg["ilumLowValue"] = 10;
	// 				childLockArg["softOnValue"] =  EH_ToolKit::StringToInt(cmd["FadeTime"].asString())*10;
	// 				KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 				if(chanDev!=NULL){
	// 					opcode = "SET_DIMMABLE_LIGHT_CONFIG";
	// 					nodeid = chanDev->nodeId;
	// 					arg = childLockArg.toStyledString();
	// 				}
	// 		}  else {
	// 			LOGW("not found svcId:%s.\n",jsonarg.c_str());
	// 			return -1;
	// 		}
	// 	} else if(dev_model_id == WaterHeating_PID||dev_model_id == ElectricHeating_PID) { //肖邦-水地暖 //肖邦-电地暖
	// 		string  channel = "1";
	// 		bool on = true;
	// 		if(jsonarg == "On"){		//地暖开关
	// 			on = cmd["On"].asString() == "1";
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "SWITCH";
	// 				nodeid = chanDev->nodeId;
	// 				arg = on?"ON":"OFF";
	// 			}
	// 		} else if(jsonarg == "Temperature") { //地暖设置工作温度（手动模式下）
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "SET_WORK_TEMPERATURE";
	// 				nodeid = chanDev->nodeId;
	// 				double filter;
	// 				double t2 = 10;
	// 				float t1 = EH_ToolKit::StringToDouble(cmd["Temperature"].asString());
	// 				filter = t1/t2;
	// 				arg = DoubleToString(filter,error);
	// 			}
	// 		} else if (jsonarg == "Mode"){  //工作模式，自动 手动
				
	// 			bool workmodel = cmd["Mode"].asString() == "1";
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "SET_WORK_MODEL";	//切换工作模式的报文
	// 				nodeid = chanDev->nodeId;
	// 				arg = workmodel?"AUTO":"MANUAL"; //模式
	// 				}
	// 		} else if (jsonarg == "Query_Action"){
	// 			channel = "1";
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL ){
	// 				opcode = "FLOOR_HEATING_GET_CONFIG_ARGS";
	// 				nodeid = chanDev->nodeId;
	// 				arg = "*";
	// 			}
	// 		} else if (jsonarg == "SwitchChildLock") {
	// 			channel = "1";
	// 			bool bChildLock = cmd["SwitchChildLock"].asString() == "1";
	// 			EH::Json::Value childLockArg;
	// 			if (bChildLock) {
	// 				childLockArg["model_lock"] = true;
	// 				childLockArg["child_lock"] = true;
	// 				childLockArg["time_lock"] = true;
	// 				childLockArg["switch_lock"] = true;
	// 				childLockArg["rotate_lock"] = true;
	// 			}else{
	// 				childLockArg["model_lock"] = false;
	// 				childLockArg["child_lock"] = false;
	// 				childLockArg["time_lock"] = false;
	// 				childLockArg["switch_lock"] = false;
	// 				childLockArg["rotate_lock"] = false;
	// 			}
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FLOOR_HEATING_SET_LOCK_STATUS";
	// 				nodeid = chanDev->nodeId;
	// 				arg = childLockArg.toStyledString();
	// 			}
	// 		} else{
	// 			LOGW("not found svcId:%s.\n",jsonarg.c_str());
	// 			return -1;
	// 		}
	// } else if (dev_model_id == FanCoilPanel_PID||dev_model_id == AirConditioner_PID) { //四期  肖邦风机盘管面板 肖邦中央空调线控器（大金）
	// 		string channel = "0";
	// 		if (jsonarg == "On") {
	// 			channel = "1";
	// 			bool on = cmd["On"].asString() == "1";
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "SWITCH";
	// 				nodeid = chanDev->nodeId;
	// 				arg = on?"ON":"OFF";
	// 			}
	// 		} else if (jsonarg == "Pattern") {
	// 			channel = "1";
	// 			string mode = cmd["Pattern"].asString();
	// 			if (mode == "1") {
	// 				arg = "COLD";
	// 			} else if (mode == "2") {
	// 				arg = "HOT";
	// 			}else if (mode == "3") {
	// 				arg = "WIND";
	// 			}else if (mode == "4") {
	// 				arg = "DEHUMIDIFICATION"; //只有肖邦中央空调线控器上有这个功能。
	// 			} else {
	// 				LOGW("not found mode:%s.\n", mode.c_str());
	// 				return -1;
	// 			}
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FAN_COIL_SET_RUN_MODEL";
	// 				nodeid = chanDev->nodeId;
	// 			}
	// 		} else if (jsonarg == "Wind_num") {
	// 			channel = "1";
	// 			string fan = cmd["Wind_num"].asString();
	// 			if (fan == "0") {
	// 				arg = "AUTO";
	// 			} else if (fan == "1") {
	// 				arg = "LOW";
	// 			} else if (fan == "2") {
	// 				arg = "MID";
	// 			} else if (fan == "3") {
	// 				arg = "HIGH";
	// 			} else {
	// 				LOGW("not found fan:%s.\n", fan.c_str());
	// 				return -1;
	// 			}
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FAN_COIL_SET_FUN_SPEED";
	// 				nodeid = chanDev->nodeId;
	// 			}
	// 		} else if (jsonarg == "SwitchChildLock") {
	// 			channel = "1";
	// 			bool bChildLock = cmd["SwitchChildLock"].asString() == "1";
	// 			EH::Json::Value childLockArg;
	// 			childLockArg["model_lock"] = false;
	// 			childLockArg["speed_lock"] = false;
	// 			childLockArg["time_lock"] = false;
	// 			childLockArg["switch_lock"] = false;
	// 			childLockArg["rotate_lock"] = false;
	// 			if (bChildLock) {
	// 				childLockArg["model_lock"] = true;
	// 				childLockArg["speed_lock"] = true;
	// 				childLockArg["time_lock"] = true;
	// 				childLockArg["switch_lock"] = true;
	// 				childLockArg["rotate_lock"] = true;
	// 			}

	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FAN_COIL_SET_LOCK_STATUS";
	// 				nodeid = chanDev->nodeId;
	// 				arg = childLockArg.toStyledString();
	// 			}
	// 		} else if (jsonarg == "Query_Action") {
	// 			channel = "1";
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL ){
	// 				opcode = "FAN_COIL_GET_CONFIG_ARGS";
	// 				nodeid = chanDev->nodeId;
	// 				arg = "*";
	// 			}
	// 		} else if (jsonarg == "Time_AutoOff") {
	// 			channel = "1";
	// 			string bLight;
	// 			string timehour = EH_ToolKit::IntToString(EH_ToolKit::StringToInt(cmd["Time_AutoOff"].asString())/60);//( cmd["Time_AutoOff"].asInt())/60;
	// 			string timeminute = EH_ToolKit::IntToString(EH_ToolKit::StringToInt(cmd["Time_AutoOff"].asString())%60);//( cmd["Time_AutoOff"].asInt())%60;
	// 			LOGD("timehour:%s  timeminute:%s.\n",timehour.c_str(),timeminute.c_str());
	// 			EH::Json::Value timing;
	// 			timing["enable"] = false;
	// 			timing["time"] = "00:00";
	// 			EH::Json::Value timing_switch;
	// 			timing_switch["timing_boot"] = timing;

	// 			if (timeminute == "0"){
	// 				bLight = timehour+":00";
	// 			}else{
	// 				bLight = timehour+":30";
	// 			}
	// 			timing["enable"] = bLight!="0:00"? true : false;
	// 			timing["time"] = bLight;
	// 			timing_switch["timing_shutdown"] = timing;
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FAN_COIL_SET_DELAY_SWITCH_TASK";
	// 				nodeid = chanDev->nodeId;
	// 				arg = timing_switch.toStyledString();
	// 			}
	// 		} else if (jsonarg == "Temperature") {
	// 			channel = "1";
	// 			double filter;
	// 			double t2 = 10;
	// 			float t1 = EH_ToolKit::StringToDouble(cmd["Temperature"].asString());//jsonObject["target"].asDouble();
	// 			filter = t1/t2;
	// 			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
	// 			if(chanDev!=NULL){
	// 				opcode = "FAN_COIL_SET_TEMPERATURE";
	// 				nodeid = chanDev->nodeId;
	// 				arg = DoubleToString(filter,error);
	// 			}
	// 		}
	// 		else {
	// 			LOGW("not found svcId:%s.\n",jsonarg.c_str());
	// 			return -1;
	// 		}
	// 	} else if (dev_model_id == DAIKINCentralACindoor_PID) { //中央空调内机(四期调整)
	// 		KKChannelDev* chanDev = subDevIt->second->channelDevs["1"];
	// 		HwCentralAcindoor* device = (HwCentralAcindoor*)subDevIt->second->channelDevs["1"];
	// 		nodeid = chanDev->nodeId;
	// 		EH::Json::Value contronlSet = centralACStatusToSet(device->fan,device->on,device->mode,device->target);
	// 		if (jsonarg == "On") {
	// 			bool on = cmd["On"].asString() == "1";	
	// 			if(chanDev!=NULL){
	// 				opcode = "CENTRAL_AC_INDOOR_UNIT_SETTING";
	// 				contronlSet["on"] = on;
	// 				arg = contronlSet.toStyledString();
	// 			}

	// 		} else if (jsonarg == "Pattern") {
	// 				string mode = cmd["Pattern"].asString();
	// 				if(chanDev!=NULL){
	// 					opcode = "CENTRAL_AC_INDOOR_UNIT_SETTING";
	// 					contronlSet["runModel"] = mode;
	// 					if ("5" == mode) {
	// 						contronlSet["runModel"] = "AUTO";
	// 					} else if ("1" == mode) {
	// 						contronlSet["runModel"] = "COLD";
	// 					} else if ("2" == mode) {
	// 						contronlSet["runModel"] = "HOT";
	// 					} else if ("3" == mode) {
	// 						contronlSet["runModel"] = "AIR_SUPPLY";
	// 					} else if ("4" == mode) {
	// 						contronlSet["runModel"] = "DEHUMIDIFICATION";
	// 					} else {
	// 						LOGW("not suppert set runModel style\n");
	// 					}
	// 					arg = contronlSet.toStyledString();
	// 				}
	// 		} else if (jsonarg == "Wind_num") {
	// 				string speed = cmd["Wind_num"].asString();
	// 				if(chanDev!=NULL){
	// 					opcode = "CENTRAL_AC_INDOOR_UNIT_SETTING";
	// 					contronlSet["fanSpeed"] = speed;
	// 					if ("1" == speed) {
	// 						contronlSet["fanSpeed"] = "LOW";
	// 					} else if ("2" == speed) {
	// 						contronlSet["fanSpeed"] = "MID";
	// 					} else if ("3" == speed) {
	// 						contronlSet["fanSpeed"] = "HIGH";
	// 					} else {
	// 						LOGW("not suppert set WindSpeed style\n");
	// 					}
	// 					arg = contronlSet.toStyledString();
	// 				}
	// 		} else if(jsonarg == "Temperature") { //设置工作温度
	// 			if(chanDev!=NULL){
	// 				opcode = "CENTRAL_AC_INDOOR_UNIT_SETTING";
	// 				nodeid = chanDev->nodeId;
	// 				double filter;
	// 				float t1 = EH_ToolKit::StringToDouble(cmd["Temperature"].asString());
	// 				double t2 =10;
	// 				filter = t1/t2;
	// 				contronlSet["settingTemperature"] = filter;
	// 				arg = contronlSet.toStyledString();
	// 			}
	// 		} 
			/*
			EH::Json::Value::Members keys = jsonObject.getMemberNames(); ///将所有内机放到一个设备下的多通道设备。通过属性后两位代表通道来进行区别；
				for (int j = 0; j < keys.size(); j++) {
					string strKey  = keys[j];
					channel = strKey.substr(strKey.size() - 2, 2);
					double temperature = jsonObject[strKey].asDouble();
					KK_HwSdk::KKChannelDev* chanDev = subDevIt->second->channelDevs[IntToString(StringToInt(channel,error))];
					if(chanDev!=NULL){
						opcode = "CENTRAL_AC_INDOOR_UNIT_SETTING";
						nodeid = chanDev->nodeId;
						// string contronl = KK_CcuConfig::GetInstance()->getCentralAcStatus(chanDev->nodeId);
						EH::Json::Value contronlSet = centralACStatusToSet(contronl);
						contronlSet["settingTemperature"] = temperature;
						arg = contronlSet.toStyledString();
					}
				}
			*/
		// }
//		else if (dev_model_id == SOSButton_PID) { //邦德-sos紧急呼叫  //待定
//			string channel= "0";
//			//bool on = true;
//			if(svcId == "pushButton"){
//				channel = "1";
//			} else {
//				LOGW("not found svcId:%s.\n",svcId.c_str());
//				return -1;
//			}
//			//on = 0;
//			KKChannelDev* chanDev = subDevIt->second->channelDevs[channel];
//			if(chanDev!=NULL){
//				opcode = "CLEAR_SOS_ALARM";
//				nodeid = chanDev->nodeId;
//				arg = "*";
//			}
//			//默认返回成功，同时将命令下发下去
//			if (dev_model_id == SOSButton_PID) { ////四期  控客-SOS按钮
//				HwSensor* device = (HwSensor*)subDevIt->second->channelDevs[channel];
//				device->alarm = false;
//				string msg = "{\"on\":"+IntToString(device->alarm)+"}";EH::Json::Value event;
//			}
		// }
	} catch (exception &e) {
		LOGW("%s.\n", e.what());
	}
	return 0;
}

//下发解析好的命令
//供：onSetDevService（）调用
int kk_handleDeviceInfo::on_Send_Service(string opcode,string nodeid,string arg,string dev_model_id){
	if(opcode!=""){
		EH::Json::Value json;
		json["opcode"] = opcode;
		json["nodeid"] = nodeid;
		json["arg"] = arg;
		if (dev_model_id == DAIKINCentralACindoor_PID) { //中央空调内机
			json["requester"] = "HJ_CentralAC";
		}else if(opcode == "SETUP_NODE"){
			json["requester"] = "HJ_Config";
		} else{
			json["requester"] = "HJ_Server";
		}
		string wholeMsg = EH_ToolKit::JsonToString(json);
		if(MQ_CCU_Adapter::GetInstance()->send_Control_Info(wholeMsg) != 0){
			LOGW("Send msg to IotHandler failed.msg is %s\n",wholeMsg.c_str());
		}
	}else{
		LOGW("nodeid:%s not support set property. \n",nodeid.c_str());
		return -1;
	}
	return 0;

}
EH::Json::Value kk_handleDeviceInfo::centralACStatusToSet(string fanSpeed,bool on,int runModel,int settingTemperature) {
	LOGI("centralACStatusToSet ， fanSpeed:%s runModel:%d \n",fanSpeed.c_str(),runModel);
	EH::Json::Value contronlSet;
	if ("1" == fanSpeed) {
		contronlSet["fanSpeed"] = "LOW";
	} else if ("2" == fanSpeed) {
		contronlSet["fanSpeed"] = "MID";
	} else if ("3" == fanSpeed) {
		contronlSet["fanSpeed"] = "HIGH";
	} else {
		LOGW("not suppert set WindSpeed style\n");
	}
	
	if (5 == runModel) {
		contronlSet["runModel"] = "AUTO";
	} else if (1 == runModel) {
		contronlSet["runModel"] = "COLD";
	} else if (2 == runModel) {
		contronlSet["runModel"] = "HOT";
	} else if (3 == runModel) {
		contronlSet["runModel"] = "AIR_SUPPLY";
	} else if (4 == runModel) {
		contronlSet["runModel"] = "DEHUMIDIFICATION";
	} else {
		LOGW("not suppert set runModel style runModel:%d\n",runModel);
	}
	contronlSet["on"] = on;
	contronlSet["settingTemperature"] = settingTemperature;//contronlStatus["settingTemperature"].asDouble();
	return contronlSet;
}

//更改设备状态信息
void kk_handleDeviceInfo::handleDeviceStatusChanged(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,string>&nodeId2channelMap,string nodeId,string opcode,EH::Json::Value arg,string pushTopic,string gw_id){
	LOGI("handleDeviceStatusChanged ， nodeId:%s opcode:%s \n      arg:%s.\n",nodeId.c_str(),opcode.c_str(),EH_ToolKit::JsonToString(arg).c_str());
	map<string,string>::iterator it = nodeId2channelMap.find(nodeId);
	if(it == nodeId2channelMap.end()){
		LOGW("nodeid:%s not in nodeId2channelMap.\n",nodeId.c_str());
		return;
	}
	int error;
	vector<string> chanMac;
	Split(it->second,"_",chanMac);
	string sn = Replace(chanMac[0],":","");
	string channel = chanMac[1];
	map<string,HwSubDev*>::iterator subDevIt = hwSubDevs.find(sn);
	if(subDevIt == hwSubDevs.end()){
		LOGW("dev:%s not in hwSubDevs.\n",sn.c_str());
		return;
	}

	string respTopic = pushTopic+"/devicestatechange";//设备状态变化上报
	string dev_model_id = subDevIt->second->dev_model_id;
	string devType = subDevIt->second->devTypeId;
	EH::Json::Value payload;
	EH::Json::Value msgstate0;
	EH::Json::Value Panel;

	payload["mac"] = sn;
	payload["product_id"] = subDevIt->second->dev_model_id;
	payload["state"] = 1; //状态

	LOGD("设备信息 dev_model_id:%s sn:%s channel:%s \n",dev_model_id.c_str(),sn.c_str(),channel.c_str());
	try {
		if(dev_model_id == ZeroFire1ChanChopinSwitch_PID || dev_model_id == ZeroFire2ChanModularSwitch_PID){  //单路灯控
			HwSwitch* device = (HwSwitch*)subDevIt->second->channelDevs[channel];
			if(opcode == "SWITCH"){
				if(device->on != (arg.asString()=="ON")){ //状态不改变不进行推送
					device->on = arg.asString()=="ON";
					msgstate0["name"] = "PowerSwitch";
					if(arg.asString()=="ON"){
						msgstate0["value"] = true;
					}else{
						msgstate0["value"] = false;
					}
					Panel.append(msgstate0);
					payload["datapoints"] = Panel;
					MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
				}
			}else if(opcode == "SETUP_NODE"){

			}
		}else if(dev_model_id == ZeroFire2ChanChopinSwitch_PID || dev_model_id == ZeroFire3ChanChopinSwitch_PID){  //多路灯控 /灯控模块
			HwSwitch* device = (HwSwitch*)subDevIt->second->channelDevs[channel];
			if(opcode == "SWITCH"){
				if(device->on != (arg.asString()=="ON")){ //状态不改变不进行推送
					device->on = arg.asString()=="ON";
					msgstate0["name"] = "PowerSwitch_"+channel;
					if(arg.asString()=="ON"){
						msgstate0["value"] = true;
					}else{
						msgstate0["value"] = false;
					}
					Panel.append(msgstate0);
					payload["datapoints"] = Panel;
					MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
				}
			}else if(opcode == "SETUP_NODE"){

			}
		} 
		// else if (dev_model_id == Chopin1CurtainSwitch_PID||dev_model_id == Chopin2CurtainSwitch_PID) {//窗帘面板
		// 	HwCurtain* device = (HwCurtain*)subDevIt->second->channelDevs[channel];
		// 	if(opcode == "SWITCH"){
		// 		string CurtainMode;
		// 		string sMode = arg.asString();
		// 		if (sMode == "OPEN") {
		// 			CurtainMode = "1";
		// 		} else if (sMode == "CLOSE") {
		// 			CurtainMode = "0";
		// 		} else if (sMode == "STOP") {
		// 			CurtainMode = "2";
		// 		}
		// 	if(device->mode != CurtainMode){
		// 		device->mode = CurtainMode;
		// 		msgstate0["Operate"] = CurtainMode;
		// 		payload["state"] = msgstate0;
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 	}else if(opcode == "SETUP_NODE"){
		// 	}
		// } else if (dev_model_id == Chopin1ChanScenePanel_PID) {  // 长供电（肖邦-情景面板）
		// 	HwScenePanel* device = (HwScenePanel*)subDevIt->second->channelDevs[channel];
		// 	if(opcode == "SHORTCUT_PANEL_ACTIVE"){
		// 		device->num = "switch"+arg.asString();
		// 		msgstate0["KeyValue"] = device->num;
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 1; //功能映射为通道1
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	}else if(opcode == "SETUP_NODE"){
		// 	}
		// } else if (dev_model_id == DoorContact_PID ||dev_model_id == BodyMotionSensor_PID||dev_model_id == WaterSensor_PID) { //邦德-门磁 KIT-人体 邦德-水浸
		// 	HwSensor* device = (HwSensor*)subDevIt->second->channelDevs[channel];
		// 	if (opcode == "SENSOR_BOOL") {

		// 		if (device->alarm != arg.asString()) {
		// 			LOGD("judge old alarm: %s, new alarm: %s",device->alarm.c_str(),arg.asString().c_str());
		// 			device->alarm = arg.asString();
		// 			msgstate0["Alarm"] = device->alarm;
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 1; //功能映射为通道1
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 	} else if (opcode == "SENSOR_BOOL_STATUS") {
		// 		if (device->leftbattery != arg["battery"].asString()) {
		// 			LOGD("judge old level: %s, new level: %s",device->leftbattery.c_str(), arg["battery"].asString().c_str());
		// 			device->leftbattery = arg["battery"].asString();
		// 			msgstate0["battery"] = device->leftbattery;
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 2; //功能映射为通道2
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 	} else if(opcode == "SETUP_NODE"){
		// 	}
		// } else if (dev_model_id == SOSButton_PID) { 	//邦德-SOS紧急按钮
		// 	HwSensor* device = (HwSensor*)subDevIt->second->channelDevs[channel];
		// 	if (opcode == "SOS_STATUS") { //(SOS紧急按钮状态)

		// 		if (device->alarm != arg["alarm"].asString()) {
		// 			LOGD("judge old alarm: %s, new alarm: %s",device->alarm.c_str(),arg["alarm"].asString().c_str());
		// 			device->alarm = arg["alarm"].asString();
		// 			msgstate0["Alarm"] = device->alarm;
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 1; //功能映射为通道1
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}

		// 		if (device->leftbattery !=  arg["battery"].asString()) {
		// 			LOGD("judge old level: %s, new level: %s",device->leftbattery.c_str(),arg["battery"].asString().c_str());
		// 			device->leftbattery =  arg["battery"].asString();
		// 			EH::Json::Value msgstate1;
		// 			msgstate1["battery"] = device->leftbattery;
		// 			payload["state"] = msgstate1;
		// 			payload["dev_ep_id"] = 2; //功能映射为通道2
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 	} else if(opcode == "SETUP_NODE"){
		// 	}
		// } else if (dev_model_id == SoundLightAlarm_PID) { 	//邦德-声光报警器
		// 	HwSensor* device = (HwSensor*)subDevIt->second->channelDevs[channel];
		// 	if (opcode == "ZIGBEE_ALERTOR_STATUS") { //Zigbee报警器状态)
		// 		if (device->alarm != arg["alarm"].asString()) {
		// 			LOGD("judge old alarm: %s, new alarm: %s",device->alarm.c_str(),arg["alarm"].asString().c_str());
		// 			device->alarm = arg["alarm"].asString();
		// 			msgstate0["Alarm"] = device->alarm;
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 1; //功能映射为通道1
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		if (device->leftbattery !=  arg["battery"].asString()) {
		// 			LOGD("judge old level: %s, new level: %s",device->leftbattery.c_str(),arg["battery"].asString().c_str());
		// 			device->leftbattery =  arg["battery"].asString();
		// 			EH::Json::Value msgstate1;
		// 			msgstate1["battery"] = device->leftbattery;
		// 			payload["state"] = msgstate1;
		// 			payload["dev_ep_id"] = 2; //功能映射为通道2
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		if (device->power_style !=  arg["power"].asString()) {
		// 			LOGD("judge old power_style: %s, new power_style: %s",device->power_style.c_str(),arg["power"].asString().c_str());
		// 			device->power_style =  arg["power"].asString();
		// 			EH::Json::Value msgstate2;
		// 			msgstate2["power_style"] = device->power_style;
		// 			payload["state"] = msgstate2;
		// 			payload["dev_ep_id"] = 3; //功能映射为通道2
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		if (device->sound !=  arg["battery"].asString()) {
		// 			LOGD("judge old sound: %s, new sound: %s",device->sound.c_str(),arg["sound"].asString().c_str());
		// 			device->sound =  arg["sound"].asString();
		// 			EH::Json::Value msgstate3;
		// 			msgstate3["Sound"] = device->sound;
		// 			payload["state"] = msgstate3;
		// 			payload["dev_ep_id"] = 4; //功能映射为通道2
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 	} else if(opcode == "SETUP_NODE"){
		// 	}
		// } else if (dev_model_id == DimmerLightPanel_PID) { //控客-肖邦调光面板
		// 	HwDimmerLightPanel* device = (HwDimmerLightPanel*)subDevIt->second->channelDevs[channel];
		// 	if(opcode == "DIMMABLE_LIGHT_STATUS"){

		// 		if(device->on != arg["on"].asBool()){
		// 			device->on = arg["on"].asBool();
		// 			if(device->on){
		// 				msgstate0["On"] = "1";
		// 			}else{
		// 				msgstate0["On"] = "0";
		// 			}
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 1; //功能映射为通道1
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		if(device->brightness != IntToString(arg["bri"].asInt())){
		// 			device->brightness = IntToString(arg["bri"].asInt());
		// 			EH::Json::Value msgstate3;
		// 			msgstate3["Brightness"] = device->brightness;
		// 			payload["state"] = msgstate3;
		// 			payload["dev_ep_id"] = 2; //功能映射为通道2
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 	} else if (opcode == "GET_DIMMABLE_LIGHT_CONFIG") { //
		// 		device->time = IntToString(arg["softOnValue"].asInt()/10);
		// 		msgstate0["FadeTime"] = device->time;
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 4; //功能映射为通道4
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "SET_DIMMABLE_LIGHT_CONFIG") { //
		// 		msgstate0["FadeTime"] = device->time;
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 4; //功能映射为通道4
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if(opcode == "SETUP_NODE"){

		// 	}
		// } else if (dev_model_id == WaterHeating_PID||dev_model_id == ElectricHeating_PID){ //肖邦-水地暖 肖邦-电地暖
		// 	HwWaterElectricHeating* device = (HwWaterElectricHeating*)subDevIt->second->channelDevs[channel];
		// 	if(opcode == "SWITCH"){ //远程反馈
		// 		device->on = arg.asString()=="ON";
		// 		if(device->on){
		// 			msgstate0["On"] = "1";
		// 		}else{
		// 			msgstate0["On"] = "0";
		// 		}
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 1; //功能映射为通道1
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if(opcode == "SET_WORK_MODEL"){       //设置工作模式
		// 		if(arg.asString()=="MANUAL"){  //MANUAL(手动模式)，AUTO(自动模式)。
		// 			device->mode = "0";
		// 		}else{
		// 			device->mode = "1";
		// 		}
		// 		msgstate0["Mode"] = device->mode;
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 2; //功能映射为通道1
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FLOOR_HEATING_SET_LOCK_STATUS") {
		// 		device->childLockSwitch = arg["switch_lock"].asString() == "true";
		// 		if(device->childLockSwitch){
		// 			msgstate0["SwitchChildLock"] = "1";
		// 		}else{
		// 			msgstate0["SwitchChildLock"] = "0";
		// 		}
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 3; //功能映射为通道4
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FLOOR_HEATING_GET_CONFIG_ARGS") {
		// 		device->childLockSwitch = arg["lock_status"]["switch_lock"].asString() == "true";
		// 		if(device->childLockSwitch){
		// 			msgstate0["SwitchChildLock"] = "1";
		// 		}else{
		// 			msgstate0["SwitchChildLock"] = "0";
		// 		}
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 3; //功能映射为通道4
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	}  else if(opcode == "SET_WORK_TEMPERATURE"){  //设置工作温度
		// 		device->target = DoubleToString(arg.asDouble() * 10,error);
		// 		msgstate0["Temperature"] = device->target;
		// 		msgstate0["Current_Temperature"] = device->current;
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 4; //功能映射为通道3
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	}else if(opcode == "FLOOR_HEATING_DEV_STATUS"){  //本地状态改变上报推送 FLOOR_HEATING_DEV_STATUS
		// 		//开关
		// 		if(arg["on"].asBool() != device->on){
		// 			device->on = arg["on"].asBool();
		// 			if(device->on){
		// 				msgstate0["On"] = "1";
		// 			}else{
		// 				msgstate0["On"] = "0";
		// 			}
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 1; //功能映射为通道1
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		//工作模式
		// 		if(device->mode != (arg["run_model"].asString() == "MANUAL"?"0":"1")){
		// 			if(arg["run_model"].asString() == "MANUAL"){  //MANUAL(手动模式)，AUTO(自动模式)。
		// 				device->mode = "0";
		// 			}else{
		// 				device->mode = "1";
		// 			}
		// 			EH::Json::Value msgstate1;
		// 			msgstate1["Mode"] = device->mode;
		// 			payload["state"] = msgstate1;
		// 			payload["dev_ep_id"] = 2; //功能映射为通道1
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		//温度
		// 		if(device->target != DoubleToString(arg["work_temperature"].asDouble() * 10,error)||
		// 				device->current != DoubleToString(arg["current_real_temperature"].asDouble() * 10,error)){

		// 			device->target = DoubleToString(arg["work_temperature"].asDouble() * 10,error);
		// 			device->current = DoubleToString(arg["current_real_temperature"].asDouble() * 10,error);
		// 			EH::Json::Value msgstate2;
		// 			msgstate2["Temperature"] = device->target;
		// 			msgstate2["Current_Temperature"] = device->current;
		// 			payload["state"] = msgstate2;
		// 			payload["dev_ep_id"] = 4; //功能映射为通道3
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 	} else if(opcode == "SETUP_NODE"){
		// 	}else {
		// 	LOGW("opcode:%s not handle handleDeviceStatusChanged.\n",opcode.c_str());
		// 	}
		// }  else if (dev_model_id == ChopinFreshAir_PID) {	//肖邦-新风控制面板
		// 	HwChopinFreshAir* device = (HwChopinFreshAir*)subDevIt->second->channelDevs[channel];
		// 	if (opcode == "FRESH_AIR_SWITCH") {
		// 		device->on = arg.asString()=="ON";
		// 		if(arg.asString()=="ON"){
		// 			msgstate0["On"] = "1";
		// 		}else{
		// 			msgstate0["On"] = "0";
		// 		}
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 1; //功能映射为通道1
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FRESH_AIR_RUN_MODEL") {
		// 		device->mode = arg.asString()=="MANUAL"? 0 : 1;
		// 		EH::Json::Value msgstate1;
		// 		if(arg.asString()=="MANUAL"){
		// 			msgstate1["Mode"] = "0";
		// 		}else{
		// 			msgstate1["Mode"] = "1";
		// 		}
		// 		payload["state"] = msgstate1;
		// 		payload["dev_ep_id"] = 2; //功能映射为通道2
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FRESH_AIR_SPEED_SET") {
		// 		string sSpeed = arg.asString();
		// 		EH::Json::Value msgstate2;
		// 		if (sSpeed == "LOW") {
		// 			device->fan = "1";
		// 		} else if (sSpeed == "MID") {
		// 			device->fan = "2";
		// 		} else if (sSpeed == "HIGH") {
		// 			device->fan = "3";
		// 		} else {
		// 			LOGW("not support:%s.\n",sSpeed.c_str());
		// 		}
		// 		msgstate2["Wind_num"] = device->fan;
		// 		payload["state"] = msgstate2;
		// 		payload["dev_ep_id"] = 3; //功能映射为通道3
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FRESH_AIR_CONFIG_ARGS_PUSH" ||opcode == "FRESH_AIR_GET_CONFIG_ARGS") {
		// 		device->childLockSwitch = arg["lock_status"]["switch_lock"].asBool();
		// 		if(device->childLockSwitch){
		// 			msgstate0["SwitchChildLock"] = "1";
		// 		}else{
		// 			msgstate0["SwitchChildLock"] = "0";
		// 		}
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 4; //功能映射为通道4
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "CHOPIN_FRESH_AIR_STATUS") {
		// 		if (device->on != arg["on"].asBool()) {
		// 			device->on = arg["on"].asBool();
		// 			if(arg["on"].asBool() == true){
		// 				msgstate0["On"] = "1";
		// 			}else{
		// 				msgstate0["On"] = "0";
		// 			}
		// 				payload["state"] = msgstate0;
		// 				payload["dev_ep_id"] = 1; //功能映射为通道1
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		if (device->mode != (arg["runModel"].asString() == "MANUAL" ? 0 : 1)) {
		// 			device->mode = arg["runModel"].asString() == "MANUAL" ? 0 : 1;
		// 			EH::Json::Value msgstate2;
		// 			if(arg["runModel"].asString() == "MANUAL"){
		// 				msgstate2["Mode"] = "0";
		// 			}else{
		// 				msgstate2["Mode"] = "1";
		// 			}
		// 				payload["state"] = msgstate2;
		// 				payload["dev_ep_id"] = 2; //功能映射为通道2
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		if (device->fan != IntToString(arg["speed"].asInt())) {
		// 			device->fan = IntToString(arg["speed"].asInt());
		// 			EH::Json::Value msgstate3;
		// 			msgstate3["Wind_num"] = device->fan;
		// 			payload["state"] = msgstate3;
		// 			payload["dev_ep_id"] = 3; //功能映射为通道3
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		if (device->current != DoubleToString(arg["cur_temperature"].asDouble() * 10, error)) {
		// 			device->current = DoubleToString(arg["cur_temperature"].asDouble() * 10, error); //arg["cur_temperature"].asDouble() * 10;
		// 			EH::Json::Value msgstate4;
		// 			msgstate4["Current_Temperature"] = device->current;
		// 			payload["state"] = msgstate4;
		// 			payload["dev_ep_id"] = 6; //功能映射为通道6
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}

		// 		string Stime = arg["time_off"].asString();
		// 		int stime1 = StringToInt(Stime.substr(0.1), error);
		// 		int stime2 =StringToInt(Stime.substr(3.4), error);
		// 		int HWTIME =  stime1*60 + stime2;
		// 		if (device->downtime != HWTIME) {   //延迟时间 时间格式转换
		// 			device->downtime = HWTIME;
		// 			msgstate0["Time_AutoOff"] = IntToString(device->downtime);
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 5; //功能映射为通道5
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}

		// 		if (device->totalTime != arg["filterScreenAlarmTime"].asInt() ||
		// 				device->leftTime != device->totalTime - arg["filterScreenWorkTime"].asInt()) {
		// 			device->totalTime = arg["filterScreenAlarmTime"].asInt();
		// 			device->leftTime = device->totalTime - arg["filterScreenWorkTime"].asInt();
		// 			if (device->leftTime < 0) {
		// 				device->leftTime = 0;
		// 			}
		// 			EH::Json::Value msgstate4;
		// 			// msgstate4["TotalTime_FilterElement"] = IntToString(device->totalTime);
		// 			msgstate4["LeftTime_FilterElement"] = IntToString(device->leftTime);
		// 			payload["state"] = msgstate4;
		// 			payload["dev_ep_id"] = 8; //功能映射为通道8
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 	} else if(opcode == "SETUP_NODE"){
		// 	}
		// }  else if (dev_model_id == FanCoilPanel_PID||dev_model_id == AirConditioner_PID) {  //肖邦-风机盘管面板 //肖邦-中央空调线控器（大金）
		// 	HwConditionerPanel* device = (HwConditionerPanel*)subDevIt->second->channelDevs[channel];
		// 	if (opcode == "SWITCH") {
		// 		device->on = arg.asString()=="ON";
		// 		if(arg.asString()=="ON"){
		// 			msgstate0["On"] = "1";
		// 		}else{
		// 			msgstate0["On"] = "0";
		// 		}
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 1; //功能映射为通道1
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FAN_COIL_SET_RUN_MODEL") {
		// 		string smode = arg.asString();
		// 		if (smode == "COLD") {
		// 			device->mode = "1";
		// 		} else if (smode == "HOT") {
		// 			device->mode = "2";
		// 		} else if (smode == "WIND") {
		// 			device->mode = "3";
		// 		} else if (smode == "DEHUMIDIFICATION") {
		// 			device->mode = "4";
		// 		} else {
		// 			LOGW("not support:%s.\n",smode.c_str());
		// 		}
		// 		msgstate0["Pattern"] = device->mode;
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 2; //功能映射为通道3
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FAN_COIL_SET_FUN_SPEED") {
		// 		string sSpeed = arg.asString();
		// 		if (sSpeed == "AUTO") {
		// 			device->fan = "0";
		// 		} else if (sSpeed == "LOW") {
		// 			device->fan = "1";
		// 		} else if (sSpeed == "MID") {
		// 			device->fan = "2";
		// 		} else if (sSpeed == "HIGH") {
		// 			device->fan = "3";
		// 		} else {
		// 			LOGW("not support:%s.\n",sSpeed.c_str());
		// 		}
		// 		msgstate0["Wind_num"] = device->fan;
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 3; //功能映射为通道2
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FAN_COIL_SET_TEMPERATURE") {
		// 		device->target = DoubleToString(StringToDouble(arg.asString(), error) * 10, error);
		// 		msgstate0["Temperature"] = device->target;
		// 		msgstate0["Current_Temperature"] = device->current;
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 6; //功能映射为通道6
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FAN_COIL_CONFIG_ARGS_PUSH"||opcode == "FAN_COIL_GET_CONFIG_ARGS") {
		// 		device->childLockSwitch = arg["lock_status"]["model_lock"].asBool();
		// 		if(device->childLockSwitch){
		// 			msgstate0["SwitchChildLock"] = "1";
		// 		}else{
		// 			msgstate0["SwitchChildLock"] = "0";
		// 		}
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 4; //功能映射为通道4
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	}  else if (opcode == "FAN_COIL_SET_DELAY_SWITCH_TASK") {
		// 		string stime = arg["timing_shutdown"]["time"].asString();   //延迟时间 时间格式转换
		// 		int HWTIME =  (StringToInt(stime.substr(0.1), error))* 60 + StringToInt(stime.substr(3.4), error);
		// 		device->downtime = HWTIME;
		// 		device->enable = arg["timing_shutdown"]["enable"].asInt();
		// 		msgstate0["Time_AutoOff"] = IntToString(device->downtime);
		// 		payload["state"] = msgstate0;
		// 		payload["dev_ep_id"] = 5; //功能映射为通道5
		// 		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 	} else if (opcode == "FAN_COIL_STATUS") {
		// 		if (device->on != arg["on"].asBool()) {
		// 			device->on = arg["on"].asBool();
		// 			if(arg["on"].asBool() == true ){
		// 				msgstate0["On"] = "1";
		// 			}else{
		// 				msgstate0["On"] = "0";
		// 			}
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 1; //功能映射为通道1
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		string smode = arg["run_model"].asString();
		// 		string Tmpmode;
		// 		if (smode == "COLD") {
		// 			Tmpmode = "1";
		// 		} else if (smode == "HOT") {
		// 			Tmpmode = "2";
		// 		} else if (smode == "WIND") {
		// 			Tmpmode = "3";
		// 		} else if (smode == "DEHUMIDIFICATION") {
		// 			Tmpmode = "4";
		// 		} else {
		// 			LOGW("not support mode:%s.\n",smode.c_str());
		// 		}
		// 		if (device->mode != Tmpmode) {
		// 			device->mode = Tmpmode;
		// 			msgstate0["Pattern"] = device->mode;
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 2; //功能映射为通道3
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		string sSpeed = arg["fan_speed"].asString();
		// 		string TmpSpeed;
		// 		if (sSpeed == "AUTO") {
		// 			TmpSpeed = "0";
		// 		} else if (sSpeed == "LOW") {
		// 			TmpSpeed = "1";
		// 		} else if (sSpeed == "MID") {
		// 			TmpSpeed = "2";
		// 		} else if (sSpeed == "HIGH") {
		// 			TmpSpeed = "3";
		// 		} else {
		// 			LOGW("not support:%s.\n",sSpeed.c_str());
		// 		}
		// 		if (device->fan != TmpSpeed) {
		// 			device->fan = TmpSpeed;
		// 			msgstate0["Wind_num"] = device->fan;
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 3; //功能映射为通道2
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		string Stime = arg["timing_shutdown"]["time"].asString();
		// 		int stime1 = StringToInt(Stime.substr(0.1), error);
		// 		int stime2 =StringToInt(Stime.substr(3.4), error);
		// 		int HWTIME =  stime1*60 + stime2;
		// 		if (device->downtime != HWTIME||device->enable != arg["timing_shutdown"]["enable"].asBool()) {   //延迟时间 时间格式转换
		// 			device->downtime = HWTIME;
		// 			device->enable = arg["timing_shutdown"]["enable"].asBool();
		// 			msgstate0["Time_AutoOff"] = IntToString(device->downtime);
		// 			payload["state"] = msgstate0;
		// 			payload["dev_ep_id"] = 5; //功能映射为通道5
		// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 		}
		// 		//DoubleToString(StringToDouble(arg.asString(), error) * 10, error);
		// 			if (device->current != EH_ToolKit::DoubleToString((arg["room_temperature"].asDouble())*10) ||device->target != EH_ToolKit::DoubleToString(arg["setting_temperature"].asDouble()*10)) {
		// 				device->current = EH_ToolKit::DoubleToString((arg["room_temperature"].asDouble())*10);
		// 				device->target = EH_ToolKit::DoubleToString(arg["setting_temperature"].asDouble()*10);
		// 				msgstate0["Temperature"] = device->target;
		// 				msgstate0["Current_Temperature"] = device->current;
		// 				payload["state"] = msgstate0;
		// 				payload["dev_ep_id"] = 6; //功能映射为通道6
		// 				MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
		// 			}
		// 	} else if(opcode == "SETUP_NODE"){
		// 	}
		// }
		// else {
		// 	LOGW("dev_model_id:%s not handle handleDeviceStatusChanged.\n",dev_model_id.c_str());
		// }

	} catch (exception &e) {
		LOGW("%s.\n", e.what());
	}
}

// void kk_handleDeviceInfo::handleCentralACStatusPush(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,string>&indoorunitsId2AddrMap,string pushTopic,
// 		string nodeId,EH::Json::Value arg,string opcode){
// 		LOGI("handleCentralACStatusPush ， nodeId:%s opcode:%s \n      arg:%s.\n",nodeId.c_str(),opcode.c_str(),EH_ToolKit::JsonToString(arg).c_str());
// 	int error;
// 	map<string,string>::iterator it = indoorunitsId2AddrMap.find(nodeId);
// 	if(it == indoorunitsId2AddrMap.end()){
// 		LOGW("indoorunits:%s not in indoorunitsId2AddrMap.\n",nodeId.c_str());
// 		return;
// 	}

// 	vector<string> chanMac;
// 	Split(it->second,"_",chanMac);
// 	string sn; //内机的sn为mac+id
// 	string channel = "1";
// 	if(StringToInt(chanMac[1],error)<10){
// 		sn = Replace(chanMac[0],":","")+"0"+chanMac[1]; //内机的sn为mac+id
// 	}else{
// 		sn = Replace(chanMac[0],":","")+chanMac[1]; //内机的sn为mac+id
// 	}
// 	LOGD("sn:%s.\n",sn.c_str());
// 	map<string, HwSubDev*>::iterator subDevIt = hwSubDevs.find(sn);
// 	if(subDevIt == hwSubDevs.end()){
// 		LOGW("dev:%s not in hwSubDevs.\n",sn.c_str());
// 		return;
// 	}
// 	string dev_model_id = subDevIt->second->dev_model_id;
// 	LOGD("prodId:%s.\n",dev_model_id.c_str());
// 	if(subDevIt->second->channelDevs.count(channel) == 0){
// 		LOGW("centralAddr:%s not found in channelDevs.\n",channel.c_str());
// 		return;
// 	}

// 	string respTopic = pushTopic+"/devicestatechange";//设备状态变化上报
// 	string devType = subDevIt->second->devTypeId;
// 	EH::Json::Value payload;
// 	EH::Json::Value msgstate0;
// 	payload["gw_id"] = EH_ToolKit::GetMacNoSpace(); //请求发起者
// 	payload["dev_id"] = sn;
// 	payload["dev_type"] = subDevIt->second->dev_model_id;
// 	payload["dev_ep_id"] = StringToInt(channel,error); //通道
// 	try
// 	{
// 	if (dev_model_id == DAIKINCentralACindoor_PID) {
// 		HwCentralAcindoor* device = (HwCentralAcindoor*)subDevIt->second->channelDevs[channel];

// 		if(opcode == "CENTRAL_AC_INDOOR_UNIT_STATUS"){
// 			string respTopic_line;
// 			//内机的在线离线
// 			if(arg["online"].asBool() == true){  //当空调网关在线时，内机的离线在线，由状态报文进行推送
// 				respTopic_line = pushTopic+"/deviceonline";//子设备在线
// 				EH::Json::Value payload;
// 				payload["dev_id"] = sn; //请求发起者
// 				// payload["dev_type"] = subDevIt->second->dev_type;
// 				payload["gw_id"] = EH_ToolKit::GetMacNoSpace();
// 				MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic_line);  //推送新设备到Roma
// 				subDevIt->second->online = true;
// 			}else{
// 				respTopic_line = pushTopic+"/deviceoffline";//子设备离线
// 				EH::Json::Value payload;
// 				payload["dev_id"] = sn; //请求发起者
// 				// payload["dev_type"] = subDevIt->second->dev_type;
// 				payload["gw_id"] = EH_ToolKit::GetMacNoSpace();
// 				MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic_line);  //推送新设备到Roma //在线状态的推送 ，待更改 2020.10.15.9
// 				subDevIt->second->online = false;
// 				}
// 			//温度
// 			if (device->current != arg["roomTemperature"].asInt()) {
// 				device->current = arg["roomTemperature"].asInt();
// 				device->target = arg["settingTemperature"].asInt();
// 				LOGD("update now old target: %d, new target: %d, old current: %d, new current: %d, will push huawei", device->target
// 						, arg["settingTemperature"].asInt(),device->current, arg["roomTemperature"].asInt());
// 				EH::Json::Value msgstate1;
// 				msgstate1["Temperature"] = IntToString(device->target*10);
// 				msgstate1["Current_Temperature"] = IntToString(device->current*10);
// 				payload["state"] = msgstate1;
// 				payload["dev_ep_id"] = 6; //功能映射为通道6
// 				MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
// 			}
// 		}

// 		//开关部分
// 		if (device->on != arg["on"].asBool()) {
// 			device->on = arg["on"].asBool();
// 			LOGD("update now old on: %d, new on: %d, will push huawei", device->on ,arg["on"].asBool());
// 			msgstate0["On"] = device->on?"1":"0";
// 			payload["state"] = msgstate0;
// 			payload["dev_ep_id"] = 1; //功能映射为通道1
// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
// 		}

// 		if (device->target != arg["settingTemperature"].asInt()) {
// 			device->target = arg["settingTemperature"].asInt();
// 			LOGD("update now old target: %d, new target: %d, old current: %d, new current: %d, will push huawei", device->target
// 					, arg["settingTemperature"].asInt(),device->current, arg["roomTemperature"].asInt());
// 			EH::Json::Value msgstate1;
// 			msgstate1["Temperature"] = IntToString(device->target*10);
// 			msgstate1["Current_Temperature"] = IntToString(device->current*10);
// 			payload["state"] = msgstate1;
// 			payload["dev_ep_id"] = 6; //功能映射为通道6
// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
// 		}

// 		string sModel = arg["runModel"].asString();
// 		int iModel;
// 		if (sModel == "AUTO") {
// 			iModel = 5;
// 		} else if (sModel == "AIR_SUPPLY") {
// 			iModel = 3;
// 		} else if (sModel == "COLD") {
// 			iModel = 1;
// 		} else if (sModel == "HOT") {
// 			iModel = 2;
// 		} else if (sModel == "DEHUMIDIFICATION") {
// 			iModel = 4;
// 		} else {
// 			LOGW("UNKNOWN style model");
// 			return;
// 		}
// 		if (iModel != device->mode) {
// 			device->mode = iModel;
// 			LOGD("update now old mode: %d, new mode: %s, will push huawei", device->mode,arg["runModel"].asString().c_str());
// 			EH::Json::Value msgstate2;
// 			msgstate2["Pattern"] = IntToString(device->mode);
// 			payload["state"] = msgstate2;
// 			payload["dev_ep_id"] = 2; //功能映射为通道2
// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
// 		}

// 		string sSpeed = arg["fanSpeed"].asString();
// 		string iSpeed;
// 		if (sSpeed == "LOW") {
// 			iSpeed = "1";
// 		} else if (sSpeed == "MID") {
// 			iSpeed = "2";
// 		} else if (sSpeed == "HIGH") {
// 			iSpeed = "3";
// 		} else {
// 			LOGW("UNKNOWN style speed");
// 			return;
// 		}
// 		if (iSpeed != device->fan){
// 			device->fan = iSpeed;
// 			LOGD("update now old gear: %s, new gear: %s, will push huawei", device->fan.c_str(),arg["fanSpeed"].asString().c_str());
// 			EH::Json::Value msgstate2;
// 			msgstate2["Wind_num"] = device->fan;
// 			payload["state"] = msgstate2;
// 			payload["dev_ep_id"] = 3; //功能映射为通道3
// 			MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic);
// 		}
// 	}

// 	} catch (exception &e) {
// 		LOGW("%s.\n", e.what());
// 	}
// }

//获取全部设备信息
int kk_handleDeviceInfo::onGetDevService(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,vector<string> >& controllerModel,string pushTopic){
	int error;
	EH::Json::Value payload,payload1;
	EH::Json::Value Panel2;
	EH::Json::Value jsonObject_0;
	string respTopic1 = pushTopic+"/devices";//1. 子设备列表
	string respTopic2 = pushTopic+"/device/sync";//全部设备信息
	map<string,HwSubDev*>::iterator it = hwSubDevs.begin();
	try
	{	
	if(it != hwSubDevs.end()){

		//1. 子设备列表
		for (it = hwSubDevs.begin(); it != hwSubDevs.end(); it++) {
			jsonObject_0["mac"] = it->second->sn;
			jsonObject_0["product_id"] = it->second->dev_model_id;
			jsonObject_0["state"] = it->second->online = true ? 1:3;
			Panel2.append(jsonObject_0);
		}
		payload1["devices"] = Panel2;
		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload1,respTopic1); 
		
		//5. 子设备状态改变 ,要上传每个设备的状态信息。
		for (it = hwSubDevs.begin(); it != hwSubDevs.end(); it++) {
			EH::Json::Value jsonObject_1;
			EH::Json::Value Panel;
			EH::Json::Value fieldinfo;
			jsonObject_1["mac"] = it->second->sn;
			jsonObject_1["product_id"] = it->second->dev_model_id;
			jsonObject_1["state"] = it->second->online = true ? 1:3;
			string dev_model_id = it->second->dev_model_id;
			if(dev_model_id == ZeroFire1ChanChopinSwitch_PID || dev_model_id == ZeroFire2ChanModularSwitch_PID){  //单路灯控 /灯控模块
				for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
					HwSwitch* chanDev = (HwSwitch* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
					fieldinfo["name"] = "PowerSwitch";
					fieldinfo["value"] = chanDev->on ? true:false;
				}
				EH::Json::Value Panel3;
				jsonObject_1["datapoints"] = Panel3.append(fieldinfo);
				Panel.append(jsonObject_1);
				payload["devices"] = Panel;
				MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic2);  //推送新设备到Roma
			}else if(dev_model_id == ZeroFire2ChanChopinSwitch_PID || dev_model_id == ZeroFire3ChanChopinSwitch_PID){  //多路灯控 /灯控模块
			EH::Json::Value Panel3;
				for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
					HwSwitch* chanDev = (HwSwitch* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
					fieldinfo["name"] = "PowerSwitch_" + IntToString(StringToInt(subIt->second->channel,error));
					fieldinfo["value"] = chanDev->on ? true:false;
					Panel3.append(fieldinfo);
				}
				
				jsonObject_1["datapoints"] = Panel3;
				Panel.append(jsonObject_1);
				payload["devices"] = Panel;
				MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic2);  //推送新设备到Roma
			}
			// else if(dev_model_id == Chopin1CurtainSwitch_PID||dev_model_id == Chopin2CurtainSwitch_PID) {//窗帘面板
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwCurtain* chanDev = (HwCurtain* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		string channelnum = "mode" + IntToString(StringToInt(subIt->second->channel,error));
			// 		fieldinfo[channelnum] = chanDev->mode;
			// 	}
			// }else if(dev_model_id == Chopin1ChanScenePanel_PID) { // 长供电（肖邦情景面板）
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwScenePanel* chanDev = (HwScenePanel* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		fieldinfo["KeyValue"] = "switch0";
			// 	}
			// }else if(dev_model_id == DoorContact_PID ) { //邦德-门磁 
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwSensor* chanDev = (HwSensor* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		fieldinfo["alarm"] = "2"; //不推送当前值状态
			// 		fieldinfo["battery"] = chanDev->leftbattery;
			// 	}
			// }else if(dev_model_id == BodyMotionSensor_PID||dev_model_id == WaterSensor_PID
			// 		||dev_model_id == SOSButton_PID) { // KIT-人体 邦德-水浸  邦德-SOS紧急按钮
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwSensor* chanDev = (HwSensor* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		fieldinfo["alarm"] = chanDev->alarm;
			// 		fieldinfo["battery"] = chanDev->leftbattery;
			// 	}
			// }else if(dev_model_id == SoundLightAlarm_PID) { // 邦德-声光报警器
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwSensor* chanDev = (HwSensor* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		fieldinfo["alarm"] = chanDev->alarm;
			// 		fieldinfo["battery"] = chanDev->leftbattery;
			// 		fieldinfo["power_style"] = chanDev->power_style;
			// 		fieldinfo["Sound"] = chanDev->sound;
			// 	}
			// }else if(dev_model_id == DimmerLightPanel_PID) { //控客-肖邦调光面板
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwDimmerLightPanel* chanDev = (HwDimmerLightPanel* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		fieldinfo["On"] = chanDev->on ? "1":"0";
			// 		fieldinfo["Brightness"] = chanDev->brightness;
			// 	}
			// }else if(dev_model_id == WaterHeating_PID||dev_model_id == ElectricHeating_PID){ //肖邦-水地暖 肖邦-电地暖
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwWaterElectricHeating* chanDev = (HwWaterElectricHeating* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		fieldinfo["On"] = chanDev->on ? "1":"0";
			// 		fieldinfo["Mode"] = chanDev->mode;
			// 		fieldinfo["Current_Temperature"] = chanDev->current;
			// 		fieldinfo["Temperature"] = chanDev->target;
			// 	}
			// }else if(dev_model_id == ChopinFreshAir_PID) {	//肖邦-新风控制面板
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwChopinFreshAir* chanDev = (HwChopinFreshAir* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		fieldinfo["On"] = chanDev->on ? "1":"0";
			// 		fieldinfo["Mode"] = IntToString(chanDev->mode);
			// 		fieldinfo["Wind_num"] = chanDev->fan;
			// 		fieldinfo["Current_Temperature"] = chanDev->current;
			// 		// fieldinfo["TotalTime_FilterElement"] = IntToString(chanDev->totalTime);
			// 		fieldinfo["LeftTime_FilterElement"] = IntToString(chanDev->leftTime);
			// 		fieldinfo["Time_AutoOff"] = IntToString(chanDev->downtime);
			// 	}
			// }else if(dev_model_id == FanCoilPanel_PID||dev_model_id == AirConditioner_PID) {  //肖邦-风机盘管面板 //肖邦-中央空调线控器（大金）
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwConditionerPanel* chanDev = (HwConditionerPanel* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		fieldinfo["On"] = chanDev->on ? "1":"0";
			// 		fieldinfo["Pattern"] = chanDev->mode;
			// 		fieldinfo["Wind_num"] = chanDev->fan;
			// 		fieldinfo["Time_AutoOff"] = IntToString(chanDev->downtime);
			// 		fieldinfo["Current_Temperature"] = chanDev->current;
			// 		fieldinfo["Temperature"] = chanDev->target;
			// 	}
			// } else if (dev_model_id == DAIKINCentralACgw_PID) { //空调网关
			// 	EH::Json::Value array;
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwCentralAcgw* chanDev = (HwCentralAcgw* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		map<string,vector<string> >::iterator numIt = controllerModel.find(it->second->mac);
			// 		if (numIt != controllerModel.end()) {
			// 			for (vector<string>::iterator it = numIt->second.begin(); it != numIt->second.end(); it++) {
			// 				EH::Json::Value idJson;
			// 				//idJson["id"] = StringToInt(*it, error);
			// 				idJson["sn"] = *it;
			// 				array.append(idJson);
			// 			}
			// 			fieldinfo["deviceList"] = array;
			// 		} else {
			// 			fieldinfo["deviceList"].resize(0);//空数组
			// 		}
			// 	}
			// }else if(dev_model_id == DAIKINCentralACindoor_PID) {  //中央空调内机
			// 	for (map<string,KKChannelDev*>::iterator subIt = it->second->channelDevs.begin();subIt!= it->second->channelDevs.end(); subIt++){
			// 		HwCentralAcindoor* chanDev = (HwCentralAcindoor* )it->second->channelDevs[IntToString(StringToInt(subIt->second->channel,error))];
			// 		fieldinfo["On"] = chanDev->on ? "1":"0";
			// 		fieldinfo["Pattern"] = IntToString(chanDev->mode);
			// 		fieldinfo["Wind_num"] = chanDev->fan;
			// 		fieldinfo["Current_Temperature"] = IntToString(chanDev->current*10);
			// 		fieldinfo["Temperature"] = IntToString(chanDev->target*10);
			// 	}
			// }
//			LOGD("发送全部的设备信息 all devs infos %s.\n",Panel.toStyledString().c_str());
		}
	}else{
		LOGW("not found hw dev in local cache.\n");
		
		payload1["devices"].resize(0);//空数组
		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload1,respTopic1); 

		payload["devices"].resize(0);//空数组
		MQ_CCU_Adapter::GetInstance()->sendtoRoma(payload,respTopic2);  //推送新设备到Roma
		return 0;
	}

	} catch (exception &e) {
		LOGW("%s.\n", e.what());
	}
	return -1;
}
