Project

General

Profile

Revision 2dde134c

ID2dde134ca53ca2a44f4bcdcd3f91ef32067ec2c9
Parent 9e26460d
Child e2a3c71f

Added by Thomas Mullins almost 10 years ago

Shorted modbus timeout

View differences:

mainbox/main.c
7 7
#include <signal.h>
8 8
#include <string.h>
9 9
#include <stdio.h>
10

  
11
#define SLEEP_MS 25
10
#include <sys/time.h>
12 11

  
13 12
static struct tool_t tools[] = {
14 13
  TOOL_DECL("Mill", 1),
......
52 51

  
53 52
int tooltron_main(const char *device, const char *server) {
54 53
  struct sigaction sigact;
55
  int i;
54
  struct timeval time_prev, time_cur;
55
  int i, diff;
56 56

  
57 57
  log_print("Serial device: %s", device);
58 58
  log_print("CRM server: http://%s/", server);
......
81 81

  
82 82
  log_print("Modbus initialized; polling tools...");
83 83

  
84
  gettimeofday(&time_prev, NULL);
85

  
84 86
  i = 0;
85 87
  while (run) {
86 88
    tool_poll(&tools[i]);
......
95 97
      cache_clear();
96 98
      clear_cache = 0;
97 99
    }
98
    usleep(SLEEP_MS * (useconds_t)1000);
100

  
101
    // slow loop period down to MB_TIMEOUT_MS
102
    gettimeofday(&time_cur, NULL);
103
    diff = (time_cur.tv_sec - time_prev.tv_sec) * 1000000
104
         + (time_cur.tv_usec - time_prev.tv_usec);
105
    diff = MB_TIMEOUT_MS * 1000 - diff;
106
    if (diff > 0) {
107
      usleep(diff);
108
    }
109
    gettimeofday(&time_prev, NULL);
110

  
99 111
    i = (i+1) % N_TOOLS;
100 112
  }
101 113
  log_print("Recieved SIGINT or SIGTERM, shutting down");

Also available in: Unified diff