Project

General

Profile

Revision 6ca98a3f

ID6ca98a3f3d28be42c8b1ef7713894d4c62c23180
Parent 92a430bc
Child f602b25b

Added by Thomas Mullins over 11 years ago

Eradicated use of signed chars in serial d'oh

View differences:

toolbox/main.c
18 18
};
19 19

  
20 20
static enum toolstate_t toolstate = TS_INIT;
21
static char coils;
22
static char current_user[RFID_SERNO_SIZE];
21
static uint8_t coils;
22
static uint8_t current_user[RFID_SERNO_SIZE];
23 23

  
24 24
static inline void set_coil(char coil, char bit) {
25
  coils |= (bit << coil);
25
  coils = (coils & ~(1 << coil)) | (bit << coil);
26 26
}
27 27
static inline char get_coil(char coil) {
28 28
  return (coils >> coil) & 1;
......
170 170
  switch (addr) {
171 171

  
172 172
    case MB_INP_SERNOL:
173
      // TODO check that these (and the ones in SERNOH) are in the right order
174 173
      *reg_buf++ = current_user[0];
175 174
      *reg_buf++ = current_user[1];
176 175
      n_regs--;
......
224 223
  rfid_start_read();
225 224
  while (1) {
226 225
    if (rfid_poll()) {
226
      rfid_get_serno(current_user);
227 227
      rfid_start_read();
228 228
    }
229
    rfid_get_serno(current_user);
230 229
    //tool_main();
231 230
    eMBPoll();
232 231
    _delay_ms(50);
toolbox/rfid.c
1 1
#include <string.h>
2
#include <stdint.h>
2 3
#include <util/delay.h>
3 4
#include "rfid.h"
4 5
#include "serial.h"
5 6

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

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

  
11 12
static void zero_serno() {
12 13
  int i;
......
72 73
char rfid_poll() {
73 74
  int c;
74 75

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

  
78 78
    if (serno_idx < 0) {
79 79
      if (c != RFID_OK) {
......
89 89
      return 1;
90 90
    }
91 91

  
92
    c = serial_read();
93 92
  }
94 93

  
95 94
  return 0;
96 95
}
97 96

  
98
void rfid_get_serno(char *buf) {
97
void rfid_get_serno(uint8_t *buf) {
99 98
  memcpy(buf, serno, sizeof(serno));
100 99
}
101 100

  
102
char rfid_check_serno(char *buf) {
101
char rfid_check_serno(uint8_t *buf) {
103 102
  return memcmp(buf, serno, sizeof(serno)) == 0;
104 103
}
105 104

  
toolbox/serial.c
1
#include "serial.h"
1
#include <stdint.h>
2 2
#include <avr/io.h>
3 3
#include <avr/interrupt.h>
4
#include "serial.h"
4 5

  
5 6
static int rx_start = 0, rx_end = 0;
6
static char rx_buffer[RX_BUFFER_SIZE];
7
static uint8_t rx_buffer[RX_BUFFER_SIZE];
7 8

  
8 9
ISR(USART1_RX_vect) {
9
  char data = UDR1;
10
  uint8_t data = UDR1;
10 11
  int new_end = rx_end+1;
11 12
  if (new_end == RX_BUFFER_SIZE) {
12 13
    new_end = 0;
......
43 44
  } else {
44 45
    ret = rx_buffer[rx_start];
45 46
    rx_start++;
46
    if (rx_start == RX_BUFFER_SIZE)
47
    if (rx_start == RX_BUFFER_SIZE) {
47 48
      rx_start = 0;
49
    }
48 50
  }
49 51
  sei();
50 52
  return ret;
......
57 59
  sei();
58 60
}
59 61

  
60
char serial_read_blocking() {
62
uint8_t serial_read_blocking() {
61 63
  int c;
62 64
  do {
63 65
    c = serial_read();
......
65 67
  return c;
66 68
}
67 69

  
68
void serial_write(char* data, int length) {
70
void serial_write(uint8_t* data, int length) {
69 71
  int i;
70 72
  for (i = 0; i < length; i++) {
71 73
    while (!(UCSR1A & _BV(UDRE1)));
toolbox/serial.h
3 3

  
4 4
#define BAUD_RATE 9600
5 5

  
6
#define RX_BUFFER_SIZE 256
6
#define RX_BUFFER_SIZE 64
7 7

  
8 8
void serial_init();
9 9
int serial_read();

Also available in: Unified diff