rs

FTDI serial communication program
git clone git://git.2f30.org/rs
Log | Files | Refs | README | LICENSE

commit 8a4fe8b7d808256d5bf4bc6240fad6018bd7def4
parent a9df8875cf37d79127025fe6178f985b98da8cee
Author: sin <sin@2f30.org>
Date:   Thu, 12 Dec 2013 12:15:20 +0000

Remove -l and -d flags - you can just use -v and -p instead.

Diffstat:
Mrs.1 | 9+--------
Mrs.c | 66++++--------------------------------------------------------------
2 files changed, 5 insertions(+), 70 deletions(-)

diff --git a/rs.1 b/rs.1 @@ -2,7 +2,7 @@ .SH NAME rs \- FTDI serial communication program .SH SYNOPSIS -.B rs [ \-l ] [ \-b baurate] [ \-v vendor ] [ \-p product] [ \-d device ] +.B rs [ \-b baurate ] [ \-v vendorid ] [ \-p productid ] .SH DESCRIPTION .B rs is an FTDI based serial communication program. You need to be root to run it @@ -11,9 +11,6 @@ it defaults to a baudrate of 115200, a vendor ID of 0x0403 and a product ID of 0x6001. To break out of rs use Control-Backlash. .SH OPTIONS .TP -.B \-l -List FTDI devices -.TP .B \-b Set the baudrate .TP @@ -22,7 +19,3 @@ Set the vendor ID .TP .B \-p Set the product ID -.TP -.B \-d -Set the device that you want to use. List the devices first to obtain -the device ID. diff --git a/rs.c b/rs.c @@ -9,12 +9,9 @@ #include "util.h" static struct ftdi_context ftdictx; -static struct ftdi_device_list *devlist; static struct termios tio, savedtio; static int bflag = 0; -static int lflag = 0; -static int dflag = 0; static int vflag = 0; static int pflag = 0; @@ -87,33 +84,9 @@ txrxloop(void) } static void -listdevs(void) -{ - char manufacturer[256]; - char description[256]; - struct ftdi_device_list *iter; - int i; - int ret; - - for (i = 0, iter = devlist; iter; iter = iter->next, i++) { - ret = ftdi_usb_get_strings(&ftdictx, iter->dev, - manufacturer, sizeof(manufacturer), - description, sizeof(description), NULL, 0); - if (ret < 0) - enprintf(EXIT_FAILURE, "ftdi_usb_get_strings: %s\n", - ftdi_get_error_string(&ftdictx)); - - printf("device %d: manufacturer: %s, description: %s, vendor = %04x, product = %04x\n", - i, manufacturer, description, iter->dev->descriptor.idVendor, - iter->dev->descriptor.idProduct); - } -} - -static void usage(void) { - fprintf(stderr, "usage: %s [-l] [-b baudrate] [-v vendor] [-p product] [-d device]\n", argv0); - fprintf(stderr, "\t-l\tList devices\n"); + fprintf(stderr, "usage: %s [ -b baudrate ] [ -v vendorid ] [ -p productid ]\n", argv0); fprintf(stderr, "\t-b\tSet baudrate\n"); fprintf(stderr, "\t-v\tSpecify vendor, defaults to 0x0403\n"); fprintf(stderr, "\t-p\tSpecify product, defaults to 0x6001\n"); @@ -124,27 +97,17 @@ usage(void) int main(int argc, char *argv[]) { - int i; + struct sigaction sa; int baudrate = 115200; - int dev = 0; int ret; - struct sigaction sa; - struct ftdi_device_list *iter; int vendor = 0x0403; int product = 0x6001; ARGBEGIN { - case 'l': - lflag = 1; - break; case 'b': bflag = 1; baudrate = estrtol(EARGF(usage()), 10); break; - case 'd': - dflag = 1; - dev = estrtol(EARGF(usage()), 10); - break; case 'v': vflag = 1; vendor = estrtol(EARGF(usage()), 0); @@ -163,37 +126,17 @@ main(int argc, char *argv[]) ret = ftdi_init(&ftdictx); if (ret < 0) enprintf(EXIT_FAILURE, "failed to initialize ftdi context\n"); + ret = ftdi_set_interface(&ftdictx, INTERFACE_ANY); if (ret < 0) enprintf(EXIT_FAILURE, "ftdi_set_interface: %s\n", ftdi_get_error_string(&ftdictx)); - ret = ftdi_usb_find_all(&ftdictx, &devlist, vendor, product); - if (ret < 0) - enprintf(EXIT_FAILURE, "ftdi_usb_find_all: %s\n", - ftdi_get_error_string(&ftdictx)); - - if (lflag) { - listdevs(); - exit(EXIT_SUCCESS); - } - - if (dflag) { - for (i = 0, iter = devlist; iter; iter = iter->next, i++) { - if (i == dev) { - vendor = iter->dev->descriptor.idVendor; - product = iter->dev->descriptor.idProduct; - break; - } - } - if (!iter) - enprintf(EXIT_FAILURE, "Can't find device %d\n", dev); - } - ret = ftdi_usb_open(&ftdictx, vendor, product); if (ret < 0) enprintf(EXIT_FAILURE, "ftdi_usb_open: %04x:%04x: %s\n", vendor, product, ftdi_get_error_string(&ftdictx)); + ret = ftdi_set_baudrate(&ftdictx, baudrate); if (ret < 0) enprintf(EXIT_FAILURE, "ftdi_set_baudrate: %d: %s\n", @@ -211,6 +154,5 @@ main(int argc, char *argv[]) ttyrestore(); putchar('\n'); ftdi_usb_close(&ftdictx); - ftdi_list_free(&devlist); exit(EXIT_SUCCESS); }