功能:完善里程边界与氢耗流式统计
This commit is contained in:
@@ -15,14 +15,40 @@ const (
|
||||
yutongFuelCellDrivingMode = 11
|
||||
)
|
||||
|
||||
// PureHydrogenModeFromEnvelope returns whether the reported vehicle is in a
|
||||
// fuel-cell-only work mode and whether the source value is understood.
|
||||
// PureHydrogenModeFromEnvelope returns whether hydrogen power participates in
|
||||
// vehicle propulsion and whether the source value is understood.
|
||||
//
|
||||
// The 32960 fuel-cell extension reports engine_work_state; production frames
|
||||
// use mode 2 for normal fuel-cell operation. Yutong reports the equivalent
|
||||
// state through TRIANGLE_STATE; production frames use 1 for inactive and 4/11
|
||||
// for active fuel-cell operating modes.
|
||||
// GB32960's standard vehicle running mode is authoritative when present:
|
||||
// mode 1 is pure electric, mode 2 is hybrid, and mode 3 is fuel powered. Mode
|
||||
// 2 is counted as hydrogen-participating mileage for the hydrogen fleet; mode
|
||||
// 1 is excluded. Fuel, abnormal, and invalid values are left unclassified.
|
||||
// Older frames without the standard field fall back to the fuel-cell extension
|
||||
// engine_work_state. Yutong reports the equivalent state through
|
||||
// TRIANGLE_STATE; production frames use 1 for inactive and 4/11 for active.
|
||||
func PureHydrogenModeFromEnvelope(env envelope.FrameEnvelope) (active bool, known bool) {
|
||||
if env.Protocol == envelope.ProtocolGB32960 {
|
||||
if value, exists := env.Fields[envelope.FieldVehicleRunningMode]; exists {
|
||||
mode, ok := integerMode(value)
|
||||
if !ok {
|
||||
return false, false
|
||||
}
|
||||
switch mode {
|
||||
case 1:
|
||||
return false, true
|
||||
case 2:
|
||||
return true, true
|
||||
default:
|
||||
return false, false
|
||||
}
|
||||
}
|
||||
}
|
||||
return FuelCellActiveModeFromEnvelope(env)
|
||||
}
|
||||
|
||||
// FuelCellActiveModeFromEnvelope reads the fuel-cell subsystem work state.
|
||||
// Hydrogen consumption segmentation uses this signal (and its current-based
|
||||
// fallback) independently from the whole-vehicle running mode used by mileage.
|
||||
func FuelCellActiveModeFromEnvelope(env envelope.FrameEnvelope) (active bool, known bool) {
|
||||
value, exists := env.Fields[envelope.FieldFuelCellWorkMode]
|
||||
if !exists {
|
||||
return false, false
|
||||
@@ -56,8 +82,9 @@ func PureHydrogenModeFromEnvelope(env envelope.FrameEnvelope) (active bool, know
|
||||
}
|
||||
|
||||
// PureHydrogenMileageDelta returns the odometer delta that can be attributed
|
||||
// to pure-hydrogen operation. Both endpoints must report a known active mode;
|
||||
// this deliberately leaves transitions and missing mode data unclassified.
|
||||
// to hydrogen-participating operation. The current endpoint owns the interval,
|
||||
// matching the daily rule: total mileage minus intervals ending in pure-electric
|
||||
// mode. Missing or invalid current modes remain unclassified.
|
||||
func PureHydrogenMileageDelta(
|
||||
previousKM float64,
|
||||
currentKM float64,
|
||||
@@ -67,7 +94,7 @@ func PureHydrogenMileageDelta(
|
||||
currentKnown bool,
|
||||
) float64 {
|
||||
delta := currentKM - previousKM
|
||||
if !previousKnown || !previousActive || !currentKnown || !currentActive {
|
||||
if !currentKnown || !currentActive {
|
||||
return 0
|
||||
}
|
||||
if delta < 0 || delta > maxSelectedDailyMileageKM {
|
||||
|
||||
Reference in New Issue
Block a user