2016-04-07 02:00:54 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/*
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * This code is taken largely from on1arf's GMSK code. Original copyright below:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								* Copyright (C) 2011 by Kristoff Bonne, ON1ARF
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								*
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								* This program is free software; you can redistribute it and/or modify
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								* it under the terms of the GNU General Public License as published by
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								* the Free Software Foundation; version 2 of the License.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								*
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								* This program is distributed 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. See the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								* GNU General Public License for more details.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "fcs.h"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "descramble.h"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "dstar_header.h"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void dstar_header_decode(int radioheaderbuffer[660]) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									int radioheaderbuffer2[660];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									unsigned char radioheader[41];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									int octetcount, bitcount, loop;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									unsigned char bit2octet[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									unsigned int FCSinheader;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									unsigned int FCScalculated;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									int len;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									scramble(radioheaderbuffer, radioheaderbuffer2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									deinterleave(radioheaderbuffer2, radioheaderbuffer);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									len = FECdecoder(radioheaderbuffer, radioheaderbuffer2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									memset(radioheader, 0, 41);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// note we receive 330 bits, but we only use 328 of them (41 octets)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// bits 329 and 330 are unused
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									octetcount = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									bitcount = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									for (loop = 0; loop < 328; loop++) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										if (radioheaderbuffer2[loop]) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[octetcount] |= bit2octet[bitcount];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										bitcount++;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// increase octetcounter and reset bitcounter every 8 bits
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										if (bitcount >= 8) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											octetcount++;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											bitcount = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// print header
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-09 04:34:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									fprintf(stderr, "\nDSTAR HEADER: ");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									//fprintf(stderr, "FLAG1: %02X - FLAG2: %02X - FLAG3: %02X\n", radioheader[0],
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-07 02:00:54 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									//		radioheader[1], radioheader[2]);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-09 04:34:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									fprintf(stderr, "RPT 2: %c%c%c%c%c%c%c%c ", radioheader[3], radioheader[4],
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-07 02:00:54 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[5], radioheader[6], radioheader[7], radioheader[8],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[9], radioheader[10]);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-09 04:34:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									fprintf(stderr, "RPT 1: %c%c%c%c%c%c%c%c ", radioheader[11], radioheader[12],
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-07 02:00:54 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[13], radioheader[14], radioheader[15], radioheader[16],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[17], radioheader[18]);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-09 04:34:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									fprintf(stderr, "YOUR: %c%c%c%c%c%c%c%c ", radioheader[19], radioheader[20],
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-07 02:00:54 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[21], radioheader[22], radioheader[23], radioheader[24],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[25], radioheader[26]);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-09 04:34:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									fprintf(stderr, "MY: %c%c%c%c%c%c%c%c/%c%c%c%c\n", radioheader[27],
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-07 02:00:54 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[28], radioheader[29], radioheader[30], radioheader[31],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[32], radioheader[33], radioheader[34], radioheader[35],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											radioheader[36], radioheader[37], radioheader[38]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									//FCSinheader = ((radioheader[39] << 8) | radioheader[40]) & 0xFFFF;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									//FCScalculated = calc_fcs((unsigned char*) radioheader, 39);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-09 04:34:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									//fprintf(stderr, "Check sum = %04X ", FCSinheader);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-07 02:00:54 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									//if (FCSinheader == FCScalculated) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-09 04:34:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									//	fprintf(stderr, "(OK)\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-07 02:00:54 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									//} else {
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-09 04:34:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									//	fprintf(stderr, "(NOT OK- Calculated FCS = %04X)\n", FCScalculated);
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-07 02:00:54 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									//}; // end else - if
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |