skyeye-sdk-js 1.4.14 → 1.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test.ts CHANGED
@@ -1,18 +1,22 @@
1
- import { JSONResponse } from "./src/proto/skyeye_rpc_pb";
2
- import { GrpcUtil } from "./src/GrpcUtil";
3
- import { ServiceError } from "@grpc/grpc-js";
4
- import { Enum } from "protobufjs";
1
+ // import { JSONResponse } from "./src/proto/skyeye_rpc_pb";
2
+ // import { GrpcUtil } from "./src/GrpcUtil";
3
+ // import { ServiceError } from "@grpc/grpc-js";
4
+ // import { Enum } from "protobufjs";
5
+
6
+ // import { write } from "fs";
7
+ // import { SkyEyeClientFactory } from "src/SkyEyeClientFactory";
8
+ import { Readable, Transform } from "stream";
5
9
 
6
10
  const { SkyEyeClientFactory } = require('./src/SkyEyeClientFactory')
7
- const { SkyEyeClient } = require('./src/SkyEyeClient')
11
+ // const { SkyEyeClient } = require('./src/SkyEyeClient')
8
12
 
9
- const { Cpu } = require('./src/models/Cpu')
13
+ // const { Cpu } = require('./src/models/Cpu')
10
14
 
11
- enum RegisterType {
12
- CPU,
13
- Device
14
- }
15
- let call
15
+ // enum RegisterType {
16
+ // CPU,
17
+ // Device
18
+ // }
19
+ // let call
16
20
  async function test() {
17
21
  // console.log("Connected to SkyEye server");
18
22
  // await client.getDeviceList();
@@ -57,16 +61,24 @@ async function test() {
57
61
  // const skyeyeDir = "D:/install/SkyEye/opt/skyeye/bin/skyeye.exe"
58
62
  // const port = "50066"
59
63
 
60
- const pathSkyEye = "C:/Users/lingt/Downloads/SkyTest_Double";
61
- const fileName = "C:/Users/lingt/Downloads/SkyTest_Double/SkyTest_Double.skyeye";
64
+ const pathSkyEye = "C:/Users/lingt/Downloads/SkyTest_Double_rm_28335";
65
+ const fileName = "C:/Users/lingt/Downloads/SkyTest_Double_rm_28335/SkyTest_Double.skyeye";
62
66
  const skyeyeDir = "G:/SkyEye/opt/skyeye/bin/skyeye.exe"
63
67
  const port = "50051"
64
68
  // const client = await SkyEyeClientFactory.instance.createConnectedClient('127.0.0.1', port);
65
- const client = SkyEyeClientFactory.instance.createClient('127.0.0.1', port);
69
+ const client = SkyEyeClientFactory.instance.createClient('127.0.0.1', port);
66
70
  const t = await client.initSkyEyeAndRun2(pathSkyEye, fileName, port, skyeyeDir)
67
- // await client.runCommand();
68
- const response = await client.getDeviceTree()
69
- console.log(response)
71
+ await client.runCommand();
72
+ setTimeout(async () => {
73
+ await client.stopCommand();
74
+ let response = await client.getGlobalVarValue("c67x_core_0","li1", 8, "int")
75
+ console.log(response)
76
+ response = await client.setGlobalVarValue("c67x_core_0","li1", 8, "int","1234567890123456789")
77
+ console.log(response)
78
+ response = await client.getGlobalVarValue("c67x_core_0","li1", 8, "int")
79
+ console.log(response)
80
+ }, 3000);
81
+
70
82
  // await client.registerTimeMonitor({
71
83
  // "id": "1",
72
84
  // "time": 50,
@@ -115,4 +127,409 @@ async function test() {
115
127
  // { name: 'SE_get_cpu_freq_hz', result: 200000000, error: null }
116
128
 
117
129
  }
118
- test()
130
+ test()
131
+ // const protobuf = require("protobufjs");
132
+ // const root = protobuf.loadSync("./src/proto/line_chart.proto");
133
+ // const Series = root.lookupType("Series");
134
+ // // const { UserData } = require('.src/proto/line_chart_pb'); // 预编译生成
135
+ // // const fs = require('fs');
136
+
137
+ // // JSON对象数据
138
+ // const jsonData = {
139
+ // series: [
140
+ // ],
141
+ // time: [
142
+
143
+ // ]
144
+ // };
145
+
146
+ // for (let i = 0; i < 50; i++) {
147
+ // jsonData.series.push({
148
+ // name: 'test' + i,
149
+ // value: []
150
+ // })
151
+ // }
152
+ // function getRandomDouble(min, max) {
153
+ // return Math.random() * (max - min) + min;
154
+ // }
155
+ // function getRandomInt(max) {
156
+ // return Math.floor(Math.random() * max);
157
+ // }
158
+ // jsonData.series.forEach((item, index) => {
159
+ // for (let i = 0; i < 300; i++) {
160
+ // item.value.push(getRandomDouble(0,10000))
161
+ // }
162
+ // })
163
+ // for (let i = 0; i < 300; i++) {
164
+ // jsonData.time.push({
165
+ // "realTime": getRandomDouble(0, 10000),
166
+ // "simulationTime": getRandomDouble(0, 10000),
167
+ // "customTime": getRandomDouble(0, 10000),
168
+ // })
169
+ // }
170
+
171
+ // console.log(jsonData.series.length)
172
+ // console.log(jsonData.series[0].value.length)
173
+ // // function getSerializedSize(obj) {
174
+ // // const jsonString = JSON.stringify(obj);
175
+ // // return Buffer.byteLength(jsonString, 'utf8'); // 精确计算 UTF-8 字节数
176
+ // // }
177
+ // // console.log(getSerializedSize(jsonData))
178
+ // // 序列化为Protobuf二进制Buffer
179
+ // // const d1 = new Date();
180
+ // // const protoBuffer = Series.encode(Series.create(jsonData)).finish();
181
+ // // const d2 = new Date();
182
+ // // console.log("序列化时间:", (d2.getTime() - d1.getTime()) / 1000);
183
+ // // const zlib = require("zlib");
184
+
185
+ // // // Gzip压缩(同步示例)
186
+ // // const compressedData = zlib.gzipSync(protoBuffer);
187
+ // // const d3 = new Date();
188
+ // // console.log("压缩时间:", (d3.getTime() - d2.getTime()) / 1000);
189
+ // // const fs = require("fs");
190
+ // // const outputStream = fs.createWriteStream('test.dat');
191
+ // // outputStream.write(compressedData);
192
+ // // const d4 = new Date();
193
+ // // console.log("存储时间:", (d4.getTime() - d3.getTime()) / 1000);
194
+ // // console.log("压缩数据已存储");
195
+
196
+ // // const zlib = require("zlib");
197
+ // // const fs = require("fs");
198
+ // // const { pipeline } = require('stream');
199
+ // // const path = require("path");
200
+ // // const d1 = new Date();
201
+ // // // 1. 创建转换流:JSON → Protobuf 二进制
202
+ // // const buffer = Series.encode(Series.create(jsonData)).finish();
203
+ // // console.log('压缩')
204
+ // // // 2. 创建压缩流(Brotli 高压缩率)
205
+ // // const compress = zlib.createGzip({ level: 9 })
206
+ // // const writeStream = fs.createWriteStream( "test.dat"); // 1MB 缓冲区
207
+
208
+ // // // 5. 管道连接:序列化数据 → 压缩 → 写入文件
209
+ // // const dataStream = require("stream").Readable.from(buffer); // 将 Buffer 转为可读流
210
+ // // dataStream
211
+ // // .pipe(compress) // 压缩数据
212
+ // // .pipe(writeStream) // 写入文件
213
+ // // .on("finish", () => {
214
+ // // const d2 = new Date();
215
+ // // console.log("序列化时间:", (d2.getTime() - d1.getTime()) / 1000);
216
+ // // console.log("数据已压缩存储成功")
217
+ // // })
218
+ // // .on("error", (err) => console.error("❌ 写入失败:", err));
219
+
220
+ // // const compressedInput = fs.readFileSync("user.dat");
221
+ // // const decompressedData = zlib.gunzipSync(compressedInput);
222
+ // // const decodedProto = Series.decode(decompressedData);
223
+ // // const originalJson = Series.toObject(decodedProto, { arrays: true }); // 保留数组类型
224
+ // // // console.log("还原的JSON:", originalJson);
225
+ // // console.log("还原的JSON:", originalJson.series[0].data[0]);
226
+
227
+
228
+
229
+ // const zlib = require("zlib");
230
+ // const fs = require("fs");
231
+
232
+ // class SplitFileWriter {
233
+ // constructor() {
234
+ // this.currentFile = null;
235
+ // this.currentSize = 0;
236
+ // this.fileIndex = 0;
237
+ // this.filename = `test_111.dat`;
238
+ // this.fd = null;
239
+ // this.createNewFile();
240
+ // }
241
+
242
+ // createNewFile() {
243
+
244
+ // if (this.currentFile) this.currentFile.end();
245
+
246
+ // this.currentFile = fs.createWriteStream(this.filename,{flags: 'a', start: 4 });
247
+ // this.currentSize = 0;
248
+ // }
249
+
250
+ // async writeHeader() {
251
+ // // 1. 读取并修改前4字节整数
252
+ // const readStream = fs.createReadStream(this.filename, { start: 0, end: 3 });
253
+ // let headerBuffer = Buffer.alloc(0);
254
+
255
+ // // 收集前4字节数据
256
+ // readStream.on('data', (chunk) => {
257
+ // headerBuffer = Buffer.concat([headerBuffer, chunk]);
258
+ // });
259
+
260
+ // // 等待头部读取完成
261
+ // await new Promise((resolve, reject) => {
262
+ // readStream.on('end', resolve);
263
+ // readStream.on('error', reject);
264
+ // });
265
+
266
+ // const newHeaderBuffer = Buffer.alloc(4);
267
+ // console.log(headerBuffer)
268
+ // if (headerBuffer.length < 4) {
269
+ // newHeaderBuffer.writeUInt32BE(0);
270
+ // } else {
271
+ // // 解析为整数并修改(小端序)
272
+ // const originalInt = headerBuffer.readUInt32BE();
273
+ // const modifiedInt = originalInt + 1;
274
+ // newHeaderBuffer.writeUInt32BE(modifiedInt);
275
+ // }
276
+ // console.log(newHeaderBuffer.readUint32BE());
277
+ // const compressedData = zlib.gzipSync(newHeaderBuffer)
278
+ // console.log(compressedData)
279
+
280
+ // // 2. 修改文件头部(覆盖写入前4字节)
281
+ // const writeHeaderStream = fs.createWriteStream(this.filename, { flags: 'r+', start: 0, end:3 });
282
+ // writeHeaderStream.write(newHeaderBuffer);
283
+ // await new Promise((resolve) => writeHeaderStream.end(resolve));
284
+ // }
285
+
286
+ // async write(chunk) {
287
+ // // 100MB限制(含压缩后数据)
288
+
289
+ // if (this.currentSize + chunk.length > 1000 * 1024 * 1024 ) {
290
+
291
+ // await this.createNewFile();
292
+
293
+ // }
294
+ // if(this.currentSize === 0) {
295
+ // await this.writeHeader()
296
+
297
+ // }
298
+
299
+ // this.currentFile.write(chunk, 'binary',async ()=>{
300
+ // const fd = this.currentFile.fd;
301
+ // fs.fsyncSync(fd);
302
+ // await this.writeHeader()
303
+ // date2 = new Date()
304
+ // console.log('存储时间:', (date2.getTime() - date1.getTime()) / 1000);
305
+ // });
306
+
307
+ // this.currentSize += chunk.length;
308
+ // }
309
+ // }
310
+
311
+ // // 3. 每30秒处理数据的管道
312
+ // const writer = new SplitFileWriter()
313
+
314
+
315
+ // function handleData(data) {
316
+ // let temp = {
317
+ // series: [],
318
+ // time: []}
319
+ // temp.series =data.series.map(series => {
320
+ // return {
321
+ // name: series.name,
322
+ // value: series.value.map(value => {
323
+ // return handleDataValue(value)
324
+ // })
325
+ // }
326
+ // })
327
+
328
+ // temp.time.map(time => {
329
+ // time.customTime = handleDataValue(time.customTime)
330
+ // time.realTime = handleDataValue(time.realTime)
331
+ // time.simulationTime = handleDataValue(time.simulationTime)
332
+ // })
333
+
334
+ // return temp
335
+ // }
336
+
337
+ // function handleDataValue(value) {
338
+ // if (typeof value === 'string') {
339
+ // return {
340
+ // type: 'str',
341
+ // stringValue: value
342
+ // }
343
+ // } else if (typeof value === 'number') {
344
+ // if (Number.isInteger(value)) {
345
+ // return {
346
+ // type: 'int',
347
+ // intValue: value
348
+ // }
349
+ // } else {
350
+ // return {
351
+ // type: 'dbl',
352
+ // doubleValue: value
353
+ // }
354
+ // }
355
+ // } else {
356
+ // return {
357
+ // type: 'str',
358
+ // stringValue: 'undefined'
359
+ // }
360
+ // }
361
+ // }
362
+ // // let date1 = new Date();
363
+ // // let date2 = new Date();
364
+ // // const handled = handleData(jsonData)
365
+ // // setInterval(async () => {
366
+ // // console.log('下一次循环')
367
+ // // date1 = new Date()
368
+ // // const chunk = Series.create(handled);
369
+ // // const serialized = Series.encode(chunk).finish();
370
+
371
+ // // // 4. 创建带长度头的消息(解决边界问题)
372
+ // // const header = Buffer.alloc(4);
373
+ // // header.writeUInt32BE(serialized.length);
374
+ // // const dataWithHeader = Buffer.concat([header, serialized]);
375
+ // // const compressedData = zlib.gzipSync(dataWithHeader);
376
+ // // await writer.write(compressedData)
377
+ // // }, 5000);
378
+
379
+
380
+
381
+ // function readAndProcessGzip(filePath) {
382
+ // try {
383
+ // // 1. 同步读取GZIP压缩文件
384
+ // let compressedData = fs.readFileSync(filePath);
385
+ // const header = Buffer.from(compressedData, 0, 4);
386
+ // compressedData = compressedData.subarray(4);
387
+ // const chunkSize = header.readUInt32BE();
388
+ // // 2. 同步解压GZIP数据
389
+ // let decompressedData = zlib.gunzipSync(compressedData);
390
+ // // console.log(decompressedData)
391
+ // // 3. 分块解析数据(假设格式为:[4字节长度头] + [序列化数据])
392
+ // let offset = 0;
393
+ // const chunks = [];
394
+ // console.log(decompressedData.length)
395
+
396
+ // console.log('chunkSize',chunkSize)
397
+
398
+ // while (offset < decompressedData.length) {
399
+ // // 3.1 检查长度头完整性(需4字节)
400
+ // if (offset + 4 > decompressedData.length) {
401
+ // throw new Error("Incomplete header at end of file");
402
+ // }
403
+
404
+ // // 3.2 读取消息长度(大端序)
405
+ // const msgLength = decompressedData.readUInt32BE(offset);
406
+ // offset += 4;
407
+
408
+ // // 3.3 检查消息体完整性
409
+ // // if (offset + msgLength > decompressedData.length) {
410
+ // // throw new Error(`Incomplete data: expected ${msgLength} bytes, got ${decompressedData.length - offset}`);
411
+ // // }
412
+
413
+ // // 3.4 提取单条消息的Buffer
414
+ // const msgBuffer = decompressedData.slice(offset, msgLength + offset);
415
+ // decompressedData = decompressedData.slice(msgLength + offset);
416
+ // offset= 0;
417
+
418
+ // chunks.push(msgBuffer);
419
+ // }
420
+
421
+ // return chunks; // 返回解析后的Buffer数组
422
+ // } catch (err) {
423
+ // console.error("Processing failed:", err);
424
+ // throw err; // 向上抛出异常
425
+ // }
426
+ // }
427
+
428
+ // // // 使用示例
429
+ // // const filePath = 'test_111.dat';
430
+ // // // const filePath = 'test_1755569497065_0.dat';
431
+ // // const date1 = new Date()
432
+ // // const parsedChunks = readAndProcessGzip(filePath);
433
+ // // const date2 = new Date()
434
+ // // console.log("读取时间:", (date2.getTime() - date1.getTime()) / 1000);
435
+ // // console.log(`Parsed ${parsedChunks.length} chunks`);
436
+
437
+ // // parsedChunks.forEach((buf, i) => {
438
+ // // // console.log(buf)
439
+ // // const decoded = Series.decode(buf);
440
+ // // console.log('读取数据长度:', decoded.series[0].value.length);
441
+ // // console.log('读取数据第一个数据:', decoded.series[0].value[0]);
442
+
443
+ // // console.log('读取数据:', decoded.time[0]);
444
+ // // });
445
+
446
+ // // console.log('处理时间:', (new Date().getTime() - date2.getTime()) / 1000);
447
+
448
+ // const filePath = 'G:\\testchunk\\双板测试通讯_线性图_Z2ooQ_20250827_150827.dat';
449
+ // const { pipeline } = require('stream');
450
+ // const readHeaderStream = fs.createReadStream(filePath,{start:0, end:3});
451
+ // let headerBuffer = Buffer.alloc(0);
452
+
453
+ // // 收集前4字节数据
454
+ // readHeaderStream.on('data', (chunk) => {
455
+ // headerBuffer = Buffer.concat([headerBuffer, chunk]);
456
+ // console.log('chunkkkkkkSize',headerBuffer.readUInt32BE())
457
+ // });
458
+
459
+ // // 等待头部读取完成
460
+
461
+ // const readStream = fs.createReadStream(filePath,{start:4});
462
+ // // 2. 创建解压流(Gunzip)
463
+ // const gunzipStream = zlib.createGunzip();
464
+ // // 3. 初始化数组存储解压后的数据块
465
+
466
+ // const decompressedData = Buffer.alloc(0)
467
+
468
+ // const chunks = [];
469
+ // // 4. 监听解压流的数据事件,收集数据块
470
+ // class ChunkProcessor extends Transform {
471
+ // constructor(decompressedData) {
472
+ // super();
473
+ // this.arr = decompressedData
474
+ // }
475
+
476
+ // _transform(chunk, encoding, callback) {
477
+ // // 将当前 chunk 加入阻塞队列
478
+ // // console.log(chunk.length)
479
+ // // console.log(this.arr)
480
+ // try {
481
+ // this.arr = Buffer.concat([this.arr, chunk]);
482
+ // let offset = 0;
483
+ // while (offset <= this.arr.length) {
484
+ // // 3.1 检查长度头完整性(需4字节)
485
+ // if (offset + 4 > this.arr.length) {
486
+ // break
487
+ // }
488
+
489
+ // // 3.2 读取消息长度(大端序)
490
+ // const msgLength = this.arr.readUInt32BE(offset);
491
+ // offset += 4;
492
+ // // console.log(msgLength)
493
+ // // 3.3 检查消息体完整性
494
+ // if (offset + msgLength > this.arr.length) {
495
+ // break;
496
+ // }
497
+
498
+ // // 3.4 提取单条消息的Buffer
499
+ // const msgBuffer = this.arr.slice(offset, msgLength + offset);
500
+ // this.arr = this.arr.slice(msgLength + offset);
501
+ // offset= 0;
502
+ // // console.log(msgBuffer.length)
503
+ // chunks.push(msgBuffer);
504
+
505
+ // }
506
+ // callback();
507
+ // } catch (err) {
508
+ // console.error("Pipeline error:", err);
509
+ // callback(err);
510
+ // }
511
+ // }
512
+ // }
513
+
514
+
515
+ // readStream.pipe(gunzipStream).pipe(new ChunkProcessor(decompressedData)).on('error', err => console.error('Pipeline error:', err)).on('finish', () => {
516
+ // console.log('读取chunk个:', chunks.length);
517
+ // let sum = 0
518
+ // chunks.forEach((buf, i) => {
519
+ // // console.log(buf)
520
+ // const decoded = Series.decode(buf);
521
+
522
+ // decoded.series.forEach((item, index) => {
523
+ // console.log(item.value[item.value.length - 1].intValue)
524
+ // })
525
+ // console.log('读取数据长度:', decoded.series[0].value.length);
526
+ // sum += decoded.series[0].value.length
527
+ // // console.log('读取数据第一个数据:', decoded.series[0].value[0]);
528
+
529
+ // // console.log('读取数据:', decoded.time[0]);
530
+ // });
531
+ // console.log('读取数据总长度:', sum);
532
+
533
+ // });
534
+
535
+
package/test_111.dat ADDED
Binary file