Revision 1085ef77 toolbox/rfid.c

View differences:

toolbox/rfid.c
4 4
#include "rfid.h"
5 5
#include "serial.h"
6 6

  
7
#define RFID_OK 1
7 8
static uint8_t read_cmd[] = {'!', 'R', 'W', 1, 32};
8 9

  
9 10
static int serno_idx;
11
static char n_failures;
10 12
static uint8_t serno[RFID_SERNO_SIZE];
11 13

  
12 14
static void zero_serno() {
......
20 22
  serial_init();
21 23
}
22 24

  
23
void rfid_start_read() {
25
static void restart_read() {
24 26
  serno_idx = -1;
25
  serial_flush();
26 27
  serial_write(read_cmd, sizeof(read_cmd));
27 28
}
28 29

  
30
void rfid_start_read() {
31
  n_failures = 0;
32
  restart_read();
33
}
34

  
29 35
char rfid_poll() {
30 36
  int c;
31 37

  
......
33 39

  
34 40
    if (serno_idx < 0) {
35 41
      if (c != RFID_OK) {
36
        zero_serno();
37
        return 1;
42
        n_failures++;
43
        if (n_failures >= RFID_N_FAILURES) {
44
          zero_serno();
45
          return 1;
46
        } else {
47
          restart_read();
48
          return 0;
49
        }
38 50
      }
39 51
    } else {
40 52
      serno[serno_idx] = c;

Also available in: Unified diff