Skip to content

Commit

Permalink
[P176] Add Events only when updated option and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tonhuisman committed Nov 24, 2024
1 parent db133eb commit bbda83d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/source/Plugin/P176.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Device Settings

* **Ignore data on checksum error**: The protocol includes a checksum calculation, and when this fails, the data is probably unreliable, and should better be dismissed.

* **Events only on updated data**: With this checkbox enabled, events and outgoing data to Controllers is only sent if at least 1 new packet is received since the last Interval or TaskRun. When disabled, data is sent out every Interval, when data is available (so at least a single packet is successfully received). This option is only available if Checksum processing is included in the build.

Led
^^^

Expand Down
Binary file modified docs/source/Plugin/P176_DeviceConfiguration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/_P176_VE_Direct.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// #######################################################################################################

/** Changelog:
* 2024-11-24 tonhuisman: Add setting "Events only on updated data" to not generate events/Controller output if no new packets have been received
* This check is independent from the Updated GetConfig value.
* 2024-11-10 tonhuisman: Renamed GetConfig ischanged to updated.
* 2024-11-08 tonhuisman: Add successcount, errorcount and ischanged values for GetConfig. IsChanged will reset the state on each call, so
* should be called only once in a session.
Expand Down Expand Up @@ -118,7 +120,7 @@ boolean Plugin_176(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_WEBFORM_LOAD:
{
addFormNumericBox(F("Baud Rate"), F("pbaud"), P176_SERIAL_BAUDRATE, 0);
uint8_t serialConfChoice = serialHelper_convertOldSerialConfig(P176_SERIAL_CONFIG);
const uint8_t serialConfChoice = serialHelper_convertOldSerialConfig(P176_SERIAL_CONFIG);
serialHelper_serialconfig_webformLoad(event, serialConfChoice);

addFormNumericBox(F("RX buffersize"), F("pbuffer"), P176_SERIAL_BUFFER, 128, 2048);
Expand All @@ -127,6 +129,9 @@ boolean Plugin_176(uint8_t function, struct EventStruct *event, String& string)
# if P176_FAIL_CHECKSUM
addFormCheckBox(F("Ignore data on checksum error"), F("pchksm"), P176_GET_FAIL_CHECKSUM);
# endif // if P176_FAIL_CHECKSUM
# if P176_HANDLE_CHECKSUM
addFormCheckBox(F("Events only on updated data"), F("pupd"), P176_GET_READ_UPDATED);
# endif // if P176_HANDLE_CHECKSUM

{ // Led settings
addFormSubHeader(F("Led"));
Expand Down Expand Up @@ -170,6 +175,9 @@ boolean Plugin_176(uint8_t function, struct EventStruct *event, String& string)
# if P176_FAIL_CHECKSUM
P176_SET_FAIL_CHECKSUM(isFormItemChecked(F("pchksm")));
# endif // if P176_FAIL_CHECKSUM
# if P176_HANDLE_CHECKSUM
P176_SET_READ_UPDATED(isFormItemChecked(F("pupd")));
# endif // if P176_HANDLE_CHECKSUM
# if P176_DEBUG
P176_SET_DEBUG_LOG(isFormItemChecked(F("pdebug")));
# endif // if P176_DEBUG
Expand Down
12 changes: 12 additions & 0 deletions src/src/PluginStructs/P176_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ P176_data_struct::P176_data_struct(struct EventStruct *event) {
# if P176_HANDLE_CHECKSUM && P176_FAIL_CHECKSUM
_failChecksum = P176_GET_FAIL_CHECKSUM;
# endif // if P176_HANDLE_CHECKSUM && P176_FAIL_CHECKSUM
# if P176_HANDLE_CHECKSUM
_readUpdated = P176_GET_READ_UPDATED;
# endif // if P176_HANDLE_CHECKSUM
# if P176_DEBUG
_debugLog = P176_GET_DEBUG_LOG;
# endif // if P176_DEBUG
Expand Down Expand Up @@ -71,6 +74,15 @@ bool P176_data_struct::plugin_read(struct EventStruct *event) {
success = true;
}
}
# if P176_HANDLE_CHECKSUM

if (success && (!_readUpdated || (_readUpdated &&
(_successCounter > 0) && (_successCounter != _lastReadCounter)))) {
_lastReadCounter = _successCounter;
} else {
success = false;
}
# endif // if P176_HANDLE_CHECKSUM
}

return success;
Expand Down
7 changes: 7 additions & 0 deletions src/src/PluginStructs/P176_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# define P176_FLAG_FAIL_CHECKSUM 9 // 1 bit
# define P176_FLAG_DEBUG_LOG 10 // 1 bit
# define P176_FLAG_LOG_QUIET 11 // 1 bit
# define P176_FLAG_READ_UPDATED 12 // 1 bit
# define P176_GET_LED_PIN get8BitFromUL(P176_FLAGS, P176_FLAG_LED_PIN)
# define P176_SET_LED_PIN(N) set8BitToUL(P176_FLAGS, P176_FLAG_LED_PIN, N)
# define P176_GET_LED_INVERTED bitRead(P176_FLAGS, P176_FLAG_LED_INVERTED)
Expand All @@ -29,6 +30,10 @@
# define P176_GET_FAIL_CHECKSUM bitRead(P176_FLAGS, P176_FLAG_FAIL_CHECKSUM)
# define P176_SET_FAIL_CHECKSUM(N) bitWrite(P176_FLAGS, P176_FLAG_FAIL_CHECKSUM, N)
# endif // if P176_FAIL_CHECKSUM
# if P176_HANDLE_CHECKSUM
# define P176_GET_READ_UPDATED bitRead(P176_FLAGS, P176_FLAG_READ_UPDATED)
# define P176_SET_READ_UPDATED(N) bitWrite(P176_FLAGS, P176_FLAG_READ_UPDATED, N)
# endif // if P176_HANDLE_CHECKSUM
# if P176_DEBUG
# define P176_GET_DEBUG_LOG bitRead(P176_FLAGS, P176_FLAG_DEBUG_LOG)
# define P176_SET_DEBUG_LOG(N) bitWrite(P176_FLAGS, P176_FLAG_DEBUG_LOG, N)
Expand Down Expand Up @@ -190,6 +195,8 @@ struct P176_data_struct : public PluginTaskData_base {
uint32_t _checksumDelta = 0;
uint32_t _successCounter = 0;
uint32_t _lastSuccessCounter = 0;
uint32_t _lastReadCounter = 0;
bool _readUpdated = false;
# endif // if P176_HANDLE_CHECKSUM
int _baud = P176_DEFAULT_BAUDRATE;
unsigned int _serialBuffer = P176_DEFAULT_BUFFER;
Expand Down

0 comments on commit bbda83d

Please sign in to comment.