IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2011-04-20 13:58:17 (12 years 11 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 2961482cac72ca292ad95a4e6bf53500014279b4 |
Message: | tools: atrf-id option -s to retrieve driver spec, with necessary
infrastructure - include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec): new function to retrieve the local or remote/final driver spec - lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local driver spec - lib/driver.h (struct atrf_driver): new driver function "driver_spec" to retrieve the driver spec - lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a cache for the driver spec - lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the "driver_spec" function - atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command SPEC to retrieve the (final) driver spec - atrf-id/atrf-id.c (usage, main): added option -s to retrieve the driver spec. One -s retrieves the local spec, -s -s the remote/final. |
Files: |
tools/atrf-id/atrf-id.c (3 diffs) tools/atrf-proxy/PROTOCOL (1 diff) tools/atrf-proxy/atrf-proxy.c (1 diff) tools/include/atrf.h (1 diff) tools/lib/atnet.c (4 diffs) tools/lib/atrf.c (3 diffs) tools/lib/driver.h (1 diff) |
Change Details
tools/atrf-id/atrf-id.c | ||
---|---|---|
158 | 158 | |
159 | 159 | static void usage(const char *name) |
160 | 160 | { |
161 | fprintf(stderr, "usage: %s [-d driver[:arg]]\n", name); | |
161 | fprintf(stderr, | |
162 | "usage: %s [-d driver[:arg]] [-s [-s]]\n\n" | |
163 | " -d driver[:arg] use the specified driver (default: %s)\n" | |
164 | " -s print only the local driver specification\n" | |
165 | " -s -s print only the remote driver specification\n" | |
166 | , name, atrf_default_driver_name()); | |
162 | 167 | exit(1); |
163 | 168 | } |
164 | 169 | |
... | ... | |
167 | 172 | { |
168 | 173 | const char *driver = NULL; |
169 | 174 | struct atrf_dsc *dsc; |
175 | int spec_only = 0; | |
170 | 176 | int c; |
171 | 177 | |
172 | while ((c = getopt(argc, argv, "d:")) != EOF) | |
178 | while ((c = getopt(argc, argv, "d:s")) != EOF) | |
173 | 179 | switch (c) { |
174 | 180 | case 'd': |
175 | 181 | driver = optarg; |
176 | 182 | break; |
183 | case 's': | |
184 | spec_only++; | |
185 | break; | |
177 | 186 | default: |
178 | 187 | usage(*argv); |
179 | 188 | } |
... | ... | |
184 | 193 | if (!dsc) |
185 | 194 | return 1; |
186 | 195 | |
187 | show_info(dsc); | |
196 | if (spec_only) { | |
197 | const char *spec = atrf_driver_spec(dsc, spec_only > 1); | |
198 | ||
199 | if (spec) | |
200 | printf("%s\n", spec); | |
201 | else { | |
202 | fprintf(stderr, "can't obtain specification\n"); | |
203 | exit(1); | |
204 | } | |
205 | } else { | |
206 | show_info(dsc); | |
207 | } | |
188 | 208 | |
189 | 209 | atrf_close(dsc); |
190 | 210 |
tools/atrf-proxy/PROTOCOL | ||
---|---|---|
8 | 8 | +[greeting] |
9 | 9 | -message |
10 | 10 | |
11 | SPEC | |
12 | +driver_spec | |
13 | -message | |
14 | ||
11 | 15 | RESET |
12 | 16 | +[comment] |
13 | 17 | -message |
tools/atrf-proxy/atrf-proxy.c | ||
---|---|---|
151 | 151 | { |
152 | 152 | int res; |
153 | 153 | |
154 | if (!strcasecmp(cmd, "spec")) { | |
155 | const char *spec = atrf_driver_spec(dsc, 1); | |
156 | ||
157 | if (spec) | |
158 | return netio_printf(netio, "+%s\n", spec); | |
159 | else | |
160 | return netio_printf(netio, | |
161 | "-can't obtain specification\n"); | |
162 | } | |
154 | 163 | if (!strcasecmp(cmd, "reset")) { |
155 | 164 | atrf_reset(dsc); |
156 | 165 | return netio_printf(netio, "+\n"); |
tools/include/atrf.h | ||
---|---|---|
32 | 32 | const char *atrf_default_driver_name(void); |
33 | 33 | struct atrf_dsc *atrf_open(const char *spec); |
34 | 34 | void atrf_close(struct atrf_dsc *dsc); |
35 | const char *atrf_driver_spec(struct atrf_dsc *dsc, int last); | |
35 | 36 | |
36 | 37 | int atrf_error(struct atrf_dsc *dsc); |
37 | 38 | int atrf_clear_error(struct atrf_dsc *dsc); |
tools/lib/atnet.c | ||
---|---|---|
31 | 31 | struct atnet_dsc { |
32 | 32 | struct netio *netio; |
33 | 33 | int error; |
34 | char *spec; | |
34 | 35 | char reply[1000]; |
35 | 36 | }; |
36 | 37 | |
... | ... | |
192 | 193 | } |
193 | 194 | |
194 | 195 | dsc->error = 0; |
196 | dsc->spec = NULL; | |
195 | 197 | *dsc->reply = 0; |
196 | 198 | |
197 | 199 | return dsc; |
... | ... | |
203 | 205 | struct atnet_dsc *dsc = handle; |
204 | 206 | |
205 | 207 | netio_close(dsc->netio); |
208 | free(dsc->spec); | |
209 | } | |
210 | ||
211 | ||
212 | /* ----- driver specification ---------------------------------------------- */ | |
213 | ||
214 | ||
215 | static const char *atnet_driver_spec(void *handle) | |
216 | { | |
217 | struct atnet_dsc *dsc = handle; | |
218 | ||
219 | if (dialog(dsc, "SPEC") < 0) { | |
220 | dsc->error = 1; | |
221 | return NULL; | |
222 | } | |
223 | free(dsc->spec); | |
224 | dsc->spec = strdup(dsc->reply+1); | |
225 | if (!dsc->spec) { | |
226 | perror("strdup"); | |
227 | exit(1); | |
228 | } | |
229 | return dsc->spec; | |
206 | 230 | } |
207 | 231 | |
208 | 232 | |
... | ... | |
421 | 445 | .name = "net", |
422 | 446 | .open = atnet_open, |
423 | 447 | .close = atnet_close, |
448 | .driver_spec = atnet_driver_spec, | |
424 | 449 | .error = atnet_error, |
425 | 450 | .clear_error = atnet_clear_error, |
426 | 451 | .reset = atnet_reset, |
tools/lib/atrf.c | ||
---|---|---|
24 | 24 | struct atrf_dsc { |
25 | 25 | const struct atrf_driver *driver; |
26 | 26 | void *handle; |
27 | char *spec; | |
27 | 28 | enum atrf_chip_id chip_id; |
28 | 29 | }; |
29 | 30 | |
... | ... | |
164 | 165 | } |
165 | 166 | dsc->driver = driver; |
166 | 167 | dsc->handle = handle; |
168 | if (spec) { | |
169 | dsc->spec = strdup(spec); | |
170 | if (!dsc->spec) { | |
171 | perror("strdup"); | |
172 | exit(1); | |
173 | } | |
174 | } else { | |
175 | dsc->spec= NULL; | |
176 | } | |
167 | 177 | dsc->chip_id = identify(dsc); |
168 | 178 | return dsc; |
169 | 179 | } |
... | ... | |
173 | 183 | { |
174 | 184 | if (dsc->driver->close) |
175 | 185 | dsc->driver->close(dsc->handle); |
186 | free(dsc->spec); | |
176 | 187 | free(dsc); |
177 | 188 | } |
178 | 189 | |
179 | 190 | |
191 | const char *atrf_driver_spec(struct atrf_dsc *dsc, int last) | |
192 | { | |
193 | if (!dsc->spec) | |
194 | return dsc->driver->name; | |
195 | if (!last || !dsc->driver->driver_spec) | |
196 | return dsc->spec; | |
197 | return dsc->driver->driver_spec(dsc->handle); | |
198 | } | |
199 | ||
200 | ||
180 | 201 | void atrf_reset(struct atrf_dsc *dsc) |
181 | 202 | { |
182 | 203 | if (dsc->driver->reset) |
tools/lib/driver.h | ||
---|---|---|
21 | 21 | const char *name; |
22 | 22 | void *(*open)(const char *arg); |
23 | 23 | void (*close)(void *dsc); |
24 | const char *(*driver_spec)(void *dsc); | |
24 | 25 | int (*error)(void *dsc); |
25 | 26 | int (*clear_error)(void *dsc); |
26 | 27 | void (*reset)(void *dsc); |