// // BwgBurn - CD-R/CD-RW/DVD-R/DVD-RW burning program for Windows XP // // Copyright (C) 2006 by Jack W. Griffin (butchg@comcast.net) // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the // // Free Software Foundation, Inc., // 59 Temple Place, Suite 330, // Boston, MA 02111-1307 USA // using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Runtime.InteropServices; namespace Bwg.Scsi { /// /// This class is a base class for classes that contain results from SCSI commands. This /// class contains information about whether or not that result is valid and provides functions /// for extract data from the SCSI response. /// public abstract class Result { #region private data members /// /// The data buffer containing the data that makes up the result /// private IntPtr m_buffer ; /// /// The size of the data in the buffer /// private int m_size ; /// /// This member is true if the result is valid. It is false if an error occurred while /// parsing the SCSI result. /// protected bool m_valid; #endregion #region constructor /// /// This is the constructor for the ScsiResult class. /// /// A pointer to the memory area containing the SCSI reply /// The size of the memory area containing the SCSI reply public Result(IntPtr buffer, int size) { m_valid = true; m_buffer = buffer; m_size = size; } #endregion #region public properties /// /// This property is true if the result is valid, and false otherwise. /// public bool Valid { get { return m_valid; } } /// /// This property returns the size of the buffer /// public int BufferSize { get { return m_size; } } /// /// This property returns the buffer /// public IntPtr Buffer { get { return m_buffer; } } #endregion #region public member functions /// /// This method returns a byte of data from the memory area associated with the SCSI reply. /// /// The location of the byte to return within the reply /// a byte of data from the reply public byte Get8(int offset) { if (offset >= m_size) throw new Exception("offset " + offset.ToString() + " is out side the range of the buffer"); return Marshal.ReadByte(m_buffer, offset); } /// /// /// /// /// public ushort Get16(int offset) { return (ushort)((Get8(offset) << 8) | Get8(offset + 1)); } /// /// Get a 16 bit number located in two different places in the buffer /// /// offset to the MSB of the number /// offset to the LSB of the number /// public ushort Get16(int msb, int lsb) { return (ushort)((Get8(msb) << 8) | Get8(lsb)); } /// /// /// /// /// public uint Get24(int offset) { return (UInt32)((Get8(offset) << 16) | (Get8(offset + 1) << 8) | Get8(offset + 2)); } /// /// /// /// /// public uint Get32(int offset) { return (UInt32)((Get8(offset) << 24) | (Get8(offset + 1) << 16) | (Get8(offset + 2) << 8) | Get8(offset + 3)); } /// /// This method returns a 32 bit integer from an offset in the data buffer. The data is /// ordered as big endian data per the SCSI-3 specification. /// /// the offset into the buffer /// public int Get32Int(int offset) { uint b = Get32(offset); Debug.Assert(b < Int32.MaxValue); return (int)b; } /// /// /// /// /// /// public string GetString(int start, int stop) { string s = ""; for (int i = start; i <= stop; i++) { byte b = Get8(i); s += (char)b; } return s; } /// /// Return a true or false value based on a bit in the buffer /// /// offset to the byte containing the bit /// the specific bit number /// boolean reflecting the value of the bit public bool GetBit(int offset, int bit) { byte b = Get8(offset); if ((b & (1 << bit)) != 0) return true; return false; } #endregion } }