forked from kb1isz/linDmrMaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode34Rate.c
176 lines (157 loc) · 5.87 KB
/
decode34Rate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* Linux DMR Master server
Copyright (C) 2014 Wim Hofman
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; either version 2 of the License, or
(at your option) any later version.
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.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "master_server.h"
bool * extractInfo();
int INTERLEAVE[] ={
0,1,8,9,16,17,24,25,32,33,40,41,48,49,56,57,64,65,72,73,80,81,88,89,96,97,
2,3,10,11,18,19,26,27,34,35,42,43,50,51,58,59,66,67,74,75,82,83,90,91,
4,5,12,13,20,21,28,29,36,37,44,45,52,53,60,61,68,69,76,77,84,85,92,93,
6,7,14,15,22,23,30,31,38,39,46,47,54,55,62,63,70,71,78,79,86,87,94,95};
unsigned char STATETABLE[]={
0,8,4,12,2,10,6,14,
4,12,2,10,6,14,0,8,
1,9,5,13,3,11,7,15,
5,13,3,11,7,15,1,9,
3,11,7,15,1,9,5,13,
7,15,1,9,5,13,3,11,
2,10,6,14,0,8,4,12,
6,14,0,8,4,12,2,10};
int * extractDibits(bool * rawBits){
int a,index=0,deinterleave;
int trellisDibit=0;
static int encDibit[98];
for (a=0;a<196;a=a+2) {
// Set the dibits
// 01 = +3
// 00 = +1
// 10 = -1
// 11 = -3
if ((*(rawBits+a)==false)&&(*(rawBits+a+1)==true)) trellisDibit=+3;
else if ((*(rawBits+a)==false)&&(*(rawBits+a+1)==false)) trellisDibit=+1;
else if ((*(rawBits+a)==true)&&(*(rawBits+a+1)==false)) trellisDibit=-1;
else if ((*(rawBits+a)==true)&&(*(rawBits+a+1)==true)) trellisDibit=-3;
// Deinterleave
deinterleave=INTERLEAVE[index];
encDibit[deinterleave]=trellisDibit;
// Increase the index
index++;
}
/*printf("Extracted dibits: ");
for (a=0;a<98;a++){
printf("%i:",encDibit[a]);
}
printf("\n");*/
return encDibit;
}
char * constellationOut (int * encDibit){
static char constellationPoints[49];
int a,index=0;
//printf("constellation: ");
for (a=0;a<98;a=a+2) {
if ((*(encDibit+a)==+1)&&(*(encDibit+a+1)==-1)) constellationPoints[index]=0;
else if ((*(encDibit+a)==-1)&&(*(encDibit+a+1)==-1)) constellationPoints[index]=1;
else if ((*(encDibit+a)==+3)&&(*(encDibit+a+1)==-3)) constellationPoints[index]=2;
else if ((*(encDibit+a)==-3)&&(*(encDibit+a+1)==-3)) constellationPoints[index]=3;
else if ((*(encDibit+a)==-3)&&(*(encDibit+a+1)==-1)) constellationPoints[index]=4;
else if ((*(encDibit+a)==+3)&&(*(encDibit+a+1)==-1)) constellationPoints[index]=5;
else if ((*(encDibit+a)==-1)&&(*(encDibit+a+1)==-3)) constellationPoints[index]=6;
else if ((*(encDibit+a)==+1)&&(*(encDibit+a+1)==-3)) constellationPoints[index]=7;
else if ((*(encDibit+a)==-3)&&(*(encDibit+a+1)==+3)) constellationPoints[index]=8;
else if ((*(encDibit+a)==+3)&&(*(encDibit+a+1)==+3)) constellationPoints[index]=9;
else if ((*(encDibit+a)==-1)&&(*(encDibit+a+1)==+1)) constellationPoints[index]=10;
else if ((*(encDibit+a)==+1)&&(*(encDibit+a+1)==+1)) constellationPoints[index]=11;
else if ((*(encDibit+a)==+1)&&(*(encDibit+a+1)==+3)) constellationPoints[index]=12;
else if ((*(encDibit+a)==-1)&&(*(encDibit+a+1)==+3)) constellationPoints[index]=13;
else if ((*(encDibit+a)==+3)&&(*(encDibit+a+1)==+1)) constellationPoints[index]=14;
else if ((*(encDibit+a)==-3)&&(*(encDibit+a+1)==+1)) constellationPoints[index]=15;
//printf("%i:",constellationPoints[index]);
index++;
}
//printf("\n");
return constellationPoints;
}
int * tribitExtract (char * cons){
int a,b,rowStart,lastState=0;
static int tribit[49];
bool match;
//printf("tribits: ");
for (a=0;a<49;a++) {
// The lastState variable decides which row of STATETABLE we should use
rowStart=lastState*8;
match=false;
for (b=rowStart;b<(rowStart+8);b++) {
// Check if this constellation point matches an element of this row of STATETABLE
if (*(cons+a)==STATETABLE[b]) {
// Yes it does
match=true;
lastState=b-rowStart;
tribit[a]=lastState;
}
}
//printf("%i:",tribit[a]);
// If no match found then we have a problem
if (match==false){
syslog(LOG_NOTICE,"TRIBIT EXTRACT no match %i !!!\n",a);
return NULL;
}
}
//printf("\n");
return tribit;
}
bool * binaryConvert (int * tribit){
int a,b=0;
static bool out[144] = {0};
if (tribit != NULL){
for (a=0;a<144;a=a+3) {
// Convert three bits at a time
if ((*(tribit+b)&4)>0) out[a]=true;
else out[a]=false;
if ((*(tribit+b)&2)>0) out[a+1]=true;
else out[a+1]=false;
if ((*(tribit+b)&1)>0) out[a+2]=true;
else out[a+2]=false;
// Increment the bit counter
b++;
}
}
return out;
}
unsigned char * decodeThreeQuarterRate(bool bits[264]){
bool *infoBits; //196 info bits
int *dibits; //98 info dibits
char *constellationPoints; //49 constallation points
int *tribits; //49 tribits
bool *decodedBinary; //144 bits
static unsigned char bb[18] = {0};
int x=0,a,i;
unsigned char bbb[100];
infoBits = extractInfo(bits);
dibits = extractDibits(infoBits);
constellationPoints = constellationOut(dibits);
tribits = tribitExtract(constellationPoints);
decodedBinary = binaryConvert(tribits);
memset(bbb,0,100);
for (a=0;a<144;a=a+8){
bb[x] = 0;
for (i=0;i<8;i++){
if(decodedBinary[a+i] == true) bb[x] = bb[x] + (char)(128 / pow(2,i));
}
if (debug == 1) sprintf(bbb,"%s(%02X)%c",bbb,bb[x],bb[x]);
x++;
}
if (debug == 1) syslog(LOG_NOTICE,"[decode34Rate-decodeThreeQuarterRate]%s",bbb);
return bb;
}