37 Commits

Author SHA1 Message Date
faf83b2545 fix:
1、光谱bin2 hdr文件中的波长信息;
2、第一次运行创建配置文件时,添加推流配置;
2024-12-04 16:13:56 +08:00
e8760dcfe5 优化编码参数解决问题:
1、编码后数据量过大导致大疆图传中断;
2、大疆遥控器解码后,视频出现偶尔后退的情况;
2024-09-25 13:46:55 +08:00
bd4d055129 待解决bug:有的仪器使用avio_open/av_write_frame将视频写入文件会崩溃,而且写入的视频无法播放; 2024-03-01 10:15:27 +08:00
a91f5f5b04 1、添加配置文件控制推流参数;
2、解决遥控器解码时帧序混乱的问题(gop_size = 1);
3、完善代码;
2024-01-29 17:21:07 +08:00
2e4679aaef 实现功能:提取rgb波段并通过h264编码; 2024-01-23 15:33:18 +08:00
061e1f83bd add:记录cpu温度; 2023-10-25 15:37:15 +08:00
d0b67b47c1 add:psdk重启后,通知本程序发送本程序的状态; 2023-10-25 15:33:52 +08:00
7fa3b70d10 Modify:去掉内存池; 2023-10-18 11:39:01 +08:00
781b33f577 add:添加温湿度传感器硬件,并解析温湿度/气压等数据; 2023-10-18 11:37:02 +08:00
f33103c970 fix:修复时间同步错误 2023-09-13 17:24:16 +08:00
a341e0b2c5 add:采集过程中同时记录相机温度,高于80度停止采集,高于90度系统关闭 2023-09-13 17:08:17 +08:00
19e2309be7 fix:返回的曝光时间都使用微秒; 2023-09-04 18:03:20 +08:00
a492baea18 fix:惯导进入full nav才开始采集高光谱; 2023-09-01 15:38:16 +08:00
096df8075c 修改:
记录上次设置的帧率和曝光时间,打开时,将上次的帧率和曝光时间设置为当前参数;
2023-08-29 13:46:40 +08:00
ba1b01bccc fix bug:解析sbg的sulution mode; 2023-08-18 16:01:22 +08:00
e4a7c4481b 打印版本号 2023-07-14 16:34:31 +08:00
1476c2bc15 内存映射mremap在320G时会失败,改为用fwrite,经测试980PRO 2个bin1 采集80分钟不会丢帧; 2023-07-14 16:33:37 +08:00
6d6b662cec 输出调试信息 2023-07-14 09:21:58 +08:00
2e158431e7 输出版本号:35 2023-07-04 21:23:25 +08:00
6473a1f4ce 内存映射写磁盘 2023-07-04 21:22:38 +08:00
cc76d62ded 1. 使用相机时间来计算times文件;
2. times放弃每帧写一次的方法;
3. 不满100帧的内容不丢弃:添加一个队列来记录压入队列的帧数;
2023-06-30 15:21:23 +08:00
e620c87ecf 打印版本号 2023-06-28 13:32:59 +08:00
47002ad894 改变光谱bin2的波长计算方式为:通过bin1平均相邻波长获取; 2023-06-28 11:59:46 +08:00
5337a40837 更新:发送 bin 状态到遥控器 2023-06-27 14:01:19 +08:00
6b78db5bc3 改变写线程退出方式,不再等待一段时间; 2023-06-25 21:20:45 +08:00
73f9b00b02 修改写线程总等待时间为:4275ms 2023-06-25 18:28:43 +08:00
6fc2680a1c 1. 配置文件:ximeadll加入 getBufferPolicy 和 getAcqBufferSize;
2. 增大内存池的大小,以便100帧写一次硬盘;
3. 增加ximea报错代码:10/11,将报错代码添加时间写入文件;
2023-06-21 16:43:33 +08:00
09d224075a 1. 通过sock发送设置成功的帧率;
2. 通过sock发送设置成功的曝光时间和曝光时最大的像素值;
2023-05-24 16:38:10 +08:00
371c422a34 1. 错误控制;
2. 创建配置文件的文件夹;
2023-04-10 15:54:57 +08:00
b31cd5fc8a 1、关闭影像文件句柄;
2、将sbg文件后缀从sbg改为bin;
2023-04-03 13:17:56 +08:00
447a1aafb1 1. 最大曝光时间乘以0.95,目的:避免曝光时间超过最大,而造成帧率降低;
2. 去掉多余的std::out,避免采集log过于杂乱;
3. 通过OpenCV从高光谱影像中提取rgb影像;
4. 在log中记录开始采集时间和停止采集时间;
5. 添加手动设置曝光时间的功能:127.0.0.1 7,2;
6. 头文件中写入仪器序列号;
2023-03-19 16:44:12 +08:00
e96953b54a 优化:
1. 通过内存池解决丢帧问题;
2. 解析惯导卫星个数,并通过socket发送给psdk;
3. 取消通过sbg卫星时间设置linux系统时间,此功能交给psdk做;
2022-12-24 16:59:41 +08:00
da57cc8e87 修补627f666提交没注意的曝光bug 2022-12-07 19:33:51 +08:00
cbff36447b 更改配置文件读写文件路径到:/media/nvme/300TC/config/ximea.cfg; 2022-12-06 14:50:18 +08:00
627f666d30 修改:
1. 写配置文件类修改:为了提高帧率 → 直接设置有效窗口,后期不进行roi裁剪;
2. 配合ximea采集类,修改写文件fwrite代码:
3. sbg新端口;
2022-11-22 23:23:32 +08:00
87a35f5dd4 新增 + 修改
1. 分离空间维(水平)和光谱维(垂直)的bin1和bin2有效窗口的参数:configfile.cpp和ximeaimager.cpp都需要修改相应代码;
2. 为了减少光谱仪的热量累积,加入了usb开电、断电功能,udpserver.cpp需要增加相应开电、断电代码:
3. 使用了云一峰的新板子,linux识别的惯导串口号改变:sbgrecorder.cpp;
2022-10-13 16:30:40 +08:00
374a48022b 修复路径问题
1. 配置文件创建在程序所在目录;
2. csv文件(ximea温度)输出路径改为:/home/programRunLog/hyperspectralLog;
2022-10-09 23:00:15 +08:00
17 changed files with 2658 additions and 265 deletions

4
.gitignore vendored
View File

@ -1,2 +1,4 @@
.idea .idea
build build
/温度测试
扩展板接口.txt

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.5.2)
project(ximeaAirborneSystem) project(ximeaAirborneSystem)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
@ -9,7 +9,7 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(QT Core Network SerialPort) set(QT Core Network SerialPort Gui)
set(TEMPLATE app) set(TEMPLATE app)
set(TARGET ximeaImageRecorder) set(TARGET ximeaImageRecorder)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
@ -17,9 +17,15 @@ find_package(Qt5 REQUIRED ${QT})#
include_directories(.) include_directories(.)
include_directories(/home/300tc/library/ximeaControlDll/Header_Files) include_directories(/home/300tc/library/ximeaControlDll/Header_Files)
link_directories(/home/300tc/library/ximeaControlDll) link_directories(/home/300tc/library/ximeaControlDll)
find_package(OpenCV 4.2.0 REQUIRED)
include_directories(/usr/local/include/opencv4/)
link_directories(/usr/local/lib)
include_directories(/home/300tc/library/ffmpeg_build/include)
link_directories(/home/300tc/library/ffmpeg_build/lib)
add_executable(${CMAKE_PROJECT_NAME} add_executable(${CMAKE_PROJECT_NAME}
Source_Files/fileoperation.cpp Source_Files/fileoperation.cpp
Header_Files/fileoperation.h Header_Files/fileoperation.h
@ -41,10 +47,17 @@ add_executable(${CMAKE_PROJECT_NAME}
Source_Files/ximeaimager.cpp Source_Files/ximeaimager.cpp
Header_Files/ximeaimager.h Header_Files/ximeaimager.h
Source_Files/configfile.cpp Source_Files/configfile.cpp
Header_Files/configfile.h) Header_Files/configfile.h
Header_Files/MemoryPool.tcc
Header_Files/MemoryPool.h Source_Files/rgbImage.cpp Header_Files/rgbImage.h)
qt5_use_modules(${CMAKE_PROJECT_NAME} ${QT}) qt5_use_modules(${CMAKE_PROJECT_NAME} ${QT})
target_link_libraries(${CMAKE_PROJECT_NAME} target_link_libraries(${CMAKE_PROJECT_NAME}
irisXimeaImager irisXimeaImager
libconfig.so libconfig.so
libconfig++.so) libconfig++.so
${OpenCV_LIBS}
avformat
avcodec
swscale
avutil)

98
Header_Files/MemoryPool.h Normal file
View File

@ -0,0 +1,98 @@
/*-
* Copyright (c) 2013 Cosku Acay, http://www.coskuacay.com
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef MEMORY_POOL_H
#define MEMORY_POOL_H
#include <climits>
#include <cstddef>
template <typename T, size_t BlockSize = 409200000>
class MemoryPool
{
public:
/* Member types */
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef const T* const_pointer;
typedef const T& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef std::false_type propagate_on_container_copy_assignment;
typedef std::true_type propagate_on_container_move_assignment;
typedef std::true_type propagate_on_container_swap;
template <typename U> struct rebind {
typedef MemoryPool<U> other;
};
/* Member functions */
MemoryPool() noexcept;
MemoryPool(const MemoryPool& memoryPool) noexcept;
MemoryPool(MemoryPool&& memoryPool) noexcept;
template <class U> MemoryPool(const MemoryPool<U>& memoryPool) noexcept;
~MemoryPool() noexcept;
MemoryPool& operator=(const MemoryPool& memoryPool) = delete;
MemoryPool& operator=(MemoryPool&& memoryPool) noexcept;
pointer address(reference x) const noexcept;
const_pointer address(const_reference x) const noexcept;
// Can only allocate one object at a time. n and hint are ignored
pointer allocate(size_type n = 1, const_pointer hint = 0);
void deallocate(pointer p, size_type n = 1);
size_type max_size() const noexcept;
template <class U, class... Args> void construct(U* p, Args&&... args);
template <class U> void destroy(U* p);
template <class... Args> pointer newElement(Args&&... args);
void deleteElement(pointer p);
private:
union Slot_ {
value_type element;
Slot_* next;
};
typedef char* data_pointer_;
typedef Slot_ slot_type_;
typedef Slot_* slot_pointer_;
slot_pointer_ currentBlock_;
slot_pointer_ currentSlot_;
slot_pointer_ lastSlot_;
slot_pointer_ freeSlots_;
size_type padPointer(data_pointer_ p, size_type align) const noexcept;
void allocateBlock();
static_assert(BlockSize >= 2 * sizeof(slot_type_), "BlockSize too small.");
};
#include "MemoryPool.tcc"
#endif // MEMORY_POOL_H

235
Header_Files/MemoryPool.tcc Normal file
View File

