From d4413e6a361aafe6922431e1369589403a63b312 Mon Sep 17 00:00:00 2001
From: "leon.bohnwagner" <leon.bohnwagner@informatik.hs-fulda.de>
Date: Thu, 13 Feb 2025 02:17:04 +0100
Subject: [PATCH] feat: add packet struct

---
 common/include/message.h |  2 +-
 kernel/kmod.c            | 13 ++++++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/common/include/message.h b/common/include/message.h
index 0ee2b9a..4805aba 100644
--- a/common/include/message.h
+++ b/common/include/message.h
@@ -15,7 +15,7 @@ typedef s64 int64_t;
 #include <stdint.h>
 #endif
 
-#define MAX_MESSAGE_DATA_SIZE 4096
+#define MAX_MESSAGE_DATA_SIZE 8
 
 enum message_data_type {
   INT8,
diff --git a/kernel/kmod.c b/kernel/kmod.c
index d36d71b..ab812ef 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -35,6 +35,11 @@ static atomic_t wake_counter = ATOMIC_INIT(0);
 
 static int slot = 0;
 
+typedef struct packet {
+    message_t data;
+    uint32_t crc;
+} packet_t;
+
 static int device_open(struct inode *inode, struct file *file)
 {
     return 0;
@@ -110,10 +115,12 @@ static int timed_thread_fn(void *args) {
         atomic_dec(&wake_counter);
 
         if (slot == 0) {
-            uint32_t crc = calculate_crc32(&message, sizeof(message));
+            packet_t packet;
+
+            packet.data = *message;
+            packet.crc = calculate_crc32(&packet.data, sizeof(&packet.data));
 
-            send_data(&message, sizeof(message));
-            send_data(&crc, sizeof(uint32_t));
+            send_data(&packet, sizeof(packet));
         }
 
         slot = (slot + 1) % SLOTS;
-- 
GitLab