type
PEndPointDescriptor = ^TEndPointDescriptor;
TEndPointDescriptor =
packed record
Length : Byte;
// sollte 0x07 sein
EndpointDescriptor : Byte;
// Endpoint Deskriptor (Typangabe)
EndpointAddress : Byte;
// Endpoint Address (IN0-IN15 0x80 - 0x8F; OUT0-OUT15 0x00 - 0x0F)
Attributes : TControlTransfer;
// _BULK, _INT, _ISO, and _CTRL
BufferSize : Word;
// 8, 16, 32 Byte; as Byte Array "64,0"
Intervall : Byte;
// Polling Intervall
end;
PInterfaceDescriptor = ^TInterfaceDescriptor;
TInterfaceDescriptor =
packed record
Length : Byte;
// sollte 0x09 sein
InterfaceDescriptor : Byte;
// Interface Deskriptor (Typangabe)
InterfaceNumber : Byte;
// Interface Nummer
AlternateSettingNumber : Byte;
// Alternate Setting Number
EndpointCount : Byte;
// Number of Endpoints (exclude Endpoint 0)
ClassCode : Byte;
SubClassCode : Byte;
ProtokollCode : Byte;
InterfaceStringIndex: Byte;
private
function GetItem(AIndex: Integer): PEndPointDescriptor;
function GetEndPoint(AIndex: Integer): PEndPointDescriptor;
public
function GetSize: Integer;
property EndPoints[AIndex: Integer]: PEndPointDescriptor
read GetEndPoint;
end;
PConfigurationDescriptor = ^TConfigurationDescriptor;
TConfigurationDescriptor =
packed record
Length : Byte;
// sollte 0x09 sein
ConfigurationDescriptor : Byte;
// Typangabe
TotalLength : Word;
// Gesamtlänge des Descriptors as Byte Array "xx,0"
InterfaceCount : Byte;
ConfigurationIndex : Byte;
// Index of this Configuration
ConfigurationStringIndex : Byte;
// Configuration string index
Attributes : Byte;
// _DEFAULT, _SELF ...
PowerConsumtion : Byte;
// Max power consumption (2X mA)
private
function GetItem(AIndex: Integer): PInterfaceDescriptor;
function GetIterfaceDescriptor(AIndex: Integer): PInterfaceDescriptor;
public
function GetSize: Integer;
property IterfaceDescriptors[AIndex: Integer]: PInterfaceDescriptor
read GetIterfaceDescriptor;
end;
implementation
{ TConfigurationDescriptor }
function TConfigurationDescriptor.GetItem(AIndex: Integer): PInterfaceDescriptor;
var
i: Integer;
begin
Result := @Self;
Inc(LongWord(Result), Self.Length);
for i := 0
to AIndex - 1
do
Inc(LongWord(Result), Result^.GetSize);
end;
function TConfigurationDescriptor.GetIterfaceDescriptor(
AIndex: Integer): PInterfaceDescriptor;
begin
if (AIndex >= 0)
and (AIndex < InterfaceCount)
then
Result := GetItem(AIndex)
else
Result :=
nil;
// oder Exception auslösen
end;
function TConfigurationDescriptor.GetSize: Integer;
begin
Result := LongWord(GetItem(InterfaceCount)) - LongWord(@Self);
end;
{ TInterfaceDescriptor }
function TInterfaceDescriptor.GetEndPoint(AIndex: Integer): PEndPointDescriptor;
begin
if (AIndex >= 0)
and (AIndex < EndpointCount)
then
Result := GetItem(AIndex)
else
Result :=
nil;
// oder Exception auslösen
end;
function TInterfaceDescriptor.GetItem(AIndex: Integer): PEndPointDescriptor;
var
i: Integer;
begin
Result := @Self;
Inc(LongWord(Result), Self.Length);
for i := 0
to AIndex - 1
do
Inc(LongWord(Result), Result^.Length);
end;
function TInterfaceDescriptor.GetSize: Integer;
begin
Result := LongWord(GetItem(EndpointCount)) - LongWord(@Self);
end;