Skip to content

Commit

Permalink
Merge pull request #816 from fridrich/next
Browse files Browse the repository at this point in the history
Implement option to specify location of index files
  • Loading branch information
AlbrechtL authored Oct 8, 2024
2 parents 2cfac34 + 5459454 commit 528da37
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.10)

project(Welle.Io LANGUAGES C CXX)

Expand All @@ -13,7 +13,7 @@ if(NOT WELLE-IO_VERSION)
endif()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

option(BUILD_WELLE_IO "Build Welle.io" ON )
option(BUILD_WELLE_CLI "Build welle-cli" ON )
Expand Down Expand Up @@ -200,8 +200,8 @@ endif()

if (SOAPYSDR)
find_package(SoapySDR NO_MODULE REQUIRED)
# Note: SoapySDRConfig.cmake sets C++11 standard so it needs to be reset to C++14
set(CMAKE_CXX_STANDARD 14)
# Note: SoapySDRConfig.cmake sets C++11 standard so it needs to be reset to C++17
set(CMAKE_CXX_STANDARD 17)
endif()

include_directories(
Expand Down
17 changes: 15 additions & 2 deletions src/welle-cli/webradiointerface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include "welle-cli/webradiointerface.h"
#include <filesystem>
#include <algorithm>
#include <cmath>
#include <complex>
Expand Down Expand Up @@ -131,13 +132,15 @@ static bool send_http_response(Socket& s, const string& statuscode,

WebRadioInterface::WebRadioInterface(CVirtualInput& in,
int port,
const string &base_dir,
DecodeSettings ds,
RadioReceiverOptions rro) :
dabparams(1),
input(in),
spectrum_fft_handler(dabparams.T_u),
rro(rro),
decode_settings(ds)
decode_settings(ds),
base_dir(base_dir)
{
{
// Ensure that rx always exists when rx_mut is free!
Expand Down Expand Up @@ -563,7 +566,17 @@ bool WebRadioInterface::send_file(Socket& s,
const std::string& filename,
const std::string& content_type)
{
FILE *fd = fopen(filename.c_str(), "r");
std::filesystem::path path_name;
if (!base_dir.empty())
{
path_name = base_dir;
path_name /= filename;
}
else
{
path_name = filename;
}
FILE *fd = fopen(path_name.c_str(), "r");
if (fd) {
if (not send_http_response(s, http_ok, "", content_type)) {
cerr << "Failed to send file headers" << endl;
Expand Down
3 changes: 3 additions & 0 deletions src/welle-cli/webradiointerface.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class WebRadioInterface : public RadioControllerInterface {
WebRadioInterface(
CVirtualInput& in,
int port,
const std::string& base_dir,
DecodeSettings cs,
RadioReceiverOptions rro);
~WebRadioInterface();
Expand Down Expand Up @@ -215,4 +216,6 @@ class WebRadioInterface : public RadioControllerInterface {
std::chrono::time_point<std::chrono::steady_clock> time_change;
};
std::list<ActiveCarouselService> carousel_services_active;

std::string base_dir;
};
9 changes: 7 additions & 2 deletions src/welle-cli/welle-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class RadioInterface : public RadioControllerInterface {
struct options_t {
string soapySDRDriverArgs = "";
string antenna = "";
string base_dir = "";
int gain = -1;
string channel = "10B";
string iqsource = "";
Expand Down Expand Up @@ -314,6 +315,7 @@ static void usage()
endl <<
"Web server mode:" << endl <<
" -w port Enable web server on port <port>." << endl <<
" -b path Base directory of index.html and index.js files." << endl <<
" -C number Number of programmes to decode in a carousel" << endl <<
" (to be used with -w, cannot be used with -D)." << endl <<
" This is useful if your machine cannot decode all programmes" << endl <<
Expand Down Expand Up @@ -409,11 +411,14 @@ options_t parse_cmdline(int argc, char **argv)
options.rro.decodeTII = true;

int opt;
while ((opt = getopt(argc, argv, "A:c:C:dDf:F:g:hp:O:Ps:Tt:uvw:")) != -1) {
while ((opt = getopt(argc, argv, "A:b:c:C:dDf:F:g:hp:O:Ps:Tt:uvw:")) != -1) {
switch (opt) {
case 'A':
options.antenna = optarg;
break;
case 'b':
options.base_dir = optarg;
break;
case 'c':
options.channel = optarg;
break;
Expand Down Expand Up @@ -605,7 +610,7 @@ int main(int argc, char **argv)
return 1;
}

WebRadioInterface wri(*in, options.web_port, ds, options.rro);
WebRadioInterface wri(*in, options.web_port, options.base_dir, ds, options.rro);
wri.serve();
}
else {
Expand Down

0 comments on commit 528da37

Please sign in to comment.