Skip to content

Commit 736fbc8

Browse files
committed
Big protocol change.
1 parent 255c102 commit 736fbc8

File tree

10 files changed

+284
-154
lines changed

10 files changed

+284
-154
lines changed

ClientSource/Libraries/MessageConverter.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,28 @@ int register_message_converters_framework_requests(){
260260
return ss.str();
261261
}
262262
);
263+
register_message_converter(
264+
PABB_MSG_REQUEST_PROGRAM_NAME,
265+
[](const std::string& body){
266+
std::ostringstream ss;
267+
ss << "PABB_MSG_REQUEST_PROGRAM_NAME - ";
268+
if (body.size() != sizeof(pabb_MsgRequestProgramName)){ ss << "(invalid size)" << std::endl; return ss.str(); }
269+
const auto* params = (const pabb_MsgRequestProgramName*)body.c_str();
270+
ss << "seqnum = " << (uint64_t)params->seqnum;
271+
return ss.str();
272+
}
273+
);
274+
register_message_converter(
275+
PABB_MSG_REQUEST_CONTROLLER_LIST,
276+
[](const std::string& body){
277+
std::ostringstream ss;
278+
ss << "PABB_MSG_REQUEST_CONTROLLER_LIST - ";
279+
if (body.size() != sizeof(pabb_MsgRequestControllerList)){ ss << "(invalid size)" << std::endl; return ss.str(); }
280+
const auto* params = (const pabb_MsgRequestControllerList*)body.c_str();
281+
ss << "seqnum = " << (uint64_t)params->seqnum;
282+
return ss.str();
283+
}
284+
);
263285
register_message_converter(
264286
PABB_MSG_REQUEST_CLOCK,
265287
[](const std::string& body){

Common/SerialPABotBase/SerialPABotBase_Protocol.h

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ typedef struct{
266266
} PABB_PACK pabb_MsgInfoI32Label;
267267

268268
////////////////////////////////////////////////////////////////////////////////
269-
// Requests
269+
// Static Requests
270270

271271
#define PABB_MSG_SEQNUM_RESET 0x40
272272
// After you send this message, the next seqnum you should use is (seqnum + 1).
@@ -289,54 +289,70 @@ typedef struct{
289289
seqnum_t seqnum;
290290
} PABB_PACK pabb_MsgRequestProgramID;
291291

292-
#define PABB_MSG_REQUEST_CLOCK 0x44
292+
#define PABB_MSG_REQUEST_PROGRAM_NAME 0x44
293293
typedef struct{
294294
seqnum_t seqnum;
295-
} PABB_PACK pabb_system_clock;
295+
} PABB_PACK pabb_MsgRequestProgramName;
296296

297-
#define PABB_MSG_REQUEST_COMMAND_FINISHED 0x45
298-
// When you receive this message, you must ack it with PABB_MSG_ACK_REQUEST.
297+
#define PABB_MSG_REQUEST_CONTROLLER_LIST 0x45
299298
typedef struct{
300299
seqnum_t seqnum;
301-
seqnum_t seq_of_original_command;
302-
uint32_t finish_time;
303-
} PABB_PACK pabb_MsgRequestCommandFinished;
300+
} PABB_PACK pabb_MsgRequestControllerList;
304301

305-
#define PABB_MSG_REQUEST_STOP 0x46
302+
#define PABB_MSG_REQUEST_QUEUE_SIZE 0x46
306303
typedef struct{
307304
seqnum_t seqnum;
308-
} PABB_PACK pabb_MsgRequestStop;
305+
} PABB_PACK pabb_MsgRequestQueueSize;
306+
307+
////////////////////////////////////////////////////////////////////////////////
308+
// Mode Requests
309309

310-
#define PABB_MSG_REQUEST_NEXT_CMD_INTERRUPT 0x47
310+
#define PABB_MSG_REQUEST_READ_CONTROLLER_MODE 0x47
311311
typedef struct{
312312
seqnum_t seqnum;
313-
} PABB_PACK pabb_MsgRequestNextCmdInterrupt;
313+
} PABB_PACK pabb_MsgRequestReadControllerMode;
314314

315-
#define PABB_MSG_REQUEST_QUEUE_SIZE 0x48
315+
#define PABB_MSG_REQUEST_CHANGE_CONTROLLER_MODE 0x48 // Change controller and keep settings.
316+
#define PABB_MSG_REQUEST_RESET_TO_CONTROLLER 0x49 // Change controller and wipe settings. (unpair from host)
316317
typedef struct{
317318
seqnum_t seqnum;
318-
} PABB_PACK pabb_MsgRequestQueueSize;
319+
uint32_t controller_id;
320+
} PABB_PACK pabb_MsgRequestChangeControllerMode;
321+
322+
////////////////////////////////////////////////////////////////////////////////
323+
// Command Queue Requests
319324

