Skip to content
Open
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ add_subdirectory(common)
add_subdirectory(radio)

if (MRC_BUILD)
add_subdirectory(libsystemd)
add_subdirectory(powerdistribution)
add_subdirectory(expansionhub)
endif()
Expand Down
6 changes: 6 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ project(Common)

set (SOURCES
version.cpp
systemd-utils.cpp
)

add_library(Common STATIC ${SOURCES})
Expand All @@ -11,3 +12,8 @@ target_include_directories(Common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_definitions(Common PRIVATE MRC_BUILD_GIT_HASH=${BUILD_CURRENT_GIT_HASH})
target_compile_definitions(Common PRIVATE MRC_BUILD_TIMESTAMP=${BUILD_CURRENT_TIMESTAMP})

if (MRC_BUILD)
target_compile_definitions(Common PRIVATE MRC_DAEMON_BUILD)
target_link_libraries(Common PRIVATE systemd)
endif()
23 changes: 23 additions & 0 deletions common/systemd-utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "systemd-utils.h"

#ifdef MRC_DAEMON_BUILD
#include <systemd/sd-daemon.h>
#endif

void systemd_utils::notify_ready() {
#ifdef MRC_DAEMON_BUILD
sd_notify(0, "READY=1");
#endif
}

void systemd_utils::notify_stopping() {
#ifdef MRC_DAEMON_BUILD
sd_notify(0, "STOPPING=1");
#endif
}

void systemd_utils::notify_status(std::string_view status) {
#ifdef MRC_DAEMON_BUILD
sd_notifyf(0, "STATUS=%s", status.data());
#endif
}
8 changes: 8 additions & 0 deletions common/systemd-utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <string_view>
namespace systemd_utils {
void notify_ready();
void notify_stopping();
void notify_status(std::string_view status);
} // namespace systemd_utils
6 changes: 1 addition & 5 deletions expansionhub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
project(ExpansionHubDaemon)

set(CMAKE_EXE_LINKER_FLAGS "-Wl,--allow-shlib-undefined")

add_executable(ExpansionHubDaemon
main.cpp
PidConstants.cpp
Expand All @@ -16,9 +14,7 @@ add_executable(ExpansionHubDaemon
target_compile_features(ExpansionHubDaemon PRIVATE cxx_std_20)
target_compile_features(ExpansionHubDaemon PRIVATE c_std_17)
wpilib_target_warnings(ExpansionHubDaemon)
target_link_libraries(ExpansionHubDaemon PRIVATE Common wpimath ntcore wpinet wpiutil)
target_link_libraries(ExpansionHubDaemon PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libsystemd.so.0.37.0)
target_include_directories(ExpansionHubDaemon PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/rhsp/include)
target_link_libraries(ExpansionHubDaemon PRIVATE Common wpimath ntcore wpinet wpiutil systemd)

if (MRC_BUILD)
target_compile_definitions(ExpansionHubDaemon PRIVATE MRC_DAEMON_BUILD)
Expand Down
7 changes: 7 additions & 0 deletions expansionhub/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "EnabledState.h"
#include "SystemDUsbMonitor.h"

#include "systemd-utils.h"

struct ExpansionHubState {
uint64_t lastLoop = wpi::util::Now();

Expand Down Expand Up @@ -413,6 +415,8 @@ int main() {
return -1;
}

systemd_utils::notify_ready();

{
#if defined(__linux__) && defined(MRC_DAEMON_BUILD)
int sig = 0;
Expand All @@ -421,6 +425,9 @@ int main() {
(void)getchar();
#endif
}

systemd_utils::notify_stopping();

ntInst.StopClient();
wpi::nt::NetworkTableInstance::Destroy(ntInst);

Expand Down
14 changes: 14 additions & 0 deletions libsystemd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_library(systemd SHARED IMPORTED GLOBAL)

set_target_properties(systemd PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/libsystemd.so.0.37.0"
IMPORTED_SONAME "libsystemd.so.0"
)

target_include_directories(systemd INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}"
)

target_link_options(systemd INTERFACE
"LINKER:--unresolved-symbols=ignore-in-shared-libs"
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions powerdistribution/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "wpi/nt/RawTopic.hpp"
#include "wpi/nt/IntegerTopic.hpp"

#include "systemd-utils.h"

#define NUM_CAN_BUSES 2

static constexpr uint32_t deviceTypeMask = 0x3F000000;
Expand Down Expand Up @@ -226,6 +228,8 @@ int main() {
return -1;
}

systemd_utils::notify_ready();

{
#if defined(__linux__) && defined(MRC_DAEMON_BUILD)
int sig = 0;
Expand All @@ -234,6 +238,9 @@ int main() {
(void)getchar();
#endif
}

systemd_utils::notify_stopping();

ntInst.StopClient();
wpi::nt::NetworkTableInstance::Destroy(ntInst);

Expand Down
7 changes: 7 additions & 0 deletions radio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "wpi/nt/StringTopic.hpp"
#include "wpi/util/StringExtras.hpp"

#include "systemd-utils.h"

struct DataStorage {
wpi::util::Logger logger;
wpi::nt::StringSubscriber teamSubscriber;
Expand Down Expand Up @@ -59,6 +61,8 @@ int main() {
return -1;
}

systemd_utils::notify_ready();

{
#if defined(__linux__) && defined(MRC_DAEMON_BUILD)
int sig = 0;
Expand All @@ -67,6 +71,9 @@ int main() {
(void)getchar();
#endif
}

systemd_utils::notify_stopping();

loopRunner.Stop();
ntInst.StopClient();
wpi::nt::NetworkTableInstance::Destroy(ntInst);
Expand Down
Loading