Debugging in SIH

Dear all,

I would like to use MAVlink debug values to send some values, while I’m performing an SIH simulation:
Sending Debug Values · PX4 Developer Guide.

Unfortunately I get following error:
error: C99 designator ‘key’ outside aggregate initializer
struct debug_key_value_s dbg = { .key = “vel”, .value = 0.0f };
^
compilation terminated due to -Wfatal-errors.

This has also been covered in Thread: mavlink debug compile error · Issue #4461 · PX4/PX4-Autopilot · GitHub

So my two question are:

  • Could anyone help me how to fix this compile error?
  • Is there even a smarter way to debug, while in SIH?

Thank you and kind regards
Chraebi

Check this: https://github.com/PX4/Firmware/issues/4461#issuecomment-466834308

Dear Julian,

Thank you for your help.
I’ve already seen this post and it states that’s a C,C++ portability issue. But I don’t exactly see how the problem can be solved. Would you mind to help me?

Kind regards
Chraebi

Check the comment I referenced, it answers exactly that question.

Dear Julian,

Thank you for your fast answer. I’m sorry but I don’t understand what you mean.
In the comment you referenced there is a solution proposed but it results in another compiliation error:

error: incompatible types in assignment of 'int' to 'int8_t [10] {aka signed char [10]}'
dbg.key= 'test';
^
compilation terminated due to -Wfatal-errors.

Thus, at the end the author stribuda asked if anyone might help and nobody replied since then.

Thank you for your help
Chraebi

You are using single quotes ' around a string but it should be double quotes ".

Dear Julian,

Thank your for your help, but it didn’t solve the problem. It ended up in another compilation error:

error: incompatible types in assignment of 'const char [5]' to 'char [10] by using the double quotes.

Although, I found the solution in the px4_mavlink_debug.cpp file. (I think it was intented to link this file in following tutorial, but the link is broken).

So the solution to correctly implement is:

/* advertise named debug value */
	struct debug_key_value_s dbg_key;
	strncpy(dbg_key.key, "velx", 10);
	dbg_key.value = 0.0f;
	orb_advert_t pub_dbg_key = orb_advertise(ORB_ID(debug_key_value), &dbg_key);

Like this it works perfectly fine.
It would be nice if someone could update the tutorial (I don’t know how to do that)

Kind regards and thanks again
Chraebi

1 Like

Ok, strncpy makes sense! thanks for sharing.

Fix is here: https://github.com/PX4/Devguide/pull/812

1 Like