Skip to content

Commit

Permalink
Added option (-d /dev/spi...) to specify SPI device on command line
Browse files Browse the repository at this point in the history
  • Loading branch information
kersing committed Jul 6, 2018
1 parent 6e523ff commit 9100f65
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions mp_pkt_fwd/src/mp_pkt_fwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ long spi_speed = 6000000;
#else
long spi_speed = SPI_SPEED;
#endif
char *spi_device = NULL;

/* path to logfile */
char *logfile_path = NULL;
Expand Down Expand Up @@ -1158,15 +1159,16 @@ double difftimespec(struct timespec end, struct timespec beginning) {
}

void usage(char *proc_name) {
fprintf(stderr, "Usage: %s [-c config_dir] [-l logfile] [-s spi speed in hz]\n", proc_name);
fprintf(stderr, "Usage: %s [-c config_dir] [-l logfile] [-s spi speed in hz] [-d device file]\n", proc_name);
exit(1);
}

static char *short_options = "c:l:s:h";
static char *short_options = "c:l:s:d:h";
static struct option long_options[] = {
{"config-dir", 1, 0, 'c'},
{"logfile", 1, 0, 'l'},
{"speed", 1, 0, 's'},
{"device", 1, 0, 'd'},
{"help", 0, 0, 'h'},
{0, 0, 0, 0},
};
Expand Down Expand Up @@ -1248,6 +1250,13 @@ int main(int argc, char *argv[])
exit(1);
}
break;
case 'd':
spi_device = strdup(optarg);
if (spi_device == NULL) {
printf("Error: can't save spi_device name\n");
exit(1);
}
break;
default:
usage(proc_name);
break;
Expand Down Expand Up @@ -1356,7 +1365,7 @@ int main(int argc, char *argv[])
/* starting the concentrator */
if (radiostream_enabled == true) {
MSG("INFO: [main] Starting the concentrator\n");
i = lgw_start(spi_speed);
i = lgw_start(spi_speed, spi_device);
if (i == LGW_HAL_SUCCESS) {
MSG("INFO: [main] concentrator started, radio packets can now be received.\n");
} else {
Expand Down

0 comments on commit 9100f65

Please sign in to comment.