mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-12-16 11:33:31 +08:00
v2.1.3
This commit is contained in:
@ -1,32 +0,0 @@
|
||||
{
|
||||
"TimeConfig": {
|
||||
"StartTime": "00:00:00",
|
||||
"EndTime": "23:59:00",
|
||||
"IntervalTime": 60
|
||||
},
|
||||
"TemperatureConfig": {
|
||||
"PortName": "ttyS2",
|
||||
"BaudRate": 115200,
|
||||
"Pin": {
|
||||
"TG": {
|
||||
"Pin_H": 7,
|
||||
"Pin_L": 10
|
||||
},
|
||||
"Fan": {
|
||||
"Pin": 11
|
||||
},
|
||||
"HOT": {
|
||||
"Pin": 12
|
||||
}
|
||||
},
|
||||
"Constant_Temperature": {
|
||||
"MaxTemp": 35,
|
||||
"MinTemp": 10
|
||||
},
|
||||
"Temperature": {
|
||||
"index_x": 0,
|
||||
"index_y": 0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
{
|
||||
{
|
||||
"TimeConfig": {
|
||||
"StartTime": "00:00:00",
|
||||
"EndTime": "23:59:00",
|
||||
@ -8,15 +8,20 @@
|
||||
"PortName": "ttyS2",
|
||||
"BaudRate": 115200,
|
||||
"Pin": {
|
||||
"TG": {
|
||||
"Pin_H": 2,
|
||||
"Pin_L": 3
|
||||
"COOLER": {
|
||||
"Pin": 24
|
||||
},
|
||||
"Fan": {
|
||||
"Pin": 10
|
||||
"Pin_H": 3,
|
||||
"Pin_L": 2
|
||||
},
|
||||
"HOT": {
|
||||
"Pin": 7
|
||||
"Pin": 19
|
||||
},
|
||||
"WINDOWS": {
|
||||
"Pin_H": 7,
|
||||
"Pin_L": 10,
|
||||
"WaitTime": 40
|
||||
}
|
||||
},
|
||||
"Constant_Temperature": {
|
||||
|
||||
@ -7,21 +7,88 @@
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <qthread.h>
|
||||
#include <fstream>
|
||||
#include "logout.h"
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QCoreApplication aaaaa(argc, argv);
|
||||
std::cout<<"Hello World"<<std::flush;
|
||||
|
||||
|
||||
json j;
|
||||
std::ifstream i("/home/data/Setting/Constant_Temperature_Config.json");
|
||||
//如果配置文件不存在则创建一个默认配置文件
|
||||
if (!i.is_open()) {
|
||||
logout("main","config file not exist,create default config file",10);
|
||||
std::ofstream o("/home/data/Setting/Constant_Temperature_Config.json");
|
||||
json jdefault={
|
||||
{"TimeConfig",
|
||||
{
|
||||
{"StartTime","00:00:00"},
|
||||
{"EndTime","23:59:00"},
|
||||
{"IntervalTime",10}
|
||||
}
|
||||
},
|
||||
{"TemperatureConfig",
|
||||
{
|
||||
{"PortName","ttyS2"},
|
||||
{"BaudRate",115200},
|
||||
{"Pin",
|
||||
{
|
||||
{"COOLER", {{"Pin",24}}},
|
||||
{"Fan", {{"Pin_H",3},{"Pin_L",2}}},
|
||||
{"HOT", {{"Pin",19}}},
|
||||
{"WINDOWS", {{"Pin_H",10},{"Pin_L",7},{"WaitTime",60}}}
|
||||
}
|
||||
},
|
||||
{"Constant_Temperature",
|
||||
{
|
||||
{"CoolBegin_Temp_Insight",20},
|
||||
{"CoolBegin_Diff_Temp",5},
|
||||
{"HeatingBegin_Temp_Insight",0},
|
||||
{"IsCoolInDaylight",false}
|
||||
}
|
||||
},
|
||||
{"Location",
|
||||
{
|
||||
{"latitude",0},
|
||||
{"longitude",0}
|
||||
}
|
||||
},
|
||||
{"IndexInfo",
|
||||
{
|
||||
{"Insight",{ {{"x",7},{"y",1}}, {{"x",8},{"y",1}} }},
|
||||
{"Outside",{ {{"x",1},{"y",1}}, {{"x",2},{"y",1}} }}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
o << std::setw(4) << jdefault << std::endl;
|
||||
o.close();
|
||||
logout("main","default config file created,please modify the config file and restart the program",10);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
logout("main","prepare to read config data,if error please check file /home/data/Setting/Constant_Temperature_Config.json",10);
|
||||
i>>j;
|
||||
logout("main","config data read finish",10);
|
||||
json timeconfig=j["TimeConfig"];
|
||||
json tempconfig=j["TemperatureConfig"];
|
||||
TemperatureRegulator *temperature_regulator=new TemperatureRegulator();
|
||||
temperature_regulator->setconfig(tempconfig);
|
||||
TimeWorker *timeWorker=new TimeWorker();
|
||||
|
||||
timeWorker->ReadConfig(timeconfig);
|
||||
|
||||
|
||||
timeWorker->SetTask(TemperatureRegulator::looptask);
|
||||
timeWorker->Start();
|
||||
|
||||
|
||||
@ -4,15 +4,32 @@
|
||||
|
||||
#include "TG_Manager.h"
|
||||
#include "string"
|
||||
#include "QThread"
|
||||
void TG_Manager::SetPin(int pin1_H, int pin1_L, int pin2_H, int pin2_L)
|
||||
{
|
||||
this->pin1_H = pin1_H;
|
||||
this->pin1_L = pin1_L;
|
||||
this->pin2_H = pin2_H;
|
||||
this->pin2_L = pin2_L;
|
||||
// this->pin1_H = pin1_H;
|
||||
// this->pin1_L = pin1_L;
|
||||
// this->pin2_H = pin2_H;
|
||||
// this->pin2_L = pin2_L;
|
||||
InitManger();
|
||||
}
|
||||
|
||||
void TG_Manager::SetPin_V2(int Windows_Pin_H, int Windows_Pin_L, int COOLER_Pin_EN, int HOT_Pin_EN, int Fan_Pin_H,
|
||||
int Fan_Pin_L) {
|
||||
this->Windows_Pin_H=Windows_Pin_H;
|
||||
this->Windows_Pin_L=Windows_Pin_L;
|
||||
this->COOLER_Pin_EN=COOLER_Pin_EN;
|
||||
this->HOT_Pin_EN=HOT_Pin_EN;
|
||||
this->Fan_Pin_H=Fan_Pin_H;
|
||||
this->Fan_Pin_L=Fan_Pin_L;
|
||||
InitManger();
|
||||
|
||||
}
|
||||
|
||||
void TG_Manager::Set_Waite_time_for_Windows(int time_in_seconds) {
|
||||
m_time_for_wait_windows = time_in_seconds;
|
||||
}
|
||||
|
||||
bool TG_Manager::SetTuiGan(int IS_High)
|
||||
{
|
||||
|
||||
@ -62,17 +79,43 @@ bool TG_Manager::SetTuiGan(int IS_High)
|
||||
}
|
||||
void TG_Manager::InitManger()
|
||||
{
|
||||
std::string comand1 = "gpio mode " + std::to_string(pin1_H) + " out";
|
||||
std::string comand2 = "gpio mode " + std::to_string(pin1_L) + " out";
|
||||
std::string comand3 = "gpio mode " + std::to_string(pin2_H) + " out";
|
||||
std::string comand4 = "gpio mode " + std::to_string(pin2_L) + " out";
|
||||
// std::string comand1 = "gpio mode " + std::to_string(pin1_H) + " out";
|
||||
// std::string comand2 = "gpio mode " + std::to_string(pin1_L) + " out";
|
||||
// std::string comand3 = "gpio mode " + std::to_string(pin2_H) + " out";
|
||||
// std::string comand4 = "gpio mode " + std::to_string(pin2_L) + " out";
|
||||
// system(comand1.c_str());
|
||||
// system(comand2.c_str());
|
||||
// system(comand3.c_str());
|
||||
// system(comand4.c_str());
|
||||
// SetTuiGan(0);
|
||||
// SetSwitch1Status(0);
|
||||
// SetSwitch2Status(0);
|
||||
std::string comand1 = "gpio mode " + std::to_string(Windows_Pin_H) + " out";
|
||||
std::string comand2 = "gpio mode " + std::to_string(Windows_Pin_L) + " out";
|
||||
std::string comand3 = "gpio mode " + std::to_string(COOLER_Pin_EN) + " out";
|
||||
std::string comand4 = "gpio mode " + std::to_string(HOT_Pin_EN) + " out";
|
||||
std::string comand5 = "gpio mode " + std::to_string(Fan_Pin_H) + " out";
|
||||
std::string comand6 = "gpio mode " + std::to_string(Fan_Pin_L) + " out";
|
||||
system(comand1.c_str());
|
||||
system(comand2.c_str());
|
||||
system(comand3.c_str());
|
||||
system(comand4.c_str());
|
||||
SetTuiGan(0);
|
||||
SetSwitch1Status(0);
|
||||
SetSwitch2Status(0);
|
||||
system(comand5.c_str());
|
||||
system(comand6.c_str());
|
||||
comand1 = "gpio write " + std::to_string(Windows_Pin_H) + " 0";
|
||||
system(comand1.c_str());
|
||||
comand1 = "gpio write " + std::to_string(Windows_Pin_L) + " 0";
|
||||
system(comand1.c_str());
|
||||
comand1 = "gpio write " + std::to_string(COOLER_Pin_EN) + " 0";
|
||||
system(comand1.c_str());
|
||||
comand1 = "gpio write " + std::to_string(HOT_Pin_EN) + " 0";
|
||||
system(comand1.c_str());
|
||||
comand1 = "gpio write " + std::to_string(Fan_Pin_H) + " 0";
|
||||
system(comand1.c_str());
|
||||
comand1 = "gpio write " + std::to_string(Fan_Pin_L) + " 0";
|
||||
system(comand1.c_str());
|
||||
|
||||
|
||||
}
|
||||
bool TG_Manager::SetSwitch1Status(bool status)
|
||||
{
|
||||
@ -104,29 +147,57 @@ bool TG_Manager::SetSwitch2Status(bool status)
|
||||
return status;
|
||||
}
|
||||
|
||||
bool TG_Manager::Heating()
|
||||
bool TG_Manager::Heating(bool isworking)
|
||||
{
|
||||
printf("Heating\n");
|
||||
SetTuiGan(true);
|
||||
SetSwitch1Status(true);
|
||||
SetSwitch2Status(false);
|
||||
|
||||
WorkingStatus = HEATING;
|
||||
return true;
|
||||
}
|
||||
bool TG_Manager::Cooling()
|
||||
bool TG_Manager::Cooling(bool isworking)
|
||||
{
|
||||
printf("Cooling\n");
|
||||
SetTuiGan(false);
|
||||
SetSwitch1Status(false);
|
||||
SetSwitch2Status(true);
|
||||
|
||||
WorkingStatus = COOLING;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TG_Manager::Windows_Open() {
|
||||
std::string comment="gpio write " + std::to_string(Windows_Pin_H) + " 1";
|
||||
std::string comment1="gpio write " + std::to_string(Windows_Pin_L) + " 0";
|
||||
system(comment.c_str());
|
||||
system(comment1.c_str());
|
||||
//休息40秒
|
||||
QThread::sleep(m_time_for_wait_windows);
|
||||
|
||||
comment="gpio write " + std::to_string(Windows_Pin_H) + " 0";
|
||||
comment1="gpio write " + std::to_string(Windows_Pin_L) + " 0";
|
||||
system(comment.c_str());
|
||||
system(comment1.c_str());
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool TG_Manager::Windows_Close() {
|
||||
std::string comment="gpio write " + std::to_string(Windows_Pin_H) + " 0";
|
||||
std::string comment1="gpio write " + std::to_string(Windows_Pin_L) + " 1";
|
||||
system(comment.c_str());
|
||||
system(comment1.c_str());
|
||||
//休息40秒
|
||||
QThread::sleep(m_time_for_wait_windows);
|
||||
|
||||
comment="gpio write " + std::to_string(Windows_Pin_H) + " 0";
|
||||
comment1="gpio write " + std::to_string(Windows_Pin_L) + " 0";
|
||||
system(comment.c_str());
|
||||
system(comment1.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TG_Manager::Stop(){
|
||||
SetTuiGan(2);
|
||||
SetSwitch1Status(false);
|
||||
SetSwitch2Status(false);
|
||||
std::string comment="gpio write " + std::to_string(Windows_Pin_H) + " 0";
|
||||
std::string comment1="gpio write " + std::to_string(Windows_Pin_L) + " 0";
|
||||
system(comment.c_str());
|
||||
system(comment1.c_str());
|
||||
|
||||
WorkingStatus = NotWroking;
|
||||
return true;
|
||||
|
||||
|
||||
@ -4,21 +4,36 @@
|
||||
|
||||
#ifndef TG_MANAGER_H
|
||||
#define TG_MANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
enum WORKINGSTATUS{
|
||||
HEATING=1,
|
||||
COOLING=2,
|
||||
WINDOWS_OPEN=3,
|
||||
WINDOWS_CLOSE=4,
|
||||
|
||||
NotWroking=0
|
||||
};
|
||||
|
||||
class TG_Manager {
|
||||
// enum WINDOWS_STATUS{
|
||||
// WINDOWS_IS_READY_OPEN=1,
|
||||
// WINDOWS_IS_CLOSE=2,
|
||||
// WINDOWS_IS_OPENING=3,
|
||||
// WINDOWS_IS_CLOSING=4,
|
||||
// WINDOWS_IS_STOP=5
|
||||
// };
|
||||
class TG_Manager:public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
void SetPin(int pin1_H=7, int pin1_L=10, int pin2_H=2, int pin2_L=4);
|
||||
void SetPin_V2(int Windows_Pin_H, int Windows_Pin_L, int COOLER_Pin_EN, int HOT_Pin_EN, int Fan_Pin_H, int Fan_Pin_L);
|
||||
void Set_Waite_time_for_Windows(int time_in_seconds);
|
||||
// void SetPin_V2
|
||||
void InitManger();
|
||||
|
||||
bool Heating();
|
||||
bool Cooling();
|
||||
bool Heating(bool isworking);
|
||||
bool Cooling(bool isworking);
|
||||
bool Windows_Open();
|
||||
bool Windows_Close();
|
||||
bool Stop();
|
||||
int GetManagerStatus();
|
||||
|
||||
@ -29,10 +44,35 @@ private:
|
||||
bool SetTuiGan(int IS_High);
|
||||
bool SetSwitch1Status(bool status);
|
||||
bool SetSwitch2Status(bool status);
|
||||
int m_time_for_wait_windows=40;
|
||||
int pin1_H=7;
|
||||
int pin1_L=10;
|
||||
int pin2_H=2;
|
||||
int pin2_L=4;
|
||||
/* "Pin": {
|
||||
"COOLER": {
|
||||
"Pin": 24
|
||||
},
|
||||
"Fan": {
|
||||
"Pin_H": 3,
|
||||
"Pin_L": 2
|
||||
},
|
||||
"HOT": {
|
||||
"Pin": 19
|
||||
},
|
||||
"WINDOWS": {
|
||||
"Pin_H": 7,
|
||||
"Pin_L": 10
|
||||
}
|
||||
}*/
|
||||
int Windows_Pin_H=7;
|
||||
int Windows_Pin_L=10;
|
||||
int COOLER_Pin_EN=24;
|
||||
int HOT_Pin_EN=19;
|
||||
int Fan_Pin_H=3;
|
||||
int Fan_Pin_L=2;
|
||||
|
||||
|
||||
bool ping1_status=false;
|
||||
int WorkingStatus=NotWroking;
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <iostream>
|
||||
#include <qthread.h>
|
||||
#include <QDebug>
|
||||
#include <logout.h>
|
||||
TemperaTureWoker::TemperaTureWoker() {
|
||||
|
||||
}
|
||||
@ -102,10 +103,21 @@ void TemperaTureWoker::ReadTempreature() {
|
||||
if (lenth==0) {
|
||||
//std::cout << "No data" << std::endl;
|
||||
qDebug()<< "No data";
|
||||
logout("TemperaSersor","no data from tempera sensor",10);
|
||||
|
||||
return;
|
||||
}
|
||||
std::cout << data.toStdString();
|
||||
//qDebug() << data;
|
||||
std::cout << data.toStdString()<< std::endl;
|
||||
logout("TemperaSersor",data.toHex(),5);
|
||||
qDebug() << data;
|
||||
try {
|
||||
json::parse(data.toStdString());
|
||||
}
|
||||
catch (...) {
|
||||
logout("TemperaSersor","data from tempera sensor parse error",3);
|
||||
return;
|
||||
|
||||
}
|
||||
json jsondata = json::parse(data.toStdString());
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
if(jsondata.contains("Temperature"+std::to_string(j+1))) {
|
||||
@ -119,11 +131,11 @@ void TemperaTureWoker::ReadTempreature() {
|
||||
|
||||
}
|
||||
}
|
||||
//<2F><>ӡm_Tempreaturegroups
|
||||
//<2F><>ӡm_Tempreaturegroups
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
std::cout << "Group " << i << ":\t|";
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
// <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>Ϊ 10<31><30>ʹ<EFBFBD>ÿո<C3BF><D5B8><EFBFBD><EFBFBD>䣬<EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD> std::internal ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD>
|
||||
// <20><><EFBFBD>ÿ<EFBFBD><C3BF>Ϊ 10<31><30>ʹ<EFBFBD>ÿո<C3BF><D5B8><EFBFBD>䣬<EFBFBD><E4A3AC>ͨ<EFBFBD><CDA8> std::internal ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD>
|
||||
//std::cout << std::setw(10) << std::setfill(' ') << std::internal
|
||||
// qDebug().noquote().nospace()<< m_Tempreaturegroups[i].tempera[j] << ":\t|";
|
||||
std::cout << std::setw(10) << std::setfill(' ') << std::internal
|
||||
|
||||
@ -53,33 +53,92 @@ void TemperatureRegulator::setconfig(json jconfig) {
|
||||
}
|
||||
m_TemperaTureWoker=new TemperaTureWoker();
|
||||
m_TemperaTureWoker->OpenCom(Port_Name,BaudRate);
|
||||
int pin1_H=7;
|
||||
int pin1_L=10;
|
||||
int pin2_H=2;
|
||||
int pin2_L=4;
|
||||
// int pin1_H=7;
|
||||
// int pin1_L=10;
|
||||
// int pin2_H=2;
|
||||
// int pin2_L=4;
|
||||
// if (jconfig.contains("Pin")) {
|
||||
// if (jconfig["Pin"].contains("")) {
|
||||
// if (jconfig["Pin"]["TG"].contains("Pin_H")) {
|
||||
// pin1_H=jconfig["Pin"]["TG"]["Pin_H"];
|
||||
// }
|
||||
// if (jconfig["Pin"]["TG"].contains("Pin_L")) {
|
||||
// pin1_L=jconfig["Pin"]["TG"]["Pin_L"];
|
||||
// }
|
||||
// }
|
||||
// if (jconfig["Pin"].contains("Fan")) {
|
||||
// if (jconfig["Pin"]["Fan"].contains("Pin")) {
|
||||
// pin2_H=jconfig["Pin"]["Fan"]["Pin"];
|
||||
// }
|
||||
// }
|
||||
// if (jconfig["Pin"].contains("HOT")) {
|
||||
// if (jconfig["Pin"]["HOT"].contains("Pin")) {
|
||||
// pin2_L=jconfig["Pin"]["HOT"]["Pin"];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
/*
|
||||
* "Pin": {
|
||||
"COOLER": {
|
||||
"Pin": 24
|
||||
},
|
||||
"Fan": {
|
||||
"Pin_H": 3,
|
||||
"Pin_L": 2
|
||||
},
|
||||
"HOT": {
|
||||
"Pin": 19
|
||||
},
|
||||
"WINDOWS": {
|
||||
"Pin_H": 7,
|
||||
"Pin_L": 10,
|
||||
"WaitTime": 40
|
||||
}
|
||||
},
|
||||
*/
|
||||
int Cooler_Pin_EN=24;
|
||||
int Fan_Pin_H=3;
|
||||
int Fan_Pin_L=2;
|
||||
int Hot_Pin_EN=19;
|
||||
int Windows_Pin_H=7;
|
||||
int Windows_Pin_L=10;
|
||||
int Windows_WaitTime=40;
|
||||
if (jconfig.contains("Pin")) {
|
||||
if (jconfig["Pin"].contains("TG")) {
|
||||
if (jconfig["Pin"]["TG"].contains("Pin_H")) {
|
||||
pin1_H=jconfig["Pin"]["TG"]["Pin_H"];
|
||||
}
|
||||
if (jconfig["Pin"]["TG"].contains("Pin_L")) {
|
||||
pin1_L=jconfig["Pin"]["TG"]["Pin_L"];
|
||||
if (jconfig["Pin"].contains("COOLER")) {
|
||||
if (jconfig["Pin"]["COOLER"].contains("Pin")) {
|
||||
Cooler_Pin_EN=jconfig["Pin"]["COOLER"]["Pin"];
|
||||
}
|
||||
}
|
||||
if (jconfig["Pin"].contains("Fan")) {
|
||||
if (jconfig["Pin"]["Fan"].contains("Pin")) {
|
||||
pin2_H=jconfig["Pin"]["Fan"]["Pin"];
|
||||
if (jconfig["Pin"]["Fan"].contains("Pin_H")) {
|
||||
Fan_Pin_H=jconfig["Pin"]["Fan"]["Pin_H"];
|
||||
}
|
||||
if (jconfig["Pin"]["Fan"].contains("Pin_L")) {
|
||||
Fan_Pin_L=jconfig["Pin"]["Fan"]["Pin_L"];
|
||||
}
|
||||
}
|
||||
if (jconfig["Pin"].contains("HOT")) {
|
||||
if (jconfig["Pin"]["HOT"].contains("Pin")) {
|
||||
pin2_L=jconfig["Pin"]["HOT"]["Pin"];
|
||||
Hot_Pin_EN=jconfig["Pin"]["HOT"]["Pin"];
|
||||
}
|
||||
}
|
||||
if (jconfig["Pin"].contains("WINDOWS")) {
|
||||
if (jconfig["Pin"]["WINDOWS"].contains("Pin_H")) {
|
||||
Windows_Pin_H=jconfig["Pin"]["WINDOWS"]["Pin_H"];
|
||||
}
|
||||
if (jconfig["Pin"]["WINDOWS"].contains("Pin_L")) {
|
||||
Windows_Pin_L=jconfig["Pin"]["WINDOWS"]["Pin_L"];
|
||||
}
|
||||
if (jconfig["Pin"]["WINDOWS"].contains("WaitTime")) {
|
||||
Windows_WaitTime=jconfig["Pin"]["WINDOWS"]["WaitTime"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_TG_Manager=new TG_Manager();
|
||||
m_TG_Manager->SetPin(pin1_H,pin1_L,pin2_H,pin2_L);
|
||||
m_TG_Manager->SetPin_V2(Windows_Pin_H,Windows_Pin_L,Cooler_Pin_EN,Hot_Pin_EN,Fan_Pin_H,Fan_Pin_L);
|
||||
// m_TG_Manager->SetPin(pin1_H,pin1_L,pin2_H,pin2_L);
|
||||
if (jconfig.contains("Constant_Temperature")) {
|
||||
if (jconfig["Constant_Temperature"].contains("CoolBegin_Temp_Insight")) {
|
||||
m_CoolBegin_Temp_Insight=jconfig["Constant_Temperature"]["CoolBegin_Temp_Insight"];
|
||||
@ -238,10 +297,68 @@ void TemperatureRegulator::init(){
|
||||
void TemperatureRegulator::PanduanCooling() {
|
||||
|
||||
}
|
||||
int timesforlog=0;
|
||||
void TemperatureRegulator::loopsample() {
|
||||
if (!isinit) return;
|
||||
m_TemperaTureWoker->ReadTempreature();
|
||||
// todo <20><>savedata<74><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼temperature
|
||||
QString datastr="";
|
||||
for (int i = 0; i < m_TemperaTureWoker->m_Tempreaturegroups.size(); ++i) {
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
datastr+=QString::number(m_TemperaTureWoker->m_Tempreaturegroups[i].tempera[j])+",";
|
||||
}
|
||||
}
|
||||
saveDataToFile("Tempratrue",datastr);
|
||||
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;
|
||||
|
||||
if (timesforlog%60==0) {
|
||||
logout("Temp","now minute of day is "+QString::number(nowminuteofday)+
|
||||
" sunrise minute is "+QString::number(sunrise_minte)+
|
||||
" sunset minute is "+QString::number(sunset_minte),6);
|
||||
|
||||
}
|
||||
timesforlog++ ;
|
||||
//<2F>ų<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ǰһ<C7B0><D2BB>Сʱ
|
||||
if (nowminuteofday>60) {
|
||||
if (last_time_in_today_minute<sunrise_minte&&nowminuteofday>=sunrise_minte&&nowminuteofday<sunset_minte) {
|
||||
//sunrise happened
|
||||
logout("Temp","sunrise happened",6);
|
||||
m_TG_Manager->Windows_Close();
|
||||
// m_TG_Manager->Stop();
|
||||
}
|
||||
if (last_time_in_today_minute<sunset_minte&&nowminuteofday>=sunset_minte) {
|
||||
//sunset happened
|
||||
logout("Temp","sunset happened",6);
|
||||
m_TG_Manager->Windows_Open();
|
||||
// m_TG_Manager->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
last_time_in_today_minute=nowminuteofday;
|
||||
};
|
||||
void TemperatureRegulator::loop(){
|
||||
if (!isinit) return;
|
||||
m_TemperaTureWoker->ReadTempreature();
|
||||
// todo <20><>savedata<74><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼temperature
|
||||
QString datastr="";
|
||||
for (int i = 0; i < m_TemperaTureWoker->m_Tempreaturegroups.size(); ++i) {
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
datastr+=QString::number(m_TemperaTureWoker->m_Tempreaturegroups[i].tempera[j])+",";
|
||||
}
|
||||
}
|
||||
saveDataToFile("Tempratrue",datastr);
|
||||
QDateTime currentTime=QDateTime::currentDateTime();
|
||||
int year=currentTime.date().year();
|
||||
int month=currentTime.date().month();
|
||||
@ -267,7 +384,7 @@ void TemperatureRegulator::loop(){
|
||||
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();
|
||||
m_TG_Manager->Cooling(true);
|
||||
logout("Temp","current max insight temp is "+QString::number(maxinsighttemp),6);
|
||||
} else {
|
||||
m_TG_Manager->Stop();
|
||||
@ -295,7 +412,7 @@ void TemperatureRegulator::loop(){
|
||||
//<2F>ڶ<EFBFBD><DAB6><EFBFBD> <20><>m_HeatingBeginTemp_Insight<68>Ƚ<EFBFBD>
|
||||
if (mininsighttemp<m_HeatingBegin_Temp_Insight)
|
||||
{
|
||||
m_TG_Manager->Heating();
|
||||
m_TG_Manager->Heating(true);
|
||||
logout("Temp","current min insight temp is "+QString::number(mininsighttemp),6);
|
||||
}
|
||||
else
|
||||
@ -316,7 +433,7 @@ void TemperatureRegulator::loop(){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>¶<EFBFBD>С<EFBFBD><D0A1><EFBFBD>ڲ<EFBFBD><DAB2>¶<EFBFBD>
|
||||
if (maxinsighttemp>minoutsighttemp)
|
||||
{
|
||||
m_TG_Manager->Cooling();
|
||||
m_TG_Manager->Cooling(true);
|
||||
logout("Temp","current max insight temp is "+QString::number(maxinsighttemp),6);
|
||||
}
|
||||
else
|
||||
@ -337,11 +454,11 @@ void TemperatureRegulator::loop(){
|
||||
// qDebug()<< "current tempreture is " << tempreture;
|
||||
if (tempreture>M_Targert_Max_Tempreature)
|
||||
{
|
||||
m_TG_Manager->Cooling();
|
||||
m_TG_Manager->Cooling(true);
|
||||
}
|
||||
else if (tempreture<M_Targert_Min_Tempreature)
|
||||
{
|
||||
m_TG_Manager->Heating();
|
||||
m_TG_Manager->Heating(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -352,7 +469,7 @@ void TemperatureRegulator::loop(){
|
||||
}
|
||||
|
||||
bool TemperatureRegulator::looptask() {
|
||||
g_tempretureRegulator->loop();
|
||||
g_tempretureRegulator->loopsample();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -56,6 +56,7 @@ public:
|
||||
float GetMin_of_Vector(int Data_type=INSIGHT_TEMPERATURE);
|
||||
void init();
|
||||
void loop();
|
||||
void loopsample();
|
||||
static bool looptask();
|
||||
void PanduanCooling();
|
||||
|
||||
@ -77,6 +78,7 @@ private:
|
||||
bool isinit=false;
|
||||
float m_Latitude=39.9;
|
||||
float m_Longitude=116.4;
|
||||
long long last_time_in_today_minute=0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -74,11 +74,11 @@ void TimeWorker::onTimerTrigger() {
|
||||
return;
|
||||
}
|
||||
m_isWork=true;
|
||||
logout("TimeWorker","Task is working");
|
||||
// logout("TimeWorker","Task is working");
|
||||
int taskid=0;
|
||||
foreach (auto task, m_TaskList) {
|
||||
task();
|
||||
logout("TimeWorker","Task "+QString::number(taskid)+" is finished",6);
|
||||
//logout("TimeWorker","Task "+QString::number(taskid)+" is finished",6);
|
||||
taskid++;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "logout.h"
|
||||
#include "iostream"
|
||||
extern FILE *file=NULL;
|
||||
FILE *datafile=NULL;
|
||||
#define _DEBUG
|
||||
void (*pFunction)(QString message)= nullptr;
|
||||
QString colorcode = "\033[";
|
||||
@ -105,8 +106,8 @@ void writelogtofile(QString sender,QString qstr)
|
||||
}
|
||||
if (file==NULL)
|
||||
{
|
||||
QString path="/home/iris/log/"+currentTime.toString("yyyy_MM_dd")+".log";
|
||||
system("mkdir -p /home/iris/log");
|
||||
QString path="/home/data/Log/"+currentTime.toString("yyyy_MM_dd_hh_mm_ss")+"_Temptrue.log";
|
||||
system("mkdir -p /home/data/Log");
|
||||
file=fopen(path.toStdString().c_str(),"a+");
|
||||
fprintf(file,"\n\n\n\nstart---------------------------------------------------------------------------------\n");
|
||||
}
|
||||
@ -122,22 +123,22 @@ void saveData(QString sender,QString qstr)
|
||||
QString datestr=currentTime.toString("yyyy_MM_dd");
|
||||
if (lastdatestr!=datestr)
|
||||
{
|
||||
if (file!=NULL)
|
||||
if (datafile!=NULL)
|
||||
{
|
||||
fclose(file);
|
||||
file=NULL;
|
||||
datafile=NULL;
|
||||
}
|
||||
lastdatestr=datestr;
|
||||
}
|
||||
if (file==NULL)
|
||||
if (datafile==NULL)
|
||||
{
|
||||
QString path="/home/iris/TempData/"+currentTime.toString("yyyy_MM_dd")+".csv";
|
||||
system("mkdir -p /home/iris/TempData");
|
||||
file=fopen(path.toStdString().c_str(),"a+");
|
||||
fprintf(file,QString::fromLocal8Bit("日期, 数据类型, 日期~n").toStdString().c_str());
|
||||
QString path="/home/data/TempData/"+currentTime.toString("yyyy_MM_dd_hh_mm_ss")+".csv";
|
||||
system("mkdir -p /home/data/TempData");
|
||||
datafile=fopen(path.toStdString().c_str(),"a+");
|
||||
fprintf(datafile,QString::fromLocal8Bit("日期, 数据类型, 日期~n").toStdString().c_str());
|
||||
}
|
||||
|
||||
|
||||
fprintf(file,"%s,%s,%s\n",currentTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString().c_str(),sender.toStdString().c_str(),qstr.toStdString().c_str());
|
||||
fflush(file);
|
||||
fprintf(datafile,"%s,%s,%s\n",currentTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString().c_str(),sender.toStdString().c_str(),qstr.toStdString().c_str());
|
||||
fflush(datafile);
|
||||
}
|
||||
@ -19,7 +19,7 @@ void logout(T str)
|
||||
std::cout<<qstr.toStdString()<<std::endl<<std::flush;
|
||||
#endif
|
||||
}
|
||||
|
||||
void saveData(QString sender,QString qstr);
|
||||
template <typename T>
|
||||
|
||||
void saveDataToFile(QString typeofdata,T str) {
|
||||
@ -35,7 +35,7 @@ void saveDataToFile(QString typeofdata,T str) {
|
||||
QDateTime currentTime = QDateTime::currentDateTime();
|
||||
std::cout<<green<<currentTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString()<<" "<<magenta<<typeofdata.toStdString()<<reset<<": "<<qstr11.toStdString()<<std::endl<<std::flush;
|
||||
QString qstr=QString(str);
|
||||
writelogtofile(typeofdata,str);
|
||||
saveData(typeofdata,str);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user