Skip to content

Commit

Permalink
Add Loader functionality to CKernelWriter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gampyg28 committed Apr 23, 2023
1 parent 920b99f commit 671cd50
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Apps/PcmHammer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,10 +1496,11 @@ private async void write_BackgroundThread(WriteType writeType, string path = nul
}
}

if (pcmInfo.HardwareType == PcmType.P04)
if (writeType != WriteType.Compare && pcmInfo.HardwareType == PcmType.P04 && pcmInfo.HardwareType == PcmType.E54)
{
this.AddUserMessage("P04 Write is not supported by PCMHammer, aborted");
MessageBox.Show("P04 Write is not supported by PCMHammer");
string msg = $"PCMHammer currently does not support writing to the {pcmInfo.HardwareType.ToString()}";
this.AddUserMessage(msg);
MessageBox.Show(msg);
return;
}

Expand Down
33 changes: 32 additions & 1 deletion Apps/PcmLibrary/CKernelWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,38 @@ public CKernelWriter(Vehicle vehicle, PcmInfo pcmInfo, Protocol protocol, WriteT
this.logger.AddUserMessage("4X communications disabled by configuration.");
}

Response<byte[]> response = await this.vehicle.LoadKernelFromFile(this.pcmInfo.KernelFileName);
await this.vehicle.SendToolPresentNotification();

Response<byte[]> response;

// Execute kernel loader, if required
if (this.pcmInfo.LoaderRequired)
{
response = await vehicle.LoadKernelFromFile(this.pcmInfo.LoaderFileName);
if (response.Status != ResponseStatus.Success)
{
logger.AddUserMessage("Failed to load loader from file.");
return false;
}

if (cancellationToken.IsCancellationRequested)
{
return false;
}

await this.vehicle.SendToolPresentNotification();

if (!await this.vehicle.PCMExecute(this.pcmInfo, response.Value, cancellationToken))
{
logger.AddUserMessage("Failed to upload loader to PCM");

return false;
}

logger.AddUserMessage("Loader uploaded to PCM succesfully.");
}

response = await this.vehicle.LoadKernelFromFile(this.pcmInfo.KernelFileName);
if (response.Status != ResponseStatus.Success)
{
logger.AddUserMessage("Failed to load kernel from file.");
Expand Down

0 comments on commit 671cd50

Please sign in to comment.