77 lines
2.1 KiB
C++
77 lines
2.1 KiB
C++
#include <iostream>
|
|
#include <csignal>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
|
|
#include "Star_sensorHS.h"
|
|
|
|
using namespace std;
|
|
|
|
// 全局变量用于信号处理
|
|
static bool running = true;
|
|
|
|
// 信号处理函数
|
|
void signal_handler(int signal) {
|
|
running = false;
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
// 设置信号处理
|
|
signal(SIGINT, signal_handler);
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
// 默认配置文件
|
|
string config_file = "Star_sensorHS.json";
|
|
|
|
cout << "[INFO] Starting Star Sensor Hardware Service" << endl;
|
|
cout << "[INFO] Loading configuration from: " << config_file << endl;
|
|
|
|
// 解析配置文件
|
|
const int MAX_STARS = 8;
|
|
StarConfig star_configs[MAX_STARS];
|
|
|
|
int star_count = parse_config_file(config_file.c_str(), star_configs, MAX_STARS);
|
|
if (star_count <= 0) {
|
|
cerr << "[ERROR] No valid star sensors configured" << endl;
|
|
return -1;
|
|
}
|
|
|
|
cout << "[INFO] Found " << star_count << " star sensors in configuration" << endl;
|
|
|
|
// 初始化星敏设备
|
|
for (int i = 0; i < star_count; i++) {
|
|
StarConfig config = star_configs[i];
|
|
|
|
// 调用初始化函数
|
|
int result = star_uart_init(config.type, config.star_num,
|
|
config.device.c_str(), config.baudrate);
|
|
|
|
if (result == SAT_ERR_OK) {
|
|
cout << "[OK] Star sensor " << config.star_num << " initialized successfully" << endl;
|
|
} else {
|
|
cerr << "[ERROR] Failed to initialize star sensor " << config.star_num << endl;
|
|
}
|
|
}
|
|
|
|
// 统计初始化成功的星敏数量
|
|
int nano_init_count = 0;
|
|
int pico_init_count = 0;
|
|
|
|
for (int i = 0; i < MAX_STAR_NUM_PER_TYPE; i++) {
|
|
if (nano_stars[i].fd > 0) nano_init_count++;
|
|
if (pico_stars[i].fd > 0) pico_init_count++;
|
|
}
|
|
|
|
// 初始化FastDDS
|
|
Fastdds_init(0, "Star_sensor_Hardware_Service");
|
|
|
|
// 主循环
|
|
while (running) {
|
|
usleep(500000); // 每500ms检查一次
|
|
}
|
|
|
|
// 清理
|
|
Star_sensorHS_cleanup();
|
|
|
|
return 0;
|
|
} |