Fix issue #89 by imposing some limits on the random client_id (#92)

This commit is contained in:
Marius Muja 2023-11-05 15:47:11 -08:00 committed by GitHub
parent e2f4b6ec5f
commit 8317f18b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 7 deletions

View File

@ -27,7 +27,7 @@ namespace ratgdo {
this->pref_ = global_preferences->make_preference<float>(this->get_object_id_hash()); this->pref_ = global_preferences->make_preference<float>(this->get_object_id_hash());
if (!this->pref_.load(&value)) { if (!this->pref_.load(&value)) {
if (this->number_type_ == RATGDO_CLIENT_ID) { if (this->number_type_ == RATGDO_CLIENT_ID) {
value = random(0x1, 0xFFFF); value = ((random_uint32() + 1) % 0xFFFF) << 12 | 0x539;
} else { } else {
value = 0; value = 0;
} }
@ -82,7 +82,7 @@ namespace ratgdo {
} else if (this->number_type_ == RATGDO_CLIENT_ID) { } else if (this->number_type_ == RATGDO_CLIENT_ID) {
this->parent_->set_client_id(value); this->parent_->set_client_id(value);
} }
this->pref_.save(&value); this->update_state(value);
} }
} // namespace ratgdo } // namespace ratgdo

View File

@ -101,7 +101,7 @@ namespace ratgdo {
uint16_t cmd = ((fixed >> 24) & 0xf00) | (data & 0xff); uint16_t cmd = ((fixed >> 24) & 0xf00) | (data & 0xff);
data &= ~0xf000; // clear parity nibble data &= ~0xf000; // clear parity nibble
if ((fixed & 0xfffffff) == this->client_id_) { // my commands if ((fixed & 0xFFFFFFFF) == this->client_id_) { // my commands
ESP_LOG1(TAG, "[%ld] received mine: rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), rolling, fixed, data); ESP_LOG1(TAG, "[%ld] received mine: rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), rolling, fixed, data);
return static_cast<uint16_t>(Command::UNKNOWN); return static_cast<uint16_t>(Command::UNKNOWN);
} else { } else {
@ -547,9 +547,7 @@ namespace ratgdo {
return; return;
} }
// Sometimes the door doesn't always close when its fully open this->door_command(data::DOOR_CLOSE);
// so we use ensure_door_command to make sure it closes
this->ensure_door_command(data::DOOR_CLOSE);
} }
void RATGDOComponent::stop_door() void RATGDOComponent::stop_door()

View File

@ -133,7 +133,7 @@ namespace ratgdo {
void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; } void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; }
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; } void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; }
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; } void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; }
void set_client_id(uint64_t client_id) { this->client_id_ = client_id & 0xffffff; } // not sure how large client_id can be, assuming not more than 24 bits void set_client_id(uint64_t client_id) { this->client_id_ = client_id & 0xFFFFFFFF; }
void gdo_state_loop(); void gdo_state_loop();
uint16_t decode_packet(const WirePacket& packet); uint16_t decode_packet(const WirePacket& packet);