forked from xin/TowerOptoSifAndSpectral
任立新 修改该温控系统的逻辑
This commit is contained in:
@ -4,33 +4,40 @@
|
||||
|
||||
#include "TemperatureRegulator.h"
|
||||
#include "logout.h"
|
||||
#include "sunupanddown.h"
|
||||
TemperatureRegulator *g_tempretureRegulator;
|
||||
TemperatureRegulator::TemperatureRegulator(){
|
||||
|
||||
g_tempretureRegulator=this;
|
||||
}
|
||||
/*
|
||||
"PortName": "ttyS2",
|
||||
"PortName": "ttyS2",
|
||||
"BaudRate": 115200,
|
||||
"Pin": {
|
||||
"TG": {
|
||||
"Pin_H": 7,
|
||||
"Pin_L": 10
|
||||
"Pin_H": 2,
|
||||
"Pin_L": 3
|
||||
},
|
||||
"Fan": {
|
||||
"Pin": 11
|
||||
"Pin": 10
|
||||
},
|
||||
"HOT": {
|
||||
"Pin": 12
|
||||
"Pin": 7
|
||||
}
|
||||
},
|
||||
"Constant_Temperature": {
|
||||
"MaxTemp": 30,
|
||||
"MinTemp": 0
|
||||
"CoolBegin_Temp_Insight": 20,
|
||||
"CoolBegin_Diff_Temp": 5,
|
||||
"HeatingBegin_Temp_Insight": 0,
|
||||
"IsCoolInDaylight": false
|
||||
},
|
||||
"Temperature": {
|
||||
"index_x": 0,
|
||||
"index_y": 0,
|
||||
"Location": {
|
||||
"latitude": 0,
|
||||
"longitude": 0
|
||||
},
|
||||
"IndexInfo": {
|
||||
"Insight": [{"x":7,"y":1},{"x":8,"y":1}],
|
||||
"Outside": [{"x":1,"y":1},{"x":2,"y":1}]
|
||||
}
|
||||
|
||||
**/
|
||||
@ -73,23 +80,53 @@ void TemperatureRegulator::setconfig(json jconfig) {
|
||||
|
||||
m_TG_Manager=new TG_Manager();
|
||||
m_TG_Manager->SetPin(pin1_H,pin1_L,pin2_H,pin2_L);
|
||||
|
||||
if (jconfig.contains("Constant_Temperature")) {
|
||||
if (jconfig["Constant_Temperature"].contains("MaxTemp")) {
|
||||
M_Targert_Max_Tempreature=jconfig["Constant_Temperature"]["MaxTemp"];
|
||||
if (jconfig["Constant_Temperature"].contains("CoolBegin_Temp_Insight")) {
|
||||
m_CoolBegin_Temp_Insight=jconfig["Constant_Temperature"]["CoolBegin_Temp_Insight"];
|
||||
}
|
||||
if (jconfig["Constant_Temperature"].contains("MinTemp")) {
|
||||
M_Targert_Min_Tempreature=jconfig["Constant_Temperature"]["MinTemp"];
|
||||
if (jconfig["Constant_Temperature"].contains("CoolBegin_Diff_Temp")) {
|
||||
m_CoolBegin_Diff_Temp=jconfig["Constant_Temperature"]["CoolBegin_Diff_Temp"];
|
||||
}
|
||||
if (jconfig["Constant_Temperature"].contains("HeatingBegin_Temp_Insight")) {
|
||||
m_HeatingBegin_Temp_Insight=jconfig["Constant_Temperature"]["HeatingBegin_Temp_Insight"];
|
||||
}
|
||||
if (jconfig["Constant_Temperature"].contains("IsCoolInDaylight")) {
|
||||
m_IsCoolInDaylight=jconfig["Constant_Temperature"]["IsCoolInDaylight"].get<bool>();
|
||||
}
|
||||
}
|
||||
if (jconfig.contains("Temperature")) {
|
||||
if (jconfig["Temperature"].contains("index_x")) {
|
||||
m_target_index=jconfig["Temperature"]["index_x"];
|
||||
|
||||
|
||||
|
||||
if (jconfig.contains("Location")) {
|
||||
if (jconfig["Location"].contains("latitude")) {
|
||||
m_Latitude=jconfig["Location"]["latitude"];
|
||||
}
|
||||
if (jconfig["Temperature"].contains("index_y")) {
|
||||
m_target_indey=jconfig["Temperature"]["index_y"];
|
||||
if (jconfig["Location"].contains("longitude")) {
|
||||
m_Longitude=jconfig["Location"]["longitude"];
|
||||
}
|
||||
}
|
||||
if (jconfig.contains("IndexInfo")) {
|
||||
if (jconfig["IndexInfo"].contains("Insight")) {
|
||||
for (int i = 0; i < jconfig["IndexInfo"]["Insight"].size(); ++i) {
|
||||
int x=jconfig["IndexInfo"]["Insight"][i]["x"];
|
||||
int y=jconfig["IndexInfo"]["Insight"][i]["y"];
|
||||
addTargetIndex(x,y,INSIGHT_TEMPERATURE);
|
||||
}
|
||||
}
|
||||
if (jconfig["IndexInfo"].contains("Outside")) {
|
||||
for (int i = 0; i < jconfig["IndexInfo"]["Outside"].size(); ++i) {
|
||||
int x=jconfig["IndexInfo"]["Outside"][i]["x"];
|
||||
int y=jconfig["IndexInfo"]["Outside"][i]["y"];
|
||||
addTargetIndex(x,y,OUTSIGHT_TEMPERATURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
isinit=true;
|
||||
@ -102,16 +139,198 @@ void TemperatureRegulator::setconfig(json jconfig) {
|
||||
void TemperatureRegulator::SetTartGetX_Y(int x,int y){
|
||||
m_target_index=x;
|
||||
m_target_indey=y;
|
||||
|
||||
}
|
||||
|
||||
void TemperatureRegulator::addTargetIndex(int x, int y,int Data_type) {
|
||||
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>
|
||||
if (x<0||y<0) {
|
||||
logout("TemperatureRegulator","addTargetIndex error little than 0",6);
|
||||
return;
|
||||
}
|
||||
if (x>7||y>7) {
|
||||
logout("TemperatureRegulator","addTargetIndex error Big",6);
|
||||
return;
|
||||
}
|
||||
switch (Data_type) {
|
||||
case INSIGHT_TEMPERATURE: {
|
||||
m_target_index_of_insight.push_back({x-1,y-1});
|
||||
break;
|
||||
}
|
||||
case OUTSIGHT_TEMPERATURE: {
|
||||
m_target_index_of_outsight.push_back({x-1,y-1});
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float TemperatureRegulator::GetMax_of_Vector(int Data_type) {
|
||||
switch (Data_type) {
|
||||
case INSIGHT_TEMPERATURE: {
|
||||
float max=0;
|
||||
for (int i = 0; i < m_target_index_of_insight.size(); ++i) {
|
||||
int x=m_target_index_of_insight[i].x;
|
||||
int y=m_target_index_of_insight[i].y;
|
||||
if (m_TemperaTureWoker->m_Tempreaturegroups[y].tempera[x]>max) {
|
||||
max=m_TemperaTureWoker->m_Tempreaturegroups[y].tempera[x];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
case OUTSIGHT_TEMPERATURE: {
|
||||
float max=0;
|
||||
for (int i = 0; i < m_target_index_of_outsight.size(); ++i) {
|
||||
int x=m_target_index_of_outsight[i].x;
|
||||
int y=m_target_index_of_outsight[i].y;
|
||||
if (m_TemperaTureWoker->m_Tempreaturegroups[y].tempera[x]>max) {
|
||||
max=m_TemperaTureWoker->m_Tempreaturegroups[y].tempera[x];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
default: {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float TemperatureRegulator::GetMin_of_Vector(int Data_type) {
|
||||
switch (Data_type) {
|
||||
case INSIGHT_TEMPERATURE: {
|
||||
|
||||
float min=100;
|
||||
for (int i = 0; i < m_target_index_of_insight.size(); ++i) {
|
||||
int x=m_target_index_of_insight[i].x;
|
||||
int y=m_target_index_of_insight[i].y;
|
||||
if (m_TemperaTureWoker->m_Tempreaturegroups[y].tempera[x]<min) {
|
||||
min=m_TemperaTureWoker->m_Tempreaturegroups[y].tempera[x];
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
case OUTSIGHT_TEMPERATURE: {
|
||||
float min=100;
|
||||
for (int i = 0; i < m_target_index_of_outsight.size(); ++i) {
|
||||
int x=m_target_index_of_outsight[i].x;
|
||||
int y=m_target_index_of_outsight[i].y;
|
||||
if (m_TemperaTureWoker->m_Tempreaturegroups[y].tempera[x]<min) {
|
||||
min=m_TemperaTureWoker->m_Tempreaturegroups[y].tempera[x];
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
default: {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TemperatureRegulator::init(){
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TemperatureRegulator::PanduanCooling() {
|
||||
|
||||
}
|
||||
void TemperatureRegulator::loop(){
|
||||
if (!isinit) return;
|
||||
m_TemperaTureWoker->ReadTempreature();
|
||||
// todo <20><>savedata<74><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼temperature
|
||||
QDateTime currentTime=QDateTime::currentDateTime();
|
||||
int year=currentTime.date().year();
|
||||
int month=currentTime.date().month();
|
||||
int day=currentTime.date().day();
|
||||
int nowhour=currentTime.time().hour();
|
||||
int nowminute=currentTime.time().minute();
|
||||
long nowminuteofday=nowhour*60+nowminute;
|
||||
SunInfo sunInfo=calculateSunriseSunset(year,month,day,m_Latitude,m_Longitude);
|
||||
float sunrise_minte=sunInfo.sunrise_h*60+sunInfo.sunrise_m;
|
||||
float sunset_minte=sunInfo.sunset_h*60+sunInfo.sunset_m;
|
||||
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>죨ǰ<ECA3A8><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>15<31><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (nowminuteofday>sunrise_minte+15&&nowminuteofday<sunset_minte-15) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
if (m_IsCoolInDaylight) {
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>²<EFBFBD><C2B2><EFBFBD><EFBFBD><EFBFBD>m_CoolBegin_Diff_Temp <20>ҵ<EFBFBD>ǰinsight<68>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD>趨<EFBFBD><E8B6A8>ʼֵ <20><><EFBFBD>Կ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
//<2F><>һ<EFBFBD><D2BB> <20><>ȡ<EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>
|
||||
float maxinsighttemp=GetMax_of_Vector(INSIGHT_TEMPERATURE);
|
||||
//<2F>ڶ<EFBFBD><DAB6><EFBFBD> <20><>ȡ<EFBFBD>ⲿ<EFBFBD><E2B2BF>С<EFBFBD>¶<EFBFBD>
|
||||
float minoutsighttemp=GetMin_of_Vector(OUTSIGHT_TEMPERATURE);
|
||||
// <20><><EFBFBD><EFBFBD>diff
|
||||
float diff=maxinsighttemp-minoutsighttemp;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>²<EFBFBD><C2B2><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4>ֵ
|
||||
if (diff>m_CoolBegin_Diff_Temp) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰinsight<68>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD>趨<EFBFBD><E8B6A8>ʼֵ
|
||||
if (maxinsighttemp>m_CoolBegin_Temp_Insight) {
|
||||
m_TG_Manager->Cooling();
|
||||
logout("Temp","current max insight temp is "+QString::number(maxinsighttemp),6);
|
||||
} else {
|
||||
m_TG_Manager->Stop();
|
||||
logout("Temp","current max insight temp is "+QString::number(maxinsighttemp),6);
|
||||
}
|
||||
} else {
|
||||
m_TG_Manager->Stop();
|
||||
logout("Temp","current diff is "+QString::number(diff),6);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD> <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>¶ȸ<C2B6><C8B8>ڿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD> ˵<><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ƴ<EFBFBD>
|
||||
if (m_CoolBegin_Temp_Insight<m_HeatingBegin_Temp_Insight)
|
||||
{
|
||||
logout("Temp","CoolBegin_Temp_Insight is less than HeatingBegin_Temp_Insight",6);
|
||||
return;
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD>ֻ<EFBFBD>ܼ<EFBFBD><DCBC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>¶ȵ<C2B6><C8B5><EFBFBD>m_HeatingBeginTemp_Insight <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
//<2F><>һ<EFBFBD><D2BB> <20><>ȡ<EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>С<EFBFBD>¶<EFBFBD>
|
||||
float mininsighttemp=GetMin_of_Vector(INSIGHT_TEMPERATURE);
|
||||
//<2F>ڶ<EFBFBD><DAB6><EFBFBD> <20><>m_HeatingBeginTemp_Insight<68>Ƚ<EFBFBD>
|
||||
if (mininsighttemp<m_HeatingBegin_Temp_Insight)
|
||||
{
|
||||
m_TG_Manager->Heating();
|
||||
logout("Temp","current min insight temp is "+QString::number(mininsighttemp),6);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_TG_Manager->Stop();
|
||||
logout("Temp","current min insight temp is "+QString::number(mininsighttemp),6);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else //ҹ<><D2B9>
|
||||
{
|
||||
//ҹ<><D2B9>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD> <20><>ֻҪ<D6BB>ⲿ<EFBFBD>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>¶ȼ<C2B6><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><>һ<EFBFBD><D2BB> <20><>ȡ<EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>
|
||||
float maxinsighttemp=GetMax_of_Vector(INSIGHT_TEMPERATURE);
|
||||
//<2F>ڶ<EFBFBD><DAB6><EFBFBD> <20><>ȡ<EFBFBD>ⲿ<EFBFBD><E2B2BF>С<EFBFBD>¶<EFBFBD>
|
||||
float minoutsighttemp=GetMin_of_Vector(OUTSIGHT_TEMPERATURE);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>¶<EFBFBD>С<EFBFBD><D0A1><EFBFBD>ڲ<EFBFBD><DAB2>¶<EFBFBD>
|
||||
if (maxinsighttemp>minoutsighttemp)
|
||||
{
|
||||
m_TG_Manager->Cooling();
|
||||
logout("Temp","current max insight temp is "+QString::number(maxinsighttemp),6);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_TG_Manager->Stop();
|
||||
logout("Temp","current max insight temp is "+QString::number(maxinsighttemp),6);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return;
|
||||
|
||||
|
||||
float tempreture=m_TemperaTureWoker->m_Tempreaturegroups[m_target_index].tempera[m_target_indey];
|
||||
//printf("current tempreture is %f\n",tempreture);
|
||||
logout("Temp","current tempreture is "+QString::number(tempreture),6);
|
||||
@ -135,3 +354,5 @@ void TemperatureRegulator::loop(){
|
||||
bool TemperatureRegulator::looptask() {
|
||||
g_tempretureRegulator->loop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user