Skip to content

Commit c3b0383

Browse files
committed
Refactor.
1 parent b1f166f commit c3b0383

File tree

7 files changed

+59
-47
lines changed

7 files changed

+59
-47
lines changed

ClientSource/Connection/PABotBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ PABotBase::PABotBase(
3939
)
4040
: PABotBaseConnection(logger, std::move(connection))
4141
, m_logger(logger)
42-
, m_max_pending_requests(PABB_DEVICE_QUEUE_SIZE)
42+
, m_max_pending_requests(PABB_DEVICE_MINIMUM_QUEUE_SIZE)
4343
, m_send_seq(1)
4444
, m_retransmit_delay(retransmit_delay)
4545
, m_last_ack(current_time())

ClientSource/Connection/PABotBase.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ namespace PokemonAutomation{
4141

4242

4343
class PABotBase : public BotBaseController, private PABotBaseConnection{
44-
// static const size_t MAX_PENDING_REQUESTS = PABB_DEVICE_QUEUE_SIZE;
4544
static const seqnum_t MAX_SEQNUM_GAP = (seqnum_t)-1 >> 2;
4645

4746
public:
4847
PABotBase(
4948
Logger& logger,
5049
std::unique_ptr<StreamConnection> connection,
5150
MessageLogger* message_logger = nullptr,
52-
std::chrono::milliseconds retransmit_delay = std::chrono::milliseconds(PABB_RETRANSMIT_DELAY_MILLIS)
51+
std::chrono::milliseconds retransmit_delay = std::chrono::milliseconds(100)
5352
);
5453
virtual ~PABotBase();
5554

Common/SerialPABotBase/SerialPABotBase_Protocol.h

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -139,48 +139,11 @@ extern "C" {
139139
////////////////////////////////////////////////////////////////////////////////
140140
////////////////////////////////////////////////////////////////////////////////
141141

142-
// This macro isn't part of the protocol. But it specifies the size of the
143-
// command queue on the device. This can be used as a hint by the client to
144-
// avoid overloading the device. This has no effect on correctness since the
145-
// device will automatically drop commands when the command queue fills up or
146-
// if it can't process serial messages quickly enough.
147-
148-
// Must be a power-of-two.
149-
#if __AVR_ATmega16U2__
150-
#define PABB_DEVICE_QUEUE_SIZE 8
151-
#elif __AVR_ATmega32U4__ || __AVR_AT90USB1286__
152-
#define PABB_DEVICE_QUEUE_SIZE 64
153-
#else
154-
#define PABB_DEVICE_QUEUE_SIZE 4
155-
#endif
156-
157-
// Client code should first assume the queue size is only 4. It can optionally
158-
// query for the actual queue size using PABB_MSG_REQUEST_QUEUE_SIZE.
159-
160-
////////////////////////////////////////////////////////////////////////////////
161-
////////////////////////////////////////////////////////////////////////////////
162-
163-
// Protocol Version:
164-
//
165-
// Backwards incompatible changes will increase by 100 or more.
166-
// Backwards compatible changes will increase by 1.
167-
//
168-
// (version / 100) must be the same on both server and client.
169-
// (version % 100) may differ though client may apply restrictions.
170-
//
171-
#define PABB_PROTOCOL_VERSION 2023121900
172-
173-
// Program versioning doesn't matter. It's just for informational purposes.
174-
#define PABB_PROGRAM_VERSION 2023121900
175-
176142
#define PABB_BAUD_RATE 115200
177-
#define PABB_RETRANSMIT_DELAY_MILLIS 80
178-
179-
// This limit of 12 is only for AVR8. ESP32 will go much larger. So we ignore
180-
// this number and allow large messages on the computer side.
181-
#define PABB_MAX_MESSAGE_SIZE 12
182143
#define PABB_PROTOCOL_OVERHEAD (2 + sizeof(uint32_t))
183-
#define PABB_MAX_PACKET_SIZE (PABB_MAX_MESSAGE_SIZE + PABB_PROTOCOL_OVERHEAD)
144+
145+
// Must be a power-of-two.
146+
#define PABB_DEVICE_MINIMUM_QUEUE_SIZE 4
184147

185148
typedef uint32_t seqnum_t;
186149

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Serial PABotBase Parameters
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_SerialPABotBase_Parameters_H
8+
#define PokemonAutomation_SerialPABotBase_Parameters_H
9+
10+
11+
// Protocol Version:
12+
//
13+
// Backwards incompatible changes will increase by 100 or more.
14+
// Backwards compatible changes will increase by 1.
15+
//
16+
// (version / 100) must be the same on both server and client.
17+
// (version % 100) may differ though client may apply restrictions.
18+
//
19+
#define PABB_PROTOCOL_VERSION 2023121900
20+
21+
// Program versioning doesn't matter. It's just for informational purposes.
22+
#define PABB_PROGRAM_VERSION 2023121900
23+
24+
#define PABB_RETRANSMIT_DELAY_MILLIS 80
25+
26+
#define PABB_MAX_MESSAGE_SIZE 12
27+
#define PABB_MAX_PACKET_SIZE (PABB_MAX_MESSAGE_SIZE + PABB_PROTOCOL_OVERHEAD)
28+
29+
30+
31+
// This macro isn't part of the protocol. But it specifies the size of the
32+
// command queue on the device. This can be used as a hint by the client to
33+
// avoid overloading the device. This has no effect on correctness since the
34+
// device will automatically drop commands when the command queue fills up or
35+
// if it can't process serial messages quickly enough.
36+
37+
// Must be a power-of-two.
38+
#if __AVR_ATmega16U2__
39+
#define PABB_DEVICE_QUEUE_SIZE 8
40+
#elif __AVR_ATmega32U4__ || __AVR_AT90USB1286__
41+
#define PABB_DEVICE_QUEUE_SIZE 64
42+
#else
43+
#define PABB_DEVICE_QUEUE_SIZE 4
44+
#endif
45+
46+
47+
48+
#endif

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ const std::map<
105105
ControllerFeature::NintendoSwitch_DateSkip,
106106
}},
107107
}},
108+
}},
109+
{2025031600, {
108110
{PABB_PID_PABOTBASE_ESP32, {
109111
{ControllerType::NintendoSwitch_WirelessProController, {
110112
ControllerFeature::TickPrecise,

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ ControllerModeStatus SerialPABotBase_Connection::read_device_specs(
168168
throw SerialProtocolException(
169169
logger, PA_CURRENT_FUNCTION,
170170
"Incompatible protocol. Device: " + std::to_string(m_protocol) + "<br>"
171-
"Please install the .hex that came with this version of the program."
171+
"Please install the firmware that came with this version of the program."
172172
);
173173
}
174174
--protocol_iter;
175175
if (protocol_iter->first < m_protocol / 100 * 100){
176176
throw SerialProtocolException(
177177
logger, PA_CURRENT_FUNCTION,
178178
"Incompatible protocol. Device: " + std::to_string(m_protocol) + "<br>"
179-
"Please install the .hex that came with this version of the program."
179+
"Please install the firmware that came with this version of the program."
180180
);
181181
}
182182

@@ -192,7 +192,7 @@ ControllerModeStatus SerialPABotBase_Connection::read_device_specs(
192192
throw SerialProtocolException(
193193
logger, PA_CURRENT_FUNCTION,
194194
"Unrecognized Program ID: " + std::to_string(m_program_id) + "<br>"
195-
"Please install the .hex that came with this version of the program."
195+
"Please install the firmware that came with this version of the program."
196196
);
197197
}
198198

SerialPrograms/Source/Tests/TestUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class DummyBotBase : public BotBaseController{
6060
virtual Logger& logger() override { return m_logger; }
6161

6262
virtual State state() const override { return State::RUNNING; }
63-
virtual size_t queue_limit() const override { return PABB_DEVICE_QUEUE_SIZE; }
63+
virtual size_t queue_limit() const override { return PABB_DEVICE_MINIMUM_QUEUE_SIZE; }
6464

6565
virtual void notify_all() override{}
6666

0 commit comments

Comments
 (0)