Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Thread pancked at 'not implemented' #10

Open
romw314 opened this issue Jun 7, 2023 · 4 comments
Open

BUG: Thread pancked at 'not implemented' #10

romw314 opened this issue Jun 7, 2023 · 4 comments

Comments

@romw314
Copy link
Contributor

romw314 commented Jun 7, 2023

Description

I am new to Rust and I want to control Lego with my app, not Lego app.
But the example is not working and I want to learn how to program Lego in Rust from the examples.

I am using Rust version 1.70.0.

Code

My Cargo.toml:

[package]
name = "myf-lego-pup"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.71"
lego-powered-up = "0.3.0"
tokio = { version = "1.28.2", features = ["full"] }

My src/main.rs:

use lego_powered_up::{notifications::Power, PoweredUp};
use std::time::Duration;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    println!("Listening for hubs...");
    let mut pu = PoweredUp::init().await?;
    let hub = pu.wait_for_hub().await?;

    println!("Connecting to hub `{}`", hub.name);
    let hub = pu.create_hub(&hub).await?;

    println!("Change the hub LED to green");
    let mut hub_led = hub.port(lego_powered_up::hubs::Port::HubLed).await?;
    hub_led.set_rgb(&[0, 0xff, 0]).await?;

    println!("Run motors");
    let mut motor_c = hub.port(lego_powered_up::hubs::Port::C).await?;
    let mut motor_d = hub.port(lego_powered_up::hubs::Port::D).await?;
    motor_c.start_speed(50, Power::Cw(50)).await?;
    motor_d.start_speed(50, Power::Cw(50)).await?;

    tokio::time::sleep(Duration::from_secs(3)).await;

    println!("Stop motors");
    motor_c.start_speed(0, Power::Float).await?;
    motor_d.start_speed(0, Power::Brake).await?;

    println!("Disconnect from hub `{}`", hub.name().await?);
    hub.disconnect().await?;

    println!("Done!");

    Ok(())
}

Commands

C:\Users\[SECRET]\source\rust\myf-lego-pup>set RUST_BACKTRACE=1
C:\Users\[SECRET]\source\rust\myf-lego-pup>dir
 Volume in drive C has no label.
 Volume Serial Number is 825C-E6B0

 Directory of C:\Users\[SECRET]\source\rust\myf-lego-pup

06/07/2023  08:27 PM    <DIR>          .
06/07/2023  06:58 PM    <DIR>          ..
06/07/2023  06:58 PM                 8 .gitignore
06/07/2023  08:11 PM               277 Cargo.toml
06/07/2023  08:10 PM    <DIR>          src
               2 File(s)            285 bytes
               3 Dir(s)  104,529,444,864 bytes free

C:\Users\[SECRET]\source\rust\myf-lego-pup>dir src
 Volume in drive C has no label.
 Volume Serial Number is 825C-E6B0

 Directory of C:\Users\[SECRET]\source\rust\myf-lego-pup\src

06/07/2023  08:10 PM    <DIR>          .
06/07/2023  08:27 PM    <DIR>          ..
06/07/2023  07:40 PM             1,102 main.rs
               1 File(s)          1,102 bytes
               2 Dir(s)  104,529,444,864 bytes free

C:\Users\[SECRET]\source\rust\myf-lego-pup>cargo run
    Updating crates.io index
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.59
   Compiling quote v1.0.28
   Compiling unicode-ident v1.0.9
   Compiling windows_x86_64_msvc v0.48.0
   Compiling futures-core v0.3.28
   Compiling windows-targets v0.48.0
   Compiling lock_api v0.4.10
   Compiling parking_lot_core v0.9.8
   Compiling smallvec v1.10.0
   Compiling cfg-if v1.0.0
   Compiling pin-project-lite v0.2.9
   Compiling winapi v0.3.9
   Compiling scopeguard v1.1.0
   Compiling futures-sink v0.3.28
   Compiling syn v2.0.18
   Compiling slab v0.4.8
   Compiling futures-channel v0.3.28
   Compiling memchr v2.5.0
   Compiling futures-task v0.3.28
   Compiling windows-sys v0.48.0
   Compiling tokio v1.28.2
   Compiling futures-util v0.3.28
   Compiling socket2 v0.4.9
   Compiling mio v0.8.8
   Compiling parking_lot v0.12.1
   Compiling futures-io v0.3.28
   Compiling bytes v1.4.0
   Compiling pin-utils v0.1.0
   Compiling syn v1.0.109
   Compiling num_cpus v1.15.0
   Compiling log v0.4.18
   Compiling futures-macro v0.3.28
   Compiling tokio-macros v2.1.0
   Compiling async-trait v0.1.68
   Compiling thiserror v1.0.40
   Compiling thiserror-impl v1.0.40
   Compiling num-traits v0.2.15
   Compiling once_cell v1.18.0
   Compiling hashbrown v0.12.3
   Compiling dashmap v5.4.0
   Compiling futures-executor v0.3.28
   Compiling futures v0.3.28
   Compiling windows v0.48.0
   Compiling static_assertions v1.1.0
   Compiling bitflags v1.3.2
   Compiling uuid v1.3.3
   Compiling tokio-util v0.7.8
   Compiling tokio-stream v0.1.14
   Compiling anyhow v1.0.71
   Compiling num-derive v0.3.3
   Compiling lpu-macros v0.1.0
   Compiling lazy_static v1.4.0
   Compiling btleplug v0.10.5
   Compiling lego-powered-up v0.3.0
   Compiling myf-lego-pup v0.1.0 (C:\Users\[SECRET]\source\rust\myf-lego-pup)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 00s
     Running `target\debug\myf-lego-pup.exe`
Listening for hubs...

When i press green button on the hub:

Connecting to hub `unknown`
[C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\lego-powered-up-0.3.0\src\lib.rs:141] &chars = {
    Characteristic {
        uuid: 00001624-1212-efde-1623-785feabcd123,
        service_uuid: 00001623-1212-efde-1623-785feabcd123,
        properties: READ | WRITE_WITHOUT_RESPONSE | WRITE | NOTIFY,
    },
    Characteristic {
        uuid: 00002a00-0000-1000-8000-00805f9b34fb,
        service_uuid: 00001800-0000-1000-8000-00805f9b34fb,
        properties: READ | WRITE_WITHOUT_RESPONSE | WRITE | AUTHENTICATED_SIGNED_WRITES,
    },
    Characteristic {
        uuid: 00002a01-0000-1000-8000-00805f9b34fb,
        service_uuid: 00001800-0000-1000-8000-00805f9b34fb,
        properties: READ | WRITE_WITHOUT_RESPONSE | WRITE | AUTHENTICATED_SIGNED_WRITES,
    },
    Characteristic {
        uuid: 00002a04-0000-1000-8000-00805f9b34fb,
        service_uuid: 00001800-0000-1000-8000-00805f9b34fb,
        properties: READ,
    },
    Characteristic {
        uuid: 00002a05-0000-1000-8000-00805f9b34fb,
        service_uuid: 00001801-0000-1000-8000-00805f9b34fb,
        properties: INDICATE,
    },
}
thread 'main' panicked at 'not implemented', C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\lego-powered-up-0.3.0\src\lib.rs:154:18
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:578
   1: core::panicking::panic_fmt
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\panicking.rs:67
   2: core::panicking::panic
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\panicking.rs:117
   3: lego_powered_up::impl$0::create_hub::async_fn$0
             at C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\lego-powered-up-0.3.0\src\lib.rs:154
   4: myf_lego_pup::main::async_block$0
             at .\src\main.rs:11
   5: tokio::runtime::park::impl$4::block_on::closure$0<enum2$<myf_lego_pup::main::async_block_env$0> >
             at C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.28.2\src\runtime\park.rs:283
   6: tokio::runtime::coop::with_budget
             at C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.28.2\src\runtime\coop.rs:107
   7: tokio::runtime::coop::budget
             at C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.28.2\src\runtime\coop.rs:73
   8: tokio::runtime::park::CachedParkThread::block_on<enum2$<myf_lego_pup::main::async_block_env$0> >
             at C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.28.2\src\runtime\park.rs:283
   9: tokio::runtime::context::BlockingRegionGuard::block_on<enum2$<myf_lego_pup::main::async_block_env$0> >
             at C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.28.2\src\runtime\context.rs:315
  10: tokio::runtime::scheduler::multi_thread::MultiThread::block_on<enum2$<myf_lego_pup::main::async_block_env$0> >
             at C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.28.2\src\runtime\scheduler\multi_thread\mod.rs:66
  11: tokio::runtime::runtime::Runtime::block_on<enum2$<myf_lego_pup::main::async_block_env$0> >
             at C:\Users\[SECRET]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.28.2\src\runtime\runtime.rs:304
  12: myf_lego_pup::main
             at .\src\main.rs:34
  13: core::ops::function::FnOnce::call_once<enum2$<core::result::Result<tuple$<>,anyhow::Error> > (*)(),tuple$<> >
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\myf-lego-pup.exe` (exit code: 101)

C:\Users\[SECRET]\source\rust\myf-lego-pup>

@sciguy16
Copy link
Member

Thanks for the report - which hub are you using? It looks like you're hitting the panic here:

Ok(Box::new(match hub.hub_type {
HubType::TechnicMediumHub => {
hubs::TechnicHub::init(peripheral, lpf_char).await?
}
_ => unimplemented!(),
}))

Currently version 0.3 only supports the Technic Medium Hub (the 4-port one, but #11 implements support for a much wider range of PoweredUp devices. If you can wait until it's merged and I've published a new release then hopefully the example code will work with whichever hub you've got.

@romw314
Copy link
Contributor Author

romw314 commented Jun 18, 2023

I am using this hub:
https://www.lego.com/en-us/product/hub-88009

@romw314
Copy link
Contributor Author

romw314 commented Jun 18, 2023

#11 does not implement my hub, but possibly it can work with the Move hub code.

@romw314
Copy link
Contributor Author

romw314 commented Jul 10, 2023

I am new to Rust, so I don't understand the code, but #11 is good. My friends does have Move hub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants