Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APA & APB added #113

Closed
wants to merge 5 commits into from
Closed

APA & APB added #113

wants to merge 5 commits into from

Conversation

rata5
Copy link

@rata5 rata5 commented Jan 9, 2024

No description provided.

Copy link
Member

@elpiel elpiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for opening this PR and working on the 2 sentences.

As discussed on Discord, the parsing should happen from NMEA 0183 sentence and not JSON. Json (de)serialization is achieved using derive macro - derive(Serialize, Deserialize)

Please, take a look at the other modules and use the nom crate to parse the sentences.

src/sentences/apa.rs Outdated Show resolved Hide resolved
src/sentences/apa.rs Outdated Show resolved Hide resolved
Comment on lines 42 to 60
impl fmt::Display for APASentence {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{{\"sentence_type\":\"{}\",\"cross_track_error\":{},\"direction_to_steer\":\"{}\",\"status\":\"{}\",\"cross_track_units\":\"{}\",\"waypoint_id\":\"{}\",\"bearing_to_destination\":{:0.1},\"heading_to_destination\":\"{}\",\"arrival_circle_entered\":\"{}\",\"perimeter_laid\":\"{}\",\"steer_to_heading\":\"{}\"}}",
self.sentence_type,
self.cross_track_error,
self.direction_to_steer,
self.status,
self.cross_track_units,
self.waypoint_id,
self.bearing_to_destination,
self.heading_to_destination,
self.arrival_circle_entered,
self.perimeter_laid,
self.steer_to_heading,
)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • You should not user std::fmt since this crate defines no_std where std is not available.
    To implement Json, you need to derive(Serialize, Deserialize) for the type

Comment on lines 62 to 79
fn main() {
let apa_sentence = APASentence {
sentence_type: String::from("$APA"),
cross_track_error: 1.5,
direction_to_steer: 'L',
status: 'A',
cross_track_units: 'N',
waypoint_id: String::from("WPT001"),
bearing_to_destination: 45.0,
heading_to_destination: 'T',
arrival_circle_entered: 'A',
perimeter_laid: 'N',
steer_to_heading: 'N',
};

let nmea_sentence = apa_sentence.to_string();
println!("NMEA APA Sentence: {}", nmea_sentence);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main function is only applicable to binaries.

  • Please remove the main fn

Comment on lines 81 to 97
#[test]
fn test_apa_sentence_serialization() {
let apa_sentence = APASentence {
sentence_type: String::from("$APA"),
cross_track_error: 1.5,
direction_to_steer: 'L',
status: 'A',
cross_track_units: 'N',
waypoint_id: String::from("WPT001"),
bearing_to_destination: 45.0,
heading_to_destination: 'T',
arrival_circle_entered: 'A',
perimeter_laid: 'N',
steer_to_heading: 'N',
};

let expected_json = r#"{"sentence_type":"$APA","cross_track_error":1.5,"direction_to_steer":"L","status":"A","cross_track_units":"N","waypoint_id":"WPT001","bearing_to_destination":45.0,"heading_to_destination":"T","arrival_circle_entered":"A","perimeter_laid":"N","steer_to_heading":"N"}"#;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The test should contain parsing from NMEA 0183 sentence and not JSON.
  • tests should be contained in their own module tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same comments apply to this sentences too.

rata5 and others added 4 commits January 16, 2024 16:38
Co-authored-by: Lachezar Lechev <8925621+elpiel@users.noreply.github.com>
Co-authored-by: Lachezar Lechev <8925621+elpiel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants