Skip to content

Commit 9302bd6

Browse files
committed
Attempt to interpret non-PABotBase serial traffic.
1 parent b3140c3 commit 9302bd6

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

ClientSource/Connection/PABotBaseConnection.cpp

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,33 @@ void PABotBaseConnection::send_message(const BotBaseMessage& message, bool is_re
8282
}
8383

8484

85+
void PABotBaseConnection::push_error_byte(ErrorBatchType type, char byte){
86+
if (m_current_error_type == type){
87+
m_current_error_batch.push_back(byte);
88+
return;
89+
}
90+
91+
switch (m_current_error_type){
92+
case ErrorBatchType::NO_ERROR_:
93+
break;
94+
case ErrorBatchType::ZERO_BYTES:
95+
m_sniffer->log("Skipped " + std::to_string(m_current_error_batch.size()) + " zero byte(s).");
96+
break;
97+
case ErrorBatchType::FF_BYTES:
98+
m_sniffer->log("Skipped " + std::to_string(m_current_error_batch.size()) + " 0xff byte(s).");
99+
break;
100+
case ErrorBatchType::ASCII_BYTES:
101+
m_sniffer->log("Received possible ASCII: " + m_current_error_batch);
102+
break;
103+
case ErrorBatchType::OTHER:
104+
// m_sniffer->log("Skipped " + std::to_string(m_current_error_batch.size()) + " invalid length byte(s).");
105+
break;
106+
}
107+
108+
m_current_error_batch.clear();
109+
m_current_error_batch.push_back(byte);
110+
m_current_error_type = type;
111+
}
85112
void PABotBaseConnection::on_recv(const void* data, size_t bytes){
86113
// Push into receive buffer.
87114
for (size_t c = 0; c < bytes; c++){
@@ -92,25 +119,32 @@ void PABotBaseConnection::on_recv(const void* data, size_t bytes){
92119
uint8_t length = ~m_recv_buffer[0];
93120

94121
if (m_recv_buffer[0] == 0){
95-
m_sniffer->log("Skipping zero byte.");
122+
// m_sniffer->log("Skipping zero byte.");
123+
push_error_byte(ErrorBatchType::ZERO_BYTES, 0);
96124
m_recv_buffer.pop_front();
97125
continue;
98126
}
99127

100128
// Message is too short.
101129
if (length < PABB_PROTOCOL_OVERHEAD){
102-
m_sniffer->log("Message is too short: bytes = " + std::to_string(length));
130+
if (length == 0){
131+
push_error_byte(ErrorBatchType::FF_BYTES, ~length);
132+
}else{
133+
m_sniffer->log("Message is too short: bytes = " + std::to_string(length));
134+
push_error_byte(ErrorBatchType::OTHER, ~length);
135+
}
103136
m_recv_buffer.pop_front();
104137
continue;
105138
}
106139

107140
// Message is too long.
108141
if (length > PABB_PROTOCOL_MAX_PACKET_SIZE){
109-
char ascii = ~length;
110-
std::string text = ascii < 32
111-
? ", ascii = " + std::to_string(ascii)
112-
: std::string(", char = ") + ascii;
113-
m_sniffer->log("Message is too long: bytes = " + std::to_string(length) + text);
142+
// char ascii = ~length;
143+
// std::string text = ascii < 32
144+
// ? ", ascii = " + std::to_string(ascii)
145+
// : std::string(", char = ") + ascii;
146+
// m_sniffer->log("Message is too long: bytes = " + std::to_string(length) + text);
147+
push_error_byte(ErrorBatchType::ASCII_BYTES, ~length);
114148
m_recv_buffer.pop_front();
115149
continue;
116150
}
@@ -120,6 +154,9 @@ void PABotBaseConnection::on_recv(const void* data, size_t bytes){
120154
return;
121155
}
122156

157+
m_current_error_type = ErrorBatchType::NO_ERROR_;
158+
m_current_error_batch.clear();
159+
123160
std::string message(m_recv_buffer.begin(), m_recv_buffer.begin() + length);
124161

125162
// Verify checksum

ClientSource/Connection/PABotBaseConnection.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,22 @@ class PABotBaseConnection : public StreamListener{
4545
virtual void on_recv(const void* data, size_t bytes) override;
4646
virtual void on_recv_message(BotBaseMessage message) = 0;
4747

48+
enum class ErrorBatchType{
49+
NO_ERROR_,
50+
ZERO_BYTES,
51+
FF_BYTES,
52+
ASCII_BYTES,
53+
OTHER,
54+
};
55+
void push_error_byte(ErrorBatchType type, char byte);
56+
4857
private:
4958
std::unique_ptr<StreamConnection> m_connection;
5059
std::deque<char> m_recv_buffer;
5160

61+
ErrorBatchType m_current_error_type;
62+
std::string m_current_error_batch;
63+
5264
protected:
5365
Logger& m_logger;
5466
MessageSniffer* m_sniffer;

ClientSource/Libraries/MessageConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ int register_message_converters_custom_info(){
420420
PABB_MSG_INFO_H32_LABEL,
421421
[](const std::string& body){
422422
std::ostringstream ss;
423-
ss << "PABB_MSG_INFO_I32_LABEL - ";
423+
ss << "PABB_MSG_INFO_H32_LABEL - ";
424424
if (body.size() < sizeof(uint32_t)){
425425
ss << "(invalid size)" << std::endl;
426426
return ss.str();

0 commit comments

Comments
 (0)