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

New attempt to fix DeveloperLevel. #320

Merged
merged 1 commit into from
Jul 20, 2023
Merged
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
5 changes: 1 addition & 4 deletions Meadow.CLI.Core/Devices/IMeadowDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ public interface IMeadowDevice : IDisposable
public Task NshDisable(CancellationToken cancellationToken = default);
public Task TraceEnable(CancellationToken cancellationToken = default);
public Task SetTraceLevel(uint traceLevel, CancellationToken cancellationToken = default);
public Task SetDeveloper1(uint userData, CancellationToken cancellationToken = default);
public Task SetDeveloper2(uint userData, CancellationToken cancellationToken = default);
public Task SetDeveloper3(uint userData, CancellationToken cancellationToken = default);
public Task SetDeveloper4(uint userData, CancellationToken cancellationToken = default);
public Task SetDeveloper(ushort level, uint userData, CancellationToken cancellationToken = default);
public Task Uart1Apps(CancellationToken cancellationToken = default);
public Task Uart1Trace(CancellationToken cancellationToken = default);
public Task TraceDisable(CancellationToken cancellationToken = default);
Expand Down
19 changes: 2 additions & 17 deletions Meadow.CLI.Core/Devices/MeadowDeviceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,9 @@ public Task TraceDisable(CancellationToken cancellationToken = default)
return _meadowDevice.TraceDisable(cancellationToken);
}

public Task SetDeveloper1(uint userData, CancellationToken cancellationToken = default)
public Task SetDeveloper(ushort level, uint userData, CancellationToken cancellationToken = default)
{
return _meadowDevice.SetDeveloper1(userData, cancellationToken);
}

public Task SetDeveloper2(uint userData, CancellationToken cancellationToken = default)
{
return _meadowDevice.SetDeveloper2(userData, cancellationToken);
}

public Task SetDeveloper3(uint userData, CancellationToken cancellationToken = default)
{
return _meadowDevice.SetDeveloper3(userData, cancellationToken);
}

public Task SetDeveloper4(uint userData, CancellationToken cancellationToken = default)
{
return _meadowDevice.SetDeveloper4(userData, cancellationToken);
return _meadowDevice.SetDeveloper(level, userData, cancellationToken);
}

public Task Uart1Apps(CancellationToken cancellationToken = default)
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Devices/MeadowLocalDevice.FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<IList<string>> GetFilesAndFolders(
}
};

var command = new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER_4)
var command = new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_GET_FILES_AND_FOLDERS)
.WithResponseHandler(handler)
.Build();

Expand Down
36 changes: 3 additions & 33 deletions Meadow.CLI.Core/Devices/MeadowLocalDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,40 +233,10 @@ public Task SetTraceLevel(uint traceLevel, CancellationToken cancellationToken =
return SendCommand(command, cancellationToken);
}

public Task SetDeveloper1(uint userData, CancellationToken cancellationToken = default)
public Task SetDeveloper(ushort level, uint userData, CancellationToken cancellationToken = default)
{
var command =
new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER_1)
.WithUserData(userData)
.Build();

return SendCommand(command, cancellationToken);
}

public Task SetDeveloper2(uint userData, CancellationToken cancellationToken = default)
{
var command =
new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER_2)
.WithUserData(userData)
.Build();

return SendCommand(command, cancellationToken);
}

public Task SetDeveloper3(uint userData, CancellationToken cancellationToken = default)
{
var command =
new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER_3)
.WithUserData(userData)
.Build();

return SendCommand(command, cancellationToken);
}

public Task SetDeveloper4(uint userData, CancellationToken cancellationToken = default)
{
var command =
new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER_4)
var command = new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER)
.WithDeveloperLevel(level)
.WithUserData(userData)
.Build();

