Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support VP230 for Huawei AC charger #1482

Merged
merged 22 commits into from
Jan 6, 2025

Conversation

schlimmchen
Copy link
Member

There is a lot more in this PR under the hood, all concerning the Huawei grid charger, especially restructuring into namespace, splitting the driver and the controller, removing code duplication (web API JSON creation, (de)serialization of settings), etc.

@schlimmchen schlimmchen linked an issue Dec 26, 2024 that may be closed by this pull request
src/Configuration.cpp Show resolved Hide resolved
src/Configuration.cpp Show resolved Hide resolved
src/main.cpp Outdated Show resolved Hide resolved
webapp/src/locales/de.json Outdated Show resolved Hide resolved
webapp/src/types/HuaweiDataStatus.ts Show resolved Hide resolved
webapp/src/locales/fr.json Show resolved Hide resolved
src/gridcharger/huawei/Controller.cpp Outdated Show resolved Hide resolved
src/gridcharger/huawei/Controller.cpp Show resolved Hide resolved
src/WebApi_Huawei.cpp Show resolved Hide resolved
src/gridcharger/huawei/Controller.cpp Outdated Show resolved Hide resolved
include/gridcharger/huawei/HardwareInterface.h Outdated Show resolved Hide resolved
src/WebApi_Huawei.cpp Show resolved Hide resolved
src/gridcharger/huawei/Controller.cpp Show resolved Hide resolved
src/gridcharger/huawei/MCP2515.cpp Outdated Show resolved Hide resolved
webapp/src/locales/de.json Outdated Show resolved Hide resolved
use separate files to hold the controller logic and the CAN/data
handling parts of the Huawei AC charger implementation.

move the respective classes to new file system paths and C++ namespaces
in the process.
this change only shows a few added/removed newlines when inspecting the
commit using `git show --ignore-all-space`.
the ESP is restarted, so the removed code is not executed at all.
* move conversion of PSU-specific values to floats with SI units into
  hardware interface.
* use enum class values to identify settings and values.
* use a queue to manage settings to be sent.
* use a map to manage received values, including the timestamp they were
  received.
* move pin handling down to hardware interface implementation, as only
  it knows what pins to use for what and another implementation will use
  a different set of pin definitions.
* make the power pin to control the slot detect relay optional.
these pins will be used to talk directly to a CAN transceiver using the
TWAI controller.
this changeset adds support for talking to the Huawei grid charger using
a CAN transceiver like the VP230 on the OpenDTU Fusion CAN/Iso shield.
we need the ESP32's TWAI controller for that, so this feature conflicts
with the Pylontech (and all other battery providers using CAN) battery
implementation.

the user selects which hardware interface to use in the web UI/config.
MCP215: make event-driven. in particular, this allows us to sleep for
some time in the loop task instead of only yield()ing, which effectively
keeps the core busy all the time because of this task. the newly added
ISR now wakes the loop task once the IRQ pin goes low.

use unique_ptr<> to manage the lifetime of the MCP2515 CAN lib object as
well as the respective SPI host object.
instead of using a large receive queue and a large stack to handle it
all, we now use a mechanism similar to the MCP2515 ISR, which alerts the
hardware interface of inbound messages once they are available. this is
done by creating another task which blocks on twai_read_alerts() and
tests if new messages arrived. if so, the upstream task is notified and
can process these messages in time.
@schlimmchen schlimmchen force-pushed the schlimmchen/feature/huawei-twai branch from 2dba698 to 45f08bd Compare January 6, 2025 19:33
@schlimmchen
Copy link
Member Author

For transparency, this is what I did:

  • Rebased onto current development
  • Applied yarn prettier and fixed up the respective commit "Feature: huawei grid charger: support serial CAN controller"
  • Used Andreas' suggestion to rename _dataRequestIntervalMillis and fixed up commit "huawei grid charger: merge common code in base class" (the commit I added based on his suggestion using the Github UI was incomplete as it only renamed the variable in the header, but not its uses).

it seems we are not supposed to do that, but instead use the
FreeRTOS-specific functions and structures without #includ'ing
the supposedly correct headers.
since this is really about using the internal TWAI controller and "any"
compatible external CAN transceiver, we rename the setting.
it is likely that the previous implementation for the MCP2515 CAN
controller and transceiver communicating with the Huawei charger did
work even without the IRQ pin in use. the new implementation will miss
CAN messages if the IRQ pin is not connected or not defined, because it
is event-driven, rather than polling with maximum frequency.

to avoid people yelling at us because their insane setup worked before
but not does not any more, we mark this to be a breaking change.
@schlimmchen schlimmchen merged commit f435c3c into development Jan 6, 2025
16 checks passed
@schlimmchen schlimmchen deleted the schlimmchen/feature/huawei-twai branch January 6, 2025 20:43
@drahdiwaberl
Copy link

oh. hope i can give it a try soon 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Request] Support for Huawei R4850G2 via SN64HVD230DR
4 participants