Esempio n. 1
0
int CAclNet::EnableButton(BOOL bEnableEdit)
{
	if(bEnableEdit)
		m_bButtonFlags |= ACL_BUTTON_SHOW_EDIT_GROUP;
	else
		m_bButtonFlags &= ~ACL_BUTTON_SHOW_EDIT_GROUP;
	SendMessageEx(m_bButtonFlags);
	return 0;
}
Esempio n. 2
0
bool CNotificationHelper::CheckAndHandleDewPointNotification(
	const uint64_t Idx,
	const std::string &devicename,
	const float temp,
	const float dewpoint)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	char szTmp[600];
	std::string szExtraData = "|Name=" + devicename + "|Image=temp-0-5|";
	std::string notValue;

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable

	atime -= m_NotificationSensorInterval;

	std::string msg = "";

	std::string signdewpoint = Notification_Type_Desc(NTYPE_DEWPOINT, 1);

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if (itt->LastUpdate)
			TouchLastUpdate(itt->ID);
		if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true
		{
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 1)
				continue; //impossible
			std::string ntype = splitresults[0];

			if (ntype == signdewpoint)
			{
				//dewpoint
				if (temp <= dewpoint)
				{
					sprintf(szTmp, "%s Dew Point reached (%.1f degrees)", devicename.c_str(), temp);
					msg = szTmp;
					sprintf(szTmp, "%.1f", temp);
					notValue = szTmp;
					if (!itt->CustomMessage.empty())
						msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
					SendMessageEx(Idx, devicename, itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
					TouchNotification(itt->ID);
				}
			}
		}
	}
	return true;
}
Esempio n. 3
0
void CAclNet::Cancel()
{	
	if((m_bButtonFlags & ACL_BUTTON_CANCEL_MASK) != ACL_BUTTON_CANCEL_MASK) return;
	for(int i = 0; i < ACL_NET_TYPE_COUNT; i++)
		m_History[i].Cancel();
	ReadAllIp();
	ListAddIp();
	m_bButtonFlags &= ~ACL_BUTTON_SHOW_APPLY_GROUP;
	SendMessageEx(m_bButtonFlags);
}
Esempio n. 4
0
bool CNotificationBase::SendMessage(
	const uint64_t Idx,
	const std::string &Name,
	const std::string &Subject,
	const std::string &Text,
	const std::string &ExtraData,
	const bool bFromNotification)
{
	return SendMessageEx(Idx, Name, Subject, Text, std::string(""), 0, std::string(""), bFromNotification);
}
Esempio n. 5
0
bool CNotificationHelper::CheckAndHandleValueNotification(
	const uint64_t Idx,
	const std::string &DeviceName,
	const int value)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	char szTmp[600];
	std::string szExtraData = "|Name=" + DeviceName + "|";

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable
	atime -= m_NotificationSensorInterval;

	std::string msg = "";
	std::string notValue;

	std::string signvalue = Notification_Type_Desc(NTYPE_VALUE, 1);

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if (itt->LastUpdate)
			TouchLastUpdate(itt->ID);
		if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true
		{
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 2)
				continue; //impossible
			std::string ntype = splitresults[0];
			int svalue = static_cast<int>(atoi(splitresults[1].c_str()));

			if (ntype == signvalue)
			{
				if (value > svalue)
				{
					sprintf(szTmp, "%s is %d", DeviceName.c_str(), value);
					msg = szTmp;
					sprintf(szTmp, "%d", value);
					notValue = szTmp;
					if (!itt->CustomMessage.empty())
						msg = ParseCustomMessage(itt->CustomMessage, DeviceName, notValue);
					SendMessageEx(Idx, DeviceName, itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
					TouchNotification(itt->ID);
				}
			}
		}
	}
	return true;
}
Esempio n. 6
0
bool CNotificationHelper::SendMessage(
	const uint64_t Idx,
	const std::string &Name,
	const std::string &Subsystems,
	const std::string &Subject,
	const std::string &Text,
	const std::string &ExtraData,
	const int Priority,
	const std::string &Sound,
	const bool bFromNotification)
{
	return SendMessageEx(Idx, Name, Subsystems, Subject, Text, ExtraData, 0, std::string(""), bFromNotification);
}
Esempio n. 7
0
bool CNotificationHelper::CheckAndHandleNotification(
	const uint64_t Idx,
	const std::string &devicename,
	const _eNotificationTypes ntype,
	const std::string &message)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	std::vector<std::vector<std::string> > result;
	result = m_sql.safe_query("SELECT SwitchType, CustomImage FROM DeviceStatus WHERE (ID=%" PRIu64 ")", Idx);
	if (result.size() == 0)
		return false;

	std::string szExtraData = "|Name=" + devicename + "|SwitchType=" + result[0][0] + "|CustomImage=" + result[0][1] + "|";
	std::string notValue;

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable
	atime -= m_NotificationSensorInterval;

	std::string ltype = Notification_Type_Desc(ntype, 1);
	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if (itt->LastUpdate)
			TouchLastUpdate(itt->ID);
		std::vector<std::string> splitresults;
		StringSplit(itt->Params, ";", splitresults);
		if (splitresults.size() < 1)
			continue; //impossible
		std::string atype = splitresults[0];
		if (atype == ltype)
		{
			if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true
			{
				std::string msg = message;
				if (!itt->CustomMessage.empty())
					msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
				SendMessageEx(Idx, devicename, itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				TouchNotification(itt->ID);
			}
		}
	}
	return true;
}
Esempio n. 8
0
BOOL CAclApp::SendSet(BYTE bOptType)
{
	BOOL bIsChange = (m_History.m_bSet != theApp.m_AclFile.GetHeader()->bAppSet)
		|| (m_History.m_bQueryEx != theApp.m_AclFile.GetHeader()->bAppQueryEx);

	bIsChange ? m_bButtonFlags |= ACL_BUTTON_SHOW_APPLY_GROUP
		: m_bButtonFlags &= ~ACL_BUTTON_SHOW_APPLY_GROUP;

	BOOL bRet = SendMessageEx(m_bButtonFlags); 
	m_History.AddHistory(
		bOptType
		, m_bButtonFlags
		, NULL
		, NULL
		, m_History.m_bSet
		, m_History.m_bQueryEx);

	return bRet;
}
Esempio n. 9
0
void CAclNet::OnSelchangedNetTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	
	CString sText = m_Tree.GetItemText(m_Tree.GetSelectedItem());
	int nCount = sizeof(ACL_NET_TYPE)/sizeof(TCHAR*);
	int nIndex =TextToIndex(sText , ACL_NET_TYPE, nCount);
	int nType = GetType(nIndex);

	m_iTreeIndex = nIndex;
	m_bType = nType;

	//ListAddIp((PXACL_IP)theApp.m_AclFile.FindAcl(1, nType));
	ListAddIp();

	if(m_iTreeIndex == 0)
		m_bButtonFlags = 0;
	else
		m_bButtonFlags |= ACL_BUTTON_ENABLE_ONLY_ADD;
	SendMessageEx(m_bButtonFlags);

	*pResult = 0;
}
Esempio n. 10
0
void CAclNet::Edit()
{
	if((m_bButtonFlags & ACL_BUTTON_EDIT_MASK) != ACL_BUTTON_EDIT_MASK) return;
	if(m_iListIndex < 0) 
		return;

	CAclDialog dlg;
	dlg.SetDialog(ACL_CAPTION_EDIT, ACL_CAPTION_NET_EDIT, ACL_DIALOG_NET);
	CAclNetSet* pSet = dlg.GetAclNetSet();
	PXACL_IP pIp = pSet->GetIp();
	pSet->SetEdit(TRUE);

	*pIp = m_arIp[m_iTreeIndex][m_iListIndex];

	int iRet = dlg.DoModal();

	if(iRet == IDCANCEL || !pSet->IsChange()) return;

	ListAddOne(pIp, TRUE, TRUE, m_iListIndex);
	m_bButtonFlags |= ACL_BUTTON_SHOW_APPLY_GROUP;
	SendMessageEx(m_bButtonFlags);
	m_History[m_iTreeIndex].AddHistory(OPT_TYPE_EDIT, m_bButtonFlags, (char*)pIp, (char*)&m_arIp[m_iTreeIndex][m_iListIndex]);
	m_arIp[m_iTreeIndex][m_iListIndex] = *pIp;
}
Esempio n. 11
0
void CAclWeb::Add()
{
	if((m_bButtonFlags & ACL_BUTTON_ADD_MASK) != ACL_BUTTON_ADD_MASK) return;

	CAclDialog dlg;
	dlg.SetDialog(ACL_CAPTION_ADD, ACL_CAPTION_WEB_ADD, ACL_DIALOG_WEB);
	CAclWebSet* pAclWebSet = dlg.GetAclWebSet();
	PXACL_WEB pAcl = pAclWebSet->GetAcl();

	int nIndex = m_List.GetItemCount();
	if(nIndex == 0)
		pAcl->dwId = 1;
	else
		pAcl->dwId = atol(m_List.GetItemText(nIndex - 1, 0)) + 1;

	int iRet = dlg.DoModal();

	if(iRet == IDCANCEL) return;

	AddAcl(pAcl);
	m_bButtonFlags |= ACL_BUTTON_SHOW_APPLY_GROUP;
	m_History.AddHistory(OPT_TYPE_ADD, m_bButtonFlags, (char*)pAcl);
	SendMessageEx(m_bButtonFlags);
}
Esempio n. 12
0
static void GB_MsgHandle(SN_MSG *msg, GB_CONNECT_STATE *gb_cons)
{
	if (msg == NULL)
		return;

	switch (msg->msgId)
	{
		case MSG_ID_FWK_UPDATE_PARAM_IND:
		{
			stParamUpdateNotify *stNotify = (stParamUpdateNotify *)msg->para;
			switch(stNotify->prm_id)
			{
				case PRM_ID_GB_SIPD_CFG:
				{
					if(GB_Get_gGBConnStatus() == 0)
					{
						if(gb_cons->connfd > 0)
						{
							close(gb_cons->connfd);
							GB_ResetConState(gb_cons);
						}
						GB_Refresh_GBCfg();
					}
					else if((gb_cons->cur_state == GB_STATE_RUNNING && gb_cons->bUnRegister == 1)// 正在注销
						|| (GB_Get_gGBConnStatus() == 2) // 离线
						)  
					{
						if(gb_cons->connfd > 0)
						{
							close(gb_cons->connfd);
							GB_ResetConState(gb_cons);
						}
						GB_Set_gGBConnStatus(0);
						GB_Refresh_GBCfg();
					}
					else
					{
						gb_cons->bUnRegister = 1;
						GB_sipd_register(gb_cons, 1); // 不带认证的注销请求
						gb_cons->last_sendtime = get_cur_time()/1000;
						GB_Set_gGBConnStatus(0);
					}		
				}
				break;
				case PRM_ID_GB_SIPD_DEVMODE_CFG:
				{
					
				}
				break;
				
				default:
				break;
			}
		}
		break;
		
		case MSG_ID_FWK_REBOOT_REQ:
		case MSG_ID_FWK_POWER_OFF_REQ:
		case MSG_IF_FWK_IPCHANGE_IND:
		{
			PRM_GB_SIPD_CFG gb_cfg;
			
			TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d    msg->msgId=%d\n",__FUNCTION__,__LINE__,msg->msgId);

			SN_MEMSET(&gb_cfg,0,sizeof(gb_cfg));

			GB_Get_GBCfg(&gb_cfg);

			if(gb_cfg.enable != 1)
			{
				break;
			}
			
			if(GB_Get_gGBConnStatus() == 1)
			{
				gb_cons->bUnRegister = 1;
				GB_sipd_register(gb_cons, 1); // 不带认证的注销请求
				gb_cons->last_sendtime = get_cur_time()/1000;
			}
			else
			{
				if(gb_cons->connfd > 0)
				{
					close(gb_cons->connfd);
					GB_ResetConState(gb_cons);
				}

				GB_Set_gGBConnStatus(0);
			}

				gb_ipchange = 1;
				gb_ipchange_time = get_cur_time()/1000;
				//  退出国标模式
			
		}
		break;

		case MSG_ID_GB_GET_STATUS_REQ:
		{
			GB_GET_STATUS_RSP rsp;

			SN_MEMSET(&rsp,0,sizeof(rsp));

			rsp.result = 0;
			rsp.status = GB_Get_gGBConnStatus();

			SendMessageEx(msg->user, MOD_GB, msg->source, msg->xid, msg->thread, msg->msgId + 1, &rsp, sizeof(rsp));
		}
		break;
		
		default:
		{
			
		}
		break;
	}
	FreeMessage(&msg);
}
Esempio n. 13
0
int GB_Change_Mode(int Flag)
{
	PRM_SwitchChnInfo stNewSwitchChnInfo;
	int chn;
	PRM_Decode DecordeMode;
	PRM_POLLSCH_PLAN pollsch_plan;
	PRM_PREVIEW_CFG_EX preview_cfg;
	Layout_crtl_Req LayoutReq;
	PRM_GB_SIPD_DEVMODE_CFG DevModeCfg;


	SN_MEMSET(&DecordeMode, 0, sizeof(DecordeMode));
	SN_MEMSET(&pollsch_plan, 0, sizeof(pollsch_plan));
	SN_MEMSET(&preview_cfg, 0, sizeof(preview_cfg));	
	SN_MEMSET(&LayoutReq,0,sizeof(LayoutReq));
	SN_MEMSET(&DevModeCfg,0,sizeof(DevModeCfg));
	

		if (ERROR == GetParameter(PRM_ID_DECODEMODE_CFG, NULL, &DecordeMode, sizeof(PRM_Decode), 1, 
			SUPER_USER_ID, NULL))
		{
			printf("%s line=%d GetParameter PRM_ID_DECODEMODE_CFG err\n", __FUNCTION__, __LINE__);
			return -1;
		}

		if (ERROR == GetParameter(PRM_ID_GB_SIPD_DEVMODE_CFG, NULL, &DevModeCfg, sizeof(PRM_GB_SIPD_DEVMODE_CFG), 1, 
			SUPER_USER_ID, NULL))
		{
			printf("%s line=%d GetParameter PRM_ID_GB_SIPD_DEVMODE_CFG err\n", __FUNCTION__, __LINE__);
			return -1;
		}
	if(Flag == 1)
	{
		printf("Enter GB28181 Mode\n");
		if(DecordeMode.DecodeMode == SwitchDecode) // 主动解码
		{
			// 断开通道连接
			for(chn = 0; chn < GB_TOTAL_CHN; chn++)
			{
				SN_MEMSET(&stNewSwitchChnInfo, 0, sizeof(stNewSwitchChnInfo));
				
				if (ERROR == GetParameter(PRM_ID_SWITCHCHN_CFG, NULL, 
					&stNewSwitchChnInfo, sizeof(PRM_SwitchChnInfo), chn+1, 
					SUPER_USER_ID, NULL))
				{
					printf("%s line=%d GetParameter err\n", __FUNCTION__, __LINE__);
					continue;
				}
			
				if(stNewSwitchChnInfo.Enable == 1)
				{
					DevModeCfg.ChnEnable[chn] = 1;
					stNewSwitchChnInfo.Enable = 0;
					GB_UpdateParam(PRM_ID_SWITCHCHN_CFG,&stNewSwitchChnInfo,sizeof(stNewSwitchChnInfo),chn+1);
				}
			}


			//  单画面显示
			if (ERROR == GetParameter(PRM_ID_POLLSCH_PLAN, NULL, &pollsch_plan, sizeof(PRM_POLLSCH_PLAN), 1, 
				SUPER_USER_ID, NULL))
			{
				printf("%s line=%d GetParameter PRM_ID_POLLSCH_PLAN err\n", __FUNCTION__, __LINE__);
				return -1;
			}

			if(pollsch_plan.EnablePollPlan == 1)  //  多画面轮巡
			{
				DevModeCfg.PollPlan = 1;
				pollsch_plan.EnablePollPlan = 0; //  关闭多画面轮巡计划
				GB_UpdateParam(PRM_ID_POLLSCH_PLAN,&pollsch_plan,sizeof(pollsch_plan),1);
			}

			LayoutReq.mode = SingleScene;
			LayoutReq.flag = 1; /*国标模式下,切换为被动解码*/
			SendMessageEx(SUPER_USER_ID, MOD_GB, MOD_SCM, 0, 0, MSG_ID_PRV_LAYOUT_CTRL_REQ, &LayoutReq, sizeof(Layout_crtl_Req));
			printf("%s Line %d ---------> here\n",__func__,__LINE__);
		}
		else if(DecordeMode.DecodeMode == PassiveDecode) // 被动解码
		{
			int layout_mode;

			//  断开通道连接
		
			layout_mode = 1; // 被动解码下的单画面;
			SendMessageEx (SUPER_USER_ID, MOD_GB, MOD_SCM, 0, 0, MSG_ID_SCM_PAS_LAYOUT_IND, &layout_mode, sizeof(layout_mode));
		}
		else
		{
			
		}
		
	}
	if(Flag == 0)
	{

		
		if(DecordeMode.DecodeMode == SwitchDecode) // 主动解码
		{
			for(chn = 0; chn < GB_TOTAL_CHN; chn++)
			{
				if(DevModeCfg.ChnEnable[chn] == 1)
				{
					SN_MEMSET(&stNewSwitchChnInfo, 0, sizeof(stNewSwitchChnInfo));
					if (ERROR == GetParameter(PRM_ID_SWITCHCHN_CFG, NULL, 
						&stNewSwitchChnInfo, sizeof(PRM_SwitchChnInfo), chn+1, 
						SUPER_USER_ID, NULL))
					{
						printf("%s line=%d GetParameter err\n", __FUNCTION__, __LINE__);
						continue;
					}
					DevModeCfg.ChnEnable[chn] = 0;
					stNewSwitchChnInfo.Enable = 1;
					GB_UpdateParam(PRM_ID_SWITCHCHN_CFG,&stNewSwitchChnInfo,sizeof(stNewSwitchChnInfo),chn+1);
				}
			}
			if(DevModeCfg.PollPlan == 1)
			{
				if (ERROR == GetParameter(PRM_ID_POLLSCH_PLAN, NULL, &pollsch_plan, sizeof(PRM_POLLSCH_PLAN), 1, 
					SUPER_USER_ID, NULL))
				{
					printf("%s line=%d GetParameter PRM_ID_POLLSCH_PLAN err\n", __FUNCTION__, __LINE__);
					return -1;
				}

				if(pollsch_plan.EnablePollPlan == 0)  //  多画面轮巡
				{
					DevModeCfg.PollPlan = 0;
					pollsch_plan.EnablePollPlan = 1; //  打开多画面轮巡计划
					GB_UpdateParam(PRM_ID_POLLSCH_PLAN,&pollsch_plan,sizeof(pollsch_plan),1);
				}
			}
		}
		else if(DecordeMode.DecodeMode == PassiveDecode) // 被动解码
		{
				
		}
		else
		{
			
		}
			
	}
	GB_UpdateParam(PRM_ID_GB_SIPD_DEVMODE_CFG,&DevModeCfg,sizeof(DevModeCfg),1);
	return 0;
}
Esempio n. 14
0
bool CNotificationHelper::CheckAndHandleSwitchNotification(
	const unsigned long long Idx,
	const std::string &devicename,
	const _eNotificationTypes ntype,
	const int llevel)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;
	std::vector<std::vector<std::string> > result;

	result = m_sql.safe_query("SELECT SwitchType, CustomImage, Options FROM DeviceStatus WHERE (ID=%llu)",
		Idx);
	if (result.size() == 0)
		return false;
	_eSwitchType switchtype = (_eSwitchType)atoi(result[0][0].c_str());
	std::string szExtraData = "|Name=" + devicename + "|SwitchType=" + result[0][0] + "|CustomImage=" + result[0][1] + "|";
	std::string sOptions = result[0][2].c_str();

	std::string msg = "";

	std::string ltype = Notification_Type_Desc(ntype, 1);

	time_t atime = mytime(NULL);
	atime -= m_NotificationSwitchInterval;

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true
		{
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 1)
				continue; //impossible
			std::string atype = splitresults[0];

			bool bSendNotification = false;

			if (atype == ltype)
			{
				msg = devicename;
				if (ntype == NTYPE_SWITCH_ON)
				{
					if (splitresults.size() < 3)
						continue; //impossible
					bool bWhenEqual = (splitresults[1] == "=");
					int iLevel = atoi(splitresults[2].c_str());
					if (!bWhenEqual || iLevel < 10 || iLevel > 100)
						continue; //invalid

					if (llevel == iLevel) 
					{
						bSendNotification = true;
						std::string sLevel = boost::lexical_cast<std::string>(llevel);
						szExtraData += "Status=Level " + sLevel + "|";

						if (switchtype == STYPE_Selector)
						{
							std::map<std::string, std::string> options = m_sql.BuildDeviceOptions(sOptions);
							std::string levelNames = options["LevelNames"];
							std::vector<std::string> splitresults;
							StringSplit(levelNames, "|", splitresults);
							msg += " >> " + splitresults[(llevel / 10)];
						}
						else
							msg += " >> LEVEL " + sLevel;
					}
				}
				else 
				{
					bSendNotification = true;
					szExtraData += "Status=Off|";
					msg += " >> OFF";
				}
			}
			if (bSendNotification)
			{
				if (!itt->CustomMessage.empty())
					msg = itt->CustomMessage;
				SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				TouchNotification(itt->ID);
			}
		}
	}
	return true;
}
Esempio n. 15
0
bool CNotificationHelper::SendMessage(const std::string &subsystems, const std::string &Subject, const std::string &Text, const std::string &ExtraData, const bool bFromNotification)
{
	return SendMessageEx(subsystems, Subject, Text, ExtraData, 0, std::string(""), bFromNotification);
}
Esempio n. 16
0
bool CNotificationHelper::CheckAndHandleSwitchNotification(
	const unsigned long long Idx,
	const std::string &devicename,
	const _eNotificationTypes ntype)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	std::vector<std::vector<std::string> > result;

	result = m_sql.safe_query("SELECT SwitchType, CustomImage FROM DeviceStatus WHERE (ID=%llu)",
		Idx);
	if (result.size() == 0)
		return false;
	_eSwitchType switchtype = (_eSwitchType)atoi(result[0][0].c_str());
	std::string szExtraData = "|Name=" + devicename + "|SwitchType=" + result[0][0] + "|CustomImage=" + result[0][1] + "|";

	std::string msg = "";

	std::string ltype = Notification_Type_Desc(ntype, 1);

	time_t atime = mytime(NULL);
	atime -= m_NotificationSwitchInterval;

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true
		{
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 1)
				continue; //impossible
			std::string atype = splitresults[0];

			bool bSendNotification = false;

			if (atype == ltype)
			{
				bSendNotification = true;
				msg = devicename;
				if (ntype == NTYPE_SWITCH_ON)
				{
					szExtraData += "Status=On|";
					switch (switchtype)
					{
					case STYPE_Doorbell:
						msg += " pressed";
						break;
					case STYPE_Contact:
						msg += " Open";
						szExtraData += "Image=contact48_open|";
						break;
					case STYPE_DoorLock:
						msg += " Open";
						szExtraData += "Image=door48open|";
						break;
					case STYPE_Motion:
						msg += " movement detected";
						break;
					case STYPE_SMOKEDETECTOR:
						msg += " ALARM/FIRE !";
						break;
					default:
						msg += " >> ON";
						break;
					}

				}
				else {
					szExtraData += "Status=Off|";
					switch (switchtype)
					{
					case STYPE_DoorLock:
					case STYPE_Contact:
						msg += " Closed";
						break;
					default:
						msg += " >> OFF";
						break;
					}
				}
			}
			if (bSendNotification)
			{
				if (!itt->CustomMessage.empty())
					msg = itt->CustomMessage;
				SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				TouchNotification(itt->ID);
			}
		}
	}
	return true;
}
Esempio n. 17
0
bool CNotificationHelper::CheckAndHandleNotification(
	const unsigned long long Idx,
	const std::string &devicename,
	const unsigned char devType,
	const unsigned char subType,
	const _eNotificationTypes ntype,
	const float mvalue)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	char szTmp[600];

	double intpart;
	std::string pvalue;
	if (modf(mvalue, &intpart) == 0)
		sprintf(szTmp, "%.0f", mvalue);
	else
		sprintf(szTmp, "%.1f", mvalue);
	pvalue = szTmp;

	std::vector<std::vector<std::string> > result;
	result = m_sql.safe_query("SELECT SwitchType FROM DeviceStatus WHERE (ID=%llu)", Idx);
	if (result.size() == 0)
		return false;
	std::string szExtraData = "|Name=" + devicename + "|SwitchType=" + result[0][0] + "|";

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable
	atime -= m_NotificationSensorInterval;

	std::string msg = "";

	std::string ltype = Notification_Type_Desc(ntype, 0);
	std::string nsign = Notification_Type_Desc(ntype, 1);
	std::string label = Notification_Type_Label(ntype);

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true
		{
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 3)
				continue; //impossible
			std::string ntype = splitresults[0];
			bool bWhenIsGreater = (splitresults[1] == ">");
			float svalue = static_cast<float>(atof(splitresults[2].c_str()));

			bool bSendNotification = false;

			if (ntype == nsign)
			{
				if (bWhenIsGreater)
				{
					if (mvalue > svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s %s is %s %s",
							devicename.c_str(),
							ltype.c_str(),
							pvalue.c_str(),
							label.c_str()
							);
						msg = szTmp;
					}
				}
				else
				{
					if (mvalue < svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s %s is %s %s",
							devicename.c_str(),
							ltype.c_str(),
							pvalue.c_str(),
							label.c_str()
							);
						msg = szTmp;
					}
				}
			}
			if (bSendNotification)
			{
				if (!itt->CustomMessage.empty())
					msg = itt->CustomMessage;
				SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				TouchNotification(itt->ID);
			}
		}
	}
	return true;
}
Esempio n. 18
0
bool CNotificationHelper::CheckAndHandleTempHumidityNotification(
	const unsigned long long Idx,
	const std::string &devicename,
	const float temp,
	const int humidity,
	const bool bHaveTemp,
	const bool bHaveHumidity)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	char szTmp[600];

	std::string szExtraData = "|Name=" + devicename + "|";

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable

	atime -= m_NotificationSensorInterval;

	std::string msg = "";

	std::string signtemp = Notification_Type_Desc(NTYPE_TEMPERATURE, 1);
	std::string signhum = Notification_Type_Desc(NTYPE_HUMIDITY, 1);

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true
		{
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 3)
				continue; //impossible
			std::string ntype = splitresults[0];
			bool bWhenIsGreater = (splitresults[1] == ">");
			float svalue = static_cast<float>(atof(splitresults[2].c_str()));
			if (m_sql.m_tempunit == TEMPUNIT_F)
			{
				//Convert to Celsius
				svalue = (svalue / 1.8f) - 32.0f;
			}

			bool bSendNotification = false;

			if ((ntype == signtemp) && (bHaveTemp))
			{
				//temperature
				if (temp > 30.0) szExtraData += "Image=temp-gt-30|";
				else if (temp > 25.0) szExtraData += "Image=temp-25-30|";
				else if (temp > 20.0) szExtraData += "Image=temp-20-25|";
				else if (temp > 15.0) szExtraData += "Image=temp-15-20|";
				else if (temp > 10.0) szExtraData += "Image=temp-10-15|";
				else if (temp > 5.0) szExtraData += "Image=temp-5-10|";
				else szExtraData += "Image=temp48|";
				if (bWhenIsGreater)
				{
					if (temp > svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s temperature is %.1f degrees", devicename.c_str(), temp);
						msg = szTmp;
					}
				}
				else
				{
					if (temp < svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s temperature is %.1f degrees", devicename.c_str(), temp);
						msg = szTmp;
					}
				}
			}
			else if ((ntype == signhum) && (bHaveHumidity))
			{
				//humanity
				szExtraData += "Image=moisture48|";
				if (bWhenIsGreater)
				{
					if (humidity > svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s Humidity is %d %%", devicename.c_str(), humidity);
						msg = szTmp;
					}
				}
				else
				{
					if (humidity < svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s Humidity is %d %%", devicename.c_str(), humidity);
						msg = szTmp;
					}
				}
			}
			if (bSendNotification)
			{
				if (!itt->CustomMessage.empty())
					msg = itt->CustomMessage;
				SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				TouchNotification(itt->ID);
			}
		}
	}
	return true;
}
Esempio n. 19
0
bool CNotificationHelper::CheckAndHandleAmpere123Notification(
	const uint64_t Idx,
	const std::string &devicename,
	const float Ampere1,
	const float Ampere2,
	const float Ampere3)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	char szTmp[600];

	std::string szExtraData = "|Name=" + devicename + "|Image=current48|";

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable
	atime -= m_NotificationSensorInterval;

	std::string msg = "";

	std::string notValue;

	std::string signamp1 = Notification_Type_Desc(NTYPE_AMPERE1, 1);
	std::string signamp2 = Notification_Type_Desc(NTYPE_AMPERE2, 1);
	std::string signamp3 = Notification_Type_Desc(NTYPE_AMPERE3, 1);

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if (itt->LastUpdate)
			TouchLastUpdate(itt->ID);

		if ((atime >= itt->LastSend) || (itt->SendAlways) || (!itt->CustomMessage.empty())) //emergency always goes true
		{
			std::string recoverymsg;
			bool bRecoveryMessage = false;
			bRecoveryMessage = CustomRecoveryMessage(itt->ID, recoverymsg, true);
			if ((atime < itt->LastSend) && (!itt->SendAlways) && (!bRecoveryMessage))
				continue;
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 3)
				continue; //impossible
			std::string ntype = splitresults[0];
			std::string custommsg;
			std::string ltype;
			float svalue = static_cast<float>(atof(splitresults[2].c_str()));
			float ampere;
			bool bSendNotification = false;
			bool bCustomMessage = false;
			bCustomMessage = CustomRecoveryMessage(itt->ID, custommsg, false);

			if (ntype == signamp1)
			{
				ampere = Ampere1;
				ltype = Notification_Type_Desc(NTYPE_AMPERE1, 0);
			}
			else if (ntype == signamp2)
			{
				ampere = Ampere2;
				ltype = Notification_Type_Desc(NTYPE_AMPERE2, 0);
			}
			else if (ntype == signamp3)
			{
				ampere = Ampere3;
				ltype = Notification_Type_Desc(NTYPE_AMPERE3, 0);
			}
			bSendNotification = ApplyRule(splitresults[1], (ampere == svalue), (ampere < svalue));
			if (bSendNotification && (!bRecoveryMessage || itt->SendAlways))
			{
				sprintf(szTmp, "%s %s is %.1f Ampere [%s %.1f Ampere]", devicename.c_str(), ltype.c_str(), ampere, splitresults[1].c_str(), svalue);
				msg = szTmp;
				sprintf(szTmp, "%.1f", ampere);
				notValue = szTmp;
			}
			else if (!bSendNotification && bRecoveryMessage)
			{
				bSendNotification = true;
				msg = recoverymsg;
				std::string clearstr = "!";
				CustomRecoveryMessage(itt->ID, clearstr, true);
			}
			else
			{
				bSendNotification = false;
			}
			if (bSendNotification)
			{
				if (bCustomMessage && !bRecoveryMessage)
					msg = ParseCustomMessage(custommsg, devicename, notValue);
				SendMessageEx(Idx, devicename, itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				if (!bRecoveryMessage)
				{
					TouchNotification(itt->ID);
					CustomRecoveryMessage(itt->ID, msg, true);
				}
			}
		}
	}
	return true;
}
Esempio n. 20
0
bool CNotificationHelper::CheckAndHandleNotification(
	const uint64_t Idx,
	const std::string &devicename,
	const unsigned char devType,
	const unsigned char subType,
	const _eNotificationTypes ntype,
	const float mvalue)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	char szTmp[600];

	double intpart;
	std::string pvalue;
	if (modf(mvalue, &intpart) == 0)
		sprintf(szTmp, "%.0f", mvalue);
	else
		sprintf(szTmp, "%.1f", mvalue);
	pvalue = szTmp;

	std::vector<std::vector<std::string> > result;
	result = m_sql.safe_query("SELECT SwitchType FROM DeviceStatus WHERE (ID=%" PRIu64 ")", Idx);
	if (result.size() == 0)
		return false;
	std::string szExtraData = "|Name=" + devicename + "|SwitchType=" + result[0][0] + "|";

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable
	atime -= m_NotificationSensorInterval;

	std::string msg = "";

	std::string ltype = Notification_Type_Desc(ntype, 0);
	std::string nsign = Notification_Type_Desc(ntype, 1);
	std::string label = Notification_Type_Label(ntype);

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if (itt->LastUpdate)
			TouchLastUpdate(itt->ID);

		if ((atime >= itt->LastSend) || (itt->SendAlways) || (!itt->CustomMessage.empty())) //emergency always goes true
		{
			std::string recoverymsg;
			bool bRecoveryMessage = false;
			bRecoveryMessage = CustomRecoveryMessage(itt->ID, recoverymsg, true);
			if ((atime < itt->LastSend) && (!itt->SendAlways) && (!bRecoveryMessage))
				continue;
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 3)
				continue; //impossible
			std::string ntype = splitresults[0];
			std::string custommsg;
			float svalue = static_cast<float>(atof(splitresults[2].c_str()));
			bool bSendNotification = false;
			bool bCustomMessage = false;
			bCustomMessage = CustomRecoveryMessage(itt->ID, custommsg, false);

			if (ntype == nsign)
			{
				bSendNotification = ApplyRule(splitresults[1], (mvalue == svalue), (mvalue < svalue));
				if (bSendNotification && (!bRecoveryMessage || itt->SendAlways))
				{
					sprintf(szTmp, "%s %s is %s %s [%s %.1f %s]", devicename.c_str(), ltype.c_str(), pvalue.c_str(), label.c_str(), splitresults[1].c_str(), svalue, label.c_str());
					msg = szTmp;
				}
				else if (!bSendNotification && bRecoveryMessage)
				{
					bSendNotification = true;
					msg = recoverymsg;
					std::string clearstr = "!";
					CustomRecoveryMessage(itt->ID, clearstr, true);
				}
				else
				{
					bSendNotification = false;
				}
			}
			if (bSendNotification)
			{
				if (bCustomMessage && !bRecoveryMessage)
					msg = ParseCustomMessage(custommsg, devicename, pvalue);
				SendMessageEx(Idx, devicename, itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				if (!bRecoveryMessage)
				{
					TouchNotification(itt->ID);
					CustomRecoveryMessage(itt->ID, msg, true);
				}
			}
		}
	}
	return true;
}
Esempio n. 21
0
bool CNotificationHelper::CheckAndHandleAmpere123Notification(
	const unsigned long long Idx,
	const std::string &devicename,
	const float Ampere1,
	const float Ampere2,
	const float Ampere3)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	char szTmp[600];

	std::string szExtraData = "|Name=" + devicename + "|Image=current48|";

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable
	atime -= m_NotificationSensorInterval;

	std::string msg = "";

	std::string signamp1 = Notification_Type_Desc(NTYPE_AMPERE1, 1);
	std::string signamp2 = Notification_Type_Desc(NTYPE_AMPERE2, 2);
	std::string signamp3 = Notification_Type_Desc(NTYPE_AMPERE3, 3);

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true
		{
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 3)
				continue; //impossible
			std::string ntype = splitresults[0];
			bool bWhenIsGreater = (splitresults[1] == ">");
			float svalue = static_cast<float>(atof(splitresults[2].c_str()));

			bool bSendNotification = false;

			if (ntype == signamp1)
			{
				//Ampere1
				if (bWhenIsGreater)
				{
					if (Ampere1 > svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s Ampere1 is %.1f Ampere", devicename.c_str(), Ampere1);
						msg = szTmp;
					}
				}
				else
				{
					if (Ampere1 < svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s Ampere1 is %.1f Ampere", devicename.c_str(), Ampere1);
						msg = szTmp;
					}
				}
			}
			else if (ntype == signamp2)
			{
				//Ampere2
				if (bWhenIsGreater)
				{
					if (Ampere2 > svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s Ampere2 is %.1f Ampere", devicename.c_str(), Ampere2);
						msg = szTmp;
					}
				}
				else
				{
					if (Ampere2 < svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s Ampere2 is %.1f Ampere", devicename.c_str(), Ampere2);
						msg = szTmp;
					}
				}
			}
			else if (ntype == signamp3)
			{
				//Ampere3
				if (bWhenIsGreater)
				{
					if (Ampere3 > svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s Ampere3 is %.1f Ampere", devicename.c_str(), Ampere3);
						msg = szTmp;
					}
				}
				else
				{
					if (Ampere3 < svalue)
					{
						bSendNotification = true;
						sprintf(szTmp, "%s Ampere3 is %.1f Ampere", devicename.c_str(), Ampere3);
						msg = szTmp;
					}
				}
			}
			if (bSendNotification)
			{
				if (!itt->CustomMessage.empty())
					msg = itt->CustomMessage;
				SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				TouchNotification(itt->ID);
			}
		}
	}
	return true;
}
Esempio n. 22
0
bool CNotificationHelper::CheckAndHandleTempHumidityNotification(
	const uint64_t Idx,
	const std::string &devicename,
	const float temp,
	const int humidity,
	const bool bHaveTemp,
	const bool bHaveHumidity)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	char szTmp[600];
	std::string notValue;

	std::string szExtraData = "|Name=" + devicename + "|";

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable

	atime -= m_NotificationSensorInterval;

	std::string msg = "";

	std::string ltemp = Notification_Type_Label(NTYPE_TEMPERATURE);
	std::string signtemp = Notification_Type_Desc(NTYPE_TEMPERATURE, 1);
	std::string signhum = Notification_Type_Desc(NTYPE_HUMIDITY, 1);

	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if (itt->LastUpdate)
			TouchLastUpdate(itt->ID);

		if ((atime >= itt->LastSend) || (itt->SendAlways) || (!itt->CustomMessage.empty())) //emergency always goes true
		{
			std::string recoverymsg;
			bool bRecoveryMessage = false;
			bRecoveryMessage = CustomRecoveryMessage(itt->ID, recoverymsg, true);
			if ((atime < itt->LastSend) && (!itt->SendAlways) && (!bRecoveryMessage))
				continue;
			std::vector<std::string> splitresults;
			StringSplit(itt->Params, ";", splitresults);
			if (splitresults.size() < 3)
				continue; //impossible
			std::string ntype = splitresults[0];
			std::string custommsg;
			float svalue = static_cast<float>(atof(splitresults[2].c_str()));
			bool bSendNotification = false;
			bool bCustomMessage = false;
			bCustomMessage = CustomRecoveryMessage(itt->ID, custommsg, false);

			if (m_sql.m_tempunit == TEMPUNIT_F)
			{
				//Convert to Celsius
				svalue = (svalue / 1.8f) - 32.0f;
			}
			if ((ntype == signtemp) && (bHaveTemp))
			{
				//temperature
				if (temp > 30.0) szExtraData += "Image=temp-gt-30|";
				else if (temp > 25.0) szExtraData += "Image=temp-25-30|";
				else if (temp > 20.0) szExtraData += "Image=temp-20-25|";
				else if (temp > 15.0) szExtraData += "Image=temp-15-20|";
				else if (temp > 10.0) szExtraData += "Image=temp-10-15|";
				else if (temp > 5.0) szExtraData += "Image=temp-5-10|";
				else szExtraData += "Image=temp48|";
				bSendNotification = ApplyRule(splitresults[1], (temp == svalue), (temp < svalue));
				if (bSendNotification && (!bRecoveryMessage || itt->SendAlways))
				{
					sprintf(szTmp, "%s temperature is %.1f %s [%s %.1f %s]", devicename.c_str(), temp, ltemp.c_str(), splitresults[1].c_str(), svalue, ltemp.c_str());
					msg = szTmp;
					sprintf(szTmp, "%.1f", temp);
					notValue = szTmp;
				}
				else if (!bSendNotification && bRecoveryMessage)
				{
					bSendNotification = true;
					msg = recoverymsg;
					std::string clearstr = "!";
					CustomRecoveryMessage(itt->ID, clearstr, true);
				}
				else
				{
					bSendNotification = false;
				}
			}
			else if ((ntype == signhum) && (bHaveHumidity))
			{
				//humidity
				szExtraData += "Image=moisture48|";
				bSendNotification = ApplyRule(splitresults[1], (humidity == svalue), (humidity < svalue));
				if (bSendNotification && (!bRecoveryMessage || itt->SendAlways))
				{
					sprintf(szTmp, "%s Humidity is %d %% [%s %.0f %%]", devicename.c_str(), humidity, splitresults[1].c_str(), svalue);
					msg = szTmp;
					sprintf(szTmp, "%d", humidity);
					notValue = szTmp;
				}
				else if (!bSendNotification && bRecoveryMessage)
				{
					bSendNotification = true;
					msg = recoverymsg;
					std::string clearstr = "!";
					CustomRecoveryMessage(itt->ID, clearstr, true);
				}
				else
				{
					bSendNotification = false;
				}
			}
			if (bSendNotification)
			{
				if (bCustomMessage && !bRecoveryMessage)
					msg = ParseCustomMessage(custommsg, devicename, notValue);
				SendMessageEx(Idx, devicename, itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				if (!bRecoveryMessage)
				{
					TouchNotification(itt->ID);
					CustomRecoveryMessage(itt->ID, msg, true);
				}
			}
		}
	}
	return true;
}
Esempio n. 23
0
void CNotificationHelper::CheckAndHandleLastUpdateNotification()
{
	if (m_notifications.size() < 1)
		return;

	time_t atime = mytime(NULL);
	atime -= m_NotificationSensorInterval;
	std::map<uint64_t, std::vector<_tNotification> >::const_iterator itt;

	for (itt = m_notifications.begin(); itt != m_notifications.end(); ++itt)
	{
		std::vector<_tNotification>::const_iterator itt2;
		for (itt2 = itt->second.begin(); itt2 != itt->second.end(); ++itt2)
		{
			if (((atime >= itt2->LastSend) || (itt2->SendAlways) || (!itt2->CustomMessage.empty())) && (itt2->LastUpdate)) //emergency always goes true
			{
				std::vector<std::string> splitresults;
				StringSplit(itt2->Params, ";", splitresults);
				if (splitresults.size() < 3)
					continue;
				std::string ttype = Notification_Type_Desc(NTYPE_LASTUPDATE, 1);
				if (splitresults[0] == ttype)
				{
					std::string recoverymsg;
					bool bRecoveryMessage = false;
					bRecoveryMessage = CustomRecoveryMessage(itt2->ID, recoverymsg, true);
					if ((atime < itt2->LastSend) && (!itt2->SendAlways) && (!bRecoveryMessage))
						continue;
					extern time_t m_StartTime;
					time_t btime = mytime(NULL);
					std::string msg;
					std::string szExtraData;
					std::string custommsg;
					uint64_t Idx = itt->first;
					int SensorTimeOut = atoi(splitresults[2].c_str());  // minutes
					int diff = (int)round(difftime(btime, itt2->LastUpdate));
					bool bStartTime = (difftime(btime, m_StartTime) < SensorTimeOut*60);
					bool bSendNotification = ApplyRule(splitresults[1], (diff == SensorTimeOut*60), (diff < SensorTimeOut*60));
					bool bCustomMessage = false;
					bCustomMessage = CustomRecoveryMessage(itt2->ID, custommsg, false);

					if (bSendNotification && !bStartTime && (!bRecoveryMessage || itt2->SendAlways))
					{
						std::vector<std::vector<std::string> > result;
						result = m_sql.safe_query("SELECT SwitchType FROM DeviceStatus WHERE (ID=%" PRIu64 ")", Idx);
						if (result.size() == 0)
							continue;
						szExtraData = "|Name=" + itt2->DeviceName + "|SwitchType=" + result[0][0] + "|";
						std::string ltype = Notification_Type_Desc(NTYPE_LASTUPDATE, 0);
						std::string label = Notification_Type_Label(NTYPE_LASTUPDATE);
						char szDate[50];
						char szTmp[300];
						struct tm ltime;
						localtime_r(&itt2->LastUpdate,&ltime);
						sprintf(szDate, "%04d-%02d-%02d %02d:%02d:%02d", ltime.tm_year + 1900, ltime.tm_mon + 1, ltime.tm_mday,
							ltime.tm_hour, ltime.tm_min, ltime.tm_sec);
						sprintf(szTmp,"Sensor %s %s: %s [%s %d %s]", itt2->DeviceName.c_str(), ltype.c_str(), szDate,
							splitresults[1].c_str(), SensorTimeOut, label.c_str());
						msg = szTmp;
					}
					else if (!bSendNotification && bRecoveryMessage)
					{
						bSendNotification = true;
						msg = recoverymsg;
						std::string clearstr = "!";
						CustomRecoveryMessage(itt2->ID, clearstr, true);
					}
					else
					{
						bSendNotification = false;
					}
					if (bSendNotification)
					{
						if (bCustomMessage && !bRecoveryMessage)
							msg = ParseCustomMessage(custommsg, itt2->DeviceName, "");
						SendMessageEx(Idx, itt2->DeviceName, itt2->ActiveSystems, msg, msg, szExtraData, itt2->Priority, std::string(""), true);
						if (!bRecoveryMessage)
						{
							TouchNotification(itt2->ID);
							CustomRecoveryMessage(itt2->ID, msg, true);
						}
					}
				}
			}
		}
	}
}