diff --git a/lib/Hoymiles/src/parser/AlarmLogParser.cpp b/lib/Hoymiles/src/parser/AlarmLogParser.cpp index 10ed305..2a6527a 100644 --- a/lib/Hoymiles/src/parser/AlarmLogParser.cpp +++ b/lib/Hoymiles/src/parser/AlarmLogParser.cpp @@ -86,16 +86,9 @@ const std::array AlarmLogParser::_alarmMe { AlarmMessageType_t::ALL, 9000, "Microinverter is suspected of being stolen" }, } }; -#define HOY_SEMAPHORE_TAKE() \ - do { \ - } while (xSemaphoreTake(_xSemaphore, portMAX_DELAY) != pdPASS) -#define HOY_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore) - AlarmLogParser::AlarmLogParser() : Parser() { - _xSemaphore = xSemaphoreCreateMutex(); - HOY_SEMAPHORE_GIVE(); // release before first use clearBuffer(); } @@ -115,16 +108,6 @@ void AlarmLogParser::appendFragment(uint8_t offset, uint8_t* payload, uint8_t le _alarmLogLength += len; } -void AlarmLogParser::beginAppendFragment() -{ - HOY_SEMAPHORE_TAKE(); -} - -void AlarmLogParser::endAppendFragment() -{ - HOY_SEMAPHORE_GIVE(); -} - uint8_t AlarmLogParser::getEntryCount() { if (_alarmLogLength < 2) { diff --git a/lib/Hoymiles/src/parser/AlarmLogParser.h b/lib/Hoymiles/src/parser/AlarmLogParser.h index 5c37589..a2c6b34 100644 --- a/lib/Hoymiles/src/parser/AlarmLogParser.h +++ b/lib/Hoymiles/src/parser/AlarmLogParser.h @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "Parser.h" -#include #include #include @@ -34,8 +33,6 @@ public: AlarmLogParser(); void clearBuffer(); void appendFragment(uint8_t offset, uint8_t* payload, uint8_t len); - void beginAppendFragment(); - void endAppendFragment(); uint8_t getEntryCount(); void getLogEntry(uint8_t entryId, AlarmLogEntry_t* entry); @@ -56,6 +53,4 @@ private: AlarmMessageType_t _messageType = AlarmMessageType_t::ALL; static const std::array _alarmMessages; - - SemaphoreHandle_t _xSemaphore; }; \ No newline at end of file diff --git a/lib/Hoymiles/src/parser/DevInfoParser.cpp b/lib/Hoymiles/src/parser/DevInfoParser.cpp index eab3a30..978af60 100644 --- a/lib/Hoymiles/src/parser/DevInfoParser.cpp +++ b/lib/Hoymiles/src/parser/DevInfoParser.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022 Thomas Basler and others + * Copyright (C) 2022 - 2023 Thomas Basler and others */ #include "DevInfoParser.h" #include "../Hoymiles.h" @@ -46,16 +46,9 @@ const devInfo_t devInfo[] = { { { 0x10, 0x33, 0x31, ALL }, 2250, "HMT-2250" } // 01 }; -#define HOY_SEMAPHORE_TAKE() \ - do { \ - } while (xSemaphoreTake(_xSemaphore, portMAX_DELAY) != pdPASS) -#define HOY_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore) - DevInfoParser::DevInfoParser() : Parser() { - _xSemaphore = xSemaphoreCreateMutex(); - HOY_SEMAPHORE_GIVE(); // release before first use clearBufferSimple(); clearBufferAll(); } @@ -92,16 +85,6 @@ void DevInfoParser::appendFragmentSimple(uint8_t offset, uint8_t* payload, uint8 _devInfoSimpleLength += len; } -void DevInfoParser::beginAppendFragment() -{ - HOY_SEMAPHORE_TAKE(); -} - -void DevInfoParser::endAppendFragment() -{ - HOY_SEMAPHORE_GIVE(); -} - uint32_t DevInfoParser::getLastUpdateAll() { return _lastUpdateAll; diff --git a/lib/Hoymiles/src/parser/DevInfoParser.h b/lib/Hoymiles/src/parser/DevInfoParser.h index b18bc8a..838ba11 100644 --- a/lib/Hoymiles/src/parser/DevInfoParser.h +++ b/lib/Hoymiles/src/parser/DevInfoParser.h @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "Parser.h" -#include #define DEV_INFO_SIZE 20 @@ -14,9 +13,6 @@ public: void clearBufferSimple(); void appendFragmentSimple(uint8_t offset, uint8_t* payload, uint8_t len); - void beginAppendFragment(); - void endAppendFragment(); - uint32_t getLastUpdateAll(); void setLastUpdateAll(uint32_t lastUpdate); @@ -47,6 +43,4 @@ private: uint8_t _payloadDevInfoSimple[DEV_INFO_SIZE] = {}; uint8_t _devInfoSimpleLength = 0; - - SemaphoreHandle_t _xSemaphore; }; \ No newline at end of file diff --git a/lib/Hoymiles/src/parser/GridProfileParser.cpp b/lib/Hoymiles/src/parser/GridProfileParser.cpp index ff69c3d..35f7689 100644 --- a/lib/Hoymiles/src/parser/GridProfileParser.cpp +++ b/lib/Hoymiles/src/parser/GridProfileParser.cpp @@ -1,21 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022 Thomas Basler and others + * Copyright (C) 2023 Thomas Basler and others */ #include "GridProfileParser.h" #include "../Hoymiles.h" #include -#define HOY_SEMAPHORE_TAKE() \ - do { \ - } while (xSemaphoreTake(_xSemaphore, portMAX_DELAY) != pdPASS) -#define HOY_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore) - GridProfileParser::GridProfileParser() : Parser() { - _xSemaphore = xSemaphoreCreateMutex(); - HOY_SEMAPHORE_GIVE(); // release before first use clearBuffer(); } @@ -35,16 +28,6 @@ void GridProfileParser::appendFragment(uint8_t offset, uint8_t* payload, uint8_t _gridProfileLength += len; } -void GridProfileParser::beginAppendFragment() -{ - HOY_SEMAPHORE_TAKE(); -} - -void GridProfileParser::endAppendFragment() -{ - HOY_SEMAPHORE_GIVE(); -} - std::vector GridProfileParser::getRawData() { std::vector ret; diff --git a/lib/Hoymiles/src/parser/GridProfileParser.h b/lib/Hoymiles/src/parser/GridProfileParser.h index fba7066..c2af52f 100644 --- a/lib/Hoymiles/src/parser/GridProfileParser.h +++ b/lib/Hoymiles/src/parser/GridProfileParser.h @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "Parser.h" -#include #define GRID_PROFILE_SIZE 141 @@ -11,14 +10,9 @@ public: void clearBuffer(); void appendFragment(uint8_t offset, uint8_t* payload, uint8_t len); - void beginAppendFragment(); - void endAppendFragment(); - std::vector getRawData(); private: uint8_t _payloadGridProfile[GRID_PROFILE_SIZE] = {}; uint8_t _gridProfileLength = 0; - - SemaphoreHandle_t _xSemaphore; }; \ No newline at end of file diff --git a/lib/Hoymiles/src/parser/Parser.cpp b/lib/Hoymiles/src/parser/Parser.cpp index 94c694c..b8e5e0e 100644 --- a/lib/Hoymiles/src/parser/Parser.cpp +++ b/lib/Hoymiles/src/parser/Parser.cpp @@ -1,9 +1,15 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022 Thomas Basler and others + * Copyright (C) 2022 - 2023 Thomas Basler and others */ #include "Parser.h" +Parser::Parser() +{ + _xSemaphore = xSemaphoreCreateMutex(); + HOY_SEMAPHORE_GIVE(); // release before first use +} + uint32_t Parser::getLastUpdate() { return _lastUpdate; @@ -12,4 +18,14 @@ uint32_t Parser::getLastUpdate() void Parser::setLastUpdate(uint32_t lastUpdate) { _lastUpdate = lastUpdate; +} + +void Parser::beginAppendFragment() +{ + HOY_SEMAPHORE_TAKE(); +} + +void Parser::endAppendFragment() +{ + HOY_SEMAPHORE_GIVE(); } \ No newline at end of file diff --git a/lib/Hoymiles/src/parser/Parser.h b/lib/Hoymiles/src/parser/Parser.h index ccb486b..5d6df75 100644 --- a/lib/Hoymiles/src/parser/Parser.h +++ b/lib/Hoymiles/src/parser/Parser.h @@ -1,7 +1,13 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once +#include #include +#define HOY_SEMAPHORE_TAKE() \ + do { \ + } while (xSemaphoreTake(_xSemaphore, portMAX_DELAY) != pdPASS) +#define HOY_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore) + typedef enum { CMD_OK, CMD_NOK, @@ -10,9 +16,16 @@ typedef enum { class Parser { public: + Parser(); uint32_t getLastUpdate(); void setLastUpdate(uint32_t lastUpdate); + void beginAppendFragment(); + void endAppendFragment(); + +protected: + SemaphoreHandle_t _xSemaphore; + private: uint32_t _lastUpdate = 0; }; \ No newline at end of file diff --git a/lib/Hoymiles/src/parser/PowerCommandParser.cpp b/lib/Hoymiles/src/parser/PowerCommandParser.cpp index 0ba3a8a..d698dad 100644 --- a/lib/Hoymiles/src/parser/PowerCommandParser.cpp +++ b/lib/Hoymiles/src/parser/PowerCommandParser.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022 Thomas Basler and others + * Copyright (C) 2022 - 2023 Thomas Basler and others */ #include "PowerCommandParser.h" diff --git a/lib/Hoymiles/src/parser/PowerCommandParser.h b/lib/Hoymiles/src/parser/PowerCommandParser.h index 6aa042f..e005812 100644 --- a/lib/Hoymiles/src/parser/PowerCommandParser.h +++ b/lib/Hoymiles/src/parser/PowerCommandParser.h @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "Parser.h" -#include class PowerCommandParser : public Parser { public: diff --git a/lib/Hoymiles/src/parser/StatisticsParser.cpp b/lib/Hoymiles/src/parser/StatisticsParser.cpp index ad75cce..d415fc3 100644 --- a/lib/Hoymiles/src/parser/StatisticsParser.cpp +++ b/lib/Hoymiles/src/parser/StatisticsParser.cpp @@ -1,15 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022 Thomas Basler and others + * Copyright (C) 2022 - 2023 Thomas Basler and others */ #include "StatisticsParser.h" #include "../Hoymiles.h" -#define HOY_SEMAPHORE_TAKE() \ - do { \ - } while (xSemaphoreTake(_xSemaphore, portMAX_DELAY) != pdPASS) -#define HOY_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore) - static float calcYieldTotalCh0(StatisticsParser* iv, uint8_t arg0); static float calcYieldDayCh0(StatisticsParser* iv, uint8_t arg0); static float calcUdcCh(StatisticsParser* iv, uint8_t arg0); @@ -62,8 +57,6 @@ const FieldId_t dailyProductionFields[] = { StatisticsParser::StatisticsParser() : Parser() { - _xSemaphore = xSemaphoreCreateMutex(); - HOY_SEMAPHORE_GIVE(); // release before first use clearBuffer(); } @@ -101,16 +94,6 @@ void StatisticsParser::appendFragment(uint8_t offset, uint8_t* payload, uint8_t _statisticLength += len; } -void StatisticsParser::beginAppendFragment() -{ - HOY_SEMAPHORE_TAKE(); -} - -void StatisticsParser::endAppendFragment() -{ - HOY_SEMAPHORE_GIVE(); -} - const byteAssign_t* StatisticsParser::getAssignmentByChannelField(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId) { for (uint8_t i = 0; i < _byteAssignmentSize; i++) { diff --git a/lib/Hoymiles/src/parser/StatisticsParser.h b/lib/Hoymiles/src/parser/StatisticsParser.h index 91cf645..4423f1f 100644 --- a/lib/Hoymiles/src/parser/StatisticsParser.h +++ b/lib/Hoymiles/src/parser/StatisticsParser.h @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "Parser.h" -#include #include #include @@ -107,8 +106,6 @@ public: StatisticsParser(); void clearBuffer(); void appendFragment(uint8_t offset, uint8_t* payload, uint8_t len); - void beginAppendFragment(); - void endAppendFragment(); void setByteAssignment(const byteAssign_t* byteAssignment, uint8_t size); @@ -157,6 +154,4 @@ private: std::list _fieldSettings; uint32_t _rxFailureCount = 0; - - SemaphoreHandle_t _xSemaphore; }; \ No newline at end of file diff --git a/lib/Hoymiles/src/parser/SystemConfigParaParser.cpp b/lib/Hoymiles/src/parser/SystemConfigParaParser.cpp index 2756e1e..d2d6365 100644 --- a/lib/Hoymiles/src/parser/SystemConfigParaParser.cpp +++ b/lib/Hoymiles/src/parser/SystemConfigParaParser.cpp @@ -1,21 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022 Thomas Basler and others + * Copyright (C) 2022 - 2023 Thomas Basler and others */ #include "SystemConfigParaParser.h" #include "../Hoymiles.h" #include -#define HOY_SEMAPHORE_TAKE() \ - do { \ - } while (xSemaphoreTake(_xSemaphore, portMAX_DELAY) != pdPASS) -#define HOY_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore) - SystemConfigParaParser::SystemConfigParaParser() : Parser() { - _xSemaphore = xSemaphoreCreateMutex(); - HOY_SEMAPHORE_GIVE(); // release before first use clearBuffer(); } @@ -35,16 +28,6 @@ void SystemConfigParaParser::appendFragment(uint8_t offset, uint8_t* payload, ui _payloadLength += len; } -void SystemConfigParaParser::beginAppendFragment() -{ - HOY_SEMAPHORE_TAKE(); -} - -void SystemConfigParaParser::endAppendFragment() -{ - HOY_SEMAPHORE_GIVE(); -} - float SystemConfigParaParser::getLimitPercent() { HOY_SEMAPHORE_TAKE(); diff --git a/lib/Hoymiles/src/parser/SystemConfigParaParser.h b/lib/Hoymiles/src/parser/SystemConfigParaParser.h index 4ec7381..37e2fa7 100644 --- a/lib/Hoymiles/src/parser/SystemConfigParaParser.h +++ b/lib/Hoymiles/src/parser/SystemConfigParaParser.h @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "Parser.h" -#include #define SYSTEM_CONFIG_PARA_SIZE 16 @@ -10,8 +9,6 @@ public: SystemConfigParaParser(); void clearBuffer(); void appendFragment(uint8_t offset, uint8_t* payload, uint8_t len); - void beginAppendFragment(); - void endAppendFragment(); float getLimitPercent(); void setLimitPercent(float value); @@ -35,6 +32,4 @@ private: uint32_t _lastUpdateCommand = 0; uint32_t _lastUpdateRequest = 0; - - SemaphoreHandle_t _xSemaphore; }; \ No newline at end of file