paparazzi / pprzlink

Message and communication library for the Paparazzi UAV system
Other
24 stars 55 forks source link

HITL doesn't work with Ppprzlink 2.0 #80

Open podhrmic opened 6 years ago

podhrmic commented 6 years ago

The issue is apparently memory alignment,

From nps_main_hitl.c when parsing DL_COMMANDS:

Pprzlink 1.0

Pprzlink 2.0

/* Getter for field values in message COMMANDS

/ Compatibility macros /

define DL_COMMANDS_values_length(_payload) pprzlink_get_COMMANDS_values_length(_payload)

define DL_COMMANDS_values(_payload) pprzlink_get_DL_COMMANDS_values(_payload)

- `length` is returned properly, but instead of a pointer to the `payload` I am getting NULL (DL_COMMANDS_values(buf) = NULL) and as a result memcopy crashes (access to memory at NULL).

printf("DL_COMMANDS_values_length(buf) = %u\n",DL_COMMANDS_values_length(buf)); printf("DL_COMMANDS_values(buf) = %p\n",DL_COMMANDS_values(buf));

prints

DL_COMMANDS_values_length(buf) = 5 DL_COMMANDS_values(buf) = (nil)


while the buffer values are:

9,0,1,102,5,0,0,0,0,0,0,0,0,0,0


(sender id =9, dest_id=0, class=telemetry, msg_id=102)

When turning the alignment off, the same result is produced.

@gautierhattenberger what do you think?
gautierhattenberger commented 6 years ago

Where is compiled this code, which MCU/CPU ? Did you try to compile with -DPPRZLINK_UNALIGNED_ACCESS ?

podhrmic commented 6 years ago

I did. I will run some more tests and post a better output info.

podhrmic commented 6 years ago

Update:

The code is from airframes/AGGIEAIR/aggieair_conf.xml and then Minion_RP3 - compiled for Lisa MX (ap target) and for a generix linux machine (hitl/nps). I am running 64-bit Ubuntu 16.04.

With pprzlink 1.0 (and PPRZLINK_UNALIGNED_ACCESS allowed):

DL_COMMANDS_values_length(buf) = 5
DL_COMMANDS_values(buf) = 0x7fea06ec1b53

With pprzlink 2.0 (and PPRZLINK_UNALIGNED_ACCESS enabled):

DL_COMMANDS_values_length(buf) = 5
DL_COMMANDS_values(buf) = (nil)

With PPRZLINK_UNALIGNED_ACCESS=0 I get:

DL_COMMANDS_values_length(buf) = 0
DL_COMMANDS_values(buf) = (nil)

So clearly with pprzlink 2.0 and unaligned access enabled I get the correct values_length, but the array pointer is still NULL.

Also, when I just read and display DL_COMMANDS_values(buf) (and don't try to do memcopy) I get different (but most likely illegal) address every time (instead of NULL).

I am kind of out of ideas - it could be related to the compiler (gcc 5.4) and many other things, but it is also just very weird:-/

gautierhattenberger commented 6 years ago

Just to be sure, could you try with a more recent (GCC7) compiler ?

gautierhattenberger commented 6 years ago

Actually, I was probably doing something wrong in the end. Can you try the fix_array_access branch ?