private async Task <int> GetCurrentKit() { // TODO: Stop assuming current kit is at address 0, although it is for TD-17, TD-50 and TD-27... var data = await device.RequestDataAsync(0, 1, new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token); return(data[0] + 1); }
public async Task RequestData_TD50X() { var input = new FakeMidiInput(); var output = new FakeMidiOutput(); var client = new RolandMidiClient(input, output, "TD-50X", "TD-50X", 0x10, ModuleIdentifier.TD50X); // Test for "Current kit" - simplest possible message. var task = client.RequestDataAsync(0, 1, new CancellationTokenSource(1000).Token); // Reply on behalf of the module var responseBytes = new byte[] { 0xF0, 0x41, 0x10, 0x00, 0x00, 0x00, 0x00, 0x07, 0x12, 0x00, 0x00, 0x00, 0x00, 0x58, 0x28, 0xF7 }; var responseMessage = new MidiMessage(responseBytes); // We should get the response input.SupplyMessage(responseMessage); var result = await task; Assert.AreEqual(new byte[] { 0x58 }, result); // Now check that the request was correct Assert.AreEqual(1, output.Messages.Count); var requestMessage = output.Messages[0]; var actualRequestData = requestMessage.Data; var expectedRequestData = new byte[] { 0xF0, 0x41, 0x10, // SYSEX, Roland, DevId 0x00, 0x00, 0x00, 0x00, 0x07, // TD-50X 0x11, // RQ1 0x00, 0x00, 0x00, 0x00, // Address 0x00, 0x00, 0x00, 0x01, // Size 0x7f, 0xF7 // Checksum and EOX }; Assert.AreEqual(expectedRequestData, actualRequestData); }
private static async Task PopulateSegment(RolandMidiClient client, ModuleData data, AnnotatedContainer annotatedContainer, CancellationToken token, IStandardStreamWriter console) { var timerToken = new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token; var effectiveToken = CancellationTokenSource.CreateLinkedTokenSource(token, timerToken).Token; try { var segment = await client.RequestDataAsync(annotatedContainer.Context.Address.Value, annotatedContainer.Container.Size, effectiveToken); data.Populate(annotatedContainer.Context.Address, segment); } catch (OperationCanceledException) when(timerToken.IsCancellationRequested) { console.WriteLine($"Device didn't respond for container {annotatedContainer.Path}; skipping."); } }
private async Task PopulateSegment(ModuleData data, AnnotatedContainer annotatedContainer, CancellationToken token) { var timerToken = new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token; var effectiveToken = CancellationTokenSource.CreateLinkedTokenSource(token, timerToken).Token; try { var segment = await client.RequestDataAsync(annotatedContainer.Context.Address.Value, annotatedContainer.Container.Size, effectiveToken); data.Populate(annotatedContainer.Context.Address, segment); } catch (OperationCanceledException) when(timerToken.IsCancellationRequested) { logger.Log($"Device didn't respond for container {annotatedContainer.Path}; skipping."); } catch { logger.Log($"Failure while loading {annotatedContainer.Path}"); throw; } }