@@ -22,6 +22,7 @@ import { EventEmitter } from "tsee";
2222import { getCliVersion , initCliApp , setupCliApp } from './init-cli-app' ;
2323import { Mutex } from 'async-mutex' ;
2424import WebSocket from 'ws' ;
25+ import encodeLabel from '../shared/encoding' ;
2526
2627const TCP_PREFIX = '\x1b[32m[WS ]\x1b[0m' ;
2728const SERIAL_PREFIX = '\x1b[33m[SER]\x1b[0m' ;
@@ -34,6 +35,8 @@ const apiKeyArgvIx = process.argv.indexOf('--api-key');
3435const apiKeyArgv = apiKeyArgvIx !== - 1 ? process . argv [ apiKeyArgvIx + 1 ] : undefined ;
3536const baudRateArgvIx = process . argv . indexOf ( '--baud-rate' ) ;
3637const baudRateArgv = baudRateArgvIx !== - 1 ? process . argv [ baudRateArgvIx + 1 ] : undefined ;
38+ const whichDeviceArgvIx = process . argv . indexOf ( '--which-device' ) ;
39+ const whichDeviceArgv = whichDeviceArgvIx !== - 1 ? Number ( process . argv [ whichDeviceArgvIx + 1 ] ) : undefined ;
3740
3841let configFactory : Config ;
3942let serial : SerialConnector | undefined ;
@@ -53,7 +56,7 @@ const cliOptions = {
5356} ;
5457
5558class SerialDevice extends ( EventEmitter as new ( ) => TypedEmitter < {
56- snapshot : ( buffer : Buffer ) => void
59+ snapshot : ( buffer : Buffer , filename : string ) => void
5760} > ) implements RemoteMgmtDevice {
5861 private _config : EdgeImpulseConfig ;
5962 private _serial : SerialConnector ;
@@ -116,6 +119,10 @@ class SerialDevice extends (EventEmitter as new () => TypedEmitter<{
116119 return this . _deviceConfig . snapshot . supportsStreaming ;
117120 }
118121
122+ supportsSnapshotStreamingWhileCapturing ( ) {
123+ return false ;
124+ }
125+
119126 async stopSnapshotStreamFromSignal ( ) {
120127 if ( ! this . _waitingForSnapshotToStart && ! this . _snapshotStream ) {
121128 return ;
@@ -211,7 +218,7 @@ class SerialDevice extends (EventEmitter as new () => TypedEmitter<{
211218 height : height ,
212219 } , 80 ) ;
213220
214- this . emit ( 'snapshot' , jpegImageData . data ) ;
221+ this . emit ( 'snapshot' , jpegImageData . data , '' ) ;
215222 this . _lastSnapshot = new Date ( ) ;
216223 }
217224 }
@@ -350,11 +357,12 @@ class SerialDevice extends (EventEmitter as new () => TypedEmitter<{
350357
351358 let headers : { [ k : string ] : string } = {
352359 'x-api-key' : this . _deviceConfig . upload . apiKey ,
353- 'x-file-name' : filename ,
360+ 'x-file-name' : encodeLabel ( filename ) ,
354361 'Content-Type' : ( ! processed . attachments ? processed . contentType : 'multipart/form-data' ) ,
355362 'Connection' : 'keep-alive'
356363 } ;
357- headers [ 'x-label' ] = s . label ;
364+
365+ headers [ 'x-label' ] = encodeLabel ( s . label ) ;
358366
359367 let url = this . _config . endpoints . internal . ingestion + s . path ;
360368 console . log ( SERIAL_PREFIX , 'Uploading to' , url ) ;
@@ -427,8 +435,8 @@ class SerialDevice extends (EventEmitter as new () => TypedEmitter<{
427435 await request.post(url, {
428436 headers : {
429437 'x-api-key' : this . _deviceConfig . upload . apiKey ,
430- 'x-file-name' : deviceResponse . filename ,
431- 'x-label' : dr . label ,
438+ 'x-file-name' : encodeLabel ( deviceResponse . filename ) ,
439+ 'x-label' : encodeLabel ( dr . label ) ,
432440 'Content-Type' : 'application/octet-stream'
433441 } ,
434442 body : deviceResponse . file ,
@@ -439,7 +447,7 @@ class SerialDevice extends (EventEmitter as new () => TypedEmitter<{
439447 await request . post ( url , {
440448 headers : {
441449 'x-api-key' : this . _deviceConfig . upload . apiKey ,
442- 'x-file-name' : deviceResponse . filename ,
450+ 'x-file-name' : encodeLabel ( deviceResponse . filename ) ,
443451 'Content-Type' : 'application/cbor'
444452 } ,
445453 body : deviceResponse . file ,
@@ -482,7 +490,7 @@ class SerialDevice extends (EventEmitter as new () => TypedEmitter<{
482490 console . log ( ' Ingestion:' , config . endpoints . internal . ingestion ) ;
483491 console . log ( '' ) ;
484492
485- let deviceId = await findSerial ( ) ;
493+ let deviceId = await findSerial ( whichDeviceArgv ) ;
486494 await connectToSerial ( config , deviceId , baudRate , ( cleanArgv || apiKeyArgv ) ? true : false ) ;
487495 }
488496 catch (ex) {
0 commit comments