Revision 75cef49f
Added query_add_event to mainbox code
mainbox/tool.c | ||
---|---|---|
1 | 1 |
#include "tool.h" |
2 | 2 |
#include "query.h" |
3 |
#include "event.h" |
|
3 | 4 |
#include "tooltron_mb.h" |
4 | 5 |
#include <modbus.h> |
5 | 6 |
#include <stdio.h> |
... | ... | |
60 | 61 |
tool->address); |
61 | 62 |
tool_write_coil(MB_COIL_EN, 1); |
62 | 63 |
tool->state = TS_ON; |
64 |
tool->event = event_alloc(); |
|
65 |
tool->event->user = tool->user; |
|
66 |
tool->event->tool_id = tool->address; |
|
67 |
tool->event->tstart = time(NULL); |
|
63 | 68 |
} |
64 | 69 |
|
65 | 70 |
static void tool_deny_access(struct tool_t *tool) { |
... | ... | |
69 | 74 |
tool->state = TS_OFF; |
70 | 75 |
} |
71 | 76 |
|
77 |
static void tool_off(struct tool_t *tool) { |
|
78 |
tool->state = TS_OFF; |
|
79 |
tool->event->tend = time(NULL); |
|
80 |
event_q_push(tool->event); |
|
81 |
tool->event = NULL; |
|
82 |
} |
|
83 |
|
|
72 | 84 |
void tool_request_disable(struct tool_t *tool) { |
73 | 85 |
printf("Requesting disable on %s (%d)\n", tool->name, tool->address); |
74 | 86 |
tool_write_coil(MB_COIL_REQ_DIS, 1); |
... | ... | |
130 | 142 |
case TS_ON: |
131 | 143 |
if (!status[MB_COIL_EN]) { |
132 | 144 |
printf("Tool %s (%d) is off\n", tool->name, tool->address); |
133 |
tool->state = TS_OFF;
|
|
145 |
tool_off(tool);
|
|
134 | 146 |
} |
135 | 147 |
break; |
136 | 148 |
|
... | ... | |
138 | 150 |
if (!status[MB_COIL_EN]) { |
139 | 151 |
printf("Tool %s (%d) is off after requested disable\n", tool->name, |
140 | 152 |
tool->address); |
141 |
tool->state = TS_OFF;
|
|
153 |
tool_off(tool);
|
|
142 | 154 |
} |
143 | 155 |
break; |
144 | 156 |
|
Also available in: Unified diff