Skip to content

Commit e7db3fe

Browse files
committed
More PABotBase2.
1 parent 3b6b53b commit e7db3fe

10 files changed

Lines changed: 46 additions & 32 deletions

Common/Cpp/StreamConnections/MockDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using std::cout;
1515
using std::endl;
1616

17-
#if 0
17+
#if 1
1818
#define PABB2_DROP_HOST_TO_DEVICE 0.01
1919
#define PABB2_DROP_DEVICE_TO_HOST 0.01
2020
#else

Common/Cpp/StreamConnections/ReliableStreamConnection.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,7 @@ void ReliableStreamConnection::on_recv(const void* data, size_t bytes){
232232
cout << "ReliableStreamConnection::on_recv(): " << bytes << endl;
233233
}
234234
#endif
235-
m_parser.push_bytes(
236-
this, &ReliableStreamConnection::on_packet,
237-
(const uint8_t*)data, bytes
238-
);
235+
m_parser.push_bytes(*this, (const uint8_t*)data, bytes);
239236
}
240237

241238

Common/Cpp/StreamConnections/ReliableStreamConnection.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ReliableStreamConnection final
2727
: public CancellableScope
2828
, public PokemonAutomation::StreamConnection
2929
, public PABotBase2::StreamConnection
30+
, private PABotBase2::PacketRunner
3031
, private StreamListener
3132
{
3233
using PacketHeader = PABotBase2::PacketHeader;
@@ -86,14 +87,10 @@ class ReliableStreamConnection final
8687
// Receive
8788

8889
virtual void on_recv(const void* data, size_t bytes) override;
89-
static void on_packet(void* context, const PacketHeader* packet){
90-
ReliableStreamConnection& self = *(ReliableStreamConnection*)context;
91-
self.on_packet(packet);
92-
}
9390
virtual size_t recv(void* data, size_t max_bytes) override{
9491
return 0;
9592
}
96-
void on_packet(const PacketHeader* packet);
93+
virtual void on_packet(const PacketHeader* packet) override;
9794

9895
void process_RET_RESET(const PacketHeader* packet);
9996
void process_RET_VERSION(const PacketHeader* packet);

Common/PABotBase2/ConnectionLayer/PABotBase2_ConnectionDebug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void PacketSender::print(bool ascii) const{
115115
std::cout << "Buffer Head: " << m_buffer_head << std::endl;
116116
std::cout << "Buffer Tail: " << m_buffer_tail << std::endl;
117117
std::cout << "Stream Offset: " << m_stream_offset << std::endl;
118-
std::cout << "Retransmit Seqnum: " << m_retransmit_seqnum << std::endl;
118+
std::cout << "Retransmit Seqnum: " << (int)m_retransmit_seqnum << std::endl;
119119
for (uint8_t seqnum = m_slot_head; seqnum != m_slot_tail; seqnum++){
120120
size_t offset = ~m_offsets[seqnum & SLOTS_MASK];
121121
std::cout << "Offset: " << offset << std::endl;

Common/PABotBase2/ConnectionLayer/PABotBase2_PacketParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const PacketHeader* PacketParser::pull_bytes(){
121121
}
122122

123123
void PacketParser::push_bytes(
124-
void* context, pabb2_fp_PacketRunner packet_runner,
124+
PacketRunner& packet_runner,
125125
const uint8_t* data, size_t bytes
126126
){
127127
// cout << "pabb2_PacketParser_push_bytes(): " << bytes << endl;
@@ -196,7 +196,7 @@ void PacketParser::push_bytes(
196196
: PABB2_PacketParser_RESULT_CHECKSUM_FAIL;
197197
}
198198

199-
packet_runner(context, header);
199+
packet_runner.on_packet(header);
200200
index = 0;
201201
}
202202

Common/PABotBase2/ConnectionLayer/PABotBase2_PacketParser.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
#ifndef PokemonAutomation_PABotBase2_ConnectionLayer_PacketParser_H
88
#define PokemonAutomation_PABotBase2_ConnectionLayer_PacketParser_H
99

10-
#include "PABotBase2_StreamInterface.h"
10+
#include "../PABotBase2_StreamInterface.h"
1111
#include "PABotBase2_Connection.h"
1212

13-
namespace PokemonAutomation{
14-
namespace PABotBase2{
15-
16-
13+
#ifdef PABB2_SIZING_OVERRIDE
14+
#include "PABotBase2_Config.h"
15+
#else
1716

1817
// Maximum size of incoming packet + overhead.
1918
// Min Size: sizeof(largest header) + sizeof(uint32_t) + 1
@@ -22,14 +21,22 @@ namespace PABotBase2{
2221
#define PABB2_MAX_INCOMING_PACKET_SIZE ((uint16_t)128)
2322
#endif
2423

24+
#endif
25+
26+
namespace PokemonAutomation{
27+
namespace PABotBase2{
28+
29+
2530

2631

2732
#define PABB2_PacketParser_RESULT_VALID 0
2833
#define PABB2_PacketParser_RESULT_INVALID 1
2934
#define PABB2_PacketParser_RESULT_CHECKSUM_FAIL 2
3035

3136

32-
typedef void (*pabb2_fp_PacketRunner)(void* context, const PacketHeader* data);
37+
struct PacketRunner{
38+
virtual void on_packet(const PacketHeader* data) = 0;
39+
};
3340

3441

3542
struct PacketParser{
@@ -62,7 +69,7 @@ struct PacketParser{
6269
// "packet_runner" multiple times.
6370
//
6471
void push_bytes(
65-
void* context, pabb2_fp_PacketRunner packet_runner,
72+
PacketRunner& packet_runner,
6673
const uint8_t* data, size_t bytes
6774
);
6875

Common/PABotBase2/ConnectionLayer/PABotBase2_PacketSender.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,32 @@
77
#ifndef PokemonAutomation_PABotBase2_ConnectionLayer_PacketSender_H
88
#define PokemonAutomation_PABotBase2_ConnectionLayer_PacketSender_H
99

10-
#include "PABotBase2_StreamInterface.h"
10+
#include "../PABotBase2_StreamInterface.h"
1111
#include "PABotBase2_Connection.h"
1212

13-
namespace PokemonAutomation{
14-
namespace PABotBase2{
15-
13+
#ifdef PABB2_SIZING_OVERRIDE
14+
#include "PABotBase2_Config.h"
15+
#else
1616

17+
// Must be power-of-two. (max 64)
1718
#ifndef PABB2_PacketSender_SLOTS
18-
#define PABB2_PacketSender_SLOTS 128 // Must be power-of-two, fits into uint8_t. (max 128)
19+
#define PABB2_PacketSender_SLOTS 64
1920
#endif
2021

22+
// Must fit into size_t.
2123
#ifndef PABB2_PacketSender_BUFFER_SIZE
22-
#define PABB2_PacketSender_BUFFER_SIZE 32768 // Must fit into size_t.
24+
#define PABB2_PacketSender_BUFFER_SIZE 16384
2325
#endif
2426

2527
#ifndef PABB2_PacketSender_RETRANSMIT_COUNTER
2628
#define PABB2_PacketSender_RETRANSMIT_COUNTER 2
2729
#endif
2830

31+
#endif
32+
33+
namespace PokemonAutomation{
34+
namespace PABotBase2{
35+
2936

3037

3138

Common/PABotBase2/ConnectionLayer/PABotBase2_StreamCoalescer.h

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

1010
#include "PABotBase2_Connection.h"
1111

12-
namespace PokemonAutomation{
13-
namespace PABotBase2{
14-
12+
#ifdef PABB2_SIZING_OVERRIDE
13+
#include "PABotBase2_Config.h"
14+
#else
1515

16+
// Must be power-of-two. (max 64)
1617
#ifndef PABB2_StreamCoalescer_SLOTS
17-
#define PABB2_StreamCoalescer_SLOTS 128 // Must be power-of-two, fits into uint8_t. (max 128)
18+
#define PABB2_StreamCoalescer_SLOTS 64
1819
#endif
1920

21+
// Must be power-of-two, fits into uint16_t. (max 32768)
2022
#ifndef PABB2_StreamCoalescer_BUFFER_SIZE
21-
#define PABB2_StreamCoalescer_BUFFER_SIZE 32768 // Must be power-of-two, fits into uint16_t. (max 32768)
23+
#define PABB2_StreamCoalescer_BUFFER_SIZE 16384
2224
#endif
2325

26+
#endif
27+
28+
namespace PokemonAutomation{
29+
namespace PABotBase2{
2430

2531

2632

Common/PABotBase2/ConnectionLayer/PABotbase2_ReliableStreamConnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef PokemonAutomation_PABotBase2_ConnectionLayer_ReliableStreamConnection_H
88
#define PokemonAutomation_PABotBase2_ConnectionLayer_ReliableStreamConnection_H
99

10-
#include "PABotBase2_StreamInterface.h"
10+
#include "../PABotBase2_StreamInterface.h"
1111
#include "PABotBase2_PacketSender.h"
1212
#include "PABotBase2_PacketParser.h"
1313
#include "PABotBase2_StreamCoalescer.h"

Common/PABotBase2/ConnectionLayer/PABotBase2_StreamInterface.h renamed to Common/PABotBase2/PABotBase2_StreamInterface.h

File renamed without changes.

0 commit comments

Comments
 (0)