/**
 * 应用程序源码文件
 */
#ifndef STT_HMIAPP_CPP_
#define STT_HMIAPP_CPP_

/*********************
 *   头文件
 *********************/
#include "HmiApp.h"
/*PAGES_HEAD_BEGIN*/
#include "pages/Frm02.h"
#include "pages/Frm03.h"
#include "pages/Frm06.h"
#include "pages/Frm07.h"
#include "pages/Frm12.h"
#include "pages/Frm13.h"
#include "pages/Frm16.h"
#include "pages/Frm19.h"
/*PAGES_HEAD_END*/

using namespace stt;

/********************************
 *
 *  应用程序入口
 *
 *  注意：IDE自动生成，用户勿修改
 *
 ********************************/
IApplication * AppMain(IRuntime* env, char **argv){
	return new HmiApp(env);
}

string getAppArgs() {
	return "{\"r\":0}";
}

/********************************
 *
 *  应用程序类
 *
 *  注意：用户可添加代码
 *
 ********************************/
HmiApp::HmiApp(IRuntime * rt) : HmiAppBase(rt) {
}

HmiApp::~HmiApp() {
}

/********************************
 *
 *  应用构建前调用此函数
 *
 *  注意：用户可添加代码
 *
 ********************************/
void HmiApp::onInit(){
	//用户在此添加客户化代码
}

/********************************
 *
 *  应用构建函数
 *
 *  注意：IDE自动生成，用户勿修改
 *
 ********************************/
void HmiApp::construct() {
	//注册字体文件
	fm->registerFontFile("文泉驿微米黑", "./fnt/wenquanyiweimihei.ttf");
	//设备注册
	dm->addDevice("Modbus/TCP_按分区", R"({"seqFloat":"2","period":"100","dll":"ModBusDriver","maxReadLen":"120","DeviceId":"Modbus/TCP_按分区","seqInt32":"2","maxWriteLen":"120","maxAddrInterval":"5","issim":"true","coding":"0","seqAsc":"0","comDelay":"1200","port":"502","StationNo":"1","IsQueue":"true","seqLong":"0","addr":"127.0.0.1","Protocol":"ModbusTcp","if":"ETHNET","seqInt16":"0","framDelay":"4"})");
	dm->addDevice("Modbus/TCP_按分区", R"({"seqFloat":"2","period":"100","dll":"ModBusDriver","maxReadLen":"120","DeviceId":"Modbus/TCP_按分区","seqInt32":"2","maxWriteLen":"120","maxAddrInterval":"5","issim":"false","coding":"0","seqAsc":"0","comDelay":"1200","port":"502","StationNo":"1","IsQueue":"true","seqLong":"0","addr":"192.168.1.10","Protocol":"ModbusTcp","if":"ETHNET","seqInt16":"0","framDelay":"4"})");
	//设备变量
	vm->add("样气压力", DataType::D_FLOAT, R"({"dvc":"Modbus/TCP_按分区","a":"0","r":"1","c":"[4区]输出寄存器","t":"0","id":"v2","l":"0"})");
	vm->add("载气压力", DataType::D_FLOAT, R"({"dvc":"Modbus/TCP_按分区","a":"2","r":"1","c":"[4区]输出寄存器","t":"0","id":"v3","l":"0"})");
	vm->add("CO2浓度", DataType::D_FLOAT, R"({"dvc":"Modbus/TCP_按分区","a":"4","r":"1","c":"[4区]输出寄存器","t":"0","id":"v21","l":"0"})");
	vm->add("可燃气体浓度", DataType::D_FLOAT, R"({"dvc":"Modbus/TCP_按分区","a":"6","r":"1","c":"[4区]输出寄存器","t":"0","id":"v33","l":"0"})");
	vm->add("进样压力", DataType::D_FLOAT, R"({"dvc":"Modbus/TCP_按分区","a":"8","r":"1","c":"[4区]输出寄存器","t":"0","id":"v34","l":"0"})");
	vm->add("环境温度", DataType::D_FLOAT, R"({"dvc":"Modbus/TCP_按分区","a":"10","r":"1","c":"[4区]输出寄存器","t":"0","id":"v35","l":"0"})");
	vm->add("环境湿度", DataType::D_FLOAT, R"({"dvc":"Modbus/TCP_按分区","a":"12","r":"1","c":"[4区]输出寄存器","t":"0","id":"v36","l":"0"})");
	vm->add("进样压力高停车信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"0","r":"1","c":"[0区]输出继电器","t":"1","id":"v82","l":"0"})");
	vm->add("可燃气体浓度高停车信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"1","r":"1","c":"[0区]输出继电器","t":"1","id":"v83","l":"0"})");
	vm->add("恒温箱温度波动停车信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"2","r":"1","c":"[0区]输出继电器","t":"1","id":"v84","l":"0"})");
	vm->add("载气压力报警信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"3","r":"1","c":"[0区]输出继电器","t":"1","id":"v85","l":"0"})");
	vm->add("进样压力低报警信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"4","r":"1","c":"[0区]输出继电器","t":"1","id":"v86","l":"0"})");
	vm->add("样气压力高报警信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"5","r":"1","c":"[0区]输出继电器","t":"1","id":"v87","l":"0"})");
	vm->add("柜内温度高报警信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"6","r":"1","c":"[0区]输出继电器","t":"1","id":"v88","l":"0"})");
	vm->add("柜内温度低报警信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"7","r":"1","c":"[0区]输出继电器","t":"1","id":"v89","l":"0"})");
	vm->add("样气压力低报警信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"8","r":"1","c":"[0区]输出继电器","t":"1","id":"v90","l":"0"})");
	vm->add("超过设定预热总时间报警信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"9","r":"1","c":"[0区]输出继电器","t":"1","id":"v91","l":"0"})");
	vm->add("CO2浓度高报警信号", DataType::D_BOOL, R"({"dvc":"Modbus/TCP_按分区","a":"10","r":"1","c":"[0区]输出继电器","t":"0","id":"v100","l":"0"})");
	//常规变量
	vm->add("历史记录关联页码", DataType::T_INT, R"({"id":"v101"})");
	vm->add("历史记录关联总页码", DataType::T_INT, R"({"id":"v102"})");
	vm->add("报警记录关联页码", DataType::T_INT, R"({"id":"v103"})");
	vm->add("报警记录关联总页码", DataType::T_INT, R"({"id":"v104"})");
	vm->add("报警记录起始时间", DataType::T_INT, R"({"id":"v105"})");
	vm->add("报警记录结束时间", DataType::T_INT, R"({"id":"v106"})");
	vm->add("历史记录起始时间", DataType::T_INT, R"({"id":"v107"})");
	vm->add("历史记录结束时间", DataType::T_INT, R"({"id":"v108"})");
	vm->add("环境历史曲线日期", DataType::T_INT, R"({"id":"v109"})");
	vm->add("CO2历史曲线日期", DataType::T_INT, R"({"id":"v110"})");
	vm->add("CO2历史曲线起始时间", DataType::T_INT, R"({"id":"v111"})");
	vm->add("CO2历史曲线结束时间", DataType::T_INT, R"({"id":"v112"})");
	vm->add("环境历史曲线起始时间", DataType::T_INT, R"({"id":"v113"})");
	vm->add("环境历史曲线结束时间", DataType::T_INT, R"({"id":"v114"})");
	//页面映射
	pm->mapping(3, "Frm06");
	pm->mapping(4, "Frm07");
	//资料采样设置
	stt::op::SampleMgr::getInstance(rt)->load(5);
	//事件采集设置
	stt::op::EventMgr::getInstance(rt)->load();
	//背光、屏保
	pm->setBackLightHoldingTime(0, 50);
}

IPagePtr HmiApp::buildPage(string id, uint8_t mode, STTWidget *target) {
	if (id == "Frm03")
		return new Frm03(this, target, "Frm03", "Frm03");
	if (id == "Frm06")
		return new Frm06(this, target, "Frm06", "Frm06");
	if (id == "Frm07")
		return new Frm07(this, target, "Frm07", "Frm07");
	if (id == "Frm12")
		return new Frm12(this, target, "Frm12", "Frm12");
	if (id == "Frm13")
		return new Frm13(this, target, "Frm13", "Frm13");
	if (id == "Frm16")
		return new Frm16(this, target, "Frm16", "Frm16");
	if (id == "Frm19")
		return new Frm19(this, target, "Frm19", "Frm19");
	return new Frm02(this, target, "Frm02", "Frm02");
}

/********************************
 *
 *  构建应用后调用此函数
 *
 *  注意：用户可添加代码
 *
 ********************************/
void HmiApp::onReady(){
	//用户在此添加客户化代码
}

/********************************
 *
 *  应用退出前调用此函数
 *
 *  注意：用户可添加代码
 *
 ********************************/
void HmiApp::onQuit(){
	//用户在此添加客户化代码
}


#endif /* STT_HMIAPP_CPP_ */


