chore: log type & value

This commit is contained in:
fengzero
2023-05-17 08:36:31 +00:00
parent bc44bfeda1
commit 30579ef578
+78
View File
@@ -112,6 +112,84 @@ typedef union {
uint8_t bytes[NEU_VALUE_SIZE];
} __attribute__((packed)) neu_value_u;
static inline char *neu_value_str(neu_type_e type, neu_value_u value)
{
static __thread char str[32] = { 0 };
switch (type) {
case NEU_TYPE_INT8:
snprintf(str, sizeof(str), "type: %s, value: %i", neu_type_string(type),
value.i8);
break;
case NEU_TYPE_UINT8:
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
value.u8);
break;
case NEU_TYPE_INT16:
snprintf(str, sizeof(str), "type: %s, value: %i", neu_type_string(type),
value.i16);
break;
case NEU_TYPE_WORD:
case NEU_TYPE_UINT16:
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
value.u16);
break;
case NEU_TYPE_INT32:
snprintf(str, sizeof(str), "type: %s, value: %i", neu_type_string(type),
value.i32);
break;
case NEU_TYPE_DWORD:
case NEU_TYPE_UINT32:
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
value.u32);
break;
case NEU_TYPE_INT64:
#if __WORDSIZE == 64
snprintf(str, sizeof(str), "type: %s, value: %li",
neu_type_string(type), value.i64);
#else
snprintf(str, sizeof(str), "type: %s, value: %lli",
neu_type_string(type), value.i64);
#endif
break;
case NEU_TYPE_LWORD:
case NEU_TYPE_UINT64:
#if __WORDSIZE == 64
snprintf(str, sizeof(str), "type: %s, value: %lu",
neu_type_string(type), value.u64);
#else
snprintf(str, sizeof(str), "type: %s, value: %llu",
neu_type_string(type), value.u64);
#endif
break;
case NEU_TYPE_FLOAT:
snprintf(str, sizeof(str), "type: %s, value: %f", neu_type_string(type),
value.f32);
break;
case NEU_TYPE_DOUBLE:
snprintf(str, sizeof(str), "type: %s, value: %f", neu_type_string(type),
value.d64);
break;
case NEU_TYPE_BIT:
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
value.u8);
break;
case NEU_TYPE_BOOL:
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
value.boolean);
break;
case NEU_TYPE_STRING: {
snprintf(str, sizeof(str), "type: %s, value: %s", neu_type_string(type),
value.str);
break;
}
default:
break;
}
return str;
}
typedef struct {
neu_type_e type;
neu_value_u value;