Files
Aaru/SCSI/Modes/22_Certance.cs

188 lines
6.9 KiB
C#
Raw Normal View History

2017-12-21 02:03:21 +00:00
// /***************************************************************************
2020-02-27 12:31:23 +00:00
// Aaru Data Preservation Suite
2017-12-21 02:03:21 +00:00
// ----------------------------------------------------------------------------
//
// Filename : 22_Certance.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device structures decoders.
//
// --[ Description ] ----------------------------------------------------------
//
// Decodes Certance MODE PAGE 22h: Interface Control Mode Page.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2022-02-18 10:02:39 +00:00
// Copyright © 2011-2022 Natalia Portillo
2017-12-21 02:03:21 +00:00
// ****************************************************************************/
2022-03-07 07:36:42 +00:00
namespace Aaru.Decoders.SCSI;
using System.Diagnostics.CodeAnalysis;
2017-12-21 02:03:21 +00:00
using System.Text;
2022-03-06 13:29:37 +00:00
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), SuppressMessage("ReSharper", "NotAccessedField.Global")]
public static partial class Modes
2017-12-21 02:03:21 +00:00
{
2022-03-06 13:29:37 +00:00
#region Certance Mode Page 0x22: Interface Control Mode Page
public struct Certance_ModePage_22
2017-12-21 02:03:21 +00:00
{
2022-03-06 13:29:37 +00:00
/// <summary>Parameters can be saved</summary>
public bool PS;
public byte BaudRate;
public byte CmdFwd;
public bool StopBits;
public byte Alerts;
public byte PortATransportType;
public byte PortAPresentSelectionID;
public byte NextSelectionID;
public byte JumperedSelectionID;
public byte TargetInitiatedBusControl;
public bool PortAEnabled;
public bool PortAEnabledOnPower;
}
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
public static Certance_ModePage_22? DecodeCertanceModePage_22(byte[] pageResponse)
{
if((pageResponse?[0] & 0x40) == 0x40)
return null;
if((pageResponse?[0] & 0x3F) != 0x22)
return null;
if(pageResponse[1] + 2 != pageResponse.Length)
return null;
if(pageResponse.Length != 16)
return null;
var decoded = new Certance_ModePage_22();
decoded.PS |= (pageResponse[0] & 0x80) == 0x80;
decoded.BaudRate = pageResponse[2];
decoded.CmdFwd = (byte)((pageResponse[3] & 0x18) >> 3);
decoded.StopBits |= (pageResponse[3] & 0x04) == 0x04;
decoded.CmdFwd = (byte)(pageResponse[3] & 0x03);
decoded.PortATransportType = pageResponse[4];
decoded.PortAPresentSelectionID = pageResponse[7];
decoded.NextSelectionID = pageResponse[12];
decoded.JumperedSelectionID = pageResponse[13];
decoded.TargetInitiatedBusControl = pageResponse[14];
decoded.PortAEnabled |= (pageResponse[15] & 0x10) == 0x10;
decoded.PortAEnabledOnPower |= (pageResponse[15] & 0x04) == 0x04;
return decoded;
}
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
public static string PrettifyCertanceModePage_22(byte[] pageResponse) =>
PrettifyCertanceModePage_22(DecodeCertanceModePage_22(pageResponse));
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
public static string PrettifyCertanceModePage_22(Certance_ModePage_22? modePage)
{
if(!modePage.HasValue)
return null;
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
Certance_ModePage_22 page = modePage.Value;
var sb = new StringBuilder();
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
sb.AppendLine("Certance Interface Control Mode Page:");
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
if(page.PS)
sb.AppendLine("\tParameters can be saved");
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
switch(page.BaudRate)
{
case 0:
case 1:
case 2:
sb.AppendLine("\tLibrary interface will operate at 9600 baud on next reset");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
case 3:
sb.AppendLine("\tLibrary interface will operate at 19200 baud on next reset");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
case 4:
sb.AppendLine("\tLibrary interface will operate at 38400 baud on next reset");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
case 5:
sb.AppendLine("\tLibrary interface will operate at 57600 baud on next reset");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
case 6:
sb.AppendLine("\tLibrary interface will operate at 115200 baud on next reset");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
default:
sb.AppendFormat("\tUnknown library interface baud rate code {0}", page.BaudRate).AppendLine();
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
}
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
sb.AppendLine(page.StopBits ? "Library interface transmits 2 stop bits per byte"
: "Library interface transmits 1 stop bits per byte");
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
switch(page.CmdFwd)
{
case 0:
sb.AppendLine("\tCommand forwarding is disabled");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
case 1:
sb.AppendLine("\tCommand forwarding is enabled");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
default:
sb.AppendFormat("\tUnknown command forwarding code {0}", page.CmdFwd).AppendLine();
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
}
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
switch(page.PortATransportType)
{
case 0:
sb.AppendLine("\tPort A link is down");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
case 3:
sb.AppendLine("\tPort A uses Parallel SCSI Ultra-160 interface");
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
default:
sb.AppendFormat("\tUnknown port A transport type code {0}", page.PortATransportType).AppendLine();
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
break;
}
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
if(page.PortATransportType > 0)
sb.AppendFormat("\tDrive responds to SCSI ID {0}", page.PortAPresentSelectionID).AppendLine();
2017-12-21 02:03:21 +00:00
2022-03-07 07:36:42 +00:00
sb.AppendFormat("\tDrive will respond to SCSI ID {0} on Port A enabling", page.NextSelectionID).AppendLine();
2019-11-25 00:54:38 +00:00
2022-03-06 13:29:37 +00:00
sb.AppendFormat("\tDrive jumpers choose SCSI ID {0}", page.JumperedSelectionID).AppendLine();
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
sb.AppendLine(page.PortAEnabled ? "\tSCSI port is enabled" : "\tSCSI port is disabled");
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
sb.AppendLine(page.PortAEnabledOnPower ? "\tSCSI port will be enabled on next power up"
: "\tSCSI port will be disabled on next power up");
2017-12-21 02:03:21 +00:00
2022-03-06 13:29:37 +00:00
return sb.ToString();
2017-12-21 02:03:21 +00:00
}
2022-03-06 13:29:37 +00:00
#endregion Certance Mode Page 0x22: Interface Control Mode Page
2017-12-21 02:03:21 +00:00
}