This blog tells me the idea and implementation of using Arduino to parse and forward raw NEMA 0813 data. Because Arduino is relatively simple, can not realize the serial data receive interrupt, so are written in the main loop inside. Do not know what flaws and loopholes in the code, you are welcome to criticize correct.
GPS Software Requirements
· Ardiuno Software
· Monitor serial 1 to receive data.
· Data format: NEMA0813
· Parse out the latitude and longitude of the original format, Xxxx.xxxxx, Xxxx.xxxxx, save, parse out short format, 2B longitude, 2B dimension, save
· Short format: Latitude are 0.0ABCD format decimal the last 4 bits, such as the signal longitude is 1234.56789, then get 67 and 89
· When the latitude is normal, the LED is lit.
· Serial 2 When you receive the ADDRESSWHR:
· Latitude by the original format to the serial port 2 sent to Addressflt beginning, followed by the fixed format latitude and longitude XXXX.XXXXX,XXXX.XXXXX,CRC end
· Latitude by the short format to the serial Port 2 sent: {addresslct,2b longitude, 2B dimension, 1B CRC}
/*** * The circuit: * RX is digital pin ten (connect to TX of other device) * TX is digital pin one (connect to RX of Oth
ER device) ***/#include softwareserial myserial (10, 11);
char rmc_flag = 0;
char command_flag = 0;
Char gps_data_nema[220] = {0};
Char gps_data_rmc[72] = {0}; Char gps_data_anal[20] = {' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', '. ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', '. ', ' 0 '
, ' 0 ', ' 0 '};//latitude and longitude of char gps_data_byte[4] = {0};
Char *gprmc = "$GPRMC";
Char *command = "Ad";
Char command_code[2] = {0};
void memcpy (char *dest, char *src, int n) {int i = 0;
for (i = 0; i < n; i++) {*dest = *SRC;
dest++;
src++;
}} int memcmp (char *s1, char *s2, int n) {int i = 0;
for (i = 0; i < n; i++) {if (*s1! = *s2) return 0;
s1++;
s2++;
} return 1;
} void Setup () {serial.begin (57600);
Myserial.begin (4800);
} void Loop () {static Char i = 0;
static char j = 0;
char k = 0;
char L = 0; Char comma[12] = {0}; A total of 12A comma//put your main code here, to run Repeatedly:if (serial.available ()) {Gps_data_nema[i] = Serial.read ();
Serial.print (Gps_data_nema[i]);
if (i = = 0) {if (gps_data_nema[i]! = ' $ ') serial.println ("warning:the data input is wrong!");
} if (gps_data_nema[i] = = ' $ ') {i = 0;
Gps_data_nema[i] = ' $ '; } if (gps_data_nema[i] = = 0x0A)//if the end of string {if (memcmp (Gps_data_nema, GPRMC, 6)) {memcpy (g
PS_DATA_RMC, Gps_data_nema, i);
Rmc_flag = 1;
};
i = 0;
if (i >)//if the data is out range serial.println ("Warning:the Data Formation is false!");
i++;
} if (Rmc_flag = = 1) {L = 0;
for (k = 0; k < k++) {if (gps_data_rmc[k] = = ', ') {comma[l] = k;
L + +;
}} if ((comma[3]-comma[2]) = = Ten) {k = comma[2] + 1;
memcpy (&gps_data_anal[11], &gps_data_rmc[k], 9); } if ((comma[5]-comma[4]) = = one) {L = comma[4] + 1;
memcpy (&gps_data_anal[0], &gps_data_rmc[l], 10);
} Gps_data_byte[0] = gps_data_anal[8];
GPS_DATA_BYTE[1] = gps_data_anal[9];
GPS_DATA_BYTE[2] = gps_data_anal[18];
GPS_DATA_BYTE[3] = gps_data_anal[19];
Rmc_flag = 0;
} if (Myserial.available () && (Command_flag = = 0)) {Command_code[j] = Myserial.read ();
Myserial.print (Command_code[j]);
j = j + 1;
if (j = = 2) {myserial.print ("addresswhr");
Command_flag = 1;
j = 0;
}} if (Command_flag = = 1) {if (memcmp (command, Command_code, 2)) {Myserial.print ("Addressflt");
for (k = 0; k < k++) Myserial.print (Gps_data_anal[k]);
Myserial.print ("CRC");
Myserial.print ("ADDRESSLCT");
for (l = 0; l < 4; l++) Myserial.print (Gps_data_byte[l]);
Myserial.print ("CRC");
} command_flag = 0;
}
}