Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:8419f38ed886
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Oct 28 22:16:36 2022 +0000
@@ -0,0 +1,67 @@
+//Michael Antonucci
+//Last modified Oct. 27, 2022
+//Assignment 4, Exercise 1: Create a working code to parse NMEA inputs into human-readable data
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+
+char dataque[100]; //calls for an array of 100 characters long with the name "dataque"
+char header[5]; //calls for an array of 5 characters long with name "header"
+float lat; //creates float "lat" for latitude
+float longi; //creates float "longi" for longitude
+char ns[1]; //creates array of 1 character with name "ns"
+char ew[1]; //creates array of 1 character with name "ew"
+float elevation; //creates float "elevation"
+char checksum[2]; //calls for an array of 2 characters long with name "checksum"
+int seconds; //creates integer "seconds" for time
+float xaccel; //creates float "xaccel" for x acceleration
+float yaccel; //creates float "yaccel" for y acceleration
+float zaccel; //creates float "zaccel" for z acceleration
+float temp; //creates float "temp" for temperature
+int main() { //starts main code
+ while(1) {
+ if (pc.readable()) {
+ pc.scanf("%s",dataque);
+ sscanf(dataque,"$%5s",header);
+ if (!strcmp(header,"GPRMC")) { //if the header is "GPRMC"
+ sscanf(dataque,"$%5s,%d,%f,%1s,%f,%1s,%f,*%2s", //reassigns variables to data
+ header,&seconds,&lat,ns,&longi,ew,&elevation,checksum);
+ pc.printf("GPS NMEA string recieved:\r\n"); //prints type of message
+ pc.printf("Time: %d seconds\r\n",seconds); //prints time
+ pc.printf("Latitude: %f degrees %s",lat,ns); //prints latitude
+ pc.printf("Longitude: %f degrees %s\r\n",longi,ew); //prints longitude
+ pc.printf("Elevation: %f m\r\n",elevation); //prints elevation
+ pc.printf("Checksum Value: %s",checksum); //prints checksum value
+ }
+ else if (!strcmp(header,"IMUPO")) { //if the header is "IMUPO", print a message
+ sscanf(dataque,"$%5s,%d,%f,%f,%f,*%2s", //reassigns variables to data
+ header,
+ &seconds,
+ &xaccel,
+ &yaccel,
+ &zaccel,
+ checksum);
+ pc.printf("Motion Message NMEA string recieved:\r\n"); //prints type of data
+ pc.printf("Time: %d seconds\r\n",seconds); //prints time
+ pc.printf("X-Acceleration: %f m/s^2 \r\n",xaccel); //prints x acceleration
+ pc.printf("Y-Acceleration: %f m/s^2 \r\n",yaccel); //prints y acceleration
+ pc.printf("Z-Acceleration: %f m/s^2 \r\n",zaccel); //prints z acceleration
+ pc.printf("Checksum Value: %2s \r\n",checksum); //prints checksum value
+ }
+ else if (!strcmp(header,"TEMPE")) { //if the header is "TEMPE", print a message
+ sscanf(dataque,"$%5s,%d,%f,*%2s", //reassigns variables to data
+ header,
+ &seconds,
+ &temp,
+ checksum);
+ pc.printf("Temperature NMEA string recieved:\r\n"); //prints type of data
+ pc.printf("Time: %d seconds\r\n",seconds); //prints time
+ pc.printf("Temperature: %f degrees Celcius\r\n",temp); //prints temperature
+ pc.printf("Checksum Value: %2s \r\n",checksum); //prints checksum value
+ }
+ else { //if the header is not one of those three, respond with an error message
+ pc.printf("NOT A VALID NMEA INDICATOR \r\n"); //shows that error is associated with header format
+ }
+ }
+ }
+ }
\ No newline at end of file
