2020#include " SerialPABotBase.h"
2121#include " SerialPABotBase_Connection.h"
2222
23- // #include <iostream>
24- // using std::cout;
25- // using std::endl;
26-
2723namespace PokemonAutomation {
2824namespace 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-
152124void 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+ }
164143ControllerType 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
0 commit comments