修复bug
This commit is contained in:
@@ -56,6 +56,83 @@ struct Aircraft_List_JSON_Service_O {
|
||||
RET<size_t> nocl; // Number of sensors providing data aircraft
|
||||
RET<std::string> tq; // Time quality of this entry
|
||||
|
||||
static Psc::JSON view_model() {
|
||||
auto columns = Psc::JSON::array();
|
||||
const auto add_column = [&columns](const char* key, const char* label, const char* type,
|
||||
const char* default_sort_order = nullptr) {
|
||||
auto column = Psc::JSON::object();
|
||||
column.append({"key", key});
|
||||
column.append({"label", label});
|
||||
column.append({"type", type});
|
||||
if (default_sort_order != nullptr) {
|
||||
column.append({"defaultSortOrder", default_sort_order});
|
||||
}
|
||||
columns.append(std::move(column));
|
||||
};
|
||||
|
||||
add_column("index", "序号", "index");
|
||||
auto time_column = Psc::JSON::object();
|
||||
time_column.append({"key", "time"});
|
||||
time_column.append({"label", "时间"});
|
||||
time_column.append({"type", "timestamp"});
|
||||
time_column.append({"secondsKey", "uti"});
|
||||
time_column.append({"nanosecondsKey", "ns"});
|
||||
columns.append(std::move(time_column));
|
||||
|
||||
add_column("times", "<mode_s>消息数", "number");
|
||||
add_column("hex", "识别码<ICAO>", "text");
|
||||
add_column("fli", "航班编号", "text");
|
||||
add_column("ava", "数据来源标识", "text");
|
||||
add_column("src", "首选数据源", "text");
|
||||
add_column("cla", "ADS-B数据子类", "text");
|
||||
add_column("lat", "纬度", "number");
|
||||
add_column("lon", "经度", "number", "descend");
|
||||
add_column("alt", "高度(米)", "number");
|
||||
add_column("spd", "地速(节)", "number");
|
||||
add_column("trk", "航向(真)", "number");
|
||||
add_column("vrt", "垂直速度(<ft/min>)", "number");
|
||||
add_column("gda", "空中/地面状态", "text");
|
||||
add_column("cat", "机型分类", "text");
|
||||
add_column("org", "起飞机场", "text");
|
||||
add_column("dst", "目的机场", "text");
|
||||
add_column("opr", "航空公司", "text");
|
||||
add_column("typ", "机型", "text");
|
||||
add_column("reg", "注册号", "text");
|
||||
add_column("squ", "应答机编码", "text");
|
||||
add_column("cou", "国家", "text");
|
||||
add_column("dis", "接收器距离", "number");
|
||||
add_column("tru", "信任值", "number");
|
||||
add_column("dbm", "信号强度(<dBm>)", "number");
|
||||
add_column("lla", "位置数据延迟(秒)", "number");
|
||||
add_column("tmp", "温度(℃)", "number");
|
||||
add_column("wsp", "风速(节)", "number");
|
||||
add_column("wdi", "风向(°)", "number");
|
||||
add_column("mop", "ADS-B协议版本", "number");
|
||||
add_column("spi", "识别应答(<SPI>)", "text");
|
||||
add_column("alr", "告警状态", "boolean");
|
||||
add_column("ias", "指示空速(<IAS>)", "number");
|
||||
add_column("tas", "真空速(<TAS>)", "number");
|
||||
add_column("hdgm", "磁航向", "number");
|
||||
add_column("hdgt", "真航向", "text");
|
||||
add_column("qnhs", "气压设定(<QNH>)", "text");
|
||||
add_column("alts", "选择高度", "text");
|
||||
add_column("hdgs", "选择航向", "number");
|
||||
add_column("altg", "GNSS椭球高度(英尺)", "number");
|
||||
add_column("pic", "<Asterix PIC>", "text");
|
||||
add_column("tcm", "防撞系统状态", "text");
|
||||
add_column("ape", "自动驾驶启用", "text");
|
||||
add_column("sil", "系统完整性等级(<SIL>)", "number");
|
||||
add_column("sda", "系统设计保证(<SDA>)", "text");
|
||||
add_column("nacp", "位置精度(<NACp>)", "number");
|
||||
add_column("pest", "位置估算次数每秒", "number");
|
||||
add_column("nocl", "提供数据的接收机数", "number");
|
||||
add_column("tq", "时间质量", "text");
|
||||
|
||||
auto model = Psc::JSON::object();
|
||||
model.append({"columns", std::move(columns)});
|
||||
return model;
|
||||
}
|
||||
|
||||
Psc::JSON toJson() {
|
||||
auto ret = Psc::JSON::object();
|
||||
ADD_Json(times);
|
||||
@@ -98,6 +175,8 @@ struct Aircraft_List_JSON_Service_O {
|
||||
ADD_Json_RET(hdgt);
|
||||
ADD_Json_RET(qnhs);
|
||||
ADD_Json_RET(alts);
|
||||
ADD_Json_RET(hdgs);
|
||||
ADD_Json_RET(altg);
|
||||
ADD_Json_RET(pic);
|
||||
ADD_Json_RET(tcm);
|
||||
ADD_Json_RET(ape);
|
||||
|
||||
@@ -604,6 +604,7 @@ void database_server(Global *g) {
|
||||
svr.Post(api + "aircraft_list", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
auto g = Global::instance();
|
||||
const auto include_model = params.try_get_bool("include_model").value_or(false);
|
||||
HTTP_REQUIRE_VALUE(data_source_key,
|
||||
params.try_get_string("data_source_key"))
|
||||
std::shared_ptr<Data_Source> db;
|
||||
@@ -633,7 +634,16 @@ void database_server(Global *g) {
|
||||
{
|
||||
Scope_Timer timer("aircraft_list.json_serialization",
|
||||
g->http_monitor_config.slow_scope_threshold_ms);
|
||||
body = warp(ret).to_json_string();
|
||||
if (include_model) {
|
||||
auto data = JSON::object();
|
||||
data.append({"items", std::move(ret)});
|
||||
auto response = JSON::object();
|
||||
response.append({"model", Aircraft_List_JSON_Service_O::view_model()});
|
||||
response.append({"data", std::move(data)});
|
||||
body = response.to_json_string();
|
||||
} else {
|
||||
body = warp(ret).to_json_string();
|
||||
}
|
||||
}
|
||||
res->setBody(body);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user