轨迹点信息优化
This commit is contained in:
+5
-5
@@ -72,7 +72,7 @@ struct CPR_Data {
|
||||
std::function<std::optional<CPR::Position>(std::string_view, std::string_view, time_t, time_t)> global_parse = nullptr;
|
||||
std::function<std::optional<CPR::Position>(std::string_view, double lat, double lon, time_t, time_t)> locale_parse = nullptr;
|
||||
std::function<std::string(double, double, CPR::Frame)> encode = nullptr;
|
||||
std::optional<CPR::Position> pos;
|
||||
std::optional<CPR::Position> last_parse_pos;
|
||||
CPR::Frame cpr_format = CPR::Frame::Even;
|
||||
};
|
||||
struct Constraint {
|
||||
@@ -91,7 +91,7 @@ struct CPR_MSG : CPR_Data {
|
||||
std::string current_state(P_S msg);
|
||||
Psc::JSON current_state_json() {
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
ret.append({"pos", (pos.has_value() ? pos->to_string() : "null")});
|
||||
ret.append({"pos", (last_parse_pos.has_value() ? last_parse_pos->to_string() : "null")});
|
||||
ret.append({"odd_msg", odd_msg.to_json()});
|
||||
ret.append({"even_msg", even_msg.to_json()});
|
||||
return ret;
|
||||
@@ -104,15 +104,15 @@ struct CPR_MSG : CPR_Data {
|
||||
}
|
||||
virtual Psc::JSON toJson() {
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
Ret_J(pos)
|
||||
Ret_J(last_parse_pos)
|
||||
Ret_J(cpr_format)
|
||||
return ret;
|
||||
}
|
||||
virtual void set(std::string& msg_bin) {
|
||||
set_bin<53, 1>(msg_bin, static_cast<int>(this->cpr_format));
|
||||
if (pos.has_value()) {
|
||||
if (last_parse_pos.has_value()) {
|
||||
set_bin<54, 34>(msg_bin,
|
||||
encode(this->pos->lat, this->pos->lon, this->cpr_format));
|
||||
encode(this->last_parse_pos->lat, this->last_parse_pos->lon, this->cpr_format));
|
||||
}
|
||||
}
|
||||
private:
|
||||
|
||||
@@ -128,3 +128,13 @@ void XYZ_to_WGS84_LBH(double X, double Y, double Z, double& longitude,
|
||||
double& latitude, double& altitude);
|
||||
} // namespace CPR
|
||||
} // namespace SSR
|
||||
#include <format>
|
||||
template <>
|
||||
struct std::formatter<SSR::CPR::Position> {
|
||||
constexpr auto parse(std::format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
auto format(const SSR::CPR::Position& pos, std::format_context& ctx) const {
|
||||
return std::format_to(ctx.out(), "({}, {})", pos.lat, pos.lon);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "convert/DataOutputFormats.h"
|
||||
#include "enum.h"
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#define STRINGIFY(x) #x
|
||||
// 硬件接收来的 二进制消息族
|
||||
@@ -204,17 +205,12 @@ struct Position_3D : CPR::Position {
|
||||
Position_3D(CPR::D lat, CPR::D lon, CPR::D alt) : CPR::Position(lat, lon), alt(alt) {}
|
||||
};
|
||||
// 这个返回值的意义在于 解码失败后 返回值能反应出是 位置解码失败
|
||||
// 还是奇偶报文解码位置失败
|
||||
// 还是奇偶报文解码位置失败 轨迹点上会显示的信息
|
||||
class Pos_Ret {
|
||||
public:
|
||||
CPR::Position pos;
|
||||
std::shared_ptr<Mode_S_Msg> that;
|
||||
using Extra = std::variant<std::shared_ptr<Mode_S_Msg>, CPR::Position>;
|
||||
Extra extra;
|
||||
Pos_Ret(CPR::Position p, std::shared_ptr<Mode_S_Msg> t,
|
||||
std::shared_ptr<Mode_S_Msg> o) : pos(p), that(std::move(t)), extra(std::move(o)) {}
|
||||
Pos_Ret(CPR::Position p, std::shared_ptr<Mode_S_Msg> t, CPR::Position old) : pos(p), that(std::move(t)),
|
||||
extra(old) {}
|
||||
Psc::JSON info;
|
||||
Pos_Ret(CPR::Position p, Psc::JSON info) : pos(p), info(std::move(info)) {}
|
||||
};
|
||||
// 展示出最详细的信息
|
||||
struct Position_Info : Position_3D {
|
||||
@@ -222,10 +218,8 @@ struct Position_Info : Position_3D {
|
||||
std::uint64_t utc{};
|
||||
std::uint64_t odd_even_diff_ns{};
|
||||
Position_Info() : Position_3D(0.0, 0.0, 0.0) {}
|
||||
Pos_Ret::Extra extra;
|
||||
std::shared_ptr<Mode_S_Msg> that;
|
||||
Position_Info(const Pos_Ret& r, CPR::D alt) : Position_3D(r.pos.lat, r.pos.lon, alt), that(r.that),
|
||||
extra(r.extra) {
|
||||
Psc::JSON info;
|
||||
Position_Info(const Pos_Ret& r, CPR::D alt) : Position_3D(r.pos.lat, r.pos.lon, alt), info(r.info) {
|
||||
using namespace std::chrono;
|
||||
utc = static_cast<std::uint64_t>(
|
||||
duration_cast<seconds>(system_clock::now().time_since_epoch()).count());
|
||||
@@ -236,30 +230,14 @@ struct Position_Info : Position_3D {
|
||||
Ret_J(lon)
|
||||
Ret_J(alt)
|
||||
Ret_J(utc)
|
||||
Ret_J(that->mlat_timestamp)
|
||||
Ret_J(that->msg_hex)
|
||||
Ret_J(that->signal_level)
|
||||
if (auto p = std::get_if<
|
||||
std::shared_ptr<Mode_S_Msg>>(
|
||||
&extra)) {
|
||||
std::shared_ptr<Mode_S_Msg> other = *p;
|
||||
Ret_J(other->mlat_timestamp)
|
||||
Ret_J(other->msg_hex)
|
||||
Ret_J(other->signal_level)
|
||||
return ret;
|
||||
}
|
||||
if (auto p = std::get_if<CPR::Position>(&extra)) {
|
||||
CPR::Position old = *p;
|
||||
Ret_J(old)
|
||||
return ret;
|
||||
}
|
||||
ret.append_list(info.children);
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
struct POS_List {
|
||||
NoneCopyLock mtx;
|
||||
size_t max_size;
|
||||
POS_List() {}
|
||||
size_t max_size{};
|
||||
POS_List() = default;
|
||||
void reset() {
|
||||
std::lock_guard g(mtx.mtx);
|
||||
seq = 0;
|
||||
@@ -300,3 +278,12 @@ protected:
|
||||
std::vector<Position_Info> buf;
|
||||
};
|
||||
} // namespace SSR
|
||||
template <>
|
||||
struct std::formatter<SSR::Play_Back_Time_Point> {
|
||||
constexpr auto parse(std::format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
auto format(const SSR::Play_Back_Time_Point& value, std::format_context& ctx) const {
|
||||
return std::format_to(ctx.out(), "{}", value.abs_sec());
|
||||
}
|
||||
};
|
||||
|
||||
+77
-42
@@ -23,31 +23,6 @@ inline CPR_CB cpr_cb = [](CPR_Type t, CPR_Ret_Type err_type, std::string_view lo
|
||||
if (mode_s_logger) mode_s_logger->debug("CPR/" + Psc::to_string(t) + "/" + Psc::to_string(err_type), {}, log);
|
||||
};
|
||||
namespace ADS_B_T {
|
||||
// cpr回调
|
||||
template <typename That>
|
||||
RET<Pos_Ret> CPR_MSG<That>::local_parse_message(CPR::Position old_pos, P_S msg, double time_s, Constraint constraint) {
|
||||
constraint.cb(SSR::CPR_Type::Local_pos_parse, SSR::CPR_Ret_Type::Base, current_state(msg), msg);
|
||||
auto diff_time = std::abs(time_s - last_parse_pos_time);
|
||||
if (constraint.time_space_filter && diff_time > constraint.max_time_s) {
|
||||
constraint.cb(SSR::CPR_Type::Local_pos_parse, SSR::CPR_Ret_Type::Time_Space_Too_Long, current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
auto new_pos = locale_parse(msg->msg_bin, old_pos.lat, old_pos.lon, time_s, last_parse_pos_time);
|
||||
if (!new_pos.has_value()) {
|
||||
constraint.cb(SSR::CPR_Type::Local_pos_parse, SSR::CPR_Ret_Type::Inter_Error, current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
auto distance_m = CPR::haversine(old_pos, new_pos.value());
|
||||
auto used_time_s = time_s - last_parse_pos_time;
|
||||
auto max_distance = used_time_s * constraint.max_speed_m_s;
|
||||
if (constraint.speed_filter && distance_m > max_distance) {
|
||||
auto var = VAR_STR_6(distance_m, time_s, last_parse_pos_time, used_time_s, constraint.max_speed_m_s, max_distance);
|
||||
constraint.cb(SSR::CPR_Type::Local_pos_parse, SSR::CPR_Ret_Type::Speed_Error, "本地解码 速度异常:" + var + current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
constraint.cb(SSR::CPR_Type::Local_pos_parse, SSR::CPR_Ret_Type::Parse_OK, current_state(msg), msg);
|
||||
return Pos_Ret(new_pos.value(), msg, old_pos);
|
||||
}
|
||||
template <typename That>
|
||||
std::string CPR_MSG<That>::current_state(P_S msg) {
|
||||
auto src = msg->source;
|
||||
@@ -63,52 +38,110 @@ std::string CPR_MSG<That>::current_state(P_S msg) {
|
||||
"}}\n",
|
||||
src->get_key(),
|
||||
msg->msg_hex, Psc::to_string(get_cpr_format()),
|
||||
pos.has_value() ? pos->to_string() : "null",
|
||||
last_parse_pos.has_value() ? last_parse_pos->to_string() : "null",
|
||||
odd_msg.to_string(),
|
||||
even_msg.to_string(),
|
||||
Psc::to_string(last_parse_pos_time)
|
||||
);
|
||||
}
|
||||
// cpr回调
|
||||
template <typename That>
|
||||
RET<Pos_Ret> CPR_MSG<That>::local_parse_message(CPR::Position old_pos, P_S msg, double time_s, Constraint constraint) {
|
||||
Psc::JSON info = Psc::JSON::object();
|
||||
auto type = SSR::CPR_Type::Local_pos_parse;
|
||||
info.append({"type", Psc::to_string(type)});
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Base, current_state(msg), msg);
|
||||
auto diff_time = std::abs(time_s - last_parse_pos_time);
|
||||
if (constraint.time_space_filter && diff_time > constraint.max_time_s) {
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Time_Space_Too_Long, current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
else {
|
||||
info.append({"diff_time", std::format("{} = std::abs(time_s:{} - last_parse_pos_time:{})", diff_time, time_s, last_parse_pos_time)});
|
||||
info.append({"if", std::format("diff_time:{} <= constraint.max_time_s:{}", diff_time, constraint.max_time_s)});
|
||||
}
|
||||
auto new_pos = locale_parse(msg->msg_bin, old_pos.lat, old_pos.lon, time_s, last_parse_pos_time);
|
||||
if (!new_pos.has_value()) {
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Inter_Error, current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
else {
|
||||
info.append({"locale_parse", std::format("msg_hex:{}_{} old_pos:{}", msg->msg_hex, msg->time(), old_pos)});
|
||||
}
|
||||
auto distance_m = CPR::haversine(old_pos, new_pos.value());
|
||||
auto used_time_s = time_s - last_parse_pos_time;
|
||||
auto max_distance = used_time_s * constraint.max_speed_m_s;
|
||||
if (constraint.speed_filter && distance_m > max_distance) {
|
||||
auto var = VAR_STR_6(distance_m, time_s, last_parse_pos_time, used_time_s, constraint.max_speed_m_s, max_distance);
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Speed_Error, "本地解码 速度异常:" + var + current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
else {
|
||||
info.append({"distance_m", std::format("{} = CPR::haversine(pos.value():{}, new_pos.value():{})", distance_m, last_parse_pos.value(), new_pos.value())});
|
||||
info.append({"used_time_s", std::format("{} = time_s:{} - last_parse_pos_time:{}", used_time_s, time_s, last_parse_pos_time)});
|
||||
info.append({"max_distance", std::format("{} = used_time_s:{} * constraint.max_speed_m_s:{}", max_distance, used_time_s, constraint.max_speed_m_s)});
|
||||
info.append({"distance_m", std::format("{} <= max_distance:{}", distance_m, max_distance)});
|
||||
}
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Parse_OK, current_state(msg), msg);
|
||||
return Pos_Ret(new_pos.value(), info);
|
||||
}
|
||||
template <typename That>
|
||||
RET<Pos_Ret> CPR_MSG<That>::global_parse_message(P_S msg, double time_s, P_S other_msg, double other_time_s, Constraint constraint) {
|
||||
constraint.cb(SSR::CPR_Type::Global_pos_parse, SSR::CPR_Ret_Type::Base, current_state(msg), msg);
|
||||
Psc::JSON info = Psc::JSON::object();
|
||||
auto type = SSR::CPR_Type::Global_pos_parse;
|
||||
info.append({"type", Psc::to_string(type)});
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Base, current_state(msg), msg);
|
||||
auto diff_time = std::abs(time_s - other_time_s);
|
||||
if (constraint.time_space_filter && diff_time > constraint.max_time_s) {
|
||||
constraint.cb(SSR::CPR_Type::Global_pos_parse, SSR::CPR_Ret_Type::Time_Space_Too_Long, current_state(msg), msg);
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Time_Space_Too_Long, current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
else {
|
||||
info.append({"diff_time", std::format("{} = std::abs(time_s:{} - other_time_s:{})", diff_time, time_s, other_time_s)});
|
||||
info.append({"if", std::format("diff_time:{} <= constraint.max_time_s:{}", diff_time, constraint.max_time_s)});
|
||||
}
|
||||
RET<CPR::Position> new_pos = global_parse(msg->msg_bin, other_msg->msg_bin, time_s, other_time_s);
|
||||
if (!new_pos.has_value()) {
|
||||
constraint.cb(SSR::CPR_Type::Global_pos_parse, SSR::CPR_Ret_Type::Inter_Error, current_state(msg), msg);
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Inter_Error, current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
if (constraint.speed_filter && pos.has_value()) {
|
||||
auto distance_m = CPR::haversine(pos.value(), new_pos.value());
|
||||
else {
|
||||
info.append({"global_parse", std::format("msg:{}_{} other_msg:{}_{}", msg->msg_hex, msg->time(), other_msg->msg_hex, other_msg->time())});
|
||||
}
|
||||
if (constraint.speed_filter && last_parse_pos.has_value()) {
|
||||
auto distance_m = CPR::haversine(last_parse_pos.value(), new_pos.value());
|
||||
auto used_time_s = time_s - other_time_s;
|
||||
auto max_distance = used_time_s * constraint.max_speed_m_s;
|
||||
if (distance_m > max_distance) {
|
||||
auto var = VAR_STR_6(distance_m, time_s, last_parse_pos_time, used_time_s, constraint.max_speed_m_s, max_distance);
|
||||
constraint.cb(SSR::CPR_Type::Global_pos_parse, SSR::CPR_Ret_Type::Speed_Error, "全局解码 速度异常:" + var + current_state(msg), msg);
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Speed_Error, "全局解码 速度异常:" + var + current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
else {
|
||||
info.append({"distance_m", std::format("{} = CPR::haversine(pos.value():{}, new_pos.value():{})", distance_m, last_parse_pos.value(), new_pos.value())});
|
||||
info.append({"used_time_s", std::format("{} = time_s:{} - other_time_s:{}", used_time_s, time_s, other_time_s)});
|
||||
info.append({"max_distance", std::format("{} = used_time_s:{} * constraint.max_speed_m_s:{}", max_distance, used_time_s, constraint.max_speed_m_s)});
|
||||
info.append({"if", std::format("distance_m:{} <= max_distance:{}", distance_m, max_distance)});
|
||||
}
|
||||
constraint.cb(SSR::CPR_Type::Global_pos_parse, SSR::CPR_Ret_Type::Parse_OK, current_state(msg), msg);
|
||||
return Pos_Ret(new_pos.value(), msg, other_msg);
|
||||
}
|
||||
constraint.cb(type, SSR::CPR_Ret_Type::Parse_OK, current_state(msg), msg);
|
||||
return Pos_Ret(new_pos.value(), info);
|
||||
}
|
||||
template <typename That>
|
||||
RET<Pos_Ret> CPR_MSG<That>::parse_message(P_S msg, double time_s, Constraint constraint) {
|
||||
auto f = get_cpr_format();
|
||||
Info* that = f == CPR::Frame::Even ? &even_msg : &odd_msg;
|
||||
Info* other = f == CPR::Frame::Even ? &odd_msg : &even_msg;
|
||||
if (!pos.has_value()) {
|
||||
if (!last_parse_pos.has_value()) {
|
||||
constraint.cb(SSR::CPR_Type::Local_pos_parse, SSR::CPR_Ret_Type::Lack_Old_Pos, "缺旧位置" + current_state(msg), msg);
|
||||
// 不返回下面接着走
|
||||
}
|
||||
else {
|
||||
RET<Pos_Ret> ret = local_parse_message(pos.value(), msg, time_s, constraint);
|
||||
RET<Pos_Ret> ret = local_parse_message(last_parse_pos.value(), msg, time_s, constraint);
|
||||
if (ret.has_value()) {
|
||||
that->msg = msg;
|
||||
that->time = time_s;
|
||||
pos = ret.value().pos;
|
||||
last_parse_pos = ret.value().pos;
|
||||
last_parse_pos_time = time_s;
|
||||
return ret;
|
||||
}
|
||||
@@ -117,19 +150,21 @@ RET<Pos_Ret> CPR_MSG<That>::parse_message(P_S msg, double time_s, Constraint con
|
||||
that->msg = msg;
|
||||
that->time = time_s;
|
||||
constraint.cb(SSR::CPR_Type::Global_pos_parse, SSR::CPR_Ret_Type::Lack_Other_Msg, "缺另一条消息" + current_state(msg), msg);
|
||||
return std::nullopt;
|
||||
}
|
||||
else {
|
||||
RET<Pos_Ret> ret = global_parse_message(msg, time_s, other->msg, other->time, constraint);
|
||||
if (ret.has_value()) {
|
||||
that->msg = msg;
|
||||
that->time = time_s;
|
||||
pos = ret.value().pos;
|
||||
last_parse_pos = ret.value().pos;
|
||||
last_parse_pos_time = time_s;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
last_parse_pos_time = 0;
|
||||
pos = std::nullopt;
|
||||
// 此时新来的点本地解码失败 全局解码也失败 很可能是 中间丢了很多消息 所以旧的pos
|
||||
// last_parse_pos_time = 0;
|
||||
// pos = std::nullopt;
|
||||
that->msg = msg;
|
||||
that->time = time_s;
|
||||
other->reset();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user