Commit 6be50b9a authored by Lucas Russo's avatar Lucas Russo

examples/*: add more functionalities to examples

parent c2b93b44
......@@ -26,6 +26,10 @@ void print_help (char *program_name)
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-bpm <BPM number = [0|1]>\n"
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-sw <Switching = [0|1]> Start switching counters\n"
"\t-sw_en <Switching enable= [0|1]> Enable switching outputs\n"
"\t-div_clk <Switching divider = [0 to ADC clock period]> Switching clock divider\n"
"\t-sw_dly <Switching/Deswitching delay = [0 to ADC clock period]> Switching/Deswitching delay\n"
, program_name);
}
......@@ -35,6 +39,10 @@ int main (int argc, char *argv [])
char *broker_endp = NULL;
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char *sw_str = NULL;
char *sw_en_str = NULL;
char *div_clk_str = NULL;
char *sw_dly_str = NULL;
char **str_p = NULL;
if (argc < 3) {
......@@ -64,6 +72,18 @@ int main (int argc, char *argv [])
{
str_p = &bpm_number_str;
}
else if (streq (argv[i], "-sw")) {
str_p = &sw_str;
}
else if (streq (argv[i], "-sw_en")) {
str_p = &sw_en_str;
}
else if (streq (argv[i], "-div_clk")) {
str_p = &div_clk_str;
}
else if (streq (argv[i], "-sw_dly")) {
str_p = &sw_dly_str;
}
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
}
......@@ -184,31 +204,56 @@ int main (int argc, char *argv [])
ksum_get);
uint32_t sw = 0;
err = bpm_set_sw (bpm_client, service_swap, sw);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_sw failed\n");
goto err_bpm_set;
if (sw_str != NULL) {
sw = strtoul (sw_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: sw = %u\n", sw);
err = bpm_set_sw (bpm_client, service_swap, sw);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_sw failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_sw was successfully executed\n");
}
fprintf (stdout, "[client:swap]: bpm_set_sw = %u was successfully executed\n",
sw);
uint32_t sw_en = 0;
err = bpm_set_sw_en (bpm_client, service_swap, sw_en);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_sw_en failed\n");
goto err_bpm_set;
if (sw_en_str != NULL) {
sw_en = strtoul (sw_en_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: sw_en = %u\n", sw_en);
err = bpm_set_sw_en (bpm_client, service_swap, sw_en);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_sw_en failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_sw_en was successfully executed\n");
}
fprintf (stdout, "[client:swap]: bpm_set_sw_en = %u was successfully executed\n",
sw_en);
uint32_t div_clk = 250;
err = bpm_set_div_clk (bpm_client, service_swap, div_clk);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:swap]: bpm_set_div_clk failed\n");
goto err_bpm_set;
uint32_t div_clk = 0;
if (div_clk_str != NULL) {
div_clk = strtoul (div_clk_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: div_clk = %u\n", div_clk);
err = bpm_set_div_clk (bpm_client, service_swap, div_clk);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_div_clk failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_div_clk was successfully executed\n");
}
uint32_t sw_dly = 0;
if (sw_dly_str != NULL) {
sw_dly = strtoul (sw_dly_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: sw_dly = %u\n", sw_dly);
err = bpm_set_sw_dly (bpm_client, service_swap, sw_dly);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_sw_dly failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_sw_dly was successfully executed\n");
}
fprintf (stdout, "[client:swap]: bpm_set_div_clk = %u was successfully executed\n",
div_clk);
uint32_t gain_aa = 32768;
uint32_t gain_ac = 32768;
......@@ -244,9 +289,22 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:swap]: bpm_set_gain_d = direct %u, inverted %u was successfully executed\n",
gain_aa, gain_ac);
err_bpm_exit:
err_bpm_get:
err_bpm_set:
bpm_client_destroy (&bpm_client);
str_p = &div_clk_str;
free (*str_p);
div_clk_str = NULL;
str_p = &sw_dly_str;
free (*str_p);
sw_dly_str = NULL;
str_p = &sw_str;
free (*str_p);
sw_str = NULL;
str_p = &sw_en_str;
free (*str_p);
sw_en_str = NULL;
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
......
......@@ -28,11 +28,6 @@ void print_help (char *program_name)
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-pll_status PLL Lock status\n"
"\t-trig_dir <dir> Trigger direction\n"
"\t-clk_sel <sel = [0(FMC front panel)|1(FMC pin)]> Clock selection\n"
"\t-adc_rand <rand = [0|1]> ADC RAND\n"
"\t-adc_dith <dith = [0|1]> ADC DITH\n"
"\t-adc_shdn <shdn = [0|1]> ADC SHDN\n"
"\t-adc_pga <pga = [0|1]> ADC PGA\n"
, program_name);
}
......@@ -43,11 +38,7 @@ int main (int argc, char *argv [])
char *board_number_str = NULL;
char *bpm_number_str = NULL;
char *trig_dir_str = NULL;
char *clk_sel_str = NULL;
char *adc_rand_str = NULL;
char *adc_dith_str = NULL;
char *adc_shdn_str = NULL;
char *adc_pga_str = NULL;
char *trig_term_str = NULL;
uint32_t get_pll_status = 0;
char **str_p = NULL;
......@@ -88,20 +79,8 @@ int main (int argc, char *argv [])
else if (streq (argv[i], "-trig_dir")) {
str_p = &trig_dir_str;
}
else if (streq (argv[i], "-clk_sel")) {
str_p = &clk_sel_str;
}
else if (streq (argv[i], "-adc_rand")) {
str_p = &adc_rand_str;
}
else if (streq (argv[i], "-adc_dith")) {
str_p = &adc_dith_str;
}
else if (streq (argv[i], "-adc_shdn")) {
str_p = &adc_shdn_str;
}
else if (streq (argv[i], "-adc_pga")) {
str_p = &adc_pga_str;
else if (streq (argv[i], "-trig_term")) {
str_p = &trig_term_str;
}
/* Fallout for options with parameters */
else {
......@@ -168,69 +147,17 @@ int main (int argc, char *argv [])
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_trig_dir was successfully executed\n");
}
uint32_t clk_sel = 0;
if (clk_sel_str != NULL) {
clk_sel = strtoul (clk_sel_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: clk_sel = %u\n", clk_sel);
err = bpm_set_fmc_clk_sel (bpm_client, service, clk_sel);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_fmc_clk_sel failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_fmc_clk_sel was successfully executed\n");
}
uint32_t adc_rand = 0;
if (adc_rand_str != NULL) {
adc_rand = strtoul (adc_rand_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: adc_rand = %u\n", adc_rand);
err = bpm_set_adc_rand (bpm_client, service, adc_rand);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_adc_rand failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_adc_rand was successfully executed\n");
}
uint32_t adc_dith = 0;
if (adc_dith_str != NULL) {
adc_dith = strtoul (adc_dith_str, NULL, 10);
uint32_t trig_term = 0;
if (trig_term_str != NULL) {
trig_term = strtoul (trig_term_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: adc_dith = %u\n", adc_dith);
err = bpm_set_adc_dith (bpm_client, service, adc_dith);
fprintf (stdout, "[client:fmc130m_4ch]: trig_term = %u\n", trig_term);
err = bpm_set_trig_term (bpm_client, service, trig_term);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_adc_dith failed\n");
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_trig_term failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_adc_dith was successfully executed\n");
}
uint32_t adc_shdn = 0;
if (adc_shdn_str != NULL) {
adc_shdn = strtoul (adc_shdn_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: adc_shdn = %u\n", adc_shdn);
err = bpm_set_adc_shdn (bpm_client, service, adc_shdn);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_adc_shdn failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_adc_shdn was successfully executed\n");
}
uint32_t adc_pga = 0;
if (adc_pga_str != NULL) {
adc_pga = strtoul (adc_pga_str, NULL, 10);
fprintf (stdout, "[client:fmc130m_4ch]: adc_pga = %u\n", adc_pga);
err = bpm_set_adc_pga (bpm_client, service, adc_pga);
if (err != BPM_CLIENT_SUCCESS){
fprintf (stderr, "[client:fmc130m_4ch]: bpm_set_adc_pga failed\n");
goto err_bpm_exit;
}
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_adc_pga was successfully executed\n");
fprintf (stdout, "[client:fmc130m_4ch]: bpm_set_trig_term was successfully executed\n");
}
if (get_pll_status) {
......@@ -246,18 +173,9 @@ int main (int argc, char *argv [])
err_bpm_exit:
bpm_client_destroy (&bpm_client);
str_p = &adc_pga_str;
free (*str_p);
adc_pga_str = NULL;
str_p = &adc_shdn_str;
free (*str_p);
adc_shdn_str = NULL;
str_p = &adc_dith_str;
free (*str_p);
adc_dith_str = NULL;
str_p = &adc_rand_str;
str_p = &trig_term_str;
free (*str_p);
adc_rand_str = NULL;
trig_term_str = NULL;
str_p = &trig_dir_str;
free (*str_p);
trig_dir_str = 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