1 /* Decoder Core for OpenPICC
2 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
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.
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.
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
21 #include <sys/types.h>
22 #include <picc/decoder.h>
26 static struct decoder_algo
*decoder_algo
[DECODER_NUM_ALGOS
];
28 static int get_next_data(struct decoder_state
*st
, u_int8_t
*data
)
30 u_int8_t parity_sample
;
33 bytesample
= st
->algo
->get_next_bytesample(st
, &parity_sample
);
35 return st
->algo
->decode_sample(bytesample
, data
);
38 /* iterate over sample buffer (size N bytes) and decode data */
39 int decoder_decode(u_int8_t algo
, const char *sample_buf
,
40 int sample_buf_size
, char *data_buf
)
43 struct decoder_state st
;
45 if (algo
>= DECODER_NUM_ALGOS
)
49 st
.buf32
= (u_int32_t
*) st
.buf
;
51 st
.algo
= decoder_algo
[algo
];
53 for (i
= 0; i
< (sample_buf_size
*8)/st
.algo
->bits_per_sampled_char
;
55 ret
= get_next_data(&st
, &data_buf
[i
]);
57 DEBUGPCR("decoder error %d at data byte %u",
66 int decoder_register(int algnum
, struct decoder_algo
*algo
)
68 if (algnum
>= DECODER_NUM_ALGOS
)
71 decoder_algo
[algnum
] = algo
;
76 void decoder_init(void)
78 decoder_register(DECODER_MILLER
, &miller_decoder
);
79 decoder_register(DECODER_NRZL
, &nrzl_decoder
);