Hoymiles Lib: Move semaphore handing into parser base class
This commit is contained in:
parent
9ac6dd6e8d
commit
0260af9ada
@ -86,16 +86,9 @@ const std::array<const AlarmMessage_t, ALARM_MSG_COUNT> 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) {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
#include "Parser.h"
|
||||
#include <Arduino.h>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
@ -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<const AlarmMessage_t, ALARM_MSG_COUNT> _alarmMessages;
|
||||
|
||||
SemaphoreHandle_t _xSemaphore;
|
||||
};
|
||||
@ -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;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
#include "Parser.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#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;
|
||||
};
|
||||
@ -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 <cstring>
|
||||
|
||||
#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<uint8_t> GridProfileParser::getRawData()
|
||||
{
|
||||
std::vector<uint8_t> ret;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
#include "Parser.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#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<uint8_t> getRawData();
|
||||
|
||||
private:
|
||||
uint8_t _payloadGridProfile[GRID_PROFILE_SIZE] = {};
|
||||
uint8_t _gridProfileLength = 0;
|
||||
|
||||
SemaphoreHandle_t _xSemaphore;
|
||||
};
|
||||
@ -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;
|
||||
@ -13,3 +19,13 @@ void Parser::setLastUpdate(uint32_t lastUpdate)
|
||||
{
|
||||
_lastUpdate = lastUpdate;
|
||||
}
|
||||
|
||||
void Parser::beginAppendFragment()
|
||||
{
|
||||
HOY_SEMAPHORE_TAKE();
|
||||
}
|
||||
|
||||
void Parser::endAppendFragment()
|
||||
{
|
||||
HOY_SEMAPHORE_GIVE();
|
||||
}
|
||||
@ -1,7 +1,13 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <cstdint>
|
||||
|
||||
#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;
|
||||
};
|
||||
@ -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"
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
#include "Parser.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
class PowerCommandParser : public Parser {
|
||||
public:
|
||||
|
||||
@ -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++) {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
#include "Parser.h"
|
||||
#include <Arduino.h>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
|
||||
@ -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_t> _fieldSettings;
|
||||
|
||||
uint32_t _rxFailureCount = 0;
|
||||
|
||||
SemaphoreHandle_t _xSemaphore;
|
||||
};
|
||||
@ -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 <cstring>
|
||||
|
||||
#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();
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
#include "Parser.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#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;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user