buttplugio / stpihkal

Repo deprecated, STPIHKAL moved to docs.buttplug.io repo
https://docs.buttplug.io/
93 stars 21 forks source link

Document AGUI Angel's Wing Protocol #176

Open blackspherefollower opened 1 year ago

blackspherefollower commented 1 year ago

V1.8:

Write to start: [ 0x87, 0xAA, 0xAA, 0x06, 0xF1, 0xD2 ] If started, reading should start with 0x55, 0xAA, 0xAA

Read with a buffer size of 65.

int index1 = 1;
          byte num2 = buffer[index1];
          byte num3 = buffer[index1 + 1];
          byte num4 = buffer[index1 + 2];
          if (num2 != (byte) 135 && num3 != (byte) 170 && num4 != (byte) 170)
          {
            Thread.Sleep(1);
          }
          else
          {
            byte num5 = buffer[index1 + 3];
            if ((int) num5 > buffer.Length - 2 || num5 == (byte) 0)
            {
              Thread.Sleep(1);
            }
            else
            {
              byte num6 = 0;
              byte num7 = buffer[index1 + (int) num5 - 1];
              for (int index2 = 0; index2 < (int) num5 - 1; ++index2)
                num6 += buffer[index1 + index2];
              if ((int) num6 == (int) num7)
              {
                USBServer.productL = (int) buffer[index1 + 4];
                USBServer.productS = (int) buffer[index1 + 5];
                USBServer.versionL = (int) buffer[index1 + 6];
                USBServer.versionS = (int) buffer[index1 + 7];
                USBServer.serialNumber = (int) buffer[index1 + 8] << 24 | (int) buffer[index1 + 9] << 16 | (int) buffer[index1 + 10] << 8 | (int) buffer[index1 + 11];
                int num8 = index1 + 8;
                short num9 = (short) ((int) buffer[num8 + 4] << 8 | (int) buffer[num8 + 5]);
                short num10 = (short) ((int) buffer[num8 + 6] << 8 | (int) buffer[num8 + 7]);
                short num11 = (short) ((int) buffer[num8 + 8] << 8 | (int) buffer[num8 + 9]);
                USBServer.accX = (float) num9 / 16384f;
                USBServer.accY = (float) num10 / 16384f;
                USBServer.accZ = (float) num11 / 16384f;
                USBServer.tempC = (float) (int) ((16.529998779296875 + (double) (short) ((int) buffer[num8 + 10] << 8 | (int) buffer[num8 + 11]) / 340.0) * 10.0) / 10f;
                short num12 = (short) ((int) buffer[num8 + 12] << 8 | (int) buffer[num8 + 13]);
                short num13 = (short) ((int) buffer[num8 + 14] << 8 | (int) buffer[num8 + 15]);
                short num14 = (short) ((int) buffer[num8 + 16] << 8 | (int) buffer[num8 + 17]);
                USBServer.gyroX = (float) num12 / 2048f;
                USBServer.gyroY = (float) num13 / 2048f;
                USBServer.gyroZ = (float) num14 / 2048f;
                short num15 = (short) ((int) buffer[num8 + 19] << 8 | (int) buffer[num8 + 18]);
                short num16 = (short) ((int) buffer[num8 + 21] << 8 | (int) buffer[num8 + 20]);
                short num17 = (short) ((int) buffer[num8 + 23] << 8 | (int) buffer[num8 + 22]);
                USBServer.magX = (float) num15 * 0.15f;
                USBServer.magY = (float) num16 * 0.15f;
                USBServer.magZ = (float) num17 * 0.15f;
                USBServer.force1 = (float) (1.0 - (double) buffer[num8 + 26] / (double) byte.MaxValue);
                USBServer.force2 = (float) (1.0 - (double) buffer[num8 + 27] / (double) byte.MaxValue);
                USBServer.force3 = (float) (1.0 - (double) buffer[num8 + 28] / (double) byte.MaxValue);
                USBServer.force4 = (float) (1.0 - (double) buffer[num8 + 29] / (double) byte.MaxValue);
                USBServer.force5 = (float) (1.0 - (double) buffer[num8 + 30] / (double) byte.MaxValue);
                USBServer.force6 = (float) (1.0 - (double) buffer[num8 + 31] / (double) byte.MaxValue);
                USBServer.voltage = kalmanFilter.Filter((float) (int) ((double) buffer[num8 + 32] / (double) byte.MaxValue * 2.0999999046325684 * 100.0) / 100f);
                USBServer.voltagePercent = (int) ((((double) USBServer.voltage > 0.8 ? ((double) USBServer.voltage > 1.5 ? 1.5 : (double) USBServer.voltage) : 0.8) - 0.8) / 0.7 * 100.0);
                USBServer.button = buffer[num8 + 38] == (byte) 1;

V1.10

Multiple controllers supported

If started, reading should start with 0x55, 0xAA, 0xAA

Start by sending: "+++CMD" to enter command mode, then "AT+ROLE=C\r\n" to enter master mode.

Scan for devices: "AT+SCAN=?\r\n", read (timeout 15000) until "end" found. The device ID prefixes "AGUI" "AT+CONNECT=" + id + "\r\n"

Fallback to 1.8 style: Write to start: [ 0x87, 0xAA, 0xAA, 0x06, 0xF1, 0xD2 ] If started, reading should start with 0x55, 0xAA, 0xAA

hread.Sleep(1);
          byte num1;
          byte num2;
          byte num3;
          if ((num1 = this.sensorData.Take()) == (byte) 85 && (num2 = this.sensorData.Take()) == (byte) 170 && (num3 = this.sensorData.Take()) == (byte) 170)
          {
            byte[] numArray = new byte[64];
            numArray[0] = num1;
            numArray[1] = num2;
            numArray[2] = num3;
            for (int index = 3; index < 48; ++index)
              numArray[index] = this.sensorData.Take();
            int num4 = 0;
            byte num5 = numArray[num4 + 3];
            if ((int) num5 > numArray.Length - 2 || num5 == (byte) 0)
            {
              Thread.Sleep(1);
            }
            else
            {