Skip to content

Commit

Permalink
Merge branch 'release/0.12' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
truschival committed Sep 2, 2020
2 parents 4c9178d + aae9f7f commit 424a2a3
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 57 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/)
# Project Name
MESSAGE( STATUS "Running ${CMAKE_COMMAND} v${CMAKE_VERSION}" )
PROJECT(DigitalRooster
VERSION 0.11.1
VERSION 0.12.0
DESCRIPTION "A digital alarm clock and podcast player"
LANGUAGES CXX C
)
Expand Down Expand Up @@ -51,7 +51,9 @@ SET(SYSTEM_TARGET_NAME "Host"
CACHE STRING "Target: {Host|Embedded}")
SET(SETTINGS_FILE_NAME "digitalrooster.json"
CACHE STRING "application configuration file name")
SET(WIFI_INTERFACE "/var/run/wpa_supplicant/wlan0"
SET(WIFI_INTERFACE "wlan0"
CACHE STRING "WIFI interface name")
SET(WPA_CTRL_SOCK "/var/run/wpa_supplicant/wlan0"
CACHE STRING "wpa_supplicant interface contrl socket path")
SET(SETTINGS_PATH "${CMAKE_CURRENT_BINARY_DIR}/settings"
CACHE PATH "application configuration path")
Expand Down
102 changes: 55 additions & 47 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,73 @@
* \brief Template for CMake to create configuration time constants in config.h
*
*************************************************************************************/
#ifndef _CONFIG_H_
#define _CONFIG_H_

/**
* Date Time string when CMake was run
*/
#ifndef CMAKE_BUILD_TIME_STAMP
#define CMAKE_BUILD_TIME_STAMP @CMAKE_CONFIGURATION_TIME@
#endif
#ifndef _CONFIG_H_
#define _CONFIG_H_

/**
* Project version string Major.Minor.Patch
*/
#ifndef CMAKE_PROJECT_NAME
#define CMAKE_PROJECT_NAME @PROJECT_NAME@
#endif

/**
* Project version string Major.Minor.Patch
*/
#ifndef CMAKE_PROJECT_VERSION
#define CMAKE_PROJECT_VERSION @PROJECT_VERSION@
#endif

/**
/**
* Date Time string when CMake was run
*/
#ifndef CMAKE_BUILD_TIME_STAMP
#define CMAKE_BUILD_TIME_STAMP @CMAKE_CONFIGURATION_TIME@
#endif

/**
* Project version string Major.Minor.Patch
*/
#ifndef CMAKE_PROJECT_NAME
#define CMAKE_PROJECT_NAME @PROJECT_NAME@
#endif

/**
* Project version string Major.Minor.Patch
*/
#ifndef CMAKE_PROJECT_VERSION
#define CMAKE_PROJECT_VERSION @PROJECT_VERSION@
#endif

/**
* GIT describe output:
* git -C $SRC_DIR describe --abbrev=8 --dirty
* v0.4.0-1-g47cb4c6a-dirty
*/
#ifndef GIT_DESCRIBE_REV
#define GIT_DESCRIBE_REV @GIT_DESCRIBE_REV@
#define GIT_DESCRIBE_REV @GIT_DESCRIBE_REV@
#endif

/**
* Application configuration file
*/
#ifndef CMAKE_SETTINGS_FILE_NAME
#define CMAKE_SETTINGS_FILE_NAME @SETTINGS_FILE_NAME@
#endif

/**
* Application configuration file
*/
#ifndef CMAKE_SETTINGS_FILE_NAME
#define CMAKE_SETTINGS_FILE_NAME @SETTINGS_FILE_NAME@
#endif

/**
* Directory where to find SETTINGS_FILE_NAME
*/
#ifndef CMAKE_SETTINGS_PATH
#define CMAKE_SETTINGS_PATH @SETTINGS_PATH@
#endif
/**
* Directory where to find SETTINGS_FILE_NAME
*/
#ifndef CMAKE_SETTINGS_PATH
#define CMAKE_SETTINGS_PATH @SETTINGS_PATH@
#endif

/**
* Build directory to find and generate files during tests
*/
#ifndef CMAKE_BUILD_DIR
#define CMAKE_BUILD_DIR @CMAKE_BINARY_DIR@
#endif
/**
* Build directory to find and generate files during tests
*/
#ifndef CMAKE_BUILD_DIR
#define CMAKE_BUILD_DIR @CMAKE_BINARY_DIR@
#endif

/**
* Wifi Interface on target
*/
#ifndef WIFI_INTERFACE_PATH
#define WIFI_INTERFACE_PATH @WIFI_INTERFACE@

#ifndef WIFI_INTERFACE_NAME
#define WIFI_INTERFACE_NAME @WIFI_INTERFACE@
#endif

/**
* Wpa supplicant socket path
*/
#ifndef WPA_SOCK
#define WPA_SOCK @WPA_CTRL_SOCK@
#endif

/**
Expand All @@ -72,4 +80,4 @@
#endif


#endif /* _CONFIG_H_ */
#endif /* _CONFIG_H_ */
4 changes: 2 additions & 2 deletions documentation/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ listed the script [buildscripts/build_local.sh](../buildscripts/build_local.sh)
- `-DBUILD_GTEST_FROM_SRC=On` download GoogleTest and build it from source
(`OFF` requires gtest as external project)

- `-DTEST_COVERAGE=Off` code coverage

- `-DREST_API=On` provide a REST API for json configuration

- `-DREST_API_PORT=6666` Default TCP listen port for REST API

- `-DPROFILING=On` profiling build for Visual Studio

- `-DTEST_COVERAGE=Off` code coverage

The following commands will checkout the sources to `/tmp/checkout/`, create a
build directory in `/tmp/build/` configure and build DigitalRooster.

Expand Down
14 changes: 13 additions & 1 deletion include/appconstants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ const QString KEY_TIMESTAMP("timestamp");
*/
const QString KEY_WPA_SOCKET_NAME("wpa_ctrl");

/**
* key for wpa control interface socket
*/
const QString KEY_WIFI_DEV_NAME("net_dev");

/**
* Directory for all downloaded RSS Files
*/
Expand Down Expand Up @@ -294,10 +299,17 @@ const QString PROJECT_BUILD_TIME(STR_VALUE(CMAKE_BUILD_TIME_STAMP));
* Json file name for configuration
*/
const QString CONFIG_JSON_FILE_NAME(STR_VALUE(CMAKE_SETTINGS_FILE_NAME));

/**
* WIFI interface
*/
const QString WPA_CONTROL_SOCKET_PATH(STR_VALUE(WIFI_INTERFACE_PATH));
const QString WIFI_NET_DEV_NAME(STR_VALUE(WIFI_INTERFACE_NAME));

/**
* WPA supplicant Control socket
*/
const QString WPA_CONTROL_SOCKET_PATH(STR_VALUE(WPA_SOCK));


/**
* Port for REST API
Expand Down
13 changes: 12 additions & 1 deletion include/configuration_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <QString>
#include <QTimer>

#include <chrono>
#include <atomic>
#include <chrono>
#include <memory>
#include <vector>

Expand Down Expand Up @@ -146,6 +146,12 @@ class ConfigurationManager : public QObject,
*/
virtual QString get_wpa_socket_name() const;

/**
* Network interface name
* @return "wlan0"
*/
virtual QString get_net_dev_name() const;

/**
* Read full configuration file path
* @return path to configuration file
Expand Down Expand Up @@ -303,6 +309,11 @@ public slots:
*/
QString wpa_socket_name;

/**
* Wifi Network device name
*/
QString net_dev_name;

/**
* Check if config and path exist, otherwise create default config file at
* that location
Expand Down
100 changes: 100 additions & 0 deletions include/networkinfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/******************************************************************************
* \filename
* \brief Get basic network information
*
* \details
*
* \copyright (c) 2018 Thomas Ruschival <thomas@ruschival.de>
* \license {This file is licensed under GNU PUBLIC LICENSE Version 3 or later
* SPDX-License-Identifier: GPL-3.0-or-later}
*
*****************************************************************************/

#ifndef _NETWORKINFO_HPP_
#define _NETWORKINFO_HPP_

#include <QObject>

namespace DigitalRooster {

/**
* Small wrapper class around QNetworkInterface et. al
* to conveniently access current IP address and interface status
*/
class NetworkInfo : public QObject {
Q_OBJECT
Q_PROPERTY(QString ipaddr READ get_ip_addr NOTIFY ip_addr_changed)
Q_PROPERTY(bool linkstatus READ get_link_status NOTIFY link_status_changed)
public:
/**
* Default Constructor
*/
explicit NetworkInfo(QObject* parent = nullptr);

/**
* Constructor setting interface name
* @param name os-name of interface (wlan0, wlp2s0)
*/
explicit NetworkInfo(QString name, QObject* parent = nullptr);
~NetworkInfo() = default;

/**
* access WIFI interface IP address
* @return Ip address formatted as QString
*/
QString get_ip_addr() const {
return ip_addr;
};

/**
* access WIFI interface link status (up/down)
* @return link status
*/
bool get_link_status() const {
return if_state;
};

signals:
/**
* IP address has changed (currently not emitted)
*/
void ip_addr_changed(QString addr);

/**
* Link status has changed (currently not emitted)
*/
void link_status_changed(bool up);

private:
/**
* Interface name to watch
*/
QString ifname = {"wlan0"};

/**
* current ip address
*/
QString ip_addr;
/**
* current interface state (up/down)
*/
bool if_state = false;

/**
* Timer Event (QObject timer) for cyclic polling of interface
*/
int evt_timer_id = -1;
private slots:
/**
* updates network info
*/
void update_net_info();
/**
* React to QObject Timer events
* @param evt
*/
void timerEvent(QTimerEvent* evt) override;
};

} // namespace DigitalRooster
#endif /* _NETWORKINFO_HPP_ */
2 changes: 2 additions & 0 deletions libsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ SET(SRCS
${CMAKE_CURRENT_SOURCE_DIR}/sleeptimer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hardware_configuration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/networkinfo.cpp
)

if(${SYSTEM_TARGET_NAME} STREQUAL "Embedded" )
Expand Down Expand Up @@ -92,6 +93,7 @@ SET(MOC_SRC
${PROJECT_INCLUDE_DIR}/wifi_control.hpp
${PROJECT_INCLUDE_DIR}/sleeptimer.hpp
${PROJECT_INCLUDE_DIR}/hardware_control.hpp
${PROJECT_INCLUDE_DIR}/networkinfo.hpp
)

#------------------------------
Expand Down
11 changes: 10 additions & 1 deletion libsrc/configuration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ ConfigurationManager::ConfigurationManager(
, brightness_act(DEFAULT_BRIGHTNESS)
, config_file(configpath)
, application_cache_dir(cachedir)
, wpa_socket_name(WPA_CONTROL_SOCKET_PATH) {
, wpa_socket_name(WPA_CONTROL_SOCKET_PATH)
, net_dev_name(WIFI_NET_DEV_NAME) {
qCDebug(CLASS_LC) << Q_FUNC_INFO;

/*
Expand Down Expand Up @@ -193,6 +194,7 @@ void ConfigurationManager::parse_json(const QByteArray& json) {

wpa_socket_name =
appconfig[KEY_WPA_SOCKET_NAME].toString(WPA_CONTROL_SOCKET_PATH);
net_dev_name = appconfig[KEY_WIFI_DEV_NAME].toString(WIFI_NET_DEV_NAME);
/* Read subsections */
read_radio_streams(appconfig);
read_podcasts(appconfig);
Expand Down Expand Up @@ -374,6 +376,7 @@ void ConfigurationManager::store_current_config() {
static_cast<qint64>(global_alarm_timeout.count());
appconfig[KEY_SLEEP_TIMEOUT] = static_cast<qint64>(sleep_timeout.count());
appconfig[KEY_WPA_SOCKET_NAME] = wpa_socket_name;
appconfig[KEY_WIFI_DEV_NAME] = net_dev_name;
appconfig[KEY_VOLUME] = volume;
appconfig[KEY_BRIGHTNESS_SB] = brightness_sb;
appconfig[KEY_BRIGHTNESS_ACT] = brightness_act;
Expand Down Expand Up @@ -461,6 +464,12 @@ QString ConfigurationManager::get_wpa_socket_name() const {
return wpa_socket_name;
}

/*****************************************************************************/
QString ConfigurationManager::get_net_dev_name() const {
qCDebug(CLASS_LC) << Q_FUNC_INFO;
return net_dev_name;
}

/*****************************************************************************/
QString ConfigurationManager::check_and_create_config() {
qCDebug(CLASS_LC) << Q_FUNC_INFO;
Expand Down
Loading

0 comments on commit 424a2a3

Please sign in to comment.