/* decode GLONASS navigation data ---------------------------------------------- * decode GLONASS navigation data and extract ephemeris * args : sdrnav_t *nav I/O sdr navigation struct * return : int string number (1-5) *-----------------------------------------------------------------------------*/ extern int decode_g1(sdrnav_t *nav) { int i,id=0,bits1[170],bits2[85]; uint8_t bin[11]; /* 85/8 word bits */ /* remove meandr from data */ for (i=0;i<170;i++) { if (i%2==0) bits1[i]= nav->polarity*nav->fbits[i]; else bits1[i]=-nav->polarity*nav->fbits[i]; } for (i=0;i<84;i++) { bits2[i+1]=bits1[2*i]*bits1[2*(i+1)]; } bits2[0] = -1; bits2byte(bits2,85,11,0,bin); /* decode navigation data */ id=decode_flame_g1(bin,&nav->sdreph); if (id<1||id>15) SDRPRINTF("error: GLONASS word number sfn=%d\n",id); return id; }
void print_frame(int len) { int i; int byte; //int err = 0; printf("\n"); for (i = 0; i < len; i++) { byte = bits2byte(bitframe+10*i+2); frame[i] = byte; //printf("%02X ", byte); } if (option_raw) { for (i = 0; i < len; i++) { fprintf(stdout, "%02x ", frame[i]); } fprintf(stdout, "\n"); } //else { if ((frame[0] == 0x01) && (frame[1] == 0x02)) { // GPS Data Packet print_gps(0x00); // packet offset in frame fprintf(stdout, "\n"); } } }
/* check Galileo E1B CRC ------------------------------------------------------- * compute and check CRC of Galileo E1B page data * args : uint8_t *data1 I E1B page part 1 (15 bytes (120 bits)) * uint8_t *data2 I E1B page part 2 (15 bytes (120 bits)) * return : int 1:okay 0: wrong parity *-----------------------------------------------------------------------------*/ extern int checkcrc_e1b(uint8_t *data1, uint8_t *data2) { uint8_t crcbins[25]={0}; int i,j,crcbits[196],crc,crcmsg; /* page part 1 */ for (i=0;i<15;i++) { for (j=0;j<8;j++) { if (8*i+j==114) break; crcbits[8*i+j]=-2*(((data1[i]<<j)&0x80)>>7)+1; } } /* page part 2 */ for (i=0;i<11;i++) { for (j=0;j<8;j++) { if (8*i+j==82) break; crcbits[114+8*i+j]=-2*(((data2[i]<<j)&0x80)>>7)+1; } } bits2byte(crcbits,196,25,1,crcbins); /* right alignment for crc */ crc=crc24q(crcbins,25); /* compute crc24 */ crcmsg=getbitu(data2,82,24); /* crc in message */ /* crc matching */ if (crc==crcmsg) return 0; else return -1; }
/* decode GPS/QZS L1CA navigation data ----------------------------------------- * decode GPS/QZS L1CA navigation data and extract ephemeris * args : sdrnav_t *nav I/O sdr navigation struct * return : int subframe ID (1-5) *-----------------------------------------------------------------------------*/ extern int decode_l1ca(sdrnav_t *nav) { int i,j,id=0; uint8_t bin[38]; /* bit inversion */ for (i=0;i<10;i++) { if (nav->fbitsdec[i*30+1]==-1) { for (j=2;j<26;j++) nav->fbitsdec[i*30+j]*=-1; } } bits2byte(&nav->fbitsdec[nav->addflen],nav->flen,38,0,bin); /* decode navigation data */ id=decode_frame_l1ca(bin,&nav->sdreph); if (id<1||id>5) SDRPRINTF("error: GPS subframe number sfn=%d\n",id); return id; }
int main(int argc, char *argv[]) { FILE *fp; char bitbuf[8]; int bit_count = 0, byte_count = FRAMESTART, header_found = 0, byte, i; int bit, len; ++argv; while ((*argv) && (!wavloaded)) { if ( (strcmp(*argv, "-v") == 0) || (strcmp(*argv, "--verbose") == 0) ) { option_verbose = 1; } else if ( (strcmp(*argv, "-r") == 0) || (strcmp(*argv, "--raw") == 0) ) { option_raw = 1; } else { if ( !(fp = fopen(*argv, "rb")) ) { fprintf(stderr, "%s konnte nicht geoeffnet werden\n", *argv); return -1; } else wavloaded = 1; } ++argv; } if (!wavloaded) { fprintf(stderr, "rs41sg [options] <rs41_audio.wav>\n"); fprintf(stderr, " options:\n"); fprintf(stderr, " -v, --verbose\n"); fprintf(stderr, " -r, --raw\n"); return -1; } i = read_wav_header(fp); if (i) { fclose(fp); return -1; } while (!read_bits_fsk(fp, &bit, &len)) { if (len == 0) { // reset_frame(); if (byte_count > FRAME_LEN-20) print_frame(byte_count); bit_count = 0; byte_count = FRAMESTART; header_found = 0; inc_bufpos(); buf[bufpos] = 'x'; continue; // ... } for (i = 0; i < len; i++) { inc_bufpos(); buf[bufpos] = 0x30 + bit; // Ascii if (!header_found) { if (compare() >= HEADLEN) header_found = 1; } else { bitbuf[bit_count] = bit; bit_count++; if (bit_count == 8) { bit_count = 0; byte = bits2byte(bitbuf); frame[byte_count] = byte; byte_count++; if (byte_count == FRAME_LEN) { byte_count = FRAMESTART; header_found = 0; print_frame(FRAME_LEN); } } } } } fclose(fp); return 0; }