Expand Down
12 changes: 7 additions & 5 deletions Meadow.CLI.Core/Internals/MeadowCommunication/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ public class Command
{
private protected const int HcomProtocolCommandRequiredHeaderLength = 12;
private protected const int HcomProtocolCommandSeqNumber = 0;
private protected const ushort HcomProtocolExtraDataDefaultValue = 0x0000;
// TODO No longer required private protected const ushort HcomProtocolExtraDataDefaultValue = 0x0000;
private protected const int HcomProtocolRequestMd5HashLength = 32;
static internal ushort HcomProtocolCommunicationVersion = Constants.HCOM_PROTOCOL_CURRENT_VERSION_NUMBER;

public Command(HcomMeadowRequestType requestType,
TimeSpan timeout,
ushort developerLevel,
uint userData,
byte[]? data,
Predicate<MeadowMessageEventArgs> responsePredicate,
Expand All @@ -24,6 +25,7 @@ public Command(HcomMeadowRequestType requestType,
{
RequestType = requestType;
Timeout = timeout;
DeveloperLevel = developerLevel;
UserData = userData;
Data = data;
ResponsePredicate = responsePredicate;
Expand All @@ -34,9 +36,10 @@ public Command(HcomMeadowRequestType requestType,
}

public HcomMeadowRequestType RequestType { get; protected set; }
public ushort DeveloperLevel { get; protected set; }
public uint UserData { get; protected set; }
public TimeSpan Timeout { get; protected set; }
public byte[]? Data { get; protected set; }
public TimeSpan Timeout { get; protected set; }
public Predicate<MeadowMessageEventArgs> ResponsePredicate { get; protected set; }
public Predicate<MeadowMessageEventArgs> CompletionPredicate { get; protected set; }
public EventHandler<MeadowMessageEventArgs>? ResponseHandler { get; protected set; }
Expand Down Expand Up @@ -77,9 +80,9 @@ protected int ToMessageBytes(ref byte[] messageBytes)

offset += sizeof(ushort);

// Extra Data
// DeveloperLevel
Array.Copy(
BitConverter.GetBytes(HcomProtocolExtraDataDefaultValue),
BitConverter.GetBytes(DeveloperLevel),
0,
messageBytes,
offset,
Expand All @@ -99,7 +102,6 @@ protected int ToMessageBytes(ref byte[] messageBytes)
messageBytes,
HcomProtocolCommandRequiredHeaderLength,
Data.Length);

offset += Data.Length;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal FileCommand(HcomMeadowRequestType requestType,
Predicate<MeadowMessageEventArgs> responseHandler,
Predicate<MeadowMessageEventArgs> completionHandler,
string commandBuilder)
: base(requestType, timeout, partition, null, responseHandler, completionHandler, null, true, commandBuilder)
: base(requestType, timeout, 0, partition, null, responseHandler, completionHandler, null, true, commandBuilder)
{
SourceFileName = sourceFileName;
DestinationFileName = destinationFileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public SimpleCommandBuilder(HcomMeadowRequestType requestType)
private protected MeadowMessageType? CompletionMessageType;

private protected HcomMeadowRequestType RequestType { get; set; }
private protected ushort DeveloperLevel { get; set; }
private protected uint UserData { get; set; }
private protected TimeSpan Timeout { get; set; }
private protected byte[]? Data { get; set; }
Expand All @@ -31,6 +32,12 @@ public SimpleCommandBuilder WithTimeout(TimeSpan timeout)
return this;
}

public SimpleCommandBuilder WithDeveloperLevel(ushort level)
{
DeveloperLevel = level;
return this;
}

public SimpleCommandBuilder WithUserData(uint userData)
{
UserData = userData;
Expand Down Expand Up @@ -95,13 +102,14 @@ public Command Build()
else CompletionPredicate = e => e.MessageType == MeadowMessageType.Concluded;
}

return new Command(RequestType, Timeout, UserData, Data, ResponsePredicate, CompletionPredicate, ResponseHandler, IsAcknowledged, ToString());
return new Command(RequestType, Timeout, DeveloperLevel, UserData, Data, ResponsePredicate, CompletionPredicate, ResponseHandler, IsAcknowledged, ToString());
}

public override string ToString()
{
return $"RequestType: {RequestType} "
+ $"Timeout: {Timeout} "
+ $"DeveloperLevel: {DeveloperLevel} "
+ $"UserData: {UserData} "
+ $"ResponseType {ResponseMessageType?.ToString() ?? "none"} "
+ $"CompletionMessageType: {CompletionMessageType?.ToString() ?? "none"} "
Expand Down
21 changes: 10 additions & 11 deletions Meadow.CLI/Commands/Trace/SetDeveloperValueCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public SetDeveloperValueCommand(DownloadManager downloadManager, ILoggerFactory
_logger = LoggerFactory.CreateLogger<SetDeveloperValueCommand>();
}

[CommandOption("developer", 'd', Description = "The developer value to set. Valid values are 1 - 4")]
public uint Developer { get; set; }
[CommandOption("developer", 'd', Description = "The developer value to set.")]
public ushort DeveloperLevel { get; set; }

[CommandOption("value", 'v', Description = "The value to apply to the developer value. Valid values are 0 to 4,294,967,295")]
public uint Value { get; set; }
Expand All @@ -31,16 +31,15 @@ public override async ValueTask ExecuteAsync(IConsole console)

var cancellationToken = console.RegisterCancellationHandler();

var task = Developer switch
try
{
1 => Meadow.SetDeveloper1(Value, cancellationToken),
2 => Meadow.SetDeveloper2(Value, cancellationToken),
3 => Meadow.SetDeveloper3(Value, cancellationToken),
4 => Meadow.SetDeveloper4(Value, cancellationToken),
_ => throw new ArgumentOutOfRangeException(nameof(Developer), Developer, "Valid values are 1 - 4")
};

await task;

await Meadow.SetDeveloper(DeveloperLevel, Value, cancellationToken);
}
catch (Exception ex)
{
_logger.LogError($"Error Setting Developer : {ex.Message}");
}
}
}
}
9 changes: 4 additions & 5 deletions Meadow.Hcom/HcomMeadowRequestType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ public enum HcomMeadowRequestType : ushort
HCOM_MDOW_REQUEST_GET_DEVICE_NAME = 0x1f | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,
HCOM_MDOW_REQUEST_GET_INITIAL_FILE_BYTES = 0x20 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,

// Only used for testing
HCOM_MDOW_REQUEST_DEVELOPER_1 = 0xf0 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,
HCOM_MDOW_REQUEST_DEVELOPER_2 = 0xf1 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,
HCOM_MDOW_REQUEST_DEVELOPER_3 = 0xf2 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,
HCOM_MDOW_REQUEST_DEVELOPER_4 = 0xf3 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,
HCOM_MDOW_REQUEST_GET_FILES_AND_FOLDERS = 0xf3 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,

// Only used internally for testing
HCOM_MDOW_REQUEST_DEVELOPER = 0xf8 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,

HCOM_MDOW_REQUEST_S25FL_QSPI_INIT = 0xf4 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,
HCOM_MDOW_REQUEST_S25FL_QSPI_WRITE = 0xf5 | HcomProtocolHeaderTypes.HCOM_PROTOCOL_HEADER_TYPE_SIMPLE,
Expand Down