Skip to content

Commit

Permalink
Rust: added CONTROLLERS dictionary (cf. uhppoted/uhppote-core#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Jul 22, 2024
1 parent cf877e4 commit 716fe4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
7 changes: 5 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
- [ ] TCP/IP protocol (cf. https://github.com/uhppoted/uhppote-core/issues/17)
- [ ] models: rename 'device id' to controller and set type to 'controller'
- [ ] Go
- [ ] controllers dictionary
- [x] controllers dictionary
- [ ] remove uhppote::resolve
- [ ] Rust
- [ ] controllers dictionary
- [x] controllers dictionary
- [ ] remove uhppote::resolve
- [ ] command line args
- [ ] Erlang
- [ ] HTTP
- [ ] Lua
Expand Down
25 changes: 21 additions & 4 deletions bindings/rust/uhppoted/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use chrono::offset::Local;
use chrono::NaiveDate;
use chrono::NaiveTime;
use async_ctrlc::CtrlC;
use lazy_static::lazy_static;

use std::fmt::Debug;
use std::collections::HashMap;

use super::uhppote;
use uhppote::error;
use uhppote::Controller;

const CONTROLLER: u32 = 405419896;
const DOOR: u8 = 3;
Expand Down Expand Up @@ -164,6 +167,16 @@ impl Command {
}
}

lazy_static! {
static ref CONTROLLERS: HashMap<u32, Controller> = HashMap::from([
(405419896, Controller {
controller: 405419896,
address: String::from("192.168.1.100:60000"),
transport: String::from("tcp"),
}),
]);
}

fn get_all_controllers() {
match futures::executor::block_on(uhppote::get_all_controllers()) {
Ok(list) => {
Expand Down Expand Up @@ -556,10 +569,14 @@ fn listen() {
}

fn resolve(controller: u32) -> uhppote::Controller {
uhppote::Controller {
controller: controller,
address: "".to_string(),
transport: "udp".to_string(),
if let Some(v) = CONTROLLERS.get(&controller){
v.clone()
} else {
uhppote::Controller {
controller: controller,
address: "".to_string(),
transport: "udp".to_string(),
}
}
}

Expand Down

0 comments on commit 716fe4b

Please sign in to comment.