Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feature/zendure_solarflow_new_dev
Browse files Browse the repository at this point in the history
vaterlangen committed Jan 25, 2025
2 parents a9819f9 + 6b1f4e8 commit 11f726f
Showing 4 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion include/gridcharger/huawei/HardwareInterface.h
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ class HardwareInterface {
};
void setParameter(Setting setting, float val);

std::unique_ptr<DataPointContainer> getCurrentData() { return std::move(_upDataCurrent); }
std::unique_ptr<DataPointContainer> getCurrentData();

static uint32_t constexpr DataRequestIntervalMillis = 2500;

53 changes: 39 additions & 14 deletions src/gridcharger/huawei/HardwareInterface.cpp
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ bool HardwareInterface::startLoop()
{
uint32_t constexpr stackSize = 3072;
return pdPASS == xTaskCreate(HardwareInterface::staticLoopHelper,
"HuaweiHwIfc", stackSize, this, 10/*prio*/, &_taskHandle);
"HuaweiHwIfc", stackSize, this, 16/*prio*/, &_taskHandle);
}

void HardwareInterface::stopLoop()
@@ -108,6 +108,13 @@ void HardwareInterface::loop()
_upDataInFlight->add<DataPointLabel::OutputCurrent>(value);
break;
}

// the OutputCurent value is the last value in a data request's answer
// among all values we process into the data point container, so we
// make the in-flight container the current container.
if (label == DataPointLabel::OutputCurrent) {
_upDataCurrent = std::move(_upDataInFlight);
}
}

size_t queueSize = _sendQueue.size();
@@ -135,20 +142,12 @@ void HardwareInterface::loop()

_nextRequestMillis = millis() + DataRequestIntervalMillis;

auto const& config = Configuration.get();
if (_upDataInFlight && config.Huawei.VerboseLogging) {
auto iter = _upDataInFlight->cbegin();
while (iter != _upDataInFlight->cend()) {
MessageOutput.printf("[Huawei::HwIfc] [%.3f] %s: %s%s\r\n",
static_cast<float>(iter->second.getTimestamp())/1000,
iter->second.getLabelText().c_str(),
iter->second.getValueText().c_str(),
iter->second.getUnitText().c_str());
++iter;
}
// this should be redundant, as every answer to a data request should
// have the OutputCurrent value, which is supposed to be the last value
// in the answer, and it already triggers moving the data in flight.
if (_upDataInFlight) {
_upDataCurrent = std::move(_upDataInFlight);
}

_upDataCurrent = std::move(_upDataInFlight);
}
}

@@ -170,8 +169,34 @@ void HardwareInterface::setParameter(HardwareInterface::Setting setting, float v
}

_sendQueue.push({setting, static_cast<uint16_t>(val)});
_nextRequestMillis = millis() - 1; // request param feedback immediately

xTaskNotifyGive(_taskHandle);
}

std::unique_ptr<DataPointContainer> HardwareInterface::getCurrentData()
{
std::unique_ptr<DataPointContainer> upData = nullptr;

{
std::lock_guard<std::mutex> lock(_mutex);
upData = std::move(_upDataCurrent);
}

auto const& config = Configuration.get();
if (upData && config.Huawei.VerboseLogging) {
auto iter = upData->cbegin();
while (iter != upData->cend()) {
MessageOutput.printf("[Huawei::HwIfc] [%.3f] %s: %s%s\r\n",
static_cast<float>(iter->second.getTimestamp())/1000,
iter->second.getLabelText().c_str(),
iter->second.getValueText().c_str(),
iter->second.getUnitText().c_str());
++iter;
}
}

return std::move(upData);
}

} // namespace GridCharger::Huawei
7 changes: 5 additions & 2 deletions src/gridcharger/huawei/MCP2515.cpp
Original file line number Diff line number Diff line change
@@ -16,8 +16,11 @@ void mcp2515Isr()
if (sIsrTaskHandle == nullptr) { return; }
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(sIsrTaskHandle, &xHigherPriorityTaskWoken);
// we assume we can wait until the lower-priority task is scheduled
// anyways, so we ignore xHigherPriorityTaskWoken == pdTRUE.
// make sure that the high-priority hardware interface task is scheduled,
// as the timing is very critical. CAN messages will be missed if the
// MCP2515 interrupt is not serviced immediately, as a new message
// overwrites a pending message.
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

std::optional<uint8_t> MCP2515::_oSpiBus = std::nullopt;
2 changes: 2 additions & 0 deletions webapp/src/views/PowerLimiterAdminView.vue
Original file line number Diff line number Diff line change
@@ -689,6 +689,8 @@ export default defineComponent({
newInv.is_behind_power_meter = true;
newInv.lower_power_limit = this.getLowerLimitMinimum(newInv);
newInv.upper_power_limit = Math.max(metaInv.max_power, 300);
newInv.use_overscaling_to_compensate_shading = false;
newInv.scaling_threshold = 98;
inverters.push(newInv);
}

0 comments on commit 11f726f

Please sign in to comment.