mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
Compare commits
224 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d8153c48bb | ||
![]() |
f3a6157080 | ||
![]() |
867512eecd | ||
![]() |
f9109d0348 | ||
![]() |
9943406836 | ||
![]() |
18ee9d6c27 | ||
![]() |
31ea1f0928 | ||
![]() |
dad97b36e1 | ||
![]() |
19a1634f4e | ||
![]() |
aa375dc36a | ||
![]() |
a91f8ab4d4 | ||
![]() |
7fbc9ffcc6 | ||
![]() |
579e0e0bcc | ||
![]() |
b26c451eaf | ||
![]() |
ee9e78e80b | ||
![]() |
706b4a7cea | ||
![]() |
f5ba607fa6 | ||
![]() |
572867b7ad | ||
![]() |
47e715ffe5 | ||
![]() |
c445bd1869 | ||
![]() |
28c0267cae | ||
![]() |
4058050423 | ||
![]() |
04d9a36292 | ||
![]() |
29129037b0 | ||
![]() |
c6b7ff82c0 | ||
![]() |
95ee6ff9ae | ||
![]() |
8cc10a1b71 | ||
![]() |
3ef3279527 | ||
![]() |
f48b4235c1 | ||
![]() |
cdf6314bff | ||
![]() |
48411680c6 | ||
![]() |
132029169d | ||
![]() |
483d4300b1 | ||
![]() |
397e8d03a1 | ||
![]() |
d336b75f56 | ||
![]() |
a7af7cf938 | ||
![]() |
2ba937bd32 | ||
![]() |
48d416b5c4 | ||
![]() |
ed2ebb00fd | ||
![]() |
0458267634 | ||
![]() |
a0de6b092b | ||
![]() |
0f2cbe8f04 | ||
![]() |
983105ab6a | ||
![]() |
5aa657e0b5 | ||
![]() |
69ae0385fb | ||
![]() |
a8d74f5885 | ||
![]() |
20b6ea5e85 | ||
![]() |
b8bbb02b20 | ||
![]() |
4896f3061a | ||
![]() |
0aaab6d4b7 | ||
![]() |
a12ea4b112 | ||
![]() |
e023962bfc | ||
![]() |
4df42e10b4 | ||
![]() |
ee4981b6e1 | ||
![]() |
172e260167 | ||
![]() |
fd52c0e5e7 | ||
![]() |
6982476e89 | ||
![]() |
24c1ce73ae | ||
![]() |
d8530a2b8b | ||
![]() |
7a5cd36e6d | ||
![]() |
3bfc350b65 | ||
![]() |
b52bc7bfd4 | ||
![]() |
89abc6a964 | ||
![]() |
45643237e4 | ||
![]() |
e66161176b | ||
![]() |
269c655dc5 | ||
![]() |
15143d1384 | ||
![]() |
0244468624 | ||
![]() |
3ead4d12d4 | ||
![]() |
5277665dd1 | ||
![]() |
79964a0601 | ||
![]() |
e11843e4a0 | ||
![]() |
df52d067e7 | ||
![]() |
1ea663c0b9 | ||
![]() |
73c6821a9a | ||
![]() |
26126bae1a | ||
![]() |
980e450871 | ||
![]() |
c7bb82c1de | ||
![]() |
a287d0e208 | ||
![]() |
50d794d0de | ||
![]() |
332e982bed | ||
![]() |
9ee0dffb33 | ||
![]() |
6094a2c85b | ||
![]() |
b5d14edb94 | ||
![]() |
00a820f007 | ||
![]() |
34466de3a7 | ||
![]() |
bf14553d77 | ||
![]() |
bc2e49fb5d | ||
![]() |
fdc1fb61ba | ||
![]() |
2546b6da21 | ||
![]() |
7178e0376e | ||
![]() |
5510d3aeb5 | ||
![]() |
9554cbf808 | ||
![]() |
082c005a20 | ||
![]() |
5b7491c7a7 | ||
![]() |
018cd4ed52 | ||
![]() |
0aad11d9bc | ||
![]() |
29e6f52c4c | ||
![]() |
25393106b8 | ||
![]() |
fd2e5f2e52 | ||
![]() |
b33f42c9c5 | ||
![]() |
5246cd34c9 | ||
![]() |
a336ac73fb | ||
![]() |
a2a00a488f | ||
![]() |
c7b6d0adee | ||
![]() |
9fe83fb131 | ||
![]() |
62d0d59e74 | ||
![]() |
2e859a1ee6 | ||
![]() |
9b6f5409c2 | ||
![]() |
57c65e2eeb | ||
![]() |
8ba6a04d61 | ||
![]() |
47ceaf9a7b | ||
![]() |
521ab481d7 | ||
![]() |
ac153ec901 | ||
![]() |
fc109cd954 | ||
![]() |
5f73a4c32b | ||
![]() |
f609427e00 | ||
![]() |
edb69472c3 | ||
![]() |
d8d64ee16c | ||
![]() |
db9537a34b | ||
![]() |
577a353285 | ||
![]() |
42353efdff | ||
![]() |
454a4565c0 | ||
![]() |
bf7d10c825 | ||
![]() |
5ae8155866 | ||
![]() |
8354e554e4 | ||
![]() |
eb44ea7f42 | ||
![]() |
96b3293023 | ||
![]() |
69b0d23b45 | ||
![]() |
d481947e34 | ||
![]() |
b5ebcdbcd7 | ||
![]() |
c6ad1f8afe | ||
![]() |
354926a6b3 | ||
![]() |
3767c698bd | ||
![]() |
b115abf081 | ||
![]() |
036f9aa4b9 | ||
![]() |
5555b38fea | ||
![]() |
7bbbf846d8 | ||
![]() |
5b277d633b | ||
![]() |
5bb12915fe | ||
![]() |
93b30241da | ||
![]() |
30a7b9d90e | ||
![]() |
e02cb61efc | ||
![]() |
c01291d15f | ||
![]() |
3c4880e783 | ||
![]() |
3172c32cc7 | ||
![]() |
7d8accb95d | ||
![]() |
fd9d1ec714 | ||
![]() |
7f8f48756d | ||
![]() |
b205b63af3 | ||
![]() |
64a3d5f5aa | ||
![]() |
a40de5ecee | ||
![]() |
99b79eab7e | ||
![]() |
9662054a4f | ||
![]() |
29aecc577b | ||
![]() |
cfdc1a3130 | ||
![]() |
b40387817d | ||
![]() |
7903805373 | ||
![]() |
282b27ff5d | ||
![]() |
1b012fb2d0 | ||
![]() |
54f9cb49f3 | ||
![]() |
b17c9ad106 | ||
![]() |
3764ab4bf9 | ||
![]() |
c1f3187306 | ||
![]() |
a8532b6f78 | ||
![]() |
a9185be603 | ||
![]() |
91bbb25270 | ||
![]() |
2ef8055535 | ||
![]() |
8fe21fddb7 | ||
![]() |
5770df46e4 | ||
![]() |
bd0923cab3 | ||
![]() |
3597a99a08 | ||
![]() |
805d506062 | ||
![]() |
e38b6286c7 | ||
![]() |
805b3e10d2 | ||
![]() |
08b6c81e67 | ||
![]() |
0617bf4b8c | ||
![]() |
21870349d4 | ||
![]() |
eba1b640cf | ||
![]() |
90d3332143 | ||
![]() |
63100d2a37 | ||
![]() |
57009c6f72 | ||
![]() |
778d9b8585 | ||
![]() |
630c67a482 | ||
![]() |
081d96e055 | ||
![]() |
53d40cbe51 | ||
![]() |
da560e1629 | ||
![]() |
bb21b5d8e1 | ||
![]() |
f03324585b | ||
![]() |
bf6e4c8a0f | ||
![]() |
21eda56c9e | ||
![]() |
58af5b658b | ||
![]() |
224c33ec1d | ||
![]() |
3e56549498 | ||
![]() |
77b1844151 | ||
![]() |
a0b0fbd5d6 | ||
![]() |
fb62b2cdb1 | ||
![]() |
1cc4a021c2 | ||
![]() |
aba193ca85 | ||
![]() |
7328f7b99b | ||
![]() |
688ba0388c | ||
![]() |
dabbcd8bcd | ||
![]() |
955688fec0 | ||
![]() |
6f76bdfeb0 | ||
![]() |
4d0777ce52 | ||
![]() |
12cc542a42 | ||
![]() |
5c3aaf0a22 | ||
![]() |
cf68489bf8 | ||
![]() |
024ff58965 | ||
![]() |
21b2b06dab | ||
![]() |
7ee0eb5e88 | ||
![]() |
ee4b14c770 | ||
![]() |
7cc5d368d1 | ||
![]() |
9031d3e5cf | ||
![]() |
6253cd678b | ||
![]() |
7ded4f1662 | ||
![]() |
13df59f806 | ||
![]() |
dc4aa95109 | ||
![]() |
d38a8d6655 | ||
![]() |
36493a89cc | ||
![]() |
d750201795 | ||
![]() |
d1d1ab9f5f | ||
![]() |
195755b21e | ||
![]() |
2b42641c6b |
204 changed files with 4051 additions and 3343 deletions
16
.github/ISSUE_TEMPLATE.md
vendored
16
.github/ISSUE_TEMPLATE.md
vendored
|
@ -16,13 +16,11 @@
|
|||
|
||||
### Settings
|
||||
|
||||
<!-- Please fill in the settings used below from USER_SETTINGS.h, as it will help with diagnosis. -->
|
||||
<!-- Please attach screenshot of configuration for easier debugging, as it will help with diagnosis. -->
|
||||
|
||||
- Software version: ``
|
||||
- Battery used: ``
|
||||
- Inverter communication protocol: ``
|
||||
- Hardware used for Battery-Emulator: `HW_LILYGO, HW_STARK, Custom`
|
||||
- CONTACTOR_CONTROL: `yes/no`
|
||||
- CAN_ADDON: `yes/no`
|
||||
- WEBSERVER: `yes/no`
|
||||
- MQTT: `yes/no`
|
||||
- Software version: X.Y.Z
|
||||
- Battery used: [Nissan LEAF]
|
||||
- Inverter communication protocol: [BYD Modbus]
|
||||
- Hardware used for Battery-Emulator: [LilyGo T-CAN/Stark CMR/LilyGo T-2CAN]
|
||||
- GPIO controlled contactors: [yes/no]
|
||||
- MQTT: [yes/no]
|
||||
|
|
10
.github/ISSUE_TEMPLATE/bug_report.md
vendored
10
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
@ -20,10 +20,10 @@ A clear and concise description of what you expected to happen.
|
|||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Version and settings (please complete the following information):**
|
||||
- Please attach your USER_SETTINGS files for easier debugging
|
||||
- Please attach screenshot of configuration for easier debugging
|
||||
- Software version: X.Y.Z
|
||||
- Battery used: [NISSAN_LEAF]
|
||||
- Inverter communication protocol: [BYD_MODBUS]
|
||||
- Hardware used for Battery-Emulator: [HW_LILYGO/HW_STARK/HW_DEVKIT]
|
||||
- CONTACTOR_CONTROL: [yes/no]
|
||||
- Battery used: [Nissan LEAF]
|
||||
- Inverter communication protocol: [BYD Modbus]
|
||||
- Hardware used for Battery-Emulator: [LilyGo T-CAN/Stark CMR/LilyGo T-2CAN]
|
||||
- GPIO controlled contactors: [yes/no]
|
||||
- MQTT: [yes/no]
|
||||
|
|
|
@ -38,16 +38,12 @@ jobs:
|
|||
~/.platformio/.cache
|
||||
key: ${{ runner.os }}-pio
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Install PlatformIO Core
|
||||
run: pip install --upgrade platformio
|
||||
|
||||
# Copy USER_SECRETS.TEMPLATE.h to USER_SECRETS.h
|
||||
- name: Copy USER_SECRETS.TEMPLATE.h to USER_SECRETS.h
|
||||
run: cp ./Software/USER_SECRETS.TEMPLATE.h ./Software/USER_SECRETS.h
|
||||
|
||||
- name: Build image for Lilygo
|
||||
run: pio run -e lilygo_2CAN_330
|
||||
|
||||
|
|
|
@ -38,16 +38,12 @@ jobs:
|
|||
~/.platformio/.cache
|
||||
key: ${{ runner.os }}-pio
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Install PlatformIO Core
|
||||
run: pip install --upgrade platformio
|
||||
|
||||
# Copy USER_SECRETS.TEMPLATE.h to USER_SECRETS.h
|
||||
- name: Copy USER_SECRETS.TEMPLATE.h to USER_SECRETS.h
|
||||
run: cp ./Software/USER_SECRETS.TEMPLATE.h ./Software/USER_SECRETS.h
|
||||
|
||||
- name: Build image for Lilygo
|
||||
run: pio run -e lilygo_330
|
||||
|
||||
|
|
|
@ -38,16 +38,12 @@ jobs:
|
|||
~/.platformio/.cache
|
||||
key: ${{ runner.os }}-pio
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Install PlatformIO Core
|
||||
run: pip install --upgrade platformio
|
||||
|
||||
# Copy USER_SECRETS.TEMPLATE.h to USER_SECRETS.h
|
||||
- name: Copy USER_SECRETS.TEMPLATE.h to USER_SECRETS.h
|
||||
run: cp ./Software/USER_SECRETS.TEMPLATE.h ./Software/USER_SECRETS.h
|
||||
|
||||
- name: Build image for Stark CMR
|
||||
run: pio run -e stark_330
|
||||
|
||||
|
|
8
.github/workflows/release-assets.yml
vendored
8
.github/workflows/release-assets.yml
vendored
|
@ -41,16 +41,12 @@ jobs:
|
|||
~/.platformio/.cache
|
||||
key: ${{ runner.os }}-pio
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Install PlatformIO Core
|
||||
run: pip install --upgrade platformio
|
||||
|
||||
# Copy USER_SECRETS.TEMPLATE.h to USER_SECRETS.h
|
||||
- name: Copy USER_SECRETS.TEMPLATE.h to USER_SECRETS.h
|
||||
run: cp ./Software/USER_SECRETS.TEMPLATE.h ./Software/USER_SECRETS.h
|
||||
|
||||
- name: 🛠 Build ota image for Lilygo T-CAN
|
||||
run: |
|
||||
pio run -e lilygo_330
|
||||
|
@ -68,7 +64,7 @@ jobs:
|
|||
|
||||
- name: 🛠 Build factory image for Lilygo 2-CAN
|
||||
run: |
|
||||
esptool --chip esp32 merge-bin -o .pio/build/lilygo_2CAN_330/factory.bin --flash-mode dio --flash-freq 40m --flash-size 4MB 0x1000 .pio/build/lilygo_2CAN_330/bootloader.bin 0x8000 .pio/build/lilygo_2CAN_330/partitions.bin 0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/lilygo_2CAN_330/firmware.bin
|
||||
esptool --chip esp32s3 merge-bin -o .pio/build/lilygo_2CAN_330/factory.bin --flash-mode dio --flash-freq 40m --flash-size 16MB 0x0000 .pio/build/lilygo_2CAN_330/bootloader.bin 0x8000 .pio/build/lilygo_2CAN_330/partitions.bin 0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/lilygo_2CAN_330/firmware.bin
|
||||
mv .pio/build/lilygo_2CAN_330/factory.bin output/BE_${{ steps.vars.outputs.tag }}_LilygoT-2CAN.factory.bin
|
||||
|
||||
- name: 🛠 Build ota image for Stark
|
||||
|
|
1
.github/workflows/unit-tests.yml
vendored
1
.github/workflows/unit-tests.yml
vendored
|
@ -13,7 +13,6 @@ jobs:
|
|||
|
||||
- name: Configure and build with CMake
|
||||
run: |
|
||||
cp Software/USER_SECRETS.TEMPLATE.h Software/USER_SECRETS.h
|
||||
cd test
|
||||
mkdir build
|
||||
cd build
|
||||
|
|
|
@ -10,7 +10,7 @@ ci:
|
|||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: v20.1.8
|
||||
rev: v21.1.0
|
||||
hooks:
|
||||
- id: clang-format
|
||||
args: [-Werror] # change formatting warnings to errors, hook includes -i (Inplace edit) by default
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
### Contributing to the Battery-Emulator project
|
||||
|
||||
What can I do?
|
||||
What can I do? 🦸
|
||||
--------------
|
||||
|
||||
**"Help - I want to contribute something, but I don't know what?"**
|
||||
|
@ -15,10 +15,66 @@ You're in luck. There's various sources to contribute:
|
|||
- [Discussion page](https://github.com/dalathegreat/Battery-Emulator/discussions)
|
||||
- [Discord server](https://www.patreon.com/dala)
|
||||
|
||||
## Notes on embedded system
|
||||
The Battery-Emulator is a real-time control system, which performs lots of time critical operations. Some operations, like contactor control, need to complete within 10 milliseconds periodically. The resources of the ESP32 microcontroller is limited, so keeping track of CPU and memory usage is essential. Keep this in mind when coding for the system! Performance profiling the system can be done by enabling the FUNCTION_TIME_MEASUREMENT option in the USER_SETTINGS.h file
|
||||
## Notes on embedded system 🕙
|
||||
The Battery-Emulator is a real-time control system, which performs lots of time critical operations. Some operations, like contactor control, need to complete within 10 milliseconds periodically. The resources of the ESP32 microcontroller is limited, so keeping track of CPU and memory usage is essential. Keep this in mind when coding for the system! Performance profiling the system can be done by enabling the "Enable performance profiling:" option in the webserver
|
||||
|
||||
## Code formatting
|
||||
## Setting up the compilation environment (VScode + PlatformIO) 💻
|
||||
|
||||
This project uses the PlatformIO extension within Visual Studio Code for development and uploading. It handles all the complex toolchains and library management for you.
|
||||
### 1. Installing VSCode
|
||||
- Download the stable build of Visual Studio Code for your operating system (Windows, macOS, or Linux) from the official website: https://code.visualstudio.com/
|
||||
- Run the installer and follow the setup instructions.
|
||||
- (Recommended) Launch VSCode after installation.
|
||||
|
||||
### 2. Installing the PlatformIO IDE Plugin
|
||||
|
||||
PlatformIO is an extension that adds all the necessary functionality to VSCode.
|
||||
- Inside VSCode, open the Extensions view by:
|
||||
- Clicking the Extensions icon in the Activity Bar on the left side.
|
||||
- Or using the keyboard shortcut: Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (macOS).
|
||||
- In the extensions search bar, type: PlatformIO IDE.
|
||||
- Find the extension published by PlatformIO and click the Install button.
|
||||
- Wait for the installation to complete. This may take a few minutes as PlatformIO downloads and installs its core tools in the background. VSCode might require a reload once finished.
|
||||
|
||||
### 3. Opening the Project and Building
|
||||
- Clone the repository to your local machine using Git.
|
||||
- In VSCode:
|
||||
- Go to File > Open Folder...
|
||||
- Navigate to and select the root folder of the cloned project (the folder containing the platformio.ini file).
|
||||
- Click Open.
|
||||
- PlatformIO will automatically recognize the project structure and begin indexing the code. You'll see the PlatformIO icon (a grey alien) appear in the Activity Bar on the left.
|
||||
|
||||
- To verify everything is set up correctly, build/compile the project:
|
||||
- Click the PlatformIO icon in the Activity Bar to open the PIO Home screen.
|
||||
- Go to Quick Access > PIO > Build.
|
||||
- Alternatively, you can use the checkmark icon in the blue status bar at the bottom of the VSCode window, or the keyboard shortcut Ctrl+Alt+B (Windows/Linux) / Cmd+Alt+B (macOS).
|
||||
- The build process will start. You can monitor the output in the integrated terminal. A successful build will end with ===== [SUCCESS] Took X.XX seconds =====.
|
||||
|
||||
### 4. Uploading Code to Board via USB
|
||||
|
||||
- Connect your Battery-Emulator hardware to your computer using a USB cable.
|
||||
- Select the right board type (Stark, LilyGo)
|
||||
- At the bottom left of VScode, click the Env to bring up a menu of boards. Select the board you are using
|
||||
<img width="396" height="95" alt="image" src="https://github.com/user-attachments/assets/23b73442-5016-4ff1-be78-13e3c41772d5" />
|
||||
<img width="679" height="177" alt="image" src="https://github.com/user-attachments/assets/2fad40a6-f388-4cd6-8e08-844602bb0442" />
|
||||
|
||||
- Ensure the correct upload port is set in the platformio.ini file (it's often auto-detected, but you may need to set it manually. See Troubleshooting below).
|
||||
- Upload the code:
|
||||
- Click the PlatformIO icon in the Activity Bar.
|
||||
- Go to Quick Access > PIO > Upload.
|
||||
- Alternatively, use the right-arrow icon (→) in the blue status bar at the bottom of the VSCode window, or the keyboard shortcut Ctrl+Alt+U (Windows/Linux) / Cmd+Alt+U (macOS).
|
||||
- The upload process will begin. The board may reset automatically. A successful upload will end with ===== [SUCCESS] Took X.XX seconds =====.
|
||||
|
||||
### ⚠️ Troubleshooting & Tips
|
||||
|
||||
#### "Upload port not found" or wrong port errors:
|
||||
|
||||
- Find the correct port:
|
||||
- Windows: Check Device Manager under "Ports (COM & LPT)". It's usually COM3, COM4, etc.
|
||||
- macOS/Linux: Run ls /dev/tty.* or ls /dev/ttyUSB* in a terminal. It's often /dev/tty.usbserial-XXX or /dev/ttyUSB0.
|
||||
- Add the line upload_port = COM4 (replace COM4 with your port) to your platformio.ini file in the [env:...] section.
|
||||
|
||||
## Code formatting 📜
|
||||
The project enforces a specific code formatting in the workflows. To get your code formatted properly, it is easiest to use a pre-commit hook before pushing the code to a pull request.
|
||||
|
||||
Before you begin, make sure you have installed Python on the system!
|
||||
|
@ -39,7 +95,7 @@ Or force it to check all files with
|
|||
pre-commit run --all-files
|
||||
```
|
||||
|
||||
## Local Unit test run
|
||||
## Local Unit test run 🧪
|
||||
The Unit tests run gtest. Here is how to install this on Debian/Ubuntu and run it locally
|
||||
```
|
||||
sudo apt-get install libgtest-dev
|
||||
|
@ -50,3 +106,20 @@ Navigate to Battery-Emulator/test folder
|
|||
sudo cmake CMakeLists.txt
|
||||
sudo make
|
||||
```
|
||||
|
||||
## Downloading a pull request build to test locally 🛜
|
||||
If you want to test a pull request, you can download the precompiled binaries from the build system. To do this,start by clicking on the "**Checks**" tab
|
||||
|
||||
<img width="779" height="312" alt="image" src="https://github.com/user-attachments/assets/fc7783c1-ba61-440e-ab09-b53d2b49f1bb" />
|
||||
|
||||
Then select which hardware you need the binaries for. Currently we build for these hardwares:
|
||||
- LilyGo T-CAN485
|
||||
- Stark CMR
|
||||
- LilyGo T-2CAN
|
||||
|
||||
<img width="647" height="476" alt="image" src="https://github.com/user-attachments/assets/fbb97719-0155-4792-9d91-c51e6052fa57" />
|
||||
|
||||
After selecting the hardware you need, click the "**Upload Artifact**", and there will be a download link. Download the file, and [OTA Update](https://github.com/dalathegreat/Battery-Emulator/wiki/OTA-Update) your device with this file!
|
||||
|
||||
<img width="1714" height="697" alt="image" src="https://github.com/user-attachments/assets/2e17f90f-cc7d-4265-b7bc-7aa5cc6b6ec8" />
|
||||
|
||||
|
|
56
README.md
56
README.md
|
@ -2,7 +2,7 @@
|
|||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## What is Battery Emulator?
|
||||
|
@ -33,52 +33,18 @@ At the same time, EV manufacturers have been putting high capacity battery packs
|
|||
|
||||
For examples showing wiring, see each battery type's own Wiki page. For instance the [Nissan LEAF page](https://github.com/dalathegreat/Battery-Emulator/wiki/Battery:-Nissan-LEAF---e%E2%80%90NV200)
|
||||
|
||||
## How to compile the software 💻
|
||||
## How to install the software 💻
|
||||
|
||||
Start by watching this [quickstart guide](https://www.youtube.com/watch?v=hcl2GdHc0Y0)
|
||||
Start by watching this [quickstart guide](https://www.youtube.com/watch?v=sR3t7j0R9Z0)
|
||||
|
||||
[](https://www.youtube.com/watch?v=hcl2GdHc0Y0)
|
||||
[](https://www.youtube.com/watch?v=sR3t7j0R9Z0)
|
||||
|
||||
1. Download the Arduino IDE: https://www.arduino.cc/en/software
|
||||
2. Open the Arduino IDE.
|
||||
3. Click `File` menu -> `Preferences` -> `Additional Development` -> `Additional Board Manager URLs` -> Enter the URL in the input box: `https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json` and click OK.
|
||||
4. Click `Tools` menu -> `Board: "...."` -> `Boards Manager...`, install the `esp32` package by `Espressif Systems` (not `Arduino ESP32 Boards`), then press `Close`.
|
||||
|
||||
**NOTE: The ESP32 version depends on which release of Battery-Emulator you are running! See the [Release Notes](https://github.com/dalathegreat/Battery-Emulator/releases) for more info on which version to use with the current version (Suggested ESP32 version X.Y.Z)**
|
||||
|
||||

|
||||
|
||||
5. The Arduino board should be set to `ESP32 Dev Module` and `Partition Scheme` to `Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)` (under `Tools` -> `Board` -> `ESP32 Arduino`) with the following settings:
|
||||
|
||||

|
||||
|
||||
6. Select which battery type you will use, along with other optional settings. This is done in the `USER_SETTINGS.h` file.
|
||||
7. Copy the `USER_SECRETS.TEMPLATE.h` file to `USER_SECRETS.h` and update connectivity settings inside this file.
|
||||
8. Press `Verify` and `Upload` to send the sketch to the board.
|
||||
NOTE: In some cases, the LilyGo must be powered through the main power connector instead of USB-C
|
||||
when performing the initial firmware upload.
|
||||
NOTE: On Mac, the following USB driver may need to be installed: https://github.com/WCHSoftGroup/ch34xser_macos
|
||||
|
||||
NOTE: If you see garbled messages on the serial console, change the serial console to match the baud rate to the code, currently 115200.
|
||||
|
||||
NOTE: If you see the error `Sketch too big` then check you set the Partition Scheme above correctly.
|
||||
|
||||
This video explains all the above mentioned steps:
|
||||
<https://youtu.be/_mH2AjnAjDk>
|
||||
|
||||
|
||||
### Linux Development Environment Setup
|
||||
In addition to the steps above, ESP32 requires a dependency for a Python module, pyserial install using the cli.\
|
||||
```python3 -m pip install pyserial```
|
||||
|
||||
If you're using Ubuntu , use apt to manage the dependencies of arduino:\
|
||||
pyserial install: ```sudo apt install python3-serial```
|
||||
|
||||
Arduino AppImage must be set as executable after downloading to run correctly\
|
||||
example: ```chmod 775 arduino-ide_2.3.3_Linux_64bit.AppImage```
|
||||
|
||||
Also you might need to install FUSE to run appimages
|
||||
```sudo apt install libfuse2```
|
||||
1. Open the [webinstaller page](https://dalathegreat.github.io/BE-Web-Installer/)
|
||||
2. Follow the instructions on that page to install the software
|
||||
3. After successful installation, connect to the wireless network (Battery-Emulator , password: 123456789)
|
||||
4. Go to setup page and configure component selection
|
||||
5. (OPTIONAL, connect the board to your home Wifi)
|
||||
6. Connect your battery and inverter to the board and you are done! 🔋⚡
|
||||
|
||||
## Dependencies 📖
|
||||
This code uses the following excellent libraries:
|
||||
|
@ -88,7 +54,7 @@ This code uses the following excellent libraries:
|
|||
- [eModbus/eModbus](https://github.com/eModbus/eModbus) MIT-License
|
||||
- [ESP32Async/AsyncTCP](https://github.com/ESP32Async/AsyncTCP) LGPL-3.0 license
|
||||
- [ESP32Async/ESPAsyncWebServer](https://github.com/ESP32Async/ESPAsyncWebServer) LGPL-3.0 license
|
||||
- [miwagner/ESP32-Arduino-CAN](https://github.com/miwagner/ESP32-Arduino-CAN/) MIT-License
|
||||
- [pierremolinaro/acan-esp32](https://github.com/pierremolinaro/acan-esp32) MIT-License
|
||||
- [pierremolinaro/acan2515](https://github.com/pierremolinaro/acan2515) MIT-License
|
||||
- [pierremolinaro/acan2517FD](https://github.com/pierremolinaro/acan2517FD) MIT-License
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
/* Do not change any code below this line unless you are sure what you are doing */
|
||||
/* Only change battery specific settings in "USER_SETTINGS.h" */
|
||||
#include <Arduino.h>
|
||||
#include "HardwareSerial.h"
|
||||
#include "USER_SECRETS.h"
|
||||
#include "USER_SETTINGS.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include "esp_timer.h"
|
||||
|
@ -26,31 +23,28 @@
|
|||
#include "src/devboard/utils/logging.h"
|
||||
#include "src/devboard/utils/time_meas.h"
|
||||
#include "src/devboard/utils/timer.h"
|
||||
#include "src/devboard/utils/types.h"
|
||||
#include "src/devboard/utils/value_mapping.h"
|
||||
#include "src/devboard/webserver/webserver.h"
|
||||
#include "src/devboard/wifi/wifi.h"
|
||||
#include "src/inverter/INVERTERS.h"
|
||||
|
||||
#if !defined(HW_LILYGO) && !defined(HW_LILYGO2CAN) && !defined(HW_STARK) && !defined(HW_3LB) && !defined(HW_DEVKIT)
|
||||
#error You must select a target hardware in the USER_SETTINGS.h file!
|
||||
#error You must select a target hardware!
|
||||
#endif
|
||||
|
||||
#ifdef PERIODIC_BMS_RESET_AT
|
||||
#include "src/devboard/utils/ntp_time.h"
|
||||
#endif
|
||||
volatile unsigned long long bmsResetTimeOffset = 0;
|
||||
|
||||
// The current software version, shown on webserver
|
||||
const char* version_number = "9.0.RC4";
|
||||
const char* version_number = "9.2.dev";
|
||||
|
||||
// Interval timers
|
||||
volatile unsigned long currentMillis = 0;
|
||||
unsigned long previousMillis10ms = 0;
|
||||
unsigned long previousMillisUpdateVal = 0;
|
||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||
// Task time measurement for debugging
|
||||
MyTimer core_task_timer_10s(INTERVAL_10_S);
|
||||
#endif
|
||||
uint64_t start_time_10ms = 0;
|
||||
uint64_t start_time_values = 0;
|
||||
uint64_t start_time_cantx = 0;
|
||||
TaskHandle_t main_loop_task;
|
||||
TaskHandle_t connectivity_loop_task;
|
||||
TaskHandle_t logging_loop_task;
|
||||
|
@ -58,114 +52,58 @@ TaskHandle_t mqtt_loop_task;
|
|||
|
||||
Logging logging;
|
||||
|
||||
// Initialization
|
||||
void setup() {
|
||||
init_hal();
|
||||
std::string mqtt_user; //TODO, move?
|
||||
std::string mqtt_password; //TODO, move?
|
||||
std::string http_username; //TODO, move?
|
||||
std::string http_password; //TODO, move?
|
||||
|
||||
init_serial();
|
||||
|
||||
// We print this after setting up serial, so that is also printed if configured to do so
|
||||
logging.printf("Battery emulator %s build " __DATE__ " " __TIME__ "\n", version_number);
|
||||
|
||||
init_events();
|
||||
|
||||
init_stored_settings();
|
||||
|
||||
if (wifi_enabled) {
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&connectivity_loop, "connectivity_loop", 4096, NULL, TASK_CONNECTIVITY_PRIO,
|
||||
&connectivity_loop_task, esp32hal->WIFICORE());
|
||||
}
|
||||
|
||||
if (!led_init()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (datalayer.system.info.CAN_SD_logging_active || datalayer.system.info.SD_logging_active) {
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&logging_loop, "logging_loop", 4096, NULL, TASK_CONNECTIVITY_PRIO,
|
||||
&logging_loop_task, esp32hal->WIFICORE());
|
||||
}
|
||||
|
||||
if (!init_contactors()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!init_precharge_control()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setup_charger();
|
||||
|
||||
if (!setup_inverter()) {
|
||||
return;
|
||||
}
|
||||
setup_battery();
|
||||
setup_can_shunt();
|
||||
|
||||
// Init CAN only after any CAN receivers have had a chance to register.
|
||||
if (!init_CAN()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!init_rs485()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!init_equipment_stop_button()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// BOOT button at runtime is used as an input for various things
|
||||
pinMode(0, INPUT_PULLUP);
|
||||
|
||||
check_reset_reason();
|
||||
|
||||
// Initialize Task Watchdog for subscribed tasks
|
||||
esp_task_wdt_config_t wdt_config = {// 5s should be enough for the connectivity tasks (which are all contending
|
||||
// for the same core) to yield to each other and reset their watchdogs.
|
||||
.timeout_ms = INTERVAL_5_S,
|
||||
// We don't benefit from idle task watchdogs, our critical loops have their
|
||||
// own. The idle watchdogs can cause nuisance reboots under heavy load.
|
||||
.idle_core_mask = 0,
|
||||
// Panic (and reboot) on timeout
|
||||
.trigger_panic = true};
|
||||
#ifdef CONFIG_ESP_TASK_WDT
|
||||
// ESP-IDF will have already initialized it, so reconfigure.
|
||||
// Arduino and PlatformIO have different watchdog defaults, so we reconfigure
|
||||
// for consistency.
|
||||
esp_task_wdt_reconfigure(&wdt_config);
|
||||
#else
|
||||
// Otherwise initialize it for the first time.
|
||||
esp_task_wdt_init(&wdt_config);
|
||||
#endif
|
||||
|
||||
// Start tasks
|
||||
|
||||
if (mqtt_enabled) {
|
||||
if (!init_mqtt()) {
|
||||
return;
|
||||
}
|
||||
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&mqtt_loop, "mqtt_loop", 4096, NULL, TASK_MQTT_PRIO, &mqtt_loop_task,
|
||||
esp32hal->WIFICORE());
|
||||
}
|
||||
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&core_loop, "core_loop", 4096, NULL, TASK_CORE_PRIO, &main_loop_task,
|
||||
esp32hal->CORE_FUNCTION_CORE());
|
||||
|
||||
#ifdef PERIODIC_BMS_RESET_AT
|
||||
bmsResetTimeOffset = getTimeOffsetfromNowUntil(PERIODIC_BMS_RESET_AT);
|
||||
if (bmsResetTimeOffset == 0) {
|
||||
set_event(EVENT_PERIODIC_BMS_RESET_AT_INIT_FAILED, 0);
|
||||
} else {
|
||||
set_event(EVENT_PERIODIC_BMS_RESET_AT_INIT_SUCCESS, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
DEBUG_PRINTF("setup() complete\n");
|
||||
static std::list<Transmitter*> transmitters;
|
||||
void register_transmitter(Transmitter* transmitter) {
|
||||
transmitters.push_back(transmitter);
|
||||
DEBUG_PRINTF("transmitter registered, total: %d\n", transmitters.size());
|
||||
}
|
||||
|
||||
// Loop empty, all functionality runs in tasks
|
||||
void loop() {}
|
||||
// Initialization functions
|
||||
void init_serial() {
|
||||
// Init Serial monitor
|
||||
Serial.begin(115200);
|
||||
#if HW_LILYGO2CAN
|
||||
// Wait up to 100ms for Serial to be available. On the ESP32S3 Serial is
|
||||
// provided by the USB controller, so will only work if the board is connected
|
||||
// to a computer.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (Serial)
|
||||
break;
|
||||
delay(10);
|
||||
}
|
||||
#else
|
||||
while (!Serial) {}
|
||||
#endif
|
||||
}
|
||||
|
||||
void connectivity_loop(void*) {
|
||||
esp_task_wdt_add(NULL); // Register this task with WDT
|
||||
// Init wifi
|
||||
init_WiFi();
|
||||
|
||||
init_webserver();
|
||||
|
||||
if (mdns_enabled) {
|
||||
init_mDNS();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
START_TIME_MEASUREMENT(wifi);
|
||||
wifi_monitor();
|
||||
|
||||
ota_monitor();
|
||||
|
||||
END_TIME_MEASUREMENT_MAX(wifi, datalayer.system.status.wifi_task_10s_max_us);
|
||||
|
||||
esp_task_wdt_reset(); // Reset watchdog
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void logging_loop(void*) {
|
||||
|
||||
|
@ -183,176 +121,6 @@ void logging_loop(void*) {
|
|||
}
|
||||
}
|
||||
|
||||
void connectivity_loop(void*) {
|
||||
esp_task_wdt_add(NULL); // Register this task with WDT
|
||||
// Init wifi
|
||||
init_WiFi();
|
||||
|
||||
if (webserver_enabled) {
|
||||
init_webserver();
|
||||
}
|
||||
|
||||
if (mdns_enabled) {
|
||||
init_mDNS();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
START_TIME_MEASUREMENT(wifi);
|
||||
wifi_monitor();
|
||||
|
||||
if (webserver_enabled) {
|
||||
ota_monitor();
|
||||
}
|
||||
|
||||
END_TIME_MEASUREMENT_MAX(wifi, datalayer.system.status.wifi_task_10s_max_us);
|
||||
|
||||
esp_task_wdt_reset(); // Reset watchdog
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void mqtt_loop(void*) {
|
||||
esp_task_wdt_add(NULL); // Register this task with WDT
|
||||
|
||||
while (true) {
|
||||
START_TIME_MEASUREMENT(mqtt);
|
||||
mqtt_loop();
|
||||
END_TIME_MEASUREMENT_MAX(mqtt, datalayer.system.status.mqtt_task_10s_max_us);
|
||||
esp_task_wdt_reset(); // Reset watchdog
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
static std::list<Transmitter*> transmitters;
|
||||
|
||||
void register_transmitter(Transmitter* transmitter) {
|
||||
transmitters.push_back(transmitter);
|
||||
DEBUG_PRINTF("transmitter registered, total: %d\n", transmitters.size());
|
||||
}
|
||||
|
||||
void core_loop(void*) {
|
||||
esp_task_wdt_add(NULL); // Register this task with WDT
|
||||
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||
const TickType_t xFrequency = pdMS_TO_TICKS(1); // Convert 1ms to ticks
|
||||
|
||||
while (true) {
|
||||
|
||||
START_TIME_MEASUREMENT(all);
|
||||
START_TIME_MEASUREMENT(comm);
|
||||
|
||||
monitor_equipment_stop_button();
|
||||
|
||||
// Input, Runs as fast as possible
|
||||
receive_can(); // Receive CAN messages
|
||||
receive_rs485(); // Process serial2 RS485 interface
|
||||
|
||||
END_TIME_MEASUREMENT_MAX(comm, datalayer.system.status.time_comm_us);
|
||||
|
||||
if (webserver_enabled) {
|
||||
START_TIME_MEASUREMENT(ota);
|
||||
ElegantOTA.loop();
|
||||
END_TIME_MEASUREMENT_MAX(ota, datalayer.system.status.time_ota_us);
|
||||
}
|
||||
|
||||
// Process
|
||||
currentMillis = millis();
|
||||
if (currentMillis - previousMillis10ms >= INTERVAL_10_MS) {
|
||||
if ((currentMillis - previousMillis10ms >= INTERVAL_10_MS_DELAYED) &&
|
||||
(milliseconds(currentMillis) > esp32hal->BOOTUP_TIME())) {
|
||||
set_event(EVENT_TASK_OVERRUN, (currentMillis - previousMillis10ms));
|
||||
}
|
||||
previousMillis10ms = currentMillis;
|
||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||
START_TIME_MEASUREMENT(time_10ms);
|
||||
#endif
|
||||
led_exe();
|
||||
handle_contactors(); // Take care of startup precharge/contactor closing
|
||||
#ifdef PRECHARGE_CONTROL
|
||||
handle_precharge_control(currentMillis);
|
||||
#endif // PRECHARGE_CONTROL
|
||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||
END_TIME_MEASUREMENT_MAX(time_10ms, datalayer.system.status.time_10ms_us);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (currentMillis - previousMillisUpdateVal >= INTERVAL_1_S) {
|
||||
previousMillisUpdateVal = currentMillis; // Order matters on the update_loop!
|
||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||
START_TIME_MEASUREMENT(time_values);
|
||||
#endif
|
||||
update_pause_state(); // Check if we are OK to send CAN or need to pause
|
||||
|
||||
// Fetch battery values
|
||||
if (battery) {
|
||||
battery->update_values();
|
||||
}
|
||||
|
||||
if (battery2) {
|
||||
battery2->update_values();
|
||||
check_interconnect_available();
|
||||
}
|
||||
update_calculated_values();
|
||||
update_machineryprotection(); // Check safeties
|
||||
|
||||
// Update values heading towards inverter
|
||||
if (inverter) {
|
||||
inverter->update_values();
|
||||
}
|
||||
|
||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||
END_TIME_MEASUREMENT_MAX(time_values, datalayer.system.status.time_values_us);
|
||||
#endif
|
||||
}
|
||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||
START_TIME_MEASUREMENT(cantx);
|
||||
#endif
|
||||
|
||||
// Let all transmitter objects send their messages
|
||||
for (auto& transmitter : transmitters) {
|
||||
transmitter->transmit(currentMillis);
|
||||
}
|
||||
|
||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||
END_TIME_MEASUREMENT_MAX(cantx, datalayer.system.status.time_cantx_us);
|
||||
END_TIME_MEASUREMENT_MAX(all, datalayer.system.status.core_task_10s_max_us);
|
||||
#endif
|
||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||
if (datalayer.system.status.core_task_10s_max_us > datalayer.system.status.core_task_max_us) {
|
||||
// Update worst case total time
|
||||
datalayer.system.status.core_task_max_us = datalayer.system.status.core_task_10s_max_us;
|
||||
// Record snapshots of task times
|
||||
datalayer.system.status.time_snap_comm_us = datalayer.system.status.time_comm_us;
|
||||
datalayer.system.status.time_snap_10ms_us = datalayer.system.status.time_10ms_us;
|
||||
datalayer.system.status.time_snap_values_us = datalayer.system.status.time_values_us;
|
||||
datalayer.system.status.time_snap_cantx_us = datalayer.system.status.time_cantx_us;
|
||||
datalayer.system.status.time_snap_ota_us = datalayer.system.status.time_ota_us;
|
||||
}
|
||||
|
||||
datalayer.system.status.core_task_max_us =
|
||||
MAX(datalayer.system.status.core_task_10s_max_us, datalayer.system.status.core_task_max_us);
|
||||
if (core_task_timer_10s.elapsed()) {
|
||||
datalayer.system.status.time_ota_us = 0;
|
||||
datalayer.system.status.time_comm_us = 0;
|
||||
datalayer.system.status.time_10ms_us = 0;
|
||||
datalayer.system.status.time_values_us = 0;
|
||||
datalayer.system.status.time_cantx_us = 0;
|
||||
datalayer.system.status.core_task_10s_max_us = 0;
|
||||
datalayer.system.status.wifi_task_10s_max_us = 0;
|
||||
datalayer.system.status.mqtt_task_10s_max_us = 0;
|
||||
}
|
||||
#endif // FUNCTION_TIME_MEASUREMENT
|
||||
esp_task_wdt_reset(); // Reset watchdog to prevent reset
|
||||
vTaskDelayUntil(&xLastWakeTime, xFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialization functions
|
||||
void init_serial() {
|
||||
// Init Serial monitor
|
||||
Serial.begin(115200);
|
||||
while (!Serial) {}
|
||||
}
|
||||
|
||||
void check_interconnect_available() {
|
||||
if (datalayer.battery.status.voltage_dV == 0 || datalayer.battery2.status.voltage_dV == 0) {
|
||||
return; // Both voltage values need to be available to start check
|
||||
|
@ -597,3 +365,211 @@ void check_reset_reason() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void core_loop(void*) {
|
||||
esp_task_wdt_add(NULL); // Register this task with WDT
|
||||
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||
const TickType_t xFrequency = pdMS_TO_TICKS(1); // Convert 1ms to ticks
|
||||
|
||||
while (true) {
|
||||
|
||||
START_TIME_MEASUREMENT(all);
|
||||
START_TIME_MEASUREMENT(comm);
|
||||
|
||||
monitor_equipment_stop_button();
|
||||
|
||||
// Input, Runs as fast as possible
|
||||
receive_can(); // Receive CAN messages
|
||||
receive_rs485(); // Process serial2 RS485 interface
|
||||
|
||||
END_TIME_MEASUREMENT_MAX(comm, datalayer.system.status.time_comm_us);
|
||||
|
||||
START_TIME_MEASUREMENT(ota);
|
||||
ElegantOTA.loop();
|
||||
END_TIME_MEASUREMENT_MAX(ota, datalayer.system.status.time_ota_us);
|
||||
|
||||
// Process
|
||||
currentMillis = millis();
|
||||
if (currentMillis - previousMillis10ms >= INTERVAL_10_MS) {
|
||||
if ((currentMillis - previousMillis10ms >= INTERVAL_10_MS_DELAYED) &&
|
||||
(milliseconds(currentMillis) > esp32hal->BOOTUP_TIME())) {
|
||||
set_event(EVENT_TASK_OVERRUN, (currentMillis - previousMillis10ms));
|
||||
}
|
||||
previousMillis10ms = currentMillis;
|
||||
if (datalayer.system.info.performance_measurement_active) {
|
||||
START_TIME_MEASUREMENT(10ms);
|
||||
}
|
||||
led_exe();
|
||||
handle_contactors(); // Take care of startup precharge/contactor closing
|
||||
if (precharge_control_enabled) {
|
||||
handle_precharge_control(currentMillis); //Drive the hia4v1 via PWM
|
||||
}
|
||||
|
||||
if (datalayer.system.info.performance_measurement_active) {
|
||||
END_TIME_MEASUREMENT_MAX(10ms, datalayer.system.status.time_10ms_us);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentMillis - previousMillisUpdateVal >= INTERVAL_1_S) {
|
||||
previousMillisUpdateVal = currentMillis; // Order matters on the update_loop!
|
||||
if (datalayer.system.info.performance_measurement_active) {
|
||||
START_TIME_MEASUREMENT(values);
|
||||
}
|
||||
update_pause_state(); // Check if we are OK to send CAN or need to pause
|
||||
|
||||
// Fetch battery values
|
||||
if (battery) {
|
||||
battery->update_values();
|
||||
}
|
||||
|
||||
if (battery2) {
|
||||
battery2->update_values();
|
||||
check_interconnect_available();
|
||||
}
|
||||
update_calculated_values();
|
||||
update_machineryprotection(); // Check safeties
|
||||
|
||||
// Update values heading towards inverter
|
||||
if (inverter) {
|
||||
inverter->update_values();
|
||||
}
|
||||
|
||||
if (datalayer.system.info.performance_measurement_active) {
|
||||
END_TIME_MEASUREMENT_MAX(values, datalayer.system.status.time_values_us);
|
||||
}
|
||||
}
|
||||
if (datalayer.system.info.performance_measurement_active) {
|
||||
START_TIME_MEASUREMENT(cantx);
|
||||
}
|
||||
|
||||
// Let all transmitter objects send their messages
|
||||
for (auto& transmitter : transmitters) {
|
||||
transmitter->transmit(currentMillis);
|
||||
}
|
||||
|
||||
if (datalayer.system.info.performance_measurement_active) {
|
||||
END_TIME_MEASUREMENT_MAX(cantx, datalayer.system.status.time_cantx_us);
|
||||
END_TIME_MEASUREMENT_MAX(all, datalayer.system.status.core_task_10s_max_us);
|
||||
if (datalayer.system.status.core_task_10s_max_us > datalayer.system.status.core_task_max_us) {
|
||||
// Update worst case total time
|
||||
datalayer.system.status.core_task_max_us = datalayer.system.status.core_task_10s_max_us;
|
||||
// Record snapshots of task times
|
||||
datalayer.system.status.time_snap_comm_us = datalayer.system.status.time_comm_us;
|
||||
datalayer.system.status.time_snap_10ms_us = datalayer.system.status.time_10ms_us;
|
||||
datalayer.system.status.time_snap_values_us = datalayer.system.status.time_values_us;
|
||||
datalayer.system.status.time_snap_cantx_us = datalayer.system.status.time_cantx_us;
|
||||
datalayer.system.status.time_snap_ota_us = datalayer.system.status.time_ota_us;
|
||||
}
|
||||
|
||||
datalayer.system.status.core_task_max_us =
|
||||
MAX(datalayer.system.status.core_task_10s_max_us, datalayer.system.status.core_task_max_us);
|
||||
if (core_task_timer_10s.elapsed()) {
|
||||
datalayer.system.status.time_ota_us = 0;
|
||||
datalayer.system.status.time_comm_us = 0;
|
||||
datalayer.system.status.time_10ms_us = 0;
|
||||
datalayer.system.status.time_values_us = 0;
|
||||
datalayer.system.status.time_cantx_us = 0;
|
||||
datalayer.system.status.core_task_10s_max_us = 0;
|
||||
datalayer.system.status.wifi_task_10s_max_us = 0;
|
||||
datalayer.system.status.mqtt_task_10s_max_us = 0;
|
||||
}
|
||||
}
|
||||
esp_task_wdt_reset(); // Reset watchdog to prevent reset
|
||||
vTaskDelayUntil(&xLastWakeTime, xFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
void mqtt_loop(void*) {
|
||||
esp_task_wdt_add(NULL); // Register this task with WDT
|
||||
|
||||
while (true) {
|
||||
START_TIME_MEASUREMENT(mqtt);
|
||||
mqtt_client_loop();
|
||||
END_TIME_MEASUREMENT_MAX(mqtt, datalayer.system.status.mqtt_task_10s_max_us);
|
||||
esp_task_wdt_reset(); // Reset watchdog
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialization
|
||||
void setup() {
|
||||
init_hal();
|
||||
|
||||
init_serial();
|
||||
|
||||
// We print this after setting up serial, so that is also printed if configured to do so
|
||||
DEBUG_PRINTF("Battery emulator %s build " __DATE__ " " __TIME__ "\n", version_number);
|
||||
|
||||
init_events();
|
||||
|
||||
init_stored_settings();
|
||||
|
||||
if (wifi_enabled) {
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&connectivity_loop, "connectivity_loop", 4096, NULL, TASK_CONNECTIVITY_PRIO,
|
||||
&connectivity_loop_task, esp32hal->WIFICORE());
|
||||
}
|
||||
|
||||
led_init();
|
||||
|
||||
if (datalayer.system.info.CAN_SD_logging_active || datalayer.system.info.SD_logging_active) {
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&logging_loop, "logging_loop", 4096, NULL, TASK_CONNECTIVITY_PRIO,
|
||||
&logging_loop_task, esp32hal->WIFICORE());
|
||||
}
|
||||
|
||||
init_contactors();
|
||||
|
||||
init_precharge_control();
|
||||
|
||||
setup_charger();
|
||||
setup_inverter();
|
||||
setup_battery();
|
||||
setup_can_shunt();
|
||||
|
||||
// Init CAN only after any CAN receivers have had a chance to register.
|
||||
init_CAN();
|
||||
|
||||
init_rs485();
|
||||
|
||||
init_equipment_stop_button();
|
||||
|
||||
// BOOT button at runtime is used as an input for various things
|
||||
pinMode(0, INPUT_PULLUP);
|
||||
|
||||
check_reset_reason();
|
||||
|
||||
// Initialize Task Watchdog for subscribed tasks
|
||||
esp_task_wdt_config_t wdt_config = {// 5s should be enough for the connectivity tasks (which are all contending
|
||||
// for the same core) to yield to each other and reset their watchdogs.
|
||||
.timeout_ms = INTERVAL_5_S,
|
||||
// We don't benefit from idle task watchdogs, our critical loops have their
|
||||
// own. The idle watchdogs can cause nuisance reboots under heavy load.
|
||||
.idle_core_mask = 0,
|
||||
// Panic (and reboot) on timeout
|
||||
.trigger_panic = true};
|
||||
#ifdef CONFIG_ESP_TASK_WDT
|
||||
// ESP-IDF will have already initialized it, so reconfigure.
|
||||
// Arduino and PlatformIO have different watchdog defaults, so we reconfigure
|
||||
// for consistency.
|
||||
esp_task_wdt_reconfigure(&wdt_config);
|
||||
#else
|
||||
// Otherwise initialize it for the first time.
|
||||
esp_task_wdt_init(&wdt_config);
|
||||
#endif
|
||||
|
||||
// Start tasks
|
||||
|
||||
if (mqtt_enabled) {
|
||||
init_mqtt();
|
||||
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&mqtt_loop, "mqtt_loop", 4096, NULL, TASK_MQTT_PRIO, &mqtt_loop_task,
|
||||
esp32hal->WIFICORE());
|
||||
}
|
||||
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&core_loop, "core_loop", 4096, NULL, TASK_CORE_PRIO, &main_loop_task,
|
||||
esp32hal->CORE_FUNCTION_CORE());
|
||||
|
||||
DEBUG_PRINTF("Setup complete!\n");
|
||||
}
|
||||
|
||||
// Loop empty, all functionality runs in tasks
|
||||
void loop() {}
|
|
@ -1,22 +0,0 @@
|
|||
/* This file should be renamed to USER_SECRETS.h to be able to use the software!
|
||||
It contains all the credentials that should never be made public */
|
||||
#ifndef COMMON_IMAGE
|
||||
|
||||
//Password to the access point generated by the Battery-Emulator
|
||||
#define AP_PASSWORD "123456789" // Minimum of 8 characters; set to blank if you want the access point to be open
|
||||
|
||||
//Name and password of Wifi network you want the emulator to connect to
|
||||
#define WIFI_SSID "REPLACE_WITH_YOUR_SSID" // Maximum of 63 characters
|
||||
#define WIFI_PASSWORD "REPLACE_WITH_YOUR_PASSWORD" // Minimum of 8 characters
|
||||
|
||||
//Set WEBSERVER_AUTH_REQUIRED to true to require a password when accessing the webserver homepage. Improves cybersecurity.
|
||||
#define WEBSERVER_AUTH_REQUIRED false
|
||||
#define HTTP_USERNAME "admin" // Username for webserver authentication
|
||||
#define HTTP_PASSWORD "admin" // Password for webserver authentication
|
||||
|
||||
//MQTT credentials
|
||||
#define MQTT_SERVER "192.168.xxx.yyy" // MQTT server address
|
||||
#define MQTT_PORT 1883 // MQTT server port
|
||||
#define MQTT_USER "" // MQTT username, leave blank for no authentication
|
||||
#define MQTT_PASSWORD "" // MQTT password, leave blank for no authentication
|
||||
#endif
|
|
@ -1,81 +0,0 @@
|
|||
#include "USER_SETTINGS.h"
|
||||
#include <string>
|
||||
#include "USER_SECRETS.h"
|
||||
#include "src/devboard/hal/hal.h"
|
||||
|
||||
/* This file contains all the battery settings and limits */
|
||||
/* They can be defined here, or later on in the WebUI */
|
||||
/* Most important is to select which CAN interface each component is connected to */
|
||||
/*
|
||||
CAN_NATIVE = Native CAN port on the LilyGo & Stark hardware
|
||||
CANFD_NATIVE = Native CANFD port on the Stark CMR hardware
|
||||
CAN_ADDON_MCP2515 = Add-on CAN MCP2515 connected to GPIO pins
|
||||
CANFD_ADDON_MCP2518 = Add-on CAN-FD MCP2518 connected to GPIO pins
|
||||
*/
|
||||
|
||||
volatile CAN_Configuration can_config = {
|
||||
.battery = CAN_NATIVE, // Which CAN is your battery connected to?
|
||||
.inverter = CAN_NATIVE, // Which CAN is your inverter connected to? (No need to configure incase you use RS485)
|
||||
.battery_double = CAN_ADDON_MCP2515, // (OPTIONAL) Which CAN is your second battery connected to?
|
||||
.charger = CAN_NATIVE, // (OPTIONAL) Which CAN is your charger connected to?
|
||||
.shunt = CAN_NATIVE // (OPTIONAL) Which CAN is your shunt connected to?
|
||||
};
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
std::string ssid;
|
||||
std::string password;
|
||||
std::string passwordAP;
|
||||
#else
|
||||
std::string ssid = WIFI_SSID; // Set in USER_SECRETS.h
|
||||
std::string password = WIFI_PASSWORD; // Set in USER_SECRETS.h
|
||||
std::string passwordAP = AP_PASSWORD; // Set in USER_SECRETS.h
|
||||
#endif
|
||||
|
||||
const uint8_t wifi_channel = 0; // Set to 0 for automatic channel selection
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
std::string http_username;
|
||||
std::string http_password;
|
||||
#else
|
||||
std::string http_username = HTTP_USERNAME; // Set in USER_SECRETS.h
|
||||
std::string http_password = HTTP_PASSWORD; // Set in USER_SECRETS.h
|
||||
#endif
|
||||
|
||||
// Set your Static IP address. Only used incase WIFICONFIG is set in USER_SETTINGS.h
|
||||
IPAddress local_IP(192, 168, 10, 150);
|
||||
IPAddress gateway(192, 168, 10, 1);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
|
||||
// MQTT
|
||||
#ifdef COMMON_IMAGE
|
||||
std::string mqtt_user;
|
||||
std::string mqtt_password;
|
||||
#else
|
||||
std::string mqtt_user = MQTT_USER; // Set in USER_SECRETS.h
|
||||
std::string mqtt_password = MQTT_PASSWORD; // Set in USER_SECRETS.h
|
||||
#endif
|
||||
|
||||
const char* mqtt_topic_name =
|
||||
"BE"; // Custom MQTT topic name. Previously, the name was automatically set to "battery-emulator_esp32-XXXXXX"
|
||||
const char* mqtt_object_id_prefix =
|
||||
"be_"; // Custom prefix for MQTT object ID. Previously, the prefix was automatically set to "esp32-XXXXXX_"
|
||||
const char* mqtt_device_name =
|
||||
"Battery Emulator"; // Custom device name in Home Assistant. Previously, the name was automatically set to "BatteryEmulator_esp32-XXXXXX"
|
||||
const char* ha_device_id =
|
||||
"battery-emulator"; // Custom device ID in Home Assistant. Previously, the ID was always "battery-emulator"
|
||||
|
||||
/* Charger settings (Optional, when using generator charging) */
|
||||
volatile float CHARGER_SET_HV = 384; // Reasonably appropriate 4.0v per cell charging of a 96s pack
|
||||
volatile float CHARGER_MAX_HV = 420; // Max permissible output (VDC) of charger
|
||||
volatile float CHARGER_MIN_HV = 200; // Min permissible output (VDC) of charger
|
||||
volatile float CHARGER_MAX_POWER = 3300; // Max power capable of charger, as a ceiling for validating config
|
||||
volatile float CHARGER_MAX_A = 11.5; // Max current output (amps) of charger
|
||||
volatile float CHARGER_END_A = 1.0; // Current at which charging is considered complete
|
||||
|
||||
#ifdef PERIODIC_BMS_RESET_AT
|
||||
// A list of rules for your zone can be obtained from https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h
|
||||
const char* time_zone =
|
||||
"GMT0BST,M3.5.0/1,M10.5.0"; // TimeZone rule for Europe/London including daylight adjustment rules (optional)
|
||||
const char* ntpServer1 = "pool.ntp.org";
|
||||
const char* ntpServer2 = "time.nist.gov";
|
||||
#endif
|
|
@ -1,219 +0,0 @@
|
|||
#ifndef __USER_SETTINGS_H__
|
||||
#define __USER_SETTINGS_H__
|
||||
#include <WiFi.h>
|
||||
#include <stdint.h>
|
||||
#include "src/devboard/utils/types.h"
|
||||
|
||||
/* This file contains all the battery/inverter protocol settings Battery-Emulator software */
|
||||
/* To switch between batteries/inverters, uncomment a line to enable, comment out to disable. */
|
||||
/* There are also some options for battery limits and extra functionality */
|
||||
/* To edit battery specific limits, see also the USER_SETTINGS.cpp file*/
|
||||
|
||||
/* Select battery used */
|
||||
//#define BMW_I3_BATTERY
|
||||
//#define BMW_IX_BATTERY
|
||||
//#define BMW_PHEV_BATTERY
|
||||
//#define BOLT_AMPERA_BATTERY
|
||||
//#define BYD_ATTO_3_BATTERY
|
||||
//#define FOXESS_BATTERY
|
||||
//#define CELLPOWER_BMS
|
||||
//#define CHADEMO_BATTERY //NOTE: inherently enables CONTACTOR_CONTROL below
|
||||
//#define GEELY_GEOMETRY_C_BATTERY
|
||||
//#define HYUNDAI_IONIQ_28_BATTERY
|
||||
//#define CMFA_EV_BATTERY
|
||||
//#define IMIEV_CZERO_ION_BATTERY
|
||||
//#define JAGUAR_IPACE_BATTERY
|
||||
//#define KIA_E_GMP_BATTERY
|
||||
//#define KIA_HYUNDAI_64_BATTERY
|
||||
//#define KIA_HYUNDAI_64_FD_BATTERY
|
||||
//#define KIA_HYUNDAI_HYBRID_BATTERY
|
||||
//#define MEB_BATTERY
|
||||
//#define MG_5_BATTERY
|
||||
//#define MG_HS_PHEV_BATTERY
|
||||
//#define NISSAN_LEAF_BATTERY
|
||||
//#define ORION_BMS
|
||||
//#define PYLON_BATTERY
|
||||
//#define DALY_BMS
|
||||
//#define RJXZS_BMS
|
||||
//#define RANGE_ROVER_PHEV_BATTERY
|
||||
//#define RELION_BATTERY
|
||||
//#define RENAULT_KANGOO_BATTERY
|
||||
//#define RENAULT_TWIZY_BATTERY
|
||||
//#define RENAULT_ZOE_GEN1_BATTERY
|
||||
//#define RENAULT_ZOE_GEN2_BATTERY
|
||||
//#define SONO_BATTERY
|
||||
//#define SAMSUNG_SDI_LV_BATTERY
|
||||
//#define SANTA_FE_PHEV_BATTERY
|
||||
//#define SIMPBMS_BATTERY
|
||||
//#define STELLANTIS_ECMP_BATTERY
|
||||
//#define TESLA_MODEL_3Y_BATTERY
|
||||
//#define TESLA_MODEL_SX_BATTERY
|
||||
//#define VOLVO_SPA_BATTERY
|
||||
//#define VOLVO_SPA_HYBRID_BATTERY
|
||||
//#define TEST_FAKE_BATTERY
|
||||
//#define DOUBLE_BATTERY //Enable this line if you use two identical batteries at the same time (requires separate CAN setup)
|
||||
|
||||
/* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/Battery-Emulator/wiki */
|
||||
//#define AFORE_CAN //Enable this line to emulate an "Afore battery" over CAN bus
|
||||
//#define BYD_CAN //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus
|
||||
//#define BYD_CAN_DEYE //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus, with Deye specific fixes
|
||||
//#define BYD_KOSTAL_RS485 //Enable this line to emulate a "BYD 11kWh HVM battery" over Kostal RS485
|
||||
//#define BYD_MODBUS //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU
|
||||
//#define FERROAMP_CAN //Enable this line to emulate a "Pylon 4x96V Force H2" over CAN Bus
|
||||
//#define FOXESS_CAN //Enable this line to emulate a "HV2600/ECS4100 battery" over CAN bus
|
||||
//#define GROWATT_HV_CAN //Enable this line to emulate a "Growatt High Voltage v1.10 battery" over CAN bus
|
||||
//#define GROWATT_LV_CAN //Enable this line to emulate a "48V Growatt Low Voltage battery" over CAN bus
|
||||
//#define PYLON_LV_CAN //Enable this line to emulate a "48V Pylontech battery" over CAN bus
|
||||
//#define PYLON_CAN //Enable this line to emulate a "High Voltage Pylontech battery" over CAN bus
|
||||
//#define SCHNEIDER_CAN //Enable this line to emulate a "Schneider Version 2: SE BMS" over CAN bus
|
||||
//#define SMA_BYD_H_CAN //Enable this line to emulate a "BYD Battery-Box H 8.9kWh, 7 mod" (SMA compatible) over CAN bus
|
||||
//#define SMA_BYD_HVS_CAN //Enable this line to emulate a "BYD Battery-Box HVS 10.2KW battery" (SMA compatible) over CAN bus
|
||||
//#define SMA_LV_CAN //Enable this line to emulate a "SMA Sunny Island 48V battery" over CAN bus
|
||||
//#define SMA_TRIPOWER_CAN //Enable this line to emulate a "SMA Home Storage battery" over CAN bus
|
||||
//#define SOFAR_CAN //Enable this line to emulate a "Sofar Energy Storage Inverter High Voltage BMS General Protocol (Extended Frame)" over CAN bus
|
||||
//#define SOLAX_CAN //Enable this line to emulate a "SolaX Triple Power LFP" over CAN bus
|
||||
//#define SOLXPOW_CAN //Enable this line to emulate a "Solxpow compatible battery" over CAN bus
|
||||
//#define SOL_ARK_LV_CAN //Enable this line to emulate a "Sol-Ark compatible LV battery" over CAN bus
|
||||
//#define SUNGROW_CAN //Enable this line to emulate a "Sungrow SBR064" over CAN bus
|
||||
|
||||
/* Select hardware used for Battery-Emulator */
|
||||
//#define HW_LILYGO
|
||||
//#define HW_STARK
|
||||
//#define HW_3LB
|
||||
//#define HW_DEVKIT
|
||||
|
||||
/* Contactor settings. If you have a battery that does not activate contactors via CAN, configure this section */
|
||||
#define PRECHARGE_TIME_MS 500 //Precharge time in milliseconds. Modify to suit your inverter (See wiki for more info)
|
||||
//#define CONTACTOR_CONTROL //Enable this line to have the emulator handle automatic precharge/contactor+/contactor- closing sequence (See wiki for pins)
|
||||
//#define CONTACTOR_CONTROL_DOUBLE_BATTERY //Enable this line to have the emulator hardware control secondary set of contactors for double battery setups (See wiki for pins)
|
||||
//#define PWM_CONTACTOR_CONTROL //Enable this line to use PWM for CONTACTOR_CONTROL, which lowers power consumption and heat generation. CONTACTOR_CONTROL must be enabled.
|
||||
//#define NC_CONTACTORS //Enable this line to control normally closed contactors. CONTACTOR_CONTROL must be enabled for this option. Extremely rare setting!
|
||||
//#define PERIODIC_BMS_RESET //Enable to have the emulator powercycle the connected battery every 24hours via GPIO. Useful for some batteries like Nissan LEAF
|
||||
//#define REMOTE_BMS_RESET //Enable to allow the emulator to remotely trigger a powercycle of the battery via MQTT. Useful for some batteries like Nissan LEAF
|
||||
// PERIODIC_BMS_RESET_AT Uses NTP server, internet required. In 24 Hour format WITHOUT leading 0. e.g 0230 should be 230. Time Zone is set in USER_SETTINGS.cpp
|
||||
//#define PERIODIC_BMS_RESET_AT 525
|
||||
|
||||
/* Shunt/Contactor settings (Optional) */
|
||||
//#define BMW_SBOX // SBOX relay control & battery current/voltage measurement
|
||||
|
||||
/* Select charger used (Optional) */
|
||||
//#define CHEVYVOLT_CHARGER //Enable this line to control a Chevrolet Volt charger connected to battery - for example, when generator charging or using an inverter without a charging function.
|
||||
//#define NISSANLEAF_CHARGER //Enable this line to control a Nissan LEAF PDM connected to battery - for example, when generator charging
|
||||
|
||||
/* Automatic Precharge settings (Optional) If you have a battery that expects an external voltage applied before opening contactors (within the battery), configure this section */
|
||||
//#define PRECHARGE_CONTROL //Enable this line to control a modified HIA4V1 via PWM on the HIA4V1_PIN (see Wiki and HAL for pin definition)
|
||||
//#define INVERTER_DISCONNECT_CONTACTOR_IS_NORMALLY_OPEN //Enable this line if you use a normally open contactor instead of normally closed
|
||||
|
||||
/* Other options */
|
||||
//#define EQUIPMENT_STOP_BUTTON // Enable this to allow an equipment stop button connected to the Battery-Emulator to disengage the battery
|
||||
//#define LFP_CHEMISTRY //Tesla specific setting, enable this line to startup in LFP mode
|
||||
//#define INTERLOCK_REQUIRED //Nissan LEAF specific setting, if enabled requires both high voltage conenctors to be seated before starting
|
||||
/* CAN options */
|
||||
//#define CAN_ADDON //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 chip (Needed for some inverters / double battery)
|
||||
#define CRYSTAL_FREQUENCY_MHZ 8 //CAN_ADDON option, what is your MCP2515 add-on boards crystal frequency?
|
||||
//#define CANFD_ADDON //Enable this line to activate an isolated secondary CAN-FD bus using add-on MCP2518FD chip / Native CANFD on Stark board
|
||||
#define CANFD_ADDON_CRYSTAL_FREQUENCY_MHZ \
|
||||
ACAN2517FDSettings::OSC_40MHz //CANFD_ADDON option, what is your MCP2518 add-on boards crystal frequency?
|
||||
//#define USE_CANFD_INTERFACE_AS_CLASSIC_CAN // Enable this line if you intend to use the CANFD as normal CAN
|
||||
|
||||
/* Connectivity options */
|
||||
#define WIFI
|
||||
//#define WIFICONFIG //Enable this line to set a static IP address / gateway /subnet mask for the device. see USER_SETTINGS.cpp for the settings
|
||||
//#define CUSTOM_HOSTNAME \
|
||||
"battery-emulator" //Enable this line to use a custom hostname for the device, if disabled the default naming format 'esp32-XXXXXX' will be used.
|
||||
#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings.
|
||||
#define WIFIAP //When enabled, the emulator will broadcast its own access point Wifi. Can be used at the same time as a normal Wifi connection to a router.
|
||||
#define MDNSRESPONDER //Enable this line to enable MDNS, allows battery monitor te be found by .local address. Requires WEBSERVER to be enabled.
|
||||
#define LOAD_SAVED_SETTINGS_ON_BOOT // Enable this line to read settings stored via the webserver on boot (overrides Wifi credentials set here)
|
||||
//#define FUNCTION_TIME_MEASUREMENT // Enable this to record execution times and present them in the web UI (WARNING, raises CPU load, do not use for production)
|
||||
|
||||
/* MQTT options */
|
||||
// #define MQTT // Enable this line to enable MQTT
|
||||
#define MQTT_QOS 0 // MQTT Quality of Service (0, 1, or 2)
|
||||
#define MQTT_PUBLISH_CELL_VOLTAGES // Enable this line to publish cell voltages to MQTT
|
||||
#define MQTT_TIMEOUT 2000 // MQTT timeout in milliseconds
|
||||
#define MQTT_MANUAL_TOPIC_OBJECT_NAME
|
||||
// Enable MQTT_MANUAL_TOPIC_OBJECT_NAME to use custom MQTT topic, object ID prefix, and device name.
|
||||
// WARNING: If this is not defined, the previous default naming format 'battery-emulator_esp32-XXXXXX' (based on hardware ID) will be used.
|
||||
// This naming convention was in place until version 7.5.0. Users should check the version from which they are updating, as this change
|
||||
// may break compatibility with previous versions of MQTT naming. Please refer to USER_SETTINGS.cpp for configuration options.
|
||||
|
||||
/* Home Assistant options */
|
||||
#define HA_AUTODISCOVERY // Enable this line to send Home Assistant autodiscovery messages. If not enabled manual configuration of Home Assitant is required
|
||||
|
||||
/* Battery settings */
|
||||
// Predefined total energy capacity of the battery in Watt-hours (updates automatically from battery data when available)
|
||||
#define BATTERY_WH_MAX 30000
|
||||
// Increases battery life. If true will rescale SOC between the configured min/max-percentage
|
||||
#define BATTERY_USE_SCALED_SOC true
|
||||
// 8000 = 80.0% , Max percentage the battery will charge to (Inverter gets 100% when reached)
|
||||
#define BATTERY_MAXPERCENTAGE 8000
|
||||
// 2000 = 20.0% , Min percentage the battery will discharge to (Inverter gets 0% when reached)
|
||||
#define BATTERY_MINPERCENTAGE 2000
|
||||
// 500 = 50.0 °C , Max temperature (Will produce a battery overheat event if above)
|
||||
#define BATTERY_MAXTEMPERATURE 500
|
||||
// -250 = -25.0 °C , Min temperature (Will produce a battery frozen event if below)
|
||||
#define BATTERY_MINTEMPERATURE -250
|
||||
// 150 = 15.0 °C , Max difference between min and max temperature (Will produce a battery temperature deviation event if greater)
|
||||
#define BATTERY_MAX_TEMPERATURE_DEVIATION 150
|
||||
// 300 = 30.0A , Max charge in Amp (Some inverters needs to be limited)
|
||||
#define BATTERY_MAX_CHARGE_AMP 300
|
||||
// 300 = 30.0A , Max discharge in Amp (Some inverters needs to be limited)
|
||||
#define BATTERY_MAX_DISCHARGE_AMP 300
|
||||
// Enable this to manually set voltage limits on how much battery can be discharged/charged. Normally not used.
|
||||
#define BATTERY_USE_VOLTAGE_LIMITS false
|
||||
// 5000 = 500.0V , Target charge voltage (Value can be tuned on the fly via webserver). Not used unless BATTERY_USE_VOLTAGE_LIMITS = true
|
||||
#define BATTERY_MAX_CHARGE_VOLTAGE 5000
|
||||
// 3000 = 300.0V, Target discharge voltage (Value can be tuned on the fly via webserver). Not used unless BATTERY_USE_VOLTAGE_LIMITS = true
|
||||
#define BATTERY_MAX_DISCHARGE_VOLTAGE 3000
|
||||
|
||||
/* Pack/cell voltage limits for custom-BMS batteries (RJXZS, Daly, etc.) */
|
||||
//#define MAX_CUSTOM_PACK_VOLTAGE_DV 5000 // 5000 = 500.0V , Maximum pack voltage in decivolts
|
||||
//#define MIN_CUSTOM_PACK_VOLTAGE_DV 2500 // 2500 = 250.0V , Minimum pack voltage in decivolts
|
||||
//#define MAX_CUSTOM_CELL_VOLTAGE_MV 4250 // 4250 = 4.250V , Maximum cell voltage in millivolts (4250 = 4.250V)
|
||||
//#define MIN_CUSTOM_CELL_VOLTAGE_MV 2650 // 2650 = 2.650V , Minimum cell voltage in millivolts (2650 = 2.650V)
|
||||
|
||||
/* Do not change any code below this line */
|
||||
/* Only change battery specific settings above and in "USER_SETTINGS.cpp" */
|
||||
typedef struct {
|
||||
CAN_Interface battery;
|
||||
CAN_Interface inverter;
|
||||
CAN_Interface battery_double;
|
||||
CAN_Interface charger;
|
||||
CAN_Interface shunt;
|
||||
} CAN_Configuration;
|
||||
extern volatile CAN_Configuration can_config;
|
||||
extern volatile uint8_t AccessPointEnabled;
|
||||
extern const uint8_t wifi_channel;
|
||||
extern volatile float CHARGER_SET_HV;
|
||||
extern volatile float CHARGER_MAX_HV;
|
||||
extern volatile float CHARGER_MIN_HV;
|
||||
extern volatile float CHARGER_MAX_POWER;
|
||||
extern volatile float CHARGER_MAX_A;
|
||||
extern volatile float CHARGER_END_A;
|
||||
|
||||
extern volatile unsigned long long bmsResetTimeOffset;
|
||||
|
||||
#include "src/communication/equipmentstopbutton/comm_equipmentstopbutton.h"
|
||||
|
||||
// Equipment stop button behavior. Use NC button for safety reasons.
|
||||
//LATCHING_SWITCH - Normally closed (NC), latching switch. When pressed it activates e-stop
|
||||
//MOMENTARY_SWITCH - Short press to activate e-stop, long 15s press to deactivate. E-stop is persistent between reboots
|
||||
|
||||
#ifdef EQUIPMENT_STOP_BUTTON
|
||||
const STOP_BUTTON_BEHAVIOR stop_button_default_behavior = STOP_BUTTON_BEHAVIOR::MOMENTARY_SWITCH;
|
||||
#else
|
||||
const STOP_BUTTON_BEHAVIOR stop_button_default_behavior = STOP_BUTTON_BEHAVIOR::NOT_CONNECTED;
|
||||
#endif
|
||||
|
||||
#ifdef WIFICONFIG
|
||||
extern IPAddress local_IP;
|
||||
extern IPAddress gateway;
|
||||
extern IPAddress subnet;
|
||||
#endif
|
||||
|
||||
#if defined(MEB_BATTERY)
|
||||
#define PRECHARGE_CONTROL
|
||||
#endif
|
||||
|
||||
#endif // __USER_SETTINGS_H__
|
|
@ -3,10 +3,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "RS485Battery.h"
|
||||
|
||||
#if !defined(COMMON_IMAGE) && !defined(SELECTED_BATTERY_CLASS)
|
||||
#error No battery selected! Choose one from the USER_SETTINGS.h file or build COMMON_IMAGE.
|
||||
#endif
|
||||
|
||||
Battery* battery = nullptr;
|
||||
Battery* battery2 = nullptr;
|
||||
|
||||
|
@ -22,6 +18,8 @@ std::vector<BatteryType> supported_battery_types() {
|
|||
|
||||
const char* name_for_chemistry(battery_chemistry_enum chem) {
|
||||
switch (chem) {
|
||||
case battery_chemistry_enum::Autodetect:
|
||||
return "Autodetect";
|
||||
case battery_chemistry_enum::LFP:
|
||||
return "LFP";
|
||||
case battery_chemistry_enum::NCA:
|
||||
|
@ -120,6 +118,8 @@ const char* name_for_battery_type(BatteryType type) {
|
|||
return RenaultZoeGen1Battery::Name;
|
||||
case BatteryType::RenaultZoe2:
|
||||
return RenaultZoeGen2Battery::Name;
|
||||
case BatteryType::RivianBattery:
|
||||
return RivianBattery::Name;
|
||||
case BatteryType::SamsungSdiLv:
|
||||
return SamsungSdiLVBattery::Name;
|
||||
case BatteryType::SantaFePhev:
|
||||
|
@ -141,19 +141,10 @@ const char* name_for_battery_type(BatteryType type) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef LFP_CHEMISTRY
|
||||
const battery_chemistry_enum battery_chemistry_default = battery_chemistry_enum::LFP;
|
||||
#else
|
||||
const battery_chemistry_enum battery_chemistry_default = battery_chemistry_enum::NMC;
|
||||
#endif
|
||||
|
||||
battery_chemistry_enum user_selected_battery_chemistry = battery_chemistry_default;
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
#ifdef SELECTED_BATTERY_CLASS
|
||||
#error "Compile time SELECTED_BATTERY_CLASS should not be defined with COMMON_IMAGE"
|
||||
#endif
|
||||
|
||||
BatteryType user_selected_battery_type = BatteryType::NissanLeaf;
|
||||
bool user_selected_second_battery = false;
|
||||
|
||||
|
@ -225,6 +216,8 @@ Battery* create_battery(BatteryType type) {
|
|||
return new RenaultZoeGen1Battery();
|
||||
case BatteryType::RenaultZoe2:
|
||||
return new RenaultZoeGen2Battery();
|
||||
case BatteryType::RivianBattery:
|
||||
return new RivianBattery();
|
||||
case BatteryType::SamsungSdiLv:
|
||||
return new SamsungSdiLVBattery();
|
||||
case BatteryType::SantaFePhev:
|
||||
|
@ -277,9 +270,15 @@ void setup_battery() {
|
|||
case BatteryType::RenaultZoe1:
|
||||
battery2 = new RenaultZoeGen1Battery(&datalayer.battery2, nullptr, can_config.battery_double);
|
||||
break;
|
||||
case BatteryType::RenaultZoe2:
|
||||
battery2 = new RenaultZoeGen2Battery(&datalayer.battery2, nullptr, can_config.battery_double);
|
||||
break;
|
||||
case BatteryType::TestFake:
|
||||
battery2 = new TestFakeBattery(&datalayer.battery2, can_config.battery_double);
|
||||
break;
|
||||
default:
|
||||
DEBUG_PRINTF("User tried enabling double battery on non-supported integration!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (battery2) {
|
||||
|
@ -287,40 +286,9 @@ void setup_battery() {
|
|||
}
|
||||
}
|
||||
}
|
||||
#else // Battery selection has been made at build-time
|
||||
|
||||
void setup_battery() {
|
||||
// Instantiate the battery only once just in case this function gets called multiple times.
|
||||
if (battery == nullptr) {
|
||||
#ifdef TESLA_MODEL_3Y_BATTERY
|
||||
battery = new SELECTED_BATTERY_CLASS(user_selected_battery_chemistry);
|
||||
#else
|
||||
battery = new SELECTED_BATTERY_CLASS();
|
||||
#endif
|
||||
}
|
||||
battery->setup();
|
||||
|
||||
#ifdef DOUBLE_BATTERY
|
||||
if (battery2 == nullptr) {
|
||||
#if defined(BMW_I3_BATTERY)
|
||||
battery2 =
|
||||
new SELECTED_BATTERY_CLASS(&datalayer.battery2, &datalayer.system.status.battery2_allowed_contactor_closing,
|
||||
can_config.battery_double, esp32hal->WUP_PIN2());
|
||||
#elif defined(KIA_HYUNDAI_64_BATTERY)
|
||||
battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, &datalayer_extended.KiaHyundai64_2,
|
||||
&datalayer.system.status.battery2_allowed_contactor_closing,
|
||||
can_config.battery_double);
|
||||
#elif defined(SANTA_FE_PHEV_BATTERY) || defined(TEST_FAKE_BATTERY)
|
||||
battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, can_config.battery_double);
|
||||
#else
|
||||
battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, nullptr, can_config.battery_double);
|
||||
#endif
|
||||
}
|
||||
battery2->setup();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* User-selected Nissan LEAF settings */
|
||||
bool user_selected_LEAF_interlock_mandatory = false;
|
||||
/* User-selected Tesla settings */
|
||||
bool user_selected_tesla_digital_HVIL = false;
|
||||
uint16_t user_selected_tesla_GTW_country = 17477;
|
||||
|
@ -328,23 +296,11 @@ bool user_selected_tesla_GTW_rightHandDrive = true;
|
|||
uint16_t user_selected_tesla_GTW_mapRegion = 2;
|
||||
uint16_t user_selected_tesla_GTW_chassisType = 2;
|
||||
uint16_t user_selected_tesla_GTW_packEnergy = 1;
|
||||
/* User-selected EGMP+others settings */
|
||||
bool user_selected_use_estimated_SOC = false;
|
||||
|
||||
/* User-selected voltages used for custom-BMS batteries (RJXZS etc.) */
|
||||
#if defined(MAX_CUSTOM_PACK_VOLTAGE_DV) && defined(MIN_CUSTOM_PACK_VOLTAGE_DV) && \
|
||||
defined(MAX_CUSTOM_CELL_VOLTAGE_MV) && defined(MIN_CUSTOM_CELL_VOLTAGE_MV)
|
||||
// Use USER_SETTINGS.h values for cell/pack voltage defaults
|
||||
uint16_t user_selected_max_pack_voltage_default_dV = MAX_CUSTOM_PACK_VOLTAGE_DV;
|
||||
uint16_t user_selected_min_pack_voltage_default_dV = MIN_CUSTOM_PACK_VOLTAGE_DV;
|
||||
uint16_t user_selected_max_cell_voltage_default_mV = MAX_CUSTOM_CELL_VOLTAGE_MV;
|
||||
uint16_t user_selected_min_cell_voltage_default_mV = MIN_CUSTOM_CELL_VOLTAGE_MV;
|
||||
#else
|
||||
// Use 0V for user selected cell/pack voltage defaults (COMMON_IMAGE will replace with saved values from NVM)
|
||||
uint16_t user_selected_max_pack_voltage_default_dV = 0;
|
||||
uint16_t user_selected_min_pack_voltage_default_dV = 0;
|
||||
uint16_t user_selected_max_cell_voltage_default_mV = 0;
|
||||
uint16_t user_selected_min_cell_voltage_default_mV = 0;
|
||||
#endif
|
||||
uint16_t user_selected_max_pack_voltage_dV = user_selected_max_pack_voltage_default_dV;
|
||||
uint16_t user_selected_min_pack_voltage_dV = user_selected_min_pack_voltage_default_dV;
|
||||
uint16_t user_selected_max_cell_voltage_mV = user_selected_max_cell_voltage_default_mV;
|
||||
uint16_t user_selected_min_cell_voltage_mV = user_selected_min_cell_voltage_default_mV;
|
||||
// Use 0V for user selected cell/pack voltage defaults (On boot will be replaced with saved values from NVM)
|
||||
uint16_t user_selected_max_pack_voltage_dV = 0;
|
||||
uint16_t user_selected_min_pack_voltage_dV = 0;
|
||||
uint16_t user_selected_max_cell_voltage_mV = 0;
|
||||
uint16_t user_selected_min_cell_voltage_mV = 0;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef BATTERIES_H
|
||||
#define BATTERIES_H
|
||||
#include "../../USER_SETTINGS.h"
|
||||
#include "Shunt.h"
|
||||
|
||||
class Battery;
|
||||
|
@ -45,6 +44,7 @@ void setup_can_shunt();
|
|||
#include "RENAULT-TWIZY.h"
|
||||
#include "RENAULT-ZOE-GEN1-BATTERY.h"
|
||||
#include "RENAULT-ZOE-GEN2-BATTERY.h"
|
||||
#include "RIVIAN-BATTERY.h"
|
||||
#include "RJXZS-BMS.h"
|
||||
#include "SAMSUNG-SDI-LV-BATTERY.h"
|
||||
#include "SANTA-FE-PHEV-BATTERY.h"
|
||||
|
@ -56,12 +56,14 @@ void setup_can_shunt();
|
|||
#include "VOLVO-SPA-HYBRID-BATTERY.h"
|
||||
|
||||
void setup_battery(void);
|
||||
Battery* create_battery(BatteryType type);
|
||||
|
||||
extern uint16_t user_selected_max_pack_voltage_dV;
|
||||
extern uint16_t user_selected_min_pack_voltage_dV;
|
||||
extern uint16_t user_selected_max_cell_voltage_mV;
|
||||
extern uint16_t user_selected_min_cell_voltage_mV;
|
||||
|
||||
extern bool user_selected_use_estimated_SOC;
|
||||
extern bool user_selected_LEAF_interlock_mandatory;
|
||||
extern bool user_selected_tesla_digital_HVIL;
|
||||
extern uint16_t user_selected_tesla_GTW_country;
|
||||
extern bool user_selected_tesla_GTW_rightHandDrive;
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
#include "BMW-I3-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef BMW_I3_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BmwI3Battery
|
||||
#endif
|
||||
|
||||
class BmwI3Battery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -37,7 +37,7 @@ uint8_t BmwIXBattery::increment_alive_counter(uint8_t counter) {
|
|||
return counter;
|
||||
}
|
||||
|
||||
static byte increment_C0_counter(byte counter) {
|
||||
static uint8_t increment_C0_counter(uint8_t counter) {
|
||||
counter++;
|
||||
// Reset to 0xF0 if it exceeds 0xFE
|
||||
if (counter > 0xFE) {
|
||||
|
@ -60,7 +60,7 @@ void BmwIXBattery::update_values() { //This function maps all the values fetche
|
|||
|
||||
datalayer.battery.status.soh_pptt = min_soh_state;
|
||||
|
||||
datalayer.battery.status.max_discharge_power_W = MAX_DISCHARGE_POWER_ALLOWED_W;
|
||||
datalayer.battery.status.max_discharge_power_W = datalayer.battery.status.override_discharge_power_W;
|
||||
|
||||
//datalayer.battery.status.max_charge_power_W = 3200; //10000; //Aux HV Port has 100A Fuse Moved to Ramping
|
||||
|
||||
|
@ -70,10 +70,10 @@ void BmwIXBattery::update_values() { //This function maps all the values fetche
|
|||
} else if (datalayer.battery.status.real_soc > RAMPDOWN_SOC) {
|
||||
// When real SOC is between RAMPDOWN_SOC-99%, ramp the value between Max<->0
|
||||
datalayer.battery.status.max_charge_power_W =
|
||||
MAX_CHARGE_POWER_ALLOWED_W *
|
||||
datalayer.battery.status.override_charge_power_W *
|
||||
(1 - (datalayer.battery.status.real_soc - RAMPDOWN_SOC) / (10000.0 - RAMPDOWN_SOC));
|
||||
} else { // No limits, max charging power allowed
|
||||
datalayer.battery.status.max_charge_power_W = MAX_CHARGE_POWER_ALLOWED_W;
|
||||
datalayer.battery.status.max_charge_power_W = datalayer.battery.status.override_charge_power_W;
|
||||
}
|
||||
|
||||
datalayer.battery.status.temperature_min_dC = min_battery_temperature;
|
||||
|
@ -459,10 +459,12 @@ void BmwIXBattery::setup(void) { // Performs one time setup at startup
|
|||
|
||||
void BmwIXBattery::HandleIncomingUserRequest(void) {
|
||||
// Debug user request to open or close the contactors
|
||||
logging.print("User request: contactor close: ");
|
||||
logging.print(userRequestContactorClose);
|
||||
logging.print(" User request: contactor open: ");
|
||||
logging.println(userRequestContactorOpen);
|
||||
if (userRequestContactorClose) {
|
||||
logging.printf("User request: contactor close");
|
||||
}
|
||||
if (userRequestContactorOpen) {
|
||||
logging.printf("User request: contactor open");
|
||||
}
|
||||
if ((userRequestContactorClose == false) && (userRequestContactorOpen == false)) {
|
||||
// do nothing
|
||||
} else if ((userRequestContactorClose == true) && (userRequestContactorOpen == false)) {
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "BMW-IX-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef BMW_IX_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BmwIXBattery
|
||||
#endif
|
||||
|
||||
class BmwIXBattery : public CanBattery {
|
||||
public:
|
||||
BmwIXBattery() : renderer(*this) {}
|
||||
|
@ -52,8 +48,6 @@ class BmwIXBattery : public CanBattery {
|
|||
static const int MAX_CELL_DEVIATION_MV = 250;
|
||||
static const int MAX_CELL_VOLTAGE_MV = 4300; //Battery is put into emergency stop if one cell goes over this value
|
||||
static const int MIN_CELL_VOLTAGE_MV = 2800; //Battery is put into emergency stop if one cell goes below this value
|
||||
static const int MAX_DISCHARGE_POWER_ALLOWED_W = 10000;
|
||||
static const int MAX_CHARGE_POWER_ALLOWED_W = 10000;
|
||||
static const int MAX_CHARGE_POWER_WHEN_TOPBALANCING_W = 500;
|
||||
static const int RAMPDOWN_SOC =
|
||||
9000; // (90.00) SOC% to start ramping down from max charge power towards 0 at 100.00%
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "BMW-PHEV-BATTERY.h"
|
||||
#include <Arduino.h>
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
@ -149,15 +150,6 @@ uint8_t BmwPhevBattery::increment_alive_counter(uint8_t counter) {
|
|||
return counter;
|
||||
}
|
||||
|
||||
static byte increment_0C0_counter(byte counter) {
|
||||
counter++;
|
||||
// Reset to 0xF0 if it exceeds 0xFE
|
||||
if (counter > 0xFE) {
|
||||
counter = 0xF0;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
void BmwPhevBattery::processCellVoltages() {
|
||||
const int startByte = 3; // Start reading at byte 3
|
||||
const int numVoltages = 96; // Number of cell voltage values to process
|
||||
|
@ -185,12 +177,15 @@ void BmwPhevBattery::wake_battery_via_canbus() {
|
|||
// Followed by a Recessive interval of at least ~3 µs (min) and at most ~10 µs (max)
|
||||
// Then a second dominant pulse of similar timing.
|
||||
|
||||
auto original_speed = change_can_speed(CAN_Speed::CAN_SPEED_100KBPS);
|
||||
change_can_speed(CAN_Speed::CAN_SPEED_100KBPS);
|
||||
|
||||
transmit_can_frame(&BMW_PHEV_BUS_WAKEUP_REQUEST);
|
||||
transmit_can_frame(&BMW_PHEV_BUS_WAKEUP_REQUEST);
|
||||
|
||||
change_can_speed(original_speed);
|
||||
// FIXME: This might not wait for the above frames to send before it changes
|
||||
// the speed back. A state-machine controlled delay is likely necessary.
|
||||
|
||||
reset_can_speed();
|
||||
|
||||
logging.println("Sent magic wakeup packet to SME at 100kbps...");
|
||||
}
|
||||
|
@ -469,7 +464,7 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
#endif // DEBUG_LOG && UDS_LOG
|
||||
transmit_can_frame(&BMW_6F1_REQUEST_CONTINUE_MULTIFRAME);
|
||||
gUDSContext.receivedInBatch = 0; // Reset batch count
|
||||
Serial.println("Sent FC for next batch of 3 frames.");
|
||||
logging.println("Sent FC for next batch of 3 frames.");
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -513,18 +508,18 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
battery_current = ((int32_t)((gUDSContext.UDS_buffer[3] << 24) | (gUDSContext.UDS_buffer[4] << 16) |
|
||||
(gUDSContext.UDS_buffer[5] << 8) | gUDSContext.UDS_buffer[6])) *
|
||||
0.1;
|
||||
logging.print("Received current/amps measurement data: ");
|
||||
logging.printf("Received current/amps measurement data: ");
|
||||
logging.print(battery_current);
|
||||
logging.print(" - ");
|
||||
logging.printf(" - ");
|
||||
for (uint16_t i = 0; i < gUDSContext.UDS_bytesReceived; i++) {
|
||||
// Optional leading zero for single-digit hex
|
||||
if (gUDSContext.UDS_buffer[i] < 0x10) {
|
||||
logging.print("0");
|
||||
logging.printf("0");
|
||||
}
|
||||
logging.print(gUDSContext.UDS_buffer[i], HEX);
|
||||
logging.print(" ");
|
||||
logging.printf(" ");
|
||||
}
|
||||
logging.println(); // new line at the end
|
||||
logging.println(""); // new line at the end
|
||||
}
|
||||
|
||||
//Cell Min/Max
|
||||
|
@ -540,14 +535,14 @@ void BmwPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
max_cell_voltage = (gUDSContext.UDS_buffer[11] << 8 | gUDSContext.UDS_buffer[12]) / 10;
|
||||
} else {
|
||||
logging.println("Cell Min Max Invalid 65535 or 0...");
|
||||
logging.print("Received data: ");
|
||||
logging.printf("Received data: ");
|
||||
for (uint16_t i = 0; i < gUDSContext.UDS_bytesReceived; i++) {
|
||||
// Optional leading zero for single-digit hex
|
||||
if (gUDSContext.UDS_buffer[i] < 0x10) {
|
||||
logging.print("0");
|
||||
logging.printf("0");
|
||||
}
|
||||
logging.print(gUDSContext.UDS_buffer[i], HEX);
|
||||
logging.print(" ");
|
||||
logging.printf(" ");
|
||||
}
|
||||
logging.println(); // new line at the end
|
||||
}
|
||||
|
@ -678,7 +673,7 @@ void BmwPhevBattery::transmit_can(unsigned long currentMillis) {
|
|||
}
|
||||
|
||||
void BmwPhevBattery::setup(void) { // Performs one time setup at startup
|
||||
strncpy(datalayer.system.info.battery_protocol, "BMW PHEV Battery", 63);
|
||||
strncpy(datalayer.system.info.battery_protocol, Name, 63);
|
||||
datalayer.system.info.battery_protocol[63] = '\0';
|
||||
//Wakeup the SME
|
||||
wake_battery_via_canbus();
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "BMW-PHEV-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef BMW_PHEV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BmwPhevBattery
|
||||
#endif
|
||||
|
||||
class BmwPhevBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
@ -14,6 +10,8 @@ class BmwPhevBattery : public CanBattery {
|
|||
virtual void update_values();
|
||||
virtual void transmit_can(unsigned long currentMillis);
|
||||
|
||||
static constexpr const char* Name = "BMW PHEV Battery";
|
||||
|
||||
BatteryHtmlRenderer& get_status_renderer() { return renderer; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "BOLT-AMPERA-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
@ -95,14 +96,14 @@ void BoltAmperaBattery::update_values() { //This function maps all the values f
|
|||
} else if (datalayer.battery.status.real_soc > RAMPDOWN_SOC) {
|
||||
// When real SOC is between RAMPDOWN_SOC-99%, ramp the value between Max<->0
|
||||
datalayer.battery.status.max_charge_power_W =
|
||||
MAX_CHARGE_POWER_ALLOWED_W *
|
||||
datalayer.battery.status.override_charge_power_W *
|
||||
(1 - (datalayer.battery.status.real_soc - RAMPDOWN_SOC) / (10000.0 - RAMPDOWN_SOC));
|
||||
} else { // No limits, max charging power allowed
|
||||
datalayer.battery.status.max_charge_power_W = MAX_CHARGE_POWER_ALLOWED_W;
|
||||
datalayer.battery.status.max_charge_power_W = datalayer.battery.status.override_charge_power_W;
|
||||
}
|
||||
|
||||
// Discharge power is also set in .h file (TODO: Remove this estimation when real value has been found)
|
||||
datalayer.battery.status.max_discharge_power_W = MAX_DISCHARGE_POWER_ALLOWED_W;
|
||||
datalayer.battery.status.max_discharge_power_W = datalayer.battery.status.override_discharge_power_W;
|
||||
|
||||
datalayer.battery.status.temperature_min_dC = temperature_lowest_C * 10;
|
||||
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "BOLT-AMPERA-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef BOLT_AMPERA_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BoltAmperaBattery
|
||||
#endif
|
||||
|
||||
class BoltAmperaBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
@ -20,8 +16,6 @@ class BoltAmperaBattery : public CanBattery {
|
|||
|
||||
private:
|
||||
BoltAmperaHtmlRenderer renderer;
|
||||
static const int MAX_DISCHARGE_POWER_ALLOWED_W = 10000;
|
||||
static const int MAX_CHARGE_POWER_ALLOWED_W = 10000;
|
||||
static const int MAX_CHARGE_POWER_WHEN_TOPBALANCING_W = 500;
|
||||
static const int RAMPDOWN_SOC =
|
||||
9000; // (90.00) SOC% to start ramping down from max charge power towards 0 at 100.00%
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "BYD-ATTO-3-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
|
|
@ -24,9 +24,6 @@ static const int RAMPDOWN_POWER_ALLOWED =
|
|||
10000; // Power to start ramp down from, set a lower value to limit the power even further as SOC decreases
|
||||
|
||||
/* Do not modify the rows below */
|
||||
#ifdef BYD_ATTO_3_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS BydAttoBattery
|
||||
#endif
|
||||
|
||||
class BydAttoBattery : public CanBattery {
|
||||
public:
|
||||
|
|
|
@ -47,6 +47,7 @@ enum class BatteryType {
|
|||
HyundaiIoniq28 = 39,
|
||||
Kia64FD = 40,
|
||||
RelionBattery = 41,
|
||||
RivianBattery = 42,
|
||||
Highest
|
||||
};
|
||||
|
||||
|
|
|
@ -20,9 +20,11 @@ void CellPowerBms::update_values() {
|
|||
|
||||
datalayer.battery.status.current_dA = battery_pack_current_dA;
|
||||
|
||||
datalayer.battery.status.max_charge_power_W = 5000; //TODO, is this available via CAN?
|
||||
datalayer.battery.status.max_charge_power_W =
|
||||
datalayer.battery.status.override_charge_power_W; //TODO, is this available via CAN?
|
||||
|
||||
datalayer.battery.status.max_discharge_power_W = 5000; //TODO, is this available via CAN?
|
||||
datalayer.battery.status.max_discharge_power_W =
|
||||
datalayer.battery.status.override_discharge_power_W; //TODO, is this available via CAN?
|
||||
|
||||
datalayer.battery.status.temperature_min_dC = (int16_t)(pack_temperature_low_C * 10);
|
||||
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "CELLPOWER-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef CELLPOWER_BMS
|
||||
#define SELECTED_BATTERY_CLASS CellPowerBms
|
||||
#endif
|
||||
|
||||
class CellPowerBms : public CanBattery {
|
||||
public:
|
||||
CellPowerBms() : CanBattery(CAN_Speed::CAN_SPEED_250KBPS) {}
|
||||
|
|
|
@ -120,7 +120,7 @@ void ChademoBattery::process_vehicle_charging_session(CAN_frame rx_frame) {
|
|||
uint8_t chargingrate = 0;
|
||||
if (x100_chg_lim.ConstantOfChargingRateIndication > 0) {
|
||||
chargingrate = x102_chg_session.StateOfCharge / x100_chg_lim.ConstantOfChargingRateIndication * 100;
|
||||
logging.print("Charge Rate (kW): ");
|
||||
logging.printf("Charge Rate (kW): ");
|
||||
logging.println(chargingrate);
|
||||
}
|
||||
|
||||
|
@ -220,9 +220,9 @@ void ChademoBattery::process_vehicle_charging_limits(CAN_frame rx_frame) {
|
|||
|
||||
if (get_measured_voltage() <= x200_discharge_limits.MinimumDischargeVoltage && CHADEMO_Status > CHADEMO_NEGOTIATE) {
|
||||
logging.println("x200 minimum discharge voltage met or exceeded, stopping.");
|
||||
logging.print("Measured: ");
|
||||
logging.printf("Measured: ");
|
||||
logging.print(get_measured_voltage());
|
||||
logging.print("Minimum voltage: ");
|
||||
logging.printf("Minimum voltage: ");
|
||||
logging.print(x200_discharge_limits.MinimumDischargeVoltage);
|
||||
CHADEMO_Status = CHADEMO_STOP;
|
||||
}
|
||||
|
@ -240,9 +240,9 @@ void ChademoBattery::process_vehicle_discharge_estimate(CAN_frame rx_frame) {
|
|||
|
||||
if (currentMillis - previousMillis5000 >= INTERVAL_5_S) {
|
||||
previousMillis5000 = currentMillis;
|
||||
logging.print("x201 availabile vehicle energy, completion time: ");
|
||||
logging.printf("x201 availabile vehicle energy, completion time: ");
|
||||
logging.println(x201_discharge_estimate.AvailableVehicleEnergy);
|
||||
logging.print("x201 approx vehicle completion time: ");
|
||||
logging.printf("x201 approx vehicle completion time: ");
|
||||
logging.println(x201_discharge_estimate.ApproxDischargeCompletionTime);
|
||||
}
|
||||
}
|
||||
|
@ -766,7 +766,7 @@ void ChademoBattery::handle_chademo_sequence() {
|
|||
/* check whether contactors ready, because externally dependent upon inverter allow during discharge */
|
||||
if (contactors_ready) {
|
||||
logging.println("Contactors ready");
|
||||
logging.print("Voltage: ");
|
||||
logging.printf("Voltage: ");
|
||||
logging.println(get_measured_voltage());
|
||||
/* transition to POWERFLOW state if discharge compatible on both sides */
|
||||
if (x109_evse_state.discharge_compatible && x102_chg_session.s.status.StatusVehicleDischargeCompatible &&
|
||||
|
|
|
@ -7,13 +7,6 @@
|
|||
#include "CHADEMO-BATTERY-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef CHADEMO_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS ChademoBattery
|
||||
|
||||
//Contactor control is required for CHADEMO support
|
||||
#define CONTACTOR_CONTROL
|
||||
#endif
|
||||
|
||||
class ChademoBattery : public CanBattery {
|
||||
public:
|
||||
ChademoBattery() {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "CHADEMO-BATTERY.h"
|
||||
#include "src/devboard/utils/logging.h"
|
||||
|
||||
/* Initial frames received from ISA shunts provide invalid during initialization */
|
||||
static int framecount = 0;
|
||||
|
@ -87,17 +86,6 @@ void ISA_handleFrame(CAN_frame* frame) {
|
|||
|
||||
case 0x510:
|
||||
case 0x511:
|
||||
logging.print(millis()); // Example printout, time, ID, length, data: 7553 1DB 8 FF C0 B9 EA 0 0 2 5D
|
||||
logging.print(" ");
|
||||
logging.print(frame->ID, HEX);
|
||||
logging.print(" ");
|
||||
logging.print(frame->DLC);
|
||||
logging.print(" ");
|
||||
for (int i = 0; i < frame->DLC; ++i) {
|
||||
logging.print(frame->data.u8[i], HEX);
|
||||
logging.print(" ");
|
||||
}
|
||||
logging.println("");
|
||||
break;
|
||||
|
||||
case 0x521:
|
||||
|
@ -245,7 +233,7 @@ void ISA_initialize() {
|
|||
ISA_STOP();
|
||||
delay(500);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
logging.print("ISA Initialization ");
|
||||
logging.printf("ISA Initialization ");
|
||||
logging.println(i);
|
||||
|
||||
outframe.data.u8[0] = (0x20 + i);
|
||||
|
@ -382,7 +370,7 @@ void ISA_initCurrent() {
|
|||
}
|
||||
|
||||
void ISA_getCONFIG(uint8_t i) {
|
||||
logging.print("ISA Get Config ");
|
||||
logging.printf("ISA Get Config ");
|
||||
logging.println(i);
|
||||
|
||||
outframe.data.u8[0] = (0x60 + i);
|
||||
|
@ -398,7 +386,7 @@ void ISA_getCONFIG(uint8_t i) {
|
|||
}
|
||||
|
||||
void ISA_getCAN_ID(uint8_t i) {
|
||||
logging.print("ISA Get CAN ID ");
|
||||
logging.printf("ISA Get CAN ID ");
|
||||
logging.println(i);
|
||||
|
||||
outframe.data.u8[0] = (0x50 + i);
|
||||
|
@ -418,8 +406,8 @@ void ISA_getCAN_ID(uint8_t i) {
|
|||
}
|
||||
|
||||
void ISA_getINFO(uint8_t i) {
|
||||
logging.print("ISA Get INFO ");
|
||||
logging.println(i, HEX);
|
||||
logging.printf("ISA Get INFO ");
|
||||
logging.println(i);
|
||||
|
||||
outframe.data.u8[0] = (0x70 + i);
|
||||
outframe.data.u8[1] = 0x00;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "CMFA-EV-BATTERY.h"
|
||||
#include <cstring> //unit tests memcpy
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CMFA-EV-HTML.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef CMFA_EV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS CmfaEvBattery
|
||||
#endif
|
||||
|
||||
class CmfaEvBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
#include "CanBattery.h"
|
||||
|
||||
CanBattery::CanBattery(CAN_Speed speed) {
|
||||
can_interface = can_config.battery;
|
||||
CanBattery::CanBattery(CAN_Speed speed) : CanBattery(can_config.battery, speed) {}
|
||||
|
||||
CanBattery::CanBattery(CAN_Interface interface, CAN_Speed speed) {
|
||||
can_interface = interface;
|
||||
initial_speed = speed;
|
||||
register_transmitter(this);
|
||||
register_can_receiver(this, can_interface, speed);
|
||||
}
|
||||
|
||||
CAN_Speed CanBattery::change_can_speed(CAN_Speed speed) {
|
||||
bool CanBattery::change_can_speed(CAN_Speed speed) {
|
||||
return ::change_can_speed(can_interface, speed);
|
||||
}
|
||||
|
||||
void CanBattery::reset_can_speed() {
|
||||
::change_can_speed(can_interface, initial_speed);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "Battery.h"
|
||||
|
||||
#include "../../USER_SETTINGS.h"
|
||||
#include "../../src/communication/Transmitter.h"
|
||||
#include "../../src/communication/can/CanReceiver.h"
|
||||
#include "../../src/communication/can/comm_can.h"
|
||||
|
@ -23,16 +22,13 @@ class CanBattery : public Battery, Transmitter, CanReceiver {
|
|||
|
||||
protected:
|
||||
CAN_Interface can_interface;
|
||||
CAN_Speed initial_speed;
|
||||
|
||||
CanBattery(CAN_Speed speed = CAN_Speed::CAN_SPEED_500KBPS);
|
||||
CanBattery(CAN_Interface interface, CAN_Speed speed = CAN_Speed::CAN_SPEED_500KBPS);
|
||||
|
||||
CanBattery(CAN_Interface interface, CAN_Speed speed = CAN_Speed::CAN_SPEED_500KBPS) {
|
||||
can_interface = interface;
|
||||
register_transmitter(this);
|
||||
register_can_receiver(this, can_interface, speed);
|
||||
}
|
||||
|
||||
CAN_Speed change_can_speed(CAN_Speed speed);
|
||||
bool change_can_speed(CAN_Speed speed);
|
||||
void reset_can_speed();
|
||||
|
||||
void transmit_can_frame(const CAN_frame* frame) { transmit_can_frame_to_interface(frame, can_interface); }
|
||||
};
|
||||
|
|
|
@ -16,7 +16,7 @@ static uint16_t voltage_dV = 0;
|
|||
static uint32_t remaining_capacity_mAh = 0;
|
||||
static uint16_t cellvoltages_mV[48] = {0};
|
||||
static uint16_t cellvoltage_min_mV = 3700;
|
||||
static uint16_t cellvoltage_max_mV = 3700;
|
||||
static uint16_t cellvoltage_max_mV = 0;
|
||||
static uint16_t cell_count = 0;
|
||||
static uint16_t SOC = 0;
|
||||
static bool has_fault = false;
|
||||
|
@ -27,8 +27,9 @@ void DalyBms::update_values() {
|
|||
datalayer.battery.status.current_dA = current_dA; //value is *10 (150 = 15.0)
|
||||
datalayer.battery.status.remaining_capacity_Wh = (remaining_capacity_mAh * (uint32_t)voltage_dV) / 10000;
|
||||
|
||||
datalayer.battery.status.max_charge_power_W = (BATTERY_MAX_CHARGE_AMP * voltage_dV) / 100;
|
||||
datalayer.battery.status.max_discharge_power_W = (BATTERY_MAX_DISCHARGE_AMP * voltage_dV) / 100;
|
||||
datalayer.battery.status.max_charge_power_W = (datalayer.battery.settings.max_user_set_charge_dA * voltage_dV) / 100;
|
||||
datalayer.battery.status.max_discharge_power_W =
|
||||
(datalayer.battery.settings.max_user_set_discharge_dA * voltage_dV) / 100;
|
||||
|
||||
// limit power when SoC is low or high
|
||||
uint32_t adaptive_power_limit = 999999;
|
||||
|
@ -72,7 +73,6 @@ void DalyBms::setup(void) { // Performs one time setup at startup
|
|||
datalayer.battery.info.min_design_voltage_dV = user_selected_min_pack_voltage_dV;
|
||||
datalayer.battery.info.max_cell_voltage_mV = user_selected_max_cell_voltage_mV;
|
||||
datalayer.battery.info.min_cell_voltage_mV = user_selected_min_cell_voltage_mV;
|
||||
datalayer.battery.info.total_capacity_Wh = BATTERY_WH_MAX;
|
||||
datalayer.system.status.battery_allows_contactor_closing = true;
|
||||
|
||||
auto rx_pin = esp32hal->RS485_RX_PIN();
|
||||
|
@ -109,12 +109,12 @@ uint32_t decode_uint32be(uint8_t data[8], uint8_t offset) {
|
|||
}
|
||||
|
||||
void dump_buff(const char* msg, uint8_t* buff, uint8_t len) {
|
||||
logging.print("[DALY-BMS] ");
|
||||
logging.print(msg);
|
||||
logging.printf("[DALY-BMS] ");
|
||||
logging.printf(msg);
|
||||
for (int i = 0; i < len; i++) {
|
||||
logging.print(buff[i] >> 4, HEX);
|
||||
logging.print(buff[i] & 0xf, HEX);
|
||||
logging.print(" ");
|
||||
logging.printf(" ");
|
||||
}
|
||||
logging.println();
|
||||
}
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "RS485Battery.h"
|
||||
|
||||
#ifdef DALY_BMS
|
||||
#define SELECTED_BATTERY_CLASS DalyBms
|
||||
#endif
|
||||
|
||||
class DalyBms : public RS485Battery {
|
||||
public:
|
||||
void setup();
|
||||
|
|
|
@ -5,51 +5,118 @@
|
|||
#include "../devboard/utils/events.h"
|
||||
|
||||
/* TODO:
|
||||
This integration is still ongoing. Here is what still needs to be done in order to use this battery type
|
||||
- Disable the isolation resistance requirement that opens contactors after 30s under load. Factory mode?
|
||||
This integration is still ongoing. The same integration can be used on multiple variants of the Stellantis platforms
|
||||
- eCMP: Disable the isolation resistance requirement that opens contactors after 30s under load. Factory mode?
|
||||
|
||||
- MysteryVan: Map more values from constantly transmitted instead of PID
|
||||
- ADD CAN sending towards the battery (CAN-logs of full vehicle wanted!)
|
||||
- Following CAN messages need to be sent towards it:
|
||||
- VCU: 4C9 , 565 , 398, 448, 458, 4F1 , 342, 3E2 , 402 , 422 , 482 4D1
|
||||
- CMM: 478 , 558, 1A8, 4B8 1F8 498 4E8
|
||||
- OBC: 531 441 541 551 3C1
|
||||
- BSIInfo_382
|
||||
- VCU_BSI_Wakeup_27A
|
||||
- V2_BSI_552
|
||||
- CRASH_4C8
|
||||
- EVSE plug in (optional): 108, 109, 119
|
||||
- CRASH_4C8
|
||||
- CRNT_SENS_095
|
||||
- MCU 526
|
||||
- JDD 55F NEW
|
||||
|
||||
- STLA medium: Everything missing
|
||||
- ADD CAN sending towards the battery (CAN-logs of full vehicle wanted!)
|
||||
*/
|
||||
|
||||
/* Do not change code below unless you are sure what you are doing */
|
||||
void EcmpBattery::update_values() {
|
||||
|
||||
datalayer.battery.status.real_soc = battery_soc * 10;
|
||||
if (!MysteryVan) { //Normal eCMP platform
|
||||
datalayer.battery.status.real_soc = battery_soc * 10;
|
||||
|
||||
datalayer.battery.status.soh_pptt;
|
||||
datalayer.battery.status.soh_pptt;
|
||||
|
||||
datalayer.battery.status.voltage_dV = battery_voltage * 10;
|
||||
datalayer.battery.status.voltage_dV = battery_voltage * 10;
|
||||
|
||||
datalayer.battery.status.current_dA = -(battery_current * 10);
|
||||
datalayer.battery.status.current_dA = -(battery_current * 10);
|
||||
|
||||
datalayer.battery.status.active_power_W = //Power in watts, Negative = charging batt
|
||||
((datalayer.battery.status.voltage_dV * datalayer.battery.status.current_dA) / 100);
|
||||
datalayer.battery.status.active_power_W = //Power in watts, Negative = charging batt
|
||||
((datalayer.battery.status.voltage_dV * datalayer.battery.status.current_dA) / 100);
|
||||
|
||||
datalayer.battery.status.max_charge_power_W = battery_AllowedMaxChargeCurrent * battery_voltage;
|
||||
datalayer.battery.status.remaining_capacity_Wh = static_cast<uint32_t>(
|
||||
(static_cast<double>(datalayer.battery.status.real_soc) / 10000) * datalayer.battery.info.total_capacity_Wh);
|
||||
|
||||
datalayer.battery.status.max_discharge_power_W = battery_AllowedMaxDischargeCurrent * battery_voltage;
|
||||
datalayer.battery.status.max_charge_power_W = battery_AllowedMaxChargeCurrent * battery_voltage;
|
||||
|
||||
datalayer.battery.status.temperature_min_dC = battery_lowestTemperature * 10;
|
||||
datalayer.battery.status.max_discharge_power_W = battery_AllowedMaxDischargeCurrent * battery_voltage;
|
||||
|
||||
datalayer.battery.status.temperature_max_dC = battery_highestTemperature * 10;
|
||||
datalayer.battery.status.temperature_min_dC = battery_lowestTemperature * 10;
|
||||
|
||||
// Initialize min and max, lets find which cells are min and max!
|
||||
uint16_t min_cell_mv_value = std::numeric_limits<uint16_t>::max();
|
||||
uint16_t max_cell_mv_value = 0;
|
||||
// Loop to find the min and max while ignoring zero values
|
||||
for (uint8_t i = 0; i < datalayer.battery.info.number_of_cells; ++i) {
|
||||
uint16_t voltage_mV = datalayer.battery.status.cell_voltages_mV[i];
|
||||
if (voltage_mV != 0) { // Skip unread values (0)
|
||||
min_cell_mv_value = std::min(min_cell_mv_value, voltage_mV);
|
||||
max_cell_mv_value = std::max(max_cell_mv_value, voltage_mV);
|
||||
datalayer.battery.status.temperature_max_dC = battery_highestTemperature * 10;
|
||||
|
||||
// Initialize min and max, lets find which cells are min and max!
|
||||
uint16_t min_cell_mv_value = std::numeric_limits<uint16_t>::max();
|
||||
uint16_t max_cell_mv_value = 0;
|
||||
// Loop to find the min and max while ignoring zero values
|
||||
for (uint8_t i = 0; i < datalayer.battery.info.number_of_cells; ++i) {
|
||||
uint16_t voltage_mV = datalayer.battery.status.cell_voltages_mV[i];
|
||||
if (voltage_mV != 0) { // Skip unread values (0)
|
||||
min_cell_mv_value = std::min(min_cell_mv_value, voltage_mV);
|
||||
max_cell_mv_value = std::max(max_cell_mv_value, voltage_mV);
|
||||
}
|
||||
}
|
||||
// If all array values are 0, reset min/max to 3700
|
||||
if (min_cell_mv_value == std::numeric_limits<uint16_t>::max()) {
|
||||
min_cell_mv_value = 3700;
|
||||
max_cell_mv_value = 3700;
|
||||
}
|
||||
}
|
||||
// If all array values are 0, reset min/max to 3700
|
||||
if (min_cell_mv_value == std::numeric_limits<uint16_t>::max()) {
|
||||
min_cell_mv_value = 3700;
|
||||
max_cell_mv_value = 3700;
|
||||
}
|
||||
|
||||
datalayer.battery.status.cell_min_voltage_mV = min_cell_mv_value;
|
||||
datalayer.battery.status.cell_max_voltage_mV = max_cell_mv_value;
|
||||
datalayer.battery.status.cell_min_voltage_mV = min_cell_mv_value;
|
||||
datalayer.battery.status.cell_max_voltage_mV = max_cell_mv_value;
|
||||
} else { //Some variant of the 50/75kWh battery that is not using the eCMP CAN mappings.
|
||||
// For these batteries we need to use the OBD2 PID polled values
|
||||
|
||||
if (pid_energy_capacity != NOT_SAMPLED_YET) {
|
||||
datalayer.battery.status.remaining_capacity_Wh = pid_energy_capacity;
|
||||
// calculate SOC based on datalayer.battery.info.total_capacity_Wh and remaining_capacity_Wh
|
||||
datalayer.battery.status.real_soc = (uint16_t)(((float)datalayer.battery.status.remaining_capacity_Wh /
|
||||
datalayer.battery.info.total_capacity_Wh) *
|
||||
10000);
|
||||
}
|
||||
|
||||
datalayer.battery.status.soh_pptt;
|
||||
|
||||
if (pid_pack_voltage != NOT_SAMPLED_YET) {
|
||||
datalayer.battery.status.voltage_dV = pid_pack_voltage + 800;
|
||||
}
|
||||
|
||||
if (pid_current != NOT_SAMPLED_YET) {
|
||||
datalayer.battery.status.current_dA = (int16_t)(pid_current / 100);
|
||||
|
||||
datalayer.battery.status.active_power_W =
|
||||
(uint16_t)((pid_current / 1000.0f) * (datalayer.battery.status.voltage_dV / 10.0f));
|
||||
}
|
||||
|
||||
if (pid_max_charge_10s != NOT_SAMPLED_YET) {
|
||||
datalayer.battery.status.max_charge_power_W = pid_max_charge_10s;
|
||||
}
|
||||
|
||||
if (pid_max_discharge_10s != NOT_SAMPLED_YET) {
|
||||
datalayer.battery.status.max_discharge_power_W = pid_max_discharge_10s;
|
||||
}
|
||||
|
||||
if ((pid_highest_temperature != NOT_SAMPLED_YET) && (pid_lowest_temperature != NOT_SAMPLED_YET)) {
|
||||
datalayer.battery.status.temperature_max_dC = pid_highest_temperature * 10;
|
||||
datalayer.battery.status.temperature_min_dC = pid_lowest_temperature * 10;
|
||||
}
|
||||
|
||||
if ((pid_high_cell_voltage != NOT_SAMPLED_YET) && (pid_low_cell_voltage != NOT_SAMPLED_YET)) {
|
||||
datalayer.battery.status.cell_max_voltage_mV = pid_high_cell_voltage;
|
||||
datalayer.battery.status.cell_min_voltage_mV = pid_low_cell_voltage;
|
||||
}
|
||||
|
||||
datalayer.battery.info.number_of_cells = NUMBER_OF_CELL_MEASUREMENTS_IN_BATTERY; //50/75kWh sends valid cellcount
|
||||
}
|
||||
|
||||
// Update extended datalayer (More Battery Info page)
|
||||
datalayer_extended.stellantisECMP.MainConnectorState = battery_MainConnectorState;
|
||||
|
@ -124,6 +191,28 @@ void EcmpBattery::update_values() {
|
|||
datalayer_extended.stellantisECMP.pid_contactor_closing_counter = pid_contactor_closing_counter;
|
||||
datalayer_extended.stellantisECMP.pid_date_of_manufacture = pid_date_of_manufacture;
|
||||
datalayer_extended.stellantisECMP.pid_SOH_cell_1 = pid_SOH_cell_1;
|
||||
// Update extended datalayer for MysteryVan
|
||||
datalayer_extended.stellantisECMP.MysteryVan = MysteryVan;
|
||||
datalayer_extended.stellantisECMP.CONTACTORS_STATE = CONTACTORS_STATE;
|
||||
datalayer_extended.stellantisECMP.CrashMemorized = HV_BATT_CRASH_MEMORIZED;
|
||||
datalayer_extended.stellantisECMP.CONTACTOR_OPENING_REASON = CONTACTOR_OPENING_REASON;
|
||||
datalayer_extended.stellantisECMP.TBMU_FAULT_TYPE = TBMU_FAULT_TYPE;
|
||||
datalayer_extended.stellantisECMP.HV_BATT_FC_INSU_MINUS_RES = HV_BATT_FC_INSU_MINUS_RES;
|
||||
datalayer_extended.stellantisECMP.HV_BATT_FC_INSU_PLUS_RES = HV_BATT_FC_INSU_PLUS_RES;
|
||||
datalayer_extended.stellantisECMP.HV_BATT_FC_VHL_INSU_PLUS_RES = HV_BATT_FC_VHL_INSU_PLUS_RES;
|
||||
datalayer_extended.stellantisECMP.HV_BATT_ONLY_INSU_MINUS_RES = HV_BATT_ONLY_INSU_MINUS_RES;
|
||||
datalayer_extended.stellantisECMP.HV_BATT_ONLY_INSU_MINUS_RES = HV_BATT_ONLY_INSU_MINUS_RES;
|
||||
datalayer_extended.stellantisECMP.ALERT_CELL_POOR_CONSIST = ALERT_CELL_POOR_CONSIST;
|
||||
datalayer_extended.stellantisECMP.ALERT_OVERCHARGE = ALERT_OVERCHARGE;
|
||||
datalayer_extended.stellantisECMP.ALERT_BATT = ALERT_BATT;
|
||||
datalayer_extended.stellantisECMP.ALERT_LOW_SOC = ALERT_LOW_SOC;
|
||||
datalayer_extended.stellantisECMP.ALERT_HIGH_SOC = ALERT_HIGH_SOC;
|
||||
datalayer_extended.stellantisECMP.ALERT_SOC_JUMP = ALERT_SOC_JUMP;
|
||||
datalayer_extended.stellantisECMP.ALERT_TEMP_DIFF = ALERT_TEMP_DIFF;
|
||||
datalayer_extended.stellantisECMP.ALERT_HIGH_TEMP = ALERT_HIGH_TEMP;
|
||||
datalayer_extended.stellantisECMP.ALERT_OVERVOLTAGE = ALERT_OVERVOLTAGE;
|
||||
datalayer_extended.stellantisECMP.ALERT_CELL_OVERVOLTAGE = ALERT_CELL_OVERVOLTAGE;
|
||||
datalayer_extended.stellantisECMP.ALERT_CELL_UNDERVOLTAGE = ALERT_CELL_UNDERVOLTAGE;
|
||||
|
||||
if (battery_InterlockOpen) {
|
||||
set_event(EVENT_HVIL_FAILURE, 0);
|
||||
|
@ -145,9 +234,223 @@ void EcmpBattery::update_values() {
|
|||
}
|
||||
|
||||
void EcmpBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.ID) {
|
||||
case 0x125: //Common
|
||||
case 0x2D4: //MysteryVan 50/75kWh platform (TBMU 100ms periodic)
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
MysteryVan = true;
|
||||
SOE_MAX_CURRENT_TEMP = (rx_frame.data.u8[2] << 8) | rx_frame.data.u8[3]; // (Wh, 0-200000)
|
||||
FRONT_MACHINE_POWER_LIMIT = (rx_frame.data.u8[4] << 6) | ((rx_frame.data.u8[5] & 0xFC) >> 2); // (W 0-1000000)
|
||||
REAR_MACHINE_POWER_LIMIT = ((rx_frame.data.u8[5] & 0x03) << 12) | (rx_frame.data.u8[6] << 4) |
|
||||
((rx_frame.data.u8[7] & 0xF0) >> 4); // (W 0-1000000)
|
||||
break;
|
||||
case 0x3B4: //MysteryVan 50/75kWh platform (TBMU 100ms periodic)
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
EVSE_INSTANT_DC_HV_CURRENT =
|
||||
((rx_frame.data.u8[2] & 0x03) << 12) | (rx_frame.data.u8[3] << 2) | ((rx_frame.data.u8[4] & 0xC0) >> 6);
|
||||
EVSE_STATE = ((rx_frame.data.u8[4] & 0x38) >> 3); /*Enumeration below
|
||||
000: NOT CONNECTED
|
||||
001: CONNECTED
|
||||
010: INITIALISATION
|
||||
011: READY
|
||||
100: PRECHARGE IN PROGRESS
|
||||
101: TRANSFER IN PROGRESS
|
||||
110: NOT READY
|
||||
111: Reserved */
|
||||
HV_BATT_SOE_HD = ((rx_frame.data.u8[4] & 0x03) << 12) | (rx_frame.data.u8[5] << 4) |
|
||||
((rx_frame.data.u8[6] & 0xF0) >> 4); // (Wh, 0-200000)
|
||||
HV_BATT_SOE_MAX = ((rx_frame.data.u8[6] & 0x03) << 8) | rx_frame.data.u8[7]; // (Wh, 0-200000)
|
||||
CHECKSUM_FRAME_3B4 = (rx_frame.data.u8[0] & 0xF0) >> 4;
|
||||
COUNTER_3B4 = (rx_frame.data.u8[0] & 0x0F);
|
||||
break;
|
||||
case 0x2F4: //MysteryVan 50/75kWh platform (Event triggered when charging)
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
//TBMU_EVSE_DC_MES_VOLTAGE = (rx_frame.data.u8[0] << 6) | (rx_frame.data.u8[1] >> 2); //V 0-1000 //Fastcharger info, not needed for BE
|
||||
//TBMU_EVSE_DC_MIN_VOLTAGE = ((rx_frame.data.u8[1] & 0x03) << 8) | rx_frame.data.u8[2]; //V 0-1000 //Fastcharger info, not needed for BE
|
||||
//TBMU_EVSE_DC_MES_CURRENT = (rx_frame.data.u8[3] << 4) | ((rx_frame.data.u8[4] & 0xF0) >> 4); //A -2000 - 2000 //Fastcharger info, not needed for BE
|
||||
//TBMU_EVSE_CHRG_REQ = (rx_frame.data.u8[4] & 0x0C) >> 2; //00 No request, 01 Stop request //Fastcharger info, not needed for BE
|
||||
//HV_STORAGE_MAX_I = ((rx_frame.data.u8[4] & 0x03) << 12) | (rx_frame.data.u8[5] << 2) | //Fastcharger info, not needed for BE
|
||||
//((rx_frame.data.u8[6] & 0xC0) >> 6); //A -2000 - 2000
|
||||
//TBMU_EVSE_DC_MAX_POWER = ((rx_frame.data.u8[6] & 0x3F) << 8) | rx_frame.data.u8[7]; //W -1000000 - 0 //Fastcharger info, not needed for BE
|
||||
break;
|
||||
case 0x3F4: //MysteryVan 50/75kWh platform (Temperature sensors)
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (((rx_frame.data.u8[0] & 0xE0) >> 5)) //Mux resides in top 3 bits of frame0
|
||||
{
|
||||
case 0:
|
||||
BMS_PROBETEMP[0] = (rx_frame.data.u8[1] - 40);
|
||||
BMS_PROBETEMP[1] = (rx_frame.data.u8[2] - 40);
|
||||
BMS_PROBETEMP[2] = (rx_frame.data.u8[3] - 40);
|
||||
BMS_PROBETEMP[3] = (rx_frame.data.u8[4] - 40);
|
||||
BMS_PROBETEMP[4] = (rx_frame.data.u8[5] - 40);
|
||||
BMS_PROBETEMP[5] = (rx_frame.data.u8[6] - 40);
|
||||
BMS_PROBETEMP[6] = (rx_frame.data.u8[7] - 40);
|
||||
break;
|
||||
default: //There are in total 64 temperature measurements in the BMS. We do not need to sample them all.
|
||||
break; //For future, we could read them all if we want to.
|
||||
}
|
||||
break;
|
||||
case 0x554: //MysteryVan 50/75kWh platform (Discharge/Charge limits)
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
HV_BATT_PEAK_DISCH_POWER_HD = (rx_frame.data.u8[1] << 6) | (rx_frame.data.u8[2] >> 2); //0-1000000 W
|
||||
HV_BATT_PEAK_CH_POWER_HD = ((rx_frame.data.u8[2] & 0x03) << 12) | (rx_frame.data.u8[3] << 4) |
|
||||
((rx_frame.data.u8[4] & 0xF0) >> 4); // -1000000 - 0 W
|
||||
HV_BATT_NOM_CH_POWER_HD = ((rx_frame.data.u8[4] & 0x0F) << 12) | (rx_frame.data.u8[5] << 6) |
|
||||
((rx_frame.data.u8[6] & 0xC0) >> 6); // -1000000 - 0 W
|
||||
MAX_ALLOW_CHRG_CURRENT = ((rx_frame.data.u8[6] & 0x3F) << 8) | rx_frame.data.u8[7];
|
||||
CHECKSUM_FRAME_554 = (rx_frame.data.u8[0] & 0xF0) >> 4; //Frame checksum 0xE
|
||||
COUNTER_554 = (rx_frame.data.u8[0] & 0x0F);
|
||||
break;
|
||||
case 0x373: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
REQ_CLEAR_DTC_TBMU = ((rx_frame.data.u8[3] & 0x40) >> 7);
|
||||
TBCU_48V_WAKEUP = (rx_frame.data.u8[3] >> 7);
|
||||
HV_BATT_MAX_REAL_CURR = (rx_frame.data.u8[5] << 7) | (rx_frame.data.u8[6] >> 1); //A -2000 - 2000 0.1 scaling
|
||||
TBMU_FAULT_TYPE = (rx_frame.data.u8[7] & 0xE0) >> 5;
|
||||
/*000: No fault
|
||||
001: FirstLevelFault: Warning Lamp
|
||||
010: SecondLevelFault: Stop Lamp
|
||||
011: ThirdLevelFault: Stop Lamp + contactor opening (EPS shutdown)
|
||||
100: FourthLevelFault: Stop Lamp + Active Discharge
|
||||
101: Inhibition of powertrain activation
|
||||
110: Reserved
|
||||
111: Invalid*/
|
||||
HV_BATT_REAL_VOLT_HD = ((rx_frame.data.u8[3] & 0x3F) << 8) | (rx_frame.data.u8[4]); //V 0-1000 * 0.1 scaling
|
||||
HV_BATT_REAL_CURR_HD = (rx_frame.data.u8[1] << 8) | (rx_frame.data.u8[2]); //A -2000 - 2000 0.1 scaling
|
||||
CHECKSUM_FRAME_373 = (rx_frame.data.u8[0] & 0xF0) >> 4; //Frame checksum 0xD
|
||||
COUNTER_373 = (rx_frame.data.u8[0] & 0x0F);
|
||||
break;
|
||||
case 0x4F4: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
HV_BATT_CRASH_MEMORIZED = ((rx_frame.data.u8[2] & 0x08) >> 3);
|
||||
HV_BATT_COLD_CRANK_ACK = ((rx_frame.data.u8[2] & 0x04) >> 2);
|
||||
HV_BATT_CHARGE_NEEDED_STATE = ((rx_frame.data.u8[2] & 0x02) >> 1);
|
||||
HV_BATT_NOM_CH_VOLTAGE = ((rx_frame.data.u8[2] & 0x01) << 8) | (rx_frame.data.u8[3]); //V 0 - 500
|
||||
HV_BATT_NOM_CH_CURRENT = rx_frame.data.u8[4]; // -120 - 0 0.5scaling
|
||||
HV_BATT_GENERATED_HEAT_RATE = (rx_frame.data.u8[5] << 1) | (rx_frame.data.u8[6] >> 7); //W 0-50000
|
||||
REQ_MIL_LAMP_CONTINOUS = (rx_frame.data.u8[7] & 0x04) >> 2;
|
||||
REQ_BLINK_STOP_AND_SERVICE_LAMP = (rx_frame.data.u8[7] & 0x02) >> 1;
|
||||
CMD_RESET_MIL = (rx_frame.data.u8[7] & 0x01);
|
||||
HV_BATT_SOC = (rx_frame.data.u8[1] << 2) | (rx_frame.data.u8[2] >> 6);
|
||||
CONTACTORS_STATE =
|
||||
(rx_frame.data.u8[2] & 0x30) >> 4; //00 : contactor open 01 : pre-load contactor 10 : contactor close
|
||||
HV_BATT_DISCONT_WARNING_OPEN = (rx_frame.data.u8[7] & 0x08) >> 3;
|
||||
CHECKSUM_FRAME_4F4 = (rx_frame.data.u8[0] & 0xF0) >> 4;
|
||||
COUNTER_4F4 = (rx_frame.data.u8[0] & 0x0F);
|
||||
break;
|
||||
case 0x414: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
HV_BATT_REAL_POWER_HD = (rx_frame.data.u8[1] << 7) | (rx_frame.data.u8[2] >> 1);
|
||||
MAX_ALLOW_CHRG_POWER =
|
||||
((rx_frame.data.u8[2] & 0x01) << 13) | (rx_frame.data.u8[3] << 5) | ((rx_frame.data.u8[4] & 0xF8) >> 3);
|
||||
MAX_ALLOW_DISCHRG_POWER =
|
||||
((rx_frame.data.u8[5] & 0x07) << 11) | (rx_frame.data.u8[6] << 3) | ((rx_frame.data.u8[7] & 0xE0) >> 5);
|
||||
CHECKSUM_FRAME_414 = (rx_frame.data.u8[0] & 0xF0) >> 4; //Frame checksum 0x9
|
||||
COUNTER_414 = (rx_frame.data.u8[0] & 0x0F);
|
||||
break;
|
||||
case 0x353: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
HV_BATT_COP_VOLTAGE =
|
||||
(rx_frame.data.u8[1] << 5) | (rx_frame.data.u8[2] >> 3); //Real voltage HV battery (dV, 0-5000)
|
||||
HV_BATT_COP_CURRENT =
|
||||
(rx_frame.data.u8[3] << 5) | (rx_frame.data.u8[4] >> 3); //High resolution battery current (dA, -4000 - 4000)
|
||||
CHECKSUM_FRAME_353 = (rx_frame.data.u8[0] & 0xF0) >> 4; //Frame checksum 0xB
|
||||
COUNTER_353 = (rx_frame.data.u8[0] & 0x0F);
|
||||
break;
|
||||
case 0x474: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
BMS_DC_RELAY_MES_EVSE_VOLTAGE = (rx_frame.data.u8[1] << 6) | (rx_frame.data.u8[2] >> 2); //V 0-1000
|
||||
FAST_CHARGE_CONTACTOR_STATE = (rx_frame.data.u8[2] & 0x03);
|
||||
/*00: Contactors Opened
|
||||
01: Contactors Closed
|
||||
10: No Request
|
||||
11: WELDING TEST*/
|
||||
BMS_FASTCHARGE_STATUS = (rx_frame.data.u8[4] & 0x03);
|
||||
/*00 : not charging
|
||||
01 : charging
|
||||
10 : charging fault
|
||||
11 : charging finished*/
|
||||
CHECKSUM_FRAME_474 = (rx_frame.data.u8[0] & 0xF0) >> 4; //Frame checksum 0xF
|
||||
COUNTER_474 = (rx_frame.data.u8[0] & 0x0F);
|
||||
break;
|
||||
case 0x574: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
HV_BATT_FC_INSU_MINUS_RES = (rx_frame.data.u8[0] << 5) | (rx_frame.data.u8[1] >> 3); //kOhm (0-60000)
|
||||
HV_BATT_FC_VHL_INSU_PLUS_RES =
|
||||
((rx_frame.data.u8[1] & 0x07) << 10) | (rx_frame.data.u8[2] << 2) | ((rx_frame.data.u8[3] & 0xC0) >> 6);
|
||||
HV_BATT_FC_INSU_PLUS_RES = (rx_frame.data.u8[5] << 4) | (rx_frame.data.u8[6] >> 4);
|
||||
HV_BATT_ONLY_INSU_MINUS_RES = ((rx_frame.data.u8[3] & 0x3F) << 7) | (rx_frame.data.u8[4] >> 1);
|
||||
break;
|
||||
case 0x583: //MysteryVan 50/75kWh platform (CAN-FD also?)
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
ALERT_OVERCHARGE = (rx_frame.data.u8[4] & 0x20) >> 5;
|
||||
NUMBER_PROBE_TEMP_MAX = rx_frame.data.u8[0];
|
||||
NUMBER_PROBE_TEMP_MIN = rx_frame.data.u8[1];
|
||||
TEMPERATURE_MINIMUM_C = rx_frame.data.u8[2] - 40;
|
||||
ALERT_BATT = (rx_frame.data.u8[3] & 0x80) >> 7;
|
||||
ALERT_TEMP_DIFF = (rx_frame.data.u8[3] & 0x40) >> 6;
|
||||
ALERT_HIGH_TEMP = (rx_frame.data.u8[3] & 0x20) >> 5;
|
||||
ALERT_OVERVOLTAGE = (rx_frame.data.u8[3] & 0x10) >> 4;
|
||||
ALERT_LOW_SOC = (rx_frame.data.u8[3] & 0x08) >> 3;
|
||||
ALERT_HIGH_SOC = (rx_frame.data.u8[3] & 0x04) >> 2;
|
||||
ALERT_CELL_OVERVOLTAGE = (rx_frame.data.u8[3] & 0x02) >> 1;
|
||||
ALERT_CELL_UNDERVOLTAGE = (rx_frame.data.u8[3] & 0x01);
|
||||
ALERT_SOC_JUMP = (rx_frame.data.u8[4] & 0x80) >> 7;
|
||||
ALERT_CELL_POOR_CONSIST = (rx_frame.data.u8[4] & 0x40) >> 6;
|
||||
CONTACTOR_OPENING_REASON = (rx_frame.data.u8[4] & 0x1C) >> 2;
|
||||
/*
|
||||
000 : Not error
|
||||
001 : Crash
|
||||
010 : 12V supply source undervoltage
|
||||
011 : 12V supply source overvoltage
|
||||
100 : Battery temperature
|
||||
101 : interlock line open
|
||||
110 : e-Service plug disconnected
|
||||
111 : Not valid
|
||||
*/
|
||||
NUMBER_OF_TEMPERATURE_SENSORS_IN_BATTERY = rx_frame.data.u8[5];
|
||||
NUMBER_OF_CELL_MEASUREMENTS_IN_BATTERY = rx_frame.data.u8[6];
|
||||
|
||||
break;
|
||||
case 0x314: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
MIN_ALLOW_DISCHRG_VOLTAGE = (rx_frame.data.u8[1] << 3) | (rx_frame.data.u8[2] >> 5); //V (0-1000)
|
||||
//EVSE_DC_MAX_CURRENT = ((rx_frame.data.u8[2] & 0x1F) << 5) | (rx_frame.data.u8[3] >> 3); //Fastcharger info, not needed for BE
|
||||
//TBMU_EVSE_DC_MAX_VOLTAGE //Fastcharger info, not needed for BE
|
||||
//TBMU_MAX_CHRG_SCKT_TEMP //Fastcharger info, not needed for BE
|
||||
//DC_CHARGE_MODE_AVAIL //Fastcharger info, not needed for BE
|
||||
//BIDIR_V2HG_MODE_AVAIL //Fastcharger info, not needed for BE
|
||||
//TBMU_CHRG_CONN_CONF //Fastcharger info, not needed for BE
|
||||
//EVSE_GRID_FAULT //Fastcharger info, not needed for BE
|
||||
CHECKSUM_FRAME_314 = (rx_frame.data.u8[0] & 0xF0) >> 4; //Frame checksum 0x8
|
||||
COUNTER_314 = (rx_frame.data.u8[0] & 0x0F);
|
||||
break;
|
||||
case 0x254: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
//HV_BATT_SOE_MAX_HR = frame6 & frame7 //Only on FD-CAN variant of the message. FD has length 7, non-fd 5
|
||||
HV_BATT_NOMINAL_DISCH_CURR_HD = (rx_frame.data.u8[0] << 7) | (rx_frame.data.u8[1] >> 1); //dA (0-20000)
|
||||
HV_BATT_PEAK_DISCH_CURR_HD = (rx_frame.data.u8[2] << 7) | (rx_frame.data.u8[3] >> 1); //dA (0-20000)
|
||||
HV_BATT_STABLE_DISCH_CURR_HD = (rx_frame.data.u8[4] << 7) | (rx_frame.data.u8[5] >> 1); //dA (0-20000)
|
||||
break;
|
||||
case 0x2B4: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
HV_BATT_NOMINAL_CHARGE_CURR_HD = (rx_frame.data.u8[0] << 7) | (rx_frame.data.u8[1] >> 1);
|
||||
HV_BATT_PEAK_CHARGE_CURR_HD = (rx_frame.data.u8[2] << 7) | (rx_frame.data.u8[3] >> 1);
|
||||
HV_BATT_STABLE_CHARGE_CURR_HD = (rx_frame.data.u8[4] << 7) | (rx_frame.data.u8[5] >> 1);
|
||||
break;
|
||||
case 0x4D4: //MysteryVan 50/75kWh platform
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
HV_BATT_STABLE_CHARGE_POWER_HD = (rx_frame.data.u8[0] << 6) | (rx_frame.data.u8[1] >> 2);
|
||||
HV_BATT_STABLE_DISCH_POWER_HD =
|
||||
((rx_frame.data.u8[2] & 0x03) << 12) | (rx_frame.data.u8[3] << 4) | ((rx_frame.data.u8[4] & 0xF0) >> 4);
|
||||
HV_BATT_NOMINAL_DISCH_POWER_HD =
|
||||
((rx_frame.data.u8[4] & 0x0F) << 10) | (rx_frame.data.u8[5] << 2) | ((rx_frame.data.u8[6] & 0xC0) >> 6);
|
||||
MAX_ALLOW_DISCHRG_CURRENT = ((rx_frame.data.u8[6] & 0x3F) << 5) | (rx_frame.data.u8[7] >> 3);
|
||||
RC01_PERM_SYNTH_TBMU = (rx_frame.data.u8[7] & 0x04) >> 2; //TBMU Readiness Code synthesis
|
||||
CHECKSUM_FRAME_4D4 = (rx_frame.data.u8[0] & 0xF0) >> 4; //Frame checksum 0x5
|
||||
COUNTER_4D4 = (rx_frame.data.u8[0] & 0x0F);
|
||||
break;
|
||||
case 0x125: //Common eCMP
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_soc = (rx_frame.data.u8[0] << 2) |
|
||||
(rx_frame.data.u8[1] >> 6); // Byte1, bit 7 length 10 (0x3FE when abnormal) (0-1000 ppt)
|
||||
battery_MainConnectorState = ((rx_frame.data.u8[2] & 0x18) >>
|
||||
|
@ -157,6 +460,7 @@ void EcmpBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
battery_current = (((rx_frame.data.u8[4] & 0x0F) << 8) | rx_frame.data.u8[5]) - 600; // TODO: Test
|
||||
break;
|
||||
case 0x127: //DFM specific
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_AllowedMaxChargeCurrent =
|
||||
(rx_frame.data.u8[0] << 2) |
|
||||
((rx_frame.data.u8[1] & 0xC0) >> 6); //Byte 1, bit 7, length 10 (0-600A) [0x3FF if invalid]
|
||||
|
@ -165,12 +469,15 @@ void EcmpBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
(rx_frame.data.u8[3] >> 4); //Byte 2, bit 5, length 10 (0-600A) [0x3FF if invalid]
|
||||
break;
|
||||
case 0x129: //PSA specific
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
break;
|
||||
case 0x31B:
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_InterlockOpen = ((rx_frame.data.u8[1] & 0x10) >> 4); //Best guess, seems to work?
|
||||
//TODO: frame7 contains checksum, we can use this to check for CAN message corruption
|
||||
break;
|
||||
case 0x358: //Common
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_highestTemperature = rx_frame.data.u8[6] - 40;
|
||||
battery_lowestTemperature = rx_frame.data.u8[7] - 40;
|
||||
break;
|
||||
|
@ -185,11 +492,13 @@ void EcmpBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
case 0x494:
|
||||
break;
|
||||
case 0x594:
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_insulation_failure_diag = ((rx_frame.data.u8[6] & 0xE0) >> 5); //Unsure if this is right position
|
||||
//byte pos 6, bit pos 7, signal lenth 3
|
||||
//0 = no failure, 1 = symmetric failure, 4 = invalid value , forbidden value 5-7
|
||||
break;
|
||||
case 0x6D0: //Common
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_insulationResistanceKOhm =
|
||||
(rx_frame.data.u8[2] << 8) | rx_frame.data.u8[3]; //Byte 2, bit 7, length 16 (0-60000 kOhm)
|
||||
break;
|
||||
|
@ -198,6 +507,7 @@ void EcmpBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
case 0x6D2:
|
||||
break;
|
||||
case 0x6D3:
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
cellvoltages[0] = (rx_frame.data.u8[0] << 8) | rx_frame.data.u8[1];
|
||||
cellvoltages[1] = (rx_frame.data.u8[2] << 8) | rx_frame.data.u8[3];
|
||||
cellvoltages[2] = (rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5];
|
||||
|
@ -374,6 +684,7 @@ void EcmpBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
memcpy(datalayer.battery.status.cell_voltages_mV, cellvoltages, 108 * sizeof(uint16_t));
|
||||
break;
|
||||
case 0x694: // Poll reply
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
|
||||
// Handle user requested functionality first if ongoing
|
||||
if (datalayer_extended.stellantisECMP.UserRequestDisableIsoMonitoring) {
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "ECMP-HTML.h"
|
||||
|
||||
#ifdef STELLANTIS_ECMP_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS EcmpBattery
|
||||
#endif
|
||||
|
||||
class EcmpBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
@ -42,6 +38,7 @@ class EcmpBattery : public CanBattery {
|
|||
static const int COMPLETED_STATE = 0;
|
||||
bool battery_RelayOpenRequest = false;
|
||||
bool battery_InterlockOpen = false;
|
||||
bool MysteryVan = false;
|
||||
uint8_t ContactorResetStatemachine = 0;
|
||||
uint8_t CollisionResetStatemachine = 0;
|
||||
uint8_t IsolationResetStatemachine = 0;
|
||||
|
@ -84,8 +81,8 @@ class EcmpBattery : public CanBattery {
|
|||
uint8_t pid_coldest_module = NOT_SAMPLED_YET;
|
||||
uint8_t pid_lowest_temperature = NOT_SAMPLED_YET;
|
||||
uint8_t pid_average_temperature = NOT_SAMPLED_YET;
|
||||
uint8_t pid_highest_temperature = NOT_SAMPLED_YET;
|
||||
uint8_t pid_hottest_module = NOT_SAMPLED_YET;
|
||||
int8_t pid_highest_temperature = NOT_SAMPLED_YET;
|
||||
int8_t pid_hottest_module = NOT_SAMPLED_YET;
|
||||
uint16_t pid_avg_cell_voltage = NOT_SAMPLED_YET;
|
||||
int32_t pid_current = NOT_SAMPLED_YET;
|
||||
uint32_t pid_insulation_res_neg = NOT_SAMPLED_YET;
|
||||
|
@ -136,7 +133,68 @@ class EcmpBattery : public CanBattery {
|
|||
uint32_t pid_date_of_manufacture = NOT_SAMPLED_YET;
|
||||
uint16_t pid_SOH_cell_1 = NOT_SAMPLED_YET;
|
||||
|
||||
unsigned long previousMillis10 = 0; // will store last time a 10ms CAN Message was sent
|
||||
//MysteryVan platform (allcaps to make code easer to co-exist)
|
||||
uint16_t SOE_MAX_CURRENT_TEMP = 0;
|
||||
uint16_t FRONT_MACHINE_POWER_LIMIT = 0;
|
||||
uint16_t REAR_MACHINE_POWER_LIMIT = 0;
|
||||
uint16_t EVSE_INSTANT_DC_HV_CURRENT = 0;
|
||||
uint8_t EVSE_STATE = 0;
|
||||
uint16_t HV_BATT_SOE_HD = 0;
|
||||
uint16_t HV_BATT_SOE_MAX = 0;
|
||||
uint8_t CHECKSUM_FRAME_314, CHECKSUM_FRAME_3B4, CHECKSUM_FRAME_554, CHECKSUM_FRAME_373, CHECKSUM_FRAME_4F4,
|
||||
CHECKSUM_FRAME_414, CHECKSUM_FRAME_353, CHECKSUM_FRAME_474, CHECKSUM_FRAME_4D4 = 0;
|
||||
uint16_t HV_STORAGE_MAX_I = 0;
|
||||
int8_t BMS_PROBETEMP[7] = {0};
|
||||
uint8_t COUNTER_314, COUNTER_554, COUNTER_373, COUNTER_3B4, COUNTER_4F4, COUNTER_414, COUNTER_353, COUNTER_474,
|
||||
COUNTER_4D4 = 0;
|
||||
uint16_t HV_BATT_PEAK_DISCH_POWER_HD = 0;
|
||||
uint16_t HV_BATT_PEAK_CH_POWER_HD = 0;
|
||||
uint16_t HV_BATT_NOM_CH_POWER_HD = 0;
|
||||
uint16_t MAX_ALLOW_CHRG_CURRENT = 0;
|
||||
int16_t HV_BATT_REAL_CURR_HD = 0;
|
||||
uint16_t HV_BATT_REAL_VOLT_HD = 0;
|
||||
uint8_t TBMU_FAULT_TYPE = 0;
|
||||
int16_t HV_BATT_MAX_REAL_CURR = 0;
|
||||
bool TBCU_48V_WAKEUP = false;
|
||||
bool REQ_CLEAR_DTC_TBMU = false;
|
||||
bool HV_BATT_DISCONT_WARNING_OPEN = false;
|
||||
uint8_t CONTACTORS_STATE = 0;
|
||||
uint16_t HV_BATT_SOC = 0;
|
||||
bool CMD_RESET_MIL = 0;
|
||||
bool REQ_BLINK_STOP_AND_SERVICE_LAMP = false;
|
||||
bool REQ_MIL_LAMP_CONTINOUS = false;
|
||||
uint16_t HV_BATT_GENERATED_HEAT_RATE = 0;
|
||||
bool HV_BATT_CRASH_MEMORIZED = false;
|
||||
bool HV_BATT_COLD_CRANK_ACK = false;
|
||||
bool HV_BATT_CHARGE_NEEDED_STATE = false;
|
||||
uint8_t HV_BATT_NOM_CH_CURRENT = 0;
|
||||
uint16_t HV_BATT_NOM_CH_VOLTAGE = 0;
|
||||
uint16_t HV_BATT_REAL_POWER_HD = 0;
|
||||
uint16_t MAX_ALLOW_CHRG_POWER = 0;
|
||||
uint16_t MAX_ALLOW_DISCHRG_POWER = 0;
|
||||
bool ALERT_CELL_POOR_CONSIST, ALERT_OVERCHARGE, ALERT_BATT, ALERT_LOW_SOC, ALERT_HIGH_SOC, ALERT_SOC_JUMP,
|
||||
ALERT_TEMP_DIFF, ALERT_HIGH_TEMP, ALERT_OVERVOLTAGE, ALERT_CELL_OVERVOLTAGE, ALERT_CELL_UNDERVOLTAGE = false;
|
||||
uint8_t NUMBER_PROBE_TEMP_MAX, NUMBER_PROBE_TEMP_MIN = 0;
|
||||
int8_t TEMPERATURE_MINIMUM_C = 0;
|
||||
uint8_t CONTACTOR_OPENING_REASON = 0;
|
||||
uint8_t NUMBER_OF_TEMPERATURE_SENSORS_IN_BATTERY, NUMBER_OF_CELL_MEASUREMENTS_IN_BATTERY = 0;
|
||||
uint16_t HV_BATT_COP_VOLTAGE = 0;
|
||||
int16_t HV_BATT_COP_CURRENT = 0;
|
||||
uint16_t BMS_DC_RELAY_MES_EVSE_VOLTAGE = 0;
|
||||
uint8_t FAST_CHARGE_CONTACTOR_STATE = 0;
|
||||
uint8_t BMS_FASTCHARGE_STATUS = 0;
|
||||
uint16_t HV_BATT_FC_INSU_MINUS_RES, HV_BATT_FC_INSU_PLUS_RES, HV_BATT_FC_VHL_INSU_PLUS_RES,
|
||||
HV_BATT_ONLY_INSU_MINUS_RES = 0;
|
||||
uint16_t MIN_ALLOW_DISCHRG_VOLTAGE = 0;
|
||||
uint16_t HV_BATT_NOMINAL_DISCH_CURR_HD, HV_BATT_PEAK_DISCH_CURR_HD, HV_BATT_STABLE_DISCH_CURR_HD = 0;
|
||||
uint16_t HV_BATT_NOMINAL_CHARGE_CURR_HD, HV_BATT_PEAK_CHARGE_CURR_HD, HV_BATT_STABLE_CHARGE_CURR_HD = 0;
|
||||
bool RC01_PERM_SYNTH_TBMU = false;
|
||||
uint16_t HV_BATT_STABLE_CHARGE_POWER_HD = 0;
|
||||
uint16_t HV_BATT_STABLE_DISCH_POWER_HD = 0;
|
||||
uint16_t HV_BATT_NOMINAL_DISCH_POWER_HD = 0;
|
||||
uint16_t MAX_ALLOW_DISCHRG_CURRENT = 0;
|
||||
|
||||
unsigned long previousMillis10 = 0; //- will store last time a 10ms CAN Message was sent
|
||||
unsigned long previousMillis20 = 0; // will store last time a 20ms CAN Message was sent
|
||||
unsigned long previousMillis50 = 0; // will store last time a 50ms CAN Message was sent
|
||||
unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was sent
|
||||
|
|
|
@ -383,6 +383,132 @@ class EcmpHtmlRenderer : public BatteryHtmlRenderer {
|
|||
: String(datalayer_extended.stellantisECMP.pid_SOH_cell_1)) +
|
||||
"</h4>";
|
||||
|
||||
if (datalayer_extended.stellantisECMP.MysteryVan) {
|
||||
content += "<h3>MysteryVan platform detected!</h3>";
|
||||
content += "<h4>Contactor State: ";
|
||||
if (datalayer_extended.stellantisECMP.CONTACTORS_STATE == 0) {
|
||||
content += "Open";
|
||||
} else if (datalayer_extended.stellantisECMP.CONTACTORS_STATE == 1) {
|
||||
content += "Precharge";
|
||||
} else if (datalayer_extended.stellantisECMP.CONTACTORS_STATE == 2) {
|
||||
content += "Closed";
|
||||
}
|
||||
content += "</h4>";
|
||||
content += "<h4>Crash Memorized: ";
|
||||
if (datalayer_extended.stellantisECMP.CrashMemorized) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Contactor Opening Reason: ";
|
||||
if (datalayer_extended.stellantisECMP.CONTACTOR_OPENING_REASON == 0) {
|
||||
content += "No error";
|
||||
} else if (datalayer_extended.stellantisECMP.CONTACTOR_OPENING_REASON == 1) {
|
||||
content += "Crash!";
|
||||
} else if (datalayer_extended.stellantisECMP.CONTACTOR_OPENING_REASON == 2) {
|
||||
content += "12V supply source undervoltage";
|
||||
} else if (datalayer_extended.stellantisECMP.CONTACTOR_OPENING_REASON == 3) {
|
||||
content += "12V supply source overvoltage";
|
||||
} else if (datalayer_extended.stellantisECMP.CONTACTOR_OPENING_REASON == 4) {
|
||||
content += "Battery temperature";
|
||||
} else if (datalayer_extended.stellantisECMP.CONTACTOR_OPENING_REASON == 5) {
|
||||
content += "Interlock line open";
|
||||
} else if (datalayer_extended.stellantisECMP.CONTACTOR_OPENING_REASON == 6) {
|
||||
content += "e-Service plug disconnected";
|
||||
}
|
||||
content += "</h4>";
|
||||
content += "<h4>Battery fault type: ";
|
||||
if (datalayer_extended.stellantisECMP.TBMU_FAULT_TYPE == 0) {
|
||||
content += "No fault";
|
||||
} else if (datalayer_extended.stellantisECMP.TBMU_FAULT_TYPE == 1) {
|
||||
content += "FirstLevelFault: Warning Lamp";
|
||||
} else if (datalayer_extended.stellantisECMP.TBMU_FAULT_TYPE == 2) {
|
||||
content += "SecondLevelFault: Stop Lamp";
|
||||
} else if (datalayer_extended.stellantisECMP.TBMU_FAULT_TYPE == 3) {
|
||||
content += "ThirdLevelFault: Stop Lamp + contactor opening (EPS shutdown)";
|
||||
} else if (datalayer_extended.stellantisECMP.TBMU_FAULT_TYPE == 4) {
|
||||
content += "FourthLevelFault: Stop Lamp + Active Discharge";
|
||||
} else if (datalayer_extended.stellantisECMP.TBMU_FAULT_TYPE == 5) {
|
||||
content += "Inhibition of powertrain activation";
|
||||
} else if (datalayer_extended.stellantisECMP.TBMU_FAULT_TYPE == 6) {
|
||||
content += "Reserved";
|
||||
}
|
||||
content += "</h4>";
|
||||
content += "<h4>FC insulation minus resistance " +
|
||||
String(datalayer_extended.stellantisECMP.HV_BATT_FC_INSU_MINUS_RES) + " kOhm</h4>";
|
||||
content += "<h4>FC insulation plus resistance " +
|
||||
String(datalayer_extended.stellantisECMP.HV_BATT_FC_INSU_PLUS_RES) + " kOhm</h4>";
|
||||
content += "<h4>FC vehicle insulation plus resistance " +
|
||||
String(datalayer_extended.stellantisECMP.HV_BATT_FC_VHL_INSU_PLUS_RES) + " kOhm</h4>";
|
||||
content += "<h4>FC vehicle insulation plus resistance " +
|
||||
String(datalayer_extended.stellantisECMP.HV_BATT_ONLY_INSU_MINUS_RES) + " kOhm</h4>";
|
||||
}
|
||||
content += "<h4>Alert Battery: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_BATT) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert Low SOC: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_LOW_SOC) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert High SOC: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_HIGH_SOC) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert SOC Jump: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_SOC_JUMP) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert Overcharge: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_OVERCHARGE) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert Temp Diff: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_TEMP_DIFF) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert Temp High: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_HIGH_TEMP) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert Overvoltage: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_OVERVOLTAGE) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert Cell Overvoltage: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_CELL_OVERVOLTAGE) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert Cell Undervoltage: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_CELL_UNDERVOLTAGE) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
content += "<h4>Alert Cell Poor Consistency: ";
|
||||
if (datalayer_extended.stellantisECMP.ALERT_CELL_POOR_CONSIST) {
|
||||
content += "Yes</h4>";
|
||||
} else {
|
||||
content += "No</h4>";
|
||||
}
|
||||
return content;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "FOXESS-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define FOXESS_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef FOXESS_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS FoxessBattery
|
||||
#endif
|
||||
|
||||
class FoxessBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "GEELY-GEOMETRY-C-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "GEELY-GEOMETRY-C-HTML.h"
|
||||
|
||||
#ifdef GEELY_GEOMETRY_C_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS GeelyGeometryCBattery
|
||||
#endif
|
||||
|
||||
class GeelyGeometryCBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef _GEELY_GEOMETRY_C_HTML_H
|
||||
#define _GEELY_GEOMETRY_C_HTML_H
|
||||
|
||||
#include <cstring> //For unit test
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
#include "../devboard/webserver/BatteryHtmlRenderer.h"
|
||||
|
||||
|
|
|
@ -5,9 +5,7 @@ String HyundaiIoniq28BatteryHtmlRenderer::get_status_html() {
|
|||
String content;
|
||||
content += "<h4>12V voltage: " + String(batt.get_lead_acid_voltage() / 10.0, 1) + "</h4>";
|
||||
content += "<h4>Temperature, power relay: " + String(batt.get_power_relay_temperature()) + "</h4>";
|
||||
content += "<h4>Battery relay: " + String(batt.get_battery_relay_mode()) + "</h4>";
|
||||
content += "<h4>Batterymanagement mode: " + String(batt.get_battery_management_mode()) + "</h4>";
|
||||
content += "<h4>BMS ignition: " + String(batt.get_battery_ignition_mode()) + "</h4>";
|
||||
|
||||
content += "<h4>Isolation resistance: " + String(batt.get_isolation_resistance()) + " kOhm</h4>";
|
||||
return content;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,11 @@ void HyundaiIoniq28Battery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
break;
|
||||
case 0x21: //First frame in PID group
|
||||
if (incoming_poll_group == 1) { //21 14 13 24 13 24 04 00
|
||||
batteryRelay = rx_frame.data.u8[7];
|
||||
//SOC = rx_frame.data.u8[1];
|
||||
//available_charge_power = 2 & 3
|
||||
//available_discharge_power = 4 & 5
|
||||
//status_bits? = 6
|
||||
//battery_current_highbyte = rx_frame.data.u8[7];
|
||||
} else if (incoming_poll_group == 2) { //21 AD AD AD AD AD AD AC
|
||||
cellvoltages_mv[0] = (rx_frame.data.u8[1] * 20);
|
||||
cellvoltages_mv[1] = (rx_frame.data.u8[2] * 20);
|
||||
|
@ -113,11 +117,19 @@ void HyundaiIoniq28Battery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
cellvoltages_mv[68] = (rx_frame.data.u8[5] * 20);
|
||||
cellvoltages_mv[69] = (rx_frame.data.u8[6] * 20);
|
||||
cellvoltages_mv[70] = (rx_frame.data.u8[7] * 20);
|
||||
} else if (incoming_poll_group == 5) { //21 0 0 0 0 0 0f0f
|
||||
//battery_module_6_temperature = rx_frame.data.u8[6];
|
||||
//battery_module_7_temperature = rx_frame.data.u8[7];
|
||||
}
|
||||
break;
|
||||
case 0x22: //Second datarow in PID group
|
||||
if (incoming_poll_group == 1) { //22 00 0C FF 17 16 17 17
|
||||
|
||||
//battery_current_lowbyte = rx_frame.data.u8[1];
|
||||
//battery_DC_voltage = ((rx_frame.data.u8[2] << 8) | rx_frame.data.u8[3]);
|
||||
//battery_max_temperature = rx_frame.data.u8[4];
|
||||
//battery_min_temperature = rx_frame.data.u8[5];
|
||||
//battery_module_1_temperature = rx_frame.data.u8[6];
|
||||
//battery_module_2_temperature = rx_frame.data.u8[7];
|
||||
} else if (incoming_poll_group == 2) { //22 AD AC AC AD AD AD AD
|
||||
cellvoltages_mv[7] = (rx_frame.data.u8[1] * 20);
|
||||
cellvoltages_mv[8] = (rx_frame.data.u8[2] * 20);
|
||||
|
@ -142,14 +154,26 @@ void HyundaiIoniq28Battery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
cellvoltages_mv[75] = (rx_frame.data.u8[5] * 20);
|
||||
cellvoltages_mv[76] = (rx_frame.data.u8[6] * 20);
|
||||
cellvoltages_mv[77] = (rx_frame.data.u8[7] * 20);
|
||||
} else if (incoming_poll_group == 5) { //22 10 0d 0c 0e 0d 26 48
|
||||
//battery_module_8_temperature = rx_frame.data.u8[1];
|
||||
//battery_module_9_temperature = rx_frame.data.u8[2];
|
||||
//battery_module_10_temperature = rx_frame.data.u8[3];
|
||||
//battery_module_11_temperature = rx_frame.data.u8[4];
|
||||
//battery_module_12_temperature = rx_frame.data.u8[5];
|
||||
//available_charge_power = ((rx_frame.data.u8[6] << 8) | rx_frame.data.u8[7]);
|
||||
} else if (incoming_poll_group == 6) {
|
||||
batteryManagementMode = rx_frame.data.u8[5];
|
||||
}
|
||||
break;
|
||||
case 0x23: //Third datarow in PID group
|
||||
if (incoming_poll_group == 1) { //23 17 17 17 00 17 AD 25
|
||||
case 0x23: //Third datarow in PID group
|
||||
if (incoming_poll_group == 1) { //23 17 17 17 00 17 AD 25
|
||||
//battery_module_3_temperature = rx_frame.data.u8[1];
|
||||
//battery_module_4_temperature = rx_frame.data.u8[2];
|
||||
//battery_module_5_temperature = rx_frame.data.u8[3];
|
||||
//battery_inlet_temperature = rx_frame.data.u8[5];
|
||||
CellVoltMax_mV = (rx_frame.data.u8[6] * 20); //(volts *50) *20 =mV
|
||||
} else if (incoming_poll_group == 2) { //23 AD AD AD AD AB AD AD
|
||||
//cellmaxvoltage_number = rx_frame.data.u8[7];
|
||||
} else if (incoming_poll_group == 2) { //23 AD AD AD AD AB AD AD
|
||||
cellvoltages_mv[14] = (rx_frame.data.u8[1] * 20);
|
||||
cellvoltages_mv[15] = (rx_frame.data.u8[2] * 20);
|
||||
cellvoltages_mv[16] = (rx_frame.data.u8[3] * 20);
|
||||
|
@ -174,13 +198,22 @@ void HyundaiIoniq28Battery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
cellvoltages_mv[83] = (rx_frame.data.u8[6] * 20);
|
||||
cellvoltages_mv[84] = (rx_frame.data.u8[7] * 20);
|
||||
} else if (incoming_poll_group == 5) {
|
||||
heatertemp = rx_frame.data.u8[7];
|
||||
//available_discharge_power = ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2]);
|
||||
//battery_cell_mV_deviation = rx_frame.data.u8[3];
|
||||
//airbag_h/wire_duty = rx_frame.data.u8[5];
|
||||
heatertemperature_1 = rx_frame.data.u8[6];
|
||||
heatertemperature_2 = rx_frame.data.u8[7];
|
||||
}
|
||||
break;
|
||||
case 0x24: //Fourth datarow in PID group
|
||||
if (incoming_poll_group == 1) { //24 AA 4F 00 00 77 00 14
|
||||
CellVoltMin_mV = (rx_frame.data.u8[1] * 20); //(volts *50) *20 =mV
|
||||
} else if (incoming_poll_group == 2) { //24 AD AD AD AD AD AD AB
|
||||
//mincellvoltage_number = rx_frame.data.u8[2];
|
||||
//fan_status = rx_frame.data.u8[3];
|
||||
//fan_feedback_signal = rx_frame.data.u8[4];
|
||||
//aux_battery_voltage = rx_frame.data.u8[5];
|
||||
//cumulative_charge_current_highbyte = ((rx_frame.data.u8[6] << 8) | rx_frame.data.u8[7]);
|
||||
} else if (incoming_poll_group == 2) { //24 AD AD AD AD AD AD AB
|
||||
cellvoltages_mv[21] = (rx_frame.data.u8[1] * 20);
|
||||
cellvoltages_mv[22] = (rx_frame.data.u8[2] * 20);
|
||||
cellvoltages_mv[23] = (rx_frame.data.u8[3] * 20);
|
||||
|
@ -204,13 +237,19 @@ void HyundaiIoniq28Battery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
cellvoltages_mv[89] = (rx_frame.data.u8[5] * 20);
|
||||
cellvoltages_mv[90] = (rx_frame.data.u8[6] * 20);
|
||||
cellvoltages_mv[91] = (rx_frame.data.u8[7] * 20);
|
||||
} else if (incoming_poll_group == 5) {
|
||||
batterySOH = ((rx_frame.data.u8[2] << 8) + rx_frame.data.u8[3]);
|
||||
} else if (incoming_poll_group == 5) { //24 3 e8 5 3 e8 m34 6e
|
||||
batterySOH = ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2]);
|
||||
//max_deterioration_cell_number = rx_frame.data.u8[3]
|
||||
//min_deterioration = ((rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5]);
|
||||
//min_deterioration_cell_number = rx_frame.data.u8[6]
|
||||
//SOC_display = rx_frame.data.u8[7]
|
||||
}
|
||||
break;
|
||||
case 0x25: //Fifth datarow in PID group
|
||||
if (incoming_poll_group == 1) { //25 5C A9 00 14 5F D3 00
|
||||
|
||||
//cumulative_charge_current_lowbyte = ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2]);
|
||||
//cumulative_discharge_current = ((rx_frame.data.u8[3] << 24) | (rx_frame.data.u8[4] << 16) | (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6]);
|
||||
//cumulative_charge_energy_highbyte = rx_frame.data.u8[7];
|
||||
} else if (incoming_poll_group == 2) { //25 AD AD AD AD 00 00 00
|
||||
cellvoltages_mv[28] = (rx_frame.data.u8[1] * 20);
|
||||
cellvoltages_mv[29] = (rx_frame.data.u8[2] * 20);
|
||||
|
@ -231,19 +270,22 @@ void HyundaiIoniq28Battery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
break;
|
||||
case 0x26: //Sixth datarow in PID group
|
||||
if (incoming_poll_group == 1) { //26 07 84 F9 00 07 42 8F
|
||||
//cumulative_charge_energy_lowbyte = (rx_frame.data.u8[1] << 16) | (rx_frame.data.u8[2] << 8) | rx_frame.data.u8[3]);
|
||||
//cumulative_discharge_energy = ((rx_frame.data.u8[4] << 24) | (rx_frame.data.u8[5] << 16) | (rx_frame.data.u8[6] << 8) | rx_frame.data.u8[7]);
|
||||
|
||||
} else if (incoming_poll_group == 5) {
|
||||
}
|
||||
break;
|
||||
case 0x27: //Seventh datarow in PID group
|
||||
if (incoming_poll_group == 1) { //27 03 3F A1 EB 00 19 99
|
||||
BMS_ign = rx_frame.data.u8[6];
|
||||
inverterVoltageFrameHigh = rx_frame.data.u8[7];
|
||||
//cumulative_operating_time = ((rx_frame.data.u8[1] << 24) | (rx_frame.data.u8[2] << 16) | (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4]);
|
||||
//bitfield (41 off, 45 car on) = rx_frame.data.u8[5];
|
||||
inverterVoltage = ((rx_frame.data.u8[6] << 8) | rx_frame.data.u8[7]);
|
||||
}
|
||||
break;
|
||||
case 0x28: //Eighth datarow in PID group
|
||||
if (incoming_poll_group == 1) { //28 7F FF 7F FF 03 E8 00
|
||||
inverterVoltage = (inverterVoltageFrameHigh << 8) + rx_frame.data.u8[1];
|
||||
isolation_resistance = ((rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -378,10 +420,6 @@ uint8_t HyundaiIoniq28Battery::get_battery_management_mode() const {
|
|||
return batteryManagementMode;
|
||||
}
|
||||
|
||||
uint8_t HyundaiIoniq28Battery::get_battery_ignition_mode() const {
|
||||
return BMS_ign;
|
||||
}
|
||||
|
||||
uint8_t HyundaiIoniq28Battery::get_battery_relay_mode() const {
|
||||
return batteryRelay;
|
||||
uint16_t HyundaiIoniq28Battery::get_isolation_resistance() const {
|
||||
return isolation_resistance;
|
||||
}
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "HYUNDAI-IONIQ-28-BATTERY-HTML.h"
|
||||
|
||||
#ifdef HYUNDAI_IONIQ_28_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS HyundaiIoniq28Battery
|
||||
#endif
|
||||
|
||||
class HyundaiIoniq28Battery : public CanBattery {
|
||||
public:
|
||||
// Use the default constructor to create the first or single battery.
|
||||
|
@ -26,10 +22,9 @@ class HyundaiIoniq28Battery : public CanBattery {
|
|||
|
||||
// Getter methods for HTML renderer
|
||||
uint16_t get_lead_acid_voltage() const;
|
||||
uint16_t get_isolation_resistance() const;
|
||||
int16_t get_power_relay_temperature() const;
|
||||
uint8_t get_battery_management_mode() const;
|
||||
uint8_t get_battery_ignition_mode() const;
|
||||
uint8_t get_battery_relay_mode() const;
|
||||
|
||||
private:
|
||||
HyundaiIoniq28BatteryHtmlRenderer renderer;
|
||||
|
@ -54,18 +49,17 @@ class HyundaiIoniq28Battery : public CanBattery {
|
|||
uint16_t allowedDischargePower = 0;
|
||||
uint16_t allowedChargePower = 0;
|
||||
uint16_t batteryVoltage = 3700;
|
||||
uint16_t inverterVoltageFrameHigh = 0;
|
||||
uint16_t inverterVoltage = 0;
|
||||
uint16_t isolation_resistance = 1000;
|
||||
uint16_t cellvoltages_mv[96];
|
||||
uint16_t leadAcidBatteryVoltage = 120;
|
||||
int16_t batteryAmps = 0;
|
||||
int16_t temperatureMax = 0;
|
||||
int16_t temperatureMin = 0;
|
||||
uint8_t batteryManagementMode = 0;
|
||||
uint8_t BMS_ign = 0;
|
||||
uint8_t batteryRelay = 0;
|
||||
uint8_t counter_200 = 0;
|
||||
int8_t heatertemp = 0;
|
||||
int8_t heatertemperature_1 = 0;
|
||||
int8_t heatertemperature_2 = 0;
|
||||
int8_t powerRelayTemperature = 0;
|
||||
bool startedUp = false;
|
||||
uint8_t incoming_poll_group = 0xFF;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "IMIEV-CZERO-ION-BATTERY.h"
|
||||
#include <cstring> //for unit tests
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
@ -19,9 +20,11 @@ void ImievCZeroIonBattery::
|
|||
(static_cast<double>(datalayer.battery.status.real_soc) / 10000) * datalayer.battery.info.total_capacity_Wh);
|
||||
|
||||
//We do not know the max charge/discharge power is sent by the battery. We hardcode value for now.
|
||||
datalayer.battery.status.max_charge_power_W = 10000; // 10kW //TODO: Fix when CAN is decoded
|
||||
datalayer.battery.status.max_charge_power_W =
|
||||
datalayer.battery.status.override_charge_power_W; //TODO: Fix when CAN is decoded
|
||||
|
||||
datalayer.battery.status.max_discharge_power_W = 10000; // 10kW //TODO: Fix when CAN is decoded
|
||||
datalayer.battery.status.max_discharge_power_W =
|
||||
datalayer.battery.status.override_discharge_power_W; //TODO: Fix when CAN is decoded
|
||||
|
||||
static int n = sizeof(cell_voltages) / sizeof(cell_voltages[0]);
|
||||
max_volt_cel = cell_voltages[0]; // Initialize max with the first element of the array
|
||||
|
@ -76,17 +79,8 @@ void ImievCZeroIonBattery::
|
|||
|
||||
if (!BMU_Detected) {
|
||||
logging.println("BMU not detected, check wiring!");
|
||||
//TODO: Raise event
|
||||
}
|
||||
|
||||
logging.println("Battery Values");
|
||||
logging.print("BMU SOC: ");
|
||||
logging.print(BMU_SOC);
|
||||
logging.print(" BMU Current: ");
|
||||
logging.print(BMU_Current);
|
||||
logging.print(" BMU Battery Voltage: ");
|
||||
logging.print(BMU_PackVoltage);
|
||||
logging.print(" BMU_Power: ");
|
||||
logging.print(BMU_Power);
|
||||
}
|
||||
|
||||
void ImievCZeroIonBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define IMIEV_CZERO_ION_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef IMIEV_CZERO_ION_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS ImievCZeroIonBattery
|
||||
#endif
|
||||
|
||||
class ImievCZeroIonBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "JAGUAR-IPACE-BATTERY.h"
|
||||
#include <cstring> //for unit tests
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
@ -57,9 +58,9 @@ CAN_frame ipace_keep_alive = {.FD = false,
|
|||
.data = {0x9E, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};*/
|
||||
|
||||
static void print_units(const char* header, int value, const char* units) {
|
||||
logging.print(header);
|
||||
logging.print(value);
|
||||
logging.print(units);
|
||||
logging.printf(header);
|
||||
logging.printf("%d", value);
|
||||
logging.printf(units);
|
||||
}
|
||||
|
||||
void JaguarIpaceBattery::update_values() {
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef JAGUAR_IPACE_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS JaguarIpaceBattery
|
||||
#endif
|
||||
|
||||
class JaguarIpaceBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
|
||||
#define ESTIMATE_SOC_FROM_CELLVOLTAGE
|
||||
|
||||
#ifdef KIA_HYUNDAI_64_FD_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS Kia64FDBattery
|
||||
#endif
|
||||
|
||||
class Kia64FDBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -55,18 +55,6 @@ uint16_t KiaEGmpBattery::estimateSOC(uint16_t packVoltage, uint16_t cellCount, i
|
|||
// Calculate average cell voltage in millivolts
|
||||
uint16_t avgCellVoltage = compensatedPackVoltageMv / cellCount;
|
||||
|
||||
logging.print("Pack: ");
|
||||
logging.print(packVoltage / 10.0);
|
||||
logging.print("V, Current: ");
|
||||
logging.print(currentAmps / 10.0);
|
||||
logging.print("A, Drop: ");
|
||||
logging.print(voltageDrop / 1000.0);
|
||||
logging.print("V, Comp Pack: ");
|
||||
logging.print(compensatedPackVoltageMv / 1000.0);
|
||||
logging.print("V, Avg Cell: ");
|
||||
logging.print(avgCellVoltage);
|
||||
logging.println("mV");
|
||||
|
||||
// Use the cell voltage lookup table to estimate SOC
|
||||
return estimateSOCFromCell(avgCellVoltage);
|
||||
}
|
||||
|
@ -84,7 +72,7 @@ uint16_t KiaEGmpBattery::selectSOC(uint16_t SOC_low, uint16_t SOC_high) {
|
|||
|
||||
void KiaEGmpBattery::set_cell_voltages(CAN_frame rx_frame, int start, int length, int startCell) {
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
if ((rx_frame.data.u8[start + i] * 20) > 1000) {
|
||||
if ((rx_frame.data.u8[start + i] * 20) > 2600) {
|
||||
datalayer.battery.status.cell_voltages_mV[startCell + i] = (rx_frame.data.u8[start + i] * 20);
|
||||
}
|
||||
}
|
||||
|
@ -126,16 +114,17 @@ uint8_t KiaEGmpBattery::calculateCRC(CAN_frame rx_frame, uint8_t length, uint8_t
|
|||
|
||||
void KiaEGmpBattery::update_values() {
|
||||
|
||||
#ifdef ESTIMATE_SOC_FROM_CELLVOLTAGE
|
||||
// Use the simplified pack-based SOC estimation with proper compensation
|
||||
datalayer.battery.status.real_soc = estimateSOC(batteryVoltage, datalayer.battery.info.number_of_cells, batteryAmps);
|
||||
if (user_selected_use_estimated_SOC) {
|
||||
// Use the simplified pack-based SOC estimation with proper compensation
|
||||
datalayer.battery.status.real_soc =
|
||||
estimateSOC(batteryVoltage, datalayer.battery.info.number_of_cells, batteryAmps);
|
||||
|
||||
// For comparison or fallback, we can still calculate from min/max cell voltages
|
||||
SOC_estimated_lowest = estimateSOCFromCell(CellVoltMin_mV);
|
||||
SOC_estimated_highest = estimateSOCFromCell(CellVoltMax_mV);
|
||||
#else
|
||||
datalayer.battery.status.real_soc = (SOC_Display * 10); //increase SOC range from 0-100.0 -> 100.00
|
||||
#endif
|
||||
// For comparison or fallback, we can still calculate from min/max cell voltages
|
||||
SOC_estimated_lowest = estimateSOCFromCell(CellVoltMin_mV);
|
||||
SOC_estimated_highest = estimateSOCFromCell(CellVoltMax_mV);
|
||||
} else {
|
||||
datalayer.battery.status.real_soc = (SOC_Display * 10); //increase SOC range from 0-100.0 -> 100.00
|
||||
}
|
||||
|
||||
datalayer.battery.status.soh_pptt = (batterySOH * 10); //Increase decimals from 100.0% -> 100.00%
|
||||
|
||||
|
@ -155,12 +144,12 @@ void KiaEGmpBattery::update_values() {
|
|||
datalayer.battery.status.max_charge_power_W =
|
||||
RAMPDOWNPOWERALLOWED * (1 - (datalayer.battery.status.real_soc - RAMPDOWN_SOC) / (10000.0 - RAMPDOWN_SOC));
|
||||
} else { // No limits, max charging power allowed
|
||||
datalayer.battery.status.max_charge_power_W = MAXCHARGEPOWERALLOWED;
|
||||
datalayer.battery.status.max_charge_power_W = datalayer.battery.status.override_charge_power_W;
|
||||
}
|
||||
|
||||
//datalayer.battery.status.max_discharge_power_W = (uint16_t)allowedDischargePower * 10; //From kW*100 to Watts
|
||||
//The allowed discharge power is not available. We hardcode this value for now
|
||||
datalayer.battery.status.max_discharge_power_W = MAXDISCHARGEPOWERALLOWED;
|
||||
datalayer.battery.status.max_discharge_power_W = datalayer.battery.status.override_discharge_power_W;
|
||||
|
||||
datalayer.battery.status.temperature_min_dC = (int8_t)temperatureMin * 10; //Increase decimals, 17C -> 17.0C
|
||||
|
||||
|
@ -182,65 +171,6 @@ void KiaEGmpBattery::update_values() {
|
|||
if (leadAcidBatteryVoltage < 110) {
|
||||
set_event(EVENT_12V_LOW, leadAcidBatteryVoltage);
|
||||
}
|
||||
|
||||
/* Safeties verified. Perform USB serial printout if configured to do so */
|
||||
|
||||
logging.println(); //sepatator
|
||||
logging.println("Values from battery: ");
|
||||
logging.print("SOC BMS: ");
|
||||
logging.print((uint16_t)SOC_BMS / 10.0, 1);
|
||||
logging.print("% | SOC Display: ");
|
||||
logging.print((uint16_t)SOC_Display / 10.0, 1);
|
||||
logging.print("% | SOH ");
|
||||
logging.print((uint16_t)batterySOH / 10.0, 1);
|
||||
logging.println("%");
|
||||
logging.print((int16_t)batteryAmps / 10.0, 1);
|
||||
logging.print(" Amps | ");
|
||||
logging.print((uint16_t)batteryVoltage / 10.0, 1);
|
||||
logging.print(" Volts | ");
|
||||
logging.print((int16_t)datalayer.battery.status.active_power_W);
|
||||
logging.println(" Watts");
|
||||
logging.print("Allowed Charge ");
|
||||
logging.print((uint16_t)allowedChargePower * 10);
|
||||
logging.print(" W | Allowed Discharge ");
|
||||
logging.print((uint16_t)allowedDischargePower * 10);
|
||||
logging.println(" W");
|
||||
logging.print("MaxCellVolt ");
|
||||
logging.print(CellVoltMax_mV);
|
||||
logging.print(" mV No ");
|
||||
logging.print(CellVmaxNo);
|
||||
logging.print(" | MinCellVolt ");
|
||||
logging.print(CellVoltMin_mV);
|
||||
logging.print(" mV No ");
|
||||
logging.println(CellVminNo);
|
||||
logging.print("TempHi ");
|
||||
logging.print((int16_t)temperatureMax);
|
||||
logging.print("°C TempLo ");
|
||||
logging.print((int16_t)temperatureMin);
|
||||
logging.print("°C WaterInlet ");
|
||||
logging.print((int8_t)temperature_water_inlet);
|
||||
logging.print("°C PowerRelay ");
|
||||
logging.print((int8_t)powerRelayTemperature * 2);
|
||||
logging.println("°C");
|
||||
logging.print("Aux12volt: ");
|
||||
logging.print((int16_t)leadAcidBatteryVoltage / 10.0, 1);
|
||||
logging.println("V | ");
|
||||
logging.print("BmsManagementMode ");
|
||||
logging.print((uint8_t)batteryManagementMode, BIN);
|
||||
if (bitRead((uint8_t)BMS_ign, 2) == 1) {
|
||||
logging.print(" | BmsIgnition ON");
|
||||
} else {
|
||||
logging.print(" | BmsIgnition OFF");
|
||||
}
|
||||
|
||||
if (bitRead((uint8_t)batteryRelay, 0) == 1) {
|
||||
logging.print(" | PowerRelay ON");
|
||||
} else {
|
||||
logging.print(" | PowerRelay OFF");
|
||||
}
|
||||
logging.print(" | Inverter ");
|
||||
logging.print(inverterVoltage);
|
||||
logging.println(" Volts");
|
||||
}
|
||||
|
||||
// Getter implementations for HTML renderer
|
||||
|
@ -321,14 +251,10 @@ void KiaEGmpBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
break;
|
||||
case 0x7EC:
|
||||
// print_canfd_frame(frame);
|
||||
switch (rx_frame.data.u8[0]) {
|
||||
case 0x10: //"PID Header"
|
||||
// logging.println ("Send ack");
|
||||
poll_data_pid = rx_frame.data.u8[4];
|
||||
// if (rx_frame.data.u8[4] == poll_data_pid) {
|
||||
transmit_can_frame(&EGMP_7E4_ack); //Send ack to BMS if the same frame is sent as polled
|
||||
// }
|
||||
transmit_can_frame(&EGMP_7E4_ack); //Send ack to BMS
|
||||
break;
|
||||
case 0x21: //First frame in PID group
|
||||
if (poll_data_pid == 1) {
|
||||
|
|
|
@ -3,11 +3,7 @@
|
|||
#include "CanBattery.h"
|
||||
#include "KIA-E-GMP-HTML.h"
|
||||
|
||||
#define ESTIMATE_SOC_FROM_CELLVOLTAGE
|
||||
|
||||
#ifdef KIA_E_GMP_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS KiaEGmpBattery
|
||||
#endif
|
||||
extern bool user_selected_use_estimated_SOC;
|
||||
|
||||
class KiaEGmpBattery : public CanBattery {
|
||||
public:
|
||||
|
@ -41,8 +37,6 @@ class KiaEGmpBattery : public CanBattery {
|
|||
static const int MAX_CELL_DEVIATION_MV = 150;
|
||||
static const int MAX_CELL_VOLTAGE_MV = 4250; //Battery is put into emergency stop if one cell goes over this value
|
||||
static const int MIN_CELL_VOLTAGE_MV = 2950; //Battery is put into emergency stop if one cell goes below this value
|
||||
static const int MAXCHARGEPOWERALLOWED = 10000;
|
||||
static const int MAXDISCHARGEPOWERALLOWED = 10000;
|
||||
static const int RAMPDOWN_SOC = 9000; // 90.00 SOC% to start ramping down from max charge power towards 0 at 100.00%
|
||||
static const int RAMPDOWNPOWERALLOWED = 10000; // What power we ramp down from towards top balancing
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "KIA-HYUNDAI-64-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "KIA-HYUNDAI-64-HTML.h"
|
||||
|
||||
#ifdef KIA_HYUNDAI_64_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS KiaHyundai64Battery
|
||||
#endif
|
||||
|
||||
class KiaHyundai64Battery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef _KIA_HYUNDAI_64_HTML_H
|
||||
#define _KIA_HYUNDAI_64_HTML_H
|
||||
|
||||
#include <cstring> //For unit test
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
#include "../devboard/webserver/BatteryHtmlRenderer.h"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "KIA-HYUNDAI-HYBRID-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
@ -43,7 +44,6 @@ void KiaHyundaiHybridBattery::
|
|||
}
|
||||
|
||||
void KiaHyundaiHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.ID) {
|
||||
case 0x5F1:
|
||||
break;
|
||||
|
@ -52,6 +52,8 @@ void KiaHyundaiHybridBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
case 0x588:
|
||||
break;
|
||||
case 0x5AE:
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
|
||||
interlock_missing = (bool)(rx_frame.data.u8[1] & 0x02) >> 1;
|
||||
break;
|
||||
case 0x5AF:
|
||||
|
@ -199,15 +201,21 @@ void KiaHyundaiHybridBattery::transmit_can(unsigned long currentMillis) {
|
|||
}
|
||||
poll_data_pid++;
|
||||
if (poll_data_pid == 1) {
|
||||
transmit_can_frame(&KIA_7E4_id1);
|
||||
KIA_7E4.data.u8[2] = 0x01;
|
||||
KIA_7E4.data.u8[3] = 0x00;
|
||||
transmit_can_frame(&KIA_7E4);
|
||||
} else if (poll_data_pid == 2) {
|
||||
transmit_can_frame(&KIA_7E4_id2);
|
||||
KIA_7E4.data.u8[2] = 0x02;
|
||||
transmit_can_frame(&KIA_7E4);
|
||||
} else if (poll_data_pid == 3) {
|
||||
transmit_can_frame(&KIA_7E4_id3);
|
||||
KIA_7E4.data.u8[2] = 0x03;
|
||||
transmit_can_frame(&KIA_7E4);
|
||||
} else if (poll_data_pid == 4) {
|
||||
|
||||
//Group 4 not polled
|
||||
} else if (poll_data_pid == 5) {
|
||||
transmit_can_frame(&KIA_7E4_id5);
|
||||
KIA_7E4.data.u8[2] = 0x05;
|
||||
KIA_7E4.data.u8[3] = 0x04;
|
||||
transmit_can_frame(&KIA_7E4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define KIA_HYUNDAI_HYBRID_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef KIA_HYUNDAI_HYBRID_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS KiaHyundaiHybridBattery
|
||||
#endif
|
||||
|
||||
class KiaHyundaiHybridBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
@ -38,26 +34,11 @@ class KiaHyundaiHybridBattery : public CanBattery {
|
|||
uint16_t min_cell_voltage_mv = 3700;
|
||||
uint16_t max_cell_voltage_mv = 3700;
|
||||
|
||||
CAN_frame KIA_7E4_id1 = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 8,
|
||||
.ID = 0x7E4,
|
||||
.data = {0x02, 0x21, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||
CAN_frame KIA_7E4_id2 = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 8,
|
||||
.ID = 0x7E4,
|
||||
.data = {0x02, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||
CAN_frame KIA_7E4_id3 = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 8,
|
||||
.ID = 0x7E4,
|
||||
.data = {0x02, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||
CAN_frame KIA_7E4_id5 = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 8,
|
||||
.ID = 0x7E4,
|
||||
.data = {0x02, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00}};
|
||||
CAN_frame KIA_7E4 = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 8,
|
||||
.ID = 0x7E4,
|
||||
.data = {0x02, 0x21, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||
CAN_frame KIA_7E4_ack = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 8,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "MEB-BATTERY.h"
|
||||
#include <Arduino.h>
|
||||
#include <algorithm> // For std::min and std::max
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../communication/can/obd.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
|
@ -331,6 +332,7 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
|
||||
switch (rx_frame.ID) {
|
||||
case 0x17F0007B: // BMS 500ms
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
can_msg_received |= RX_0x17F0007B;
|
||||
component_protection_active = (rx_frame.data.u8[0] & 0x01);
|
||||
shutdown_active = ((rx_frame.data.u8[0] & 0x02) >> 1);
|
||||
|
@ -346,11 +348,13 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
case 0x17FE007B: // BMS - Offboard tester diag response
|
||||
break;
|
||||
case 0x1B00007B: // BMS - 200ms
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
wakeup_type =
|
||||
((rx_frame.data.u8[1] & 0x10) >> 4); //0 passive, SG has not woken up, 1 active, SG has woken up the network
|
||||
instrumentation_cluster_request = ((rx_frame.data.u8[1] & 0x40) >> 6); //True/false
|
||||
break;
|
||||
case 0x12DD54D0: // BMS Limits 100ms
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
can_msg_received |= RX_0x12DD54D0;
|
||||
max_discharge_power_watt =
|
||||
((rx_frame.data.u8[6] & 0x07) << 10) | (rx_frame.data.u8[5] << 2) | (rx_frame.data.u8[4] & 0xC0) >> 6; //*100
|
||||
|
@ -360,6 +364,7 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
max_charge_current_amp = ((rx_frame.data.u8[4] & 0x3F) << 7) | (rx_frame.data.u8[3] >> 1); //*0.2
|
||||
break;
|
||||
case 0x12DD54D1: // BMS 100ms
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
can_msg_received |= RX_0x12DD54D1;
|
||||
if (rx_frame.data.u8[6] != 0xFE || rx_frame.data.u8[7] != 0xFF) { // Init state, values below invalid
|
||||
battery_SOC = ((rx_frame.data.u8[3] & 0x0F) << 7) | (rx_frame.data.u8[2] >> 1); //*0.05
|
||||
|
@ -371,6 +376,7 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
warning_support = (rx_frame.data.u8[1] & 0x70) >> 4;
|
||||
break;
|
||||
case 0x12DD54D2: // BMS 100ms
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
can_msg_received |= RX_0x12DD54D2;
|
||||
battery_heating_active = (rx_frame.data.u8[4] & 0x40) >> 6;
|
||||
heating_request = (rx_frame.data.u8[5] & 0xE0) >> 5;
|
||||
|
@ -379,6 +385,7 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
power_battery_heating_req_watt = rx_frame.data.u8[7];
|
||||
break;
|
||||
case 0x1A555550: // BMS 500ms
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
can_msg_received |= RX_0x1A555550;
|
||||
balancing_active = (rx_frame.data.u8[1] & 0xC0) >> 6;
|
||||
charging_active = (rx_frame.data.u8[2] & 0x01);
|
||||
|
@ -388,6 +395,7 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
isolation_resistance_kOhm = (((rx_frame.data.u8[3] & 0x1F) << 7) | rx_frame.data.u8[2] >> 1); //*5
|
||||
break;
|
||||
case 0x1A555551: // BMS 500ms
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
can_msg_received |= RX_0x1A555551;
|
||||
battery_heating_installed = (rx_frame.data.u8[1] & 0x20) >> 5;
|
||||
error_NT_circuit = (rx_frame.data.u8[1] & 0x40) >> 6;
|
||||
|
@ -401,6 +409,7 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
return_temperature_C = rx_frame.data.u8[7]; //*0,5 -40
|
||||
break;
|
||||
case 0x1A5555B2: // BMS
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
can_msg_received |= RX_0x1A5555B2;
|
||||
performance_index_discharge_peak_temperature_percentage =
|
||||
(((rx_frame.data.u8[3] & 0x07) << 6) | rx_frame.data.u8[2] >> 2); //*0.2
|
||||
|
@ -410,6 +419,7 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
temperature_status_charge = (((rx_frame.data.u8[2] & 0x03) << 1) | rx_frame.data.u8[1] >> 7);
|
||||
break;
|
||||
case 0x16A954A6: // BMS
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
can_msg_received |= RX_0x16A954A6;
|
||||
BMS_16A954A6_counter = (rx_frame.data.u8[1] & 0x0F); // Can be used to check CAN signal integrity later on
|
||||
isolation_fault = (rx_frame.data.u8[2] & 0xE0) >> 5;
|
||||
|
@ -423,11 +433,13 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
datalayer.battery.status.cell_max_voltage_mV = actual_cellvoltage_highest_mV + 1000;
|
||||
}
|
||||
break;
|
||||
case 0x16A954F8: // BMS
|
||||
case 0x16A954F8: // BMS
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
predicted_power_dyn_standard_watt = ((rx_frame.data.u8[6] << 1) | rx_frame.data.u8[5] >> 7); //*50
|
||||
predicted_time_dyn_standard_minutes = rx_frame.data.u8[7];
|
||||
break;
|
||||
case 0x16A954E8: // BMS Temperature and cellvoltages - 180ms
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
mux = (rx_frame.data.u8[0] & 0x0F);
|
||||
switch (mux) {
|
||||
case 0: // Temperatures 1-56. Value is 0xFD if sensor not present
|
||||
|
@ -1259,14 +1271,11 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
}
|
||||
break;
|
||||
case 0x18DAF105:
|
||||
handle_obd_frame(rx_frame);
|
||||
handle_obd_frame(rx_frame, can_interface);
|
||||
break;
|
||||
default:
|
||||
logging.printf("Unknown CAN frame received:\n");
|
||||
dump_can_frame(rx_frame, MSG_RX);
|
||||
break;
|
||||
}
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
if (can_msg_received == 0xFFFF && nof_cells_determined) {
|
||||
if (datalayer.battery.status.real_bms_status == BMS_DISCONNECTED)
|
||||
datalayer.battery.status.real_bms_status = BMS_STANDBY;
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "MEB-HTML.h"
|
||||
|
||||
#ifdef MEB_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS MebBattery
|
||||
#endif
|
||||
|
||||
class MebBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "MG-5-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
@ -33,7 +34,6 @@ void Mg5Battery::
|
|||
}
|
||||
|
||||
void Mg5Battery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.ID) {
|
||||
case 0x171: //Following messages were detected on a MG5 battery BMS
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; // Let system know battery is sending CAN
|
||||
|
@ -112,7 +112,7 @@ void Mg5Battery::transmit_can(unsigned long currentMillis) {
|
|||
}
|
||||
|
||||
void Mg5Battery::setup(void) { // Performs one time setup at startup
|
||||
strncpy(datalayer.system.info.battery_protocol, "MG 5 battery", 63);
|
||||
strncpy(datalayer.system.info.battery_protocol, Name, 63);
|
||||
datalayer.system.info.battery_protocol[63] = '\0';
|
||||
datalayer.system.status.battery_allows_contactor_closing = true;
|
||||
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_DV;
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define MG_5_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef MG_5_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS Mg5Battery
|
||||
#endif
|
||||
|
||||
class Mg5Battery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "MG-HS-PHEV-BATTERY.h"
|
||||
#include <cmath> //For unit test
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../communication/contactorcontrol/comm_contactorcontrol.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
|
@ -14,8 +16,6 @@ changing.
|
|||
|
||||
OPTIONAL SETTINGS
|
||||
|
||||
Put these in your USER_SETTINGS.h:
|
||||
|
||||
// This will scale the SoC so the batteries top out at 4.2V/cell instead of
|
||||
4.1V/cell. The car only seems to use up to 4.1V/cell in service.
|
||||
#define MG_HS_PHEV_USE_FULL_CAPACITY true
|
||||
|
@ -372,6 +372,5 @@ void MgHsPHEVBattery::setup(void) { // Performs one time setup at startup
|
|||
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_DV;
|
||||
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_MV;
|
||||
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_MV;
|
||||
datalayer.battery.info.total_capacity_Wh = BATTERY_WH_MAX;
|
||||
datalayer.battery.info.number_of_cells = 90;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef MG_HS_PHEV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS MgHsPHEVBattery
|
||||
#endif
|
||||
|
||||
class MgHsPHEVBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "NISSAN-LEAF-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../charger/CHARGERS.h"
|
||||
#include "../charger/CanCharger.h"
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h" //For "More battery info" webpage
|
||||
#include "../devboard/utils/events.h"
|
||||
#include "../devboard/utils/logging.h"
|
||||
|
||||
#include "../charger/CHARGERS.h"
|
||||
#include "../charger/CanCharger.h"
|
||||
|
||||
uint16_t Temp_fromRAW_to_F(uint16_t temperature);
|
||||
//Cryptographic functions
|
||||
void decodeChallengeData(unsigned int SeedInput, unsigned char* Crypt_Output_Buffer);
|
||||
|
@ -150,13 +150,14 @@ void NissanLeafBattery::
|
|||
clear_event(EVENT_BATTERY_CHG_DISCHG_STOP_REQ);
|
||||
}
|
||||
|
||||
#ifdef INTERLOCK_REQUIRED
|
||||
if (!battery_Interlock) {
|
||||
set_event(EVENT_HVIL_FAILURE, 0);
|
||||
} else {
|
||||
clear_event(EVENT_HVIL_FAILURE);
|
||||
if (user_selected_LEAF_interlock_mandatory) {
|
||||
//If user requires both large 80kW and small 6kW interlock to be seated for operation
|
||||
if (!battery_Interlock) {
|
||||
set_event(EVENT_HVIL_FAILURE, 0);
|
||||
} else {
|
||||
clear_event(EVENT_HVIL_FAILURE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (battery_HeatExist) {
|
||||
if (battery_Heating_Stop) {
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
#include "CanBattery.h"
|
||||
#include "NISSAN-LEAF-HTML.h"
|
||||
|
||||
#ifdef NISSAN_LEAF_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS NissanLeafBattery
|
||||
#endif
|
||||
extern bool user_selected_LEAF_interlock_mandatory;
|
||||
|
||||
class NissanLeafBattery : public CanBattery {
|
||||
public:
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../system_settings.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef ORION_BMS
|
||||
#define SELECTED_BATTERY_CLASS OrionBms
|
||||
#endif
|
||||
|
||||
class OrionBms : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -37,7 +37,6 @@ void PylonBattery::update_values() {
|
|||
}
|
||||
|
||||
void PylonBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
datalayer_battery->status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.ID) {
|
||||
case 0x7310:
|
||||
case 0x7311:
|
||||
|
@ -55,6 +54,7 @@ void PylonBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
break;
|
||||
case 0x4210:
|
||||
case 0x4211:
|
||||
datalayer_battery->status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
voltage_dV = ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[0]);
|
||||
current_dA = ((rx_frame.data.u8[3] << 8) | rx_frame.data.u8[2]) - 30000;
|
||||
SOC = rx_frame.data.u8[6];
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef PYLON_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS PylonBattery
|
||||
#endif
|
||||
|
||||
class PylonBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "RANGE-ROVER-PHEV-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
@ -76,7 +77,6 @@ void RangeRoverPhevBattery::update_values() {
|
|||
}
|
||||
|
||||
void RangeRoverPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.ID) {
|
||||
case 0x080: // 15ms
|
||||
StatusCAT5BPOChg = (rx_frame.data.u8[0] & 0x01);
|
||||
|
@ -104,6 +104,7 @@ void RangeRoverPhevBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
DischargeContPwrLmt = ((rx_frame.data.u8[6] << 8) | rx_frame.data.u8[7]);
|
||||
break;
|
||||
case 0x102: // 20ms
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
PwrGpCS = rx_frame.data.u8[0];
|
||||
PwrGpCounter = (rx_frame.data.u8[1] & 0x3C) >> 2;
|
||||
VoltageExt = (((rx_frame.data.u8[1] & 0x03) << 8) | rx_frame.data.u8[2]);
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RANGE_ROVER_PHEV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RangeRoverPhevBattery
|
||||
#endif
|
||||
|
||||
class RangeRoverPhevBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../system_settings.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RELION_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RelionBattery
|
||||
#endif
|
||||
|
||||
class RelionBattery : public CanBattery {
|
||||
public:
|
||||
RelionBattery() : CanBattery(CAN_Speed::CAN_SPEED_250KBPS) {}
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RENAULT_KANGOO_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RenaultKangooBattery
|
||||
#endif
|
||||
|
||||
class RenaultKangooBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "RENAULT-TWIZY.h"
|
||||
#include <cstdint>
|
||||
#include <cstring> //For unit test
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
||||
|
@ -51,9 +52,10 @@ void RenaultTwizyBattery::update_values() {
|
|||
}
|
||||
|
||||
void RenaultTwizyBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.ID) {
|
||||
case 0x155:
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
|
||||
// max charge power is in steps of 300W from 0 to 7
|
||||
max_charge_power = (uint16_t)rx_frame.data.u8[0] * 300;
|
||||
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#define RENAULT_TWIZY_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RENAULT_TWIZY_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RenaultTwizyBattery
|
||||
#endif
|
||||
|
||||
class RenaultTwizyBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include "RENAULT-ZOE-GEN1-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
||||
void transmit_can_frame(CAN_frame* tx_frame, int interface);
|
||||
|
||||
/* Information in this file is based of the OVMS V3 vehicle_renaultzoe.cpp component
|
||||
https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/blob/master/vehicle/OVMS.V3/components/vehicle_renaultzoe/src/vehicle_renaultzoe.cpp
|
||||
The Zoe BMS apparently does not send total pack voltage, so we use the polled 96x cellvoltages summed up as total voltage
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "RENAULT-ZOE-GEN1-HTML.h"
|
||||
|
||||
#ifdef RENAULT_ZOE_GEN1_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RenaultZoeGen1Battery
|
||||
#endif
|
||||
|
||||
class RenaultZoeGen1Battery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
@ -38,10 +34,10 @@ class RenaultZoeGen1Battery : public CanBattery {
|
|||
private:
|
||||
RenaultZoeGen1HtmlRenderer renderer;
|
||||
|
||||
static const int MAX_PACK_VOLTAGE_DV = 4200; //5000 = 500.0V
|
||||
static const int MAX_PACK_VOLTAGE_DV = 4040; //5000 = 500.0V
|
||||
static const int MIN_PACK_VOLTAGE_DV = 3000;
|
||||
static const int MAX_CELL_DEVIATION_MV = 150;
|
||||
static const int MAX_CELL_VOLTAGE_MV = 4250; //Battery is put into emergency stop if one cell goes over this value
|
||||
static const int MAX_CELL_VOLTAGE_MV = 4220; //Battery is put into emergency stop if one cell goes over this value
|
||||
static const int MIN_CELL_VOLTAGE_MV = 2700; //Battery is put into emergency stop if one cell goes below this value
|
||||
|
||||
DATALAYER_BATTERY_TYPE* datalayer_battery;
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "RENAULT-ZOE-GEN2-HTML.h"
|
||||
|
||||
#ifdef RENAULT_ZOE_GEN2_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS RenaultZoeGen2Battery
|
||||
#endif
|
||||
|
||||
class RenaultZoeGen2Battery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
159
Software/src/battery/RIVIAN-BATTERY.cpp
Normal file
159
Software/src/battery/RIVIAN-BATTERY.cpp
Normal file
|
@ -0,0 +1,159 @@
|
|||
#include "RIVIAN-BATTERY.h"
|
||||
|
||||
#include "../battery/BATTERIES.h"
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
||||
/*
|
||||
Initial support for Rivian BIG battery (135kWh)
|
||||
The battery has 3x CAN channels
|
||||
- Failover CAN (CAN-FD) lots of content, not required for operation. Has all cellvoltages!
|
||||
- Platform CAN (500kbps) with all the control messages needed to control the battery <- This is the one we want
|
||||
- Battery CAN (500kbps) lots of content, not required for operation
|
||||
*/
|
||||
|
||||
void RivianBattery::update_values() {
|
||||
|
||||
datalayer.battery.status.real_soc = battery_SOC;
|
||||
|
||||
datalayer.battery.status.soh_pptt;
|
||||
|
||||
datalayer.battery.status.voltage_dV = battery_voltage;
|
||||
datalayer.battery.status.current_dA = ((int16_t)battery_current / 10.0 - 3200) * 10;
|
||||
|
||||
datalayer.battery.status.remaining_capacity_Wh = static_cast<uint32_t>(
|
||||
(static_cast<double>(datalayer.battery.status.real_soc) / 10000) * datalayer.battery.info.total_capacity_Wh);
|
||||
|
||||
datalayer.battery.status.max_charge_power_W = ((battery_voltage / 10) * battery_charge_limit_amp);
|
||||
datalayer.battery.status.max_discharge_power_W = ((battery_voltage / 10) * battery_discharge_limit_amp);
|
||||
|
||||
//datalayer.battery.status.cell_min_voltage_mV = 3700; //TODO: Take from failover CAN?
|
||||
//datalayer.battery.status.cell_max_voltage_mV = 3700; //TODO: Take from failover CAN?
|
||||
|
||||
datalayer.battery.status.temperature_min_dC = battery_min_temperature * 10;
|
||||
datalayer.battery.status.temperature_max_dC = battery_max_temperature * 10;
|
||||
}
|
||||
|
||||
void RivianBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
switch (rx_frame.ID) {
|
||||
case 0x160: //Current [Platform CAN]+
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_current = ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[0]);
|
||||
break;
|
||||
case 0x151: //Celltemps (requires other CAN channel)
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
break;
|
||||
case 0x120: //Voltages [Platform CAN]+
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_voltage = (((rx_frame.data.u8[7] & 0x1F) << 8) | rx_frame.data.u8[6]);
|
||||
break;
|
||||
case 0x25A: //SOC and kWh [Platform CAN]+
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
//battery_SOC = (((rx_frame.data.u8[1] & 0x03) << 8) | rx_frame.data.u8[0]);
|
||||
kWh_available_max =
|
||||
(((rx_frame.data.u8[3] & 0x03) << 14) | (rx_frame.data.u8[2] << 6) | (rx_frame.data.u8[1] >> 2)) / 200;
|
||||
kWh_available_total =
|
||||
(((rx_frame.data.u8[5] & 0x03) << 14) | (rx_frame.data.u8[4] << 6) | (rx_frame.data.u8[3] >> 2)) / 200;
|
||||
break;
|
||||
case 0x405: //State [Platform CAN]+
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
BMS_state = (rx_frame.data.u8[0] & 0x03);
|
||||
break;
|
||||
case 0x100: //Discharge/Charge speed
|
||||
battery_charge_limit_amp =
|
||||
(((rx_frame.data.u8[3] & 0x0F) << 8) | (rx_frame.data.u8[2] << 4) | (rx_frame.data.u8[1] >> 4)) / 20;
|
||||
battery_discharge_limit_amp =
|
||||
(((rx_frame.data.u8[5] & 0x0F) << 8) | (rx_frame.data.u8[4] << 4) | (rx_frame.data.u8[3] >> 4)) / 20;
|
||||
break;
|
||||
case 0x153: //Temperatures
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_max_temperature = (rx_frame.data.u8[5] / 2) - 40;
|
||||
battery_min_temperature = (rx_frame.data.u8[6] / 2) - 40;
|
||||
break;
|
||||
case 0x55B: //Temperatures
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_SOC = (rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void RivianBattery::transmit_can(unsigned long currentMillis) {
|
||||
// Send 500ms CAN Message, too fast and the pack can't change states (pre-charge is built in, seems we can't change state during pre-charge)
|
||||
// 100ms seems to draw too much current for a 5A supply during contactor pull in
|
||||
if (currentMillis - previousMillis10 >= (INTERVAL_200_MS)) {
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
//If we want to close contactors, and preconditions are met
|
||||
if ((datalayer.system.status.inverter_allows_contactor_closing) && (datalayer.battery.status.bms_status != FAULT)) {
|
||||
//Standby -> Ready Mode
|
||||
if (BMS_state == STANDBY || BMS_state == SLEEP) {
|
||||
RIVIAN_150.data.u8[0] = 0x03;
|
||||
RIVIAN_150.data.u8[2] = 0x01;
|
||||
RIVIAN_420.data.u8[0] = 0x02;
|
||||
RIVIAN_200.data.u8[0] = 0x08;
|
||||
|
||||
transmit_can_frame(&RIVIAN_150);
|
||||
transmit_can_frame(&RIVIAN_420);
|
||||
transmit_can_frame(&RIVIAN_41F);
|
||||
transmit_can_frame(&RIVIAN_207);
|
||||
transmit_can_frame(&RIVIAN_200);
|
||||
}
|
||||
//Ready mode -> Go Mode
|
||||
|
||||
if (BMS_state == READY) {
|
||||
RIVIAN_150.data.u8[0] = 0x3E;
|
||||
RIVIAN_150.data.u8[2] = 0x03;
|
||||
RIVIAN_420.data.u8[0] = 0x03;
|
||||
|
||||
transmit_can_frame(&RIVIAN_150);
|
||||
transmit_can_frame(&RIVIAN_420);
|
||||
}
|
||||
|
||||
} else { //If we want to open contactors, transition the other way
|
||||
//Go mode -> Ready Mode
|
||||
|
||||
if (BMS_state == GO) {
|
||||
RIVIAN_150.data.u8[0] = 0x03;
|
||||
RIVIAN_150.data.u8[2] = 0x01;
|
||||
|
||||
transmit_can_frame(&RIVIAN_150);
|
||||
}
|
||||
|
||||
if (BMS_state == READY) {
|
||||
RIVIAN_150.data.u8[0] = 0x03;
|
||||
RIVIAN_150.data.u8[2] = 0x01;
|
||||
RIVIAN_420.data.u8[0] = 0x01;
|
||||
RIVIAN_200.data.u8[0] = 0x10;
|
||||
|
||||
transmit_can_frame(&RIVIAN_245);
|
||||
transmit_can_frame(&RIVIAN_150);
|
||||
transmit_can_frame(&RIVIAN_420);
|
||||
transmit_can_frame(&RIVIAN_41F);
|
||||
transmit_can_frame(&RIVIAN_200);
|
||||
}
|
||||
}
|
||||
//disabled this because the battery didn't like it so fast (slowed to 100ms) and because the battery couldn't change states fast enough
|
||||
//as much as I don't like the "free-running" aspect of it, checking the BMS_state and acting on it should fix issues caused by that.
|
||||
//transmit_can_frame(&RIVIAN_150);
|
||||
//transmit_can_frame(&RIVIAN_420);
|
||||
//transmit_can_frame(&RIVIAN_41F);
|
||||
//transmit_can_frame(&RIVIAN_207);
|
||||
//transmit_can_frame(&RIVIAN_200);
|
||||
}
|
||||
}
|
||||
|
||||
void RivianBattery::setup(void) { // Performs one time setup at startup
|
||||
strncpy(datalayer.system.info.battery_protocol, Name, 63);
|
||||
datalayer.system.info.battery_protocol[63] = '\0';
|
||||
datalayer.battery.info.number_of_cells = 108;
|
||||
datalayer.battery.info.total_capacity_Wh = 135000;
|
||||
datalayer.battery.info.chemistry = NMC;
|
||||
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_DV;
|
||||
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_DV;
|
||||
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_MV;
|
||||
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_MV;
|
||||
datalayer.system.status.battery_allows_contactor_closing = true;
|
||||
}
|
60
Software/src/battery/RIVIAN-BATTERY.h
Normal file
60
Software/src/battery/RIVIAN-BATTERY.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
#ifndef RIVIAN_BATTERY_H
|
||||
#define RIVIAN_BATTERY_H
|
||||
#include "CanBattery.h"
|
||||
|
||||
class RivianBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
virtual void handle_incoming_can_frame(CAN_frame rx_frame);
|
||||
virtual void update_values();
|
||||
virtual void transmit_can(unsigned long currentMillis);
|
||||
static constexpr const char* Name = "Rivian R1T large 135kWh battery";
|
||||
|
||||
private:
|
||||
static const int MAX_PACK_VOLTAGE_DV = 4480;
|
||||
static const int MIN_PACK_VOLTAGE_DV = 2920;
|
||||
static const int MAX_CELL_DEVIATION_MV = 150;
|
||||
static const int MAX_CELL_VOLTAGE_MV = 4200; //Battery is put into emergency stop if one cell goes over this value
|
||||
static const int MIN_CELL_VOLTAGE_MV = 3300; //Battery is put into emergency stop if one cell goes below this value
|
||||
|
||||
uint8_t BMS_state = 0;
|
||||
uint16_t battery_voltage = 3700;
|
||||
uint16_t battery_SOC = 5000;
|
||||
int32_t battery_current = 32000;
|
||||
uint16_t kWh_available_total = 135;
|
||||
uint16_t kWh_available_max = 135;
|
||||
int16_t battery_min_temperature = 0;
|
||||
int16_t battery_max_temperature = 0;
|
||||
uint16_t battery_discharge_limit_amp = 0;
|
||||
uint16_t battery_charge_limit_amp = 0;
|
||||
static const uint8_t SLEEP = 0;
|
||||
static const uint8_t STANDBY = 1;
|
||||
static const uint8_t READY = 2;
|
||||
static const uint8_t GO = 3;
|
||||
unsigned long previousMillis10 = 0; // will store last time a 10ms CAN Message was sent
|
||||
|
||||
CAN_frame RIVIAN_150 = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 6,
|
||||
.ID = 0x150,
|
||||
.data = {0x03, 0x00, 0x01, 0x00, 0x01, 0x00}};
|
||||
CAN_frame RIVIAN_420 = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 8,
|
||||
.ID = 0x420,
|
||||
.data = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||
CAN_frame RIVIAN_41F = {.FD = false, .ext_ID = false, .DLC = 3, .ID = 0x41F, .data = {0x62, 0x10, 0x00}};
|
||||
CAN_frame RIVIAN_245 = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 6,
|
||||
.ID = 0x245,
|
||||
.data = {0x10, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||
CAN_frame RIVIAN_200 = {.FD = false, .ext_ID = false, .DLC = 1, .ID = 0x200, .data = {0x08}};
|
||||
CAN_frame RIVIAN_207 = {.FD = false,
|
||||
.ext_ID = false,
|
||||
.DLC = 1,
|
||||
.ID = 0x207,
|
||||
.data = {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00}};
|
||||
};
|
||||
|
||||
#endif
|
|
@ -33,20 +33,20 @@ void RjxzsBms::update_values() {
|
|||
datalayer.battery.status.current_dA = total_current;
|
||||
}
|
||||
|
||||
// Charge power is set in .h file
|
||||
// Charge power is manually set
|
||||
if (datalayer.battery.status.real_soc > 9900) {
|
||||
datalayer.battery.status.max_charge_power_W = MAX_CHARGE_POWER_WHEN_TOPBALANCING_W;
|
||||
} else if (datalayer.battery.status.real_soc > RAMPDOWN_SOC) {
|
||||
// When real SOC is between RAMPDOWN_SOC-99%, ramp the value between Max<->0
|
||||
datalayer.battery.status.max_charge_power_W =
|
||||
MAX_CHARGE_POWER_ALLOWED_W *
|
||||
datalayer.battery.status.override_charge_power_W *
|
||||
(1 - (datalayer.battery.status.real_soc - RAMPDOWN_SOC) / (10000.0 - RAMPDOWN_SOC));
|
||||
} else { // No limits, max charging power allowed
|
||||
datalayer.battery.status.max_charge_power_W = MAX_CHARGE_POWER_ALLOWED_W;
|
||||
datalayer.battery.status.max_charge_power_W = datalayer.battery.status.override_charge_power_W;
|
||||
}
|
||||
|
||||
// Discharge power is also set in .h file
|
||||
datalayer.battery.status.max_discharge_power_W = MAX_DISCHARGE_POWER_ALLOWED_W;
|
||||
// Discharge power is manually set
|
||||
datalayer.battery.status.max_discharge_power_W = datalayer.battery.status.override_discharge_power_W;
|
||||
|
||||
uint16_t temperatures[] = {
|
||||
module_1_temperature, module_2_temperature, module_3_temperature, module_4_temperature,
|
||||
|
@ -140,262 +140,18 @@ void RjxzsBms::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
charging_active = false;
|
||||
discharging_active = true;
|
||||
}
|
||||
} else if (mux == 0x07) { // Cellvoltages 1-3
|
||||
cellvoltages[0] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[1] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[2] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x08) { // Cellvoltages 4-6
|
||||
cellvoltages[3] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[4] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[5] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x09) { // Cellvoltages 7-9
|
||||
cellvoltages[6] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[7] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[8] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x0A) { // Cellvoltages 10-12
|
||||
cellvoltages[9] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[10] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[11] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x0B) { // Cellvoltages 13-15
|
||||
cellvoltages[12] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[13] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[14] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x0C) { // Cellvoltages 16-18
|
||||
cellvoltages[15] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[16] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[17] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x0D) { // Cellvoltages 19-21
|
||||
cellvoltages[18] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[19] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[20] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x0E) { // Cellvoltages 22-24
|
||||
cellvoltages[21] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[22] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[23] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x0F) { // Cellvoltages 25-27
|
||||
cellvoltages[24] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[25] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[26] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x10) { // Cellvoltages 28-30
|
||||
cellvoltages[27] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[28] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[29] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x11) { // Cellvoltages 31-33
|
||||
cellvoltages[30] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[31] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[32] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x12) { // Cellvoltages 34-36
|
||||
cellvoltages[33] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[34] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[35] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x13) { // Cellvoltages 37-39
|
||||
cellvoltages[36] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[37] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[38] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x14) { // Cellvoltages 40-42
|
||||
cellvoltages[39] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[40] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[41] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x15) { // Cellvoltages 43-45
|
||||
cellvoltages[42] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[43] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[44] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x16) { // Cellvoltages 46-48
|
||||
cellvoltages[45] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[46] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[47] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x17) { // Cellvoltages 49-51
|
||||
cellvoltages[48] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[49] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[50] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x18) { // Cellvoltages 52-54
|
||||
cellvoltages[51] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[52] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[53] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x19) { // Cellvoltages 55-57
|
||||
cellvoltages[54] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[55] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[56] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x1A) { // Cellvoltages 58-60
|
||||
cellvoltages[57] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[58] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[59] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x1B) { // Cellvoltages 61-63
|
||||
cellvoltages[60] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[61] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[62] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x1C) { // Cellvoltages 64-66
|
||||
cellvoltages[63] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[64] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[65] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x1D) { // Cellvoltages 67-69
|
||||
cellvoltages[66] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[67] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[68] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x1E) { // Cellvoltages 70-72
|
||||
cellvoltages[69] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[70] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[71] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x1F) { // Cellvoltages 73-75
|
||||
cellvoltages[72] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[73] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[74] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x20) { // Cellvoltages 76-78
|
||||
cellvoltages[75] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[76] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[77] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x21) { // Cellvoltages 79-81
|
||||
cellvoltages[78] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[79] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[80] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x22) { // Cellvoltages 82-84
|
||||
cellvoltages[81] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[82] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[83] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x23) { // Cellvoltages 85-87
|
||||
cellvoltages[84] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[85] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[86] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x24) { // Cellvoltages 88-90
|
||||
cellvoltages[87] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[88] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[89] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x25) { // Cellvoltages 91-93
|
||||
cellvoltages[90] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[91] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[92] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x26) { // Cellvoltages 94-96
|
||||
cellvoltages[93] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[94] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[95] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x27) { // Cellvoltages 97-99
|
||||
cellvoltages[96] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[97] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[98] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x28) { // Cellvoltages 100-102
|
||||
cellvoltages[99] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[100] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[101] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x29) { // Cellvoltages 103-105
|
||||
cellvoltages[102] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[103] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[104] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x2A) { // Cellvoltages 106-108
|
||||
cellvoltages[105] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[106] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[107] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x2B) { // Cellvoltages 109-111
|
||||
cellvoltages[108] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[109] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[110] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x2C) { // Cellvoltages 112-114
|
||||
cellvoltages[111] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[112] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[113] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x2D) { // Cellvoltages 115-117
|
||||
cellvoltages[114] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[115] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[116] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x2E) { // Cellvoltages 118-120
|
||||
cellvoltages[117] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[118] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[119] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x2F) { // Cellvoltages 121-123
|
||||
cellvoltages[120] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[121] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[122] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x30) { // Cellvoltages 124-126
|
||||
cellvoltages[123] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[124] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[125] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x31) { // Cellvoltages 127-129
|
||||
cellvoltages[126] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[127] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[128] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x32) { // Cellvoltages 130-132
|
||||
cellvoltages[129] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[130] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[131] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x33) { // Cellvoltages 133-135
|
||||
cellvoltages[132] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[133] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[134] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x34) { // Cellvoltages 136-138
|
||||
cellvoltages[135] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[136] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[137] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x35) { // Cellvoltages 139-141
|
||||
cellvoltages[138] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[139] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[140] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x36) { // Cellvoltages 142-144
|
||||
cellvoltages[141] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[142] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[143] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x37) { // Cellvoltages 145-147
|
||||
cellvoltages[144] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[145] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[146] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x38) { // Cellvoltages 148-150
|
||||
cellvoltages[147] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[148] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[149] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x39) { // Cellvoltages 151-153
|
||||
cellvoltages[150] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[151] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[152] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x3A) { // Cellvoltages 154-156
|
||||
cellvoltages[153] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[154] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[155] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x3B) { // Cellvoltages 157-159
|
||||
cellvoltages[156] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[157] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[158] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x3C) { // Cellvoltages 160-162
|
||||
cellvoltages[159] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[160] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[161] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x3D) { // Cellvoltages 163-165
|
||||
cellvoltages[162] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[163] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[164] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x3E) { // Cellvoltages 166-167
|
||||
cellvoltages[165] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[166] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[167] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x3F) { // Cellvoltages 169-171
|
||||
cellvoltages[168] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[169] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[170] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x40) { // Cellvoltages 172-174
|
||||
cellvoltages[171] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[172] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[173] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x41) { // Cellvoltages 175-177
|
||||
cellvoltages[174] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[175] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[176] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x42) { // Cellvoltages 178-180
|
||||
cellvoltages[177] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[178] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[179] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x43) { // Cellvoltages 181-183
|
||||
cellvoltages[180] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[181] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[182] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x44) { // Cellvoltages 184-186
|
||||
cellvoltages[183] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[184] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[185] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x45) { // Cellvoltages 187-189
|
||||
cellvoltages[186] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[187] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[188] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux == 0x46) { // Cellvoltages 190-192
|
||||
cellvoltages[189] = (rx_frame.data.u8[1] << 8) | rx_frame.data.u8[2];
|
||||
cellvoltages[190] = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
cellvoltages[191] = (rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6];
|
||||
} else if (mux >= 0x07 && mux <= 0x46) {
|
||||
// Cell voltages 1-192 (3 per message, 0x07=1-3, 0x08=4-6, ..., 0x46=190-192)
|
||||
int cell_index = (mux - 0x07) * 3;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (cell_index + i >= MAX_AMOUNT_CELLS) {
|
||||
break;
|
||||
}
|
||||
cellvoltages[cell_index + i] = (rx_frame.data.u8[1 + i * 2] << 8) | rx_frame.data.u8[2 + i * 2];
|
||||
}
|
||||
if (cell_index + 2 >= populated_cellvoltages) {
|
||||
populated_cellvoltages = cell_index + 2 + 1;
|
||||
}
|
||||
} else if (mux == 0x47) {
|
||||
temperature_below_zero_mod1_4 = rx_frame.data.u8[2];
|
||||
module_1_temperature = (rx_frame.data.u8[3] << 8) | rx_frame.data.u8[4];
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../system_settings.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef RJXZS_BMS
|
||||
#define SELECTED_BATTERY_CLASS RjxzsBms
|
||||
#endif
|
||||
|
||||
class RjxzsBms : public CanBattery {
|
||||
public:
|
||||
RjxzsBms() : CanBattery(CAN_Speed::CAN_SPEED_250KBPS) {}
|
||||
|
@ -19,9 +15,6 @@ class RjxzsBms : public CanBattery {
|
|||
static constexpr const char* Name = "RJXZS BMS, DIY battery";
|
||||
|
||||
private:
|
||||
/* Tweak these according to your battery build */
|
||||
static const int MAX_DISCHARGE_POWER_ALLOWED_W = 5000;
|
||||
static const int MAX_CHARGE_POWER_ALLOWED_W = 5000;
|
||||
static const int MAX_CHARGE_POWER_WHEN_TOPBALANCING_W = 500;
|
||||
static const int RAMPDOWN_SOC =
|
||||
9000; // (90.00) SOC% to start ramping down from max charge power towards 0 at 100.00%
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef SAMSUNG_SDI_LV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS SamsungSdiLVBattery
|
||||
#endif
|
||||
|
||||
class SamsungSdiLVBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "SANTA-FE-PHEV-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef SANTA_FE_PHEV_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS SantaFePhevBattery
|
||||
#endif
|
||||
|
||||
class SantaFePhevBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "SIMPBMS-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../battery/BATTERIES.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
||||
void SimpBmsBattery::update_values() {
|
||||
|
||||
datalayer.battery.status.real_soc = (SOC * 100); //increase SOC range from 0-100 -> 100.00
|
||||
|
@ -40,9 +40,10 @@ void SimpBmsBattery::update_values() {
|
|||
}
|
||||
|
||||
void SimpBmsBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.ID) {
|
||||
case 0x355:
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
|
||||
SOC = (rx_frame.data.u8[1] << 8) + rx_frame.data.u8[0];
|
||||
SOH = (rx_frame.data.u8[3] << 8) + rx_frame.data.u8[2];
|
||||
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef SIMPBMS_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS SimpBmsBattery
|
||||
#endif
|
||||
|
||||
class SimpBmsBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "SONO-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/events.h"
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef SONO_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS SonoBattery
|
||||
#endif
|
||||
|
||||
class SonoBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef _SHUNT_H
|
||||
#define _SHUNT_H
|
||||
|
||||
#include "../../USER_SETTINGS.h"
|
||||
#include "../../src/communication/Transmitter.h"
|
||||
#include "../../src/communication/can/CanReceiver.h"
|
||||
#include "../../src/communication/can/comm_can.h"
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
CanShunt* shunt = nullptr;
|
||||
ShuntType user_selected_shunt_type = ShuntType::None;
|
||||
|
||||
#ifdef COMMON_IMAGE
|
||||
#ifdef SELECTED_SHUNT_CLASS
|
||||
#error "Compile time SELECTED_SHUNT_CLASS should not be defined with COMMON_IMAGE"
|
||||
#endif
|
||||
|
||||
void setup_can_shunt() {
|
||||
if (shunt) {
|
||||
return;
|
||||
|
@ -30,21 +25,6 @@ void setup_can_shunt() {
|
|||
}
|
||||
}
|
||||
|
||||
#else
|
||||
void setup_can_shunt() {
|
||||
if (shunt) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(SELECTED_SHUNT_CLASS)
|
||||
shunt = new SELECTED_SHUNT_CLASS();
|
||||
if (shunt) {
|
||||
shunt->setup();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
extern std::vector<ShuntType> supported_shunt_types() {
|
||||
std::vector<ShuntType> types;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "TESLA-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h" //For Advanced Battery Insights webpage
|
||||
|
@ -112,33 +113,6 @@ inline const char* getHvilStatusState(int index) {
|
|||
}
|
||||
}
|
||||
|
||||
inline const char* getBMSState(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "STANDBY";
|
||||
case 1:
|
||||
return "DRIVE";
|
||||
case 2:
|
||||
return "SUPPORT";
|
||||
case 3:
|
||||
return "CHARGE";
|
||||
case 4:
|
||||
return "FEIM";
|
||||
case 5:
|
||||
return "CLEAR_FAULT";
|
||||
case 6:
|
||||
return "FAULT";
|
||||
case 7:
|
||||
return "WELD";
|
||||
case 8:
|
||||
return "TEST";
|
||||
case 9:
|
||||
return "SNA";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* getBMSContactorState(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
|
@ -160,174 +134,10 @@ inline const char* getBMSContactorState(int index) {
|
|||
}
|
||||
}
|
||||
|
||||
inline const char* getBMSHvState(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "DOWN";
|
||||
case 1:
|
||||
return "COMING_UP";
|
||||
case 2:
|
||||
return "GOING_DOWN";
|
||||
case 3:
|
||||
return "UP_FOR_DRIVE";
|
||||
case 4:
|
||||
return "UP_FOR_CHARGE";
|
||||
case 5:
|
||||
return "UP_FOR_DC_CHARGE";
|
||||
case 6:
|
||||
return "UP";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* getBMSUiChargeStatus(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "DISCONNECTED";
|
||||
case 1:
|
||||
return "NO_POWER";
|
||||
case 2:
|
||||
return "ABOUT_TO_CHARGE";
|
||||
case 3:
|
||||
return "CHARGING";
|
||||
case 4:
|
||||
return "CHARGE_COMPLETE";
|
||||
case 5:
|
||||
return "CHARGE_STOPPED";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* getPCS_DcdcStatus(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "IDLE";
|
||||
case 1:
|
||||
return "ACTIVE";
|
||||
case 2:
|
||||
return "FAULTED";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* getPCS_DcdcMainState(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "STANDBY";
|
||||
case 1:
|
||||
return "12V_SUPPORT_ACTIVE";
|
||||
case 2:
|
||||
return "PRECHARGE_STARTUP";
|
||||
case 3:
|
||||
return "PRECHARGE_ACTIVE";
|
||||
case 4:
|
||||
return "DIS_HVBUS_ACTIVE";
|
||||
case 5:
|
||||
return "SHUTDOWN";
|
||||
case 6:
|
||||
return "FAULTED";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* getPCS_DcdcSubState(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "PWR_UP_INIT";
|
||||
case 1:
|
||||
return "STANDBY";
|
||||
case 2:
|
||||
return "12V_SUPPORT_ACTIVE";
|
||||
case 3:
|
||||
return "DIS_HVBUS";
|
||||
case 4:
|
||||
return "PCHG_FAST_DIS_HVBUS";
|
||||
case 5:
|
||||
return "PCHG_SLOW_DIS_HVBUS";
|
||||
case 6:
|
||||
return "PCHG_DWELL_CHARGE";
|
||||
case 7:
|
||||
return "PCHG_DWELL_WAIT";
|
||||
case 8:
|
||||
return "PCHG_DI_RECOVERY_WAIT";
|
||||
case 9:
|
||||
return "PCHG_ACTIVE";
|
||||
case 10:
|
||||
return "PCHG_FLT_FAST_DIS_HVBUS";
|
||||
case 11:
|
||||
return "SHUTDOWN";
|
||||
case 12:
|
||||
return "12V_SUPPORT_FAULTED";
|
||||
case 13:
|
||||
return "DIS_HVBUS_FAULTED";
|
||||
case 14:
|
||||
return "PCHG_FAULTED";
|
||||
case 15:
|
||||
return "CLEAR_FAULTS";
|
||||
case 16:
|
||||
return "FAULTED";
|
||||
case 17:
|
||||
return "NUM";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* getBMSPowerLimitState(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "NOT_CALCULATED_FOR_DRIVE";
|
||||
case 1:
|
||||
return "CALCULATED_FOR_DRIVE";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* getHVPStatus(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "INVALID";
|
||||
case 1:
|
||||
return "NOT_AVAILABLE";
|
||||
case 2:
|
||||
return "STALE";
|
||||
case 3:
|
||||
return "VALID";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* getHVPContactor(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "NOT_ACTIVE";
|
||||
case 1:
|
||||
return "ACTIVE";
|
||||
case 2:
|
||||
return "COMPLETED";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* getFalseTrue(bool value) {
|
||||
return value ? "True" : "False";
|
||||
}
|
||||
|
||||
inline const char* getNoYes(bool value) {
|
||||
return value ? "Yes" : "No";
|
||||
}
|
||||
|
||||
inline const char* getFault(bool value) {
|
||||
return value ? "ACTIVE" : "NOT_ACTIVE";
|
||||
}
|
||||
|
||||
// Clamp DLC to 0–8 bytes for classic CAN
|
||||
inline int getDataLen(uint8_t dlc) {
|
||||
return std::min<int>(dlc, 8);
|
||||
|
@ -626,8 +436,8 @@ void TeslaBattery::
|
|||
// Define the allowed discharge power
|
||||
datalayer.battery.status.max_discharge_power_W = (battery_max_discharge_current * (battery_volts / 10));
|
||||
// Cap the allowed discharge power if higher than the maximum discharge power allowed
|
||||
if (datalayer.battery.status.max_discharge_power_W > MAXDISCHARGEPOWERALLOWED) {
|
||||
datalayer.battery.status.max_discharge_power_W = MAXDISCHARGEPOWERALLOWED;
|
||||
if (datalayer.battery.status.max_discharge_power_W > datalayer.battery.status.override_discharge_power_W) {
|
||||
datalayer.battery.status.max_discharge_power_W = datalayer.battery.status.override_discharge_power_W;
|
||||
}
|
||||
|
||||
//The allowed charge power behaves strangely. We instead estimate this value
|
||||
|
@ -648,7 +458,7 @@ void TeslaBattery::
|
|||
}
|
||||
}
|
||||
} else { // No limits, max charging power allowed
|
||||
datalayer.battery.status.max_charge_power_W = MAXCHARGEPOWERALLOWED;
|
||||
datalayer.battery.status.max_charge_power_W = datalayer.battery.status.override_charge_power_W;
|
||||
}
|
||||
|
||||
datalayer.battery.status.temperature_min_dC = battery_min_temp;
|
||||
|
@ -659,8 +469,6 @@ void TeslaBattery::
|
|||
|
||||
datalayer.battery.status.cell_min_voltage_mV = battery_cell_min_v;
|
||||
|
||||
battery_cell_deviation_mV = (battery_cell_max_v - battery_cell_min_v);
|
||||
|
||||
/* Value mapping is completed. Start to check all safeties */
|
||||
|
||||
//INTERNAL_OPEN_FAULT - Someone disconnected a high voltage cable while battery was in use
|
||||
|
@ -675,11 +483,24 @@ void TeslaBattery::
|
|||
} else {
|
||||
clear_event(EVENT_BATTERY_FUSE);
|
||||
}
|
||||
// Raise any Tesla BMS events in BE
|
||||
// Events: Informational
|
||||
if (BMS_a145_SW_SOC_Change) { // BMS has newly recalibrated pack SOC
|
||||
set_event_latched(EVENT_BATTERY_SOC_RECALIBRATION, 0); // Latcched as BMS_a145 can be active for a while
|
||||
} else if (!BMS_a145_SW_SOC_Change) {
|
||||
clear_event(EVENT_BATTERY_SOC_RECALIBRATION);
|
||||
}
|
||||
// Events: Warning
|
||||
if (BMS_contactorState == 5) { // BMS has detected welded contactor(s)
|
||||
set_event_latched(EVENT_CONTACTOR_WELDED, 0);
|
||||
} else if (BMS_contactorState != 5) {
|
||||
clear_event(EVENT_CONTACTOR_WELDED);
|
||||
}
|
||||
|
||||
if (user_selected_tesla_GTW_chassisType > 1) { //{{0, "Model S"}, {1, "Model X"}, {2, "Model 3"}, {3, "Model Y"}};
|
||||
// Autodetect algoritm for chemistry on 3/Y packs.
|
||||
// Autodetect algorithm for chemistry on 3/Y packs.
|
||||
// NCM/A batteries have 96s, LFP has 102-108s
|
||||
// Drawback with this check is that it takes 3-5minutes before all cells have been counted!
|
||||
// Drawback with this check is that it takes 3-5 minutes before all cells have been counted!
|
||||
if (datalayer.battery.info.number_of_cells > 101) {
|
||||
datalayer.battery.info.chemistry = battery_chemistry_enum::LFP;
|
||||
}
|
||||
|
@ -720,23 +541,28 @@ void TeslaBattery::
|
|||
//Start the BMS ECU reset statemachine, only if contactors are OPEN and BMS ECU allows it
|
||||
stateMachineBMSReset = 0;
|
||||
datalayer.battery.settings.user_requests_tesla_bms_reset = false;
|
||||
logging.println("BMS reset requested");
|
||||
logging.println("INFO: BMS reset requested");
|
||||
} else {
|
||||
logging.println("ERROR: BMS reset failed due to contactors not being open, or BMS ECU not allowing it");
|
||||
stateMachineBMSReset = 0xFF;
|
||||
datalayer.battery.settings.user_requests_tesla_bms_reset = false;
|
||||
set_event(EVENT_BMS_RESET_REQ_FAIL, 0);
|
||||
clear_event(EVENT_BMS_RESET_REQ_FAIL);
|
||||
}
|
||||
}
|
||||
if (datalayer.battery.settings.user_requests_tesla_soc_reset) {
|
||||
if (datalayer.battery.status.real_soc < 1500 || datalayer.battery.status.real_soc > 9000) {
|
||||
//Start the SOC reset statemachine, only if SOC < 15% or > 90%
|
||||
if ((datalayer.battery.status.real_soc < 1500 || datalayer.battery.status.real_soc > 9000) &&
|
||||
battery_contactor == 1) {
|
||||
//Start the SOC reset statemachine, only if SOC less than 15% or greater than 90%, and contactors open
|
||||
stateMachineSOCReset = 0;
|
||||
datalayer.battery.settings.user_requests_tesla_soc_reset = false;
|
||||
logging.println("SOC reset requested");
|
||||
logging.println("INFO: SOC reset requested");
|
||||
} else {
|
||||
logging.println("ERROR: SOC reset failed due to SOC not being less than 15 or greater than 90");
|
||||
logging.println("ERROR: SOC reset failed, SOC not < 15 or > 90, or contactors not open");
|
||||
stateMachineSOCReset = 0xFF;
|
||||
datalayer.battery.settings.user_requests_tesla_soc_reset = false;
|
||||
set_event(EVENT_BATTERY_SOC_RESET_FAIL, 0);
|
||||
clear_event(EVENT_BATTERY_SOC_RESET_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -971,86 +797,51 @@ void TeslaBattery::
|
|||
datalayer_extended.tesla.HVP_shuntBarTempStatus = HVP_shuntBarTempStatus;
|
||||
datalayer_extended.tesla.HVP_shuntAsicTempStatus = HVP_shuntAsicTempStatus;
|
||||
|
||||
//Safety checks for CAN message sesnding
|
||||
//Safety checks for CAN message sending
|
||||
if ((datalayer.system.status.inverter_allows_contactor_closing == true) &&
|
||||
(datalayer.battery.status.bms_status != FAULT) && (!datalayer.system.settings.equipment_stop_active)) {
|
||||
// Carry on: 0x221 DRIVE state & reset power down timer
|
||||
vehicleState = 1;
|
||||
powerDownTimer = 180; //0x221 50ms cyclic, 20 calls/second
|
||||
vehicleState = CAR_DRIVE;
|
||||
powerDownSeconds = 9;
|
||||
} else {
|
||||
// Faulted state, or inverter blocks contactor closing
|
||||
// Shut down: 0x221 ACCESSORY state for 3 seconds, followed by GOING_DOWN, then OFF
|
||||
if (powerDownTimer <= 180 && powerDownTimer > 120) {
|
||||
vehicleState = 2; //ACCESSORY
|
||||
powerDownTimer--;
|
||||
if (powerDownSeconds <= 9 && powerDownSeconds > 6) {
|
||||
vehicleState = ACCESSORY;
|
||||
powerDownSeconds--;
|
||||
}
|
||||
if (powerDownTimer <= 120 && powerDownTimer > 60) {
|
||||
vehicleState = 3; //GOING_DOWN
|
||||
powerDownTimer--;
|
||||
if (powerDownSeconds <= 6 && powerDownSeconds > 3) {
|
||||
vehicleState = GOING_DOWN;
|
||||
powerDownSeconds--;
|
||||
}
|
||||
if (powerDownTimer <= 60 && powerDownTimer > 0) {
|
||||
vehicleState = 0; //OFF
|
||||
powerDownTimer--;
|
||||
if (powerDownSeconds <= 3 && powerDownSeconds > 0) {
|
||||
vehicleState = CAR_OFF;
|
||||
powerDownSeconds--;
|
||||
}
|
||||
}
|
||||
|
||||
printFaultCodesIfActive();
|
||||
logging.print("BMS Contactors State: ");
|
||||
logging.print(getBMSContactorState(battery_contactor)); // Display what state the BMS thinks the contactors are in
|
||||
logging.print(", HVIL: ");
|
||||
logging.print(getHvilStatusState(battery_hvil_status));
|
||||
logging.print(", NegativeState: ");
|
||||
logging.print(getContactorState(battery_packContNegativeState));
|
||||
logging.print(", PositiveState: ");
|
||||
logging.printf("Contactor State: ");
|
||||
logging.printf(getBMSContactorState(battery_contactor)); // Display what state the BMS thinks the contactors are in
|
||||
logging.printf(" HVIL: ");
|
||||
logging.printf(getHvilStatusState(battery_hvil_status));
|
||||
logging.printf(" NegState: ");
|
||||
logging.printf(getContactorState(battery_packContNegativeState));
|
||||
logging.printf(" PosState: ");
|
||||
logging.println(getContactorState(battery_packContPositiveState));
|
||||
logging.print("HVP Contactors setState: ");
|
||||
logging.print(
|
||||
logging.printf("Cont. setState: ");
|
||||
logging.printf(
|
||||
getContactorText(battery_packContactorSetState)); // Display what state the HVP has set the contactors to be in
|
||||
logging.print(", Closing blocked: ");
|
||||
logging.print(getNoYes(battery_packCtrsClosingBlocked));
|
||||
logging.printf(" Closing blocked: ");
|
||||
logging.printf(getNoYes(battery_packCtrsClosingBlocked));
|
||||
if (battery_packContactorSetState == 5) {
|
||||
logging.print(" (already CLOSED)");
|
||||
logging.printf(" (already CLOSED)");
|
||||
}
|
||||
logging.print(", Pyrotest: ");
|
||||
logging.printf(", Pyrotest: ");
|
||||
logging.println(getNoYes(battery_pyroTestInProgress));
|
||||
|
||||
logging.print("Battery values: ");
|
||||
logging.print("Real SOC: ");
|
||||
logging.print(battery_soc_ui / 10.0, 1);
|
||||
logging.print(", Battery voltage: ");
|
||||
logging.print(battery_volts / 10.0, 1);
|
||||
logging.print("V");
|
||||
logging.print(", Battery HV current: ");
|
||||
logging.print(battery_amps / 10.0, 1);
|
||||
logging.print("A");
|
||||
logging.print(", Fully charged?: ");
|
||||
if (battery_full_charge_complete)
|
||||
logging.print("YES, ");
|
||||
else
|
||||
logging.print("NO, ");
|
||||
if (datalayer.battery.info.chemistry == battery_chemistry_enum::LFP) {
|
||||
logging.print("LFP chemistry detected!");
|
||||
}
|
||||
logging.println("");
|
||||
logging.print("Cellstats, Max: ");
|
||||
logging.print(battery_cell_max_v);
|
||||
logging.print("mV (cell ");
|
||||
logging.print(battery_BrickVoltageMaxNum);
|
||||
logging.print("), Min: ");
|
||||
logging.print(battery_cell_min_v);
|
||||
logging.print("mV (cell ");
|
||||
logging.print(battery_BrickVoltageMinNum);
|
||||
logging.print("), Imbalance: ");
|
||||
logging.print(battery_cell_deviation_mV);
|
||||
logging.println("mV.");
|
||||
|
||||
logging.printf("High Voltage Output Pins: %.2f V, Low Voltage: %.2f V, DC/DC 12V current: %.2f A.\n",
|
||||
(battery_dcdcHvBusVolt * 0.146484), (battery_dcdcLvBusVolt * 0.0390625),
|
||||
(battery_dcdcLvOutputCurrent * 0.1));
|
||||
|
||||
logging.printf("PCS_ambientTemp: %.2f°C, DCDC_Temp: %.2f°C, ChgPhA: %.2f°C, ChgPhB: %.2f°C, ChgPhC: %.2f°C.\n",
|
||||
PCS_ambientTemp * 0.1 + 40, PCS_dcdcTemp * 0.1 + 40, PCS_chgPhATemp * 0.1 + 40,
|
||||
PCS_chgPhBTemp * 0.1 + 40, PCS_chgPhCTemp * 0.1 + 40);
|
||||
logging.printf("HV: %.2f V, 12V: %.2f V, 12V current: %.2f A.\n", (battery_dcdcHvBusVolt * 0.146484),
|
||||
(battery_dcdcLvBusVolt * 0.0390625), (battery_dcdcLvOutputCurrent * 0.1));
|
||||
}
|
||||
|
||||
void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
|
@ -1894,17 +1685,17 @@ void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
}
|
||||
*/
|
||||
break;
|
||||
case 0x612: // CAN UDSs for BMS
|
||||
case 0x612: // CAN UDS responses for BMS
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
//BMS Query
|
||||
if (stateMachineBMSQuery != 0xFF && stateMachineBMSReset == 0xFF) {
|
||||
if (stateMachineBMSQuery != 0xFF && stateMachineBMSReset == 0xFF && stateMachineSOCReset == 0xFF) {
|
||||
if (memcmp(rx_frame.data.u8, "\x02\x50\x03\xAA\xAA\xAA\xAA\xAA", 8) == 0) {
|
||||
//Received initial response, proceed to actual query
|
||||
logging.println("CAN UDS: Received BMS query initial handshake reply");
|
||||
stateMachineBMSQuery = 1;
|
||||
break;
|
||||
}
|
||||
if (memcmp(&rx_frame.data.u8[0], "\x10", 1) == 0) {
|
||||
if (rx_frame.data.u8[0] == 0x10) {
|
||||
//Received first data frame
|
||||
battery_partNumber[0] = rx_frame.data.u8[5];
|
||||
battery_partNumber[1] = rx_frame.data.u8[6];
|
||||
|
@ -1913,7 +1704,7 @@ void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
stateMachineBMSQuery = 2;
|
||||
break;
|
||||
}
|
||||
if (memcmp(&rx_frame.data.u8[0], "\x21", 1) == 0) {
|
||||
if (rx_frame.data.u8[0] == 0x21) {
|
||||
//Second part of part number after flow control
|
||||
battery_partNumber[3] = rx_frame.data.u8[1];
|
||||
battery_partNumber[4] = rx_frame.data.u8[2];
|
||||
|
@ -1925,7 +1716,7 @@ void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
logging.println("CAN UDS: Received BMS query second data frame");
|
||||
break;
|
||||
}
|
||||
if (memcmp(&rx_frame.data.u8[0], "\x22", 1) == 0) {
|
||||
if (rx_frame.data.u8[0] == 0x22) {
|
||||
//Final part of part number
|
||||
battery_partNumber[10] = rx_frame.data.u8[1];
|
||||
battery_partNumber[11] = rx_frame.data.u8[2];
|
||||
|
@ -1940,15 +1731,28 @@ void TeslaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
//BMS Reset
|
||||
if (stateMachineBMSQuery == 0xFF) { // Make sure this is reset request not query
|
||||
if (memcmp(rx_frame.data.u8, "\x02\x67\x06\xAA\xAA\xAA\xAA\xAA", 8) == 0) {
|
||||
logging.println("CAN UDS: ECU unlocked");
|
||||
} else if (memcmp(rx_frame.data.u8, "\x03\x7F\x11\x78\xAA\xAA\xAA\xAA", 8) == 0) {
|
||||
logging.println("CAN UDS: ECU reset request successful but ECU busy, response pending");
|
||||
} else if (memcmp(rx_frame.data.u8, "\x02\x51\x01\xAA\xAA\xAA\xAA\xAA", 8) == 0) {
|
||||
logging.println("CAN UDS: ECU reset positive response, 1 second downtime");
|
||||
}
|
||||
//BMS ECU responses
|
||||
if (memcmp(rx_frame.data.u8, "\x02\x67\x06\xAA\xAA\xAA\xAA\xAA", 8) == 0) {
|
||||
logging.println("CAN UDS: BMS ECU unlocked");
|
||||
}
|
||||
if (memcmp(rx_frame.data.u8, "\x03\x7F\x11\x78\xAA\xAA\xAA\xAA", 8) == 0) {
|
||||
logging.println("CAN UDS: BMS ECU reset request successful but ECU busy, response pending");
|
||||
}
|
||||
if (memcmp(rx_frame.data.u8, "\x02\x51\x01\xAA\xAA\xAA\xAA\xAA", 8) == 0) {
|
||||
logging.println("CAN UDS: BMS ECU reset positive response, 1 second downtime");
|
||||
set_event(EVENT_BMS_RESET_REQ_SUCCESS, 0);
|
||||
clear_event(EVENT_BMS_RESET_REQ_SUCCESS);
|
||||
}
|
||||
if (memcmp(rx_frame.data.u8, "\x05\x71\x01\x04\x07\x01\xAA\xAA", 8) == 0) {
|
||||
logging.println("CAN UDS: BMS SOC reset accepted, resetting BMS ECU");
|
||||
set_event(EVENT_BATTERY_SOC_RESET_SUCCESS, 0);
|
||||
clear_event(EVENT_BATTERY_SOC_RESET_SUCCESS);
|
||||
stateMachineBMSReset = 6; // BMS ECU already unlocked etc. so we jump straight to reset
|
||||
}
|
||||
if (memcmp(rx_frame.data.u8, "\x05\x71\x01\x04\x07\x00\xAA\xAA", 8) == 0) {
|
||||
logging.println("CAN UDS: BMS SOC reset failed");
|
||||
set_event(EVENT_BATTERY_SOC_RESET_FAIL, 0);
|
||||
clear_event(EVENT_BATTERY_SOC_RESET_FAIL);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -1984,41 +1788,26 @@ CAN_frame can_msg_118[] = {
|
|||
{.FD = false, .ext_ID = false, .DLC = 8, .ID = 0x118, .data = {0x6F, 0x8E, 0x30, 0x10, 0x00, 0x08, 0x00, 0x80}},
|
||||
{.FD = false, .ext_ID = false, .DLC = 8, .ID = 0x118, .data = {0x70, 0x8F, 0x30, 0x10, 0x00, 0x08, 0x00, 0x80}}};
|
||||
|
||||
unsigned long lastSend1CF = 0;
|
||||
unsigned long lastSend118 = 0;
|
||||
|
||||
int index_1CF = 0;
|
||||
int index_118 = 0;
|
||||
|
||||
void TeslaBattery::transmit_can(unsigned long currentMillis) {
|
||||
|
||||
if (user_selected_tesla_digital_HVIL) { //Special S/X? mode for 2024+ batteries
|
||||
if ((datalayer.system.status.inverter_allows_contactor_closing) && (datalayer.battery.status.bms_status != FAULT)) {
|
||||
if (currentMillis - lastSend1CF >= 10) {
|
||||
transmit_can_frame(&can_msg_1CF[index_1CF]);
|
||||
|
||||
index_1CF = (index_1CF + 1) % 8;
|
||||
lastSend1CF = currentMillis;
|
||||
}
|
||||
|
||||
if (currentMillis - lastSend118 >= 10) {
|
||||
transmit_can_frame(&can_msg_118[index_118]);
|
||||
|
||||
index_118 = (index_118 + 1) % 16;
|
||||
lastSend118 = currentMillis;
|
||||
}
|
||||
} else {
|
||||
index_1CF = 0;
|
||||
index_118 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//Send 10ms messages
|
||||
if (currentMillis - previousMillis10 >= INTERVAL_10_MS) {
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
//0x118 DI_systemStatus
|
||||
transmit_can_frame(&TESLA_118);
|
||||
if (user_selected_tesla_digital_HVIL) { //Special Digital HVIL mode for S/X 2024+ batteries
|
||||
if ((datalayer.system.status.inverter_allows_contactor_closing) &&
|
||||
(datalayer.battery.status.bms_status != FAULT)) {
|
||||
transmit_can_frame(&can_msg_1CF[index_1CF]);
|
||||
index_1CF = (index_1CF + 1) % 8;
|
||||
transmit_can_frame(&can_msg_118[index_118]);
|
||||
index_118 = (index_118 + 1) % 16;
|
||||
}
|
||||
} else { //Normal handling of 118 message (Non digital HVIL version)
|
||||
//0x118 DI_systemStatus
|
||||
transmit_can_frame(&TESLA_118);
|
||||
index_1CF = 0; //Stop broadcasting Digital HVIL 1CF and 118 to keep contactors open
|
||||
index_118 = 0;
|
||||
}
|
||||
|
||||
//0x2E1 VCFRONT_status
|
||||
switch (muxNumber_TESLA_2E1) {
|
||||
|
@ -2058,7 +1847,7 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) {
|
|||
previousMillis50 = currentMillis;
|
||||
|
||||
//0x221 VCFRONT_LVPowerState
|
||||
if (vehicleState == 1) { // Drive
|
||||
if (vehicleState == CAR_DRIVE) {
|
||||
switch (muxNumber_TESLA_221) {
|
||||
case 0:
|
||||
generateMuxFrameCounterChecksum(TESLA_221_DRIVE_Mux0, frameCounter_TESLA_221, 52, 4, 56, 8);
|
||||
|
@ -2073,10 +1862,8 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
//Generate next new frame
|
||||
frameCounter_TESLA_221 = (frameCounter_TESLA_221 + 1) % 16;
|
||||
}
|
||||
if (vehicleState == 2) { // Accessory
|
||||
if (vehicleState == ACCESSORY) {
|
||||
switch (muxNumber_TESLA_221) {
|
||||
case 0:
|
||||
generateMuxFrameCounterChecksum(TESLA_221_ACCESSORY_Mux0, frameCounter_TESLA_221, 52, 4, 56, 8);
|
||||
|
@ -2091,10 +1878,8 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
//Generate next new frame
|
||||
frameCounter_TESLA_221 = (frameCounter_TESLA_221 + 1) % 16;
|
||||
}
|
||||
if (vehicleState == 3) { // Going down
|
||||
if (vehicleState == GOING_DOWN) {
|
||||
switch (muxNumber_TESLA_221) {
|
||||
case 0:
|
||||
generateMuxFrameCounterChecksum(TESLA_221_GOING_DOWN_Mux0, frameCounter_TESLA_221, 52, 4, 56, 8);
|
||||
|
@ -2109,10 +1894,8 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
//Generate next new frame
|
||||
frameCounter_TESLA_221 = (frameCounter_TESLA_221 + 1) % 16;
|
||||
}
|
||||
if (vehicleState == 0) { // Off
|
||||
if (vehicleState == CAR_OFF) {
|
||||
switch (muxNumber_TESLA_221) {
|
||||
case 0:
|
||||
generateMuxFrameCounterChecksum(TESLA_221_OFF_Mux0, frameCounter_TESLA_221, 52, 4, 56, 8);
|
||||
|
@ -2127,23 +1910,13 @@ void TeslaBattery::transmit_can(unsigned long currentMillis) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
//Generate next new frame
|
||||
frameCounter_TESLA_221 = (frameCounter_TESLA_221 + 1) % 16;
|
||||
}
|
||||
//Generate next new frame
|
||||
frameCounter_TESLA_221 = (frameCounter_TESLA_221 + 1) % 16;
|
||||
|
||||
//0x3C2 VCLEFT_switchStatus
|
||||
switch (muxNumber_TESLA_3C2) {
|
||||
case 0:
|
||||
transmit_can_frame(&TESLA_3C2_Mux0);
|
||||
muxNumber_TESLA_3C2++;
|
||||
break;
|
||||
case 1:
|
||||
transmit_can_frame(&TESLA_3C2_Mux1);
|
||||
muxNumber_TESLA_3C2 = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
transmit_can_frame(muxNumber_TESLA_3C2 == 0 ? &TESLA_3C2_Mux0 : &TESLA_3C2_Mux1);
|
||||
muxNumber_TESLA_3C2 = !muxNumber_TESLA_3C2; // Flip between sending Mux0 and Mux1 on each pass
|
||||
|
||||
//0x39D IBST_status
|
||||
transmit_can_frame(&TESLA_39D);
|
||||
|
@ -2566,7 +2339,7 @@ void TeslaBattery::printFaultCodesIfActive() {
|
|||
printDebugIfActive(BMS_a139_SW_DC_Link_V_Irrational, "ERROR: BMS_a139_SW_DC_Link_V_Irrational");
|
||||
printDebugIfActive(BMS_a141_SW_BMB_Status_Warning, "ERROR: BMS_a141_SW_BMB_Status_Warning");
|
||||
printDebugIfActive(BMS_a144_Hvp_Config_Mismatch, "ERROR: BMS_a144_Hvp_Config_Mismatch");
|
||||
printDebugIfActive(BMS_a145_SW_SOC_Change, "ERROR: BMS_a145_SW_SOC_Change");
|
||||
printDebugIfActive(BMS_a145_SW_SOC_Change, "INFO: BMS_a145_SW_SOC_Change");
|
||||
printDebugIfActive(BMS_a146_SW_Brick_Overdischarged, "ERROR: BMS_a146_SW_Brick_Overdischarged");
|
||||
printDebugIfActive(BMS_a149_SW_Missing_Config_Block, "ERROR: BMS_a149_SW_Missing_Config_Block");
|
||||
printDebugIfActive(BMS_a151_SW_external_isolation, "ERROR: BMS_a151_SW_external_isolation");
|
||||
|
@ -2600,7 +2373,7 @@ void TeslaModel3YBattery::setup(void) { // Performs one time setup at startup
|
|||
//0x7FF GTW CAN frame values
|
||||
//Mux1
|
||||
write_signal_value(&TESLA_7FF_Mux1, 16, 16, user_selected_tesla_GTW_country, false);
|
||||
write_signal_value(&TESLA_7FF_Mux1, 11, 1, user_selected_tesla_GTW_country, false);
|
||||
write_signal_value(&TESLA_7FF_Mux1, 11, 1, user_selected_tesla_GTW_rightHandDrive, false);
|
||||
//Mux3
|
||||
write_signal_value(&TESLA_7FF_Mux3, 8, 4, user_selected_tesla_GTW_mapRegion, false);
|
||||
write_signal_value(&TESLA_7FF_Mux3, 18, 3, user_selected_tesla_GTW_chassisType, false);
|
||||
|
|
|
@ -4,13 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "TESLA-HTML.h"
|
||||
|
||||
#ifdef TESLA_MODEL_3Y_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS TeslaModel3YBattery
|
||||
#endif
|
||||
#ifdef TESLA_MODEL_SX_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS TeslaModelSXBattery
|
||||
#endif
|
||||
|
||||
// 0x7FF gateway config, "Gen3" vehicles only, not applicable to Gen2 "classic" Model S and Model X
|
||||
// These are user configurable from the Webserver UI
|
||||
extern bool user_selected_tesla_digital_HVIL;
|
||||
|
@ -46,15 +39,6 @@ class TeslaBattery : public CanBattery {
|
|||
TeslaHtmlRenderer renderer;
|
||||
|
||||
protected:
|
||||
/* Modify these if needed */
|
||||
static const int MAXCHARGEPOWERALLOWED =
|
||||
15000; // 15000W we use a define since the value supplied by Tesla is always 0
|
||||
static const int MAXDISCHARGEPOWERALLOWED =
|
||||
60000; // 60000W we use a define since the value supplied by Tesla is always 0
|
||||
|
||||
// Set this to true to try to close contactors/full startup even with no inverter defined/connected
|
||||
bool batteryTestOverride = false;
|
||||
|
||||
/* Do not change anything below this line! */
|
||||
static const int RAMPDOWN_SOC = 900; // 90.0 SOC% to start ramping down from max charge power towards 0 at 100.00%
|
||||
static const int RAMPDOWNPOWERALLOWED = 10000; // What power we ramp down from towards top balancing
|
||||
|
@ -94,7 +78,11 @@ class TeslaBattery : public CanBattery {
|
|||
uint8_t muxNumber_TESLA_221 = 0;
|
||||
uint8_t frameCounter_TESLA_221 = 15; // Start at 15 for Mux 0
|
||||
uint8_t vehicleState = 1; // "OFF": 0, "DRIVE": 1, "ACCESSORY": 2, "GOING_DOWN": 3
|
||||
uint16_t powerDownTimer = 180; // Car power down (i.e. contactor open) tracking timer, 3 seconds per sendingState
|
||||
static const uint8_t CAR_OFF = 0;
|
||||
static const uint8_t CAR_DRIVE = 1;
|
||||
static const uint8_t ACCESSORY = 2;
|
||||
static const uint8_t GOING_DOWN = 3;
|
||||
uint8_t powerDownSeconds = 9; // Car power down (i.e. contactor open) tracking timer, 3 seconds per sendingState
|
||||
//0x2E1 VCFRONT_status, 6 mux tracker
|
||||
uint8_t muxNumber_TESLA_2E1 = 0;
|
||||
//0x334 UI
|
||||
|
@ -473,15 +461,14 @@ class TeslaBattery : public CanBattery {
|
|||
.DLC = 8,
|
||||
.ID = 0x610,
|
||||
.data = {0x02, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}}; // Define initial UDS request
|
||||
|
||||
uint8_t index_1CF = 0;
|
||||
uint8_t index_118 = 0;
|
||||
uint8_t stateMachineClearIsolationFault = 0xFF;
|
||||
uint8_t stateMachineBMSReset = 0xFF;
|
||||
uint8_t stateMachineSOCReset = 0xFF;
|
||||
uint8_t stateMachineBMSQuery = 0xFF;
|
||||
uint16_t sendContactorClosingMessagesStill = 300;
|
||||
uint16_t battery_cell_max_v = 3300;
|
||||
uint16_t battery_cell_min_v = 3300;
|
||||
uint16_t battery_cell_deviation_mV = 0; //contains the deviation between highest and lowest cell in mV
|
||||
bool cellvoltagesRead = false;
|
||||
//0x3d2: 978 BMS_kwhCounter
|
||||
uint32_t battery_total_discharge = 0;
|
||||
|
|
|
@ -3,12 +3,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "../devboard/utils/logging.h"
|
||||
|
||||
static void print_units(const char* header, int value, const char* units) {
|
||||
logging.print(header);
|
||||
logging.print(value);
|
||||
logging.print(units);
|
||||
}
|
||||
|
||||
void TestFakeBattery::
|
||||
update_values() { /* This function puts fake values onto the parameters sent towards the inverter */
|
||||
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "CanBattery.h"
|
||||
|
||||
#ifdef TEST_FAKE_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS TestFakeBattery
|
||||
#endif
|
||||
|
||||
class TestFakeBattery : public CanBattery {
|
||||
public:
|
||||
// Use this constructor for the second battery.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "VOLVO-SPA-BATTERY.h"
|
||||
#include <cstring> //For unit test
|
||||
#include "../communication/can/comm_can.h"
|
||||
#include "../datalayer/datalayer.h"
|
||||
#include "../datalayer/datalayer_extended.h" //For "More battery info" webpage
|
||||
|
@ -85,12 +86,20 @@ void VolvoSpaBattery::
|
|||
datalayer.battery.info.total_capacity_Wh = 69511;
|
||||
}
|
||||
}
|
||||
|
||||
//Check safeties
|
||||
if (datalayer_extended.VolvoPolestar.BECMsupplyVoltage < 10700) { //10.7V,
|
||||
//If 12V voltage goes under this, latch battery OFF to prevent contactors from swinging between on/off
|
||||
set_event(EVENT_12V_LOW, (datalayer_extended.VolvoPolestar.BECMsupplyVoltage / 100));
|
||||
set_event(EVENT_BATTERY_CHG_DISCHG_STOP_REQ, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void VolvoSpaBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (rx_frame.ID) {
|
||||
case 0x3A:
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
|
||||
if ((rx_frame.data.u8[6] & 0x80) == 0x80)
|
||||
BATT_I = (0 - ((((rx_frame.data.u8[6] & 0x7F) * 256.0 + rx_frame.data.u8[7]) * 0.1) - 1638));
|
||||
else {
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include "CanBattery.h"
|
||||
#include "VOLVO-SPA-HTML.h"
|
||||
|
||||
#ifdef VOLVO_SPA_BATTERY
|
||||
#define SELECTED_BATTERY_CLASS VolvoSpaBattery
|
||||
#endif
|
||||
|
||||
class VolvoSpaBattery : public CanBattery {
|
||||
public:
|
||||
virtual void setup(void);
|
||||
|
|
|
@ -12,7 +12,7 @@ class VolvoSpaHtmlRenderer : public BatteryHtmlRenderer {
|
|||
content += "</h4><h4>BECM reported number of DTCs: " + String(datalayer_extended.VolvoPolestar.DTCcount) + "</h4>";
|
||||
content += "<h4>BECM reported SOC: " + String(datalayer_extended.VolvoPolestar.soc_bms / 10.0) + " %</h4>";
|
||||
content += "<h4>Calculated SOC: " + String(datalayer_extended.VolvoPolestar.soc_calc / 10.0) + " %</h4>";
|
||||
content += "<h4>Rescaled SOC: " + String(datalayer_extended.VolvoPolestar.soc_rescaled / 10.0) + " %</h4>";
|
||||
content += "<h4>Rescaled SOC: " + String(datalayer_extended.VolvoPolestar.soc_rescaled / 100.0) + " %</h4>";
|
||||
content += "<h4>BECM reported SOH: " + String(datalayer_extended.VolvoPolestar.soh_bms / 100.0) + " %</h4>";
|
||||
content += "<h4>BECM supply voltage: " + String(datalayer_extended.VolvoPolestar.BECMsupplyVoltage) + " mV</h4>";
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue