RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi.cpp File Reference
#include "../../Headers/RumPi/RumPi.h"
#include "../../Headers/RumPi/Logger.h"
#include "../../Headers/RumPi/AlertManager.h"
#include "../../Headers/RumPi/RumPiConfig.h"
#include "../../Headers/RumPi/ComponentFactory.h"
#include "../../Headers/RumPi/RemoteCommand.h"
#include "../../Headers/RumPi/Components/Receiver.h"
#include "../../Headers/json.hpp"
#include <atomic>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <csignal>
#include <chrono>
#include <iostream>
#include <fstream>
Include dependency graph for RumPi.cpp:

Namespaces

namespace  RumPi
 RumPi is the library's top-level facade.
 

Functions

static std::vector< RemoteCommand > RumPi::BuildRemoteCommands ()
 Builds the list of commands a remote client can send. More...
 
static void RumPi::ThreadWait (unsigned int milliseconds)
 Sleeps for the requested time, but wakes immediately if the library has been asked to shut down. More...
 
static void RumPi::WriteToConsole (const char *str)
 Writes a line to the console under a lock, so messages from different threads do not interleave. More...
 
static void RumPi::Shutdown (int signalNum)
 SIGINT handler: flips the run flag and wakes the poll loop so it exits promptly. More...
 
static void RumPi::Teardown ()
 Turns components off, frees the component manager (which owns the receiver), and drains and closes the logger. More...
 
static bool RumPi::IsReceiverReady ()
 Reports whether the remote receiver exists and currently has a client connected. More...
 
static void RumPi::StartComponentManagerUpdateLoop ()
 The Start(true) worker loop: repeatedly polls all components, pushes the fresh data to the receiver when a client is connected, then waits the configured delay - until Shutdown()/Stop() flips the run flag. More...
 
static void RumPi::OnMessageReceived (const char *receivedMessage)
 Receiver callback: routes an incoming client message to the first command that matches, then runs that command's handler. More...
 
static nlohmann::json RumPi::LoadConfigJson (const char *path)
 Reads and parses the config file once. More...
 
void RumPi::Initialize ()
 Brings the library up: initializes the logger, loads and validates the configuration, hooks Ctrl+C, sets up WiringPi, creates the component manager, self-assembles the sensors from the manifest, and (if enabled) starts the remote receiver. More...
 
void RumPi::Start (bool runAndUpdateOnSeparateThread)
 Turns on every managed component. More...
 
void RumPi::Stop ()
 Cleanly shuts down after a pull-based Start(false): wakes anything waiting, then tears down (turns components off, frees the component manager, drains and closes the logger). More...
 
void RumPi::AddComponent (BaseComponent *theComponent)
 Adds the provided component to the manager so it is polled and reported alongside the rest. More...
 
int RumPi::GetNumberOfComponents ()
 Gets how many components the manager currently holds. More...
 
void RumPi::UpdateComponents ()
 Polls every managed component once, refreshing the values that GetRawJsonDataFromComponentManager() reports. More...
 
void RumPi::UpdateComponentsOfType (const EComponentType typeOfComponentToUpdate)
 Polls just the components of one type, letting a pull-based consumer sample a fast sensor (e.g. More...
 
std::string RumPi::GetRawJsonDataFromComponentManager ()
 Gets every managed component's current readings as a JSON string, keyed by each component's unique name. More...
 
bool RumPi::GetComponentTypes (std::vector< EComponentType > &outComponentTypes)
 Fills the provided vector with the distinct component types the manager currently holds. More...
 
std::string RumPi::GetLogFilePath ()
 Gets the path of the library's log file, so a client can reveal or open it without hardcoding the path. More...
 
SelectedSensorReadings RumPi::GetSelectedSensorReadings ()
 Gets the curated set of current sensor readings for the Home dashboard, assembled by the ComponentManager. More...
 
static void RumPi::HandleMoveForward (const char *receivedMessage)
 Command handler for the "MoveForward" message from a remote client (placeholder - drives the robot forward). More...
 

Variables

static std::atomic< bool > RumPi::myIsRunning { false }
 
static std::atomic< bool > RumPi::myHasTornDown { false }
 
static ComponentManager * RumPi::myComponentManager = nullptr
 
static std::thread RumPi::myComponentManagerThread
 
static std::mutex RumPi::myDelayLock
 
static std::mutex RumPi::myOutputLock
 
static std::condition_variable RumPi::myDelayCond
 
static Receiver * RumPi::myReceiver = nullptr
 
static std::size_t RumPi::myLoggerSubscriptionId = 0
 
static const std::vector< RemoteCommand > RumPi::myRemoteCommands = BuildRemoteCommands()
 
static const char * RumPi::DEFAULT_LIBRARY_CONFIG_FILE = "RumPiConfig.json"
 
static RumPiConfig RumPi::myLibraryConfig