main: Move code around to let the SIMtrace keep running...
Re-open the USB device, reset the state... handle reconnects of the device.
This commit is contained in:
parent
54683c7b8f
commit
5f9f38378b
45
host/main.c
45
host/main.c
|
@ -123,6 +123,7 @@ static void print_help(void)
|
|||
printf( "\t-i\t--gsmtap-ip\tA.B.C.D\n"
|
||||
"\t-a\t--skip-atr\n"
|
||||
"\t-h\t--help\n"
|
||||
"\t-k\t--keep-running\n"
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
|
@ -131,6 +132,7 @@ static const struct option opts[] = {
|
|||
{ "gsmtap-ip", 1, 0, 'i' },
|
||||
{ "skip-atr", 0, 0, 'a' },
|
||||
{ "help", 0, 0, 'h' },
|
||||
{ "keep-running", 0, 0, 'k' },
|
||||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
@ -165,6 +167,7 @@ int main(int argc, char **argv)
|
|||
int rc;
|
||||
int c, ret = 1;
|
||||
int skip_atr = 0;
|
||||
int keep_running = 0;
|
||||
struct libusb_device_handle *devh;
|
||||
|
||||
print_welcome();
|
||||
|
@ -172,7 +175,7 @@ int main(int argc, char **argv)
|
|||
while (1) {
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, "i:ah", opts, &option_index);
|
||||
c = getopt_long(argc, argv, "i:ahk", opts, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
|
@ -186,6 +189,9 @@ int main(int argc, char **argv)
|
|||
case 'a':
|
||||
skip_atr = 1;
|
||||
break;
|
||||
case 'k':
|
||||
keep_running = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,26 +212,31 @@ int main(int argc, char **argv)
|
|||
if (!as)
|
||||
goto release_exit;
|
||||
|
||||
devh = libusb_open_device_with_vid_pid(NULL, SIMTRACE_USB_VENDOR, SIMTRACE_USB_PRODUCT);
|
||||
if (!devh) {
|
||||
fprintf(stderr, "can't open USB device\n");
|
||||
goto close_exit;
|
||||
}
|
||||
do {
|
||||
devh = libusb_open_device_with_vid_pid(NULL, SIMTRACE_USB_VENDOR, SIMTRACE_USB_PRODUCT);
|
||||
if (!devh) {
|
||||
fprintf(stderr, "can't open USB device\n");
|
||||
goto close_exit;
|
||||
}
|
||||
|
||||
rc = libusb_claim_interface(devh, 0);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "can't claim interface; rc=%d\n", rc);
|
||||
goto close_exit;
|
||||
}
|
||||
rc = libusb_claim_interface(devh, 0);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "can't claim interface; rc=%d\n", rc);
|
||||
goto close_exit;
|
||||
}
|
||||
|
||||
run_mainloop(devh);
|
||||
ret = 0;
|
||||
run_mainloop(devh);
|
||||
ret = 0;
|
||||
|
||||
libusb_release_interface(devh, 0);
|
||||
close_exit:
|
||||
if (devh)
|
||||
libusb_close(devh);
|
||||
if (keep_running)
|
||||
sleep(1);
|
||||
} while (keep_running);
|
||||
|
||||
release_exit:
|
||||
libusb_release_interface(devh, 0);
|
||||
close_exit:
|
||||
if (devh)
|
||||
libusb_close(devh);
|
||||
libusb_exit(NULL);
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue