Remove drogue example
This commit is contained in:
parent
d4f5e05ba6
commit
bf0bc29578
39
Cargo.toml
39
Cargo.toml
|
@ -1,12 +1,31 @@
|
||||||
[workspace]
|
[package]
|
||||||
members = [
|
name = "rust-mqtt"
|
||||||
"mqtt"
|
version = "0.0.1"
|
||||||
]
|
authors = ["Ondrej Babec <ond.babec@gmail.com>"]
|
||||||
|
edition = "2021"
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
description = "MQTT client for both embedded and non-embedded devices"
|
||||||
|
readme = "README.md"
|
||||||
|
license-file = "LICENSE"
|
||||||
|
|
||||||
[patch.crates-io]
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
embassy = { git = "https://github.com/embassy-rs/embassy.git", rev = "3d6b8bd9832d5a29cab4aa21434663e6ea6f4488" }
|
|
||||||
embassy-traits = { git = "https://github.com/embassy-rs/embassy.git", rev = "3d6b8bd9832d5a29cab4aa21434663e6ea6f4488" }
|
[dependencies]
|
||||||
embassy-net = { git = "https://github.com/embassy-rs/embassy.git", rev = "3d6b8bd9832d5a29cab4aa21434663e6ea6f4488" }
|
heapless = "0.7.10"
|
||||||
drogue-device = { git = "https://github.com/drogue-iot/drogue-device.git", rev = "62ff20e278a6a705056173171714b1bbdc078df5" }
|
rand_core = "0.6.0"
|
||||||
embassy-nrf = { git = "https://github.com/embassy-rs/embassy.git", rev = "3d6b8bd9832d5a29cab4aa21434663e6ea6f4488" }
|
defmt = { version = "0.3", optional = true }
|
||||||
|
log = { version = "0.4.14", optional = true }
|
||||||
|
tokio = { version = "1", features = ["full"], optional = true, default-features = false }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
tokio-test = { version = "0.4.2"}
|
||||||
|
env_logger = "0.9.0"
|
||||||
|
futures = { version = "0.3.21" }
|
||||||
|
log = { version = "0.4.14"}
|
||||||
|
serial_test = "0.6.0"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["std"]
|
||||||
|
std = ["tokio", "log"]
|
||||||
|
no_std = ["defmt"]
|
|
@ -1,11 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "drogue-network"
|
|
||||||
version = "0.0.1"
|
|
||||||
authors = ["Ondrej Babec <ond.babec@gmail.com>"]
|
|
||||||
edition = "2021"
|
|
||||||
resolver = "2"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
defmt = { version = "0.3" }
|
|
||||||
rust-mqtt = { path = "../../mqtt", features = ["no_std"], default-features = false }
|
|
||||||
drogue-device = { path = "/drogue-device/device", features = ["time"], default-features = false }
|
|
|
@ -1,103 +0,0 @@
|
||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) [2022] [Ondrej Babec <ond.babec@gmail.com>]
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publishistribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIMAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use crate::network::socket::Socket;
|
|
||||||
use crate::Address;
|
|
||||||
use core::future::Future;
|
|
||||||
use core::ops::Range;
|
|
||||||
use rust_mqtt::packet::v5::reason_codes::ReasonCode;
|
|
||||||
|
|
||||||
use crate::traits::tcp;
|
|
||||||
use crate::traits::tcp::TcpStack;
|
|
||||||
use rust_mqtt::network::{NetworkConnection, NetworkConnectionFactory};
|
|
||||||
|
|
||||||
pub struct DrogueNetwork<A>
|
|
||||||
where
|
|
||||||
A: TcpStack + Clone + 'static,
|
|
||||||
{
|
|
||||||
socket: Socket<A>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A> DrogueNetwork<A>
|
|
||||||
where
|
|
||||||
A: TcpStack + Clone + 'static,
|
|
||||||
{
|
|
||||||
pub fn new(socket: Socket<A>) -> Self {
|
|
||||||
Self { socket }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A> NetworkConnection for DrogueNetwork<A>
|
|
||||||
where
|
|
||||||
A: TcpStack + Clone + 'static,
|
|
||||||
{
|
|
||||||
type SendFuture<'m>
|
|
||||||
where
|
|
||||||
Self: 'm,
|
|
||||||
= impl Future<Output = Result<(), ReasonCode>> + 'm;
|
|
||||||
|
|
||||||
type ReceiveFuture<'m>
|
|
||||||
where
|
|
||||||
Self: 'm,
|
|
||||||
= impl Future<Output = Result<usize, ReasonCode>> + 'm;
|
|
||||||
|
|
||||||
type CloseFuture<'m>
|
|
||||||
where
|
|
||||||
Self: 'm,
|
|
||||||
= impl Future<Output = Result<(), ReasonCode>> + 'm;
|
|
||||||
|
|
||||||
fn send<'m>(&'m mut self, buffer: &'m [u8]) -> Self::SendFuture<'m> {
|
|
||||||
async move {
|
|
||||||
self.socket
|
|
||||||
.write(buffer)
|
|
||||||
.await
|
|
||||||
.map_err(|_| ReasonCode::NetworkError)
|
|
||||||
.map(|_| ())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn receive<'m>(&'m mut self, buffer: &'m mut [u8]) -> Self::ReceiveFuture<'m> {
|
|
||||||
async move {
|
|
||||||
let r = self
|
|
||||||
.socket
|
|
||||||
.read(buffer)
|
|
||||||
.await
|
|
||||||
.map_err(|_| ReasonCode::NetworkError);
|
|
||||||
// Workaround for the fair access mutex, issue:
|
|
||||||
if let Ok(0) = r {
|
|
||||||
embassy::time::Timer::after(embassy::time::Duration::from_millis(10)).await;
|
|
||||||
}
|
|
||||||
r
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn close<'m>(mut self) -> Self::CloseFuture<'m> {
|
|
||||||
async move {
|
|
||||||
self.socket
|
|
||||||
.close()
|
|
||||||
.await
|
|
||||||
.map_err(|_| ReasonCode::NetworkError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) [2022] [Ondrej Babec <ond.babec@gmail.com>]
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#![no_std]
|
|
||||||
#![feature(in_band_lifetimes)]
|
|
||||||
#![macro_use]
|
|
||||||
#![allow(dead_code)]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
#![feature(generic_associated_types)]
|
|
||||||
pub mod fmt;
|
|
||||||
pub mod drogue_network;
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "rust-mqtt"
|
|
||||||
version = "0.0.1"
|
|
||||||
authors = ["Ondrej Babec <ond.babec@gmail.com>"]
|
|
||||||
edition = "2021"
|
|
||||||
resolver = "2"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
heapless = "0.7.10"
|
|
||||||
rand_core = "0.6.0"
|
|
||||||
defmt = { version = "0.3", optional = true }
|
|
||||||
log = { version = "0.4.14", optional = true }
|
|
||||||
tokio = { version = "1", features = ["full"], optional = true, default-features = false }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
tokio = { version = "1", features = ["full"] }
|
|
||||||
tokio-test = { version = "0.4.2"}
|
|
||||||
env_logger = "0.9.0"
|
|
||||||
futures = { version = "0.3.21" }
|
|
||||||
log = { version = "0.4.14"}
|
|
||||||
serial_test = "0.6.0"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["std"]
|
|
||||||
std = ["tokio", "log"]
|
|
||||||
no_std = ["defmt"]
|
|
228
mqtt/src/fmt.rs
228
mqtt/src/fmt.rs
|
@ -1,228 +0,0 @@
|
||||||
#![macro_use]
|
|
||||||
#![allow(unused_macros)]
|
|
||||||
|
|
||||||
#[cfg(all(feature = "defmt", feature = "log"))]
|
|
||||||
compile_error!("You may not enable both `defmt` and `log` features.");
|
|
||||||
|
|
||||||
macro_rules! assert {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::assert!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::assert!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! assert_eq {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::assert_eq!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::assert_eq!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! assert_ne {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::assert_ne!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::assert_ne!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! debug_assert {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::debug_assert!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::debug_assert!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! debug_assert_eq {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::debug_assert_eq!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::debug_assert_eq!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! debug_assert_ne {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::debug_assert_ne!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::debug_assert_ne!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! todo {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::todo!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::todo!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! unreachable {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::unreachable!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::unreachable!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! panic {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::panic!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::panic!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! trace {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::trace!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::trace!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! debug {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::debug!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::debug!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! info {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::info!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::info!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! warn {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::warn!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::warn!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! error {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::error!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::error!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
macro_rules! unwrap {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
::defmt::unwrap!($($x)*)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
macro_rules! unwrap {
|
|
||||||
($arg:expr) => {
|
|
||||||
match $crate::fmt::Try::into_result($arg) {
|
|
||||||
::core::result::Result::Ok(t) => t,
|
|
||||||
::core::result::Result::Err(e) => {
|
|
||||||
::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
($arg:expr, $($msg:expr),+ $(,)? ) => {
|
|
||||||
match $crate::fmt::Try::into_result($arg) {
|
|
||||||
::core::result::Result::Ok(t) => t,
|
|
||||||
::core::result::Result::Err(e) => {
|
|
||||||
::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "defmt-timestamp-uptime")]
|
|
||||||
defmt::timestamp! {"{=u64:us}", crate::time::Instant::now().as_micros() }
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
|
||||||
pub struct NoneError;
|
|
||||||
|
|
||||||
pub trait Try {
|
|
||||||
type Ok;
|
|
||||||
type Error;
|
|
||||||
fn into_result(self) -> Result<Self::Ok, Self::Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Try for Option<T> {
|
|
||||||
type Ok = T;
|
|
||||||
type Error = NoneError;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn into_result(self) -> Result<T, NoneError> {
|
|
||||||
self.ok_or(NoneError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E> Try for Result<T, E> {
|
|
||||||
type Ok = T;
|
|
||||||
type Error = E;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn into_result(self) -> Self {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user