Replies: 9 comments 18 replies
-
Ok, as long as I see this there is no need to copy the bytes (only if you need and reuse the rx_buffer for the next reception and want to keep the struct data independent of it. But this is another question). In C you are empowered to use pointers as you like to interpret known memory areas. So in this case you can do something like this
The (data_structure *) cast in front of the uint8_t pointer is only used to get rid the compiler warnings which indicate to you that you assign the values of 'incompatible pointer types'. In the example I use only stacked local variables but if buffer and or the pointers used are 'module static' variable, the systax is exactly the same. Only difference would be that module variables are always initialized to 0x00 s after reset. Local Stack variables - i think - are never initialized and have a random content as long as you do not assign any value.... |
Beta Was this translation helpful? Give feedback.
-
If you have to copy the data (because of your design needs rx_buffer and 'datastruct' having same content and beeing independend variables the memcpy() is the correct method to do this. To get the correct len to use with memcopy you can either use your knowledge of the magic number 108 here or you can use compiler magic with sizeof(data_structure); another thing to be aware of is usage of compiler directives for packing structure. Use
If no packed attribute is used the compiler assumes that all values are 32bit alligned and will introduce the needed bytes to fill up or overread the 8/16 bit values within the struct .... |
Beta Was this translation helpful? Give feedback.
-
@Moza3105 : I just remembered here that you are familiar with C- Syntax. Maybe you could have answered this q also ;-). But never mind. Let's see how discussions advance here :-D |
Beta Was this translation helpful? Give feedback.
-
Thank you @RobertK66 memcpy would be appropriate in case of thruster. rx_buffer gets overwritten always. It can receive messages of OK type which does not carry any useful register values... Buffer has to be recorded into structure only after validation. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
With your current design and preparing the Sequences, I think you get 'around that problem with help of the compiler: e.g.
On the right side of the assignments you hardcode some strings. (This would be the equivalent of a typed paramter at some position of a CLI). This Constant string is placed by compiler somwhere in Flash-ROM. The left side (beeing the pointer to some char - string) is then assigned to point to this const string in flash. As long as you only read there this should not be a problem. But as this is const you can never expect to write something to this strings from code (which you would need if data comes from 'persitence mram memory' or ground station.... |
Beta Was this translation helpful? Give feedback.
-
But this THR_HARDCODED_SEQUENCES[sequence_id_int].sequences[exeFunc_index].thr_argv[1] = "14"; "14" and "1" are const strings! How do you change this to be e.g. "15 and "2" !? |
Beta Was this translation helpful? Give feedback.
-
No, you do not get the ppoint here. And your solution to make the array char*[6][max_parlen]; is not a very good one, because here the array ALWAYS takes the space of the maximum possible pars (and this times the maximum possible par-count..... This is all but memory efficient! But anyway as you are trying to think it over already so lets talk somewhen the next days... |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
@RobertK66 Robert could you please explain how is it possible to :
We have rx buffer
uint8_t rx_buffer[108]
and structure that should represent some PSU /Thruster reguster / magnerometer data
How is it possible with pointers to copy raw bytes from rx_buffer into structure of another type ? what is the correct syntaxis ?
should memcpy be used for that ? what is the best way to achieve it ?
Note that it is assumed that size of RX buffer fills datastructure completely
Note2 : Reason why I ask is that I believe that my thruster register parser function in current implementation is causing hard fault sometimes. Therefore I want to write it and optimize the way thruster register values would be stored
Beta Was this translation helpful? Give feedback.
All reactions