-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcon-raw.c
86 lines (75 loc) · 1.91 KB
/
dcon-raw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* dcon-raw.c -- exchange a single command with an DCON module
* Copyright (C) 2014 Sergei Ianovich <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "includes.h"
#include <stdio.h>
#include <unistd.h>
#include "icpdas.h"
#define MAX_RESPONSE 256
static void
usage(int err)
{
fprintf(stderr, "Usage: dcon-raw [-d] [-p port] [-s slot] command\n");
fprintf(stderr, " dcon-raw -h\n");
exit(err);
}
int
main(int argc, char **argv)
{
const char *device = "/dev/ttyS1";
int log_level = LOG_NOTICE;
unsigned int slot = 0;
char *bad;
int opt;
char data[MAX_RESPONSE];
int err;
while ((opt = getopt(argc, argv, "dhp:s:")) != -1) {
switch (opt) {
case 'd':
if (log_level >= LOG_DEBUG)
log_level++;
else
log_level = LOG_DEBUG;
break;
case 'h':
usage(0);
break;
case 'p':
device = optarg;
break;
case 's':
slot = (unsigned int) strtoul(optarg, &bad, 10);
if (bad[0] != 0) {
fprintf(stderr, "Bad slot value %s\n", optarg);
exit(1);
}
break;
default:
usage(1);
break;
}
}
log_init("icp-raw", log_level, LOG_DAEMON, 1);
err = icpdas_serial_exchange(device, slot, argv[argc - 1],
MAX_RESPONSE, data);
if (0 > err) {
return 1;
}
printf("%s\n", data);
return 0;
}