Skip to content
Permalink
Browse files

Merge branch 'develop' of https://github.com/LegacyNsfw/PcmHacks into…

… develop
  • Loading branch information
LegacyNsfw committed Dec 1, 2019
2 parents a67839e + 597cf3a commit 2978a611d759f90e9f15a3831273e9e007a54b71
Binary file not shown.

This file was deleted.

@@ -53,7 +53,7 @@ public async Task<Response<Stream>> ReadContents(PcmInfo info, CancellationToken
await this.vehicle.SendToolPresentNotification();

// execute read kernel
Response<byte[]> response = await vehicle.LoadKernelFromFile("read-kernel.bin");
Response<byte[]> response = await vehicle.LoadKernelFromFile("kernel.bin");
if (response.Status != ResponseStatus.Success)
{
logger.AddUserMessage("Failed to load kernel from file.");
@@ -123,6 +123,48 @@ public async Task<Response<Stream>> ReadContents(PcmInfo info, CancellationToken
startAddress += blockSize;
}

logger.AddUserMessage("Read complete. Starting verification...");
Query<UInt32> chipIdQuery = this.vehicle.CreateQuery<UInt32>(
this.protocol.CreateFlashMemoryTypeQuery,
this.protocol.ParseFlashMemoryType,
cancellationToken);

Response<UInt32> chipIdResponse = await chipIdQuery.Execute();

if (chipIdResponse.Status == ResponseStatus.Success)
{
IList<MemoryRange> ranges = FlashChips.GetMemoryRanges(chipIdResponse.Value, this.logger);
if (ranges != null)
{
CKernelVerifier verifier = new CKernelVerifier(
image,
ranges,
this.vehicle,
this.protocol,
this.logger);

if (await verifier.CompareRanges(
ranges,
image,
BlockType.All,
cancellationToken))
{
logger.AddUserMessage("The PCM was read without errors.");
}
else
{
logger.AddUserMessage("##############################################################################");
logger.AddUserMessage("There are errors in the data that was read from the PCM. Do not use this file.");
logger.AddUserMessage("##############################################################################");
}
}
}
else
{
logger.AddUserMessage("Unable to determine which flash chip is in this PCM.");
logger.AddUserMessage("That prevents us from validating the results of this operation.");
}

await this.vehicle.Cleanup(); // Not sure why this does not get called in the finally block on successfull read?

MemoryStream stream = new MemoryStream(image);
@@ -65,7 +65,7 @@ public CKernelWriter(Vehicle vehicle, Protocol protocol, ILogger logger)
return false;
}

Response<byte[]> response = await this.vehicle.LoadKernelFromFile("write-kernel.bin");
Response<byte[]> response = await this.vehicle.LoadKernelFromFile("kernel.bin");
if (response.Status != ResponseStatus.Success)
{
logger.AddUserMessage("Failed to load kernel from file.");
@@ -14,6 +14,9 @@ public enum TimeoutScenario
ReadCrc,
SendKernel,
ReadMemoryBlock,
DataLogging1,
DataLogging2,
DataLogging3,
Maximum,
}

@@ -264,6 +267,20 @@ protected int GetVpwTimeoutMilliseconds(TimeoutScenario scenario)
packetSize = this.MaxSendSize + 20;
break;

case TimeoutScenario.DataLogging1:
packetSize = 30;
break;

// This one was tuned by hand to avoid timeouts with STPX.
// 1 and 3 probably still need tuning.
case TimeoutScenario.DataLogging2:
packetSize = 47;
break;

case TimeoutScenario.DataLogging3:
packetSize = 64;
break;

case TimeoutScenario.Maximum:
return 0xFF * 4;

@@ -156,6 +156,8 @@ public override async Task SetTimeout(TimeoutScenario scenario)
int parameter = Math.Min(Math.Max(1, (milliseconds / 4)), 255);
string value = parameter.ToString("X2");
await this.implementation.SendAndVerify("AT ST " + value, "OK");
this.currentTimeout = scenario;
this.implementation.TimeoutScenario = scenario;
}

/// <summary>
@@ -22,6 +22,8 @@ public class ElmDeviceImplementation

public bool Supports4X { get; protected set; }

public TimeoutScenario TimeoutScenario { get; set; }

protected readonly Action<Message> enqueue;

protected readonly Func<int> getRecievedMessageCount;
@@ -123,7 +123,19 @@ public override async Task<bool> SendMessage(Message message)
builder.Append(messageBytes[0].ToString("X2"));
builder.Append(messageBytes[1].ToString("X2"));
builder.Append(messageBytes[2].ToString("X2"));
builder.Append(", R:1");

int responses = 1;
if (this.TimeoutScenario == TimeoutScenario.DataLogging2)
{
responses += 1;
}

if (this.TimeoutScenario == TimeoutScenario.DataLogging3)
{
responses += 2;
}

builder.AppendFormat(", R:{0}", responses);
builder.Append(", L:");
int dataLength = messageBytes.Length - 3;
builder.Append(dataLength.ToString());
@@ -1,4 +1,6 @@
using System;
//#define FAST_LOGGING

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -41,12 +43,14 @@ public async Task<bool> StartLogging()
return false;
}

