⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtcmtoasciiconvertor.c

📁 该程序是一个将RTCM格式转化为ASCII格式的C程序
💻 C
📖 第 1 页 / 共 3 页
字号:
	int length = 0;
	int health = 0;

	FILE *header;

	loadword(rawbuf[0],rawbuf[1],rawbuf[2],rawbuf[3],rawbuf[4]);
	
	// decode data in first word

	for (j = 0; j < 8; j++){
		preamble = preamble | (bitword[7 - j] << j);
	}
	for (j = 0; j < 6; j++){
		message_type = message_type + (bitword[13 - j] << j);
	}
	for (j = 0; j < 10; j++){
		station_id = station_id | (bitword[23 - j] << j);
	}

	loadword(rawbuf[5],rawbuf[6],rawbuf[7],rawbuf[8],rawbuf[9]);
	
	// decode data in second word

	for (j = 0; j < 13; j++){
		mod_zcount = mod_zcount | (bitword[12 - j] << j);
	}
	for (j = 0; j < 3; j++){
		seq_no = seq_no | (bitword[15 - j] << j);
	}
	for (j = 0; j < 5; j++){
		length = length | (bitword[20 - j] << j);
	}
	for (j = 0; j < 3; j++){
		health = health | (bitword[23 - j] << j);
	}

	// This is defined in the RTCM standard

	if (message_type == 0){
		message_type = 64;
	}
	
	// Added to help in debugging the output
	// Often some messages are lost in transmission

	fprintf(seqno,"%d\n",seq_no);
	
	// Set the correct filepointer so output is directed
	// to the correct place. Default is screen to flag an
	// error or warning
	
	switch(message_type){
		case 1: header = mtype1; break;
		case 2: header = mtype2; break;
		case 3: header = mtype3; break;
		case 6: header = mtype6; break;
		case 16: header = mtype16; break;
		case 18: header = mtype18; break;
		case 19: header = mtype19; break;
		default: header = stdout;
	}
	
	// Write header information in files
	
	if (bool_pre){
		fprintf(header,"%d ",preamble);
	}

	if (bool_mtype){
		fprintf(header,"%2.0f ",message_type);
	}
	
	if (bool_refid){
		fprintf(header,"%4.0f ",station_id);
	}

	if (bool_zcount){
		fprintf(header,"%6.1f ",mod_zcount*0.6);
	}

	if (bool_seqno){
		fprintf(header,"%d ",seq_no);
	}

	if (bool_length){
		fprintf(header,"%2.0f ",length);
	}

	if (bool_health){
		fprintf(header,"%d ",health);
	}
	
	// Call the correct function to decode the rest of the message.

	switch(message_type){
		case 1:	readmessage1(length); break;
		case 2: readmessage2(length); break;
		case 3: readmessage3(length); break;
		case 6: break;
		case 16: readmessage16(length); break;
		case 18: readmessage18(length); break;
		case 19: readmessage19(length); break;
		default: printf("WARNING: (l.%d) Unsupported message type detected! (type %d)\n",l,message_type);
	}
	
}

/*****************************************************************************
 * MAIN                                                                      *
 *                                                                           *
 * MAIN reads the command line arguments to determine which part of the data *
 * the user wants as output. If no arguments are given the help screen is    *
 * displayed. The input and output files are opened/created and the input    *
 * file is read line by line by searching for the CrLf symbol. If the size   *
 * of the message is not a multiple of five an error is flagged otherwise    *
 * the message is decode using the READHEADER function                       *
 *****************************************************************************/
 
