Skip to content

Commit

Permalink
Add --fix-permission and --list-wifi-country-codes options to PiPedal…
Browse files Browse the repository at this point in the history
…Config.
  • Loading branch information
rerdavies committed Nov 21, 2024
1 parent aca9631 commit 33dc523
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,16 @@ add_executable(pipedalconfig
JackServerSettings.hpp JackServerSettings.cpp
SystemConfigFile.hpp SystemConfigFile.cpp
WifiChannelSelectors.cpp WifiChannelSelectors.hpp
Locale.cpp Locale.hpp
asan_options.cpp

)

target_link_libraries(pipedalconfig PRIVATE PiPedalCommon pthread atomic uuid stdc++fs asound
icui18n
icuuc
icudata

)

add_executable(pipedal_latency_test
Expand Down
64 changes: 58 additions & 6 deletions src/ConfigMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "SystemConfigFile.hpp"
#include "ModFileTypes.hpp"
#include "alsaCheck.hpp"
#include "RegDb.hpp"
#include "Locale.hpp"

#include <filesystem>
#include <stdlib.h>
Expand Down Expand Up @@ -1296,6 +1298,11 @@ static void PrintHelp()
<< "\n\n"
<< HangingIndent() << " --list-wifi-channels [<country_code>] \tList valid Wifi channels for the current/specified country."
<< "\n\n"
<< HangingIndent() << " --list-wifi-country-codes\tList valid country codes."
<< "\n\n"

<< HangingIndent() << " --fix-permissions\t"
<< "Set correct permissions on /var/pipedal directories and sub-directories\n\n"

<< Indent(0) << "Country codes:"
<< "\n\n"
Expand All @@ -1307,11 +1314,10 @@ static void PrintHelp()
<< "Without a country code, Wi-Fi must be restricted to channels 1 through 11 "
<< "with reduced amplitude and feature sets."
<< "\n\n"
<< "For the most part, Wi-Fi country codes are taken from the list of ISO 3661 "
<< "2-letter country codes; although there are a handful of exceptions for small "
<< "countries and islands. See the Alpha-2 code column of "
<< "\n\n"
<< Indent(8) << "https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes."
<< " Wi-Fi country codes are taken from the list of ISO 3661 "
<< "2-letter country codes.\n\n"
<< "To see a list of countries and their country codes, run: \n\n"
<< Indent(8) << "pipedalconfig --list-wifi-country-codes"
<< "\n\n";
}

Expand Down Expand Up @@ -1361,6 +1367,41 @@ void RequireNetworkManager()
}
}

void ListValidCountryCodes()
{
RegDb regdb;

auto ccs = regdb.getRegulatoryDomains();

if (ccs.size() == 0)
{
cout << "No regulatory domains found." << endl;
} else {
using pair = std::pair<std::string,std::string>;
std::vector<pair> list;
for (auto &cc: ccs)
{
list.push_back(pair(cc.first,cc.second));
}

auto collator = Locale::GetInstance()->GetCollator();
auto compare = [&collator](
pair &left,
pair &right)
{
return collator->Compare(
left.second, right.second) < 0;
};
std::sort(list.begin(), list.end(), compare);

for (const auto &entry: list)
{
cout << entry.first << " - " << entry.second << endl;
}
}
}


int main(int argc, char **argv)
{
CommandLineParser parser;
Expand All @@ -1383,9 +1424,11 @@ int main(int argc, char **argv)
std::string portOption;
std::string homeNetwork;
bool noEthernet = false;
bool list_wifi_country_codes = false;
bool noWifi = false;

parser.AddOption("--nosudo", &nosudo); // strictly a debugging aid. Run without sudo, until we fail because of permissions.
parser.AddOption("--list-wifi-country-codes",&list_wifi_country_codes);
parser.AddOption("--install", &install);
parser.AddOption("--uninstall", &uninstall);
parser.AddOption("--stop", &stop);
Expand All @@ -1404,12 +1447,16 @@ int main(int argc, char **argv)
parser.AddOption("--no-wifi", &noWifi);
parser.AddOption("--alsa-devices", &alsaDevices);
parser.AddOption("--alsa-device", &alsaDevice);
parser.AddOption("--fix-permissions", &fix_permissions);
try
{
parser.Parse(argc, (const char **)argv);

int actionCount =
(!alsaDevice.empty()) + alsaDevices + help + get_current_port + install + uninstall + stop + start + enable + disable + enable_hotspot + disable_hotspot + restart + enable_p2p + disable_p2p + list_p2p_channels + fix_permissions;
(!alsaDevice.empty()) + alsaDevices + help + get_current_port + install +
uninstall + stop + start + enable + disable + enable_hotspot +
disable_hotspot + restart + enable_p2p + disable_p2p + list_p2p_channels +
fix_permissions + list_wifi_country_codes;
if (actionCount > 1)
{
throw std::runtime_error("Please provide only one action.");
Expand Down Expand Up @@ -1466,6 +1513,11 @@ int main(int argc, char **argv)
PrintHelp();
return EXIT_SUCCESS;
}
if (list_wifi_country_codes)
{
ListValidCountryCodes();
return EXIT_SUCCESS;
}
if (get_current_port)
{
std::cout << "current port: " << GetCurrentWebServicePort() << std::endl;
Expand Down

0 comments on commit 33dc523

Please sign in to comment.