title: How would you model this device?
body: <p>I'm creating an in-house diagnostics application for a product that has a bunch of individually addressable devices on an I2C bus.  </p>
  
  <p>The general idea is that I query each device on the bus and obtain a byte array of 'raw data'.  The length of the byte array depends on the individual device.  </p>
  
  <p>I've created an abstract class called 'FormattedData' with a single property called 'RawData'.  </p>
  
  <pre><code>public abstract class FormattedData {
  
      protected byte[] _rawData;
  
      public FormattedData(int rawDataLength) {
          _rawData = new byte[rawDataLength];
      }
  
      public byte[] RawData {
          get { return _rawData; }
          set {
              if (value.Length != _rawData.Length) {
                  throw new ArgumentOutOfRangeException("RawData",
                      "The Raw Data byte array for a " + this.GetType().Name +
                      " must be " + _rawData.Length.ToString() + "-bytes long." +
                      Environment.NewLine +
                      "Length of supplied array: [" + value.Length.ToString() + "]");
              }
  
              _rawData = value;
          }
      }
  }
  </code></pre>
  
  <p>Each device on the I2C bus gets its own model by inheriting from FormattedData.  </p>
  
  <p>I can then expose a bunch of properties for the device by manipulating data from the RawData byte array as required.   For my purposes the data is all read-only.  For example:</p>
  
  <pre><code>public class MyTestDevice : FormattedData {
  
      public MyTestDevice()
          : base(256) {
      }
  
      public string VendorName {
          get { return (ASCIIEncoding.ASCII.GetString(_rawData, 20, 16)); }
          set { ;}
      }
  
      public bool LossOfSignal {
          get { return ((_rawData[110] &amp; 0x02) == 0x02); }
          set { ;}
      }
  }
  </code></pre>
  
  <p>So, onto my question.</p>
  
  <p>I'm creating a model for an SFP transceiver based on the <a href="http://www.google.com/search?q=sff-8472" rel="nofollow noreferrer">SFF-8472</a> spec.</p>
  
  <p>Long story short, a single physical SFP device has <strong>2 raw data tables</strong>  (AO and A2).  Each data table must be queried independently and can return up to 256 bytes. </p>
  
  <p>The problem is that a couple of the properties from the A2 table depend on values from the A0 table (some analog values from the A2 table are scaled differently depending upon a flag set in the A0 table).</p>
  
  <p>What would be the best way to model a device like this with more than one 'Raw Data' byte array, and where it's possible that values from one array may depend on values from another?</p>
  
  <p>I'd like to maintain some kind of standard interface for all devices if possible.</p>