-
Notifications
You must be signed in to change notification settings - Fork 41
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
APA & APB added #113
Conversation
There was a problem hiding this 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
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, | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
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 definesno_std
where std is not available.
To implement Json, you need toderive(Serialize, Deserialize)
for the type
src/sentences/apa.rs
Outdated
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); | ||
} |
There was a problem hiding this comment.
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
src/sentences/apa.rs
Outdated
#[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"}"#; |
There was a problem hiding this comment.
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
src/sentences/apb.rs
Outdated
There was a problem hiding this comment.
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.
Co-authored-by: Lachezar Lechev <8925621+elpiel@users.noreply.github.com>
Co-authored-by: Lachezar Lechev <8925621+elpiel@users.noreply.github.com>
No description provided.