Skip to content

Commit 540813e

Browse files
Handle QiYi manufacturer data
1 parent 8a0e305 commit 540813e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/app/discovery/discovery.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { CommonModule } from '@angular/common';
1717
type DiscoveredDevicesFilter = (devices: DiscoveredDevice[]) => DiscoveredDevice[];
1818

1919
const NoFilter: DiscoveredDevicesFilter = devices => devices;
20-
const CubingPrefixes = ['GAN', 'MG', 'AiCube', 'Gi', 'Mi Smart Magic Cube', 'GoCube', 'Rubiks', 'MHC', 'WCU', 'QY-'];
20+
const QiYiPrefix = 'QY-';
21+
const CubingPrefixes = ['GAN', 'MG', 'AiCube', 'Gi', 'Mi Smart Magic Cube', 'GoCube', 'Rubiks', 'MHC', 'WCU', QiYiPrefix];
2122
const CubingDeviceFilter: DiscoveredDevicesFilter = devices => devices.filter(isCubingDevice);
2223
const ScanTimeout = 30000;
2324

@@ -94,10 +95,22 @@ export class DiscoveryComponent {
9495
return undefined;
9596
}
9697

97-
// extract the last 6 bytes of the manufacturer data, reverse them and format them as a MAC address
98+
if (device.name?.startsWith(QiYiPrefix)) {
99+
return this.qiyiEncryptionKey(manufacturerDataPart);
100+
} else {
101+
return this.ganEncryptionKey(manufacturerDataPart);
102+
}
103+
}
104+
105+
private ganEncryptionKey(manufacturerDataPart: number[]): string | undefined {
98106
return manufacturerDataPart.slice(-6).reverse().map(byte => byte.toString(16).padStart(2, '0')).join(':').toUpperCase();
99107
}
100108

109+
110+
private qiyiEncryptionKey(manufacturerDataPart: number[]): string | undefined {
111+
return manufacturerDataPart.slice(0, 6).reverse().map(byte => byte.toString(16).padStart(2, '0')).join(':').toUpperCase();
112+
}
113+
101114
async copyToClipboard(text: string): Promise<void> {
102115
await writeText(text);
103116

0 commit comments

Comments
 (0)