-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from atc1441/development
Release Version 1.0 of NETSGPClient
- Loading branch information
Showing
11 changed files
with
720 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
# Based on Webkit style | ||
BasedOnStyle: Webkit | ||
IndentWidth: 4 | ||
ColumnLimit: 120 | ||
--- | ||
Language: Cpp | ||
Standard: Cpp11 | ||
# Pointers aligned to the left | ||
DerivePointerAlignment: false | ||
PointerAlignment: Left | ||
AccessModifierOffset: -4 | ||
AllowShortFunctionsOnASingleLine: Inline | ||
AlwaysBreakTemplateDeclarations: true | ||
BreakBeforeBraces: Custom | ||
BraceWrapping: | ||
AfterClass: true | ||
AfterControlStatement: true | ||
AfterEnum: true | ||
AfterFunction: true | ||
AfterNamespace: true | ||
AfterStruct: true | ||
AfterUnion: true | ||
AfterExternBlock: true | ||
BeforeCatch: true | ||
BeforeElse: true | ||
SplitEmptyFunction: false | ||
SplitEmptyRecord: false | ||
SplitEmptyNamespace: false | ||
BreakConstructorInitializers: BeforeColon | ||
CompactNamespaces: false | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||
ConstructorInitializerIndentWidth: 4 | ||
Cpp11BracedListStyle: true | ||
FixNamespaceComments: true | ||
IncludeBlocks: Regroup | ||
IncludeCategories: | ||
# C++ standard headers (no .h) | ||
- Regex: '<[[:alnum:]_-]+>' | ||
Priority: 1 | ||
# Extenal libraries (with .h) | ||
- Regex: '<[[:alnum:]_./-]+>' | ||
Priority: 2 | ||
# Headers from same folder | ||
- Regex: '"[[:alnum:]_.-]+"' | ||
Priority: 3 | ||
# Headers from other folders | ||
- Regex: '"[[:alnum:]_/.-]+"' | ||
Priority: 4 | ||
IndentCaseLabels: false | ||
NamespaceIndentation: All | ||
SortIncludes: true | ||
SortUsingDeclarations: true | ||
SpaceAfterTemplateKeyword: true | ||
SpacesInAngles: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
UseTab: Never |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <Arduino.h> | ||
|
||
#include "AsyncNETSGPClient.h" | ||
|
||
AsyncNETSGPClient::AsyncNETSGPClient(Stream& stream, const uint8_t progPin, const uint8_t interval) | ||
: NETSGPClient(stream, progPin), mIntervalMS(1000 * interval) | ||
{ } | ||
|
||
void AsyncNETSGPClient::update() | ||
{ | ||
const uint32_t currentMillis = millis(); | ||
|
||
// Send comands at mIntervalMS | ||
if (currentMillis - mLastUpdateMS >= mIntervalMS) | ||
{ | ||
mLastUpdateMS = currentMillis; | ||
|
||
for (const uint32_t deviceID : mDevices) | ||
{ | ||
sendCommand(Command::STATUS, 0x00, deviceID); | ||
} | ||
} | ||
|
||
// Check for answers | ||
while (mStream.available() >= 27) | ||
{ | ||
// Search for a read status message | ||
if (findAndReadStatusMessage() && mCallback) | ||
{ | ||
InverterStatus status; | ||
fillInverterStatusFromBuffer(&mBuffer[0], status); | ||
status.valid = true; // TODO maybe use checksum for this | ||
mCallback(status); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include <set> | ||
|
||
#include "NETSGPClient.h" | ||
|
||
/// @brief Async version of NETSGPClient | ||
class AsyncNETSGPClient : public NETSGPClient | ||
{ | ||
/// @brief Callback function type definition for inverter status updates | ||
typedef void (*InverterStatusCallback)(const NETSGPClient::InverterStatus&); | ||
|
||
public: | ||
/// @brief Construct a new AsyncNETSGPClient object. | ||
/// | ||
/// @param stream Stream to communicate with the RF module | ||
/// @param progPin Programming enable pin of RF module (active low) | ||
/// @param interval The update interval in seconds, default is 2 seconds | ||
AsyncNETSGPClient(Stream& stream, const uint8_t progPin, const uint8_t interval = 2); | ||
|
||
/// @brief Set the callback for inverter status updates | ||
/// | ||
/// @param callback Callback that gets called on updates, may be nullptr | ||
void setStatusCallback(InverterStatusCallback callback) { mCallback = callback; } | ||
|
||
/// @brief Register a new inverter to receive status updates | ||
/// | ||
/// @param deviceID The device identifier of the inverter | ||
void registerInverter(const uint32_t deviceID) { mDevices.insert(deviceID); } | ||
|
||
/// @brief Deregister an inverter to not receive status updates | ||
/// | ||
/// @param deviceID The device identifier of the inverter | ||
void deregisterInverter(const uint32_t deviceID) { mDevices.erase(deviceID); } | ||
|
||
/// @brief Update the internal state | ||
/// | ||
/// @note Needs to be called inside loop() | ||
void update(); | ||
|
||
private: | ||
uint16_t mIntervalMS; /// Update interval in milliseconds | ||
uint32_t mLastUpdateMS; /// Last update time in milliseconds | ||
std::set<uint32_t> mDevices; /// All devices to poll | ||
InverterStatusCallback mCallback = nullptr; /// Callback for status updates | ||
}; |
Oops, something went wrong.