Skip to content

General purpose text channel - #171

Open
rkalwak wants to merge 1 commit into
SUPLA:mainfrom
rkalwak:general-purpose-text-channel
Open

rkalwak wants to merge 1 commit into
SUPLA:mainfrom
rkalwak:general-purpose-text-channel

Conversation

@rkalwak

@rkalwak rkalwak commented May 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR change?

Introducing new channel that allows to pass text - General Purpose Text channel


Affected area

  • Arduino
  • ESP-IDF
  • extras/
  • Documentation

Checklist

  • Code builds for affected platforms
  • Code follows existing style and conventions
  • Documentation updated if needed
  • CLA accepted (requested automatically after opening the PR)

@rkalwak
rkalwak marked this pull request as ready for review May 30, 2026 16:28

@klew klew left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside of below comments, we should define how to handle "read-write" variant of GPT, i.e. the same channel type, but different function? Do we allow user to change the function? If yes, how to define which functions are supported by the device? etc.

Please discuss open questions before making further changes.

char text[SUPLA_GENERAL_PURPOSE_TEXT_MAX_SIZE + 1] = {};
bool valueChanged = false;
uint32_t keepHistory = 0;
uint16_t refreshIntervalMs = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used in current code


private:
ChannelExtended channel;
char text[SUPLA_GENERAL_PURPOSE_TEXT_MAX_SIZE + 1] = {};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need to keep text copy here. You already have a channel member, which can hold text value

Comment thread src/supla-common/proto.h
#define SUPLA_GENERAL_PURPOSE_MEASUREMENT_CHART_TYPE_CANDLE 2

#define SUPLA_GENERAL_PURPOSE_UNIT_SIZE 15
#define SUPLA_GENERAL_PURPOSE_TEXT_MAX_SIZE 255 // ver. >= 29

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a static_assert to proto_check.cpp that ensure that this define is <= SUPLA_CHANNELEXTENDEDVALUE_SIZE

Comment thread src/supla-common/proto.h
// Keep history: 0 = no (default), 1 = yes
unsigned char KeepHistory;
unsigned char Reserved[13];
} TChannelConfig_GeneralPurposeText; // v. >= 29

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used currenlty. If no device shared configuration is needed, then maybe we don't need to define it and share it with a device?
What other configuration options may be added later?

Comment on lines +34 to +43
if (text == nullptr) {
text = "";
}
size_t len = strnlen(text, SUPLA_GENERAL_PURPOSE_TEXT_MAX_SIZE);
bool same = (strncmp(this->text, text, SUPLA_GENERAL_PURPOSE_TEXT_MAX_SIZE) == 0);
if (!same) {
memset(this->text, 0, sizeof(this->text));
memcpy(this->text, text, len);
valueChanged = true;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic should be added to ChannelExtended class (see setNewValue method in channel.h/cpp for standard channels - it performs check if value was changed and handles "value changed" flag on Channel class level).

Comment on lines +79 to +82
// Increment a persistent 64-bit sequence counter stored in the 8-byte
// channel value so the server always sees a changed value and sends it.
++seqCounter;
channel.setNewValue(reinterpret_cast<const char *>(&seqCounter));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be also handled internally in ChannelExtended class withint some setNewValue override (or new method like setNewTextValue in order to avoid overload of current const char * variant)

Comment on lines +85 to +106
ApplyConfigResult GeneralPurposeText::applyChannelConfig(
TSD_ChannelConfig *newConfig, bool local) {
(void)local;
if (!newConfig) {
return ApplyConfigResult::NotSupported;
}
if (newConfig->ConfigType != SUPLA_CONFIG_TYPE_DEFAULT) {
return ApplyConfigResult::NotSupported;
}
if (newConfig->ConfigSize < sizeof(TChannelConfig_GeneralPurposeText)) {
SUPLA_LOG_WARNING("GPT[%d]: config too short", getChannelNumber());
return ApplyConfigResult::NotSupported;
}
auto cfg = reinterpret_cast<TChannelConfig_GeneralPurposeText *>(
newConfig->Config);
keepHistory = cfg->KeepHistory;
refreshIntervalMs = cfg->RefreshIntervalMs;
SUPLA_LOG_INFO(
"GPT[%d]: config applied: keepHistory=%u refreshIntervalMs=%u",
getChannelNumber(), keepHistory, refreshIntervalMs);
return ApplyConfigResult::Success;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it needed?

@klew

klew commented Jun 1, 2026

Copy link
Copy Markdown
Member

Please also add some tests that covers new GPT channel. Consider adding support to sd4linux as well.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants