diff --git a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp index db09f99b34..ccc64bc55f 100644 --- a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp +++ b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp @@ -151,13 +151,6 @@ GlobalSettings::GlobalSettings() , m_advanced_options( "Advanced Options: You should not need to touch anything below here." ) - , ENABLE_PABOTBASE1( - "Enable PABotBase1:
Enable support for the legacy PABotBase 1 protocol.
" - "Turn this on if you are still using Arduino Uno R3, Arduino Leonardo, Teensy, or Pro Micro. " - "Note that this feature is slated to be removed in September 2026.", - LockMode::UNLOCK_WHILE_RUNNING, - false - ) , DUMP_VIDEO_FORMATS( "Dump Video Formats:
Log all video formats supported by your capture card.", LockMode::UNLOCK_WHILE_RUNNING, @@ -226,7 +219,6 @@ GlobalSettings::GlobalSettings() PA_ADD_STATIC(m_advanced_options); add_option(PokemonAutomation::LOG_EVERYTHING(), "LOG_EVERYTHING"); - PA_ADD_OPTION(ENABLE_PABOTBASE1); PA_ADD_OPTION(DUMP_VIDEO_FORMATS); PA_ADD_OPTION(SAVE_DEBUG_IMAGES); diff --git a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h index 7f36879680..be883b2994 100644 --- a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h +++ b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h @@ -104,7 +104,6 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener, priva SectionDividerOption m_advanced_options; - BooleanCheckBoxOption ENABLE_PABOTBASE1; BooleanCheckBoxOption DUMP_VIDEO_FORMATS; BooleanCheckBoxOption SAVE_DEBUG_IMAGES; BooleanCheckBoxOption SAVE_DEBUG_VIDEOS_ON_SWITCH; diff --git a/SerialPrograms/Source/CommonFramework/Main.cpp b/SerialPrograms/Source/CommonFramework/Main.cpp index 42512baad9..3c47e8b9ca 100644 --- a/SerialPrograms/Source/CommonFramework/Main.cpp +++ b/SerialPrograms/Source/CommonFramework/Main.cpp @@ -42,7 +42,7 @@ #include "CommonFramework/VideoPipeline/Backends/CameraImplementations.h" #include "CommonTools/OCR/OCR_Routines.h" #include "ControllerInput/ControllerInput.h" -#include "Controllers/SerialPortPollerQt.h" +#include "Controllers/SerialPort/SerialPortPollerQt.h" #include "Integrations/DiscordWebhook.h" #include "Windows/MainWindow.h" diff --git a/SerialPrograms/Source/Controllers/ControllerSelectorWidget.cpp b/SerialPrograms/Source/Controllers/ControllerSelectorWidget.cpp index bd86ca5ef0..e81b72dd91 100644 --- a/SerialPrograms/Source/Controllers/ControllerSelectorWidget.cpp +++ b/SerialPrograms/Source/Controllers/ControllerSelectorWidget.cpp @@ -16,7 +16,6 @@ #include "PABotBase2/SerialPABotBase2_Descriptor.h" -#include "SerialPABotBase/SerialPABotBase_SelectorWidget.h" #include "PABotBase2/SerialPABotBase2_SelectorWidget.h" #include "NintendoSwitch/Controllers/SysbotBase/SysbotBase_SelectorWidget.h" @@ -55,9 +54,6 @@ ControllerSelectorWidget::ControllerSelectorWidget(QWidget& parent, ControllerSe // Add all the supported interfaces. { - if (GlobalSettings::instance().ENABLE_PABOTBASE1){ - m_interface_list.emplace_back(ControllerInterface::SerialPABotBase); - } m_interface_list.emplace_back(ControllerInterface::SerialPABotBase2); m_interface_list.emplace_back(ControllerInterface::TcpSysbotBase); // m_interface_list.emplace_back(ControllerInterface::UsbSysbotBase); @@ -212,11 +208,6 @@ void ControllerSelectorWidget::refresh_selection(ControllerInterface interface_t // m_status_text->setText(QString::fromStdString(html_color_text("Not Connected", COLOR_RED))); switch (interface_type){ - case ControllerInterface::SerialPABotBase: - m_selector = new SerialPABotBase::SerialPABotBase_SelectorWidget(*this, m_session.descriptor().get()); - m_dropdowns->insertWidget(1, m_selector, 1); - break; - case ControllerInterface::SerialPABotBase2: m_selector = new SerialPABotBase::SerialPABotBase2_SelectorWidget(*this, m_session.descriptor().get()); m_dropdowns->insertWidget(1, m_selector, 1); diff --git a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp index 4c1f6a5a07..c8d96761c3 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp +++ b/SerialPrograms/Source/Controllers/PABotBase2/PABotBase2_DeviceHandle.cpp @@ -14,7 +14,7 @@ #include "Common/Cpp/ColoredText.h" #include "Controllers/ControllerTypeStrings.h" #include "Controllers/ControllerSettings.h" -#include "Controllers/SerialPABotBase/SerialPABotBase.h" +#include "Controllers/SerialPort/SerialPABotBase.h" #include "PABotBase2_DeviceHandle.h" //#include diff --git a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Connection.cpp b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Connection.cpp index a7751e8c78..0e88cd331f 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Connection.cpp +++ b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Connection.cpp @@ -7,7 +7,7 @@ #ifdef QT_CORE_LIB #include #include -#include "Controllers/SerialPortPollerQt.h" +#include "Controllers/SerialPort/SerialPortPollerQt.h" #endif #include "Common/Cpp/ScopeExit.h" #include "Common/Cpp/PrettyPrint.h" diff --git a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Connection.h b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Connection.h index f916552440..61ab4af666 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Connection.h +++ b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Connection.h @@ -10,8 +10,8 @@ #include "Common/Cpp/Concurrency/AsyncTask.h" #include "Common/Cpp/SerialConnection/SerialConnection.h" #include "Common/PABotBase2/ReliableConnectionLayer/PABotBase2CC_ReliableStreamConnection.h" +#include "Controllers/SerialPort/SerialLogger.h" #include "Controllers/PABotBase2/PABotBase2_Connection.h" -#include "Controllers/SerialPABotBase/Connection/MessageLogger.h" namespace PokemonAutomation{ namespace SerialPABotBase{ diff --git a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.cpp b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.cpp index 06c96a09fc..9d67dc6296 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.cpp +++ b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.cpp @@ -7,7 +7,7 @@ #include "Common/Cpp/Json/JsonValue.h" #include "Controllers/ControllerTypeStrings.h" #ifdef QT_CORE_LIB -#include "Controllers/SerialPortPollerQt.h" +#include "Controllers/SerialPort/SerialPortPollerQt.h" #endif #include "SerialPABotBase2_Connection.h" #include "SerialPABotBase2_Descriptor.h" diff --git a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_SelectorWidget.cpp b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_SelectorWidget.cpp index 9bef4a88f2..85d557edee 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_SelectorWidget.cpp +++ b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_SelectorWidget.cpp @@ -4,7 +4,7 @@ * */ -#include "Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.h" +#include #include "SerialPABotBase2_Descriptor.h" #include "SerialPABotBase2_SelectorWidget.h" @@ -19,6 +19,45 @@ template class RegisterUiStateQtWidget diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/BotBase.cpp b/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/BotBase.cpp deleted file mode 100644 index bac4024420..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/BotBase.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* Pokemon Automation Bot-Base Interface - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "BotBaseMessage.h" -#include "BotBase.h" - -//#include -//using std::cout; -//using std::endl; - -namespace PokemonAutomation{ - - - -} diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/BotBase.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/BotBase.h deleted file mode 100644 index 87221f6c69..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/BotBase.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Pokemon Automation Bot-Base Interface - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_AbstractBotBase_H -#define PokemonAutomation_AbstractBotBase_H - -#include -#include "Common/Cpp/CancellableScope.h" -#include "Common/Cpp/ListenerSet.h" - -namespace PokemonAutomation{ - -class Logger; -struct BotBaseMessage; -class BotBaseRequest; -class BotBaseControllerContext; - - - -class BotBaseController : public Cancellable::CancelListener{ -public: - struct Listener{ - virtual void on_info_message(const BotBaseMessage& message) noexcept{}; - virtual void on_error_message(const BotBaseMessage& message) noexcept{}; - }; - void add_listener(Listener& listener){ - m_listeners.add(listener); - } - void remove_listener(Listener& listener){ - m_listeners.remove(listener); - } - -public: - using ContextType = BotBaseControllerContext; - - enum class State{ - RUNNING, - STOPPING, - STOPPED, -// ERROR, - }; - -public: - virtual ~BotBaseController() = default; - virtual void stop(std::string error_message = "") noexcept = 0; - - virtual Logger& logger() = 0; - virtual State state() const = 0; - virtual size_t queue_limit() const = 0; - - // Waits for all pending requests to finish. - virtual void wait_for_all_requests(Cancellable* cancelled = nullptr) = 0; - - // Stop all pending commands. This wipes the command queue on both sides - // and stops any currently executing command. - virtual void stop_all_commands() = 0; - - // Tell the device that the next command should replace the command queue. - // - // So once the next command is issued, it will stop all ongoing commands - // and run the new command instead. - // - // Once this function is called, all commands before it are no longer - // guaranteed to finish even if no command interrupts it. - virtual void next_command_interrupt() = 0; - -public: - virtual bool try_issue_request( - const BotBaseRequest& request, - Cancellable* cancelled = nullptr - ) = 0; - virtual void issue_request( - const BotBaseRequest& request, - Cancellable* cancelled = nullptr - ) = 0; - virtual BotBaseMessage issue_request_and_wait( - const BotBaseRequest& request, - Cancellable* cancelled = nullptr - ) = 0; - -protected: - ListenerSet m_listeners; -}; - - - - - -} - - -#endif - diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/BotBaseMessage.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/BotBaseMessage.h deleted file mode 100644 index 377522183c..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/BotBaseMessage.h +++ /dev/null @@ -1,141 +0,0 @@ -/* Bot-Base Message - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_BotBaseMessage_H -#define PokemonAutomation_BotBaseMessage_H - -#include -#include -#include -#include "Common/Cpp/PrettyPrint.h" -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/LifetimeSanitizer.h" -#include "Common/Cpp/Options/BooleanCheckBoxOption.h" -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "CommonFramework/Logging/Logger.h" - -namespace PokemonAutomation{ - - -struct BotBaseMessage{ - uint8_t type; - std::string body; - - LifetimeSanitizer sanitizer; - - BotBaseMessage() = default; - BotBaseMessage(uint8_t p_type, std::string p_body) - : type(p_type) - , body(std::move(p_body)) - {} - - template - BotBaseMessage(uint8_t p_type, const Params& params) - : type(p_type) - , body((char*)¶ms, sizeof(params)) - {} - - template - void convert(Logger& logger, MessageBody& params) const{ - sanitizer.check_usage(); - if (type != MessageType){ - throw SerialProtocolException( - logger, PA_CURRENT_FUNCTION, - "Received Incorrect Response Type: Expected = " + std::to_string(MessageType) + ", Actual = " + std::to_string(type) - ); - } - if (body.size() != sizeof(MessageBody)){ - throw SerialProtocolException( - logger, PA_CURRENT_FUNCTION, - "Received Incorrect Response Size: Expected = " + std::to_string(sizeof(MessageBody)) + ", Actual = " + std::to_string(body.size()) - ); - } - memcpy(¶ms, body.c_str(), body.size()); - sanitizer.check_usage(); - } - -}; - -class BotBaseRequest{ -public: - BotBaseRequest(bool is_command) - : m_is_command(is_command) - {} - virtual ~BotBaseRequest() = default; - virtual BotBaseMessage message() const = 0; - - bool is_command() const{ return m_is_command; } - -private: - bool m_is_command; -}; - - - - - -class BotBaseMessageType{ -public: - template - static const BotBaseMessageType& instance(){ - static const ChildType type; - return type; - } - - BotBaseMessageType(const char* name, uint8_t type, uint8_t body_size) - : m_name(name) - , m_type(type) - , m_size(body_size) - {} - - uint8_t type() const{ - return m_type; - } - - friend bool operator<(const BotBaseMessageType& x, const BotBaseMessageType& y){ - return x.m_type < y.m_type; - } - - -public: - virtual bool should_print(const std::string& body) const{ - if (LOG_EVERYTHING()){ - return true; - } - if (PABB_MSG_IS_ACK(m_type)){ - return false; - } - return true; - } - virtual bool is_valid(const std::string& body) const{ - return body.size() == m_size; - } - virtual std::string tostr(const std::string& body) const{ - std::string ret; - ret += "(0x" + tostr_hex(m_type) + ") "; - ret += m_name; - if (!is_valid(body)){ - ret += ": (Invalid: Size = " + std::to_string(body.size()) + ")"; - } - return ret; - } - - -private: - const char* m_name; - const uint8_t m_type; - const uint8_t m_size; // Excluding header and CRC. -}; - - - - - - - - -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/MessageSniffer.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/MessageSniffer.h deleted file mode 100644 index 0e43bb03d1..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/MessageSniffer.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Message Sniffer - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_MessageSniffer_H -#define PokemonAutomation_MessageSniffer_H - -#include -#include "Common/Compiler.h" - -namespace PokemonAutomation{ - -struct BotBaseMessage; - - -class MessageSniffer{ -public: - virtual void on_send(const BotBaseMessage& message, bool is_retransmit){} - virtual void on_recv(const BotBaseMessage& message){} -}; - - - -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBase.cpp b/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBase.cpp deleted file mode 100644 index 804ec64426..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBase.cpp +++ /dev/null @@ -1,1022 +0,0 @@ -/* Pokemon Automation Bot Base - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/PanicDump.h" -#include "Common/Cpp/Concurrency/SpinPause.h" -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_StaticRequests.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_CommandQueue.h" -#include "PABotBase.h" - -//#include -//using std::cout; -//using std::endl; - - -// Intentionally drop some messages to test self-recovery. -//#define INTENTIONALLY_DROP_MESSAGES - - - -// #define DEBUG_STACK_TRACE - -#ifdef DEBUG_STACK_TRACE - -#if defined(__APPLE__) -#include -#include -#endif - -#endif // DEBUG_STACK_TRACE - -namespace PokemonAutomation{ - - - -PABotBase::PABotBase( - Logger& logger, - ThreadPool& thread_pool, - std::unique_ptr connection, - std::chrono::milliseconds retransmit_delay -) - : PABotBaseConnection(logger, std::move(connection)) - , m_logger(logger) - , m_max_pending_requests(PABB_DEVICE_MINIMUM_QUEUE_SIZE) - , m_send_seq(1) - , m_retransmit_delay(retransmit_delay) - , m_last_ack(current_time()) - , m_state(State::RUNNING) - , m_error(false) -{ - // We must initialize this last because it will trigger the lifetime - // sanitizer if it beats it to construction. - m_retransmit_thread = thread_pool.dispatch_now_blocking([this]{ - run_with_catch( - "PABotBase::retransmit_thread()", - [this]{ - try{ - retransmit_thread(); - }catch (ConnectionException& e){ - { - ReadSpinLock lg(m_state_lock, "PABotBase::retransmit_thread()"); - m_error_message = e.to_str(); - } - m_error.store(true, std::memory_order_release); - m_cv.notify_all(); - } - } - ); - }); -} -PABotBase::~PABotBase(){ - stop(); - while (m_state.load(std::memory_order_acquire) != State::STOPPED){ - pause(); - } -} - -size_t PABotBase::inflight_requests(){ - auto scope_check = m_sanitizer.check_scope(); - - // Must be called under m_state_lock. - - size_t ret = m_pending_requests.size(); - for (const auto& item : m_pending_commands){ - if (item.second.state == AckState::NOT_ACKED){ - ret++; - } - } - return ret; -} - -void PABotBase::connect(){ - auto scope_check = m_sanitizer.check_scope(); - - pabb_MsgAckRequest response; - issue_request_and_wait( - SerialPABotBase::DeviceRequest_seqnum_reset(), nullptr - ).convert(logger(), response); -} -void PABotBase::stop(std::string error_message) noexcept{ - auto scope_check = m_sanitizer.check_scope(); - - // Make sure only one thread can get in here. - State expected = State::RUNNING; - if (!m_state.compare_exchange_strong(expected, State::STOPPING)){ - return; - } - - if (!error_message.empty()){ - WriteSpinLock lg(m_state_lock, "PABotBase::stop()"); - m_error_message = std::move(error_message); - } - - // Wake everyone up. - { - std::lock_guard lg(m_sleep_lock); - } - m_cv.notify_all(); - m_retransmit_thread.wait_and_ignore_exceptions(); - - { - ReadSpinLock lg(m_state_lock, "PABotBase::stop()"); - - // Send a stop request, but don't wait for a response that we may never - // receive. - pabb_MsgRequestStop params; - uint64_t seqnum = m_send_seq; - seqnum_t seqnum_s = (seqnum_t)seqnum; - memcpy(¶ms, &seqnum_s, sizeof(seqnum_t)); -// try_issue_request(params); -// m_state.store(State::STOPPING, std::memory_order_release); - BotBaseMessage stop_request(PABB_MSG_REQUEST_STOP, std::string((char*)¶ms, sizeof(params))); - try{ - send_message(stop_request, false); - }catch (...){ - m_logger.log("Unable to send stop signal.", COLOR_RED); - } - } - - // Must call this to stop the receiver thread from making any more async - // calls into this class which touch its fields. - safely_stop(); - - // Now the receiver thread is dead. Nobody else is touching this class so - // it is safe to destruct. - m_state.store(State::STOPPED, std::memory_order_release); -} -void PABotBase::on_cancellable_cancel( - Cancellable& cancellable, - std::exception_ptr reason -){ - { - std::unique_lock lg(m_sleep_lock); - } - m_cv.notify_all(); -} - -void PABotBase::set_queue_limit(size_t queue_limit){ - m_max_pending_requests.store(queue_limit, std::memory_order_relaxed); -} - -void PABotBase::wait_for_all_requests(Cancellable* cancelled){ - auto scope_check = m_sanitizer.check_scope(); - - std::unique_lock lg(m_sleep_lock); - m_logger.log("Waiting for all requests to finish...", COLOR_DARKGREEN); - while (true){ - if (cancelled){ - cancelled->throw_if_cancelled(); - } - if (m_state.load(std::memory_order_acquire) != State::RUNNING){ - ReadSpinLock lg0(m_state_lock, "PABotBase::wait_for_all_requests() - 0"); - throw InvalidConnectionStateException(m_error_message); - } - if (m_error.load(std::memory_order_acquire)){ - ReadSpinLock lg0(m_state_lock, "PABotBase::wait_for_all_requests() - 1"); - throw ConnectionException(&m_logger, m_error_message); - } - { - ReadSpinLock lg1(m_state_lock, "PABotBase::wait_for_all_requests() - 2"); -#if 0 - m_logger.log( - "Waiting for all requests to finish... (Requests: " + - std::to_string(m_pending_requests.size()) + - ", Commands: " + std::to_string(m_pending_commands.size()) + ")", - COLOR_DARKGREEN - ); -#endif - if (m_pending_requests.empty() && m_pending_commands.empty()){ - break; - } - } - cv_wait(cancelled, lg); - } - -// m_logger.log("Waiting for all requests to finish... Completed.", COLOR_DARKGREEN); -} -void PABotBase::stop_all_commands(){ - -#ifdef DEBUG_STACK_TRACE - cout << __FILE__ << ":" << __LINE__ << " PABotBase::stop_all_commands()" << endl; - cout << "-----------------------------------------------------------------------------------------" << endl; -#if defined(__APPLE__) - void* callstack[128]; - int i, frames = backtrace(callstack, 128); - char** strs = backtrace_symbols(callstack, frames); - for (i = 0; i < frames; ++i){ - cout << strs[i] << endl; - } - free(strs); -#endif - cout << "-----------------------------------------------------------------------------------------" << endl; -#endif - - auto scope_check = m_sanitizer.check_scope(); - - uint64_t seqnum = issue_request(nullptr, SerialPABotBase::DeviceRequest_request_stop(), true, true); - clear_all_active_commands(seqnum); -} -void PABotBase::next_command_interrupt(){ - auto scope_check = m_sanitizer.check_scope(); - - uint64_t seqnum = issue_request(nullptr, SerialPABotBase::DeviceRequest_next_command_interrupt(), true, true); - clear_all_active_commands(seqnum); -} -void PABotBase::clear_all_active_commands(uint64_t seqnum){ - auto scope_check = m_sanitizer.check_scope(); - { - // Remove all commands at or before the specified seqnum. - std::lock_guard lg0(m_sleep_lock); - WriteSpinLock lg1(m_state_lock, "PABotBase::next_command_interrupt()"); - m_logger.log( - "Clearing all active commands... (Commands: " + std::to_string(m_pending_commands.size()) + ")", - COLOR_DARKGREEN - ); - - - if (m_pending_commands.empty()){ - return; - } - - // Remove all active commands up to the seqnum. - while (true){ - auto iter = m_pending_commands.begin(); - if (iter == m_pending_commands.end() || iter->first > seqnum){ - break; - } - iter->second.sanitizer.check_usage(); - - // We cannot remove un-acked messages from our buffer. If an un-acked - // message is dropped and the receiver is still waiting for it, it will - // wait forever since we will never retransmit. - - if (iter->second.state == AckState::NOT_ACKED){ - // Convert the command into a no-op request. - SerialPABotBase::DeviceRequest_program_id request; - BotBaseMessage message = request.message(); - seqnum_t seqnum_s = (seqnum_t)iter->first; - memcpy(&message.body[0], &seqnum_s, sizeof(seqnum_t)); - -// cout << "removing = " << seqnum_s << ", " << (int)iter->second.state << endl; - - std::pair::iterator, bool> ret = m_pending_requests.emplace( - std::piecewise_construct, - std::forward_as_tuple(iter->first), - std::forward_as_tuple() - ); - if (!ret.second){ - throw InternalProgramError( - &m_logger, - PA_CURRENT_FUNCTION, - "Duplicate sequence number: " + std::to_string(seqnum) - ); - } - - // This block will never throw. - { - PendingRequest& handle = ret.first->second; - handle.silent_remove = true; - handle.request = std::move(message); - handle.first_sent = current_time(); - } - } - - m_pending_commands.erase(iter); - } - } - m_cv.notify_all(); -} -template -uint64_t PABotBase::infer_full_seqnum(const Map& map, seqnum_t seqnum) const{ - auto scope_check = m_sanitizer.check_scope(); - - // The protocol uses a 32-bit seqnum that wraps around. For our purposes of - // retransmits, we use a full 64-bit seqnum to maintain sorting order - // across the wrap-arounds. - - // Since the oldest unacked messaged will never be more than 63 (MAX_SEQNUM_GAP) - // requests old, there is no ambiguity on which request is being referred - // to with just the lower 32 bits. - // Here we infer the upper 32 bits of the seqnum to obtain the full 64-bit - // seqnum that we need to index our map. - - // This needs to be called inside the lock. Furthermore, the map must not - // be empty. If it is empty, we know we don't have it and can drop it - // before we even call this function. - - // Figure out the upper 32 bits of the seqnum. - uint64_t lo = map.begin()->first; - uint64_t hi = map.rbegin()->first; - uint64_t lo_candidate = (lo & 0xffffffff00000000) | seqnum; - uint64_t hi_candidate = (hi & 0xffffffff00000000) | seqnum; - return lo_candidate >= lo - ? lo_candidate - : hi_candidate; -} - -uint64_t PABotBase::oldest_live_seqnum() const{ - auto scope_check = m_sanitizer.check_scope(); - - // Must call under state lock. - uint64_t oldest = m_send_seq; - if (!m_pending_requests.empty()){ - oldest = std::min(oldest, m_pending_requests.begin()->first); - } - if (!m_pending_commands.empty()){ - oldest = std::min(oldest, m_pending_commands.begin()->first); - } - return oldest; -} - -template -void PABotBase::process_ack_request(BotBaseMessage message){ - auto scope_check = m_sanitizer.check_scope(); - - if constexpr (!variable_length){ - if (message.body.size() != sizeof(Params)){ - m_logger.log("Ignoring message with invalid size."); - return; - } - } - const Params* params = (const Params*)message.body.c_str(); - seqnum_t seqnum = params->seqnum; - - AckState state; - { - WriteSpinLock lg(m_state_lock, "PABotBase::process_ack_request()"); - - if (m_pending_requests.empty()){ - m_logger.log("Unexpected request ack message: seqnum = " + std::to_string(seqnum)); - return; - } - - uint64_t full_seqnum = infer_full_seqnum(m_pending_requests, seqnum); - std::map::iterator iter = m_pending_requests.find(full_seqnum); - if (iter == m_pending_requests.end()){ - m_logger.log("Unexpected request ack message: seqnum = " + std::to_string(seqnum)); - return; - } - iter->second.sanitizer.check_usage(); - - state = iter->second.state; - if (state == AckState::NOT_ACKED){ - if (iter->second.silent_remove){ - m_pending_requests.erase(iter); - }else{ - iter->second.state = AckState::ACKED; - iter->second.ack = std::move(message); - } - } - } - - m_last_ack.store(current_time(), std::memory_order_release); - - switch (state){ - case AckState::NOT_ACKED: - { - std::lock_guard lg(m_sleep_lock); - } - m_cv.notify_all(); - return; - case AckState::ACKED: - m_logger.log("Duplicate request ack message: seqnum = " + std::to_string(seqnum)); - return; - case AckState::FINISHED: - m_logger.log("Request ack on command finish: seqnum = " + std::to_string(seqnum)); - return; - } -} -template -void PABotBase::process_ack_command(BotBaseMessage message){ - auto scope_check = m_sanitizer.check_scope(); - - if (message.body.size() != sizeof(Params)){ - m_logger.log("Ignoring message with invalid size."); - return; - } - const Params* params = (const Params*)message.body.c_str(); - seqnum_t seqnum = params->seqnum; - - WriteSpinLock lg(m_state_lock, "PABotBase::process_ack_command()"); - - if (m_pending_commands.empty()){ - m_logger.log("Unexpected command ack message: seqnum = " + std::to_string(seqnum)); - return; - } - - uint64_t full_seqnum = infer_full_seqnum(m_pending_commands, seqnum); - auto iter = m_pending_commands.find(full_seqnum); - if (iter == m_pending_commands.end()){ - m_logger.log("Unexpected command ack message: seqnum = " + std::to_string(seqnum)); - return; - } - iter->second.sanitizer.check_usage(); - - m_last_ack.store(current_time(), std::memory_order_release); - - switch (iter->second.state){ - case AckState::NOT_ACKED: -// std::cout << "acked: " << full_seqnum << std::endl; - iter->second.state = AckState::ACKED; - iter->second.ack = std::move(message); - return; - case AckState::ACKED: - m_logger.log("Duplicate command ack message: seqnum = " + std::to_string(seqnum)); - return; - case AckState::FINISHED: - m_logger.log("Command ack on finished command: seqnum = " + std::to_string(seqnum)); - return; - } -} -template -void PABotBase::process_command_finished(BotBaseMessage message){ - auto scope_check = m_sanitizer.check_scope(); - - if (message.body.size() != sizeof(Params)){ - m_logger.log("Ignoring message with invalid size."); - return; - } - const Params* params = (const Params*)message.body.c_str(); - seqnum_t seqnum = params->seqnum; - seqnum_t command_seqnum = params->seq_of_original_command; - - // Send the ack first. - pabb_MsgAckRequest ack; - ack.seqnum = seqnum; -// m_send_queue.emplace_back((uint8_t)PABB_MSG_ACK, std::string((char*)&ack, sizeof(ack))); - - { - std::lock_guard lg0(m_sleep_lock); - WriteSpinLock lg1(m_state_lock, "PABotBase::process_command_finished()"); - -#ifdef INTENTIONALLY_DROP_MESSAGES - if (rand() % 10 != 0){ - send_message(BotBaseMessage(PABB_MSG_ACK_REQUEST, std::string((char*)&ack, sizeof(ack))), false); - }else{ - m_logger.log("Intentionally dropping finish ack: " + std::to_string(seqnum), COLOR_RED); - } -#else - send_message(BotBaseMessage(PABB_MSG_ACK_REQUEST, std::string((char*)&ack, sizeof(ack))), false); -#endif - - if (m_pending_commands.empty()){ - m_logger.log( - "Unexpected command finished message: seqnum = " + std::to_string(seqnum) + - ", command_seqnum = " + std::to_string(command_seqnum) - ); - return; - } - - uint64_t full_seqnum = infer_full_seqnum(m_pending_commands, command_seqnum); - auto iter = m_pending_commands.find(full_seqnum); - if (iter == m_pending_commands.end()){ - m_logger.log( - "Unexpected command finished message: seqnum = " + std::to_string(seqnum) + - ", command_seqnum = " + std::to_string(command_seqnum) - ); - return; - } - iter->second.sanitizer.check_usage(); - - switch (iter->second.state){ - case AckState::NOT_ACKED: - case AckState::ACKED: - iter->second.state = AckState::FINISHED; - iter->second.ack = std::move(message); - if (iter->second.silent_remove){ - m_pending_commands.erase(iter); - } - break; - case AckState::FINISHED: - m_logger.log("Duplicate command finish: seqnum = " + std::to_string(seqnum)); - return; - } - } - m_cv.notify_all(); -} -void PABotBase::on_recv_message(BotBaseMessage message){ - auto scope_check = m_sanitizer.check_scope(); - - if (PABB_MSG_IS_INFO(message.type)){ - m_listeners.run_method(&Listener::on_info_message, message); - } - if (PABB_MSG_IS_ERROR(message.type)){ - m_listeners.run_method(&Listener::on_error_message, message); - } - - switch (message.type){ - case PABB_MSG_ACK_COMMAND: - process_ack_command(std::move(message)); - return; - case PABB_MSG_ACK_REQUEST: - process_ack_request(std::move(message)); - return; - case PABB_MSG_ACK_REQUEST_I8: - process_ack_request(std::move(message)); - return; - case PABB_MSG_ACK_REQUEST_I16: - process_ack_request(std::move(message)); - return; - case PABB_MSG_ACK_REQUEST_I32: - process_ack_request(std::move(message)); - return; - case PABB_MSG_ACK_REQUEST_DATA: - process_ack_request(std::move(message)); - return; - case PABB_MSG_ERROR_INVALID_TYPE:{ - if (message.body.size() != sizeof(pabb_MsgInfoInvalidType)){ - m_logger.log("Ignoring message with invalid size."); - return; - } - const pabb_MsgInfoInvalidType* params = (const pabb_MsgInfoInvalidType*)message.body.c_str(); - { - WriteSpinLock lg(m_state_lock, "PABotBase::on_recv_message() - 0"); - m_error_message = "PABotBase incompatibility. Device does not recognize message type: " + std::to_string(params->type); - m_logger.log(m_error_message, COLOR_RED); - } - m_error.store(true, std::memory_order_release); - { - std::lock_guard lg0(m_sleep_lock); - } - m_cv.notify_all(); - } - case PABB_MSG_ERROR_MISSED_REQUEST:{ - if (message.body.size() != sizeof(pabb_MsgInfoMissedRequest)){ - m_logger.log("Ignoring message with invalid size."); - return; - } - const pabb_MsgInfoMissedRequest* params = (const pabb_MsgInfoMissedRequest*)message.body.c_str(); - if (params->seqnum == 1){ - { - WriteSpinLock lg(m_state_lock, "PABotBase::on_recv_message() = 1"); - m_error_message = "Serial connection has been interrupted."; - m_logger.log(m_error_message, COLOR_RED); - } - m_error.store(true, std::memory_order_release); - { - std::lock_guard lg0(m_sleep_lock); - } - m_cv.notify_all(); - } - return; - } - case PABB_MSG_ERROR_DISCONNECTED:{ - m_logger.log("The console has disconnected the controller.", COLOR_RED); - { - WriteSpinLock lg(m_state_lock, "PABotBase::on_recv_message() - 2"); - m_error_message = "Disconnected by console."; - } - m_error.store(true, std::memory_order_release); - { - std::lock_guard lg0(m_sleep_lock); - } - m_cv.notify_all(); - return; - } - case PABB_MSG_REQUEST_COMMAND_FINISHED:{ - process_command_finished(std::move(message)); - return; - } - } -} - -void PABotBase::retransmit_thread(){ - auto scope_check = m_sanitizer.check_scope(); - -// cout << "retransmit_thread()" << endl; - auto last_sent = current_time(); - while (m_state.load(std::memory_order_acquire) == State::RUNNING){ - auto now = current_time(); - - if (now - last_sent < m_retransmit_delay){ - std::unique_lock lg(m_sleep_lock); - if (m_state.load(std::memory_order_acquire) != State::RUNNING){ - break; - } - if (m_error.load(std::memory_order_acquire)){ - break; - } - m_cv.wait_for(lg, m_retransmit_delay); - continue; - } - - // Process retransmits. - WriteSpinLock lg(m_state_lock, "PABotBase::retransmit_thread()"); -// std::cout << "retransmit_thread - m_pending_messages.size(): " << m_pending_messages.size() << std::endl; -// cout << "m_pending_messages.size()" << endl; - - // Retransmit - // Iterate through all pending requests and retransmit them in - // chronological order. ~~Skip the ones that are new.~~ - // (Don't skip the new ones since it will lead to gaps.) - - // Gather together all requests/commands. Sort them by seqnum and - // resend everything. - - WallClock oldest = last_sent; - - std::map messages; - for (auto& item : m_pending_requests){ - item.second.sanitizer.check_usage(); - if (item.second.state == AckState::NOT_ACKED){ - oldest = std::max(oldest, item.second.first_sent); - messages[item.first] = &item.second.request; - } - } - for (auto& item : m_pending_commands){ - item.second.sanitizer.check_usage(); - if (item.second.state == AckState::NOT_ACKED){ - oldest = std::max(oldest, item.second.first_sent); - messages[item.first] = &item.second.request; - } - } - - if (!messages.empty() && now - oldest >= m_retransmit_delay){ - for (const auto& item : messages){ - send_message(*item.second, true); - } - } - -#if 0 - for (auto& item : m_pending_requests){ - item.second.sanitizer.check_usage(); - if (item.second.state == AckState::NOT_ACKED && - current_time() - item.second.first_sent >= m_retransmit_delay - ){ - send_message(item.second.request, true); - } - } - for (auto& item : m_pending_commands){ - item.second.sanitizer.check_usage(); - if (item.second.state == AckState::NOT_ACKED && - current_time() - item.second.first_sent >= m_retransmit_delay - ){ - send_message(item.second.request, true); - } - } -#endif - - last_sent = current_time(); - } -// cout << "retransmit_thread() - exit" << endl; -} - - - - -uint64_t PABotBase::try_issue_request( - Cancellable* cancelled, - const BotBaseRequest& request, - bool silent_remove, bool do_not_block -){ - auto scope_check = m_sanitizer.check_scope(); - - BotBaseMessage message = request.message(); - if (message.body.size() < sizeof(uint32_t)){ - throw InternalProgramError(&m_logger, PA_CURRENT_FUNCTION, "Message is too short."); - } - if (message.body.size() > PABB_PROTOCOL_MAX_PACKET_SIZE){ - throw InternalProgramError(&m_logger, PA_CURRENT_FUNCTION, "Message is too long."); - } - - WriteSpinLock lg(m_state_lock, "PABotBase::try_issue_request()"); - if (cancelled){ - cancelled->throw_if_cancelled(); - } - - State state = m_state.load(std::memory_order_acquire); - if (state != State::RUNNING){ - throw InvalidConnectionStateException(m_error_message); - } - if (m_error.load(std::memory_order_acquire)){ - throw ConnectionException(&m_logger, m_error_message); - } - - size_t queue_limit = m_max_pending_requests.load(std::memory_order_relaxed); - - // Too many unacked requests in flight. - if (!do_not_block && inflight_requests() >= queue_limit){ -// m_logger.log("Message throttled due to too many inflight requests."); - return 0; - } - - // Don't get too far ahead of the oldest seqnum. - uint64_t seqnum = m_send_seq; - if (seqnum - oldest_live_seqnum() > MAX_SEQNUM_GAP){ - if (do_not_block){ - throw ConnectionException( - &m_logger, - "Connection has stalled for a long time. Assuming it is dead." - ); - } - return 0; - } - - seqnum_t seqnum_s = (seqnum_t)seqnum; - memcpy(&message.body[0], &seqnum_s, sizeof(seqnum_t)); - - std::pair::iterator, bool> ret = m_pending_requests.emplace( - std::piecewise_construct, - std::forward_as_tuple(seqnum), - std::forward_as_tuple() - ); - if (!ret.second){ - throw InternalProgramError(&m_logger, PA_CURRENT_FUNCTION, "Duplicate sequence number: " + std::to_string(seqnum)); - } - - m_send_seq = seqnum + 1; - - PendingRequest& handle = ret.first->second; - - handle.silent_remove = silent_remove; - handle.request = std::move(message); - handle.first_sent = current_time(); - -#ifdef INTENTIONALLY_DROP_MESSAGES - if (rand() % 10 != 0){ - send_message(handle.request, false); - }else{ - m_logger.log("Intentionally dropping request: " + std::to_string(seqnum), COLOR_RED); - } -#else - send_message(handle.request, false); -#endif - - return seqnum; -} -uint64_t PABotBase::try_issue_command( - Cancellable* cancelled, - const BotBaseRequest& request, - bool silent_remove -){ - auto scope_check = m_sanitizer.check_scope(); - - BotBaseMessage message = request.message(); - if (message.body.size() < sizeof(uint32_t)){ - throw InternalProgramError(&m_logger, PA_CURRENT_FUNCTION, "Message is too short."); - } - if (message.body.size() > PABB_PROTOCOL_MAX_PACKET_SIZE){ - throw InternalProgramError(&m_logger, PA_CURRENT_FUNCTION, "Message is too long."); - } - - WriteSpinLock lg(m_state_lock, "PABotBase::try_issue_command()"); - if (cancelled){ - cancelled->throw_if_cancelled(); - } - - State state = m_state.load(std::memory_order_acquire); - if (state != State::RUNNING){ - throw InvalidConnectionStateException(m_error_message); - } - if (m_error.load(std::memory_order_acquire)){ - throw ConnectionException(&m_logger, m_error_message); - } - - size_t queue_limit = m_max_pending_requests.load(std::memory_order_relaxed); - - // Command queue is full. - if (m_pending_commands.size() >= queue_limit){ -// cout << "Command queue is full" << endl; - return 0; - } - - // Too many unacked requests in flight. - if (inflight_requests() >= queue_limit){ -// m_logger.log("Message throttled due to too many inflight requests."); - return 0; - } - - // Don't get too far ahead of the oldest seqnum. - uint64_t seqnum = m_send_seq; - if (seqnum - oldest_live_seqnum() > MAX_SEQNUM_GAP){ - return 0; - } - - seqnum_t seqnum_s = (seqnum_t)seqnum; - memcpy(&message.body[0], &seqnum_s, sizeof(seqnum_t)); - - std::pair::iterator, bool> ret = m_pending_commands.emplace( - std::piecewise_construct, - std::forward_as_tuple(seqnum), - std::forward_as_tuple() - ); - if (!ret.second){ - throw InternalProgramError(&m_logger, PA_CURRENT_FUNCTION, "Duplicate sequence number: " + std::to_string(seqnum)); - } - - m_send_seq = seqnum + 1; - - PendingCommand& handle = ret.first->second; - - handle.silent_remove = silent_remove; - handle.request = std::move(message); - handle.first_sent = current_time(); - -#ifdef INTENTIONALLY_DROP_MESSAGES - if (rand() % 10 != 0){ - send_message(handle.request, false); - }else{ - m_logger.log("Intentionally dropping command: " + std::to_string(seqnum), COLOR_RED); - } -#else - send_message(handle.request, false); -#endif - - return seqnum; -} -uint64_t PABotBase::issue_request( - Cancellable* cancelled, - const BotBaseRequest& request, - bool silent_remove, bool do_not_block -){ - auto scope_check = m_sanitizer.check_scope(); - - // Issue a request and return. - // - // If it cannot be issued (because we're over the limits), this function - // will wait until it can be issued. - // - // The "silent_remove" parameter determines what to do when the - // ack (for a request) or a finish (for a command) is received. - // - // If (silent_remove = true), the receiving thread will remove the request - // from the map and do nothing else. This is for async commands. - // - // If (silent_remove = false), the receiving thread will not remove the - // request. Instead, it will notify whatever thread is waiting for the - // result. That waiting thread will process the return value (if any) and - // remove the request from the map. This is for synchronous commands where - // the function waits for the command to finish before returning. - // - - while (true){ - uint64_t seqnum = try_issue_request(cancelled, request, silent_remove, do_not_block); - if (seqnum != 0){ - return seqnum; - } - std::unique_lock lg(m_sleep_lock); - if (cancelled){ - cancelled->throw_if_cancelled(); - } - if (m_state.load(std::memory_order_acquire) != State::RUNNING){ - ReadSpinLock lg0(m_state_lock, "PABotBase::issue_request() - 0"); - throw InvalidConnectionStateException(m_error_message); - } - if (m_error.load(std::memory_order_acquire)){ - ReadSpinLock lg0(m_state_lock, "PABotBase::issue_request() - 1"); - throw ConnectionException(&m_logger, m_error_message); - } - cv_wait(cancelled, lg); - } -} -uint64_t PABotBase::issue_command( - Cancellable* cancelled, - const BotBaseRequest& request, - bool silent_remove -){ - auto scope_check = m_sanitizer.check_scope(); - - // Issue a command and return. - // - // If it cannot be issued (because we're over the limits), this function - // will wait until it can be issued. - // - // The "silent_remove" parameter determines what to do when the - // ack (for a request) or a finish (for a command) is received. - // - // If (silent_remove = true), the receiving thread will remove the request - // from the map and do nothing else. This is for async commands. - // - // If (silent_remove = false), the receiving thread will not remove the - // request. Instead, it will notify whatever thread is waiting for the - // result. That waiting thread will process the return value (if any) and - // remove the request from the map. This is for synchronous commands where - // the function waits for the command to finish before returning. - // - - while (true){ - uint64_t seqnum = try_issue_command(cancelled, request, silent_remove); - if (seqnum != 0){ - return seqnum; - } - std::unique_lock lg(m_sleep_lock); - if (cancelled){ - cancelled->throw_if_cancelled(); - } - if (m_state.load(std::memory_order_acquire) != State::RUNNING){ - ReadSpinLock lg0(m_state_lock, "PABotBase::issue_command() - 0"); - throw InvalidConnectionStateException(m_error_message); - } - if (m_error.load(std::memory_order_acquire)){ - ReadSpinLock lg0(m_state_lock, "PABotBase::issue_command() - 1"); - throw ConnectionException(&m_logger, m_error_message); - } - cv_wait(cancelled, lg); - } -} - -bool PABotBase::try_issue_request( - const BotBaseRequest& request, - Cancellable* cancelled -){ - auto scope_check = m_sanitizer.check_scope(); - - if (!request.is_command()){ - return try_issue_request(cancelled, request, true, false) != 0; - }else{ - return try_issue_command(cancelled, request, true) != 0; - } -} -void PABotBase::issue_request( - const BotBaseRequest& request, - Cancellable* cancelled -){ - auto scope_check = m_sanitizer.check_scope(); - - if (!request.is_command()){ - issue_request(cancelled, request, true, false); - }else{ - issue_command(cancelled, request, true); - } -} - -BotBaseMessage PABotBase::issue_request_and_wait( - const BotBaseRequest& request, - Cancellable* cancelled -){ - auto scope_check = m_sanitizer.check_scope(); - - if (request.is_command()){ - throw InternalProgramError(&m_logger, PA_CURRENT_FUNCTION, "This function only supports requests."); - } - - uint64_t seqnum = issue_request(cancelled, request, false, false); - return wait_for_request(seqnum, cancelled); -} -BotBaseMessage PABotBase::wait_for_request(uint64_t seqnum, Cancellable* cancelled){ - auto scope_check = m_sanitizer.check_scope(); - - std::unique_lock lg(m_sleep_lock); - while (true){ - if (cancelled){ - cancelled->throw_if_cancelled(); - } - - { - WriteSpinLock slg(m_state_lock, "PABotBase::issue_request_and_wait()"); - auto iter = m_pending_requests.find(seqnum); - if (iter == m_pending_requests.end()){ - throw OperationCancelledException(); - } - iter->second.sanitizer.check_usage(); - - State state = m_state.load(std::memory_order_acquire); - if (state != State::RUNNING){ - m_pending_requests.erase(iter); - m_cv.notify_all(); - throw InvalidConnectionStateException(m_error_message); - } - if (m_error.load(std::memory_order_acquire)){ - m_pending_requests.erase(iter); - m_cv.notify_all(); - throw ConnectionException(&m_logger, m_error_message); - } - if (iter->second.state == AckState::ACKED){ - BotBaseMessage ret = std::move(iter->second.ack); - m_pending_requests.erase(iter); - m_cv.notify_all(); - return ret; - } - } - cv_wait(cancelled, lg); - } -} - - -void PABotBase::cv_wait(Cancellable* cancellable, std::unique_lock& lg){ - if (cancellable == nullptr){ - m_cv.wait(lg); - return; - } - - cancellable->add_cancel_listener(*this); - m_cv.wait(lg); - - // Unlock to remove. Otherwise, it may deadlock with "on_cancellable_cancel()" - // being called from a listener callback. - lg.unlock(); - cancellable->remove_cancel_listener(*this); - lg.lock(); -} - - - - - -} diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBase.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBase.h deleted file mode 100644 index 810deb6984..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBase.h +++ /dev/null @@ -1,216 +0,0 @@ -/* Pokemon Automation Bot Base - * - * From: https://github.com/PokemonAutomation/ - * - * This is the main PABotBase class. - * - * This class represents a connection to a single PABotBase instance running on - * a user specified COM port. You can have multiple instances of this class if - * you are connecting to multiple devices at once. - * - * This class implements the full communication protocol. So you directly - * invoke commands from this class which will be passed on to the Arduino/Teensy. - * - * Requests and commands may be asynchronous. They may return before the device - * executes it. - * - * - * Note that button commands will only work if the device is running PABotBase - * and is not already running a command. The regular programs do not listen to - * button press requests since they are already running their own program. - * - */ - -#ifndef PokemonAutomation_PABotBase_H -#define PokemonAutomation_PABotBase_H - -#include -#include -#include -#include "Common/Cpp/Logging/AbstractLogger.h" -#include "Common/Cpp/Concurrency/SpinLock.h" -#include "Common/Cpp/Concurrency/Mutex.h" -#include "Common/Cpp/Concurrency/ConditionVariable.h" -#include "Common/Cpp/Concurrency/AsyncTask.h" -#include "Common/Cpp/Concurrency/ThreadPool.h" -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/SerialPABotBase/Connection/PABotBaseConnection.h" -#include "BotBase.h" -#include "BotBaseMessage.h" - - -namespace PokemonAutomation{ - - -class PABotBase final : public BotBaseController, public PABotBaseConnection{ - static const seqnum_t MAX_SEQNUM_GAP = (seqnum_t)-1 >> 2; - -public: - PABotBase( - Logger& logger, - ThreadPool& thread_pool, - std::unique_ptr connection, - std::chrono::milliseconds retransmit_delay = std::chrono::milliseconds(100) - ); - virtual ~PABotBase(); - - void connect(); - virtual void stop(std::string error_message = "") noexcept override; - - std::chrono::time_point last_ack() const{ - return m_last_ack.load(std::memory_order_acquire); - } - - virtual Logger& logger() override{ - return m_logger; - } - virtual State state() const override{ - return m_state.load(std::memory_order_acquire); - } - virtual void on_cancellable_cancel( - Cancellable& cancellable, - std::exception_ptr reason - ) override; - - virtual size_t queue_limit() const override{ - return m_max_pending_requests.load(std::memory_order_relaxed); - } - void set_queue_limit(size_t queue_limit); - -public: - // Basic Requests - - virtual void wait_for_all_requests(Cancellable* cancelled = nullptr) override; - virtual void stop_all_commands() override; - virtual void next_command_interrupt() override; - - -public: - // For Command Implementations - -// using BotBaseController::try_issue_request; - using BotBaseController::issue_request; - using BotBaseController::issue_request_and_wait; - - -private: - enum class AckState{ - NOT_ACKED, - ACKED, - FINISHED, - }; - struct PendingRequest{ - AckState state = AckState::NOT_ACKED; - bool silent_remove; - BotBaseMessage request; - BotBaseMessage ack; - WallClock first_sent; - LifetimeSanitizer sanitizer; - }; - struct PendingCommand{ - AckState state = AckState::NOT_ACKED; - bool silent_remove; - BotBaseMessage request; - BotBaseMessage ack; - WallClock first_sent; - LifetimeSanitizer sanitizer; - }; - - template - uint64_t infer_full_seqnum(const Map& map, seqnum_t seqnum) const; - - uint64_t oldest_live_seqnum() const; - - template - void process_ack_request(BotBaseMessage message); - template - void process_ack_command(BotBaseMessage message); - - template void process_command_finished(BotBaseMessage message); - virtual void on_recv_message(BotBaseMessage message) override; - - void clear_all_active_commands(uint64_t seqnum); - - void retransmit_thread(); - -private: - size_t inflight_requests(); - - // Returns the seqnum of the request. If failed, returns zero. - uint64_t try_issue_request( - Cancellable* cancelled, - const BotBaseRequest& request, - bool silent_remove, bool do_not_block - ); - uint64_t try_issue_command( - Cancellable* cancelled, - const BotBaseRequest& request, - bool silent_remove - ); - - // Returns the seqnum of the request. - uint64_t issue_request( - Cancellable* cancelled, - const BotBaseRequest& request, - bool silent_remove, bool do_not_block - ); - uint64_t issue_command( - Cancellable* cancelled, - const BotBaseRequest& request, - bool silent_remove - ); - -public: - virtual bool try_issue_request( - const BotBaseRequest& request, - Cancellable* cancelled - ) override; - virtual void issue_request( - const BotBaseRequest& request, - Cancellable* cancelled - ) override; - virtual BotBaseMessage issue_request_and_wait( - const BotBaseRequest& request, - Cancellable* cancelled - ) override; - -private: - BotBaseMessage wait_for_request(uint64_t seqnum, Cancellable* cancelled = nullptr); - - // Make we get notified of a cancellable cancels so we can wake up. - void cv_wait(Cancellable* cancellable, std::unique_lock& lg); - -private: - Logger& m_logger; - - std::atomic m_max_pending_requests; - - uint64_t m_send_seq; - std::chrono::milliseconds m_retransmit_delay; - std::atomic> m_last_ack; - - std::map m_pending_requests; - std::map m_pending_commands; - - // If you need both locks, always acquire m_sleep_lock first! - SpinLock m_state_lock; - Mutex m_sleep_lock; - - ConditionVariable m_cv; - std::atomic m_state; - std::atomic m_error; - std::string m_error_message; - AsyncTask m_retransmit_thread; - - LifetimeSanitizer m_sanitizer; -}; - - - - - - - -} - -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBaseConnection.cpp b/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBaseConnection.cpp deleted file mode 100644 index d6f8a2c80f..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBaseConnection.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* Pokemon Automation Bot Base - Client Example - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Common/Cpp/Exceptions.h" -#include "Common/CRC32/pabb_CRC32.h" -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "BotBaseMessage.h" -#include "PABotBaseConnection.h" - -//#include -//using std::cout; -//using std::endl; - -namespace PokemonAutomation{ - - - -PABotBaseConnection::PABotBaseConnection( - Logger& logger, - std::unique_ptr connection -) - : m_connection(std::move(connection)) - , m_logger(logger) -{ - m_connection->add_listener(*this); -} -PABotBaseConnection::~PABotBaseConnection(){ - if (m_connection){ - safely_stop(); - } -} -void PABotBaseConnection::safely_stop(){ - if (m_connection){ - m_connection->stop(); - m_connection.reset(); - } -} - - -void PABotBaseConnection::add_message_printer(const BotBaseMessageType& type){ - auto ret = m_printers.emplace(type.type(), &type); - if (ret.second){ - return; - } - throw InternalProgramError( - nullptr, - PA_CURRENT_FUNCTION, - "Duplicate Message Type: 0x" + tostr_hex(type.type()) - ); -} - - -void PABotBaseConnection::send_zeros(uint8_t bytes){ - if (!m_connection){ - return; - } - - char ch = 0; - for (uint8_t c = 0; c < bytes; c++){ - m_connection->unreliable_send(&ch, 1); -// Sleep(10); - } -} -void PABotBaseConnection::send_message(const BotBaseMessage& message, bool is_retransmit){ - if (!m_connection){ - return; - } - -// log("Sending: " + message_to_string(type, msg)); - { - std::string str = is_retransmit ? "Re-send" : "Sending"; - auto iter = m_printers.find(message.type); - if (iter == m_printers.end()){ - m_logger.log(str + ": Unknown Message Type (0x" + tostr_hex(message.type) + ")", COLOR_RED); - }else if (is_retransmit || iter->second->should_print(message.body)){ - m_logger.log( - str + ": " + iter->second->tostr(message.body), - is_retransmit ? COLOR_ORANGE : COLOR_DARKGREEN - ); - } - } - - size_t total_bytes = PABB_PROTOCOL_OVERHEAD + message.body.size(); - if (total_bytes > PABB_PROTOCOL_MAX_PACKET_SIZE){ - throw InternalProgramError(&m_logger, PA_CURRENT_FUNCTION, "Message is too long."); - } - - std::string buffer; - buffer += ~(uint8_t)total_bytes; - buffer += message.type; - buffer += message.body; - buffer += std::string(sizeof(uint32_t), 0); - pabb_crc32_write_to_message(0xffffffff, &buffer[0], buffer.size()); - - m_connection->unreliable_send(&buffer[0], buffer.size()); -} - - -void PABotBaseConnection::push_error_byte(ErrorBatchType type, char byte){ - if (m_current_error_type == type){ - m_current_error_batch.push_back(byte); - return; - } - - switch (m_current_error_type){ - case ErrorBatchType::NO_ERROR_: - break; - case ErrorBatchType::ZERO_BYTES: - m_logger.log("Skipped " + std::to_string(m_current_error_batch.size()) + " zero byte(s).", COLOR_RED); - break; - case ErrorBatchType::FF_BYTES: - m_logger.log("Skipped " + std::to_string(m_current_error_batch.size()) + " 0xff byte(s).", COLOR_RED); - break; - case ErrorBatchType::ASCII_BYTES: - m_logger.log("Received possible ASCII: " + m_current_error_batch, COLOR_RED); - break; - case ErrorBatchType::OTHER: -// m_logger.log("Skipped " + std::to_string(m_current_error_batch.size()) + " invalid length byte(s).", COLOR_RED); - break; - } - - m_current_error_batch.clear(); - m_current_error_batch.push_back(byte); - m_current_error_type = type; -} -void PABotBaseConnection::on_recv(const void* data, size_t bytes){ - // Push into receive buffer. - for (size_t c = 0; c < bytes; c++){ - m_recv_buffer.emplace_back(((const char*)data)[c]); - } - - while (!m_recv_buffer.empty()){ - uint8_t length = ~m_recv_buffer[0]; - - if (m_recv_buffer[0] == 0){ -// m_logger.log("Skipping zero byte.", COLOR_RED); - push_error_byte(ErrorBatchType::ZERO_BYTES, 0); - m_recv_buffer.pop_front(); - continue; - } - - // Message is too short. - if (length < PABB_PROTOCOL_OVERHEAD){ - if (length == 0){ - push_error_byte(ErrorBatchType::FF_BYTES, ~length); - }else{ - m_logger.log("Message is too short: bytes = " + std::to_string(length), COLOR_RED); - push_error_byte(ErrorBatchType::OTHER, ~length); - } - m_recv_buffer.pop_front(); - continue; - } - - // Message is too long. - if (length > PABB_PROTOCOL_MAX_PACKET_SIZE){ -// char ascii = ~length; -// std::string text = ascii < 32 -// ? ", ascii = " + std::to_string(ascii) -// : std::string(", char = ") + ascii; -// m_logger.log("Message is too long: bytes = " + std::to_string(length) + text, COLOR_RED); - push_error_byte(ErrorBatchType::ASCII_BYTES, ~length); - m_recv_buffer.pop_front(); - continue; - } - - // Message is incomplete. - if (length > m_recv_buffer.size()){ - return; - } - - m_current_error_type = ErrorBatchType::NO_ERROR_; - m_current_error_batch.clear(); - - std::string message(m_recv_buffer.begin(), m_recv_buffer.begin() + length); - - // Verify checksum - { - // Calculate checksum. - uint32_t checksumA = 0xffffffff; - pabb_crc32_buffer(&checksumA, &message[0], length - sizeof(uint32_t)); - - // Read the checksum from the message. - uint32_t checksumE = ((uint32_t*)(&message[0] + length))[-1]; - - // Compare -// std::cout << checksumA << " / " << checksumE << std::endl; - if (checksumA != checksumE){ - m_logger.log("Invalid Checksum: bytes = " + std::to_string(length), COLOR_RED); -// std::cout << checksumA << " / " << checksumE << std::endl; -// log(message_to_string(message[1], &message[2], length - PABB_PROTOCOL_OVERHEAD)); - m_recv_buffer.pop_front(); - continue; - } - } - m_recv_buffer.erase(m_recv_buffer.begin(), m_recv_buffer.begin() + length); - - BotBaseMessage msg(message[1], std::string(&message[2], length - PABB_PROTOCOL_OVERHEAD)); - { - auto iter = m_printers.find(msg.type); - if (iter == m_printers.end()){ - m_logger.log("Receive: Unknown Message Type (0x" + tostr_hex(msg.type) + ")", COLOR_RED); - }else if (iter->second->should_print(msg.body)){ - m_logger.log("Receive: " + iter->second->tostr(msg.body), COLOR_DARKGREEN); - } - } - on_recv_message(std::move(msg)); - } -} - - -} diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBaseConnection.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBaseConnection.h deleted file mode 100644 index 4441ba1b54..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBaseConnection.h +++ /dev/null @@ -1,81 +0,0 @@ -/* PABotBase Connection - * - * From: https://github.com/PokemonAutomation/ - * - * This class wraps a raw SerialConnection object and applies the - * communication protocol on top of it. It automatically throws out bad - * messsages and passes only the relevant message body onto the child - * listener class. - * - * This class does not handle retransmissions. - * - */ - -#ifndef PokemonAutomation_PABotBaseConnection_H -#define PokemonAutomation_PABotBaseConnection_H - -#include -#include -#include -#include "Common/Cpp/StreamConnections/PushingStreamConnections.h" -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "BotBase.h" - -namespace PokemonAutomation{ - - -class BotBaseMessageType; - - - -// None the functions in this class are thread-safe. It is up to -// the child class to wrap and make them thread-safe. -class PABotBaseConnection : public StreamListener{ -public: - PABotBaseConnection( - Logger& logger, - std::unique_ptr connection - ); - virtual ~PABotBaseConnection(); - - void add_message_printer(const BotBaseMessageType& type); - -public: - void send_zeros(uint8_t bytes = PABB_PROTOCOL_MAX_PACKET_SIZE); - void send_message(const BotBaseMessage& message, bool is_retransmit); - -protected: - // Not thread-safe with sends. - void safely_stop(); - -private: - virtual void on_recv(const void* data, size_t bytes) override; - virtual void on_recv_message(BotBaseMessage message) = 0; - - enum class ErrorBatchType{ - NO_ERROR_, - ZERO_BYTES, - FF_BYTES, - ASCII_BYTES, - OTHER, - }; - void push_error_byte(ErrorBatchType type, char byte); - -private: - std::unique_ptr m_connection; - std::deque m_recv_buffer; - - ErrorBatchType m_current_error_type; - std::string m_current_error_batch; - -protected: - Logger& m_logger; - - std::map m_printers; -}; - - - -} - -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Acks.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Acks.h deleted file mode 100644 index b21d808830..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Acks.h +++ /dev/null @@ -1,162 +0,0 @@ -/* SerialPABotBase Messages - Base Protocol Acks - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_Acks_H -#define PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_Acks_H - -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - -class MessageType_AckCommand : public BotBaseMessageType{ - using Params = pabb_MsgAckCommand; -public: - MessageType_AckCommand() - : BotBaseMessageType( - "PABB_MSG_ACK_COMMAND", - PABB_MSG_ACK_COMMAND, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class MessageType_AckRequest : public BotBaseMessageType{ - using Params = pabb_MsgAckRequest; -public: - MessageType_AckRequest() - : BotBaseMessageType( - "PABB_MSG_ACK_REQUEST", - PABB_MSG_ACK_REQUEST, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class MessageType_AckRequest_i8 : public BotBaseMessageType{ - using Params = pabb_MsgAckRequestI8; -public: - MessageType_AckRequest_i8() - : BotBaseMessageType( - "PABB_MSG_ACK_REQUEST_I8", - PABB_MSG_ACK_REQUEST_I8, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", value = " + std::to_string((unsigned)params.data); - return ret; - } -}; -class MessageType_AckRequest_i16 : public BotBaseMessageType{ - using Params = pabb_MsgAckRequestI16; -public: - MessageType_AckRequest_i16() - : BotBaseMessageType( - "PABB_MSG_ACK_REQUEST_I16", - PABB_MSG_ACK_REQUEST_I16, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", value = " + std::to_string(params.data); - return ret; - } -}; -class MessageType_AckRequest_i32 : public BotBaseMessageType{ - using Params = pabb_MsgAckRequestI32; -public: - MessageType_AckRequest_i32() - : BotBaseMessageType( - "PABB_MSG_ACK_REQUEST_I32", - PABB_MSG_ACK_REQUEST_I32, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", value = " + std::to_string(params.data); - return ret; - } -}; -class MessageType_AckRequest_Data : public BotBaseMessageType{ -public: - MessageType_AckRequest_Data() - : BotBaseMessageType( - "PABB_MSG_ACK_REQUEST_DATA", - PABB_MSG_ACK_REQUEST_DATA, - sizeof(seqnum_t) - ) - {} - virtual bool is_valid(const std::string& body) const override{ - return sizeof(seqnum_t) <= body.size(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - seqnum_t seqnum; - memcpy(&seqnum, body.data(), sizeof(seqnum)); - ret += ": seqnum = " + std::to_string(seqnum); - ret += ", data ="; - static const char HEX_DIGITS[] = "0123456789abcdef"; - for (size_t c = sizeof(seqnum_t); c < body.size(); c++){ - uint8_t byte = body[c]; - ret += " "; - ret += HEX_DIGITS[(byte >> 4)]; - ret += HEX_DIGITS[byte & 15]; - } - return ret; - } -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_CommandQueue.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_CommandQueue.h deleted file mode 100644 index 004aba274c..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_CommandQueue.h +++ /dev/null @@ -1,117 +0,0 @@ -/* SerialPABotBase Messages - Base Protocol Command Queue - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_CommandQueue_H -#define PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_CommandQueue_H - -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - -class MessageType_CommandFinished : public BotBaseMessageType{ - using Params = pabb_MsgRequestCommandFinished; -public: - MessageType_CommandFinished() - : BotBaseMessageType( - "PABB_MSG_REQUEST_COMMAND_FINISHED", - PABB_MSG_REQUEST_COMMAND_FINISHED, - sizeof(Params) - ) - {} - virtual bool should_print(const std::string& body) const override{ - return LOG_EVERYTHING(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", seq_of_original_command = " + std::to_string((unsigned)params.seq_of_original_command); - ret += ", finish_time = " + std::to_string(params.finish_time); - return ret; - } -}; - - - -class MessageType_RequestStop : public BotBaseMessageType{ - using Params = pabb_MsgRequestProtocolVersion; -public: - MessageType_RequestStop() - : BotBaseMessageType( - "PABB_MSG_REQUEST_STOP", - PABB_MSG_REQUEST_STOP, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_request_stop : public BotBaseRequest{ -public: - pabb_MsgRequestProtocolVersion params{}; - DeviceRequest_request_stop() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_STOP, params); - } -}; - - - -class MessageType_NextCommandInterrupt : public BotBaseMessageType{ - using Params = pabb_MsgRequestNextCmdInterrupt; -public: - MessageType_NextCommandInterrupt() - : BotBaseMessageType( - "PABB_MSG_REQUEST_NEXT_CMD_INTERRUPT", - PABB_MSG_REQUEST_NEXT_CMD_INTERRUPT, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_next_command_interrupt : public BotBaseRequest{ -public: - pabb_MsgRequestNextCmdInterrupt params{}; - DeviceRequest_next_command_interrupt() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_NEXT_CMD_INTERRUPT, params); - } -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode.h deleted file mode 100644 index bfc3cd1d5c..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode.h +++ /dev/null @@ -1,128 +0,0 @@ -/* SerialPABotBase Messages - Base Protocol Controller Mode - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode_H -#define PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode_H - -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - -class MessageType_ReadControllerMode : public BotBaseMessageType{ - using Params = pabb_MsgRequestReadControllerMode; -public: - MessageType_ReadControllerMode() - : BotBaseMessageType( - "PABB_MSG_REQUEST_READ_CONTROLLER_MODE", - PABB_MSG_REQUEST_READ_CONTROLLER_MODE, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_read_controller_mode : public BotBaseRequest{ -public: - pabb_MsgRequestReadControllerMode params{}; - DeviceRequest_read_controller_mode() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_READ_CONTROLLER_MODE, params); - } -}; - - - -class MessageType_ChangeControllerMode : public BotBaseMessageType{ - using Params = pabb_MsgRequestChangeControllerMode; -public: - MessageType_ChangeControllerMode() - : BotBaseMessageType( - "PABB_MSG_REQUEST_CHANGE_CONTROLLER_MODE", - PABB_MSG_REQUEST_CHANGE_CONTROLLER_MODE, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", controller = " + tostr_hex(params.controller_id); - return ret; - } -}; -class DeviceRequest_change_controller_mode : public BotBaseRequest{ -public: - pabb_MsgRequestChangeControllerMode params{}; - DeviceRequest_change_controller_mode(uint32_t controller_id) - : BotBaseRequest(false) - { - params.controller_id = controller_id; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_CHANGE_CONTROLLER_MODE, params); - } -}; - - - -class MessageType_ResetToController : public BotBaseMessageType{ - using Params = pabb_MsgRequestChangeControllerMode; -public: - MessageType_ResetToController() - : BotBaseMessageType( - "PABB_MSG_REQUEST_RESET_TO_CONTROLLER", - PABB_MSG_REQUEST_RESET_TO_CONTROLLER, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", controller = " + tostr_hex(params.controller_id); - return ret; - } -}; -class DeviceRequest_reset_to_controller : public BotBaseRequest{ -public: - pabb_MsgRequestChangeControllerMode params{}; - DeviceRequest_reset_to_controller(uint32_t controller_id) - : BotBaseRequest(false) - { - params.controller_id = controller_id; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_RESET_TO_CONTROLLER, params); - } -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Errors.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Errors.h deleted file mode 100644 index ac1929a565..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Errors.h +++ /dev/null @@ -1,201 +0,0 @@ -/* SerialPABotBase Messages - Base Protocol Errors - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_Errors_H -#define PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_Errors_H - -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - -class MessageType_ErrorReady : public BotBaseMessageType{ -public: - MessageType_ErrorReady() - : BotBaseMessageType( - "PABB_MSG_ERROR_READY", - PABB_MSG_ERROR_READY, - 0 - ) - {} -}; -class MessageType_InvalidMessage : public BotBaseMessageType{ - using Params = pabb_MsgInfoInvalidMessage; -public: - MessageType_InvalidMessage() - : BotBaseMessageType( - "PABB_MSG_ERROR_INVALID_MESSAGE", - PABB_MSG_ERROR_INVALID_MESSAGE, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": length = " + std::to_string((unsigned)params.message_length); - return ret; - } -}; -class MessageType_ChecksumMismatch : public BotBaseMessageType{ - using Params = pabb_MsgInfoChecksumMismatch; -public: - MessageType_ChecksumMismatch() - : BotBaseMessageType( - "PABB_MSG_ERROR_CHECKSUM_MISMATCH", - PABB_MSG_ERROR_CHECKSUM_MISMATCH, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": length = " + std::to_string((unsigned)params.message_length); - return ret; - } -}; -class MessageType_InvalidType : public BotBaseMessageType{ - using Params = pabb_MsgInfoInvalidType; -public: - MessageType_InvalidType() - : BotBaseMessageType( - "PABB_MSG_ERROR_INVALID_TYPE", - PABB_MSG_ERROR_INVALID_TYPE, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": type = " + std::to_string((unsigned)params.type); - return ret; - } -}; -class MessageType_InvalidRequest : public BotBaseMessageType{ - using Params = pabb_MsgInfoInvalidRequest; -public: - MessageType_InvalidRequest() - : BotBaseMessageType( - "PABB_MSG_ERROR_INVALID_REQUEST", - PABB_MSG_ERROR_INVALID_REQUEST, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class MessageType_MissedRequest : public BotBaseMessageType{ - using Params = pabb_MsgInfoMissedRequest; -public: - MessageType_MissedRequest() - : BotBaseMessageType( - "PABB_MSG_ERROR_MISSED_REQUEST", - PABB_MSG_ERROR_MISSED_REQUEST, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class MessageType_CommandDropped : public BotBaseMessageType{ - using Params = pabb_MsgInfoCommandDropped; -public: - MessageType_CommandDropped() - : BotBaseMessageType( - "PABB_MSG_ERROR_COMMAND_DROPPED", - PABB_MSG_ERROR_COMMAND_DROPPED, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class MessageType_ErrorWarning : public BotBaseMessageType{ - using Params = pabb_MsgInfoWARNING; -public: - MessageType_ErrorWarning() - : BotBaseMessageType( - "PABB_MSG_ERROR_WARNING", - PABB_MSG_ERROR_WARNING, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": error_code = " + std::to_string(params.error_code); - return ret; - } -}; -class MessageType_ErrorDisconnected : public BotBaseMessageType{ - using Params = pabb_MsgInfoDisconnected; -public: - MessageType_ErrorDisconnected() - : BotBaseMessageType( - "PABB_MSG_ERROR_DISCONNECTED", - PABB_MSG_ERROR_DISCONNECTED, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": error_code = " + std::to_string(params.error_code); - return ret; - } -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Info.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Info.h deleted file mode 100644 index 531eeae3f9..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Info.h +++ /dev/null @@ -1,190 +0,0 @@ -/* SerialPABotBase Messages - Base Protocol Info - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_Info_H -#define PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_Info_H - -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - -class MessageType_Info_i32 : public BotBaseMessageType{ - using Params = pabb_MsgInfoI32; -public: - MessageType_Info_i32() - : BotBaseMessageType( - "PABB_MSG_INFO_I32", - PABB_MSG_INFO_I32, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": tag = " + std::to_string(params.tag); - ret += ", value = " + std::to_string(params.data); - return ret; - } -}; -class MessageType_Info_Data : public BotBaseMessageType{ - using Params = pabb_MsgInfoData; -public: - MessageType_Info_Data() - : BotBaseMessageType( - "PABB_MSG_INFO_DATA", - PABB_MSG_INFO_DATA, - sizeof(Params) - ) - {} - virtual bool is_valid(const std::string& body) const override{ - return sizeof(seqnum_t) <= body.size(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": tag = " + std::to_string(params.tag); - ret += ", data ="; - static const char HEX_DIGITS[] = "0123456789abcdef"; - for (size_t c = sizeof(seqnum_t); c < body.size(); c++){ - uint8_t byte = body[c]; - ret += " "; - ret += HEX_DIGITS[(byte >> 4)]; - ret += HEX_DIGITS[byte & 15]; - } - return ret; - } -}; -class MessageType_Info_String : public BotBaseMessageType{ -public: - MessageType_Info_String() - : BotBaseMessageType( - "PABB_MSG_INFO_STRING", - PABB_MSG_INFO_STRING, - 0 - ) - {} - virtual bool is_valid(const std::string& body) const override{ - return true; - } - virtual std::string tostr(const std::string& body) const override{ - return BotBaseMessageType::tostr(body) + ": " + body; - } -}; -class MessageType_Info_Label_i32 : public BotBaseMessageType{ - using Params = pabb_MsgInfoI32Label; -public: - MessageType_Info_Label_i32() - : BotBaseMessageType( - "PABB_MSG_INFO_I32_LABEL", - PABB_MSG_INFO_I32_LABEL, - sizeof(Params) - ) - {} - virtual bool is_valid(const std::string& body) const override{ - return sizeof(Params) <= body.size(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": " + std::string(body.data() + sizeof(uint32_t), body.size() - sizeof(uint32_t)); - ret += ": " + std::to_string(params.value); - return ret; - } -}; -class MessageType_Info_Label_h32 : public BotBaseMessageType{ - using Params = pabb_MsgInfoI32Label; -public: - MessageType_Info_Label_h32() - : BotBaseMessageType( - "PABB_MSG_INFO_H32_LABEL", - PABB_MSG_INFO_H32_LABEL, - sizeof(Params) - ) - {} - virtual bool is_valid(const std::string& body) const override{ - return sizeof(Params) <= body.size(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": " + std::string(body.data() + sizeof(uint32_t), body.size() - sizeof(uint32_t)); - ret += ": 0x" + tostr_hex(params.value); - return ret; - } -}; -class MessageType_Info_ResetReason : public BotBaseMessageType{ - using Params = pabb_MsgDeviceReset; -public: - MessageType_Info_ResetReason() - : BotBaseMessageType( - "PABB_MSG_INFO_DEVICE_RESET_REASON", - PABB_MSG_INFO_DEVICE_RESET_REASON, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - - std::string reason; - switch (params.reason){ - case PABB_DeviceResetReason_UNKNOWN: - reason = "Unknown"; - break; - case PABB_DeviceResetReason_OTHER: - reason = "Other"; - break; - case PABB_DeviceResetReason_POWER_ON: - reason = "Power On"; - break; - case PABB_DeviceResetReason_MANUAL: - reason = "Manual"; - break; - case PABB_DeviceResetReason_BROWNOUT: - reason = "Brownout"; - break; - case PABB_DeviceResetReason_CRASH: - reason = "Crash"; - break; - default: - reason = "(Invalid Reason)"; - } - - ret += ": reason = " + reason; - ret += ", native_code = " + std::to_string(params.native_code); - return ret; - } -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Misc.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Misc.h deleted file mode 100644 index 524fe9744b..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Misc.h +++ /dev/null @@ -1,175 +0,0 @@ -/* SerialPABotBase Messages - Base Protocol Misc. - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_Misc_H -#define PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_Misc_H - -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/ControllerTypes.h" -#include "Controllers/SerialPABotBase/SerialPABotBase.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - -class MessageType_SystemClock : public BotBaseMessageType{ - using Params = pabb_system_clock; -public: - MessageType_SystemClock() - : BotBaseMessageType( - "PABB_MSG_REQUEST_CLOCK", - PABB_MSG_REQUEST_CLOCK, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_system_clock : public BotBaseRequest{ -public: - pabb_system_clock params{}; - DeviceRequest_system_clock() - : BotBaseRequest(false) - { - params.seqnum = 0; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_CLOCK, params); - } -}; - - - -class MessageType_ControllerStatus : public BotBaseMessageType{ - using Params = pabb_Message_RequestStatus; -public: - MessageType_ControllerStatus() - : BotBaseMessageType( - "PABB_MSG_REQUEST_STATUS", - PABB_MSG_REQUEST_STATUS, - sizeof(Params) - ) - {} - virtual bool should_print(const std::string& body) const override{ - return LOG_EVERYTHING(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class MessageControllerStatus : public BotBaseRequest{ -public: - pabb_Message_RequestStatus params{}; - MessageControllerStatus() - : BotBaseRequest(false) - { - params.seqnum = 0; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_STATUS, params); - } -}; - - - -class MessageType_ReadMacAddress : public BotBaseMessageType{ - using Params = pabb_MsgRequestReadMacAddress; -public: - MessageType_ReadMacAddress() - : BotBaseMessageType( - "PABB_MSG_REQUEST_READ_MAC_ADDRESS", - PABB_MSG_REQUEST_READ_MAC_ADDRESS, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", mode = " + std::to_string(params.mode); - return ret; - } -}; -class DeviceRequest_read_mac_address : public BotBaseRequest{ -public: - pabb_MsgRequestReadMacAddress params{}; - DeviceRequest_read_mac_address(uint32_t mode) - : BotBaseRequest(false) - { - params.seqnum = 0; - params.mode = mode; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_READ_MAC_ADDRESS, params); - } -}; - - - -class MessageType_PairedMacAddress : public BotBaseMessageType{ - using Params = pabb_MsgRequestPairedMacAddress; -public: - MessageType_PairedMacAddress() - : BotBaseMessageType( - "PABB_MSG_REQUEST_PAIRED_MAC_ADDRESS", - PABB_MSG_REQUEST_PAIRED_MAC_ADDRESS, - sizeof(Params) - ) - {} - virtual bool should_print(const std::string& body) const override{ - return LOG_EVERYTHING(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", mode = " + std::to_string(params.mode); - return ret; - } -}; -class DeviceRequest_paired_mac_address : public BotBaseRequest{ -public: - pabb_MsgRequestPairedMacAddress params{}; - DeviceRequest_paired_mac_address(ControllerType controller_type) - : BotBaseRequest(false) - { - params.mode = controller_type_to_id(controller_type); - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_PAIRED_MAC_ADDRESS, params); - } -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_StaticRequests.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_StaticRequests.h deleted file mode 100644 index 320f24c1ad..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_StaticRequests.h +++ /dev/null @@ -1,260 +0,0 @@ -/* SerialPABotBase Messages - Base Protocol Static Requests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_StaticRequests_H -#define PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_StaticRequests_H - -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - -class MessageType_SeqnumReset : public BotBaseMessageType{ - using Params = pabb_MsgInfoSeqnumReset; -public: - MessageType_SeqnumReset() - : BotBaseMessageType( - "PABB_MSG_SEQNUM_RESET", - PABB_MSG_SEQNUM_RESET, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_seqnum_reset : public BotBaseRequest{ -public: - pabb_MsgInfoSeqnumReset params{}; - DeviceRequest_seqnum_reset() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_SEQNUM_RESET, params); - } -}; - - - -class MessageType_ProtocolVersion : public BotBaseMessageType{ - using Params = pabb_MsgRequestProtocolVersion; -public: - MessageType_ProtocolVersion() - : BotBaseMessageType( - "PABB_MSG_REQUEST_PROTOCOL_VERSION", - PABB_MSG_REQUEST_PROTOCOL_VERSION, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_protocol_version : public BotBaseRequest{ -public: - pabb_MsgRequestProtocolVersion params{}; - DeviceRequest_protocol_version() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_PROTOCOL_VERSION, params); - } -}; - - - -class MessageType_ProgramVersion : public BotBaseMessageType{ - using Params = pabb_MsgRequestProgramVersion; -public: - MessageType_ProgramVersion() - : BotBaseMessageType( - "PABB_MSG_REQUEST_PROGRAM_VERSION", - PABB_MSG_REQUEST_PROGRAM_VERSION, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_program_version : public BotBaseRequest{ -public: - pabb_MsgRequestProgramVersion params{}; - DeviceRequest_program_version() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_PROGRAM_VERSION, params); - } -}; - - - -class MessageType_ProgramID : public BotBaseMessageType{ - using Params = pabb_MsgRequestProgramID; -public: - MessageType_ProgramID() - : BotBaseMessageType( - "PABB_MSG_REQUEST_PROGRAM_ID", - PABB_MSG_REQUEST_PROGRAM_ID, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_program_id : public BotBaseRequest{ -public: - pabb_MsgRequestProgramID params{}; - DeviceRequest_program_id() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_PROGRAM_ID, params); - } -}; - - - -class MessageType_ProgramName : public BotBaseMessageType{ - using Params = pabb_MsgRequestProgramName; - -public: - MessageType_ProgramName() - : BotBaseMessageType( - "PABB_MSG_REQUEST_PROGRAM_NAME", - PABB_MSG_REQUEST_PROGRAM_NAME, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_program_name : public BotBaseRequest{ -public: - pabb_MsgRequestProgramName params{}; - DeviceRequest_program_name() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_PROGRAM_NAME, params); - } -}; - - - -class MessageType_ControllerList : public BotBaseMessageType{ - using Params = pabb_MsgRequestControllerList; -public: - MessageType_ControllerList() - : BotBaseMessageType( - "PABB_MSG_REQUEST_CONTROLLER_LIST", - PABB_MSG_REQUEST_CONTROLLER_LIST, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_controller_list : public BotBaseRequest{ -public: - pabb_MsgRequestControllerList params{}; - DeviceRequest_controller_list() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_CONTROLLER_LIST, params); - } -}; - - - -class MessageType_QueueSize : public BotBaseMessageType{ - using Params = pabb_MsgRequestQueueSize; - -public: - MessageType_QueueSize() - : BotBaseMessageType( - "PABB_MSG_REQUEST_QUEUE_SIZE", - PABB_MSG_REQUEST_QUEUE_SIZE, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_queue_size : public BotBaseRequest{ -public: - pabb_MsgRequestQueueSize params{}; - DeviceRequest_queue_size() - : BotBaseRequest(false) - {} - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_QUEUE_SIZE, params); - } -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_HID_Keyboard.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_HID_Keyboard.h deleted file mode 100644 index 4f75f14e1a..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_HID_Keyboard.h +++ /dev/null @@ -1,82 +0,0 @@ -/* SerialPABotBase Messages - StandardHid: HID Keyboard - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_StandardHid_MessageWrappers_HID_Keyboard_H -#define PokemonAutomation_StandardHid_MessageWrappers_HID_Keyboard_H - -#include "Common/SerialPABotBase/SerialPABotBase_Messages_HID_Keyboard.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace StandardHid{ - - - -class MessageType_HID_Keyboard_StateMs : public BotBaseMessageType{ - using Params = pabb_Message_Command_HID_Keyboard_State; -public: - MessageType_HID_Keyboard_StateMs() - : BotBaseMessageType( - "PABB_MSG_COMMAND_HID_KEYBOARD_STATE", - PABB_MSG_COMMAND_HID_KEYBOARD_STATE, - sizeof(Params) - ) - {} - virtual bool should_print(const std::string& body) const override{ - return LOG_EVERYTHING(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", ms = " + std::to_string(params.milliseconds); - - // Do not log the contents of the command due to privacy concerns. - // (people entering passwords) -#if 0 - ret += ", 0x" + tostr_hex((int)params.report.key[0]); - ret += ", 0x" + tostr_hex((int)params.report.key[1]); - ret += ", 0x" + tostr_hex((int)params.report.key[2]); - ret += ", 0x" + tostr_hex((int)params.report.key[3]); - ret += ", 0x" + tostr_hex((int)params.report.key[4]); - ret += ", 0x" + tostr_hex((int)params.report.key[5]); -#endif - return ret; - } -}; -class DeviceRequest_HID_Keyboard_StateMs : public BotBaseRequest{ -public: - pabb_Message_Command_HID_Keyboard_State params; - DeviceRequest_HID_Keyboard_StateMs( - uint16_t milliseconds, - const pabb_HID_Keyboard_State& report - ) - : BotBaseRequest(true) - { - memset(¶ms, 0, sizeof(params)); - - params.seqnum = 0; - params.milliseconds = milliseconds; - params.report = report; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_COMMAND_HID_KEYBOARD_STATE, params); - } -}; - - - - - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS1_OemControllers.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS1_OemControllers.h deleted file mode 100644 index 8a7e0d65a9..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS1_OemControllers.h +++ /dev/null @@ -1,307 +0,0 @@ -/* SerialPABotBase Messages - NintendoSwitch OEM Controllers - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_NintendoSwitch_OemControllers_H -#define PokemonAutomation_SerialPABotBase_MessageWrappers_NintendoSwitch_OemControllers_H - -#include "Common/SerialPABotBase/SerialPABotBase_Messages_NS1_OemControllers.h" -#include "Controllers/ControllerTypes.h" -#include "Controllers/SerialPABotBase/SerialPABotBase.h" -//#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - - - -class MessageType_NS1_PlayerLights : public BotBaseMessageType{ - using Params = pabb_MsgInfo_NS1_OemController_PlayerLights; -public: - MessageType_NS1_PlayerLights() - : BotBaseMessageType( - "PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_PLAYER_LIGHTS", - PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_PLAYER_LIGHTS, - sizeof(Params) - ) - {} - virtual bool should_print(const std::string& body) const override{ - return LOG_EVERYTHING(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - return ret; - } -}; -class DeviceRequest_PlayerLights : public BotBaseRequest{ -public: - pabb_MsgInfo_NS1_OemController_PlayerLights params; - DeviceRequest_PlayerLights(ControllerType controller_type) - : BotBaseRequest(false) - { - params.seqnum = 0; - params.controller_type = SerialPABotBase::controller_type_to_id(controller_type); - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_PLAYER_LIGHTS, params); - } -}; - - - -class MessageType_NS1_ReadSpi : public BotBaseMessageType{ - using Params = pabb_Message_NS1_OemController_ReadSpi; -public: - MessageType_NS1_ReadSpi() - : BotBaseMessageType( - "PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_READ_SPI", - PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_READ_SPI, - sizeof(Params) - ) - {} - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", controller = " + std::to_string(params.controller_type); - ret += ", address = 0x" + tostr_hex(params.address); - ret += ", bytes = " + std::to_string((size_t)params.bytes); - return ret; - } -}; -class DeviceRequest_NS1_ReadSpi : public BotBaseRequest{ -public: - pabb_Message_NS1_OemController_ReadSpi params; - DeviceRequest_NS1_ReadSpi(ControllerType controller_type, uint32_t address, uint8_t bytes) - : BotBaseRequest(false) - { - params.seqnum = 0; - params.controller_type = SerialPABotBase::controller_type_to_id(controller_type); - params.address = address; - params.bytes = bytes; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_READ_SPI, params); - } -}; - - - -class MessageType_NS1_WriteSpi : public BotBaseMessageType{ - using Params = pabb_Message_NS1_OemController_WriteSpi; -public: - MessageType_NS1_WriteSpi() - : BotBaseMessageType( - "PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_WRITE_SPI", - PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_WRITE_SPI, - 0 - ) - {} - virtual bool is_valid(const std::string& body) const override{ - return body.size() >= sizeof(Params); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", controller = " + std::to_string(params.controller_type); - ret += ", address = 0x" + tostr_hex(params.address); - ret += ", bytes = " + std::to_string((size_t)params.bytes); - return ret; - } -}; -class DeviceRequest_NS1_WriteSpi : public BotBaseRequest{ -public: - std::string data; - DeviceRequest_NS1_WriteSpi( - ControllerType controller_type, - uint32_t address, uint8_t bytes, - const void* p_data - ) - : BotBaseRequest(false) - { - pabb_Message_NS1_OemController_WriteSpi params; - params.seqnum = 0; - params.controller_type = SerialPABotBase::controller_type_to_id(controller_type); - params.address = address; - params.bytes = bytes; - data = std::string((char*)¶ms, sizeof(params)); - data += std::string((const char*)p_data, bytes); - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_WRITE_SPI, data); - } -}; - - - -class MessageType_NS1_OemControllerStateButtons : public BotBaseMessageType{ - using Params = pabb_Message_Command_NS1_OemController_Buttons; -public: - MessageType_NS1_OemControllerStateButtons() - : BotBaseMessageType( - "PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_BUTTONS", - PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_BUTTONS, - sizeof(Params) - ) - {} - virtual bool should_print(const std::string& body) const override{ - return LOG_EVERYTHING(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", ms = " + std::to_string(params.milliseconds); - return ret; - } -}; -class DeviceRequest_ControllerStateButtons : public BotBaseRequest{ -public: - pabb_Message_Command_NS1_OemController_Buttons params; - DeviceRequest_ControllerStateButtons( - uint16_t milliseconds, - const pabb_NintendoSwitch_OemController_State0x30_Buttons& state - ) - : BotBaseRequest(true) - { - params.seqnum = 0; - params.milliseconds = milliseconds; - params.buttons = state; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_BUTTONS, params); - } -}; - - - -class MessageType_NS1_OemControllerStateFull : public BotBaseMessageType{ - using Params = pabb_Message_Command_NS1_OemController_FullState; -public: - MessageType_NS1_OemControllerStateFull() - : BotBaseMessageType( - "PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_FULL_STATE", - PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_FULL_STATE, - sizeof(Params) - ) - {} - virtual bool should_print(const std::string& body) const override{ - return LOG_EVERYTHING(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", ms = " + std::to_string(params.milliseconds); - return ret; - } -}; -class DeviceRequest_ControllerStateFull : public BotBaseRequest{ -public: - pabb_Message_Command_NS1_OemController_FullState params; - DeviceRequest_ControllerStateFull( - uint16_t milliseconds, - const pabb_NintendoSwitch_OemController_State0x30_Buttons& buttons, - const pabb_NintendoSwitch_OemController_State0x30_GyroX3& gyro - ) - : BotBaseRequest(true) - { - params.seqnum = 0; - params.milliseconds = milliseconds; - params.state.buttons = buttons; - params.state.gyro = gyro; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_FULL_STATE, params); - } -}; - - - -class MessageType_NS1_OemControllerRumble : public BotBaseMessageType{ - using Params = pabb_MsgInfo_NS1_OemController_Rumble; -public: - MessageType_NS1_OemControllerRumble() - : BotBaseMessageType( - "PABB_MSG_INFO_NS1_OEM_CONTROLLER_RUMBLE", - PABB_MSG_INFO_NS1_OEM_CONTROLLER_RUMBLE, - sizeof(Params) - ) - {} - virtual bool should_print(const std::string& body) const override{ - if (!is_valid(body) || LOG_EVERYTHING()){ - return true; - } - - uint32_t left, right; - memcpy(&left, body.data(), sizeof(uint32_t)); - memcpy(&right, (uint32_t*)body.data() + 1, sizeof(uint32_t)); - - const uint32_t NEUTRAL = 0x40400100; - if (left != 0 && left != NEUTRAL){ - return true; - } - if (right != 0 && right != NEUTRAL){ - return true; - } - return false; - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - static const char HEX_DIGITS[] = "0123456789abcdef"; - for (size_t c = 0; c < body.size(); c++){ - uint8_t byte = body[c]; - ret += " "; - ret += HEX_DIGITS[(byte >> 4)]; - ret += HEX_DIGITS[byte & 15]; - } - return ret; - } -}; -class MessageType_NS1_OemControllerUsbDisallowed : public BotBaseMessageType{ -public: - MessageType_NS1_OemControllerUsbDisallowed() - : BotBaseMessageType( - "PABB_MSG_INFO_NS1_OEM_CONTROLLER_USB_DISALLOWED", - PABB_MSG_INFO_NS1_OEM_CONTROLLER_USB_DISALLOWED, - 0 - ) - {} -}; - - - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS_WiredController.h b/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS_WiredController.h deleted file mode 100644 index 774b2766d5..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS_WiredController.h +++ /dev/null @@ -1,95 +0,0 @@ -/* SerialPABotBase Messages - NintendoSwitch: Wired Controller - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_NintendoSwitch_WiredController_H -#define PokemonAutomation_SerialPABotBase_MessageWrappers_NintendoSwitch_WiredController_H - -#include "Common/SerialPABotBase/SerialPABotBase_Messages_NS_WiredController.h" -#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - - - -class MessageType_WiredController_ControllerStateMs : public BotBaseMessageType{ - using Params = pabb_Message_Command_NS_WiredController_State; -public: - MessageType_WiredController_ControllerStateMs() - : BotBaseMessageType( - "PABB_MSG_COMMAND_NS_WIRED_CONTROLLER_STATE", - PABB_MSG_COMMAND_NS_WIRED_CONTROLLER_STATE, - sizeof(Params) - ) - {} - virtual bool should_print(const std::string& body) const override{ - return LOG_EVERYTHING(); - } - virtual std::string tostr(const std::string& body) const override{ - std::string ret = BotBaseMessageType::tostr(body); - if (!is_valid(body)){ - return ret; - } - Params params; - memcpy(¶ms, body.data(), sizeof(params)); - ret += ": seqnum = " + std::to_string(params.seqnum); - ret += ", ms = " + std::to_string(params.milliseconds); - - // Do not log the contents of the command due to privacy concerns. - // (people entering passwords) -#if 0 - uint32_t buttons = params.report.buttons0; - buttons |= (uint32_t)params.report.buttons1 << 8; - if (params.report.dpad_byte & 0x80){ - buttons |= NintendoSwitch::BUTTON_C; - } - ret += ", buttons = " + std::to_string(buttons) + " (" + button_to_string((NintendoSwitch::Button)buttons) + ")"; - ret += ", dpad = " + dpad_to_string((NintendoSwitch::DpadPosition)(params.report.dpad_byte & 0x0f)); - - ret += ", LJ = (" + std::to_string((int)params.report.left_joystick_x) + "," + std::to_string((int)params.report.left_joystick_y) + ")"; - ret += ", RJ = (" + std::to_string((int)params.report.right_joystick_x) + "," + std::to_string((int)params.report.right_joystick_y) + ")"; -#endif - return ret; - } -}; -class DeviceRequest_WiredController_ControllerStateMs : public BotBaseRequest{ -public: - pabb_Message_Command_NS_WiredController_State params; - DeviceRequest_WiredController_ControllerStateMs( - uint16_t milliseconds, - uint16_t buttons, - uint8_t dpad_byte, - uint8_t left_joystick_x, - uint8_t left_joystick_y, - uint8_t right_joystick_x, - uint8_t right_joystick_y - ) - : BotBaseRequest(true) - { - memset(¶ms, 0, sizeof(params)); - - params.seqnum = 0; - params.milliseconds = milliseconds; - - params.report.buttons0 = (uint8_t)buttons; - params.report.buttons1 = (uint8_t)(buttons >> 8); - params.report.dpad_byte = dpad_byte; - params.report.left_joystick_x = left_joystick_x; - params.report.left_joystick_y = left_joystick_y; - params.report.right_joystick_x = right_joystick_x; - params.report.right_joystick_y = right_joystick_y; - } - virtual BotBaseMessage message() const override{ - return BotBaseMessage(PABB_MSG_COMMAND_NS_WIRED_CONTROLLER_STATE, params); - } -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp b/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp deleted file mode 100644 index a9a1174d73..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp +++ /dev/null @@ -1,367 +0,0 @@ -/* Serial Port (PABotBase) Connection - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include "Common/Cpp/PrettyPrint.h" -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/PanicDump.h" -#include "Common/Cpp/SerialConnection/SerialConnection.h" -#include "CommonFramework/Globals.h" -#include "CommonFramework/GlobalSettingsPanel.h" -#include "Common/Cpp/ColoredText.h" -#include "CommonFramework/Tools/GlobalThreadPools.h" -#include "Controllers/ControllerTypeStrings.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Errors.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Acks.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Info.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_StaticRequests.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_CommandQueue.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Misc.h" -#include "Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.h" -#include "SerialPABotBase.h" -#include "SerialPABotBase_Connection.h" - -//#include -//using std::cout; -//using std::endl; - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - - -SerialPABotBase_Connection::SerialPABotBase_Connection( - Logger& logger, - const std::string& name -) - : m_logger(logger, LOG_EVERYTHING()) -{ - set_status_line0("Not Connected", COLOR_RED); - - QSerialPortInfo info(QString::fromStdString(name)); - - // Port is invalid. - if (info.isNull()){ - logger.log("Serial port " + name + " is invalid. Maybe wrong port name?"); - return; - } - - // Prolific is banned - if (info.description().indexOf("Prolific") != -1){ - QMessageBox box; - box.critical( - nullptr, - "Error", - "Cannot select Prolific controller.

" - "Prolific controllers do not work for Arduino and similar microcontrollers.
" - "You were warned of this in the setup instructions. Please buy a CP210x controller instead." - ); - std::string text = "Cannot connect to Prolific controller."; - m_logger.log(text, COLOR_RED); - set_status_line0(text, COLOR_RED); - return; - } - - m_device_name = info.portName().toStdString(); - std::string error; - try{ - set_status_line0("Connecting...", COLOR_DARKGREEN); - std::unique_ptr connection( - new SerialConnection( - GlobalThreadPools::unlimited_normal(), - info.systemLocation().toStdString(), - PABB_BAUD_RATE - ) - ); - connection->set_control_state(true, false); - m_botbase.reset( - new PABotBase( - m_logger, - GlobalThreadPools::unlimited_normal(), - std::move(connection) - ) - ); - add_message_printers(); - }catch (const ConnectionException& e){ - error = e.message(); - }catch (const SerialProtocolException& e){ - error = e.message(); - }catch (const ProgramCancelledException& e){ - error = e.message(); - } - if (!error.empty()){ - set_status_line0("Unable to open port.", COLOR_RED); - return; - } - - m_status_thread = GlobalThreadPools::unlimited_normal().dispatch_now_blocking([=, this]{ - run_with_catch( - "SerialPABotBase_Connection::thread_body()", - [=, this]{ thread_body(); } - ); - }); -} -SerialPABotBase_Connection::~SerialPABotBase_Connection(){ - m_status.store(Status::NOT_CONNECTED, std::memory_order_release); -// signal_pre_not_ready(); - if (m_botbase == nullptr){ - return; - } - m_botbase->stop(); - { - std::lock_guard lg(m_lock); - m_cv.notify_all(); - } - m_status_thread.wait_and_ignore_exceptions(); - m_botbase.reset(); -} - - - -BotBaseController* SerialPABotBase_Connection::botbase(){ - BotBaseController* ret = m_botbase.get(); - if (ret == nullptr){ - m_logger.log("SerialPABotBase_Connection::botbase() called with null botbase...", COLOR_RED); - } - return ret; -} -ControllerType SerialPABotBase_Connection::refresh_controller_type(){ - m_logger.log("Reading Controller Mode..."); - uint32_t type_id = read_controller_mode(*botbase()); - ControllerType current_controller = id_to_controller_type(type_id); - m_logger.log( - "Reading Controller Mode... Mode = " + - CONTROLLER_TYPE_STRINGS.get_string(current_controller) - ); - m_current_controller.store(current_controller, std::memory_order_release); - return current_controller; -} - -bool SerialPABotBase_Connection::cancel(std::exception_ptr reason) noexcept{ - if (ControllerConnection::cancel(std::move(reason))){ - return true; - } - if (m_botbase){ - m_botbase->on_cancellable_cancel(*this, cancel_reason()); - } - return false; -} - -void SerialPABotBase_Connection::add_message_printers(){ - // Errors - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - - // Framework Acks - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - - // Custom Info - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - - // Static Requests - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); - - // Mode Requests - add_message_printer(); - add_message_printer(); - add_message_printer(); - - // Command Queue Requests - add_message_printer(); - add_message_printer(); - add_message_printer(); - - // Other Requests - add_message_printer(); - add_message_printer(); - add_message_printer(); - add_message_printer(); -} -void SerialPABotBase_Connection::process_queue_size(){ - m_logger.log("Requesting queue size..."); - uint8_t queue_size = device_queue_size(*m_botbase); - m_logger.Logger::log("Requesting queue size... Queue Size = " + std::to_string(queue_size)); - - // For now we don't need to use that much queue size. - queue_size = std::min(queue_size, 32); - - m_logger.Logger::log("Setting queue size to: " + std::to_string(queue_size)); - m_botbase->set_queue_limit(queue_size); -} - -void SerialPABotBase_Connection::throw_incompatible_protocol(){ - throw SerialProtocolException( - m_logger, PA_CURRENT_FUNCTION, - "Incompatible protocol. Device: " + std::to_string(m_protocol) + "
" - "Please flash your microcontroller (e.g. ESP32, Pico W, Arduino)
" - "with the .bin/.uf2/.hex that came with this version of the program.
" + - make_text_url(ONLINE_DOC_URL_BASE + "SetupGuide/Reflash.html", "See documentation for more details.") - ); -} -ControllerType SerialPABotBase_Connection::process_device(){ - // Protocol Version - const std::map* PROGRAMS; - { - m_logger.Logger::log("Checking Protocol Version..."); - m_protocol = SerialPABotBase::protocol_version(*m_botbase); - m_logger.Logger::log("Checking Protocol Version... (" + std::to_string(m_protocol) + ")"); - auto iter = SUPPORTED_VERSIONS().find(m_protocol / 100); - if (iter == SUPPORTED_VERSIONS().end()){ - throw_incompatible_protocol(); - } - PROGRAMS = &iter->second; - } - - // Program ID - { - m_logger.Logger::log("Checking Program ID..."); - m_program_id = program_id(*m_botbase); - m_logger.Logger::log("Checking Program ID... (0x" + tostr_hex(m_program_id) + ")"); - auto iter = PROGRAMS->find(m_program_id); - if (iter == PROGRAMS->end()){ - m_logger.Logger::log( - "Unrecognized Program ID: (0x" + tostr_hex(m_program_id) + ") for this protocol version. " - "Compatibility is not guaranteed.", - COLOR_RED - ); - iter = PROGRAMS->find(PABB_PID_UNSPECIFIED); - if (iter == PROGRAMS->end()){ - throw_incompatible_protocol(); - } - } - if (m_protocol % 100 < iter->second){ - throw_incompatible_protocol(); - } - } - - // Firmware Version - { - m_logger.Logger::log("Checking Firmware Version..."); - m_version = program_version(*m_botbase); - m_logger.Logger::log("Checking Firmware Version... (" + std::to_string(m_version) + ")"); - } - - // Program Name - { - m_logger.Logger::log("Checking Program Name..."); - m_program_name = program_name(*m_botbase); - m_logger.Logger::log("Checking Program Name... (" + m_program_name + ")"); - } - - // Controller List - { - m_logger.Logger::log("Checking Controller List..."); - std::string str; - bool first = true; - for (pabb_ControllerID id : SerialPABotBase::controller_list(*m_botbase)){ - if (!first){ - str += ", "; - } - first = false; - str += "0x" + tostr_hex(id); - if (controller_is_valid(id)){ - m_controller_list.emplace_back(id_to_controller_type(id)); - } - } - m_logger.Logger::log("Checking Controller List... (" + str + ")"); - } - - // Queue Size - process_queue_size(); - - // Current Controller - ControllerType current_controller = refresh_controller_type(); - - return current_controller; -} - - - -void SerialPABotBase_Connection::thread_body(){ - using namespace PokemonAutomation; - - // Connect - { - std::string error; - try{ - m_botbase->connect(); - }catch (InvalidConnectionStateException&){ - m_botbase->stop(); - set_status_line0(""); - return; - }catch (SerialProtocolException& e){ - error = e.message(); - }catch (ConnectionException& e){ - error = e.message(); - } - if (!error.empty()){ - m_botbase->stop(); - set_status_line0(error, COLOR_RED); - return; - } - } - - // Check protocol and version. - - { - std::string error; - try{ - process_device(); - - // Stop pending commands. - m_botbase->stop_all_commands(); - - std::string text = m_program_name + " (" + std::to_string(m_version) + ")"; - set_status_line0(text, theme_friendly_darkblue()); - declare_ready(); - }catch (InvalidConnectionStateException&){ - return; - }catch (SerialProtocolException& e){ - error = e.message(); - }catch (ConnectionException& e){ - error = e.message(); - } - if (!error.empty()){ -// m_ready.store(false, std::memory_order_relaxed); - set_status_line0(error, COLOR_RED); -// signal_pre_not_ready(); - m_botbase->stop(); - return; - } - } -} - - - -} -} diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h b/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h deleted file mode 100644 index 1749c3cc0f..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h +++ /dev/null @@ -1,85 +0,0 @@ -/* Serial Port (PABotBase) Connection - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_Controllers_SerialPABotBase_Connection_H -#define PokemonAutomation_Controllers_SerialPABotBase_Connection_H - -#include -//#include -#include "Common/Cpp/Concurrency/Mutex.h" -#include "Common/Cpp/Concurrency/ConditionVariable.h" -#include "Common/Cpp/Concurrency/AsyncTask.h" -#include "Controllers/SerialPABotBase/Connection/BotBase.h" -#include "Controllers/SerialPABotBase/Connection/PABotBase.h" -#include "Controllers/SerialPABotBase/Connection/MessageLogger.h" -#include "Controllers/ControllerConnection.h" - -namespace PokemonAutomation{ - class PABotBase; - class BotBaseMessageType; -namespace SerialPABotBase{ - - -class SerialPABotBase_Connection final : public ControllerConnection{ -public: - SerialPABotBase_Connection( - Logger& logger, - const std::string& name - ); - ~SerialPABotBase_Connection(); - - template - void add_message_printer(){ - m_botbase->add_message_printer(BotBaseMessageType::instance()); - } - - -public: - const std::string& device_name() const{ - return m_device_name; - } - uint32_t protocol_version() const{ - return m_protocol; - } - - BotBaseController* botbase(); - - ControllerType refresh_controller_type(); - - virtual bool cancel(std::exception_ptr exception = nullptr) noexcept override; - - -private: - void add_message_printers(); - - void process_queue_size(); - void throw_incompatible_protocol(); - ControllerType process_device(); - - void thread_body(); - - -private: - SerialLogger m_logger; - std::string m_device_name; - - uint32_t m_protocol = 0; - uint32_t m_version = 0; - uint8_t m_program_id = 0; - std::string m_program_name; - - AsyncTask m_status_thread; - std::unique_ptr m_botbase; - mutable Mutex m_lock; - Mutex m_sleep_lock; - ConditionVariable m_cv; -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp b/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp deleted file mode 100644 index 01092d1632..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* Serial Port (PABotBase) Interface - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Common/Cpp/Json/JsonValue.h" -#include "Controllers/ControllerTypeStrings.h" -#include "SerialPABotBase_Descriptor.h" - -#include "NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.h" - -//#include -//using std::cout; -//using std::endl; - -namespace PokemonAutomation{ - -template class InterfaceType_t; - -namespace SerialPABotBase{ - - - - -bool SerialPABotBase_Descriptor::operator==(const ControllerDescriptor& x) const{ - if (typeid(*this) != typeid(x)){ - return false; - } - return m_name == static_cast(x).m_name; -} - - -std::string SerialPABotBase_Descriptor::display_name() const{ - if (m_name.empty()){ - return "(none)"; - } - return m_name; -} -void SerialPABotBase_Descriptor::load_json(const JsonValue& json){ - const std::string* name = json.to_string(); - if (name == nullptr || name->empty()){ - return; - } - m_name = *name; -} -JsonValue SerialPABotBase_Descriptor::to_json() const{ - return m_name; -} - -std::unique_ptr SerialPABotBase_Descriptor::open_connection(Logger& logger) const{ - if (m_name.empty()){ - return nullptr; - } - return std::unique_ptr( - new SerialPABotBase_Connection(logger, m_name) - ); -} -std::unique_ptr SerialPABotBase_Descriptor::make_controller( - Logger& logger, - ControllerConnection& connection, - ControllerType controller_type -) const{ - switch (controller_type){ - case ControllerType::NintendoSwitch_WiredController: - case ControllerType::NintendoSwitch2_WiredController: - return std::unique_ptr( - new PokemonAutomation::NintendoSwitch::SerialPABotBase_WiredController( - logger, - static_cast(connection), - controller_type - ) - ); - - default:; - } - - logger.log( - std::string("Unsupported Controller Type: ") + CONTROLLER_TYPE_STRINGS.get_string(controller_type), - COLOR_RED - ); - return nullptr; -} - - - - - - -} -} diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h b/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h deleted file mode 100644 index 9e4539da8d..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h +++ /dev/null @@ -1,56 +0,0 @@ -/* Serial Port (PABotBase) Interface - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_Controllers_SerialPABotBase_Descriptor_H -#define PokemonAutomation_Controllers_SerialPABotBase_Descriptor_H - -#include "Controllers/ControllerDescriptor.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - -class SerialPABotBase_Descriptor : public UiState{ -public: - static constexpr ControllerInterface INTERFACE_NAME = ControllerInterface::SerialPABotBase; - - -public: - SerialPABotBase_Descriptor() - : UiState(INTERFACE_NAME) - {} - SerialPABotBase_Descriptor(std::string name) - : UiState(INTERFACE_NAME) - , m_name(std::move(name)) - {} - - const std::string& name() const{ - return m_name; - } - - virtual bool operator==(const ControllerDescriptor& x) const override; - virtual std::string display_name() const override; - - virtual void load_json(const JsonValue& json) override; - virtual JsonValue to_json() const override; - - virtual std::unique_ptr open_connection(Logger& logger) const override; - virtual std::unique_ptr make_controller( - Logger& logger, - ControllerConnection& connection, - ControllerType controller_type - ) const override; - -private: - std::string m_name; -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.cpp b/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.cpp deleted file mode 100644 index bc7d8cff94..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* SerialPABotBase Routines (Protocol) - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Messages/SerialPABotBase_MessageWrappers_BaseProtocol_StaticRequests.h" -#include "Messages/SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode.h" -#include "SerialPABotBase_Routines_Protocol.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - -uint32_t protocol_version(BotBaseController& botbase){ - pabb_MsgAckRequestI32 response; - botbase.issue_request_and_wait( - DeviceRequest_protocol_version() - ).convert(botbase.logger(), response); - return response.data; -} -uint32_t program_version(BotBaseController& botbase){ - pabb_MsgAckRequestI32 response; - botbase.issue_request_and_wait( - DeviceRequest_program_version() - ).convert(botbase.logger(), response); - return response.data; -} -uint8_t program_id(BotBaseController& botbase){ - pabb_MsgAckRequestI8 response; - botbase.issue_request_and_wait( - DeviceRequest_program_id() - ).convert(botbase.logger(), response); - return response.data; -} -std::string program_name(BotBaseController& botbase){ - BotBaseMessage response = botbase.issue_request_and_wait( - DeviceRequest_program_name(), - nullptr - ); - return response.body.substr(sizeof(seqnum_t)); -} -std::vector controller_list(BotBaseController& botbase){ - BotBaseMessage response = botbase.issue_request_and_wait( - DeviceRequest_controller_list(), - nullptr - ); - size_t bytes = response.body.size() - sizeof(seqnum_t); - if (bytes % sizeof(uint32_t) != 0){ - throw SerialProtocolException( - botbase.logger(), PA_CURRENT_FUNCTION, - "Device sent back invalid reponse length: " + std::to_string(response.body.size()) - ); - } - std::vector ret(bytes / sizeof(uint32_t)); - memcpy(ret.data(), response.body.data() + sizeof(seqnum_t), bytes); - return ret; -} -uint8_t device_queue_size(BotBaseController& botbase){ - pabb_MsgAckRequestI8 response; - botbase.issue_request_and_wait( - DeviceRequest_queue_size() - ).convert(botbase.logger(), response); - return response.data; - -} -uint32_t read_controller_mode(BotBaseController& botbase){ - pabb_MsgAckRequestI32 response; - botbase.issue_request_and_wait( - DeviceRequest_read_controller_mode() - ).convert(botbase.logger(), response); - return response.data; -} -uint32_t change_controller_mode(BotBaseController& botbase, uint32_t mode){ - pabb_MsgAckRequestI32 response; - botbase.issue_request_and_wait( - DeviceRequest_change_controller_mode(mode) - ).convert(botbase.logger(), response); - return response.data; -} - - -} -} diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.h b/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.h deleted file mode 100644 index 79d67e565a..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.h +++ /dev/null @@ -1,30 +0,0 @@ -/* SerialPABotBase Routines (Protocol) - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_Routines_Protocol_H -#define PokemonAutomation_SerialPABotBase_Routines_Protocol_H - -#include -#include "Common/SerialPABotBase/SerialPABotBase_Protocol_IDs.h" -#include "Controllers/SerialPABotBase/Connection/BotBase.h" - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - -uint32_t protocol_version(BotBaseController& botbase); -uint32_t program_version(BotBaseController& botbase); -uint8_t program_id(BotBaseController& botbase); -std::string program_name(BotBaseController& botbase); -std::vector controller_list(BotBaseController& botbase); -uint8_t device_queue_size(BotBaseController& botbase); -uint32_t read_controller_mode(BotBaseController& botbase); -uint32_t change_controller_mode(BotBaseController& botbase, uint32_t mode); - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.cpp b/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.cpp deleted file mode 100644 index 1ea969b505..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* SerialPABotBase Selector Widget - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Controllers/SerialPortPollerQt.h" -#include "SerialPABotBase_Descriptor.h" -#include "SerialPABotBase_SelectorWidget.h" - -namespace PokemonAutomation{ - -template class RegisterUiStateQtWidget; - -namespace SerialPABotBase{ - - - -bool filter_serial_port(const QSerialPortInfo& port){ -#ifdef _WIN32 - // COM1 is never the correct port on Windows. - if (port.portName() == "COM1"){ - return false; - } -#endif - -#if defined(__APPLE__) - // exlude tty - if (port.portName().startsWith("tty.")){ - return false; - } - // exclude system builtin serial ports - if (port.portName() == "cu.debug-console" || - port.portName() == "cu.Bluetooth-Incoming-Port" - ){ - return false; - } -#endif - -#if defined(__linux__) - const QString path = port.systemLocation(); - - QFileInfo file(path); - // Exclude devices that don't have Read/Write access - if (!(file.isReadable() && file.isWritable())) - { - return false; - } -#endif - - return true; -} - - - - - -SerialPABotBase_SelectorWidget::SerialPABotBase_SelectorWidget( - ControllerSelectorWidget& parent, - const ControllerDescriptor* current -) - : NoWheelCompactComboBox(&parent) - , m_parent(parent) -{ -// cout << "SerialPABotBase(): " << current << endl; - this->setMaxVisibleItems(32); - - if (current == nullptr || ( - current->interface_type != ControllerInterface::None && - current->interface_type != ControllerInterface::SerialPABotBase - ) - ){ - std::shared_ptr descriptor = - parent.session().option().get_descriptor_from_cache(ControllerInterface::SerialPABotBase); - if (!descriptor){ - descriptor.reset(new SerialPABotBase_Descriptor()); - } - parent.session().set_device(descriptor); - } - - refresh_devices(); - - connect( - this, static_cast(&QComboBox::activated), - &parent, [this, &parent](int index){ - if (index < 0){ - return; - } - index = std::min(index, (int)m_ports.size() - 1); - std::shared_ptr& selected = m_ports[index]; - - std::shared_ptr current = parent.session().descriptor(); - if (*current == *selected){ - return; - } - - parent.session().set_device(selected); - refresh_devices(); - } - ); -} - - -void SerialPABotBase_SelectorWidget::refresh_devices(){ -// cout << "Current = " << width() << " x " << height() << endl; -// cout << "sizeHint = " << sizeHint().width() << " x " << sizeHint().height() << endl; -// cout << "minimumContentsLength = " << this->minimumContentsLength() << endl; - - m_ports.clear(); - this->clear(); - -// cout << "SerialPABotBase_SelectorWidget::refresh_devices()" << endl; - - - m_ports.emplace_back(new SerialPABotBase_Descriptor()); - for (QSerialPortInfo& port : SerialPortPoller::instance().ports()){ - if (filter_serial_port(port)){ - m_ports.emplace_back( - new SerialPABotBase_Descriptor(port.portName().toStdString()) - ); - } - } - -// size_t width = 6; - int index = 0; - int c = 0; - for (const auto& port : m_ports){ - QString display_name = QString::fromStdString(port->display_name()); -// width = std::max(width, display_name.size()); - this->addItem(display_name); - if (*m_parent.session().descriptor() == *m_ports[c]){ - index = c; - } - c++; - } - - if (this->count() > this->maxVisibleItems()){ -// width++; - } -// setMinimumContentsLength((int)width); - setCurrentIndex(index); -} - - - - - -} -} diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.h b/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.h deleted file mode 100644 index 9d67fb1b2a..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.h +++ /dev/null @@ -1,68 +0,0 @@ -/* SerialPABotBase Selector Widget - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_Controllers_SerialPABotBase_SelectorWidget_H -#define PokemonAutomation_Controllers_SerialPABotBase_SelectorWidget_H - -#include -#include -#include "Common/Qt/UiStateQtWidget.h" -#include "Common/Qt/NoWheelComboBox.h" -#include "Controllers/ControllerDescriptor.h" -#include "Controllers/ControllerSelectorWidget.h" -#include "SerialPABotBase_Descriptor.h" - -//#include -//using std::cout; -//using std::endl; - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - -bool filter_serial_port(const QSerialPortInfo& port); - - - - -class SerialPABotBase_SelectorWidget - : public NoWheelCompactComboBox - , public UiComponentQtWidget -{ -public: - using ParentState = const SerialPABotBase_Descriptor; - - SerialPABotBase_SelectorWidget( - QWidget& parent, - const ParentState& current - ) - : SerialPABotBase_SelectorWidget(static_cast(parent), ¤t) - {} - SerialPABotBase_SelectorWidget( - ControllerSelectorWidget& parent, - const ControllerDescriptor* current - ); - - void refresh_devices(); - - virtual QWidget& widget() override{ - return *this; - } - - -private: - ControllerSelectorWidget& m_parent; - std::vector> m_ports; -}; - - - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_StatusThread.h b/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_StatusThread.h deleted file mode 100644 index 305af009fa..0000000000 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_StatusThread.h +++ /dev/null @@ -1,177 +0,0 @@ -/* SerialPABotBase: Status Thread Helper - * - * From: https://github.com/PokemonAutomation/ - * - * This is a helper class to reuse the code for the status updater thread. - * - */ - -#ifndef PokemonAutomation_SerialPABotBase_StatusThread_H -#define PokemonAutomation_SerialPABotBase_StatusThread_H - -#include "Common/Cpp/PrettyPrint.h" -#include "Common/Cpp/Concurrency/Mutex.h" -#include "Common/Cpp/Concurrency/ConditionVariable.h" -#include "CommonFramework/Tools/GlobalThreadPools.h" -#include "SerialPABotBase_Connection.h" - -//#include -//using std::cout; -//using std::endl; - -namespace PokemonAutomation{ -namespace SerialPABotBase{ - - - - -struct ControllerStatusThreadCallback{ - virtual void update_status(Cancellable& cancellable) = 0; - virtual void stop_with_error(std::string message) = 0; -}; - - - - -class ControllerStatusThread{ -public: - ControllerStatusThread( - SerialPABotBase_Connection& connection, - ControllerStatusThreadCallback& callback - ) - : m_connection(connection) - , m_callback(callback) - , m_stopping(false) - , m_error(false) - , m_status_thread( - GlobalThreadPools::unlimited_normal().dispatch_now_blocking( - [this]{ status_thread(); } - ) - ) - {} - ~ControllerStatusThread(){ - if (m_stopping.exchange(true)){ - return; - } - m_scope.cancel(nullptr); - { - std::unique_lock lg(m_sleep_lock); - BotBaseController* botbase = m_connection.botbase(); - if (botbase){ - botbase->on_cancellable_cancel(); - } - m_cv.notify_all(); - } - m_status_thread.wait_and_ignore_exceptions(); - } - -private: - void status_thread(){ - constexpr std::chrono::milliseconds PERIOD(1000); - std::atomic last_ack(current_time()); - - AsyncTask watchdog = GlobalThreadPools::unlimited_normal().dispatch_now_blocking( - [&, this]{ - WallClock next_ping = current_time(); - while (true){ - if (m_stopping.load(std::memory_order_relaxed) || - m_error.load(std::memory_order_acquire) || - !m_connection.is_ready() - ){ - break; - } - - auto last = current_time() - last_ack.load(std::memory_order_relaxed); - std::chrono::duration seconds = last; - if (last > 2 * PERIOD){ - std::string text = "Last Ack: " + tostr_fixed(seconds.count(), 3) + " seconds ago"; - m_connection.set_status_line1(text, COLOR_RED); - // m_logger.log("Connection issue detected. Turning on all logging..."); - // settings.log_everything.store(true, std::memory_order_release); - } - - std::unique_lock lg(m_sleep_lock); - if (m_stopping.load(std::memory_order_relaxed) || - m_error.load(std::memory_order_acquire) || - !m_connection.is_ready() - ){ - break; - } - - WallClock now = current_time(); - next_ping += PERIOD; - if (now + PERIOD < next_ping){ - next_ping = now + PERIOD; - } - m_cv.wait_until(lg, next_ping); - } - } - ); - - - WallClock next_ping = current_time(); - while (true){ - if (m_stopping.load(std::memory_order_relaxed) || !m_connection.is_ready()){ - break; - } - - std::string error; - try{ - m_callback.update_status(m_scope); - last_ack.store(current_time(), std::memory_order_relaxed); - }catch (OperationCancelledException&){ - break; - }catch (InvalidConnectionStateException& e){ - error = e.message(); - }catch (SerialProtocolException& e){ - error = e.message(); - }catch (ConnectionException& e){ - error = e.message(); - }catch (...){ - error = "Unknown error."; - } - if (!error.empty()){ - m_error.store(true, std::memory_order_release); - m_connection.set_status_line1(error, COLOR_RED); - m_callback.stop_with_error(std::move(error)); - } - - std::unique_lock lg(m_sleep_lock); - if (m_stopping.load(std::memory_order_relaxed) || !m_connection.is_ready()){ - break; - } - - WallClock now = current_time(); - next_ping += PERIOD; - if (now + PERIOD < next_ping){ - next_ping = now + PERIOD; - } - m_cv.wait_until(lg, next_ping); - } - - { - std::unique_lock lg(m_sleep_lock); - } - m_cv.notify_all(); - watchdog.wait_and_ignore_exceptions(); - } - -private: - SerialPABotBase::SerialPABotBase_Connection& m_connection; - ControllerStatusThreadCallback& m_callback; - CancellableHolder m_scope; - std::atomic m_stopping; - std::atomic m_error; - Mutex m_sleep_lock; - ConditionVariable m_cv; - AsyncTask m_status_thread; -}; - - - - - - -} -} -#endif diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/MessageLogger.cpp b/SerialPrograms/Source/Controllers/SerialPort/SerialLogger.cpp similarity index 91% rename from SerialPrograms/Source/Controllers/SerialPABotBase/Connection/MessageLogger.cpp rename to SerialPrograms/Source/Controllers/SerialPort/SerialLogger.cpp index 543cdebd31..07ef703d29 100644 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/MessageLogger.cpp +++ b/SerialPrograms/Source/Controllers/SerialPort/SerialLogger.cpp @@ -1,11 +1,11 @@ -/* Message Logger +/* Serial Logger * * From: https://github.com/PokemonAutomation/ * */ #include "Common/Cpp/PrettyPrint.h" -#include "MessageLogger.h" +#include "SerialLogger.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/MessageLogger.h b/SerialPrograms/Source/Controllers/SerialPort/SerialLogger.h similarity index 83% rename from SerialPrograms/Source/Controllers/SerialPABotBase/Connection/MessageLogger.h rename to SerialPrograms/Source/Controllers/SerialPort/SerialLogger.h index f04b389187..bd8b76d928 100644 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/Connection/MessageLogger.h +++ b/SerialPrograms/Source/Controllers/SerialPort/SerialLogger.h @@ -1,11 +1,11 @@ -/* Message Logger +/* Serial Logger * * From: https://github.com/PokemonAutomation/ * */ -#ifndef PokemonAutomation_MessageLogger_H -#define PokemonAutomation_MessageLogger_H +#ifndef PokemonAutomation_SerialLogger_H +#define PokemonAutomation_SerialLogger_H #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/Time.h" diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp b/SerialPrograms/Source/Controllers/SerialPort/SerialPABotBase.cpp similarity index 83% rename from SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp rename to SerialPrograms/Source/Controllers/SerialPort/SerialPABotBase.cpp index e848edc10c..62c1aa045d 100644 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp +++ b/SerialPrograms/Source/Controllers/SerialPort/SerialPABotBase.cpp @@ -13,35 +13,6 @@ namespace PokemonAutomation{ namespace SerialPABotBase{ -// -// PABotBase 1 -// - -const std::map& SUPPORTED_DEVICES(){ - static const std::map database{ - {PABB_PID_UNSPECIFIED, 2025120815}, - {PABB_PID_PABOTBASE_ArduinoUnoR3, 2025090303}, - {PABB_PID_PABOTBASE_ArduinoLeonardo, 2025090303}, - {PABB_PID_PABOTBASE_ProMicro, 2025090303}, - {PABB_PID_PABOTBASE_Teensy2, 2025090303}, - {PABB_PID_PABOTBASE_TeensyPP2, 2025090303}, - }; - return database; -} - -std::map> make_SUPPORTED_VERSIONS(){ - std::map> ret; - for (const auto& item : SUPPORTED_DEVICES()){ - ret[item.second / 100][item.first] = (uint8_t)(item.second % 100); - } - return ret; -} -const std::map>& SUPPORTED_VERSIONS(){ - static const std::map> database = make_SUPPORTED_VERSIONS(); - return database; -} - - // // PABotBase 2 diff --git a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.h b/SerialPrograms/Source/Controllers/SerialPort/SerialPABotBase.h similarity index 70% rename from SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.h rename to SerialPrograms/Source/Controllers/SerialPort/SerialPABotBase.h index 8e1cf8c9bb..1e0c39ab10 100644 --- a/SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.h +++ b/SerialPrograms/Source/Controllers/SerialPort/SerialPABotBase.h @@ -17,19 +17,6 @@ namespace SerialPABotBase{ -// -// PABotBase 1 -// -const std::map& SUPPORTED_DEVICES(); -const std::map< - uint32_t, // Major protocol version. (version # / 100) - std::map< - pabb_ProgramID, - uint8_t // Minimum minor protocol version (version # % 100) - > ->& SUPPORTED_VERSIONS(); - - // // PABotBase 2 // diff --git a/SerialPrograms/Source/Controllers/SerialPortPollerQt.cpp b/SerialPrograms/Source/Controllers/SerialPort/SerialPortPollerQt.cpp similarity index 100% rename from SerialPrograms/Source/Controllers/SerialPortPollerQt.cpp rename to SerialPrograms/Source/Controllers/SerialPort/SerialPortPollerQt.cpp diff --git a/SerialPrograms/Source/Controllers/SerialPortPollerQt.h b/SerialPrograms/Source/Controllers/SerialPort/SerialPortPollerQt.h similarity index 100% rename from SerialPrograms/Source/Controllers/SerialPortPollerQt.h rename to SerialPrograms/Source/Controllers/SerialPort/SerialPortPollerQt.h diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp index 7f1e99c781..4a5eee0e91 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_OemController.cpp @@ -6,7 +6,7 @@ #include "Common/PABotBase2/Controllers/PABotBase2_Controller_NS1_OemController.h" #include "Common/Cpp/ColoredText.h" -#include "Controllers/SerialPABotBase/SerialPABotBase.h" +#include "Controllers/SerialPort/SerialPABotBase.h" #include "NintendoSwitch/NintendoSwitch_Settings.h" #include "NintendoSwitch_PABotBase2_OemController.h" diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.cpp b/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.cpp deleted file mode 100644 index bdb27b2646..0000000000 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* SerialPABotBase: Controller - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Common/Cpp/Exceptions.h" -#include "Controllers/ControllerTypeStrings.h" -#include "NintendoSwitch_SerialPABotBase_Controller.h" - -//#include -//using std::cout; -//using std::endl; - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - -using namespace std::chrono_literals; - - - - -SerialPABotBase_Controller::SerialPABotBase_Controller( - Logger& logger, - RecursiveThrottler& logging_throttler, - ControllerType controller_type, - SerialPABotBase::SerialPABotBase_Connection& connection -) - : ControllerWithScheduler(logger, logging_throttler) - , m_handle(connection) - , m_serial(connection.botbase()) -{ - if (!connection.is_ready()){ - return; - } - - // Check compatibility. - - logger.log( - "SerialPABotBase_Controller(): ControllerType = " + - CONTROLLER_TYPE_STRINGS.get_string(connection.current_controller()) - ); -} - - -void SerialPABotBase_Controller::stop_with_error(std::string error_message) noexcept{ - try{ - WriteSpinLock lg(m_error_lock); - m_error_string = error_message; - }catch (...){} - m_serial->stop(std::move(error_message)); -} - -bool SerialPABotBase_Controller::is_ready() const{ - return m_serial - && m_serial->state() == BotBaseController::State::RUNNING - && m_handle.is_ready(); -} -std::string SerialPABotBase_Controller::error_string() const{ - ReadSpinLock lg(m_error_lock); - return m_error_string; -} - -void SerialPABotBase_Controller::cancel_all_commands(){ - std::lock_guard lg(m_state_lock); - if (!is_ready()){ - throw InvalidConnectionStateException(error_string()); - } - m_serial->stop_all_commands(); - m_scheduler.clear_on_next(); - m_logger.log("cancel_all_commands()", COLOR_DARKGREEN); -} -void SerialPABotBase_Controller::replace_on_next_command(){ - std::lock_guard lg(m_state_lock); - if (!is_ready()){ - throw InvalidConnectionStateException(error_string()); - } - m_serial->next_command_interrupt(); - m_scheduler.clear_on_next(); - m_logger.log("replace_on_next_command()", COLOR_DARKGREEN); -} - - -void SerialPABotBase_Controller::wait_for_all(Cancellable* cancellable){ - SuperscalarScheduler::Schedule schedule; - std::lock_guard lg0(m_issue_lock); - { - std::lock_guard lg1(m_state_lock); - - ThrottleScope scope(m_logging_throttler); - if (scope){ - m_logger.log("wait_for_all()", COLOR_DARKGREEN); - } - - if (!is_ready()){ - throw InvalidConnectionStateException(error_string()); - } - - m_scheduler.issue_wait_for_all(schedule); - } - execute_schedule(cancellable, schedule); - m_serial->wait_for_all_requests(cancellable); -} - - - - - - - - - - - - - -} -} diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.h b/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.h deleted file mode 100644 index f2a5f2aa16..0000000000 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.h +++ /dev/null @@ -1,59 +0,0 @@ -/* SerialPABotBase: Controller - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_NintendoSwitch_SerialPABotBase_Controller_H -#define PokemonAutomation_NintendoSwitch_SerialPABotBase_Controller_H - -#include "Controllers/SerialPABotBase/Connection/BotBase.h" -#include "Controllers/SerialPABotBase/SerialPABotBase_Connection.h" -#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - - -class SerialPABotBase_Controller : public ControllerWithScheduler{ -public: - SerialPABotBase_Controller( - Logger& logger, - RecursiveThrottler& logging_throttler, - ControllerType controller_type, - SerialPABotBase::SerialPABotBase_Connection& connection - ); - - uint32_t protocol_version() const{ - return m_handle.protocol_version(); - } - - void stop_with_error(std::string error_message) noexcept; - - bool is_ready() const; - std::string error_string() const; - - -public: - void cancel_all_commands(); - void replace_on_next_command(); - - void wait_for_all(Cancellable* cancellable); - - -protected: - // These are set on construction and never changed again. So it is safe to - // access these asynchronously. - SerialPABotBase::SerialPABotBase_Connection& m_handle; - BotBaseController* m_serial; - - mutable SpinLock m_error_lock; - std::string m_error_string; -}; - - - - -} -} -#endif diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.cpp b/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.cpp deleted file mode 100644 index 344d80bc26..0000000000 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* SerialPABotBase: Wired Controller (Switch 1) - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/ColoredText.h" -#include "Controllers/JoystickTools.h" -#include "Controllers/SerialPABotBase/SerialPABotBase.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Misc.h" -#include "Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS_WiredController.h" -#include "NintendoSwitch_SerialPABotBase_WiredController.h" - -//#include -//using std::cout; -//using std::endl; - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - -using namespace std::chrono_literals; - - - - -SerialPABotBase_WiredController::SerialPABotBase_WiredController( - Logger& logger, - SerialPABotBase::SerialPABotBase_Connection& connection, - ControllerType controller_type -) - : ProController(logger) - , SerialPABotBase_Controller( - logger, - logging_throttler(), - controller_type, - connection - ) -{ - using namespace SerialPABotBase; - - - // Add controller-specific messages. - connection.add_message_printer(); - - m_status_thread.reset(new ControllerStatusThread( - connection, *this - )); -} -SerialPABotBase_WiredController::~SerialPABotBase_WiredController(){ - stop(); -} -void SerialPABotBase_WiredController::stop(){ - m_status_thread.reset(); -} - - - - -void SerialPABotBase_WiredController::execute_state( - Cancellable* cancellable, - const SuperscalarScheduler::ScheduleEntry& entry -){ - if (!is_ready()){ - throw InvalidConnectionStateException(error_string()); - } - - SwitchControllerState controller_state; - for (auto& item : entry.state){ - static_cast(*item).apply(controller_state); - } - - int dpad_x = 0; - int dpad_y = 0; - uint16_t buttons = 0; - uint8_t dpad_byte = 0; - - buttons = (uint16_t)controller_state.buttons; - if (controller_state.buttons & Button::BUTTON_UP) dpad_y--; - if (controller_state.buttons & Button::BUTTON_RIGHT) dpad_x++; - if (controller_state.buttons & Button::BUTTON_DOWN) dpad_y++; - if (controller_state.buttons & Button::BUTTON_LEFT) dpad_x--; - if (controller_state.buttons & Button::BUTTON_C) dpad_byte |= 0x80; - - // Merge the dpad states. - DpadPosition dpad = controller_state.dpad; - { - switch (dpad){ - case DpadPosition::DPAD_UP: - dpad_y--; - break; - case DpadPosition::DPAD_UP_RIGHT: - dpad_x++; - dpad_y--; - break; - case DpadPosition::DPAD_RIGHT: - dpad_x++; - break; - case DpadPosition::DPAD_DOWN_RIGHT: - dpad_x++; - dpad_y++; - break; - case DpadPosition::DPAD_DOWN: - dpad_y++; - break; - case DpadPosition::DPAD_DOWN_LEFT: - dpad_x--; - dpad_y++; - break; - case DpadPosition::DPAD_LEFT: - dpad_x--; - break; - case DpadPosition::DPAD_UP_LEFT: - dpad_x--; - dpad_y--; - break; - default:; - } - - if (dpad_x < 0){ - if (dpad_y < 0){ - dpad = DpadPosition::DPAD_UP_LEFT; - }else if (dpad_y > 0){ - dpad = DpadPosition::DPAD_DOWN_LEFT; - }else{ - dpad = DpadPosition::DPAD_LEFT; - } - }else if (dpad_x > 0){ - if (dpad_y < 0){ - dpad = DpadPosition::DPAD_UP_RIGHT; - }else if (dpad_y > 0){ - dpad = DpadPosition::DPAD_DOWN_RIGHT; - }else{ - dpad = DpadPosition::DPAD_RIGHT; - } - }else{ - if (dpad_y < 0){ - dpad = DpadPosition::DPAD_UP; - }else if (dpad_y > 0){ - dpad = DpadPosition::DPAD_DOWN; - }else{ - dpad = DPAD_NONE; - } - } - } - dpad_byte |= dpad; - - // Divide the controller state into smaller chunks that fit into the report - // duration. - Milliseconds time_left = std::chrono::duration_cast(entry.duration); - - while (time_left > Milliseconds::zero()){ - Milliseconds current = std::min(time_left, 65535ms); - m_serial->issue_request( - DeviceRequest_WiredController_ControllerStateMs( - (uint16_t)current.count(), - buttons, - dpad_byte, - JoystickTools::linear_float_to_u8(controller_state.left_joystick.x), - JoystickTools::linear_float_to_u8(-controller_state.left_joystick.y), - JoystickTools::linear_float_to_u8(controller_state.right_joystick.x), - JoystickTools::linear_float_to_u8(-controller_state.right_joystick.y) - ), - cancellable - ); - time_left -= current; - } -} - - - - -void SerialPABotBase_WiredController::update_status(Cancellable& cancellable){ - pabb_MsgAckRequestI32 response; - m_serial->issue_request_and_wait( - SerialPABotBase::MessageControllerStatus(), - &cancellable - ).convert(m_logger, response); - - uint32_t status = response.data; - bool status_connected = status & 1; - bool status_ready = status & 2; - - std::string str; - str += "Connected: " + (status_connected - ? html_color_text("Yes", theme_friendly_darkblue()) - : html_color_text("No", COLOR_RED) - ); - str += " - Ready: " + (status_ready - ? html_color_text("Yes", theme_friendly_darkblue()) - : html_color_text("No", COLOR_RED) - ); - - m_handle.set_status_line1(str); -} -void SerialPABotBase_WiredController::stop_with_error(std::string message){ - SerialPABotBase_Controller::stop_with_error(std::move(message)); -} - - - - - - - -} -} diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.h b/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.h deleted file mode 100644 index 6855fd6c8d..0000000000 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.h +++ /dev/null @@ -1,242 +0,0 @@ -/* SerialPABotBase: Wired Controller (Switch 1) - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_NintendoSwitch_SerialPABotBase_WiredControllerNS1_H -#define PokemonAutomation_NintendoSwitch_SerialPABotBase_WiredControllerNS1_H - -#include "Controllers/ControllerStatusThread.h" -#include "NintendoSwitch/NintendoSwitch_Settings.h" -#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" -#include "NintendoSwitch_SerialPABotBase_Controller.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - - - - -class SerialPABotBase_WiredController final : - public ProController, - public SerialPABotBase_Controller, - private ControllerStatusThreadCallback -{ -public: - using ContextType = ProControllerContext; - - -public: - SerialPABotBase_WiredController( - Logger& logger, - SerialPABotBase::SerialPABotBase_Connection& connection, - ControllerType controller_type - ); - ~SerialPABotBase_WiredController(); - void stop(); - - virtual Logger& logger() override{ - return m_logger; - } - virtual bool is_ready() const override{ - return SerialPABotBase_Controller::is_ready(); - } - - -public: - virtual ControllerPerformanceClass performance_class() const override{ - return ControllerPerformanceClass::SerialPABotBase_Wired; - } - virtual Milliseconds ticksize() const override{ - return Milliseconds(0); - } - virtual Milliseconds cooldown() const override{ - return Milliseconds(8); - } - virtual Milliseconds timing_variation() const override{ - return ConsoleSettings::instance().TIMING_OPTIONS.WIRED; - } - virtual bool atomic_multibutton() const override{ - return true; - } - - -public: - virtual void cancel_all_commands() override{ - SerialPABotBase_Controller::cancel_all_commands(); - } - virtual void replace_on_next_command() override{ - SerialPABotBase_Controller::replace_on_next_command(); - } - - virtual void wait_for_all(Cancellable* cancellable) override{ - SerialPABotBase_Controller::wait_for_all(cancellable); - } - - -public: - // Superscalar Commands (the "ssf" framework) - - virtual void issue_barrier(Cancellable* cancellable) override{ - ControllerWithScheduler::issue_barrier(cancellable); - } - virtual void issue_nop(Cancellable* cancellable, Milliseconds duration) override{ - ControllerWithScheduler::issue_nop(cancellable, duration); - } - virtual void issue_buttons( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - Button button - ) override{ - button &= VALID_PRO_CONTROLLER_BUTTONS; - ControllerWithScheduler::issue_buttons(cancellable, delay, hold, cooldown, button); - } - virtual void issue_dpad( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - DpadPosition position - ) override{ - ControllerWithScheduler::issue_dpad(cancellable, delay, hold, cooldown, position); - } - virtual void issue_left_joystick( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - const JoystickPosition& position - ) override{ - ControllerWithScheduler::issue_left_joystick(cancellable, delay, hold, cooldown, position); - } - virtual void issue_right_joystick( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - const JoystickPosition& position - ) override{ - ControllerWithScheduler::issue_right_joystick(cancellable, delay, hold, cooldown, position); - } - - virtual void issue_gyro_accel_x( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - int16_t value - ) override{ - ControllerWithScheduler::issue_gyro_accel_x(cancellable, delay, hold, cooldown, value); - } - virtual void issue_gyro_accel_y( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - int16_t value - ) override{ - ControllerWithScheduler::issue_gyro_accel_y(cancellable, delay, hold, cooldown, value); - } - virtual void issue_gyro_accel_z( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - int16_t value - ) override{ - ControllerWithScheduler::issue_gyro_accel_z(cancellable, delay, hold, cooldown, value); - } - virtual void issue_gyro_rotate_x( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - int16_t value - ) override{ - ControllerWithScheduler::issue_gyro_rotate_x(cancellable, delay, hold, cooldown, value); - } - virtual void issue_gyro_rotate_y( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - int16_t value - ) override{ - ControllerWithScheduler::issue_gyro_rotate_y(cancellable, delay, hold, cooldown, value); - } - virtual void issue_gyro_rotate_z( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - int16_t value - ) override{ - ControllerWithScheduler::issue_gyro_rotate_z(cancellable, delay, hold, cooldown, value); - } - - virtual void issue_full_controller_state( - Cancellable* cancellable, - bool enable_logging, - Milliseconds duration, - Button button, - DpadPosition dpad, - const JoystickPosition& left_joystick, - const JoystickPosition& right_joystick - ) override{ - ControllerWithScheduler::issue_full_controller_state( - cancellable, - enable_logging, - duration, - button, - dpad, - left_joystick, - right_joystick - ); - } - - -public: - // High speed RPCs. - - virtual void issue_mash_button( - Cancellable* cancellable, - Milliseconds duration, - Button button, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown - ) override{ - button &= VALID_PRO_CONTROLLER_BUTTONS; - ControllerWithScheduler::issue_mash_button(cancellable, duration, button, delay, hold, cooldown); - } - virtual void issue_mash_button( - Cancellable* cancellable, - Milliseconds duration, - Button button0, Button button1 - ) override{ - button0 &= VALID_PRO_CONTROLLER_BUTTONS; - button1 &= VALID_PRO_CONTROLLER_BUTTONS; - ControllerWithScheduler::issue_mash_button(cancellable, duration, button0, button1); - } - virtual void issue_mash_AZs( - Cancellable* cancellable, - Milliseconds duration - ) override{ - ControllerWithScheduler::issue_mash_AZs(cancellable, duration); - } - virtual void issue_system_scroll( - Cancellable* cancellable, - Milliseconds delay, Milliseconds hold, Milliseconds cooldown, - DpadPosition direction // Diagonals not allowed. - ) override{ - ControllerWithScheduler::issue_system_scroll(cancellable, delay, hold, cooldown, direction); - } - - -private: - virtual void update_status(Cancellable& cancellable) override; - virtual void stop_with_error(std::string message) override; - - -private: - template - PA_FORCE_INLINE Type milliseconds_to_ticks_8ms(Type milliseconds){ - return milliseconds / 8 + (milliseconds % 8 + 7) / 8; - } - virtual void execute_state( - Cancellable* cancellable, - const SuperscalarScheduler::ScheduleEntry& entry - ) override; - - -private: - std::unique_ptr m_status_thread; -}; - - - - -} -} -#endif diff --git a/SerialPrograms/Source/PokemonLA/Inference/Sounds/PokemonLA_ShinySoundDetector.cpp b/SerialPrograms/Source/PokemonLA/Inference/Sounds/PokemonLA_ShinySoundDetector.cpp index 89038a7d77..117d55dfc1 100644 --- a/SerialPrograms/Source/PokemonLA/Inference/Sounds/PokemonLA_ShinySoundDetector.cpp +++ b/SerialPrograms/Source/PokemonLA/Inference/Sounds/PokemonLA_ShinySoundDetector.cpp @@ -8,8 +8,8 @@ #include "CommonTools/Audio/SpectrogramMatcher.h" #include "CommonTools/Audio/AudioTemplateCache.h" #include "Tests/TestUtils.h" +#include "Controllers/NullController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" -#include "NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.h" #include "PokemonLA/PokemonLA_Settings.h" #include "PokemonLA_ShinySoundDetector.h" @@ -55,12 +55,7 @@ class Test_ShinySoundDetector : public UnitTest{ {} virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{ - DummyBotBase botbase(logger); - SerialPABotBase::SerialPABotBase_Connection connection(logger, ""); - SerialPABotBase_WiredController controller( - logger, connection, - ControllerType::NintendoSwitch_WiredController - ); + NullController controller(logger); DummyVideoFeed video_feed; DummyVideoOverlay video_overlay; DummyAudioFeed audio_feed; diff --git a/SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.cpp b/SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.cpp index 12999e39ca..6253809769 100644 --- a/SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.cpp +++ b/SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.cpp @@ -681,7 +681,7 @@ class Test_BoxCellInfoDetector : public UnitTest{ // Test BoxDexNumberDetector if (expect_dex_detection){ - BoxDexNumberDetector dex_detector(global_logger_command_line()); + BoxDexNumberDetector dex_detector(logger); bool detected_dex = dex_detector.detect(image); if (!detected_dex){ diff --git a/SerialPrograms/Source/PokemonLZA/Inference/Donuts/PokemonLZA_DonutBerriesDetector.cpp b/SerialPrograms/Source/PokemonLZA/Inference/Donuts/PokemonLZA_DonutBerriesDetector.cpp index 24dcabfb6c..5326e8d1ac 100644 --- a/SerialPrograms/Source/PokemonLZA/Inference/Donuts/PokemonLZA_DonutBerriesDetector.cpp +++ b/SerialPrograms/Source/PokemonLZA/Inference/Donuts/PokemonLZA_DonutBerriesDetector.cpp @@ -4,7 +4,7 @@ * */ -#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/Filesystem/FilePath.h" #include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTools/ImageStats.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" @@ -224,7 +224,7 @@ class Test_DonutBerriesReader : public UnitTest{ DonutBerriesReader reader; for (size_t i = 0; i < DonutBerriesReader::BERRY_PAGE_LINES; ++i){ - OCR::StringMatchResult results = reader.read_berry_page_with_ocr(image, global_logger_command_line(), language, i); + OCR::StringMatchResult results = reader.read_berry_page_with_ocr(image, logger, language, i); output_file << (results.results.empty() ? "unknown-berry" : results.results.begin()->second.token) << std::endl; } return true; @@ -243,7 +243,7 @@ class Test_DonutBerriesReader : public UnitTest{ DonutBerriesSelectionDetector selection_detector(i); TEST_RESULT_COMPONENT_EQUAL_STR(selection_detector.detect(image), i == selected_berry, "selection detector : berry slot " + std::to_string(i)); - OCR::StringMatchResult results = reader.read_berry_page_with_ocr(image, global_logger_command_line(), language, i); + OCR::StringMatchResult results = reader.read_berry_page_with_ocr(image, logger, language, i); if (results.results.empty()){ return "No berry detected via OCR"; } diff --git a/SerialPrograms/Source/PokemonLZA/Inference/PokemonLZA_HyperspaceCalorieDetector.cpp b/SerialPrograms/Source/PokemonLZA/Inference/PokemonLZA_HyperspaceCalorieDetector.cpp index 29d363b746..290db31f37 100644 --- a/SerialPrograms/Source/PokemonLZA/Inference/PokemonLZA_HyperspaceCalorieDetector.cpp +++ b/SerialPrograms/Source/PokemonLZA/Inference/PokemonLZA_HyperspaceCalorieDetector.cpp @@ -142,7 +142,7 @@ class Test_HyperspaceCalorieDetector : public UnitTest{ return "Error: expected calorie must be in range [1, 9999]."; } - HyperspaceCalorieDetector detector(global_logger_command_line()); + HyperspaceCalorieDetector detector(logger); ImageRGB32 image(m_image); if (!detector.detect(image)){ return "Error: detector failed to detect calorie number in image."; diff --git a/SerialPrograms/Source/PokemonSV/Inference/Picnics/PokemonSV_SandwichPlateDetector.cpp b/SerialPrograms/Source/PokemonSV/Inference/Picnics/PokemonSV_SandwichPlateDetector.cpp index 60f655dd6c..80fc074798 100644 --- a/SerialPrograms/Source/PokemonSV/Inference/Picnics/PokemonSV_SandwichPlateDetector.cpp +++ b/SerialPrograms/Source/PokemonSV/Inference/Picnics/PokemonSV_SandwichPlateDetector.cpp @@ -150,11 +150,10 @@ class Test_SandwichPlateDetector : public UnitTest{ return "Error: invalid language word in filename."; } - auto& unit_logger = global_logger_command_line(); FixedLimitVector detectors(3); - detectors.emplace_back(unit_logger, COLOR_RED, language, SandwichPlateDetector::Side::LEFT); - detectors.emplace_back(unit_logger, COLOR_RED, language, SandwichPlateDetector::Side::MIDDLE); - detectors.emplace_back(unit_logger, COLOR_RED, language, SandwichPlateDetector::Side::RIGHT); + detectors.emplace_back(logger, COLOR_RED, language, SandwichPlateDetector::Side::LEFT); + detectors.emplace_back(logger, COLOR_RED, language, SandwichPlateDetector::Side::MIDDLE); + detectors.emplace_back(logger, COLOR_RED, language, SandwichPlateDetector::Side::RIGHT); std::string sides[3] = {"left", "middle", "right"}; ImageRGB32 image(m_image); diff --git a/SerialPrograms/Source/StaticRegistrationQt.cpp b/SerialPrograms/Source/StaticRegistrationQt.cpp index 1d987e9709..2b497f42ee 100644 --- a/SerialPrograms/Source/StaticRegistrationQt.cpp +++ b/SerialPrograms/Source/StaticRegistrationQt.cpp @@ -46,7 +46,6 @@ // Controllers #include "Controllers/NullControllerWidget.h" -#include "Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.h" #include "Controllers/PABotBase2/SerialPABotBase2_SelectorWidget.h" #include "ControllerInput/Keyboard/KeyBindingWidget.h" @@ -120,7 +119,6 @@ void register_all_statics(){ // Controllers RegisterUiStateQtWidget(); - RegisterUiStateQtWidget(); RegisterUiStateQtWidget(); RegisterUiStateQtWidget(); diff --git a/SerialPrograms/Source/Tests/TestMap.cpp b/SerialPrograms/Source/Tests/TestMap.cpp index 50649390b3..3ffe1d24f2 100644 --- a/SerialPrograms/Source/Tests/TestMap.cpp +++ b/SerialPrograms/Source/Tests/TestMap.cpp @@ -5,6 +5,7 @@ */ +#include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Containers/AlignedVector.tpp" #include "TestMap.h" #include "TestUtils.h" diff --git a/SerialPrograms/Source/Tests/TestUtils.h b/SerialPrograms/Source/Tests/TestUtils.h index e960030068..bc9b966010 100644 --- a/SerialPrograms/Source/Tests/TestUtils.h +++ b/SerialPrograms/Source/Tests/TestUtils.h @@ -9,13 +9,9 @@ #ifndef PokemonAutomation_Tests_TestUtils_H #define PokemonAutomation_Tests_TestUtils_H -#include #include #include #include -#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h" -#include "Controllers/SerialPABotBase/Connection/BotBase.h" -#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h" #include "CommonFramework/AudioPipeline/AudioFeed.h" //#include "CommonFramework/Logging/Logger.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" @@ -51,44 +47,6 @@ bool load_sprite_count(const std::string& filepath, std::map& bool load_slug_list(const std::string& filepath, std::vector& sprites); -// Implement the dummy interface of BotBase so that we can run the test code -// that relies on a BotBase. -class DummyBotBase : public BotBaseController{ -public: - DummyBotBase(Logger& logger) : m_logger(logger) {} - - virtual void stop(std::string error_message) noexcept override{} - - virtual Logger& logger() override { return m_logger; } - - virtual State state() const override { return State::RUNNING; } - virtual size_t queue_limit() const override { return PABB_DEVICE_MINIMUM_QUEUE_SIZE; } - - virtual void on_cancellable_cancel( - Cancellable& cancellable, - std::exception_ptr reason - ) override{} - - virtual void wait_for_all_requests(Cancellable* cancelled = nullptr) override {} - virtual void stop_all_commands() override {} - virtual void next_command_interrupt() override {}; - - virtual bool try_issue_request( - const BotBaseRequest& request, - Cancellable* cancelled = nullptr - ) override { return true; } - virtual void issue_request( - const BotBaseRequest& request, - Cancellable* cancelled = nullptr - ) override {} - virtual BotBaseMessage issue_request_and_wait( - const BotBaseRequest& request, - Cancellable* cancelled = nullptr - ) override { return BotBaseMessage(0, ""); } - - Logger& m_logger; -}; - // Implement the dummy interface of VideoFeed so that we can test // the video inference code that relies on a VideoFeed. class DummyVideoFeed: public VideoFeed{ diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index b05a5537ab..c0e5c82baa 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -840,38 +840,12 @@ file(GLOB LIBRARY_SOURCES Source/Controllers/Schedulers/ControllerWithScheduler.h Source/Controllers/Schedulers/SuperscalarScheduler.cpp Source/Controllers/Schedulers/SuperscalarScheduler.h - Source/Controllers/SerialPABotBase/Connection/BotBase.cpp - Source/Controllers/SerialPABotBase/Connection/BotBase.h - Source/Controllers/SerialPABotBase/Connection/BotBaseMessage.h - Source/Controllers/SerialPABotBase/Connection/MessageLogger.cpp - Source/Controllers/SerialPABotBase/Connection/MessageLogger.h - Source/Controllers/SerialPABotBase/Connection/MessageSniffer.h - Source/Controllers/SerialPABotBase/Connection/PABotBase.cpp - Source/Controllers/SerialPABotBase/Connection/PABotBase.h - Source/Controllers/SerialPABotBase/Connection/PABotBaseConnection.cpp - Source/Controllers/SerialPABotBase/Connection/PABotBaseConnection.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Acks.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_CommandQueue.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_ControllerMode.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Errors.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Info.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Misc.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_StaticRequests.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_HID_Keyboard.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS_WiredController.h - Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS1_OemControllers.h - Source/Controllers/SerialPABotBase/SerialPABotBase.cpp - Source/Controllers/SerialPABotBase/SerialPABotBase.h - Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp - Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h - Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp - Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h - Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.cpp - Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.h - Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.cpp - Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.h - Source/Controllers/SerialPortPollerQt.cpp - Source/Controllers/SerialPortPollerQt.h + Source/Controllers/SerialPort/SerialLogger.cpp + Source/Controllers/SerialPort/SerialLogger.h + Source/Controllers/SerialPort/SerialPABotBase.cpp + Source/Controllers/SerialPort/SerialPABotBase.h + Source/Controllers/SerialPort/SerialPortPollerQt.cpp + Source/Controllers/SerialPort/SerialPortPollerQt.h Source/Controllers/StandardHid/StandardHid_Keyboard.cpp Source/Controllers/StandardHid/StandardHid_Keyboard.h Source/Controllers/StandardHid/StandardHid_KeyboardWithScheduler.cpp @@ -1163,10 +1137,6 @@ file(GLOB LIBRARY_SOURCES Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_ProController.h Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_WiredController.cpp Source/NintendoSwitch/Controllers/PABotBase2/NintendoSwitch_PABotBase2_WiredController.h - Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.cpp - Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.h - Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.cpp - Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.h Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase3_ControllerState.h Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase3_ProController.cpp Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase3_ProController.h