From 60559291f2edc1e158221417cf00563226af90e9 Mon Sep 17 00:00:00 2001 From: xin Date: Mon, 23 Mar 2026 14:32:12 +0800 Subject: [PATCH] =?UTF-8?q?V1.1=20=E6=AD=A3=E5=BC=8F=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主要新增功能: 1. 添加 Debian 打包脚本 (pack_deb.sh),支持一键打包部署 2. 新增机顶辐照度使用说明书 (README.md),记录系统配置和使用方法 3. 添加 SD 卡配置更新功能 (configdatairis 文件夹),便于现场配置 4. 新增光谱仪打开失败检测,两灯同时闪烁提示异常 5. 添加说明书自动拷贝到 SD 卡功能 详细修改: - main.cpp: * 添加 SD 卡 configdatairis 配置更新逻辑 * 添加说明书自动拷贝到 /home/data/ * 优化 stopwait.txt 判断逻辑 - Source/Capture/MainGrabber.cpp: * 添加光谱仪初始化失败检测,失败时两灯同时闪烁 - Source/Logger/Logger.h: * 添加日志功能支持 - pack_deb.sh: * 新增完整的 Debian 打包脚本 * 支持自动构建、复制文件、生成 postinst/prerm - root/start.sh: * 添加 mkdir 确保 /home/data 目录存在 - root/DCTable.txt: * 添加默认暗电流校准表文件 - README.md: * 编写完整的中文使用说明书 * 包含硬件连接、目录结构、配置说明、GPIO 指示灯含义等 依赖文件: - /root/DeviceSettings.ini (需另行配置) - /root/机顶辐照度使用说明书.md (打包时自动复制) --- README.md | 120 +++++++++++++++++++++++++++++ Source/Capture/MainGrabber.cpp | 20 ++++- Source/Logger/Logger.h | 1 + main.cpp | 108 +++++++++++++------------- pack_deb.sh | 137 +++++++++++++++++++++++++++++++++ root/DCTable.txt | 28 +++++++ root/start.sh | 3 + 7 files changed, 363 insertions(+), 54 deletions(-) create mode 100755 pack_deb.sh create mode 100644 root/DCTable.txt create mode 100644 root/start.sh diff --git a/README.md b/README.md index e69de29..8e896ea 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,120 @@ +# 机顶辐照度使用说明书 + +## 1. 系统概述 + +机顶辐照度使用说明书 支持 GPS 北斗双模定位、实时暗背景扣除等功能。 + +## 2. 硬件连接 + + 光谱仪 |USB(下) + GPS (内置) + +## 3. 目录结构 + +**SD 卡根目录** (挂载到 /home/data/) + +``` +SD卡根目录/ +├── configdatairis/ # 配置更新文件夹(可选) +│ ├── DeviceSettings.ini # 设备配置文件 +│ └── DCTable.txt # 暗电流校准表 +├── Setting/ +│ └── DeviceSettings.ini # 设备配置文件 +├── Data/ +│ ├── DCTable.txt # 暗电流校准表 +│ └── WavelengthInfo.txt # 波长校准信息(程序生成) +├── Log/ # 日志目录 +└── stopwait.txt # 启动等待文件(可选) +``` + + + +## 4. 配置文件 + +### DeviceSettings.ini + +```ini +[FS] +Model=IS1 # 光谱仪型号:IS1, IS11, FLAME +Port=/dev/ttyUSB0 # 串口路径 +UID=FLMS15814 # 设备序列号 +Depth=65535 # 积分深度 +AEMax=0.85 # 自动曝光最大值 +AEMin=0.60 # 自动曝光最小值 +MinSI=1000 # 最小光谱强度 + +[GPS] +Port=/dev/ttyS1 # GPS 串口 +Baud=9600 # GPS 波特率 +``` + +### 支持的光谱仪型号 + +- `IS1` - Iris S1 +- `IS11` - Iris S11 +- `FLAME` - Ocean Optics FLAME + +## 5. 输入输出文件 + +| 文件 | 类型 | 说明 | +|------|------|------| +| DeviceSettings.ini | 输入 | 设备参数配置 | +| DCTable.txt | 输入 | 暗电流校准表 | +| WavelengthInfo.txt | 输出 | 波长校准信息(程序生成) | +| *.dat | 输出 | 采集的光谱数据文件 | + +## 6. 配置更新流程 + +如果在 SD 卡上放置 `configdatairis` 文件夹,程序启动时会自动拷贝其中的配置文件到 `/root` 并删除该文件夹。 + +``` +1. 在 SD 卡根目录创建目录:configdatairis/ +2. 放入配置文件: + - DeviceSettings.ini + - DCTable.txt +3. 启动程序,配置文件会自动复制到系统 /root/ 目录 +4. configdatairis 文件夹会被自动删除 +``` + +## 7. 使用流程 + +### 首次部署 + +1. 格式化 SD 卡(FAT32) +2. 创建必要目录结构: + ``` + SD卡根目录/ + ├── Setting/ + ├── Data/ + └── Log/ + ``` +3. 部署 deb 包或手动复制可执行文件到 `/home/pi/bin/` +4. 配置文件会随程序从系统 /root/ 复制到 SD 卡 + +### 正常启动 + +1. 系统上电,TF 卡自动挂载到 /home/data/ +2. 启动程序:`/home/pi/bin/IRIS_FODIS &` + +### 启动等待 + +如果 **不存在** SD 卡根目录下的 `stopwait.txt` 文件,程序会等待 30 秒再继续(用于调试时等待调试器附加)。 + +### 采集数据 + +程序自动采集光谱数据,保存到 SD 卡根目录 `/Data/` 目录,文件名格式为时间戳。 + +## 8. GPIO 指示灯 + +| 灯状态 | 含义 | +|--------|------| +| 灯1与灯2交替闪烁(各亮200ms) | TF 卡检测失败(卡未挂载),程序等待中 | +| 灯1与灯2同时闪烁(各亮200ms) | 光谱仪打开失败,程序异常 | +| 灯1亮,灯2灭 | GPS 时间同步中 | +| 灯1灭,灯2闪烁(亮200ms) | 数据采集中(光谱采集→写卡) | +| 灯1灭,灯2常亮 | 采集完成/待机 | + +## 9. 版本信息 + +- 当前版本:1.1 +- 版本号文件:SD卡根目录 `/version` diff --git a/Source/Capture/MainGrabber.cpp b/Source/Capture/MainGrabber.cpp index 2e7331b..df7c3bc 100644 --- a/Source/Capture/MainGrabber.cpp +++ b/Source/Capture/MainGrabber.cpp @@ -113,7 +113,23 @@ int CMainGrabber::InitializeWorkers() } m_pctrlFS->SetContext(m_struFSRunParams); - m_pctrlFS->Initialize(); + int iFSInitResult = m_pctrlFS->Initialize(); + if (iFSInitResult != 0) + { + // Sensor 打开失败,两灯同时闪烁 + while (1) + { + system("gpio write 4 1"); + system("gpio write 5 1"); + QEventLoop qeLoop; + QTimer::singleShot(200, &qeLoop, SLOT(quit())); + qeLoop.exec(); + system("gpio write 4 0"); + system("gpio write 5 0"); + QTimer::singleShot(200, &qeLoop, SLOT(quit())); + qeLoop.exec(); + } + } while (!m_pctrlFS->m_iFlagInit) { Delay_MSec(1000); @@ -214,7 +230,7 @@ int CMainGrabber::CheckExposureTime(DataFrame dfTemp) int CMainGrabber::RemoveBackground(DataFrame& dfTemp) { - //ѧ۰ǰΪ + //�����ѧ�۰�������ǰ����������Ϊ������ if (m_struFSRunParams.ucDeviceModel==DeviceModel::FLAME) { double dBackground = 0; diff --git a/Source/Logger/Logger.h b/Source/Logger/Logger.h index cfbcf02..f22fc96 100644 --- a/Source/Logger/Logger.h +++ b/Source/Logger/Logger.h @@ -49,6 +49,7 @@ namespace QT_LOG outFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); QTextStream ts(&outFile); ts << log_info << endl; + std::cout<< log_info.toStdString() << std::endl; outFile.close(); m_LogMutex.unlock(); diff --git a/main.cpp b/main.cpp index 8b1cd49..f78e29f 100644 --- a/main.cpp +++ b/main.cpp @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) QCoreApplication a(argc, argv); - //ָʾƿ + //ָʾ�ƿ��� //system("sudo mount / dev / mmcblk1p1 / home / data"); system("gpio mode 4 out"); system("gpio mode 5 out"); @@ -55,7 +55,7 @@ int main(int argc, char* argv[]) qDebug() << "system(gpio mode 5 out)"; ///check tf card - //sdǷأûеƾͽ˸ + //���sd���Ƿ���أ����û�еƾͽ�����˸ std::string device = "/dev/mmcblk1p1"; std::string mount_point = "/home/data"; if (!is_mounted(device, mount_point)/*1*/) @@ -75,21 +75,60 @@ int main(int argc, char* argv[]) } } + // 拷贝说明书到 SD 卡 + if (!QFile::exists("/home/data/机顶辐照度使用说明书.md")) { + if (QFile::exists("/root/机顶辐照度使用说明书.md")) { + QFile::copy("/root/机顶辐照度使用说明书.md", "/home/data/机顶辐照度使用说明书.md"); + } + } - QEventLoop qeLoop; - QTimer::singleShot(30000, &qeLoop, SLOT(quit())); - //QTimer::singleShot(10000, &qeLoop, SLOT(quit())); - qeLoop.exec(); + //////////////////////////////////////////////////////////////////////////Check configdatairis folder + QDir qdirConfigDataIris("/home/data/configdatairis"); + if (qdirConfigDataIris.exists()) + { + printf("configdatairis folder found. Copying config files...\n"); + + QFileInfo fiSettings("/home/data/configdatairis/DeviceSettings.ini"); + if (fiSettings.isFile() && fiSettings.size() >= 50) + { + QFile::copy("/home/data/configdatairis/DeviceSettings.ini", "/root/DeviceSettings.ini"); + printf(" DeviceSettings.ini copied.\n"); + } + + QFileInfo fiDCTable("/home/data/configdatairis/DCTable.txt"); + if (fiDCTable.isFile()) + { + QFile::copy("/home/data/configdatairis/DCTable.txt", "/root/DCTable.txt"); + printf(" DCTable.txt copied.\n"); + } + + // 删除configdatairis文件夹 + qdirConfigDataIris.removeRecursively(); + printf("configdatairis folder removed.\n"); + } + //////////////////////////////////////////////////////////////////////////Check configdatairis folder + + + + if (!QFile::exists("/home/data/stopwait.txt")) { + QEventLoop qeLoop; + QTimer::singleShot(30000, &qeLoop, SLOT(quit())); + // //QTimer::singleShot(10000, &qeLoop, SLOT(quit())); + qeLoop.exec(); + } + // QTimer::singleShot(30000, &qeLoop, SLOT(quit())); + // //QTimer::singleShot(10000, &qeLoop, SLOT(quit())); + // qeLoop.exec(); - OneFSContext m_struFSParam;// + OneFSContext m_struFSParam;//������ GPSInfo m_struGPSInfo; //FodisRP m_struMiscRunParams; - ZZ_SysConfigger m_syscfSettings;// + ZZ_SysConfigger m_syscfSettings;//������ BD357Controller m_ctrlGPS; - CMainGrabber m_mgMainGrabber;//ɼ + CMainGrabber m_mgMainGrabber;//���ɼ� DataFileProcessor m_dfpDataSaver; #ifndef WIN32 @@ -108,47 +147,12 @@ int main(int argc, char* argv[]) QFileInfo m_qfiSettingFileInfo("/home/data/Setting/DeviceSettings.ini"); - if (!m_qfiSettingFileInfo.isFile()) + // 如果SD卡上有配置文件,拷贝到/root下 + if (m_qfiSettingFileInfo.isFile() && m_qfiSettingFileInfo.size() >= 50) { - printf ("DeviceSettings File Missing !!! Will create from default one."); - - QDir qdirPath("/home/data/Setting"); - if (!qdirPath.exists()) - { - bool bRes = qdirPath.mkpath("/home/data/Setting"); - if (!bRes) - { - qDebug() << "DataFileProcessor mkdir Failed."; - return -1; - } - } - - bool bRes = QFile::copy("/root/DeviceSettings.ini", "/home/data/Setting/DeviceSettings.ini"); - if (!bRes) - { - qDebug() << " QFile::copy Failed."; - return -2; - } - } - else - { - int iSize = m_qfiSettingFileInfo.size(); - if (iSize<50) - { - bool bRes = QFile::remove("/home/data/Setting/DeviceSettings.ini"); - if (!bRes) - { - qDebug() << " QFile::remove Failed."; - return -2; - } - - bRes = QFile::copy("/root/DeviceSettings.ini", "/home/data/Setting/DeviceSettings.ini"); - if (!bRes) - { - qDebug() << " QFile::copy Failed."; - return -2; - } - } + printf("DeviceSettings found on SD card. Copying to /root..."); + QFile::copy("/home/data/Setting/DeviceSettings.ini", "/root/DeviceSettings.ini"); + printf("Done.\n"); } //////////////////////////////////////////////////////////////////////////Check Settings File //////////////////////////////////////////////////////////////////////////Load Settings File @@ -209,19 +213,19 @@ int main(int argc, char* argv[]) //m_test.Initialize_Part(); //m_test.LoadTable(); ////////////////////////////////test only - m_ctrlGPS.SetContext(m_mgMainGrabber);//ʼgps + m_ctrlGPS.SetContext(m_mgMainGrabber);//��ʼ��gps m_ctrlGPS.SetupMessagePipeline(); m_ctrlGPS.Initialize(m_struGPSInfo); QThread* m_pqDataGrabberThreadHolder = new QThread(); m_mgMainGrabber.moveToThread(m_pqDataGrabberThreadHolder); - m_mgMainGrabber.SetRunParams(m_struFSParam);//ʼɼ߳ + m_mgMainGrabber.SetRunParams(m_struFSParam);//��ʼ�����ɼ��߳� m_mgMainGrabber.SetContext(m_ctrlGPS, m_dfpDataSaver); m_pqDataGrabberThreadHolder->start(); - m_mgMainGrabber.Initialize();//ʼ + m_mgMainGrabber.Initialize();//��ʼ���� //m_ctrlGPS.VSlot_SkipSyncDateOnce(); diff --git a/pack_deb.sh b/pack_deb.sh new file mode 100755 index 0000000..b7b1621 --- /dev/null +++ b/pack_deb.sh @@ -0,0 +1,137 @@ +#!/bin/bash + +# IRIS_FODIS 项目打包脚本 +# 打包成 Debian 包 + +VERSION=1.1 +PROJECT_NAME="iris-fodis" +PACKAGE_NAME="${PROJECT_NAME}_V${VERSION}.deb" +BUILD_DIR="build" +DEB_DIR="Debpack_iris_fodis" + +# 检查是否在正确目录 +if [ ! -f "CMakeLists.txt" ]; then + echo "错误:请在项目根目录运行此脚本" + exit 1 +fi + +echo "=========================================" +echo "IRIS_FODIS 打包脚本 v${VERSION}" +echo "=========================================" + +# 1. 构建项目 +echo "" +echo "[1/5] 开始构建项目..." + +# 清理旧的 build 目录并重新创建 +#rm -rf $BUILD_DIR +mkdir -p $BUILD_DIR + +cd $BUILD_DIR +cmake .. +#if [ $? -ne 0 ]; then +# echo "错误:cmake 配置失败" +# exit 1 +#fi + +# 执行 make +make -j$(nproc) +if [ $? -ne 0 ]; then + echo "错误:构建失败" + exit 1 +fi +cd .. + +# 检查构建产物 +if [ ! -f "${BUILD_DIR}/IRIS_FODIS" ]; then + echo "错误:构建产物不存在" + exit 1 +fi +echo "构建完成" + +# 2. 创建打包目录 +echo "" +echo "[2/5] 创建打包目录..." +rm -rf $DEB_DIR +mkdir -p $DEB_DIR + +# 3. 复制可执行文件和脚本文件 +echo "" +echo "[3/5] 复制文件..." +mkdir -p ${DEB_DIR}/home/pi/bin +cp ${BUILD_DIR}/IRIS_FODIS ${DEB_DIR}/home/pi/bin/ +chmod +x ${DEB_DIR}/home/pi/bin/IRIS_FODIS + +# 复制启动脚本和配置文件到 /root/ +mkdir -p ${DEB_DIR}/root +cp root/start.sh ${DEB_DIR}/root/ +cp Settings/DeviceSettings.ini ${DEB_DIR}/root/ +cp root/DCTable.txt ${DEB_DIR}/root/ +cp README.md ${DEB_DIR}/root/机顶辐照度使用说明书.md +chmod +x ${DEB_DIR}/root/start.sh + +# 4. 创建 DEBIAN 目录和配置文件 +echo "" +echo "[4/5] 创建 DEBIAN 配置..." +mkdir -p ${DEB_DIR}/DEBIAN + +# 创建 control 文件 +cat > ${DEB_DIR}/DEBIAN/control < ${DEB_DIR}/DEBIAN/postinst < /home/data/version + fi +fi +exit 0 +EOF + +# 创建 prerm 脚本(删除前执行) +cat > ${DEB_DIR}/DEBIAN/prerm <