90 lines
2.7 KiB
C++
90 lines
2.7 KiB
C++
#ifdef _USE_GTEST
|
|
#ifndef TEST_SURV_H
|
|
#define TEST_SURV_H
|
|
#include "global.h"
|
|
|
|
// TEST(SurvTest, FlightStatus) {
|
|
// EXPECT_EQ(surv::fs(hex2bin("2A00516D492B80"))[0], 2);
|
|
// }
|
|
//
|
|
// TEST(SurvTest, DownlinkRequest) {
|
|
// EXPECT_EQ(surv::dr(hex2bin("2A00516D492B80"))[0], 0);
|
|
// }
|
|
//
|
|
// TEST(SurvTest, UtilityMessage) {
|
|
// auto um_result = surv::um(hex2bin("200CBE4ED80137"));
|
|
// EXPECT_EQ(um_result[0], 9);
|
|
// EXPECT_EQ(um_result[1], 1);
|
|
// }
|
|
//
|
|
// TEST(SurvTest, Identity) {
|
|
// EXPECT_EQ(surv::identity(hex2bin("2A00516D492B80")), "0356");
|
|
// }
|
|
//
|
|
// TEST(SurvTest, Altitude) {
|
|
// EXPECT_EQ(surv::altitude(hex2bin("20001718029FCD")), 36000);
|
|
//
|
|
// }
|
|
|
|
TEST(SurvTest, Altitude) {
|
|
// std::string squawk = "0356"; // 示例应答代码
|
|
// try {
|
|
// std::string encoded = encode_squawk(squawk);
|
|
// std::cout << ::squawk(encoded).value() << std::endl;
|
|
// std::cout << "Encoded 13-bit squawk: " << encoded << std::endl; // 输出编码后的13位二进制字符串
|
|
// } catch (const std::invalid_argument& e) {
|
|
// std::cerr << "Error: " << e.what() << std::endl; // 输出错误信息
|
|
// }
|
|
|
|
// auto it = Surveillance_Reply::Surveillance_Altitude_Reply::Builder("4CA7E8")
|
|
// .set_altitude(36000);
|
|
//
|
|
// auto alt = Surveillance_Reply::Surveillance_Altitude_Reply::Builder("4CA7E8")
|
|
// .set_altitude(36000)
|
|
|
|
// .set_flight_status(Flight_Status::no_alert_airborne)
|
|
// .set_utility_message(Utility_Message::no_information)
|
|
// .set_downlink_request(Downlink_Request::no_request)
|
|
// .build();
|
|
|
|
// std::cout << "1111111111111111111" << std::endl;
|
|
//
|
|
// std::cout << "t==" << bin2hex(alt.msg) << std::endl;
|
|
// std::cout << icao(alt.msg) << std::endl;
|
|
|
|
|
|
//
|
|
// std::cout << tell(alt.msg) << std::endl;
|
|
//
|
|
// auto identity = Surveillance_Reply::Surveillance_Identity_Reply::Builder("4CA7E8")
|
|
// .set_flight_status(Flight_Status::no_alert_airborne)
|
|
// .set_utility_message(Utility_Message::no_information)
|
|
// .set_downlink_request(Downlink_Request::no_request)
|
|
// .set_Identity("0356")
|
|
// .build();
|
|
//
|
|
// std::cout << tell(identity.msg) << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
// AP
|
|
TEST(SurvTest, ICAO) {
|
|
// 解析icao
|
|
std::string msg = hex2bin("A0001838CA380031440000F24177");
|
|
std::string crc = std::bitset<24>(::crc(msg, true)).to_string();
|
|
std::string icao = Psc::xorHex(crc, hex2bin("F24177"));
|
|
EXPECT_STREQ("CE2CA7", bin2hex(crc).c_str());
|
|
EXPECT_STREQ("3C6DD0", bin2hex(icao).c_str());
|
|
EXPECT_STREQ("3C6DD0", ::decode_icao(msg).c_str());
|
|
|
|
|
|
// 生成后面24位
|
|
std::string last24 = xorBin(crc, icao);
|
|
EXPECT_STREQ("F24177", bin2hex(last24).c_str());
|
|
|
|
}
|
|
#endif
|
|
#endif |