From 6e82c1e201fc21bda18972b456128ea8f6b9f32c Mon Sep 17 00:00:00 2001
From: zeisele <zeisele@iastate.edu>
Date: Mon, 21 Mar 2022 04:24:43 +0100
Subject: [PATCH] fix decoding packet

---
 groundStation/adapters/crazyflie/src/cf_adapter.c | 4 ++--
 groundStation/src/backend/packet.c                | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/groundStation/adapters/crazyflie/src/cf_adapter.c b/groundStation/adapters/crazyflie/src/cf_adapter.c
index 84871e5b4..9cc1912de 100644
--- a/groundStation/adapters/crazyflie/src/cf_adapter.c
+++ b/groundStation/adapters/crazyflie/src/cf_adapter.c
@@ -267,11 +267,11 @@ size_t getSinglePacket(int fd, uint8_t * packet, int pSize){
 
     //Get to data size bytes to find out total packet size
     while(curLoc<6){
-        curLoc += recv(fd, packet,6,MSG_WAITALL);
+        curLoc += recv(fd, packet,7,MSG_WAITALL);
     }
 
     //get the total packet size
-    totalPacketSize = packetSize(*(packet+4)<<8 | (*(packet +5)));
+    totalPacketSize = packetSize(*(packet+5)<<8 | (*(packet +6)));
     printf("\t\ttotal packet size %d\n",totalPacketSize);
 
     //check that the total packet size isnt unreasonable TODO is this a valid check?
diff --git a/groundStation/src/backend/packet.c b/groundStation/src/backend/packet.c
index 020827e58..bbbaf67f1 100644
--- a/groundStation/src/backend/packet.c
+++ b/groundStation/src/backend/packet.c
@@ -20,7 +20,7 @@ ssize_t EncodePacket(
 	packet[BEGIN] = BEGIN_CHAR;
 	packet[MTYPE_L] = LSByte16(m->msg_type);
 	packet[MTYPE_H] = MSByte16(m->msg_type);
-	memcpy(packet[ID_L], m->msg_id, 2);
+	memcpy(&packet[ID_L], &m->msg_id, 2);
 	packet[DLEN_L] = LSByte16(m->data_len);
 	packet[DLEN_H] = MSByte16(m->data_len);
 	memcpy(&packet[HDR_SIZE], data, m->data_len);
-- 
GitLab