mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-10 06:59:54 +08:00
Switch downlink_transport to void * to avoid alignment warnings
This commit is contained in:
@@ -52,7 +52,7 @@ struct DownlinkTransport
|
||||
uint8_t (*SizeOf)(void *impl, uint8_t size);
|
||||
int (*CheckFreeSpace)(void *impl, uint8_t size);
|
||||
|
||||
void (*PutBytes)(void *impl, enum DownlinkDataType data_type, uint8_t len, const uint8_t *bytes);
|
||||
void (*PutBytes)(void *impl, enum DownlinkDataType data_type, uint8_t len, const void *bytes);
|
||||
|
||||
void (*StartMessage)(void *impl, char *name, uint8_t msg_id, uint8_t payload_len);
|
||||
void (*EndMessage)(void *impl);
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
#define FILENAME_LEN 64
|
||||
#define TIMESTAMP_SCALE 10000
|
||||
|
||||
static void put_bytes(void *impl, enum DownlinkDataType data_type, uint8_t len __attribute__((unused)), const uint8_t *bytes)
|
||||
static void put_bytes(void *impl, enum DownlinkDataType data_type, uint8_t len __attribute__((unused)), const void *bytes)
|
||||
{
|
||||
struct onboard_transport *onboard = (struct onboard_transport *) impl;
|
||||
uint32_t length = 0;
|
||||
|
||||
if (data_type == DL_TYPE_ARRAY_LENGTH) {
|
||||
onboard->array_length = (uint8_t) *bytes;
|
||||
onboard->array_length = *((const uint8_t *) bytes);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,48 +32,48 @@ static void put_bytes(void *impl, enum DownlinkDataType data_type, uint8_t len _
|
||||
}
|
||||
switch (data_type) {
|
||||
case DL_TYPE_UINT8:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%hhu", *bytes);
|
||||
bytes = bytes + 1;
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%hhu", * (const uint8_t *)bytes);
|
||||
bytes = (const uint8_t *) bytes + 1;
|
||||
break;
|
||||
case DL_TYPE_UINT16:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%hu", * (const uint16_t *)bytes);
|
||||
bytes = bytes + 2;
|
||||
bytes = (const uint16_t *) bytes + 2;
|
||||
break;
|
||||
case DL_TYPE_UINT32:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%u", * (const uint32_t *)bytes);
|
||||
bytes = bytes + 4;
|
||||
bytes = (const uint32_t *) bytes + 4;
|
||||
break;
|
||||
case DL_TYPE_UINT64:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%llu", *(const uint64_t *)bytes);
|
||||
bytes = bytes + 8;
|
||||
bytes = (const uint64_t *) bytes + 8;
|
||||
break;
|
||||
case DL_TYPE_INT8:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%hhi", * (const int8_t *)bytes);
|
||||
bytes = bytes + 1;
|
||||
bytes = (const int8_t *) bytes + 1;
|
||||
break;
|
||||
case DL_TYPE_INT16:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%hi", * (const int16_t *)bytes);
|
||||
bytes = bytes + 2;
|
||||
bytes = (const int16_t *) bytes + 2;
|
||||
break;
|
||||
case DL_TYPE_INT32:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%i", * (const int32_t *)bytes);
|
||||
bytes = bytes + 4;
|
||||
bytes = (const int32_t *) bytes + 4;
|
||||
break;
|
||||
case DL_TYPE_INT64:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%lli", *(const int64_t *)bytes);
|
||||
bytes = bytes + 8;
|
||||
bytes = (const int64_t *) bytes + 8;
|
||||
break;
|
||||
case DL_TYPE_FLOAT:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%#f", *(const float *)bytes);
|
||||
bytes = bytes + 4;
|
||||
bytes = (const float *) bytes + 4;
|
||||
break;
|
||||
case DL_TYPE_DOUBLE:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%#f", *(const double *)bytes);
|
||||
bytes = bytes + 8;
|
||||
bytes = (const double *) bytes + 8;
|
||||
break;
|
||||
case DL_TYPE_TIMESTAMP:
|
||||
onboard->buffer_idx += snprintf(onboard->buffer + onboard->buffer_idx, ONBOARD_BUFFER_LEN - onboard->buffer_idx, "%u.%04u", (*(const uint32_t *)bytes) / TIMESTAMP_SCALE,(*(const uint32_t *)bytes) % TIMESTAMP_SCALE);
|
||||
bytes = bytes + 4;
|
||||
bytes = (const uint32_t *) bytes + 4;
|
||||
break;
|
||||
case DL_TYPE_ARRAY_LENGTH:
|
||||
break;
|
||||
|
||||
@@ -22,9 +22,10 @@ static void put_named_uint8_t(struct udp_transport *udp, char *name __attribute_
|
||||
put_uint8_t(udp, byte);
|
||||
}
|
||||
|
||||
static void put_bytes(void *impl, enum DownlinkDataType data_type __attribute__((unused)), uint8_t len, const uint8_t *bytes)
|
||||
static void put_bytes(void *impl, enum DownlinkDataType data_type __attribute__((unused)), uint8_t len, const void *buf)
|
||||
{
|
||||
struct udp_transport *udp = (struct udp_transport *) impl;
|
||||
const uint8_t *bytes = (const uint8_t *) buf;
|
||||
for (int i = 0; i < len; i++) {
|
||||
put_uint8_t(udp, bytes[i]);
|
||||
}
|
||||
@@ -38,7 +39,7 @@ static void header(struct udp_transport *udp, uint8_t payload_len)
|
||||
uint8_t msg_len = payload_len + PPRZ_PROTOCOL_OVERHEAD;
|
||||
udp->udpt_ck_a = udp->udpt_ck_b = 0;
|
||||
put_uint8_t(udp, msg_len);
|
||||
put_bytes(udp, DL_TYPE_UINT32, 4, (uint8_t *) &msg_timestamp);
|
||||
put_bytes(udp, DL_TYPE_UINT32, 4, &msg_timestamp);
|
||||
}
|
||||
|
||||
static void start_message(void *impl, char *name, uint8_t msg_id, uint8_t payload_len)
|
||||
|
||||
@@ -139,11 +139,11 @@ module Gen_onboard = struct
|
||||
let print_field = fun h (t, name, (_f: format option)) ->
|
||||
match t with
|
||||
Basic _ ->
|
||||
fprintf h "\t tp->PutBytes(tp->impl, %s, %s, (uint8_t *) _%s); \n" (dl_type (Syntax.nameof t)) (Syntax.sizeof t) name
|
||||
fprintf h "\t tp->PutBytes(tp->impl, %s, %s, (void *) _%s); \n" (dl_type (Syntax.nameof t)) (Syntax.sizeof t) name
|
||||
| Array (t, varname) ->
|
||||
let _s = Syntax.sizeof (Basic t) in
|
||||
fprintf h "\t tp->PutBytes(tp->impl, DL_TYPE_ARRAY_LENGTH, 1, (uint8_t *) &%s); \n" (Syntax.length_name varname);
|
||||
fprintf h "\t tp->PutBytes(tp->impl, %s, %s * %s, (uint8_t *) _%s); \n" (dl_type (Syntax.nameof (Basic t))) (Syntax.sizeof (Basic t)) (Syntax.length_name varname) name
|
||||
fprintf h "\t tp->PutBytes(tp->impl, DL_TYPE_ARRAY_LENGTH, 1, (void *) &%s); \n" (Syntax.length_name varname);
|
||||
fprintf h "\t tp->PutBytes(tp->impl, %s, %s * %s, (void *) _%s); \n" (dl_type (Syntax.nameof (Basic t))) (Syntax.sizeof (Basic t)) (Syntax.length_name varname) name
|
||||
|
||||
let print_parameter h = function
|
||||
(Array (t, varname), s, _) -> fprintf h "uint8_t %s, %s *_%s" (Syntax.length_name s) (c_type (Syntax.nameof (Basic t))) s
|
||||
|
||||
Reference in New Issue
Block a user