await this.vehicle.SetDeviceTimeout(TimeoutScenario.ReadProperty);
int scenario = ((int)TimeoutScenario.DataLogging1 - 1);
scenario += this.profile.ParameterGroups.Count;
await this.vehicle.SetDeviceTimeout((TimeoutScenario)scenario);

#if FAST_LOGGING
if (!await this.vehicle.RequestDpids(this.dpids))
{
return null;
return false;
}

this.lastRequestTime = DateTime.Now;
@@ -63,7 +67,7 @@ public async Task<string[]> GetNextRow()
LogRowParser row = new LogRowParser(this.profile);

#if FAST_LOGGING
if (DateTime.Now.Subtract(lastRequestTime) > TimeSpan.FromSeconds(2))
// if (DateTime.Now.Subtract(lastRequestTime) > TimeSpan.FromSeconds(2))
{
await this.vehicle.ForceSendToolPresentNotification();
}
@@ -1,4 +1,6 @@
using System;
//#define FAST_LOGGING

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
@@ -102,12 +104,13 @@ public Message RequestDpids(DpidCollection dpids)
// 0x01 = send once
// 0x12 = send slowly
// 0x13 = send medium
// 0x14 = send medium
// 0x24 = send fast
byte responseType = 0x24;
byte responseType = 0x01;
byte[] header = new byte[] { Priority.Physical0, DeviceId.Pcm, DeviceId.Tool, Mode.SendDynamicData, responseType };
byte[] padding = new byte[4];// { 0xFF, 0xFF, 0xFF, 0xFF };
IEnumerable<byte> test = padding.Take(5 - dpid.Length);
return new Message(header.Concat(dpid).Concat(test).ToArray());
IEnumerable<byte> test = padding.Take(5 - dpids.Values.Length);
return new Message(header.Concat(dpids.Values).Concat(test).ToArray());
#else
byte[] header = new byte[] { Priority.Physical0, DeviceId.Pcm, DeviceId.Tool, Mode.SendDynamicData, 0x01 };
return new Message(header.Concat(dpids.Values).ToArray());
@@ -25,23 +25,23 @@
},
{
"Conversion": {
"Name": "C",
"Expression": "x-40"
"Name": "kpa",
"Expression": "x"
},
"Name": "Coolant Temperature",
"Name": "Manifold Absolute Pressure",
"DefineBy": 1,
"ByteCount": 1,
"Address": "0x5"
"Address": "0xB"
},
{
"Conversion": {
"Name": "C",
"Expression": "x-40"
"Name": "%",
"Expression": "x\/2.56"
},
"Name": "Intake Air Temperature",
"Name": "Throttle Position Sensor",
"DefineBy": 1,
"ByteCount": 1,
"Address": "0xF"
"Address": "0x11"
}
],
"TotalBytes": 6
@@ -51,64 +51,64 @@
"Parameters": [
{
"Conversion": {
"Name": "psi",
"Expression": "x"
"Name": "C",
"Expression": "x-40"
},
"Name": "Engine Oil Pressure",
"Name": "Intake Air Temperature",
"DefineBy": 1,
"ByteCount": 1,
"Address": "0x115C"
"Address": "0xF"
},
{
"Conversion": {
"Name": "RPM",
"Expression": "x*12.5"
"Name": "C",
"Expression": "x-40"
},
"Name": "Target idle speed",
"Name": "Engine Coolant Temperature",
"DefineBy": 1,
"ByteCount": 1,
"Address": "0x1192"
"Address": "0x5"
},
{
"Conversion": {
"Name": "percent",
"Expression": "x/2.56"
"Name": "%",
"Expression": "(x-128)\/1.28"
},
"Name": "target throttle position - fail",
"Name": "Left Long Term Fuel Trim",
"DefineBy": 1,
"ByteCount": 1,
"Address": "0x1464"
"Address": "0x7"
},
{
"Conversion": {
"Name": "%",
"Expression": "x/2.56"
"Expression": "(x-128)\/1.28"
},
"Name": "EGR DC",
"Name": "Right Long Term Fuel Trim",
"DefineBy": 1,
"ByteCount": 1,
"Address": "0x1172"
"Address": "0x9"
},
{
"Conversion": {
"Name": "Seconds",
"Expression": "x"
"Name": "Degrees",
"Expression": "(x*256)\/22.5"
},
"Name": "Engine Off Time - fail",
"Name": "Knock Retard",
"DefineBy": 1,
"ByteCount": 1,
"Address": "0x13B5"
"Address": "0x11A6"
},
{
"Conversion": {
"Name": "C",
"Expression": "(x+40)*(256/192)"
"Name": "AFR",
"Expression": "x*10"
},
"Name": "Transmission Oil Temp",
"Name": "Target AFR",
"DefineBy": 1,
"ByteCount": 1,
"Address": "0x1949"
},
"Address": "0x119E"
}
],
"TotalBytes": 6
}

0 comments on commit 2978a61

Please sign in to comment.
You can’t perform that action at this time.