Skip to content

Commit

Permalink
Improved device selection and filtering with multiple serial numbers
Browse files Browse the repository at this point in the history
- The function 'captureDataToJson' is updated to accept a set of serial numbers for filtering
- The 'consoleHandler' function is changed to handle multiple serial numbers for device selection
- The type of 'selected_serial' is changed to an array of strings ('selected_serials')
- The logic in 'consoleHandler' is updated to allow the user to enter multiple serial numbers separated by commas
  • Loading branch information
arkadiusz committed Jul 19, 2024
1 parent 34428fa commit 65ae9ed
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "style.hpp"
#include <cmake_git_version/version.hpp>
#include "jasonhandler.hpp"
Expand All @@ -11,18 +10,18 @@
#include <optional>

// Declaration of the functions
nlohmann::json captureDataToJson(const std::map<Omniscope::Id, std::vector<std::pair<double, double>>>& captureData, const std::optional<std::string>& filter_serial = std::nullopt);
nlohmann::json captureDataToJson(const std::map<Omniscope::Id, std::vector<std::pair<double, double>>>& captureData, const std::set<std::string>& filter_serials = {});

// Forward declaration of the consoleHandler function
void consoleHandler(bool &flagInitState, nlohmann::json &config, bool &flagPaused, std::optional<std::string>& selected_serial);
//void consoleHandler(bool &flagInitState, nlohmann::json &config, bool &flagPaused, std::optional<std::string>& selected_serial);

// Conversion function captureDate to JSON
nlohmann::json captureDataToJson(const std::map<Omniscope::Id, std::vector<std::pair<double, double>>>& data, const std::optional<std::string>& filter_serial) {
nlohmann::json captureDataToJson(const std::map<Omniscope::Id, std::vector<std::pair<double, double>>>& data, const std::set<std::string>& filter_serials) {
nlohmann::json jsonData = nlohmann::json::array();

for (const auto& entry : data) {
const Omniscope::Id& id = entry.first;
if (filter_serial.has_value() && id.serial != filter_serial.value()) {
if (!filter_serials.empty() && filter_serials.find(id.serial) == filter_serials.end()) {
continue;
}

Expand All @@ -49,7 +48,7 @@ nlohmann::json captureDataToJson(const std::map<Omniscope::Id, std::vector<std::
}

// Separate function to handle console input
void consoleHandler(bool &flagInitState, nlohmann::json &config, bool &flagPaused, std::optional<std::string>& selected_serial) {
void consoleHandler(bool &flagInitState, nlohmann::json &config, bool &flagPaused, std::set<std::string>& selected_serials) {

Check warning on line 51 in src/main.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-latest-C++ CI

no previous declaration for ‘void consoleHandler(bool&, nlohmann::json_abi_v3_11_2::json&, bool&, std::set<std::__cxx11::basic_string<char> >&)’ [-Wmissing-declarations]
std::string input;
while (true) {
std::cout << "Enter command: ";
Expand All @@ -65,7 +64,13 @@ void consoleHandler(bool &flagInitState, nlohmann::json &config, bool &flagPause
if (!devices.empty()) {
std::cout << "Enter the serial number of the device to select: ";
std::getline(std::cin, input);
selected_serial = input;
selected_serials.clear();
size_t pos = 0;
while ((pos = input.find(',')) != std::string::npos) {
selected_serials.insert(input.substr(0, pos));
input.erase(0, pos + 1);
}
selected_serials.insert(input);
}
else {
std::cout << "No devices found.\n";
Expand Down Expand Up @@ -114,12 +119,12 @@ int main() {
set_json(config);
bool flagPaused{true};
bool flagInitState{true};
std::optional<std::string> selected_serial;
std::set<std::string> selected_serials;

WebSocketHandler wsHandler("ws://localhost:8080/");

// Start console handler thread
std::thread consoleThread(consoleHandler, std::ref(flagInitState), std::ref(config), std::ref(flagPaused), std::ref(selected_serial));
std::thread consoleThread(consoleHandler, std::ref(flagInitState), std::ref(config), std::ref(flagPaused), std::ref(selected_serials));

// main loop
auto render = [&]() {
Expand All @@ -138,7 +143,7 @@ int main() {

if (sampler.has_value() && !flagPaused) {
sampler->copyOut(captureData);
auto jsonData = captureDataToJson(captureData, selected_serial);
auto jsonData = captureDataToJson(captureData, selected_serials);
wsHandler.send(jsonData);
//fmt::print("CaptureData: {}\n", jsonData);
}
Expand Down

0 comments on commit 65ae9ed

Please sign in to comment.