#include "sensor_network.h" #include #include #include template void SensorNetwork::start(size_t sensors, size_t analysers) { running = true; // Sensor threads for (size_t i = 0; i < sensors; ++i) { threads.emplace_back([this] { std::mt19937 gen(std::random_device{}()); std::uniform_int_distribution<> dist(0, 100); while (running) { std::this_thread::sleep_for(std::chrono::milliseconds(100 + gen() % 400)); buffer.push(dist(gen)); } }); } // Analyser threads for (size_t i = 0; i < analysers; ++i) { threads.emplace_back([this] { while (running) { int data = buffer.pop(); int model_val = model.read(); std::cout << "Data: " << data << " Model: " << model_val << "\n"; } }); } // Controller thread threads.emplace_back([this] { std::mt19937 gen(std::random_device{}()); while (running) { std::this_thread::sleep_for(std::chrono::milliseconds(500 + gen() % 1500)); model.write(gen() % 100); } }); } template void SensorNetwork::stop() { running = false; for (auto& t : threads) { if (t.joinable()) t.join(); } } template class SensorNetwork<8>; template class SensorNetwork<16>; template class SensorNetwork<32>;