Skip to content

Commit

Permalink
Update fields.h
Browse files Browse the repository at this point in the history
  • Loading branch information
marcovannoord committed Jul 3, 2020
1 parent a3d9113 commit 29b1d33
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/dsmr/fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,19 @@ const uint8_t WATER_MBUS_ID = 2;
const uint8_t THERMAL_MBUS_ID = 3;
const uint8_t SLAVE_MBUS_ID = 4;

template <typename FieldT>
struct NameConverter {
public:
operator const __FlashStringHelper*() const { return reinterpret_cast<const __FlashStringHelper*>(&FieldT::name_progmem); }
};

#define DEFINE_FIELD(fieldname, value_t, obis, field_t, field_args...) \
struct fieldname : field_t<fieldname, ##field_args> { \
value_t fieldname; \
bool fieldname ## _present = false; \
static constexpr ObisId id = obis; \
static constexpr char name_progmem[] DSMR_PROGMEM = #fieldname; \
static constexpr const __FlashStringHelper *name = reinterpret_cast<const __FlashStringHelper*>(&name_progmem); \
static constexpr NameConverter<dsmr::fields::fieldname> name = {}; \
value_t& val() { return fieldname; } \
bool& present() { return fieldname ## _present; } \
}
Expand Down

0 comments on commit 29b1d33

Please sign in to comment.