ok, I never had to do this before and i want to know what the best way to do this is.
i have a struct like
struct status
{
uint16_t heading;
uint8_t speed;
uint8_t battery;
uint8_t event;
uint8_t headlights;
};
what I want to do is use a UART connection to send this data. first two bytes heading and the remaining bytes speed battery event and headlights in that order.
The function prototype for the UART is this:
void UARTSend( uint32_t portNum, uint8_t *BufferPtr, uint32_t Length );
now I would like a simple way of just sending the struct, i know i will have to use pointers but i am not sure how to use them in this case.
instead i have done the following.
void transmit(struct status stat)
{
uint8_t data[6];
data[0] = stat.heading & 0x00FF;
data[1] = (stat.heading & 0xFF00)>>8;
data[2] = stat.speed;
data[3] = stat.battery;
data[3] = stat.event;
data[4] = stat.headlights;
UARTSend( 0, data, sizeof(data));
}
Does anyone know if a cleaner way to do this?