Skip to content

Commit

Permalink
Configure CRA field [DEVINFRA-987] (#96)
Browse files Browse the repository at this point in the history
# Context

The option to send CRA messages as opposed to just GGA must be added

<!--- Background regarding what prompted this PR --->

# Description

Four new cli args are added, used to construct a CRA message.
`area_id` - if areaid is set, use CRA message instead of GGA. Populate the CRA message with the areaid value
`request_counter` - the id of the request
`corrections_mask` - specify which corrections to use.
`solution_id` solution id represents the identifier of the connection stream to reconnect to in the event of disconnections

<!--- Changes proposed in this PR --->

# JIRA Reference

https://swift-nav.atlassian.net/browse/DEVINFRA-987

## resources

https://docs.google.com/document/d/10L8i-CAY3_q3UxZAIy8IQhcc-6tDeN5a/edit#heading=h.z337ya
  • Loading branch information
achubbic-snav authored Nov 15, 2022
1 parent 6c1b82b commit ab5d9e7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
lint:
name: Format and lint
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -29,7 +29,7 @@ jobs:
args: --all-features --all-targets -- -D warnings
test:
name: Tests
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -50,7 +50,7 @@ jobs:
- test
strategy:
matrix:
os: [windows-2019, macos-11, ubuntu-18.04]
os: [windows-2019, macos-11, ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
binary_target: x86_64-unknown-linux-musl
- os: windows-2019
binary_target: x86_64-pc-windows-msvc
- os: macos-11
binary_target: x86_64-apple-darwin
steps:
- name: Install musl tools
if: matrix.os == 'ubuntu-18.04'
if: matrix.os == 'ubuntu-20.04'
run: sudo apt-get install musl-tools
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:

post-build:
name: Post Build
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
needs: [ build ]
steps:
- name: Get tag
Expand Down
53 changes: 43 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ struct Cli {
height: String,

/// Client ID
#[clap(long, default_value = "00000000-0000-0000-0000-000000000000")]
client: String,
#[clap(
long,
default_value = "00000000-0000-0000-0000-000000000000",
alias = "client"
)]
client_id: String,

#[clap(short, long)]
verbose: bool,
Expand All @@ -54,6 +58,22 @@ struct Cli {
/// GGA update period, in seconds. 0 means to never send a GGA
#[clap(long, default_value = "10")]
gga_period: u64,

/// Request counter allows correlation between message sent and acknowledgment response from corrections stream
#[clap(long)]
request_counter: Option<u8>,

/// Area ID to be used in generation of CRA message. If this flag is set, ntripping outputs messages of type CRA rather than the default GGA
#[clap(long)]
area_id: Option<u32>,

/// Field specifying which types of corrections are to be received
#[clap(long)]
corrections_mask: Option<u16>,

/// Solution ID, the identifier of the connection stream to reconnect to in the event of disconnections
#[clap(long)]
solution_id: Option<u8>,
}

type Result<T> = std::result::Result<T, Box<dyn Error>>;
Expand Down Expand Up @@ -90,12 +110,14 @@ fn main() -> Result<()> {
let lat_dir = if latf < 0.0 { 'S' } else { 'N' };
let lon_dir = if lonf < 0.0 { 'W' } else { 'E' };

let mut request_counter = opt.request_counter.unwrap_or(0);

CURL.with(|curl| -> Result<()> {
let mut curl = curl.borrow_mut();

let mut headers = List::new();
let mut client_header = "X-SwiftNav-Client-Id: ".to_string();
client_header.push_str(&opt.client);
client_header.push_str(&opt.client_id);

headers.append("Transfer-Encoding:")?;
headers.append("Ntrip-Version: Ntrip/2.0")?;
Expand Down Expand Up @@ -150,13 +172,24 @@ fn main() -> Result<()> {
LAST.with(|last| *last.borrow_mut() = now);
let datetime: DateTime<Utc> = now.into();
let time = datetime.format("%H%M%S.00");
let gpgga = format!(
"$GPGGA,{},{:02}{:010.7},{},{:03}{:010.7},{},4,12,1.3,{:.2},M,0.0,M,1.7,0078",
time, lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir, heightf
);
let checksum = checksum(gpgga.as_bytes());
let gpgga = format!("{}*{:X}\r\n", gpgga, checksum);
buf.write_all(gpgga.as_bytes()).unwrap();
let message = match &opt.area_id {
Some(area_id) => {
let corrections_mask = &opt.corrections_mask.unwrap_or(0);
let solution_id = match &opt.solution_id {
Some(solution_id) => solution_id.to_string(),
None => String::new()
};
format!("$PSWTCRA,{},{},{},{}", request_counter, area_id, corrections_mask, solution_id)
},
None => {
format!("$GPGGA,{},{:02}{:010.7},{},{:03}{:010.7},{},4,12,1.3,{:.2},M,0.0,M,1.7,0078",
time, lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir, heightf)
}
};
request_counter = request_counter.overflowing_add(1).0;
let checksum = checksum(message.as_bytes());
let message = format!("{}*{:X}\r\n", message, checksum);
buf.write_all(message.as_bytes()).unwrap();
Ok(buf.len())
} else {
Err(ReadError::Pause)
Expand Down

0 comments on commit ab5d9e7

Please sign in to comment.