pprzlink
pprzlink copied to clipboard
HITL doesn't work with Ppprzlink 2.0
The issue is apparently memory alignment,
From nps_main_hitl.c when parsing DL_COMMANDS
:
Pprzlink 1.0
- everything works fine
#define DL_COMMANDS_values_length(_payload) _PPRZ_VAL_len_aligned(_payload, 2)
#define DL_COMMANDS_values(_payload) _PPRZ_VAL_int16_t_array(_payload, 3)
Pprzlink 2.0
-
length
is at index 4, andpayload
is at index 5
/** Getter for length of array values in message COMMANDS
*
* @return values :
*/
static inline uint8_t pprzlink_get_COMMANDS_values_length(__attribute__ ((unused)) void* _payload) {
return _PPRZ_VAL_len_aligned(_payload, 4);
}
/** Getter for field values in message COMMANDS
*
* @param _payload : a pointer to the COMMANDS message
* @return
*/
static inline int16_t * pprzlink_get_DL_COMMANDS_values(uint8_t * _payload __attribute__((unused)))
{
return _PPRZ_VAL_int16_t_array(_payload, 5);
}
/* 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 thepayload
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?
Where is compiled this code, which MCU/CPU ?
Did you try to compile with -DPPRZLINK_UNALIGNED_ACCESS
?
I did. I will run some more tests and post a better output info.
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:-/
Just to be sure, could you try with a more recent (GCC7) compiler ?
Actually, I was probably doing something wrong in the end. Can you try the fix_array_access
branch ?