Revision 532ba0bd toolbox/rfid.c

View differences:

toolbox/rfid.c
5 5

  
6 6
static char read_cmd[] = {'!', 'R', 'W', 1, 32};
7 7

  
8
static int serno_idx;
8 9
static char serno[RFID_SERNO_SIZE];
9 10

  
10 11
static void zero_serno() {
......
57 58
        return;
58 59
      }
59 60
    }
60
    _delay_ms(40);
61
    _delay_ms(10);
61 62
  }
62 63
}
63 64

  
64
void rfid_read() {
65
  while (1) {
66
    serial_write(read_cmd, sizeof(read_cmd));
67
    if (serial_read_blocking() == RFID_OK) {
68
      read_serno();
69
      return;
65
void rfid_start_read() {
66
  serno_idx = -1;
67
  zero_serno(); // TODO temporary
68
  serial_flush();
69
  serial_write(read_cmd, sizeof(read_cmd));
70
}
71

  
72
char rfid_poll() {
73
  int c;
74

  
75
  c = serial_read();
76
  while (c >= 0) {
77

  
78
    if (serno_idx < 0) {
79
      if (c != RFID_OK) {
80
        zero_serno();
81
        return 1;
82
      }
83
    } else {
84
      serno[serno_idx] = c;
85
    }
86

  
87
    serno_idx++;
88
    if (serno_idx >= RFID_SERNO_SIZE) {
89
      return 1;
70 90
    }
71
    _delay_ms(40);
91

  
92
    c = serial_read();
72 93
  }
94

  
95
  return 0;
73 96
}
74 97

  
75 98
void rfid_get_serno(char *buf) {

Also available in: Unified diff