com.geotab.util.DeviceDefaultsUtil Maven / Gradle / Ivy
package com.geotab.util;
import com.geotab.model.entity.device.CustomVehicleDevice;
import com.geotab.model.entity.device.DigitalAuxiliariesAware;
import com.geotab.model.entity.device.EngineHoursAdjustmentProviderAware;
import com.geotab.model.entity.device.GoCurve;
import com.geotab.model.entity.device.GoDevice;
import com.geotab.model.entity.device.GoLegacy;
import com.geotab.model.entity.device.LicensableAware;
import com.geotab.model.entity.device.OdometerAdjustmentProviderAware;
import com.geotab.model.entity.device.RfChannelsAware;
import com.geotab.model.entity.device.VehicleIdentificationNumberAware;
import com.geotab.model.entity.enginetype.EngineTypeGeneric;
import com.geotab.model.enumeration.GoTalkLanguage;
import java.util.ArrayList;
import java.util.Optional;
import lombok.experimental.UtilityClass;
/**
* A helper class where all device defaults are contained. This allows us to reuse some of the
* defaults for non-related device objects. For example, {@link GoLegacy} and Go4v3 both have
* auxiliaries but are not in the same lineage.
*/
@UtilityClass
public class DeviceDefaultsUtil {
/**
* Add the defaults to VIN.
*
* @param vehicleIdentificationNumberAware GoDevice.
*/
public static void addVehicleIdentificationNumberDefaults(
VehicleIdentificationNumberAware vehicleIdentificationNumberAware) {
if (vehicleIdentificationNumberAware == null) {
return;
}
vehicleIdentificationNumberAware.setVehicleIdentificationNumber(
Optional.ofNullable(vehicleIdentificationNumberAware.getVehicleIdentificationNumber())
.orElse(""));
vehicleIdentificationNumberAware.setEngineVehicleIdentificationNumber(
Optional.ofNullable(vehicleIdentificationNumberAware.getEngineVehicleIdentificationNumber())
.orElse("?"));
}
/**
* Applies the defaults for the GoDevice device. We do not currently have an interface for the
* things the GoDevice adds - but we need to centralize the settings so it's here as GoDevice for
* now.
*
* @param goDevice GoDevice.
*/
public static void addGoDeviceDefaults(GoDevice goDevice) {
if (goDevice == null) {
return;
}
goDevice.setEngineType(
Optional.ofNullable(goDevice.getEngineType()).orElse(EngineTypeGeneric.getInstance()));
goDevice.setMinor(Optional.ofNullable(goDevice.getMinor()).orElse(Short.valueOf("0")));
goDevice.setMajor(Optional.ofNullable(goDevice.getMajor()).orElse(Short.valueOf("0")));
goDevice.setAutoGroups(Optional.ofNullable(goDevice.getAutoGroups()).orElse(new ArrayList<>()));
goDevice.setMinAccidentSpeed(Optional.ofNullable(goDevice.getMinAccidentSpeed()).orElse(4d));
goDevice.setSpeedingOn(Optional.ofNullable(goDevice.getSpeedingOn()).orElse(100d));
goDevice.setSpeedingOff(Optional.ofNullable(goDevice.getSpeedingOff()).orElse(90d));
goDevice.setGpsOffDelay(Optional.ofNullable(goDevice.getGpsOffDelay()).orElse(0));
goDevice.setParameterVersion(
Optional.ofNullable(goDevice.getParameterVersion()).orElse(Short.valueOf("0")));
goDevice.setParameterVersionOnDevice(
Optional.ofNullable(goDevice.getParameterVersionOnDevice()).orElse(Short.valueOf("0")));
goDevice.setIdleMinutes(Optional.ofNullable(goDevice.getIdleMinutes()).orElse(3));
goDevice.setGoTalkLanguage(Optional.ofNullable(goDevice.getGoTalkLanguage()).orElse(
GoTalkLanguage.ENGLISH));
goDevice.setFuelTankCapacity(Optional.ofNullable(goDevice.getFuelTankCapacity()).orElse(0d));
goDevice.setCustomParameters(
Optional.ofNullable(goDevice.getCustomParameters()).orElse(new ArrayList<>()));
addLicensableDefaults(goDevice);
}
/**
* Adds the license defaults.
*
* @param licensableAware LicensableAware.
*/
public static void addLicensableDefaults(LicensableAware licensableAware) {
if (licensableAware == null) {
return;
}
licensableAware
.setLicensePlate(Optional.ofNullable(licensableAware.getLicensePlate()).orElse(""));
licensableAware
.setLicenseState(Optional.ofNullable(licensableAware.getLicenseState()).orElse(""));
}
/**
* Adds the go legacy defaults.
*
* @param goLegacy GoLegacy.
*/
public static void addGoLegacyDefaults(GoLegacy goLegacy) {
if (goLegacy == null) {
return;
}
goLegacy.setDeltaSpeed(Optional.ofNullable(goLegacy.getDeltaSpeed()).orElse(9d));
goLegacy.setDeltaMinSpeed(Optional.ofNullable(goLegacy.getDeltaMinSpeed()).orElse(50d));
goLegacy.setDeltaHeading(Optional.ofNullable(goLegacy.getDeltaHeading()).orElse(48));
goLegacy.setDeltaHeadingMinSpeed(
Optional.ofNullable(goLegacy.getDeltaHeadingMinSpeed()).orElse(20d));
goLegacy.setDeltaHeadingHS(Optional.ofNullable(goLegacy.getDeltaHeadingHS()).orElse(14));
goLegacy.setDeltaHeadingMinSpeedHS(
Optional.ofNullable(goLegacy.getDeltaHeadingMinSpeedHS()).orElse(72d));
goLegacy.setDeltaDistance(Optional.ofNullable(goLegacy.getDeltaDistance()).orElse(1000));
goLegacy.setHarshBreak(Optional.ofNullable(goLegacy.getHarshBreak()).orElse(17d));
}
/**
* Adds the RF channel defaults.
*
* @param rfChannels GoLegacy.
*/
public static void addRfChannelDefaults(RfChannelsAware rfChannels) {
if (rfChannels == null) {
return;
}
rfChannels
.setChannelCount(
Optional.ofNullable(rfChannels.getChannelCount()).orElse(Byte.valueOf("1")));
rfChannels.setChannel(GoDevice.checkAndPadChannelArray(rfChannels.getChannel()));
rfChannels.setFrequencyOffset(
Optional.ofNullable(rfChannels.getFrequencyOffset()).orElse(Byte.valueOf("1")));
rfChannels.setRfParameterVersion((short) 0);
}
/**
* Adds the auxiliary defaults.
*
* @param digitalAuxiliaries GoLegacy.
*/
public static void addAuxiliaryDefaults(DigitalAuxiliariesAware digitalAuxiliaries) {
if (digitalAuxiliaries == null) {
return;
}
digitalAuxiliaries.setEnableAuxWarning(
GoDevice.checkAndPadAuxArray(digitalAuxiliaries.getEnableAuxWarning()));
digitalAuxiliaries
.setAuxWarningSpeed(GoDevice.checkAndPadAuxArray(digitalAuxiliaries.getAuxWarningSpeed()));
digitalAuxiliaries.setIsAuxIgnTrigger(
GoDevice.checkAndPadAuxIgnArray(digitalAuxiliaries.getIsAuxIgnTrigger()));
digitalAuxiliaries.setExternalDeviceShutDownDelay(0);
digitalAuxiliaries.setImmobilizeArming(3);
digitalAuxiliaries
.setIsAuxInverted(GoDevice.checkAndPadAuxIgnArray(digitalAuxiliaries.getIsAuxInverted()));
}
/**
* Applies the defaults for the GoCurve device. We do not currently have an interface for the
* things the GoCurve adds - but we need to centralize the settings so it's here as GoCurve for
* now.
*
* @param goCurve GoCurve.
*/
public static void addGoCurveDefaults(GoCurve goCurve) {
if (goCurve == null) {
return;
}
goCurve.setEnableBeepOnRpm(false);
goCurve.setRpmValue(3500);
goCurve.setDriverSeatbeltWarningOn(false);
goCurve.setPassengerSeatbeltWarningOn(false);
goCurve.setReverseDetectOn(false);
goCurve.setIoxConnectionEnabled(true);
goCurve.setAccelerationWarningThreshold(22);
goCurve.setBrakingWarningThreshold(-34);
goCurve.setCorneringWarningThreshold(26);
goCurve.setAccelerometerThresholdWarningFactor(0);
goCurve.setSeatbeltWarningSpeed(10d);
goCurve.setEnableBeepOnDangerousDriving(false);
goCurve.setActiveTrackingEnabled(false);
addOdometerAdjustmentProviderDefaults(goCurve);
addEngineHoursAdjustmentProviderDefaults(goCurve);
}
/**
* Adds the odometer adjustment provider defaults.
*
* @param odometerAdjustmentProviderAware OdometerAdjustmentProviderAware.
*/
public static void addOdometerAdjustmentProviderDefaults(
OdometerAdjustmentProviderAware odometerAdjustmentProviderAware) {
if (odometerAdjustmentProviderAware == null) {
return;
}
odometerAdjustmentProviderAware.setOdometerOffset(0d);
odometerAdjustmentProviderAware.setOdometerFactor(1f);
}
/**
* Adds the odometer adjustment provider defaults.
*
* @param engineHoursAdjustmentProviderAware EngineHoursAdjustmentProviderAware.
*/
public static void addEngineHoursAdjustmentProviderDefaults(
EngineHoursAdjustmentProviderAware engineHoursAdjustmentProviderAware) {
if (engineHoursAdjustmentProviderAware == null) {
return;
}
engineHoursAdjustmentProviderAware.setEngineHourOffset(0);
}
/**
* Adds the custom vehicle device defaults.
*
* @param customVehicleDevice CustomVehicleDevice
*/
public static void addCustomVehicleDeviceDefaults(CustomVehicleDevice customVehicleDevice) {
if (customVehicleDevice == null) {
return;
}
addVehicleIdentificationNumberDefaults(customVehicleDevice);
addOdometerAdjustmentProviderDefaults(customVehicleDevice);
addEngineHoursAdjustmentProviderDefaults(customVehicleDevice);
addLicensableDefaults(customVehicleDevice);
}
}