Skip to content

Commit

Permalink
modbus_tcp: Use tftools/option.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrbt committed Oct 31, 2024
1 parent e952369 commit 122e23f
Showing 1 changed file with 2 additions and 67 deletions.
69 changes: 2 additions & 67 deletions software/src/modules/modbus_tcp/modbus_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "modules/power_manager/power_manager.h"
#endif

#include <TFTools/Option.h>

extern uint32_t local_uid_num;

// MODBUS TABLE CHANGELOG
Expand All @@ -41,73 +43,6 @@ extern uint32_t local_uid_num;
// 3 - Add phase switch
#define MODBUS_TABLE_VERSION 3


template<typename T>
struct Option {
public:
template<typename U = std::is_trivially_copy_constructible<T>, typename std::enable_if<U::value>::type...>
Option(T t): val(t), have_val(true) {}

// val has to be initialized if it is a primitive type.
Option() : val(), have_val(false) {}

T &unwrap() {
return expect("unwrapped Option without value!");
}

const T &unwrap() const {
return expect("unwrapped Option without value!");
}

T &unwrap_or(T &default_value) {
if (!have_val)
return default_value;
return val;
}

const T &unwrap_or(const T &default_value) const {
if (!have_val)
return default_value;
return val;
}

T &expect(const char *message) {
if (!have_val)
esp_system_abort(message);
return val;
}

const T &expect(const char *message) const {
if (!have_val)
esp_system_abort(message);
return val;
}

T &insert(const T &default_value) {
val = default_value;
have_val = true;
return val;
}

bool is_some() const {
return have_val;
}

bool is_none() const {
return !have_val;
}

void clear() {
have_val = false;
}

private:
T val;
bool have_val;
};



static uint8_t hextouint(const char c)
{
uint8_t i = 0;
Expand Down

0 comments on commit 122e23f

Please sign in to comment.