2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2009 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "lowlevelconf.h"
27 /** aborts program with a printf like message */
29 die (const char *msg
, ...)
40 /** structure to store low level backends */
45 /** factory function */
46 LowLevel_Create_Func Create
;
47 /** cleanup function */
52 struct urldef URLs
[] = {
54 #define L2_NAME(a) { a##_PREFIX, a##_CREATE, a##_CLEANUP },
55 #include "lowlevelcreate.h"
61 /** determines the right backend for the url and creates it */
62 LowLevelDriverInterface
*
63 Create (const char *url
, Trace
* t
)
66 struct urldef
*u
= URLs
;
67 while (url
[p
] && url
[p
] != ':')
70 die ("not a valid url");
73 if (strlen (u
->prefix
) == p
&& !memcmp (u
->prefix
, url
, p
))
76 return u
->Create (url
+ p
+ 1, t
);
80 die ("url not supported");
85 const char *argp_program_version
= "bcuread " VERSION
;
88 "bcuread -- read BCU memory\n"
89 "(C) 2005-2009 Martin Koegler <mkoegler@auto.tuwien.ac.at>\n"
90 "supported URLs are:\n"
92 #define L2_NAME(a) a##_URL
93 #include "lowlevelcreate.h"
96 #define L2_NAME(a) a##_DOC
97 #include "lowlevelcreate.h"
100 /** structure to store the arguments */
106 /** storage for the arguments*/
107 struct arguments arg
;
110 readHex (const char *addr
)
113 sscanf (addr
, "%x", &i
);
117 /** documentation for arguments*/
118 static char args_doc
[] = "URL addr len";
121 static struct argp_option options
[] = {
123 {"trace", 't', "LEVEL", 0, "set trace level"},
128 /** parses and stores an option */
130 parse_opt (int key
, char *arg
, struct argp_state
*state
)
132 struct arguments
*arguments
= (struct arguments
*) state
->input
;
136 arguments
->tracelevel
= (arg
? atoi (arg
) : 0);
139 return ARGP_ERR_UNKNOWN
;
144 /** information for the argument parser*/
145 static struct argp argp
= { options
, parse_opt
, args_doc
, doc
};
149 main (int ac
, char *ag
[])
155 LowLevelDriverInterface
*iface
= 0;
156 memset (&arg
, 0, sizeof (arg
));
158 argp_parse (&argp
, ac
, ag
, 0, &index
, &arg
);
160 die ("more parameter expected");
162 die ("unexpected parameter");
164 signal (SIGPIPE
, SIG_IGN
);
168 t
.SetTraceLevel (arg
.tracelevel
);
170 iface
= Create (ag
[index
], &t
);
172 die ("initialisation failed");
174 die ("initialisation failed");
176 addr
= readHex (ag
[index
+ 1]);
177 len
= atoi (ag
[index
+ 2]);
179 int res
= readEMIMem (iface
, addr
, len
, result
);
182 printf ("Read failed");
186 for (int i
= 0; i
< result (); i
++)
187 printf ("%02x ", result
[i
]);