diff options
Diffstat (limited to 'libarmep/service.c')
-rw-r--r-- | libarmep/service.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/libarmep/service.c b/libarmep/service.c index 798e256..7d569c0 100644 --- a/libarmep/service.c +++ b/libarmep/service.c @@ -22,6 +22,7 @@ #include <linux/serial.h> + void add_pollfd(struct aep_context *aep_context, int fd, int events) { aep_context->pollfds[aep_context->count_pollfds].fd = fd; @@ -174,7 +175,6 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx) struct timeval tv; unsigned char *p; unsigned char c; - char filepath[20]; struct termios tty; struct serial_struct sinfo; int n, m, i, chan; @@ -187,26 +187,32 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx) gettimeofday(&tv, NULL); - /* look for any new devices appearing */ + if (tv.tv_sec == aep_context->last_scan_sec) + goto bail; + + aep_context->last_scan_sec = tv.tv_sec; + + /* look for next device appearing */ + + if (!aep_context->device_paths[aep_context->scan][0]) + goto bail; if (aep_context->aeps[aep_context->scan].fd > 0) goto bail; - sprintf(filepath, "/dev/ttyACM%d", aep_context->scan); - fd = open(filepath, O_RDWR | O_NONBLOCK | O_EXCL | O_NOCTTY); + fd = open(aep_context->device_paths[aep_context->scan], O_RDWR | O_NONBLOCK | O_EXCL | O_NOCTTY); if (fd < 0) goto bail; if (ioctl(fd, TIOCEXCL) < 0) { fprintf(stderr, "Wasn't able to open %s exclusive", - filepath); + aep_context->device_paths[aep_context->scan]); close(fd); goto bail; } - - fprintf(stderr, "+"); + fprintf(stderr, "+ %s\n", aep_context->device_paths[aep_context->scan]); tcflush(fd, TCIOFLUSH); @@ -216,13 +222,13 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx) } if (aep_context->verbose) - fprintf(stderr, "initing %s fd=%d\n", filepath, fd); + fprintf(stderr, "initing %s fd=%d\n", aep_context->device_paths[aep_context->scan], fd); /* enforce suitable tty state */ memset (&tty, 0, sizeof tty); if (tcgetattr (fd, &tty)) { - fprintf(stderr, "tcgetattr failed on %s\n", filepath); + fprintf(stderr, "tcgetattr failed on %s\n", aep_context->device_paths[aep_context->scan]); close(fd); goto bail; } @@ -242,11 +248,11 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx) cfsetospeed(&tty, B115200); tcsetattr(fd, TCSANOW, &tty); - init_aep(aep_context, &aep_context->aeps[aep_context->scan], filepath); + init_aep(aep_context, &aep_context->aeps[aep_context->scan], aep_context->device_paths[aep_context->scan]); - if (configure(aep_context, &aep_context->aeps[aep_context->scan], filepath, + if (configure(aep_context, &aep_context->aeps[aep_context->scan], aep_context->device_paths[aep_context->scan], aep_context->config_filepath, NULL) < 0) { - fprintf(stderr, "config for %s failed\n", filepath); + fprintf(stderr, "config for %s failed\n", aep_context->device_paths[aep_context->scan]); close(fd); goto bail; } @@ -301,12 +307,10 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx) } aep_context->aeps[aep_context->scan].done_config |= 1; + aep_context->scan++; bail: aep_context->scans++; - aep_context->scan++; - if (aep_context->scan == MAX_PROBES) - aep_context->scan = 0; /* if we're waiting to start but saw every channel / probe */ @@ -352,6 +356,10 @@ bail: if (c != aep_context->matched_channel_names) goto post_start; + /* still something expected? */ + if (aep_context->device_paths[aep_context->scan][0]) + goto post_start; + /* tell everyone to start */ fprintf(stderr, "Starting...\n"); @@ -360,11 +368,12 @@ bail: for (m = 0; m <= aep_context->highest; m++) { if (aep_context->aeps[m].fd <= 0 || aep_context->aeps[m].done_config != 3 ) { - fprintf(stderr, "not starting %d fd %d done_config %d\n", m, aep_context->aeps[m].fd, aep_context->aeps[m].done_config); + if (aep_context->verbose) + fprintf(stderr, "not starting %d fd %d done_config %d\n", m, aep_context->aeps[m].fd, aep_context->aeps[m].done_config); continue; } - if (aep_context->verbose) +// if (aep_context->verbose) fprintf(stderr, "sending start to %d\n", m); c = AEPC_START; if (write(aep_context->aeps[m].fd, &c, 1) != 1) { |