static const struct option options[] = {
{ .name = "tty", .has_arg = 1, .val = 'T' },
{ .name = "device", .has_arg = 1, .val = 'D' },
+ { .name = "remote", .has_arg = 1, .val = 'R' },
{ 0, 0, 0, 0},
};
static void usage(char *program)
{
- fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>\n", program);
+ fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] [-R]\n", program);
exit(1);
}
int data[8];
int done;
int column;
+ int remote = 0;
- while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "T:D:R", options, NULL)) != -1) {
switch (c) {
case 'T':
tty = optarg;
case 'D':
device = optarg;
break;
+ case 'R':
+ remote = 1;
+ break;
default:
usage(argv[0]);
break;
}
}
- if (!tty)
- tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
+ if (!tty) {
+ if (remote)
+ tty = cc_usbdevs_find_by_arg(device, "TeleDongle");
+ else
+ tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
+ }
if (!tty)
tty = getenv("ALTOS_TTY");
if (!tty)
cc = cc_usb_open(tty);
if (!cc)
exit(1);
+ if (remote)
+ cc_usb_open_remote(cc);
/* send a 'version' command followed by a 'log' command */
cc_usb_printf(cc, "v\n");
out = NULL;
struct cc_hex_read hex_buf[CC_NUM_HEX_READ];
int hex_count;
+
+ int remote;
};
#define NOT_HEX 0xff
return 1;
}
+void
+cc_usb_open_remote(struct cc_usb *cc)
+{
+ if (!cc->remote) {
+ cc_usb_printf(cc, "p\nE 0\n");
+ do {
+ cc->in_count = cc->in_pos = 0;
+ _cc_usb_sync(cc, 100);
+ } while (cc->in_count > 0);
+ cc->remote = 1;
+ }
+}
+
+void
+cc_usb_close_remote(struct cc_usb *cc)
+{
+ if (cc->remote) {
+ cc_usb_printf(cc, "~");
+ cc->remote = 0;
+ }
+}
+
static struct termios save_termios;
struct cc_usb *
void
cc_usb_close(struct cc_usb *cc)
{
+ cc_usb_close_remote(cc);
+ cc_usb_sync(cc);
tcsetattr(cc->fd, TCSAFLUSH, &save_termios);
close (cc->fd);
free (cc);