Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated for supporting new HCOM "runtime" text #515

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
81 changes: 9 additions & 72 deletions Source/v2/Meadow.Hcom/Connections/SerialConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,8 @@ private void EncodeAndSendPacket(byte[] messageBytes, int length, CancellationTo
try
{
// Send the data to Meadow
// Debug.Write($"Sending {encodedToSend} bytes...");
//await _port.BaseStream.WriteAsync(encodedBytes, 0, encodedToSend, cancellationToken ?? CancellationToken.None);
// DO NOT USE _port.BaseStream. It disables port timeouts!
_port.Write(encodedBytes, 0, encodedToSend);
// Debug.WriteLine($"sent");
}
catch (InvalidOperationException ioe) // Port not opened
{
Expand Down Expand Up @@ -411,7 +409,6 @@ private void EncodeAndSendPacket(byte[] messageBytes, int length, CancellationTo
}
}


private class SerialMessage
{
private readonly IList<Memory<byte>> _segments;
Expand Down Expand Up @@ -462,20 +459,6 @@ private bool DecodeAndProcessPacket(Memory<byte> packetBuffer, CancellationToken

var decodedSize = CobsTools.CobsDecoding(packetBuffer.ToArray(), packetLength, ref decodedBuffer);

/*
// If a message is too short it is ignored
if (decodedSize < MeadowDeviceManager.ProtocolHeaderSize)
{
return false;
}

Debug.Assert(decodedSize <= MeadowDeviceManager.MaxAllowableMsgPacketLength);

// Process the received packet
ParseAndProcessReceivedPacket(decodedBuffer.AsSpan(0, decodedSize).ToArray(),
cancellationToken);

*/
ArrayPool<byte>.Shared.Return(decodedBuffer);
return true;
}
Expand Down Expand Up @@ -506,10 +489,10 @@ protected override void Dispose(bool disposing)
private List<string> StdErr { get; } = new List<string>();
private List<string> InfoMessages { get; } = new List<string>();

private const string RuntimeSucessfullyEnabledToken = "Meadow successfully started MONO";
private const string RuntimeSucessfullyDisabledToken = "Mono is disabled";
private const string RuntimeStateToken = "Mono is";
private const string RuntimeIsEnabledToken = "Mono is enabled";
private const string MonoStateToken = "Mono is";
private const string RuntimeStateToken = "Runtime is";
private const string MonoIsEnabledToken = "Mono is enabled";
private const string RuntimeIsEnabledToken = "Runtime is enabled";
private const string RtcRetrievalToken = "UTC time:";

public int CommandTimeoutSeconds { get; set; } = 30;
Expand Down Expand Up @@ -641,10 +624,12 @@ public override async Task<bool> IsRuntimeEnabled(CancellationToken? cancellatio

if (InfoMessages.Count > 0)
{
var m = InfoMessages.FirstOrDefault(i => i.Contains(RuntimeStateToken));
var m = InfoMessages.FirstOrDefault(i =>
i.Contains(RuntimeStateToken) ||
i.Contains(MonoStateToken));
if (m != null)
{
return m == RuntimeIsEnabledToken;
return (m == RuntimeIsEnabledToken) || (m == MonoIsEnabledToken);
}
}

Expand Down Expand Up @@ -868,54 +853,6 @@ public override async Task<bool> WriteRuntime(
cancellationToken);


/*
RaiseConnectionMessage("\nErasing runtime flash blocks...");
status = await WaitForResult(() =>
{
if (_lastRequestConcluded != null)
{
// happens on error
return true;
}

var m = string.Join('\n', InfoMessages);
return m.Contains("Mono memory erase success");
},
cancellationToken);

InfoMessages.Clear();

RaiseConnectionMessage("Moving runtime to flash...");

status = await WaitForResult(() =>
{
if (_lastRequestConcluded != null)
{
// happens on error
return true;
}

var m = string.Join('\n', InfoMessages);
return m.Contains("Verifying runtime flash operation.");
},
cancellationToken);

InfoMessages.Clear();

RaiseConnectionMessage("Verifying...");

status = await WaitForResult(() =>
{
if (_lastRequestConcluded != null)
{
return true;
}

return false;
},
cancellationToken);
*/

if (status)
{
await WaitForConcluded(null, cancellationToken);
Expand Down
Loading