Created
December 19, 2019 18:47
-
-
Save notpike/fae67284205e034e3177a4fbcca60270 to your computer and use it in GitHub Desktop.
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 <inttypes.h> | |
uint8_t checksum(uint8_t *in) { | |
uint8_t crc = 0x07; // CRC Magic Number | |
int i; | |
for (i = 7; i <= 61; i ++) { // CRC for 54Byte LED Matrix | |
crc = crc ^ in[i] & 0xff; // Each Byte is XORed ontop of the last | |
} | |
return crc; | |
} | |
int main() { | |
uint8_t msg[64] = {0xFA, 0x03, 0x00, 0x39, 0x01, 0x00, 0x06, // Starting Bytes | |
0xC0, 0X00, 0X00, 0X00, 0X00, 0X00, // LED Matrix | |
0x00, 0X00, 0X00, 0X00, 0X00, 0X00, | |
0x00, 0X00, 0X00, 0X00, 0X00, 0X00, | |
0x00, 0X00, 0X00, 0X00, 0X00, 0X00, | |
0x00, 0X00, 0X00, 0X00, 0X00, 0X00, | |
0x00, 0X00, 0X00, 0X00, 0X00, 0X00, | |
0x00, 0X00, 0X00, 0X00, 0X00, 0X00, | |
0x00, 0X00, 0X00, 0X00, 0X00, 0X00, | |
0x00, 0X00, 0X00, 0X00, 0X00, 0X00}; | |
msg[62] = checksum(msg); // Get CRC | |
msg[63] = 0x55; // Ending Bytes | |
msg[64] = 0xa9; // Ending Bytes | |
// Check values | |
int i; | |
for(i = 0; i <= 64; i++) { | |
printf("Msg %i: %i\n", i, msg[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment