diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbe9c82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/ \ No newline at end of file diff --git a/ES_Grobkonzept.pdf b/ES_Grobkonzept.pdf new file mode 100644 index 0000000..a8c5e3f Binary files /dev/null and b/ES_Grobkonzept.pdf differ diff --git a/Software/CRC_Test/.gitignore b/Software/CRC_Test/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/Software/CRC_Test/.gitignore @@ -0,0 +1 @@ +build diff --git a/Software/CRC_Test/crc.c b/Software/CRC_Test/crc.c new file mode 100644 index 0000000..e3fb732 --- /dev/null +++ b/Software/CRC_Test/crc.c @@ -0,0 +1,110 @@ +#include +#include +#include +#include + +// Berechnen einer 8 Bit CRC-Pruefsumme +uint8_t crc8(uint8_t* data, size_t size); + +// Berechnen einer 32 Bit CRC-Pruefsumme +uint32_t crc32(uint8_t* inBytes, size_t size, uint32_t polynomial); + +// Check einer 32 Bit CRC-Pruefsumme +int checkCrc32(uint8_t* data, size_t size, uint32_t crc, uint32_t polynomial); + +int main() +{ + char msg[] = "Hello World!\0\0\0\0"; + uint32_t crc = crc32((uint8_t*) msg, strlen(msg)+4, 0x4C11DB7); + printf("CRC32 of '%s': 0x%08x\n\n", msg, crc); + + int crcValid = checkCrc32((uint8_t*) msg, strlen(msg), crc, 0x4C11DB7); + // String einlesen und CRC32 ausgeben + // char input[1024]; + // printf("String eingeben:\n"); + // while (1) + // { + // // Liest eine Zeile von stdin ein und speichert sie in 'eingabe' + // if (fgets(input, sizeof(input), stdin) != NULL) { + // // Entfernt das Newline-Zeichen, das fgets hinzufügt + // size_t laenge = strlen(input); + // if (laenge > 0 && input[laenge - 1] == '\n') { + // input[laenge - 1] = '\0'; + // } + // } + + // crc = crc32((uint8_t*) input, strlen(input)); + // printf("'%s' -> 0x%08x\n\n", input, crc); + // } + + return 0; +} + +uint8_t crc8(uint8_t* inBytes, size_t size) +{ + uint8_t crc = 0x0; // initial value + uint8_t polynomial = 0x7; + + for (size_t i = 0; i < size; i++) { + for (int bit = 7; bit >= 0; bit--) { + // get next bit + uint8_t inBit = (inBytes[i] & (1<= 0; bit--) { + // get next bit + uint8_t inBit = (inBytes[i] & (1<