Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ matrix:
allow_failures:
- rust: nightly
fast_finish: true
before_script:
- rustup component add rustfmt-preview
- which rustfmt
22 changes: 4 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
[package]
name = "ublox"
version = "0.1.0"
authors = ["Lane Kolbly <lane@rscheme.org>"]
edition = "2018"
license = "MIT"
description = "A crate to communicate with u-blox GPS devices using the UBX protocol"
[workspace]
members = ["ublox", "ublox_derive", "ubx_protocol"]

[dependencies]
serde = "1.0"
serde_derive = "1.0"
serialport = "3.3.0"
bincode = "1.2.1"
chrono = "0.4"
crc = "1.8.1"
syn = "1.0.14"
ublox_derive = { path = "ublox_derive/" }
num-traits = "0.2"
num-derive = "0.2"
[patch.'crates-io']
ublox_derive = { path = "ublox_derive" }
15 changes: 15 additions & 0 deletions ublox/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "ublox"
version = "0.1.0"
authors = ["Lane Kolbly <lane@rscheme.org>"]
edition = "2018"
license = "MIT"
description = "A crate to communicate with u-blox GPS devices using the UBX protocol"

[dependencies]
serde = "1.0"
serde_derive = "1.0"
serialport = "3.3.0"
bincode = "1.2.1"
chrono = "0.4"
crc = "1.8.1"
File renamed without changes.
29 changes: 18 additions & 11 deletions src/lib.rs → ublox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
//! `ublox` is a library to talk to u-blox GPS devices using the UBX protocol.
//! At time of writing this library is developed for a device which behaves like
//! a NEO-6M device.
use crate::error::{Error, Result};
use chrono::prelude::*;
use crc::{crc16, Hasher16};
use std::io;
use std::time::{Duration, Instant};
use crate::error::{Error, Result};

pub use crate::ubx_packets::*;
pub use crate::segmenter::Segmenter;
pub use crate::ubx_packets::*;

mod error;
mod ubx_packets;
mod segmenter;
mod ubx_packets;

#[derive(Debug)]
pub enum ResetType {
Expand All @@ -32,7 +32,6 @@ pub struct Device {
port: Box<dyn serialport::SerialPort>,
segmenter: Segmenter,
//buf: Vec<u8>,

alp_data: Vec<u8>,
alp_file_id: u16,

Expand Down Expand Up @@ -61,7 +60,7 @@ impl Device {
///
/// This function will panic if it cannot open the serial port.
pub fn new(device: &str) -> Result<Device> {
let s = serialport::SerialPortSettings{
let s = serialport::SerialPortSettings {
baud_rate: 9600,
data_bits: serialport::DataBits::Eight,
flow_control: serialport::FlowControl::None,
Expand All @@ -70,7 +69,7 @@ impl Device {
timeout: Duration::from_millis(1),
};
let port = serialport::open_with_settings(device, &s).unwrap();
let mut dev = Device{
let mut dev = Device {
port: port,
segmenter: Segmenter::new(),
alp_data: Vec::new(),
Expand Down Expand Up @@ -174,7 +173,7 @@ impl Device {
pub fn get_position(&mut self) -> Option<Position> {
match (&self.navstatus, &self.navpos) {
(Some(status), Some(pos)) => {
if status.itow != pos.get_itow() {
if status.itow != pos.itow {
None
} else if status.flags & 0x1 == 0 {
None
Expand All @@ -190,7 +189,7 @@ impl Device {
pub fn get_velocity(&mut self) -> Option<Velocity> {
match (&self.navstatus, &self.navvel) {
(Some(status), Some(vel)) => {
if status.itow != vel.get_itow() {
if status.itow != vel.itow {
None
} else if status.flags & 0x1 == 0 {
None
Expand Down Expand Up @@ -264,7 +263,7 @@ impl Device {
pub fn load_aid_data(
&mut self,
position: Option<Position>,
tm: Option<DateTime<Utc>>
tm: Option<DateTime<Utc>>,
) -> Result<()> {
let mut aid = AidIni::new();
match position {
Expand Down Expand Up @@ -313,7 +312,10 @@ impl Device {
return Ok(Some(Packet::AckAck(packet)));
}
Some(Packet::MonVer(packet)) => {
println!("Got versions: SW={} HW={}", packet.sw_version, packet.hw_version);
println!(
"Got versions: SW={} HW={}",
packet.sw_version, packet.hw_version
);
return Ok(None);
}
Some(Packet::NavPosVelTime(packet)) => {
Expand Down Expand Up @@ -382,7 +384,12 @@ impl Device {
}

fn send(&mut self, packet: UbxPacket) -> Result<()> {
CfgMsg{classid: 5, msgid: 4, rates: [0, 0, 0, 0, 0, 0]}.to_bytes();
CfgMsg {
classid: 5,
msgid: 4,
rates: [0, 0, 0, 0, 0, 0],
}
.to_bytes();
let serialized = packet.serialize();
self.port.write_all(&serialized)?;
Ok(())
Expand Down
12 changes: 8 additions & 4 deletions src/main.rs → ublox/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use ublox::{Device, Position};
use std::time::Duration;
use chrono::prelude::*;
use std::time::Duration;
use ublox::{Device, Position};

fn main() {
let mut dev = Device::new("/dev/ttyUSB0").unwrap();

let pos = Position{lon: -97.5, lat: 30.2, alt: 200.0};
let pos = Position {
lon: -97.5,
lat: 30.2,
alt: 200.0,
};
println!("Setting AID data...");
match dev.load_aid_data(Some(pos), Some(Utc::now())) {
Err(e) => {
println!("Got error setting AID data: {:?}", e);
},
}
_ => {}
}

Expand Down
File renamed without changes.
Loading