From b1078e13621e6925d5a5aecaa14b6d0566dc8adb Mon Sep 17 00:00:00 2001 From: zxkmm Date: Wed, 17 Apr 2024 18:13:04 +0800 Subject: [PATCH 01/12] add serial_debug --- firmware/application/apps/ui_sstvtx.cpp | 4 ++ .../application/usb_serial_debug_bridge.cpp | 5 ++ .../application/usb_serial_debug_bridge.hpp | 53 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 firmware/application/usb_serial_debug_bridge.cpp create mode 100644 firmware/application/usb_serial_debug_bridge.hpp diff --git a/firmware/application/apps/ui_sstvtx.cpp b/firmware/application/apps/ui_sstvtx.cpp index 7358a854a..f9ce355f2 100644 --- a/firmware/application/apps/ui_sstvtx.cpp +++ b/firmware/application/apps/ui_sstvtx.cpp @@ -26,6 +26,8 @@ #include "portapack.hpp" #include "hackrf_hal.hpp" +#include "usb_serial_debug_bridge.hpp" + #include #include @@ -157,6 +159,8 @@ void SSTVTXView::start_tx() { // TX start, and asks for fill-up when a new scanline starts being read. This should // leave enough time for the code in prepare_scanline() before it ends. + UsbSerialDebugBridge::ppdbg("JammerView::start_tx()"); + scanline_counter = 0; prepare_scanline(); // Preload one scanline diff --git a/firmware/application/usb_serial_debug_bridge.cpp b/firmware/application/usb_serial_debug_bridge.cpp new file mode 100644 index 000000000..3b6fb223f --- /dev/null +++ b/firmware/application/usb_serial_debug_bridge.cpp @@ -0,0 +1,5 @@ +// +// Created by zxkmm on 24-4-17. +// + +#include "usb_serial_debug_bridge.hpp" diff --git a/firmware/application/usb_serial_debug_bridge.hpp b/firmware/application/usb_serial_debug_bridge.hpp new file mode 100644 index 000000000..7b2adc800 --- /dev/null +++ b/firmware/application/usb_serial_debug_bridge.hpp @@ -0,0 +1,53 @@ +/* +* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. +* Copyright (C) 2017 Furrtek +* Copyleft (ɔ) 2024 zxkmm with the GPL license +* +* This file is part of PortaPack. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; see the file COPYING. If not, write to +* the Free Software Foundation, Inc., 51 Franklin Street, +* Boston, MA 02110-1301, USA. + */ + +#ifndef MAYHEM_FIRMWARE_USB_SERIAL_DEBUG_BRIDGE_H +#define MAYHEM_FIRMWARE_USB_SERIAL_DEBUG_BRIDGE_H + +#include +#include +#include +#include +#include "usb_serial_device_to_host.h" + +class UsbSerialDebugBridge { + + public: + static void ppdbg(const std::string& data) { + std::ostringstream oss; + oss << data; + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", oss.str().c_str()); + } + + static void ppdbg(const std::vector& data) { + std::ostringstream oss; + for (const auto& item : data) { + oss << item << ' '; + } + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", oss.str().c_str()); + } + +}; + + +#endif // MAYHEM_FIRMWARE_USB_SERIAL_DEBUG_BRIDGE_H \ No newline at end of file From 37ae5ff8cf47d875fd5fc95b4869e7e4c4ae80a8 Mon Sep 17 00:00:00 2001 From: zxkmm Date: Wed, 17 Apr 2024 18:50:19 +0800 Subject: [PATCH 02/12] not use OSS --- firmware/application/CMakeLists.txt | 1 + firmware/application/apps/ui_fileman.cpp | 4 + firmware/application/apps/ui_sstvtx.cpp | 4 - .../application/usb_serial_debug_bridge.hpp | 86 +++++++++++-------- 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 8fab990e5..69342a4f7 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -225,6 +225,7 @@ set(CPPSRC tone_key.cpp transmitter_model.cpp tuning.cpp + usb_serial_debug_bridge.hpp hw/debounce.cpp hw/encoder.cpp hw/max2837.cpp diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 2ad716ad5..843d0c260 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -35,6 +35,8 @@ #include "portapack.hpp" #include "event_m0.hpp" +#include "usb_serial_debug_bridge.hpp" + using namespace portapack; namespace fs = std::filesystem; @@ -322,6 +324,8 @@ void FileManBaseView::focus() { } void FileManBaseView::push_dir(const fs::path& path) { + UsbSerialDebugBridge::ppdbg(path); + if (path == parent_dir_path) { pop_dir(); } else { diff --git a/firmware/application/apps/ui_sstvtx.cpp b/firmware/application/apps/ui_sstvtx.cpp index f9ce355f2..dbe0794d6 100644 --- a/firmware/application/apps/ui_sstvtx.cpp +++ b/firmware/application/apps/ui_sstvtx.cpp @@ -26,7 +26,6 @@ #include "portapack.hpp" #include "hackrf_hal.hpp" -#include "usb_serial_debug_bridge.hpp" #include #include @@ -158,9 +157,6 @@ void SSTVTXView::start_tx() { // The baseband SSTV TX code (proc_sstv) has a 2-scanline buffer. It is preloaded before // TX start, and asks for fill-up when a new scanline starts being read. This should // leave enough time for the code in prepare_scanline() before it ends. - - UsbSerialDebugBridge::ppdbg("JammerView::start_tx()"); - scanline_counter = 0; prepare_scanline(); // Preload one scanline diff --git a/firmware/application/usb_serial_debug_bridge.hpp b/firmware/application/usb_serial_debug_bridge.hpp index 7b2adc800..6147ddd32 100644 --- a/firmware/application/usb_serial_debug_bridge.hpp +++ b/firmware/application/usb_serial_debug_bridge.hpp @@ -1,28 +1,28 @@ /* -* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. -* Copyright (C) 2017 Furrtek -* Copyleft (ɔ) 2024 zxkmm with the GPL license -* -* This file is part of PortaPack. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2, or (at your option) -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; see the file COPYING. If not, write to -* the Free Software Foundation, Inc., 51 Franklin Street, -* Boston, MA 02110-1301, USA. + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * Copyleft (ɔ) 2024 zxkmm with the GPL license + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ -#ifndef MAYHEM_FIRMWARE_USB_SERIAL_DEBUG_BRIDGE_H -#define MAYHEM_FIRMWARE_USB_SERIAL_DEBUG_BRIDGE_H +#ifndef USB_SERIAL_DEBUG_BRIDGE_H +#define USB_SERIAL_DEBUG_BRIDGE_H #include #include @@ -31,23 +31,35 @@ #include "usb_serial_device_to_host.h" class UsbSerialDebugBridge { - public: - static void ppdbg(const std::string& data) { - std::ostringstream oss; - oss << data; - chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", oss.str().c_str()); - } - - static void ppdbg(const std::vector& data) { - std::ostringstream oss; - for (const auto& item : data) { - oss << item << ' '; - } - chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", oss.str().c_str()); - } + template + static void ppdbg(const STRINGCOVER& data); + template + static void ppdbg(const std::vector& data); }; +template <> +void UsbSerialDebugBridge::ppdbg(const int64_t& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialDebugBridge::ppdbg(const uint64_t& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_uint(data).c_str()); +} + +template <> +void UsbSerialDebugBridge::ppdbg(const std::filesystem::path& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str()); +} + + +template +void UsbSerialDebugBridge::ppdbg(const std::vector& data) { + for (const auto& item : data) { + ppdbg(item); + } +} -#endif // MAYHEM_FIRMWARE_USB_SERIAL_DEBUG_BRIDGE_H \ No newline at end of file +#endif // USB_SERIAL_DEBUG_BRIDGE_H From 0e93c91a956f5ce17328aa2f2982ac86384fc4f0 Mon Sep 17 00:00:00 2001 From: zxkmm Date: Wed, 17 Apr 2024 19:19:44 +0800 Subject: [PATCH 03/12] add path print --- firmware/application/apps/ui_fileman.cpp | 3 ++- firmware/application/usb_serial_debug_bridge.hpp | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 843d0c260..9992ece27 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -324,7 +324,8 @@ void FileManBaseView::focus() { } void FileManBaseView::push_dir(const fs::path& path) { - UsbSerialDebugBridge::ppdbg(path); + uint64_t test = 99999999; + UsbSerialDebugBridge::ppdbg(test); if (path == parent_dir_path) { pop_dir(); diff --git a/firmware/application/usb_serial_debug_bridge.hpp b/firmware/application/usb_serial_debug_bridge.hpp index 6147ddd32..ff37c6d67 100644 --- a/firmware/application/usb_serial_debug_bridge.hpp +++ b/firmware/application/usb_serial_debug_bridge.hpp @@ -40,21 +40,26 @@ class UsbSerialDebugBridge { }; template <> +//usage: UsbSerialDebugBridge::ppdbg(num); void UsbSerialDebugBridge::ppdbg(const int64_t& data) { chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } template <> +//usage: UsbSerialDebugBridge::ppdbg(num); void UsbSerialDebugBridge::ppdbg(const uint64_t& data) { chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_uint(data).c_str()); } template <> +//usage: UsbSerialDebugBridge::ppdbg(path); void UsbSerialDebugBridge::ppdbg(const std::filesystem::path& data) { - chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str()); + std::string path_str = data.string(); + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", path_str.c_str()); } + template void UsbSerialDebugBridge::ppdbg(const std::vector& data) { for (const auto& item : data) { From 46e092655f3a251116ce599b57e845293f4aa30b Mon Sep 17 00:00:00 2001 From: zxkmm Date: Wed, 17 Apr 2024 19:37:01 +0800 Subject: [PATCH 04/12] add string print and vec --- firmware/application/apps/ui_fileman.cpp | 7 ++- .../application/usb_serial_debug_bridge.hpp | 54 ++++++++++++++++--- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 9992ece27..ddf3e423a 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -324,7 +324,12 @@ void FileManBaseView::focus() { } void FileManBaseView::push_dir(const fs::path& path) { - uint64_t test = 99999999; + std::vector test_vector; + test_vector.push_back(1); + test_vector.push_back(2); + test_vector.push_back(3); + UsbSerialDebugBridge::ppdbg(test_vector); + uint8_t test = 254; UsbSerialDebugBridge::ppdbg(test); if (path == parent_dir_path) { diff --git a/firmware/application/usb_serial_debug_bridge.hpp b/firmware/application/usb_serial_debug_bridge.hpp index ff37c6d67..57b923cbf 100644 --- a/firmware/application/usb_serial_debug_bridge.hpp +++ b/firmware/application/usb_serial_debug_bridge.hpp @@ -39,29 +39,69 @@ class UsbSerialDebugBridge { static void ppdbg(const std::vector& data); }; +/// value + template <> -//usage: UsbSerialDebugBridge::ppdbg(num); +// usage: UsbSerialDebugBridge::ppdbg(num); void UsbSerialDebugBridge::ppdbg(const int64_t& data) { chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } template <> -//usage: UsbSerialDebugBridge::ppdbg(num); +void UsbSerialDebugBridge::ppdbg(const int32_t& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialDebugBridge::ppdbg(const int16_t& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialDebugBridge::ppdbg(const int8_t& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialDebugBridge::ppdbg(const uint8_t& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialDebugBridge::ppdbg(const uint16_t& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> +void UsbSerialDebugBridge::ppdbg(const uint32_t& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); +} + +template <> void UsbSerialDebugBridge::ppdbg(const uint64_t& data) { - chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_uint(data).c_str()); + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } +/// path + template <> -//usage: UsbSerialDebugBridge::ppdbg(path); +// usage: UsbSerialDebugBridge::ppdbg(path); void UsbSerialDebugBridge::ppdbg(const std::filesystem::path& data) { std::string path_str = data.string(); chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", path_str.c_str()); } +/// string +template <> +// usage: UsbSerialDebugBridge::ppdbg(str); +void UsbSerialDebugBridge::ppdbg(const std::string& data) { + chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str()); +} - -template -void UsbSerialDebugBridge::ppdbg(const std::vector& data) { +///vec worker +// ussgae: UsbSerialDebugBridge::ppdbg(vec); +template +void UsbSerialDebugBridge::ppdbg(const std::vector& data) { for (const auto& item : data) { ppdbg(item); } From 8f8089fcf2cceacf6f6653967221b45360ef23c2 Mon Sep 17 00:00:00 2001 From: zxkmm Date: Wed, 17 Apr 2024 19:56:48 +0800 Subject: [PATCH 05/12] clean up --- firmware/application/apps/ui_fileman.cpp | 10 ---------- firmware/application/apps/ui_sstvtx.cpp | 1 - firmware/application/usb_serial_debug_bridge.cpp | 5 ----- firmware/application/usb_serial_debug_bridge.hpp | 14 ++++++++++++-- 4 files changed, 12 insertions(+), 18 deletions(-) delete mode 100644 firmware/application/usb_serial_debug_bridge.cpp diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index ddf3e423a..2ad716ad5 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -35,8 +35,6 @@ #include "portapack.hpp" #include "event_m0.hpp" -#include "usb_serial_debug_bridge.hpp" - using namespace portapack; namespace fs = std::filesystem; @@ -324,14 +322,6 @@ void FileManBaseView::focus() { } void FileManBaseView::push_dir(const fs::path& path) { - std::vector test_vector; - test_vector.push_back(1); - test_vector.push_back(2); - test_vector.push_back(3); - UsbSerialDebugBridge::ppdbg(test_vector); - uint8_t test = 254; - UsbSerialDebugBridge::ppdbg(test); - if (path == parent_dir_path) { pop_dir(); } else { diff --git a/firmware/application/apps/ui_sstvtx.cpp b/firmware/application/apps/ui_sstvtx.cpp index dbe0794d6..d6e8ca084 100644 --- a/firmware/application/apps/ui_sstvtx.cpp +++ b/firmware/application/apps/ui_sstvtx.cpp @@ -26,7 +26,6 @@ #include "portapack.hpp" #include "hackrf_hal.hpp" - #include #include diff --git a/firmware/application/usb_serial_debug_bridge.cpp b/firmware/application/usb_serial_debug_bridge.cpp deleted file mode 100644 index 3b6fb223f..000000000 --- a/firmware/application/usb_serial_debug_bridge.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by zxkmm on 24-4-17. -// - -#include "usb_serial_debug_bridge.hpp" diff --git a/firmware/application/usb_serial_debug_bridge.hpp b/firmware/application/usb_serial_debug_bridge.hpp index 57b923cbf..a1896b2ad 100644 --- a/firmware/application/usb_serial_debug_bridge.hpp +++ b/firmware/application/usb_serial_debug_bridge.hpp @@ -39,7 +39,17 @@ class UsbSerialDebugBridge { static void ppdbg(const std::vector& data); }; +/*Notes: + * - Don't use MayhemHub since it currently not support real time serial output + * - If you don't use this class linker will drop it so it won't use any space + * - so delete all debug things before you push your code to production + * - usage: + * #include "usb_serial_debug_bridge.hpp" + * UsbSerialDebugBridge::ppdbg("Hello PP"); + * */ + /// value +// to_string_bin/ to_string_decimal/ to_string_hex/ to_string_hex_array/ to_string_dec_uint/ to_string_dec_int etc seems usellss so i didn't add them here template <> // usage: UsbSerialDebugBridge::ppdbg(num); @@ -82,7 +92,7 @@ void UsbSerialDebugBridge::ppdbg(const uint64_t& data) { chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } -/// path +/// fs things template <> // usage: UsbSerialDebugBridge::ppdbg(path); @@ -98,7 +108,7 @@ void UsbSerialDebugBridge::ppdbg(const std::string& data) { chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str()); } -///vec worker +/// vec worker // ussgae: UsbSerialDebugBridge::ppdbg(vec); template void UsbSerialDebugBridge::ppdbg(const std::vector& data) { From b52eafc9811fc2bd05cea1839f91e68897d9fa20 Mon Sep 17 00:00:00 2001 From: zxkmm Date: Wed, 17 Apr 2024 20:07:43 +0800 Subject: [PATCH 06/12] clean up --- firmware/application/CMakeLists.txt | 2 +- firmware/application/apps/ui_sstvtx.cpp | 1 + firmware/application/usb_serial_debug_bridge.hpp | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 69342a4f7..9b5393a99 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -225,7 +225,7 @@ set(CPPSRC tone_key.cpp transmitter_model.cpp tuning.cpp - usb_serial_debug_bridge.hpp + usb_serial_debug_bridge.hpp hw/debounce.cpp hw/encoder.cpp hw/max2837.cpp diff --git a/firmware/application/apps/ui_sstvtx.cpp b/firmware/application/apps/ui_sstvtx.cpp index d6e8ca084..e60b2bc15 100644 --- a/firmware/application/apps/ui_sstvtx.cpp +++ b/firmware/application/apps/ui_sstvtx.cpp @@ -156,6 +156,7 @@ void SSTVTXView::start_tx() { // The baseband SSTV TX code (proc_sstv) has a 2-scanline buffer. It is preloaded before // TX start, and asks for fill-up when a new scanline starts being read. This should // leave enough time for the code in prepare_scanline() before it ends. + scanline_counter = 0; prepare_scanline(); // Preload one scanline diff --git a/firmware/application/usb_serial_debug_bridge.hpp b/firmware/application/usb_serial_debug_bridge.hpp index a1896b2ad..b756a32c4 100644 --- a/firmware/application/usb_serial_debug_bridge.hpp +++ b/firmware/application/usb_serial_debug_bridge.hpp @@ -43,6 +43,7 @@ class UsbSerialDebugBridge { * - Don't use MayhemHub since it currently not support real time serial output * - If you don't use this class linker will drop it so it won't use any space * - so delete all debug things before you push your code to production + * - use this client to filter only PP devices: https://github.com/zxkmm/Pyserial-Demo-portapack * - usage: * #include "usb_serial_debug_bridge.hpp" * UsbSerialDebugBridge::ppdbg("Hello PP"); From 0f0125359cb4d48c8929f7426d0ea14ab77344fa Mon Sep 17 00:00:00 2001 From: zxkmm Date: Wed, 17 Apr 2024 20:12:17 +0800 Subject: [PATCH 07/12] format --- firmware/application/apps/ui_sstvtx.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/firmware/application/apps/ui_sstvtx.cpp b/firmware/application/apps/ui_sstvtx.cpp index e60b2bc15..d6e8ca084 100644 --- a/firmware/application/apps/ui_sstvtx.cpp +++ b/firmware/application/apps/ui_sstvtx.cpp @@ -156,7 +156,6 @@ void SSTVTXView::start_tx() { // The baseband SSTV TX code (proc_sstv) has a 2-scanline buffer. It is preloaded before // TX start, and asks for fill-up when a new scanline starts being read. This should // leave enough time for the code in prepare_scanline() before it ends. - scanline_counter = 0; prepare_scanline(); // Preload one scanline From 45f33a603ac811ac83a1535dddb6512c35f6d46e Mon Sep 17 00:00:00 2001 From: zxkmm Date: Wed, 17 Apr 2024 23:46:09 +0800 Subject: [PATCH 08/12] add an async blocking bool --- firmware/application/portapack.cpp | 2 ++ firmware/application/portapack.hpp | 2 ++ firmware/application/usb_serial_shell.cpp | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 7a88b57f5..598951600 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -617,4 +617,6 @@ void setEventDispatcherToUSBSerial(EventDispatcher* evt) { usb_serial.setEventDispatcher(evt); } +bool async_tx_enabled = false; + } /* namespace portapack */ diff --git a/firmware/application/portapack.hpp b/firmware/application/portapack.hpp index 24eae598c..1fc3fc9bc 100644 --- a/firmware/application/portapack.hpp +++ b/firmware/application/portapack.hpp @@ -81,4 +81,6 @@ void setEventDispatcherToUSBSerial(EventDispatcher* evt); Backlight* backlight(); +extern bool async_tx_enabled; + } /* namespace portapack */ diff --git a/firmware/application/usb_serial_shell.cpp b/firmware/application/usb_serial_shell.cpp index 3964e6ed4..7d615f3d4 100644 --- a/firmware/application/usb_serial_shell.cpp +++ b/firmware/application/usb_serial_shell.cpp @@ -1131,6 +1131,23 @@ static void cmd_sendpocsag(BaseSequentialStream* chp, int argc, char* argv[]) { chprintf(chp, "ok\r\n"); } +static void cmd_forbid_tx(BaseSequentialStream* chp, int argc, char* argv[]) { + const char* usage = "usage: forbid_tx x, x can be yes or no\r\n"; + if (argc != 1) { + chprintf(chp, usage); + return; + } + if (strcmp(argv[0], "yes") == 0) { + portapack::async_tx_enabled = false; + chprintf(chp, "ok\r\n"); + } else if (strcmp(argv[0], "no") == 0) { + portapack::async_tx_enabled = true; + chprintf(chp, "ok\r\n"); + } else { + chprintf(chp, usage); + } +} + static const ShellCommand commands[] = { {"reboot", cmd_reboot}, {"dfu", cmd_dfu}, @@ -1162,6 +1179,7 @@ static const ShellCommand commands[] = { {"pmemreset", cmd_pmemreset}, {"settingsreset", cmd_settingsreset}, {"sendpocsag", cmd_sendpocsag}, + {"forbidtx", cmd_forbid_tx}, {NULL, NULL}}; static const ShellConfig shell_cfg1 = { From 24bd55f6d736b6a1c3b00231dbfc1b6671cba7a8 Mon Sep 17 00:00:00 2001 From: zxkmm Date: Wed, 17 Apr 2024 23:56:27 +0800 Subject: [PATCH 09/12] add an async blocking bool - comment --- firmware/application/portapack.cpp | 2 +- firmware/application/portapack.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 598951600..6010c6044 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -617,6 +617,6 @@ void setEventDispatcherToUSBSerial(EventDispatcher* evt) { usb_serial.setEventDispatcher(evt); } -bool async_tx_enabled = false; +bool async_tx_enabled = false; // this is for serial tx things, globally } /* namespace portapack */ diff --git a/firmware/application/portapack.hpp b/firmware/application/portapack.hpp index 1fc3fc9bc..f9f23d6e1 100644 --- a/firmware/application/portapack.hpp +++ b/firmware/application/portapack.hpp @@ -81,6 +81,6 @@ void setEventDispatcherToUSBSerial(EventDispatcher* evt); Backlight* backlight(); -extern bool async_tx_enabled; +extern bool async_tx_enabled; // this is for serial tx things, globally } /* namespace portapack */ From 54a9eecad674c861096e4481f4bbbbaff9890e58 Mon Sep 17 00:00:00 2001 From: zxkmm Date: Thu, 18 Apr 2024 00:23:30 +0800 Subject: [PATCH 10/12] protect the unexpected tx --- .../application/usb_serial_debug_bridge.hpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/firmware/application/usb_serial_debug_bridge.hpp b/firmware/application/usb_serial_debug_bridge.hpp index b756a32c4..2c3ab8159 100644 --- a/firmware/application/usb_serial_debug_bridge.hpp +++ b/firmware/application/usb_serial_debug_bridge.hpp @@ -55,41 +55,65 @@ class UsbSerialDebugBridge { template <> // usage: UsbSerialDebugBridge::ppdbg(num); void UsbSerialDebugBridge::ppdbg(const int64_t& data) { + if (!portapack::async_tx_enabled) { + return; + } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } template <> void UsbSerialDebugBridge::ppdbg(const int32_t& data) { + if (!portapack::async_tx_enabled) { + return; + } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } template <> void UsbSerialDebugBridge::ppdbg(const int16_t& data) { + if (!portapack::async_tx_enabled) { + return; + } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } template <> void UsbSerialDebugBridge::ppdbg(const int8_t& data) { + if (!portapack::async_tx_enabled) { + return; + } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } template <> void UsbSerialDebugBridge::ppdbg(const uint8_t& data) { + if (!portapack::async_tx_enabled) { + return; + } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } template <> void UsbSerialDebugBridge::ppdbg(const uint16_t& data) { + if (!portapack::async_tx_enabled) { + return; + } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } template <> void UsbSerialDebugBridge::ppdbg(const uint32_t& data) { + if (!portapack::async_tx_enabled) { + return; + } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } template <> void UsbSerialDebugBridge::ppdbg(const uint64_t& data) { + if (!portapack::async_tx_enabled) { + return; + } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str()); } @@ -98,6 +122,9 @@ void UsbSerialDebugBridge::ppdbg(const uint64_t& data) { template <> // usage: UsbSerialDebugBridge::ppdbg(path); void UsbSerialDebugBridge::ppdbg(const std::filesystem::path& data) { + if (!portapack::async_tx_enabled) { + return; + } std::string path_str = data.string(); chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", path_str.c_str()); } @@ -106,6 +133,9 @@ void UsbSerialDebugBridge::ppdbg(const std::filesystem::p template <> // usage: UsbSerialDebugBridge::ppdbg(str); void UsbSerialDebugBridge::ppdbg(const std::string& data) { + if (!portapack::async_tx_enabled) { + return; + } chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str()); } @@ -113,6 +143,9 @@ void UsbSerialDebugBridge::ppdbg(const std::string& data) { // ussgae: UsbSerialDebugBridge::ppdbg(vec); template void UsbSerialDebugBridge::ppdbg(const std::vector& data) { + if (!portapack::async_tx_enabled) { + return; + } for (const auto& item : data) { ppdbg(item); } From 8a383288dc22fb769d5fc0e3e13e4101eacc6f17 Mon Sep 17 00:00:00 2001 From: zxkmm Date: Thu, 18 Apr 2024 00:42:39 +0800 Subject: [PATCH 11/12] naming --- firmware/application/CMakeLists.txt | 2 +- firmware/application/apps/ui_fileman.cpp | 25 ++++++++++ ...bug_bridge.hpp => usb_serial_asyncmsg.hpp} | 46 +++++++++---------- firmware/application/usb_serial_shell.cpp | 10 ++-- 4 files changed, 54 insertions(+), 29 deletions(-) rename firmware/application/{usb_serial_debug_bridge.hpp => usb_serial_asyncmsg.hpp} (74%) diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 9b5393a99..1410d95d1 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -225,7 +225,7 @@ set(CPPSRC tone_key.cpp transmitter_model.cpp tuning.cpp - usb_serial_debug_bridge.hpp + usb_serial_asyncmsg.hpp hw/debounce.cpp hw/encoder.cpp hw/max2837.cpp diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 2ad716ad5..99a667807 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -35,6 +35,8 @@ #include "portapack.hpp" #include "event_m0.hpp" +#include "usb_serial_asyncmsg.hpp" + using namespace portapack; namespace fs = std::filesystem; @@ -322,6 +324,29 @@ void FileManBaseView::focus() { } void FileManBaseView::push_dir(const fs::path& path) { + std::string test_string = "test string:"; + UsbSerialAsyncmsg::asyncmsg(test_string); + std::string test_string111 = "abcdefghi"; + UsbSerialAsyncmsg::asyncmsg(test_string111); + + std::string test_path_label = "test_path:"; + UsbSerialAsyncmsg::asyncmsg(test_path_label); + UsbSerialAsyncmsg::asyncmsg(path); + + std::string test_vec_label = "test_vector:"; + UsbSerialAsyncmsg::asyncmsg(test_vec_label); + + std::vector test_vector; + test_vector.push_back(1); + test_vector.push_back(2); + test_vector.push_back(3); + UsbSerialAsyncmsg::asyncmsg(test_vector); + + std::string test_num_label = "test_num:"; + UsbSerialAsyncmsg::asyncmsg(test_num_label); + + uint8_t test = 254; + UsbSerialAsyncmsg::asyncmsg(test); if (path == parent_dir_path) { pop_dir(); } else { diff --git a/firmware/application/usb_serial_debug_bridge.hpp b/firmware/application/usb_serial_asyncmsg.hpp similarity index 74% rename from firmware/application/usb_serial_debug_bridge.hpp rename to firmware/application/usb_serial_asyncmsg.hpp index 2c3ab8159..588694076 100644 --- a/firmware/application/usb_serial_debug_bridge.hpp +++ b/firmware/application/usb_serial_asyncmsg.hpp @@ -21,8 +21,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef USB_SERIAL_DEBUG_BRIDGE_H -#define USB_SERIAL_DEBUG_BRIDGE_H +#ifndef USB_SERIAL_AYNCMSG_HPP +#define USB_SERIAL_AYNCMSG_HPP #include #include @@ -30,13 +30,13 @@ #include #include "usb_serial_device_to_host.h" -class UsbSerialDebugBridge { +class UsbSerialAsyncmsg { public: template - static void ppdbg(const STRINGCOVER& data); + static void asyncmsg(const STRINGCOVER& data); template - static void ppdbg(const std::vector& data); + static void asyncmsg(const std::vector& data); }; /*Notes: @@ -46,15 +46,15 @@ class UsbSerialDebugBridge { * - use this client to filter only PP devices: https://github.com/zxkmm/Pyserial-Demo-portapack * - usage: * #include "usb_serial_debug_bridge.hpp" - * UsbSerialDebugBridge::ppdbg("Hello PP"); + * UsbSerialAsyncmsg::asyncmsg("Hello PP"); * */ /// value // to_string_bin/ to_string_decimal/ to_string_hex/ to_string_hex_array/ to_string_dec_uint/ to_string_dec_int etc seems usellss so i didn't add them here template <> -// usage: UsbSerialDebugBridge::ppdbg(num); -void UsbSerialDebugBridge::ppdbg(const int64_t& data) { +// usage: UsbSerialAsyncmsg::asyncmsg(num); +void UsbSerialAsyncmsg::asyncmsg(const int64_t& data) { if (!portapack::async_tx_enabled) { return; } @@ -62,7 +62,7 @@ void UsbSerialDebugBridge::ppdbg(const int64_t& data) { } template <> -void UsbSerialDebugBridge::ppdbg(const int32_t& data) { +void UsbSerialAsyncmsg::asyncmsg(const int32_t& data) { if (!portapack::async_tx_enabled) { return; } @@ -70,7 +70,7 @@ void UsbSerialDebugBridge::ppdbg(const int32_t& data) { } template <> -void UsbSerialDebugBridge::ppdbg(const int16_t& data) { +void UsbSerialAsyncmsg::asyncmsg(const int16_t& data) { if (!portapack::async_tx_enabled) { return; } @@ -78,7 +78,7 @@ void UsbSerialDebugBridge::ppdbg(const int16_t& data) { } template <> -void UsbSerialDebugBridge::ppdbg(const int8_t& data) { +void UsbSerialAsyncmsg::asyncmsg(const int8_t& data) { if (!portapack::async_tx_enabled) { return; } @@ -86,7 +86,7 @@ void UsbSerialDebugBridge::ppdbg(const int8_t& data) { } template <> -void UsbSerialDebugBridge::ppdbg(const uint8_t& data) { +void UsbSerialAsyncmsg::asyncmsg(const uint8_t& data) { if (!portapack::async_tx_enabled) { return; } @@ -94,7 +94,7 @@ void UsbSerialDebugBridge::ppdbg(const uint8_t& data) { } template <> -void UsbSerialDebugBridge::ppdbg(const uint16_t& data) { +void UsbSerialAsyncmsg::asyncmsg(const uint16_t& data) { if (!portapack::async_tx_enabled) { return; } @@ -102,7 +102,7 @@ void UsbSerialDebugBridge::ppdbg(const uint16_t& data) { } template <> -void UsbSerialDebugBridge::ppdbg(const uint32_t& data) { +void UsbSerialAsyncmsg::asyncmsg(const uint32_t& data) { if (!portapack::async_tx_enabled) { return; } @@ -110,7 +110,7 @@ void UsbSerialDebugBridge::ppdbg(const uint32_t& data) { } template <> -void UsbSerialDebugBridge::ppdbg(const uint64_t& data) { +void UsbSerialAsyncmsg::asyncmsg(const uint64_t& data) { if (!portapack::async_tx_enabled) { return; } @@ -120,8 +120,8 @@ void UsbSerialDebugBridge::ppdbg(const uint64_t& data) { /// fs things template <> -// usage: UsbSerialDebugBridge::ppdbg(path); -void UsbSerialDebugBridge::ppdbg(const std::filesystem::path& data) { +// usage: UsbSerialAsyncmsg::asyncmsg(path); +void UsbSerialAsyncmsg::asyncmsg(const std::filesystem::path& data) { if (!portapack::async_tx_enabled) { return; } @@ -131,8 +131,8 @@ void UsbSerialDebugBridge::ppdbg(const std::filesystem::p /// string template <> -// usage: UsbSerialDebugBridge::ppdbg(str); -void UsbSerialDebugBridge::ppdbg(const std::string& data) { +// usage: UsbSerialAsyncmsg::asyncmsg(str); +void UsbSerialAsyncmsg::asyncmsg(const std::string& data) { if (!portapack::async_tx_enabled) { return; } @@ -140,15 +140,15 @@ void UsbSerialDebugBridge::ppdbg(const std::string& data) { } /// vec worker -// ussgae: UsbSerialDebugBridge::ppdbg(vec); +// ussgae: UsbSerialAsyncmsg::asyncmsg(vec); template -void UsbSerialDebugBridge::ppdbg(const std::vector& data) { +void UsbSerialAsyncmsg::asyncmsg(const std::vector& data) { if (!portapack::async_tx_enabled) { return; } for (const auto& item : data) { - ppdbg(item); + asyncmsg(item); } } -#endif // USB_SERIAL_DEBUG_BRIDGE_H +#endif // USB_SERIAL_AYNCMSG_HPP diff --git a/firmware/application/usb_serial_shell.cpp b/firmware/application/usb_serial_shell.cpp index 7d615f3d4..e260b8b87 100644 --- a/firmware/application/usb_serial_shell.cpp +++ b/firmware/application/usb_serial_shell.cpp @@ -1131,16 +1131,16 @@ static void cmd_sendpocsag(BaseSequentialStream* chp, int argc, char* argv[]) { chprintf(chp, "ok\r\n"); } -static void cmd_forbid_tx(BaseSequentialStream* chp, int argc, char* argv[]) { - const char* usage = "usage: forbid_tx x, x can be yes or no\r\n"; +static void cmd_asyncmsg(BaseSequentialStream* chp, int argc, char* argv[]) { + const char* usage = "usage: asyncmsg x, x can be enable or disable\r\n"; if (argc != 1) { chprintf(chp, usage); return; } - if (strcmp(argv[0], "yes") == 0) { + if (strcmp(argv[0], "disable") == 0) { portapack::async_tx_enabled = false; chprintf(chp, "ok\r\n"); - } else if (strcmp(argv[0], "no") == 0) { + } else if (strcmp(argv[0], "enable") == 0) { portapack::async_tx_enabled = true; chprintf(chp, "ok\r\n"); } else { @@ -1179,7 +1179,7 @@ static const ShellCommand commands[] = { {"pmemreset", cmd_pmemreset}, {"settingsreset", cmd_settingsreset}, {"sendpocsag", cmd_sendpocsag}, - {"forbidtx", cmd_forbid_tx}, + {"asyncmsg", cmd_asyncmsg}, {NULL, NULL}}; static const ShellConfig shell_cfg1 = { From 94e55aa2e6799db5037f4c2afd234d5df4f67acd Mon Sep 17 00:00:00 2001 From: zxkmm Date: Thu, 18 Apr 2024 00:54:36 +0800 Subject: [PATCH 12/12] remove demo code --- firmware/application/apps/ui_fileman.cpp | 25 ------------------------ 1 file changed, 25 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 99a667807..2ad716ad5 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -35,8 +35,6 @@ #include "portapack.hpp" #include "event_m0.hpp" -#include "usb_serial_asyncmsg.hpp" - using namespace portapack; namespace fs = std::filesystem; @@ -324,29 +322,6 @@ void FileManBaseView::focus() { } void FileManBaseView::push_dir(const fs::path& path) { - std::string test_string = "test string:"; - UsbSerialAsyncmsg::asyncmsg(test_string); - std::string test_string111 = "abcdefghi"; - UsbSerialAsyncmsg::asyncmsg(test_string111); - - std::string test_path_label = "test_path:"; - UsbSerialAsyncmsg::asyncmsg(test_path_label); - UsbSerialAsyncmsg::asyncmsg(path); - - std::string test_vec_label = "test_vector:"; - UsbSerialAsyncmsg::asyncmsg(test_vec_label); - - std::vector test_vector; - test_vector.push_back(1); - test_vector.push_back(2); - test_vector.push_back(3); - UsbSerialAsyncmsg::asyncmsg(test_vector); - - std::string test_num_label = "test_num:"; - UsbSerialAsyncmsg::asyncmsg(test_num_label); - - uint8_t test = 254; - UsbSerialAsyncmsg::asyncmsg(test); if (path == parent_dir_path) { pop_dir(); } else {