mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-10-19 19:49:42 +08:00
添加了位置定标程序 及位置移动相关程序源码
This commit is contained in:
238
othersoft/shuttercali/source_rlx/sensor/SensorMannager.cpp
Normal file
238
othersoft/shuttercali/source_rlx/sensor/SensorMannager.cpp
Normal file
@ -0,0 +1,238 @@
|
||||
#include "SensorMannager.h"
|
||||
#include "SensorQExPRO.h"
|
||||
#include <QThread>
|
||||
#include "logout.h"
|
||||
#include "QDateTime"
|
||||
#include "QLocale"
|
||||
#include"SensorOptoSky.h"
|
||||
int maxtime = 30000;
|
||||
SensorMannager::SensorMannager(QObject *parent )
|
||||
: QObject(parent)
|
||||
{
|
||||
|
||||
Numberofscan = 5;
|
||||
//Sensor = new SensorQExPRO(QEPRO_QE);
|
||||
Sensor = new SensorOptoSky(ATP6500,"COM12");
|
||||
Sensor->initSensor();
|
||||
}
|
||||
|
||||
SensorMannager::~SensorMannager()
|
||||
{
|
||||
delete Sensor;
|
||||
logout::out("<EFBFBD>˳<EFBFBD>",1);
|
||||
|
||||
}
|
||||
|
||||
void SensorMannager::opensensor()
|
||||
{
|
||||
Sensor->initSensor();
|
||||
}
|
||||
|
||||
void SensorMannager::CloseSensor()
|
||||
{
|
||||
Sensor->CloseSensor();
|
||||
}
|
||||
|
||||
long SensorMannager::SensorOpt(int persent)
|
||||
{
|
||||
long maxvalue = Sensor->SensorInfo.maxValue*1.0*persent / 100;
|
||||
STROnePlot plot;
|
||||
long maxvaluenow = 0;
|
||||
float shutternow = 10;
|
||||
if (Sensor->SensorType=="USB2000PLUS")
|
||||
{
|
||||
// shutternow = 1;
|
||||
}
|
||||
|
||||
Sensor->Settingshuttertime(shutternow);
|
||||
|
||||
Sensor->GetOnePlot(plot);
|
||||
if (!plot.isInit)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
maxvaluenow = Getmaxvalue(plot.Plot,4, plot.BandNum-4);
|
||||
logout::out("<EFBFBD>Զ<EFBFBD><EFBFBD>ع<EFBFBD>Ϊ: " + QString::number(shutternow) + " <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ֵΪ" + QString::number(maxvaluenow),1);
|
||||
//QThread::msleep(1000);
|
||||
int numberoftry = 0;
|
||||
while (maxvaluenow<maxvalue*0.95 ||maxvaluenow>maxvalue)
|
||||
{
|
||||
|
||||
if (maxvaluenow > maxvalue)
|
||||
{
|
||||
shutternow = shutternow *0.9;
|
||||
}
|
||||
else
|
||||
{
|
||||
shutternow = maxvalue * 0.98 / (maxvaluenow * 1.0)*shutternow + 1;
|
||||
}
|
||||
if (shutternow>maxtime)
|
||||
{
|
||||
shutternow = maxtime;
|
||||
}
|
||||
//QThread::msleep(100);
|
||||
Sensor->Settingshuttertime(shutternow);
|
||||
Sensor->GetOnePlot(plot);
|
||||
if (plot.isInit)
|
||||
{
|
||||
maxvaluenow = Getmaxvalue(plot.Plot, 4, plot.BandNum - 4);
|
||||
|
||||
}
|
||||
|
||||
|
||||
numberoftry++;
|
||||
|
||||
logout::out("<EFBFBD>Զ<EFBFBD><EFBFBD>ع<EFBFBD>Ϊ: " + QString::number(shutternow) + " <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ֵΪ"+QString::number(maxvaluenow),1);
|
||||
if (numberoftry>200)
|
||||
{
|
||||
logout::out("<EFBFBD>عⳢ<EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ع<EFBFBD>ʧ<EFBFBD><CAA7>",3);
|
||||
return -1;
|
||||
|
||||
}
|
||||
if (shutternow == maxtime)
|
||||
{
|
||||
logout::out("<EFBFBD>ع<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ﵽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>",3);
|
||||
return -1*maxtime;
|
||||
}
|
||||
|
||||
}
|
||||
logout::out("<EFBFBD>ع<EFBFBD><EFBFBD>ɹ<EFBFBD> <20>ع<EFBFBD>ʱ<EFBFBD><CAB1>Ϊ: "+QString::number(shutternow)+" <20><><EFBFBD><EFBFBD>",1);
|
||||
return shutternow;
|
||||
|
||||
}
|
||||
|
||||
long SensorMannager::Getmaxvalue(float *arr, int start, int lenth)
|
||||
{
|
||||
long val = -1;
|
||||
for (size_t i = start; i < lenth; i++)
|
||||
{
|
||||
if (val <= arr[i])
|
||||
{
|
||||
val = arr[i];
|
||||
}
|
||||
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
void SensorMannager::SetnumbertoGot(int nscan)
|
||||
{
|
||||
Numberofscan = nscan;
|
||||
}
|
||||
|
||||
void SensorMannager::GetSifData(QString outfilepath, bool isskyfirs /*= true*/)
|
||||
{
|
||||
|
||||
Sensor->SettingShutterOpen(true);//ȷ<><C8B7>shutter<65><72><EFBFBD><EFBFBD>
|
||||
QThread::msleep(50);
|
||||
Sensor->SettingSwitchShutter(true);//<2F>л<EFBFBD>Ϊsky
|
||||
logout::out("Switch <20>л<EFBFBD><D0BB><EFBFBD>SKY",1);
|
||||
QThread::msleep(50);
|
||||
//////////////////////////<2F>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD>////////////////////////////////////////////////
|
||||
float skyshutter=SensorOpt();
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
{
|
||||
|
||||
if (skyshutter!=-1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
skyshutter = SensorOpt();
|
||||
|
||||
}
|
||||
/////////////////////////////////////////////
|
||||
if (skyshutter==-1)//opt<70><74><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>δ-1 ˵<><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
logout::out("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",3);
|
||||
return;
|
||||
}
|
||||
skyshutter = abs(skyshutter);
|
||||
Sensor->SettingSwitchShutter(false);//<2F>л<EFBFBD>ΪVEG
|
||||
logout::out("Switch <20>л<EFBFBD><D0BB><EFBFBD>VEG",1);
|
||||
QThread::msleep(50);
|
||||
//////////////////////////veg////////////////////////////////////////////////
|
||||
float vegshutter = SensorOpt();
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
{
|
||||
if (vegshutter ==-1 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
vegshutter = SensorOpt();
|
||||
|
||||
}
|
||||
if (vegshutter == -1)
|
||||
{
|
||||
logout::out("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",3);
|
||||
return;
|
||||
}
|
||||
vegshutter = abs(vegshutter);
|
||||
//////////////////////////ģ<><C4A3><EFBFBD>ָ<EFBFBD>////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////<2F><EFBFBD><F2BFAAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>////////////////////////////////////////////////
|
||||
FILE *fp = fopen(outfilepath.toStdString().c_str(), "w");
|
||||
if (fp==NULL)
|
||||
{
|
||||
logout::out("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>" + outfilepath + "ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>", 3);
|
||||
return;
|
||||
}
|
||||
//fprintf(fp, "%s<><73>
|
||||
STROnePlot oneplot;
|
||||
float tempp = Sensor->GettingTempratrue();
|
||||
WriteTitletoCSV(fp, Sensor->SensorInfo.SensorName,Numberofscan, tempp, Sensor->SensorInfo.WavelenthStr, skyshutter, vegshutter);
|
||||
logout::setoutlevel(10);
|
||||
Sensor->SettingSwitchShutter(true);//<2F>л<EFBFBD><D0BB><EFBFBD>sky
|
||||
Sensor->Settingshuttertime(skyshutter);
|
||||
for (size_t i = 0; i < Numberofscan; i++)
|
||||
{
|
||||
logout::out("<EFBFBD><EFBFBD>ʼ<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>"+QString::number(i+1)+"<EFBFBD><EFBFBD>Sky <20><><EFBFBD><EFBFBD>");
|
||||
Sensor->GetOnePlot(oneplot,true);
|
||||
writeonedatatoCSV(fp, oneplot);
|
||||
}
|
||||
|
||||
Sensor->SettingSwitchShutter(false);//<2F>л<EFBFBD>ΪVEG
|
||||
Sensor->Settingshuttertime(vegshutter);
|
||||
for (size_t i = 0; i < Numberofscan; i++)
|
||||
{
|
||||
logout::out("<EFBFBD><EFBFBD>ʼ<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>" + QString::number(i+1) + "<EFBFBD><EFBFBD>Veg <20><><EFBFBD><EFBFBD>");
|
||||
Sensor->GetOnePlot(oneplot,true);
|
||||
writeonedatatoCSV(fp, oneplot);
|
||||
}
|
||||
fflush(fp);
|
||||
fclose(fp);
|
||||
logout::out("<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",1);
|
||||
logout::setoutlevel();
|
||||
|
||||
}
|
||||
|
||||
void SensorMannager::writeonedatatoCSV(FILE *fp, STROnePlot plot)
|
||||
{
|
||||
//.fprintf(fp, "%s,%s,%s\n", xvaluetoWrite.at(i).toStdString().c_str()
|
||||
size_t lenth = plot.BandNum;
|
||||
size_t i;
|
||||
for (i = 0; i < lenth-1; i++)
|
||||
{
|
||||
fprintf(fp, "%s,", QString::number(plot.Plot[i], 'f', 1).toStdString().c_str());
|
||||
|
||||
}
|
||||
fprintf(fp, "%s\n", QString::number(plot.Plot[i], 'f', 1).toStdString().c_str());
|
||||
}
|
||||
|
||||
void SensorMannager::WriteTitletoCSV(FILE *fp, QString sensname, int NmberofScan, float temp, QString wavestring, float skyshutter, float vegshutter)
|
||||
{
|
||||
if (fp == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QDateTime datetime = QDateTime::currentDateTime();
|
||||
QLocale locale = QLocale::English;
|
||||
QString datestr = locale.toString(datetime, "ddd MMM dd hh:mm:ss yyyy");
|
||||
fprintf(fp, "observation date and time: %s\n", datestr.toStdString().c_str());
|
||||
fprintf(fp, "numberofscan: %s\n", QString::number(Numberofscan).toStdString().c_str());
|
||||
fprintf(fp, "spectrometer: %s\n", sensname.toStdString().c_str());
|
||||
fprintf(fp, "ambient temperature: %s\n", QString::number(temp,'f',2).toStdString().c_str());
|
||||
fprintf(fp, "%s\n", wavestring.toStdString().c_str());
|
||||
fprintf(fp, "integration time 1: %s\n", QString::number(skyshutter, 'f', 2).toStdString().c_str());
|
||||
fprintf(fp, "integration time 2: %s\n", QString::number(vegshutter, 'f', 2).toStdString().c_str());
|
||||
}
|
||||
|
Reference in New Issue
Block a user