@@ -3,9 +3,10 @@ use crate::{
3
3
Error , Result ,
4
4
} ;
5
5
use chrono:: { DateTime , Utc } ;
6
+ use h3o:: CellIndex ;
6
7
use helium_crypto:: PublicKeyBinary ;
7
8
use helium_proto:: services:: poc_mobile:: {
8
- self as proto, RadioLocationEstimateV1 , RadioLocationEstimatesReqV1 , RleEventV1 ,
9
+ self as proto, RadioLocationCorrelationV1 , RadioLocationEstimateV1 , RadioLocationEstimatesReqV1 ,
9
10
} ;
10
11
use rust_decimal:: Decimal ;
11
12
use serde:: { Deserialize , Serialize } ;
@@ -108,73 +109,77 @@ impl TryFrom<RadioLocationEstimatesReqV1> for RadioLocationEstimatesReq {
108
109
109
110
#[ derive( Clone , Deserialize , Serialize , Debug , PartialEq ) ]
110
111
pub struct RadioLocationEstimate {
111
- pub radius : Decimal ,
112
- pub lat : Decimal ,
113
- pub lon : Decimal ,
112
+ pub hex : CellIndex ,
113
+ pub grid_distance : u32 ,
114
114
pub confidence : Decimal ,
115
- pub events : Vec < RadioLocationEstimateEvent > ,
115
+ pub radio_location_correlations : Vec < RadioLocationCorrelation > ,
116
116
}
117
117
118
118
impl From < RadioLocationEstimate > for RadioLocationEstimateV1 {
119
119
fn from ( rle : RadioLocationEstimate ) -> Self {
120
120
RadioLocationEstimateV1 {
121
- radius : Some ( to_proto_decimal ( rle. radius ) ) ,
122
- lat : Some ( to_proto_decimal ( rle. lat ) ) ,
123
- lon : Some ( to_proto_decimal ( rle. lon ) ) ,
121
+ hex : rle. hex . into ( ) ,
122
+ grid_distance : rle. grid_distance ,
124
123
confidence : Some ( to_proto_decimal ( rle. confidence ) ) ,
125
- events : rle. events . into_iter ( ) . map ( |e| e. into ( ) ) . collect ( ) ,
124
+ radio_location_correlations : rle
125
+ . radio_location_correlations
126
+ . into_iter ( )
127
+ . map ( |e| e. into ( ) )
128
+ . collect ( ) ,
126
129
}
127
130
}
128
131
}
129
132
130
133
impl TryFrom < RadioLocationEstimateV1 > for RadioLocationEstimate {
131
134
type Error = Error ;
132
135
fn try_from ( estimate : RadioLocationEstimateV1 ) -> Result < Self > {
136
+ let hex = CellIndex :: try_from ( estimate. hex )
137
+ . map_err ( crate :: error:: DecodeError :: InvalidCellIndexError ) ?;
138
+
133
139
Ok ( Self {
134
- radius : to_rust_decimal ( estimate. radius . unwrap ( ) ) ,
135
- lat : to_rust_decimal ( estimate. lat . unwrap ( ) ) ,
136
- lon : to_rust_decimal ( estimate. lon . unwrap ( ) ) ,
137
- confidence : to_rust_decimal ( estimate. confidence . unwrap ( ) ) ,
138
- events : estimate
139
- . events
140
+ hex,
141
+ grid_distance : estimate. grid_distance ,
142
+ confidence : to_rust_decimal ( estimate. confidence ) ?,
143
+ radio_location_correlations : estimate
144
+ . radio_location_correlations
140
145
. into_iter ( )
141
- . map ( |e| e . try_into ( ) . unwrap ( ) )
146
+ . flat_map ( |rlc| rlc . try_into ( ) )
142
147
. collect ( ) ,
143
148
} )
144
149
}
145
150
}
146
151
147
152
#[ derive( Clone , Deserialize , Serialize , Debug , PartialEq ) ]
148
- pub struct RadioLocationEstimateEvent {
153
+ pub struct RadioLocationCorrelation {
149
154
pub id : String ,
150
155
pub timestamp : DateTime < Utc > ,
151
156
}
152
157
153
- impl MsgTimestamp < Result < DateTime < Utc > > > for RleEventV1 {
158
+ impl MsgTimestamp < Result < DateTime < Utc > > > for RadioLocationCorrelationV1 {
154
159
fn timestamp ( & self ) -> Result < DateTime < Utc > > {
155
160
self . timestamp . to_timestamp ( )
156
161
}
157
162
}
158
163
159
- impl MsgTimestamp < u64 > for RadioLocationEstimateEvent {
164
+ impl MsgTimestamp < u64 > for RadioLocationCorrelation {
160
165
fn timestamp ( & self ) -> u64 {
161
166
self . timestamp . encode_timestamp ( )
162
167
}
163
168
}
164
169
165
- impl From < RadioLocationEstimateEvent > for RleEventV1 {
166
- fn from ( event : RadioLocationEstimateEvent ) -> Self {
170
+ impl From < RadioLocationCorrelation > for RadioLocationCorrelationV1 {
171
+ fn from ( event : RadioLocationCorrelation ) -> Self {
167
172
let timestamp = event. timestamp ( ) ;
168
- RleEventV1 {
173
+ RadioLocationCorrelationV1 {
169
174
id : event. id ,
170
175
timestamp,
171
176
}
172
177
}
173
178
}
174
179
175
- impl TryFrom < RleEventV1 > for RadioLocationEstimateEvent {
180
+ impl TryFrom < RadioLocationCorrelationV1 > for RadioLocationCorrelation {
176
181
type Error = Error ;
177
- fn try_from ( event : RleEventV1 ) -> Result < Self > {
182
+ fn try_from ( event : RadioLocationCorrelationV1 ) -> Result < Self > {
178
183
let timestamp = event. timestamp ( ) ?;
179
184
Ok ( Self {
180
185
id : event. id ,
@@ -183,9 +188,10 @@ impl TryFrom<RleEventV1> for RadioLocationEstimateEvent {
183
188
}
184
189
}
185
190
186
- fn to_rust_decimal ( x : helium_proto:: Decimal ) -> rust_decimal:: Decimal {
191
+ fn to_rust_decimal ( x : Option < helium_proto:: Decimal > ) -> Result < rust_decimal:: Decimal > {
192
+ let x = x. ok_or ( Error :: NotFound ( "Decimal" . to_string ( ) ) ) ?;
187
193
let str = x. value . as_str ( ) ;
188
- rust_decimal:: Decimal :: from_str_exact ( str) . unwrap ( )
194
+ Ok ( rust_decimal:: Decimal :: from_str_exact ( str) ? )
189
195
}
190
196
191
197
fn to_proto_decimal ( x : rust_decimal:: Decimal ) -> helium_proto:: Decimal {
0 commit comments