首次提交
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
#ifndef MOCK_CORE_H
|
||||
#define MOCK_CORE_H
|
||||
#include <vector>
|
||||
|
||||
|
||||
// 通过构造 三个基站 以及 一个飞机 三个数据源 来生成数据
|
||||
|
||||
namespace Mock {
|
||||
struct BaseStation {
|
||||
Psc::socket::Server_Socket server;
|
||||
HULC_Status_Message hulc_message{};
|
||||
// 生成HUCL消息报告 1a34 自身经纬度 1s 1次
|
||||
BaseStation() {
|
||||
hulc_message.SerNum = 3;
|
||||
hulc_message.Alt = 7500;
|
||||
hulc_message.HDOP = 0.75;
|
||||
hulc_message.Sat = 75;
|
||||
hulc_message.I_U_ = 88;
|
||||
}
|
||||
|
||||
std::string generage_message() {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto epoch = std::chrono::system_clock::to_time_t(now);
|
||||
hulc_message.xTime = epoch;
|
||||
// 要经过转义
|
||||
return packet_to_escape_format(hulc_message.toBinary());
|
||||
}
|
||||
|
||||
void set_pos(CPR::D lat, CPR::D lon) {
|
||||
hulc_message.set_latitude(lat);
|
||||
hulc_message.set_longitude(lon);
|
||||
}
|
||||
[[nodiscard]] CPR::Position position() const {
|
||||
CPR::Position pos{};
|
||||
pos.latitude = hulc_message.get_latitude();
|
||||
pos.longitude = hulc_message.get_longitude();
|
||||
return pos;
|
||||
}
|
||||
};
|
||||
|
||||
class Plane {
|
||||
public:
|
||||
std::string icao;
|
||||
std::vector<CPR::Position> track;
|
||||
std::string generate_message(MLAT_timestamp* timestamp, CPR::Position pos, BaseStation* station) {
|
||||
All_Call_Reply::All_Call_Reply r = All_Call_Reply::All_Call_Reply::Builder()
|
||||
.set_icao(icao)
|
||||
.set_interrogator_identifier("abc750")
|
||||
.set_transponder_address(hex2bin("abc617"))
|
||||
.build();
|
||||
|
||||
|
||||
auto [i1, i2] = CPR::light_time_second_nano(station->position(), pos);
|
||||
auto total_nanosec = timestamp->nanosec + i2; // 累加纳秒部分
|
||||
auto total_sec = timestamp->daysec + i1; // 累加秒部分
|
||||
if (total_nanosec >= 1000000000) {
|
||||
// 纳秒部分超过 1 秒,处理进位
|
||||
total_sec += total_nanosec / 1000000000; // 将纳秒转换为秒并加到 total_sec
|
||||
total_nanosec = total_nanosec % 1000000000; // 保留纳秒部分,取余数
|
||||
}
|
||||
MLAT_timestamp t(total_sec, total_nanosec);
|
||||
// 默认构造获取系统的描述 已经经过转义
|
||||
return create_Binary_Format_memory(bin2hex(r.msg), 75, &t);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct Global {
|
||||
std::vector<Plane> planes;
|
||||
|
||||
|
||||
|
||||
std::vector<BaseStation> stations;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user