320-
#define PABB_MSG_REQUEST_READ_CONTROLLER_MODE 0x49
325+
#define PABB_MSG_REQUEST_COMMAND_FINISHED 0x4a
326+
// When you receive this message, you must ack it with PABB_MSG_ACK_REQUEST.
321327
typedef struct{
322328
seqnum_t seqnum;
323-
} PABB_PACK pabb_MsgRequestReadControllerMode;
329+
seqnum_t seq_of_original_command;
330+
uint32_t finish_time;
331+
} PABB_PACK pabb_MsgRequestCommandFinished;
324332

325-
#define PABB_MSG_REQUEST_CHANGE_CONTROLLER_MODE 0x4a // Change controller and keep settings.
326-
#define PABB_MSG_REQUEST_RESET_TO_CONTROLLER 0x4b // Change controller and wipe settings. (unpair from host)
333+
#define PABB_MSG_REQUEST_STOP 0x4b
327334
typedef struct{
328335
seqnum_t seqnum;
329-
uint32_t controller_id;
330-
} PABB_PACK pabb_MsgRequestChangeControllerMode;
336+
} PABB_PACK pabb_MsgRequestStop;
331337

338+
#define PABB_MSG_REQUEST_NEXT_CMD_INTERRUPT 0x4c
339+
typedef struct{
340+
seqnum_t seqnum;
341+
} PABB_PACK pabb_MsgRequestNextCmdInterrupt;
332342

333343
////////////////////////////////////////////////////////////////////////////////
334-
// Common Requests
344+
// Other Requests
345+
346+
#define PABB_MSG_REQUEST_CLOCK 0x4f // Deprecated
347+
typedef struct{
348+
seqnum_t seqnum;
349+
} PABB_PACK pabb_system_clock;
335350

