Skip to content

Commit 081ce6c

Browse files
committed
fix: correct minor mistakes in networker
1 parent e23aeb9 commit 081ce6c

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ To have the boop box automatically start when the system boots, create a systemd
2323

2424
```
2525
[Unit]
26-
Description=BoopBox.js
26+
Description=BoopBox
2727
After=network.target
2828
2929
[Service]
3030
Type=simple
3131
User=pi
32-
ExecStart=/usr/local/bin/node /home/pi/bin/boop-box
32+
ExecStart=/home/pi/bin/boop-box
33+
Environment="RUST_LOG=info"
3334
WorkingDirectory=/home/pi
3435
Restart=always
3536

src/nfc/reader.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use nfc1::target_info::TargetInfo;
33
use nfc1::BaudRate::Baud106;
44
use nfc1::Error::Timeout as TimeoutError;
55
use nfc1::ModulationType::Iso14443a;
6-
use nfc1::{Modulation, Timeout};
6+
use nfc1::{Modulation, Property, Timeout};
77

88
use crate::nfc::ndef::{parse_ndef_text_record, NdefMessageParser};
99

@@ -49,6 +49,9 @@ impl<'a> NfcReader<'a> {
4949
}
5050

5151
pub fn select_target(&mut self) -> Option<Uid> {
52+
self.device
53+
.set_property_bool(Property::InfiniteSelect, false)
54+
.unwrap();
5255
let result = self.device.initiator_select_passive_target(&Modulation {
5356
modulation_type: Iso14443a,
5457
baud_rate: Baud106,

src/nfc/thread.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn start_nfc_listener(mut nfc_rx: mpsc::Receiver<NfcCommand>) {
2929
let device = context.open().unwrap();
3030
let mut nfc_reader = NfcReader::new(device);
3131

32-
while let Some(command) = nfc_rx.blocking_recv() {
32+
'command: while let Some(command) = nfc_rx.blocking_recv() {
3333
use NfcCommand::*;
3434

3535
match command {
@@ -39,7 +39,7 @@ pub fn start_nfc_listener(mut nfc_rx: mpsc::Receiver<NfcCommand>) {
3939
} => {
4040
let uid = loop {
4141
if cancel_rx.try_recv() != Err(TryRecvError::Empty) {
42-
return;
42+
continue 'command;
4343
}
4444

4545
if let Some(uid) = nfc_reader.select_target() {

src/subsystems/controller.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ impl Controller {
100100

101101
match maybe_achievements {
102102
Some(achievements) => {
103-
let (done_tx, done_rx) = oneshot::channel();
104-
self.audio_player.send(PlayerCommand::PlayConfirm { done: done_tx }).await?;
105-
done_rx.await?;
106-
107103
for achievement_id in achievements.iter() {
104+
let (done_tx, done_rx) = oneshot::channel();
105+
self.audio_player.send(PlayerCommand::PlayConfirm { done: done_tx }).await?;
106+
done_rx.await?;
107+
108108
let filename = format!("{:x?}.mp3", achievement_id);
109109
let path = self.cache_path.join(&filename);
110110

src/subsystems/networker.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,11 @@ impl Networker {
110110
}
111111

112112
let mut interval = time::interval(Duration::from_secs(3));
113+
let mut invalid_credentials = false;
113114

114115
loop {
115116
tokio::select! {
116117
maybe_command = self.rx.recv() => {
117-
let stream = match maybe_stream {
118-
Some(ref mut stream) => stream,
119-
None => continue,
120-
};
121-
122118
use NetworkerCommand::*;
123119

124120
match maybe_command {
@@ -127,6 +123,7 @@ impl Networker {
127123
SetConnection { connection_config } => {
128124
maybe_connection_config = Some(connection_config.clone());
129125
maybe_stream = None;
126+
invalid_credentials = false;
130127

131128
let (config_tx, config_rx) = oneshot::channel();
132129
self.config.send(ConfigCommand::SetConnection {
@@ -136,20 +133,32 @@ impl Networker {
136133
config_rx.await?;
137134
},
138135
CheckUid { uid, responder } => {
136+
let stream = match maybe_stream {
137+
Some(ref mut stream) => stream,
138+
None => continue,
139+
};
140+
139141
match self.check_uid(stream, &uid).await {
140142
Ok(achievements) => responder.send(achievements).unwrap(),
141143
Err(_) => {
142144
maybe_stream = None;
143145
self.status_tx.send(NetworkerStatus::Disconnected).await?;
146+
responder.send(None).unwrap();
144147
},
145148
}
146149
},
147150
GetAudio { id, responder } => {
151+
let stream = match maybe_stream {
152+
Some(ref mut stream) => stream,
153+
None => continue,
154+
};
155+
148156
match self.get_audio(stream, &id).await {
149157
Ok(data) => responder.send(data).unwrap(),
150158
Err(_) => {
151159
maybe_stream = None;
152160
self.status_tx.send(NetworkerStatus::Disconnected).await?;
161+
responder.send(None).unwrap();
153162
},
154163
}
155164
},
@@ -168,17 +177,25 @@ impl Networker {
168177
},
169178
None => {
170179
if let Some(connection_config) = maybe_connection_config.as_ref() {
180+
if invalid_credentials {
181+
continue;
182+
}
183+
184+
self.status_tx.send(NetworkerStatus::Disconnected).await?;
185+
171186
if let Ok(maybe_connected_stream) = self.connect(
172187
&connector,
173188
connection_config
174189
).await {
175190
match maybe_connected_stream {
176191
Some(connected_stream) => {
177192
maybe_stream = Some(connected_stream);
178-
self.status_tx.send(NetworkerStatus::Connected).await?
193+
self.status_tx.send(NetworkerStatus::Connected).await?;
194+
invalid_credentials = false;
179195
},
180196
None => {
181-
self.status_tx.send(NetworkerStatus::InvalidCredentials).await?
197+
self.status_tx.send(NetworkerStatus::InvalidCredentials).await?;
198+
invalid_credentials = true;
182199
},
183200
}
184201
}
@@ -202,7 +219,7 @@ impl Networker {
202219

203220
let result = stream.read_u8().await?;
204221

205-
if result == 0x00 {
222+
if result == 0x00 || result == 0x02 {
206223
return Ok(None);
207224
}
208225

@@ -286,7 +303,7 @@ impl Networker {
286303
stream.write_u8(auth_string.len() as u8).await?;
287304
stream.write_all(auth_string.as_bytes()).await?;
288305

289-
Ok(stream.read_u8().await? == 0x00)
306+
Ok(stream.read_u8().await? == 0x01)
290307
}
291308
}
292309

0 commit comments

Comments
 (0)