I'm creating an in-house diagnostics application for a product that has a bunch of individually addressable devices on an I2C bus.
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.
I've created an abstract class called 'FormattedData' with a single property called 'RawData'.
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;
}
}
}
Each device on the I2C bus gets its own model by inheriting from FormattedData.
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:
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] & 0x02) == 0x02); }
set { ;}
}
}
So, onto my question.
I'm creating a model for an SFP transceiver based on the SFF-8472 spec.
Long story short, a single physical SFP device has 2 raw data tables (AO and A2). Each data table must be queried independently and can return up to 256 bytes.
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).
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?
I'd like to maintain some kind of standard interface for all devices if possible.