private async Task <byte[]> SendAsync(CommandSubsystem commandSubsystem, byte[] payload, Func <SerialPacket, bool> predicate, CancellationToken cancellationToken) { throw new NotImplementedException(); //return await RetryAsync(async () => //{ // var request = new SynchronousRequest(commandSubsystem, 0, payload); // _transmitQueue.Add(request); // var response = await WaitForResponseAsync((msg) => predicate((SynchronousResponse) msg), cancellationToken).ConfigureAwait(false); // return ((SynchronousResponse) response).Payload; //}, $"{commandSubsystem} {(payload != null ? BitConverter.ToString(payload) : string.Empty)}", cancellationToken); }
public ZpiObject(CommandSubsystem commandSubsystem, byte cmdId) { CommandSubsystem = commandSubsystem; CommandId = cmdId; ZpiObject zpi = ZpiMeta.GetCommand(commandSubsystem, cmdId); if (zpi != null) { this.Type = zpi.Type; this.Name = zpi.Name; this.RequestArguments = zpi.RequestArguments; } }
public ZpiSREQ(CommandSubsystem subSystem, byte cmdId) { CommandSubsystem = subSystem; CommandId = cmdId; ZpiObject zpi = ZpiMeta.GetCommand(subSystem, cmdId); if (zpi != null) { this.Type = zpi.Type; this.Name = zpi.Name; this.RequestArguments = zpi.RequestArguments; if (zpi is ZpiSREQ) { this.ResponseArguments = ((ZpiSREQ)zpi).ResponseArguments; } } }
public ZpiObject(CommandSubsystem commandSubsystem, MessageType type, byte commandId) : this(commandSubsystem, (byte)commandId) { Type = type; }
private static void LoadSubSys(JObject root) { foreach (JObject subSys in root.Values()) { string subSysName = subSys.Path; CommandSubsystem subSystem = (CommandSubsystem)subSys["id"].Value <int>(); if (_zpiObjects.ContainsKey(subSystem) == false) { _zpiObjects.Add(subSystem, new List <ZpiObject>()); } foreach (var attr in subSys["cmds"].Values()) { if (attr["params"].Value <JArray>("rsp") != null) { //Sync ZpiSREQ zpiSREQ = new ZpiSREQ(); zpiSREQ.Name = attr.Path.Substring(attr.Path.LastIndexOf(".") + 1); zpiSREQ.CommandId = (byte)attr["cmdId"].Value <byte>(); zpiSREQ.Type = (MessageType)attr["type"].Value <int>(); zpiSREQ.CommandSubsystem = subSystem; foreach (JObject item in attr["params"]["req"]) { foreach (var itm in item) { ZpiArgument zpiArgument = new ZpiArgument() { Name = itm.Key, ParamType = (ParamType)itm.Value.Value <int>() }; zpiSREQ.RequestArguments.AddOrUpdate(zpiArgument); } } if (attr["params"].Value <JArray>("rsp") != null) { foreach (JObject item in attr["params"]["rsp"]) { foreach (var itm in item) { ZpiArgument zpiArgument = new ZpiArgument() { Name = itm.Key, ParamType = (ParamType)itm.Value.Value <int>() }; zpiSREQ.ResponseArguments.AddOrUpdate(zpiArgument); } } } _zpiObjects[subSystem].Add(zpiSREQ); } else { //Async ZpiObject zpiObject = new ZpiSREQ(); zpiObject.Name = attr.Path.Substring(attr.Path.LastIndexOf(".") + 1); zpiObject.CommandId = (byte)attr["cmdId"].Value <byte>(); zpiObject.Type = (MessageType)attr["type"].Value <int>(); zpiObject.CommandSubsystem = subSystem; foreach (JObject item in attr["params"]["req"]) { foreach (var itm in item) { ZpiArgument zpiArgument = new ZpiArgument() { Name = itm.Key, ParamType = (ParamType)itm.Value.Value <int>() }; zpiObject.RequestArguments.AddOrUpdate(zpiArgument); } } _zpiObjects[subSystem].Add(zpiObject); } } } }
public static MessageType GetMessageType(CommandSubsystem subSystem, byte cmdId) { return(GetCommand(subSystem, cmdId).Type); }
public static ZpiObject GetCommand(CommandSubsystem subSystem, byte cmdId) { return(ZpiObjects[subSystem].SingleOrDefault(cmd => cmd.CommandId == cmdId)); }
public ZpiSREQ(CommandSubsystem subSystem, MessageType type, byte commandId) : this(subSystem, (byte)commandId) { Type = type; }