Hi everyone.
I am trying to build a class constructor that can take multiple different struct arrays, where the object modifies the original arrays, not copies. I found this example for a single array and successfully adjusted it for my project.
The trouble is, I don't really understand the syntax in the constructor, so I don't know how to add a reference to the second array (struct Signal_decode signals[]) or if it is even possible.
struct Can_frame {
uint32_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
uint8_t can_dlc; /* Data Length Code (number of data bytes)*/
uint8_t data[8];
};
struct Signal_decode {
uint32_t signal_frame;
uint8_t start_byte;
uint8_t end_byte;
uint8_t start_bit;
uint8_t number_of_bits;
};
Can_frame raw_frames[] =
{
{0x5E8, 8, 0x05, 0xEF, 0x02, 0x0D, 0x06, 0x5D, 0x00, 0x8F},
{0x5E9, 8, 0x6C, 0xDB, 0x6C, 0xDB, 0x01, 0xF5, 0x00, 0x96},
{0x5EA, 8, 0x7A, 0xAA, 0x03, 0xE8, 0x00, 0x00, 0x6C, 0xDB},
{0x5EB, 8, 0x05, 0xEF, 0x02, 0x0D, 0x06, 0x5D, 0x00, 0x8F},
{0x5EC, 8, 0x05, 0xEF, 0x02, 0x0D, 0x06, 0x5D, 0x00, 0x8F}
};
struct Signal_decode signals[] =
{
{0x5E8, 0, 1, 0, 16},
{0x5E8, 2, 3, 0, 16},
{0x5E8, 4, 5, 0, 16},
{0x5E8, 6, 7, 0, 16}
};
class FrameHandler{
public:
template <size_t N>
FrameHandler(Can_frame (&raw_frames)[N])
: raw_frames(raw_frames), length(N) {}
void printLocations() const {
for (size_t i = 0; i < length; ++i)
Serial.println(raw_frames[i].can_id);
}
private:
Can_frame *raw_frames;
size_t length;
};
FrameHandler canTest = raw_frames;
void setup() {
Serial.begin(115200);
while (!Serial);
canTest.printLocations();
}
void loop() {}
Any help would be greatly appreciated.
Many thanks.