Skip to content

Commit 6106168

Browse files
committed
Reorganize PABotBase2 folder.
1 parent d2aa35d commit 6106168

30 files changed

Lines changed: 1086 additions & 72 deletions

Common/PABotBase2/DataLayer/PABotBase2_Controller_HID_Keyboard.h renamed to Common/PABotBase2/Controllers/PABotBase2_Controller_HID_Keyboard.h

File renamed without changes.

Common/PABotBase2/DataLayer/PABotBase2_Controller_NS1_OemController.h renamed to Common/PABotBase2/Controllers/PABotBase2_Controller_NS1_OemController.h

File renamed without changes.

Common/PABotBase2/DataLayer/PABotBase2_Controller_NS_WiredController.h renamed to Common/PABotBase2/Controllers/PABotBase2_Controller_NS_WiredController.h

File renamed without changes.
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
/* PABotBase2 Message Dumper
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "Common/Cpp/PrettyPrint.h"
8+
#include "PABotBase2CC_MessageDumper.h"
9+
10+
namespace PokemonAutomation{
11+
namespace PABotBase2{
12+
13+
14+
std::string tostr(const PacketHeader* header){
15+
// TODO: Make sure packets are large enough before reading them.
16+
17+
std::string str;
18+
if (header->opcode & PABB2_CONNECTION_RETRANSMIT_FLAG){
19+
str += "(Retransmit) ";
20+
}
21+
switch (header->opcode & PABB2_CONNECTION_OPCODE_MASK){
22+
case PABB2_CONNECTION_OPCODE_INVALID:
23+
str += "PABB2_CONNECTION_OPCODE_INVALID: seqnum = ";
24+
str += std::to_string(header->seqnum);
25+
return str;
26+
27+
case PABB2_CONNECTION_OPCODE_ASK_RESET:
28+
str += "PABB2_CONNECTION_OPCODE_ASK_RESET: seqnum = ";
29+
str += std::to_string(header->seqnum);
30+
return str;
31+
case PABB2_CONNECTION_OPCODE_RET_RESET:
32+
str += "PABB2_CONNECTION_OPCODE_RET_RESET: seqnum = ";
33+
str += std::to_string(header->seqnum);
34+
return str;
35+
36+
case PABB2_CONNECTION_OPCODE_ASK_VERSION:
37+
str += "PABB2_CONNECTION_OPCODE_ASK_VERSION: seqnum = ";
38+
str += std::to_string(header->seqnum);
39+
return str;
40+
case PABB2_CONNECTION_OPCODE_RET_VERSION:
41+
str += "PABB2_CONNECTION_OPCODE_RET_VERSION: seqnum = ";
42+
str += std::to_string(header->seqnum);
43+
str += ", version = " + std::to_string(((const PacketHeader_Ack_u32*)header)->data);
44+
return str;
45+
46+
case PABB2_CONNECTION_OPCODE_ASK_PACKET_SIZE:
47+
str += "PABB2_CONNECTION_OPCODE_ASK_PACKET_SIZE: seqnum = ";
48+
str += std::to_string(header->seqnum);
49+
return str;
50+
case PABB2_CONNECTION_OPCODE_RET_PACKET_SIZE:
51+
str += "PABB2_CONNECTION_OPCODE_RET_PACKET_SIZE: seqnum = ";
52+
str += std::to_string(header->seqnum);
53+
str += ", bytes = " + std::to_string(((const PacketHeader_Ack_u16*)header)->data);
54+
return str;
55+
56+
case PABB2_CONNECTION_OPCODE_ASK_BUFFER_SLOTS:
57+
str += "PABB2_CONNECTION_OPCODE_ASK_BUFFER_SLOTS: seqnum = ";
58+
str += std::to_string(header->seqnum);
59+
return str;
60+
case PABB2_CONNECTION_OPCODE_RET_BUFFER_SLOTS:
61+
str += "PABB2_CONNECTION_OPCODE_RET_BUFFER_SLOTS: seqnum = ";
62+
str += std::to_string(header->seqnum);
63+
str += ", slots = " + std::to_string(((const PacketHeader_Ack_u8*)header)->data);
64+
return str;
65+
66+
case PABB2_CONNECTION_OPCODE_ASK_BUFFER_BYTES:
67+
str += "PABB2_CONNECTION_OPCODE_ASK_BUFFER_BYTES: seqnum = ";
68+
str += std::to_string(header->seqnum);
69+
return str;
70+
case PABB2_CONNECTION_OPCODE_RET_BUFFER_BYTES:
71+
str += "PABB2_CONNECTION_OPCODE_RET_BUFFER_BYTES: seqnum = ";
72+
str += std::to_string(header->seqnum);
73+
str += ", bytes = " + std::to_string(((const PacketHeader_Ack_u16*)header)->data);
74+
return str;
75+
76+
case PABB2_CONNECTION_OPCODE_ASK_STREAM_DATA:
77+
str += "PABB2_CONNECTION_OPCODE_ASK_STREAM_DATA: seqnum = ";
78+
str += std::to_string(header->seqnum);
79+
str += ", offset = " + std::to_string(((const PacketHeaderData*)header)->stream_offset);
80+
str += ", bytes = " + std::to_string(header->packet_bytes - sizeof(PacketHeaderData) - sizeof(uint32_t));
81+
return str;
82+
case PABB2_CONNECTION_OPCODE_RET_STREAM_DATA:
83+
str += "PABB2_CONNECTION_OPCODE_RET_STREAM_REQUEST: seqnum = ";
84+
str += std::to_string(header->seqnum);
85+
return str;
86+
case PABB2_CONNECTION_OPCODE_ASK_STREAM_REQUEST:
87+
str += "PABB2_CONNECTION_OPCODE_RET_STREAM: seqnum = ";
88+
str += std::to_string(header->seqnum);
89+
str += ", offset = " + std::to_string(((const PacketHeaderData*)header)->stream_offset);
90+
return str;
91+
92+
case PABB2_CONNECTION_OPCODE_INFO:
93+
str += "PABB2_CONNECTION_OPCODE_INFO: seqnum = ";
94+
str += std::to_string(header->seqnum);
95+
return str;
96+
case PABB2_CONNECTION_OPCODE_INFO_U8:
97+
str += "PABB2_CONNECTION_OPCODE_INFO_U8: seqnum = ";
98+
str += std::to_string(header->seqnum);
99+
str += ", data = " + std::to_string(((const PacketHeader_Ack_u8*)header)->data);
100+
return str;
101+
case PABB2_CONNECTION_OPCODE_INFO_U16:
102+
str += "PABB2_CONNECTION_OPCODE_INFO_U16: seqnum = ";
103+
str += std::to_string(header->seqnum);
104+
str += ", data = " + std::to_string(((const PacketHeader_Ack_u16*)header)->data);
105+
return str;
106+
case PABB2_CONNECTION_OPCODE_INFO_U32:
107+
str += "PABB2_CONNECTION_OPCODE_INFO_U32: seqnum = ";
108+
str += std::to_string(header->seqnum);
109+
str += ", data = " + std::to_string(((const PacketHeader_Ack_u32*)header)->data);
110+
return str;
111+
112+
case PABB2_CONNECTION_OPCODE_INVALID_LENGTH:
113+
str += "PABB2_CONNECTION_OPCODE_INVALID_LENGTH: seqnum = ";
114+
str += std::to_string(header->seqnum);
115+
return str;
116+
case PABB2_CONNECTION_OPCODE_INVALID_CHECKSUM_FAIL:
117+
str += "PABB2_CONNECTION_OPCODE_INVALID_CHECKSUM_FAIL: seqnum = ";
118+
str += std::to_string(header->seqnum);
119+
return str;
120+
case PABB2_CONNECTION_OPCODE_UNKNOWN_OPCODE:
121+
str += "PABB2_CONNECTION_OPCODE_UNKNOWN_OPCODE: seqnum = ";
122+
str += std::to_string(header->seqnum);
123+
return str;
124+
}
125+
return "Unknown Packet Opcode: 0x" + tostr_hex(header->opcode);
126+
}
127+
128+
std::string tostr(const MessageHeader* header){
129+
// TODO: Make sure packets are large enough before reading them.
130+
131+
std::string str;
132+
switch (header->opcode & PABB2_CONNECTION_OPCODE_MASK){
133+
case PABB2_MESSAGE_OPCODE_INVALID:
134+
str += "PABB2_MESSAGE_OPCODE_INVALID: id = ";
135+
str += std::to_string(header->id);
136+
return str;
137+
case PABB2_MESSAGE_OPCODE_LOG_STRING:
138+
str += "PABB2_MESSAGE_OPCODE_LOG_STRING: id = ";
139+
str += std::to_string(header->id);
140+
str += ": " + std::string(
141+
(const char*)(header + 1),
142+
header->message_bytes - sizeof(MessageHeader)
143+
);
144+
return str;
145+
case PABB2_MESSAGE_OPCODE_LOG_LABEL_H32:{
146+
const Message_u32* message = (const Message_u32*)header;
147+
str += "PABB2_MESSAGE_OPCODE_LOG_LABEL_U32: id = ";
148+
str += std::to_string(message->id);
149+
str += ": " + std::string(
150+
(const char*)(message + 1),
151+
message->message_bytes - sizeof(Message_u32)
152+
);
153+
str += ": ";
154+
str += tostr_hex(message->data);
155+
return str;
156+
}
157+
case PABB2_MESSAGE_OPCODE_LOG_LABEL_U32:{
158+
const Message_u32* message = (const Message_u32*)header;
159+
str += "PABB2_MESSAGE_OPCODE_LOG_LABEL_U32: id = ";
160+
str += std::to_string(message->id);
161+
str += ": " + std::string(
162+
(const char*)(message + 1),
163+
message->message_bytes - sizeof(Message_u32)
164+
);
165+
str += ": ";
166+
str += std::to_string((uint32_t)message->data);
167+
return str;
168+
}
169+
case PABB2_MESSAGE_OPCODE_LOG_LABEL_I32:{
170+
const Message_u32* message = (const Message_u32*)header;
171+
str += "PABB2_MESSAGE_OPCODE_LOG_LABEL_U32: id = ";
172+
str += std::to_string(message->id);
173+
str += ": " + std::string(
174+
(const char*)(message + 1),
175+
message->message_bytes - sizeof(Message_u32)
176+
);
177+
str += ": ";
178+
str += std::to_string((int32_t)message->data);
179+
return str;
180+
}
181+
182+
case PABB2_MESSAGE_OPCODE_RET:
183+
str += "PABB2_MESSAGE_OPCODE_RET: id = ";
184+
str += std::to_string(header->id);
185+
return str;
186+
case PABB2_MESSAGE_OPCODE_REQUEST_DROPPED:
187+
str += "PABB2_MESSAGE_OPCODE_REQUEST_DROPPED: id = ";
188+
str += std::to_string(header->id);
189+
return str;
190+
case PABB2_MESSAGE_OPCODE_RET_U32:
191+
str += "PABB2_MESSAGE_OPCODE_RET_U32: id = ";
192+
str += std::to_string(header->id);
193+
str += ", data = " + std::to_string(((const Message_u32*)header)->data);
194+
return str;
195+
case PABB2_MESSAGE_OPCODE_RET_DATA:
196+
str += "PABB2_MESSAGE_OPCODE_RET_DATA: id = ";
197+
str += std::to_string(header->id);
198+
str += ", bytes = " + std::to_string(header->message_bytes - sizeof(MessageHeader));
199+
return str;
200+
201+
case PABB2_MESSAGE_OPCODE_PROTOCOL_VERSION:
202+
str += "PABB2_MESSAGE_OPCODE_PROTOCOL_VERSION: id = ";
203+
str += std::to_string(header->id);
204+
return str;
205+
case PABB2_MESSAGE_OPCODE_FIRMWARE_VERSION:
206+
str += "PABB2_MESSAGE_OPCODE_FIRMWARE_VERSION: id = ";
207+
str += std::to_string(header->id);
208+
return str;
209+
case PABB2_MESSAGE_OPCODE_DEVICE_IDENTIFIER:
210+
str += "PABB2_MESSAGE_OPCODE_DEVICE_IDENTIFIER: id = ";
211+
str += std::to_string(header->id);
212+
return str;
213+
case PABB2_MESSAGE_OPCODE_DEVICE_NAME:
214+
str += "PABB2_MESSAGE_OPCODE_DEVICE_NAME: id = ";
215+
str += std::to_string(header->id);
216+
return str;
217+
case PABB2_MESSAGE_OPCODE_CONTROLLER_LIST:
218+
str += "PABB2_MESSAGE_OPCODE_CONTROLLER_LIST: id = ";
219+
str += std::to_string(header->id);
220+
return str;
221+
case PABB2_MESSAGE_OPCODE_CQ_CAPACITY:
222+
str += "PABB2_MESSAGE_OPCODE_CQ_CAPACITY: id = ";
223+
str += std::to_string(header->id);
224+
return str;
225+
226+
case PABB_MESSAGE_OPCODE_READ_CONTROLLER_MODE:
227+
str += "PABB_MESSAGE_OPCODE_READ_CONTROLLER_MODE: id = ";
228+
str += std::to_string(header->id);
229+
return str;
230+
case PABB_MESSAGE_OPCODE_CHANGE_CONTROLLER_MODE:
231+
str += "PABB_MESSAGE_OPCODE_CHANGE_CONTROLLER_MODE: id = ";
232+
str += std::to_string(header->id);
233+
return str;
234+
case PABB_MESSAGE_OPCODE_RESET_TO_CONTROLLER:
235+
str += "PABB_MESSAGE_OPCODE_RESET_TO_CONTROLLER: id = ";
236+
str += std::to_string(header->id);
237+
return str;
238+
case PABB_MESSAGE_OPCODE_CONTROLLER_MAC_ADDRESS:
239+
str += "PABB_MESSAGE_OPCODE_CONTROLLER_MAC_ADDRESS: id = ";
240+
str += std::to_string(header->id);
241+
return str;
242+
case PABB_MESSAGE_OPCODE_PAIRED_MAC_ADDRESS:
243+
str += "PABB_MESSAGE_OPCODE_PAIRED_MAC_ADDRESS: id = ";
244+
str += std::to_string(header->id);
245+
return str;
246+
247+
case PABB2_MESSAGE_OPCODE_CQ_CANCEL:
248+
str += "PABB2_MESSAGE_OPCODE_CQ_CANCEL: id = ";
249+
str += std::to_string(header->id);
250+
return str;
251+
case PABB2_MESSAGE_OPCODE_CQ_REPLACE_ON_NEXT:
252+
str += "PABB2_MESSAGE_OPCODE_CQ_REPLACE_ON_NEXT: id = ";
253+
str += std::to_string(header->id);
254+
return str;
255+
case PABB2_MESSAGE_OPCODE_CQ_COMMAND_FINISHED:
256+
str += "PABB2_MESSAGE_OPCODE_CQ_COMMAND_FINISHED: id = ";
257+
str += std::to_string(header->id);
258+
return str;
259+
}
260+
261+
262+
return "Unknown Message Opcode: 0x" + tostr_hex(header->opcode);
263+
}
264+
265+
266+
267+
268+
269+
}
270+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* PABotBase2 Message Dumper
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PABotBase2_MessageDumper_H
8+
#define PokemonAutomation_PABotBase2_MessageDumper_H
9+
10+
#include <string>
11+
#include "ReliableConnectionLayer/PABotBase2_PacketProtocol.h"
12+
#include "PABotBase2_MessageProtocol.h"
13+
14+
namespace PokemonAutomation{
15+
namespace PABotBase2{
16+
17+
18+
std::string tostr(const PacketHeader* header);
19+
std::string tostr(const MessageHeader* header);
20+
21+
22+
}
23+
}
24+
#endif

Common/PABotBase2/DataLayer/PABotBase2_ComputerHandle.cpp renamed to Common/PABotBase2/PABotBase2_ComputerHandle.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ namespace PABotBase2{
1616

1717

1818

19-
void ComputerHandle::send_message_u32(uint8_t id, uint32_t data){
19+
void ComputerHandle::send_message_invalid_message(uint8_t id){
20+
MessageHeader message;
21+
message.message_bytes = sizeof(MessageHeader);
22+
message.opcode = PABB2_MESSAGE_OPCODE_INVALID;
23+
message.id = id;
24+
data_connection.reliable_send(&message, message.message_bytes);
25+
}
26+
void ComputerHandle::send_message_u32(uint8_t id, const uint32_t& data){
2027
Message_u32 response;
2128
response.message_bytes = sizeof(Message_u32);
2229
response.opcode = PABB2_MESSAGE_OPCODE_RET_U32;
@@ -72,10 +79,13 @@ void ComputerHandle::process_completed_message(){
7279
case PABB2_MESSAGE_OPCODE_CQ_CAPACITY:
7380
send_message_u32(header->id, PABB2_CommandQueue_SLOTS);
7481
return;
75-
7682
}
7783

84+
if (m_listener && m_listener->execute_message(header)){
85+
return;
86+
}
7887

88+
send_message_invalid_message(header->id);
7989
}
8090

8191

Common/PABotBase2/DataLayer/PABotBase2_ComputerHandle.h renamed to Common/PABotBase2/PABotBase2_ComputerHandle.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,26 @@ namespace PokemonAutomation{
1616
namespace PABotBase2{
1717

1818

19+
1920
class ComputerHandle{
2021
public:
21-
ComputerHandle(ReliableStreamConnectionPolling& connection)
22+
struct Listener{
23+
virtual bool execute_message(const MessageHeader* header) = 0;
24+
};
25+
26+
27+
public:
28+
ComputerHandle(
29+
ReliableStreamConnectionPolling& connection,
30+
Listener* listener = nullptr
31+
)
2232
: m_connection(connection)
33+
, m_listener(listener)
2334
, m_index(0)
2435
{}
36+
void set_listener(Listener* listener){
37+
m_listener = listener;
38+
}
2539

2640
// Returns true if there may be more work to do.
2741
bool run_events();
@@ -30,6 +44,15 @@ class ComputerHandle{
3044
}
3145

3246

47+
public:
48+
void send_message_invalid_message(uint8_t id);
49+
void send_message_u32(uint8_t id, const uint32_t& data);
50+
void send_message_data(
51+
uint8_t opcode, uint8_t id,
52+
uint16_t bytes, const void* data
53+
);
54+
55+
3356
public:
3457
void send_log_str(const char* str){
3558
send_message_data(PABB2_MESSAGE_OPCODE_LOG_STRING, 0, strlen(str), str);
@@ -46,11 +69,6 @@ class ComputerHandle{
4669

4770

4871
private:
49-
void send_message_u32(uint8_t id, uint32_t data);
50-
void send_message_data(
51-
uint8_t opcode, uint8_t id,
52-
uint16_t bytes, const void* data
53-
);
5472
void send_message_u32_data(
5573
uint8_t opcode, uint8_t id,
5674
const uint32_t& u32,
@@ -61,6 +79,7 @@ class ComputerHandle{
6179

6280
private:
6381
ReliableStreamConnectionPolling& m_connection;
82+
Listener* m_listener = nullptr;
6483

6584
uint8_t m_index;
6685
char m_buffer[PABB2_MAX_INCOMING_MESSAGE_SIZE];
File renamed without changes.

0 commit comments

Comments
 (0)