Revision 273
Pass information back and forth between read_card
cardreader.c | ||
---|---|---|
78 | 78 |
} |
79 | 79 |
} |
80 | 80 |
|
81 |
int8_t parse_card(void) {
|
|
81 |
int8_t parse_card(uint8_t *buf, uint8_t *buflen) {
|
|
82 | 82 |
int32_t i = cr_buf_idx - 1; |
83 |
uint8_t j = 0; |
|
83 | 84 |
uint8_t start_sentinal = 0; |
84 | 85 |
uint8_t byte_idx = 0; |
85 | 86 |
uint8_t byte = 0; |
86 | 87 |
uint8_t parity; |
87 | 88 |
|
89 |
// Look for the start sentinal |
|
88 | 90 |
while (start_sentinal == 0) { |
89 | 91 |
byte = (((byte >> 1) & 0x1F) | (cr_buf[i])); |
90 | 92 |
|
91 | 93 |
if (cr_dict[byte] == CR_SS) { |
92 |
|
|
93 |
toggle_led(LED_GREEN, ON); |
|
94 | 94 |
start_sentinal = 1; |
95 |
|
|
96 |
rs485_send_byte(cr_dict[byte]); |
|
95 |
|
|
96 |
(buf)[j++] = cr_dict[byte]; |
|
97 |
//rs485_send_byte(cr_dict[byte]); |
|
97 | 98 |
|
98 | 99 |
// Skip parity bit |
99 | 100 |
i--; |
100 | 101 |
} |
101 | 102 |
|
103 |
// Increment bits |
|
102 | 104 |
i--; |
103 | 105 |
|
106 |
// Ran out of buffer to search, no start sentinal found |
|
104 | 107 |
if (i == 0) { |
105 | 108 |
return CR_ERR_NO_START; |
106 | 109 |
} |
107 | 110 |
} |
108 | 111 |
|
112 |
// Prepare for reading of data |
|
109 | 113 |
byte = 0; |
110 | 114 |
byte_idx = 0; |
111 | 115 |
parity = 0; |
... | ... | |
118 | 122 |
return CR_ERR_BAD_PARITY; |
119 | 123 |
} |
120 | 124 |
|
121 |
rs485_send_byte(cr_dict[byte]); |
|
125 |
//rs485_send_byte(cr_dict[byte]); |
|
126 |
(buf)[j++] = cr_dict[byte]; |
|
122 | 127 |
|
123 | 128 |
// Stop at the stop sentinal |
124 | 129 |
if (cr_dict[byte] == CR_ES) { |
130 |
*buflen = j-1; |
|
125 | 131 |
return 0; |
126 | 132 |
} |
127 | 133 |
|
Also available in: Unified diff