@@ -13,6 +13,7 @@ const LPP_TEMPERATURE_SENSOR: u8 = 103;
13
13
const LPP_HUMIDITY_SENSOR : u8 = 104 ;
14
14
const LPP_ACCELEROMETER : u8 = 113 ;
15
15
const LPP_BAROMETER : u8 = 115 ;
16
+ const LPP_DISTANCE : u8 = 130 ;
16
17
const LPP_GYROMETER : u8 = 134 ;
17
18
const LPP_GPS_LOCATION : u8 = 136 ;
18
19
@@ -56,6 +57,7 @@ struct CayenneLpp {
56
57
humidity_sensor : BTreeMap < u8 , f64 > ,
57
58
accelerometer : BTreeMap < u8 , Accelerometer > ,
58
59
barometer : BTreeMap < u8 , f64 > ,
60
+ distance : BTreeMap < u8 , f64 > ,
59
61
gyrometer : BTreeMap < u8 , Gyrometer > ,
60
62
gps_location : BTreeMap < u8 , GpsLocation > ,
61
63
}
@@ -82,6 +84,7 @@ impl CayenneLpp {
82
84
LPP_HUMIDITY_SENSOR => lpp. set_humidity_sensor ( buf[ 0 ] , & mut cur) ?,
83
85
LPP_ACCELEROMETER => lpp. set_accelerometer ( buf[ 0 ] , & mut cur) ?,
84
86
LPP_BAROMETER => lpp. set_barometer ( buf[ 0 ] , & mut cur) ?,
87
+ LPP_DISTANCE => lpp. set_distance ( buf[ 0 ] , & mut cur) ?,
85
88
LPP_GYROMETER => lpp. set_gyrometer ( buf[ 0 ] , & mut cur) ?,
86
89
LPP_GPS_LOCATION => lpp. set_gps_location ( buf[ 0 ] , & mut cur) ?,
87
90
_ => {
@@ -124,6 +127,7 @@ impl CayenneLpp {
124
127
. set_accelerometer_from_value ( v)
125
128
. context ( "accelerometer" ) ?,
126
129
"barometer" => lpp. set_barometer_from_value ( v) . context ( "barometer" ) ?,
130
+ "distance" => lpp. set_distance_from_value ( v) . context ( "distance" ) ?,
127
131
"gyrometer" => lpp. set_gyrometer_from_value ( v) . context ( "gyrometer" ) ?,
128
132
"gpsLocation" => lpp. set_gps_location_from_value ( v) . context ( "gpsLocation" ) ?,
129
133
_ => {
@@ -214,6 +218,14 @@ impl CayenneLpp {
214
218
out. extend ( val. to_be_bytes ( ) ) ;
215
219
}
216
220
221
+ // distance
222
+ for ( k, v) in & self . distance {
223
+ out. extend ( [ * k, LPP_DISTANCE ] ) ;
224
+
225
+ let val = ( * v * 1000.0 ) as u32 ;
226
+ out. extend ( val. to_be_bytes ( ) ) ;
227
+ }
228
+
217
229
// gyrometer
218
230
for ( k, v) in & self . gyrometer {
219
231
out. extend ( [ * k, LPP_GYROMETER ] ) ;
@@ -445,6 +457,24 @@ impl CayenneLpp {
445
457
) ;
446
458
}
447
459
460
+ if !self . distance . is_empty ( ) {
461
+ let mut val: pbjson_types:: Struct = Default :: default ( ) ;
462
+ for ( k, v) in & self . distance {
463
+ val. fields . insert (
464
+ format ! ( "{}" , k) ,
465
+ pbjson_types:: Value {
466
+ kind : Some ( pbjson_types:: value:: Kind :: NumberValue ( * v) ) ,
467
+ } ,
468
+ ) ;
469
+ }
470
+ out. fields . insert (
471
+ "distance" . to_string ( ) ,
472
+ pbjson_types:: Value {
473
+ kind : Some ( pbjson_types:: value:: Kind :: StructValue ( val) ) ,
474
+ } ,
475
+ ) ;
476
+ }
477
+
448
478
if !self . gyrometer . is_empty ( ) {
449
479
let mut val: pbjson_types:: Struct = Default :: default ( ) ;
450
480
for ( k, v) in & self . gyrometer {
@@ -769,6 +799,27 @@ impl CayenneLpp {
769
799
Ok ( ( ) )
770
800
}
771
801
802
+ fn set_distance ( & mut self , channel : u8 , cur : & mut Cursor < & [ u8 ] > ) -> Result < ( ) > {
803
+ let mut buf: [ u8 ; 4 ] = [ 0 ; 4 ] ;
804
+ cur. read_exact ( & mut buf) ?;
805
+ let val = u32:: from_be_bytes ( buf) ;
806
+ self . distance . insert ( channel, ( val as f64 ) / 1000.0 ) ;
807
+ Ok ( ( ) )
808
+ }
809
+
810
+ fn set_distance_from_value ( & mut self , v : & prost_types:: Value ) -> Result < ( ) > {
811
+ if let Some ( prost_types:: value:: Kind :: StructValue ( s) ) = & v. kind {
812
+ for ( k, v) in & s. fields {
813
+ let c: u8 = k. parse ( ) ?;
814
+ if let Some ( prost_types:: value:: Kind :: NumberValue ( v) ) = & v. kind {
815
+ self . distance . insert ( c, * v) ;
816
+ }
817
+ }
818
+ }
819
+
820
+ Ok ( ( ) )
821
+ }
822
+
772
823
fn set_gyrometer ( & mut self , channel : u8 , cur : & mut Cursor < & [ u8 ] > ) -> Result < ( ) > {
773
824
let mut buf_x: [ u8 ; 2 ] = [ 0 ; 2 ] ;
774
825
let mut buf_y: [ u8 ; 2 ] = [ 0 ; 2 ] ;
@@ -913,6 +964,7 @@ pub mod test {
913
964
3 , 104 , 41 , 5 , 104 , 150 , // humidity sensors
914
965
3 , 113 , 0 , 1 , 0 , 2 , 0 , 3 , 5 , 113 , 3 , 234 , 7 , 211 , 11 , 187 , // accelerometers
915
966
3 , 115 , 4 , 31 , 5 , 115 , 9 , 196 , // barometers
967
+ 3 , 130 , 0 , 0 , 1 , 16 , 5 , 130 , 1 , 2 , 3 , 4 , // distance
916
968
3 , 134 , 0 , 1 , 0 , 2 , 0 , 3 , 5 , 134 , 3 , 233 , 7 , 210 , 11 , 187 , // gyrometers
917
969
1 , 136 , 6 , 118 , 95 , 242 , 150 , 10 , 0 , 3 , 232 , // gps location
918
970
] ;
@@ -1222,6 +1274,30 @@ pub mod test {
1222
1274
} ) ) ,
1223
1275
} ,
1224
1276
) ,
1277
+ (
1278
+ "distance" . to_string ( ) ,
1279
+ prost_types:: Value {
1280
+ kind : Some ( prost_types:: value:: Kind :: StructValue ( prost_types:: Struct {
1281
+ fields : [
1282
+ (
1283
+ "3" . to_string ( ) ,
1284
+ prost_types:: Value {
1285
+ kind : Some ( prost_types:: value:: Kind :: NumberValue ( 0.272 ) ) ,
1286
+ } ,
1287
+ ) ,
1288
+ (
1289
+ "5" . to_string ( ) ,
1290
+ prost_types:: Value {
1291
+ kind : Some ( prost_types:: value:: Kind :: NumberValue ( 16909.060 ) ) ,
1292
+ } ,
1293
+ ) ,
1294
+ ]
1295
+ . iter ( )
1296
+ . cloned ( )
1297
+ . collect ( ) ,
1298
+ } ) ) ,
1299
+ } ,
1300
+ ) ,
1225
1301
(
1226
1302
"gyrometer" . to_string ( ) ,
1227
1303
prost_types:: Value {
@@ -1704,6 +1780,34 @@ pub mod test {
1704
1780
) ) ,
1705
1781
} ,
1706
1782
) ,
1783
+ (
1784
+ "distance" . to_string ( ) ,
1785
+ pbjson_types:: Value {
1786
+ kind : Some ( pbjson_types:: value:: Kind :: StructValue (
1787
+ pbjson_types:: Struct {
1788
+ fields : [
1789
+ (
1790
+ "3" . to_string ( ) ,
1791
+ pbjson_types:: Value {
1792
+ kind : Some ( pbjson_types:: value:: Kind :: NumberValue ( 0.272 ) ) ,
1793
+ } ,
1794
+ ) ,
1795
+ (
1796
+ "5" . to_string ( ) ,
1797
+ pbjson_types:: Value {
1798
+ kind : Some ( pbjson_types:: value:: Kind :: NumberValue (
1799
+ 16909.060 ,
1800
+ ) ) ,
1801
+ } ,
1802
+ ) ,
1803
+ ]
1804
+ . iter ( )
1805
+ . cloned ( )
1806
+ . collect ( ) ,
1807
+ } ,
1808
+ ) ) ,
1809
+ } ,
1810
+ ) ,
1707
1811
(
1708
1812
"gyrometer" . to_string ( ) ,
1709
1813
pbjson_types:: Value {
0 commit comments