1
こんにちはGNSS - NMEAの文字列を解析するコードを作ったのですが、現時点ではstrtokが文字を間違えて文字列を正しく分割していないようです。パーズGNSS - NMEAの文字列
このコードの問題点は何ですか?
奇妙なことに、私は基本的にFixstatusを取得しません。 GNSSrunstatusと同じですが、それがSerial.println(Fixstatus)とstrcpy(Fixstatus)で始まった理由です。
p.s .: Arduinoプロジェクト用です。
Fixstatus
UTCdatetime
20160501124554.000
latitude
47.199923
logitude
9.442710
altitude
474.100
speedOTG
0.37
course
fixmode
1
HDOP
1.3
PDOP
0.8
VDOP
?>0
また: - 解析コード(ない毎回)の
AT
OK
AT+CGNSPWR=1
OK
AT+CGNSINF
+CGNSINF: 1,1,20160501124254.000,47.199897,9.442750,473.500,0.35,36.8,1,,1.1,1.9,1.6,,13,7,,,39,,
OK
出力:私は文字列を解析していない場合、出力は次のようになります
#include <SoftwareSerial.h>
char frame[100];
char GNSSrunstatus[1];
char Fixstatus[1];
char UTCdatetime[18];
char latitude[10];
char logitude[11];
char altitude[8];
char speedOTG[6];
char course[6];
char fixmode[1];
char HDOP[4];
char PDOP[4];
char VDOP[4];
char satellitesinview[2];
char GNSSsatellitesused[2];
char GLONASSsatellitesused[2];
char cn0max[2];
char HPA[6];
char VPA[6];
boolean state;
double serialnr;
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Alles OK");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("AT");
mySerial.println("AT+CGNSPWR=1");
}
void loop() { // run over and over
get_GPS();
}
int8_t get_GPS() {
int8_t counter, answer;
long previous;
// First get the NMEA string
// Clean the input buffer
while (mySerial.available() > 0) mySerial.read();
// request Basic string
mySerial.println("AT+CGNSINF"); //sendATcommand("AT+CGNSINF", "AT+CGNSINF\r\n\r\n", 2000);
counter = 0;
answer = 0;
memset(frame, '\0', sizeof(frame)); // Initialize the string
previous = millis();
// this loop waits for the NMEA string
do {
if (mySerial.available() != 0) {
frame[counter] = mySerial.read();
counter++;
// check if the desired answer is in the response of the module
if (strstr(frame, "OK") != NULL)
{
answer = 1;
}
}
// Waits for the asnwer with time out
}
while ((answer == 0) && ((millis() - previous) < 2000));
frame[counter - 3] = '\0';
// Parses the string
strtok(frame, ",");
strcpy(Fixstatus, strtok(NULL, ",")); // Gets Fix status
strcpy(UTCdatetime, strtok(NULL, ",")); // Gets UTC date and time
strcpy(latitude, strtok(NULL, ",")); // Gets latitude
strcpy(logitude, strtok(NULL, ",")); // Gets longitude
strcpy(altitude, strtok(NULL, ",")); // Gets MSL altitude
strcpy(speedOTG, strtok(NULL, ",")); // Gets speed over ground
strcpy(course, strtok(NULL, ",")); // Gets course over ground
strcpy(fixmode, strtok(NULL, ",")); // Gets Fix Mode
strtok(NULL, ",");
strcpy(HDOP, strtok(NULL, ",")); // Gets HDOP
strcpy(PDOP, strtok(NULL, ",")); // Gets PDOP
strcpy(VDOP, strtok(NULL, ",")); // Gets VDOP
strtok(NULL, ",");
strcpy(satellitesinview, strtok(NULL, ",")); // Gets GNSS Satellites in View
strcpy(GNSSsatellitesused, strtok(NULL, ",")); // Gets GNSS Satellites used
strcpy(GLONASSsatellitesused, strtok(NULL, ",")); // Gets GLONASS Satellites used
strtok(NULL, ",");
strcpy(cn0max, strtok(NULL, ",")); // Gets C/N0 max
strcpy(HPA, strtok(NULL, ",")); // Gets HPA
strcpy(VPA, strtok(NULL, "\r")); // Gets VPA
Serial.println("Fixstatus");
Serial.println(Fixstatus);
Serial.println("UTCdatetime");
Serial.println(UTCdatetime);
Serial.println("latitude");
Serial.println(latitude);
Serial.println("logitude");
Serial.println(logitude);
Serial.println("altitude");
Serial.println(altitude);
Serial.println("speedOTG");
Serial.println(speedOTG);
Serial.println("course");
Serial.println(course);
Serial.println("fixmode");
Serial.println(fixmode);
Serial.println("HDOP");
Serial.println(HDOP);
Serial.println("PDOP");
Serial.println(PDOP);
Serial.println("VDOP");
Serial.println(VDOP);
Serial.println("satellitesinview");
Serial.println(satellitesinview);
Serial.println("GNSSsatellitesused");
Serial.println(GNSSsatellitesused);
Serial.println("GLONASSsatellitesused");
Serial.println(GLONASSsatellitesused);
Serial.println("cn0max");
Serial.println(cn0max);
Serial.println("HPA");
Serial.println(HPA);
Serial.println("VPA");
Serial.println(VPA);
return answer;
}
SIM808およびGNSS NEMAストリングのマニュアル(ページ9-10): Manual