MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / handle_stream

Function handle_stream

chirpstack/src/stream/frame.rs:281–376  ·  view source on GitHub ↗
(
    stream_id: &str,
    channel: &mpsc::Sender<api::LogItem>,
    k: &str,
    v: &redis::Value,
)

Source from the content-addressed store, hash-verified

279}
280
281async fn handle_stream(
282 stream_id: &str,
283 channel: &mpsc::Sender<api::LogItem>,
284 k: &str,
285 v: &redis::Value,
286) -> Result<()> {
287 match k {
288 "up" => {
289 trace!(key = %k, id = %stream_id, "Frame-log received from stream");
290 if let redis::Value::BulkString(b) = v {
291 let pl = stream::UplinkFrameLog::decode(&mut Cursor::new(b))?;
292 let mut phy = lrwn::PhyPayload::from_slice(&pl.phy_payload)?;
293 if pl.plaintext_f_opts
294 && let Err(e) = phy.decode_f_opts_to_mac_commands()
295 {
296 warn!(error = %e.full(), "Decode f_opts to mac-commands error");
297 }
298 if pl.plaintext_frm_payload
299 && let Err(e) = phy.decode_frm_payload()
300 {
301 warn!(error = %e.full(), "Decode frm_payload error");
302 }
303
304 let pl = api::LogItem {
305 id: stream_id.to_string(),
306 time: pl.time.as_ref().map(|t| prost_types::Timestamp {
307 seconds: t.seconds,
308 nanos: t.nanos,
309 }),
310 description: pl.f_type().into(),
311 body: json!({
312 "phy_payload": phy,
313 "tx_info": pl.tx_info,
314 "rx_info": pl.rx_info,
315 })
316 .to_string(),
317 properties: [
318 ("DevAddr".to_string(), pl.dev_addr),
319 ("DevEUI".to_string(), pl.dev_eui),
320 ]
321 .iter()
322 .cloned()
323 .collect(),
324 };
325
326 channel.send(pl).await?;
327 }
328 }
329 "down" => {
330 trace!(key = %k, id = %stream_id, "frame-log received from stream");
331 if let redis::Value::BulkString(b) = v {
332 let pl = stream::DownlinkFrameLog::decode(&mut Cursor::new(b))?;
333 let mut phy = lrwn::PhyPayload::from_slice(&pl.phy_payload)?;
334 if pl.plaintext_f_opts
335 && let Err(e) = phy.decode_f_opts_to_mac_commands()
336 {
337 warn!(error = %e.full(), "Decode f_opts to mac-commands error");
338 }

Callers 1

get_frame_logsFunction · 0.70

Calls 7

decode_frm_payloadMethod · 0.80
to_stringMethod · 0.80
as_refMethod · 0.80
iterMethod · 0.80
decodeFunction · 0.50
intoMethod · 0.45

Tested by

no test coverage detected