Example #1
0
        public void Write(byte page, byte writeAddress, byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            var dataLength   = data.Length;
            var bytesWritten = 0;

            lock (ReadWriteLock)
            {
                SetPage((byte)page);
                while (dataLength != 0)
                {
                    var writeLength = dataLength > VendorCommand.MaxWriteLen
                        ? VendorCommand.MaxWriteLen
                        : (byte)dataLength;
                    var writeData = data.Skip(bytesWritten).Take(writeLength).ToArray();
                    I2C.I2C_RandomWrite(Qsfp100GRegister.I2CAddress, writeAddress, 1, writeData);
                    dataLength   -= writeLength;
                    bytesWritten += writeLength;
                    writeAddress += writeLength;
                }
            }
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
 public void ClearModuleMfrPassword()
 {
     I2C.I2C_RandomWrite(0, Sff8636.Password.EntryAddress, Sff8636.Password.Size, _hostMfrPassword);
 }