Commit 5b3c70a3 authored by Lucas Russo's avatar Lucas Russo

examples/monit*: add BOARD/BPM selection option

This commit, up to 02e6830e, fix #82 github issue.
parent 88e53565
......@@ -11,18 +11,28 @@
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
void print_help (char *program_name)
{
printf( "Usage: %s [options]\n"
"\t-h This help message\n"
"\t-v Verbose output\n"
"\t-b <broker_endpoint> Broker endpoint\n", program_name);
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
, program_name);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char **str_p = NULL;
if (argc < 2) {
......@@ -47,6 +57,13 @@ int main (int argc, char *argv [])
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
}
else if (streq (argv[i], "-board")) { /* board_number: board number */
str_p = &board_number_str;
}
else if (streq(argv[i], "-bpm"))
{
str_p = &bpm_number_str;
}
/* Fallout for options with parameters */
else {
*str_p = strdup (argv[i]);
......@@ -58,6 +75,37 @@ int main (int argc, char *argv [])
broker_endp = strdup ("ipc://"DFLT_BIND_FOLDER);
}
/* Set default board number */
uint32_t board_number;
if (board_number_str == NULL) {
fprintf (stderr, "[client:acq]: Setting default value to BOARD number: %u\n",
DFLT_BOARD_NUMBER);
board_number = DFLT_BOARD_NUMBER;
}
else {
board_number = strtoul (board_number_str, NULL, 10);
}
/* Set default bpm number */
uint32_t bpm_number;
if (bpm_number_str == NULL) {
fprintf (stderr, "[client:leds]: Setting default value to BPM number: %u\n",
DFLT_BPM_NUMBER);
bpm_number = DFLT_BPM_NUMBER;
}
else {
bpm_number = strtoul (bpm_number_str, NULL, 10);
if (bpm_number > MAX_BPM_NUMBER) {
fprintf (stderr, "[client:leds]: BPM number too big! Defaulting to: %u\n",
MAX_BPM_NUMBER);
bpm_number = MAX_BPM_NUMBER;
}
}
char service[50];
snprintf (service, strlen (service)+1, "BPM%u:DEVIO:DSP%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
......@@ -65,7 +113,7 @@ int main (int argc, char *argv [])
}
uint32_t monit_amp;
bpm_client_err_e err = bpm_get_monit_amp_ch0 (bpm_client, "BPM0:DEVIO:DSP0",
bpm_client_err_e err = bpm_get_monit_amp_ch0 (bpm_client, service,
&monit_amp);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch0 failed\n");
......@@ -74,8 +122,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_amp]: monitoring amplitude ch0 = %u\n", monit_amp);
err = bpm_get_monit_amp_ch1 (bpm_client, "BPM0:DEVIO:DSP0",
&monit_amp);
err = bpm_get_monit_amp_ch1 (bpm_client, service, &monit_amp);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch1 failed\n");
goto err_get_monit_amp;
......@@ -83,8 +130,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_amp]: monitoring amplitude ch1 = %u\n", monit_amp);
err = bpm_get_monit_amp_ch2 (bpm_client, "BPM0:DEVIO:DSP0",
&monit_amp);
err = bpm_get_monit_amp_ch2 (bpm_client, service, &monit_amp);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch2 failed\n");
goto err_get_monit_amp;
......@@ -92,8 +138,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_amp]: monitoring amplitude ch2 = %u\n", monit_amp);
err = bpm_get_monit_amp_ch3 (bpm_client, "BPM0:DEVIO:DSP0",
&monit_amp);
err = bpm_get_monit_amp_ch3 (bpm_client, service, &monit_amp);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_amp_ch3 failed\n");
goto err_get_monit_amp;
......@@ -104,6 +149,12 @@ int main (int argc, char *argv [])
err_bpm_client_new:
err_get_monit_amp:
bpm_client_destroy (&bpm_client);
str_p = &board_number_str;
free (*str_p);
board_number_str = NULL;
str_p = &bpm_number_str;
free (*str_p);
bpm_number_str = NULL;
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
......
......@@ -11,18 +11,28 @@
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BPM_NUMBER 0
#define MAX_BPM_NUMBER 1
#define DFLT_BOARD_NUMBER 0
void print_help (char *program_name)
{
printf( "Usage: %s [options]\n"
"\t-h This help message\n"
"\t-v Verbose output\n"
"\t-b <broker_endpoint> Broker endpoint\n", program_name);
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
, program_name);
}
int main (int argc, char *argv [])
{
int verbose = 0;
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char **str_p = NULL;
if (argc < 2) {
......@@ -47,6 +57,13 @@ int main (int argc, char *argv [])
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
}
else if (streq (argv[i], "-board")) { /* board_number: board number */
str_p = &board_number_str;
}
else if (streq(argv[i], "-bpm"))
{
str_p = &bpm_number_str;
}
/* Fallout for options with parameters */
else {
*str_p = strdup (argv[i]);
......@@ -58,6 +75,37 @@ int main (int argc, char *argv [])
broker_endp = strdup ("ipc://"DFLT_BIND_FOLDER);
}
/* Set default board number */
uint32_t board_number;
if (board_number_str == NULL) {
fprintf (stderr, "[client:acq]: Setting default value to BOARD number: %u\n",
DFLT_BOARD_NUMBER);
board_number = DFLT_BOARD_NUMBER;
}
else {
board_number = strtoul (board_number_str, NULL, 10);
}
/* Set default bpm number */
uint32_t bpm_number;
if (bpm_number_str == NULL) {
fprintf (stderr, "[client:leds]: Setting default value to BPM number: %u\n",
DFLT_BPM_NUMBER);
bpm_number = DFLT_BPM_NUMBER;
}
else {
bpm_number = strtoul (bpm_number_str, NULL, 10);
if (bpm_number > MAX_BPM_NUMBER) {
fprintf (stderr, "[client:leds]: BPM number too big! Defaulting to: %u\n",
MAX_BPM_NUMBER);
bpm_number = MAX_BPM_NUMBER;
}
}
char service[50];
snprintf (service, strlen (service)+1, "BPM%u:DEVIO:DSP%u", board_number, bpm_number);
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose, NULL);
if (bpm_client == NULL) {
fprintf (stderr, "[client:acq]: bpm_client could be created\n");
......@@ -65,7 +113,7 @@ int main (int argc, char *argv [])
}
uint32_t monit_pos;
bpm_client_err_e err = bpm_get_monit_pos_x (bpm_client, "BPM0:DEVIO:DSP0",
bpm_client_err_e err = bpm_get_monit_pos_x (bpm_client, service,
&monit_pos);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_x failed\n");
......@@ -74,8 +122,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_pos]: monitoring pos x = %d\n", (int32_t) monit_pos);
err = bpm_get_monit_pos_y (bpm_client, "BPM0:DEVIO:DSP0",
&monit_pos);
err = bpm_get_monit_pos_y (bpm_client, service, &monit_pos);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_y failed\n");
goto err_get_monit_pos;
......@@ -83,8 +130,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_pos]: monitoring pos y = %d\n", (int32_t) monit_pos);
err = bpm_get_monit_pos_q (bpm_client, "BPM0:DEVIO:DSP0",
&monit_pos);
err = bpm_get_monit_pos_q (bpm_client, service, &monit_pos);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_q failed\n");
goto err_get_monit_pos;
......@@ -92,8 +138,7 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:monit_pos]: monitoring pos q = %d\n", (int32_t) monit_pos);
err = bpm_get_monit_pos_sum (bpm_client, "BPM0:DEVIO:DSP0",
&monit_pos);
err = bpm_get_monit_pos_sum (bpm_client, service, &monit_pos);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:acq]: bpm_get_monit_pos_sum failed\n");
goto err_get_monit_pos;
......@@ -104,6 +149,12 @@ int main (int argc, char *argv [])
err_bpm_client_new:
err_get_monit_pos:
bpm_client_destroy (&bpm_client);
str_p = &board_number_str;
free (*str_p);
board_number_str = NULL;
str_p = &bpm_number_str;
free (*str_p);
bpm_number_str = NULL;
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment