From db78d4324c7cd68b3a4a4e88246ae6b59dfa7d02 Mon Sep 17 00:00:00 2001
From: Davide Mor <davide.mor@skywarder.eu>
Date: Wed, 13 Sep 2023 16:48:57 +0200
Subject: [PATCH] [Radio][Transceiver] Added ConsoleTransceiver

---
 .../ConsoleTransceiver/ConsoleTransceiver.h   | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 src/shared/radio/ConsoleTransceiver/ConsoleTransceiver.h

diff --git a/src/shared/radio/ConsoleTransceiver/ConsoleTransceiver.h b/src/shared/radio/ConsoleTransceiver/ConsoleTransceiver.h
new file mode 100644
index 000000000..75cee7c18
--- /dev/null
+++ b/src/shared/radio/ConsoleTransceiver/ConsoleTransceiver.h
@@ -0,0 +1,47 @@
+/* Copyright (c) 2023 Skyward Experimental Rocketry
+ * Authors: Davide Mor, Niccolò Betto
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <filesystem/console/console_device.h>
+#include <radio/Transceiver.h>
+
+namespace Boardcore
+{
+
+class ConsoleTransceiver : public Transceiver
+{
+public:
+    bool send(uint8_t* pkt, size_t len)
+    {
+        auto serial = miosix::DefaultConsole::instance().get();
+        return serial->writeBlock(pkt, len, 0) == static_cast<ssize_t>(len);
+    }
+
+    ssize_t receive(uint8_t* pkt, size_t len)
+    {
+        auto serial = miosix::DefaultConsole::instance().get();
+        return serial->readBlock(pkt, len, 0);
+    }
+};
+
+}  // namespace Boardcore
-- 
GitLab