BS_Praktikum4/sensor_network.h

41 lines
976 B
C
Raw Permalink Normal View History

2025-06-03 00:50:08 +02:00
#pragma once
#include <thread>
#include <atomic>
#include <vector>
#include "ring_buffer.h"
#include "analysis_model.h"
/**
* Hauptklasse des Sensornetzwerks
* @tparam N Größe des Ringpuffers
*
* Verwaltet alle Komponenten:
* - Ringpuffer für Sensordaten
* - Analysemodell
* - Threads für Sensoren, Analyse und Controller
*/
2025-06-03 00:50:08 +02:00
template <size_t N>
class SensorNetwork {
RingBuffer<N> buffer; // Gemeinsamer Datenpuffer
AnalysisModel model; // Geteiltes Analysemodell
std::atomic<bool> running{false}; // Steuerflag für Threads
2025-06-03 00:50:08 +02:00
// Thread-Container
2025-06-03 00:50:08 +02:00
std::vector<std::thread> sensors;
std::vector<std::thread> analysers;
std::thread controller;
public:
~SensorNetwork() {
if (running) stop();
}
void start(size_t num_sensors, size_t num_analysers);
void stop();
private:
// Thread-Funktionen
2025-06-03 00:50:08 +02:00
void sensor_thread(int id);
void analyser_thread(int id);
void controller_thread();
};