// 定义GPS数据的结构体
struct GPSData {
double latitude; // 纬度
double longitude; // 经度
double altitude; // 海拔高度
double timestamp; // 时间戳,用于记录接收信号的时间
double speed; // 速度
double heading; // 方向,表示运动方向的角度
double hdop; // 水平精度因子 (Horizontal Dilution of Precision)
double vdop; // 垂直精度因子 (Vertical Dilution of Precision)
int satellite_count; // 可见卫星的数量
};
// GPS设备类,用于模拟或记录GPS的操作
class GPSDevice {
public:
// 构造函数
GPSDevice() : latitude(0.0), longitude(0.0), altitude(0.0), timestamp(0.0), speed(0.0), heading(0.0), hdop(0.0), vdop(0.0), satellite_count(0) {}
// 更新GPS数据
void updateGPSData(double lat, double lon, double alt, double time, double spd, double head, double h_dp, double v_dp, int sat_count) {
data.latitude = lat;
data.longitude = lon;
data.altitude = alt;
data.timestamp = time;
data.speed = spd;
data.heading = head;
data.hdop = h_dp;
data.vdop = v_dp;
data.satellite_count = sat_count;
}
// 获取当前GPS数据
GPSData getGPSData() {
return data;
}
// 打印GPS数据
void printGPSData() {
std::cout << "Latitude: " << data.latitude << "\n";
std::cout << "Longitude: " << data.longitude << "\n";
std::cout << "Altitude: " << data.altitude << " meters\n";
std::cout << "Timestamp: " << data.timestamp << " seconds\n";
std::cout << "Speed: " << data.speed << " m/s\n";
std::cout << "Heading: " << data.heading << " degrees\n";
std::cout << "HDOP: " << data.hdop << "\n";
std::cout << "VDOP: " << data.vdop << "\n";
std::cout << "Satellite Count: " << data.satellite_count << "\n";
}
private:
GPSData data; // GPS数据
};