The problem is that I have a struct that is member of another (major) struct. I've written a function to clear the first struct (it takes a pointer to struct).
I would like to use that function to clear the struct inside the major structure, but I don't know exactly which is the correct way of doing that.
To explain it better, here is some code:
I have a structure, defined as:
typedef struct
{
unsigned char next;
unsigned char first;
unsigned long data[TCP_RX_BUFFER+1];
}struct_circ_buff;
and a function to clear it:
void clearCircularBuffer(volatile struct_circ_buff *circular_buffer)
{
int i=0;
for(i=0;i<TCP_RX_BUFFER+1;i++)
circular_buffer->data[i]=0;
circular_buffer->first=0;
circular_buffer->next=0;
}
Then, I have another struct which includes struct_circ_buff
:
typedef struct
{
volatile unsigned char sensorType;
volatile uint16_t sensorFlag;
volatile struct_circ_buff st_circular_buffer;
}struct_sens;
and I would like to write a function that would clean this struct, using the clearCircularBuffer
function written above. How could I do that?
void clear_sensors_struc (volatile struct_sens *sensors_struct)
{
sensors_struct->sensorFlag=0;
sensors_struct->tipoSensor=0;
//NOW, HOW CAN I USE clearCircularBuffer to clean sensors_struct->
//st_circular_buffer??
//this way compiles fine, but i don´t think it´s correct
clearCircularBuffer(&(sensors_struct->st_circular_buffer));
//this way wouldn´t even compile
clearCircularBuffer(sensors_struct->st_circular_buffer));
}
Finally, I have a variable declared as:
struct_sens struct_sensores[MAX_NUMBER_OF_SENSORS];
and I would like to write a function that would clean that array of structures...
So how could I use clear_sensors_struc
function to do that?
void clear_sensors_struc_array(struct_sens *sensors_struct)
{
struct_sens aux_str[MAX_NUMBER_OF_SENSORS];
int i=0;
for(i=0;i<MAX_NUMBER_OF_SENSORS;i++)
{
clear_sensors_struc(&aux_str[i]);
*(sensors_struct+i)=aux_str[i];
}
}
Is there any way of doing that without defining an internal struct_sens aux_str?