1use super::*;
2
3const DEFAULT_COMMAND_TIMEOUT: Duration = Duration::from_secs(3);
7
8const DEFAULT_CHANNEL_SIZE: usize = 32;
10
11pub struct WifiSetup {
13 wifi: WifiStation,
15 request_client: RequestClient,
17}
18
19impl WifiSetup {
20 pub fn new() -> Self {
21 Self::with_capacities(DEFAULT_CHANNEL_SIZE, DEFAULT_CHANNEL_SIZE)
22 }
23
24 pub fn with_capacities(request_channel_size: usize, broadcast_channel_size: usize) -> Self {
27 let (self_sender, request_receiver) = mpsc::channel(request_channel_size);
29 let request_client = RequestClient::new(self_sender.clone());
30 let broadcast_sender = broadcast::Sender::new(broadcast_channel_size);
32
33 Self {
34 wifi: WifiStation {
35 socket_path: PATH_DEFAULT_SERVER.into(),
36 request_receiver,
37 broadcast_sender,
38 self_sender,
39 select_timeout: Duration::from_secs(10),
40 command_timeout: DEFAULT_COMMAND_TIMEOUT,
41 },
42 request_client,
43 }
44 }
45
46 pub fn set_socket_path<S: Into<std::path::PathBuf>>(&mut self, path: S) {
47 self.wifi.socket_path = path.into();
48 }
49
50 pub fn set_select_timeout(&mut self, timeout: Duration) {
51 self.wifi.select_timeout = timeout;
52 }
53
54 pub fn set_command_timeout(&mut self, timeout: Duration) {
57 self.wifi.command_timeout = timeout;
58 }
59
60 pub fn get_broadcast_receiver(&self) -> BroadcastReceiver {
61 self.wifi.broadcast_sender.subscribe()
62 }
63 pub fn get_request_client(&self) -> RequestClient {
64 self.request_client.clone()
65 }
66
67 pub fn complete(self) -> WifiStation {
68 self.wifi
69 }
70}
71
72impl Default for WifiSetup {
73 fn default() -> Self {
74 Self::new()
75 }
76}