-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmdc_decode.h
More file actions
203 lines (167 loc) · 6.04 KB
/
mdc_decode.h
File metadata and controls
203 lines (167 loc) · 6.04 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*-
* mdc_decode.h
* header for mdc_decode.c
*
* Author: Matthew Kaufman (matthew@eeph.com)
*
* Copyright (c) 2005, 2010 Matthew Kaufman All rights reserved.
*
* This file is part of Matthew Kaufman's MDC Encoder/Decoder Library
*
* The MDC Encoder/Decoder Library is free software; you can
* redistribute it and/or modify it under the terms of version 2 of
* the GNU General Public License as published by the Free Software
* Foundation.
*
* If you cannot comply with the terms of this license, contact
* the author for alternative license arrangements or do not use
* or redistribute this software.
*
* The MDC Encoder/Decoder Library 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 software; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA.
*
* or see http://www.gnu.org/copyleft/gpl.html
*
-*/
#ifndef _MDC_DECODE_H_
#define _MDC_DECODE_H_
// #define MDC_FIXEDMATH // if you want this, define before mdc_types.h
#include "mdc_types.h"
#define MDC_GDTHRESH 5 // "good bits" threshold
#define MDC_ECC
#define MDC_FOURPOINT // recommended 4-point method, requires high sample rates (16000 or higher)
#undef MDC_ONEPOINT // alternative 1-point method
#ifdef MDC_FOURPOINT
#define MDC_ND 5 // recommended for four-point method
#endif
#ifdef MDC_ONEPOINT
#define MDC_ND 4 // recommended for one-point method
#endif
typedef void (*mdc_decoder_callback_t)( int frameCount, // 1 or 2 - if 2 then extra0-3 are valid
unsigned char op,
unsigned char arg,
unsigned short unitID,
unsigned char extra0,
unsigned char extra1,
unsigned char extra2,
unsigned char extra3,
void *context);
typedef struct
{
// mdc_float_t th;
mdc_u32_t thu;
// mdc_int_t zc; - deprecated
mdc_int_t xorb;
mdc_int_t invert;
#ifdef MDC_FOURPOINT
#ifdef MDC_FIXEDMATH
#error "fixed-point math not allowed for fourpoint strategy"
#endif // MDC_FIXEDMATH
mdc_int_t nlstep;
mdc_float_t nlevel[10];
#endif // MDC_FOURPOINT
#ifdef PLL
mdc_u32_t plt;
#endif
mdc_u32_t synclow;
mdc_u32_t synchigh;
mdc_int_t shstate;
mdc_int_t shcount;
mdc_int_t bits[112];
} mdc_decode_unit_t;
typedef struct {
mdc_decode_unit_t du[MDC_ND];
// mdc_float_t hyst;
// mdc_float_t incr;
mdc_u32_t incru;
#ifdef PLL
mdc_u32_t zthu;
mdc_int_t zprev;
mdc_float_t vprev;
#endif
mdc_int_t level;
mdc_int_t good;
mdc_int_t indouble;
mdc_u8_t op;
mdc_u8_t arg;
mdc_u16_t unitID;
mdc_u8_t extra0;
mdc_u8_t extra1;
mdc_u8_t extra2;
mdc_u8_t extra3;
mdc_decoder_callback_t callback;
void *callback_context;
} mdc_decoder_t;
/*
mdc_decoder_new
create a new mdc_decoder object
parameters: int sampleRate - the sampling rate in Hz
returns: an mdc_decoder object or null if failure
*/
mdc_decoder_t * mdc_decoder_new(int sampleRate);
/*
mdc_decoder_process_samples
process incoming samples using an mdc_decoder object
parameters: mdc_decoder_t *decoder - pointer to the decoder object
mdc_sample_t *samples - pointer to samples (in format set in mdc_types.h)
int numSamples - count of the number of samples in buffer
returns: 0 if more samples are needed
-1 if an error occurs
1 if a decoded single packet is available to read (if no callback set)
2 if a decoded double packet is available to read (if no callback set)
*/
int mdc_decoder_process_samples(mdc_decoder_t *decoder,
mdc_sample_t *samples,
int numSamples);
/*
mdc_decoder_get_packet
retrieve last successfully decoded data packet from decoder object
parameters: mdc_decoder_t *decoder - pointer to the decoder object
unsigned char *op - pointer to where to store "opcode"
unsigned char *arg - pointer to where to store "argument"
unsigned short *unitID - pointer to where to store "unit ID"
returns: -1 if error, 0 otherwise
*/
int mdc_decoder_get_packet(mdc_decoder_t *decoder,
unsigned char *op,
unsigned char *arg,
unsigned short *unitID);
/*
mdc_decoder_get_double_packet
retrieve last successfully decoded double-length packet from decoder object
parameters: mdc_decoder_t *decoder - pointer to the decoder object
unsigned char *op - pointer to where to store "opcode"
unsigned char *arg - pointer to where to store "argument"
unsigned short *unitID - pointer to where to store "unit ID"
unsigned char *extra0 - pointer to where to store 1st extra byte
unsigned char *extra1 - pointer to where to store 2nd extra byte
unsigned char *extra2 - pointer to where to store 3rd extra byte
unsigned char *extra3 - pointer to where to store 4th extra byte
returns: -1 if error, 0 otherwise
*/
int mdc_decoder_get_double_packet(mdc_decoder_t *decoder,
unsigned char *op,
unsigned char *arg,
unsigned short *unitID,
unsigned char *extra0,
unsigned char *extra1,
unsigned char *extra2,
unsigned char *extra3);
/*
mdc_decoder_set_callback
set a callback function to be called upon successful decode
if this is set, the functions mdc_decoder_get_packet and mdc_decoder_get_double_packet
will no longer be functional, instead the callback function is called immediately when
a successful decode happens (from within the context of mdc_decoder_process_samples)
the callback function will be passed the (void *)context that is set here
returns: -1 if error, 0 otherwise
*/
int mdc_decoder_set_callback(mdc_decoder_t *decoder, mdc_decoder_callback_t callbackFunction, void *context);
#endif