Files
stm32-openinverter-teslacha…/src/chargercan.cpp
T
Bastian de Byl b7fcd2b301
Build Firmware / Build stm32-teslacharger (pull_request) Successful in 59s
feat: broadcast worst-case OBC temperature on 0x211 byte 7
The Tesla OBC hardware already publishes 9 temperature probes (3
modules × {tmp1, tmp2, tmpin}) on CAN 0x237/0x239/0x23B which the
teslacharger receives as c[123]tmp[12,in]. Until now none of these
were forwarded downstream — the Polarity VCU's STATUS_SCREEN OBC-temp
and DCDC-temp fields rendered 0 °C on OI-OBC cars.

This commit:

- Adds Param::tmpobcmax — derived value computed each Ms100Task tick
  as the max across the 9 probes, skipping any that read -40 °C
  (sensor absent / module not present).
- Maps it to 0x211 byte 7 (previously reserved, the last unused byte
  of the 7-byte frame). Wire encoding uses the Tesla OBC convention
  of offset 40 (wire = °C + 40), matching c[123]tmp* upstream so
  receivers can decode with the same formula.
- Bumps VERSTR to -S5 so the right firmware is visually confirmable
  in the OpenInverter web UI.

The new byte is purely additive — existing 0x211 consumers that read
only bytes 0-6 continue to work unchanged.

The Polarity VCU's 0x211 RX handler grows a corresponding decode +
display path in a paired stm32-hal-vcu commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 15:48:40 -04:00

127 lines
6.6 KiB
C++

/*
* This file is part of the stm32-... project.
*
* Copyright (C) 2021 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "chargercan.h"
void ChargerCAN::MapMessages(CanMap* can)
{
can->AddRecv(Param::hwaclim, 0x207, 32, 9, 0.06666f); //gain 0.06666
can->AddRecv(Param::hwaclim, 0x209, 32, 9, 0.06666f); //gain 0.06666
can->AddRecv(Param::hwaclim, 0x20B, 32, 9, 0.06666f); //gain 0.06666
can->AddRecv(Param::c1iac, 0x207, 41, 9, 0.06666f); //gain 0.06666
can->AddRecv(Param::c2iac, 0x209, 41, 9, 0.06666f); //gain 0.06666
can->AddRecv(Param::c3iac, 0x20B, 41, 9, 0.06666f); //gain 0.06666
can->AddRecv(Param::c1uac, 0x207, 8, 8, 1);
can->AddRecv(Param::c2uac, 0x209, 8, 8, 1);
can->AddRecv(Param::c3uac, 0x20B, 8, 8, 1);
can->AddRecv(Param::c1flag, 0x207, 17, 2, 1);
can->AddRecv(Param::c2flag, 0x209, 17, 2, 1);
can->AddRecv(Param::c3flag, 0x20B, 17, 2, 1);
can->AddRecv(Param::c1stt, 0x217, 0, 8, 1);
can->AddRecv(Param::c2stt, 0x219, 0, 8, 1);
can->AddRecv(Param::c3stt, 0x21B, 0, 8, 1);
can->AddRecv(Param::c1idc, 0x227, 32, 16, 0.000839233f); //gain 0.000839233
can->AddRecv(Param::c2idc, 0x229, 32, 16, 0.000839233f); //gain 0.000839233
can->AddRecv(Param::c3idc, 0x22B, 32, 16, 0.000839233f); //gain 0.000839233
can->AddRecv(Param::c1udc, 0x227, 16, 16, 0.01052856f); //gain 0.01052856
can->AddRecv(Param::c2udc, 0x229, 16, 16, 0.01052856f); //gain 0.01052856
can->AddRecv(Param::c3udc, 0x22B, 16, 16, 0.01052856f); //gain 0.01052856
can->AddRecv(Param::c1tmp1, 0x237, 0, 8, 1, -40); //offset -40°C
can->AddRecv(Param::c2tmp1, 0x239, 0, 8, 1, -40); //offset -40°C
can->AddRecv(Param::c3tmp1, 0x23B, 0, 8, 1, -40); //offset -40°C
can->AddRecv(Param::c1tmp2, 0x237, 8, 8, 1, -40); //offset -40°C
can->AddRecv(Param::c2tmp2, 0x239, 8, 8, 1, -40); //offset -40°C
can->AddRecv(Param::c3tmp2, 0x23B, 8, 8, 1, -40); //offset -40°C
can->AddRecv(Param::c1tmpin, 0x237, 40, 8, 1, -40); //offset -40°C
can->AddRecv(Param::c2tmpin, 0x239, 40, 8, 1, -40); //offset -40°C
can->AddRecv(Param::c3tmpin, 0x23B, 40, 8, 1, -40); //offset -40°C
//We don't have enough space for all messages, so we discard these
//can->AddRecv(Param::c1tmplim, 0x247, 0, 8, 7); //gain 0.234375
//can->AddRecv(Param::c2tmplim, 0x249, 0, 8, 7); //gain 0.234375
//can->AddRecv(Param::c3tmplim, 0x24B, 0, 8, 7); //gain 0.234375
/***** CHAdeMO RX *****/
can->AddRecv(Param::canenable, 0x102, 40, 1, 1);
can->AddRecv(Param::idcspnt, 0x102, 24, 8, 1);
can->AddRecv(Param::udclim, 0x102, 8, 16, 1);
can->AddRecv(Param::soc, 0x102, 48, 8, 1);
/***** Charger TX ******/
can->AddSend(Param::udcspnt, 0x45c, 0, 16, 100); //gain 100
//Send 0xe14 when opmode is 0 and 0x2e14 when opmode=1
can->AddSend(Param::opmode, 0x45c, 24, 8, 32, 0xe); //opmode is 1 when running
//constant value 0x14, version just used as dummy, multiplied by 0
can->AddSend(Param::version, 0x45c, 16, 8, 0, 0x14);
//same as above
can->AddSend(Param::version, 0x45c, 48, 8, 0, (int8_t)0x90);
can->AddSend(Param::version, 0x45c, 56, 8, 0, (int8_t)0x8c);
can->AddSend(Param::version, 0x42c, 0, 8, 0, 0x42);
can->AddSend(Param::version, 0x42c, 8, 8, 0, (int8_t)0xBB); //TODO: AC voltage
can->AddSend(Param::aclim, 0x42c, 16, 16, 1500);
can->AddSend(Param::opmode, 0x42c, 32, 8, 154, 100);
can->AddSend(Param::version, 0x43c, 0, 8, 0, 0x42);
can->AddSend(Param::version, 0x43c, 8, 8, 0, (int8_t)0xBB); //TODO: AC voltage
can->AddSend(Param::aclim, 0x43c, 16, 16, 1500);
can->AddSend(Param::opmode, 0x43c, 32, 8, 154, 100);
can->AddSend(Param::version, 0x44c, 0, 8, 0, 0x42);
can->AddSend(Param::version, 0x44c, 8, 8, 0, (int8_t)0xBB); //TODO: AC voltage
can->AddSend(Param::aclim, 0x44c, 16, 16, 1500);
can->AddSend(Param::opmode, 0x44c, 32, 8, 154, 100);
can->AddSend(Param::version, 0x368, 0, 8, 0, 0x03);
can->AddSend(Param::version, 0x368, 8, 8, 0, 0x49);
can->AddSend(Param::version, 0x368, 16, 8, 0, 0x29);
can->AddSend(Param::version, 0x368, 24, 8, 0, 0x11);
can->AddSend(Param::version, 0x368, 40, 8, 0, 0x0c);
can->AddSend(Param::version, 0x368, 48, 8, 0, 0x40);
can->AddSend(Param::version, 0x368, 56, 8, 0, (int8_t)0xff);
/***** CHAdeMO TX *****/
can->AddSend(Param::version, 0x108, 8, 16, 107); //output 428V max = 4*107
can->AddSend(Param::idclim, 0x108, 24, 8, 1);
can->AddSend(Param::udc, 0x109, 8, 16, 1);
can->AddSend(Param::idc, 0x109, 24, 16, 1);
can->AddSend(Param::opmode, 0x109, 40, 3, 5); //Set charging and connlock at once
/***** SKUDAK VCU command RX (0x212) — SKUDAK-516 user ChargeLimit *****/
// Byte 0: ChargeLimit_pct (0-100). Bytes 1-7 reserved 0x00.
// Param::Change(vcuchglim) translates % to udcspnt setpoint (see src/main.cpp).
// VCU broadcasts every 200 ms once teslacharger detected; charger holds last
// value if VCU goes silent.
can->AddRecv(Param::vcuchglim, 0x212, 0, 8, 1);
/***** SKUDAK VCU telemetry (0x211) — SKUDAK-448 expanded charger telemetry *****/
// Byte 0: state (0=Off, 1=WaitStart, 2=Enable, 3=Activate, 4=Run, 5=Stop)
// Bytes 1-2: udc (V, gain=1)
// Bytes 3-4: idc (0.1A, gain=10)
// Byte 5: uaux (decivolts, gain=10) — 12V aux battery rail
// Byte 6: soc (%, gain=1)
// Byte 7: tmpobcmax (°C, gain=1, offset=-40) — worst-case across all
// 9 OBC probes; matches Tesla OBC's own CAN offset
// so receivers can decode with the same formula.
// Consumed by stm32-hal-vcu Core/Src/main.c CHARGER_CAN_ID_OI_OBC_AUX handler.
can->AddSend(Param::state, 0x211, 0, 8, 1);
can->AddSend(Param::udc, 0x211, 8, 16, 1);
can->AddSend(Param::idc, 0x211, 24, 16, 10);
can->AddSend(Param::uaux, 0x211, 40, 8, 10);
can->AddSend(Param::soc, 0x211, 48, 8, 1);
can->AddSend(Param::tmpobcmax, 0x211, 56, 8, 1, 40); // offset 40 → wire byte = temp + 40
}