Revision 273
| trunk/cardbox/cardreader.h (revision 273) | ||
|---|---|---|
| 23 | 23 |
extern volatile uint16_t cr_buf_idx; |
| 24 | 24 |
|
| 25 | 25 |
void card_reader_setup(void); |
| 26 |
int8_t parse_card(void); |
|
| 26 |
int8_t parse_card(uint8_t *buf, uint8_t *buflen); |
|
| 27 | 27 |
#endif |
| trunk/cardbox/main.c (revision 273) | ||
|---|---|---|
| 154 | 154 |
|
| 155 | 155 |
int main(void) {
|
| 156 | 156 |
uint8_t mbuf[PROGD_PACKET_SIZE]; |
| 157 |
uint8_t cbuf[100]; |
|
| 158 |
uint8_t clen; |
|
| 157 | 159 |
uint8_t resp; |
| 158 | 160 |
uint8_t c; |
| 159 | 161 |
uint8_t len; |
| ... | ... | |
| 175 | 177 |
read_card = 1; |
| 176 | 178 |
if (cr_flag != CR_NONE) {
|
| 177 | 179 |
read_card = 0; |
| 178 |
if (parse_card() < 0) {
|
|
| 180 |
if (parse_card(cbuf, &clen) < 0) {
|
|
| 179 | 181 |
rs485_send_byte('F');
|
| 182 |
} else {
|
|
| 183 |
for (c = 0; c < clen; c++) {
|
|
| 184 |
rs485_send_byte(cbuf[c]); |
|
| 185 |
} |
|
| 180 | 186 |
} |
| 181 | 187 |
cr_flag = CR_NONE; |
| 182 | 188 |
} |
| trunk/cardbox/cardreader.c (revision 273) | ||
|---|---|---|
| 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