Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Server Build
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
env:
alpine_url: http://dl-cdn.alpinelinux.org/alpine/v3.20
SKIP_MODLOOP: 1

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: recursive

- name: setup packages
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake ninja-build libconfig++-dev \
libfftw3-dev zlib1g-dev libfdk-aac-dev libgps-dev libunwind-dev \
libsqlite3-dev libcurl4-openssl-dev libssl-dev libconfig++-dev minify

- name: Build
run: |
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_HDFL=OFF ..
cmake --build . --config Release
44 changes: 26 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(UPSTREAM_DIR ${CMAKE_SOURCE_DIR})
find_program(MINIFY_COMMAND NAMES minify)

option(ZYNQ "Build for Zynq7000 serial based WebSDR" ON)
option(RPI "Build for RPI serial based WebSDR" OFF)
option(ENABLE_HDFL "Enable HFDL" ON)

if(NOT CMAKE_BUILD_TYPE)
Expand All @@ -19,25 +18,35 @@ endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_CXX_STANDARD 11)

set(CMAKE_CXX_FLAGS "-Wall -fsingle-precision-constant -pthread")
set(CMAKE_CXX_FLAGS "-Wall -fsingle-precision-constant -ffast-math -pthread")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-g -O3")

set(CMAKE_C_FLAGS "-Wall -fsingle-precision-constant")
set(CMAKE_C_FLAGS "-Wall -fsingle-precision-constant -ffast-math")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
set(CMAKE_C_FLAGS_RELEASE "-g -O3")

set(PLATFORM zynq)
set(PLATFORM_INC ${PLATFORM})
FILE(GLOB PLATFORM_SRCS
"${PLATFORM}/*.cpp"
)

# Detect if host system is ARM
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(PLATFORM_FLAGS -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard -mvectorize-with-neon-quad)
set(PLATFORM_DEFINES
# for CMSIS
ARM_MATH_NEON
ARM_MATH_LOOPUNROLL

if(ZYNQ)
set(PLATFORM zynq)
set(PLATFORM_INC ${PLATFORM})
set(PLATFORM_FLAGS -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard -ffast-math -fsingle-precision-constant -mvectorize-with-neon-quad)
FILE(GLOB PLATFORM_SRCS
"${PLATFORM}/*.cpp"
# for SIMD
__ARM_NEON
)
else()
# Not supported
MESSAGE(FATAL "Not supported")
set(PLATFORM_FLAGS -ffast-math)
set(ENABLE_HFDL OFF)
SET(EMULATOR ON)
endif()

find_package(PkgConfig REQUIRED)
Expand All @@ -52,7 +61,11 @@ pkg_check_modules(SQLite3 REQUIRED sqlite3)
pkg_check_modules(CURL REQUIRED libcurl)
pkg_check_modules(SSL REQUIRED openssl)

set(CONFIG_LIBRARIES "/usr/lib/libconfig++.a")
if (EMULATOR)
pkg_check_modules(CONFIG REQUIRED libconfig++)
else()
set(CONFIG_LIBRARIES "/usr/lib/libconfig++.a")
endif()

find_program(CCACHE_FOUND ccache)

Expand Down Expand Up @@ -259,12 +272,7 @@ target_compile_definitions(websdr.bin PUBLIC
MONGOOSE_USE_EXTRA_HTTP_HEADERS="Access-Control-Allow-Origin: *"
EDATA_EMBED

# for CMSIS
ARM_MATH_NEON
ARM_MATH_LOOPUNROLL

# for SIMD
__ARM_NEON
${PLATFORM_DEFINES}

# Enable SSL
USE_SSL
Expand Down
2 changes: 0 additions & 2 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ typedef enum { ESPEED_AUTO = 0,
#define PROXY_SERVER_HOST "proxy.rx-888.com"
#define PROXY_SERVER_PORT 8073

extern int rx_chans, wf_chans, nrx_bufs, nrx_samps, snd_rate, rx_decim;

// INET6_ADDRSTRLEN (46) plus some extra in case ipv6 scope/zone is an issue
// can't be in net.h due to #include recursion problems
#define NET_ADDRSTRLEN 64
Expand Down
43 changes: 20 additions & 23 deletions extensions/ant_switch/ant_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,13 @@ static void ant_switch_init(int rx_chan)
ext_send_msg(rx_chan, ANT_SWITCH_DEBUG_MSG, "EXT channels=%d", n_ch);
}

int ant_switch_queryantennas()
{
if (antenna_current)
{
// find the first 1
for(int i = 0; i < kiwi.ant_switch_nch; i++)
{
if (antenna_current & (1 << i))
return i + 1;
}
}

return 0;
}

void ant_switch_setantenna(int antenna)
{
if (antenna == 0)
antenna_current = 0;
else
antenna_current |= 1 << (antenna - 1);
antenna_current = 1 << (antenna - 1);

fpga_set_antenna(antenna_current);
return;
}
Expand Down Expand Up @@ -189,20 +175,31 @@ bool ant_switch_msgs(char *msg, int rx_chan)

if (strcmp(msg, "GET Antenna") == 0)
{
int selected_antennas = ant_switch_queryantennas();
ext_send_msg(rx_chan, ANT_SWITCH_DEBUG_MSG, "EXT Antenna=%d", selected_antennas);
char buf[32] = "";
if (antenna_current == 0)
snprintf(buf, sizeof(buf), "0");
else {
for(int i = 0; i < kiwi.ant_switch_nch; i++)
{
if (antenna_current & (1 << i))
sprintf(buf + strlen(buf), "%d,", i + 1);
}
buf[strlen(buf) - 1] = '\0'; // remove trailing comma
}

ext_send_msg(rx_chan, ANT_SWITCH_DEBUG_MSG, "EXT Antenna=%s", buf);

static int last_selected_antennas;
if (selected_antennas != last_selected_antennas)
if (antenna_current != last_selected_antennas)
{
char *s;
if (selected_antennas == 0)
if (antenna_current == 0)
s = (char *)"All antennas now grounded.";
else
s = stprintf("Selected antennas are now: %d", selected_antennas);
s = stprintf("Selected antennas are now: %s", buf);
static u4_t seq;
ext_notify_connected(rx_chan, seq++, s);
last_selected_antennas = selected_antennas;
last_selected_antennas = antenna_current;
}

int deny_reason = 0;
Expand All @@ -225,7 +222,7 @@ bool ant_switch_msgs(char *msg, int rx_chan)
{
ext_send_msg(rx_chan, ANT_SWITCH_DEBUG_MSG, "EXT Thunderstorm=1");
// also ground antenna if not grounded
if (selected_antennas == 0)
if (antenna_current == 0)
{
ant_switch_setantenna(0);
ext_send_msg(rx_chan, ANT_SWITCH_DEBUG_MSG, "EXT Antenna=g");
Expand Down
4 changes: 2 additions & 2 deletions extensions/wspr/wspr_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ void WSPR_Deco(void *param)
wspr_decode_t *dp = &w->deco[i];
if (strcmp(dp->call, "...") == 0) continue;

mqtt_publish("WSPR", "\"call\":\"%s\",\"grid\":\"%s\",\"snr\":%.1f,\"dt\":%.1f,\"drift\":%d,\"freq\":%.6f,\"pwr\":%d",
dp->call, dp->grid, dp->snr, dp->dt_print, (int) dp->drift1, dp->freq_print, (int) dp->pwr);
mqtt_publish("WSPR", "\"call\":\"%s\",\"grid\":\"%s\",\"snr\":%.1f,\"dt\":%.1f,\"drift\":%d,\"freq\":%.6f,\"pwr\":%s",
dp->call, dp->grid, dp->snr, dp->dt_print, (int) dp->drift1, dp->freq_print, dp->pwr);

if (w->autorun) {
asprintf(&cmd, WSPR_SPOT, wspr_c.rcall, wspr_c.rgrid, rqrg, year%100, month, day,
Expand Down
10 changes: 2 additions & 8 deletions gps/gps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@ static void gps_task(void* param);
static void pps_task(void* param);

static void gps_connect() {
struct fixsource_t source;

blocking_system("/etc/init.d/gpsd restart");

gpsd_source_spec(NULL, &source);

if (0 != gps_open(source.server, source.port, &gps_handle)) {
if (0 != gps_open("localhost", "2947", &gps_handle)) {
printf("open gpsd failed\n");
return;
}

int flags = WATCH_ENABLE;
if (source.device != NULL)
flags |= WATCH_DEVICE;
(void)gps_stream(&gps_handle, flags, source.device);
(void)gps_stream(&gps_handle, flags, NULL);
}

void gps_main(int argc, char* argv[]) {
Expand Down
21 changes: 21 additions & 0 deletions init/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,27 @@ static void cfg_test() {

int serial_number;

// Hardware configuration variables
int rx_chans, wf_chans, nrx_samps, snd_rate, rx_decim;
int rx_num, wf_num, monitors_max;

// System configuration variables
int debian_maj, debian_min, bg;
bool need_hardware, create_eeprom;

// System state variables
u4_t ov_mask;
int is_locked, drm_nreg_chans;
bool have_ant_switch_ext, disable_led_task, kiwi_reg_debug;

// GPS configuration variables
int gps_chans = GPS_MAX_CHANS;

void cfg_hw_init() {
// Hardware configuration variables are initialized when hardware is detected
// or set via configuration/command line arguments
}

// only called once from main()
void cfg_reload() {
cfg_init();
Expand Down
19 changes: 19 additions & 0 deletions init/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,22 @@ typedef enum { CFG_OPT_NONE,
CFG_OPT_ID1,
CFG_OPT_ID2,
CFG_OPT_NO_DOT } cfg_lookup_e;

// Hardware configuration variables
extern int rx_chans, wf_chans, nrx_samps, snd_rate, rx_decim;
extern int rx_num, wf_num, monitors_max;

// System configuration variables
extern int debian_maj, debian_min, bg;
extern bool need_hardware, create_eeprom;

// System state variables
extern u4_t ov_mask;
extern int is_locked, drm_nreg_chans;
extern bool have_ant_switch_ext, disable_led_task, kiwi_reg_debug;

// GPS configuration variables
extern int gps_chans;

// Initialize hardware configuration
void cfg_hw_init();
14 changes: 4 additions & 10 deletions kiwi.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,16 @@ extern kiwi_t kiwi;

extern int version_maj, version_min;

extern bool background_mode, need_hardware, any_preempt_autorun,
DUC_enable_start, rev_enable_start, web_nocache, kiwi_reg_debug, cmd_debug,
have_ant_switch_ext, disable_led_task, debug_printfs, force_camp,
extern bool background_mode, any_preempt_autorun,
DUC_enable_start, rev_enable_start, web_nocache, force_camp,
snr_local_time, log_local_ip, DRM_enable, have_snd_users, admin_keepalive;

extern int ev_dump, tone, down, navg, meas, monitors_max,
gps_chans, rx_num, wf_num, bg, dx_print,
port, print_stats, serial_number, ip_limit_mins, is_locked, test_flag, n_camp,
extern int port, serial_number, ip_limit_mins, test_flag, n_camp,
inactivity_timeout_mins, S_meter_cal, waterfall_cal, current_nusers, debug_v,
utc_offset, dst_offset, reg_kiwisdr_com_status, kiwi_reg_lo_kHz, kiwi_reg_hi_kHz,
debian_maj, debian_min, use_foptim, web_caching_debug,
drm_nreg_chans, snr_meas_interval_hrs, snr_all, snr_HF, ant_connected;
web_caching_debug, snr_meas_interval_hrs, snr_all, snr_HF, ant_connected;

extern char** main_argv;

extern u4_t ov_mask;
extern float g_genfreq, g_genampl, g_mixfreq, max_thr;
extern double ui_srate, ui_srate_kHz, freq_offset_kHz, freq_offmax_kHz;
#define freq_offset freq_offset_kHz // ant switch ext compatibility
Expand Down
6 changes: 6 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ Boston, MA 02110-1301, USA.
#define OPTION_DENY_APP_FINGERPRINT_CONN
#define OPTION_EXPERIMENT_CICF
//#define OPTION_HONEY_POT

// Command-line options and runtime settings
extern int tone, down, navg, meas, print_stats, use_foptim;

// Initialize options
void options_init();
9 changes: 9 additions & 0 deletions support/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
#include <stdarg.h>
#include <signal.h>

// Debug variables
int ev_dump = 0, test_flag, dx_print;
bool debug_printfs, cmd_debug;

void debug_init() {
// Debug variables are initialized to their default values above
// or set via command line arguments
}

#ifdef EV_MEAS

typedef struct {
Expand Down
7 changes: 7 additions & 0 deletions support/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,11 @@ void ev(int cmd, int event, int param, const char* s, const char* s2);

char* evprintf(const char* fmt, ...);

// Debug variables
extern int ev_dump, test_flag, dx_print;
extern bool debug_printfs, cmd_debug;

// Initialize debug variables
void debug_init();

#endif
28 changes: 28 additions & 0 deletions support/options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
--------------------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
--------------------------------------------------------------------------------
*/

// Copyright (c) 2014-2022 John Seamons, ZL4VO/KF6VO

#include "options.h"

// Command-line options and runtime settings
int tone, down, navg = 1, meas, print_stats, use_foptim;

void options_init() {
// Options are initialized to their default values above
// or set via command line arguments
}
2 changes: 1 addition & 1 deletion support/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define MINUTES_TO_SEC(min) ((min)*60)
#define SEC_TO_MINUTES(sec) ((sec) / 60)
#define SEC_TO_MSEC(sec) ((sec)*1000)
#define SEC_TO_USEC(sec) ((sec)*1000000)
#define SEC_TO_USEC(sec) ((sec)*1000000LL)
#define MSEC_TO_USEC(msec) ((msec)*1000)

#define TIME_DIFF_MS(now, start) ((float)((now) - (start)) / 1e3)
Expand Down
Loading
Loading