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