Skip to content

Commit

Permalink
Merge pull request #4 from SuperJappie08/main
Browse files Browse the repository at this point in the history
Make parse pool size configurable at runtime
  • Loading branch information
ArendJan authored Nov 26, 2024
2 parents 0d4350c + b6a82f7 commit 84a39dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
8 changes: 7 additions & 1 deletion DEBUGGING.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Debug Flags
- `TMX_RX_DEBUG`: Debug message on recieving
- `TMX_TX_DEBUG`: Debug message on transmission
- `TMX_HW_DEBUG`: Set poolsize to 1.

## Deprecated
Deprecated debug flags and there replacements:

| Flag | Description | Replacement |
| :------------: | :----------------- | :-------------------------------------------------------------------- |
| `TMX_HW_DEBUG` | Set poolsize to 1. | Intialize the `tmx_cpp::TMX` object with `parse_pool_size` equal to 1 |
3 changes: 2 additions & 1 deletion include/tmx_cpp/tmx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class TMX {
// Sensors sensors;

public:
TMX(std::function<void()> stop_func, std::string port = "/dev/ttyACM0");
TMX(std::function<void()> stop_func, std::string port = "/dev/ttyACM0",
size_t parse_pool_size = std::thread::hardware_concurrency());
~TMX();
enum PIN_MODES : uint8_t {
DIGITAL_INPUT = 0,
Expand Down
15 changes: 5 additions & 10 deletions src/tmx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@
#include <tmx_cpp/serialization.hpp>
#include <tmx_cpp/types.hpp>

#ifdef TMX_HW_DEBUG
#define POOL_SIZE 1
#else
#define POOL_SIZE std::thread::hardware_concurrency()
#endif

using namespace tmx_cpp;

TMX::TMX(std::function<void()> stop_func, std::string port)
: parsePool(POOL_SIZE), stop_func(stop_func) {
TMX::TMX(std::function<void()> stop_func, std::string port, size_t parse_pool_size)
: parsePool(std::max<size_t>(parse_pool_size, 1)), stop_func(stop_func) {
using namespace std::placeholders;

this->serial = std::make_shared<CallbackAsyncSerial>(port, 115200);
this->serial->setCallback([this](const char *data, size_t len) { this->callback(data, len); });

this->ping_thread = std::thread(&TMX::ping_task, this);
this->add_callback(MESSAGE_IN_TYPE::PONG_REPORT,
std::bind(&TMX::ping_callback, this, std::placeholders::_1));
this->add_callback(MESSAGE_IN_TYPE::PONG_REPORT, std::bind(&TMX::ping_callback, this, _1));
// this->add_callback(
// MESSAGE_IN_TYPE::ANALOG_REPORT, [](std::vector<uint8_t> t) { t[1] = 3; });
}
Expand Down

0 comments on commit 84a39dd

Please sign in to comment.