You’re implementing a communication packet for transmission. Each packet is 6 bytes structured as follows:
| Field | Size (bytes) |
| Start Byte | 1 |
| Command | 1 |
| Data (2B) | 2 |
| CRC | 1 |
| End Byte | 1 |
Your task is to:
- Define a union that overlays:
- a struct view of these fields, and
- a uint8_t[6] array view
- Accept values for start, command, data (16-bit), CRC, and end
- Fill the packet struct
- Print the raw 6-byte array using the byte array view
Example-1
Input: start = 0xA5, cmd = 0x01, data = 0x1234, crc = 0x77, end = 0x5A
Output: 165 1 52 18 119 90
Example-2
Input: start = 0xAA, cmd = 0xFF, data = 0x00FF, crc = 0xFE, end = 0x55
Output: 170 255 255 0 254 85