Project

General

Profile

Statistics
| Branch: | Revision:

root / main.c @ 04b8cd51

History | View | Annotate | Download (1.63 KB)

1
#include <stdint.h>
2
#include <util/delay.h>
3
#include "mb.h"
4
#include "mbport.h"
5
#include "tooltron_mb.h"
6
#include "rfid.h"
7

    
8
eMBErrorCode eMBRegCoilsCB(UCHAR *reg_buf, USHORT addr, USHORT n_coils,
9
    eMBRegisterMode mode) {
10
  // TODO implement coils
11
  if (mode == MB_REG_WRITE) {
12
    return MB_ENOREG;
13
  } else if (mode == MB_REG_READ) {
14
    return MB_ENOREG;
15
  } else {
16
    return MB_EIO;
17
  }
18
}
19

    
20
eMBErrorCode eMBRegDiscreteCB(UCHAR *reg_buf, USHORT addr, USHORT n_coils) {
21
  return MB_ENOREG;
22
}
23

    
24
eMBErrorCode eMBRegInputCB(UCHAR *reg_buf, USHORT addr, USHORT n_regs) {
25
  char serno[RFID_SERNO_SIZE];
26

    
27
  rfid_get_serno(serno);
28

    
29
  switch (addr) {
30

    
31
    case MB_INP_SERNOL:
32
      // TODO check that these (and the ones in SERNOH) are in the right order
33
      *reg_buf++ = serno[0];
34
      *reg_buf++ = serno[1];
35
      n_regs--;
36
      if (n_regs == 0) {
37
        return MB_ENOERR;
38
      }
39

    
40
    case MB_INP_SERNOH:
41
      *reg_buf++ = serno[2];
42
      *reg_buf++ = serno[3];
43
      n_regs--;
44
      if (n_regs == 0) {
45
        return MB_ENOERR;
46
      }
47

    
48
    case MB_INP_CURRENT:
49
      *reg_buf++ = 0;
50
      *reg_buf++ = 0;
51
      n_regs--;
52
      if (n_regs == 0) {
53
        return MB_ENOERR;
54
      }
55

    
56
    default:
57
      return MB_ENOREG;
58
  }
59
}
60

    
61
eMBErrorCode eMBRegHoldingCB(UCHAR *reg_buf, USHORT addr, USHORT n_regs,
62
    eMBRegisterMode mode) {
63
  if (mode == MB_REG_WRITE) {
64
    return MB_ENOREG;
65
  } else if (mode == MB_REG_READ) {
66
    return MB_ENOREG;
67
  } else {
68
    return MB_EIO;
69
  }
70
}
71

    
72
int main() {
73
  rfid_init();
74

    
75
  eMBInit(MB_RTU, SLAVE_ADDR, 0, MB_BAUD, MB_PAR_NONE);
76
  eMBEnable();
77

    
78
  while (1) {
79
    rfid_read();
80
    eMBPoll();
81
    _delay_ms(200);
82
  }
83

    
84
  return 0;
85
}