1 |
32985a29
|
laforge
|
/* Decoder Core for OpenPICC
|
2 |
548ec55e
|
(no author)
|
* (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
|
3 |
32985a29
|
laforge
|
*
|
4 |
|
|
* This program is free software; you can redistribute it and/or modify
|
5 |
|
|
* it under the terms of the GNU General Public License as published by
|
6 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
7 |
|
|
* (at your option) any later version.
|
8 |
|
|
*
|
9 |
|
|
* This program is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this program; if not, write to the Free Software
|
16 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17 |
|
|
*
|
18 |
548ec55e
|
(no author)
|
*/
|
19 |
|
|
|
20 |
29d8974f
|
(no author)
|
#include <errno.h>
|
21 |
548ec55e
|
(no author)
|
#include <sys/types.h>
|
22 |
29d8974f
|
(no author)
|
#include <picc/decoder.h>
|
23 |
|
|
|
24 |
|
|
#include <os/dbgu.h>
|
25 |
548ec55e
|
(no author)
|
|
26 |
|
|
static struct decoder_algo *decoder_algo[DECODER_NUM_ALGOS];
|
27 |
|
|
|
28 |
373c172a
|
Harald Welte
|
static int get_next_data(struct decoder_state *st, uint8_t *data)
|
29 |
548ec55e
|
(no author)
|
{
|
30 |
373c172a
|
Harald Welte
|
uint8_t parity_sample;
|
31 |
|
|
uint32_t bytesample;
|
32 |
548ec55e
|
(no author)
|
|
33 |
|
|
bytesample = st->algo->get_next_bytesample(st, &parity_sample);
|
34 |
|
|
|
35 |
|
|
return st->algo->decode_sample(bytesample, data);
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
/* iterate over sample buffer (size N bytes) and decode data */
|
39 |
373c172a
|
Harald Welte
|
int decoder_decode(uint8_t algo, const char *sample_buf,
|
40 |
548ec55e
|
(no author)
|
int sample_buf_size, char *data_buf)
|
41 |
|
|
{
|
42 |
29d8974f
|
(no author)
|
int i, ret;
|
43 |
548ec55e
|
(no author)
|
struct decoder_state st;
|
44 |
|
|
|
45 |
|
|
if (algo >= DECODER_NUM_ALGOS)
|
46 |
|
|
return -EINVAL;
|
47 |
|
|
|
48 |
|
|
st.buf = sample_buf;
|
49 |
373c172a
|
Harald Welte
|
st.buf32 = (uint32_t *) st.buf;
|
50 |
548ec55e
|
(no author)
|
st.bit_ofs = 0;
|
51 |
|
|
st.algo = decoder_algo[algo];
|
52 |
|
|
|
53 |
|
|
for (i = 0; i < (sample_buf_size*8)/st.algo->bits_per_sampled_char;
|
54 |
|
|
i++) {
|
55 |
|
|
ret = get_next_data(&st, &data_buf[i]);
|
56 |
|
|
if (ret < 0) {
|
57 |
|
|
DEBUGPCR("decoder error %d at data byte %u",
|
58 |
|
|
ret, i);
|
59 |
|
|
return ret;
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
return i+1;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
29d8974f
|
(no author)
|
int decoder_register(int algnum, struct decoder_algo *algo)
|
67 |
548ec55e
|
(no author)
|
{
|
68 |
29d8974f
|
(no author)
|
if (algnum >= DECODER_NUM_ALGOS)
|
69 |
548ec55e
|
(no author)
|
return -EINVAL;
|
70 |
|
|
|
71 |
29d8974f
|
(no author)
|
decoder_algo[algnum] = algo;
|
72 |
548ec55e
|
(no author)
|
|
73 |
|
|
return 0;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
29d8974f
|
(no author)
|
void decoder_init(void)
|
77 |
548ec55e
|
(no author)
|
{
|
78 |
|
|
decoder_register(DECODER_MILLER, &miller_decoder);
|
79 |
|
|
decoder_register(DECODER_NRZL, &nrzl_decoder);
|
80 |
|
|
}
|