Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
97249cd
working on passing and processing commands through terminal
annhypen Mar 1, 2026
0bd849c
added toStringAll(), clear(), and size() to the command processing; n…
annhypen Mar 1, 2026
047401d
added printAll method in dataBuffer to print the buffer contents to t…
annhypen Mar 1, 2026
0a2b78e
added sensorID and sensor name in panorama defines
annhypen Mar 7, 2026
7a04ff6
initial creation data filter
henovw Mar 21, 2026
72385fc
Merge remote-tracking branch 'origin/main' into data-filters
henovw Mar 21, 2026
6cd21d5
Tracks and prints data recieved per secodn - also merged to start of …
henovw Mar 28, 2026
5ede9a2
to fix enter info
henovw Apr 11, 2026
ee8c27c
Added post_processing files
annhypen Mar 28, 2026
8eac292
Fixed a deadlock in reset method
annhypen Mar 28, 2026
8ef93a6
initial creation data filter
henovw Mar 21, 2026
91c3252
working on passing and processing commands through terminal
annhypen Mar 1, 2026
191c86b
added toStringAll(), clear(), and size() to the command processing; n…
annhypen Mar 1, 2026
08b4aa6
added printAll method in dataBuffer to print the buffer contents to t…
annhypen Mar 1, 2026
f579dd3
Implemented adding offset and scaling through terminal
annhypen Mar 28, 2026
c816848
Added post_processing files
annhypen Mar 28, 2026
0c97d4d
Fixed a deadlock in reset method
annhypen Mar 28, 2026
327f2b3
Removed firmware cache files and updated gitignore
aexzhou Mar 14, 2026
4e4c0c8
Add ESP32 AP TCP connection
aexzhou Mar 21, 2026
50eafc5
Added ESP32 scanning ability
aexzhou Mar 21, 2026
1ee6c86
Fixed merge conflict issues
aexzhou Mar 21, 2026
c378e66
working on passing and processing commands through terminal
annhypen Mar 1, 2026
019277f
added toStringAll(), clear(), and size() to the command processing; n…
annhypen Mar 1, 2026
18f5214
Implemented adding offset and scaling through terminal
annhypen Mar 28, 2026
c01e706
Fixed a deadlock in reset method
annhypen Mar 28, 2026
b2adc45
fixed redeclarations errors
annhypen Apr 11, 2026
2f2e07c
fixed merge conflicts
annhypen Apr 11, 2026
75e4cfa
Merge remote-tracking branch 'origin/post_processing' into RefreshRat…
annhypen Apr 11, 2026
404d914
Fixed redeclarations
annhypen Apr 11, 2026
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ __pycache__/
firmware/panorama/.cache/

# Runtime directory
rundir/
rundir/