336351
#define PABB_MSG_REQUEST_STATUS 0x50
337352
typedef struct{
338353
seqnum_t seqnum;
339354
} PABB_PACK pabb_Message_RequestStatus;
355+
340356
#define PABB_MSG_REQUEST_READ_MAC_ADDRESS 0x51
341357
typedef struct{
342358
seqnum_t seqnum;

Common/SerialPABotBase/SerialPABotBase_Protocol_IDs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
#ifndef PokemonAutomation_SerialPABotBase_Protocol_IDs_H
88
#define PokemonAutomation_SerialPABotBase_Protocol_IDs_H
99

10+
#include <stdint.h>
11+
1012
//
1113
// Program IDs
1214
//
1315

16+
typedef uint8_t pabb_ProgramID;
17+
1418
#define PABB_PID_UNSPECIFIED 0x00
1519

1620
// Old AVR8
@@ -40,13 +44,16 @@
4044
// Controller IDs
4145
//
4246

47+
typedef uint32_t pabb_ControllerID;
48+
4349
#define PABB_CID_NONE 0
4450

4551
#define PABB_CID_NintendoSwitch_WiredController 0x1000
4652
#define PABB_CID_NintendoSwitch_WiredProController 0x1001
4753
#define PABB_CID_NintendoSwitch_WirelessProController 0x1002
4854
#define PABB_CID_NintendoSwitch_LeftJoycon 0x1003
4955
#define PABB_CID_NintendoSwitch_RightJoycon 0x1004
56+
5057
#define PABB_CID_NintendoSwitch2_WiredController 0x1010
5158
#define PABB_CID_NintendoSwitch2_WiredProController 0x1011
5259
#define PABB_CID_NintendoSwitch2_WirelessProController 0x1012

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,38 @@ namespace SerialPABotBase{
1313

1414

1515

16+
const std::map<pabb_ProgramID, uint32_t>& SUPPORTED_DEVICES(){
17+
static const std::map<pabb_ProgramID, uint32_t> database{
18+
{PABB_PID_UNSPECIFIED, 2025090300},
19+
{PABB_PID_PABOTBASE_ArduinoUnoR3, 2025090300},
20+
{PABB_PID_PABOTBASE_ArduinoLeonardo, 2025090300},
21+
{PABB_PID_PABOTBASE_ProMicro, 2025090300},
22+
{PABB_PID_PABOTBASE_Teensy2, 2025090300},
23+
{PABB_PID_PABOTBASE_TeensyPP2, 2025090300},
24+
{PABB_PID_PABOTBASE_ESP32, 2025090300},
25+
{PABB_PID_PABOTBASE_ESP32S3, 2025090300},
26+
{PABB_PID_PABOTBASE_PicoW_USB, 2025090300},
27+
{PABB_PID_PABOTBASE_PicoW_UART, 2025090300},
28+
};
29+
return database;
30+
}
31+
32+
std::map<uint32_t, std::set<pabb_ProgramID>> make_SUPPORTED_VERSIONS(){
33+
std::map<uint32_t, std::set<pabb_ProgramID>> ret;
34+
for (const auto& item : SUPPORTED_DEVICES()){
35+
ret[item.second].insert(item.first);
36+
}
37+
return ret;
38+
}
39+
const std::map<uint32_t, std::set<pabb_ProgramID>>& SUPPORTED_VERSIONS(){
40+
static const std::map<uint32_t, std::set<pabb_ProgramID>> database = make_SUPPORTED_VERSIONS();
41+
return database;
42+
}
43+
44+
1645

17-
std::string program_name(uint8_t id){
46+
47+
std::string program_name(uint32_t id){
1848
switch (id){
1949
case PABB_PID_UNSPECIFIED: return "None";
2050

@@ -109,65 +139,6 @@ uint32_t controller_type_to_id(ControllerType controller_type){
109139

110140

111141

112-
const std::map<
113-
uint32_t, // Protocol Version
114-
std::map<
115-
uint32_t, // Program ID
116-
std::vector<ControllerType>
117-
>
118-
> SUPPORTED_VERSIONS{
119-
{2025081300, {
120-
{PABB_PID_PABOTBASE_ArduinoUnoR3, {
121-
ControllerType::NintendoSwitch2_WiredController,
122-
}},
123-
{PABB_PID_PABOTBASE_ArduinoLeonardo, {
124-
ControllerType::NintendoSwitch2_WiredController,
125-
}},
126-
{PABB_PID_PABOTBASE_ProMicro, {
127-
ControllerType::NintendoSwitch2_WiredController,
128-
}},
129-
{PABB_PID_PABOTBASE_Teensy2, {
130-
ControllerType::NintendoSwitch2_WiredController,
131-
}},
132-
{PABB_PID_PABOTBASE_TeensyPP2, {
133-
ControllerType::NintendoSwitch2_WiredController,
134-
}},
135-
}},
136-
{2025081700, {
137-
{PABB_PID_PABOTBASE_ESP32, {
138-
ControllerType::None,
139-
ControllerType::NintendoSwitch_WirelessProController,
140-
ControllerType::NintendoSwitch_LeftJoycon,
141-
ControllerType::NintendoSwitch_RightJoycon,
142-
}},
143-
{PABB_PID_PABOTBASE_PicoW_USB, {
144-
ControllerType::None,
145-
ControllerType::NintendoSwitch_WirelessProController,
146-
ControllerType::NintendoSwitch_LeftJoycon,
147-
ControllerType::NintendoSwitch_RightJoycon,
148-
}},
149-
{PABB_PID_PABOTBASE_PicoW_UART, {
150-
ControllerType::None,
151-
ControllerType::NintendoSwitch_WiredController,
152-
ControllerType::NintendoSwitch2_WiredController,
153-
ControllerType::NintendoSwitch_WirelessProController,
154-
ControllerType::NintendoSwitch_LeftJoycon,
155-
ControllerType::NintendoSwitch_RightJoycon,
156-
}},
157-
}},
158-
{2025081711, {
159-
{PABB_PID_PABOTBASE_ESP32S3, {
160-
ControllerType::None,
161-
ControllerType::NintendoSwitch_WiredController,
162-
ControllerType::NintendoSwitch2_WiredController,
163-
}},
164-
}},
165-
};
166-
167-
168-
169-
170-
171142

172143

173144

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <stdint.h>
1111
#include <string>
12-
#include <vector>
12+
#include <set>
1313
#include <map>
1414
#include "Controllers/ControllerTypes.h"
1515

@@ -18,20 +18,16 @@ namespace SerialPABotBase{
1818

1919

2020

21-
std::string program_name(uint8_t id);
22-
ControllerType id_to_controller_type(uint32_t id);
23-
uint32_t controller_type_to_id(ControllerType controller_type);
21+
22+
const std::map<pabb_ProgramID, uint32_t>& SUPPORTED_DEVICES();
23+
const std::map<uint32_t, std::set<pabb_ProgramID>>& SUPPORTED_VERSIONS();
2424

2525

2626

27-
extern const std::map<
28-
uint32_t, // Protocol Version
29-
std::map<
30-
uint32_t, // Program ID
31-
std::vector<ControllerType>
32-
>
33-
> SUPPORTED_VERSIONS;
3427

28+
std::string program_name(uint32_t id);
29+
ControllerType id_to_controller_type(uint32_t id);
30+
uint32_t controller_type_to_id(ControllerType controller_type);
3531

3632

3733

0 commit comments

Comments
 (0)