tangled
alpha
login
or
join now
sachy.dev
/
pico-strike
0
fork
atom
A RPi Pico powered Lightning Detector
0
fork
atom
overview
issues
pulls
pipelines
Updated detector rpc configuration
sachy.dev
6 days ago
fa752e8e
ac811d43
+120
-47
6 changed files
expand all
collapse all
unified
split
Cargo.lock
src
detector.rs
locks.rs
rpc.rs
state.rs
updates.rs
+33
-26
Cargo.lock
···
93
93
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
94
94
95
95
[[package]]
96
96
+
name = "base64ct"
97
97
+
version = "1.8.3"
98
98
+
source = "registry+https://github.com/rust-lang/crates.io-index"
99
99
+
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
100
100
+
101
101
+
[[package]]
96
102
name = "bit-set"
97
103
version = "0.8.0"
98
104
source = "registry+https://github.com/rust-lang/crates.io-index"
···
571
577
[[package]]
572
578
name = "embassy-strike-driver"
573
579
version = "0.1.0"
574
574
-
source = "git+https://tangled.org/sachy.dev/strike-sensor#99f235f794688d6f7756f64b4e0224571421b9a1"
580
580
+
source = "git+https://tangled.org/sachy.dev/strike-sensor#20f871621244db023615d50c3a1be42470e7c73a"
575
581
dependencies = [
576
582
"defmt 1.0.1",
577
583
"embassy-rp",
···
961
967
962
968
[[package]]
963
969
name = "jiff"
964
964
-
version = "0.2.21"
970
970
+
version = "0.2.23"
965
971
source = "registry+https://github.com/rust-lang/crates.io-index"
966
966
-
checksum = "b3e3d65f018c6ae946ab16e80944b97096ed73c35b221d1c478a6c81d8f57940"
972
972
+
checksum = "1a3546dc96b6d42c5f24902af9e2538e82e39ad350b0c766eb3fbf2d8f3d8359"
967
973
dependencies = [
968
974
"jiff-static",
969
975
"portable-atomic",
···
972
978
973
979
[[package]]
974
980
name = "jiff-static"
975
975
-
version = "0.2.21"
981
981
+
version = "0.2.23"
976
982
source = "registry+https://github.com/rust-lang/crates.io-index"
977
977
-
checksum = "a17c2b211d863c7fde02cbea8a3c1a439b98e109286554f2860bdded7ff83818"
983
983
+
checksum = "2a8c8b344124222efd714b73bb41f8b5120b27a7cc1c75593a6ff768d9d05aa4"
978
984
dependencies = [
979
985
"proc-macro2",
980
986
"quote",
···
1024
1030
1025
1031
[[package]]
1026
1032
name = "libc"
1027
1027
-
version = "0.2.182"
1033
1033
+
version = "0.2.183"
1028
1034
source = "registry+https://github.com/rust-lang/crates.io-index"
1029
1029
-
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
1035
1035
+
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
1030
1036
1031
1037
[[package]]
1032
1038
name = "linux-raw-sys"
···
1292
1298
1293
1299
[[package]]
1294
1300
name = "pin-project-lite"
1295
1295
-
version = "0.2.16"
1301
1301
+
version = "0.2.17"
1296
1302
source = "registry+https://github.com/rust-lang/crates.io-index"
1297
1297
-
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
1303
1303
+
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
1298
1304
1299
1305
[[package]]
1300
1306
name = "pio"
···
1414
1420
1415
1421
[[package]]
1416
1422
name = "quote"
1417
1417
-
version = "1.0.44"
1423
1423
+
version = "1.0.45"
1418
1424
source = "registry+https://github.com/rust-lang/crates.io-index"
1419
1419
-
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
1425
1425
+
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
1420
1426
dependencies = [
1421
1427
"proc-macro2",
1422
1428
]
···
1546
1552
[[package]]
1547
1553
name = "sachy-config"
1548
1554
version = "0.1.0"
1549
1549
-
source = "git+https://tangled.org/sachy.dev/sachy-embed-core#7f489f3300e0769817b6b8f7394eb36c8e3f8a03"
1555
1555
+
source = "git+https://tangled.org/sachy.dev/sachy-embed-core#ee60e727e6d412cd13009809eb08f51a9b441b44"
1550
1556
dependencies = [
1557
1557
+
"base64ct",
1551
1558
"miette",
1552
1559
"toml_edit",
1553
1560
]
···
1555
1562
[[package]]
1556
1563
name = "sachy-fmt"
1557
1564
version = "0.1.0"
1558
1558
-
source = "git+https://tangled.org/sachy.dev/sachy-embed-core#7f489f3300e0769817b6b8f7394eb36c8e3f8a03"
1565
1565
+
source = "git+https://tangled.org/sachy.dev/sachy-embed-core#ee60e727e6d412cd13009809eb08f51a9b441b44"
1559
1566
dependencies = [
1560
1567
"defmt 1.0.1",
1561
1568
]
···
1563
1570
[[package]]
1564
1571
name = "sachy-mdns"
1565
1572
version = "0.1.0"
1566
1566
-
source = "git+https://tangled.org/sachy.dev/sachy-embed-core#7f489f3300e0769817b6b8f7394eb36c8e3f8a03"
1573
1573
+
source = "git+https://tangled.org/sachy.dev/sachy-embed-core#ee60e727e6d412cd13009809eb08f51a9b441b44"
1567
1574
dependencies = [
1568
1575
"defmt 1.0.1",
1569
1576
"embassy-time",
···
1574
1581
[[package]]
1575
1582
name = "sachy-sntp"
1576
1583
version = "0.1.0"
1577
1577
-
source = "git+https://tangled.org/sachy.dev/sachy-embed-core#7f489f3300e0769817b6b8f7394eb36c8e3f8a03"
1584
1584
+
source = "git+https://tangled.org/sachy.dev/sachy-embed-core#ee60e727e6d412cd13009809eb08f51a9b441b44"
1578
1585
dependencies = [
1579
1586
"defmt 1.0.1",
1580
1587
"embassy-net",
···
1721
1728
[[package]]
1722
1729
name = "striker-proto"
1723
1730
version = "0.1.0"
1724
1724
-
source = "git+https://tangled.org/sachy.dev/striker#9ba3ebbda1208b254b6677d7c385cf79de61bad6"
1731
1731
+
source = "git+https://tangled.org/sachy.dev/striker#c4fbeb50a975419c7034ea3523fc3cf05d14008c"
1725
1732
dependencies = [
1726
1733
"postcard",
1727
1734
"serde",
···
1861
1868
1862
1869
[[package]]
1863
1870
name = "toml_datetime"
1864
1864
-
version = "0.7.5+spec-1.1.0"
1871
1871
+
version = "1.0.0+spec-1.1.0"
1865
1872
source = "registry+https://github.com/rust-lang/crates.io-index"
1866
1866
-
checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347"
1873
1873
+
checksum = "32c2555c699578a4f59f0cc68e5116c8d7cabbd45e1409b989d4be085b53f13e"
1867
1874
dependencies = [
1868
1875
"serde_core",
1869
1876
]
1870
1877
1871
1878
[[package]]
1872
1879
name = "toml_edit"
1873
1873
-
version = "0.24.1+spec-1.1.0"
1880
1880
+
version = "0.25.4+spec-1.1.0"
1874
1881
source = "registry+https://github.com/rust-lang/crates.io-index"
1875
1875
-
checksum = "01f2eadbbc6b377a847be05f60791ef1058d9f696ecb51d2c07fe911d8569d8e"
1882
1882
+
checksum = "7193cbd0ce53dc966037f54351dbbcf0d5a642c7f0038c382ef9e677ce8c13f2"
1876
1883
dependencies = [
1877
1884
"indexmap",
1878
1885
"toml_datetime",
···
2069
2076
2070
2077
[[package]]
2071
2078
name = "winnow"
2072
2072
-
version = "0.7.14"
2079
2079
+
version = "0.7.15"
2073
2080
source = "registry+https://github.com/rust-lang/crates.io-index"
2074
2074
-
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
2081
2081
+
checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
2075
2082
dependencies = [
2076
2083
"memchr",
2077
2084
]
2078
2085
2079
2086
[[package]]
2080
2087
name = "zerocopy"
2081
2081
-
version = "0.8.39"
2088
2088
+
version = "0.8.40"
2082
2089
source = "registry+https://github.com/rust-lang/crates.io-index"
2083
2083
-
checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a"
2090
2090
+
checksum = "a789c6e490b576db9f7e6b6d661bcc9799f7c0ac8352f56ea20193b2681532e5"
2084
2091
dependencies = [
2085
2092
"zerocopy-derive",
2086
2093
]
2087
2094
2088
2095
[[package]]
2089
2096
name = "zerocopy-derive"
2090
2090
-
version = "0.8.39"
2097
2097
+
version = "0.8.40"
2091
2098
source = "registry+https://github.com/rust-lang/crates.io-index"
2092
2092
-
checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517"
2099
2099
+
checksum = "f65c489a7071a749c849713807783f70672b28094011623e200cb86dcb835953"
2093
2100
dependencies = [
2094
2101
"proc-macro2",
2095
2102
"quote",
+21
-6
src/detector.rs
···
1
1
use alloc::vec::Vec;
2
2
use sachy_fmt::{info, unwrap};
3
3
4
4
-
use embassy_futures::select::select3;
4
4
+
use embassy_futures::select::select4;
5
5
use embassy_rp::peripherals::DMA_CH1;
6
6
use embassy_strike_driver::{
7
7
-
DetectorConfig, DetectorDriver, ZeroCopyChannel,
7
7
+
DetectorDriver, ZeroCopyChannel,
8
8
drivers::rp::{AdcDriver, PwmDriver},
9
9
+
traits::{AdcSource, PwmSource, TimeSource},
9
10
};
10
11
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, zerocopy_channel::Channel as ZChannel};
11
12
use embassy_time::Timer;
12
13
13
14
use crate::{
14
14
-
constants::{BLIP_SIZE, BLIP_THRESHOLD, BLOCK_SIZE},
15
15
+
constants::BLOCK_SIZE,
15
16
rtc::GlobalRtc,
16
16
-
updates::UpdateConnection,
17
17
+
updates::{DetectorConfigurationHandle, UpdateConnection},
17
18
utils::{static_alloc, try_buffer, try_static_timestamped_block_vecs},
18
19
};
19
20
···
39
40
40
41
let (mut sender, mut receiver) = buf_channel.split();
41
42
42
42
-
let config = DetectorConfig::new(BLIP_THRESHOLD, BLIP_SIZE);
43
43
+
let config = DetectorConfigurationHandle::get_config();
43
44
let mut detector = DetectorDriver::new(config, rtc.track_time().await, pwm, adc);
44
45
let mut samples = unwrap!(try_buffer(64), "Failed to allocate sample buffer");
45
46
let mut peaks = Vec::new();
···
52
53
loop {
53
54
detector.tune(samples.as_mut_slice()).await;
54
55
55
55
-
select3(
56
56
+
select4(
57
57
+
update_detector_config(&detector),
56
58
detector.sample_with_zerocopy(&mut sender),
57
59
detector.detect_with_zerocopy(
58
60
&mut receiver,
···
66
68
detector.reset_timer_source(rtc).await;
67
69
}
68
70
}
71
71
+
72
72
+
async fn update_detector_config<T, P, A>(detector: &DetectorDriver<T, P, A>)
73
73
+
where
74
74
+
T: TimeSource,
75
75
+
P: PwmSource,
76
76
+
A: AdcSource,
77
77
+
{
78
78
+
loop {
79
79
+
let update = DetectorConfigurationHandle::get_updated_config().await;
80
80
+
81
81
+
detector.set_config(update);
82
82
+
}
83
83
+
}
+1
src/locks.rs
···
4
4
pub type RtcLock = SpinlockRawMutex<1>;
5
5
pub type ConnectionStatusLock = SpinlockRawMutex<2>;
6
6
pub type NetDataLock = SpinlockRawMutex<3>;
7
7
+
pub type ConfigUpdateLock = SpinlockRawMutex<4>;
+20
-11
src/rpc.rs
···
1
1
-
use alloc::string::ToString;
2
1
use striker_proto::{Request, Response, StrikerRequest, StrikerResponse};
3
2
4
4
-
use crate::constants::{BLIP_SIZE, BLIP_THRESHOLD};
3
3
+
use crate::updates::{DetectorConfigUpdate, DetectorConfigurationHandle};
5
4
6
5
pub struct RpcServer;
7
6
···
9
8
pub async fn handle_request(req: StrikerRequest) -> Option<StrikerResponse> {
10
9
match req.request {
11
10
Request::Ping => Some(StrikerResponse::Response(Response::Pong)),
12
12
-
Request::DetectorInfo => Some(StrikerResponse::Response(Response::DetectorInfo {
13
13
-
blip_threshold: BLIP_THRESHOLD as usize,
14
14
-
blip_size: BLIP_SIZE,
15
15
-
max_duty: 100,
16
16
-
duty: 0,
17
17
-
})),
18
18
-
Request::SetDetectorConfig { .. } => {
11
11
+
Request::DetectorInfo => {
12
12
+
let config = DetectorConfigurationHandle::get_config();
13
13
+
14
14
+
Some(StrikerResponse::Response(Response::DetectorInfo {
15
15
+
blip_threshold: config.blip_threshold(),
16
16
+
blip_size: config.blip_size(),
17
17
+
}))
18
18
+
}
19
19
+
Request::SetDetectorConfig {
20
20
+
blip_size,
21
21
+
blip_threshold,
22
22
+
} => {
23
23
+
DetectorConfigurationHandle::set_config(DetectorConfigUpdate {
24
24
+
blip_threshold,
25
25
+
blip_size,
26
26
+
});
27
27
+
19
28
Some(StrikerResponse::Response(Response::SetDetectorConfig {
20
20
-
success: false,
21
21
-
message: Some("NOT IMPLEMENTED".to_string()),
29
29
+
success: true,
30
30
+
message: None,
22
31
}))
23
32
}
24
33
}
+11
-2
src/state.rs
···
1
1
use core::cell::Cell;
2
2
3
3
-
use embassy_sync::blocking_mutex::Mutex;
3
3
+
use embassy_strike_driver::DetectorConfig;
4
4
+
use embassy_sync::{blocking_mutex::Mutex, signal::Signal};
4
5
5
5
-
use crate::locks::ConnectionStatusLock;
6
6
+
use crate::{
7
7
+
constants::{BLIP_SIZE, BLIP_THRESHOLD},
8
8
+
locks::{ConfigUpdateLock, ConnectionStatusLock},
9
9
+
};
6
10
7
11
pub static DEVICE_STATE: Mutex<ConnectionStatusLock, Cell<DeviceState>> =
8
12
Mutex::new(Cell::new(DeviceState::Disconnected));
···
12
16
Disconnected,
13
17
Connected,
14
18
}
19
19
+
20
20
+
pub static DETECTOR_CONFIG_UPDATES: Signal<ConfigUpdateLock, DetectorConfig> = Signal::new();
21
21
+
22
22
+
pub static DETECTOR_CONFIG: Mutex<ConfigUpdateLock, DetectorConfig> =
23
23
+
Mutex::new(DetectorConfig::new(BLIP_THRESHOLD, BLIP_SIZE));
+34
-2
src/updates.rs
···
1
1
-
use embassy_strike_driver::DetectorUpdate;
1
1
+
use embassy_strike_driver::{DetectorConfig, DetectorUpdate};
2
2
use embassy_sync::channel::{Channel, Receiver, Sender};
3
3
use sachy_fmt::info;
4
4
use striker_proto::{StrikerResponse, Update};
5
5
6
6
use crate::{
7
7
locks::NetDataLock,
8
8
-
state::{DEVICE_STATE, DeviceState},
8
8
+
state::{DETECTOR_CONFIG, DETECTOR_CONFIG_UPDATES, DEVICE_STATE, DeviceState},
9
9
};
10
10
11
11
pub type NetDataChannel = Channel<NetDataLock, StrikerResponse, 8>;
···
75
75
};
76
76
}
77
77
}
78
78
+
79
79
+
pub struct DetectorConfigUpdate {
80
80
+
pub blip_threshold: Option<u16>,
81
81
+
pub blip_size: Option<usize>,
82
82
+
}
83
83
+
84
84
+
pub struct DetectorConfigurationHandle;
85
85
+
86
86
+
impl DetectorConfigurationHandle {
87
87
+
pub fn set_config(update: DetectorConfigUpdate) {
88
88
+
let update = DETECTOR_CONFIG.lock(|config| {
89
89
+
if let Some(size) = update.blip_size {
90
90
+
config.set_blip_size(size);
91
91
+
}
92
92
+
93
93
+
if let Some(threshold) = update.blip_threshold {
94
94
+
config.set_blip_threshold(threshold);
95
95
+
}
96
96
+
97
97
+
config.clone()
98
98
+
});
99
99
+
DETECTOR_CONFIG_UPDATES.signal(update);
100
100
+
}
101
101
+
102
102
+
pub fn get_config() -> DetectorConfig {
103
103
+
DETECTOR_CONFIG.lock(Clone::clone)
104
104
+
}
105
105
+
106
106
+
pub async fn get_updated_config() -> DetectorConfig {
107
107
+
DETECTOR_CONFIG_UPDATES.wait().await
108
108
+
}
109
109
+
}