Skip to content

Instantly share code, notes, and snippets.

@repen
Created November 20, 2021 16:57
Show Gist options
  • Save repen/8fb04c84cf0aa026901d8647e4000335 to your computer and use it in GitHub Desktop.
Save repen/8fb04c84cf0aa026901d8647e4000335 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define MESSAGE_QUANTITY 10;
struct LEDMessage{
unsigned char led_code;
unsigned char value;
unsigned int hash_sum;
};
#pragma pack(push, 1)
union UMessage{
unsigned char bytes[60];
struct LEDMessage message_array[10];
};
#pragma pack(pop)
struct LEDMessage message_provider(unsigned char code, unsigned char val, unsigned int hash);
void accumulated_messages(void);
void convert_byte_to_struct(unsigned char *byte);
int main() {
union UMessage messages;
// заполняю массив сообщениями в union
for (int i = 0; i < 10; ++i) {
messages.message_array[i] = message_provider(1 + i, 0, 0xDD3322AA);
}
// получаю последовательность байтов из union так как данные лежат в одной области памяти
for (int i = 0; i < 60; ++i) {
printf("index[%d]Byte: %d\n", i, messages.bytes[i]);
}
// accumulated_messages();
return 0;
}
struct LEDMessage message_provider(unsigned char code, unsigned char val, unsigned int hash){
struct LEDMessage temp = {code, val, hash};
return temp;
};
void accumulated_messages(){
for (int i = 0; i < 10; i++) {
printf("i = %d\n", i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment