/// <summary> /// Writes and verifies setting a Qsfp100GRegister register which > 1 byte. /// data is a byte array. /// /// Retries and Timeout set by policy. /// </summary> /// <param name="reg"></param> /// <param name="data"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <bool> SetRegAsync(Qsfp100GRegister reg, byte[] data, CancellationToken cancellationToken = default) { if (reg.Register.Size != data.Length) { throw new ArgumentOutOfRangeException(reg.Name, $"requires {reg.Register.Size} bytes while data only has {data.Length} bytes."); } var policyWrapResults = await _policyWrap.ExecuteAndCaptureAsync(async (context, ct) => { ct.ThrowIfCancellationRequested(); SetPage(reg.Register.Page); I2C.I2C_RandomWrite(Qsfp100GRegister.I2CAddress, reg.Register.Address, reg.Register.Size, data); var readBack = await I2C.I2C_RandomReadAsync(Qsfp100GRegister.I2CAddress, reg.Register.Address).ConfigureAwait(false); if (!StructuralComparisons.StructuralEqualityComparer.Equals(data, readBack)) { throw new ValidationException($"Validation failed, {data} not equal {readBack}."); } }, new Dictionary <string, object>() { { $"{GetCaller()}", $"{reg.Name}({reg.Page}.{reg.Address}:{data})" } }, cancellationToken : cancellationToken); if (policyWrapResults.Outcome == OutcomeType.Failure) { throw policyWrapResults.FinalException; } return(policyWrapResults.Outcome == OutcomeType.Successful); }
public async Task <byte[]> ReadAsync(byte page, byte readAddress, byte numBytes) { SetPage((byte)page); var readData = await I2C.I2C_RandomReadAsync(Qsfp100GRegister.I2CAddress, readAddress, numBytes) .ConfigureAwait(false); return(readData); }
//=========================== QSFP100G /// <summary> /// Reads a Qsfp100GRegister register. /// /// Retries and Timeout set by policy. /// </summary> /// <param name="reg"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <dynamic> GetRegAsync(Qsfp100GRegister reg, CancellationToken cancellationToken = default) { var policyWrapResults = await _policyWrap.ExecuteAndCaptureAsync(async (context, ct) => { ct.ThrowIfCancellationRequested(); SetPage(reg.Register.Page); var readData = await I2C.I2C_RandomReadAsync(Qsfp100GRegister.I2CAddress, reg.Register.Address, reg.Register.Size).ConfigureAwait(false); var res = ConvertData(reg, readData); return(res); }, new Dictionary <string, object>() { { $"{GetCaller()}", $"{reg.Name}({reg.Page}.{reg.Address})" } }, cancellationToken : cancellationToken); if (policyWrapResults.Outcome == OutcomeType.Failure) { throw policyWrapResults.FinalException; } return(policyWrapResults.Result); }
/// <summary> /// Writes and verifies setting of a SFF8636 register. /// /// Retries and Timeout set by policy. /// </summary> /// <param name="reg"></param> /// <param name="data"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <bool> SetRegAsync(Sff8636 reg, byte data, CancellationToken cancellationToken = default) { var policyWrapResults = await _policyWrap.ExecuteAndCaptureAsync(async (context, ct) => { ct.ThrowIfCancellationRequested(); SetPage(reg.Register.Page); I2C.I2C_RandomWrite(Sff8636.I2CAddress, reg.Register.Address, data); var readBack = await I2C.I2C_RandomReadAsync(Sff8636.I2CAddress, reg.Register.Address).ConfigureAwait(false); if (data != readBack) { throw new ValidationException($"Validation failed, {data} not equal {readBack}."); } }, new Dictionary <string, object>() { { $"{GetCaller()}", $"{reg.Name}({reg.Page}.{reg.Address}:{data})" } }, cancellationToken : cancellationToken); if (policyWrapResults.Outcome == OutcomeType.Failure) { throw policyWrapResults.FinalException; } return(policyWrapResults.Outcome == OutcomeType.Successful); }