GNSS单点定位与测速4:基于二进制文件的单点定位与测速主函数
本程序适用于导航工程专业本科生课程作业:单点定位与测速。
本节为主函数。
程序用到的原始观测文件和可直接执行的代码详见百度云链接:https://pan.baidu.com/s/1KljX438WgyVZPR51y9goyA?pwd=0000
基于二进制文件的单点定位与测速主函数
功能:如题。
#include "satpos.h"
int main()
{
/*文件读取并生成报表*/
clock_t tstart = clock(), et;
FILE* fp;
breport epoch[3000];//消息报告
int epochnum = 0;//消息数量/历元索引
//unsigned char str[100];
unsigned char fullodata[MAXSIZE];//消息内容存储结构体
const char filepath[50] = "20220927OBS+NAV+PSRPOS+IONUTC.dat";
if ((fp = fopen(filepath, "rb")) == NULL)
{
printf("Can not open file\n"); return 0;
}
epochnum = binaryfileread(epoch, fullodata, fp);//读取文件
fclose(fp);
printf("文件%s中共有%d组卫星文件\n", filepath, epochnum);
/*冷启动初始化星历结构体*/
eph_t eph[36] = {};//初始化GPS星历结构体
for (int e = 0; e < epochnum; e++) {
//星历文件
if (epoch[e].ID == 7) {
unsigned long prn = getsat(eph, fullodata, epoch[e]);
if (prn == -1) continue;
eph[prn].statu = EPHYES;
}
}
/*初始化电离层延迟改正参数*/
double ion[8];
for (int e = 0; e < epochnum; e++) {
if (epoch[e].ID == 8) {
int start = epoch[e].start, end = epoch[e].end;
getion(fullodata, ion, epoch[e],"OEM7");
//printf("%d. %.4e %.4e %.4e %.4e\n",e+1,bit2double(fullodata+start+24+32),bit2double(fullodata+start+24+40),bit2double(fullodata+start+24+48),bit2double(fullodata+start+24+56));
}
}
/*逐历元读取伪距观测值并计算位置*/
//GPSOBS R={};
for (int e = 0; e < epochnum; e++) {
//观测值文件
if (epoch[e].ID == 43 || epoch[e].ID == 631) {
GPSOBS R = {};
getobs(R, fullodata, epoch[e]);
//计算单点定位
SPPpos(R, eph, ion);
}
if (epoch[e].ID == 47) {
int start = epoch[e].start, end = epoch[e].end;
printf("%d sol statue:%d pos type%d %lf %lf %lf %lf satsnum%x\n", e + 1, bit2ulong(fullodata + start + 28), bit2ulong(fullodata + start + 28 + 4), bit2double(fullodata + start + 28 + 8), bit2double(fullodata + start + 28 + 16), bit2double(fullodata + start + 28 + 24), bit2float(fullodata + start + 28 + 32), fullodata[start + 28 + 65]);
}
}
et = clock();
printf("CPUtime %lf sec\n", (et - tstart) / 1000.0);
return 0;
}