Hi, I have a structure in a library that defines various parameters for wireless transmission. I want to create an array of these structures, which each element in the array containing the required parameters for a particular wireless channel.

The structure:

typedef struct S_RF_RXTXPAIR_SETTINGS {
    byte    modem0;             // Baudrate, xosc_freq, dataformat
    byte    modem1;             // settling, peakdetect
    byte    modem2;             // Peak level offset
    byte    freq_2a;            // RX channel frequency (A)
    byte    freq_1a;
    byte    freq_0a;
    byte    freq_2b;            // TX channel frequency (B)
    byte    freq_1b;
    byte    freq_0b;
    byte    fsep1;              // Frequency seperation
    byte    fsep0;
    byte    pll_rx;             // refdiv
    byte    pll_tx;             // refdiv
    byte    current_rx;         // vco_current, lo_drive, pa_drive
    byte    current_tx;         // vco_current, lo_drive, pa_drive
    byte    frend;              // buf_current, lna_current
    byte    pa_pow;             // TX output power
    byte    match;              // rx_match, tx_match
    byte    prescaler;          // pre_swing, pre_current
} RF_RXTXPAIR_SETTINGS;

My attempt at defining the array is as follows:

RF_RXTXPAIR_SETTINGS code RF_SETTINGS[2]; 
RF_SETTINGS[1] = {0xA8,0x2F,0x37,0x50,0xA0,0x00,0x41,0xF6,0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,0xFF,0xC0,0x00};
RF_SETTINGS[2] = {0xA8,0x2F,0x37,0x50,0xA8,0x00,0x41,0xF6,0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,0xFF,0xC0,0x00};

It has been a while since i have done any C programming, an i cant seem to find a good example of what i am trying to do. Any help would be greatly appreciated.

Recommended Answers

All 2 Replies

What you are doing will work i.e. RF_RXTXPAIR_SETTINGS code RF_SETTINGS[2];

If you want to dynamically assign an array size at runtime, you could do

RF_SETTINGS = malloc (number_of_elements * sizeof(RF_RXTXPAIR_SETTINGS));

Well the first thing you need to remember is arrays start at 0, not 1.

2. Arrays can be initialised, not assigned, eg

RF_RXTXPAIR_SETTINGS RF_SETTINGS[2] = {
    {0xA8,0x2F,0x37,0x50,0xA0,0x00,0x41,0xF6,
     0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,
     0xFF,0xC0,0x00},
    {0xA8,0x2F,0x37,0x50,0xA8,0x00,0x41,0xF6,
     0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,
     0xFF,0xC0,0x00}
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.