Revision 76915f20
Various fixes to tool main.c
- Input register callback no longer copies current_user to reg_buf
prematurely, and then write the uninitialized serno into reg_buf (?!)
- tool_disable was missing a ~
- Updated coil read/write to use new 1 indexed addresses
toolbox/main.c | ||
---|---|---|
29 | 29 |
|
30 | 30 |
static inline void tool_init() {DDRA |= _BV(DDA1);} |
31 | 31 |
static inline void tool_enable() {PORTA |= _BV(PA1);} |
32 |
static inline void tool_disable() {PORTA &= _BV(PA1);} |
|
32 |
static inline void tool_disable() {PORTA &= ~ _BV(PA1);}
|
|
33 | 33 |
|
34 | 34 |
static void tool_main() { |
35 | 35 |
|
... | ... | |
108 | 108 |
eMBErrorCode eMBRegCoilsCB(UCHAR *reg_buf, USHORT addr, USHORT n_coils, |
109 | 109 |
eMBRegisterMode mode) { |
110 | 110 |
|
111 |
if (addr >= N_COILS || n_coils >= N_COILS-addr) {
|
|
111 |
if (addr > N_COILS || n_coils >= N_COILS-addr) { |
|
112 | 112 |
return MB_ENOREG; |
113 | 113 |
} |
114 | 114 |
|
... | ... | |
152 | 152 |
|
153 | 153 |
} else if (mode == MB_REG_READ) { |
154 | 154 |
|
155 |
reg_buf[0] = (coils >> addr) & ((1 << n_coils) - 1);
|
|
155 |
reg_buf[0] = (coils >> (addr-1)) & ((1 << n_coils) - 1);
|
|
156 | 156 |
return MB_ENOERR; |
157 | 157 |
|
158 | 158 |
} |
... | ... | |
165 | 165 |
} |
166 | 166 |
|
167 | 167 |
eMBErrorCode eMBRegInputCB(UCHAR *reg_buf, USHORT addr, USHORT n_regs) { |
168 |
char serno[RFID_SERNO_SIZE]; |
|
169 |
|
|
170 |
memcpy(reg_buf, current_user, sizeof(current_user)); |
|
171 | 168 |
|
172 | 169 |
switch (addr) { |
173 | 170 |
|
174 | 171 |
case MB_INP_SERNOL: |
175 | 172 |
// TODO check that these (and the ones in SERNOH) are in the right order |
176 |
*reg_buf++ = serno[0];
|
|
177 |
*reg_buf++ = serno[1];
|
|
173 |
*reg_buf++ = current_user[0];
|
|
174 |
*reg_buf++ = current_user[1];
|
|
178 | 175 |
n_regs--; |
179 | 176 |
if (n_regs == 0) { |
180 | 177 |
return MB_ENOERR; |
181 | 178 |
} |
182 | 179 |
|
183 | 180 |
case MB_INP_SERNOH: |
184 |
*reg_buf++ = serno[2];
|
|
185 |
*reg_buf++ = serno[3];
|
|
181 |
*reg_buf++ = current_user[2];
|
|
182 |
*reg_buf++ = current_user[3];
|
|
186 | 183 |
n_regs--; |
187 | 184 |
if (n_regs == 0) { |
188 | 185 |
return MB_ENOERR; |
... | ... | |
226 | 223 |
rfid_read(); |
227 | 224 |
tool_main(); |
228 | 225 |
eMBPoll(); |
229 |
_delay_ms(200);
|
|
226 |
_delay_ms(100);
|
|
230 | 227 |
} |
231 | 228 |
|
232 | 229 |
return 0; |
Also available in: Unified diff