Compare commits

...

3 Commits

Author SHA1 Message Date
Leonora Tindall 774f4a9f9e Merge pull request 'add RN2483 support and send packet support' (#1) from waxzce/rn2903:main into main 2020-06-13 17:43:19 +00:00
Quentin ADAM b086057ba0 add packet sending support 2020-05-19 01:33:28 +02:00
Quentin ADAM 1b380935a3 add RN2483 chip support 2020-05-19 01:29:32 +02:00
3 changed files with 38 additions and 1 deletions

7
Cargo.lock generated
View File

@ -42,6 +42,11 @@ name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hex"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -133,6 +138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "rn2903"
version = "0.2.0"
dependencies = [
"hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serialport 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -192,6 +198,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
"checksum libudev 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea626d3bdf40a1c5aee3bcd4f40826970cae8d80a8fec934c82a63840094dcfe"

View File

@ -14,4 +14,5 @@ categories = ["api-bindings", "embedded", "hardware-support"]
[dependencies]
serialport = "3.3"
quick-error = "1"
hex = "0.4.2"

View File

@ -32,6 +32,7 @@
// a `Result<T, rn2903::Error>`.
#[macro_use]
extern crate quick_error;
use hex;
use std::io;
quick_error! {
@ -80,6 +81,16 @@ quick_error! {
description(err.description())
from()
}
TransmissionUnsuccessful {
description("the radio transmission was unsuccessful")
display("if transmission was unsuccessful (interrupted by radio Watchdog Timer time-out)")
}
InvalidParam {
description("the parameter is not valid")
display("the parameter is not valid")
}
}
}
@ -203,7 +214,8 @@ impl Rn2903 {
pub fn new(port: Box<dyn SerialPort>) -> Result<Self> {
let mut new = Self::new_unchecked(port);
let version = new.system_version()?;
if &version[0..6] != "RN2903" {
// RN2483 and RN2903 are the same, just EU and US chip, but talk the same
if &version[0..6] != "RN2903" && &version[0..6] != "RN2483" {
Err(Error::WrongDevice(version))
} else {
Ok(new)
@ -465,6 +477,23 @@ impl Rn2903 {
)),
}
}
pub fn radio_tx(&mut self, send: String) -> Result<Option<Vec<u8>>> {
let result = self.transact(&format!("radio tx {}", hex::encode(send)).into_bytes())?;
match &result[..] {
b"ok" => {
let sresult = self.read_line()?;
match &sresult[..] {
b"radio_tx_ok" => return Ok(None),
b"radio_err" => return Err(Error::TransmissionUnsuccessful),
v => return Err(Error::bad_response("nok", bytes_to_string(v))),
}
}
b"invalid_param" => return Err(Error::InvalidParam),
b"busy" => return Err(Error::TransceiverBusy),
v => return Err(Error::bad_response("ok | busy", bytes_to_string(v))),
};
}
}
/// # MAC API Functions