Project

General

Profile

Statistics
| Branch: | Revision:

root / mainbox / main.c @ 7bdb98c5

History | View | Annotate | Download (1.01 KB)

1
#include "tool.h"
2
#include <unistd.h>
3
#include <signal.h>
4
#include <strings.h>
5
#include <stdio.h>
6

    
7
#define SLEEP_MS 250
8

    
9
struct tool_t tools[] = {
10
  {4, "test", TS_INIT}
11
};
12

    
13
#define N_TOOLS (sizeof(tools)/sizeof(struct tool_t))
14

    
15
volatile int run = 1;
16

    
17
void sigint(int sig) {
18
  run = 0;
19
}
20

    
21
int main(int argc, char **argv) {
22
  int i;
23
  struct sigaction sigact;
24
  const char *device = "/dev/ttyUSB0";
25

    
26
  // TODO getopts to get device name
27

    
28
  bzero(&sigact, sizeof(sigact));
29
  sigact.sa_handler = sigint;
30
  sigact.sa_flags = SA_RESTART;
31
  sigemptyset(&sigact.sa_mask);
32
  sigaction(SIGINT, &sigact, NULL);
33

    
34
  if (tool_init_mb(device)) {
35
    return 1;
36
  }
37

    
38
  printf("Modbus initialized; polling tools...\n");
39

    
40
  i = 0;
41
  while (run) {
42
    tool_poll(&tools[i]);
43
    usleep(SLEEP_MS * (useconds_t)1000);
44
    i = (i+1) % N_TOOLS;
45
  }
46

    
47
  printf("\nDisabling tools\n");
48
  for (i = 0; i < N_TOOLS; i++) {
49
    tool_request_disable(&tools[i]);
50
  }
51

    
52
  printf("Closing modbus connection\n");
53
  tool_close_mb();
54

    
55
  printf("Exiting\n");
56
  return 0;
57
}