Struct within a Struct

I have struct with nested structs .
I get no errors but when I try to use it the second set of structs are ignore with code complete.
example: cal. Does not show data
Ray.

#ifndef _CAL
#define _CAL

#include <Arduino.h>
#include <stdint.h>


typedef struct { 
    uint8_t PacketHi = 0x10;
    uint8_t PacketLo = 0x00;
    uint8_t PacketID = 0x04;
    uint8_t  dummy1Byte = 0x00;//reqired so cal size is even number
    uint8_t  dummy2Byte = 0x00; // Required so cal size is even number
    struct RealTime_Data {
        uint8_t startChar =0x24; // $ Start character
        uint8_t PacketHi = 0x10;
        uint8_t PacketLo = 0x00; 
        uint8_t PacketID = 0x04;
        uint16_t rpm = 845;
        uint16_t ect = 120;
        uint16_t map = 101;
        uint16_t tps = 0;
        uint16_t vehicalSpeed = 0;
        uint16_t oiltemp = 80;
        uint16_t oilpress = 150;
        uint8_t slector = 0;
        uint8_t gear = 0;
        uint8_t solState[6] = { 0,0,0,0,0,0, };
        uint16_t oilpumpPwmhz = 0;
        uint8_t duty = 50;
    }data;

    struct CAN_BUS {
        uint16_t frame1ID = 100;
        uint16_t frame2ID = 101;
    }can;
    struct TransControl {
        uint16_t Hz = 120;
        uint16_t pressTable[5][10]{ {100,100,100,100,100,100,100,100,100,100},
                                    {100,100,100,100,100,100,100,100,100,100},
                                    {120,120,120,120,120,130,130,140,140,140},
                                    {130,130,140,140,150,160,170,180,190,200},
                                    {150,160,180,200,220,260,270,280,290,300}};

    }tc;

    uint16_t checkSum = 0;

}ECU_Cal;

extern ECU_Cal cal;



#endif // End Cal.h

Please post a complete code that compiles and demonstrates the problem.

I recommend typedef-ing the internal struct:

typedef struct RealTime_Data {
        uint8_t startChar =0x24; // $ Start character
        uint8_t PacketHi = 0x10;
        uint8_t PacketLo = 0x00; 
     :
} rtdata_t;

typedef struct { 
    uint8_t PacketHi = 0x10;
    uint8_t PacketLo = 0x00;
    uint8_t PacketID = 0x04;
    rtdata_t RealTime_Data;
    :
}  ECU_Cal_t;

(Hmm.  Can you really assign values in a typedef?)

I recommend typedef-ing the internal struct:<
That did not help it is like the code complete is not looking beyond the first main struct.
Ray.

Then post that code. Perhaps there is a different issue.

I know what complete code is, but what be “code complete”?

If it is some tool to help you write code, you may be asking more of it than it is capable of.

a7

If I run this code:

#include <Arduino.h>
#include <stdint.h>

typedef struct 
{ 
    uint8_t PacketHi = 0x10;
    uint8_t PacketLo = 0x00;
    uint8_t PacketID = 0x04;
    uint8_t  dummy1Byte = 0x00;//reqired so cal size is even number
    uint8_t  dummy2Byte = 0x00; // Required so cal size is even number
    
    struct RealTime_Data 
    {
        uint8_t startChar =0x24; // $ Start character
        uint8_t PacketHi = 0x10;
        uint8_t PacketLo = 0x00; 
        uint8_t PacketID = 0x04;
        uint16_t rpm = 845;
        uint16_t ect = 120;
        uint16_t map = 101;
        uint16_t tps = 0;
        uint16_t vehicalSpeed = 0;
        uint16_t oiltemp = 80;
        uint16_t oilpress = 150;
        uint8_t slector = 0;
        uint8_t gear = 0;
        uint8_t solState[6] = { 0,0,0,0,0,0, };
        uint16_t oilpumpPwmhz = 0;
        uint8_t duty = 50;
        
    }data;

    struct CAN_BUS 
    {
        uint16_t frame1ID = 100;
        uint16_t frame2ID = 101;
    }can;
    
    struct TransControl 
    {
        uint16_t Hz = 120;
        uint16_t pressTable[5][10]{ {100,100,100,100,100,100,100,100,100,100},
                                    {100,100,100,100,100,100,100,100,100,100},
                                    {120,120,120,120,120,130,130,140,140,140},
                                    {130,130,140,140,150,160,170,180,190,200},
                                    {150,160,180,200,220,260,270,280,290,300}};

    }tc;

    uint16_t checkSum = 0;

}ECU_Cal;

ECU_Cal cal;

void setup( void )
{
    Serial.begin(115200);
    Serial.println( cal.PacketID, HEX );
    Serial.println( cal.data.rpm );
    Serial.println( cal.can.frame2ID );
    Serial.println( cal.tc.Hz );
    
    while(1);
}

void loop( void )
{
}//loop

I am able to access random members within each struct within "cal."

How are you trying to access them?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.