Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

UDP Server Output Packet Information

Travis Nickles edited this page Sep 4, 2022 · 4 revisions

Work in Progress

Byte Index bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
[0-3] "DSUS"
[4-5] Protocol Version (1001)
[6-7] Buffer Length (84)
[8-11] CRC32
[12-15] Server Id
[16-19] PadDataRsp (0x1000002)
[20] PadId (0 - 3)
[21] PadState
[22] Model
[23] Connection Type
[24-29] Mac Address
[30] Battery Status
[31] Pad IsActive (0,1)
[32-35] Hid Report Packet Counter
[36] Dpad Left Dpad Down Dpad Right Dpad Up Options R3 L3 Share
[37] Square Cross Circle Triangle R1 L1 R2Btn L2Btn
[38] PS
[39] Touch Button
[40] Left Stick X
[41] Left Stick Y Inverted
[42] Right Stick X
[43] Right Stick Y Inverted
[44] DPad Left Button
[45] DPad Down Button
[46] DPad Right Button
[47] DPad Up Button
[48] Square Button
[49] Cross Button
[50] Circle Button
[51] Triangle Button
[52] R1 Button
[53] L1 Button
[54] R2
[55] L2
[56] Touch 1 Active
[57] Touch 1 Id
[58-59] Touch 1 X
[60-61] Touch 1 Y
[62] Touch 2 Active
[63] Touch 2 Id
[64-65] Touch 2 X
[66-67] Touch 2 Y
[68-75] Total Micro Seconds
[76-79] Accelerometer X
[80-83] Accelerometer Y
[84-87] Accelerometer Z Inverted
[88-91] Gyro Angular Velocity Pitch
[92-95] Gyro Angular Velocity Yaw
[96-99] Gyro Angular Velocity Roll

Struct based version

For ease of use and better documentation, a struct based message handler is now used in DS4Windows. The information is placed in a defined struct and then copied over to a byte array that is then transmitted. The struct based version is slightly faster due to some design choices but I am sure the older array based version can be improved.

[StructLayout(LayoutKind.Explicit, Size = 100)]
unsafe struct PadDataRspPacket
{
    // Header section
    [FieldOffset(0)]
    public fixed byte initCode[4];
    [FieldOffset(4)]
    public ushort protocolVersion;
    [FieldOffset(6)]
    public ushort messageLen;
    [FieldOffset(8)]
    public int crc;
    [FieldOffset(12)]
    public uint serverId;
    [FieldOffset(16)]
    public uint messageType;

    // Pad meta section
    [FieldOffset(20)]
    public byte padId;
    [FieldOffset(21)]
    public byte padState;
    [FieldOffset(22)]
    public byte model;
    [FieldOffset(23)]
    public byte connectionType;
    [FieldOffset(24)]
    public fixed byte address[6];
    [FieldOffset(30)]
    public byte batteryStatus;
    [FieldOffset(31)]
    public byte isActive;
    [FieldOffset(32)]
    public uint packetCounter;

    // Primary controls
    [FieldOffset(36)]
    public byte buttons1;
    [FieldOffset(37)]
    public byte buttons2;
    [FieldOffset(38)]
    public byte psButton;
    [FieldOffset(39)]
    public byte touchButton;
    [FieldOffset(40)]
    public byte lx;
    [FieldOffset(41)]
    public byte ly;
    [FieldOffset(42)]
    public byte rx;
    [FieldOffset(43)]
    public byte ry;
    [FieldOffset(44)]
    public byte dpadLeft;
    [FieldOffset(45)]
    public byte dpadDown;
    [FieldOffset(46)]
    public byte dpadRight;
    [FieldOffset(47)]
    public byte dpadUp;
    [FieldOffset(48)]
    public byte square;
    [FieldOffset(49)]
    public byte cross;
    [FieldOffset(50)]
    public byte circle;
    [FieldOffset(51)]
    public byte triangle;
    [FieldOffset(52)]
    public byte r1;
    [FieldOffset(53)]
    public byte l1;
    [FieldOffset(54)]
    public byte r2;
    [FieldOffset(55)]
    public byte l2;

    // Touch 1
    [FieldOffset(56)]
    public byte touch1Active;
    [FieldOffset(57)]
    public byte touch1PacketId;
    [FieldOffset(58)]
    public ushort touch1X;
    [FieldOffset(60)]
    public ushort touch1Y;

    // Touch 2
    [FieldOffset(62)]
    public byte touch2Active;
    [FieldOffset(63)]
    public byte touch2PacketId;
    [FieldOffset(64)]
    public ushort touch2X;
    [FieldOffset(66)]
    public ushort touch2Y;

    // Accel
    [FieldOffset(68)]
    public ulong totalMicroSec;
    [FieldOffset(76)]
    public float accelXG;
    [FieldOffset(80)]
    public float accelYG;
    [FieldOffset(84)]
    public float accelZG;

    // Gyro
    [FieldOffset(88)]
    public float angVelPitch;
    [FieldOffset(92)]
    public float angVelYaw;
    [FieldOffset(96)]
    public float angVelRoll;
}

https://github.com/Ryochan7/DS4Windows/blob/ef6f5b1d2f8337e48a3f2c00025b007175662094/DS4Windows/DS4Control/UdpServer.cs#L68