MCPcopy Create free account
hub / github.com/IQEngine/IQEngine / LocalClient

Class LocalClient

client/src/api/iqdata/LocalClient.ts:8–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6import { MINIMAP_FFT_SIZE } from '@/utils/constants';
7
8export class LocalClient implements IQDataClient {
9 files: FileWithDirectoryAndFileHandle[];
10
11 constructor(files: FileWithDirectoryAndFileHandle[]) {
12 this.files = files;
13 }
14 async getMinimapIQ(meta: SigMFMetadata, signal: AbortSignal): Promise<Float32Array[]> {
15 const localDirectory: FileWithDirectoryAndFileHandle[] = this.files;
16 if (!localDirectory) {
17 return Promise.reject('No local directory found');
18 }
19 const skipNFfts = Math.floor(meta.getTotalSamples() / (1000 * MINIMAP_FFT_SIZE)); // sets the decimation rate (manually tweaked)
20 const numFfts = Math.floor(meta.getTotalSamples() / MINIMAP_FFT_SIZE / (skipNFfts + 1));
21 let dataRange = [];
22 for (let i = 0; i < numFfts; i++) {
23 dataRange.push(i * skipNFfts);
24 }
25 const { file_path } = meta.getOrigin();
26 const dataFile = localDirectory.find((file) => {
27 return file.webkitRelativePath === file_path + '.sigmf-data' || file.name === file_path + '.sigmf-data';
28 });
29 if (!dataFile) {
30 return Promise.reject('No data file found');
31 }
32 const result: Float32Array[] = [];
33 for (const index of dataRange) {
34 const bytesPerSample = meta.getBytesPerIQSample();
35 const offsetBytes = index * MINIMAP_FFT_SIZE * bytesPerSample;
36 const countBytes = MINIMAP_FFT_SIZE * bytesPerSample;
37 const slice = dataFile.slice(offsetBytes, offsetBytes + countBytes);
38 const buffer = await slice.arrayBuffer();
39 const iqArray = convertToFloat32(buffer, meta.getDataType());
40 result.push(iqArray);
41 }
42 return result;
43 }
44
45 getIQDataBlocks(
46 meta: SigMFMetadata,
47 indexes: number[],
48 blockSize: number,
49 signal: AbortSignal
50 ): Promise<IQDataSlice[]> {
51
52 const localDirectory: FileWithDirectoryAndFileHandle[] = this.files;
53 if (!localDirectory) {
54 return Promise.reject('No local directory found');
55 }
56
57 const filePath = meta.getOrigin().file_path;
58 const dataFile = localDirectory.find((file) => {
59 return file.webkitRelativePath === filePath + '.sigmf-data' || file.name === filePath + '.sigmf-data';
60 });
61 if (!dataFile) {
62 return Promise.reject('No data file found');
63 }
64
65 return Promise.all(indexes.map(async (index) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected