📄 rtcmtoasciiconvertor.c
字号:
/***************************************************************************
** **
** RTCM2ASC.C **
** **
**----------------------------------------------------------------------- **
** **
** Copyright (c) 2000 by Mikkel Jensen **
** Danish GPS Center **
** Aalborg University **
** Niels Jernes Vej 12 **
** DK-9920 Aalborg East **
** Denmark **
** email: mikkel@kom.auc.dk **
** **
** Permission is granted to copy and distribute this file in modified **
** or unmodified form, for noncommercial use, provided (a) this copyright **
** notice is preserved, (b) no attempt is made to restrict redistribution **
** of this file, and (c) this file is not distributed as part of any **
** collection whose redistribution is restricted by a compilation **
** copyright. **
** **
** This software is distributed as it is in the hope that it will be **
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE **
** **
**------------------------------------------------------------------------**
** **
** history: **
** rev date author comment **
** **
** 1.0 001220 MJ First Release, compiled with Visual C++ 6 **
** **
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <conio.h>
int bitparity[6];
int bitword[24];
char rawbuf[255];
char ch;
int k;
signed char d;
int l;
int d29star = 0;
int d30star = 1;
int bool_cslip = 0;
int bool_dprc = 0;
int bool_drrc = 0;
int bool_factor = 0;
int bool_freq = 0;
int bool_gnsstime = 0;
int bool_gpsglo = 0;
int bool_health = 0;
int bool_iod = 0;
int bool_length = 0;
int bool_mpe = 0;
int bool_msg = 0;
int bool_mtype = 0;
int bool_multi = 0;
int bool_pcind = 0;
int bool_phase = 0;
int bool_pr = 0;
int bool_prc = 0;
int bool_pre = 0;
int bool_prn = 0;
int bool_qual = 0;
int bool_refid = 0;
int bool_rrc = 0;
int bool_seqno = 0;
int bool_smooth = 0;
int bool_udre = 0;
int bool_xyz = 0;
int bool_zcount = 0;
int count;
div_t div_result;
FILE *rtcmbin;
FILE *mtype1, *mtype2, *mtype3, *mtype6, *mtype16, *mtype18, *mtype19, *seqno;
/*****************************************************************************
* BITPOINT *
* *
* This small function accepts a byte "bt" and an integer "bp" as its input *
* variables and returns the value of bit number "bp" in "bt" as an integer *
* either 0 or 1 *
*****************************************************************************/
int bitpoint(char bt, int bp){
return (bt >> bp) & 0x01;
}
/*****************************************************************************
* LOADWORD *
* *
* LOADWORD takes five bytes ch1-ch5 as its input variables. From these it *
* generates the corresponding GPS word taking into account both parity and *
* the Least Significant Bit First Rule. It uses BITPOINT to perform the *
* byte roll part. The result is written to the Bitword variable and the *
* has no return value *
*****************************************************************************/
void loadword(char ch1, char ch2, char ch3, char ch4, char ch5){
int cnt;
if (d30star == 0){
for (cnt = 0; cnt < 6; cnt++){
bitword[cnt] = bitpoint(ch1, cnt);
}
for (cnt = 0; cnt < 6; cnt++){
bitword[cnt + 6] = bitpoint(ch2, cnt);
}
for (cnt = 0; cnt < 6; cnt++){
bitword[cnt + 12] = bitpoint(ch3, cnt);
}
for (cnt = 0; cnt < 6; cnt++){
bitword[cnt + 18] = bitpoint(ch4, cnt);
}
}
else {
for (cnt = 0; cnt < 6; cnt++){
bitword[cnt] = 1 - bitpoint(ch1, cnt);
}
for (cnt = 0; cnt < 6; cnt++){
bitword[cnt + 6] = 1 - bitpoint(ch2, cnt);
}
for (cnt = 0; cnt < 6; cnt++){
bitword[cnt + 12] = 1 - bitpoint(ch3, cnt);
}
for (cnt = 0; cnt < 6; cnt++){
bitword[cnt + 18] = 1 - bitpoint(ch4, cnt);
}
}
for (cnt = 0; cnt < 6; cnt++){
bitparity[cnt] = bitpoint(ch5, cnt);
}
d29star = bitparity[4];
d30star = bitparity[5];
}
/*****************************************************************************
* READMESSAGE1 *
* *
* This function reads and decodes type 1 message and writes the result to a *
* text file. The input to the function is the length of the message in *
* bytes. LOADWORD is used to read the GPS words. There is no return value *
*****************************************************************************/
void readmessage1(int msglen){
int type1packet[40];
int m;
int n = 10;
int o;
int q = 0;
int p = 0;
unsigned char scale_factor = 0;
unsigned char udre = 0;
unsigned char sat_id = 0;
signed short prc = 0;
signed char rrc = 0;
unsigned char iod = 0;
int j;
double sfprc;
double sfrrc;
for (m = 0; m < msglen; m++){
loadword(rawbuf[n],rawbuf[n+1],rawbuf[n+2],rawbuf[n+3],rawbuf[n+4]);
n = n + 5;
p = 0;
for (o = 0; o < 3; o++){
for (j = 0; j < 8; j++){
type1packet[q] = bitword[p];
q++;
p++;
}
if (q == 40){ // packet done, write to file
sat_id = 0;
prc = 0;
rrc = 0;
iod = 0;
scale_factor = type1packet[0];
udre = type1packet[1]*2 + type1packet[2];
for (j = 0; j < 5; j++){
sat_id = sat_id | (type1packet[7 - j] << j);
}
for (j = 0; j < 16; j++){
prc = prc | (type1packet[23 - j] << j);
}
for (j = 0; j < 8; j++){
rrc = rrc | (type1packet[31 - j] << j);
}
for (j = 0; j < 8; j++){
iod = iod | (type1packet[39 - j] << j);
}
if (scale_factor == 0){
sfprc = 0.02;
sfrrc = 0.002;
}
else {
sfprc = 0.32;
sfrrc = 0.032;
}
if (sat_id == 0){
sat_id = 32;
}
if (bool_factor){
fprintf(mtype1,"%d ",scale_factor);
}
if (bool_udre){
fprintf(mtype1,"%d ",udre);
}
if (bool_prn){
fprintf(mtype1,"%2.0f ",(double)sat_id);
}
if (bool_prc){
fprintf(mtype1,"%9.2f ",prc*sfprc);
}
if (bool_rrc){
fprintf(mtype1,"%6.3f ",rrc*sfrrc);
}
if (bool_iod){
fprintf(mtype1,"%3.0f ",(double)iod);
}
//fprintf(mtype1,"\t%d\t%d\t%d\t%d\t%d\t%d",scale_factor,udre,sat_id,prc,rrc,iod);
q = 0;
}
}
}
fprintf(mtype1,"\n");
}
/*****************************************************************************
* READMESSAGE2 *
* *
* This function reads and decodes type 2 message and writes the result to a *
* text file. The input to the function is the length of the message in *
* bytes. LOADWORD is used to read the GPS words. There is no return value *
*****************************************************************************/
void readmessage2(int msglen){
int type2packet[40];
int m;
int n = 10;
int o;
int q = 0;
int p = 0;
unsigned char scale_factor = 0;
unsigned char udre = 0;
unsigned char sat_id = 0;
signed short dprc = 0;
signed char drrc = 0;
unsigned char iod = 0;
int j;
double sfdprc;
double sfdrrc;
for (m = 0; m < msglen; m++){
loadword(rawbuf[n],rawbuf[n+1],rawbuf[n+2],rawbuf[n+3],rawbuf[n+4]);
n = n + 5;
p = 0;
for (o = 0; o < 3; o++){
for (j = 0; j < 8; j++){
type2packet[q] = bitword[p];
q++;
p++;
}
if (q == 40){ // packet done, write to file
sat_id = 0;
dprc = 0;
drrc = 0;
iod = 0;
scale_factor = type2packet[0];
udre = type2packet[1]*2 + type2packet[2];
for (j = 0; j < 5; j++){
sat_id = sat_id | (type2packet[7 - j] << j);
}
for (j = 0; j < 16; j++){
dprc = dprc | (type2packet[23 - j] << j);
}
for (j = 0; j < 8; j++){
drrc = drrc | (type2packet[31 - j] << j);
}
for (j = 0; j < 8; j++){
iod = iod | (type2packet[39 - j] << j);
}
if (scale_factor == 0){
sfdprc = 0.02;
sfdrrc = 0.002;
}
else {
sfdprc = 0.32;
sfdrrc = 0.032;
}
if (sat_id == 0){
sat_id = 32;
}
if (bool_factor){
fprintf(mtype2,"%d ",scale_factor);
}
if (bool_udre){
fprintf(mtype2,"%d ",udre);
}
if (bool_prn){
fprintf(mtype2,"%2.0f ",(double)sat_id);
}
if (bool_dprc){
fprintf(mtype2,"%9.2f ",dprc*sfdprc);
}
if (bool_drrc){
fprintf(mtype2,"%6.3f ",drrc*sfdrrc);
}
if (bool_iod){
fprintf(mtype2,"%3.0f ",(double)iod);
}
q = 0;
}
}
}
fprintf(mtype2,"\n");
}
/*****************************************************************************
* READMESSAGE3 *
* *
* This function reads and decodes type 3 message and writes the result to a *
* text file. The input to the function is the length of the message in *
* bytes. LOADWORD is used to read the GPS words. There is no return value *
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -