From 6cb3c15f5d932b7b2c3150b351cf88cc4c518c4a Mon Sep 17 00:00:00 2001
From: 488_MP-4 <488_MP-4@iastate.edu>
Date: Wed, 25 Oct 2023 18:49:22 +0200
Subject: [PATCH] adding functionality to send packets back

---
 .../crazyflie_connection.cpython-38.pyc       | Bin 2650 -> 2650 bytes
 .../groundstation_socket.cpython-38.pyc       | Bin 4253 -> 4253 bytes
 cflib_groundstation/groundstation_socket.py   |  15 +++++++
 cflib_groundstation/main.py                   |  38 +++++++++++++++++-
 4 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/cflib_groundstation/__pycache__/crazyflie_connection.cpython-38.pyc b/cflib_groundstation/__pycache__/crazyflie_connection.cpython-38.pyc
index 46a66108eef65d96e5e41d73bf7defe483a5523d..e6d5daf61a108acc7e4a3a17e2ac232b2a13e297 100644
GIT binary patch
delta 20
acmca5a!Z6el$V!_0SL}mTW;j`=K=sWVg$AT

delta 20
acmca5a!Z6el$V!_0SGLPm~G_t=K=sVeFUfg

diff --git a/cflib_groundstation/__pycache__/groundstation_socket.cpython-38.pyc b/cflib_groundstation/__pycache__/groundstation_socket.cpython-38.pyc
index 704af640fbe957aa1ab2b02b8e7b8d6685ee8597..8992ae1d5dc36d7cf4ca436430a295654b520bb4 100644
GIT binary patch
delta 857
zcmZva&rcIU6vrLeZfiGNH$g*EN@5MP-AGHd5?g)*nzmSlme8fq;Gsc_Nr_gOHu2ZR
zt4H(B95@m#Aa`%Zi+9Z&OgM7zFYw~~Zc!HOZswEOw=<vj=Iw4rx1&bgG=mrT`Zk?A
zFg^{8D}R2WQLo;6s0?Shu-I@`Yo&Ze`CiIayQ{Rvt#(uC&sv@CMqAPGKujpIv`rB|
ze5cKb_%NH~5JPF5jds(%C`S>A0r7uG9RBp}2;TYLKWvS0_^n=C@2*c>v#-b@+Vf9}
z>vZIQZI19OTkk2x=xHEhc^t4sX*aN+&0u;Pn7{_#$p!@GfILHqmbU<eXX)dmHxU&3
zx6FBjJt-&_{9xM%-T<P&EKmea7rL_q{RqAgNh%u?n<czo0PX@Q;0}-la=;WY4a@+y
zfb&Mgl8h%jIu;`!v@^F%(vgv^yA2RnZ7{0bfwKjy=>?}=X)N`c)GrGR&v|q-2C~Qu
z%n#E1c>Edo#rWSWZ*q7oP^uOig>t^u_XKck@i=v-**!vGGc|bMwd&q_>5(~V_p7nS
zYhS^mGkTqnHP`gTlwp|UBCrHhfGV&|E1`<vX$b9xR`}oh9r}8;UmAzLU!D{WnO4MC
bW`UxV6}Isiq}yj4N1_(#0Ou97WsUy<ker=!

delta 857
zcmZvaO-~b16o$Proz_mKOrkZWtwI3@M=L7OrV_uJwoua#1GUjy7Yzy~C0gLNiC-JH
zF3nlEV&RgwQQ5mQEcgMCE=*Xm@E5r8yi<h%I+Oe4&Y63kbMBd0i?79vnrQ}4@bzgc
z_09O+myrI<biG!&|5zH;2iao1`fx6vDR+D;s?lsq?P;UAAoUlGR(r82X|K-~k}PdW
z#5dk)x5VgKHmNY9qqP>B3(iS(0g*u<zK@}eU%t<RcfR*WtpN_d)pPUh`KdwYj0)2i
ze^SI~*Z<l)$FCf{s~Di?feFjwfGtYvfv@QVrdNSW*x>uO0f96y#psBJw*Z7w^zqc2
z7>fO0=1qh>Daa0faE1}Q2t<Jta2q&S=+1^{C%7zZDj3(6?%@4h;2tmvTnBCd<G=(k
z2_%6lz)>S&HscwOmc<AN?a-}k+BMQOw*dmH4Mv4KaJT@eXREbxz0_?|uPiXU<k8X?
z$f6Q3KXUkS?+5Ukaonsfb65uQm0Uer$jtRT0UWD54%`mA&r`%4JDqi{y0>0>Vvaby
zYAo{FSMcbJZYNaHHT^VI1SXXO^1w7O0~BaBR5m;fq4m%#|9gKzo8ew*O0?ad6eTjP
dm@mTuNn=*T!DmozpK%<8T2u)*s-RUX@fQl6mQw%#

diff --git a/cflib_groundstation/groundstation_socket.py b/cflib_groundstation/groundstation_socket.py
index 803726dc3..edbf47da7 100644
--- a/cflib_groundstation/groundstation_socket.py
+++ b/cflib_groundstation/groundstation_socket.py
@@ -92,6 +92,21 @@ class GroundstationSocket():
 
     def EncodePacket(self, messagedata):
         print("encoding packet")
+        bytedata = bytearray(Message.BEGIN_CHAR.value)
+        bytedata.append(messagedata["msg_type"] & 0xFF)
+        bytedata.append((messagedata["msg_type"] >> 8) & 0xFF)
+        bytedata.append(messagedata["msg_id"])
+        bytedata.append(messagedata["data_len"] & 0xFF)
+        bytedata.append((messagedata["data_len"] >> 8) & 0xFF)
+        bytedata.append(messagedata["data"])
+        bytedata.append(self.packetChecksum(messagedata, PacketHeader.HDR_SIZE.value + messagedata["data_len"] + ChecksumFormat.CSUM_SIZE.value))
+        return bytedata
+
+    def WriteToBackend(self, message):
+        messagedata = self.EncodePacket(message)
+        self.connection.send(messagedata)
+
+
 
 
 
diff --git a/cflib_groundstation/main.py b/cflib_groundstation/main.py
index 76e489c3c..4f6d633d7 100644
--- a/cflib_groundstation/main.py
+++ b/cflib_groundstation/main.py
@@ -1,7 +1,7 @@
 from email import message
 from queue import Queue
 from threading import Thread
-from groundstation_socket import GroundstationSocket
+from groundstation_socket import GroundstationSocket, MessageTypeID
 from crazyflie_connection import CrazyflieConnection
 
 
@@ -16,12 +16,48 @@ class main():
         gs = GroundstationSocket()
         self.inThread = Thread(target = gs.groundstation_connect, args = (self.inputQueue,))
         self.inThread.start()
+        cfConnect = CrazyflieConnection()
         while True:
             if self.inputQueue.not_empty:
                 command = self.inputQueue.get()
                 print(command)
                 msg_type = command["msg_type"]
                 print(msg_type)
+                if msg_type == MessageTypeID.GETPACKETLOGS_ID.value:
+                    cfConnect.GetPacketLogs()
+                elif msg_type == MessageTypeID.UPDATE_ID.value:
+                    cfConnect.Update()
+                elif msg_type == MessageTypeID.BEGINUPDATE_ID.value:
+                    cfConnect.BeginUpdate()
+                elif msg_type == MessageTypeID.OUTPUT_OVERRIDE_ID.value:
+                    cfConnect.OverrideOuput()
+                elif msg_type == MessageTypeID.GETNODES_ID.value:
+                    cfConnect.GetNodes()
+                elif msg_type == MessageTypeID.SETPARAM_ID.value:
+                    cfConnect.SetParam()
+                elif msg_type == MessageTypeID.GETPARAM_ID.value:
+                    cfConnect.GetParam()
+                elif msg_type == MessageTypeID.SETSOURCE_ID.value:
+                    cfConnect.SetSource()
+                elif msg_type == MessageTypeID.GETSOURCE_ID.value:
+                    cfConnect.GetSource()
+                elif msg_type == MessageTypeID.RESPSOURCE_ID.value:
+                    cfConnect.RespSource()
+                elif msg_type == MessageTypeID.GETOUTPUT_ID.value:
+                    cfConnect.GetOutput()
+                elif msg_type == MessageTypeID.GETNODES_ID.value:
+                    cfConnect.GetNodes()
+                elif msg_type == MessageTypeID.ADDNODE_ID.value:
+                    cfConnect.AddNode()
+                elif msg_type == MessageTypeID.LOG_ID.value:
+                    cfConnect.GetLogFile()
+                elif msg_type == MessageTypeID.LOG_END_ID.value:
+                    cfConnect.LogBlockCommand()
+            
+            if self.outputQueue.not_empty:
+                message = self.outputQueue.get()
+                gs.WriteToBackend(message)
+
                 
 
                 
-- 
GitLab