Class including 2d struct

Hi,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Message {
    public:
        /** A flag indicating whether this is an extended CAN message */
        uint8_t extended;
        /** The identifier of the CAN message.  The ID is 29 bytes long
          * if the extended flag is set, or 11 bytes long if not set. */
        uint32_t id;
        /** The number of bytes in the data field (0-8) */
        uint8_t len;
        /** Array containing the bytes of the CAN message.  This array
          * may be accessed directly to set or read the CAN message.
          * This field can also be set by the set<Type>Data functions and
          * read by the get<Type>Data functions. */
        uint8_t data[CAN_BYTES_MAX];
        /** The PGN of a CAN frame */
		uint32_t pgn;
        /** The identifier of the CAN message.  The ID is 29 bytes long
          * if the extended flag is set, or 11 bytes long if not set. */
		struct {
				struct{
				float EngineSpeed;
			}EEC1;
				struct{
				uint16_t WheelBasedSpeed;
				uint32_t WheelBasedDistance;
				uint8_t WheelBasedDirection;
			}WBSD_TECU;
				struct{
				uint16_t GroundBasedSpeed;
				uint32_t GroundBasedDistance;
				uint8_t GroundBasedDirection;
			}GBSD_TECU;
				struct{
				float FrontHitchPosition;
			}FHS_TECU;
				struct{
				float RearHitchPosition;
			}RHS_TECU;
		}pg;
        /** The identifier of the CAN message.  The ID is 29 bytes long
          * if the extended flag is set, or 11 bytes long if not set. */
        uint32_t value;

        Message();
};


I'm currently using a 2d struct within a class in order to create a data structure like this:

Message i
i.pg.EEC1.EngineSpeed


This approach compiles without any problems, but I have the feeling things are going wrong writing data into these 2d struct elements(other elements are overwritten).

Is this the right way to create such a data structure? What can be the possible cause other struct elements being overwritten with strange values when for example writing data a specific struct element (e.g. i.pg.EEC1.EngineSpeed = data[0]; )?
Any input will be appreciated.

Topic archived. No new replies allowed.