Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/devices/BuildHat/Brick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,15 +1564,40 @@ private void Reset()
private string GetRawVersion()
{
PortWrite(GetFirmwareVersion);
PortReadLine();
return PortReadExisting();
return PortReadUntil(FirmwareVersion);
}

private string GetRawSignature()
{
PortWrite("signature\r");
PortReadLine();
return PortReadLine();
return PortReadUntil(FirmwareSignature);
}

// Reads complete lines from the port until one contains the expected
// marker. Relying on ReadLine (which waits for the newline terminator)
// instead of a fixed delay or ReadExisting makes the reads independent
// of the board speed and serial timing, which differ a lot between
// boards (for example a faster Raspberry Pi 5 may return before the
// firmware has answered). The firmware can prepend echo, prompt or
// asynchronous lines before the answer, so several lines may need to be
// skipped before the expected one is found.
private string PortReadUntil(string marker)
{
// The expected answer normally comes within the first couple of
// lines; the extra budget covers echo, the prompt and any
// asynchronous port notifications that may be interleaved.
const int MaximumLines = 10;
string line = string.Empty;
for (int i = 0; i < MaximumLines; i++)
{
line = PortReadLine();
if (line.Contains(marker))
{
break;
}
}

return line;
}

private string GetRawVoltage()
Expand Down
Binary file modified src/devices/BuildHat/data/firmware.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion src/devices/BuildHat/data/signature.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
�;�>g����]mV�V!�Lٙ�� ]NF��鴋�X�|��[�-�;&X�8\Son|�$
��N�.2�wSm�Q/I�Ӎm�)io\�~��I�Az4�ĘɅ�P��w�>\w��L�V�
Expand Down
2 changes: 1 addition & 1 deletion src/devices/BuildHat/data/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1636109636
1737564117