Skip to content

Commit 50b5ec2

Browse files
committed
Fix version check.
1 parent 81d1e9e commit 50b5ec2

File tree

5 files changed

+40
-59
lines changed

5 files changed

+40
-59
lines changed

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace PokemonAutomation{
2626
const bool IS_BETA_VERSION = true;
2727
const int PROGRAM_VERSION_MAJOR = 0;
2828
const int PROGRAM_VERSION_MINOR = 57;
29-
const int PROGRAM_VERSION_PATCH = 2;
29+
const int PROGRAM_VERSION_PATCH = 3;
3030

3131
const std::string PROGRAM_VERSION_BASE =
3232
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ const std::map<pabb_ProgramID, uint32_t>& SUPPORTED_DEVICES(){
2727
return database;
2828
}
2929

30-
std::map<uint32_t, std::set<pabb_ProgramID>> make_SUPPORTED_VERSIONS(){
31-
std::map<uint32_t, std::set<pabb_ProgramID>> ret;
30+
std::map<uint32_t, std::map<pabb_ProgramID, uint8_t>> make_SUPPORTED_VERSIONS(){
31+
std::map<uint32_t, std::map<pabb_ProgramID, uint8_t>> ret;
3232
for (const auto& item : SUPPORTED_DEVICES()){
33-
ret[item.second].insert(item.first);
33+
ret[item.second / 100][item.first] = (uint8_t)(item.second % 100);
3434
}
3535
return ret;
3636
}
37-
const std::map<uint32_t, std::set<pabb_ProgramID>>& SUPPORTED_VERSIONS(){
38-
static const std::map<uint32_t, std::set<pabb_ProgramID>> database = make_SUPPORTED_VERSIONS();
37+
const std::map<uint32_t, std::map<pabb_ProgramID, uint8_t>>& SUPPORTED_VERSIONS(){
38+
static const std::map<uint32_t, std::map<pabb_ProgramID, uint8_t>> database = make_SUPPORTED_VERSIONS();
3939
return database;
4040
}
4141

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ namespace SerialPABotBase{
2121

2222

2323
const std::map<pabb_ProgramID, uint32_t>& SUPPORTED_DEVICES();
24-
const std::map<uint32_t, std::set<pabb_ProgramID>>& SUPPORTED_VERSIONS();
24+
const std::map<
25+
uint32_t, // Major protocol version. (version # / 100)
26+
std::map<
27+
pabb_ProgramID,
28+
uint8_t // Minimum minor protocol version (version # % 100)
29+
>
30+
>& SUPPORTED_VERSIONS();
2531

2632

2733

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
#include "SerialPABotBase.h"
2121
#include "SerialPABotBase_Connection.h"
2222

23-
//#include <iostream>
24-
//using std::cout;
25-
//using std::endl;
26-
2723
namespace PokemonAutomation{
2824
namespace SerialPABotBase{
2925

@@ -125,30 +121,6 @@ ControllerType SerialPABotBase_Connection::refresh_controller_type(){
125121

126122

127123

128-
129-
const std::set<pabb_ProgramID>& SerialPABotBase_Connection::get_programs_for_protocol(uint32_t protocol){
130-
// (protocol_requested / 100) == (protocol_device / 100)
131-
// (protocol_requested % 100) <= (protocol_device % 100)
132-
auto iter = SUPPORTED_VERSIONS().upper_bound(protocol);
133-
if (iter == SUPPORTED_VERSIONS().begin()){
134-
throw SerialProtocolException(
135-
m_logger, PA_CURRENT_FUNCTION,
136-
"Incompatible protocol. Device: " + std::to_string(protocol) + "<br>"
137-
"Please flash the .hex/.bin that came with this version of the program."
138-
);
139-
}
140-
--iter;
141-
if (iter->first < protocol / 100 * 100){
142-
throw SerialProtocolException(
143-
m_logger, PA_CURRENT_FUNCTION,
144-
"Incompatible protocol. Device: " + std::to_string(protocol) + "<br>"
145-
"Please flash the .hex/.bin that came with this version of the program."
146-
);
147-
}
148-
149-
return iter->second;
150-
}
151-
152124
void SerialPABotBase_Connection::process_queue_size(){
153125
m_logger.log("Requesting queue size...");
154126
uint8_t queue_size = device_queue_size(*m_botbase);
@@ -161,42 +133,47 @@ void SerialPABotBase_Connection::process_queue_size(){
161133
m_botbase->set_queue_limit(queue_size);
162134
}
163135

136+
void SerialPABotBase_Connection::throw_incompatible_protocol(){
137+
throw SerialProtocolException(
138+
m_logger, PA_CURRENT_FUNCTION,
139+
"Incompatible protocol. Device: " + std::to_string(m_protocol) + "<br>"
140+
"Please flash the .hex/.bin that came with this version of the program."
141+
);
142+
}
164143
ControllerType SerialPABotBase_Connection::process_device(bool set_to_null_controller){
165144
// Protocol Version
145+
const std::map<pabb_ProgramID, uint8_t>* PROGRAMS;
166146
{
167147
m_logger.Logger::log("Checking Protocol Version...");
168148
m_protocol = protocol_version(*m_botbase);
169149
m_logger.Logger::log("Checking Protocol Version... (" + std::to_string(m_protocol) + ")");
150+
auto iter = SUPPORTED_VERSIONS().find(m_protocol / 100);
151+
if (iter == SUPPORTED_VERSIONS().end()){
152+
throw_incompatible_protocol();
153+
}
154+
PROGRAMS = &iter->second;
170155
}
171-
const std::set<pabb_ProgramID>& PROGRAMS = get_programs_for_protocol(m_protocol);
172156

173157
// Program ID
174158
{
175159
m_logger.Logger::log("Checking Program ID...");
176160
m_program_id = program_id(*m_botbase);
177161
m_logger.Logger::log("Checking Program ID... (0x" + tostr_hex(m_program_id) + ")");
178-
}
179-
if (PROGRAMS.find(m_program_id) == PROGRAMS.end()){
180-
#if 1
181-
m_logger.Logger::log(
182-
"Unrecognized Program ID: (0x" + tostr_hex(m_program_id) + ") for this protocol version. "
183-
"Compatibility is not guaranteed.",
184-
COLOR_RED
185-
);
186-
if (PROGRAMS.find(PABB_PID_UNSPECIFIED) == PROGRAMS.end()){
187-
throw SerialProtocolException(
188-
m_logger, PA_CURRENT_FUNCTION,
189-
"Unrecognized program IDs require latest protocol.<br>"
190-
"Program ID: 0x" + tostr_hex(m_program_id) + ", Device Protocol: " + std::to_string(m_protocol)
162+
auto iter = PROGRAMS->find(m_program_id);
163+
if (iter == PROGRAMS->end()){
164+
m_logger.Logger::log(
165+
"Unrecognized Program ID: (0x" + tostr_hex(m_program_id) + ") for this protocol version. "
166+
"Compatibility is not guaranteed.",
167+
COLOR_RED
191168
);
169+
iter = PROGRAMS->find(PABB_PID_UNSPECIFIED);
170+
if (iter == PROGRAMS->end()){
171+
throw_incompatible_protocol();
172+
}
173+
}
174+
if (m_protocol % 100 < iter->second){
175+
throw_incompatible_protocol();
192176
}
193-
#else
194-
throw SerialProtocolException(
195-
m_logger, PA_CURRENT_FUNCTION,
196-
"Unrecognized Program ID: 0x" + tostr_hex(m_program_id) + "<br>"
197-
"Please install the firmware that came with this version of the program."
198-
);
199-
#endif
200177
}
201178

202179
// Firmware Version

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ class SerialPABotBase_Connection : public ControllerConnection{
4444

4545

4646
private:
47-
const std::set<pabb_ProgramID>& get_programs_for_protocol(uint32_t protocol);
48-
4947
void process_queue_size();
50-
48+
void throw_incompatible_protocol();
5149
ControllerType process_device(bool set_to_null_controller);
5250

5351
void thread_body(bool set_to_null_controller);

0 commit comments

Comments
 (0)