@ -0,0 +1,235 @@
/*-
* Copyright (c) 2013 Cosku Acay, http://www.coskuacay.com
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef MEMORY_BLOCK_TCC
#define MEMORY_BLOCK_TCC
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::size_type
MemoryPool<T, BlockSize>::padPointer(data_pointer_ p, size_type align)
const noexcept
{
uintptr_t result = reinterpret_cast<uintptr_t>(p);
return ((align - result) % align);
}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>::MemoryPool()
noexcept
{
currentBlock_ = nullptr;
currentSlot_ = nullptr;
lastSlot_ = nullptr;
freeSlots_ = nullptr;
}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>::MemoryPool(const MemoryPool& memoryPool)
noexcept :
MemoryPool()
{}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>::MemoryPool(MemoryPool&& memoryPool)
noexcept
{
currentBlock_ = memoryPool.currentBlock_;
memoryPool.currentBlock_ = nullptr;
currentSlot_ = memoryPool.currentSlot_;
lastSlot_ = memoryPool.lastSlot_;
freeSlots_ = memoryPool.freeSlots;
}
template <typename T, size_t BlockSize>
template<class U>
MemoryPool<T, BlockSize>::MemoryPool(const MemoryPool<U>& memoryPool)
noexcept :
MemoryPool()
{}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>&
MemoryPool<T, BlockSize>::operator=(MemoryPool&& memoryPool)
noexcept
{
if (this != &memoryPool)
{
std::swap(currentBlock_, memoryPool.currentBlock_);
currentSlot_ = memoryPool.currentSlot_;
lastSlot_ = memoryPool.lastSlot_;
freeSlots_ = memoryPool.freeSlots;
}
return *this;
}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>::~MemoryPool()
noexcept
{
slot_pointer_ curr = currentBlock_;
while (curr != nullptr) {
slot_pointer_ prev = curr->next;
operator delete(reinterpret_cast<void*>(curr));
curr = prev;
}
}
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::pointer
MemoryPool<T, BlockSize>::address(reference x)
const noexcept
{
return &x;
}
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::const_pointer
MemoryPool<T, BlockSize>::address(const_reference x)
const noexcept
{
return &x;
}
template <typename T, size_t BlockSize>
void
MemoryPool<T, BlockSize>::allocateBlock()
{
// Allocate space for the new block and store a pointer to the previous one
data_pointer_ newBlock = reinterpret_cast<data_pointer_>
(operator new(BlockSize));
reinterpret_cast<slot_pointer_>(newBlock)->next = currentBlock_;
currentBlock_ = reinterpret_cast<slot_pointer_>(newBlock);
// Pad block body to staisfy the alignment requirements for elements
data_pointer_ body = newBlock + sizeof(slot_pointer_);
size_type bodyPadding = padPointer(body, alignof(slot_type_));
currentSlot_ = reinterpret_cast<slot_pointer_>(body + bodyPadding);
lastSlot_ = reinterpret_cast<slot_pointer_>
(newBlock + BlockSize - sizeof(slot_type_) + 1);
}
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::pointer
MemoryPool<T, BlockSize>::allocate(size_type n, const_pointer hint)
{
if (freeSlots_ != nullptr) {
pointer result = reinterpret_cast<pointer>(freeSlots_);
freeSlots_ = freeSlots_->next;
return result;
}
else {
if (currentSlot_ >= lastSlot_)
allocateBlock();
return reinterpret_cast<pointer>(currentSlot_++);
}
}
template <typename T, size_t BlockSize>
inline void
MemoryPool<T, BlockSize>::deallocate(pointer p, size_type n)
{
if (p != nullptr) {
reinterpret_cast<slot_pointer_>(p)->next = freeSlots_;
freeSlots_ = reinterpret_cast<slot_pointer_>(p);
}
}
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::size_type
MemoryPool<T, BlockSize>::max_size()
const noexcept
{
size_type maxBlocks = -1 / BlockSize;
return (BlockSize - sizeof(data_pointer_)) / sizeof(slot_type_) * maxBlocks;
}
template <typename T, size_t BlockSize>
template <class U, class... Args>
inline void
MemoryPool<T, BlockSize>::construct(U* p, Args&&... args)
{
new (p) U (std::forward<Args>(args)...);
}
template <typename T, size_t BlockSize>
template <class U>
inline void
MemoryPool<T, BlockSize>::destroy(U* p)
{
p->~U();
}
template <typename T, size_t BlockSize>
template <class... Args>
inline typename MemoryPool<T, BlockSize>::pointer
MemoryPool<T, BlockSize>::newElement(Args&&... args)
{
pointer result = allocate();
construct<value_type>(result, std::forward<Args>(args)...);
return result;
}
template <typename T, size_t BlockSize>
inline void
MemoryPool<T, BlockSize>::deleteElement(pointer p)
{
if (p != nullptr) {
p->~value_type();
deallocate(p);
}
}
#endif // MEMORY_BLOCK_TCC

View File

@ -9,9 +9,14 @@
#include <iomanip> #include <iomanip>
#include <cstdlib> #include <cstdlib>
#include <libconfig.h++> #include <libconfig.h++>
#include <string>
#include <QFileInfo> #include <QFileInfo>
#include <QString> #include <QString>
#include <QCoreApplication>
#include <QDir>
#include "utility_tc.h"
using namespace std; using namespace std;
using namespace libconfig; using namespace libconfig;
@ -25,10 +30,19 @@ public:
bool isConfigfileExist(); bool isConfigfileExist();
bool parseConfigfile(); bool parseConfigfile();
bool getBin(int &bin); bool getSpectralBin(int &spectralBin);
bool getspatialBin(int &spatialBin);
bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety); bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety);
bool getEffectiveWindowRoi(int &width, int &offsetx); bool getEffectiveWindowRoi(int &width, int &offsetx);
bool getWindowOffsety_HeightOfSpectral(int &offsety, int &height, string spectralBinString);//spectralBinString = "bin1"或者”bin2“
bool getGainOffset(float &gain, float &offset); bool getGainOffset(float &gain, float &offset);
bool getGainOffsetOfSpectralBin1(float &gain, float &offset);
bool getSN(QString &SN);
bool getBufferPolicy(int &bufferPolicy);
bool getAcqBufferSize(int &acqBufferSize);
bool getPushFlowParam(int &flowSwitch, int &rgbHeight, int &framerateVideo);
bool createConfigFile(); bool createConfigFile();
bool updateConfigFile(); bool updateConfigFile();
@ -37,4 +51,55 @@ private:
string m_configfilePath; string m_configfilePath;
Config cfg; Config cfg;
}; };
class ParameterConfigfile
{
public:
ParameterConfigfile();
void setConfigfilePath(string configfilePath);
bool isConfigfileExist();
bool parseConfigfile();
bool getFrameRate(int &frameRate);
bool setFrameRate(int frameRate);
bool getExposeTime(float &exposeTime);
bool setExposeTime(float exposeTime);
bool createConfigFile();
// bool updateConfigFile();
bool writeConfig2File();
string m_configfilePath;
Config cfg;
private:
};
class StateOf300tcConfigfile:public ParameterConfigfile
{
public:
StateOf300tcConfigfile();
bool getSwitchState(bool &switchState);
bool setSwitchState(bool switchState);
bool getSbgState(int &sbgState);
bool setSbgState(int sbgState);
bool getSbgSolutionMode(int &sbgSolutionMode);
bool setSbgSolutionMode(int sbgSolutionMode);
bool getXimeaState(int &ximeaState);
bool setXimeaState(int ximeaState);
bool getExposeMaxValueOfOneFrame(int &exposeMaxValueOfOneFrame);
bool setExposeMaxValueOfOneFrame(int exposeMaxValueOfOneFrame);
bool createConfigFile();
private:
bool getIntValue(int &value, string field);
bool setIntValue(int value, string field);
};
#endif //XIMEAIMAGERECORDER_CONFIGFILE_H #endif //XIMEAIMAGERECORDER_CONFIGFILE_H

84
Header_Files/rgbImage.h Normal file
View File

@ -0,0 +1,84 @@
//
// Created by tangchao on 2022/12/24.
//
#ifndef XIMEAAIRBORNESYSTEM_RGBIMAGE_H
#define XIMEAAIRBORNESYSTEM_RGBIMAGE_H
#include <iostream>
#include <string>
#include <QObject>
#include <QImage>
#include <opencv2/opencv.hpp>//包含了所有东西,编译很慢
#include "opencv2/imgproc/types_c.h"
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
#include "libavutil/pixfmt.h"
#include "libswscale/swscale.h"
#include <libavutil/imgutils.h>
#include <libavutil/avutil.h>
#include "libavdevice/avdevice.h"
}
using namespace cv;
class rgbImage :public QObject
{
Q_OBJECT
public:
rgbImage(QWidget* pParent = NULL);
~rgbImage();
void SetRgbImageWidthAndHeight(int BandCount, int Width, int height);
void SetRgbBandNumber(int redBandNumber, int greenBandNumber, int blueBandNumber);
void FillRgbImage(unsigned short *datacube);
void FillFocusGrayImage(unsigned short *datacube);
void FillFocusGrayQImage(unsigned short * datacube);
void FillOnerowofRgbImage(cv::Mat * matRgbImage, int rowNumber, unsigned short *datacube);
QImage Mat2QImage(cv::Mat cvImg);//https://www.cnblogs.com/annt/p/ant003.html
QImage *m_QRgbImage;
cv::Mat *m_matRgbImage;
QImage m_Qphoto;
QImage *m_qimageFocusGrayImage;
cv::Mat *m_matFocusGrayImage;//用于调焦时,显示一帧的灰度图
//cv::Mat m_matFocusGrayImage;//用于调焦时,显示一帧的灰度图
CvVideoWriter *m_frame_writer;
VideoWriter m_VideoWriter;
// VideoWriter m_video("appsrc ! autovideoconvert ! filesink location=/media/nvme/delete/live.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(640, 480));
// VideoWriter video("test.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(640, 480));//
//控制该填充rgb图像第几帧数据
//以下两种情况需要重置为01调用函数SetRgbImageWidthAndHeight2每次开始填充数据前
int m_iFrameCounter;
int m_iFramerate;//
protected:
private:
int m_iSampleNumber;//
int m_iBandNumber;//
int m_iFrameNumber;//
void initffmpeg();
int m_iRedBandNumber;
int m_iGreenBandNumber;
int m_iBlueBandNumber;
public slots:
signals :
void sendstr(QString str);
void sendstr1(QString str);
void refreslabelimg(QImage* img1);
};
#endif //XIMEAAIRBORNESYSTEM_RGBIMAGE_H

View File

@ -69,8 +69,7 @@ namespace sbgtc
void sbgSolutionModeSignal(int); void sbgSolutionModeSignal(int);
void sbgAccuracySignal(int); void sbgAccuracySignal(int, int);
}; };
} }

View File

@ -11,17 +11,43 @@
#include <QObject> #include <QObject>
#include <QThread> #include <QThread>
#include <QDir> #include <QDir>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include "ximeaimager.h" #include "ximeaimager.h"
#include "sbgrecorder.h" #include "sbgrecorder.h"
#include "fileoperation.h" #include "fileoperation.h"
#include "configfile.h"
extern "C" extern "C"
{ {
// #include <sbgEComLib.h> // #include <sbgEComLib.h>
#include <stdlib.h> #include <stdlib.h>
} }
class Record300TcTemperature : public QObject
{
Q_OBJECT
public:
Record300TcTemperature();
void stopRecordTemperature();
private:
bool m_bIsRecord;
QSerialPort * m_serial;
float parseMessage(QByteArray * data);
public slots:
void recordTemperature(QString filePath);
signals:
};
class UdpServer:public QObject class UdpServer:public QObject
{ {
Q_OBJECT Q_OBJECT
@ -48,6 +74,11 @@ class UdpServer:public QObject
void sender(int status); void sender(int status);
QThread * m_recordTempThread;
Record300TcTemperature * m_300tcTemperature;
StateOf300tcConfigfile stateOf300tc;
signals: signals:
void systemStart(); void systemStart();
void systemStop(); void systemStop();
@ -56,6 +87,7 @@ signals:
void startDeleteFileSignal(); void startDeleteFileSignal();
void recordXimeaOnlySignal(double,QString); void recordXimeaOnlySignal(double,QString);
void record300tcTemperatureSignal(QString);
public slots: public slots:
void onRecordFinished(); void onRecordFinished();
@ -63,9 +95,12 @@ public slots:
void sendSerialPortStatus(int serialPortStatus); void sendSerialPortStatus(int serialPortStatus);
void sendSbgSolutionModeState(int SolutionMode); void sendSbgSolutionModeState(int SolutionMode);
void sendSbgAccuracyState(int Accuracy); void sendSbgAccuracyState(int Accuracy,int SatelliteCounter);
void sendXimeaImageStatus(int ximeaImageStatus); void sendXimeaImageStatus(int ximeaImageStatus);
void sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOneFrame, double exposeTime);
void sendXimeaBinState(int spatialBin, int spectralBin);
void sendXimeaImageFrameRate(double frameRate);
void sendCopyFileStatus(int fileStatus); void sendCopyFileStatus(int fileStatus);
}; };
#endif // UDPSERVER_H #endif // UDPSERVER_H

View File

@ -2,15 +2,22 @@
#define UTILITY_TC_H #define UTILITY_TC_H
#include <iostream> #include <iostream>
#include <ctime>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
QString getFileNameBaseOnTime(); QString getFileNameBaseOnTime();
QString formatTimeStr(char * format);
//https://blog.csdn.net/MoreWindows/article/details/6657829 //https://blog.csdn.net/MoreWindows/article/details/6657829
void bubbleSort(unsigned short * a, int n); void bubbleSort(unsigned short * a, int n);
void swap(unsigned short * a, unsigned short * b); void swap(unsigned short * a, unsigned short * b);
bool createDir(QString fullPath);
QList<QString> getFileInfo(QString file);
#endif // UTILITY_TC_H #endif // UTILITY_TC_H

View File

@ -25,10 +25,15 @@
#include <fstream> #include <fstream>
#include <unistd.h> #include <unistd.h>
#include <exception> #include <exception>
#include <fcntl.h>
#include <sys/mman.h>
#include <cmath>
#include <vector>
#include <QObject> #include <QObject>
#include <QDateTime> #include <QDateTime>
#include <qthread.h> #include <qthread.h>
#include <QDir>
#include "configfile.h" #include "configfile.h"
@ -36,6 +41,16 @@
#include "math.h" #include "math.h"
#include "utility_tc.h" #include "utility_tc.h"
#include "MemoryPool.h"
#include <queue>
#include <QMutex>
#include <QUdpSocket>
#include "rgbImage.h"
#define PUSH_FLOW_PORT 666
//#ifdef WIN32 //#ifdef WIN32
//#include <xiApi.h> // Windows //#include <xiApi.h> // Windows
@ -43,12 +58,30 @@
//#include <m3api/xiApi.h> // Linux, OSX //#include <m3api/xiApi.h> // Linux, OSX
//#endif //#endif
//struct DataBuffer
//{
// unsigned short data[409200/2];
//};
class DataBuffer
{
public:
DataBuffer();
~DataBuffer();
unsigned short data[41040000];//1368*300*100=41040000为了兼容所有设置spectral bin和spatial bin
private:
};
class XimeaImager;
class RecordXimeaTemperature : public QObject class RecordXimeaTemperature : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
RecordXimeaTemperature(Iris::IrisXimeaImager * imager); RecordXimeaTemperature(Iris::IrisXimeaImager * imager, XimeaImager * ximeaImager);
void stopRecordTemperature(); void stopRecordTemperature();
@ -56,6 +89,7 @@ private:
Iris::IrisXimeaImager * m_imager; Iris::IrisXimeaImager * m_imager;
bool m_bIsRecord; bool m_bIsRecord;
XimeaImager * m_ximeaImager;
public slots: public slots:
void recordTemperature(QString filePath); void recordTemperature(QString filePath);
@ -63,16 +97,74 @@ signals:
}; };
//queue<DataBuffer *> q;
//static QMutex r_qtx{ QMutex::Recursive };
static std::mutex r_qtx;
class WriteData2Disk : public QObject
{
Q_OBJECT
public:
WriteData2Disk();
void setParm(queue<DataBuffer *> * q, queue<int> * qFrameCounter, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
private:
queue<DataBuffer *> * m_q;
queue<int> * m_qFrameCounter;
QString m_QbaseFileName;
int m_iFrameSizeInByte;
int m_iNumber_WriteDisk;
MemoryPool<DataBuffer> * m_pool;
bool isExitWriteData2Disk;
rgbImage * m_rgbImage;
public slots:
void write2Disk();
void exitWriteData2Disk();
signals:
};
class PushFlow : public QObject
{
Q_OBJECT
public:
PushFlow();
void setParm(rgbImage * img, int width, int height, int framerateVideo);
void exitPushFlow();
void setVedioFilePath(QString path);
private:
QString m_QVedioFilePath;
bool isExitPushFlow;
rgbImage * m_rgbImage;
int m_iWidth;
int m_iHeight;
int m_iFramerateVideo;
public slots:
void encodePushFlow();
signals:
};
class XimeaImager : public QObject class XimeaImager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
XimeaImager(); XimeaImager();
~XimeaImager();
void setFramerate(double framerate); void setFramerate(double framerate);
double getFramerate(); double getFramerate();
double setExposureTime(float exposureTime); double setExposureTime(float exposureTime_in_us);
int wrapSetExposureTime(float exposureTime_in_us);
double getExposureTime(); double getExposureTime();
double autoExposure(); double autoExposure();
void setGain(double gain); void setGain(double gain);
@ -84,8 +176,12 @@ public:
int getWindowEndBand(); int getWindowEndBand();
double geWavelengthAtBand(int x); double geWavelengthAtBand(int x);
static int findClosestIndex(const std::vector<double>& numbers, double target);
void getRgbBandNumber(int &redBandNumber, int &greenBandNumber, int &blueBandNumber);
void stopRecord(); void stopRecord();
int getFrameCounter(); int getFrameCounter();
void writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes);
int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel); int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel);
@ -95,46 +191,52 @@ private:
int m_iImagerState; int m_iImagerState;
int m_iImagerStateTemp; int m_iImagerStateTemp;
int m_iOffsetyOfSpectralBin1, m_iOffsetyOfSpectralBin2;
int m_iHeightOfSpectralBin1, m_iHeightOfSpectralBin2;
QThread * m_recordTempThread; QThread * m_recordTempThread;
RecordXimeaTemperature * m_ximeaTemperature; RecordXimeaTemperature * m_ximeaTemperature;
QThread * writeData2DiskThread;
WriteData2Disk * writeData2Disk;
queue<DataBuffer *> * q;
queue<int> * m_qFrameCounter;
MemoryPool<DataBuffer> * m_pool;
QThread * m_pushFlowThread;
PushFlow * m_pushFlow;
int m_iFlowSwitch;
QString m_baseFileName; QString m_baseFileName;
QString m_ximeaTemperatureCSVPath; QString m_ximeaTemperatureCSVPath;
Iris::IrisXimeaImager m_imager; Iris::IrisXimeaImager m_imager;
unsigned short * m_buffer; unsigned short * m_buffer;
// MemoryPool<unsigned short> m_pool;
bool m_bRecordControl; bool m_bRecordControl;
int m_iFrameCounter; int m_iFrameCounter;
int m_iFrameSizeInByte; int m_iFrameSizeInByte;
rgbImage * m_rgbImage;
void writeHdr(); void writeHdr();
void processXiApiErrorCodes(int xiApiErrorCodes); void processXiApiErrorCodes(int xiApiErrorCodes);
inline double getSbgTime(double TimeDifferenceBetweensOSAndSbg) inline double getSbgTime(XI_IMG * image, double timeDifferenceBetweenSbgAndXimea)
{ {
struct timespec systemTime; double ximeaTime = (double)image->tsSec + (double)image->tsUSec/1000000;
clock_gettime(CLOCK_REALTIME,&systemTime); return ximeaTime + timeDifferenceBetweenSbgAndXimea;
tm systemTime_rili;
localtime_r(&systemTime.tv_sec, &systemTime_rili);
double secondSystem=(systemTime_rili.tm_mday-1)*24*60*60+systemTime_rili.tm_hour*60*60+systemTime_rili.tm_min*60+systemTime_rili.tm_sec;
double nanosecondSystem=secondSystem+static_cast<double>(systemTime.tv_nsec)/1000000000;
// printf("\n");
// printf("XimeaImager::getSbgTime------系统时间纳秒%d\n", systemTime.tv_nsec);
// printf("XimeaImager::getSbgTime------系统时间(未偏移)%f\n", nanosecondSystem);
// printf("XimeaImager::getSbgTime------系统时间(偏移)%f\n", nanosecondSystem-TimeDifferenceBetweensOSAndSbg);
return nanosecondSystem-TimeDifferenceBetweensOSAndSbg;
} }
Configfile m_configfile; Configfile m_configfile;
ParameterConfigfile m_parameterConfigfile;
public slots: public slots:
void openImger(); void openImger();
void closeImger(); void closeImger();
double calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * m_image, double timeDifferenceBetweenSbgAndOS);
void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName); void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName);
signals: signals:
@ -142,5 +244,11 @@ signals:
void ximeaImageStatus(int); void ximeaImageStatus(int);
void recordXimeaTemperatureSignal(QString); void recordXimeaTemperatureSignal(QString);
void startWriteDiskSignal();
void startPushFlowSignal();
void autoExposeMaxValueOfOneFrame(int, double);
void frameRateSignal(double);
void binSignal(int, int);
}; };
#endif // XIMEAIMAGER_H #endif // XIMEAIMAGER_H

View File

@ -43,17 +43,32 @@ bool Configfile::parseConfigfile()
} }
} }
bool Configfile::getBin(int &bin) bool Configfile::getSpectralBin(int &spectralBin)
{ {
try try
{ {
bin = cfg.lookup("bin"); spectralBin = cfg.lookup("spectralBin");
return true; return true;
} }
catch(const SettingNotFoundException &nfex) catch(const SettingNotFoundException &nfex)
{ {
cerr << "No 'bin' setting in configuration file." << endl; cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
}
bool Configfile::getspatialBin(int &spatialBin)
{
try
{
spatialBin = cfg.lookup("spatialBin");
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spatialBin' setting in configuration file." << endl;
return false; return false;
} }
} }
@ -62,22 +77,41 @@ bool Configfile::getEffectiveWindow(int &width, int &offsetx, int &height, int &
{ {
const Setting& root = cfg.getRoot(); const Setting& root = cfg.getRoot();
// Output a list of all books in the inventory.
try try
{ {
const Setting &effective_window = root["effective_window"]; int spatialBin;
int count = effective_window.getLength(); int spectralBin;
getspatialBin(spatialBin);
getSpectralBin(spectralBin);
int bin; string spatialBinString;
getBin(bin); if(spatialBin == 1)
{
spatialBinString = "bin1";
}
else
{
spatialBinString = "bin2";
}
const Setting &spatialArgument = root["effective_window"][spatialBinString]["spatial"];
if(!(spatialArgument.lookupValue("width", width)
&& spatialArgument.lookupValue("offsetx", offsetx)))
{
return false;
}
const Setting &window = effective_window[bin-1]; string spectralBinString;
string name = window.getName(); if(spectralBin == 1)
{
if(!(window.lookupValue("width", width) spectralBinString = "bin1";
&& window.lookupValue("offsetx", offsetx) }
&& window.lookupValue("height", height) else
&& window.lookupValue("offsety", offsety))) {
spectralBinString = "bin2";
}
const Setting &spectralArgument = root["effective_window"][spectralBinString]["spectral"];
if(!(spectralArgument.lookupValue("height", height)
&& spectralArgument.lookupValue("offsety", offsety)))
{ {
return false; return false;
} }
@ -95,16 +129,25 @@ bool Configfile::getEffectiveWindowRoi(int &width, int &offsetx)
{ {
const Setting& root = cfg.getRoot(); const Setting& root = cfg.getRoot();
// Output a list of all books in the inventory.
try try
{ {
const Setting &effective_window = root["effective_window_roi"]; const Setting &effective_window = root["effective_window_roi"];
int count = effective_window.getLength(); int count = effective_window.getLength();
int bin; int spatialBin;
getBin(bin); getspatialBin(spatialBin);
const Setting &window = effective_window[bin-1]; string spatialBinString;
if(spatialBin == 1)
{
spatialBinString = "spatialBin1";
}
else
{
spatialBinString = "spatialBin2";
}
const Setting &window = effective_window[spatialBinString];
string name = window.getName(); string name = window.getName();
if(!(window.lookupValue("width", width) if(!(window.lookupValue("width", width)
@ -123,20 +166,109 @@ bool Configfile::getEffectiveWindowRoi(int &width, int &offsetx)
return true; return true;
} }
bool Configfile::getPushFlowParam(int &flowSwitch, int &rgbHeight, int &framerateVideo)
{
Setting& root = cfg.getRoot();
if (!root.exists("push_flow_param"))
{
// 配置项不存在,添加配置项
Setting & push_flow_param = root.add("push_flow_param", Setting::TypeGroup);
push_flow_param.add("flow_switch", Setting::TypeInt) = 0;
push_flow_param.add("rgb_height", Setting::TypeInt) = 720;
push_flow_param.add("framerate_video", Setting::TypeInt) = 5;
// 保存修改后的配置到文件
try
{
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
bool ret = createDir(fileInfo[0]);
cfg.writeFile(m_configfilePath.c_str());
std::cout << "Config item 'push_flow_param' added." << std::endl;
flowSwitch = 0;
rgbHeight = 720;
framerateVideo = 5;
return true;
}
catch (const libconfig::FileIOException &fioex)
{
std::cerr << "I/O error while writing file." << std::endl;
return false;
}
}
else
{
try
{
const Setting &push_flow_param = root["push_flow_param"];
if(!(push_flow_param.lookupValue("rgb_height", rgbHeight)
&& push_flow_param.lookupValue("framerate_video", framerateVideo)
&& push_flow_param.lookupValue("flow_switch", flowSwitch)
))
{
return false;
}
}
catch(const SettingNotFoundException &nfex)
{
// Ignore.
return false;
}
return true;
}
}
bool Configfile::getWindowOffsety_HeightOfSpectral(int &offsety, int &height, string spectralBinString)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &spectralArgument = root["effective_window"][spectralBinString]["spectral"];
if(!(spectralArgument.lookupValue("height", height)
&& spectralArgument.lookupValue("offsety", offsety)))
{
return false;
}
}
catch(const SettingNotFoundException &nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::getGainOffset(float &gain, float &offset) bool Configfile::getGainOffset(float &gain, float &offset)
{ {
const Setting& root = cfg.getRoot(); const Setting& root = cfg.getRoot();
// Output a list of all books in the inventory.
try try
{ {
const Setting &gainOffset = root["gainOffset"]; const Setting &gainOffset = root["gainOffset"];
int count = gainOffset.getLength(); int count = gainOffset.getLength();
int bin; int spectralBin;
getBin(bin); getSpectralBin(spectralBin);
const Setting &gainOffsetSetting = gainOffset[bin-1]; string spectralBinString;
if(spectralBin == 1)
{
spectralBinString = "spectralBin1";
}
else
{
spectralBinString = "spectralBin2";
}
const Setting &gainOffsetSetting = gainOffset[spectralBinString];
string name = gainOffsetSetting.getName(); string name = gainOffsetSetting.getName();
if(!(gainOffsetSetting.lookupValue("gain", gain) if(!(gainOffsetSetting.lookupValue("gain", gain)
@ -154,69 +286,175 @@ bool Configfile::getGainOffset(float &gain, float &offset)
return true; return true;
} }
bool Configfile::getGainOffsetOfSpectralBin1(float &gain, float &offset)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &gainOffset = root["gainOffset"];
int count = gainOffset.getLength();
string spectralBinString = "spectralBin1";
const Setting &gainOffsetSetting = gainOffset[spectralBinString];
string name = gainOffsetSetting.getName();
if(!(gainOffsetSetting.lookupValue("gain", gain)
&& gainOffsetSetting.lookupValue("offset", offset)))
{
return false;
}
}
catch(const SettingNotFoundException &nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::getSN(QString &SN)
{
try
{
std::string SN_tem = cfg.lookup("SN");
SN = QString::fromStdString(SN_tem);
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
}
bool Configfile::getBufferPolicy(int &bufferPolicy)
{
const Setting& root = cfg.getRoot();
const Setting &ximeadll = root["ximeadll"];
try
{
if(!(ximeadll.lookupValue("buffer_policy", bufferPolicy)
))
{
return false;
}
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
return true;
}
bool Configfile::getAcqBufferSize(int &acqBufferSize)
{
const Setting& root = cfg.getRoot();
const Setting &ximeadll = root["ximeadll"];
try
{
if(!(ximeadll.lookupValue("acq_buffer_size", acqBufferSize)
))
{
return false;
}
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
return true;
}
bool Configfile::createConfigFile() bool Configfile::createConfigFile()
{ {
using namespace std; using namespace std;
using namespace libconfig; using namespace libconfig;
static const char *output_file = "ximea.cfg";
Config cfg; Config cfg;
Setting &root = cfg.getRoot(); Setting &root = cfg.getRoot();
// Add some settings to the configuration. // Add some settings to the configuration.
Setting &bin = root.add("bin", Setting::TypeInt) = 1;
Setting &SN = root.add("SN", Setting::TypeString) = "0098"; Setting &SN = root.add("SN", Setting::TypeString) = "0098";
Setting &spatialBin = root.add("spatialBin", Setting::TypeInt) = 2;
Setting &SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
Setting &effective_window = root.add("effective_window", Setting::TypeGroup); Setting &effective_window = root.add("effective_window", Setting::TypeGroup);
Setting &effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup); Setting &effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup);
Setting &effective_window_Bin1_spatial = effective_window_Bin1.add("spatial", Setting::TypeGroup);
Setting &effective_window_Bin1_Spectral = effective_window_Bin1.add("spectral", Setting::TypeGroup);
Setting &effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup); Setting &effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup);
Setting &effective_window_Bin2_spatial = effective_window_Bin2.add("spatial", Setting::TypeGroup);
Setting &effective_window_Bin2_Spectral = effective_window_Bin2.add("spectral", Setting::TypeGroup);
effective_window_Bin1.add("width", Setting::TypeInt) = 1392; effective_window_Bin1_spatial.add("width", Setting::TypeInt) = 1368;
effective_window_Bin1.add("offsetx", Setting::TypeInt) = 272; effective_window_Bin1_spatial.add("offsetx", Setting::TypeInt) = 288;
effective_window_Bin1.add("height", Setting::TypeInt) = 300; effective_window_Bin1_Spectral.add("height", Setting::TypeInt) = 300;
effective_window_Bin1.add("offsety", Setting::TypeInt) = 348; effective_window_Bin1_Spectral.add("offsety", Setting::TypeInt) = 348;
effective_window_Bin2.add("width", Setting::TypeInt) = 712; effective_window_Bin2_spatial.add("width", Setting::TypeInt) = 688;
effective_window_Bin2.add("offsetx", Setting::TypeInt) = 128; effective_window_Bin2_spatial.add("offsetx", Setting::TypeInt) = 144;
effective_window_Bin2.add("height", Setting::TypeInt) = 151; effective_window_Bin2_Spectral.add("height", Setting::TypeInt) = 150;
effective_window_Bin2.add("offsety", Setting::TypeInt) = 174; effective_window_Bin2_Spectral.add("offsety", Setting::TypeInt) = 174;
Setting &effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup); Setting &effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup);
Setting &effective_window_roi_Bin1 = effective_window_roi.add("bin1", Setting::TypeGroup); Setting &effective_window_roi_spatialBin1 = effective_window_roi.add("spatialBin1", Setting::TypeGroup);
Setting &effective_window_roi_Bin2 = effective_window_roi.add("bin2", Setting::TypeGroup); Setting &effective_window_roi_spatialBin2 = effective_window_roi.add("spatialBin2", Setting::TypeGroup);
effective_window_roi_Bin1.add("width", Setting::TypeInt) = 1364; effective_window_roi_spatialBin1.add("width", Setting::TypeInt) = 1364;
effective_window_roi_Bin1.add("offsetx", Setting::TypeInt) = 14; effective_window_roi_spatialBin1.add("offsetx", Setting::TypeInt) = 14;
// effective_window_roi_Bin1.add("height", Setting::TypeInt) = 300; // effective_window_roi_Bin1.add("height", Setting::TypeInt) = 300;
// effective_window_roi_Bin1.add("offsety", Setting::TypeInt) = 348; // effective_window_roi_Bin1.add("offsety", Setting::TypeInt) = 348;
effective_window_roi_Bin2.add("width", Setting::TypeInt) = 682; effective_window_roi_spatialBin2.add("width", Setting::TypeInt) = 682;
effective_window_roi_Bin2.add("offsetx", Setting::TypeInt) = 15; effective_window_roi_spatialBin2.add("offsetx", Setting::TypeInt) = 15;
// effective_window_roi_Bin2.add("height", Setting::TypeInt) = 151; // effective_window_roi_Bin2.add("height", Setting::TypeInt) = 151;
// effective_window_roi_Bin2.add("offsety", Setting::TypeInt) = 174; // effective_window_roi_Bin2.add("offsety", Setting::TypeInt) = 174;
Setting &gainOffset = root.add("gainOffset", Setting::TypeGroup); Setting &gainOffset = root.add("gainOffset", Setting::TypeGroup);
Setting &gainOffsetBin1 = gainOffset.add("bin1", Setting::TypeGroup); Setting &gainOffsetSpectralBin1 = gainOffset.add("spectralBin1", Setting::TypeGroup);
Setting &gainOffsetBin2 = gainOffset.add("bin2", Setting::TypeGroup); Setting &gainOffsetSpectralBin2 = gainOffset.add("spectralBin2", Setting::TypeGroup);
gainOffsetBin1.add("gain", Setting::TypeFloat) = 2.00313433; gainOffsetSpectralBin1.add("gain", Setting::TypeFloat) = 2.00313433;
gainOffsetBin1.add("offset", Setting::TypeFloat) = -300.46283157590585; gainOffsetSpectralBin1.add("offset", Setting::TypeFloat) = -300.46283157590585;
gainOffsetBin2.add("gain", Setting::TypeFloat) = 4.00626868; gainOffsetSpectralBin2.add("gain", Setting::TypeFloat) = 4.00626868;
gainOffsetBin2.add("offset", Setting::TypeFloat) = -299.46126663407176; gainOffsetSpectralBin2.add("offset", Setting::TypeFloat) = -299.46126663407176;
Setting &ximeadll = root.add("ximeadll", Setting::TypeGroup);
ximeadll.add("buffer_policy", Setting::TypeInt) = 0;
ximeadll.add("acq_buffer_size", Setting::TypeInt) = 400;
Setting &push_flow_param = root.add("push_flow_param", Setting::TypeGroup);
push_flow_param.add("flow_switch", Setting::TypeInt) = 1;
push_flow_param.add("rgb_height", Setting::TypeInt) = 720;
push_flow_param.add("framerate_video", Setting::TypeInt) = 5;
// Write out the new configuration. // Write out the new configuration.
QString output_file = "/media/nvme/300TC/config/ximea.cfg";
try try
{ {
cfg.writeFile(output_file); QList<QString> fileInfo = getFileInfo(output_file);
cerr << "New configuration successfully written to: " << output_file << endl; bool ret = createDir(fileInfo[0]);
cfg.writeFile(output_file.toStdString().c_str());
cerr << "New configuration successfully written to: " << output_file.toStdString().c_str() << endl;
} }
catch(const FileIOException &fioex) catch(const FileIOException &fioex)
{ {
cerr << "I/O error while writing configuration file: " << output_file << endl; cerr << "I/O error while writing configuration file: " << output_file.toStdString().c_str() << endl;
return true; return true;
} }
@ -292,3 +530,295 @@ bool Configfile::updateConfigFile()
return true; return true;
} }
ParameterConfigfile::ParameterConfigfile()
{
}
void ParameterConfigfile::setConfigfilePath(string configfilePath)
{
m_configfilePath = configfilePath;
}
bool ParameterConfigfile::isConfigfileExist()
{
QFileInfo info(QString::fromStdString(m_configfilePath));
return info.exists();
}
bool ParameterConfigfile::parseConfigfile()
{
// Read the file. If there is an error, report it and exit.
try
{
cfg.readFile(m_configfilePath);
return true;
}
catch(const FileIOException &fioex)
{
std::cerr << "I/O error while reading file." << std::endl;
return false;
}
catch(const ParseException &pex)
{
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
return false;
}
}
bool ParameterConfigfile::createConfigFile()
{
using namespace std;
using namespace libconfig;
Config cfg;
Setting &root = cfg.getRoot();
// Add some settings to the configuration.
// Setting &SN = root.add("SN", Setting::TypeString) = "0098";
// Setting &spatialBin = root.add("spatialBin", Setting::TypeInt) = 2;
// Setting &SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
Setting &ximeaParam = root.add("ximeaParam", Setting::TypeGroup);
ximeaParam.add("frameRate", Setting::TypeInt) = 100;
ximeaParam.add("exposeTime", Setting::TypeFloat) = 10.0;
// Write out the new configuration.
try
{
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
bool ret = createDir(fileInfo[0]);
cfg.writeFile(m_configfilePath.c_str());
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
}
catch(const FileIOException &fioex)
{
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
return true;
}
return true;
}
bool ParameterConfigfile::getFrameRate(int &frameRate)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &ximeaParam = root["ximeaParam"];
frameRate = ximeaParam.lookup("frameRate");
// std::cout << "ParameterConfigfile::getFrameRate"<< frameRate<<std::endl;
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'frameRate' setting in configuration file." << endl;
return false;
}
}
bool ParameterConfigfile::setFrameRate(int frameRate)
{
const Setting& root = cfg.getRoot();
try
{
Setting &frameRate2 = root["ximeaParam"]["frameRate"];
frameRate2 = frameRate;
writeConfig2File();
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'frameRate' setting in configuration file." << endl;
return false;
}
}
bool ParameterConfigfile::getExposeTime(float &exposeTime)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &ximeaParam = root["ximeaParam"];
exposeTime = ximeaParam.lookup("exposeTime");
// std::cout << "ParameterConfigfile::getExposeTime"<< exposeTime<<std::endl;
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'exposeTime' setting in configuration file." << endl;
return false;
}
}
bool ParameterConfigfile::setExposeTime(float exposeTime)
{
const Setting& root = cfg.getRoot();
try
{
Setting &frameRate2 = root["ximeaParam"]["exposeTime"];
frameRate2 = exposeTime;
writeConfig2File();
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'exposeTime' setting in configuration file." << endl;
return false;
}
}
bool ParameterConfigfile::writeConfig2File()
{
try
{
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
bool ret = createDir(fileInfo[0]);
cfg.writeFile(m_configfilePath.c_str());
// cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
}
catch(const FileIOException &fioex)
{
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
return false;
}
return true;
}
StateOf300tcConfigfile::StateOf300tcConfigfile()
{
}
bool StateOf300tcConfigfile::getIntValue(int &value, string field)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &ximeaParam = root["ximeaParam"];
value = ximeaParam.lookup(field);
// std::cout << "StateOf300tcConfigfile::getIntValue"<< value<<std::endl;
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No setting in configuration file." << endl;
return false;
}
}
bool StateOf300tcConfigfile::setIntValue(int value, string field)
{
const Setting& root = cfg.getRoot();
try
{
Setting &frameRate2 = root["ximeaParam"][field];
frameRate2 = value;
writeConfig2File();
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No setting in configuration file." << endl;
return false;
}
}
bool StateOf300tcConfigfile::createConfigFile()
{
using namespace std;
using namespace libconfig;
Config cfg;
Setting &root = cfg.getRoot();
// Add some settings to the configuration.
// Setting &SN = root.add("SN", Setting::TypeString) = "0098";
// Setting &spatialBin = root.add("spatialBin", Setting::TypeInt) = 2;
// Setting &SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
Setting &ximeaParam = root.add("ximeaParam", Setting::TypeGroup);
ximeaParam.add("sbgState", Setting::TypeInt) = 0;
ximeaParam.add("sbgSolutionMode", Setting::TypeInt) = 0;
ximeaParam.add("ximeaState", Setting::TypeInt) = 100;
ximeaParam.add("frameRate", Setting::TypeInt) = 0;
ximeaParam.add("exposeTime", Setting::TypeFloat) = 0.0;
ximeaParam.add("exposeMaxValueOfOneFrame", Setting::TypeInt) = 0;
// Write out the new configuration.
try
{
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
bool ret = createDir(fileInfo[0]);
cfg.writeFile(m_configfilePath.c_str());
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
}
catch(const FileIOException &fioex)
{
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
return true;
}
return true;
}
bool StateOf300tcConfigfile::getSbgState(int &sbgState)
{
return getIntValue(sbgState,"sbgState");
}
bool StateOf300tcConfigfile::setSbgState(int sbgState)
{
return setIntValue(sbgState,"sbgState");
}
bool StateOf300tcConfigfile::getSbgSolutionMode(int &sbgSolutionMode)
{
return getIntValue(sbgSolutionMode,"sbgSolutionMode");
}
bool StateOf300tcConfigfile::setSbgSolutionMode(int sbgSolutionMode)
{
return setIntValue(sbgSolutionMode,"sbgSolutionMode");
}
bool StateOf300tcConfigfile::getXimeaState(int &ximeaState)
{
return getIntValue(ximeaState,"ximeaState");
}
bool StateOf300tcConfigfile::setXimeaState(int ximeaState)
{
return setIntValue(ximeaState,"ximeaState");
}
bool StateOf300tcConfigfile::getExposeMaxValueOfOneFrame(int &exposeMaxValueOfOneFrame)
{
return getIntValue(exposeMaxValueOfOneFrame,"exposeMaxValueOfOneFrame");
}
bool StateOf300tcConfigfile::setExposeMaxValueOfOneFrame(int exposeMaxValueOfOneFrame)
{
return setIntValue(exposeMaxValueOfOneFrame,"exposeMaxValueOfOneFrame");
}

View File

@ -3,6 +3,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
std::cout<<"ximeaAirborneSystem 版本:"<< "44." <<std::endl;
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
//UdpServer* x=new UdpServer(); //UdpServer* x=new UdpServer();

307
Source_Files/rgbImage.cpp Normal file
View File

@ -0,0 +1,307 @@
//
// Created by tangchao on 2022/12/24.
//
#include "../Header_Files/rgbImage.h"
rgbImage::rgbImage(QWidget* pParent)
{
m_QRgbImage = nullptr;
m_matRgbImage = nullptr;
m_matFocusGrayImage = nullptr;
m_qimageFocusGrayImage = nullptr;
m_iRedBandNumber = 0;
m_iGreenBandNumber = 0;
m_iBlueBandNumber = 0;
}
rgbImage::~rgbImage()
{
}
void rgbImage::SetRgbBandNumber(int redBandNumber, int greenBandNumber, int blueBandNumber)
{
m_iRedBandNumber = redBandNumber;
m_iGreenBandNumber = greenBandNumber;
m_iBlueBandNumber = blueBandNumber;
// std::cout<<"rgbImage::SetRgbBandNumber红波段的波段号"<< redBandNumber <<std::endl;
// std::cout<<"rgbImage::SetRgbBandNumber绿波段的波段号"<< greenBandNumber <<std::endl;
// std::cout<<"rgbImage::SetRgbBandNumber蓝波段的波段号"<< blueBandNumber <<std::endl;
}
void rgbImage::SetRgbImageWidthAndHeight(int BandCount, int Width, int height)
{
using namespace cv;
if (m_QRgbImage != nullptr)
{
delete m_QRgbImage;//有问题????????????????????????????????????????????????
}
//m_QRgbImage = new QImage(Width, height, QImage::Format_RGB888);
if (m_matRgbImage != nullptr)
{
delete m_matRgbImage;
}
m_matRgbImage = new Mat(height, Width, CV_8UC3, Scalar(0, 0, 0));
// int codec = VideoWriter::fourcc('H', '2', '6', '4'); // select desired codec (must be available at runtime)
// double fps = 20.0;// framerate of the created video stream
// std::string filename = "appsrc ! autovideoconvert ! filesink location=/media/nvme/live.mp4";//https://blog.csdn.net/ancientapesman/article/details/117324638
//// std::string filename = "/media/nvme/live.mp4";
// auto ddddd=m_matRgbImage->size();
// m_VideoWriter.open(filename, codec, fps, Size(20, 1368), true);
// VideoWriter video("test.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(640, 480));
// m_frame_writer = cvCreateVideoWriter("/media/nvme/delete/live.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 20.0, Size(688, 688), false);
if (m_qimageFocusGrayImage == nullptr)
{
m_qimageFocusGrayImage = new QImage(Width, BandCount, QImage::Format_RGB32);
}
if (m_matFocusGrayImage == nullptr)
{
m_matFocusGrayImage = new Mat(BandCount, Width, CV_16U, Scalar(0));
//cv::Mat matAdjustPreview = Mat::zeros(BandCount, Width, CV_16U);
}
//cv::Mat matAdjustPreview = Mat::zeros(BandCount, Width, CV_16U);
//m_matFocusGrayImage = matAdjustPreview;
std::cout << "高光谱rgb图像设置高度" << height << std::endl;
m_iFrameCounter = 0;//每次都重置为0
m_iSampleNumber = Width;
m_iBandNumber = BandCount;
m_iFrameNumber = height;
//std::cout << "rgb影像内存地址为" << m_QRgbImage << std::endl;
}
void rgbImage::FillOnerowofRgbImage(cv::Mat * matRgbImage, int rowNumber, unsigned short *datacube)
{
//方式1逐像素修改
// unsigned short r, g, b;
// for (int j = 0; j < m_iSampleNumber; j++)
// {
// //取值一帧影像中从左到右的rgb像元值
// r = *(datacube + m_iRedBandNumber * m_iSampleNumber + j)*255/4096;
// g = *(datacube + m_iGreenBandNumber * m_iSampleNumber + j)*255/4096;
// b = *(datacube + m_iBlueBandNumber * m_iSampleNumber + j)*255/4096;
//
//// r = *(datacube + m_iRedBandNumber * m_iSampleNumber + j);
//// g = *(datacube + m_iGreenBandNumber * m_iSampleNumber + j);
//// b = *(datacube + m_iBlueBandNumber * m_iSampleNumber + j);
//
// //将像元值赋值到cv::Mat中操作像元值https://zhuanlan.zhihu.com/p/51842288
// //int dataType = m_matRgbImage->type();//当数据类型为CV_16UC3时返回18
// //std::cout << "m_matRgbImage数据类型为" << dataType << std::endl;
// if (matRgbImage->type() == CV_8UC3)
// {
//// std::cout << "操作像素值!" << std::endl;
// matRgbImage->at<cv::Vec3b>(rowNumber, j)[2] = r;
// matRgbImage->at<cv::Vec3b>(rowNumber, j)[1] = g;
// matRgbImage->at<cv::Vec3b>(rowNumber, j)[0] = b;
//
//// QString savePath_cv = "/media/nvme/delete/" + QString::number(m_iFrameCounter) + "_cv.png";
//// cv::imwrite(savePath_cv.toStdString(), *matRgbImage);
// }
//
// int column = 800;
// if(j == column)
// {
// std::cout << "行:" << rowNumber << "提取:第 " << column << " 列的 r g b 分别为 " << r << " " << g << " " << b << std::endl;
// std::cout << "mat第 " << column << " 列的 r g b 分别为 " << (unsigned short)matRgbImage->at<cv::Vec3b>(rowNumber, j)[2] << " " << (unsigned short)matRgbImage->at<cv::Vec3b>(rowNumber, j)[1] << " " << (unsigned short)matRgbImage->at<cv::Vec3b>(rowNumber, j)[0] << std::endl;
// }
// }
//方式2通过指针操作更快
unsigned short r, g, b;
const int cols = matRgbImage->cols;
const int step = matRgbImage->channels();
unsigned char *p_row0_b = matRgbImage->ptr(rowNumber);
unsigned char *p_row0_g = matRgbImage->ptr(rowNumber) + 1;
unsigned char *p_row0_r = matRgbImage->ptr(rowNumber) + 2;
for (int j = 0; j < m_iSampleNumber; j++)
{
//取值一帧影像中从左到右的rgb像元值线性拉伸
r = *(datacube + m_iRedBandNumber * m_iSampleNumber + j)*255/4096;
g = *(datacube + m_iGreenBandNumber * m_iSampleNumber + j)*255/4096;
b = *(datacube + m_iBlueBandNumber * m_iSampleNumber + j)*255/4096;
*p_row0_b = b;
*p_row0_g = g;
*p_row0_r = r;
// int column = 800;
// if(j == column)
// {
// std::cout << "行:" << rowNumber << "提取:第 " << column << " 列的 r g b 分别为 " << r << " " << g << " " << b << std::endl;
//// std::cout << "修改后" << rowNumber << "提取:第 " << column << " 列的 r g b 分别为 " << (unsigned short)*p_row0_r << " " << (unsigned short)*p_row0_g << " " << (unsigned short)*p_row0_b << std::endl;
//// std::cout << "mat第 " << column << " 列的 r g b 分别为 " << (unsigned short)matRgbImage->at<cv::Vec3b>(rowNumber, j)[2] << " " << (unsigned short)matRgbImage->at<cv::Vec3b>(rowNumber, j)[1] << " " << (unsigned short)matRgbImage->at<cv::Vec3b>(rowNumber, j)[0] << std::endl;
// }
p_row0_b += step;
p_row0_g += step;
p_row0_r += step;
}
//方式3通过内存拷贝快速提取rgb
// if (matRgbImage->isContinuous())// check mat is continuous or not
// matRgbImage->reshape(1, matRgbImage->rows * matRgbImage->cols).col(0).setTo(Scalar(value));
// else
// {
// for (int i = 0; i < matRgbImage->rows; i++)
// matRgbImage->row(i).reshape(1, matRgbImage->cols).col(0).setTo(Scalar(value));
// }
}
QImage rgbImage::Mat2QImage(cv::Mat cvImg)//https://www.cnblogs.com/annt/p/ant003.html
{
QImage qImg;
if (cvImg.channels() == 3)//3 channels color image
{
cv::cvtColor(cvImg, cvImg, CV_BGR2RGB);
qImg = QImage((const unsigned char*)(cvImg.data),
cvImg.cols, cvImg.rows,
cvImg.cols*cvImg.channels(),
QImage::Format_RGB888);
}
else if (cvImg.channels() == 1)//grayscale image
{
qImg = QImage((const unsigned char*)(cvImg.data),
cvImg.cols, cvImg.rows,
cvImg.cols*cvImg.channels(),
QImage::Format_Indexed8);
}
else
{
qImg = QImage((const unsigned char*)(cvImg.data),
cvImg.cols, cvImg.rows,
cvImg.cols*cvImg.channels(),
QImage::Format_RGB888);
}
return qImg;
}
void rgbImage::FillRgbImage(unsigned short *datacube)
{
//从第二行开始向下移动一行https://blog.csdn.net/u014686356/article/details/65937750
// m_matRgbImage->rowRange(0, m_matRgbImage->rows - 1).copyTo(m_matRgbImage->rowRange(1, m_matRgbImage->rows));//经tc验证此行代码工作异常为啥不加.clone()就异常??????
// m_matRgbImage->rowRange(0, m_matRgbImage->rows - 1).clone().copyTo(m_matRgbImage->rowRange(1, m_matRgbImage->rows));//此方式ximea帧率130hz1min左右就出现漏帧
// cv::Mat upperPart = m_matRgbImage->rowRange(0, m_matRgbImage->rows - 1).clone();//此方式ximea帧率130hz1min左右就出现漏帧
// upperPart.copyTo(m_matRgbImage->rowRange(1, m_matRgbImage->rows));
for (int i = m_matRgbImage->rows - 2; i >= 0; --i)//此方式ximea帧率130hz4.5min左右出现漏帧 → 此方式效率最高
{
m_matRgbImage->row(i).copyTo(m_matRgbImage->row(i+1));
}
FillOnerowofRgbImage(m_matRgbImage, 0, datacube);
// m_Qphoto = Mat2QImage(*m_matRgbImage);
//保存rgb图片
// if (m_iFrameCounter % m_iFramerate == 0 || m_iFrameCounter == m_iFrameNumber - 1)
// {
//// QString savePath = "/media/nvme/delete/" + QString::number(m_iFrameCounter) + "_qt.jpg";
//// m_Qphoto.save(savePath);
//
// QString savePath_cv = "/media/nvme/delete/" + QString::number(m_iFrameCounter) + "_cv.jpg";
// cv::imwrite(savePath_cv.toStdString(), *m_matRgbImage);
// }
// m_VideoWriter.write(*m_matRgbImage);
// std::string rgbFilePathNoStrech = "/media/nvme/delete/" + std::to_string(m_iFrameCounter) + "ctmp_image_no_strech.png";
// cv::imwrite(rgbFilePathNoStrech, *m_matRgbImage);
m_iFrameCounter++;
}
void rgbImage::FillFocusGrayImage(unsigned short * datacube)
{
int rowCount = m_matFocusGrayImage->rows;
int colCount = m_matFocusGrayImage->cols;
for (unsigned short i = 0; i < m_matFocusGrayImage->rows; i++)
{
for (unsigned short j = 0; j < m_matFocusGrayImage->cols; j++)
{
//m_matFocusGrayImage->at<ushort>(i, j) = *(datacube + m_matFocusGrayImage->cols*i + j);
m_matFocusGrayImage->at<ushort>(i, j) = datacube[m_matFocusGrayImage->cols*i + j];
}
}
//int rowCount = m_matFocusGrayImage.rows;
//int colCount = m_matFocusGrayImage.cols;
////memcpy(m_matFocusGrayImage.data, datacube, rowCount*colCount);
//for (unsigned short i = 0; i < m_matFocusGrayImage.rows; i++)
//{
// for (unsigned short j = 0; j < m_matFocusGrayImage.cols; j++)
// {
// m_matFocusGrayImage.at<ushort>(i, j) = *(datacube + m_matFocusGrayImage.cols*i + j);
// //m_matFocusGrayImage.at<ushort>(i, j) = datacube[colCount*i + j];
// }
//}
//将mat保存成文件
//cv::imwrite("D:/delete/2222222222/test.bmp", m_matFocusGrayImage);
}
void rgbImage::FillFocusGrayQImage(unsigned short * datacube)
{
float two_eight = pow(2.0, 8);
float two_sixteen = pow(2.0, 12);
int width = m_qimageFocusGrayImage->width();
int height = m_qimageFocusGrayImage->height();
for (unsigned short i = 0; i < height; i++)
{
for (unsigned short j = 0; j < width; j++)
{
//uint tmp = (two_eight* *(datacube + width * i + j)) / two_sixteen;
uint tmp = (two_eight* datacube[width*i + j]) / two_sixteen;
//uint tmp = datacube[width*i + j];
//m_qimageFocusGrayImage->setPixel(j, i, tmp);
m_qimageFocusGrayImage->setPixel(j, i, qRgb((unsigned char)tmp, (unsigned char)tmp, (unsigned char)tmp));
}
}
m_qimageFocusGrayImage->save("D:/delete/2222222222/test.bmp");
/*float two_eight = pow(2.0, 8);
float two_sixteen = pow(2.0, 16);
QImage *qi = new QImage(imwidth, imheight, QImage::Format_RGB32);
for (int i = 0; i < imheight; i++)
{
for (int j = 0; j < imwidth; j++)
{
floatData[i*imwidth + j] = (two_eight* floatData[i*imwidth + j]) / two_sixteen;
qi->setPixel(j, i, qRgb((unsigned char)floatData[i*imwidth + j], (unsigned char)floatData[i*imwidth + j], (unsigned char)floatData[i*imwidth + j]));
}
}*/
}

