From 7f0c804cd6242c93ba2f8c9da44b6e462d0199cf Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Fri, 10 Jan 2020 05:08:51 +0000 Subject: [PATCH 1/6] Add the ability to set a universe to blackout instead via ola_set_dmx Currently untested (cherry picked from commit 54ac1fb6ec9376944b0aec0a8c12f0d1a74243a0) --- examples/ola-client.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/ola-client.cpp b/examples/ola-client.cpp index f6eeab53c9..aa001d2d2e 100644 --- a/examples/ola-client.cpp +++ b/examples/ola-client.cpp @@ -84,6 +84,7 @@ typedef struct { string cmd; // argv[0] string uni_name; // universe name string dmx; // DMX string + bool blackout; ola::port_priority_mode priority_mode; // port priority mode uint8_t priority_value; // port priority value bool list_plugin_ids; @@ -304,6 +305,7 @@ void InitOptions(options *opts) { opts->port_direction = ola::client::OUTPUT_PORT; opts->device_id = INVALID_VALUE; opts->merge_mode = OlaUniverse::MERGE_HTP; + opts->blackout = false; opts->priority_mode = ola::PRIORITY_MODE_INHERIT; opts->priority_value = 0; } @@ -358,6 +360,7 @@ void ParseOptions(int argc, char *argv[], options *opts) { static struct option long_options[] = { {"dmx", required_argument, 0, 'd'}, + {"blackout", no_argument, 0, 'b'}, {"help", no_argument, 0, 'h'}, {"ltp", no_argument, 0, 'l'}, {"name", required_argument, 0, 'n'}, @@ -373,7 +376,7 @@ void ParseOptions(int argc, char *argv[], options *opts) { int option_index = 0; while (1) { - c = getopt_long(argc, argv, "ld:n:u:p:s:hv", long_options, &option_index); + c = getopt_long(argc, argv, "ld:bn:u:p:s:hv", long_options, &option_index); if (c == -1) break; @@ -384,6 +387,9 @@ void ParseOptions(int argc, char *argv[], options *opts) { case 'd': opts->dmx = optarg; break; + case 'b': + opts->blackout = true; + break; case 'h': opts->help = true; break; @@ -656,7 +662,8 @@ void DisplayUniverseMergeHelp(const options &opts) { * Help message for set dmx */ void DisplaySetDmxHelp(const options &opts) { - cout << "Usage: " << opts.cmd << " --universe --dmx \n" + cout << "Usage: " << opts.cmd << " --universe [ --dmx ] " + "[ --blackout ]\n" "\n" "Sets the DMX values for a universe.\n" "\n" @@ -665,6 +672,7 @@ void DisplaySetDmxHelp(const options &opts) { " -d, --dmx Comma separated DMX values, e.g. " "0,255,128 sets first channel to 0, second channel to 255" " and third channel to 128.\n" + " -b, --blackout Send a universe to blackout instead.\n" << endl; } @@ -857,9 +865,16 @@ int SendDmx(OlaClientWrapper *wrapper, const options &opts) { SelectServer *ss = wrapper->GetSelectServer(); OlaClient *client = wrapper->GetClient(); ola::DmxBuffer buffer; - bool status = buffer.SetFromString(opts.dmx); + bool status = false; + if (opts.blackout) { + status = buffer.Blackout(); + } else { + status = buffer.SetFromString(opts.dmx); + } - if (opts.uni < 0 || !status || buffer.Size() == 0) { + // A dmx string and blackout are mutually exclusive + if (opts.uni < 0 || !status || (opts.blackout && !opts.dmx.empty) || + buffer.Size() == 0) { DisplaySetDmxHelp(opts); exit(1); } From 0e260badb1b74eb13c1b3a2bed07c380878bb4d6 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Fri, 10 Jan 2020 05:13:46 +0000 Subject: [PATCH 2/6] Update the man page (cherry picked from commit bdb844efb97c5961223222014dd4bf76f111123b) --- man/ola_set_dmx.1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/man/ola_set_dmx.1 b/man/ola_set_dmx.1 index 0de61b95f7..89f95379bb 100644 --- a/man/ola_set_dmx.1 +++ b/man/ola_set_dmx.1 @@ -4,7 +4,7 @@ ola_set_dmx \- Sets the DMX values for a universe. .SH SYNOPSIS .B ola_set_dmx -\fI--universe --dmx \fR +\fI--universe [ --dmx ] [ --blackout ]\fR .SH DESCRIPTION Sets the DMX values for a universe. .TP @@ -15,3 +15,7 @@ Display this help message and exit. .TP \fB\-d\fR, \fB\-\-dmx\fR Comma separated DMX values, e.g. 0,255,128 sets first channel to 0, second channel to 255 and third channel to 128. +.HP +\fB\-b\fR, \fB\-\-blackout\fR +Send a universe to blackout instead. +.TP From 838a8b6098b8280626db5402be20d7e0c9a520b4 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 14 Jan 2020 15:17:46 +0000 Subject: [PATCH 3/6] Add an extended mode to ola_uni_info showing port counts and RDM device counts too (cherry picked from commit 98704e0bd7b2a50a0512812d62ec395e97b78207) --- examples/ola-client.cpp | 96 +++++++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 22 deletions(-) diff --git a/examples/ola-client.cpp b/examples/ola-client.cpp index aa001d2d2e..76e400114e 100644 --- a/examples/ola-client.cpp +++ b/examples/ola-client.cpp @@ -83,8 +83,9 @@ typedef struct { OlaUniverse::merge_mode merge_mode; // the merge mode string cmd; // argv[0] string uni_name; // universe name - string dmx; // DMX string bool blackout; + string dmx; // DMX string + bool extended; ola::port_priority_mode priority_mode; // port priority mode uint8_t priority_value; // port priority value bool list_plugin_ids; @@ -143,14 +144,18 @@ void ListPorts(const vector &ports, bool input) { /* * This is called when we receive universe results from the client * @param list_ids_only show ids only + * @param extended show extended info about each universe * @param universes a vector of OlaUniverses */ void DisplayUniverses(SelectServer *ss, bool list_ids_only, + bool extended, const Result &result, const vector &universes) { vector::const_iterator iter; + string divider = string(58 + (extended ? 41 : 0), '-'); + if (!result.Success()) { cerr << result.Error() << endl; ss->Terminate(); @@ -162,20 +167,42 @@ void DisplayUniverses(SelectServer *ss, cout << iter->Id() << endl; } } else { - cout << setw(5) << "Id" << "\t" << setw(30) << "Name" << "\t\tMerge Mode" - << endl; - cout << "----------------------------------------------------------" - << endl; + cout << setw(5) << "Id" << "\t" << setw(30) << "Name" << "\t"; + if (extended) { + cout << setw(10); + } else { + // By default keep the double tab for backwards compatibility of anyone + // parsing the shell, not that we'd recommend that + cout << "\t"; + } + cout << "Merge Mode"; + if (extended) { + cout << "\t" << setw(11) << "Input Ports" << "\t" << setw(12) + << "Output Ports" << "\t" << setw(11) << "RDM Devices"; + } + cout << endl; + cout << divider << endl; for (iter = universes.begin(); iter != universes.end(); ++iter) { cout << setw(5) << iter->Id() << "\t" << setw(30) << iter->Name() - << "\t\t" - << (iter->MergeMode() == OlaUniverse::MERGE_HTP ? "HTP" : "LTP") - << endl; + << "\t"; + if (extended) { + cout << setw(10); + } else { + // By default keep the double tab for backwards compatibility of anyone + // parsing the shell, not that we'd recommend that + cout << "\t"; + } + cout << (iter->MergeMode() == OlaUniverse::MERGE_HTP ? "HTP" : "LTP"); + if (extended) { + cout << "\t" << setw(11) << iter->InputPortCount() << "\t" << setw(12) + << iter->OutputPortCount() << "\t" << setw(11) + << iter->RDMDeviceCount(); + } + cout << endl; } - cout << "----------------------------------------------------------" << - endl; + cout << divider << endl; } ss->Terminate(); @@ -298,6 +325,8 @@ void InitOptions(options *opts) { opts->uni = INVALID_VALUE; opts->plugin_id = ola::OLA_PLUGIN_ALL; opts->help = false; + opts->blackout = false; + opts->extended = false; opts->list_plugin_ids = false; opts->list_universe_ids = false; opts->patch_action = ola::client::PATCH; @@ -305,7 +334,6 @@ void InitOptions(options *opts) { opts->port_direction = ola::client::OUTPUT_PORT; opts->device_id = INVALID_VALUE; opts->merge_mode = OlaUniverse::MERGE_HTP; - opts->blackout = false; opts->priority_mode = ola::PRIORITY_MODE_INHERIT; opts->priority_value = 0; } @@ -359,16 +387,17 @@ void ParseOptions(int argc, char *argv[], options *opts) { }; static struct option long_options[] = { - {"dmx", required_argument, 0, 'd'}, {"blackout", no_argument, 0, 'b'}, + {"dmx", required_argument, 0, 'd'}, + {"extended", no_argument, 0, 'e'}, {"help", no_argument, 0, 'h'}, {"ltp", no_argument, 0, 'l'}, {"name", required_argument, 0, 'n'}, {"plugin-id", required_argument, 0, 'p'}, {"state", required_argument, 0, 's'}, + {"universe", required_argument, 0, 'u'}, {"list-plugin-ids", no_argument, 0, LIST_PLUGIN_IDS_OPTION}, {"list-universe-ids", no_argument, 0, LIST_UNIVERSE_IDS_OPTION}, - {"universe", required_argument, 0, 'u'}, {0, 0, 0, 0} }; @@ -384,11 +413,14 @@ void ParseOptions(int argc, char *argv[], options *opts) { switch (c) { case 0: break; + case 'b': + opts->blackout = true; + break; case 'd': opts->dmx = optarg; break; - case 'b': - opts->blackout = true; + case 'e': + opts->extended = true; break; case 'h': opts->help = true; @@ -620,6 +652,7 @@ void DisplayUniverseInfoHelp(const options &opts) { "Shows info on the active universes in use.\n" "\n" " -h, --help Display this help message and exit.\n" + " --extended Show port counts and RDM devices too.\n" " --list-universe-ids List universe Ids only.\n" << endl; } @@ -736,8 +769,8 @@ void DisplayHelpAndExit(const options &opts) { /* * Send a fetch device info request - * @param client the ola client - * @param opts the const options + * @param client the ola client + * @param opts the const options */ int FetchDeviceInfo(OlaClientWrapper *wrapper, const options &opts) { SelectServer *ss = wrapper->GetSelectServer(); @@ -817,11 +850,32 @@ int FetchPluginState(OlaClientWrapper *wrapper, const options &opts) { } +/* + * Send a fetch universe info request + * @param client the ola client + * @param opts the const options + */ +int FetchUniverseInfo(OlaClientWrapper *wrapper, const options &opts) { + SelectServer *ss = wrapper->GetSelectServer(); + OlaClient *client = wrapper->GetClient(); + if (opts.extended && opts.list_universe_ids) { + // These are mutually exclusive + DisplayUniverseInfoHelp(opts); + exit(1); + } + + client->FetchUniverseList(NewSingleCallback(&DisplayUniverses, + ss, + opts.list_universe_ids, + opts.extended)); + return 0; +} + /* * send a set name request * @param client the ola client - * @param opts the const options + * @param opts the const options */ int SetUniverseName(OlaClientWrapper *wrapper, const options &opts) { SelectServer *ss = wrapper->GetSelectServer(); @@ -839,7 +893,7 @@ int SetUniverseName(OlaClientWrapper *wrapper, const options &opts) { /* * send a set name request * @param client the ola client - * @param opts the const options + * @param opts the const options */ int SetUniverseMergeMode(OlaClientWrapper *wrapper, const options &opts) { @@ -960,9 +1014,7 @@ int main(int argc, char *argv[]) { FetchPluginState(&ola_client, opts); break; case UNIVERSE_INFO: - ola_client.GetClient()->FetchUniverseList( - NewSingleCallback(&DisplayUniverses, - ola_client.GetSelectServer(), opts.list_universe_ids)); + FetchUniverseInfo(&ola_client, opts); break; case UNIVERSE_NAME: SetUniverseName(&ola_client, opts); From 5172b76a7eda861128c048c9fad2f18b055159bf Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 14 Jan 2020 15:19:22 +0000 Subject: [PATCH 4/6] Update the man page too (cherry picked from commit 335c657a8f53838effd7815e0543effc0eed7fdc) --- man/ola_uni_info.1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/man/ola_uni_info.1 b/man/ola_uni_info.1 index 1d98df751b..49bc541f92 100644 --- a/man/ola_uni_info.1 +++ b/man/ola_uni_info.1 @@ -9,6 +9,8 @@ displays the universe name and merge mode for the active universes in olad(1). .SH OPTIONS .IP "-h, --help" Display the help message. +.IP "--extended" +Show port counts and RDM devices too. .IP "--list-universe-ids" Just list the universe ids with no additional information. .SH SEE ALSO From 16effcc2970eb3473af624d8cb52e801bbe5be6f Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 20 Jan 2022 12:55:38 +0000 Subject: [PATCH 5/6] Fix the compliation --- examples/ola-client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ola-client.cpp b/examples/ola-client.cpp index 76e400114e..00789773fe 100644 --- a/examples/ola-client.cpp +++ b/examples/ola-client.cpp @@ -927,7 +927,7 @@ int SendDmx(OlaClientWrapper *wrapper, const options &opts) { } // A dmx string and blackout are mutually exclusive - if (opts.uni < 0 || !status || (opts.blackout && !opts.dmx.empty) || + if (opts.uni < 0 || !status || (opts.blackout && !opts.dmx.empty()) || buffer.Size() == 0) { DisplaySetDmxHelp(opts); exit(1); From 232ecd6db5e967c277dd2eabb53553a446c095b1 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 9 Feb 2022 16:45:08 +0000 Subject: [PATCH 6/6] Remove the magic numbers and use a better way of calculating widths onscreen etc --- examples/ola-client.cpp | 69 +++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/examples/ola-client.cpp b/examples/ola-client.cpp index 00789773fe..60878340fb 100644 --- a/examples/ola-client.cpp +++ b/examples/ola-client.cpp @@ -31,6 +31,7 @@ #include +#include #include #include #include @@ -70,6 +71,17 @@ typedef enum { SET_PORT_PRIORITY, } mode; +static const int CONSOLE_TAB_WIDTH = 8; + +static const int PLUGIN_ID_WIDTH = 5; + +static const int UNI_ID_WIDTH = 5; +static const int UNI_NAME_WIDTH = 30; + +static const char UNI_MERGE_MODE[] = "Merge Mode"; +static const char UNI_INPUT_PORTS[] = "Input Ports"; +static const char UNI_OUTPUT_PORTS[] = "Output Ports"; +static const char UNI_RDM_DEVICES[] = "RDM Devices"; typedef struct { mode m; // mode @@ -141,6 +153,15 @@ void ListPorts(const vector &ports, bool input) { } +int OutputColumnTitle(const string title, + const size_t width_override, + const int overall_width) { + int width = std::max(width_override, title.length()); + cout << "\t" << setw(width) << title; + return width + (CONSOLE_TAB_WIDTH - (overall_width % CONSOLE_TAB_WIDTH)); +} + + /* * This is called when we receive universe results from the client * @param list_ids_only show ids only @@ -154,8 +175,6 @@ void DisplayUniverses(SelectServer *ss, const vector &universes) { vector::const_iterator iter; - string divider = string(58 + (extended ? 41 : 0), '-'); - if (!result.Success()) { cerr << result.Error() << endl; ss->Terminate(); @@ -167,36 +186,42 @@ void DisplayUniverses(SelectServer *ss, cout << iter->Id() << endl; } } else { - cout << setw(5) << "Id" << "\t" << setw(30) << "Name" << "\t"; - if (extended) { - cout << setw(10); - } else { + // Pre-set the first title + int divider_width = UNI_ID_WIDTH; + cout << setw(UNI_ID_WIDTH) << "Id"; + divider_width += OutputColumnTitle("Name", UNI_NAME_WIDTH, divider_width); + if (!extended) { // By default keep the double tab for backwards compatibility of anyone // parsing the shell, not that we'd recommend that - cout << "\t"; + // Output an empty title to cover this + divider_width += OutputColumnTitle("", 0, divider_width); } - cout << "Merge Mode"; + divider_width += OutputColumnTitle(UNI_MERGE_MODE, 0, divider_width); if (extended) { - cout << "\t" << setw(11) << "Input Ports" << "\t" << setw(12) - << "Output Ports" << "\t" << setw(11) << "RDM Devices"; + divider_width += OutputColumnTitle(UNI_INPUT_PORTS, 0, divider_width); + divider_width += OutputColumnTitle(UNI_OUTPUT_PORTS, 0, divider_width); + divider_width += OutputColumnTitle(UNI_RDM_DEVICES, 0, divider_width); } cout << endl; + string divider = string(divider_width, '-'); cout << divider << endl; for (iter = universes.begin(); iter != universes.end(); ++iter) { - cout << setw(5) << iter->Id() << "\t" << setw(30) << iter->Name() - << "\t"; - if (extended) { - cout << setw(10); - } else { + cout << setw(UNI_ID_WIDTH) << iter->Id() + << "\t" << setw(UNI_NAME_WIDTH) << iter->Name(); + if (!extended) { // By default keep the double tab for backwards compatibility of anyone // parsing the shell, not that we'd recommend that cout << "\t"; } - cout << (iter->MergeMode() == OlaUniverse::MERGE_HTP ? "HTP" : "LTP"); + cout << "\t" << setw(strlen(UNI_MERGE_MODE)) + << (iter->MergeMode() == OlaUniverse::MERGE_HTP ? "HTP" : "LTP"); if (extended) { - cout << "\t" << setw(11) << iter->InputPortCount() << "\t" << setw(12) - << iter->OutputPortCount() << "\t" << setw(11) + cout << "\t" << setw(strlen(UNI_INPUT_PORTS)) + << iter->InputPortCount() + << "\t" << setw(strlen(UNI_OUTPUT_PORTS)) + << iter->OutputPortCount() + << "\t" << setw(strlen(UNI_RDM_DEVICES)) << iter->RDMDeviceCount(); } cout << endl; @@ -230,11 +255,15 @@ void DisplayPlugins(SelectServer *ss, cout << iter->Id() << endl; } } else { - cout << setw(5) << "Id" << "\tPlugin Name" << endl; + // Leave for backwards compatibility (in case anyone is parsing the shell, + // not that we'd recommend that), but this could use OutputColumnTitle with + // a setw of 30 on the plugin name + cout << setw(PLUGIN_ID_WIDTH) << "Id" << "\tPlugin Name" << endl; cout << "--------------------------------------" << endl; for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - cout << setw(5) << iter->Id() << "\t" << iter->Name() << endl; + cout << setw(PLUGIN_ID_WIDTH) << iter->Id() + << "\t" << iter->Name() << endl; } cout << "--------------------------------------" << endl;