# Firmware related:
firmware/panorama/.cache/
8 changes: 7 additions & 1 deletion client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ file(GLOB CLIENT_HEADERS CONFIGURE_DEPENDS include/client/*.hpp include/client/*
set(WXMATHPLOT_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(external/wxMathPlot_0.2.0/mathplot)

option(BENCHMARK "ENABLE" OFF)

if (BENCHMARK)
add_compile_definitions(BENCHMARK)
endif()

# Executable settings
if(APPLE)
add_executable(panorama-client MACOSX_BUNDLE ${CLIENT_SOURCES} ${COMMON_HEADERS} ${CLIENT_HEADERS})
Expand Down Expand Up @@ -79,7 +85,7 @@ if(APPLE)

message(STATUS "Using wxWidgets prebuilt from ${WXWIDGETS_PREBUILT_PATH}")
else() # linux


find_program(wxWidgets_CONFIG_EXECUTABLE wx-config)
#set(wxWidgets_CONFIG_EXECUTABLE "${WXWIDGETS_PREBUILT_PATH}/bin/wx-config")
Expand Down
2 changes: 2 additions & 0 deletions client/include/client/DataBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class DataBuffer : public BufferBase<buffer_data_t> {

std::string toStringAll();

void printAll();

void exportBuffer(std::string exportPath);

private:
Expand Down
2 changes: 1 addition & 1 deletion client/include/client/buffer_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ class BufferBase {
std::list<T> buffer_;
mutable std::mutex mutex_;
int MAX_BUFFER_SIZE = 500;
int FLUSH_THRESHOLD = 50; //percentage
int FLUSH_THRESHOLD = 100; //percentage
};
25 changes: 25 additions & 0 deletions client/include/client/command_processor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "client/DataBuffer.hpp"
#include "client/post_processing.hpp"

#include <string>
#include <iostream>
#include <atomic>
#include <memory>

class CommandProcessor {
public:
CommandProcessor(std::shared_ptr<DataBuffer> dataBuffer, std::shared_ptr<PostProcessing> postProcessor);
void start(); //run command loop
void stop();

private:
std::shared_ptr<DataBuffer> dataBuffer_;
std::shared_ptr<PostProcessing> postProcessor_;
std::string command;
std::atomic<bool> running_{true};

void processCommand(const std::string& command);
};

21 changes: 21 additions & 0 deletions client/include/client/data_filters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <iostream>
#include <vector>
#include <deque>

class DataFilters {
public:
DataFilters();

int KalmanFilter(double input);
double MovingAverageFilter(double input);

private:
size_t MAX_KALMAN_SIZE = 10;
std::vector<double> kalmanList;

size_t MAX_MOVINGAVERAGE = 10;
std::deque<double> movingAverageList;

};
6 changes: 5 additions & 1 deletion client/include/client/graph_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#include <vector>
#include <set>
#include <string>
#include <memory>
#include "client/post_processing.hpp"

class GraphPanel : public wxPanel {
public:
GraphPanel(wxWindow* parent);
GraphPanel(wxWindow* parent, std::shared_ptr<PostProcessing> postProcessor);

void AddDataPoint(const std::string& sensorName, double value, double timestamp);
void SetVisibleSensors(const std::set<std::string>& visisble);
Expand All @@ -30,4 +32,6 @@ class GraphPanel : public wxPanel {
void UpdateGraph();

wxDECLARE_EVENT_TABLE();

std::shared_ptr<PostProcessing> postProcessor_;
};
10 changes: 8 additions & 2 deletions client/include/client/mainframe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#include <wx/socket.h>
#include <vector>
#include <memory>
#include <atomic>
#include <map>
#include <atomic>
#include "client/sensor_data_panel.h"
#include "client/sensor_manager.hpp"
#include "client/sensor.hpp"
#include "client/graph_panel.hpp"
#include "client/post_processing.hpp"
#include <set>

class MessageModel;
Expand Down Expand Up @@ -45,7 +47,7 @@ class MainFrame : public wxFrame {
};

MainFrame(const wxString& title, std::shared_ptr<MessageModel> model,
std::shared_ptr<DataBuffer> dataBuffer,
std::shared_ptr<DataBuffer> dataBuffer, std::shared_ptr<PostProcessing> postProcessor,
TcpClient* tcpClient,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxSize(1200, 800));
Expand Down Expand Up @@ -91,12 +93,16 @@ class MainFrame : public wxFrame {

void OnUpdateTimer(wxTimerEvent& event);

std::shared_ptr<PostProcessing> postProcessor_;

// Auto detecting ESP32s
std::unique_ptr<Esp32Scanner> esp32Scanner_;
wxPanel* esp32Banner_ = nullptr;
wxBoxSizer* mainSizer_ = nullptr;
std::atomic<bool> esp32BannerPending_{false};
bool esp32BannerVisible_ = false;
bool esp32BannerVisible_ = false;


};

#endif // __MAINFRAME__
21 changes: 21 additions & 0 deletions client/include/client/post_processing.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <mutex>
#include <iostream>
#include <list>

class PostProcessing {
public:
PostProcessing();
float processData(float data);
void reset();
void addOffset(float offset);
void addScaling(float scaleFactor);
void updateDataBase();

private:
float currentOffset = 0.0;
float currentScaleFactor = 1.0;
std::mutex mutex_;

};
10 changes: 10 additions & 0 deletions client/include/client/tcp_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ class TcpClient {
std::atomic<bool> running_;
std::thread clientThread_;



#ifdef _WIN32
unsigned long long socket_; // SOCKET type on Windows
#else
int socket_;
#endif

#ifdef BENCHMARK
// track bitrate
std::time_t prevRefresh_ = std::time(nullptr);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use std::chrono::steady_clock and duration_cast<milliseconds> for rate measurements - leaving this as a reference for potential future improvement :)

double dataPerSecond_ = 0.0;
int dataCount_ = 0;

#endif
};

#endif
54 changes: 38 additions & 16 deletions client/src/DataBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,18 @@ DataBuffer::~DataBuffer() {
}

void DataBuffer::writeData(buffer_data_t jsonChunk) {
// Append the new chunk of raw JSON data to the buffer. This functions only job is to store raw
// inbound data in a way that doesn't lose anything later the parser will call extractNextJson()
// parseNextJson()
// std::cout << "[DataBuffer] Writing data to buffer:" << std::endl;
// std::cout << "[DataBuffer] a: '" << jsonChunk.a << "' a_data: " << jsonChunk.a_data << std::endl;
// std::cout << "[DataBuffer] b: '" << jsonChunk.b << "' b_data: " << jsonChunk.b_data << std::endl;
// std::cout << "[DataBuffer] Buffer size before write: " << size() << std::endl;

//get the runtime directory path from DataLogger to export buffer if it exceeds threshold

//DataLogger logger;
//std::string exportPath = logger.getLogFilePath();

//before writing, do necessary post processing on jsonChunk
//jsonChunk.data = PostProcessing.processData(jsonChunk.data);

write(jsonChunk);

if ((int)size() > FLUSH_THRESHOLD * MAX_BUFFER_SIZE / 100) {
popFront();
exportBuffer(logFilePath_);
}

// std::cout << "[DataBuffer] Buffer size after write: " << size() << std::endl;
// std::cout << buffer_.size();
// std::cout << "[DataBuffer] : " << toStringAll() << std::endl;

}

void DataBuffer::setData(buffer_data_t jsonData) {
Expand Down Expand Up @@ -153,6 +142,11 @@ std::string DataBuffer::toStringAll() {
return res;
}

void DataBuffer::printAll() {
//print all buffer_ as string
std::cout << toStringAll() << std::endl;
}

void DataBuffer::exportBuffer(std::string exportPath) {
//Export the entire buffer (make a local JSON file under client/src/)

Expand All @@ -170,4 +164,32 @@ void DataBuffer::exportBuffer(std::string exportPath) {
fputs(json_content.c_str(), fp);
fclose(fp);
return;
}
}

/*
void DataBuffer::replaceData(std::string dataType, float targetValue) {
//replace all data of type dataType in buffer_ with targetValue
std::lock_guard<std::mutex> lock(mutex_);

std::cout << "Replacing data of type " << dataType << " with value " << targetValue << std::endl;
std::cout << "Buffer before replaceData: " << toStringAll() << std::endl;

for (auto& item : readAll()) {
if (item.datatype == dataType) {
item.data = targetValue;
std::cout << "Replaced data of type " << dataType << " with value " << targetValue << std::endl;
}
}
}

void DataBuffer::addOffset(std::string dataType, float offsetValue) {
//add offsetValue to all data of type dataType in buffer_
std::lock_guard<std::mutex> lock(mutex_);

for (auto& item : readAll()) {
if (item.datatype == dataType) {
item.data += offsetValue;
}
}
}
*/
72 changes: 72 additions & 0 deletions client/src/command_processor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "client/command_processor.hpp"
#include "client/DataBuffer.hpp"

/*
TO DO: add stop mechanism for command processor thread, currently it runs indefinitely and can only be stopped by exiting the program
TO DO: add command_processor in onExit() in main.cpp
TO DO: handle race conditions between command processor and tcp client both accessing data buffer using mutex
*/

CommandProcessor::CommandProcessor(std::shared_ptr<DataBuffer> dataBuffer, std::shared_ptr<PostProcessing> postProcessor)
: dataBuffer_(dataBuffer), postProcessor_(postProcessor) {

}

void CommandProcessor::start() {
while(running_) {
std::cout << "Enter command (type 'exit' to quit): ";
std::getline(std::cin, command);

if (command == "exit") {
break;
}


processCommand(command);
}
}

void CommandProcessor::stop() {
running_ = false;
}

void CommandProcessor::processCommand(const std::string& command) {
/*
command:
<function> <parameter1> <parameter2>
*/
std::string cmdType = command.substr(0, command.find(' '));

//get the parameters from command
size_t firstSpace = command.find(' ');
size_t secondSpace = command.find(' ', firstSpace + 1);
std::string firstParameter = command.substr(firstSpace + 1, secondSpace - firstSpace - 1);
std::string secondParameter = command.substr(secondSpace + 1);

Comment on lines +40 to +45

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding a note here:
If there are no spaces between the two arguments, or maybe even entering "exit", firstParameter may become the full string

if(cmdType == "printAll") {
dataBuffer_->printAll();

} else if (cmdType == "clear") {
dataBuffer_->clear();

} else if (cmdType == "size"){
std::cout << "Buffer size: " << dataBuffer_->size() << std::endl;

} else if (cmdType == "reset"){
//reset all post processing parameters to default values
postProcessor_->reset();

} else if (cmdType == "setOffset"){
float offset = std::stof(firstParameter);
postProcessor_->addOffset(offset);

} else if (cmdType == "setScale"){
float scaleFactor = std::stof(firstParameter);
postProcessor_->addScaling(scaleFactor);

} else {
std::cout << "Unknown command: " << command << std::endl;
}

//add more commands as needed
}
28 changes: 28 additions & 0 deletions client/src/data_filters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "client/data_filters.hpp";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ; at the end of this line should be removed



DataFilters::DataFilters() {
}


int DataFilters::KalmanFilter(double input) {

// QUEUE DATA TYPE, FIRST IN FIRST OUT
return 0.0;
}

double DataFilters::MovingAverageFilter(double input) {
movingAverageList.push_front(input);
if (MAX_MOVINGAVERAGE <= movingAverageList.size()) {
movingAverageList.pop_back();
}

double sum = 0;
int i = 0;
while (i < movingAverageList.size()) {
sum += movingAverageList[i];
i++;
}

return sum / i;
}
Loading
Loading