diff options
Diffstat (limited to 'libarmep')
-rwxr-xr-x | libarmep/configuration.c | 22 | ||||
-rw-r--r-- | libarmep/libarmep.h | 8 | ||||
-rw-r--r-- | libarmep/service.c | 43 |
3 files changed, 45 insertions, 28 deletions
diff --git a/libarmep/configuration.c b/libarmep/configuration.c index f6eb9aa..98070cd 100755 --- a/libarmep/configuration.c +++ b/libarmep/configuration.c @@ -126,6 +126,7 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_ }; enum parser parser = ACPP_FIRST; enum parser entry_parser; + int stanza = -1; int index = 0; int copy_pos = 0; int field = 0; @@ -135,6 +136,8 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_ char linebuf[1024]; int no_copy = 0; int ret = 0; + int nope = 0; + int n; if (wch) { strncpy(temp_config, config_filepath, sizeof temp_config - 2); @@ -156,6 +159,8 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_ if (aep_context->count_virtual_channels >= MAX_VIRTUAL_CHANNELS) return -1; ch = &aep_context->vch[aep_context->count_virtual_channels]; + for (n = 0; n < MAX_PROBES; n++) + aep_context->device_paths[n][0] = '\0'; } if (fd < 0) { @@ -227,19 +232,22 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_ break; case APCA_CHECK_DEVPATH: if (entry_parser == ACPP_FIRST) { + copy_pos = 0; + nope = 0; if (c != '/') { if (c != '\n') parser = ACPP_SKIP; continue; } - copy_pos = 1; + aep_context->device_paths[stanza++][copy_pos++] = c; + aep_context->device_paths[stanza][copy_pos] = '\0'; actions = APCA_MATCH_DEVPATH; } break; case APCA_MATCH_DEVPATH: if (parser == ACPP_FIRST) { - if (dev_filepath[copy_pos] != '\0') { + if (dev_filepath[copy_pos] != '\0' || nope) { parser = ACPP_SKIP; actions = APCA_CHECK_DEVPATH; copy_pos = 0; @@ -250,12 +258,10 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_ no_copy = ch == wch; break; } - if (dev_filepath[copy_pos++] != c) { - parser = ACPP_SKIP; - actions = APCA_CHECK_DEVPATH; - copy_pos = 0; - break; - } + aep_context->device_paths[stanza][copy_pos] = c; + if (dev_filepath[copy_pos++] != c) + nope = 1; + aep_context->device_paths[stanza][copy_pos] = '\0'; break; case APCA_PULL_CHANNELS: diff --git a/libarmep/libarmep.h b/libarmep/libarmep.h index dafbe04..10ca101 100644 --- a/libarmep/libarmep.h +++ b/libarmep/libarmep.h @@ -153,8 +153,8 @@ struct interp_tables { struct aep_channel { struct aep *aep; - char channel_name[64]; - char channel_name_pretty[64]; + char channel_name[256]; + char channel_name_pretty[256]; char supply[64]; /* parent channel name */ char colour[16]; /* #xxxxxx HTML-style colour */ char class[16]; /* optional class of power, eg, Soc */ @@ -209,7 +209,7 @@ struct aep { struct aep_context *aep_context; int fd; char name[64]; - char dev_filepath[64]; + char dev_filepath[128]; int index; int head; int tail; @@ -235,8 +235,10 @@ struct aep_context { struct aep_channel vch[MAX_VIRTUAL_CHANNELS]; int count_virtual_channels; int auto_zero; + unsigned int last_scan_sec; char config_filepath[256]; char configuration_name[64]; + char device_paths[MAX_PROBES][256]; int highest; int decimate; int no_correction; 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) { |