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

Function handle

chirpstack/src/maccommand/notify_new_end_device.rs:10–71  ·  view source on GitHub ↗
(
    t: &tenant::Tenant,
    dp: &device_profile::DeviceProfile,
    app: &application::Application,
    dev: &device::Device,
    block: &lrwn::MACCommandSet,
)

Source from the content-addressed store, hash-verified

8use chirpstack_api::integration as integration_pb;
9
10pub async fn handle(
11 t: &tenant::Tenant,
12 dp: &device_profile::DeviceProfile,
13 app: &application::Application,
14 dev: &device::Device,
15 block: &lrwn::MACCommandSet,
16) -> Result<Option<lrwn::MACCommandSet>> {
17 let req_mac = (**block)
18 .first()
19 .ok_or_else(|| anyhow!("MACCommandSet is empty"))?;
20 let req_pl = if let lrwn::MACCommand::NotifyNewEndDeviceReq(pl) = req_mac {
21 pl
22 } else {
23 return Err(anyhow!("NotifyNewEndDeviceReq is expected"));
24 };
25
26 info!(dev_eui = %dev.dev_eui, ed_dev_addr = %req_pl.dev_addr, "NotifyNewEndDeviceReq received");
27
28 let device_info = integration_pb::DeviceInfo {
29 tenant_id: t.id.to_string(),
30 tenant_name: t.name.clone(),
31 application_id: app.id.to_string(),
32 application_name: app.name.to_string(),
33 device_profile_id: dp.id.to_string(),
34 device_profile_name: dp.name.clone(),
35 device_name: dev.name.clone(),
36 device_class_enabled: dev.enabled_class.to_proto().into(),
37 dev_eui: dev.dev_eui.to_string(),
38 tags: {
39 let mut tags = (*app.tags).clone();
40 tags.extend((*dp.tags).clone());
41 tags.extend((*dev.tags).clone());
42 tags
43 },
44 };
45
46 let log_event = integration_pb::LogEvent {
47 time: Some(Utc::now().into()),
48 device_info: Some(device_info),
49 level: integration_pb::LogLevel::Info.into(),
50 code: integration_pb::LogCode::RelayNewEndDevice.into(),
51 description: "NotifyNewEndDevice received from relay".into(),
52 context: [
53 ("dev_addr".to_string(), req_pl.dev_addr.to_string()),
54 (
55 "wor_snr".to_string(),
56 req_pl.power_level.wor_snr.to_string(),
57 ),
58 (
59 "wor_rssi".to_string(),
60 req_pl.power_level.wor_rssi.to_string(),
61 ),
62 ]
63 .iter()
64 .cloned()
65 .collect(),
66 };
67

Callers 1

test_handleFunction · 0.70

Calls 5

to_stringMethod · 0.80
to_protoMethod · 0.80
iterMethod · 0.80
log_eventFunction · 0.50
intoMethod · 0.45

Tested by 1

test_handleFunction · 0.56