Created
July 7, 2022 00:17
-
-
Save Xevion/f47edbb6b28d044e43bf2f7a2aa8014c to your computer and use it in GitHub Desktop.
Addressed Single Block Write Union Magic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <string.h> | |
struct AddressedSingleBlockWrite { | |
uint8_t Flag; | |
uint8_t Command; | |
uint8_t Address[8]; | |
uint8_t Block; | |
uint8_t Data[4]; | |
}; | |
union ASBUnion { | |
uint8_t data[15]; | |
struct AddressedSingleBlockWrite marshalled; | |
}; | |
int main() { | |
struct AddressedSingleBlockWrite command; | |
command.Flag = 0x20 | 0x40; | |
command.Command = 0x21; | |
uint8_t address[8] = {0xA7, 0x3E, 0xFF, 0x58, 0x21, 0x32, 0x10, 0xFE}; | |
memcpy(&command.Address, &address, sizeof(command.Address)); | |
command.Block = 0x05; | |
uint8_t data[4] = {0x11, 0x22, 0x33, 0x44}; | |
memcpy(&command.Data, &data, sizeof(command.Data)); | |
union ASBUnion demarshalled; | |
demarshalled.marshalled = command; | |
for (int i = 0; i < 15; i++) { | |
printf("%x ", demarshalled.data[i]); | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment