mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-10-19 11:49:42 +08:00
在服务器上第一次调试
This commit is contained in:
306
source_rlx/sensor/SensorOptoSky.cpp
Normal file
306
source_rlx/sensor/SensorOptoSky.cpp
Normal file
@ -0,0 +1,306 @@
|
||||
#include "SensorOptoSky.h"
|
||||
#include "OptoSkyType.h"
|
||||
#include "logout.h"
|
||||
#include "QtEndian"
|
||||
using namespace OptoSky;
|
||||
SensorOptoSky::SensorOptoSky(OPTOSENSORTYPE type, QString comname, qint32 bandrate)
|
||||
|
||||
{
|
||||
sensortype = type;
|
||||
SensorType = "opt";
|
||||
SensorInfo.SensorName = "opotsky";
|
||||
COMname = comname;
|
||||
BandRate = bandrate;
|
||||
shutter.resize(2);
|
||||
|
||||
//SendComment(comi);
|
||||
}
|
||||
|
||||
SensorOptoSky::SensorOptoSky(OPTOSENSORTYPE type, QString comname)
|
||||
{
|
||||
|
||||
sensortype = type;
|
||||
SensorType = "opt";
|
||||
SensorInfo.SensorName = "opotsky";
|
||||
COMname = comname;
|
||||
BandRate = 115200;
|
||||
shutter.resize(2);
|
||||
}
|
||||
|
||||
bool SensorOptoSky::initSensor(int id /*= 0*/)
|
||||
{
|
||||
|
||||
|
||||
OptoSky::SetPortName(COMname, BandRate);
|
||||
if (!OptoSky::isSensorInit())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
SensorInfo = GetSensorInfo();
|
||||
float a = GettingTempratrue();
|
||||
//SendComment()
|
||||
return true;
|
||||
}
|
||||
|
||||
void SensorOptoSky::Settingshuttertime(float msc)
|
||||
{
|
||||
if (!OptoSky::isSensorInit())
|
||||
{
|
||||
return;
|
||||
}
|
||||
shuttertime = (int)msc;
|
||||
shutter[0] = (int)msc / 256;
|
||||
shutter[1] = (int)msc % 256;
|
||||
QByteArray temp;
|
||||
SendComment(SET_INTEGRAL_TIME,shutter);
|
||||
GetReturn(SET_INTEGRAL_TIME,temp);
|
||||
}
|
||||
|
||||
void SensorOptoSky::SettingTemprature(float temp)
|
||||
{
|
||||
QByteArray buf;
|
||||
buf.resize(2);
|
||||
|
||||
if (temp<0)
|
||||
{
|
||||
buf[0] = 0xff;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf[1] = 0x00;
|
||||
|
||||
}
|
||||
buf[1] = (int)abs(temp);
|
||||
SendComment(SET_TEC_TEMP, buf);
|
||||
GetReturn(SET_TEC_TEMP, buf);
|
||||
|
||||
}
|
||||
|
||||
float SensorOptoSky::GettingTempratrue()
|
||||
{
|
||||
if (!OptoSky::isSensorInit())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
QByteArray buf;
|
||||
SendComment(GET_TEC_TEMP);
|
||||
GetReturn(GET_TEC_TEMP, buf);
|
||||
QString str;
|
||||
str.append(buf);
|
||||
float ret = str.toFloat();
|
||||
return ret;
|
||||
}
|
||||
|
||||
STRSensorInfo SensorOptoSky::GetSensorInfo()
|
||||
{
|
||||
STRSensorInfo setem;
|
||||
if (!OptoSky::isSensorInit())
|
||||
{
|
||||
return setem;
|
||||
}
|
||||
STRSensorInfo se;
|
||||
QByteArray buf;
|
||||
SendComment(GET_PN_NUMBER);
|
||||
GetReturn(GET_PN_NUMBER, buf);
|
||||
QString str;
|
||||
str.append(buf);
|
||||
se.SensorName = str;
|
||||
logout::out("<EFBFBD>豸<EFBFBD>ͺ<EFBFBD>Ϊ<EFBFBD><EFBFBD>" + str);
|
||||
SendComment(GET_SN_NUMBER);
|
||||
GetReturn(GET_SN_NUMBER, buf);
|
||||
str.clear();
|
||||
str.append(buf);
|
||||
logout::out("<EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>Ϊ<EFBFBD><EFBFBD>" + str);
|
||||
SendComment(GET_PIXEL_LENGTH);
|
||||
GetReturn(GET_PIXEL_LENGTH, buf);
|
||||
se.BandNum = buf[0] * 256 + buf[1];
|
||||
//////////////////////////ģ<><C4A3><EFBFBD>ָ<EFBFBD>////////////////////////////////////////////////
|
||||
Settingshuttertime(6);
|
||||
SendComment(SYNCHRONIZATION_GET_DATA);
|
||||
GetReturn(SYNCHRONIZATION_GET_DATA, buf);
|
||||
se.BandNum = (buf.size() - 1)/2;
|
||||
//////////////////////////ģ<><C4A3><EFBFBD>ָ<EFBFBD>////////////////////////////////////////////////
|
||||
getwavelenthlist(se);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><DEB7><EFBFBD>ȡ <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>δ<EFBFBD><CEB4>ȡ
|
||||
//////////////////////////ģ<><C4A3><EFBFBD>ָ<EFBFBD>////////////////////////////////////////////////
|
||||
QByteArray bbb;
|
||||
bbb.resize(2);
|
||||
bbb[0] = 0x00;
|
||||
bbb[1] = 0x01;
|
||||
SendComment(SET_AVERAGE_NUMBER, bbb);
|
||||
GetReturn(SET_AVERAGE_NUMBER, bbb);
|
||||
se.maxValue = 65535;
|
||||
return se;
|
||||
}
|
||||
|
||||
void SensorOptoSky::SettingShutterOpen(bool isopen)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SensorOptoSky::SettingSwitchShutter(bool isright)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SensorOptoSky::GetOnePlot(STROnePlot &OnePlot, bool Dark)
|
||||
{
|
||||
OnePlot.temp = GettingTempratrue();
|
||||
|
||||
SendComment(SYNCHRONIZATION_GET_DATA,shutter);
|
||||
OnePlot.shutter = shuttertime;
|
||||
QByteArray buf;
|
||||
if (!GetReturn(SYNCHRONIZATION_GET_DATA, buf))
|
||||
{
|
||||
OnePlot.isInit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ((unsigned char )buf[0]==0x00)
|
||||
{
|
||||
//OnePlot.isInit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OnePlot.isInit = false;
|
||||
}
|
||||
int bandsumnwo = SensorInfo.BandNum;
|
||||
unsigned short *arr = new unsigned short[bandsumnwo];
|
||||
memcpy(arr, buf.data() + 1, bandsumnwo*2);
|
||||
if (!OnePlot.isInit)
|
||||
{
|
||||
OnePlot.Plot = new float[bandsumnwo];
|
||||
OnePlot.isInit = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < bandsumnwo; i++)
|
||||
{
|
||||
OnePlot.Plot[i] = qToBigEndian(arr[i]);
|
||||
}
|
||||
delete[] arr;
|
||||
OnePlot.BandNum = bandsumnwo;
|
||||
OnePlot.maxDNvalue = SensorInfo.maxValue;
|
||||
OnePlot.wavelenthlist = SensorInfo.wavelenthlist;
|
||||
if (Dark)
|
||||
{
|
||||
if (DarkNess.isInit)
|
||||
{
|
||||
if (DarkNess.shutter != shuttertime)
|
||||
{
|
||||
GetOneDark(DarkNess);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GetOneDark(DarkNess);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < bandsumnwo; i++)
|
||||
{
|
||||
OnePlot.Plot[i] = OnePlot.Plot[i] - DarkNess.Plot[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SensorOptoSky::CloseSensor()
|
||||
{
|
||||
closeport();
|
||||
}
|
||||
|
||||
void SensorOptoSky::GetOneDark(STROnePlot &darkplot)
|
||||
{
|
||||
STROnePlot &OnePlot = darkplot;
|
||||
OnePlot.temp = GettingTempratrue();
|
||||
OnePlot.shutter = shuttertime;
|
||||
SendComment(SYNCHRONIZATION_GET_DARK, shutter);
|
||||
QByteArray buf;
|
||||
if (!GetReturn(SYNCHRONIZATION_GET_DARK, buf))
|
||||
{
|
||||
OnePlot.isInit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ((unsigned char)buf[0] == 0x00)
|
||||
{
|
||||
//OnePlot.isInit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OnePlot.isInit = false;
|
||||
}
|
||||
int bandsumnwo = SensorInfo.BandNum;
|
||||
unsigned short *arr = new unsigned short[bandsumnwo];
|
||||
memcpy(arr, buf.data() + 1, bandsumnwo * 2);
|
||||
if (!OnePlot.isInit)
|
||||
{
|
||||
OnePlot.Plot = new float[bandsumnwo];
|
||||
OnePlot.isInit = true;
|
||||
}
|
||||
for (size_t i = 0; i < bandsumnwo; i++)
|
||||
{
|
||||
OnePlot.Plot[i] = qToBigEndian(arr[i]);
|
||||
|
||||
|
||||
}
|
||||
delete[] arr;
|
||||
OnePlot.BandNum = bandsumnwo;
|
||||
OnePlot.maxDNvalue = SensorInfo.maxValue;
|
||||
OnePlot.wavelenthlist = SensorInfo.wavelenthlist;
|
||||
OnePlot.DataType = DARKNESS;
|
||||
|
||||
}
|
||||
|
||||
SensorOptoSky::~SensorOptoSky()
|
||||
{
|
||||
CloseSensor();
|
||||
}
|
||||
|
||||
void SensorOptoSky::RemoveHeaderandEnd(QByteArray &buf)
|
||||
{
|
||||
if (buf.size()<6)
|
||||
{
|
||||
return;
|
||||
}
|
||||
buf.remove(0, 5);
|
||||
buf.remove(buf.size() - 1,1);
|
||||
|
||||
}
|
||||
|
||||
void SensorOptoSky::getwavelenthlist(STRSensorInfo &se)
|
||||
{
|
||||
if (!OptoSky::isSensorInit())
|
||||
{
|
||||
return ;
|
||||
}
|
||||
QByteArray bufin;
|
||||
bufin.resize(2);
|
||||
bufin[0] = 0x00;
|
||||
bufin[1] = 0x01;
|
||||
QByteArray buf;
|
||||
SendComment(GET_WAVELENGTH_CALIBRATION_COFF,bufin);
|
||||
GetReturn(GET_WAVELENGTH_CALIBRATION_COFF, buf);
|
||||
float a[4];
|
||||
memcpy(a, buf.data() + 16, 4 * 4);
|
||||
int bandsss = se.BandNum;
|
||||
QStringList strlist;
|
||||
QString str="";
|
||||
int i = 0;
|
||||
for ( i = 0; i <bandsss-1 ; i++)
|
||||
{
|
||||
float wavelenth = a[0] * i*i*i + a[1] * i*i + a[2] * i + a[3];
|
||||
strlist.append(QString::number(wavelenth, 'f', 2) );
|
||||
str = str + QString::number(wavelenth, 'f', 2) + ",";
|
||||
|
||||
}
|
||||
|
||||
float wavelenth = a[0] * i*i*i + a[1] * i*i + a[2] * i + a[3];
|
||||
str = str + QString::number(wavelenth, 'f', 2);
|
||||
strlist.append(QString::number(wavelenth, 'f', 2));
|
||||
se.wavelenthlist = strlist;
|
||||
se.WavelenthStr = str;
|
||||
}
|
Reference in New Issue
Block a user