/* ____________________________________________________________ Objet : Retirer l'indication de l'angle de la phrase VHW ____________________________________________________________ VHW - Water speed and heading 1 2 3 4 5 6 7 8 9 | | | | | | | | | $--VHW,x.x,T,x.x,M,x.x,N,x.x,K*hh Field Number: Heading degress, True T = True Heading degrees, Magnetic M = Magnetic Speed of vessel relative to the water, knots N = Knots Speed of vessel relative to the water, km/hr K = Kilometers Checksum ****************************************** ATTENTION : le programme qui suit a été réalisé sans vérification in situ. Il faut - entre autres - vérifier/compter exactement le nombre d'items dans la phrase nmea ****************************************** */ /////////////////////////////////////////////////////////// #include #include #include NMEA nmeaDecoder(ALL); SoftwareSerial mySerial(9,10); // 9 RX, 10 TX (ou autres) void setup() { Serial.begin(4800); mySerial.begin(4800); } // calculate checksum function (thanks to https://mechinations.wordpress.com) byte checksum(char* str) { byte cs = 0; for (unsigned int n = 1; n < strlen(str) - 1; n++) { cs ^= str[n]; } return cs; } void loop() { if (mySerial.available()) { if (nmeaDecoder.decode(mySerial.read())) { char* title = nmeaDecoder.term(0); if (strcmp(title,"IIVHW") == 0) { // on ne retient que les phrases qui commencent par VHW (vérifier les deux premiers termes) float vit = atof(nmeaDecoder.term(5)); //on reprend la vitesse en noeuds du capteur // on ajoute les termes pour faire la phrase NMEA en ajoutant les virgules La phrase est volontairement décomposée char mtwSentence [20]; byte cst; PString strt(mtwSentence, sizeof(mtwSentence)); strt.print("$IIVHW,"); strt.print(","); strt.print("T,"); // ou alors ne rien mettre => strt.print(",") à tester... strt.print(","); strt.print("M,"); // ou alors ne rien mettre => strt.print(",") à tester... strt.print(vit); strt.print(",N,,"); strt.print("K*"); cst = checksum(mtwSentence); if (cst < 0x10) strt.print('0'); strt.print(cst, HEX); Serial.println(mtwSentence); } } } }