@@ -331,7 +331,68 @@ const closeCloudMonitor = (deviceId) => {
331
331
return unsubscribe ( cloudMonitorOutputTopic ) ;
332
332
} ;
333
333
334
- const sendProperty = ( thingId , name , value , timestamp ) => {
334
+ const toCloudProtocolV2 = ( cborValue ) => {
335
+ const cloudV2CBORValue = { } ;
336
+ let cborLabel = null ;
337
+
338
+ Object . keys ( cborValue ) . forEach ( ( label ) => {
339
+ switch ( label ) {
340
+ case 'bn' :
341
+ cborLabel = - 2 ;
342
+ break ;
343
+ case 'bt' :
344
+ cborLabel = - 3 ;
345
+ break ;
346
+ case 'bu' :
347
+ cborLabel = - 4 ;
348
+ break ;
349
+ case 'bv' :
350
+ cborLabel = - 5 ;
351
+ break ;
352
+ case 'bs' :
353
+ cborLabel = - 6 ;
354
+ break ;
355
+ case 'bver' :
356
+ cborLabel = - 1 ;
357
+ break ;
358
+ case 'n' :
359
+ cborLabel = 0 ;
360
+ break ;
361
+ case 'u' :
362
+ cborLabel = 1 ;
363
+ break ;
364
+ case 'v' :
365
+ cborLabel = 2 ;
366
+ break ;
367
+ case 'vs' :
368
+ cborLabel = 3 ;
369
+ break ;
370
+ case 'vb' :
371
+ cborLabel = 4 ;
372
+ break ;
373
+ case 'vd' :
374
+ cborLabel = 8 ;
375
+ break ;
376
+ case 's' :
377
+ cborLabel = 5 ;
378
+ break ;
379
+ case 't' :
380
+ cborLabel = 6 ;
381
+ break ;
382
+ case 'ut' :
383
+ cborLabel = 7 ;
384
+ break ;
385
+ default :
386
+ cborLabel = label ;
387
+ }
388
+
389
+ cloudV2CBORValue [ cborLabel ] = cborValue [ label ] ;
390
+ } ) ;
391
+
392
+ return cloudV2CBORValue ;
393
+ } ;
394
+
395
+ const sendProperty = ( thingId , name , value , timestamp , useCloudProtocolV2 = false ) => {
335
396
const propertyInputTopic = `/a/t/${ thingId } /e/i` ;
336
397
337
398
if ( timestamp && ! Number . isInteger ( timestamp ) ) {
@@ -342,7 +403,7 @@ const sendProperty = (thingId, name, value, timestamp) => {
342
403
throw new Error ( 'Name must be a valid string' ) ;
343
404
}
344
405
345
- const cborValue = {
406
+ let cborValue = {
346
407
bt : timestamp || new Date ( ) . getTime ( ) ,
347
408
n : name ,
348
409
} ;
@@ -361,10 +422,14 @@ const sendProperty = (thingId, name, value, timestamp) => {
361
422
break ;
362
423
}
363
424
425
+ if ( useCloudProtocolV2 ) {
426
+ cborValue = toCloudProtocolV2 ( cborValue ) ;
427
+ }
428
+
364
429
return sendMessage ( propertyInputTopic , CBOR . encode ( [ cborValue ] ) ) ;
365
430
} ;
366
431
367
- const getSenml = ( deviceId , name , value , timestamp ) => {
432
+ const getSenml = ( deviceId , name , value , timestamp , useCloudProtocolV2 = false ) => {
368
433
if ( timestamp && ! Number . isInteger ( timestamp ) ) {
369
434
throw new Error ( 'Timestamp must be Integer' ) ;
370
435
}
@@ -395,6 +460,12 @@ const getSenml = (deviceId, name, value, timestamp) => {
395
460
default :
396
461
break ;
397
462
}
463
+
464
+
465
+ if ( useCloudProtocolV2 ) {
466
+ return toCloudProtocolV2 ( senMl ) ;
467
+ }
468
+
398
469
return senMl ;
399
470
} ;
400
471
0 commit comments