Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expander last_message_age property. #62

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/module_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ The `disconnect()` method might be useful to access the other microcontroller on

Note that the expander forwards all other method calls to the remote core module, e.g. `expander.info()`.

| Properties | Description | Data type |
| ------------------ | ------------------------------------------------------- | --------- |
| `last_message_age` | Time since last message from other microcontroller (ms) | `int` |

## Proxy

-- _This module is mainly for internal use with the expander module._ --
Expand Down
7 changes: 5 additions & 2 deletions main/modules/expander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Expander::Expander(const std::string name,
const gpio_num_t enable_pin,
MessageHandler message_handler)
: Module(expander, name), serial(serial), boot_pin(boot_pin), enable_pin(enable_pin), message_handler(message_handler) {
this->properties["last_message_age"] = std::make_shared<IntegerVariable>();

serial->enable_line_detection();
if (boot_pin != GPIO_NUM_NC && enable_pin != GPIO_NUM_NC) {
gpio_reset_pin(boot_pin);
Expand Down Expand Up @@ -45,13 +47,14 @@ void Expander::step() {
while (this->serial->has_buffered_lines()) {
int len = this->serial->read_line(buffer);
check(buffer, len);
this->last_message_millis = millis();
if (buffer[0] == '!' && buffer[1] == '!') {
/* Don't trigger keep-alive from expander updates */
this->message_handler(&buffer[2], false, true);
this->message_handler(&buffer[2], false, true); // Don't trigger core keep-alive from expander broadcasts
} else {
echo("%s: %s", this->name.c_str(), buffer);
}
}
this->properties.at("last_message_age")->integer_value = millis_since(this->last_message_millis);
Module::step();
}

Expand Down
3 changes: 3 additions & 0 deletions main/modules/expander.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Expander;
using Expander_ptr = std::shared_ptr<Expander>;

class Expander : public Module {
private:
unsigned long int last_message_millis = 0;

public:
const ConstSerial_ptr serial;
const gpio_num_t boot_pin;
Expand Down