buttplugio / stpihkal

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

Document Fredorch F21S/T8 protocol #131

Open blackspherefollower opened 3 years ago

blackspherefollower commented 3 years ago

BLE Name: YXlinksSPP Service UUID: 0000ffb0-0000-1000-8000-00805f9b34fb Tx Characteristic UUID: 0000ffb1-0000-1000-8000-00805f9b34fb Rx Characteristic UUID: 0000ffb2-0000-1000-8000-00805f9b34fb

Device is a positional belt driven linear actuator:

Pattern mode:

Free mode:

Program mode:

Turns out that if you initialise the program with:

You can then send follow-up position/speeds by just sending:

_auchCRCHi = [0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64, 0, 193, 129, 64, 1, 192, 128, 65, 0, 193, 129, 64, 1, 192, 128, 65, 1, 192, 128, 65, 0, 193, 129, 64];
_auchCRCLo = [0, 192, 193, 1, 195, 3, 2, 194, 198, 6, 7, 199, 5, 197, 196, 4, 204, 12, 13, 205, 15, 207, 206, 14, 10, 202, 203, 11, 201, 9, 8, 200, 216, 24, 25, 217, 27, 219, 218, 26, 30, 222, 223, 31, 221, 29, 28, 220, 20, 212, 213, 21, 215, 23, 22, 214, 210, 18, 19, 211, 17, 209, 208, 16, 240, 48, 49, 241, 51, 243, 242, 50, 54, 246, 247, 55, 245, 53, 52, 244, 60, 252, 253, 61, 255, 63, 62, 254, 250, 58, 59, 251, 57, 249, 248, 56, 40, 232, 233, 41, 235, 43, 42, 234, 238, 46, 47, 239, 45, 237, 236, 44, 228, 36, 37, 229, 39, 231, 230, 38, 34, 226, 227, 35, 225, 33, 32, 224, 160, 96, 97, 161, 99, 163, 162, 98, 102, 166, 167, 103, 165, 101, 100, 164, 108, 172, 173, 109, 175, 111, 110, 174, 170, 106, 107, 171, 105, 169, 168, 104, 120, 184, 185, 121, 187, 123, 122, 186, 190, 126, 127, 191, 125, 189, 188, 124, 180, 116, 117, 181, 119, 183, 182, 118, 114, 178, 179, 115, 177, 113, 112, 176, 80, 144, 145, 81, 147, 83, 82, 146, 150, 86, 87, 151, 85, 149, 148, 84, 156, 92, 93, 157, 95, 159, 158, 94, 90, 154, 155, 91, 153, 89, 88, 152, 136, 72, 73, 137, 75, 139, 138, 74, 78, 142, 143, 79, 141, 77, 76, 140, 68, 132, 133, 69, 135, 71, 70, 134, 130, 66, 67, 131, 65, 129, 128, 64];

function padLeft(e, t, n) {
    void 0 == n && (n = "0");
    for (var o = 0, i = t - e.length; o < i; o++) {
        e = n + e;
    }
    return e;
}
function CRC16(t) {
    for (var n = 255, o = 255, i = 0; i < t.length; i++) {
        var a = n ^ t[i];
        n = o ^ e._auchCRCHi[a];
        o = e._auchCRCLo[a]
    }
    return [n, o];
}
blackspherefollower commented 3 years ago

Since the CRC16 thing makes testing with nRF Connect hard, I threw together a test app here: https://glitch.com/edit/#!/cactus-square-debt After connect send the messages without the CRC16 (send will calculate and add the data)

blackspherefollower commented 2 years ago
Valid movement positions: Hex Dec Depth
0x00 0 170mm
0x0a 10 180mm
0x14 20 197mm
0x1e 30 205mm
0x28 40 214mm
0x32 50 223mm
0x3c 60 231mm
0x46 70 240mm
0x50 80 248mm
0x5a 90 258mm
0x64 100 266mm
0x6e 110 275mm
0x78 120 284mm
0x82 130 292mm
0x8c 140 300mm
0x96 150 310mm

image

blackspherefollower commented 2 years ago

Right... an update, because I've been covering my progress on my patron and I need to replicate it here. I have a decent surface fit: TIME = 2.61607666e+03 (SPEED ^ -9.64147031e-01) ((DISTANCE*10) ^ 2.28645432e-01) Where time is in ms, speed is 1-15 and distance is 0-15.

Here's the relevant cross links:

forest-devil commented 1 month ago

FYI, according to the I/O byte pattern, I believe this is MODBUS RTU. You can check https://www.modbustools.com/modbus.html for more details.

Address Function Data CRC
1 byte 1 byte N bytes 2 bytes

The first byte 02 is the device ID, the second byte is Function, where

01 (0x01) Read Coils 02 (0x02) Read Discrete Inputs 03 (0x03) Read Holding Registers 04 (0x04) Read Input Registers 05 (0x05) Write Single Coil 06 (0x06) Write Single Register 08 (0x08) Diagnostics (Serial Line only) 11 (0x0B) Get Comm Event Counter (Serial Line only) 15 (0x0F) Write Multiple Coils 16 (0x10) Write Multiple Registers 17 (0x11) Report Server ID (Serial Line only) 22 (0x16) Mask Write Register 23 (0x17) Read/Write Multiple Registers 43 / 14 (0x2B / 0x0E) Read Device Identification

button73 commented 1 month ago

@forest-devil Do you know what is the current status of F21S support in the library? On iostindex it is added as supported, but I've seen posts on reddit that position control is not working (at least on xtoys)

blackspherefollower commented 1 month ago

@forest-devil Do you know what is the current status of F21S support in the library? On iostindex it is added as supported, but I've seen posts on reddit that position control is not working (at least on xtoys)

The protocol is implemented and "works". The timings in Buttplug are off, but we do at least have the numbers (see https://www.patreon.com/posts/66668487).

Position control "should" be fine, but we do not control the Xtoys implementation.