Notifications
Clear all

Convert struct_message myData back to original format

6 Posts
2 Users
0 Likes
215 Views
 Otto
(@otto)
Active Member
Joined: 2 years ago
Posts: 6
Topic starter  

Have two ESP32 units, using sketch Code from DroneBot Workshop.  Sending myData successfully to receiving unit and printing on LCD screen successfully.  How do I get the "myData.x" converted back to the original form so I can make decisions/calculations within the receiving unit?

 

// Define a data structure

typedef struct struct_message {

  char a[32];

  int b;

  float c;

  bool d;

} struct_message;




// Create a structured object

struct_message myData;

   
Quote
Ron
 Ron
(@zander)
Illustrious Member
Joined: 2 years ago
Posts: 4454
 

Posted by: @otto

Have two ESP32 units, using sketch Code from DroneBot Workshop.  Sending myData successfully to receiving unit and printing on LCD screen successfully.  How do I get the "myData.x" converted back to the original form so I can make decisions/calculations within the receiving unit?

 

// Define a data structure

typedef struct struct_message {

  char a[32];

  int b;

  float c;

  bool d;

} struct_message;




// Create a structured object

struct_message myData;

Not sure what you mean, if you mean working with the individual fields, then syntax like myData.b can be read or changed if on other side of the equation. Is that what you wanted to know?

 

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
 Otto
(@otto)
Active Member
Joined: 2 years ago
Posts: 6
Topic starter  

Not quite following your reply.  Please give an example about the "other side of the equation".  e.g. : a=myData.a


   
ReplyQuote
Ron
 Ron
(@zander)
Illustrious Member
Joined: 2 years ago
Posts: 4454
 

@otto To retrieve data from the structure you would code

b = myData.b;

To store data in the structure you would code

myData.b = b;

Where b is int and myData.b is int

Clear?

of course the char array a requires a little more work, but by now you should understand what is needed.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
 Otto
(@otto)
Active Member
Joined: 2 years ago
Posts: 6
Topic starter  

Ron, thanx very much.  Have put the equations into the code, but haven't had time to test yet, thanks again


   
ReplyQuote
Ron
 Ron
(@zander)
Illustrious Member
Joined: 2 years ago
Posts: 4454
 

@otto Just remember the char array will need appropriate strxxxx or memxxx helpers depending on if the array is really just a char array or is actually a string. Then you must deal with if the string is /0 terminated or not. I am old school but understand there are C++ things to deal with that situation that I am only vaguely aware of. Perhaps one of our C++ members will chime in.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote