Project

General

Profile

Download (2.08 KB) Statistics
| Branch: | Tag: | Revision:
1 29ea5bbf henryk
/* Decoder Core for OpenPICC
2
 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
3
 *
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
 */
19
20
#include <errno.h>
21
#include <sys/types.h>
22
23
#include "openpicc.h"
24
#include "dbgu.h"
25
#include "decoder.h"
26
27
static struct decoder_algo *decoder_algo[DECODER_NUM_ALGOS];
28
29
static int get_next_data(struct decoder_state *st, u_int8_t *data)
30
{
31
	u_int8_t parity_sample;
32
	u_int32_t bytesample;
33
34
	bytesample = st->algo->get_next_bytesample(st, &parity_sample);
35
36
	return st->algo->decode_sample(bytesample, data);
37
}
38
39
/* iterate over sample buffer (size N bytes) and decode data */
40
int decoder_decode(u_int8_t algo, const char *sample_buf,
41
	  	   int sample_buf_size, unsigned char *data_buf)
42
{
43
	int i, ret;
44
	struct decoder_state st;
45
46
	if (algo >= DECODER_NUM_ALGOS)
47
		return -EINVAL;
48
49
	st.buf = sample_buf;
50
	st.buf32 = (u_int32_t *) st.buf;
51
	st.bit_ofs = 0;
52
	st.algo = decoder_algo[algo];
53
54
	for (i = 0; i < (sample_buf_size*8)/st.algo->bits_per_sampled_char;
55
	     i++) {
56
		ret = get_next_data(&st, &data_buf[i]);
57
		if (ret < 0) {
58
			DEBUGPCR("decoder error %d at data byte %u",
59
				 ret, i);
60
			return ret;
61
		}
62
	}
63
64
	return i+1;
65
}
66
67
int decoder_register(int algnum, struct decoder_algo *algo)
68
{
69
	if (algnum >= DECODER_NUM_ALGOS)
70
		return -EINVAL;
71
72
	decoder_algo[algnum] = algo;
73
74
	return 0;
75
}
76
77
void decoder_init(void)
78
{
79
	decoder_register(DECODER_MILLER, &miller_decoder);
80
	decoder_register(DECODER_NRZL, &nrzl_decoder);
81
}
Add picture from clipboard (Maximum size: 48.8 MB)