1 Star 0 Fork 1

gnss2020/GNSS_rtk

forked from Anna Catherine/GNSS 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rtcm.c 7.36 KB
一键复制 编辑 原始数据 按行查看 历史
Anna Catherine 提交于 2024-10-12 04:56 . SPP选星算法VS2022工程文件
#include "rtcm.h"
/* constants -----------------------------------------------------------------*/
#define RTCM3PREAMB 0xD3 /* rtcm ver.3 frame preamble */
/* initialize rtcm control -----------------------------------------------------
* initialize rtcm control struct and reallocate memory for observation and
* ephemeris buffer in rtcm control struct
* args : rtcm_t *raw IO rtcm control struct
* return : status (1:ok,0:memory allocation error)
*-----------------------------------------------------------------------------*/
extern int init_rtcm(rtcm_t *rtcm)
{
gtime_t time0={0};
obsd_t data0={{0}};
eph_t eph0 ={0,-1,-1};
geph_t geph0={0,-1};
ssr_t ssr0={{{0}}};
int i,j;
trace(3,"init_rtcm:\n");
rtcm->staid=rtcm->stah=rtcm->seqno=rtcm->outtype=0;
rtcm->time=rtcm->time_s=time0;
rtcm->sta.name[0]=rtcm->sta.marker[0]='\0';
rtcm->sta.antdes[0]=rtcm->sta.antsno[0]='\0';
rtcm->sta.rectype[0]=rtcm->sta.recver[0]=rtcm->sta.recsno[0]='\0';
rtcm->sta.antsetup=rtcm->sta.itrf=rtcm->sta.deltype=0;
for (i=0;i<3;i++) {
rtcm->sta.pos[i]=rtcm->sta.del[i]=0.0;
}
rtcm->sta.hgt=0.0;
rtcm->dgps=NULL;
for (i=0;i<MAXSAT;i++) {
rtcm->ssr[i]=ssr0;
}
rtcm->msg[0]=rtcm->msgtype[0]=rtcm->opt[0]='\0';
for (i=0;i<6;i++) rtcm->msmtype[i][0]='\0';
rtcm->obsflag=rtcm->ephsat=0;
for (i=0;i<MAXSAT;i++) for (j=0;j<NFREQ+NEXOBS;j++) {
rtcm->cp[i][j]=0.0;
rtcm->lock[i][j]=rtcm->loss[i][j]=0;
rtcm->lltime[i][j]=time0;
}
rtcm->nbyte=rtcm->nbit=rtcm->len=0;
rtcm->word=0;
for (i=0;i<100;i++) rtcm->nmsg2[i]=0;
for (i=0;i<400;i++) rtcm->nmsg3[i]=0;
rtcm->obs.data=NULL;
rtcm->nav.eph =NULL;
rtcm->nav.geph=NULL;
/* reallocate memory for observation and ephemris buffer */
if (!(rtcm->obs.data=(obsd_t *)malloc(sizeof(obsd_t)*MAXOBS))||
!(rtcm->nav.eph =(eph_t *)malloc(sizeof(eph_t )*MAXSAT))||
!(rtcm->nav.geph=(geph_t *)malloc(sizeof(geph_t)*MAXPRNGLO))) {
free_rtcm(rtcm);
return 0;
}
rtcm->obs.n=0;
rtcm->nav.n=MAXSAT;
rtcm->nav.ng=MAXPRNGLO;
for (i=0;i<MAXOBS ;i++) rtcm->obs.data[i]=data0;
for (i=0;i<MAXSAT ;i++) rtcm->nav.eph [i]=eph0;
for (i=0;i<MAXPRNGLO;i++) rtcm->nav.geph[i]=geph0;
return 1;
}
/* free rtcm control ----------------------------------------------------------
* free observation and ephemris buffer in rtcm control struct
* args : rtcm_t *raw IO rtcm control struct
* return : none
*-----------------------------------------------------------------------------*/
extern void free_rtcm(rtcm_t *rtcm)
{
trace(3,"free_rtcm:\n");
/* free memory for observation and ephemeris buffer */
free(rtcm->obs.data); rtcm->obs.data=NULL; rtcm->obs.n=0;
free(rtcm->nav.eph ); rtcm->nav.eph =NULL; rtcm->nav.n=0;
free(rtcm->nav.geph); rtcm->nav.geph=NULL; rtcm->nav.ng=0;
}
/* input rtcm 3 message from stream --------------------------------------------
* fetch next rtcm 3 message and input a message from byte stream
* args : rtcm_t *rtcm IO rtcm control struct
* unsigned char data I stream data (1 byte)
* return : status (-1: error message, 0: no message, 1: input observation data,
* 2: input ephemeris, 5: input station pos/ant parameters,
* 10: input ssr messages)
* notes : before firstly calling the function, time in rtcm control struct has
* to be set to the approximate time within 1/2 week in order to resolve
* ambiguity of time in rtcm messages.
*
* to specify input options, set rtcm->opt to the following option
* strings separated by spaces.
*
* -EPHALL : input all ephemerides
* -STA=nnn : input only message with STAID=nnn
* -GLss : select signal ss for GPS MSM (ss=1C,1P,...)
* -RLss : select signal ss for GLO MSM (ss=1C,1P,...)
* -ELss : select signal ss for GAL MSM (ss=1C,1B,...)
* -JLss : select signal ss for QZS MSM (ss=1C,2C,...)
* -CLss : select signal ss for BDS MSM (ss=2I,7I,...)
*
* supported RTCM 3 messages
* (ref [2][3][4][5][6][7][8][9][10][11][12][13][14][15])
*
* TYPE GPS GLOASS GALILEO QZSS BEIDOU SBAS
* ----------------------------------------------------------------------
* OBS C-L1 : 1001~ 1009~ - - - -
* F-L1 : 1002 1010 - - - -
* C-L12 : 1003~ 1011~ - - - -
* F-L12 : 1004 1012 - - - -
*
* NAV : 1019 1020 1045* 1044* 1047* -
* - - 1046* - - -
* MSM 7 : 1077 1087 1097 1117* 1127* 1107*
* ANT INFO : 1005 1006 1007 1008 1033
* ----------------------------------------------------------------------
* (* draft, ~ only encode)
*
* for MSM observation data with multiple signals for a frequency,
* a signal is selected according to internal priority. to select
* a specified signal, use the input options.
*
* rtcm3 message format:
* +----------+--------+-----------+--------------------+----------+
* | preamble | 000000 | length | data message | parity |
* +----------+--------+-----------+--------------------+----------+
* |<-- 8 --->|<- 6 -->|<-- 10 --->|<--- length x 8 --->|<-- 24 -->|
*
*----------------------------------------------------------------------------*/
extern int input_rtcm3(rtcm_t* rtcm, unsigned char data)
{
/* synchronize frame */
if (rtcm->nbyte == 0) {
if (data != RTCM3PREAMB) {//识别文件头D3
return 0;
}
rtcm->buff[rtcm->nbyte++] = data;
return 0;
}
rtcm->buff[rtcm->nbyte++] = data;
if (rtcm->nbyte == 3) {/* 无奇偶校验位长度 */
rtcm->len = getbitu(rtcm->buff, 14, 10) + 3;
}
//字节数目小于len + 3,则退出函数
if (rtcm->nbyte < 3 || rtcm->nbyte < rtcm->len + 3) { //读取一帧数据至buff
return 0;
}
rtcm->nbyte = 0; //一帧数据字节数清0,为下一帧数据做准备
if (rtk_crc24q(rtcm->buff, rtcm->len) != getbitu(rtcm->buff, rtcm->len * 8, 24)) { /* 检查CRC */
return 0;
}
/* decode rtcm3 message */
return decode_rtcm3(rtcm);
}
/* input rtcm 3 message from file ----------------------------------------------
* fetch next rtcm 3 message and input a messsage from file
* args : rtcm_t *rtcm IO rtcm control struct
* FILE *fp I file pointer
* return : status (-2: end of file, -1...10: same as above)
* notes : same as above
*-----------------------------------------------------------------------------*/
extern int input_rtcm3f(rtcm_t* rtcm, FILE* fp) {
int data = 0, ret;
rtcm->sys = 0;
rtcm->timeflag = 0;
//int posflag = rtcm->time.time = 0; //posflag不等于rtcm->time.time 就会跳出RTCM解析
for (int i = 0; i < 1024; i++) {/* return at every 4096 bytes */
if ((data = fgetc(fp)) == EOF) {
return -2;
}
if ((ret = input_rtcm3(rtcm, (unsigned char)data))) {
return ret;
}
}
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/gnss2020/gnssCollection.git
git@gitee.com:gnss2020/gnssCollection.git
gnss2020
gnssCollection
GNSS_rtk
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385