43 static const unsigned char GCR_encode[16] = {
44 0x0a, 0x0b, 0x12, 0x13,
45 0x0e, 0x0f, 0x16, 0x17,
46 0x09, 0x19, 0x1a, 0x1b,
47 0x0d, 0x1d, 0x1e, 0x15
51 static const unsigned char GCR_decode[32] = {
52 0xff, 0xff, 0xff, 0xff,
53 0xff, 0xff, 0xff, 0xff,
54 0xff, 0x08, 0x00, 0x01,
55 0xff, 0x0c, 0x04, 0x05,
57 0xff, 0xff, 0x02, 0x03,
58 0xff, 0x0f, 0x06, 0x07,
59 0xff, 0x09, 0x0a, 0x0b,
60 0xff, 0x0d, 0x0e, 0xff,
63 static unsigned char gcr_bits = 0;
64 static unsigned short gcr_val = 0;
73 unsigned char gcr_finished() {
78 void gcr_encode(
unsigned char raw_data) {
80 ((GCR_encode[raw_data >> 4u] << 5u ) |
81 GCR_encode[raw_data & 0xf]) << gcr_bits;
86 unsigned char gcr_get_encoded(
unsigned char *raw_data) {
88 *raw_data = (
unsigned char) (gcr_val & 0xff);
89 gcr_val = gcr_val >> 8u;
90 gcr_bits = gcr_bits - 8;
97 void gcr_decode(
unsigned char gcr_data) {
98 gcr_val |= gcr_data << gcr_bits;
103 unsigned char gcr_valid() {
104 if (gcr_bits >= 10) {
105 unsigned short val = gcr_val & 0x3ff;
106 if ((GCR_decode[val >> 5u] << 4u) == 0xff ||
107 (GCR_decode[val & 0x1f]) == 0xff) {
115 unsigned char gcr_get_decoded(
unsigned char *raw_data) {
116 if (gcr_bits >= 10) {
117 unsigned short val = gcr_val & 0x3ff;
118 *raw_data = (
unsigned char) ((GCR_decode[val >> 5] << 4) |
119 (GCR_decode[val & 0x1f]));
120 gcr_val = gcr_val >> 10;
121 gcr_bits = gcr_bits - 10;