remove unnecessary union, initialize all fields of dtlf_t

This commit is contained in:
John
2022-09-25 13:16:57 +02:00
parent c3935d4946
commit 9102c89258
2 changed files with 11 additions and 14 deletions
+2 -2
View File
@@ -311,14 +311,14 @@ result_t getFieldLength(const SingleDataField *field, dtlf_t *length) {
// adjust bit count for non-existent 24 bit KNX type // adjust bit count for non-existent 24 bit KNX type
bitCnt = 32; bitCnt = 32;
} }
*length = {{ *length = {
.hasDivisor = nt->getDivisor() != 1, .hasDivisor = nt->getDivisor() != 1,
.isFloat = dt->hasFlag(EXP), .isFloat = dt->hasFlag(EXP),
.isSigned = dt->hasFlag(SIG), .isSigned = dt->hasFlag(SIG),
.lastValueSent = false, .lastValueSent = false,
.length = static_cast<uint8_t>(bitCnt/8), .length = static_cast<uint8_t>(bitCnt/8),
.lastValue = 0, .lastValue = 0,
}}; };
return RESULT_OK; return RESULT_OK;
} }
+3 -6
View File
@@ -82,20 +82,17 @@ enum apci_t {
#define FLAG_WRITE 0x800000 #define FLAG_WRITE 0x800000
/** datatype length flags (byte length on KNX in bits 0-3, extra info in higher bits). */ /** datatype length flags (byte length on KNX in bits 0-3, extra info in higher bits). */
typedef union { typedef struct {
struct {
bool hasDivisor: 1; bool hasDivisor: 1;
bool isFloat: 1; bool isFloat: 1;
bool isSigned: 1; bool isSigned: 1;
bool lastValueSent: 1; bool lastValueSent: 1;
uint8_t length; // 0 for 1-6 bits, number of bytes otherwise uint8_t length; // 0 for 1-6 bits, number of bytes otherwise
uint32_t lastValue; uint32_t lastValue;
};
uint64_t value;
} dtlf_t; } dtlf_t;
#define DTLF_1BIT dtlf_t{.length = 0} #define DTLF_1BIT dtlf_t{.hasDivisor = false, .isFloat = false, .isSigned = false, .lastValueSent = false, .length = 0, .lastValue = 0}
#define DTLF_8BIT dtlf_t{.length = 1} #define DTLF_8BIT dtlf_t{.hasDivisor = false, .isFloat = false, .isSigned = false, .lastValueSent = false, .length = 1, .lastValue = 0}
/** type for global values not associated with an ebus message. */ /** type for global values not associated with an ebus message. */
enum global_t { enum global_t {