mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-14 09:47:30 -05:00
Rewrite and Simplify DSTAR Handling;
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
*
|
||||
* This code is taken largely from on1arf's GMSK code. Original copyright below:
|
||||
*
|
||||
*
|
||||
*
|
||||
* 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
|
||||
@@ -13,74 +13,70 @@
|
||||
* 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"
|
||||
#include "dsd.h"
|
||||
|
||||
void dstar_header_decode(dsd_state * state, int radioheaderbuffer[660]) {
|
||||
void dstar_header_decode(dsd_state * state, int radioheaderbuffer[660])
|
||||
{
|
||||
int radioheaderbuffer2[660];
|
||||
unsigned char radioheader[41];
|
||||
char radioheader[41];
|
||||
int octetcount, bitcount, loop;
|
||||
unsigned char bit2octet[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
|
||||
int len;
|
||||
UNUSED(len);
|
||||
|
||||
scramble(radioheaderbuffer, radioheaderbuffer2);
|
||||
deinterleave(radioheaderbuffer2, radioheaderbuffer);
|
||||
len = FECdecoder(radioheaderbuffer, radioheaderbuffer2);
|
||||
FECdecoder(radioheaderbuffer, radioheaderbuffer2);
|
||||
memset(radioheader, 0, 41);
|
||||
//memset(state->dstarradioheader, 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]) {
|
||||
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) {
|
||||
if (bitcount >= 8)
|
||||
{
|
||||
octetcount++;
|
||||
bitcount = 0;
|
||||
}
|
||||
}
|
||||
//state->dstarradioheader = radioheader;
|
||||
|
||||
for (short i = 0; i < 41; i++)
|
||||
{
|
||||
state->dstarradioheader[i] = radioheader[i];
|
||||
}
|
||||
char str1[9];
|
||||
char str2[9];
|
||||
char str3[9];
|
||||
char str4[13];
|
||||
|
||||
memcpy (str1, radioheader+3, 8);
|
||||
memcpy (str2, radioheader+11, 8);
|
||||
memcpy (str3, radioheader+19, 8);
|
||||
memcpy (str4, radioheader+27, 12);
|
||||
|
||||
// print header
|
||||
fprintf (stderr, "\nDSTAR HEADER: ");
|
||||
//fprintf (stderr, "FLAG1: %02X - FLAG2: %02X - FLAG3: %02X\n", radioheader[0],
|
||||
// radioheader[1], radioheader[2]);
|
||||
fprintf (stderr, "RPT 2: %c%c%c%c%c%c%c%c ", radioheader[3], radioheader[4],
|
||||
radioheader[5], radioheader[6], radioheader[7], radioheader[8],
|
||||
radioheader[9], radioheader[10]);
|
||||
fprintf (stderr, "RPT 1: %c%c%c%c%c%c%c%c ", radioheader[11], radioheader[12],
|
||||
radioheader[13], radioheader[14], radioheader[15], radioheader[16],
|
||||
radioheader[17], radioheader[18]);
|
||||
fprintf (stderr, "YOUR: %c%c%c%c%c%c%c%c ", radioheader[19], radioheader[20],
|
||||
radioheader[21], radioheader[22], radioheader[23], radioheader[24],
|
||||
radioheader[25], radioheader[26]);
|
||||
fprintf (stderr, "MY: %c%c%c%c%c%c%c%c/%c%c%c%c\n", radioheader[27],
|
||||
radioheader[28], radioheader[29], radioheader[30], radioheader[31],
|
||||
radioheader[32], radioheader[33], radioheader[34], radioheader[35],
|
||||
radioheader[36], radioheader[37], radioheader[38]);
|
||||
str1[8] = '\0';
|
||||
str2[8] = '\0';
|
||||
str3[8] = '\0';
|
||||
str4[12] = '\0';
|
||||
|
||||
//FCSinheader = ((radioheader[39] << 8) | radioheader[40]) & 0xFFFF;
|
||||
//FCScalculated = calc_fcs((unsigned char*) radioheader, 39);
|
||||
//fprintf (stderr, "Check sum = %04X ", FCSinheader);
|
||||
//if (FCSinheader == FCScalculated) {
|
||||
// fprintf (stderr, "(OK)\n");
|
||||
//} else {
|
||||
// fprintf (stderr, "(NOT OK- Calculated FCS = %04X)\n", FCScalculated);
|
||||
//}; // end else - if
|
||||
//debug
|
||||
// fprintf (stderr, " %02X %02X %02X", radioheader[0], radioheader[1], radioheader[2]);
|
||||
|
||||
fprintf (stderr, " RPT 2: %s", str1);
|
||||
fprintf (stderr, " RPT 1: %s", str2);
|
||||
fprintf (stderr, " DST: %s", str3);
|
||||
fprintf (stderr, " SRC: %s", str4);
|
||||
|
||||
memcpy (state->dstar_rpt2, str1, sizeof(str1));
|
||||
memcpy (state->dstar_rpt1, str2, sizeof(str2));
|
||||
memcpy (state->dstar_dst, str3, sizeof(str3));
|
||||
memcpy (state->dstar_src, str4, sizeof(str4));
|
||||
|
||||
//TODO: Call History for DSTAR
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user