This commit is contained in:
Robin K 2022-09-03 18:06:27 +02:00
parent ee51409125
commit cfd4106613
1 changed files with 39 additions and 41 deletions

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2020 RomRaider.com
* Copyright (C) 2006-2022 RomRaider.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
@ -18,56 +18,54 @@
*/
package com.romraider.maps.checksum;
import java.util.Map;
import com.romraider.util.HexUtil;
/**
* This class implements a copy "checksum", which can be useful for old Motronic ECUs
* It simply checks if an array of data is identical to a specified location and copies it over if necessary
* This class implements a copy "checksum", which can be useful for old Motronic
* ECUs. It simply checks if an array of data is identical to a specified
* location and copies it over if necessary
*/
public final class ChecksumCOPY implements ChecksumManager {
private static final String START = "start";
private static final String END = "end";
private static final String LOC = "loc";
private int start; // Start of checksum area
private int end; // End of area (inclusive)
private int loc; // Start of location where data is copied
public final class ChecksumCOPY implements ChecksumManager {
private static final String START = "start";
private static final String END = "end";
private static final String LOC = "loc";
private int start; // Start of checksum area
private int end; // End of area (inclusive)
private int loc; // Start of location where data is copied
@Override
public void configure(Map<String, String> vars) {
if (start >= end) {
this.start = HexUtil.hexToInt(vars.get(START));
this.end = HexUtil.hexToInt(vars.get(END));
this.loc = HexUtil.hexToInt(vars.get(LOC));
}
}
@Override
public void configure(Map<String, String> vars) {
if(start >= end)
{
this.start = HexUtil.hexToInt(vars.get(START));
this.end = HexUtil.hexToInt(vars.get(END));
this.loc = HexUtil.hexToInt(vars.get(LOC));
}
}
@Override
public int getNumberOfChecksums() {
return 1;
}
@Override
public int validate(byte[] binData) {
for(int i = 0; i <= start - end; i++)
{
if(binData[start + i] != binData[loc + i])
{
return 0;
}
}
return 1;
}
@Override
public int validate(byte[] binData) {
for (int i = 0; i <= end - start; i++) {
if (binData[start + i] != binData[loc + i]) {
return 0;
}
}
return 1;
}
@Override
public int update(byte[] binData) {
int updateNeeded = 1 - validate(binData);
if(updateNeeded > 0)
{
System.arraycopy(binData, start, binData, loc, start + 1 - end);
}
return updateNeeded;
}
@Override
public int update(byte[] binData) {
int updateNeeded = 1 - validate(binData);
if (updateNeeded > 0) {
System.arraycopy(binData, start, binData, loc, end - start + 1);
}
return updateNeeded;
}
}