implemented precision timestamps in report messages

This commit is contained in:
2018-01-27 20:27:33 +01:00
parent 94e87c74d3
commit 04e32860f7
14 changed files with 246 additions and 59 deletions
+42
View File
@@ -86,6 +86,36 @@ bool pb_u32(PayloadBuilder *pb, uint32_t word)
return true;
}
/** Write uint64_t to the buffer. */
bool pb_u64(PayloadBuilder *pb, uint64_t word)
{
pb_check_capacity(pb, 4);
if (!pb->ok) return false;
if (pb->bigendian) {
*pb->current++ = (uint8_t) ((word >> 56) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 48) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 40) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 32) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 24) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 16) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 8) & 0xFF);
*pb->current++ = (uint8_t) (word & 0xFF);
} else {
*pb->current++ = (uint8_t) (word & 0xFF);
*pb->current++ = (uint8_t) ((word >> 8) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 16) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 24) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 32) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 40) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 48) & 0xFF);
*pb->current++ = (uint8_t) ((word >> 56) & 0xFF);
}
return true;
}
/** Write int8_t to the buffer. */
bool pb_i8(PayloadBuilder *pb, int8_t byte)
{
@@ -104,8 +134,20 @@ bool pb_i32(PayloadBuilder *pb, int32_t word)
return pb_u32(pb, ((union conv32){.i32 = word}).u32);
}
/** Write int64_t to the buffer. */
bool pb_i64(PayloadBuilder *pb, int64_t word)
{
return pb_u64(pb, ((union conv64){.i64 = word}).u64);
}
/** Write 4-byte float to the buffer. */
bool pb_float(PayloadBuilder *pb, float f)
{
return pb_u32(pb, ((union conv32){.f32 = f}).u32);
}
/** Write 8-byte float to the buffer. */
bool pb_double(PayloadBuilder *pb, double f)
{
return pb_u64(pb, ((union conv64){.f64 = f}).u64);
}
+9
View File
@@ -98,6 +98,9 @@ bool pb_u16(PayloadBuilder *pb, uint16_t word);
/** Write uint32_t to the buffer. */
bool pb_u32(PayloadBuilder *pb, uint32_t word);
/** Write uint64_t to the buffer */
bool pb_u64(PayloadBuilder *pb, uint64_t word);
/** Write int8_t to the buffer. */
bool pb_i8(PayloadBuilder *pb, int8_t byte);
@@ -113,7 +116,13 @@ bool pb_i16(PayloadBuilder *pb, int16_t word);
/** Write int32_t to the buffer. */
bool pb_i32(PayloadBuilder *pb, int32_t word);
/** Write int64_t to the buffer. */
bool pb_i64(PayloadBuilder *pb, int64_t word);
/** Write 4-byte float to the buffer. */
bool pb_float(PayloadBuilder *pb, float f);
/** Write 8-byte float to the buffer. */
bool pb_double(PayloadBuilder *pb, double f);
#endif // PAYLOAD_BUILDER_H
+43
View File
@@ -56,6 +56,37 @@ uint32_t pp_u32(PayloadParser *pp)
return x;
}
uint64_t pp_u64(PayloadParser *pp)
{
pp_check_capacity(pp, 4);
if (!pp->ok) return 0;
uint64_t x = 0;
if (pp->bigendian) {
x |= (uint64_t) ((uint64_t) *pp->current++ << 56);
x |= (uint64_t) ((uint64_t) *pp->current++ << 48);
x |= (uint64_t) ((uint64_t) *pp->current++ << 40);
x |= (uint64_t) ((uint64_t) *pp->current++ << 32);
x |= (uint64_t) (*pp->current++ << 24);
x |= (uint64_t) (*pp->current++ << 16);
x |= (uint64_t) (*pp->current++ << 8);
x |= *pp->current++;
} else {
x |= *pp->current++;
x |= (uint64_t) (*pp->current++ << 8);
x |= (uint64_t) (*pp->current++ << 16);
x |= (uint64_t) (*pp->current++ << 24);
x |= (uint64_t) ((uint64_t) *pp->current++ << 32);
x |= (uint64_t) ((uint64_t) *pp->current++ << 40);
x |= (uint64_t) ((uint64_t) *pp->current++ << 48);
x |= (uint64_t) ((uint64_t) *pp->current++ << 56);
}
return x;
}
const uint8_t *pp_tail(PayloadParser *pp, uint32_t *length)
{
int32_t len = (int) (pp->end - pp->current);
@@ -89,12 +120,24 @@ int32_t pp_i32(PayloadParser *pp)
return ((union conv32) {.u32 = pp_u32(pp)}).i32;
}
/** Read int364_t from the payload. */
int64_t pp_i64(PayloadParser *pp)
{
return ((union conv64) {.u64 = pp_u64(pp)}).i64;
}
/** Read 4-byte float from the payload. */
float pp_float(PayloadParser *pp)
{
return ((union conv32) {.u32 = pp_u32(pp)}).f32;
}
/** Read 8-byte float from the payload. */
double pp_double(PayloadParser *pp)
{
return ((union conv64) {.u64 = pp_u64(pp)}).f64;
}
/** Read a zstring */
uint32_t pp_string(PayloadParser *pp, char *buffer, uint32_t maxlen)
{
+9
View File
@@ -101,6 +101,9 @@ uint16_t pp_u16(PayloadParser *pp);
/** Read uint32_t from the payload. */
uint32_t pp_u32(PayloadParser *pp);
/** Read uint64_t from the payload. */
uint64_t pp_u64(PayloadParser *pp);
/** Read int8_t from the payload. */
int8_t pp_i8(PayloadParser *pp);
@@ -116,9 +119,15 @@ int16_t pp_i16(PayloadParser *pp);
/** Read int32_t from the payload. */
int32_t pp_i32(PayloadParser *pp);
/** Read int64_t from the payload. */
int64_t pp_i64(PayloadParser *pp);
/** Read 4-byte float from the payload. */
float pp_float(PayloadParser *pp);
/** Read 8-byte float from the payload. */
double pp_double(PayloadParser *pp);
/**
* Parse a zero-terminated string
*
+6
View File
@@ -29,4 +29,10 @@ union conv32 {
float f32;
};
union conv64 {
uint64_t u64;
int64_t i64;
double f64;
};
#endif // TYPE_COERCE_H