Revision 8f961e44
Added getopt for inputting serial device and CRM server
mainbox/main.c | ||
---|---|---|
1 | 1 |
#include "tool.h" |
2 |
#include "query.h" |
|
2 | 3 |
#include <unistd.h> |
3 | 4 |
#include <signal.h> |
4 | 5 |
#include <strings.h> |
... | ... | |
18 | 19 |
run = 0; |
19 | 20 |
} |
20 | 21 |
|
22 |
void print_usage(const char *name) { |
|
23 |
printf("Usage: %s [-h] [-d serial_device] [-s db_server[:port]]\n", name); |
|
24 |
printf(" -h prints this message\n"); |
|
25 |
printf(" -d specifies the serial port for Modbus\n"); |
|
26 |
printf(" defaults to /dev/ttyUSB0\n"); |
|
27 |
printf(" -s specifies the server where the CRM is running\n"); |
|
28 |
printf(" defaults to minecraft.roboclub.org:8000\n"); |
|
29 |
} |
|
30 |
|
|
21 | 31 |
int main(int argc, char **argv) { |
22 |
int i; |
|
32 |
int i, opt;
|
|
23 | 33 |
struct sigaction sigact; |
24 | 34 |
const char *device = "/dev/ttyUSB0"; |
35 |
const char *server = "minecraft.roboclub.org:8000"; |
|
36 |
|
|
37 |
while ((opt = getopt(argc, argv, "hd:s:")) != -1) { |
|
38 |
switch (opt) { |
|
39 |
case 'h': |
|
40 |
print_usage(argv[0]); |
|
41 |
return 0; |
|
42 |
case 'd': |
|
43 |
device = optarg; |
|
44 |
break; |
|
45 |
case 's': |
|
46 |
server = optarg; |
|
47 |
break; |
|
48 |
default: |
|
49 |
print_usage(argv[0]); |
|
50 |
return 1; |
|
51 |
} |
|
52 |
} |
|
25 | 53 |
|
26 |
// TODO getopts to get device name |
|
54 |
printf("Serial device: %s\n", device); |
|
55 |
printf("CRM server: http://%s/\n", server); |
|
27 | 56 |
|
28 | 57 |
bzero(&sigact, sizeof(sigact)); |
29 | 58 |
sigact.sa_handler = sigint; |
... | ... | |
31 | 60 |
sigemptyset(&sigact.sa_mask); |
32 | 61 |
sigaction(SIGINT, &sigact, NULL); |
33 | 62 |
|
63 |
if (query_init(server)) { |
|
64 |
return 1; |
|
65 |
} |
|
66 |
|
|
34 | 67 |
if (tool_init_mb(device)) { |
35 | 68 |
return 1; |
36 | 69 |
} |
Also available in: Unified diff