Revision dc472500 mainbox/tool.c

View differences:

mainbox/tool.c
58 58
static void tool_grant_access(struct tool_t *tool) {
59 59
  printf("Granting access to %08x on %s\n", tool->user, tool->name);
60 60
  tool_write_coil(MB_COIL_EN, 1);
61
  tool->state = TS_ON;
61 62
}
62 63

  
63 64
static void tool_deny_access(struct tool_t *tool) {
64 65
  printf("Denying access to %08x on %s\n", tool->user, tool->name);
65 66
  tool_write_coil(MB_COIL_EN, 0);
67
  tool->state = TS_OFF;
66 68
}
67 69

  
68 70
void tool_request_disable(struct tool_t *tool) {
69 71
  printf("Requesting disable on %s\n", tool->name);
70 72
  tool_write_coil(MB_COIL_REQ_DIS, 1);
73
  tool->state = TS_REQ_DIS;
71 74
}
72 75

  
73 76
void tool_poll(struct tool_t *tool) {
......
77 80
    fprintf(stderr, "modbus_set_slave: %s\n", modbus_strerror(errno));
78 81
  }
79 82

  
80
  tool_read_user(tool);
81
  printf("%08x\n", tool->user);
82
  return;
83

  
84 83
  if (modbus_read_bits(ctx, 0, N_COILS, status) == -1) {
85 84
    fprintf(stderr, "modbus_read_bits: %s\n", modbus_strerror(errno));
86 85
    return;
87 86
  }
88 87

  
88
  printf("new:%d en:%d req_dis:%d init:%d\n", status[MB_COIL_NEW],
89
      status[MB_COIL_EN], status[MB_COIL_REQ_DIS], status[MB_COIL_INIT]);
90

  
89 91
  if (!status[MB_COIL_INIT]) {
90 92
    tool->state = TS_INIT;
91 93
  }
......
100 102
      if (status[MB_COIL_NEW]) {
101 103
        tool_read_user(tool);
102 104
        // TODO check actual credentials
103
        if (rand() & 1) {
105
        printf("user:%08x\n", tool->user);
106
        //if (rand() & 1) {
104 107
          tool_grant_access(tool);
105
        } else {
108
        /*} else {
106 109
          tool_deny_access(tool);
107
        }
110
        }*/
108 111
      }
109 112
      break;
110 113

  

Also available in: Unified diff