void main(int argc,char *argv[]){
	
	// decode input arguments
	
	for (count = 0; count < argc; count++){
		if (strcmp(argv[count],"-cslip") == 0){
			bool_cslip = 1;
		}
		if (strcmp(argv[count],"-dprc") == 0){
			bool_dprc = 1;
		}
		if (strcmp(argv[count],"-drrc") == 0){
			bool_drrc = 1;
		}
		if (strcmp(argv[count],"-factor") == 0){
			bool_factor = 1;
		}
		if (strcmp(argv[count],"-freq") == 0){
			bool_freq = 1;
		}
		if (strcmp(argv[count],"-extime") == 0){
			bool_gnsstime = 1;
		}
		if (strcmp(argv[count],"-gpsglo") == 0){
			bool_gpsglo = 1;
		}
		if (strcmp(argv[count],"-health") == 0){
			bool_health = 1;
		}
		if (strcmp(argv[count],"-iod") == 0){
			bool_iod = 1;
		}
		if (strcmp(argv[count],"-length") == 0){
			bool_length = 1;
		}
		if (strcmp(argv[count],"-mpe") == 0){
			bool_mpe = 1;
		}
		if (strcmp(argv[count],"-msg") == 0){
			bool_msg = 1;
		}
		if (strcmp(argv[count],"-mtype") == 0){
			bool_mtype = 1;
		}
		if (strcmp(argv[count],"-multi") == 0){
			bool_multi = 1;
		}
		if (strcmp(argv[count],"-pca") == 0){
			bool_pcind = 1;
		}
		if (strcmp(argv[count],"-phase") == 0){
			bool_phase = 1;
		}
		if (strcmp(argv[count],"-pr") == 0){
			bool_pr = 1;
		}
		if (strcmp(argv[count],"-prc") == 0){
			bool_prc = 1;
		}
		if (strcmp(argv[count],"-pre") == 0){
			bool_pre = 1;
		}
		if (strcmp(argv[count],"-prn") == 0){
			bool_prn = 1;
		}
		if (strcmp(argv[count],"-dqual") == 0){
			bool_qual = 1;
		}
		if (strcmp(argv[count],"-refid") == 0){
			bool_refid = 1;
		}
		if (strcmp(argv[count],"-rrc") == 0){
			bool_rrc = 1;
		}
		if (strcmp(argv[count],"-seqno") == 0){
			bool_seqno = 1;
		}
		if (strcmp(argv[count],"-smooth") == 0){
			bool_smooth = 1;
		}
		if (strcmp(argv[count],"-udre") == 0){
			bool_udre = 1;
		}
		if (strcmp(argv[count],"-xyz") == 0){
			bool_xyz = 1;
		}
		if (strcmp(argv[count],"-zcount") == 0){
			bool_zcount = 1;
		}
		if (strcmp(argv[count],"-p00") == 0){
			d29star = 0;
			d30star = 0;
		}
		if (strcmp(argv[count],"-p01") == 0){
			d29star = 0;
			d30star = 1;
		}
		if (strcmp(argv[count],"-p10") == 0){
			d29star = 1;
			d30star = 0;
		}
		if (strcmp(argv[count],"-p11") == 0){
			d29star = 1;
			d30star = 1;
		}
		if (strcmp(argv[count],"-default") == 0){
			bool_dprc = 1;
			bool_drrc = 1;
			bool_prc = 1;
			bool_prn = 1;
			bool_rrc = 1;
			bool_xyz = 1;
			bool_zcount = 1;
			bool_msg = 1;
			bool_phase = 1;
			bool_pr = 1;
		}
	}
	
	// if no arguments are given then display help screen and terminate execution
	
	if  (!(bool_cslip || bool_dprc || bool_drrc || bool_factor || bool_freq || bool_gnsstime || bool_gpsglo || bool_health || bool_iod || bool_length || bool_mpe || bool_msg || bool_mtype || bool_multi || bool_pcind || bool_phase || bool_pr || bool_prc || bool_pre || bool_prn || bool_qual || bool_refid || bool_rrc || bool_seqno || bool_smooth || bool_udre || bool_xyz || bool_zcount)){
		printf("\nUSAGE: rtcm2asc.exe [-flags [-flags... ]]\n\n");
		
		printf("This program converts the binary RTCM messages to ASCII format.\n");
		printf("The program requires the RTCM file to be named \"rtcmout.bin\" and placed in the\n");
		printf("same folder as the .exe file\n\n");
		
		printf("ASCII text files named \"mtype1.txt\",\"mtype2.txt\" etc. are then generated by\n");
		printf("the program and can be easily loaded into eg. Matlab\n");
		printf("Currently only message types: 1,2,3,6,16,18 and 19 are supported\n\n");
		printf("The amount of data stored in the ASCII files are controlled by using\n");
		printf("command-line arguments:\n\n");
		
		printf("\"-cslip\":   Cumulative loss of continuity indicator [0 - 31]\n");
		printf("\"-dprc\":    Delta Pseudorange corrections [+-655.34 or +-10485.44 m]\n");
		printf("\"-drrc\":    Delta Range-Rate Correction [+-0.254 or +- 4.064 m/s]\n");
		printf("\"-dqual\":   Data quality indicator\n");
		printf("\"-extime\":  Extended GNSS time [0-599999 us]\n");
		printf("\"-factor\":  Scale factor bit [0|1]\n");
		printf("\"-freq\":    Frequency indicator [0-3] 0 = L1, 2 = L2\n");
		printf("\"-gpsglo\":  GPS/GLONASS indicator [0|1] 0 = GPS, 1 = GLONASS\n\n");

		printf("Press any key to continue...");

		getch();
		
		printf("\n\n\"-health\":  Health of the reference station [0-7]\n");
		printf("\"-iod\":     Issue-of-data of the satellites [0-256]\n");
		printf("\"-length\":  Number of words in message containing data\n");
		printf("\"-mpe\":     Multipath error [0-15]\n");
		printf("\"-msg\":     Message from reference station, max 90 characters long\n");
		printf("\"-mtype\":   Message type [1-64]\n");
		printf("\"-multi\":   Multi-message indicator [0|1]\n");
		printf("\"-pca\":     P-code or C/A-code indicator [0|1] 0 = C/A, 1 = P\n");
		printf("\"-phase\":   Uncorrected carrier phases [+-8,388,608 cycles]\n");
		printf("\"-pr\":      Uncorrected pseudoranges [0-85,899,345.90 m]\n");
		printf("\"-prc\":     Pseudorange corrections [+-655.34 or +-10,485.44 m]\n");
		printf("\"-pre\":     Preamble [102]\n");
		printf("\"-prn\":     Satellite ID [1-32]\n");
		printf("\"-pXY\":     Enter initial parity values for bits 29 and 30. X [0|1], Y [0|1]\n");
		printf("\"-refid\":   Reference station ID [0-1023]\n");
		printf("\"-rrc\":     Range-Rate Correction [+-0.254 or +-4.064 m/s]\n");
		printf("\"-seqno\":   Sequence number of the message [0-7]\n");
		printf("\"-smooth\":  Smoothing interval [0-3]\n");
		printf("\"-udre\":    User Differential Range Error [0-3]\n");
		printf("\"-xyz\":     ECEF position (XYZ) of the ref. station [0-21,474,836.47 m]\n");
		printf("\"-zcount\":  Modified z-count [0-3599.4 sec]\n\n");

		printf("\"-default\": Uses the most common of the above parameters\n");
		exit(0);
	}
	
	// else open input files for reading and writing
	
	if ((rtcmbin  = fopen("rtcmout.bin","rb")) == NULL){
      printf("ERROR opening input file\n" );
	  exit(1);
	}

	if ((mtype1  = fopen("mtype1.txt","wt")) == NULL){
      printf("ERROR opening output file 'mtype1.txt'\n" );
	  exit(1);
	}

	if ((mtype2  = fopen("mtype2.txt","wt")) == NULL){
      printf("ERROR opening output file 'mtype2.txt'\n" );
	  exit(1);
	}

	if ((mtype3  = fopen("mtype3.txt","wt")) == NULL){
      printf("ERROR opening output file 'mtype3.txt'\n" );
	  exit(1);
	}

	if ((mtype6  = fopen("mtype6.txt","wt")) == NULL){
      printf("ERROR opening output file 'mtype6.txt'\n" );
	  exit(1);
	}

	if ((mtype16  = fopen("mtype16.txt","wt")) == NULL){
      printf("ERROR opening output file 'mtype16.txt'\n" );
	  exit(1);
	}
	
	if ((mtype18  = fopen("mtype18.txt","wt")) == NULL){
      printf("ERROR opening output file 'mtype18.txt'\n" );
	  exit(1);
	}

	if ((mtype19  = fopen("mtype19.txt","wt")) == NULL){
      printf("ERROR opening output file 'mtype19.txt'\n" );
	  exit(1);
	}
	
	if ((seqno  = fopen("seqno.txt","wt")) == NULL){
      printf("ERROR opening output file 'seqno.txt'\n" );
	  exit(1);
	}

	// for each line in the input use readheader
	// to decode the contents

	l = 0;
	while (!feof(rtcmbin)){
		k = 0;
		d = 0;
		rawbuf[0] = '\0';
		while ((d == 0) && (k < 255)){
			ch = fgetc(rtcmbin);
			
			// other termination strings could be used here
			
			if (ch == 0x0D){
				if (0x0A == fgetc(rtcmbin)) {
					d = 1;
					l++;
				}
			}
			else {
				
				// if not termination string then read into buffer
				rawbuf[k] = ch;
				k++;
			}
		}
		rawbuf[k] = '\0';

		div_result = div(k,5);

		// check if message size is a multiple of five

		if (div_result.rem != 0){
			printf("ERROR: (l.%d) Input does not follow word boundaries!\n\n",l);
		}

		readheader();
	}

	// finish by closing all open files

	_fcloseall();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -