Add solar charge controller integration and firmware
App: - New DeviceRole.solar with its own BLE session/protocol/state (SolarSession, VanAlignSolarProtocol, SolarState), mirroring the leveling sensor but deliberately not wired into the Live Activity. - BluetoothManager now keeps an in-memory history per metric (voltage, current, power) instead of a single primary-metric series; cleared on app restart by design, not persisted to disk. - DeviceDetailView shows a channel picker above the history chart when a device has more than one chartable metric. - AddDeviceView recognizes the solar service UUID during setup. - DemoData gets a simulated solar device so the integration can be checked in the simulator without hardware. Firmware: - Add esp32_ble_solar.yaml (Votronic solar charge controller over BLE) and simulated variants (esp32_ble_sim.yaml, esp32_ble_solar_sim.yaml) for testing without a vehicle. - esp32_ble.yaml: set flash_size/psram for the ESP32-S3 N16R8 module. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
9a3b5cb472
commit
6d7b32d622
@@ -0,0 +1,55 @@
|
||||
import Foundation
|
||||
|
||||
/// Solarladeregler „VanAlign Solar" – zweiter ESP32 im Fahrzeug, liest einen
|
||||
/// Votronic-Solarladeregler aus und stellt die Werte über einen eigenen
|
||||
/// BLE-Dienst bereit. Siehe `firmware/vanalign/esp32_ble_solar.yaml`.
|
||||
///
|
||||
/// Wie beim Neigungsmesser: kein Rahmenprotokoll, jede Messgrösse liegt in
|
||||
/// einer eigenen Charakteristik, alle sind reine Lesewerte, der Client fragt
|
||||
/// sie im Takt ab.
|
||||
enum VanAlignSolarProtocol {
|
||||
|
||||
/// Wird vom Gerät beworben, das Gerät ist darüber auffindbar.
|
||||
static let serviceUUID = "05C9A349-2B8E-4B1D-9C9D-C247E9A6A001"
|
||||
|
||||
static let batteryVoltageUUID = "05C9A349-2B8E-4B1D-9C9D-C247E9A6A101"
|
||||
static let pvVoltageUUID = "05C9A349-2B8E-4B1D-9C9D-C247E9A6A102"
|
||||
static let pvCurrentUUID = "05C9A349-2B8E-4B1D-9C9D-C247E9A6A103"
|
||||
static let pvPowerUUID = "05C9A349-2B8E-4B1D-9C9D-C247E9A6A104"
|
||||
static let controllerTempUUID = "05C9A349-2B8E-4B1D-9C9D-C247E9A6A105"
|
||||
/// Bit0 Batterie lädt, Bit1 Batterie entlädt, Bit2 PV-Regler aktiv,
|
||||
/// Bit3 PV-Strombegrenzung, Bit4 AES aktiv.
|
||||
static let statusFlagsUUID = "05C9A349-2B8E-4B1D-9C9D-C247E9A6A106"
|
||||
|
||||
/// Liest einen Messwert aus vier Bytes, little-endian – wie beim
|
||||
/// Neigungsmesser legt die Firmware den Float per `memcpy` ab.
|
||||
static func float(from data: Data) -> Double? {
|
||||
guard data.count >= 4 else { return nil }
|
||||
var raw: UInt32 = 0
|
||||
for (index, byte) in data.prefix(4).enumerated() {
|
||||
raw |= UInt32(byte) << UInt32(8 * index)
|
||||
}
|
||||
let value = Float(bitPattern: raw)
|
||||
guard value.isFinite else { return nil }
|
||||
return Double(value)
|
||||
}
|
||||
|
||||
struct StatusFlags {
|
||||
var isBatteryCharging = false
|
||||
var isBatteryDischarging = false
|
||||
var isControllerActive = false
|
||||
var isCurrentLimited = false
|
||||
var isAESActive = false
|
||||
}
|
||||
|
||||
static func statusFlags(from data: Data) -> StatusFlags? {
|
||||
guard let byte = data.first else { return nil }
|
||||
var flags = StatusFlags()
|
||||
flags.isBatteryCharging = byte & (1 << 0) != 0
|
||||
flags.isBatteryDischarging = byte & (1 << 1) != 0
|
||||
flags.isControllerActive = byte & (1 << 2) != 0
|
||||
flags.isCurrentLimited = byte & (1 << 3) != 0
|
||||
flags.isAESActive = byte & (1 << 4) != 0
|
||||
return flags
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user