Skip to content

Commit

Permalink
Merge pull request #182 from rerdavies/dev
Browse files Browse the repository at this point in the history
v1.2.44 Release
  • Loading branch information
rerdavies authored Aug 29, 2024
2 parents faee210 + a318d92 commit d93b354
Show file tree
Hide file tree
Showing 97 changed files with 4,452 additions and 922 deletions.
7 changes: 4 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
//"[json_variants]" // subtest of your choice, or none to run all of the tests.
//"[inverting_mutex_test]"
// "[utf8_to_utf32]"
"[wifi_channels_test]"
"[updater]"
],

"stopAtEntry": false,
Expand Down Expand Up @@ -258,10 +258,11 @@
"program": "${command:cmake.launchTargetPath}",
"args": [
"--nosudo", // run without sudo (which will fail because of perms, but allow us to debug deeper into install code.)
"--prefix", "/usr",
//"--get-current-port"
// "--uninstall"
"--install"
//"--enable-p2p" , "CA", "PiPedalTest","12345678","14"
"--list-p2p-channels"
//"--list-p2p-channels"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
Expand Down
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
cmake_minimum_required(VERSION 3.16.0)
project(pipedal
VERSION 1.2.41
VERSION 1.2.44
DESCRIPTION "PiPedal Guitar Effect Pedal For Raspberry Pi"
HOMEPAGE_URL "https://rerdavies.github.io/pipedal"
)
set (DISPLAY_VERSION "v1.2.41")

set (DISPLAY_VERSION "PiPedal v1.2.42-Experimental")
set (PACKAGE_ARCHITECTURE "arm64")
set (CMAKE_INSTALL_PREFIX "/usr/")

include(CTest)
enable_testing()

# Frameworks
# catch

add_subdirectory("submodules/pipedal_p2pd")

add_subdirectory("PiPedalCommon")
Expand Down Expand Up @@ -95,14 +92,16 @@ set(CPACK_DEBIAN_PACKAGE_SECTION sound)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "jackd2, hostapd, dhcpcd, dnsmasq" )
set(CPACK_DEBIAN_PACKAGE_DEPENDS "lv2-dev, hostapd, dhcpcd,dnsmasq, authbind" )
set(CPACK_DEBIAN_PACKAGE_DEPENDS "lv2-dev, hostapd, dhcpcd,dnsmasq, authbind, gpg" )
#set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "arm64")
set(CPACK_PACKAGING_INSTALL_PREFIX /usr)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set (CPACK_STRIP_FILES ON)

set(CPACK_DEBIAN_PACKAGE_SIGN_ALGORITHM "detached")
set(CPACK_DEBIAN_PACKAGE_SIGN_TYPE "origin")

set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/debian/postinst;${CMAKE_CURRENT_SOURCE_DIR}/debian/prerm")

Expand Down
41 changes: 36 additions & 5 deletions NetworkManagerP2P/src/NMP2pSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
#include "WifiRegs.hpp"
#include "ChannelInfo.hpp"
#include "DBusLog.hpp"
#include <sys/stat.h>

using namespace pipedal;
P2pSettings::P2pSettings(const std::filesystem::path&configDirectoryPath)
P2pSettings::P2pSettings(const std::filesystem::path&configDirectoryPath, const std::filesystem::path&varDirectoryPath)
: configDirectoryPath(configDirectoryPath),
varDirectoryPath(varDirectoryPath)

{
this->configDirectoryPath = configDirectoryPath;

}

static const char*hexDigits = "0123456789abcdef";
std::string MakeBssid()
{
Expand Down Expand Up @@ -188,12 +191,40 @@ void P2pSettings::Load()
}

}

static void openWithPerms(
std::ofstream &f,
const std::filesystem::path &path,
std::filesystem::perms perms =
std::filesystem::perms::owner_read | std::filesystem::perms::owner_write |
std::filesystem::perms::group_read | std::filesystem::perms::group_write)
{
auto directory = path.parent_path();
std::filesystem::create_directories(directory);
// open and close to make an existing empty file.
// close it.
{
std::ofstream f;
f.open(path);
f.close();
}
// set the perms.
std::filesystem::permissions(
path,
perms,
std::filesystem::perm_options::replace);

// open for re3al.
f.open(path);
}
void P2pSettings::Save()
{
auto filename = config_filename();
try {
std::ofstream f(filename);
if (!f)
std::ofstream f;
openWithPerms(f,filename);

if (!f.is_open())
{
throw std::runtime_error("Can't write to file.");
}
Expand Down
7 changes: 5 additions & 2 deletions NetworkManagerP2P/src/NMP2pSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
class P2pSettings {
// adapter between nm p2p settings, and legacy p2p
public:
P2pSettings(const std::filesystem::path&configDirectory = "/etc/pipedal/config");
P2pSettings(
const std::filesystem::path&configDirectory = "/etc/pipedal/config",
const std::filesystem::path&varDirectory = "/var/pipedal/config" );

void Load();
void Save();

private:
bool valid_ = false;
std::filesystem::path configDirectoryPath;
std::filesystem::path varDirectoryPath;
bool auth_changed_ = true;
std::vector<uint8_t> device_type_{
0x00,0x01, 0x00,0x50,0xF2,0x04, 0x00,0x02 /*"1-0050F204-2";*/
Expand Down Expand Up @@ -59,7 +62,7 @@ class P2pSettings {
};
std::filesystem::path config_filename() const {
// "/etc/pipedal/config/wpa_supplicant/wpa_supplicant-pipedal.conf"; }
return (configDirectoryPath / "NetworkManagerP2P.json").string();
return (varDirectoryPath / "NetworkManagerP2P.json").string();
};

const std::string& bssid() const { return bssid_; }
Expand Down
53 changes: 30 additions & 23 deletions PiPedalCommon/src/ServiceConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* MIT License
*
*
* Copyright (c) 2022 Robin E. R. Davies
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -23,6 +23,7 @@
*/

#include "ServiceConfiguration.hpp"
#include <filesystem>
#include <fstream>
#include <stdexcept>
#include <grp.h>
Expand All @@ -35,43 +36,49 @@ using namespace pipedal;
using namespace std;
using namespace config_serializer;


const char ServiceConfiguration::DEVICEID_FILE_NAME[] = "/etc/pipedal/config/service.conf";
const char ServiceConfiguration::DEVICEID_FILE_NAME[] = "/var/pipedal/config/service.conf";

#define SERIALIZER_ENTRY(MEMBER_NAME) \
new ConfigSerializer<ServiceConfiguration,decltype(ServiceConfiguration::MEMBER_NAME)>(#MEMBER_NAME, &ServiceConfiguration::MEMBER_NAME, "")

new ConfigSerializer<ServiceConfiguration, decltype(ServiceConfiguration::MEMBER_NAME)>(#MEMBER_NAME, &ServiceConfiguration::MEMBER_NAME, "")

static p2p::autoptr_vector<ConfigSerializerBase<ServiceConfiguration>>
deviceIdSerializers
{
SERIALIZER_ENTRY(uuid),
SERIALIZER_ENTRY(deviceName),
SERIALIZER_ENTRY(server_port)
};

deviceIdSerializers{
SERIALIZER_ENTRY(uuid),
SERIALIZER_ENTRY(deviceName),
SERIALIZER_ENTRY(server_port)};

ServiceConfiguration::ServiceConfiguration()
: base(deviceIdSerializers)
: base(deviceIdSerializers)
{

filename = "/var/pipedal/config/service.conf";
}

void ServiceConfiguration::Load()
void ServiceConfiguration::Load(std::filesystem::path filename)
{
base::Load(DEVICEID_FILE_NAME,false);
this->filename = filename;
base::Load(filename, false);
}
void ServiceConfiguration::Save()
{
base::Save(DEVICEID_FILE_NAME);
{
struct group *group_;
auto directory = filename.parent_path();
std::filesystem::create_directories(directory);

// make sure the file has correct permissions.
std::ofstream t;
t.open(filename);
t.close();

struct group *group_;
group_ = getgrnam("pipedal_d");
if (group_ == nullptr)
{
throw logic_error("Group not found: pipedal_d");
}
std::ignore = chown(DEVICEID_FILE_NAME,-1,group_->gr_gid);
std::ignore = chmod(DEVICEID_FILE_NAME, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
std::ignore = chown(DEVICEID_FILE_NAME, -1, group_->gr_gid);
std::ignore = chmod(DEVICEID_FILE_NAME, S_IWUSR | S_IRUSR | S_IRGRP | S_IWGRP | S_IROTH);

}

base::Save(filename);
}
39 changes: 39 additions & 0 deletions PiPedalCommon/src/SysExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,42 @@ int pipedal::sysExecWait(ProcessId pid_)
return exitStatus;

}

SysExecOutput pipedal::sysExecForOutput(const std::string &program, const std::string &args)
{
namespace fs = std::filesystem;
fs::path fullPath = findOnSystemPath(program);
if (!fs::exists(fullPath))
{
throw std::runtime_error(SS("Path does not exist. " << fullPath));
}
std::stringstream s;
s << fullPath.c_str() << " " << args << " 2>&1";

std::string fullCommand = s.str();
FILE *output = popen(fullCommand.c_str(), "r");
if (output)
{
char buffer[512];
std::stringstream ssOutput;

while (!feof(output))
{
size_t nRead = fread(buffer, sizeof(char),sizeof(buffer), output);
ssOutput.write(buffer,nRead);
if (nRead == 0)
break;

}
int rc = pclose(output);
SysExecOutput result
{
.exitCode = rc,
.output = ssOutput.str()
};
return result;
} else {
throw std::runtime_error(SS("Failed to execute command. " << fullCommand ));
}

}
12 changes: 6 additions & 6 deletions PiPedalCommon/src/WifiDirectConfigSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ void WifiDirectConfigSettings::Load()
{
this->enable_ = false;
std::string strEnable;
if (ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","enabled",&strEnable))
if (ConfigUtil::GetConfigLine("/var/pipedal/config/pipedal_p2pd.conf","enabled",&strEnable))
{
this->enable_ = (strEnable == "true" || strEnable == "1");
}
std::string strWlan;
if (ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","wlan",&strWlan))
if (ConfigUtil::GetConfigLine("/var/pipedal/config/pipedal_p2pd.conf","wlan",&strWlan))
{
this->wlan_ = strWlan;
} else {
Expand All @@ -172,20 +172,20 @@ void WifiDirectConfigSettings::Load()



if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","p2p_device_name",&this->hotspotName_))
if (!ConfigUtil::GetConfigLine("/var/pipedal/config/pipedal_p2pd.conf","p2p_device_name",&this->hotspotName_))
{
this->hotspotName_ = "PiPedal";
}

if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","country_code",&this->countryCode_))
if (!ConfigUtil::GetConfigLine("/var/pipedal/config/pipedal_p2pd.conf","country_code",&this->countryCode_))
{
this->countryCode_ = "US";
}
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","p2p_pin",&this->pin_))
if (!ConfigUtil::GetConfigLine("/var/pipedal/config/pipedal_p2pd.conf","p2p_pin",&this->pin_))
{
this->pin_ = "12345678";
}
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","wifiChannel",&this->channel_))
if (!ConfigUtil::GetConfigLine("/var/pipedal/config/pipedal_p2pd.conf","wifiChannel",&this->channel_))
{
this->channel_ = "6";
}
Expand Down
7 changes: 6 additions & 1 deletion PiPedalCommon/src/include/ServiceConfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <string>
#include "ConfigSerializer.hpp"
#include <filesystem>

namespace pipedal {
using namespace config_serializer;
Expand All @@ -38,12 +39,16 @@ namespace pipedal {

static const char DEVICEID_FILE_NAME[];

void Load();
void Load(
std::filesystem::path path = "/var/pipedal/config/service.conf"
);
void Save();


std::string uuid;
std::string deviceName = "PiPedal";
uint32_t server_port = 80;
private:
std::filesystem::path filename;
};
}
Loading

0 comments on commit d93b354

Please sign in to comment.