#include <stdio.h>
#include <stdint.h>
void build_packet(uint8_t command, uint16_t value, uint8_t status, uint32_t checksum) {
uint8_t buff[10];
for (int i=0;i<10;i++){
switch(i){
case 0:
buff[i]=0xA5;
break;
case 1:
buff[i]=command;
break;
case 2:
buff[i]=value & (0xff);
break;
case 3:
buff[i]=value>>8;
break;
case 4:
buff[i]=status;
break;
case 5:
buff[i]=checksum & (0xff);
break;
case 6:
buff[i]=(checksum>>8) & (0xff);
break;
case 7:
buff[i]=(checksum>>16) & (0xff);
break;
case 8:
buff[i]=(checksum>>24) & (0xff);
break;
case 9:
buff[i]=0x5A;
break;
}
}
for (int i=0;i<10;i++)
printf("%d ",buff[i]);
// Your logic to fill buffer
// Then print buffer
}
int main() {
uint8_t cmd, status;
uint16_t val;
uint32_t crc;
scanf("%hhu %hu %hhu %u", &cmd, &val, &status, &crc);
build_packet(cmd, val, status, crc);
return 0;
}
Input
1 4660 1 2864434397
Expected Output
165 1 52 18 1 221 204 187 170 90