add packet sending support
This commit is contained in:
		
							parent
							
								
									1b380935a3
								
							
						
					
					
						commit
						b086057ba0
					
				|  | @ -42,6 +42,11 @@ name = "cfg-if" | ||||||
| version = "0.1.10" | version = "0.1.10" | ||||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | 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]] | [[package]] | ||||||
| name = "lazy_static" | name = "lazy_static" | ||||||
| version = "1.4.0" | version = "1.4.0" | ||||||
|  | @ -133,6 +138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
| name = "rn2903" | name = "rn2903" | ||||||
| version = "0.2.0" | version = "0.2.0" | ||||||
| dependencies = [ | 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)", |  "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)", |  "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 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 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 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 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 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" | "checksum libudev 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea626d3bdf40a1c5aee3bcd4f40826970cae8d80a8fec934c82a63840094dcfe" | ||||||
|  |  | ||||||
|  | @ -14,4 +14,5 @@ categories = ["api-bindings", "embedded", "hardware-support"] | ||||||
| [dependencies] | [dependencies] | ||||||
| serialport = "3.3" | serialport = "3.3" | ||||||
| quick-error = "1" | quick-error = "1" | ||||||
|  | hex = "0.4.2" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										28
									
								
								src/lib.rs
								
								
								
								
							
							
						
						
									
										28
									
								
								src/lib.rs
								
								
								
								
							|  | @ -32,6 +32,7 @@ | ||||||
| // a `Result<T, rn2903::Error>`.
 | // a `Result<T, rn2903::Error>`.
 | ||||||
| #[macro_use] | #[macro_use] | ||||||
| extern crate quick_error; | extern crate quick_error; | ||||||
|  | use hex; | ||||||
| use std::io; | use std::io; | ||||||
| 
 | 
 | ||||||
| quick_error! { | quick_error! { | ||||||
|  | @ -80,6 +81,16 @@ quick_error! { | ||||||
|             description(err.description()) |             description(err.description()) | ||||||
|             from() |             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") | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -466,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
 | /// # MAC API Functions
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue