/// <summary> /// creates a new s.m.a.r.t. data instance /// </summary> /// <param name="smartData"></param> public SMARTDATA(byte[] smartData) { Entries = new SMARTDATAENTRY[30]; for (var i = 0; i < 30; i++) { Entries[i] = new SMARTDATAENTRY(smartData, i); } }
/// <summary> /// creates a new s.m.a.r.t. data instance /// </summary> /// <param name="smartData"></param> public SMARTDATA(string smartData) { if (smartData == null) { throw new ArgumentNullException(nameof(smartData)); } Entries = new SMARTDATAENTRY[30]; var data = new byte[512]; var currentValue = 0; var currentStage = 0; var currentPosition = 0; foreach (var c in smartData.ToUpperInvariant()) { var value = -1; if ((c >= '0') && (c <= '9')) { value = (byte)(c - '0'); } else if ((c >= 'A') && (c <= 'F')) { value = (byte)(c - 'A') + 10; } if (value >= 0) { currentValue = (currentValue << 4) + value; if (++currentStage == 2) { data[currentPosition++] = (byte)currentValue; currentValue = 0; currentStage = 0; } } } if (currentPosition != 512) { throw new InvalidDataException(); } for (var i = 0; i < 30; i++) { Entries[i] = new SMARTDATAENTRY(data, i); } }