View File

@ -53,7 +53,7 @@ void sbgtc::SbgRecorder::openSerialPort()
} }
// QString portname = "sbg_serial_port"; // QString portname = "sbg_serial_port";
QString portname = "ttyS4"; QString portname = "ttyUSB0";
m_serial->setPortName(portname); m_serial->setPortName(portname);
m_serial->open(QIODevice::ReadWrite); m_serial->open(QIODevice::ReadWrite);
@ -608,76 +608,51 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
//判断模式是否为: NAV_POSITION //判断模式是否为: NAV_POSITION
if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_EKF_EULER) if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_EKF_EULER)
{ {
m_iSolutionModeCounter++;// m_iSolutionModeCounter++;
uint32_t status=logData.ekfEulerData.status; uint32_t status=logData.ekfEulerData.status;
uint32_t mode=status>>24;//????????????????????????????????????? uint32_t mode=status & 0xf;
// uint32_t mode=status;//这是错的
//一秒钟发射一次mode //一秒钟发射一次mode
if(m_iSolutionModeCounter%200 == 0) if(m_iSolutionModeCounter%200 == 0)
{ {
emit sbgSolutionModeSignal(mode); emit sbgSolutionModeSignal(mode);
// std::cout << "logData.ekfEulerData.status: " << status << std::endl;
switch (mode) switch (mode) {
{ case SBG_ECOM_SOL_MODE_UNINITIALIZED:
case SBG_ECOM_SOL_MODE_UNINITIALIZED: // std::cout << "此刻模式为: " << "UNINITIALIZED" << std::endl;
std::cout<<"此刻模式为: "<<"UNINITIALIZED"<<std::endl; m_bIsNAV_POSITION_MODE = false;
break; break;
case SBG_ECOM_SOL_MODE_VERTICAL_GYRO: case SBG_ECOM_SOL_MODE_VERTICAL_GYRO:
std::cout<<"此刻模式为: "<<"VERTICAL_GYRO"<<std::endl; // std::cout << "此刻模式为: " << "VERTICAL_GYRO" << std::endl;
break; m_bIsNAV_POSITION_MODE = false;
case SBG_ECOM_SOL_MODE_AHRS: break;
std::cout<<"此刻模式为: "<<"AHRS"<<std::endl; case SBG_ECOM_SOL_MODE_AHRS:
break; // std::cout << "此刻模式为: " << "AHRS" << std::endl;
case SBG_ECOM_SOL_MODE_NAV_VELOCITY: m_bIsNAV_POSITION_MODE = false;
std::cout<<"此刻模式为: "<<"NAV_VELOCITY"<<std::endl; break;
break; case SBG_ECOM_SOL_MODE_NAV_VELOCITY:
case SBG_ECOM_SOL_MODE_NAV_POSITION: // std::cout << "此刻模式为: " << "NAV_VELOCITY" << std::endl;
std::cout<<"此刻模式为: "<<"NAV_POSITION"<<std::endl; m_bIsNAV_POSITION_MODE = false;
break;
case SBG_ECOM_SOL_MODE_NAV_POSITION:
// std::cout << "此刻模式为: " << "NAV_POSITION" << std::endl;
m_bIsNAV_POSITION_MODE = true;
break; break;
default: default:
break; break;
} }
} }
switch (mode)
{
case SBG_ECOM_SOL_MODE_UNINITIALIZED:
// std::cout<<"此刻模式为: "<<"UNINITIALIZED"<<std::endl;
m_bIsNAV_POSITION_MODE=false;
break;
case SBG_ECOM_SOL_MODE_VERTICAL_GYRO:
// std::cout<<"此刻模式为: "<<"VERTICAL_GYRO"<<std::endl;
m_bIsNAV_POSITION_MODE=false;
break;
case SBG_ECOM_SOL_MODE_AHRS:
// std::cout<<"此刻模式为: "<<"AHRS"<<std::endl;
m_bIsNAV_POSITION_MODE=false;
break;
case SBG_ECOM_SOL_MODE_NAV_VELOCITY:
// std::cout<<"此刻模式为: "<<"NAV_VELOCITY"<<std::endl;
m_bIsNAV_POSITION_MODE=false;
break;
case SBG_ECOM_SOL_MODE_NAV_POSITION:
// std::cout<<"此刻模式为: "<<"NAV_POSITION"<<std::endl;
m_bIsNAV_POSITION_MODE=true;
break;
default:
break;
}
} }
else if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_GPS1_POS) else if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_GPS1_POS)
{ {
// std::cout<<"纬度精度为:"<<logData.gpsPosData.latitudeAccuracy<<std::endl;
float maximal=0; float maximal=0;
float latitudeAccuracy=logData.gpsPosData.latitudeAccuracy; float latitudeAccuracy=logData.gpsPosData.latitudeAccuracy;
float longitudeAccuracy=logData.gpsPosData.longitudeAccuracy; float longitudeAccuracy=logData.gpsPosData.longitudeAccuracy;
float altitudeAccuracy=logData.gpsPosData.altitudeAccuracy; float altitudeAccuracy=logData.gpsPosData.altitudeAccuracy;
int satelliteCounter=(int)logData.gpsPosData.numSvUsed;
if(latitudeAccuracy<longitudeAccuracy) if(latitudeAccuracy<longitudeAccuracy)
maximal = longitudeAccuracy; maximal = longitudeAccuracy;
@ -687,7 +662,14 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
if(maximal<altitudeAccuracy) if(maximal<altitudeAccuracy)
maximal = altitudeAccuracy; maximal = altitudeAccuracy;
emit sbgAccuracySignal(static_cast<int>(maximal)); // std::cout<<"纬度精度为:"<<maximal<<std::endl;
// std::cout<<"numSvUsed"<<satelliteCounter<<std::endl;
//
// std::cout<<"latitude"<<logData.gpsPosData.latitude<<std::endl;
// std::cout<<"longitude"<<logData.gpsPosData.longitude<<std::endl;
// std::cout<<"altitude"<<logData.gpsPosData.altitude<<std::endl;
emit sbgAccuracySignal(static_cast<int>(maximal), satelliteCounter);
if(maximal<7) if(maximal<7)
{ {
@ -710,15 +692,10 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
char setGpsTimeCommand[256]; char setGpsTimeCommand[256];
sprintf(setGpsTimeCommand,"date --set=\"%d%02d%02d %02d:%02d:%02d\"",year,month,day,hour,minute,second);//02中的2代表2位数字0代表以0补全 sprintf(setGpsTimeCommand,"date --set=\"%d%02d%02d %02d:%02d:%02d\"",year,month,day,hour,minute,second);//02中的2代表2位数字0代表以0补全
system(setGpsTimeCommand);// // system(setGpsTimeCommand);
m_bIsSyncSystemTimeBaseGpstime=true; m_bIsSyncSystemTimeBaseGpstime=true;
} }
else if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_EKF_EULER)
{
// std::cout<<"1111111111111"<<"UTC time:"<<(int)logData.utcData.year<<","<<(int)logData.utcData.month<<","<<(int)logData.utcData.day<<","<<(int)logData.utcData.hour<<","<<(int)logData.utcData.minute<<","<<(int)(int)logData.utcData.second<<std::endl;
// std::cout<<"receivedMsg:"<<(int)receivedMsg<<std::endl;
}
else if(receivedMsgClass!=SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_EKF_QUAT) else if(receivedMsgClass!=SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_EKF_QUAT)
{ {
//std::cout<<"1111111111111------"<<"UTC time:"<<(int)logData.utcData.year<<","<<(int)logData.utcData.month<<","<<(int)logData.utcData.day<<","<<(int)logData.utcData.hour<<","<<(int)logData.utcData.minute<<","<<(int)(int)logData.utcData.second<<std::endl; //std::cout<<"1111111111111------"<<"UTC time:"<<(int)logData.utcData.year<<","<<(int)logData.utcData.month<<","<<(int)logData.utcData.day<<","<<(int)logData.utcData.hour<<","<<(int)logData.utcData.minute<<","<<(int)(int)logData.utcData.second<<std::endl;
@ -731,7 +708,7 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
//控制开始采集高光谱影像,m_bIsNAV_POSITION_MODE && //控制开始采集高光谱影像,m_bIsNAV_POSITION_MODE &&
if(m_bIsRecordHyperspecatralImage && m_bIsSyncSystemTimeBaseGpstime && receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_UTC_TIME) if(m_bIsRecordHyperspecatralImage && m_bIsSyncSystemTimeBaseGpstime && m_bIsNAV_POSITION_MODE && receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_UTC_TIME)
{ {
m_baseFileName=getFileNameBaseOnTime(); m_baseFileName=getFileNameBaseOnTime();
emit sbgReady(calculateTimeDifferenceBetweenSystemAndSbg(logData),m_baseFileName); emit sbgReady(calculateTimeDifferenceBetweenSystemAndSbg(logData),m_baseFileName);
@ -793,7 +770,7 @@ void sbgtc::SbgRecorder::startRecordSbg()
m_baseFileName=getFileNameBaseOnTime(); m_baseFileName=getFileNameBaseOnTime();
QString sbgFileName=m_baseFileName+".sbg"; QString sbgFileName=m_baseFileName+".bin";
FILE * fileHandle=fopen(sbgFileName.toStdString().c_str(),"w+b"); FILE * fileHandle=fopen(sbgFileName.toStdString().c_str(),"w+b");
@ -802,7 +779,7 @@ void sbgtc::SbgRecorder::startRecordSbg()
while (m_bRecordControl) while (m_bRecordControl)
{ {
//std::cout<<"SbgRecorder::startRecordSbg--------------:"<<std::endl; //std::cout<<"SbgRecorder::startRecordSbg--------------:"<<std::endl;
if(m_serial->waitForReadyRead()) if(m_serial->waitForReadyRead(30000))
{ {
//requestData.resize(m_serial->size()); //requestData.resize(m_serial->size());
requestData = m_serial->readAll(); requestData = m_serial->readAll();

View File

@ -8,16 +8,16 @@ UdpServer::UdpServer()
m_udpSocket->bind(45454, QUdpSocket::ShareAddress); m_udpSocket->bind(45454, QUdpSocket::ShareAddress);
connect(m_udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams())); connect(m_udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams()));
m_RecordThread=new QThread();
m_imager=new XimeaImager();
m_imager->moveToThread(m_RecordThread);
m_RecordThread->start(QThread::HighestPriority);
m_RecordSbgThread=new QThread(); m_RecordSbgThread=new QThread();
m_sbgRecorder=new sbgtc::SbgRecorder(); m_sbgRecorder=new sbgtc::SbgRecorder();
m_sbgRecorder->moveToThread(m_RecordSbgThread); m_sbgRecorder->moveToThread(m_RecordSbgThread);
m_RecordSbgThread->start(); m_RecordSbgThread->start();
m_RecordThread=new QThread();
m_imager=new XimeaImager();
m_imager->moveToThread(m_RecordThread);
m_RecordThread->start();
m_CopyFileThread=new QThread(); m_CopyFileThread=new QThread();
m_copyFile=new FileOperation(); m_copyFile=new FileOperation();
m_copyFile->moveToThread(m_CopyFileThread); m_copyFile->moveToThread(m_CopyFileThread);
@ -47,21 +47,45 @@ UdpServer::UdpServer()
connect(m_sbgRecorder, SIGNAL(serialPortStatus(int)),this, SLOT(sendSerialPortStatus(int))); connect(m_sbgRecorder, SIGNAL(serialPortStatus(int)),this, SLOT(sendSerialPortStatus(int)));
connect(m_sbgRecorder, SIGNAL(sbgSolutionModeSignal(int)),this, SLOT(sendSbgSolutionModeState(int))); connect(m_sbgRecorder, SIGNAL(sbgSolutionModeSignal(int)),this, SLOT(sendSbgSolutionModeState(int)));
connect(m_sbgRecorder, SIGNAL(sbgAccuracySignal(int)),this, SLOT(sendSbgAccuracyState(int))); connect(m_sbgRecorder, SIGNAL(sbgAccuracySignal(int,int)),this, SLOT(sendSbgAccuracyState(int,int)));
connect(m_imager, SIGNAL(ximeaImageStatus(int)),this, SLOT(sendXimeaImageStatus(int))); connect(m_imager, SIGNAL(ximeaImageStatus(int)),this, SLOT(sendXimeaImageStatus(int)));
connect(m_imager, SIGNAL(autoExposeMaxValueOfOneFrame(int, double)),this, SLOT(sendXimeaAutoExposeMaxValueOfOneFrame(int, double)));
connect(m_imager, SIGNAL(binSignal(int, int)),this, SLOT(sendXimeaBinState(int, int)));
connect(m_imager, SIGNAL(frameRateSignal(double)),this, SLOT(sendXimeaImageFrameRate(double)));
connect(m_copyFile, SIGNAL(copyFileStatus(int)),this, SLOT(sendCopyFileStatus(int))); connect(m_copyFile, SIGNAL(copyFileStatus(int)),this, SLOT(sendCopyFileStatus(int)));
QString ximeaParamCfgFile = "/media/nvme/300TC/config/StateOf300tc.cfg";
stateOf300tc.setConfigfilePath(ximeaParamCfgFile.toStdString());
if(!stateOf300tc.isConfigfileExist())
stateOf300tc.createConfigFile();
stateOf300tc.parseConfigfile();
stateOf300tc.setSbgState(0);
stateOf300tc.setSbgSolutionMode(0);
stateOf300tc.setXimeaState(100);
stateOf300tc.setFrameRate(0);
stateOf300tc.setExposeTime(0);
stateOf300tc.setExposeMaxValueOfOneFrame(0);
//当软件不正常关闭并且重启后通知其他psdk程序 //当软件不正常关闭并且重启后通知其他psdk程序
m_clientIpAddress=QHostAddress(QHostAddress::LocalHost); m_clientIpAddress=QHostAddress(QHostAddress::LocalHost);
sendSerialPortStatus(0); sendSerialPortStatus(0);
sendXimeaImageStatus(0); sendXimeaImageStatus(100);
sendCopyFileStatus(0); sendCopyFileStatus(0);
system("sudo gpio write 10 0");
m_recordTempThread=new QThread();
m_300tcTemperature = new Record300TcTemperature();
m_300tcTemperature->moveToThread(m_recordTempThread);
m_recordTempThread->start();
connect(this, SIGNAL(record300tcTemperatureSignal(QString)),m_300tcTemperature, SLOT(recordTemperature(QString)));
QDateTime curDateTime = QDateTime::currentDateTime();
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
QString Temperature300tcCSVPath = QDir::cleanPath(QString::fromStdString("/media/nvme/300TC/programRunLog/300tcTemperature") + QDir::separator() + "300tcTemperature_" + currentTime + ".csv");
emit record300tcTemperatureSignal(Temperature300tcCSVPath);
std::cout<<"UdpServer::UdpServer--------:System ready!"<<std::endl; std::cout<<"UdpServer::UdpServer--------:System ready!"<<std::endl;
} }
@ -88,6 +112,10 @@ void UdpServer::processPendingDatagrams()
case 1://启动系统: 打开sbg串口并采集数据打开光谱仪 case 1://启动系统: 打开sbg串口并采集数据打开光谱仪
{ {
std::cout<<"1代表启动系统!"<<std::endl; std::cout<<"1代表启动系统!"<<std::endl;
system("sudo gpio write 10 1");
sleep(4);//睡眠4秒等待电脑打开usb电源以便给相机供电
emit systemStart(); emit systemStart();
break; break;
@ -95,7 +123,7 @@ void UdpServer::processPendingDatagrams()
case 2://关闭系统:关闭相机和sbg串口,关闭软件 case 2://关闭系统:关闭相机和sbg串口,关闭软件
{ {
std::cout<<"2代表关闭系统!"<<std::endl; std::cout<<"2代表关闭系统!"<<std::endl;
m_300tcTemperature->stopRecordTemperature();
if(m_sbgRecorder->getSbgState()>=1) if(m_sbgRecorder->getSbgState()>=1)
{ {
@ -110,31 +138,27 @@ void UdpServer::processPendingDatagrams()
emit systemStop(); emit systemStop();
sleep(4);//睡眠4秒等待
system("sudo gpio write 10 0");
//QCoreApplication::quit(); //QCoreApplication::quit();
break; break;
} }
case 3://系统开始采集高光谱影像 case 3://系统开始采集高光谱影像
{ {
//emit startRecordHyperspectralSignal();//真实的影像开始采集通过惯导中的信号(sbgReady)触发 if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=103)
m_sbgRecorder->startRecordHyperspectral(); {
std::cout<<"3代表系统开始采集高光谱影像!"<<std::endl;
// if(m_sbgRecorder->getSbgState()==2)//开始采集前还需要判断相机的状态?????????????????????????????????????????? m_sbgRecorder->startRecordHyperspectral();
// { }
// }
// else if(m_sbgRecorder->getSbgState()==3)
// {
// std::cout<<"系统已经开始采集!"<<std::endl;
// }
break; break;
} }
case 4://系统停止采集高光谱影像 case 4://系统停止采集高光谱影像
{ {
std::cout<<"4代表系统停止采集高光谱影像!"<<std::endl;
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=104) if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=104)
{ {
std::cout<<"4代表系统停止采集高光谱影像!"<<std::endl;
m_imager->stopRecord(); m_imager->stopRecord();
} }
@ -162,17 +186,11 @@ void UdpServer::processPendingDatagrams()
} }
case 7: case 7:
{ {
if(datagramList[1].toInt()==1) if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=103)
{ {
std::cout<<"拷贝数据!"<<std::endl; float time = datagramList[1].toFloat();//μs
m_imager->wrapSetExposureTime(time);
emit startCopyFileSignal(); std::cout<<"7手动设置曝光时间为" << time <<std::endl;
}
else if(datagramList[1].toInt()==0)
{
std::cout<<"删除数据!"<<std::endl;
emit startDeleteFileSignal();
} }
break; break;
@ -200,8 +218,30 @@ void UdpServer::processPendingDatagrams()
break; break;
} }
case 10:
{
std::cout<<"10代表!"<<std::endl;
int sbgState,sbgSolutionMode,ximeaState,frameRate,exposeMaxValueOfOneFrame;
float exposeTime;
stateOf300tc.getSbgState(sbgState);
stateOf300tc.getSbgSolutionMode(sbgSolutionMode);
stateOf300tc.getXimeaState(ximeaState);
stateOf300tc.getFrameRate(frameRate);
stateOf300tc.getExposeTime(exposeTime);
stateOf300tc.getExposeMaxValueOfOneFrame(exposeMaxValueOfOneFrame);
sendSerialPortStatus(sbgState);
sendSbgSolutionModeState(sbgSolutionMode);
sendXimeaImageStatus(ximeaState);
sendXimeaAutoExposeMaxValueOfOneFrame(exposeMaxValueOfOneFrame, exposeTime);
sendXimeaImageFrameRate(frameRate);
break;
}
default: default:
std::cout<<">=9没有意义!"<<std::endl; std::cout<<">=11没有意义!"<<std::endl;
break; break;
} }
@ -253,9 +293,9 @@ void UdpServer::sender(int status)
void UdpServer::sendSerialPortStatus(int serialPortStatus) void UdpServer::sendSerialPortStatus(int serialPortStatus)
{ {
std::cout<<"UdpServer::sendSerialPortStatus---------------------:"<< serialPortStatus <<std::endl; // std::cout<<"UdpServer::sendSerialPortStatus---------------------:"<< serialPortStatus <<std::endl;
std::cout<<"UdpServer::sendSerialPortStatus---------------------:"<< m_clientIpAddress.AnyIPv4 <<std::endl; // std::cout<<"UdpServer::sendSerialPortStatus---------------------:"<< m_clientIpAddress.AnyIPv4 <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;
@ -263,11 +303,13 @@ void UdpServer::sendSerialPortStatus(int serialPortStatus)
datagram2send.operator =(status.toStdString().c_str()); datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455); m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setSbgState(serialPortStatus);
} }
void UdpServer::sendSbgSolutionModeState(int SolutionMode) void UdpServer::sendSbgSolutionModeState(int SolutionMode)
{ {
std::cout<<"UdpServer::sendSbgSolutionModeState---------------------:"<< SolutionMode <<std::endl; // std::cout<<"UdpServer::sendSbgSolutionModeState---------------------:"<< SolutionMode <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;
@ -275,15 +317,17 @@ void UdpServer::sendSbgSolutionModeState(int SolutionMode)
datagram2send.operator =(status.toStdString().c_str()); datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455); m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setSbgSolutionMode(SolutionMode);
} }
void UdpServer::sendSbgAccuracyState(int Accuracy) void UdpServer::sendSbgAccuracyState(int Accuracy,int SatelliteCounter)
{ {
// std::cout<<"UdpServer::sendSbgAccuracyState---------------------:"<< Accuracy <<std::endl; // std::cout<<"UdpServer::sendSbgAccuracyState---------------------:"<< Accuracy <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;
QString status = "Accuracy," + QString::number(Accuracy); QString status = "Accuracy," + QString::number(Accuracy) + "," + QString::number(SatelliteCounter);
datagram2send.operator =(status.toStdString().c_str()); datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455); m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
@ -291,7 +335,7 @@ void UdpServer::sendSbgAccuracyState(int Accuracy)
void UdpServer::sendXimeaImageStatus(int ximeaImageStatus) void UdpServer::sendXimeaImageStatus(int ximeaImageStatus)
{ {
std::cout<<"UdpServer::sendXimeaImageStatus---------------------:"<< ximeaImageStatus <<std::endl; // std::cout<<"UdpServer::sendXimeaImageStatus---------------------:"<< ximeaImageStatus <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;
@ -299,11 +343,54 @@ void UdpServer::sendXimeaImageStatus(int ximeaImageStatus)
datagram2send.operator =(status.toStdString().c_str()); datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455); m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setXimeaState(ximeaImageStatus);
}
void UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOneFrame, double exposeTime)
{
// std::cout<<"UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame---------------------:"<< exposeTime << " " << autoExposeMaxValueOfOneFrame <<std::endl;
QByteArray datagram2send;
QString status = "XimeaAutoExpose," + QString::number(autoExposeMaxValueOfOneFrame) + "," + QString::number(exposeTime, 'f', 2);
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setExposeTime(exposeTime);
stateOf300tc.setExposeMaxValueOfOneFrame(autoExposeMaxValueOfOneFrame);
}
void UdpServer::sendXimeaBinState(int spatialBin, int spectralBin)
{
// std::cout<<"UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame---------------------:"<< ximeaImageStatus <<std::endl;
QByteArray datagram2send;
QString status = "bin," + QString::number(spatialBin) + "," + QString::number(spectralBin);
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
}
void UdpServer::sendXimeaImageFrameRate(double frameRate)
{
// std::cout<<"UdpServer::sendXimeaImageFrameRate---------------------:"<< ximeaImageStatus <<std::endl;
QByteArray datagram2send;
QString status = "XimeaFrameRate," + QString::number(frameRate, 'f', 2);
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setFrameRate(frameRate);
} }
void UdpServer::sendCopyFileStatus(int fileStatus) void UdpServer::sendCopyFileStatus(int fileStatus)
{ {
std::cout<<"UdpServer::sendCopyFileStatus---------------------:"<< fileStatus <<std::endl; // std::cout<<"UdpServer::sendCopyFileStatus---------------------:"<< fileStatus <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;
@ -317,3 +404,199 @@ void UdpServer::onRecordFinished()
{ {
std::cout<<"UdpServer::onRecordFinished----------------:影像停止采集"<<std::endl; std::cout<<"UdpServer::onRecordFinished----------------:影像停止采集"<<std::endl;
} }
Record300TcTemperature::Record300TcTemperature()
{
m_bIsRecord = true;
}
void Record300TcTemperature::stopRecordTemperature()
{
m_bIsRecord = false;
}
void Record300TcTemperature::recordTemperature(QString filePath= nullptr)
{
if(filePath== nullptr)
filePath="300tcTemperature.csv";
QList<QString> fileInfo = getFileInfo(filePath);
bool ret = createDir(fileInfo[0]);
ofstream temperatureFile300Tc(filePath.toStdString().c_str(),ios::app);
int counter = 0;
m_serial=new QSerialPort();
if(m_serial->isOpen())//如果串口已经打开了 先给他关闭了
{
m_serial->clear();
m_serial->close();
}
QString portname = "ttyUSB2";
m_serial->setPortName(portname);
m_serial->open(QIODevice::ReadWrite);
bool x=m_serial->setBaudRate(9600);
QByteArray requestData;
while (m_bIsRecord)
{
counter++;
if(m_serial->waitForReadyRead(30000))
{
requestData = m_serial->readAll();
float temp = parseMessage(&requestData);
if (temp == -10000)
{
continue;
}
QDateTime curDateTime = QDateTime::currentDateTime();
QString currentTime = curDateTime.toString("yyyy/MM/dd hh:mm:ss");
temperatureFile300Tc << currentTime.toStdString() << "," << temp << "\n";
// if(temp > 80)
// {
// system("/home/300tc/projects/udpClient/udpClient 127.0.0.1 9,0");
// }
// if(temp > 90)
// {
// system("/home/300tc/projects/udpClient/udpClient 127.0.0.1 2");
// }
//
if (counter % 60 == 0)
{
temperatureFile300Tc.flush();
}
sleep(1);
}
else
{
// std::cout<<"Record300TcTemperature::recordTemperature--Wait response timeout."<<std::endl;
}
}
m_bIsRecord = true;
temperatureFile300Tc.close();
}
float Record300TcTemperature::parseMessage(QByteArray * data)
{
float Lux;
float T;
float P;
float Hum;
float H;
bool hasTemperature = false;
// qDebug() << "Received data(hex): " << data->toHex();
// for (int i = 0; i < data->length(); ++i)
// {
// qDebug() << i << ":" << (int)data->at(i);
// }
QByteArray target = QByteArray::fromHex("5a5a"); // The pattern to search for
int offset_tmp = data->indexOf(target);
QList<int> offsets;
while (offset_tmp != -1)
{
offsets.append(offset_tmp);
offset_tmp = data->indexOf(target, offset_tmp + target.size());
}
if (offsets.isEmpty())
{
// qDebug() << "5A5A not found in the data.";
return -10000;
}
// qDebug() << "5A5A found at offsets:" << offsets;
for (int i = 0; i < offsets.length(); ++i)
{
int offset = offsets.at(i);
int messageClass = data->at(offset + 2);
int messageCount = data->at(offset + 3) + 5;
// qDebug() << "messageCount:" << messageCount;
if (offset + messageCount - 1 > data->length() - 1)
{
qDebug() << i << ": Some data of this frame is missing! Discarding the frame.";
continue;
}
int checksum = 0;
QList<int> numbers;
for (int j = 0; j < messageCount - 1; ++j)
{
if (i==offsets.length()-1 && j== messageCount-1)
{
int sdf=1;
}
int index = offset + j;
if (index >= data->length())//Some data of this frame is missing! Discarding the frame.
{
checksum = -1;
break;
}
int tmp = static_cast<int>(data->at(index));
numbers.append(tmp);
checksum += tmp;
}
// qDebug() << "jiaqilai:" << numbers;
if (checksum == -1)
{
qDebug() << "Some data of this frame is missing! Discarding the frame.";
continue;
}
if ((checksum & 0xFF) != data->at(offset + messageCount - 1))
{
qDebug() << "Checksum mismatch! Discarding the frame.";
continue;
}
//parse data
switch (messageClass)
{
case 0x15:
Lux = (float)((data->at(offset + 4)<<24)|(data->at(offset + 5)<<16)|(data->at(offset + 6)<<8)|data->at(offset + 7)) / 100;
// qDebug() << "lux: " << Lux;
break;
case 0x45:
T = (float)((data->at(offset + 4)<<8)|data->at(offset + 5)) / 100;
P = (float)((data->at(offset + 6)<<24)|(data->at(offset + 7)<<16)|(data->at(offset + 8)<<8)|data->at(offset + 9)) / 100;
Hum = (float)((data->at(offset + 10)<<8) | data->at(offset + 11)) / 100;
H = (float)((data->at(offset + 12)<<8)|data->at(offset + 13));
hasTemperature = true;
// qDebug() << "T: " << T;
// qDebug() << "P: " << P;
// qDebug() << "Hum: " << Hum;
// qDebug() << "H: " << H;
break;
default : // 可选的
;
}
}
if (hasTemperature)
{
return T;
}
else
{
return -10000;
}
}

View File

@ -1,6 +1,25 @@
#include "Header_Files/utility_tc.h" #include "Header_Files/utility_tc.h"
#include <QDir> #include <QDir>
QString formatTimeStr(char * format)
{
//获取系统时间
time_t timer;//time_t就是long int 类型
struct tm *tblock;
timer = time(NULL);//返回秒数(精度为秒)从1970-1-1,00:00:00 可以当成整型输出或用于其它函数
tblock = localtime(&timer);
//printf("Local time is: %s\n", asctime(tblock));
//格式化时间为需要的格式
char timeStr_tmp[256] = { 0 };
strftime(timeStr_tmp, sizeof(timeStr_tmp), format, tblock);//
QString timeStr2(timeStr_tmp);
// qDebug() << "time is:" << timeStr2;
return timeStr2;
}
QString getFileNameBaseOnTime() QString getFileNameBaseOnTime()
{ {
using namespace std; using namespace std;
@ -69,3 +88,36 @@ void swap(unsigned short * a, unsigned short * b)
*a=*b; *a=*b;
*b=tmp; *b=tmp;
} }
bool createDir(QString fullPath)
{
QDir dir(fullPath);
if (dir.exists()) {
return true;
} else {
bool ok = dir.mkpath(fullPath);//创建多级目录
return ok;
}
}
QList<QString> getFileInfo(QString file)
{
QFileInfo fileInfo = QFileInfo(file);
QString fileName, fileSuffix, filePath;
filePath = fileInfo.absolutePath();//绝对路径
fileName = fileInfo.fileName();//文件名
fileSuffix = fileInfo.suffix();//文件后缀
// qDebug() << fileName <<endl
// << fileSuffix<< endl
// << filePath<< endl;
QList<QString> result;
result.append(filePath);
result.append(fileName);
result.append(fileSuffix);
return result;
}

File diff suppressed because it is too large Load Diff