root / main.c @ 9b2b6d91
History | View | Annotate | Download (1.19 KB)
1 | 20e5429c | Tom Mullins | #include <stdint.h> |
---|---|---|---|
2 | #include <util/delay.h> |
||
3 | #include "mb.h" |
||
4 | #include "mbport.h" |
||
5 | #include "tooltron_mb.h" |
||
6 | 9b2b6d91 | Tom Mullins | #include "rfid.h" |
7 | 20e5429c | Tom Mullins | |
8 | eMBErrorCode eMBRegCoilsCB(UCHAR *reg_buf, USHORT addr, USHORT num, |
||
9 | eMBRegisterMode mode) { |
||
10 | if (mode == MB_REG_WRITE) {
|
||
11 | return MB_ENOREG;
|
||
12 | } else if (mode == MB_REG_READ) { |
||
13 | return MB_ENOREG;
|
||
14 | } else {
|
||
15 | return MB_EIO;
|
||
16 | } |
||
17 | } |
||
18 | |||
19 | eMBErrorCode eMBRegDiscreteCB(UCHAR *reg_buf, USHORT addr, USHORT num) { |
||
20 | return MB_ENOREG;
|
||
21 | } |
||
22 | |||
23 | eMBErrorCode eMBRegInputCB(UCHAR *reg_buf, USHORT addr, USHORT num) { |
||
24 | int i;
|
||
25 | switch (addr) {
|
||
26 | case 0: |
||
27 | // TODO test whether the following works as expected (8 or 16 bit buf?)
|
||
28 | for (i = 0; i < 2*num; i++) { |
||
29 | reg_buf[i] = i; |
||
30 | } |
||
31 | return MB_ENOERR;
|
||
32 | default:
|
||
33 | return MB_ENOREG;
|
||
34 | } |
||
35 | } |
||
36 | |||
37 | eMBErrorCode eMBRegHoldingCB(UCHAR *reg_buf, USHORT addr, USHORT num, |
||
38 | eMBRegisterMode mode) { |
||
39 | if (mode == MB_REG_WRITE) {
|
||
40 | return MB_ENOREG;
|
||
41 | } else if (mode == MB_REG_READ) { |
||
42 | return MB_ENOREG;
|
||
43 | } else {
|
||
44 | return MB_EIO;
|
||
45 | } |
||
46 | } |
||
47 | |||
48 | int main() {
|
||
49 | 9b2b6d91 | Tom Mullins | rfid_init(); |
50 | 20e5429c | Tom Mullins | |
51 | eMBInit(MB_RTU, SLAVE_ADDR, 0, MB_BAUD, MB_PAR_NONE);
|
||
52 | eMBEnable(); |
||
53 | |||
54 | while (1) { |
||
55 | rfid_read(); |
||
56 | eMBPoll(); |
||
57 | _delay_ms(200);
|
||
58 | } |
||
59 | |||
60 | return 0; |
||
61 | } |