mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-10-19 11:49:42 +08:00
Compare commits
13 Commits
d8c9d070dc
...
master
Author | SHA1 | Date | |
---|---|---|---|
030381aa5c | |||
455013fa07 | |||
3275a1abd6 | |||
45e9592718 | |||
776769c206 | |||
dcba7db121 | |||
e68eed4f56 | |||
d5a8175aba | |||
2269432ef7 | |||
e8abb254f7 | |||
285f37b043 | |||
6e53ea4db2 | |||
f1c5aa6902 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -21,3 +21,6 @@
|
||||
/othersoft/movingliner/cmake-build-release/
|
||||
/othersoft/TemperatureControler/project/cmake-build-debug/
|
||||
/othersoft/calibration_console/cmake-build-debug/
|
||||
/othersoft/TemperatureControler/project/cmake-build-debug-towersif/
|
||||
/othersoft/TemperatureControler/project/cmake-build-debug-towersif/
|
||||
/DEB/
|
||||
|
@ -32,9 +32,9 @@ add_executable( TowerOptoSifAndSpectral
|
||||
${SRC_LIST}
|
||||
)
|
||||
IF (WIN32)
|
||||
target_link_libraries(TowerOptoSifAndSpectral SeaBreeze)
|
||||
target_link_libraries(TowerOptoSifAndSpectral SeaBreeze)
|
||||
ELSE ()
|
||||
target_link_libraries(TowerOptoSifAndSpectral seabreeze usb stdc++ m)
|
||||
target_link_libraries(TowerOptoSifAndSpectral seabreeze usb stdc++ m)
|
||||
ENDIF ()
|
||||
qt5_use_modules(TowerOptoSifAndSpectral ${QT})
|
||||
set_target_properties(TowerOptoSifAndSpectral PROPERTIES AUTOMOC ON)
|
||||
|
@ -1,42 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.3)
|
||||
|
||||
project(TowerOptoSifAndSpectral)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(QT Core Network WebSockets SerialPort Widgets)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
find_package(Qt5 REQUIRED ${QT})
|
||||
|
||||
|
||||
file(GLOB_RECURSE HDR_LIST "source/*.h")
|
||||
file(GLOB_RECURSE SRC_LIST "source/*.cpp")
|
||||
|
||||
include_directories("source")
|
||||
include_directories("source/FS")
|
||||
include_directories("source/Logger")
|
||||
include_directories("source/ZZ_SDK")
|
||||
include_directories("source/Settings")
|
||||
include_directories("source/CaptureThread")
|
||||
include_directories("source/LinearShutter")
|
||||
include_directories("source/OSIF/include")
|
||||
include_directories("source/Misc_Detector")
|
||||
include_directories("source/Uploader")
|
||||
|
||||
link_directories("source/OSIF/DLib")
|
||||
link_directories("/home/pi/SeaBrease/lib")
|
||||
add_executable( TowerOptoSifAndSpectral
|
||||
main.cpp
|
||||
${HDR_LIST}
|
||||
${SRC_LIST}
|
||||
)
|
||||
IF (WIN32)
|
||||
target_link_libraries(TowerOptoSifAndSpectral SeaBreeze)
|
||||
ELSE ()
|
||||
target_link_libraries(TowerOptoSifAndSpectral seabreeze usb stdc++ m)
|
||||
ENDIF ()
|
||||
qt5_use_modules(TowerOptoSifAndSpectral ${QT})
|
||||
set_target_properties(TowerOptoSifAndSpectral PROPERTIES AUTOMOC ON)
|
||||
|
||||
|
42
deb_pack.sh
Executable file
42
deb_pack.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 检查是否提供了版本号参数
|
||||
#if [ $# -eq 0 ]; then
|
||||
# echo "错误:请提供版本号参数"
|
||||
# echo "用法: $0 <版本号>"
|
||||
# exit 1
|
||||
#fi
|
||||
|
||||
VERSION=2.1
|
||||
sh install.sh
|
||||
|
||||
thispwd=$(pwd)
|
||||
#cd /home/pi/
|
||||
|
||||
DebDirectory=DebpackTowerSif
|
||||
|
||||
mkdir $DebDirectory
|
||||
cd $DebDirectory/
|
||||
|
||||
mkdir -p ./home/pi/bin
|
||||
cd home/pi/bin/
|
||||
cp /home/pi/bin/* .
|
||||
|
||||
cd ../../..
|
||||
mkdir DEBIAN
|
||||
cd DEBIAN
|
||||
echo "Package: TowerSif
|
||||
Version: $VERSION
|
||||
Architecture: armhf
|
||||
Maintainer: rlx, tc
|
||||
Description: test" > control
|
||||
|
||||
#cd /home/pi/
|
||||
cd $thispwd
|
||||
sudo dpkg -b $DebDirectory TowerSif_V${VERSION}.deb
|
||||
mkdir -p DEB
|
||||
cp TowerSif_V${VERSION}.deb DEB/
|
||||
rm -r $DebDirectory
|
||||
|
||||
#sudo dpkg -r TowerSif
|
||||
|
@ -0,0 +1,6 @@
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ../
|
||||
make -j4
|
||||
cd ../othersoft
|
||||
sh install.sh
|
2
main.cpp
2
main.cpp
@ -94,7 +94,7 @@ int main(int argc, char *argv[])
|
||||
//m_mduUploader.Initialize();
|
||||
m_ctrlHumitureDetector.Initialize(m_struHumitureDI.qstrInterfaceName.toStdString());
|
||||
//////////////////////////////////////////////////////////////////////////prepare
|
||||
//m_sTimer.Preheating();
|
||||
m_sTimer.Preheating();
|
||||
m_ctrlHumitureDetector.GetHumiture_retry(m_fChassisTemp, m_fChassisHum);
|
||||
m_ctrlHumitureDetector.GetHumiture_retry(m_fChassisTemp, m_fChassisHum);
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
{
|
||||
"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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -10,13 +10,16 @@ include_directories("../src/json")
|
||||
include_directories("../src/TimeWorker")
|
||||
include_directories("../src/Temperature")
|
||||
include_directories("../src/controler")
|
||||
|
||||
include_directories("../src/sunfunction")
|
||||
set(CMAKE_MOC_VERBOSE TRUE)
|
||||
add_executable(TemperatureControler
|
||||
tempmain.cpp
|
||||
../src/TimeWorker/TimeWorker.cpp
|
||||
../src/json/logout.cpp
|
||||
../src/Temperature/TemperaTureWoker.cpp
|
||||
../src/controler/controler.cpp
|
||||
../src/Temperature/TG_Manager.cpp
|
||||
../src/Temperature/TemperatureRegulator.cpp
|
||||
../src/sunfunction/sunupanddown.cpp
|
||||
|
||||
)
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
{
|
||||
"TimeConfig": {
|
||||
"StartTime": "00:00:00",
|
||||
"EndTime": "23:59:00",
|
||||
"IntervalTime": 10
|
||||
},
|
||||
"TemperatureConfig": {
|
||||
"PortName": "ttyS2",
|
||||
"BaudRate": 115200,
|
||||
"Pin": {
|
||||
"TG": {
|
||||
"Pin_H": 2,
|
||||
"Pin_L": 3
|
||||
},
|
||||
"Fan": {
|
||||
"Pin": 10
|
||||
},
|
||||
"HOT": {
|
||||
"Pin": 7
|
||||
}
|
||||
},
|
||||
"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}]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,14 +2,31 @@
|
||||
// Created by xin on 24-12-11.
|
||||
//
|
||||
#include <iostream>
|
||||
#include <TemperaTureWoker.h>
|
||||
#include <TemperatureRegulator.h>
|
||||
#include <TimeWorker.h>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <qthread.h>
|
||||
#include <fstream>
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QCoreApplication aaaaa(argc, argv);
|
||||
std::cout<<"Hello World";
|
||||
TemperaTureWoker *pTemperaTureWoker = new TemperaTureWoker();
|
||||
std::cout<<"Hello World"<<std::flush;
|
||||
json j;
|
||||
std::ifstream i("/home/data/Setting/Constant_Temperature_Config.json");
|
||||
|
||||
|
||||
i>>j;
|
||||
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();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
138
othersoft/TemperatureControler/src/Temperature/TG_Manager.cpp
Normal file
138
othersoft/TemperatureControler/src/Temperature/TG_Manager.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
//
|
||||
// Created by xin on 25-3-31.
|
||||
//
|
||||
|
||||
#include "TG_Manager.h"
|
||||
#include "string"
|
||||
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;
|
||||
InitManger();
|
||||
}
|
||||
|
||||
bool TG_Manager::SetTuiGan(int IS_High)
|
||||
{
|
||||
|
||||
switch (IS_High)
|
||||
{
|
||||
case 2:
|
||||
{std::string comand1 = "gpio write " + std::to_string(pin1_H) + " 0";
|
||||
std::string comand2 = "gpio write " + std::to_string(pin1_L) + " 0";
|
||||
system(comand1.c_str());
|
||||
system(comand2.c_str());
|
||||
break;}
|
||||
case 1:
|
||||
{std::string comand3 = "gpio write " + std::to_string(pin1_H) + " 1";
|
||||
std::string comand4 = "gpio write " + std::to_string(pin1_L) + " 0";
|
||||
system(comand3.c_str());
|
||||
system(comand4.c_str());
|
||||
break;}
|
||||
case 0:
|
||||
{std::string comand3 = "gpio write " + std::to_string(pin1_H) + " 0";
|
||||
std::string comand4 = "gpio write " + std::to_string(pin1_L) + " 1";
|
||||
system(comand3.c_str());
|
||||
system(comand4.c_str());
|
||||
break;}
|
||||
default:
|
||||
{std::string comand1 = "gpio write " + std::to_string(pin1_H) + " 0";
|
||||
std::string comand2 = "gpio write " + std::to_string(pin1_L) + " 0";
|
||||
system(comand1.c_str());
|
||||
system(comand2.c_str());
|
||||
break;}
|
||||
}
|
||||
|
||||
if (IS_High)
|
||||
{
|
||||
std::string comand1 = "gpio write " + std::to_string(pin1_H) + " 1";
|
||||
std::string comand2 = "gpio write " + std::to_string(pin1_L) + " 0";
|
||||
system(comand1.c_str());
|
||||
system(comand2.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string comand1 = "gpio write " + std::to_string(pin1_H) + " 0";
|
||||
std::string comand2 = "gpio write " + std::to_string(pin1_L) + " 1";
|
||||
system(comand1.c_str());
|
||||
system(comand2.c_str());
|
||||
}
|
||||
return 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";
|
||||
system(comand1.c_str());
|
||||
system(comand2.c_str());
|
||||
system(comand3.c_str());
|
||||
system(comand4.c_str());
|
||||
SetTuiGan(0);
|
||||
SetSwitch1Status(0);
|
||||
SetSwitch2Status(0);
|
||||
}
|
||||
bool TG_Manager::SetSwitch1Status(bool status)
|
||||
{
|
||||
if (status)
|
||||
{
|
||||
std::string comand1 = "gpio write " + std::to_string(pin2_H) + " 1";
|
||||
system(comand1.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string comand1 = "gpio write " + std::to_string(pin2_H) + " 0";
|
||||
system(comand1.c_str());
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
bool TG_Manager::SetSwitch2Status(bool status)
|
||||
{
|
||||
if (status)
|
||||
{
|
||||
std::string comand1 = "gpio write " + std::to_string(pin2_L) + " 1";
|
||||
system(comand1.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string comand1 = "gpio write " + std::to_string(pin2_L) + " 0";
|
||||
system(comand1.c_str());
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
bool TG_Manager::Heating()
|
||||
{
|
||||
printf("Heating\n");
|
||||
SetTuiGan(true);
|
||||
SetSwitch1Status(true);
|
||||
SetSwitch2Status(false);
|
||||
WorkingStatus = HEATING;
|
||||
return true;
|
||||
}
|
||||
bool TG_Manager::Cooling()
|
||||
{
|
||||
printf("Cooling\n");
|
||||
SetTuiGan(false);
|
||||
SetSwitch1Status(false);
|
||||
SetSwitch2Status(true);
|
||||
WorkingStatus = COOLING;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TG_Manager::Stop(){
|
||||
SetTuiGan(2);
|
||||
SetSwitch1Status(false);
|
||||
SetSwitch2Status(false);
|
||||
WorkingStatus = NotWroking;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
int TG_Manager::GetManagerStatus(){
|
||||
return WorkingStatus;
|
||||
}
|
||||
|
44
othersoft/TemperatureControler/src/Temperature/TG_Manager.h
Normal file
44
othersoft/TemperatureControler/src/Temperature/TG_Manager.h
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// Created by xin on 25-3-31.
|
||||
//
|
||||
|
||||
#ifndef TG_MANAGER_H
|
||||
#define TG_MANAGER_H
|
||||
|
||||
enum WORKINGSTATUS{
|
||||
HEATING=1,
|
||||
COOLING=2,
|
||||
NotWroking=0
|
||||
};
|
||||
|
||||
class TG_Manager {
|
||||
public:
|
||||
|
||||
void SetPin(int pin1_H=7, int pin1_L=10, int pin2_H=2, int pin2_L=4);
|
||||
void InitManger();
|
||||
|
||||
bool Heating();
|
||||
bool Cooling();
|
||||
bool Stop();
|
||||
int GetManagerStatus();
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
bool SetTuiGan(int IS_High);
|
||||
bool SetSwitch1Status(bool status);
|
||||
bool SetSwitch2Status(bool status);
|
||||
int pin1_H=7;
|
||||
int pin1_L=10;
|
||||
int pin2_H=2;
|
||||
int pin2_L=4;
|
||||
bool ping1_status=false;
|
||||
int WorkingStatus=NotWroking;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //TG_MANAGER_H
|
@ -6,42 +6,66 @@
|
||||
#include "fstream"
|
||||
#include <iostream>
|
||||
#include <qthread.h>
|
||||
#include <QDebug>
|
||||
TemperaTureWoker::TemperaTureWoker() {
|
||||
m_SerialPort = new QSerialPort();
|
||||
json jsonconfig;
|
||||
std::ifstream i("/home/data/Setting/tempreature.json");
|
||||
//<2F>ж<EFBFBD><D0B6>ļ<EFBFBD><C4BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (!i.is_open())
|
||||
|
||||
}
|
||||
//
|
||||
// TemperaTureWoker::TemperaTureWoker(json jsonconfig) {
|
||||
//
|
||||
// if(jsonconfig.contains("portname")&&jsonconfig["portname"].is_string())
|
||||
// {
|
||||
//
|
||||
// }else {
|
||||
// jsonconfig["portname"] = "ttyS2";
|
||||
// }
|
||||
// if(jsonconfig.contains("baudrate")&&jsonconfig["baudrate"].is_number()) {
|
||||
// }
|
||||
// else {
|
||||
// jsonconfig["baudrate"] = 115200;
|
||||
// }
|
||||
// m_SerialPort->setPortName(jsonconfig["portname"].get<std::string>().c_str());
|
||||
// m_SerialPort->setBaudRate(jsonconfig["baudrate"].get<int>());
|
||||
// if (!m_SerialPort->open(QIODevice::ReadWrite))
|
||||
// {
|
||||
// std::cout << "Error open serial port" << std::endl;
|
||||
// m_isInit = false;
|
||||
// return;
|
||||
// }
|
||||
// else {
|
||||
// std::cout << "Open serial port success" << std::endl;
|
||||
// m_isInit = true;
|
||||
// }
|
||||
// tempera_group temp1;
|
||||
// tempera_group temp2;
|
||||
// tempera_group temp3;
|
||||
// tempera_group temp4;
|
||||
// m_Tempreaturegroups.append(temp1);
|
||||
// m_Tempreaturegroups.append(temp2);
|
||||
// m_Tempreaturegroups.append(temp3);
|
||||
// m_Tempreaturegroups.append(temp4);
|
||||
//
|
||||
//
|
||||
// ReadTempreature();
|
||||
// }
|
||||
|
||||
void TemperaTureWoker::OpenCom(QString portname, int baudrate) {
|
||||
if (m_SerialPort== nullptr)
|
||||
{
|
||||
std::cout << "Error open file" << std::endl;
|
||||
jsonconfig["portname"] = "ttyS2";
|
||||
jsonconfig["baudrate"] = 115200;
|
||||
|
||||
|
||||
}else {
|
||||
i >> jsonconfig;
|
||||
if(jsonconfig.contains("portname")&&jsonconfig["portname"].is_string())
|
||||
{
|
||||
|
||||
}else {
|
||||
jsonconfig["portname"] = "ttyS2";
|
||||
m_SerialPort=new QSerialPort();
|
||||
}
|
||||
if(jsonconfig.contains("baudrate")&&jsonconfig["baudrate"].is_number()) {
|
||||
}
|
||||
else {
|
||||
jsonconfig["baudrate"] = 115200;
|
||||
}
|
||||
}
|
||||
m_SerialPort->setPortName(jsonconfig["portname"].get<std::string>().c_str());
|
||||
m_SerialPort->setBaudRate(jsonconfig["baudrate"].get<int>());
|
||||
m_SerialPort->setPortName(portname);
|
||||
m_SerialPort->setBaudRate(baudrate);
|
||||
if (!m_SerialPort->open(QIODevice::ReadWrite))
|
||||
{
|
||||
std::cout << "Error open serial port" << std::endl;
|
||||
// std::cout << "Error open serial port" << std::endl;
|
||||
qDebug()<< "Error open serial port";
|
||||
m_isInit = false;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
std::cout << "Open serial port success" << std::endl;
|
||||
//std::cout << "Open serial port success" << std::endl;
|
||||
qDebug()<< "Open serial port success";
|
||||
m_isInit = true;
|
||||
}
|
||||
tempera_group temp1;
|
||||
@ -55,9 +79,6 @@ TemperaTureWoker::TemperaTureWoker() {
|
||||
|
||||
|
||||
ReadTempreature();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TemperaTureWoker::ReadTempreature() {
|
||||
@ -79,10 +100,12 @@ void TemperaTureWoker::ReadTempreature() {
|
||||
}
|
||||
|
||||
if (lenth==0) {
|
||||
std::cout << "No data" << std::endl;
|
||||
//std::cout << "No data" << std::endl;
|
||||
qDebug()<< "No data";
|
||||
return;
|
||||
}
|
||||
std::cout << data.toStdString() << std::endl;
|
||||
std::cout << data.toStdString();
|
||||
//qDebug() << data;
|
||||
json jsondata = json::parse(data.toStdString());
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
if(jsondata.contains("Temperature"+std::to_string(j+1))) {
|
||||
@ -101,15 +124,19 @@ void TemperaTureWoker::ReadTempreature() {
|
||||
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><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
|
||||
<< m_Tempreaturegroups[i].tempera[j] << "\t|";
|
||||
}
|
||||
//qDebug() <<"\n";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
} else {
|
||||
std::cout << "Serial port is not init" << std::endl;
|
||||
//std::cout << "Serial port is not init" << std::endl;
|
||||
qDebug()<< "Serial port is not init";
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,10 +18,12 @@ class TemperaTureWoker:public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TemperaTureWoker();
|
||||
// TemperaTureWoker(json jconfig);
|
||||
void OpenCom(QString portname,int baudrate);
|
||||
QList<tempera_group> m_Tempreaturegroups;
|
||||
void ReadTempreature();
|
||||
private:
|
||||
QSerialPort *m_SerialPort;
|
||||
QSerialPort *m_SerialPort= nullptr;
|
||||
bool m_isInit=false;
|
||||
|
||||
};
|
||||
|
@ -0,0 +1,358 @@
|
||||
//
|
||||
// Created by xin on 25-4-2.
|
||||
//
|
||||
|
||||
#include "TemperatureRegulator.h"
|
||||
#include "logout.h"
|
||||
#include "sunupanddown.h"
|
||||
TemperatureRegulator *g_tempretureRegulator;
|
||||
TemperatureRegulator::TemperatureRegulator(){
|
||||
|
||||
g_tempretureRegulator=this;
|
||||
}
|
||||
/*
|
||||
"PortName": "ttyS2",
|
||||
"BaudRate": 115200,
|
||||
"Pin": {
|
||||
"TG": {
|
||||
"Pin_H": 2,
|
||||
"Pin_L": 3
|
||||
},
|
||||
"Fan": {
|
||||
"Pin": 10
|
||||
},
|
||||
"HOT": {
|
||||
"Pin": 7
|
||||
}
|
||||
},
|
||||
"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}]
|
||||
}
|
||||
|
||||
**/
|
||||
void TemperatureRegulator::setconfig(json jconfig) {
|
||||
QString Port_Name="ttyS2";
|
||||
int BaudRate=115200;
|
||||
|
||||
if (jconfig.contains("PortName")) {
|
||||
Port_Name=QString::fromStdString(jconfig["PortName"]);
|
||||
}
|
||||
if (jconfig.contains("BaudRate")) {
|
||||
BaudRate=jconfig["BaudRate"];
|
||||
}
|
||||
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;
|
||||
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("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"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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("CoolBegin_Temp_Insight")) {
|
||||
m_CoolBegin_Temp_Insight=jconfig["Constant_Temperature"]["CoolBegin_Temp_Insight"];
|
||||
}
|
||||
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("Location")) {
|
||||
if (jconfig["Location"].contains("latitude")) {
|
||||
m_Latitude=jconfig["Location"]["latitude"];
|
||||
}
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
// qDebug()<< "current tempreture is " << tempreture;
|
||||
if (tempreture>M_Targert_Max_Tempreature)
|
||||
{
|
||||
m_TG_Manager->Cooling();
|
||||
}
|
||||
else if (tempreture<M_Targert_Min_Tempreature)
|
||||
{
|
||||
m_TG_Manager->Heating();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_TG_Manager->Stop();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool TemperatureRegulator::looptask() {
|
||||
g_tempretureRegulator->loop();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,85 @@
|
||||
//
|
||||
// Created by xin on 25-4-2.
|
||||
//
|
||||
|
||||
#ifndef TEMPERATUREREGULATOR_H
|
||||
#define TEMPERATUREREGULATOR_H
|
||||
#include "TG_Manager.h"
|
||||
#include "TemperaTureWoker.h"
|
||||
#include "QObject"
|
||||
#include "vector"
|
||||
#define INSIGHT_TEMPERATURE 0
|
||||
#define OUTSIGHT_TEMPERATURE 1
|
||||
/*
|
||||
* "PortName": "ttyS2",
|
||||
"BaudRate": 115200,
|
||||
"Pin": {
|
||||
"TG": {
|
||||
"Pin_H": 2,
|
||||
"Pin_L": 3
|
||||
},
|
||||
"Fan": {
|
||||
"Pin": 10
|
||||
},
|
||||
"HOT": {
|
||||
"Pin": 7
|
||||
}
|
||||
},
|
||||
"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}]
|
||||
}
|
||||
**/
|
||||
struct indexofdata
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
class TemperatureRegulator :public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TemperatureRegulator();
|
||||
void setconfig(json j);
|
||||
void SetTartGetX_Y(int x,int y);
|
||||
void addTargetIndex(int x,int y,int Data_type=INSIGHT_TEMPERATURE);
|
||||
float GetMax_of_Vector(int Data_type=INSIGHT_TEMPERATURE);
|
||||
float GetMin_of_Vector(int Data_type=INSIGHT_TEMPERATURE);
|
||||
void init();
|
||||
void loop();
|
||||
static bool looptask();
|
||||
void PanduanCooling();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
TemperaTureWoker *m_TemperaTureWoker;
|
||||
TG_Manager *m_TG_Manager;
|
||||
float M_Targert_Max_Tempreature=35;
|
||||
float M_Targert_Min_Tempreature=25;
|
||||
float m_CoolBegin_Temp_Insight=20;
|
||||
float m_CoolBegin_Diff_Temp=5;
|
||||
float m_HeatingBegin_Temp_Insight=0;
|
||||
bool m_IsCoolInDaylight=false;
|
||||
int m_target_index=0;
|
||||
std::vector<indexofdata> m_target_index_of_insight;
|
||||
std::vector<indexofdata> m_target_index_of_outsight;
|
||||
int m_target_indey=0;
|
||||
bool isinit=false;
|
||||
float m_Latitude=39.9;
|
||||
float m_Longitude=116.4;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //TEMPERATUREREGULATOR_H
|
@ -135,3 +135,13 @@ try
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TimeWorker::ReadConfig(json j) {
|
||||
if (j.contains("StartTime")&&j["StartTime"].is_string())
|
||||
m_StartTime=QTime::fromString(QString::fromStdString(j["StartTime"]),"hh:mm:ss");
|
||||
if(j.contains("EndTime")&&j["EndTime"].is_string())
|
||||
m_EndTime=QTime::fromString(QString::fromStdString(j["EndTime"]),"hh:mm:ss");
|
||||
if (j.contains("IntervalTime")&&j["IntervalTime"].is_number())
|
||||
SetIntervalTime(j["IntervalTime"].get<int>()*1000);
|
||||
logout("TimeWorker","ReadjsonConfig success: StartTime:"+m_StartTime.toString("hh:mm:ss")+" EndTime:"+m_EndTime.toString("hh:mm:ss")+" IntervalTime:"+QString::number(m_IntervalTime)+"ms",6);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
void SetWorkTime(QTime start,QTime end);
|
||||
void SetWorkTime(QString start,QString end);
|
||||
void ReadjsonConfig(QString path);
|
||||
void ReadConfig(json j);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -115,3 +115,29 @@ void writelogtofile(QString sender,QString qstr)
|
||||
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);
|
||||
}
|
||||
|
||||
void saveData(QString sender,QString qstr)
|
||||
{
|
||||
QDateTime currentTime = QDateTime::currentDateTime();
|
||||
QString datestr=currentTime.toString("yyyy_MM_dd");
|
||||
if (lastdatestr!=datestr)
|
||||
{
|
||||
if (file!=NULL)
|
||||
{
|
||||
fclose(file);
|
||||
file=NULL;
|
||||
}
|
||||
lastdatestr=datestr;
|
||||
}
|
||||
if (file==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());
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
@ -20,12 +20,30 @@ void logout(T str)
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
void saveDataToFile(QString typeofdata,T str) {
|
||||
const std::string red("\033[0;31m");
|
||||
const std::string green("\033[0;32m");
|
||||
const std::string yellow("\033[0;33m");
|
||||
const std::string blue("\033[0;34m");
|
||||
const std::string magenta("\033[0;35m");
|
||||
const std::string cyan("\033[0;36m");
|
||||
const std::string reset("\033[0m");
|
||||
|
||||
QString qstr11=QString(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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void logout(QString sender,T str,int level = 5)
|
||||
{
|
||||
|
||||
|
||||
|
||||
const std::string red("\033[0;31m");
|
||||
const std::string green("\033[0;32m");
|
||||
const std::string yellow("\033[0;33m");
|
||||
@ -35,6 +53,8 @@ void logout(QString sender,T str,int level = 5)
|
||||
const std::string reset("\033[0m");
|
||||
|
||||
|
||||
|
||||
|
||||
QString qstr11=QString(str);
|
||||
// Log(qstr,3);
|
||||
QDateTime currentTime = QDateTime::currentDateTime();
|
||||
|
@ -0,0 +1,99 @@
|
||||
//
|
||||
// Created by xin on 25-5-8.
|
||||
//
|
||||
|
||||
#include "sunupanddown.h"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
bool isLeapYear(int year) {
|
||||
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
|
||||
}
|
||||
int dayOfYear(int year, int month, int day) {
|
||||
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
if (isLeapYear(year)) {
|
||||
days[2] = 29;
|
||||
}
|
||||
int sum = day;
|
||||
for (int i = 1; i < month; ++i) {
|
||||
sum += days[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
void calculateSunriseSunset(int year, int month, int day, double latitude, double longitude,
|
||||
double &sunrise, double &sunset, bool &hasSunlight) {
|
||||
int n = dayOfYear(year, month, day);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>̫<EFBFBD><CCAB><EFBFBD><EFBFBD>γ<EFBFBD><CEB3><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ȣ<EFBFBD>
|
||||
double delta_deg = 23.44 * sin(2 * M_PI * (284.0 + n) / 365.0);
|
||||
double delta_rad = delta_deg * M_PI / 180.0;
|
||||
|
||||
// <20>ճ<EFBFBD><D5B3><EFBFBD><EFBFBD><EFBFBD>ʱ̫<CAB1><CCAB><EFBFBD>߶Ƚǣ<C8BD><C7A3><EFBFBD><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣩
|
||||
double h0_deg = -0.833;
|
||||
double h0_rad = h0_deg * M_PI / 180.0;
|
||||
|
||||
// γ<><CEB3>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
double phi_rad = latitude * M_PI / 180.0;
|
||||
double sin_phi = sin(phi_rad);
|
||||
double cos_phi = cos(phi_rad);
|
||||
double sin_delta = sin(delta_rad);
|
||||
double cos_delta = cos(delta_rad);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
double numerator = sin(h0_rad) - sin_phi * sin_delta;
|
||||
double denominator = cos_phi * cos_delta;
|
||||
|
||||
if (denominator == 0) {
|
||||
hasSunlight = false;
|
||||
return;
|
||||
}
|
||||
|
||||
double cos_omega = numerator / denominator;
|
||||
|
||||
if (cos_omega < -1.0 || cos_omega > 1.0) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҹ
|
||||
hasSunlight = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>Dz<EFBFBD>ת<EFBFBD><D7AA>ΪСʱ
|
||||
double omega_rad = acos(cos_omega);
|
||||
double omega_deg = omega_rad * 180.0 / M_PI;
|
||||
double omega_hours = omega_deg / 15.0;
|
||||
|
||||
// <20>ط<EFBFBD>ʱ<EFBFBD>ճ<EFBFBD><D5B3><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
double sunrise_local = 12.0 - omega_hours;
|
||||
double sunset_local = 12.0 + omega_hours;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
double timezone_h = round(longitude / 15.0);
|
||||
double timezone_lon = timezone_h * 15.0;
|
||||
double time_diff = (longitude - timezone_lon) / 15.0; // Сʱ
|
||||
|
||||
// ת<><D7AA>Ϊ<EFBFBD><CEAA>ʱ<D7BC><CAB1>
|
||||
sunrise = sunrise_local - time_diff;
|
||||
sunset = sunset_local - time_diff;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
sunrise = fmod(sunrise + 24.0, 24.0);
|
||||
sunset = fmod(sunset + 24.0, 24.0);
|
||||
|
||||
hasSunlight = true;
|
||||
}
|
||||
|
||||
SunInfo calculateSunriseSunset(int year, int month, int day, double latitude, double longitude){
|
||||
SunInfo sunInfo;
|
||||
double sunrise, sunset;
|
||||
bool hasSunlight;
|
||||
|
||||
calculateSunriseSunset(year, month, day, latitude, longitude, sunrise, sunset, hasSunlight);
|
||||
|
||||
sunInfo.sunrise_h = floor(sunrise);
|
||||
sunInfo.sunrise_m = (sunrise - sunInfo.sunrise_h) * 60;
|
||||
sunInfo.sunset_h = floor(sunset);
|
||||
sunInfo.sunset_m = (sunset - sunInfo.sunset_h) * 60;
|
||||
sunInfo.hasSunlight = hasSunlight;
|
||||
|
||||
return sunInfo;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by xin on 25-5-8.
|
||||
//
|
||||
|
||||
#ifndef SUNUPANDDOWN_H
|
||||
#define SUNUPANDDOWN_H
|
||||
struct SunInfo {
|
||||
double sunrise_h; // <20>ճ<EFBFBD>ʱ<EFBFBD>䣨Сʱ<D0A1><CAB1>
|
||||
double sunrise_m; // <20>ճ<EFBFBD>ʱ<EFBFBD>䣨<EFBFBD><E4A3A8><EFBFBD>ӣ<EFBFBD>
|
||||
double sunset_h; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>䣨Сʱ<D0A1><CAB1>
|
||||
double sunset_m; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>䣨<EFBFBD><E4A3A8><EFBFBD>ӣ<EFBFBD>
|
||||
bool hasSunlight; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
SunInfo calculateSunriseSunset(int year, int month, int day, double latitude, double longitude);
|
||||
|
||||
void calculateSunriseSunset(int year, int month, int day, double latitude, double longitude,
|
||||
double &sunrise, double &sunset, bool &hasSunlight);
|
||||
|
||||
|
||||
|
||||
#endif //SUNUPANDDOWN_H
|
@ -1,7 +1,7 @@
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
mkdir movingliner
|
||||
mkdir -p movingliner
|
||||
cd movingliner
|
||||
cmake ../../movingliner
|
||||
make -j4
|
||||
@ -11,15 +11,23 @@ echo beging build shuttercali
|
||||
|
||||
cd ../
|
||||
|
||||
mkdir shuttercali
|
||||
mkdir -p shuttercali
|
||||
cd shuttercali
|
||||
cmake ../../shuttercali/project/LocationCali
|
||||
make -j4
|
||||
cp ./shutter_calibrate /home/pi/bin
|
||||
|
||||
cd ../
|
||||
mkdir -p TemperatureControler
|
||||
cd TemperatureControler
|
||||
cmake ../../TemperatureControler/project
|
||||
make -j4
|
||||
cp ./TemperatureControler /home/pi/bin
|
||||
mkdir -p /home/data/Setting
|
||||
cp ../../TemperatureControler/Constant_Temperature_Config.json /home/data/Setting
|
||||
cd ../
|
||||
|
||||
mkdir console
|
||||
mkdir -p console
|
||||
cd console
|
||||
cmake ../../calibration_console
|
||||
make -j4
|
||||
@ -36,7 +44,7 @@ cd ../
|
||||
cp ./root/Mywathdog.sh /root
|
||||
cp ./root/start.sh /root
|
||||
chmod +x /root/start.sh
|
||||
mkdir /home/data
|
||||
mkdir -p /home/data
|
||||
cd ../
|
||||
rm -rf ./TowerOptoSifAndSpectral
|
||||
cd /root/filebrew
|
||||
@ -47,5 +55,5 @@ sudo apt-get install -y timedatectl
|
||||
timedatectl set-timezone Asia/Shanghai
|
||||
date -R
|
||||
sudo hwclock -w -f /dev/rtc0
|
||||
sudo reboot
|
||||
#sudo reboot
|
||||
#tc
|
||||
|
@ -6,4 +6,5 @@ chmod +x /root/ffwatch.sh
|
||||
mount /dev/mmcblk1p1 /home/data/
|
||||
chmod +x /root/Mywathdog.sh
|
||||
bash /root/Mywathdog.sh &
|
||||
/home/pi/bin/TemperatureControler > /root/templog.log &
|
||||
|
||||
|
Reference in New Issue
Block a user